1- import * as eacAggregatorProxy from '@abi/eac-aggregator-proxy'
2- import { Block , Context , invertMap } from '@originprotocol/squid-utils'
3- import { sonicAddresses } from '@utils/addresses-sonic'
1+ import * as eacAggregatorProxy from '@abi/eac-aggregator-proxy' ;
2+ import { Block , Context , invertMap } from '@originprotocol/squid-utils' ;
3+ import { sonicAddresses } from '@utils/addresses-sonic' ;
4+
45
56const PRECISION_DECIMALS = 18n
67const PRECISION = 10n ** PRECISION_DECIMALS
78
8- const createChainlinkPriceFeed = ( address : string , decimals : bigint , from : number ) => {
9+ const createChainlinkPriceFeed = ( address : string , decimals : bigint , from : number , softFail : boolean = false ) => {
910 return async ( ctx : Context , height : number ) => {
1011 if ( height < from ) return 0n
1112 try {
1213 const feedContract = new eacAggregatorProxy . Contract ( ctx , { height } , address )
1314 const result = await feedContract . latestAnswer ( )
1415 return result * 10n ** ( PRECISION_DECIMALS - decimals )
1516 } catch ( err ) {
16- console . log ( 'Failed to get price for: ' , address , height )
17- throw err
17+ if ( softFail ) {
18+ return 0n
19+ } else {
20+ throw err
21+ }
1822 }
1923 }
2024}
@@ -39,7 +43,7 @@ const chainlinkPriceFeeds: Record<string, { height: number; get: (ctx: Context,
3943 } ,
4044 OS_S : {
4145 height : 21623950 ,
42- get : createChainlinkPriceFeed ( '0x30caC44b395eB969C9CA0d44dF39e6E0aE8f8D94' , 18n , 4189824 ) ,
46+ get : createChainlinkPriceFeed ( '0x30caC44b395eB969C9CA0d44dF39e6E0aE8f8D94' , 18n , 4189824 , true ) ,
4347 } ,
4448 OS_ETH : {
4549 height : 4189824 ,
@@ -99,4 +103,4 @@ export const translateSonicSymbol = (symbol: SonicCurrency): SonicCurrencySymbol
99103 if ( symbol === 'wS' ) return 'S'
100104 if ( symbol === 'WETH' ) return 'ETH'
101105 return symbol
102- }
106+ }
0 commit comments