@@ -58,6 +58,10 @@ const getCurveAMOStrategyHoldings = async (
5858}
5959
6060export const getStrategyBalances = async ( ctx : Context , block : { height : number } , strategyData : IStrategyData ) => {
61+ // Use gauge-based balance calculation if gaugeAddress is provided
62+ if ( strategyData . curvePoolInfo ?. gaugeAddress ) {
63+ return getCurveGaugeBalances ( ctx , block , strategyData )
64+ }
6165 return await Promise . all (
6266 strategyData . assets
6367 . filter ( ( asset ) => asset . checkBalance !== false )
@@ -69,6 +73,37 @@ export const getStrategyBalances = async (ctx: Context, block: { height: number
6973 )
7074}
7175
76+ export const getCurveGaugeBalances = async (
77+ ctx : Context ,
78+ block : { height : number } ,
79+ strategyData : IStrategyData ,
80+ ) => {
81+ const { address, curvePoolInfo } = strategyData
82+ const { poolAddress, gaugeAddress } = curvePoolInfo !
83+
84+ const pool = new curvePool . Contract ( ctx , block , poolAddress )
85+ const gauge = new erc20 . Contract ( ctx , block , gaugeAddress ! )
86+
87+ // Get pool state in parallel - use balances(i) instead of get_balances() for compatibility
88+ const [ poolBalance0 , poolBalance1 , totalSupply , strategyLpBalance , coin0 , coin1 ] = await Promise . all ( [
89+ pool . balances ( 0n ) ,
90+ pool . balances ( 1n ) ,
91+ pool . totalSupply ( ) ,
92+ gauge . balanceOf ( address ) ,
93+ pool . coins ( 0n ) ,
94+ pool . coins ( 1n ) ,
95+ ] )
96+
97+ // Calculate strategy's share of each coin
98+ const eth1 = 1000000000000000000n
99+ const share = totalSupply > 0n ? ( strategyLpBalance * eth1 ) / totalSupply : 0n
100+
101+ return [
102+ { address, asset : coin0 . toLowerCase ( ) , balance : ( poolBalance0 * share ) / eth1 } ,
103+ { address, asset : coin1 . toLowerCase ( ) , balance : ( poolBalance1 * share ) / eth1 } ,
104+ ]
105+ }
106+
72107export const getConvexEthMetaStrategyBalances = async (
73108 ctx : Context ,
74109 block : { height : number } ,
@@ -78,7 +113,7 @@ export const getConvexEthMetaStrategyBalances = async (
78113 const { poolAddress, rewardsPoolAddress } = curvePoolInfo !
79114
80115 const pool = new curvePool . Contract ( ctx , block , poolAddress )
81- const rewardsPool = new erc20 . Contract ( ctx , block , rewardsPoolAddress )
116+ const rewardsPool = new erc20 . Contract ( ctx , block , rewardsPoolAddress ! )
82117 const strategy = new abstractStrategyAbi . Contract ( ctx , block , address )
83118
84119 const lpPrice = await pool . get_virtual_price ( )
0 commit comments