From ef862d2baff7e5eb3a2d4811db2e88ad44cbdf4b Mon Sep 17 00:00:00 2001 From: fiftyeightandeight Date: Wed, 12 Jun 2024 15:46:33 +0800 Subject: [PATCH] add api.js --- projects/xlink/api.js | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 projects/xlink/api.js diff --git a/projects/xlink/api.js b/projects/xlink/api.js new file mode 100644 index 000000000..1744ecb12 --- /dev/null +++ b/projects/xlink/api.js @@ -0,0 +1,51 @@ +const { call } = require("../helper/chain/stacks-api"); + +module.exports = { + timetravel: false, + stacks: { tvl }, +}; + +async function tvl() { + const owners = [ + "SP2XD7417HGPRTREMKF748VNEQPDRR0RMANB7X1NK.cross-bridge-registry-v2-01", + "SP2XD7417HGPRTREMKF748VNEQPDRR0RMANB7X1NK.btc-peg-out-endpoint-v2-01", + ]; + let lqstx = 0; + let abtc = 0; + let alex = 0; + for (const owner of owners) { + lqstx += Number( + ( + await call({ + target: "SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.token-vlqstx", + abi: "get-share", + inputArgs: [{ type: "principal", value: owner }], + }) + ).value + ); + abtc += Number( + ( + await call({ + target: "SP2XD7417HGPRTREMKF748VNEQPDRR0RMANB7X1NK.token-abtc", + abi: "get-balance", + inputArgs: [{ type: "principal", value: owner }], + }) + ).value + ); + alex += Number( + ( + await call({ + target: "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex", + abi: "get-balance", + inputArgs: [{ type: "principal", value: owner }], + }) + ).value + ); + } + + return { + blockstack: lqstx / 1e6, + bitcoin: abtc / 1e8, + alexgo: alex / 1e8, + }; +}