@@ -13,7 +13,7 @@ import {
1313} from "../typechain-types" ;
1414
1515const INCREASE = true ;
16- // const DECREASE = false;
16+ const DECREASE = false ;
1717
1818describe ( "LiquidityHub" , function ( ) {
1919 const deployAll = async ( ) => {
@@ -463,4 +463,128 @@ describe("LiquidityHub", function () {
463463 await expect ( liquidityHub . connect ( user ) . adjustTotalAssets ( 0n , INCREASE ) )
464464 . to . be . revertedWithCustomError ( liquidityHub , "AccessControlUnauthorizedAccount(address,bytes32)" ) ;
465465 } ) ;
466+
467+ it ( "Should process deposits after adjustment with increased assets" , async function ( ) {
468+ const {
469+ lpToken, liquidityHub, usdc, deployer, user, user2, USDC , LP ,
470+ liquidityPool, admin,
471+ } = await loadFixture ( deployAll ) ;
472+
473+ await usdc . connect ( deployer ) . transfer ( user . address , 20n * USDC ) ;
474+ await usdc . connect ( deployer ) . transfer ( user2 . address , 40n * USDC ) ;
475+ await usdc . connect ( user ) . approve ( liquidityHub . target , 20n * USDC ) ;
476+ await usdc . connect ( user2 ) . approve ( liquidityHub . target , 40n * USDC ) ;
477+ await liquidityHub . connect ( user ) . deposit ( 10n * USDC , user . address ) ;
478+ await liquidityHub . connect ( user2 ) . deposit ( 20n * USDC , user2 . address ) ;
479+ await liquidityHub . connect ( admin ) . adjustTotalAssets ( 0n , INCREASE ) ;
480+ expect ( await lpToken . balanceOf ( user . address ) ) . to . equal ( 0n ) ;
481+ expect ( await lpToken . balanceOf ( user2 . address ) ) . to . equal ( 0n ) ;
482+ expect ( await lpToken . totalSupply ( ) ) . to . equal ( 0n ) ;
483+ expect ( await liquidityHub . totalSupply ( ) ) . to . equal ( 30n * LP ) ;
484+ expect ( await liquidityHub . totalAssets ( ) ) . to . equal ( 30n * USDC ) ;
485+ expect ( await liquidityHub . releasedAssets ( ) ) . to . equal ( 0n ) ;
486+ expect ( await liquidityHub . balanceOf ( user . address ) ) . to . equal ( 10n * LP ) ;
487+ expect ( await liquidityHub . balanceOf ( user2 . address ) ) . to . equal ( 20n * LP ) ;
488+ expect ( await usdc . balanceOf ( user . address ) ) . to . equal ( 10n * USDC ) ;
489+ expect ( await usdc . balanceOf ( user2 . address ) ) . to . equal ( 20n * USDC ) ;
490+ expect ( await usdc . balanceOf ( liquidityPool . target ) ) . to . equal ( 30n * USDC ) ;
491+ expect ( await usdc . balanceOf ( liquidityHub . target ) ) . to . equal ( 0n ) ;
492+
493+ await liquidityHub . connect ( user ) . deposit ( 10n * USDC , user . address ) ;
494+ await liquidityHub . connect ( user2 ) . deposit ( 20n * USDC , user2 . address ) ;
495+ await liquidityHub . connect ( admin ) . adjustTotalAssets ( 120n * USDC , INCREASE ) ;
496+ expect ( await lpToken . balanceOf ( user . address ) ) . to . equal ( 10n * LP ) ;
497+ expect ( await lpToken . balanceOf ( user2 . address ) ) . to . equal ( 20n * LP ) ;
498+ expect ( await lpToken . totalSupply ( ) ) . to . equal ( 30n * LP ) ;
499+ expect ( await liquidityHub . totalSupply ( ) ) . to . equal ( 36n * LP ) ;
500+ expect ( await liquidityHub . totalAssets ( ) ) . to . equal ( 180n * USDC ) ;
501+ expect ( await liquidityHub . releasedAssets ( ) ) . to . equal ( 0n ) ;
502+ expect ( await liquidityHub . balanceOf ( user . address ) ) . to . equal ( 12n * LP ) ;
503+ expect ( await liquidityHub . balanceOf ( user2 . address ) ) . to . equal ( 24n * LP ) ;
504+ expect ( await usdc . balanceOf ( user . address ) ) . to . equal ( 0n ) ;
505+ expect ( await usdc . balanceOf ( user2 . address ) ) . to . equal ( 0n ) ;
506+ expect ( await usdc . balanceOf ( liquidityPool . target ) ) . to . equal ( 60n * USDC ) ;
507+ expect ( await usdc . balanceOf ( liquidityHub . target ) ) . to . equal ( 0n ) ;
508+
509+ await liquidityHub . settle ( user . address ) ;
510+ await liquidityHub . settle ( user2 . address ) ;
511+ expect ( await lpToken . balanceOf ( user . address ) ) . to . equal ( 12n * LP ) ;
512+ expect ( await lpToken . balanceOf ( user2 . address ) ) . to . equal ( 24n * LP ) ;
513+ expect ( await lpToken . totalSupply ( ) ) . to . equal ( 36n * LP ) ;
514+ expect ( await liquidityHub . totalSupply ( ) ) . to . equal ( 36n * LP ) ;
515+ expect ( await liquidityHub . totalAssets ( ) ) . to . equal ( 180n * USDC ) ;
516+ expect ( await liquidityHub . releasedAssets ( ) ) . to . equal ( 0n ) ;
517+ expect ( await liquidityHub . balanceOf ( user . address ) ) . to . equal ( 12n * LP ) ;
518+ expect ( await liquidityHub . balanceOf ( user2 . address ) ) . to . equal ( 24n * LP ) ;
519+ expect ( await usdc . balanceOf ( user . address ) ) . to . equal ( 0n ) ;
520+ expect ( await usdc . balanceOf ( user2 . address ) ) . to . equal ( 0n ) ;
521+ expect ( await usdc . balanceOf ( liquidityPool . target ) ) . to . equal ( 60n * USDC ) ;
522+ expect ( await usdc . balanceOf ( liquidityHub . target ) ) . to . equal ( 0n ) ;
523+ } ) ;
524+
525+ it ( "Should process deposits after adjustment with decreased assets" , async function ( ) {
526+ const {
527+ lpToken, liquidityHub, usdc, deployer, user, user2, USDC , LP ,
528+ liquidityPool, admin,
529+ } = await loadFixture ( deployAll ) ;
530+
531+ await usdc . connect ( deployer ) . transfer ( user . address , 20n * USDC ) ;
532+ await usdc . connect ( deployer ) . transfer ( user2 . address , 40n * USDC ) ;
533+ await usdc . connect ( user ) . approve ( liquidityHub . target , 20n * USDC ) ;
534+ await usdc . connect ( user2 ) . approve ( liquidityHub . target , 40n * USDC ) ;
535+ await liquidityHub . connect ( user ) . deposit ( 10n * USDC , user . address ) ;
536+ await liquidityHub . connect ( user2 ) . deposit ( 20n * USDC , user2 . address ) ;
537+ await liquidityHub . connect ( admin ) . adjustTotalAssets ( 0n , INCREASE ) ;
538+ expect ( await lpToken . balanceOf ( user . address ) ) . to . equal ( 0n ) ;
539+ expect ( await lpToken . balanceOf ( user2 . address ) ) . to . equal ( 0n ) ;
540+ expect ( await lpToken . totalSupply ( ) ) . to . equal ( 0n ) ;
541+ expect ( await liquidityHub . totalSupply ( ) ) . to . equal ( 30n * LP ) ;
542+ expect ( await liquidityHub . totalAssets ( ) ) . to . equal ( 30n * USDC ) ;
543+ expect ( await liquidityHub . releasedAssets ( ) ) . to . equal ( 0n ) ;
544+ expect ( await liquidityHub . balanceOf ( user . address ) ) . to . equal ( 10n * LP ) ;
545+ expect ( await liquidityHub . balanceOf ( user2 . address ) ) . to . equal ( 20n * LP ) ;
546+ expect ( await usdc . balanceOf ( user . address ) ) . to . equal ( 10n * USDC ) ;
547+ expect ( await usdc . balanceOf ( user2 . address ) ) . to . equal ( 20n * USDC ) ;
548+ expect ( await usdc . balanceOf ( liquidityPool . target ) ) . to . equal ( 30n * USDC ) ;
549+ expect ( await usdc . balanceOf ( liquidityHub . target ) ) . to . equal ( 0n ) ;
550+
551+ await liquidityHub . connect ( user ) . deposit ( 10n * USDC , user . address ) ;
552+ await liquidityHub . connect ( user2 ) . deposit ( 20n * USDC , user2 . address ) ;
553+ await liquidityHub . connect ( admin ) . adjustTotalAssets ( 20n * USDC , DECREASE ) ;
554+ expect ( await lpToken . balanceOf ( user . address ) ) . to . equal ( 10n * LP ) ;
555+ expect ( await lpToken . balanceOf ( user2 . address ) ) . to . equal ( 20n * LP ) ;
556+ expect ( await lpToken . totalSupply ( ) ) . to . equal ( 30n * LP ) ;
557+ expect ( await liquidityHub . totalSupply ( ) ) . to . equal ( 120n * LP ) ;
558+ expect ( await liquidityHub . totalAssets ( ) ) . to . equal ( 40n * USDC ) ;
559+ expect ( await liquidityHub . releasedAssets ( ) ) . to . equal ( 0n ) ;
560+ expect ( await liquidityHub . balanceOf ( user . address ) ) . to . equal ( 40n * LP ) ;
561+ expect ( await liquidityHub . balanceOf ( user2 . address ) ) . to . equal ( 80n * LP ) ;
562+ expect ( await usdc . balanceOf ( user . address ) ) . to . equal ( 0n ) ;
563+ expect ( await usdc . balanceOf ( user2 . address ) ) . to . equal ( 0n ) ;
564+ expect ( await usdc . balanceOf ( liquidityPool . target ) ) . to . equal ( 60n * USDC ) ;
565+ expect ( await usdc . balanceOf ( liquidityHub . target ) ) . to . equal ( 0n ) ;
566+
567+ await liquidityHub . settle ( user . address ) ;
568+ await liquidityHub . settle ( user2 . address ) ;
569+ expect ( await lpToken . balanceOf ( user . address ) ) . to . equal ( 40n * LP ) ;
570+ expect ( await lpToken . balanceOf ( user2 . address ) ) . to . equal ( 80n * LP ) ;
571+ expect ( await lpToken . totalSupply ( ) ) . to . equal ( 120n * LP ) ;
572+ expect ( await liquidityHub . totalSupply ( ) ) . to . equal ( 120n * LP ) ;
573+ expect ( await liquidityHub . totalAssets ( ) ) . to . equal ( 40n * USDC ) ;
574+ expect ( await liquidityHub . releasedAssets ( ) ) . to . equal ( 0n ) ;
575+ expect ( await liquidityHub . balanceOf ( user . address ) ) . to . equal ( 40n * LP ) ;
576+ expect ( await liquidityHub . balanceOf ( user2 . address ) ) . to . equal ( 80n * LP ) ;
577+ expect ( await usdc . balanceOf ( user . address ) ) . to . equal ( 0n ) ;
578+ expect ( await usdc . balanceOf ( user2 . address ) ) . to . equal ( 0n ) ;
579+ expect ( await usdc . balanceOf ( liquidityPool . target ) ) . to . equal ( 60n * USDC ) ;
580+ expect ( await usdc . balanceOf ( liquidityHub . target ) ) . to . equal ( 0n ) ;
581+ } ) ;
582+
583+ it . skip ( "Should process withdrawals after adjustment with increased assets" , async function ( ) { } ) ;
584+
585+ it . skip ( "Should process withdrawals after adjustment with decreased assets" , async function ( ) { } ) ;
586+
587+ it . skip ( "Should process deposits and withdrawals after adjustment with increased assets" , async function ( ) { } ) ;
588+
589+ it . skip ( "Should process deposits and withdrawals after adjustment with decreased assets" , async function ( ) { } ) ;
466590} ) ;
0 commit comments