@stake-dao/reader 0.5.14 → 0.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/bytecodes/index.js +1 -0
- package/dist/esm/bytecodes/index.js.map +1 -1
- package/dist/esm/bytecodes/strategies/batches/batchBalancerStrats.js +1 -1
- package/dist/esm/bytecodes/strategies/batches/batchBalancerStrats.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/batchDirectIncentives.js +17 -0
- package/dist/esm/bytecodes/votemarket/batchDirectIncentives.js.map +1 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/balancer.js +2 -0
- package/dist/esm/lockers/fetch/protocols/balancer.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/blackpool.js +2 -0
- package/dist/esm/lockers/fetch/protocols/blackpool.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/curve.js +2 -0
- package/dist/esm/lockers/fetch/protocols/curve.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/frax-fxs.js +2 -0
- package/dist/esm/lockers/fetch/protocols/frax-fxs.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/fxn.js +2 -0
- package/dist/esm/lockers/fetch/protocols/fxn.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/maverick.js +2 -0
- package/dist/esm/lockers/fetch/protocols/maverick.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/pendle.js +2 -0
- package/dist/esm/lockers/fetch/protocols/pendle.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/spectra.js +2 -0
- package/dist/esm/lockers/fetch/protocols/spectra.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/yearn.js +2 -0
- package/dist/esm/lockers/fetch/protocols/yearn.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/yieldbasis.js +2 -0
- package/dist/esm/lockers/fetch/protocols/yieldbasis.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/yieldnest.js +2 -0
- package/dist/esm/lockers/fetch/protocols/yieldnest.js.map +1 -1
- package/dist/esm/lockers/fetch/protocols/zerolend.js +2 -0
- package/dist/esm/lockers/fetch/protocols/zerolend.js.map +1 -1
- package/dist/esm/prices.js +178 -85
- package/dist/esm/prices.js.map +1 -1
- package/dist/esm/strategies/balancer/fetch.js +3 -21
- package/dist/esm/strategies/balancer/fetch.js.map +1 -1
- package/dist/esm/strategies/v2/parse.js +196 -183
- package/dist/esm/strategies/v2/parse.js.map +1 -1
- package/dist/esm/votemarket/balancer/fetchUserVlAuraClaimable.js +96 -0
- package/dist/esm/votemarket/balancer/fetchUserVlAuraClaimable.js.map +1 -0
- package/dist/esm/votemarket/fetchDirectIncentives.js +20 -0
- package/dist/esm/votemarket/fetchDirectIncentives.js.map +1 -0
- package/dist/types/bytecodes/index.d.ts +1 -0
- package/dist/types/bytecodes/index.d.ts.map +1 -1
- package/dist/types/bytecodes/votemarket/batchDirectIncentives.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/batchDirectIncentives.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/balancer.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/blackpool.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/curve.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/frax-fxs.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/fxn.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/maverick.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/pendle.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/spectra.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/yearn.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/yieldbasis.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/yieldnest.d.ts.map +1 -1
- package/dist/types/lockers/fetch/protocols/zerolend.d.ts.map +1 -1
- package/dist/types/lockers/fetch/types.d.ts +2 -0
- package/dist/types/lockers/fetch/types.d.ts.map +1 -1
- package/dist/types/prices.d.ts +17 -5
- package/dist/types/prices.d.ts.map +1 -1
- package/dist/types/strategies/balancer/fetch.d.ts +1 -2
- package/dist/types/strategies/balancer/fetch.d.ts.map +1 -1
- package/dist/types/strategies/v2/parse.d.ts +1 -51
- package/dist/types/strategies/v2/parse.d.ts.map +1 -1
- package/dist/types/votemarket/balancer/fetchUserVlAuraClaimable.d.ts +19 -0
- package/dist/types/votemarket/balancer/fetchUserVlAuraClaimable.d.ts.map +1 -0
- package/dist/types/votemarket/fetchDirectIncentives.d.ts +2 -0
- package/dist/types/votemarket/fetchDirectIncentives.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/bytecodes/index.ts +3 -0
- package/src/bytecodes/strategies/batches/batchBalancerStrats.ts +1 -1
- package/src/bytecodes/votemarket/batchDirectIncentives.ts +21 -0
- package/src/index.ts +8 -1
- package/src/lockers/fetch/protocols/balancer.ts +2 -0
- package/src/lockers/fetch/protocols/blackpool.ts +2 -0
- package/src/lockers/fetch/protocols/curve.ts +2 -0
- package/src/lockers/fetch/protocols/frax-fxs.ts +2 -0
- package/src/lockers/fetch/protocols/fxn.ts +2 -0
- package/src/lockers/fetch/protocols/maverick.ts +2 -0
- package/src/lockers/fetch/protocols/pendle.ts +2 -0
- package/src/lockers/fetch/protocols/spectra.ts +2 -0
- package/src/lockers/fetch/protocols/yearn.ts +2 -0
- package/src/lockers/fetch/protocols/yieldbasis.ts +2 -0
- package/src/lockers/fetch/protocols/yieldnest.ts +2 -0
- package/src/lockers/fetch/protocols/zerolend.ts +2 -0
- package/src/lockers/fetch/types.ts +2 -0
- package/src/prices.ts +206 -92
- package/src/strategies/balancer/fetch.ts +3 -31
- package/src/strategies/v2/parse.ts +234 -217
- package/src/votemarket/balancer/fetchUserVlAuraClaimable.ts +159 -0
- package/src/votemarket/fetchDirectIncentives.ts +23 -0
package/src/prices.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { tokenWithId } from '@stake-dao/constants'
|
|
2
|
-
import { chunk, uniq } from 'lodash-es'
|
|
1
|
+
import { RPC, tokenWithId, tokens } from '@stake-dao/constants'
|
|
2
|
+
import { chunk, uniq, uniqWith } from 'lodash-es'
|
|
3
|
+
import { decodeAbiParameters, formatUnits } from 'viem'
|
|
4
|
+
import { mainnet } from 'viem/chains'
|
|
3
5
|
import { TOKENS_CHUNK_SIZE } from './strategies/curve/fetch/curveApiData/config.js'
|
|
4
|
-
import { equalTlc } from './utils.js'
|
|
6
|
+
import { equalTlc, rpcCall } from './utils.js'
|
|
5
7
|
|
|
6
8
|
const LLAMA_API_URL = 'https://coins.llama.fi'
|
|
7
9
|
const GECKO_TERMINAL_API_URL = 'https://api.geckoterminal.com/api/v2'
|
|
@@ -12,41 +14,127 @@ export type Price = {
|
|
|
12
14
|
usdPrice: number
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
interface TokenToFetch {
|
|
18
|
+
address: string
|
|
19
|
+
symbol: string
|
|
20
|
+
extensions?: {
|
|
21
|
+
onChainPrice?: {
|
|
22
|
+
to: string
|
|
23
|
+
data: string
|
|
24
|
+
decimals: number
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface TokenToFetchWithChainId extends TokenToFetch {
|
|
30
|
+
chainId: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const FORCE_GECKO_TERMINAL_TOKENS = {
|
|
34
|
+
[mainnet.id]: [],
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ********************************************************************************
|
|
38
|
+
// ******** ********
|
|
39
|
+
// ******** DEFILLAMA CHAIN PREFIX ********
|
|
40
|
+
// ******** ********
|
|
41
|
+
// ********************************************************************************
|
|
42
|
+
|
|
15
43
|
export const getLlamaTokenPrefix = (chainId = 1): string => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
if (chainId === 1) return 'ethereum'
|
|
45
|
+
if (chainId === 10) return 'optimism'
|
|
46
|
+
if (chainId === 56) return 'bsc'
|
|
47
|
+
if (chainId === 137) return 'polygon'
|
|
48
|
+
if (chainId === 146) return 'sonic'
|
|
49
|
+
if (chainId === 252) return 'fraxtal'
|
|
50
|
+
if (chainId === 999) return 'hyperliquid'
|
|
51
|
+
if (chainId === 8453) return 'base'
|
|
52
|
+
if (chainId === 42161) return 'arbitrum'
|
|
53
|
+
if (chainId === 43114) return 'avax'
|
|
54
|
+
if (chainId === 59144) return 'linea'
|
|
55
|
+
if (chainId === 42793) return 'etherlink'
|
|
56
|
+
|
|
57
|
+
return 'ethereum'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ********************************************************************************
|
|
61
|
+
// ******** ********
|
|
62
|
+
// ******** GECKO TERMINAL CHAIN PREFIX ********
|
|
63
|
+
// ******** ********
|
|
64
|
+
// ********************************************************************************
|
|
65
|
+
|
|
66
|
+
export const getGeckoTerminalTokenPrefix = (chainId = 1): string => {
|
|
67
|
+
if (chainId === 1) return 'eth'
|
|
68
|
+
if (chainId === 10) return 'optimism'
|
|
69
|
+
if (chainId === 56) return 'bsc'
|
|
70
|
+
if (chainId === 137) return 'polygon_pos'
|
|
71
|
+
if (chainId === 146) return 'sonic'
|
|
72
|
+
if (chainId === 252) return 'fraxtal'
|
|
73
|
+
if (chainId === 999) return 'hyperliquid'
|
|
74
|
+
if (chainId === 8453) return 'base'
|
|
75
|
+
if (chainId === 42161) return 'arbitrum'
|
|
76
|
+
if (chainId === 43114) return 'avax'
|
|
77
|
+
if (chainId === 59144) return 'linea'
|
|
78
|
+
if (chainId === 42793) return 'etherlink'
|
|
79
|
+
|
|
80
|
+
return 'eth'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ********************************************************************************
|
|
84
|
+
// ******** ********
|
|
85
|
+
// ******** ON CHAIN ********
|
|
86
|
+
// ******** ********
|
|
87
|
+
// ********************************************************************************
|
|
88
|
+
|
|
89
|
+
export const getOnChainPrices = async (tokens: TokenToFetch[]): Promise<Price[]> => {
|
|
90
|
+
try {
|
|
91
|
+
const tokenWithOnChainPrice = tokens.filter((t) => t.extensions?.onChainPrice)
|
|
92
|
+
if (tokenWithOnChainPrice.length === 0) return []
|
|
93
|
+
|
|
94
|
+
const uniqCalls = uniqWith(
|
|
95
|
+
tokenWithOnChainPrice.map((t) => t.extensions!.onChainPrice!),
|
|
96
|
+
(a, b) => {
|
|
97
|
+
return equalTlc(a.to, b.to) && equalTlc(a.data, b.data) && a.decimals === b.decimals
|
|
98
|
+
},
|
|
99
|
+
)
|
|
100
|
+
const rawPrices = await rpcCall(RPC[mainnet.id], uniqCalls)
|
|
101
|
+
const prices: Price[] = []
|
|
102
|
+
|
|
103
|
+
for (let i = 0; i < rawPrices.length; i++) {
|
|
104
|
+
const call = uniqCalls[i]!
|
|
105
|
+
const tokensToPrice = tokenWithOnChainPrice.filter((t) => equalTlc(t.extensions!.onChainPrice!.to, call.to))
|
|
106
|
+
const decodedRes = decodeAbiParameters([{ type: 'int256' }], rawPrices[i].result)[0]
|
|
107
|
+
|
|
108
|
+
for (const t of tokensToPrice) {
|
|
109
|
+
prices.push({
|
|
110
|
+
symbol: t.symbol,
|
|
111
|
+
address: t.address,
|
|
112
|
+
usdPrice: Number(formatUnits(decodedRes, call.decimals)),
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return prices
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error(e)
|
|
120
|
+
return []
|
|
43
121
|
}
|
|
44
122
|
}
|
|
45
123
|
|
|
46
|
-
|
|
124
|
+
// ********************************************************************************
|
|
125
|
+
// ******** ********
|
|
126
|
+
// ******** DEFILLAMA ********
|
|
127
|
+
// ******** ********
|
|
128
|
+
// ********************************************************************************
|
|
129
|
+
|
|
130
|
+
export const getPricesFromLlama = async (
|
|
131
|
+
tokens: TokenToFetch[],
|
|
132
|
+
chainId: number = mainnet.id,
|
|
133
|
+
defaultErrorValue?: any,
|
|
134
|
+
): Promise<Price[]> => {
|
|
47
135
|
if (tokens.length > 0) {
|
|
48
136
|
try {
|
|
49
|
-
const parsedPrice:
|
|
137
|
+
const parsedPrice: Price[] = []
|
|
50
138
|
|
|
51
139
|
const prefix: string = getLlamaTokenPrefix(chainId)
|
|
52
140
|
const tokensChunks = chunk(tokens, TOKENS_CHUNK_SIZE)
|
|
@@ -77,47 +165,15 @@ export const getPricesFromLlama = async (tokens: any[], chainId = 1, defaultErro
|
|
|
77
165
|
return []
|
|
78
166
|
}
|
|
79
167
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const getGeckoTerminalTokenPrefix = (chainId = 1): string => {
|
|
88
|
-
switch (chainId) {
|
|
89
|
-
case 1:
|
|
90
|
-
return 'eth'
|
|
91
|
-
case 10:
|
|
92
|
-
return 'optimism'
|
|
93
|
-
case 56:
|
|
94
|
-
return 'bsc'
|
|
95
|
-
case 137:
|
|
96
|
-
return 'polygon_pos'
|
|
97
|
-
case 146:
|
|
98
|
-
return 'sonic'
|
|
99
|
-
case 252:
|
|
100
|
-
return 'fraxtal'
|
|
101
|
-
case 999:
|
|
102
|
-
return 'hyperliquid'
|
|
103
|
-
case 8453:
|
|
104
|
-
return 'base'
|
|
105
|
-
case 42161:
|
|
106
|
-
return 'arbitrum'
|
|
107
|
-
case 43114:
|
|
108
|
-
return 'avax'
|
|
109
|
-
case 59144:
|
|
110
|
-
return 'linea'
|
|
111
|
-
case 42793:
|
|
112
|
-
return 'etherlink'
|
|
113
|
-
default:
|
|
114
|
-
return 'eth'
|
|
115
|
-
}
|
|
116
|
-
}
|
|
168
|
+
// ********************************************************************************
|
|
169
|
+
// ******** ********
|
|
170
|
+
// ******** GECKO TERMINAL ********
|
|
171
|
+
// ******** ********
|
|
172
|
+
// ********************************************************************************
|
|
117
173
|
|
|
118
174
|
export const getPricesFromGeckoTerminal = async (
|
|
119
|
-
tokens:
|
|
120
|
-
chainId =
|
|
175
|
+
tokens: TokenToFetch[],
|
|
176
|
+
chainId: number = mainnet.id,
|
|
121
177
|
defaultErrorValue?: any,
|
|
122
178
|
): Promise<Price[]> => {
|
|
123
179
|
try {
|
|
@@ -149,41 +205,99 @@ export const getPricesFromGeckoTerminal = async (
|
|
|
149
205
|
}
|
|
150
206
|
}
|
|
151
207
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
208
|
+
// ********************************************************************************
|
|
209
|
+
// ******** ********
|
|
210
|
+
// ******** CURVE API ********
|
|
211
|
+
// ******** ********
|
|
212
|
+
// ********************************************************************************
|
|
213
|
+
|
|
214
|
+
export const getPricesFromCurve = async (chainId: number) => {
|
|
215
|
+
const prefix = getLlamaTokenPrefix(chainId)
|
|
216
|
+
const httpRequest = (await fetch(`https://prices.curve.finance/v1/usd_price/${prefix}`)).json()
|
|
217
|
+
|
|
218
|
+
return httpRequest
|
|
155
219
|
}
|
|
156
220
|
|
|
221
|
+
// ********************************************************************************
|
|
222
|
+
// ******** ********
|
|
223
|
+
// ******** GLOBAL PER CHAIN ********
|
|
224
|
+
// ******** ********
|
|
225
|
+
// ********************************************************************************
|
|
226
|
+
|
|
157
227
|
export const getPrices = async (tokens: TokenToFetch[], chainId = 1): Promise<Price[]> => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
pricesFromGecko = pricesFromGecko.concat(await getPricesFromGeckoTerminal(tokens, chainId))
|
|
161
|
-
}
|
|
228
|
+
// Fetch on chain first
|
|
229
|
+
let res: Price[] = await getOnChainPrices(tokens)
|
|
162
230
|
|
|
163
|
-
const
|
|
164
|
-
.map((t) => {
|
|
165
|
-
|
|
166
|
-
return coinPrice === 0 ? t : undefined
|
|
167
|
-
})
|
|
168
|
-
.filter(Boolean)
|
|
231
|
+
const toFetchFromGecko = tokens
|
|
232
|
+
.map((t) => ({ ...t, usdPrice: res.find((r) => equalTlc(r.address, t.address))?.usdPrice || 0 }))
|
|
233
|
+
.filter((t) => t.usdPrice === 0)
|
|
169
234
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
235
|
+
if (toFetchFromGecko.length > 0) res = res.concat(await getPricesFromGeckoTerminal(toFetchFromGecko, chainId))
|
|
236
|
+
|
|
237
|
+
const toFetchFromLlama = tokens
|
|
238
|
+
.map((t) => ({ ...t, usdPrice: res.find((r) => equalTlc(r.address, t.address))?.usdPrice || 0 }))
|
|
239
|
+
.filter((t) => t.usdPrice === 0)
|
|
174
240
|
|
|
175
|
-
|
|
241
|
+
if (toFetchFromLlama.length > 0) res = res.concat(await getPricesFromLlama(toFetchFromLlama, chainId))
|
|
176
242
|
|
|
177
243
|
// Use WBTC price for WBTC18
|
|
178
|
-
const wbtc =
|
|
244
|
+
const wbtc = res.find((p) => equalTlc(p.address, tokenWithId('wbtc', 1)?.address!))
|
|
179
245
|
if (wbtc) {
|
|
180
246
|
const wbtc18 = tokenWithId('wbtc18', 1)!
|
|
181
|
-
|
|
247
|
+
res.push({ symbol: wbtc18.symbol, address: wbtc18.address, usdPrice: wbtc.usdPrice })
|
|
182
248
|
}
|
|
183
249
|
|
|
184
|
-
return
|
|
250
|
+
return res
|
|
185
251
|
}
|
|
186
252
|
|
|
253
|
+
// ********************************************************************************
|
|
254
|
+
// ******** ********
|
|
255
|
+
// ******** GLOBAL ********
|
|
256
|
+
// ******** ********
|
|
257
|
+
// ********************************************************************************
|
|
258
|
+
|
|
259
|
+
export const fetchPrices = async (tokensToFetch: TokenToFetchWithChainId[] = tokens) => {
|
|
260
|
+
// Fetch on chain first
|
|
261
|
+
let prices: Price[] = await getOnChainPrices(tokensToFetch)
|
|
262
|
+
|
|
263
|
+
// Fetch from missing tokens from llama next
|
|
264
|
+
const pricesToFetchFromLlama = tokensToFetch
|
|
265
|
+
.map((t) => ({ ...t, usdPrice: prices.find((pl) => equalTlc(pl.address, t.address))?.usdPrice || 0 }))
|
|
266
|
+
.filter((t) => t.usdPrice === 0)
|
|
267
|
+
|
|
268
|
+
if (pricesToFetchFromLlama.length > 0) {
|
|
269
|
+
const llamaChunkedTokens = chunk(pricesToFetchFromLlama, 130)
|
|
270
|
+
|
|
271
|
+
for (const tokenChunk of llamaChunkedTokens) {
|
|
272
|
+
const httpArgs = tokenChunk.map((t) => `${getLlamaTokenPrefix(t.chainId)}:${t.address}`).toString()
|
|
273
|
+
const httpRequest = await fetch(`${LLAMA_API_URL}/prices/current/${httpArgs}`).then((res) => res.json())
|
|
274
|
+
const coinsData = httpRequest.coins
|
|
275
|
+
|
|
276
|
+
prices = prices.concat(
|
|
277
|
+
tokenChunk.map((t) => ({
|
|
278
|
+
symbol: t.symbol,
|
|
279
|
+
address: t.address,
|
|
280
|
+
usdPrice: coinsData[`${getLlamaTokenPrefix(t.chainId)}:${t.address}`]?.price || 0,
|
|
281
|
+
})),
|
|
282
|
+
)
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const forcePrices = await Promise.all(
|
|
287
|
+
Object.keys(FORCE_GECKO_TERMINAL_TOKENS).map((chainId) =>
|
|
288
|
+
getPricesFromGeckoTerminal(FORCE_GECKO_TERMINAL_TOKENS[chainId], Number(chainId), []),
|
|
289
|
+
),
|
|
290
|
+
).then((res) => res.flat())
|
|
291
|
+
|
|
292
|
+
return [...forcePrices, ...prices]
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ********************************************************************************
|
|
296
|
+
// ******** ********
|
|
297
|
+
// ******** UTILS ********
|
|
298
|
+
// ******** ********
|
|
299
|
+
// ********************************************************************************
|
|
300
|
+
|
|
187
301
|
export const mergePrices = async (basePrices: Price[], tokens: TokenToFetch[], chainId = 1): Promise<Price[]> => {
|
|
188
302
|
let fetchedPrices: Price[] = []
|
|
189
303
|
if (tokens.length > 0) {
|
|
@@ -14,11 +14,9 @@ import {
|
|
|
14
14
|
tokenWithId,
|
|
15
15
|
} from '@stake-dao/constants'
|
|
16
16
|
import { batchBalancerStrats } from '../../bytecodes/index.js'
|
|
17
|
-
import { concatBytecode, getBoost,
|
|
17
|
+
import { concatBytecode, getBoost, getPricesFromLlama, getSdtApr } from '../../index.js'
|
|
18
18
|
import { equalTlc, graphql } from '../../utils.js'
|
|
19
|
-
import { FACTORY_EVENT_TOPIC } from '../curve/endpoints.js'
|
|
20
19
|
import type { BalancerGlobalData, RewardsData, Strategy, StrategyData, ValidChainId } from '../types.js'
|
|
21
|
-
import decodeEtherscanFactoryEvent from '../utils/decodeEtherscanFactoryEvent.js'
|
|
22
20
|
import { getAprBreakdown } from '../utils/getAprBreakdown.js'
|
|
23
21
|
import getTokenTypes from '../utils/getTokenTypes.js'
|
|
24
22
|
import { buildBalancerStrategies } from './build.js'
|
|
@@ -26,43 +24,17 @@ import { BALANCER_POOLS_DATA_QUERY, BALANCER_SUBGRAPH_URL } from './endpoints.js
|
|
|
26
24
|
|
|
27
25
|
interface TFetchBalancer {
|
|
28
26
|
provider: any
|
|
29
|
-
explorerApiKey: string
|
|
30
27
|
chainId: ValidChainId
|
|
31
28
|
sdtEmissionData: any
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
export const fetchBalancer = async ({
|
|
35
|
-
provider,
|
|
36
|
-
explorerApiKey,
|
|
37
|
-
chainId,
|
|
38
|
-
sdtEmissionData,
|
|
39
|
-
}: TFetchBalancer): Promise<StrategyData> => {
|
|
31
|
+
export const fetchBalancer = async ({ provider, chainId, sdtEmissionData }: TFetchBalancer): Promise<StrategyData> => {
|
|
40
32
|
const currentBlockNumber = Number(await provider.getBlockNumber())
|
|
41
|
-
const fromBlock = balancerStrats.meta.lastSyncBlock[chainId]! + 1
|
|
42
33
|
const toBlock = Number(await provider.getBlockNumber())
|
|
43
34
|
|
|
44
|
-
const httpCalls = [
|
|
45
|
-
// Etherscan Events
|
|
46
|
-
getLogsFromEtherscan({
|
|
47
|
-
chainId,
|
|
48
|
-
address: contracts.balancerVaultFactory![1]!,
|
|
49
|
-
apikey: explorerApiKey,
|
|
50
|
-
extraQueryParams: {
|
|
51
|
-
topic0: FACTORY_EVENT_TOPIC,
|
|
52
|
-
fromBlock: `${fromBlock}`,
|
|
53
|
-
toBlock: `${toBlock}`,
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
const httpResponses = (await Promise.allSettled(httpCalls)).map((result) =>
|
|
59
|
-
result.status === 'fulfilled' ? result.value : [],
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
const newVaultsAndLp = decodeEtherscanFactoryEvent(httpResponses[0])
|
|
63
35
|
const vaultsAndLp = balancerStrats.strats[chainId] || []
|
|
64
36
|
|
|
65
|
-
const strats: any[] = await buildBalancerStrategies(provider, vaultsAndLp
|
|
37
|
+
const strats: any[] = await buildBalancerStrategies(provider, vaultsAndLp, chainId)
|
|
66
38
|
|
|
67
39
|
const poolIds = strats.map((s) => s.key)
|
|
68
40
|
const tokensToFetch: any = [tokenWithId('bal'), tokenWithId('sdt')]
|