@@ -17,12 +17,9 @@ import {
17
17
beefyClmVaultsMulticallBytecode ,
18
18
} from './abis/beefy-clm-vaults-multicall'
19
19
import { beefyV2AppMulticallAbi } from './abis/beefy-v2-app-multicall'
20
- import {
21
- BaseBeefyVault ,
22
- GovVault ,
23
- getBeefyLpsPrices ,
24
- getBeefyVaults ,
25
- } from './api'
20
+ import { BaseBeefyVault , GovVault , getBeefyPrices , getBeefyVaults } from './api'
21
+
22
+ type BeefyPrices = Awaited < ReturnType < typeof getBeefyPrices > >
26
23
27
24
// Fetched addresses from https://github.com/beefyfinance/beefy-v2/blob/main/src/config/config.tsx
28
25
const BEEFY_MULTICALL_ADDRESS : {
@@ -46,37 +43,40 @@ const BEEFY_MULTICALL_ADDRESS: {
46
43
const beefyAppTokenDefinition = (
47
44
networkId : NetworkId ,
48
45
vault : BaseBeefyVault ,
49
- prices : Record < string , number > ,
50
- ) : AppTokenPositionDefinition => ( {
51
- type : 'app-token-definition' ,
52
- networkId,
53
- address : vault . earnedTokenAddress . toLowerCase ( ) ,
54
- tokens : [
55
- {
56
- address : vault . tokenAddress . toLowerCase ( ) ,
57
- networkId,
58
- fallbackPriceUsd : prices [ vault . id ]
59
- ? toSerializedDecimalNumber ( prices [ vault . id ] )
60
- : undefined ,
46
+ prices : BeefyPrices ,
47
+ ) : AppTokenPositionDefinition => {
48
+ const priceUsd = prices [ vault . id ]
49
+ return {
50
+ type : 'app-token-definition' ,
51
+ networkId,
52
+ address : vault . earnedTokenAddress . toLowerCase ( ) ,
53
+ tokens : [
54
+ {
55
+ address : vault . tokenAddress . toLowerCase ( ) ,
56
+ networkId,
57
+ fallbackPriceUsd : priceUsd
58
+ ? toSerializedDecimalNumber ( priceUsd )
59
+ : undefined ,
60
+ } ,
61
+ ] ,
62
+ displayProps : ( ) => {
63
+ return {
64
+ title : vault . name + ( vault . status === 'eol' ? ' (Retired)' : '' ) ,
65
+ description : 'Vault' ,
66
+ imageUrl :
67
+ 'https://raw.githubusercontent.com/valora-inc/dapp-list/main/assets/beefy.png' ,
68
+ }
61
69
} ,
62
- ] ,
63
- displayProps : ( ) => {
64
- return {
65
- title : vault . name + ( vault . status === 'eol' ? ' (Retired)' : '' ) ,
66
- description : 'Vault' ,
67
- imageUrl :
68
- 'https://raw.githubusercontent.com/valora-inc/dapp-list/main/assets/beefy.png' ,
69
- }
70
- } ,
71
- pricePerShare : async ( { tokensByTokenId } ) => {
72
- const tokenId = getTokenId ( {
73
- address : vault . tokenAddress ,
74
- networkId,
75
- } )
76
- const { decimals } = tokensByTokenId [ tokenId ]
77
- return [ toDecimalNumber ( BigInt ( vault . pricePerFullShare ) , decimals ) ]
78
- } ,
79
- } )
70
+ pricePerShare : async ( { tokensByTokenId } ) => {
71
+ const tokenId = getTokenId ( {
72
+ address : vault . tokenAddress ,
73
+ networkId,
74
+ } )
75
+ const { decimals } = tokensByTokenId [ tokenId ]
76
+ return [ toDecimalNumber ( BigInt ( vault . pricePerFullShare ) , decimals ) ]
77
+ } ,
78
+ }
79
+ }
80
80
81
81
// CLM = Cowcentrated Liquidity Manager: https://docs.beefy.finance/beefy-products/clm
82
82
interface ClmVaultBalanceInfo {
@@ -91,6 +91,7 @@ const beefyConcentratedContractDefinition = (
91
91
vault : BaseBeefyVault ,
92
92
balanceInfo : ClmVaultBalanceInfo | undefined ,
93
93
description : string ,
94
+ prices : BeefyPrices ,
94
95
) : ContractPositionDefinition | null => {
95
96
if ( ! balanceInfo ) {
96
97
return null
@@ -100,10 +101,17 @@ const beefyConcentratedContractDefinition = (
100
101
type : 'contract-position-definition' ,
101
102
networkId,
102
103
address : vault . earnedTokenAddress . toLowerCase ( ) ,
103
- tokens : vault . depositTokenAddresses . map ( ( address ) => ( {
104
- address : address . toLowerCase ( ) ,
105
- networkId,
106
- } ) ) ,
104
+ tokens : vault . depositTokenAddresses . map ( ( address ) => {
105
+ const addressLower = address . toLowerCase ( )
106
+ const priceUsd = prices [ addressLower ]
107
+ return {
108
+ address : addressLower ,
109
+ networkId,
110
+ fallbackPriceUsd : priceUsd
111
+ ? toSerializedDecimalNumber ( priceUsd )
112
+ : undefined ,
113
+ }
114
+ } ) ,
107
115
displayProps : ( ) => {
108
116
return {
109
117
title : vault . name + ( vault . status === 'eol' ? ' (Retired)' : '' ) ,
@@ -140,6 +148,7 @@ const beefyBaseVaultsPositions = async (
140
148
address : Address ,
141
149
vaults : BaseBeefyVault [ ] ,
142
150
multicallAddress : Address ,
151
+ prices : BeefyPrices ,
143
152
) => {
144
153
const client = getClient ( networkId )
145
154
@@ -171,8 +180,6 @@ const beefyBaseVaultsPositions = async (
171
180
return [ ]
172
181
}
173
182
174
- const prices = await getBeefyLpsPrices ( )
175
-
176
183
const clmVaults = userVaults . filter ( ( vault ) => vault . type === 'cowcentrated' )
177
184
const info =
178
185
clmVaults . length === 0
@@ -195,6 +202,7 @@ const beefyBaseVaultsPositions = async (
195
202
i . token1 === vault . depositTokenAddresses [ 1 ] ,
196
203
) ,
197
204
'CLM Vault' ,
205
+ prices ,
198
206
)
199
207
: beefyAppTokenDefinition ( networkId , vault , prices ) ,
200
208
)
@@ -207,6 +215,7 @@ const beefyGovVaultsPositions = async (
207
215
vaults : BaseBeefyVault [ ] ,
208
216
govVaults : GovVault [ ] ,
209
217
multicallAddress : Address ,
218
+ prices : BeefyPrices ,
210
219
) => {
211
220
const client = getClient ( networkId )
212
221
@@ -278,6 +287,7 @@ const beefyGovVaultsPositions = async (
278
287
i . token1 === vault ! . depositTokenAddresses [ 1 ] ,
279
288
) ,
280
289
'CLM Pool' ,
290
+ prices ,
281
291
) ,
282
292
)
283
293
. filter ( ( position ) : position is ContractPositionDefinition => ! ! position )
@@ -297,20 +307,26 @@ const hook: PositionsHook = {
297
307
return [ ]
298
308
}
299
309
300
- const { vaults, govVaults } = await getBeefyVaults ( networkId )
310
+ const [ { vaults, govVaults } , prices ] = await Promise . all ( [
311
+ getBeefyVaults ( networkId ) ,
312
+ getBeefyPrices ( networkId ) ,
313
+ ] )
314
+
301
315
return [
302
316
...( await beefyBaseVaultsPositions (
303
317
networkId ,
304
318
address as Address ,
305
319
vaults ,
306
320
multicallAddress ,
321
+ prices ,
307
322
) ) ,
308
323
...( await beefyGovVaultsPositions (
309
324
networkId ,
310
325
address as Address ,
311
326
vaults ,
312
327
govVaults ,
313
328
multicallAddress ,
329
+ prices ,
314
330
) ) ,
315
331
]
316
332
} ,
0 commit comments