Skip to content

Feat: Prefetch Function Support in Adapter #3027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 30, 2025

Conversation

treeoflife2
Copy link
Member

The prefetch function solves a key inefficiency in multi-chain DeFi adapters by fetching common data once instead of repeatedly for each chain. In the Rainbow Wallet example, it executes a single Dune SQL query that retrieves fee data for all chains, then stores this in preFetchedResults. Each chain's fetch function accesses this shared data through options.preFetchedResults, eliminating redundant database queries, reducing API load, and improving performance. This approach keeps the codebase cleaner by separating shared data fetching from chain-specific processing while maintaining backward compatibility.
This function would improve performance and use less resource/credits. mostly would be useful in dune/allium query/APIs where we can have multi-chain data in single request.

@treeoflife2 treeoflife2 requested a review from g1nt0ki April 25, 2025 21:18
@llamabutler
Copy link

The rainbow-wallet.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees rainbow-wallet.ts

🦙 Running RAINBOW-WALLET.TS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 24 Apr 2025 00:00:00 GMT
End Date:	Fri, 25 Apr 2025 00:00:00 GMT
---------------------------------------------------

[Error: Request failed with status code 401] {
  url: 'https://api.dune.com/api/v1/query/3996608/execute',
  method: 'POST',
  axiosError: 'invalid API Key'
}

@llamabutler
Copy link

The rainbow-wallet.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees rainbow-wallet.ts

🦙 Running RAINBOW-WALLET.TS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 24 Apr 2025 00:00:00 GMT
End Date:	Fri, 25 Apr 2025 00:00:00 GMT
---------------------------------------------------

[Error: Request failed with status code 401] {
  url: 'https://api.dune.com/api/v1/query/3996608/execute',
  method: 'POST',
  axiosError: 'invalid API Key'
}

@llamabutler
Copy link

The rainbow-wallet.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees rainbow-wallet.ts

🦙 Running RAINBOW-WALLET.TS adapter 🦙
---------------------------------------------------
Start Date:	Thu, 24 Apr 2025 00:00:00 GMT
End Date:	Fri, 25 Apr 2025 00:00:00 GMT
---------------------------------------------------

[Error: Request failed with status code 401] {
  url: 'https://api.dune.com/api/v1/query/3996608/execute',
  method: 'POST',
  axiosError: 'invalid API Key'
}

@@ -17,6 +17,7 @@ function getUnixTimeNow() {
export default async function runAdapter(volumeAdapter: BaseAdapter, cleanCurrentDayTimestamp: number, chainBlocks: ChainBlocks, id?: string, version?: string, {
adapterVersion = 1,
isTest = false,
prefetch = null,
Copy link
Member

Choose a reason for hiding this comment

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

volumeAdapter will have the prefetch field right? if you use that instead of the extra field here, prefetch will work without automatically for all the code calling runAdapter without any modification to them

@llamabutler
Copy link

The rainbow-wallet.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees rainbow-wallet.ts

🦙 Running RAINBOW-WALLET.TS adapter 🦙
---------------------------------------------------
Start Date:	Fri, 25 Apr 2025 00:00:00 GMT
End Date:	Sat, 26 Apr 2025 00:00:00 GMT
---------------------------------------------------

[Error: Request failed with status code 401] {
  url: 'https://api.dune.com/api/v1/query/3996608/execute',
  method: 'POST',
  axiosError: 'invalid API Key'
}

@llamabutler
Copy link

The rainbow-wallet.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees rainbow-wallet.ts

🦙 Running RAINBOW-WALLET.TS adapter 🦙
---------------------------------------------------
Start Date:	Tue, 29 Apr 2025 00:00:00 GMT
End Date:	Wed, 30 Apr 2025 00:00:00 GMT
---------------------------------------------------

[Error: Request failed with status code 401] {
  url: 'https://api.dune.com/api/v1/query/3996608/execute',
  method: 'POST',
  axiosError: 'invalid API Key'
}

@g1nt0ki g1nt0ki merged commit aa653a8 into DefiLlama:master Apr 30, 2025
2 checks passed
@llamabutler
Copy link

The rainbow-wallet.ts adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees rainbow-wallet.ts

🦙 Running RAINBOW-WALLET.TS adapter 🦙
---------------------------------------------------
Start Date:	Tue, 29 Apr 2025 00:00:00 GMT
End Date:	Wed, 30 Apr 2025 00:00:00 GMT
---------------------------------------------------

[Error: Request failed with status code 401] {
  url: 'https://api.dune.com/api/v1/query/3996608/execute',
  method: 'POST',
  axiosError: 'invalid API Key'
}

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