@@ -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
5968const 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
6577const 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' ,
0 commit comments