Skip to content

Commit

Permalink
Merge pull request #194 from EdgeApp/paul/lifiReporter
Browse files Browse the repository at this point in the history
Paul/lifi reporter
  • Loading branch information
paullinator authored Dec 2, 2024
2 parents a964ae5 + 027b1b5 commit 7e84987
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"clean": "rimraf lib dist .parcel-cache",
"fix": "npm run lint -- --fix",
"fio:promo": "node -r sucrase/register src/bin/fioPromo/fioPromo.ts",
"lifi": "node -r sucrase/register src/bin/lifiReporter.ts",
"precommit": "lint-staged && npm run prepare",
"prepare": "./scripts/prepare.sh && npm-run-all clean -p build.*",
"start": "node -r sucrase/register src/indexQuery.ts",
Expand Down
80 changes: 80 additions & 0 deletions src/bin/lifiReporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 asTransactionRequest = asObject({
transactionRequest: asObject({
data: asString,
to: asString
})
})

const url = 'https://li.quest'

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

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

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}\n`)
for (const chainId in tokenAddresses) {
console.log(`\n**********************************`)
console.log(`chainId:${chainId}\n`)
const tokens = tokenAddresses[chainId].join(',')
const response = await fetch(
`${url}/v1/integrators/edgeapp/withdraw/${chainId}?tokenAddresses=${tokens}`
)

if (!response.ok) {
const text = await response.text()
throw new Error(text)
}

const result = asTransactionRequest(await response.json())
console.log(`to address: ${result.transactionRequest.to}`)
console.log(`data: ${result.transactionRequest.data}`)
}
}

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

0 comments on commit 7e84987

Please sign in to comment.