Skip to content

Commit 38c460c

Browse files
committed
more intelligent curve OUSD/USDC amo tracking
1 parent 11b7c0a commit 38c460c

5 files changed

Lines changed: 51 additions & 8 deletions

File tree

src/ousd/processors/strategies/const.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { USDS_ADDRESS } from '@utils/addresses'
1+
import { OUSD_ADDRESS, USDS_ADDRESS } from '@utils/addresses'
22

33
export const DAI = {
44
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
@@ -16,3 +16,7 @@ export const USDS = {
1616
address: USDS_ADDRESS,
1717
decimals: 18,
1818
}
19+
export const OUSD = {
20+
address: OUSD_ADDRESS,
21+
decimals: 18,
22+
}

src/ousd/processors/strategies/strategies.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as mainnetAddresses from '@utils/addresses'
66
import { USDS_ADDRESS } from '@utils/addresses'
77

88
import { aaveStrategy } from './aave-strategy'
9-
import { USDC, USDT } from './const'
9+
import { OUSD, USDC, USDT } from './const'
1010
import { convexMetaStrategy } from './convex-meta-strategy'
1111
import { fluxStrategy } from './flux-strategy'
1212
import { makerDsrStrategy } from './maker-dsr-strategy'
@@ -62,12 +62,16 @@ export const ousdStrategies: readonly IStrategyData[] = [
6262
chainId: 1,
6363
from: 22224255,
6464
oTokenAddress: mainnetAddresses.OUSD_ADDRESS,
65-
kind: 'Generic',
65+
kind: 'CurveAMO',
6666
name: 'OUSD Curve AMO',
6767
contractName: 'CurveAMOStrategy',
6868
address: mainnetAddresses.strategies.ousd.CurveUSDCAMOStrategy,
6969
base: { address: mainnetCurrencies.USD, decimals: 18 },
70-
assets: [USDC],
70+
assets: [OUSD, USDC],
71+
curvePoolInfo: {
72+
poolAddress: '0x6d18e1a7faeb1f0467a77c0d293872ab685426dc',
73+
gaugeAddress: '0x1ef8b6ea6434e722c916314caf8bf16c81caf2f9',
74+
},
7175
earnings: { passiveByDepositWithdrawal: true, rewardTokenCollected: true },
7276
},
7377
{

src/templates/strategy/strategy-curve-amo.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ const getCurveAMOStrategyHoldings = async (
5858
}
5959

6060
export 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+
72107
export 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()

src/templates/strategy/strategy-earnings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const depositWithdrawalFilter = (strategyData: IStrategyData) =>
4444

4545
const curvePoolFilter = (strategyData: IStrategyData) =>
4646
logFilter({
47-
address: [strategyData.curvePoolInfo!.rewardsPoolAddress],
47+
address: [strategyData.curvePoolInfo!.rewardsPoolAddress!],
4848
topic0: [baseRewardPool.events.Staked.topic, baseRewardPool.events.Withdrawn.topic],
4949
topic1: [strategyData.address],
5050
range: { from: strategyData.from },
@@ -124,7 +124,7 @@ export const setupStrategyEarnings = (processor: EvmBatchProcessor, strategyData
124124

125125
// Detect Staked/Withdrawn events
126126
// The curve incident caused us to fully withdraw from our pool and these logs contain that.
127-
if (strategyData.kind === 'CurveAMO') {
127+
if (strategyData.kind === 'CurveAMO' && strategyData.curvePoolInfo?.rewardsPoolAddress) {
128128
balanceUpdateFilters.push(curvePoolFilter(strategyData))
129129
}
130130
}

src/templates/strategy/strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type IBalancerPoolInfo = {
2020
export type ICurveAMOInfo = {
2121
poolAddress: string
2222
gaugeAddress?: string
23-
rewardsPoolAddress: string
23+
rewardsPoolAddress?: string
2424
}
2525

2626
export type IStrategyData = {

0 commit comments

Comments
 (0)