Skip to content

Commit

Permalink
chore: simplify structure
Browse files Browse the repository at this point in the history
  • Loading branch information
SGiaccobasso committed Sep 24, 2024
1 parent b370672 commit 8fedb85
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 42 deletions.
20 changes: 2 additions & 18 deletions .github/workflows/validate-tokens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,5 @@ jobs:
- name: Install dependencies
run: bun install

- name: Extract and validate new tokens
run: |
git fetch origin ${{ github.base_ref }}
git show origin/${{ github.base_ref }}:registry/mainnet/interchain/squid.tokenlist.json > base_file.json
cp registry/mainnet/interchain/squid.tokenlist.json current_file.json
bun run - <<EOF
import * as fs from 'fs/promises';
const base = JSON.parse(await fs.readFile('base_file.json', 'utf8'));
const current = JSON.parse(await fs.readFile('current_file.json', 'utf8'));
const newTokens = Object.entries(current.tokens)
.filter(([id, token]) => !base.tokens[id])
.reduce((obj, [id, token]) => ({ ...obj, [id]: token }), {});
await fs.writeFile('new_tokens.json', JSON.stringify(newTokens, null, 2));
EOF
bun run scripts/validate-token-configs.ts
- name: Run validation
run: bun run scripts/run-validation.ts
80 changes: 80 additions & 0 deletions registry/mainnet/interchain/squid.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,86 @@
}
]
},
"0x1ac831937426660d5952bc9ae0dc7c895a3c3f5f159d3518813df30181404be6": {
"tokenId": "0x1ac831937426660d5952bc9ae0dc7c895a3c3f5f159d3518813df30181404be6",
"deployer": "0x7AAd74b7f0d60D5867B59dbD377a71783425af47",
"originalMinter": null,
"prettySymbol": "agETH",
"decimals": 18,
"originAxelarChainId": "ethereum",
"tokenType": "canonical",
"deploySalt": "0x",
"iconUrls": {
"svg": "https://raw.githubusercontent.com/axelarnetwork/axelar-configs/main/images/tokens/ageth.svg"
},
"deploymentMessageId": "0x9c77e79177ec83dff97c1d0749cd9d4cd2a7f2c6b36256d017df53819e10ab0e-476",
"chains": [
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "ethereum",
"tokenAddress": "0xe1b4d34e8754600962cd944b535180bd758e6c2e",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "lockUnlock"
},
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "polygon",
"tokenAddress": "0x1bD0Fe8E92a157D3ef66C9FB9e38621252b407c2",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "mintBurn"
},
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "optimism",
"tokenAddress": "0x1bD0Fe8E92a157D3ef66C9FB9e38621252b407c2",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "mintBurn"
},
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "linea",
"tokenAddress": "0x1bD0Fe8E92a157D3ef66C9FB9e38621252b407c2",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "mintBurn"
},
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "base",
"tokenAddress": "0x1bD0Fe8E92a157D3ef66C9FB9e38621252b407c2",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "mintBurn"
},
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "scroll",
"tokenAddress": "0x1bD0Fe8E92a157D3ef66C9FB9e38621252b407c2",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "mintBurn"
},
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "blast",
"tokenAddress": "0x1bD0Fe8E92a157D3ef66C9FB9e38621252b407c2",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "mintBurn"
},
{
"symbol": "agETH",
"name": "Kelp Gain",
"axelarChainId": "arbitrum",
"tokenAddress": "0x1bD0Fe8E92a157D3ef66C9FB9e38621252b407c2",
"tokenManager": "0xa526eDa85A1CF901E77a33493852B0aFD910Ed0d",
"tokenManagerType": "mintBurn"
}
]
},
"0x291401f2645b4a6a6439323c4db76a820439ace0a5ad7637e10a3f5adfdd7c33": {
"tokenId": "0x291401f2645b4a6a6439323c4db76a820439ace0a5ad7637e10a3f5adfdd7c33",
"deployer": "0xfb311Eb413a49389a2078284B57C8BEFeF6aFF67",
Expand Down
42 changes: 21 additions & 21 deletions scripts/run-validation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { readFile, writeFile, unlink } from "fs/promises";
import { execSync } from "child_process";
import { readFile } from "fs/promises";
import { execSync, spawnSync } from "child_process";
import path from "path";

const tokenListPath = "registry/mainnet/interchain/squid.tokenlist.json";
const tempFile = "new_tokens.json";

async function cleanup() {
try {
await unlink(tempFile);
} catch {}
}

async function main() {
try {
Expand All @@ -27,23 +20,30 @@ async function main() {
);
const localTokens = JSON.parse(localContent).tokens;

// Extract new tokens to new_tokens.json
// Extract new tokens
const newTokens = Object.entries(localTokens)
.filter(([id]) => !mainTokens[id])
.reduce((obj, [id, token]) => ({ ...obj, [id]: token }), {});

await writeFile("new_tokens.json", JSON.stringify(newTokens, null, 2));
} catch (error) {
console.error("An error occurred:", error);
cleanup();
}
// Run validation script with new tokens as parameter
const result = spawnSync(
"bun",
["run", "scripts/validate-token-configs.ts"],
{
input: JSON.stringify(newTokens),
encoding: "utf-8",
stdio: ["pipe", "inherit", "inherit"],
}
);

// Run validation script
try {
execSync("bun run scripts/validate-token-configs.ts", { stdio: "inherit" });
} catch {
} finally {
cleanup();
if (result.status !== 0) {
throw new Error(`Validation script exited with status ${result.status}`);
}

console.log("All new token configurations are valid.");
} catch (error) {
console.error("Validation failed:", (error as Error).message);
process.exit(1);
}
}

Expand Down
11 changes: 8 additions & 3 deletions scripts/validate-token-configs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as fs from "fs";
import { ethers } from "ethers";
import axios from "axios";

Expand Down Expand Up @@ -43,7 +42,6 @@ const tokenManagerTypes = [
"gateway",
];
const ITSAddress = "0xB5FB4BE02232B1bBA4dC8f81dc24C26980dE9e3C";
const TOKEN_FILE_ROUTE = "./new_tokens.json";
const COINGECKO_API_KEY = "CG-3VGxh1K3Qk7jAvpt4DJA3LvB";
const COINGECKO_URL = "https://api.coingecko.com/api/v3/coins/";
const CHAIN_CONFIGS_URL =
Expand Down Expand Up @@ -111,6 +109,13 @@ const tokenManagerABI = [
* Section: Helper Functions
* =============================
*/

async function getInputTokens() {
const chunks: any[] = [];
for await (const chunk of process.stdin) chunks.push(chunk);
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
}

async function getAxelarChains() {
const { data } = await axios.get(CHAIN_CONFIGS_URL);
return data.chains;
Expand Down Expand Up @@ -374,7 +379,7 @@ async function validateDeployerAndSalt(
async function main() {
try {
// Read new token configurations from file
const newTokens = JSON.parse(fs.readFileSync(TOKEN_FILE_ROUTE, "utf8"));
const newTokens = await getInputTokens();
await validateTokenInfo(newTokens);
} catch (error) {
exitWithError((error as Error).message);
Expand Down

0 comments on commit 8fedb85

Please sign in to comment.