|
| 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