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