@@ -75,6 +75,7 @@ export async function setModuleDefaults(module: SimpleAdapter) {
7575}
7676
7777type AdapterRunOptions = {
78+ deadChains ?: Set < string > , // chains that are dead and should be skipped
7879 module : SimpleAdapter ,
7980 endTimestamp : number ,
8081 name ?: string ,
@@ -95,19 +96,33 @@ export default async function runAdapter(options: AdapterRunOptions) {
9596
9697 if ( ! adapterRunResponseCache [ runKey ] ) adapterRunResponseCache [ runKey ] = _runAdapter ( options )
9798 else sdk . log ( `[Dimensions run] Using cached results for ${ runKey } ` )
98- return adapterRunResponseCache [ runKey ]
99+ return adapterRunResponseCache [ runKey ] . then ( ( res : any ) => clone ( res ) ) // clone the object to avoid accidental mutation of the cached object
100+
101+ function clone ( obj : any ) {
102+ return JSON . parse ( JSON . stringify ( obj ) )
103+ }
99104}
100105
101106function getRunKey ( options : AdapterRunOptions ) {
102107 let randomUID = options . module . _randomUID ?? genUID ( 10 )
103108 return `${ randomUID } -${ options . endTimestamp } -${ options . withMetadata } `
104109}
105110
111+ const startOfDayIdCache : { [ key : string ] : string } = { }
112+
113+ function getStartOfDayId ( timestamp : number ) : string {
114+ if ( ! startOfDayIdCache [ timestamp ] ) {
115+ startOfDayIdCache [ timestamp ] = '' + Math . floor ( timestamp / 86400 )
116+ }
117+ return startOfDayIdCache [ timestamp ]
118+ }
119+
106120
107121async function _runAdapter ( {
108122 module, endTimestamp, name,
109123 isTest = false ,
110124 withMetadata = false ,
125+ deadChains = new Set ( ) ,
111126} : AdapterRunOptions ) {
112127 const cleanCurrentDayTimestamp = endTimestamp
113128 const adapterVersion = module . version
@@ -160,7 +175,7 @@ async function _runAdapter({
160175 const response = await Promise . all ( chains . filter ( chain => {
161176 const res = validStart [ chain ] ?. canRun
162177 if ( isTest && ! res ) console . log ( `Skipping ${ chain } because the configured start time is ${ new Date ( validStart [ chain ] ?. startTimestamp * 1e3 ) . toUTCString ( ) } \n\n` )
163- return validStart [ chain ] ?. canRun
178+ return validStart [ chain ] ?. canRun && ! deadChains . has ( chain )
164179 } ) . map ( getChainResult ) )
165180
166181 Object . entries ( breakdownByToken ) . forEach ( ( [ chain , data ] : any ) => {
@@ -227,6 +242,7 @@ async function _runAdapter({
227242 // if (value === undefined || value === null) throw new Error(`Value: ${value} ${recordType} is undefined or null`)
228243 if ( value instanceof Balances ) {
229244 const { labelBreakdown, usdTvl, usdTokenBalances, rawTokenBalances } = await value . getUSDJSONs ( )
245+ // if (usdTvl > 1e6) value.debug()
230246 result [ recordType ] = usdTvl
231247 breakdownByToken [ chain ] = breakdownByToken [ chain ] || { }
232248 breakdownByToken [ chain ] [ recordType ] = { usdTvl, usdTokenBalances, rawTokenBalances }
@@ -299,7 +315,13 @@ async function _runAdapter({
299315 const fromTimestamp = toTimestamp - ONE_DAY_IN_SECONDS
300316 const getFromBlock = async ( ) => await getBlock ( fromTimestamp , chain )
301317 const getToBlock = async ( ) => await getBlock ( toTimestamp , chain , chainBlocks )
318+ const problematicChains = new Set ( [ 'sei' , 'xlayer' ] )
319+
302320 const getLogs = async ( { target, targets, onlyArgs = true , fromBlock, toBlock, flatten = true , eventAbi, topics, topic, cacheInCloud = false , skipCacheRead = false , entireLog = false , skipIndexer, noTarget, ...rest } : FetchGetLogsOptions ) => {
321+
322+
323+ if ( problematicChains . has ( chain ) ) throw new Error ( `getLogs is disabled for ${ chain } chain due to frequent timeouts` )
324+
303325 fromBlock = fromBlock ?? await getFromBlock ( )
304326 toBlock = toBlock ?? await getToBlock ( )
305327
@@ -343,6 +365,7 @@ async function _runAdapter({
343365 getEndBlock,
344366 dateString : getDateString ( startOfDay ) ,
345367 moduleUID,
368+ startOfDayId : getStartOfDayId ( startOfDay ) ,
346369 }
347370 }
348371
@@ -431,7 +454,7 @@ function addMissingMetrics(chain: string, result: any) {
431454 if ( result . dailyFees && result . dailyFees instanceof Balances && result . dailyFees . hasBreakdownBalances ( ) ) {
432455
433456 // if we have supplySideRevenue but missing revenue, add revenue = fees - supplySideRevenue
434- if ( result . dailySupplySideRevenue && ! result . dailyrevenue ) {
457+ if ( result . dailySupplySideRevenue && ! result . dailyRevenue ) {
435458 result . dailyRevenue = createBalanceFrom ( { chain, timestamp : result . timestamp , amount : result . dailyFees } )
436459 subtractBalance ( { balance : result . dailyRevenue , amount : result . dailySupplySideRevenue } )
437460 }
0 commit comments