Skip to content

feat: Allow pullHourly for adapters that support granular data fetching (version 2)#11130

Closed
0xpeluche wants to merge 10 commits intoDefiLlama:masterfrom
0xpeluche:hourly_wip
Closed

feat: Allow pullHourly for adapters that support granular data fetching (version 2)#11130
0xpeluche wants to merge 10 commits intoDefiLlama:masterfrom
0xpeluche:hourly_wip

Conversation

@0xpeluche
Copy link
Contributor

@0xpeluche 0xpeluche commented Dec 19, 2025

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

List of environment variables required to run tests locally (this creates the slices locally as well as the daily data from those slices):

$env:DIM_PROTOCOL_NAME="aave-v3"
$env:DIM_ADAPTER_TYPE="fees"
$env:DIM_DRY_RUN="false"
$env:DIM_LOCAL_STORE="true"
$env:DIM_LOCAL_STORE_DIR="./dim-local-store"
$env:runLocal="true"
$env:DIM_SKIP_HOURLY_CACHE="false"
$env:DIM_SKIP_REFILL_YESTERDAY="true"

To do this, the desired adapter must be adjusted by adding the flag: pullHourly: true

Command to execute: npx ts-node storeAll.ts

Brief overview

The changes introduced by this PR aim to both speed up the execution of our internal jobs and improve the reliability of the returned data by providing higher granularity and better accuracy

  • Adapter updates are split into hourly slices (one slice per hour)
  • When a job runs, it pulls from the database the 23 slices preceding the current slice being processed
  • If all 23 previous slices are available, the job fetches the 24th (current) slice on-chain, and the rolling 24h daily data can be reconstructed from these slices
  • If any of the previous 23 slices are missing, the job fetches the missing on-chain data together with the current slice. Once all 24 slices are available, the rolling 24h daily data is rebuilt

@0xpeluche 0xpeluche self-assigned this Dec 19, 2025

let isInitialized: any

const isLocalStoreEnabled = () => process.env.DIM_LOCAL_STORE === 'true'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as db2, need to remove this, we already have support for dry run

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 } {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be moved to hourly.ts in this folder?

let tblc: any
let hourlySlicesForDebug: any[] | undefined

if (isHourlyAdapter && runType === 'store-all' && !isRunFromRefillScript) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this/parts of this be moved to hourly.ts in this folder?


if (newSlices.length) {
if (!isDryRun || localStoreEnabled) {
await upsertHourlySlicesForProtocol({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should instead return a promise that the parent function can if they want along with inserting the daily record

@noateden noateden assigned noateden and unassigned 0xpeluche Feb 6, 2026
@g1nt0ki g1nt0ki mentioned this pull request Feb 7, 2026
@g1nt0ki g1nt0ki closed this Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants