Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Nov 4, 2024
1 parent ba5b557 commit ca99ccd
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/bin/lifiReporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { asArray, asNumber, asObject, asString } from 'cleaners'
import fetch from 'node-fetch'

const asIntegrators = asObject({
feeBalances: asArray(
asObject({
tokenBalances: asArray(
asObject({
amountUsd: asString,
token: asObject({
name: asString,
symbol: asString,
address: asString,
chainId: asNumber
})
})
)
})
)
})

const main = async (): Promise<void> => {
const response = await fetch('https://li.quest/v1/integrators/edgeapp')
if (!response.ok) {
const text = await response.text()
throw new Error(text)
}

const minAmount = Number(process.argv[2] ?? 0)

const result = await response.json()
const integrators = asIntegrators(result)
let balUsd = 0
const tokenAddresses: { [chainId: string]: string[] } = []
console.log(JSON.stringify(integrators, null, 2))
integrators.feeBalances.forEach(fb => {
fb.tokenBalances.forEach(tb => {
const amount = Number(tb.amountUsd)
if (amount >= minAmount) {
balUsd += amount
if (tokenAddresses[tb.token.chainId] === undefined) {
tokenAddresses[tb.token.chainId] = []
}
tokenAddresses[tb.token.chainId].push(tb.token.address)
console.log(
`chainId:${tb.token.chainId} ${tb.token.symbol} (${tb.token.address}): $${tb.amountUsd}`
)
}
})
})
console.log(`Total: $${balUsd}`)
for (const chainId in tokenAddresses) {
console.log(
`chainId:${chainId} tokenAddresses=${tokenAddresses[chainId].join(',')}`
)
}
}

main().catch(e => console.log(e))

0 comments on commit ca99ccd

Please sign in to comment.