Skip to content

Commit 72e40e9

Browse files
authored
Add swap.coffee staking and pool2 adapter (DefiLlama#12031)
1 parent 3c19210 commit 72e40e9

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

projects/helper/chain/ton.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ async function getTonBalance(addr) {
1111
return res.balance
1212
}
1313

14+
async function getJettonBalances(addr) {
15+
const response = await get(`https://tonapi.io/v2/accounts/${addr}/jettons?currencies=usd`)
16+
17+
const res = { }
18+
response.balances.forEach(val => {
19+
res[val.jetton.address] = { balance: val.balance, price: val.price.prices.USD, decimals: val.jetton.decimals }
20+
})
21+
22+
return res
23+
}
24+
1425
async function _sumTokensAccount({ api, addr, tokens = [], onlyWhitelistedTokens = false }) {
1526
if (tokens.includes(ADDRESSES.null)) {
1627
const balance = await getTonBalance(addr)
@@ -91,4 +102,5 @@ module.exports = {
91102
sumTokens,
92103
sumTokensExport,
93104
call,
105+
getJettonBalances,
94106
}

projects/swap-coffee/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { call, sumTokensExport, getTokenRates, getJettonBalances } = require('../helper/chain/ton')
2+
const {sleep} = require("../helper/utils");
3+
4+
const CES_MASTER = "0:a5d12e31be87867851a28d3ce271203c8fa1a28ae826256e73c506d94d49edad"
5+
const STAKING_CONTRACT = "0:29f90533937d696105883b981e9427d1ae411eef5b08eab83f4af89c495d27df"
6+
const DEDUST_TON_CES_POOL = "0:123e245683bd5e93ae787764ebf22291306f4a3fcbb2dcfcf9e337186af92c83"
7+
const STONFI_CES_TON_POOL = "0:6a839f7a9d6e5303d71f51e3c41469f2c35574179eb4bfb420dca624bb989753"
8+
9+
async function getTokenSupply(addr) {
10+
return (await call({ target: addr, abi: "get_jetton_data"}))[0] / 1e9
11+
}
12+
13+
function calcVolume(reserve, supply, rate) {
14+
return ((reserve / 1e9) / supply) * rate
15+
}
16+
17+
module.exports = {
18+
methodology: "Counts swap.coffee smartcontract balance as TVL.",
19+
timetravel: false,
20+
ton: {
21+
tvl: () => { },
22+
staking: sumTokensExport({ owners: [STAKING_CONTRACT], tokens: [CES_MASTER]}),
23+
pool2: async (api) => {
24+
const dedustPoolReserves = await call({ target: DEDUST_TON_CES_POOL, abi: "get_reserves" })
25+
const dedustLpSupply = await getTokenSupply(DEDUST_TON_CES_POOL)
26+
27+
// toncenter api is rate limited
28+
await sleep(3000)
29+
30+
const stonfiPoolReserves = await call({ target: STONFI_CES_TON_POOL, abi: "get_pool_data" })
31+
const stonfiLpSupply = await getTokenSupply(STONFI_CES_TON_POOL)
32+
33+
const rates = await getTokenRates({ tokens: ["TON", CES_MASTER] })
34+
35+
const stonLpPrice = calcVolume(stonfiPoolReserves[0], stonfiLpSupply, rates[CES_MASTER]) +
36+
calcVolume(stonfiPoolReserves[1], stonfiLpSupply, rates["TON"])
37+
const dedustLpPrice = calcVolume(dedustPoolReserves[0], dedustLpSupply, rates["TON"]) +
38+
calcVolume(dedustPoolReserves[1], dedustLpSupply, rates[CES_MASTER])
39+
40+
const balances = await getJettonBalances(STAKING_CONTRACT)
41+
42+
return api.addUSDValue((stonLpPrice * balances[STONFI_CES_TON_POOL].balance / 1e9) +
43+
(dedustLpPrice * balances[DEDUST_TON_CES_POOL].balance / 1e9))
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)