-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba5b557
commit ca99ccd
Showing
1 changed file
with
59 additions
and
0 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
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)) |