@@ -17,12 +17,9 @@ import {
1717 beefyClmVaultsMulticallBytecode ,
1818} from './abis/beefy-clm-vaults-multicall'
1919import { 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 > >
2623
2724// Fetched addresses from https://github.com/beefyfinance/beefy-v2/blob/main/src/config/config.tsx
2825const BEEFY_MULTICALL_ADDRESS : {
@@ -46,37 +43,40 @@ const BEEFY_MULTICALL_ADDRESS: {
4643const beefyAppTokenDefinition = (
4744 networkId : NetworkId ,
4845 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+ }
6169 } ,
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+ }
8080
8181// CLM = Cowcentrated Liquidity Manager: https://docs.beefy.finance/beefy-products/clm
8282interface ClmVaultBalanceInfo {
@@ -91,6 +91,7 @@ const beefyConcentratedContractDefinition = (
9191 vault : BaseBeefyVault ,
9292 balanceInfo : ClmVaultBalanceInfo | undefined ,
9393 description : string ,
94+ prices : BeefyPrices ,
9495) : ContractPositionDefinition | null => {
9596 if ( ! balanceInfo ) {
9697 return null
@@ -100,10 +101,17 @@ const beefyConcentratedContractDefinition = (
100101 type : 'contract-position-definition' ,
101102 networkId,
102103 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+ } ) ,
107115 displayProps : ( ) => {
108116 return {
109117 title : vault . name + ( vault . status === 'eol' ? ' (Retired)' : '' ) ,
@@ -140,6 +148,7 @@ const beefyBaseVaultsPositions = async (
140148 address : Address ,
141149 vaults : BaseBeefyVault [ ] ,
142150 multicallAddress : Address ,
151+ prices : BeefyPrices ,
143152) => {
144153 const client = getClient ( networkId )
145154
@@ -171,8 +180,6 @@ const beefyBaseVaultsPositions = async (
171180 return [ ]
172181 }
173182
174- const prices = await getBeefyLpsPrices ( )
175-
176183 const clmVaults = userVaults . filter ( ( vault ) => vault . type === 'cowcentrated' )
177184 const info =
178185 clmVaults . length === 0
@@ -195,6 +202,7 @@ const beefyBaseVaultsPositions = async (
195202 i . token1 === vault . depositTokenAddresses [ 1 ] ,
196203 ) ,
197204 'CLM Vault' ,
205+ prices ,
198206 )
199207 : beefyAppTokenDefinition ( networkId , vault , prices ) ,
200208 )
@@ -207,6 +215,7 @@ const beefyGovVaultsPositions = async (
207215 vaults : BaseBeefyVault [ ] ,
208216 govVaults : GovVault [ ] ,
209217 multicallAddress : Address ,
218+ prices : BeefyPrices ,
210219) => {
211220 const client = getClient ( networkId )
212221
@@ -278,6 +287,7 @@ const beefyGovVaultsPositions = async (
278287 i . token1 === vault ! . depositTokenAddresses [ 1 ] ,
279288 ) ,
280289 'CLM Pool' ,
290+ prices ,
281291 ) ,
282292 )
283293 . filter ( ( position ) : position is ContractPositionDefinition => ! ! position )
@@ -297,20 +307,26 @@ const hook: PositionsHook = {
297307 return [ ]
298308 }
299309
300- const { vaults, govVaults } = await getBeefyVaults ( networkId )
310+ const [ { vaults, govVaults } , prices ] = await Promise . all ( [
311+ getBeefyVaults ( networkId ) ,
312+ getBeefyPrices ( networkId ) ,
313+ ] )
314+
301315 return [
302316 ...( await beefyBaseVaultsPositions (
303317 networkId ,
304318 address as Address ,
305319 vaults ,
306320 multicallAddress ,
321+ prices ,
307322 ) ) ,
308323 ...( await beefyGovVaultsPositions (
309324 networkId ,
310325 address as Address ,
311326 vaults ,
312327 govVaults ,
313328 multicallAddress ,
329+ prices ,
314330 ) ) ,
315331 ]
316332 } ,
0 commit comments