Skip to content

Commit

Permalink
Merge pull request #1220 from airswap/develop
Browse files Browse the repository at this point in the history
Publish metadata package to NPM
  • Loading branch information
dmosites authored Oct 16, 2023
2 parents bc19efd + 0689375 commit ba3510f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
4 changes: 3 additions & 1 deletion source/pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
"deploy": "hardhat run ./scripts/deploy.js",
"verify": "hardhat run ./scripts/verify.js",
"ownership": "hardhat run ./scripts/ownership.js",
"migrate": "hardhat run ./scripts/migrate.js"
"migrate": "hardhat run ./scripts/migrate.js",
"balances": "hardhat run ./scripts/balances.js"
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.3"
},
"devDependencies": {
"@airswap/constants": "^4.1.2",
"@airswap/metadata": "^4.1.6",
"@airswap/types": "^4.1.1",
"@airswap/utils": "^4.1.5",
"prompt-confirm": "^2.0.4"
Expand Down
71 changes: 71 additions & 0 deletions source/pool/scripts/balances.js
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)
})
4 changes: 2 additions & 2 deletions source/pool/scripts/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const { abi } = require('./migrate-abis/4-1-1.js')
const deploys = require('../deploys.js')

const CONFIRMATIONS = 2
const PREVIOUS_POOL = '0xa55CDCe4F6300D57831b2792c45E55a899D8e2a4'
const NEW_POOL = '0xEEcD248D977Fd4D392915b4AdeF8154BA3aE9c02'
const PREVIOUS_POOL = '0xEEcD248D977Fd4D392915b4AdeF8154BA3aE9c02'
const NEW_POOL = '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11'

async function main() {
const [account] = await ethers.getSigners()
Expand Down
9 changes: 9 additions & 0 deletions tools/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ export async function getKnownTokens(
}
}
}
const hasToken: any = {}
let length = tokens.length
while (length--) {
if (hasToken[tokens[length].address.toLowerCase()]) {
tokens.splice(length, 1)
} else {
hasToken[tokens[length].address.toLowerCase()] = 1
}
}
return { tokens, errors }
}

Expand Down
2 changes: 1 addition & 1 deletion tools/metadata/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/metadata",
"version": "4.1.5",
"version": "4.1.6",
"description": "AirSwap: Token Metadata for Developers",
"repository": {
"type": "git",
Expand Down

0 comments on commit ba3510f

Please sign in to comment.