Skip to content

Commit

Permalink
added some scripts to finds deployed token managers
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Mar 13, 2024
1 parent e4ba59b commit 0fd9f35
Show file tree
Hide file tree
Showing 6 changed files with 7,910 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ local.json
keys.json

temp-arguments.js
rpcs.toml
7,789 changes: 7,789 additions & 0 deletions axelar-chains-config/info/tokenManagers.json

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions evm/get-duplicate-token-managers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { ethers } = require('hardhat');
const { Contract, getDefaultProvider } = ethers;
const info = require('../axelar-chains-config/info/mainnet.json');
const tokenManagerInfo = require('../axelar-chains-config/info/tokenManagers.json');
const ITokenManager = require('@axelar-network/interchain-token-service/artifacts/contracts/interfaces/ITokenManager.sol/ITokenManager.json');
const fs = require('fs');
const toml = require('toml');

const RPCs = toml.parse(fs.readFileSync('./axelar-chains-config/info/rpcs.toml', 'utf-8'));

async function getTokens(name) {
if(!tokenManagerInfo[name]) return;
const tokenManagers = tokenManagerInfo[name].tokenManagers;
const chain = info.chains[name];
if(chain.contracts.InterchainTokenService.skip) return;

const rpc = RPCs.axelar_bridge_evm.find((chain) => chain.name.toLowerCase() === name.toLowerCase()).rpc_addr;
const provider = getDefaultProvider(rpc);

for(const tokenData of tokenManagers) {
const tokenManager = new Contract(tokenData[1], ITokenManager.abi, provider);
tokenData.tokenAddress = await tokenManager.tokenAddress();
}
const managerCounts = {};
const tokenCounts = {};
tokenManagers.forEach(function (x) { tokenCounts[x.tokenAddress] = (tokenCounts[x.tokenAddress] || 0) + 1; });
tokenManagers.forEach(function (x) { managerCounts[x[1]] = (managerCounts[x[1]] || 0) + 1; });
duplicated = tokenManagers.filter((x) => tokenCounts[x.tokenAddress] > managerCounts[x[1]]);
console.log(duplicated);

const mintBurn = tokenManagers.filter((x) => x[2] == 2);
console.log(`MintBurn: ${mintBurn.length}`);

const mintBurnFrom = tokenManagers.filter((x) => x[2] == 1);
console.log(`MintBurnFrom: ${mintBurnFrom.length}`);
}

(async() => {

for(const name of Object.keys(info.chains)) {
console.log(name);
try {
await getTokens(name);
} catch (e) {
console.log(name);
console.log(e);
}
}
})();
59 changes: 59 additions & 0 deletions evm/get-token-manager-deployments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { ethers } = require('hardhat');
const { Contract, getDefaultProvider } = ethers;
const info = require('../axelar-chains-config/info/mainnet.json');
const tokenManagerInfo = require('../axelar-chains-config/info/tokenManagers.json');
const IInterchainTokenService = require('@axelar-network/interchain-token-service/artifacts/contracts/interfaces/IInterchainTokenService.sol/IInterchainTokenService.json');
const fs = require('fs');
const toml = require('toml');

const RPCs = toml.parse(fs.readFileSync('./axelar-chains-config/info/rpcs.toml', 'utf-8'));

// This is before the its was deployed on mainnet.
const startTimestamp = 1702800000;
const eventsLength = 2000;

async function getTokenManagers(name) {
try {
const chain = info.chains[name];
if(chain.contracts.InterchainTokenService.skip) return;

const rpc = RPCs.axelar_bridge_evm.find((chain) => chain.name.toLowerCase() === name.toLowerCase()).rpc_addr;
const provider = getDefaultProvider(rpc);

const its = new Contract(chain.contracts.InterchainTokenService.address, IInterchainTokenService.abi, provider);

const blockNumber = await provider.getBlockNumber();
if(!tokenManagerInfo[name]) {
tokenManagerInfo[name] = {start: blockNumber, end: blockNumber, tokenManagers: []};
}

const filter = its.filters.TokenManagerDeployed();
while(blockNumber > tokenManagerInfo[name].end) {
let end = blockNumber > tokenManagerInfo[name].end + eventsLength ? blockNumber : tokenManagerInfo[name].end + eventsLength;
const events = await its.queryFilter(filter, tokenManagerInfo[name].end + 1, end);
tokenManagerInfo[name].tokenManagers = tokenManagerInfo[name].tokenManagers.concat(events.map(event => event.args));
tokenManagerInfo[name].end = end;
fs.writeFileSync('./axelar-chains-config/info/tokenManagers.json', JSON.stringify(tokenManagerInfo, null, 2));
}

while(true) {
const block = await provider.getBlock(tokenManagerInfo[name].start);
console.log(name, block.timestamp);
if(block.timestamp < startTimestamp || tokenManagerInfo[name].start < 0) break;
const events = await its.queryFilter(filter, tokenManagerInfo[name].start - eventsLength, tokenManagerInfo[name].start-1);

tokenManagerInfo[name].tokenManagers = tokens[name].tokenManagers.concat(events.map(event => event.args));
tokenManagerInfo[name].start -= eventsLength;
fs.writeFileSync('./axelar-chains-config/info/tokenManagers.json', JSON.stringify(tokenManagerInfo, null, 2))
}
} catch (e) {
console.log(name);
console.log(e);
}
}
(async() => {
for(const name of Object.keys(info.chains)) {
// add an await to run in sequence, which is slower.
getTokenManagers(name);
}
})();
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
"@axelar-network/interchain-token-service": "1.2.1",
"@cosmjs/cosmwasm-stargate": "^0.32.1",
"@ledgerhq/hw-app-eth": "6.32.2",
"axios": "^1.6.2",
"path": "^0.12.7",
"axios": "^1.6.2"
"toml": "^3.0.0"
},
"devDependencies": {
"@ledgerhq/hw-transport-node-hid": "^6.27.21",
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@openzeppelin/defender-relay-client": "^1.54.1",
"chai": "^4.3.7",
"chalk": "^4.1.2",
"commander": "^11.0.0",
Expand All @@ -43,9 +46,7 @@
"hardhat": "^2.13.0",
"mocha": "^10.2.0",
"prettier": "^2.8.7",
"readline-sync": "^1.4.10",
"@ledgerhq/hw-transport-node-hid": "^6.27.21",
"@openzeppelin/defender-relay-client": "^1.54.1"
"readline-sync": "^1.4.10"
},
"engines": {
"node": ">=16"
Expand Down

0 comments on commit 0fd9f35

Please sign in to comment.