Skip to content

Commit 83d3064

Browse files
Adolf998DurianDev
andauthored
update BounceBit CeDeFi Yield v3 calculation (#16950)
Co-authored-by: durian <[email protected]>
1 parent fe6268f commit 83d3064

File tree

3 files changed

+128
-2
lines changed

3 files changed

+128
-2
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
const ADDRESSES = require('../helper/coreAssets.json')
2+
const { cachedGraphQuery } = require("../helper/cache")
3+
4+
const config = {
5+
ethereum: [{
6+
type: 'subscribe',
7+
url: 'https://api.studio.thegraph.com/query/109925/portal-eth-v-3/v0.0.1',
8+
query: `query {
9+
tokens(first:10) {
10+
id
11+
tvl
12+
}
13+
_meta {
14+
block {
15+
number
16+
}
17+
}
18+
}`
19+
}, {
20+
type: 'simpleETHReward',
21+
url: 'https://bitswap-subgraph.bouncebit.io/subgraphs/name/portal-bb-v-3',
22+
query: `query {
23+
_meta {
24+
block {
25+
number
26+
}
27+
}
28+
tokenRewards(where: {tokenMappings_: {eid: "30101", oAddress: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}}) {
29+
reward
30+
}
31+
}`
32+
}],
33+
bsc: [{
34+
type: 'subscribe',
35+
url: 'https://api.studio.thegraph.com/query/109925/portal-bsc-v-3/v0.0.1',
36+
query: `query {
37+
tokens(first:10) {
38+
id
39+
tvl
40+
}
41+
_meta {
42+
block {
43+
number
44+
}
45+
}
46+
}`
47+
},
48+
{
49+
type: 'rewardList',
50+
url: 'https://bitswap-subgraph.bouncebit.io/subgraphs/name/portal-bb-v-3',
51+
query: `query {
52+
tokenRewards(first: 10) {
53+
reward
54+
tokenMappings{
55+
eid
56+
oAddress
57+
}
58+
}
59+
_meta {
60+
block {
61+
number
62+
}
63+
}
64+
}`
65+
}
66+
]
67+
}
68+
69+
async function fetchTokens(chain, subgraphUrl, query, cacheKey = '') {
70+
const prefix = `bouncebit-cedefi-v3${cacheKey}`
71+
return cachedGraphQuery(`${prefix}/${chain}`, subgraphUrl, query)
72+
// return graphQuery(subgraphUrl, query)
73+
}
74+
75+
async function cedefiV3Tvl(api) {
76+
const chain = api.chain
77+
const graphConfigList = config[chain]
78+
if (graphConfigList.length === 0) return api
79+
80+
const sourceTokenLists = await Promise.all(
81+
graphConfigList.map(item => fetchTokens(chain, item.url, item.query, item.type))
82+
)
83+
const subscribeTokenLists = sourceTokenLists.filter((_, idx) => graphConfigList[idx].type === 'subscribe').flatMap(result => result.tokens)
84+
85+
const rewardTokenLists = sourceTokenLists.filter((_, idx) => graphConfigList[idx].type === 'rewardList').flatMap(result => {
86+
return result.tokenRewards.flatMap(item => {
87+
// only bsc
88+
const targetToken = item.tokenMappings.find(i => i.eid == '30102')
89+
if (item.reward > 0 && targetToken && targetToken.oAddress) {
90+
return [{
91+
id: targetToken.oAddress,
92+
tvl: item.reward
93+
}]
94+
}
95+
}).filter(i => !!i)
96+
})
97+
98+
const rewardByETH = sourceTokenLists.filter((_, idx) => graphConfigList[idx].type === 'simpleETHReward').flatMap(result => {
99+
return result.tokenRewards.flatMap(item => {
100+
if (item.reward > 0) {
101+
return [{
102+
id: ADDRESSES.null,
103+
tvl: item.reward
104+
}]
105+
}
106+
}).filter(i => !!i)
107+
})
108+
109+
const allTokens = [...subscribeTokenLists, ...rewardTokenLists, ...rewardByETH]
110+
111+
allTokens.forEach(token => {
112+
api.add(token.id, token.tvl)
113+
})
114+
115+
return api
116+
}
117+
118+
Object.keys(config).forEach(chain => {
119+
module.exports[chain] = {
120+
tvl: cedefiV3Tvl
121+
}
122+
})

projects/bouncebit-cedefi/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const premium = require('./premium')
44
const promo = require('./promo')
55
const cedefiForCedefi = require('./cedefiFromSolana')
66
const promoFromSolana = require('./promoFromSolana')
7+
const cedefiV3 = require('./cedefiV3')
78

89
const config = {
910
ethereum: {
@@ -70,16 +71,17 @@ async function cedefiTvl(api) {
7071
}
7172

7273
async function combinedTvl(api) {
73-
const [cedefiBalances, easyBTCBalances, premiumBalances] = await Promise.all([
74+
const [cedefiBalances, easyBTCBalances, premiumBalances, cedefiV3Balances, promoBalances, promoFromSolanaBalances] = await Promise.all([
7475
cedefiTvl(api),
7576
easyBTC[api.chain]?.tvl?.(api) || {},
7677
premium[api.chain]?.tvl?.(api) || {},
78+
cedefiV3[api.chain]?.tvl?.(api) || {},
7779
promo[api.chain]?.tvl?.(api) || {},
7880
promoFromSolana[api.chain]?.tvl?.(api) || {}
7981
])
8082

8183
// merge all balances
82-
return api.sumTokens([cedefiBalances, easyBTCBalances, premiumBalances])
84+
return api.sumTokens([cedefiBalances, easyBTCBalances, premiumBalances, cedefiV3Balances, promoBalances, promoFromSolanaBalances])
8385
}
8486

8587
module.exports = {

projects/bouncebit-cedefi/promo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ async function promoTvl(api) {
5656
Object.entries(tokenTvls).forEach(([token, balance]) => {
5757
api.add(token, balance);
5858
});
59+
60+
return api.getBalances()
5961
}
6062

6163
Object.keys(config).forEach(chain => {

0 commit comments

Comments
 (0)