@@ -159,6 +159,14 @@ describe("reservoir", () => {
159159 address1
160160 ) ;
161161
162+ // Add liquidity so amount check passes and we reach fee validation
163+ simnet . callPublicFn (
164+ "reservoir" ,
165+ "add-liquidity" ,
166+ [ Cl . none ( ) , Cl . uint ( 1000000 ) ] ,
167+ deployer
168+ ) ;
169+
162170 const mySignature = generateDepositSignature (
163171 address1PK ,
164172 null ,
@@ -554,6 +562,89 @@ describe("reservoir", () => {
554562 ) ;
555563 } ) ;
556564
565+ it ( "can borrow liquidity with zero fee when borrow rate is zero" , ( ) => {
566+ // borrow-rate is u0 from init
567+ const { result : feeResult } = simnet . callReadOnlyFn (
568+ "reservoir" ,
569+ "get-borrow-fee" ,
570+ [ Cl . uint ( 50000 ) ] ,
571+ deployer
572+ ) ;
573+ expect ( feeResult ) . toBeUint ( 0 ) ;
574+
575+ // Add liquidity to reservoir
576+ simnet . callPublicFn (
577+ "reservoir" ,
578+ "add-liquidity" ,
579+ [ Cl . none ( ) , Cl . uint ( 5000000000 ) ] ,
580+ deployer
581+ ) ;
582+
583+ // Fund initial tap
584+ const { result } = simnet . callPublicFn (
585+ "reservoir" ,
586+ "create-tap" ,
587+ [
588+ Cl . principal ( stackflowContract ) ,
589+ Cl . none ( ) ,
590+ Cl . uint ( 1000000 ) ,
591+ Cl . uint ( 0 ) ,
592+ ] ,
593+ address1
594+ ) ;
595+ expect ( result . type ) . toBe ( ClarityType . ResponseOk ) ;
596+
597+ const amount = 50000 ;
598+ const fee = 0 ;
599+
600+ const mySignature = generateDepositSignature (
601+ address1PK ,
602+ null ,
603+ address1 ,
604+ reservoirContract ,
605+ 1000000 ,
606+ 50000 ,
607+ 1 ,
608+ reservoirContract
609+ ) ;
610+
611+ const reservoirSignature = generateDepositSignature (
612+ deployerPK ,
613+ null ,
614+ reservoirContract ,
615+ address1 ,
616+ 50000 ,
617+ 1000000 ,
618+ 1 ,
619+ reservoirContract
620+ ) ;
621+
622+ const borrow = simnet . callPublicFn (
623+ "reservoir" ,
624+ "borrow-liquidity" ,
625+ [
626+ Cl . principal ( stackflowContract ) ,
627+ Cl . uint ( amount ) ,
628+ Cl . uint ( fee ) ,
629+ Cl . none ( ) ,
630+ Cl . uint ( 1000000 ) ,
631+ Cl . uint ( 50000 ) ,
632+ Cl . buffer ( mySignature ) ,
633+ Cl . buffer ( reservoirSignature ) ,
634+ Cl . uint ( 1 ) ,
635+ ] ,
636+ address1
637+ ) ;
638+ expect ( borrow . result ) . toBeOk (
639+ Cl . uint ( simnet . burnBlockHeight + BORROW_TERM_BLOCKS )
640+ ) ;
641+
642+ // 5000000000 - 50000 (borrowed), with no fee transfer
643+ const stxBalances = simnet . getAssetsMap ( ) . get ( "STX" ) ! ;
644+ const reservoirBalance = stxBalances . get ( reservoirContract ) ;
645+ expect ( reservoirBalance ) . toBe ( 4999950000n ) ;
646+ } ) ;
647+
557648 it ( "can borrow additional liquidity before previous term ends" , ( ) => {
558649 // Set rate to 10% and fund the reservoir
559650 simnet . callPublicFn (
@@ -764,7 +855,7 @@ describe("reservoir", () => {
764855 ] ,
765856 address1
766857 ) ;
767- expect ( result ) . toBeErr ( Cl . uint ( StackflowError . DepositFailed ) ) ;
858+ expect ( result ) . toBeErr ( Cl . uint ( ReservoirError . AmountNotAvailable ) ) ;
768859 } ) ;
769860 } ) ;
770861
0 commit comments