-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some scripts to finds deployed token managers
- Loading branch information
Showing
6 changed files
with
7,910 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,3 +111,4 @@ local.json | |
keys.json | ||
|
||
temp-arguments.js | ||
rpcs.toml |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters