Skip to content

refactor merkl to use api key#2707

Merged
0xkr3p merged 4 commits into
DefiLlama:masterfrom
0xkr3p:refactor/merkl-use-key
Jun 1, 2026
Merged

refactor merkl to use api key#2707
0xkr3p merged 4 commits into
DefiLlama:masterfrom
0xkr3p:refactor/merkl-use-key

Conversation

@0xkr3p
Copy link
Copy Markdown
Contributor

@0xkr3p 0xkr3p commented May 26, 2026

Summary by CodeRabbit

  • Refactor
    • Multiple adapters now use a unified Merkl API client for consistent data fetching, timeout handling, and more reliable reward/opportunity lookups while preserving existing behaviors.
  • Chores
    • Deployment workflow now exposes a MERKL_API_KEY environment variable so runtime processes can access the Merkl API securely.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9b66454b-4821-439f-a03a-7aadd71b674e

📥 Commits

Reviewing files that changed from the base of the PR and between 0779782 and 8aadfd4.

📒 Files selected for processing (10)
  • src/adaptors/altura/index.js
  • src/adaptors/crosscurve/index.js
  • src/adaptors/extra-finance-xlend/index.js
  • src/adaptors/gearbox/index.js
  • src/adaptors/lendle-earn/index.js
  • src/adaptors/merkl/merkl-additional-reward.js
  • src/adaptors/merkl/merkl-by-identifier.js
  • src/adaptors/superlend/constants.js
  • src/adaptors/superlend/index.js
  • src/adaptors/termmax/index.js
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/adaptors/lendle-earn/index.js
  • src/adaptors/extra-finance-xlend/index.js
  • src/adaptors/crosscurve/index.js
  • src/adaptors/superlend/index.js
  • src/adaptors/altura/index.js
  • src/adaptors/termmax/index.js
  • src/adaptors/merkl/merkl-by-identifier.js

📝 Walkthrough

Walkthrough

Adds a shared Merkl API client (merklGet) that injects MERKL_API_KEY from env and migrates multiple adapters to use it for fetching /v4/opportunities; the deploy workflow exposes MERKL_API_KEY from secrets to the deploy step.

Changes

Merkl Client Refactor

Layer / File(s) Summary
Merkl client module and exports
src/adaptors/merkl/merkl-client.js
New module exports merklGet(pathOrUrl, options), buildUrl(), and getMerklHeaders() which conditionally adds X-API-Key from process.env.MERKL_API_KEY, and applies a default timeout.
Merkl subdirectory adapters migration
src/adaptors/merkl/merkl-additional-reward.js, src/adaptors/merkl/merkl-by-identifier.js
Replace direct axios/getData calls with merklGet and fetch opportunities using relative /v4/opportunities?... paths; reward extraction and batching logic unchanged.
Multi-protocol adapters Merkl integration
src/adaptors/altura/index.js, src/adaptors/betswirl/index.js, src/adaptors/crosscurve/index.js, src/adaptors/extra-finance-xlend/index.js, src/adaptors/gearbox/index.js, src/adaptors/lendle-earn/index.js, src/adaptors/ploutos-money/index.js, src/adaptors/superlend/index.js, src/adaptors/termmax/index.js
Add merklGet imports and replace direct HTTP calls with merklGet('/v4/opportunities...') (with adapter-specific params/timeouts); downstream APY/reward processing is preserved.
Superlend constants and wiring
src/adaptors/superlend/constants.js, src/adaptors/superlend/index.js
Replace MERKLE_BASE_URL usage with MERKL_CAMPAIGNS_PATH and call merklGet(MERKL_CAMPAIGNS_PATH, { params: { chainId, campaignId, withOpportunity: true } }) to fetch campaign/opportunity data.
Deployment workflow API key configuration
.github/workflows/master.yml
Expose MERKL_API_KEY from secrets.MERKL_API_KEY in the "Deploy infrastructure stack" step environment so the client can send the API key.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code to weave one thread,
A client shared where calls were spread.
Secrets tucked in env so sly,
Ten adapters sip the same supply —
A tidy burrow, clean and fed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: refactoring Merkl integration to support API key usage via environment variables and a dedicated client.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: one or more packages not found in the registry.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

The altura adapter exports pools:

Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total
Snapshots: 0 total
Time: 0.223 s
Ran all test suites.

Nb of pools: 1
 

Sample pools:
┌─────────┬──────────────────────────────────────────────────────────┬──────────────────┬──────────┬─────────┬─────────────────┬────────────────────┬───────────┬───────────────┬──────────────────────────────────────────────────┬──────────────┬───────────────────────────────────┬────────────────────────────┐
│ (index) │ pool                                                     │ chain            │ project  │ symbol  │ tvlUsd          │ apyBase            │ apyReward │ pricePerShare │ underlyingTokens                                 │ rewardTokens │ poolMeta                          │ url                        │
├─────────┼──────────────────────────────────────────────────────────┼──────────────────┼──────────┼─────────┼─────────────────┼────────────────────┼───────────┼───────────────┼──────────────────────────────────────────────────┼──────────────┼───────────────────────────────────┼────────────────────────────┤
│ 0       │ '0xd0ee0cf300dfb598270cd7f4d0c6e0d8f6e13f29-hyperliquid' │ 'Hyperliquid L1' │ 'altura' │ 'USDT0' │ 24835305.612333 │ 17.516914187378745 │ 0         │ 1.081137      │ [ '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb' ] │ undefined    │ 'Multi-Strategy Stablecoin Vault' │ 'https://app.altura.trade' │
└─────────┴──────────────────────────────────────────────────────────┴──────────────────┴──────────┴─────────┴─────────────────┴────────────────────┴───────────┴───────────────┴──────────────────────────────────────────────────┴──────────────┴───────────────────────────────────┴────────────────────────────┘

@github-actions
Copy link
Copy Markdown

The altura adapter exports pools:

Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total
Snapshots: 0 total
Time: 0.278 s
Ran all test suites.

Nb of pools: 1
 

Sample pools:
┌─────────┬──────────────────────────────────────────────────────────┬──────────────────┬──────────┬─────────┬─────────────────┬────────────────────┬───────────┬───────────────┬──────────────────────────────────────────────────┬──────────────┬───────────────────────────────────┬────────────────────────────┐
│ (index) │ pool                                                     │ chain            │ project  │ symbol  │ tvlUsd          │ apyBase            │ apyReward │ pricePerShare │ underlyingTokens                                 │ rewardTokens │ poolMeta                          │ url                        │
├─────────┼──────────────────────────────────────────────────────────┼──────────────────┼──────────┼─────────┼─────────────────┼────────────────────┼───────────┼───────────────┼──────────────────────────────────────────────────┼──────────────┼───────────────────────────────────┼────────────────────────────┤
│ 0       │ '0xd0ee0cf300dfb598270cd7f4d0c6e0d8f6e13f29-hyperliquid' │ 'Hyperliquid L1' │ 'altura' │ 'USDT0' │ 25149023.718237 │ 17.513141968819284 │ 0         │ 1.081352      │ [ '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb' ] │ undefined    │ 'Multi-Strategy Stablecoin Vault' │ 'https://app.altura.trade' │
└─────────┴──────────────────────────────────────────────────────────┴──────────────────┴──────────┴─────────┴─────────────────┴────────────────────┴───────────┴───────────────┴──────────────────────────────────────────────────┴──────────────┴───────────────────────────────────┴────────────────────────────┘

@0xkr3p 0xkr3p marked this pull request as ready for review May 27, 2026 08:59
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/adaptors/lendle-earn/index.js (1)

24-24: ⚡ Quick win

Prefer a relative Merkl path to keep this adapter aligned with the shared client contract.

Passing a full URL still works, but using a relative path keeps base-URL management centralized in merkl-client and consistent with the rest of this PR.

Suggested diff
-const vaultsCampaignApi = 'https://api.merkl.xyz/v4/opportunities?name=lendle';
+const vaultsCampaignApi = '/v4/opportunities?name=lendle';

Also applies to: 54-54

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/adaptors/lendle-earn/index.js` at line 24, Replace the hardcoded full
Merkl URL with a relative path so base-URL resolution stays in merkl-client:
change the constant vaultsCampaignApi (and the other similar constant at the
second occurrence) from 'https://api.merkl.xyz/v4/opportunities?name=lendle' to
the relative '/v4/opportunities?name=lendle' (preserve the variable names
vaultsCampaignApi and the other identifier) so the shared client can prepend the
base URL consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/adaptors/gearbox/index.js`:
- Line 583: The call to merklGet uses a trailing slash in the endpoint
(`/v4/opportunities/`) which may behave differently than `/v4/opportunities`;
update the merklGet invocation in the code that constructs `data` so it uses a
normalized path (e.g., `/v4/opportunities` without the trailing slash) or build
the URL using a join that strips duplicate slashes; change the line with `const
data = await
merklGet(`/v4/opportunities/?chainId=${config.chainId}&identifier=${poolId}`);`
to use the normalized endpoint (`/v4/opportunities`) while keeping the same
query parameters.

In `@src/adaptors/merkl/merkl-client.js`:
- Around line 16-23: The merklGet function lacks an axios timeout which can
cause indefinite hangs; update merklGet to accept/merge a timeout from options
(e.g., options.timeout) and pass a sensible default (e.g., 5000 ms) into the
axios.get config along with the existing headers (used via getMerklHeaders) and
other rest options; ensure you still call buildUrl(pathOrUrl) and do not remove
existing merging of ...rest so callers can override the default timeout if
desired.

---

Nitpick comments:
In `@src/adaptors/lendle-earn/index.js`:
- Line 24: Replace the hardcoded full Merkl URL with a relative path so base-URL
resolution stays in merkl-client: change the constant vaultsCampaignApi (and the
other similar constant at the second occurrence) from
'https://api.merkl.xyz/v4/opportunities?name=lendle' to the relative
'/v4/opportunities?name=lendle' (preserve the variable names vaultsCampaignApi
and the other identifier) so the shared client can prepend the base URL
consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 47ff7956-1e49-459f-992d-a21691610ecb

📥 Commits

Reviewing files that changed from the base of the PR and between 570fec6 and 3f64519.

📒 Files selected for processing (13)
  • .github/workflows/master.yml
  • src/adaptors/altura/index.js
  • src/adaptors/betswirl/index.js
  • src/adaptors/crosscurve/index.js
  • src/adaptors/extra-finance-xlend/index.js
  • src/adaptors/gearbox/index.js
  • src/adaptors/lendle-earn/index.js
  • src/adaptors/merkl/merkl-additional-reward.js
  • src/adaptors/merkl/merkl-by-identifier.js
  • src/adaptors/merkl/merkl-client.js
  • src/adaptors/ploutos-money/index.js
  • src/adaptors/superlend/index.js
  • src/adaptors/termmax/index.js

Comment thread src/adaptors/gearbox/index.js Outdated
Comment thread src/adaptors/merkl/merkl-client.js
@github-actions
Copy link
Copy Markdown

The altura adapter exports pools:

Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total
Snapshots: 0 total
Time: 0.222 s
Ran all test suites.

Nb of pools: 1
 

Sample pools:
┌─────────┬──────────────────────────────────────────────────────────┬──────────────────┬──────────┬─────────┬─────────────────┬────────────────────┬───────────┬───────────────┬──────────────────────────────────────────────────┬──────────────┬───────────────────────────────────┬────────────────────────────┐
│ (index) │ pool                                                     │ chain            │ project  │ symbol  │ tvlUsd          │ apyBase            │ apyReward │ pricePerShare │ underlyingTokens                                 │ rewardTokens │ poolMeta                          │ url                        │
├─────────┼──────────────────────────────────────────────────────────┼──────────────────┼──────────┼─────────┼─────────────────┼────────────────────┼───────────┼───────────────┼──────────────────────────────────────────────────┼──────────────┼───────────────────────────────────┼────────────────────────────┤
│ 0       │ '0xd0ee0cf300dfb598270cd7f4d0c6e0d8f6e13f29-hyperliquid' │ 'Hyperliquid L1' │ 'altura' │ 'USDT0' │ 25410285.398093 │ 17.512843769540524 │ 0         │ 1.081369      │ [ '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb' ] │ undefined    │ 'Multi-Strategy Stablecoin Vault' │ 'https://app.altura.trade' │
└─────────┴──────────────────────────────────────────────────────────┴──────────────────┴──────────┴─────────┴─────────────────┴────────────────────┴───────────┴───────────────┴──────────────────────────────────────────────────┴──────────────┴───────────────────────────────────┴────────────────────────────┘

@github-actions
Copy link
Copy Markdown

The altura adapter exports pools:

Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total
Snapshots: 0 total
Time: 0.242 s
Ran all test suites.

Nb of pools: 1
 

Sample pools:
┌─────────┬──────────────────────────────────────────────────────────┬──────────────────┬──────────┬─────────┬─────────────────┬────────────────────┬───────────┬───────────────┬──────────────────────────────────────────────────┬──────────────┬───────────────────────────────────┬────────────────────────────┐
│ (index) │ pool                                                     │ chain            │ project  │ symbol  │ tvlUsd          │ apyBase            │ apyReward │ pricePerShare │ underlyingTokens                                 │ rewardTokens │ poolMeta                          │ url                        │
├─────────┼──────────────────────────────────────────────────────────┼──────────────────┼──────────┼─────────┼─────────────────┼────────────────────┼───────────┼───────────────┼──────────────────────────────────────────────────┼──────────────┼───────────────────────────────────┼────────────────────────────┤
│ 0       │ '0xd0ee0cf300dfb598270cd7f4d0c6e0d8f6e13f29-hyperliquid' │ 'Hyperliquid L1' │ 'altura' │ 'USDT0' │ 25824697.861439 │ 17.495985696455946 │ 0         │ 1.082331      │ [ '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb' ] │ undefined    │ 'Multi-Strategy Stablecoin Vault' │ 'https://app.altura.trade' │
└─────────┴──────────────────────────────────────────────────────────┴──────────────────┴──────────┴─────────┴─────────────────┴────────────────────┴───────────┴───────────────┴──────────────────────────────────────────────────┴──────────────┴───────────────────────────────────┴────────────────────────────┘

@0xkr3p 0xkr3p merged commit 4b5850c into DefiLlama:master Jun 1, 2026
2 checks passed
@0xkr3p 0xkr3p deleted the refactor/merkl-use-key branch June 1, 2026 07:47
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.

1 participant