From 8987f89fa4f75c90fd6ae71d2d2f437b4bc35484 Mon Sep 17 00:00:00 2001 From: Paul V Puey Date: Mon, 15 May 2023 21:40:03 -0700 Subject: [PATCH] WIP --- src/bin/lifiReporter.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/lifiReporter.ts diff --git a/src/bin/lifiReporter.ts b/src/bin/lifiReporter.ts new file mode 100644 index 00000000..5c0461b7 --- /dev/null +++ b/src/bin/lifiReporter.ts @@ -0,0 +1,40 @@ +import { asArray, 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 + }) + }) + ) + }) + ) +}) + +const main = async (): Promise => { + const response = await fetch('https://li.quest/v1/integrators/edgeapp') + if (!response.ok) { + const text = await response.text() + throw new Error(text) + } + + const result = await response.json() + const integrators = asIntegrators(result) + let balUsd = 0 + console.log(JSON.stringify(integrators, null, 2)) + integrators.feeBalances.forEach(fb => { + fb.tokenBalances.forEach(tb => { + balUsd += Number(tb.amountUsd) + console.log(`${tb.token.name} (${tb.token.symbol}): $${tb.amountUsd}`) + }) + }) + console.log(`Total: $${balUsd}`) +} + +main().catch(e => console.log(e))