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
3 changes: 3 additions & 0 deletions packages/indexer-api/src/dtos/deposits.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const DepositsParams = s.object({
integratorId: s.optional(s.string()),
status: s.optional(s.enums(Object.values(entities.RelayStatus))),
depositType: s.optional(DepositType), // Filter by deposit type: "across" (V3FundsDeposited), "cctp" (DepositForBurn), or "oft" (OFTSent)
startBlock: s.optional(stringToInt),
endBlock: s.optional(stringToInt),
// some kind of pagination options, skip could be the start point
skip: s.optional(stringToInt),
// pagination limit, how many to return after the start, note we convert string to number
Expand Down Expand Up @@ -156,6 +158,7 @@ export type DepositReturnType = {

// from fill
relayer?: string;
fillBlockNumber?: number;
fillBlockTimestamp?: Date;
fillTx?: string | null; // Renamed from fillTransactionHash

Expand Down
33 changes: 33 additions & 0 deletions packages/indexer-api/src/services/deposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,39 @@ export class DepositsService {
oftSentQueryBuilder.andWhere("1 = 0");
}

if (params.startBlock) {
fundsDepositedQueryBuilder.andWhere(
"deposit.blockNumber >= :startBlock",
{
startBlock: params.startBlock,
},
);
depositForBurnQueryBuilder.andWhere(
"depositForBurn.blockNumber >= :startBlock",
{
startBlock: params.startBlock,
},
);
oftSentQueryBuilder.andWhere("oftSent.blockNumber >= :startBlock", {
startBlock: params.startBlock,
});
}

if (params.endBlock) {
fundsDepositedQueryBuilder.andWhere("deposit.blockNumber <= :endBlock", {
endBlock: params.endBlock,
});
depositForBurnQueryBuilder.andWhere(
"depositForBurn.blockNumber <= :endBlock",
{
endBlock: params.endBlock,
},
);
oftSentQueryBuilder.andWhere("oftSent.blockNumber <= :endBlock", {
endBlock: params.endBlock,
});
}

// Calculate upper bound for fetching records from each query
// We fetch more than needed to ensure we have enough after sorting
const skip = params.skip || 0;
Expand Down
5 changes: 5 additions & 0 deletions packages/indexer-api/src/tests/deposits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ describe("Deposits Service Tests", () => {
swapData.swapTokenAmount,
);
expect(queriedDeposit?.relayer).to.equal(filledRelayData.relayer);
expect(queriedDeposit?.fillBlockNumber).to.equal(
filledRelayData.blockNumber,
);
expect(queriedDeposit?.status).to.equal(relayHashInfoData.status);
});

Expand Down Expand Up @@ -478,6 +481,7 @@ describe("Deposits Service Tests", () => {
expect(cctpDeposit?.inputAmount).to.equal("1000000");
expect(cctpDeposit?.depositor).to.equal("0xdepositor");
expect(cctpDeposit?.recipient).to.equal("0xrecipient");
expect(cctpDeposit?.fillBlockNumber).to.equal(2000);
});

it("should return OFTSent deposits with OFTReceived", async () => {
Expand Down Expand Up @@ -528,5 +532,6 @@ describe("Deposits Service Tests", () => {
expect(oftDeposit?.depositor).to.equal("0xfrom");
expect(oftDeposit?.inputAmount).to.equal("3000000");
expect(oftDeposit?.outputAmount).to.equal("2900000");
expect(oftDeposit?.fillBlockNumber).to.equal(4000);
});
});
3 changes: 3 additions & 0 deletions packages/indexer-api/src/utils/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const RelayHashInfoFields = [

export const FilledRelayFields = [
`fill.relayer::varchar as "relayer"`,
`fill."blockNumber"::integer as "fillBlockNumber"`,
`fill."blockTimestamp"::timestamp as "fillBlockTimestamp"`,
`fill."transactionHash"::varchar as "fillTx"`, // Renamed field
];
Expand Down Expand Up @@ -102,6 +103,7 @@ export const DepositForBurnRelayHashInfoFields = [

export const DepositForBurnFilledRelayFields = [
`NULL::varchar as "relayer"`,
`"mintAndWithdraw"."blockNumber"::integer as "fillBlockNumber"`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible we might get into some trouble with the naming here?
fillBlockNumber is not really a fill, but a mint, no?

`"mintAndWithdraw"."blockTimestamp"::timestamp as "fillBlockTimestamp"`,
`"mintAndWithdraw"."transactionHash"::varchar as "fillTx"`,
];
Expand Down Expand Up @@ -159,6 +161,7 @@ export const OftSentRelayHashInfoFields = [

export const OftSentFilledRelayFields = [
`NULL::varchar as "relayer"`,
`"oftReceived"."blockNumber"::integer as "fillBlockNumber"`,
`"oftReceived"."blockTimestamp"::timestamp as "fillBlockTimestamp"`,
`"oftReceived"."transactionHash"::varchar as "fillTx"`,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CctpFinalizerJob } from "../CctpFinalizerJob";
])
@Index("IX_depositForBurn_finalised", ["finalised"])
@Index("IX_depositForBurn_deletedAt", ["deletedAt"])
@Index("IX_depositForBurn_chainId_blockNumber", ["chainId", "blockNumber"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Will the blockNumber query parameters always be used alongside chainId?
Keep in mind that with this IX, blockNumber index won't be used by postgres if chainId is missing from the request parameters.

Also, I think this index is redundant and doesn't bring any performance improvements because we already have UK_depositForBurn_chain_block_txn_log index. The first 2 columns from there are identical to your columns.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given the conversation we had, we can remove this index

export class DepositForBurn {
@PrimaryGeneratedColumn()
id: number;
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-database/src/entities/evm/OftSent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
])
@Index("IX_oftSent_finalised", ["finalised"])
@Index("IX_oftSent_deletedAt", ["deletedAt"])
@Index("IX_oftSent_chainId_blockNumber", ["chainId", "blockNumber"])
export class OFTSent {
@PrimaryGeneratedColumn()
id: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import { RelayHashInfo } from "../RelayHashInfo";
"originChainId",
"depositId",
])
@Index("IX_v3FundsDeposited_originChainId_blockNumber", [
"originChainId",
"blockNumber",
])
Comment on lines +39 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not 100% sure but I think we can remove this because we have the IX_deposits_block_chain_logIndex index

@Index("IX_v3FundsDeposited_internalHash", ["internalHash"])
export class V3FundsDeposited {
@PrimaryGeneratedColumn()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from "typeorm";

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE INDEX "IX_v3FundsDeposited_originChainId_blockNumber" ON "evm"."v3_funds_deposited" ("originChainId", "blockNumber") `,
);
await queryRunner.query(
`CREATE INDEX "IX_depositForBurn_chainId_blockNumber" ON "evm"."deposit_for_burn" ("chainId", "blockNumber") `,
);
await queryRunner.query(
`CREATE INDEX "IX_oftSent_chainId_blockNumber" ON "evm"."oft_sent" ("chainId", "blockNumber") `,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX "evm"."IX_oftSent_chainId_blockNumber"`,
);
await queryRunner.query(
`DROP INDEX "evm"."IX_depositForBurn_chainId_blockNumber"`,
);
await queryRunner.query(
`DROP INDEX "evm"."IX_v3FundsDeposited_originChainId_blockNumber"`,
);
}
}