-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paul/lifi reporter #194
base: master
Are you sure you want to change the base?
Paul/lifi reporter #194
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a cleaner to avoid NaN numbers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
const result = await response.json() | ||
const integrators = asIntegrators(result) | ||
Comment on lines
+40
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why we don't use |
||
let balUsd = 0 | ||
const tokenAddresses: { [chainId: string]: string[] } = {} | ||
console.log(JSON.stringify(integrators, null, 2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this console log for debugging? |
||
integrators.feeBalances.forEach(fb => { | ||
fb.tokenBalances.forEach(tb => { | ||
const amount = Number(tb.amountUsd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, why not use an asStringNumber? |
||
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error should include text for lookup