Skip to content

Commit

Permalink
using transformDexBalances, rm owner tokens from tvl
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpeluche committed Aug 13, 2024
1 parent 0a424e3 commit f23e383
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
44 changes: 9 additions & 35 deletions projects/alexlab/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const axios = require("axios");
const ADDRESSES = require("../helper/coreAssets.json");
const { toUSDT } = require("../helper/balances");
const { transformDexBalances } = require('../helper/portedTokens')

const pool_api = "https://api.alexlab.co/v2/public/pools";
const price_api = "https://api.alexlab.co/v1/price/";
const decimals = 1e18;
const decimals = 18;

const ownerTokens = [
"SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
Expand All @@ -14,41 +12,17 @@ const ownerTokens = [
const getPools = async (url) => {
const { data } = await axios.get(url);
return data.data.map((pool) => ({
token_x: pool.token_x,
balance_x: pool.balance_x,
token_y: pool.token_y,
balance_y: pool.balance_y,
token0: pool.token_x,
token0Bal: pool.balance_x / 10**(decimals-8),
token1: pool.token_y,
token1Bal: pool.balance_y / 10**(decimals-8),
}));
};

const poolPriceInUSD = async (api, pools) => {
await Promise.all(
pools.map(async (pool) => {
const [{ data: priceX }, { data: priceY }] = await Promise.all([
axios.get(`${price_api}${pool.token_x}`),
axios.get(`${price_api}${pool.token_y}`),
]);

let usd_balance_x = 0;
let usd_balance_y = 0;

if (!ownerTokens.includes(pool.token_x)) {
usd_balance_x = pool.balance_x * priceX.price;
}

if (!ownerTokens.includes(pool.token_y)) {
usd_balance_y = pool.balance_y * priceY.price;
}

const usdtPoolBalance = toUSDT(usd_balance_x + usd_balance_y) / decimals;
api.add(ADDRESSES.ethereum.USDT, usdtPoolBalance, { skipChain: true });
})
);
};

const tvl = async (api) => {
const pools = await getPools(pool_api);
return poolPriceInUSD(api, pools, ownerTokens);
const data = await getPools(pool_api);
await transformDexBalances({ chain: "stacks", data, balances: api.getBalances() })
api.deleteTokens(ownerTokens)
};

module.exports = {
Expand Down
5 changes: 4 additions & 1 deletion projects/helper/coreAssets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,10 @@
"stSTX": "SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token::ststx",
"USDT": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-susdt::bridged-usdt",
"aeUSDC": "SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-aeusdc",
"aBTC": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-abtc::bridged-btc"
"aBTC": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-abtc::bridged-btc",
"WSTX_3": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-wstx-v2",
"ALEX": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex",
"sUSDT": "SP2XD7417HGPRTREMKF748VNEQPDRR0RMANB7X1NK.token-susdt"
},
"neon_evm": {
"WNEON": "0xb14760c064a1b9eaf9ec5a8a421971e40a51b59c"
Expand Down

0 comments on commit f23e383

Please sign in to comment.