Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/adaptors/metrom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const CHAIN_TYPE_AND_NAMES: ByChainTypeAndId<string> = {
9_745: 'Plasma',
5_464: 'Saga',
56: 'BSC',
4_326: 'MegaETH',
},
aptos: {
1: 'Aptos',
Expand All @@ -44,6 +45,7 @@ interface BaseTarget {
interface AmmPoolLiquidityTarget extends BaseTarget {
type: 'amm-pool-liquidity';
id: string;
dex: string;
tokens: Token[];
usdTvl: number;
}
Expand Down Expand Up @@ -177,6 +179,7 @@ module.exports = {
interface ProcessedCampaign {
symbol: string;
underlyingTokens: string[];
poolMeta: string;
}

function processCampaign(campaign: Campaign): ProcessedCampaign | null {
Expand All @@ -187,30 +190,61 @@ function processCampaign(campaign: Campaign): ProcessedCampaign | null {
campaign.target.tokens.map((token) => token.symbol).join(' - ')
),
underlyingTokens: campaign.target.tokens.map((token) => token.address),
poolMeta: humanizeTargetProtocol('Pool on', campaign.target.dex),
};
}
case 'liquity-v2-debt': {
return {
symbol: formatSymbol(campaign.target.collateral.symbol),
underlyingTokens: [campaign.target.collateral.address],
poolMeta: humanizeTargetProtocol('Borrow on', campaign.target.brand),
};
}
case 'liquity-v2-debt':
case 'liquity-v2-stability-pool': {
return {
symbol: formatSymbol(campaign.target.collateral.symbol),
underlyingTokens: [campaign.target.collateral.address],
poolMeta: humanizeTargetProtocol(
'Deposit to stability pool on',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please reduce the text too long and wont easily be seen

Copy link
Copy Markdown
Contributor

@0xkr3p 0xkr3p Mar 31, 2026

Choose a reason for hiding this comment

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

Stability pool - brand

campaign.target.brand
),
};
}
case 'gmx-v1-liquidity': {
// FIXME: for now, with the current API, it's impossible to process GMX v1
// campaigns, address this later on
return null;
}
case 'aave-v3-supply':
case 'aave-v3-borrow':
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-borrow': {
return {
symbol: formatSymbol(campaign.target.collateral.symbol),
underlyingTokens: [campaign.target.collateral.address],
poolMeta: humanizeTargetProtocol('Borrow on', campaign.target.brand),
};
}
case 'aave-v3-net-supply': {
return {
symbol: formatSymbol(campaign.target.collateral.symbol),
underlyingTokens: [campaign.target.collateral.address],
poolMeta: humanizeTargetProtocol('Net lend on', campaign.target.brand),
};
}
default: {
return null;
}
}
}

function humanizeTargetProtocol(action: string, protocolSlug: string): string {
return `${action} ${protocolSlug
.split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')}`;
Comment on lines +245 to +249
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Mar 26, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

Suggested change
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@luzzif pls implement this fix to future proof

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

}
Loading