1
1
const {
2
- Pool ,
2
+ PoolV1 ,
3
3
BackstopToken,
4
4
Backstop,
5
5
FixedMath,
6
+ TokenMetadata,
6
7
} = require ( '@blend-capital/blend-sdk' ) ;
7
- const { getPrices, keepFinite, formatChain } = require ( '../utils' ) ;
8
+ const { getPrices, keepFinite, formatChain, getData } = require ( '../utils' ) ;
8
9
9
10
const BACKSTOP_ID = 'CAO3AGAMZVRMHITL36EJ2VZQWKYRPWMQAPDQD5YEOF3GIF7T44U4JAL3' ;
10
11
const BLND_ID = 'CD25MNVTZDL4Y3XBCPCJXGXATV5WUHHOWMYFF4YBEGU5FCPGMYTVG5JY' ;
11
12
const BLEND_POOLS = [
12
13
'CDVQVKOY2YSXS2IC7KN6MNASSHPAO7UN2UR2ON4OI2SKMFJNVAMDX6DP' ,
13
14
'CBP7NO6F7FRDHSOFQBT2L2UWYIZ2PU76JKVRYAQTG3KZSQLYAOKIF2WB' ,
15
+ 'CDE65QK2ROZ32V2LVLBOKYPX47TYMYO37Z6ASQTBRTBNK53C7C6QF4Y7' ,
16
+ 'CAQF5KNOFIGRI24NQRRGUPD46Q45MGMXZMRTQFXS25Y4NZVNPT34GM6S' ,
14
17
] ;
15
18
const NETWORK = {
16
19
rpc : 'https://soroban-rpc.creit.tech/' ,
17
20
passphrase : 'Public Global Stellar Network ; September 2015' ,
18
21
} ;
19
22
20
- const getApy = async ( poolId , backstop ) => {
21
- const pool = await Pool . load ( NETWORK , poolId ) ;
23
+ const getApy = async ( poolId , backstop , blndPrice ) => {
24
+ const pool = await PoolV1 . load ( NETWORK , poolId ) ;
22
25
// Skip pools that have been admin frozen - Pool is very likely to be broken
23
- if ( pool . config . status === 4 ) return [ ] ;
24
- const prices = await getPrices ( pool . config . reserveList , 'stellar' ) ;
26
+ if ( pool . metadata . status === 4 ) return [ ] ;
27
+
28
+ const prices = await getPrices ( pool . metadata . reserveList , 'stellar' ) ;
25
29
let pools = [ ] ;
26
- for ( const reserve of pool . reserves . values ( ) ) {
30
+
31
+ for ( const reserve of Array . from ( pool . reserves . values ( ) ) ) {
27
32
const price = prices . pricesByAddress [ reserve . assetId . toLowerCase ( ) ] ;
33
+
28
34
if ( price ) {
29
- let supplyEmissionsPerAsset = reserve . emissionsPerYearPerSuppliedAsset ( ) ;
30
- let borrowEmissionsPerAsset = reserve . emissionsPerYearPerBorrowedAsset ( ) ;
35
+ let tokenMetadata = await TokenMetadata . load ( NETWORK , reserve . assetId ) ;
31
36
let supplyEmissionsAPR = undefined ;
32
37
let borrowEmissionsAPR = undefined ;
33
- // The backstop token is an 80/20 weighted lp token of blnd and usdc respectively
34
- // (Calculated using balancer spot equation)
35
- // @TODO replace with coingecko price after listing
36
- const usdcPerBlnd =
37
- FixedMath . toFloat ( backstop . backstopToken . usdc , 7 ) /
38
- 0.2 /
39
- ( FixedMath . toFloat ( backstop . backstopToken . blnd , 7 ) / 0.8 ) ;
40
- if ( supplyEmissionsPerAsset > 0 ) {
41
- supplyEmissionsAPR = ( supplyEmissionsPerAsset * usdcPerBlnd ) / price ;
38
+ if ( reserve . supplyEmissions ) {
39
+ const supplyEmissionsPerAsset =
40
+ reserve . supplyEmissions . emissionsPerYearPerToken (
41
+ reserve . totalSupply ( ) ,
42
+ reserve . config . decimals
43
+ ) ;
44
+
45
+ supplyEmissionsAPR = ( supplyEmissionsPerAsset * blndPrice ) / price ;
42
46
}
43
- if ( borrowEmissionsPerAsset > 0 ) {
44
- borrowEmissionsAPR = ( borrowEmissionsPerAsset * usdcPerBlnd ) / price ;
47
+ if ( reserve . borrowEmissions ) {
48
+ const borrowEmissionsPerAsset =
49
+ reserve . borrowEmissions . emissionsPerYearPerToken (
50
+ reserve . totalLiabilities ( ) ,
51
+ reserve . config . decimals
52
+ ) ;
53
+ borrowEmissionsAPR = ( borrowEmissionsPerAsset * blndPrice ) / price ;
45
54
}
46
- // Estimate borrow APY compounded daily
47
- const borrowApy = ( 1 + reserve . borrowApr / 365 ) ** 365 - 1 ;
55
+
48
56
let totalSupply = reserve . totalSupplyFloat ( ) * price ;
49
57
let totalBorrow = reserve . totalLiabilitiesFloat ( ) * price ;
50
-
51
58
const url = `https://mainnet.blend.capital/dashboard/?poolId=${ poolId } ` ;
52
59
53
60
pools . push ( {
54
61
pool : `${ pool . id } -${ reserve . assetId } -stellar` . toLowerCase ( ) ,
55
62
chain : formatChain ( 'stellar' ) ,
56
63
project : 'blend-pools' ,
57
- symbol : reserve . tokenMetadata . symbol ,
64
+ symbol : tokenMetadata . symbol ,
58
65
tvlUsd : totalSupply - totalBorrow ,
59
- // Supply is kept as APR to prevent overestimation of APY
60
- apyBase : reserve . supplyApr * 100 ,
66
+ //Estimated weekly compounding
67
+ apyBase : reserve . estSupplyApy * 100 ,
61
68
apyReward : supplyEmissionsAPR * 100 ,
62
69
underlyingTokens : [ reserve . assetId ] ,
63
70
rewardTokens : borrowEmissionsAPR || supplyEmissionsAPR ? [ BLND_ID ] : [ ] ,
64
71
totalSupplyUsd : totalSupply ,
65
72
totalBorrowUsd : totalBorrow ,
66
- apyBaseBorrow : borrowApy * 100 ,
73
+ // Estimated daily compounding
74
+ apyBaseBorrow : reserve . estBorrowApy * 100 ,
67
75
apyRewardBorrow : borrowEmissionsAPR * 100 ,
68
76
ltv : totalBorrow / totalSupply ,
69
- poolMeta : `${ pool . config . name } Pool` ,
77
+ poolMeta : `${ pool . metadata . name } Pool` ,
70
78
url,
71
79
} ) ;
72
80
}
@@ -77,10 +85,16 @@ const getApy = async (poolId, backstop) => {
77
85
const apy = async ( ) => {
78
86
let backstop = await Backstop . load ( NETWORK , BACKSTOP_ID ) ;
79
87
let pools = [ ] ;
80
-
88
+ const data = await getData (
89
+ 'https://coins.llama.fi/prices/current/coingecko:blend'
90
+ ) ;
81
91
for ( const poolId of BLEND_POOLS ) {
82
- let poolApys = await getApy ( poolId , backstop ) ;
83
- pools . push ( ...poolApys )
92
+ let poolApys = await getApy (
93
+ poolId ,
94
+ backstop ,
95
+ data . coins [ 'coingecko:blend' ] . price
96
+ ) ;
97
+ pools . push ( ...poolApys ) ;
84
98
}
85
99
return pools ;
86
100
} ;
0 commit comments