feat(metrom-adapter): add support for megaeth and pool meta information#2512
feat(metrom-adapter): add support for megaeth and pool meta information#2512luzzif wants to merge 3 commits intoDefiLlama:masterfrom
Conversation
📝 WalkthroughWalkthroughAdded support for MegaETH chain, extended campaign target types with a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
The metrom adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/adaptors/metrom/index.ts (1)
218-237: Consider extracting duplicated single-collateral branch mapping.
aave-v3-supply,aave-v3-borrow, andaave-v3-net-supplydiffer only by action string. A shared helper would reduce drift risk.Refactor sketch
+function fromSingleCollateralTarget( + collateral: Token, + action: string, + protocol: string +): ProcessedCampaign { + return { + symbol: formatSymbol(collateral.symbol), + underlyingTokens: [collateral.address], + poolMeta: humanizeTargetProtocol(action, protocol), + }; +} ... - case 'aave-v3-supply': { - return { - symbol: formatSymbol(campaign.target.collateral.symbol), - underlyingTokens: [campaign.target.collateral.address], - poolMeta: humanizeTargetProtocol('Lend on', campaign.target.brand), - }; - } + case 'aave-v3-supply': + return fromSingleCollateralTarget( + campaign.target.collateral, + 'Lend on', + campaign.target.brand + );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/adaptors/metrom/index.ts` around lines 218 - 237, The three case branches ('aave-v3-supply', 'aave-v3-borrow', 'aave-v3-net-supply') duplicate the same mapping except for the action string; extract a helper (e.g., buildSingleCollateralMapping or mapAaveV3SingleCollateral) that accepts the action label ("Lend on"/"Borrow on"/"Net lend on") and returns { symbol: formatSymbol(campaign.target.collateral.symbol), underlyingTokens: [campaign.target.collateral.address], poolMeta: humanizeTargetProtocol(actionLabel, campaign.target.brand) }, then replace each case to call that helper with the appropriate label to eliminate duplication while keeping formatSymbol and humanizeTargetProtocol usage intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/adaptors/metrom/index.ts`:
- Around line 245-249: humanizeTargetProtocol can throw when protocolSlug is
undefined; update it to safely handle missing/empty values by defaulting
protocolSlug to an empty string (or a sentinel like "Unknown") before splitting
and by guarding word access in the mapper. Concretely, change
humanizeTargetProtocol to use (protocolSlug ?? '') or String(protocolSlug) and
.split('-').filter(Boolean) and map each word with safe access (e.g.,
word.charAt(0)?.toUpperCase() + word.slice(1)) so the function returns a
sensible string (like just the action or "action Unknown") instead of throwing.
---
Nitpick comments:
In `@src/adaptors/metrom/index.ts`:
- Around line 218-237: The three case branches ('aave-v3-supply',
'aave-v3-borrow', 'aave-v3-net-supply') duplicate the same mapping except for
the action string; extract a helper (e.g., buildSingleCollateralMapping or
mapAaveV3SingleCollateral) that accepts the action label ("Lend on"/"Borrow
on"/"Net lend on") and returns { symbol:
formatSymbol(campaign.target.collateral.symbol), underlyingTokens:
[campaign.target.collateral.address], poolMeta:
humanizeTargetProtocol(actionLabel, campaign.target.brand) }, then replace each
case to call that helper with the appropriate label to eliminate duplication
while keeping formatSymbol and humanizeTargetProtocol usage intact.
🪄 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: b6ef77a3-503e-4265-9b39-586f932404fa
📒 Files selected for processing (1)
src/adaptors/metrom/index.ts
| function humanizeTargetProtocol(action: string, protocolSlug: string): string { | ||
| return `${action} ${protocolSlug | ||
| .split('-') | ||
| .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | ||
| .join(' ')}`; |
There was a problem hiding this comment.
Make humanizeTargetProtocol resilient to missing protocol values.
At Line 246, .split('-') will throw if upstream payloads omit dex/brand, and the caller then drops the entire campaign in the catch block.
Proposed fix
-function humanizeTargetProtocol(action: string, protocolSlug: string): string {
- return `${action} ${protocolSlug
- .split('-')
+function humanizeTargetProtocol(
+ action: string,
+ protocolSlug?: string
+): string {
+ const normalizedSlug = protocolSlug?.trim();
+ if (!normalizedSlug) return action;
+
+ return `${action} ${normalizedSlug
+ .split(/[-_]/)
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')}`;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function humanizeTargetProtocol(action: string, protocolSlug: string): string { | |
| return `${action} ${protocolSlug | |
| .split('-') | |
| .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | |
| .join(' ')}`; | |
| function humanizeTargetProtocol( | |
| action: string, | |
| protocolSlug?: string | |
| ): string { | |
| const normalizedSlug = protocolSlug?.trim(); | |
| if (!normalizedSlug) return action; | |
| return `${action} ${normalizedSlug | |
| .split(/[-_]/) | |
| .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | |
| .join(' ')}`; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/adaptors/metrom/index.ts` around lines 245 - 249, humanizeTargetProtocol
can throw when protocolSlug is undefined; update it to safely handle
missing/empty values by defaulting protocolSlug to an empty string (or a
sentinel like "Unknown") before splitting and by guarding word access in the
mapper. Concretely, change humanizeTargetProtocol to use (protocolSlug ?? '') or
String(protocolSlug) and .split('-').filter(Boolean) and map each word with safe
access (e.g., word.charAt(0)?.toUpperCase() + word.slice(1)) so the function
returns a sensible string (like just the action or "action Unknown") instead of
throwing.
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
| symbol: formatSymbol(campaign.target.collateral.symbol), | ||
| underlyingTokens: [campaign.target.collateral.address], | ||
| poolMeta: humanizeTargetProtocol( | ||
| 'Deposit to stability pool on', |
There was a problem hiding this comment.
please reduce the text too long and wont easily be seen
Summary by CodeRabbit