Skip to content

Commit d0ea56d

Browse files
committed
Revert Base transfer sync from BitQuery back to CDP
Reverts PRs #954 and #956. BitQuery sync was fetching data but all transfers were rejected as duplicates due to the unique constraint (tx_hash, log_index, chain, block_timestamp) colliding with existing CDP rows. The resumeOverlapMs caused the cursor to go backwards 60s into CDP territory every run, creating an infinite loop of zero saves. CDP resumes from its last transfer at 2026-06-05T17:45:31Z. No data gap — CDP will backfill from that point to now via Coinbase.
1 parent 08ec3a7 commit d0ea56d

8 files changed

Lines changed: 24 additions & 259 deletions

File tree

sync/transfers/trigger/chains/evm/base/bitquery/config.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

sync/transfers/trigger/chains/evm/base/bitquery/query.ts

Lines changed: 0 additions & 120 deletions
This file was deleted.

sync/transfers/trigger/chains/evm/base/bitquery/sync.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

sync/transfers/trigger/chains/evm/base/cdp/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const baseCdpConfig: SyncConfig = {
1616
facilitators: FACILITATORS_BY_CHAIN(Network.BASE),
1717
buildQuery,
1818
transformResponse,
19-
enabled: false,
19+
enabled: true,
2020
machine: 'medium-1x',
2121
splitSyncByFacilitator: true,
2222
};

