@@ -5,6 +5,27 @@ import { fetchTransfers } from './fetch/fetch';
55
66import type { Facilitator , SyncConfig } from './types' ;
77
8+ function normalizeTransactionFrom ( chain : string , address : string ) : string {
9+ return chain === Network . SOLANA . toString ( ) ? address : address . toLowerCase ( ) ;
10+ }
11+
12+ function getResumeSince (
13+ latestTimestamp : Date | undefined ,
14+ syncConfig : SyncConfig ,
15+ syncStartDate : Date
16+ ) : Date {
17+ if ( ! latestTimestamp ) {
18+ return syncStartDate ;
19+ }
20+
21+ const resumeTimestamp =
22+ syncConfig . resumeOverlapMs !== undefined
23+ ? latestTimestamp . getTime ( ) - syncConfig . resumeOverlapMs
24+ : latestTimestamp . getTime ( ) + 1000 ;
25+
26+ return new Date ( Math . max ( resumeTimestamp , syncStartDate . getTime ( ) ) ) ;
27+ }
28+
829async function syncFacilitator (
930 syncConfig : SyncConfig ,
1031 facilitator : Facilitator ,
@@ -24,27 +45,32 @@ async function syncFacilitator(
2445 `[${ syncConfig . chain } ] Getting most recent transfer for ${ facilitator . id } :${ facilitatorConfig . address } `
2546 ) ;
2647
48+ const resumeFromProviders = syncConfig . resumeFromProviders ?? [
49+ syncConfig . provider ,
50+ ] ;
51+
2752 const mostRecentTransfer = await getTransferEvents ( {
2853 orderBy : { block_timestamp : 'desc' } ,
2954 take : 1 ,
3055 where : {
3156 chain : syncConfig . chain ,
32- transaction_from :
33- syncConfig . chain === Network . SOLANA . toString ( )
34- ? facilitatorConfig . address
35- : facilitatorConfig . address . toLowerCase ( ) ,
36- provider : syncConfig . provider ,
57+ transaction_from : normalizeTransactionFrom (
58+ syncConfig . chain ,
59+ facilitatorConfig . address
60+ ) ,
61+ provider : { in : resumeFromProviders } ,
3762 } ,
3863 } ) ;
3964
4065 logger . log (
41- `[${ syncConfig . chain } ] Most recent transfer: ${ mostRecentTransfer [ 0 ] ?. block_timestamp ?. toISOString ( ) } `
66+ `[${ syncConfig . chain } ] Most recent transfer from ${ resumeFromProviders . join ( ',' ) } : ${ mostRecentTransfer [ 0 ] ?. block_timestamp ?. toISOString ( ) } `
4267 ) ;
4368
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 ;
69+ const since = getResumeSince (
70+ mostRecentTransfer [ 0 ] ?. block_timestamp ,
71+ syncConfig ,
72+ facilitatorConfig . syncStartDate
73+ ) ;
4874
4975 logger . log (
5076 `[${ syncConfig . chain } ] Syncing ${ facilitator . id } :${ facilitatorConfig . address } from ${ since . toISOString ( ) } to ${ now . toISOString ( ) } `
0 commit comments