Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 13 additions & 11 deletions lib/contracts/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/app/api/cron/trade-history/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
9 changes: 5 additions & 4 deletions src/app/api/index/trade/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading