feat: Allow pullHourly for adapters that support granular data fetching (version 2)#11130
feat: Allow pullHourly for adapters that support granular data fetching (version 2)#111300xpeluche wants to merge 10 commits intoDefiLlama:masterfrom
Conversation
defi/src/adaptors/db-utils/db2.ts
Outdated
|
|
||
| let isInitialized: any | ||
|
|
||
| const isLocalStoreEnabled = () => process.env.DIM_LOCAL_STORE === 'true' |
There was a problem hiding this comment.
this entire block is related to mocking the db function right, I would keep it out of this file, you can create a localDb file and keep all the logic there and add the logic for switching based of env flag where it is imported, tbh, I wouldnt this, we can start using a shadow/dev db for these testings, it is easier
| return `${yyyy}-${mm}-${dd}-${hh}` | ||
| } | ||
|
|
||
| export async function getHourlySlicesForProtocol({ adapterType, id, fromTimestamp, toTimestamp, transform = a => a }: { adapterType: AdapterType, id: string, fromTimestamp: number, toTimestamp: number, transform?: (a: any) => any}) { |
There was a problem hiding this comment.
can you add a bulk fetch method, that will pull all the hourly slices of all the protocols in the past 50 hours (50 because the hourly runner will try to refill yesterday's data if missing in the db)
There was a problem hiding this comment.
then on the actual runner if requested time range is within this cache, we return from cache, else query the db
| console.log('This will run with MAX_RUNTIME:', MAX_RUNTIME / 60000, 'minutes'); | ||
| if (isDryRun) { | ||
| console.log('>>> DIMENSIONS DRY-RUN MODE ENABLED <<<'); | ||
| if (singleAdapterTypeEnv) console.log('Limiting to adapterType:', singleAdapterTypeEnv); |
There was a problem hiding this comment.
think we already have support for dry run, same for passing certain adapters to run, check ui-tool/dimensions.ts
for testing, I would say, create a test.ts script in this folder instead of editting this file
| maxRunTime, | ||
| onlyYesterday = false, | ||
| deadChains, | ||
| skipHourlyCache = false, |
There was a problem hiding this comment.
while I still remember, can you update the ui-tool to add an option to enable/disable this cache while refilling
| skipHourlyCache = false, | ||
| } = options | ||
|
|
||
| const localStoreEnabled = process.env.DIM_LOCAL_STORE === 'true' |
There was a problem hiding this comment.
same comment as db2, need to remove this, we already have support for dry run
There was a problem hiding this comment.
hmm, havent checked the rest of the code but storing hourly data needs to wait for approval from the ui-tool like storing the daily record
| rawTokenBalances?: Record<string, string | number> | ||
| } | ||
|
|
||
| function buildTokenBreakdownsByLabel(params: { tokenBreakdown?: any, breakdownByLabel?: any, breakdownByLabelByChain?: any }): { tbl?: any, tblc?: any } { |
There was a problem hiding this comment.
can this be moved to hourly.ts in this folder?
| let tblc: any | ||
| let hourlySlicesForDebug: any[] | undefined | ||
|
|
||
| if (isHourlyAdapter && runType === 'store-all' && !isRunFromRefillScript) { |
There was a problem hiding this comment.
can this/parts of this be moved to hourly.ts in this folder?
|
|
||
| if (newSlices.length) { | ||
| if (!isDryRun || localStoreEnabled) { | ||
| await upsertHourlySlicesForProtocol({ |
There was a problem hiding this comment.
should instead return a promise that the parent function can if they want along with inserting the daily record
The following PR requires the changes introduced by the PR: DefiLlama/dimension-adapters#5027
This is currently still a WIP, with a codebase that can run locally in order to adjust and validate tests
Required
To do this, the desired adapter must be adjusted by adding the flag:
pullHourly: trueCommand to execute:
npx ts-node storeAll.tsBrief overview