@@ -498,6 +498,106 @@ describe('L1Reservoir', () => {
498
498
. div ( 2 )
499
499
. add ( expectedTotalRewards . sub ( rewardsUntilSecondDripBlock ) . mul ( 8 ) . div ( 10 ) )
500
500
501
+ const tx2 = await l1Reservoir
502
+ . connect ( governor . signer )
503
+ . drip ( maxGas , gasPriceBid , maxSubmissionCost , { value : defaultEthValue } )
504
+ const newActualAmount = await grt . balanceOf ( l1Reservoir . address )
505
+ const newEscrowedAmount = await grt . balanceOf ( bridgeEscrow . address )
506
+ expect ( toRound ( newActualAmount ) ) . to . eq (
507
+ toRound ( expectedTotalRewards . sub ( expectedNewTotalSentToL2 ) ) ,
508
+ )
509
+ expect ( toRound ( ( await grt . totalSupply ( ) ) . sub ( supplyBeforeDrip ) ) ) . to . eq (
510
+ toRound ( expectedNewMintedAmount ) ,
511
+ )
512
+ expect ( toRound ( newEscrowedAmount ) ) . to . eq ( toRound ( expectedNewTotalSentToL2 ) )
513
+ normalizedTokenSupply = ( await l1Reservoir . tokenSupplyCache ( ) )
514
+ . mul ( await l1Reservoir . l2RewardsFraction ( ) )
515
+ . div ( toGRT ( '1' ) )
516
+ expectedCallhookData = l2ReservoirIface . encodeFunctionData ( 'receiveDrip' , [
517
+ normalizedTokenSupply ,
518
+ issuanceRate ,
519
+ toBN ( '1' ) , // Incremented nonce
520
+ ] )
521
+ expectedL2Data = await l1GraphTokenGateway . getOutboundCalldata (
522
+ grt . address ,
523
+ l1Reservoir . address ,
524
+ mockL2Reservoir . address ,
525
+ newEscrowedAmount . sub ( escrowedAmount ) ,
526
+ expectedCallhookData ,
527
+ )
528
+ await expect ( tx2 )
529
+ . emit ( l1GraphTokenGateway , 'TxToL2' )
530
+ . withArgs ( l1Reservoir . address , mockL2Gateway . address , toBN ( 2 ) , expectedL2Data )
531
+ await expect ( tx2 )
532
+ . emit ( l1Reservoir , 'RewardsDripped' )
533
+ . withArgs (
534
+ newActualAmount . add ( newEscrowedAmount ) . sub ( actualAmount . add ( escrowedAmount ) ) ,
535
+ newEscrowedAmount . sub ( escrowedAmount ) ,
536
+ expectedNewNextDeadline ,
537
+ )
538
+ } )
539
+ it ( 'sends the outstanding amount if the L2 rewards fraction stays constant' , async function ( ) {
540
+ await l1Reservoir . connect ( governor . signer ) . setL2RewardsFraction ( toGRT ( '0.5' ) )
541
+ await l1Reservoir . connect ( governor . signer ) . initialSnapshot ( toBN ( 0 ) )
542
+ supplyBeforeDrip = await grt . totalSupply ( )
543
+ const startAccrued = await l1Reservoir . getAccumulatedRewards ( await latestBlock ( ) )
544
+ expect ( startAccrued ) . to . eq ( 0 )
545
+ const dripBlock = ( await latestBlock ( ) ) . add ( 1 ) // We're gonna drip in the next transaction
546
+ const tracker = await RewardsTracker . create (
547
+ supplyBeforeDrip ,
548
+ defaults . rewards . issuanceRate ,
549
+ dripBlock ,
550
+ )
551
+ expect ( await tracker . accRewards ( dripBlock ) ) . to . eq ( 0 )
552
+ const expectedNextDeadline = dripBlock . add ( defaults . rewards . dripInterval )
553
+ const expectedMintedAmount = await tracker . accRewards ( expectedNextDeadline )
554
+ const expectedSentToL2 = expectedMintedAmount . div ( 2 )
555
+ const tx = await l1Reservoir
556
+ . connect ( governor . signer )
557
+ . drip ( maxGas , gasPriceBid , maxSubmissionCost , { value : defaultEthValue } )
558
+ const actualAmount = await grt . balanceOf ( l1Reservoir . address )
559
+ const escrowedAmount = await grt . balanceOf ( bridgeEscrow . address )
560
+ expect ( toRound ( actualAmount ) ) . to . eq ( toRound ( expectedMintedAmount . sub ( expectedSentToL2 ) ) )
561
+ expect ( toRound ( ( await grt . totalSupply ( ) ) . sub ( supplyBeforeDrip ) ) ) . to . eq (
562
+ toRound ( expectedMintedAmount ) ,
563
+ )
564
+ expect ( toRound ( escrowedAmount ) ) . to . eq ( toRound ( expectedSentToL2 ) )
565
+ await expect ( tx )
566
+ . emit ( l1Reservoir , 'RewardsDripped' )
567
+ . withArgs ( actualAmount . add ( escrowedAmount ) , escrowedAmount , expectedNextDeadline )
568
+
569
+ let normalizedTokenSupply = ( await l1Reservoir . tokenSupplyCache ( ) )
570
+ . mul ( await l1Reservoir . l2RewardsFraction ( ) )
571
+ . div ( toGRT ( '1' ) )
572
+ const issuanceRate = await l1Reservoir . issuanceRate ( )
573
+ let expectedCallhookData = l2ReservoirIface . encodeFunctionData ( 'receiveDrip' , [
574
+ normalizedTokenSupply ,
575
+ issuanceRate ,
576
+ toBN ( '0' ) ,
577
+ ] )
578
+ let expectedL2Data = await l1GraphTokenGateway . getOutboundCalldata (
579
+ grt . address ,
580
+ l1Reservoir . address ,
581
+ mockL2Reservoir . address ,
582
+ escrowedAmount ,
583
+ expectedCallhookData ,
584
+ )
585
+ await expect ( tx )
586
+ . emit ( l1GraphTokenGateway , 'TxToL2' )
587
+ . withArgs ( l1Reservoir . address , mockL2Gateway . address , toBN ( 1 ) , expectedL2Data )
588
+
589
+ await tracker . snapshotRewards ( )
590
+
591
+ supplyBeforeDrip = await grt . totalSupply ( )
592
+ const secondDripBlock = ( await latestBlock ( ) ) . add ( 1 )
593
+ const expectedNewNextDeadline = secondDripBlock . add ( defaults . rewards . dripInterval )
594
+ const rewardsUntilSecondDripBlock = await tracker . accRewards ( secondDripBlock )
595
+ const expectedTotalRewards = await tracker . accRewards ( expectedNewNextDeadline )
596
+ const expectedNewMintedAmount = expectedTotalRewards . sub ( expectedMintedAmount )
597
+ // The amount sent to L2 should cover up to the new drip block with the old fraction,
598
+ // and from then onwards with the new fraction
599
+ const expectedNewTotalSentToL2 = expectedTotalRewards . div ( 2 )
600
+
501
601
const tx2 = await l1Reservoir
502
602
. connect ( governor . signer )
503
603
. drip ( maxGas , gasPriceBid , maxSubmissionCost , { value : defaultEthValue } )
0 commit comments