@@ -2,7 +2,7 @@ import { clients, constants, utils as sdkUtils } from "@across-protocol/sdk";
2
2
import { AcrossApiClient , ConfigStoreClient , MultiCallerClient , TokenClient } from "../src/clients" ;
3
3
import { FillStatus , V3Deposit , V3RelayData } from "../src/interfaces" ;
4
4
import { CONFIG_STORE_VERSION } from "../src/common" ;
5
- import { bnZero , bnOne , bnUint256Max , getNetworkName , getAllUnfilledDeposits } from "../src/utils" ;
5
+ import { averageBlockTime , bnZero , bnOne , bnUint256Max , getNetworkName , getAllUnfilledDeposits } from "../src/utils" ;
6
6
import { Relayer } from "../src/relayer/Relayer" ;
7
7
import { RelayerConfig } from "../src/relayer/RelayerConfig" ; // Tested
8
8
import {
@@ -499,6 +499,67 @@ describe("Relayer: Check for Unfilled Deposits and Fill", async function () {
499
499
expect ( lastSpyLogIncludes ( spy , "0 unfilled deposits found." ) ) . to . be . true ;
500
500
} ) ;
501
501
502
+ it ( "Correctly defers destination chain fills" , async function ( ) {
503
+ let { average : avgBlockTime } = await averageBlockTime ( spokePool_2 . provider ) ;
504
+ avgBlockTime = Math . ceil ( avgBlockTime ) ;
505
+ const minFillTime = 4 * avgBlockTime ; // Fill after deposit has aged 4 blocks.
506
+
507
+ relayerInstance = new Relayer (
508
+ relayer . address ,
509
+ spyLogger ,
510
+ {
511
+ spokePoolClients,
512
+ hubPoolClient,
513
+ configStoreClient,
514
+ tokenClient,
515
+ profitClient,
516
+ multiCallerClient,
517
+ inventoryClient : new MockInventoryClient ( null , null , null , null , null , hubPoolClient ) ,
518
+ acrossApiClient : new AcrossApiClient ( spyLogger , hubPoolClient , chainIds ) ,
519
+ } ,
520
+ {
521
+ minFillTime : { [ destinationChainId ] : minFillTime } ,
522
+ relayerTokens : [ ] ,
523
+ minDepositConfirmations : defaultMinDepositConfirmations ,
524
+ sendingRelaysEnabled : true ,
525
+ } as unknown as RelayerConfig
526
+ ) ;
527
+
528
+ const deposit = await depositV3 (
529
+ spokePool_1 ,
530
+ destinationChainId ,
531
+ depositor ,
532
+ inputToken ,
533
+ inputAmount ,
534
+ outputToken ,
535
+ outputAmount
536
+ ) ;
537
+ await updateAllClients ( ) ;
538
+ let txnReceipts = await relayerInstance . checkForUnfilledDepositsAndFill ( ) ;
539
+ for ( const receipts of Object . values ( txnReceipts ) ) {
540
+ expect ( ( await receipts ) . length ) . to . equal ( 0 ) ;
541
+ }
542
+ expect ( lastSpyLogIncludes ( spy , "due to insufficient fill time for" ) ) . to . be . true ;
543
+
544
+ // SpokePool time is overridden and does not increment; it must be cranked manually.
545
+ const startTime = Number ( await spokePool_2 . getCurrentTime ( ) ) ;
546
+ let nextTime : number ;
547
+ do {
548
+ await fillV3Relay (
549
+ spokePool_2 ,
550
+ { ...deposit , depositId : deposit . depositId + 1 , outputAmount : bnZero , recipient : randomAddress ( ) } ,
551
+ relayer
552
+ ) ;
553
+ nextTime = Number ( await spokePool_2 . getCurrentTime ( ) ) + avgBlockTime ;
554
+ await spokePool_2 . setCurrentTime ( nextTime ) ;
555
+ } while ( startTime + minFillTime > nextTime ) ;
556
+
557
+ await updateAllClients ( ) ;
558
+ txnReceipts = await relayerInstance . checkForUnfilledDepositsAndFill ( ) ;
559
+ const receipts = await txnReceipts [ destinationChainId ] ;
560
+ expect ( receipts . length ) . to . equal ( 1 ) ;
561
+ } ) ;
562
+
502
563
it ( "Correctly tracks origin chain fill commitments" , async function ( ) {
503
564
await erc20_2 . connect ( relayer ) . approve ( spokePool_2 . address , MAX_SAFE_ALLOWANCE ) ;
504
565
0 commit comments