From 84e8562e59c4ff5911551f5c55dfe345d0d304bb Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Wed, 18 Mar 2026 17:57:30 +0000 Subject: [PATCH] Fix MCV2_Bond event ABIs: Mint/Burn not Minted/Burned The upstream MCV2_Bond.sol uses event names `Mint` and `Burn` (not `Minted`/`Burned`), with 6 params and 3 indexed (not 5 params and 2 indexed). The wrong signatures caused decodeEventLog to silently fail on every trade, resulting in zero rows in trade_history. Corrected: - Mint(address indexed token, address indexed user, address receiver, uint256 amountMinted, address indexed reserveToken, uint256 reserveAmount) - Burn(address indexed token, address indexed user, address receiver, uint256 amountBurned, address indexed reserveToken, uint256 refundAmount) Updated both the direct indexer and cron route to match. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/contracts/abi.ts | 24 +++++++++++++----------- src/app/api/cron/trade-history/route.ts | 13 +++++++------ src/app/api/index/trade/route.ts | 9 +++++---- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/contracts/abi.ts b/lib/contracts/abi.ts index ac387367..a67be308 100644 --- a/lib/contracts/abi.ts +++ b/lib/contracts/abi.ts @@ -91,31 +91,33 @@ export const donateFunction = { // MCV2_Bond events (from MCV2_Bond.sol upstream) // --------------------------------------------------------------------------- -export const mcv2MintedEvent = { +export const mcv2MintEvent = { type: "event", - name: "Minted", + name: "Mint", inputs: [ { name: "token", type: "address", indexed: true }, - { name: "account", type: "address", indexed: true }, - { name: "tokenAmount", type: "uint256", indexed: false }, + { name: "user", type: "address", indexed: true }, + { name: "receiver", type: "address", indexed: false }, + { name: "amountMinted", type: "uint256", indexed: false }, + { name: "reserveToken", type: "address", indexed: true }, { name: "reserveAmount", type: "uint256", indexed: false }, - { name: "beneficiary", type: "address", indexed: false }, ], } as const; -export const mcv2BurnedEvent = { +export const mcv2BurnEvent = { type: "event", - name: "Burned", + name: "Burn", inputs: [ { name: "token", type: "address", indexed: true }, - { name: "account", type: "address", indexed: true }, - { name: "tokenAmount", type: "uint256", indexed: false }, + { name: "user", type: "address", indexed: true }, + { name: "receiver", type: "address", indexed: false }, + { name: "amountBurned", type: "uint256", indexed: false }, + { name: "reserveToken", type: "address", indexed: true }, { name: "refundAmount", type: "uint256", indexed: false }, - { name: "beneficiary", type: "address", indexed: false }, ], } as const; -export const mcv2BondEventAbi = [mcv2MintedEvent, mcv2BurnedEvent] as const; +export const mcv2BondEventAbi = [mcv2MintEvent, mcv2BurnEvent] as const; // --------------------------------------------------------------------------- // MCV2_Bond view functions diff --git a/src/app/api/cron/trade-history/route.ts b/src/app/api/cron/trade-history/route.ts index 932cc860..402b6877 100644 --- a/src/app/api/cron/trade-history/route.ts +++ b/src/app/api/cron/trade-history/route.ts @@ -108,7 +108,7 @@ export async function GET(req: Request) { topics: log.topics, }); - if (decoded.eventName !== "Minted" && decoded.eventName !== "Burned") { + if (decoded.eventName !== "Mint" && decoded.eventName !== "Burn") { skipped++; continue; } @@ -132,7 +132,7 @@ export async function GET(req: Request) { ); inserted++; } catch (err) { - // Skip events that don't decode as Minted/Burned + // Skip events that don't decode as Mint/Burn if (err instanceof Error && err.message.includes("could not find")) { skipped++; continue; @@ -171,15 +171,16 @@ async function processTradeEvent( ) { const args = decoded.args as { token: `0x${string}`; - account: `0x${string}`; - tokenAmount: bigint; + user: `0x${string}`; + amountMinted?: bigint; + amountBurned?: bigint; reserveAmount?: bigint; refundAmount?: bigint; }; - const isMint = decoded.eventName === "Minted"; + const isMint = decoded.eventName === "Mint"; const reserveAmount = isMint ? args.reserveAmount! : args.refundAmount!; - const tokenAmount = args.tokenAmount; + const tokenAmount = isMint ? args.amountMinted! : args.amountBurned!; // Compute price per token (reserve per token, 18 decimals) const pricePerToken = diff --git a/src/app/api/index/trade/route.ts b/src/app/api/index/trade/route.ts index 9f5a250c..011e5d19 100644 --- a/src/app/api/index/trade/route.ts +++ b/src/app/api/index/trade/route.ts @@ -61,20 +61,21 @@ export async function POST(req: Request) { topics: log.topics, }); - if (decoded.eventName !== "Minted" && decoded.eventName !== "Burned") continue; + if (decoded.eventName !== "Mint" && decoded.eventName !== "Burn") continue; const args = decoded.args as { token: `0x${string}`; - tokenAmount: bigint; + amountMinted?: bigint; + amountBurned?: bigint; reserveAmount?: bigint; refundAmount?: bigint; }; if (args.token.toLowerCase() !== tokenAddress) continue; - const isMint = decoded.eventName === "Minted"; + const isMint = decoded.eventName === "Mint"; const reserveAmount = isMint ? args.reserveAmount! : args.refundAmount!; - const tokenAmount = args.tokenAmount; + const tokenAmount = isMint ? args.amountMinted! : args.amountBurned!; const pricePerToken = tokenAmount > BigInt(0)