Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DeleteDateColumn,
Unique,
} from "typeorm";
import { DataSourceType } from "../../model";

@Entity({ schema: "evm" })
@Unique("UK_sponsoredDepositForBurn_chain_block_tx_log", [
Expand Down Expand Up @@ -75,6 +76,9 @@ export class SponsoredDepositForBurn {
@CreateDateColumn()
createdAt: Date;

@Column({ type: "simple-enum", enum: DataSourceType, nullable: true })
dataSource?: DataSourceType;

@DeleteDateColumn({ nullable: true })
deletedAt?: Date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddDataSourceToSponsoredDepositForBurn1767709500000
implements MigrationInterface
{
name = "AddDataSourceToSponsoredDepositForBurn1767709500000";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "evm"."sponsored_deposit_for_burn" ADD "dataSource" "evm"."datasource_type_enum" DEFAULT 'polling'`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "evm"."sponsored_deposit_for_burn" DROP COLUMN "dataSource"`,
);
}
}
4 changes: 4 additions & 0 deletions packages/indexer/src/data-indexing/model/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ export const SWAP_FLOW_FINALIZED_ABI = [
export const SWAP_FLOW_INITIALIZED_ABI = [
"event SwapFlowInitialized(bytes32 indexed quoteNonce,address indexed finalRecipient,address indexed finalToken,uint256 evmAmountIn,uint256 bridgingFeesIncurred,uint256 coreAmountIn,uint64 minAmountToSend,uint64 maxAmountToSend)",
];

export const SPONSORED_DEPOSIT_FOR_BURN_ABI = [
"event SponsoredDepositForBurn(bytes32 indexed quoteNonce, address indexed originSender, bytes32 indexed finalRecipient, uint256 quoteDeadline, uint256 maxBpsToSponsor, uint256 maxUserSlippageBps, bytes32 finalToken, bytes signature)",
];
15 changes: 14 additions & 1 deletion packages/indexer/src/data-indexing/model/eventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,23 @@ export interface SwapFlowInitializedArgs {
maxAmountToSend: bigint;
}

export interface SponsoredDepositForBurnArgs {
quoteNonce: `0x${string}`;
originSender: `0x${string}`;
finalRecipient: `0x${string}`;
quoteDeadline: bigint;
maxBpsToSponsor: bigint;
maxUserSlippageBps: bigint;
finalToken: `0x${string}`;
signature: `0x${string}`;
destinationChainId?: number;
}

export type EventArgs =
| DepositForBurnArgs
| MessageSentArgs
| MessageReceivedArgs
| MintAndWithdrawArgs
| SwapFlowFinalizedArgs
| SwapFlowInitializedArgs;
| SwapFlowInitializedArgs
| SponsoredDepositForBurnArgs;
42 changes: 40 additions & 2 deletions packages/indexer/src/data-indexing/service/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CCTP_DEPOSIT_FOR_BURN_ABI,
CCTP_MESSAGE_RECEIVED_ABI,
CCTP_MESSAGE_SENT_ABI,
SPONSORED_DEPOSIT_FOR_BURN_ABI,
CCTP_MINT_AND_WITHDRAW_ABI,
} from "../model/abis";
import {
Expand All @@ -19,12 +20,16 @@ import {
import { IndexerEventPayload } from "./genericEventListening";
import { IndexerEventHandler } from "./genericIndexing";
import { Logger } from "winston";
import { extractRawArgs } from "./preprocessing";
import {
extractRawArgs,
preprocessSponsoredDepositForBurn,
} from "./preprocessing";
import {
DepositForBurnArgs,
EventArgs,
MessageReceivedArgs,
MessageSentArgs,
SponsoredDepositForBurnArgs,
MintAndWithdrawArgs,
SwapFlowFinalizedArgs,
SwapFlowInitializedArgs,
Expand All @@ -39,6 +44,7 @@ import {
transformDepositForBurnEvent,
transformMessageReceivedEvent,
transformMessageSentEvent,
transformSponsoredDepositForBurnEvent,
transformMintAndWithdrawEvent,
transformSwapFlowFinalizedEvent,
transformSwapFlowInitializedEvent,
Expand All @@ -47,6 +53,7 @@ import {
storeDepositForBurnEvent,
storeMessageReceivedEvent,
storeMessageSentEvent,
storeSponsoredDepositForBurnEvent,
storeMintAndWithdrawEvent,
storeSwapFlowFinalizedEvent,
storeSwapFlowInitializedEvent,
Expand Down Expand Up @@ -165,6 +172,37 @@ export const CCTP_PROTOCOL: SupportedProtocols<
},
};

export const SPONSORED_CCTP_PROTOCOL: SupportedProtocols<
Partial<typeof Entity>,
BlockchainEventRepository,
IndexerEventPayload,
EventArgs
> = {
getEventHandlers: (logger: Logger, chainId: number) => {
const handlers = CCTP_PROTOCOL.getEventHandlers(logger, chainId);
return [
...handlers,
{
config: {
address: getSponsoredCCTPDstPeripheryAddress(
chainId,
) as `0x${string}`,
abi: SPONSORED_DEPOSIT_FOR_BURN_ABI,
eventName: "SponsoredDepositForBurn",
},
preprocess: (payload: IndexerEventPayload) =>
preprocessSponsoredDepositForBurn(payload, logger),
filter: async () => true,
transform: (
args: SponsoredDepositForBurnArgs,
payload: IndexerEventPayload,
) => transformSponsoredDepositForBurnEvent(args, payload, logger),
store: storeSponsoredDepositForBurnEvent,
},
];
},
};

/**
* Configuration for Sponsored Bridging Protocol.
*/
Expand Down Expand Up @@ -217,7 +255,7 @@ export const CHAIN_PROTOCOLS: Record<
EventArgs
>[]
> = {
[CHAIN_IDs.ARBITRUM]: [CCTP_PROTOCOL],
[CHAIN_IDs.ARBITRUM]: [SPONSORED_CCTP_PROTOCOL],
[CHAIN_IDs.ARBITRUM_SEPOLIA]: [CCTP_PROTOCOL],
[CHAIN_IDs.HYPEREVM]: [CCTP_PROTOCOL, SPONSORED_BRIDGING_PROTOCOL],
[CHAIN_IDs.MAINNET]: [CCTP_PROTOCOL],
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer/src/data-indexing/service/filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
CCTP_DEPOSIT_FOR_BURN_ABI,
CCTP_MESSAGE_RECEIVED_ABI,
} from "../model/abis";
import { decodeEventFromReceipt } from "./tranforming";
import { decodeEventFromReceipt } from "./preprocessing";
import {
DepositForBurnArgs,
MessageReceivedArgs,
Expand Down
65 changes: 65 additions & 0 deletions packages/indexer/src/data-indexing/service/preprocessing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
import { IndexerEventPayload } from "./genericEventListening";
import {
Abi,
parseAbi,
parseEventLogs,
TransactionReceipt,
decodeEventLog,
} from "viem";
import {
SPONSORED_DEPOSIT_FOR_BURN_ABI,
CCTP_DEPOSIT_FOR_BURN_ABI,
} from "../model/abis";
import { DEPOSIT_FOR_BURN_EVENT_NAME } from "./constants";
import {
DepositForBurnArgs,
SponsoredDepositForBurnArgs,
} from "../model/eventTypes";
import { getCctpDestinationChainFromDomain } from "../adapter/cctp-v2/service";
import { Logger } from "winston";

/**
* extracts and decodes a specific event from a transaction receipt's logs.
* @param receipt The transaction receipt.
* @param abi The Abi containing the event definition.
* @returns The decoded event arguments, or undefined if not found.
*/
export const decodeEventFromReceipt = <T>(
receipt: TransactionReceipt,
abi: Abi,
eventName: string,
): T | undefined => {
const logs = parseEventLogs({
abi,
logs: receipt.logs,
});
const log = logs.find((log) => log.eventName === eventName);
return (log?.args as T) ?? undefined;
};

export const extractRawArgs = <TEvent>(
payload: IndexerEventPayload,
Expand All @@ -13,3 +50,31 @@ export const extractRawArgs = <TEvent>(

return rawArgs as TEvent;
};

export const preprocessSponsoredDepositForBurn = (
payload: IndexerEventPayload,
logger: Logger,
): SponsoredDepositForBurnArgs => {
const args = extractRawArgs<SponsoredDepositForBurnArgs>(payload);

if (payload.transactionReceipt) {
const depositArgs = decodeEventFromReceipt<DepositForBurnArgs>(
payload.transactionReceipt,
parseAbi(CCTP_DEPOSIT_FOR_BURN_ABI),
DEPOSIT_FOR_BURN_EVENT_NAME,
);
if (depositArgs) {
args.destinationChainId = getCctpDestinationChainFromDomain(
depositArgs.destinationDomain,
);
} else {
Comment on lines +61 to +70
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought that we're going the fetch events separately. OOC why is the destinationChainId needed to be associated with the SponsoredDepositForBurn? Is it for formatting addresses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is for formatting addresses, we do the same for the regular CCTP indexer here:

const destinationChainId = getCctpDestinationChainFromDomain(

Copy link
Contributor Author

@NikolasHaimerl NikolasHaimerl Jan 8, 2026

Choose a reason for hiding this comment

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

What do you mean with events being fetched separately?
The websocket listens to DepositForBurn and SponsoredDepositForBurn separately.

const message = `Failed to decode DepositForBurn event from transaction receipt to decode destination chain id for SponsoredDepositForBurnEvent.`;
logger.error({
message,
payload,
});
throw new Error(message);
}
}
return args;
};
22 changes: 22 additions & 0 deletions packages/indexer/src/data-indexing/service/storing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ const PK_CHAIN_BLOCK_TX_LOG = [
"logIndex",
];

/**
* Stores a DepositForBurn event in the database.
*
* @param event The DepositForBurn entity to store.
Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

SponsoredDepositForBurn

* @param repository The BlockchainEventRepository instance.
* @returns A promise that resolves to the result of the save operation.
*/
export const storeSponsoredDepositForBurnEvent: Storer<
Partial<entities.SponsoredDepositForBurn>,
dbUtils.BlockchainEventRepository
> = async (
event: Partial<entities.SponsoredDepositForBurn>,
repository: dbUtils.BlockchainEventRepository,
) => {
return repository.saveAndHandleFinalisationBatch<entities.SponsoredDepositForBurn>(
entities.SponsoredDepositForBurn,
[{ ...event, dataSource: DataSourceType.WEB_SOCKET } as any],
PK_CHAIN_BLOCK_TX_LOG as (keyof entities.SponsoredDepositForBurn)[],
[],
);
};

/**
* Stores a DepositForBurn event in the database.
*
Expand Down
67 changes: 40 additions & 27 deletions packages/indexer/src/data-indexing/service/tranforming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@ import * as across from "@across-protocol/sdk";
import { IndexerEventPayload } from "./genericEventListening";
import {
getCctpDestinationChainFromDomain,
decodeMessage, // New import
decodeMessage,
} from "../adapter/cctp-v2/service";
import { formatFromAddressToChainFormat, safeJsonStringify } from "../../utils";
import { getFinalisedBlockBufferDistance } from "./constants";
import {
DepositForBurnArgs,
MessageReceivedArgs,
MessageSentArgs,
SponsoredDepositForBurnArgs,
MintAndWithdrawArgs,
SwapFlowFinalizedArgs,
SwapFlowInitializedArgs,
} from "../model/eventTypes";
import { Logger } from "winston";
import { arrayify } from "ethers/lib/utils"; // New import
import {
TransactionReceipt,
parseEventLogs,
ParseEventLogsReturnType,
Abi,
} from "viem";
import { arrayify } from "ethers/lib/utils";

/**
* A generic transformer for addresses.
Expand Down Expand Up @@ -128,6 +123,43 @@ export const transformDepositForBurnEvent = (
};
};

export const transformSponsoredDepositForBurnEvent = (
preprocessed: SponsoredDepositForBurnArgs,
payload: IndexerEventPayload,
logger: Logger,
): Partial<entities.SponsoredDepositForBurn> => {
const base = baseTransformer(payload, logger);

const destinationChainId = preprocessed.destinationChainId;
if (!destinationChainId) {
const message = `Failed to decode DepositForBurn event from transaction receipt to decode destination chain id for SponsoredDepositForBurnEvent.`;
logger.error({
message,
payload,
});
throw new Error(message);
}
const finalRecipient = transformAddress(
preprocessed.finalRecipient,
destinationChainId,
);
const finalToken = transformAddress(
preprocessed.finalToken,
destinationChainId,
);

return {
...base,
quoteNonce: preprocessed.quoteNonce,
originSender: preprocessed.originSender.toLowerCase(),
finalRecipient: finalRecipient.toLowerCase(),
quoteDeadline: new Date(Number(preprocessed.quoteDeadline) * 1000),
maxBpsToSponsor: preprocessed.maxBpsToSponsor.toString(),
maxUserSlippageBps: preprocessed.maxUserSlippageBps.toString(),
finalToken: finalToken.toLowerCase(),
signature: preprocessed.signature,
};
};
export const transformMessageSentEvent = (
preprocessed: MessageSentArgs,
payload: IndexerEventPayload,
Expand Down Expand Up @@ -165,25 +197,6 @@ export const transformMessageSentEvent = (
};
};

/**
* extracts and decodes a specific event from a transaction receipt's logs.
* @param receipt The transaction receipt.
* @param abi The Abi containing the event definition.
* @returns The decoded event arguments, or undefined if not found.
*/
export const decodeEventFromReceipt = <T>(
receipt: TransactionReceipt,
abi: Abi,
eventName: string,
): T | undefined => {
const logs = parseEventLogs({
abi,
logs: receipt.logs,
});
const log = logs.find((log) => log.eventName === eventName);
return (log?.args as T) ?? undefined;
};

/**
* Transforms a raw `MessageReceived` event payload into a partial `MessageReceived` entity.
* The 'finalised' property is set by the `baseTransformer` based on the event's block number
Expand Down
Loading