Skip to content

Commit

Permalink
include refinance update
Browse files Browse the repository at this point in the history
  • Loading branch information
androolloyd committed Dec 11, 2023
1 parent 04bf816 commit df5d1b4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/Starport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -61,6 +62,7 @@ contract Starport is PausableNonReentrant {
error InvalidCaveatSigner();
error InvalidCustodian();
error InvalidLoan();
error InvalidLoanState();
error InvalidPostRepayment();
error InvalidRefinance();
error LoanExists();
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/StarportTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 7 additions & 3 deletions test/fuzz-testing/TestFuzzStarport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -641,7 +644,8 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq {
account.addr,
refiFulfiller != account.addr ? lenderCaveat : _emptyCaveat(),
goodLoan2,
abi.encode(newPricingDetails)
abi.encode(newPricingDetails),
""
);
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/integration-testing/TestCaveats.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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, "");
}
}
6 changes: 3 additions & 3 deletions test/unit-testing/TestStarport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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, "");
}
}

0 comments on commit df5d1b4

Please sign in to comment.