Skip to content

Commit 7e84987

Browse files
authored
Merge pull request #194 from EdgeApp/paul/lifiReporter
Paul/lifi reporter
2 parents a964ae5 + 027b1b5 commit 7e84987

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"clean": "rimraf lib dist .parcel-cache",
1515
"fix": "npm run lint -- --fix",
1616
"fio:promo": "node -r sucrase/register src/bin/fioPromo/fioPromo.ts",
17+
"lifi": "node -r sucrase/register src/bin/lifiReporter.ts",
1718
"precommit": "lint-staged && npm run prepare",
1819
"prepare": "./scripts/prepare.sh && npm-run-all clean -p build.*",
1920
"start": "node -r sucrase/register src/indexQuery.ts",

src/bin/lifiReporter.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { asArray, asNumber, asObject, asString } from 'cleaners'
2+
import fetch from 'node-fetch'
3+
4+
const asIntegrators = asObject({
5+
feeBalances: asArray(
6+
asObject({
7+
tokenBalances: asArray(
8+
asObject({
9+
amountUsd: asString,
10+
token: asObject({
11+
name: asString,
12+
symbol: asString,
13+
address: asString,
14+
chainId: asNumber
15+
})
16+
})
17+
)
18+
})
19+
)
20+
})
21+
22+
const asTransactionRequest = asObject({
23+
transactionRequest: asObject({
24+
data: asString,
25+
to: asString
26+
})
27+
})
28+
29+
const url = 'https://li.quest'
30+
31+
const main = async (): Promise<void> => {
32+
const response = await fetch(`${url}/v1/integrators/edgeapp`)
33+
if (!response.ok) {
34+
const text = await response.text()
35+
throw new Error(text)
36+
}
37+
38+
const minAmount = Number(process.argv[2] ?? 100)
39+
40+
const result = await response.json()
41+
const integrators = asIntegrators(result)
42+
let balUsd = 0
43+
const tokenAddresses: { [chainId: string]: string[] } = {}
44+
console.log(JSON.stringify(integrators, null, 2))
45+
integrators.feeBalances.forEach(fb => {
46+
fb.tokenBalances.forEach(tb => {
47+
const amount = Number(tb.amountUsd)
48+
if (amount >= minAmount) {
49+
balUsd += amount
50+
if (tokenAddresses[tb.token.chainId] === undefined) {
51+
tokenAddresses[tb.token.chainId] = []
52+
}
53+
tokenAddresses[tb.token.chainId].push(tb.token.address)
54+
console.log(
55+
`chainId:${tb.token.chainId} ${tb.token.symbol} (${tb.token.address}): $${tb.amountUsd}`
56+
)
57+
}
58+
})
59+
})
60+
console.log(`Total: $${balUsd}\n`)
61+
for (const chainId in tokenAddresses) {
62+
console.log(`\n**********************************`)
63+
console.log(`chainId:${chainId}\n`)
64+
const tokens = tokenAddresses[chainId].join(',')
65+
const response = await fetch(
66+
`${url}/v1/integrators/edgeapp/withdraw/${chainId}?tokenAddresses=${tokens}`
67+
)
68+
69+
if (!response.ok) {
70+
const text = await response.text()
71+
throw new Error(text)
72+
}
73+
74+
const result = asTransactionRequest(await response.json())
75+
console.log(`to address: ${result.transactionRequest.to}`)
76+
console.log(`data: ${result.transactionRequest.data}`)
77+
}
78+
}
79+
80+
main().catch(e => console.log(e))

0 commit comments

Comments
 (0)