sync/transfers/trigger/fetch/bitquery/fetch.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export async function fetchWithOffsetPagination(
1414
facilitator: Facilitator,
1515
facilitatorConfig: FacilitatorConfig,
1616
since: Date,
17-
now: Date,
18-
onBatchFetched?: (batch: TransferEventData[]) => Promise<void>
17+
now: Date
1918
): Promise<TransferEventData[]> {
2019
const allTransfers = [];
2120
let offset = 0;
@@ -40,10 +39,6 @@ export async function fetchWithOffsetPagination(
4039

4140
allTransfers.push(...transfers);
4241

43-
if (onBatchFetched && transfers.length > 0) {
44-
await onBatchFetched(transfers);
45-
}
46-
4742
if (transfers.length < config.limit) {
4843
hasMore = false;
4944
} else {

sync/transfers/trigger/fetch/fetch.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ async function fetchWithOffset(
137137
facilitator,
138138
facilitatorConfig,
139139
since,
140-
now,
141-
onBatchFetched
140+
now
142141
);
143142

143+
if (onBatchFetched && results.length > 0) {
144+
await onBatchFetched(results);
145+
}
146+
144147
return { totalFetched: results.length };
145148
}
146149

sync/transfers/trigger/sync.ts

Lines changed: 17 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,6 @@ import { fetchTransfers } from './fetch/fetch';
55

66
import type { Facilitator, SyncConfig } from './types';
77

8-
type ResumeTransfer = Awaited<ReturnType<typeof getTransferEvents>>[number];
9-
10-
function normalizeTransactionFrom(chain: string, address: string): string {
11-
return chain === Network.SOLANA.toString() ? address : address.toLowerCase();
12-
}
13-
14-
function getResumeSince(
15-
latestTimestamp: Date | undefined,
16-
syncConfig: SyncConfig,
17-
syncStartDate: Date
18-
): Date {
19-
if (!latestTimestamp) {
20-
return syncStartDate;
21-
}
22-
23-
const resumeTimestamp =
24-
syncConfig.resumeOverlapMs !== undefined
25-
? latestTimestamp.getTime() - syncConfig.resumeOverlapMs
26-
: latestTimestamp.getTime() + 1000;
27-
28-
return new Date(Math.max(resumeTimestamp, syncStartDate.getTime()));
29-
}
30-
31-
async function getMostRecentTransferForResume(
32-
syncConfig: SyncConfig,
33-
transactionFrom: string,
34-
resumeFromProviders: string[]
35-
): Promise<ResumeTransfer | undefined> {
36-
const results = await Promise.all(
37-
resumeFromProviders.map(provider =>
38-
getTransferEvents({
39-
orderBy: { block_timestamp: 'desc' },
40-
take: 1,
41-
where: {
42-
chain: syncConfig.chain,
43-
transaction_from: transactionFrom,
44-
provider,
45-
},
46-
})
47-
)
48-
);
49-
50-
return results
51-
.flat()
52-
.sort(
53-
(a, b) => b.block_timestamp.getTime() - a.block_timestamp.getTime()
54-
)[0];
55-
}
56-
578
async function syncFacilitator(
589
syncConfig: SyncConfig,
5910
facilitator: Facilitator,
@@ -73,29 +24,27 @@ async function syncFacilitator(
7324
`[${syncConfig.chain}] Getting most recent transfer for ${facilitator.id}:${facilitatorConfig.address}`
7425
);
7526

76-
const resumeFromProviders = syncConfig.resumeFromProviders ?? [
77-
syncConfig.provider,
78-
];
79-
const transactionFrom = normalizeTransactionFrom(
80-
syncConfig.chain,
81-
facilitatorConfig.address
82-
);
83-
84-
const mostRecentTransfer = await getMostRecentTransferForResume(
85-
syncConfig,
86-
transactionFrom,
87-
resumeFromProviders
88-
);
27+
const mostRecentTransfer = await getTransferEvents({
28+
orderBy: { block_timestamp: 'desc' },
29+
take: 1,
30+
where: {
31+
chain: syncConfig.chain,
32+
transaction_from:
33+
syncConfig.chain === Network.SOLANA.toString()
34+
? facilitatorConfig.address
35+
: facilitatorConfig.address.toLowerCase(),
36+
provider: syncConfig.provider,
37+
},
38+
});
8939

9040
logger.log(
91-
`[${syncConfig.chain}] Most recent transfer from ${resumeFromProviders.join(',')}: ${mostRecentTransfer?.block_timestamp?.toISOString()}`
41+
`[${syncConfig.chain}] Most recent transfer: ${mostRecentTransfer[0]?.block_timestamp?.toISOString()}`
9242
);
9343

94-
const since = getResumeSince(
95-
mostRecentTransfer?.block_timestamp,
96-
syncConfig,
97-
facilitatorConfig.syncStartDate
98-
);
44+
// Start from 1 second after the most recent transfer to avoid re-fetching it
45+
const since = mostRecentTransfer[0]?.block_timestamp
46+
? new Date(mostRecentTransfer[0].block_timestamp.getTime() + 1000)
47+
: facilitatorConfig.syncStartDate;
9948

10049
logger.log(
10150
`[${syncConfig.chain}] Syncing ${facilitator.id}:${facilitatorConfig.address} from ${since.toISOString()} to ${now.toISOString()}`

sync/transfers/trigger/types.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ export type SyncConfig = QueryConfig & {
8080
enabled: boolean;
8181
machine: 'small-1x' | 'medium-1x' | 'large-2x';
8282
splitSyncByFacilitator?: boolean;
83-
resumeFromProviders?: QueryProvider[];
84-
resumeOverlapMs?: number;
8583
};
8684

8785
export interface EvmChainConfig {
@@ -149,35 +147,3 @@ export interface BitQueryTransferRowStream {
149147
From: string;
150148
};
151149
}
152-
153-
export interface EvmBitQueryTransferRow {
154-
Transfer: {
155-
Amount: string;
156-
Sender: string;
157-
Receiver: string;
158-
Index: number;
159-
Type: string;
160-
Success: boolean;
161-
Currency: {
162-
Name: string;
163-
SmartContract: string;
164-
Symbol: string;
165-
Decimals: number;
166-
};
167-
};
168-
Block: {
169-
Time: string;
170-
Number: string;
171-
};
172-
Transaction: {
173-
Hash: string;
174-
From: string;
175-
Index: number;
176-
};
177-
Log?: {
178-
Index: number | null;
179-
};
180-
Call?: {
181-
Index: number | null;
182-
};
183-
}

0 commit comments

Comments
 (0)