Skip to content

Commit a9eb743

Browse files
committed
add height checks for base price routing
1 parent 215af32 commit a9eb743

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ const createChainlinkPriceFeed = (address: string, decimals: bigint) => {
1515
}
1616
}
1717

18-
const chainlinkPriceFeeds: Record<string, (ctx: Context, height: number) => Promise<bigint>> = {
19-
ETH_USD: createChainlinkPriceFeed('0x71041dddad3595f9ced3dccfbe3d1f4b0a16bb70', 8n),
20-
superOETHb_USD: createChainlinkPriceFeed('0x71041dddad3595f9ced3dccfbe3d1f4b0a16bb70', 8n),
21-
superOETHb_ETH: createChainlinkPriceFeed('0x39C6E14CdE46D4FFD9F04Ff159e7ce8eC20E10B4', 18n),
22-
AERO_USD: createChainlinkPriceFeed('0x4EC5970fC728C5f65ba413992CD5fF6FD70fcfF0', 8n),
23-
}
18+
const chainlinkPriceFeeds: Record<string, { height: number; get: (ctx: Context, height: number) => Promise<bigint> }> =
19+
{
20+
ETH_USD: { height: 2092862, get: createChainlinkPriceFeed('0x71041dddad3595f9ced3dccfbe3d1f4b0a16bb70', 8n) },
21+
superOETHb_USD: {
22+
height: 2092862,
23+
get: createChainlinkPriceFeed('0x71041dddad3595f9ced3dccfbe3d1f4b0a16bb70', 8n),
24+
},
25+
superOETHb_ETH: {
26+
height: 27814188,
27+
get: createChainlinkPriceFeed('0x39C6E14CdE46D4FFD9F04Ff159e7ce8eC20E10B4', 18n),
28+
},
29+
AERO_USD: { height: 12730314, get: createChainlinkPriceFeed('0x4EC5970fC728C5f65ba413992CD5fF6FD70fcfF0', 8n) },
30+
}
2431

2532
const createAMMPriceFeed = (pool: PoolDefinition) => async (ctx: Context, height: number) => {
2633
if (pool.from > height) return 0n
@@ -57,18 +64,18 @@ const alternativePriceFeeds: Record<string, (ctx: Context, height: number) => Pr
5764
OGN_superOETHb: createAMMPriceFeed(baseAddresses.aerodrome.pools['vAMM-OGN/superOETHb']),
5865
OGN_USD: async (ctx: Context, height: number) => {
5966
const rate1 = await alternativePriceFeeds['OGN_superOETHb'](ctx, height)
60-
const rate2 = await chainlinkPriceFeeds['superOETHb_USD'](ctx, height)
67+
const rate2 = await chainlinkPriceFeeds['superOETHb_USD'].get(ctx, height)
6168
return (rate1 * rate2) / ONE_ETH
6269
},
6370
AERO_ETH: async (ctx: Context, height: number) => {
64-
const aeroUsd = await chainlinkPriceFeeds['AERO_USD'](ctx, height)
65-
const ethUsd = await chainlinkPriceFeeds['ETH_USD'](ctx, height)
71+
const aeroUsd = await chainlinkPriceFeeds['AERO_USD'].get(ctx, height)
72+
const ethUsd = await chainlinkPriceFeeds['ETH_USD'].get(ctx, height)
6673
if (ethUsd === 0n) return 0n
6774
return (aeroUsd * ONE_ETH) / ethUsd
6875
},
6976
AERO_WETH: async (ctx: Context, height: number) => {
70-
const aeroUsd = await chainlinkPriceFeeds['AERO_USD'](ctx, height)
71-
const ethUsd = await chainlinkPriceFeeds['ETH_USD'](ctx, height)
77+
const aeroUsd = await chainlinkPriceFeeds['AERO_USD'].get(ctx, height)
78+
const ethUsd = await chainlinkPriceFeeds['ETH_USD'].get(ctx, height)
7279
if (ethUsd === 0n) return 0n
7380
return (aeroUsd * ONE_ETH) / ethUsd
7481
},
@@ -86,8 +93,8 @@ export const getBasePrice = async (ctx: Context, height: number, base: BaseCurre
8693
quote = translateBaseSymbol(quote)
8794
if (base === quote) return [1_000_000_000_000_000_000n, 18] as const
8895
const feed = chainlinkPriceFeeds[`${base}_${quote}`]
89-
if (feed) {
90-
return [await feed(ctx, height), 18] as const
96+
if (feed && feed.height <= height) {
97+
return [await feed.get(ctx, height), 18] as const
9198
}
9299
const alternateFeed = alternativePriceFeeds[`${base}_${quote}`]
93100
if (alternateFeed) {

0 commit comments

Comments
 (0)