From df5d1b4de0d8dbb3432a1d9060e8efdc20243794 Mon Sep 17 00:00:00 2001 From: Andrew Redden Date: Mon, 11 Dec 2023 10:43:26 -0400 Subject: [PATCH] include refinance update --- src/Starport.sol | 8 +++++++- test/StarportTest.sol | 2 +- test/fuzz-testing/TestFuzzStarport.sol | 10 +++++++--- test/integration-testing/TestCaveats.sol | 12 ++++++------ test/unit-testing/TestStarport.sol | 6 +++--- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Starport.sol b/src/Starport.sol index f3e0a1f2..12a58ebb 100644 --- a/src/Starport.sol +++ b/src/Starport.sol @@ -31,6 +31,7 @@ import {CaveatEnforcer} from "./enforcers/CaveatEnforcer.sol"; import {Custodian} from "./Custodian.sol"; import {PausableNonReentrant} from "./lib/PausableNonReentrant.sol"; import {Pricing} from "./pricing/Pricing.sol"; +import {Status} from "./status/Status.sol"; import {Settlement} from "./settlement/Settlement.sol"; import {StarportLib, AdditionalTransfer} from "./lib/StarportLib.sol"; @@ -61,6 +62,7 @@ contract Starport is PausableNonReentrant { error InvalidCaveatSigner(); error InvalidCustodian(); error InvalidLoan(); + error InvalidLoanState(); error InvalidPostRepayment(); error InvalidRefinance(); error LoanExists(); @@ -248,11 +250,15 @@ contract Starport is PausableNonReentrant { address lender, CaveatEnforcer.SignedCaveats calldata lenderCaveat, Starport.Loan memory loan, - bytes calldata pricingData + bytes calldata pricingData, + bytes calldata statusData ) external pausableNonReentrant { if (loan.start == block.timestamp) { revert InvalidLoan(); } + if (!Status(loan.terms.status).isActive(loan, statusData)) { + revert InvalidLoanState(); + } ( SpentItem[] memory considerationPayment, SpentItem[] memory carryPayment, diff --git a/test/StarportTest.sol b/test/StarportTest.sol index bd351fc0..c766db83 100644 --- a/test/StarportTest.sol +++ b/test/StarportTest.sol @@ -501,7 +501,7 @@ contract StarportTest is BaseOrderTest, Stargate { if (revertMessage.length > 0) { vm.expectRevert(revertMessage); //reverts InvalidContractOfferer with an address an a contract nonce so expect general revert } - SP.refinance(lender, lenderCaveat, loan, pricingData); + SP.refinance(lender, lenderCaveat, loan, pricingData, ""); vm.stopPrank(); diff --git a/test/fuzz-testing/TestFuzzStarport.sol b/test/fuzz-testing/TestFuzzStarport.sol index bd25afac..344e6d76 100644 --- a/test/fuzz-testing/TestFuzzStarport.sol +++ b/test/fuzz-testing/TestFuzzStarport.sol @@ -599,8 +599,11 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq { Account memory account = makeAndAllocateAccount(params.refiKey); address refiFulfiller; - skip(1); - skip(_boundMax(params.skipTime, abi.decode(goodLoan.terms.statusData, (FixedTermStatus.Details)).loanDuration)); + skip( + _bound( + params.skipTime, 1, abi.decode(goodLoan.terms.statusData, (FixedTermStatus.Details)).loanDuration - 1 + ) + ); ( SpentItem[] memory considerationPayment, SpentItem[] memory carryPayment, @@ -641,7 +644,8 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq { account.addr, refiFulfiller != account.addr ? lenderCaveat : _emptyCaveat(), goodLoan2, - abi.encode(newPricingDetails) + abi.encode(newPricingDetails), + "" ); } } diff --git a/test/integration-testing/TestCaveats.sol b/test/integration-testing/TestCaveats.sol index 8fe7875a..feb00f81 100644 --- a/test/integration-testing/TestCaveats.sol +++ b/test/integration-testing/TestCaveats.sol @@ -255,7 +255,7 @@ contract IntegrationTestCaveats is StarportTest, DeepEq, MockCall { vm.warp(block.timestamp + 1); mockIsValidRefinanceCall(loan.terms.pricing, loan.debt, new SpentItem[](0), new AdditionalTransfer[](0)); vm.expectRevert(StarportLib.InvalidSalt.selector); - SP.refinance(lender.addr, lenderCaveat, loan, ""); + SP.refinance(lender.addr, lenderCaveat, loan, "", ""); } function testRefinanceAsLender() public { @@ -268,7 +268,7 @@ contract IntegrationTestCaveats is StarportTest, DeepEq, MockCall { vm.warp(block.timestamp + 1); vm.prank(newLender); mockIsValidRefinanceCall(loan.terms.pricing, loan.debt, new SpentItem[](0), new AdditionalTransfer[](0)); - SP.refinance(newLender, _emptyCaveat(), loan, defaultPricingData); + SP.refinance(newLender, _emptyCaveat(), loan, defaultPricingData, ""); } function testRefinanceWLenderApproval() public { @@ -282,7 +282,7 @@ contract IntegrationTestCaveats is StarportTest, DeepEq, MockCall { vm.warp(block.timestamp + 1); vm.prank(borrower.addr); mockIsValidRefinanceCall(loan.terms.pricing, loan.debt, new SpentItem[](0), new AdditionalTransfer[](0)); - SP.refinance(lender.addr, _emptyCaveat(), loan, defaultPricingData); + SP.refinance(lender.addr, _emptyCaveat(), loan, defaultPricingData, ""); } function testRefinanceUnapprovedFulfiller() public { @@ -311,7 +311,7 @@ contract IntegrationTestCaveats is StarportTest, DeepEq, MockCall { mockIsValidRefinanceCall(loan.terms.pricing, loan.debt, new SpentItem[](0), new AdditionalTransfer[](0)); - SP.refinance(lender.addr, lenderCaveat, loan, defaultPricingData); + SP.refinance(lender.addr, lenderCaveat, loan, defaultPricingData, ""); } function testRefinanceCaveatFailure() public { @@ -330,7 +330,7 @@ contract IntegrationTestCaveats is StarportTest, DeepEq, MockCall { vm.prank(loan.borrower); mockIsValidRefinanceCall(loan.terms.pricing, loan.debt, new SpentItem[](0), new AdditionalTransfer[](0)); vm.expectRevert(LenderEnforcer.InvalidLoanTerms.selector); - SP.refinance(lender.addr, lenderCaveat, loan, defaultPricingData); + SP.refinance(lender.addr, lenderCaveat, loan, defaultPricingData, ""); } function testRefinanceLoanStartAtBlockTimestampInvalidLoan() public { @@ -347,6 +347,6 @@ contract IntegrationTestCaveats is StarportTest, DeepEq, MockCall { vm.prank(loan.borrower); vm.expectRevert(Starport.InvalidLoan.selector); - SP.refinance(lender.addr, lenderCaveat, loan, defaultPricingData); + SP.refinance(lender.addr, lenderCaveat, loan, defaultPricingData, ""); } } diff --git a/test/unit-testing/TestStarport.sol b/test/unit-testing/TestStarport.sol index ffc971c6..0a2bf287 100644 --- a/test/unit-testing/TestStarport.sol +++ b/test/unit-testing/TestStarport.sol @@ -962,7 +962,7 @@ contract TestStarport is StarportTest, DeepEq { skip(1); uint256 borrowerBalanceBefore = erc20s[0].balanceOf(address(activeLoan.borrower)); vm.startPrank(lender.addr); - SP.refinance(lender.addr, _emptyCaveat(), activeLoan, newPricingData); + SP.refinance(lender.addr, _emptyCaveat(), activeLoan, newPricingData, ""); assert(erc20s[0].balanceOf(address(activeLoan.borrower)) == borrowerBalanceBefore + 20); } @@ -981,7 +981,7 @@ contract TestStarport is StarportTest, DeepEq { skip(1); vm.expectRevert(abi.encodeWithSelector(Starport.InvalidPostRepayment.selector)); vm.startPrank(lender.addr); - SP.refinance(lender.addr, _emptyCaveat(), activeLoan, newPricingData); + SP.refinance(lender.addr, _emptyCaveat(), activeLoan, newPricingData, ""); } function testInvalidAdditionalTransfersRefinance() public { @@ -1009,6 +1009,6 @@ contract TestStarport is StarportTest, DeepEq { skip(1); vm.startPrank(lender.addr); vm.expectRevert(abi.encodeWithSelector(Starport.UnauthorizedAdditionalTransferIncluded.selector)); - SP.refinance(lender.addr, _emptyCaveat(), activeLoan, newPricingData); + SP.refinance(lender.addr, _emptyCaveat(), activeLoan, newPricingData, ""); } }