From 06418a7d8abdd8e25b1bf58d5faf757710bdcf52 Mon Sep 17 00:00:00 2001 From: greatpie Date: Thu, 15 Aug 2024 22:35:30 +0800 Subject: [PATCH 1/2] feat: subtract the cgUSDT in the withdrawal vault to reflect the true supply --- projects/cygnus-finance/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/projects/cygnus-finance/index.js b/projects/cygnus-finance/index.js index a4a696fe38b8..0bb68bcf7ed7 100644 --- a/projects/cygnus-finance/index.js +++ b/projects/cygnus-finance/index.js @@ -13,12 +13,15 @@ async function getJettonMetadata(addr) { const res = await get(`https://tonapi.io/v2/jettons/${addr}`) return res } +async function getJettonBalance(address, jettonMasterAddress) { + const res = await get(`https://tonapi.io/v2/accounts/${address}/jettons/${jettonMasterAddress}`) + return res.balance +} async function tonTvl() { const MINTER_ADDRESS = "EQCfvQW-thWpqKgyqtXCFbYayDlHqS0-frkyP6VD70paLFZa" const CGUSDT_ADDRESS = 'EQBIBw3mF_TDMJqWAZihVsyUBMWpWw_deftZLiCxTmrCUOKy' - const minterResult = await call({ target: MINTER_ADDRESS, abi: "get_minter_data", stack: [] }) // exchange rate from cgUSDT to USDT: decimal 9 const cgusdtTousdt = (minterResult[5]) / 10 ** 9 @@ -27,8 +30,11 @@ async function tonTvl() { const jettonResult = await getJettonMetadata(CGUSDT_ADDRESS) const cgUsdtTotalSupply = jettonResult['total_supply'] + // subtract the amount of cgUSDT in the withdrawal vault + const balance = await getJettonBalance(MINTER_ADDRESS, CGUSDT_ADDRESS) + // caculate tvl - const tvl = (cgUsdtTotalSupply) / 10 ** 6 * cgusdtTousdt + const tvl = (cgUsdtTotalSupply - balance) / 10 ** 6 * cgusdtTousdt return { "coingecko:tether": tvl } } From 6a3ce1cae6ab2fcc28a77c390bbc27102de577a5 Mon Sep 17 00:00:00 2001 From: greatpie Date: Thu, 15 Aug 2024 22:41:13 +0800 Subject: [PATCH 2/2] chore: rename balance variable --- projects/cygnus-finance/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/cygnus-finance/index.js b/projects/cygnus-finance/index.js index 0bb68bcf7ed7..91b035082561 100644 --- a/projects/cygnus-finance/index.js +++ b/projects/cygnus-finance/index.js @@ -31,10 +31,10 @@ async function tonTvl() { const cgUsdtTotalSupply = jettonResult['total_supply'] // subtract the amount of cgUSDT in the withdrawal vault - const balance = await getJettonBalance(MINTER_ADDRESS, CGUSDT_ADDRESS) + const withdrawVaultBalance = await getJettonBalance(MINTER_ADDRESS, CGUSDT_ADDRESS) // caculate tvl - const tvl = (cgUsdtTotalSupply - balance) / 10 ** 6 * cgusdtTousdt + const tvl = (cgUsdtTotalSupply - withdrawVaultBalance) / 10 ** 6 * cgusdtTousdt return { "coingecko:tether": tvl } }