-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1220 from airswap/develop
Publish metadata package to NPM
- Loading branch information
Showing
5 changed files
with
86 additions
and
4 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
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,71 @@ | ||
const { ethers } = require('hardhat') | ||
const { getKnownTokens } = require('@airswap/metadata') | ||
const { chainNames, ChainIds } = require('@airswap/constants') | ||
const BalanceChecker = require('@airswap/balances/build/contracts/BalanceChecker.sol/BalanceChecker.json') | ||
const balancesDeploys = require('@airswap/balances/deploys.js') | ||
const poolDeploys = require('../deploys.js') | ||
|
||
async function main() { | ||
const [account] = await ethers.getSigners() | ||
const chainId = await account.getChainId() | ||
if (chainId === ChainIds.HARDHAT) { | ||
console.log('Value for --network flag is required') | ||
return | ||
} | ||
console.log('Account:', account.address) | ||
console.log('Network:', chainNames[chainId].toUpperCase()) | ||
console.log('\nPool:', poolDeploys[chainId]) | ||
|
||
if (!balancesDeploys[chainId]) { | ||
throw new Error('Unable to check balances on this chain.') | ||
} | ||
|
||
const tokens = (await getKnownTokens(Number(chainId))).tokens | ||
|
||
let count = tokens.length | ||
const addresses = [] | ||
while (count--) { | ||
if (ethers.utils.isAddress(tokens[count].address)) { | ||
addresses.push(tokens[count].address.toLowerCase()) | ||
} | ||
} | ||
|
||
console.log(`\nScanning non-zero balances for ${tokens.length} tokens...\n`) | ||
|
||
const balancesContract = new ethers.Contract( | ||
balancesDeploys[chainId], | ||
BalanceChecker.abi, | ||
account.provider | ||
) | ||
|
||
const chunk = 750 | ||
let balances = [] | ||
let index = 0 | ||
count = addresses.length | ||
while (index < count) { | ||
balances = balances.concat( | ||
await balancesContract.walletBalances( | ||
poolDeploys[chainId], | ||
addresses.slice(index, index + chunk) | ||
) | ||
) | ||
index += chunk | ||
} | ||
|
||
const result = [] | ||
for (let i = 0; i < balances.length; i++) { | ||
if (!balances[i].eq(0)) { | ||
result.push(addresses[i]) | ||
} | ||
} | ||
|
||
console.log('Non-zero balances in', result.length, 'tokens:\n') | ||
console.log(JSON.stringify(result)) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
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
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
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