Files
DefiLlama-Adapters/projects/algomint/utils.js
Ronan Clooney 51c360e3f5 Algomint TVL update (#6288)
* algomint TVL to monitor new BTC & ETH baskets

* Fix incorrect export

* Orginal format

* update token obj

* correct format
2023-05-18 12:11:30 +02:00

38 lines
1.0 KiB
JavaScript

const {
getAppGlobalState,
getAccountInfo,
} = require("../helper/chain/algorand");
async function lpTokenPostion(asaId, appId, basketAddress) {
const poolGlobalState = await getAppGlobalState(appId);
//A & B represent the two tokens in the LP pool, Token A is always the ASA with the lowest ID
const balanceA = poolGlobalState.A;
const balanceB = poolGlobalState.B;
const lpCirculatingSupply = poolGlobalState.L;
const ratioA = balanceA / lpCirculatingSupply;
const ratioB = balanceB / lpCirculatingSupply;
//get basket balance of lp token
const basketBalance = await getAccountInfo(basketAddress);
const basketLpBalanceObject = basketBalance.assets;
let basketLpBalance;
for (let lpAsset of basketLpBalanceObject) {
if (lpAsset["asset-id"] === asaId) {
basketLpBalance = lpAsset.amount;
}
}
const positionA = basketLpBalance * ratioA;
const positionB = basketLpBalance * ratioB;
return { positionA: positionA, positionB: positionB };
}
module.exports = {
lpTokenPostion,
};