Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

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

}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a cleaner to avoid NaN numbers

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asStringNumber?


const result = await response.json()
const integrators = asIntegrators(result)
Comment on lines +40 to +41
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we don't use asJSON more often?

let balUsd = 0
const tokenAddresses: { [chainId: string]: string[] } = {}
console.log(JSON.stringify(integrators, null, 2))
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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))
Loading