Skip to content

Commit ce36d65

Browse files
committed
add oeth_eth chainlink price feed
1 parent 1102855 commit ce36d65

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/shared/post-processors/exchange-rates/price-routing-mainnet.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,44 @@ const createChainlinkPriceFeed = (address: string, decimals: bigint) => {
3434

3535
// 0xCd627aA160A6fA45Eb793D19Ef54f5062F20f33f
3636

37-
const chainlinkPriceFeeds: Record<string, (ctx: Context, height: number) => Promise<bigint>> = {
38-
CRV_USD: createChainlinkPriceFeed('0xcd627aa160a6fa45eb793d19ef54f5062f20f33f', 8n),
39-
CRV_USDC: createChainlinkPriceFeed('0xcd627aa160a6fa45eb793d19ef54f5062f20f33f', 8n),
37+
const chainlinkPriceFeeds: Record<
38+
string,
39+
undefined | { height: number; get: (ctx: Context, height: number) => Promise<bigint> }
40+
> = {
41+
CRV_USD: { height: 12162244, get: createChainlinkPriceFeed('0xcd627aa160a6fa45eb793d19ef54f5062f20f33f', 8n) },
42+
CRV_USDC: { height: 12162244, get: createChainlinkPriceFeed('0xcd627aa160a6fa45eb793d19ef54f5062f20f33f', 8n) },
43+
OETH_ETH: { height: 19384550, get: createChainlinkPriceFeed('0x703118c4cbcccbf2ab31913e0f8075fbbb15f563', 18n) },
4044
}
4145

42-
export const getMainnetPrice = async (ctx: Context, height: number, base: MainnetCurrency, quote: MainnetCurrency) => {
46+
export const getMainnetPrice = async (
47+
ctx: Context,
48+
height: number,
49+
base: MainnetCurrency,
50+
quote: MainnetCurrency,
51+
): Promise<[bigint, number]> => {
4352
base = translateMainnetSymbol(base)
4453
quote = translateMainnetSymbol(quote)
4554

4655
const feed = chainlinkPriceFeeds[`${base}_${quote}`]
47-
if (feed) {
48-
return [await feed(ctx, height), 18] as const
56+
if (feed && feed.height <= height) {
57+
return [await feed.get(ctx, height), 18]
4958
}
5059

5160
const priceEntry = priceMap[`${base}_${quote}`]
5261
if (priceEntry) {
5362
const [getPrice, decimals] = priceEntry
54-
return [await getPrice(ctx, height), decimals] as const
63+
return [await getPrice(ctx, height), decimals]
5564
}
5665
throw new Error(`No price for ${base}_${quote}`)
5766
}
5867

5968
const getOETHETHPrice = async (ctx: Context, height: number) => {
6069
if (height < 17230232) return 10n ** 18n
61-
const contract = new curveLpToken.Contract(ctx, { height }, CURVE_ETH_OETH_POOL_ADDRESS)
62-
return await contract.get_dy(0n, 1n, 1000000000000000000n)
70+
if (height < 19384550) {
71+
const contract = new curveLpToken.Contract(ctx, { height }, CURVE_ETH_OETH_POOL_ADDRESS)
72+
return await contract.get_dy(0n, 1n, 1000000000000000000n)
73+
}
74+
return chainlinkPriceFeeds['OETH_ETH']!.get(ctx, height)
6375
}
6476

6577
const getETHOETHPrice = async (ctx: Context, height: number) => {
@@ -234,6 +246,16 @@ export const priceMap: Partial<
234246
...twoWay('USDT', 'USD', (ctx, height) => getChainlinkPrice(ctx, height, 'USDT', 'USD'), 8),
235247
...twoWay('USDS', 'USD', (ctx, height) => getChainlinkPrice(ctx, height, 'USDS', 'USD'), 8),
236248
...twoWay('ETH', 'USDS', (ctx, height) => getChainlinkPrice(ctx, height, 'ETH', 'USDS'), 8),
249+
...twoWay('BAL', 'USD', (ctx, height) => getChainlinkPrice(ctx, height, 'BAL', 'USD'), 8),
250+
...derived(
251+
'BAL',
252+
'WETH',
253+
[
254+
{ base: 'BAL', quote: 'USD' },
255+
{ base: 'USD', quote: 'ETH' },
256+
],
257+
18,
258+
),
237259
...derived(
238260
'DAI',
239261
'ETH',

src/templates/strategy/strategy-earnings.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,14 @@ export const processStrategyEarnings = async (
257257
data.rewardToken as CurrencyAddress,
258258
saveAsAsset ?? (strategyData.assets[0].address as CurrencyAddress),
259259
data.amount,
260-
),
260+
).catch((e) => {
261+
// Ignore earnings errors for OETH which happened before the LST switch.
262+
// Why?
263+
// - We've changed some processing which picks up more earnings from the past but they do not matter anymore.
264+
// - Avoid having to hook up all the rates.
265+
if (strategyData.oTokenAddress === OETH_ADDRESS && block.header.height < 21175501) return 0n
266+
throw e
267+
}),
261268
})
262269
}
263270
}

0 commit comments

Comments
 (0)