Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: review BaseRecall #52

Merged
merged 3 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 49 additions & 48 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
DiffFuzzTestStarportLib:testSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 880557, ~: 883183)
DiffFuzzTestStarportLib:testUnboundSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 232911, ~: 237832)
DiffFuzzTestStarportLib:testSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 880612, ~: 882686)
DiffFuzzTestStarportLib:testUnboundSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 232899, ~: 237832)
IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 341166)
IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 298037)
IntegrationTestCaveats:testOriginateWCaveats() (gas: 272104)
IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 200214)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 257759)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 175780)
IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 298091)
IntegrationTestCaveats:testRefinanceAsLender() (gas: 1036148)
IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 402330)
IntegrationTestCaveats:testRefinanceAsLender() (gas: 1042171)
IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 408353)
IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 377358)
IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 459637)
IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 380750)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 405252)
IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 465660)
IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 386773)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 411275)
PausableNonReentrantImpl:test() (gas: 2442)
PausableNonReentrantImpl:testReentrancy() (gas: 2735)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallBase() (gas: 1021149)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLender() (gas: 727571)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLiquidation() (gas: 1404896)
TestAstariaV1Pricing:testGetRefiannceConsiderationValidEqualRate() (gas: 146135)
TestAstariaV1Pricing:testGetRefiannceConsiderationValidHigherRate() (gas: 158343)
TestAstariaV1Pricing:testGetRefiannceConsiderationValidLowerRate() (gas: 153372)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallBase() (gas: 1009322)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLender() (gas: 711557)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLiquidation() (gas: 1382121)
TestAstariaV1Pricing:testGetRefiannceConsiderationValidEqualRate() (gas: 143045)
TestAstariaV1Pricing:testGetRefiannceConsiderationValidHigherRate() (gas: 155206)
TestAstariaV1Pricing:testGetRefiannceConsiderationValidLowerRate() (gas: 150235)
TestAstariaV1Pricing:testGetRefinanceConsiderationAsBorrowerZeroRate() (gas: 81159)
TestAstariaV1Pricing:testGetRefinanceConsiderationInsufficientRefinance() (gas: 108010)
TestAstariaV1Pricing:testGetRefinanceConsiderationInvalidRefinance() (gas: 88264)
TestAstariaV1Pricing:testGetRefinanceConsiderationZeroRate() (gas: 138753)
TestAstariaV1Pricing:testGetRefinanceConsiderationInsufficientRefinance() (gas: 107916)
TestAstariaV1Pricing:testGetRefinanceConsiderationInvalidRefinance() (gas: 88217)
TestAstariaV1Pricing:testGetRefinanceConsiderationZeroRate() (gas: 135663)
TestAstariaV1Settlement:testGetAuctionStart() (gas: 433743)
TestAstariaV1Settlement:testGetAuctionStartNotStarted() (gas: 433316)
TestAstariaV1Settlement:testGetCurrentAuctionPrice() (gas: 448527)
Expand All @@ -34,17 +34,18 @@ TestAstariaV1Settlement:testGetSettlementFailedDutchAuction() (gas: 448917)
TestAstariaV1Settlement:testGetSettlementLoanNotRecalled() (gas: 439423)
TestAstariaV1Settlement:testV1SettlementHandlerValidate() (gas: 419993)
TestAstariaV1Settlement:testV1SettlementHandlerValidateInvalidHandler() (gas: 420117)
TestAstariaV1Status:testCannotRecallTwice() (gas: 580122)
TestAstariaV1Status:testCannotWithdrawLoanHasNotBeenRefinanced() (gas: 425694)
TestAstariaV1Status:testCannotWithdrawWithdrawDoesNotExist() (gas: 432123)
TestAstariaV1Status:testGenerateRecallConsideration() (gas: 481364)
TestAstariaV1Status:testInvalidRecallInvalidStakeType() (gas: 507391)
TestAstariaV1Status:testInvalidRecallLoanDoesNotExist() (gas: 523634)
TestAstariaV1Status:testIsActive() (gas: 432737)
TestAstariaV1Status:testIsRecalledInsideWindow() (gas: 570875)
TestAstariaV1Status:testIsRecalledOutsideWindow() (gas: 568776)
TestAstariaV1Status:testRecallRateActiveRecall() (gas: 556605)
TestAstariaV1Status:testRecallRateEmptyRecall() (gas: 430391)
TestAstariaV1Status:testCannotRecallTwice() (gas: 545599)
TestAstariaV1Status:testCannotWithdrawLoanHasNotBeenRefinanced() (gas: 428440)
TestAstariaV1Status:testCannotWithdrawWithdrawDoesNotExist() (gas: 434857)
TestAstariaV1Status:testGenerateRecallConsideration() (gas: 477168)
TestAstariaV1Status:testInvalidRecallInvalidStakeType() (gas: 507644)
TestAstariaV1Status:testInvalidRecallLoanDoesNotExist() (gas: 475937)
TestAstariaV1Status:testIsActive() (gas: 432690)
TestAstariaV1Status:testIsRecalledInsideWindow() (gas: 559633)
TestAstariaV1Status:testIsRecalledOutsideWindow() (gas: 557534)
TestAstariaV1Status:testRecallAndRefinanceInsideWindow() (gas: 713941)
TestAstariaV1Status:testRecallRateActiveRecall() (gas: 545388)
TestAstariaV1Status:testRecallRateEmptyRecall() (gas: 430233)
TestBorrowerEnforcer:testBERevertAdditionalTransfers() (gas: 73195)
TestBorrowerEnforcer:testBERevertInvalidLoanTerms() (gas: 78316)
TestBorrowerEnforcer:testBEValidLoanTerms() (gas: 69518)
Expand All @@ -56,19 +57,19 @@ TestCompoundInterest:testRateTooLowZero() (gas: 68419)
TestCustodian:testCannotLazyMintTwice() (gas: 76753)
TestCustodian:testCannotMintInvalidLoanInvalidCustodian() (gas: 66884)
TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 72556)
TestCustodian:testCustodySelector() (gas: 2820915)
TestCustodian:testCustodySelector() (gas: 2818515)
TestCustodian:testDefaultCustodySelectorRevert() (gas: 70061)
TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 171281)
TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 155941)
TestCustodian:testGenerateOrderRepay() (gas: 175271)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 191405)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNative() (gas: 827047)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNativeHandlerAuthorized() (gas: 744382)
TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 171272)
TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 155932)
TestCustodian:testGenerateOrderRepay() (gas: 175262)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 191396)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNative() (gas: 827029)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNativeHandlerAuthorized() (gas: 744385)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 90248)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 84652)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 99148)
TestCustodian:testGenerateOrderSettlement() (gas: 147620)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 153177)
TestCustodian:testGenerateOrderSettlement() (gas: 147611)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 153168)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 155828)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 94388)
TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 452795)
Expand All @@ -84,11 +85,11 @@ TestCustodian:testNonPayableFunctions() (gas: 212635)
TestCustodian:testOnlySeaport() (gas: 17873)
TestCustodian:testPayableFunctions() (gas: 41645)
TestCustodian:testPreviewOrderNoActiveLoan() (gas: 98764)
TestCustodian:testPreviewOrderRepay() (gas: 228570)
TestCustodian:testPreviewOrderSettlement() (gas: 179304)
TestCustodian:testPreviewOrderRepay() (gas: 228561)
TestCustodian:testPreviewOrderSettlement() (gas: 179295)
TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 100931)
TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 106834)
TestCustodian:testRatifyOrder() (gas: 181788)
TestCustodian:testRatifyOrder() (gas: 181779)
TestCustodian:testSeaportMetadata() (gas: 8545)
TestCustodian:testSupportsInterface() (gas: 9428)
TestCustodian:testSymbol() (gas: 7127)
Expand All @@ -99,30 +100,30 @@ TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 78341)
TestLenderEnforcer:testLEValidLoanTerms() (gas: 69496)
TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 69494)
TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 70740)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 542758)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 530387)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 560581)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 550323)
TestLoanCombinations:testLoanSimpleInterestEnglishFixed() (gas: 556101)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 542749)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 530378)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 560572)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 550314)
TestLoanCombinations:testLoanSimpleInterestEnglishFixed() (gas: 556092)
TestNewLoan:testBuyNowPayLater() (gas: 2832773)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 394391)
TestNewLoan:testNewLoanERC721CollateralLessDebtThanOffered() (gas: 2348)
TestNewLoan:testNewLoanRefinanceNew() (gas: 207)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 305651)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 358345)
TestNewLoan:testSettleLoan() (gas: 611290)
TestNewLoan:testSettleLoan() (gas: 611281)
TestPausableNonReentrant:testNotOwner() (gas: 21254)
TestPausableNonReentrant:testPauseAndUnpause() (gas: 22555)
TestPausableNonReentrant:testReentrancy() (gas: 15360)
TestPausableNonReentrant:testUnpauseWhenNotPaused() (gas: 12582)
TestRefStarportLib:testSpentToReceived() (gas: 13315)
TestRefStarportLib:testValidateSalt(address,bytes32) (runs: 256, μ: 33865, ~: 33865)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 635212)
TestRepayLoan:testRepayLoanBase() (gas: 571502)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 635203)
TestRepayLoan:testRepayLoanBase() (gas: 571493)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 402312)
TestRepayLoan:testRepayLoanInSettlement() (gas: 549952)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 569739)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 842802)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 842793)
TestSimpleInterestPricing:test_calculateInterest() (gas: 800891)
TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 882219)
TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 876412)
Expand Down
11 changes: 3 additions & 8 deletions src/Custodian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,12 @@ contract Custodian is ERC721, ContractOffererInterface {
*/
function _postSettlementExecute(Starport.Loan memory loan, address fulfiller) internal virtual {
_beforeSettlementHandlerHook(loan);
if (
Settlement(loan.terms.settlement).postSettlement{gas: 100_000}(loan, fulfiller)
!= Settlement.postSettlement.selector
) {
if (Settlement(loan.terms.settlement).postSettlement(loan, fulfiller) != Settlement.postSettlement.selector) {
revert InvalidPostSettlement();
}
_afterSettlementHandlerHook(loan);
}

/**
* @dev settle the loan with the LoanManager
*
Expand All @@ -429,10 +427,7 @@ contract Custodian is ERC721, ContractOffererInterface {

function _postRepaymentExecute(Starport.Loan memory loan, address fulfiller) internal virtual {
_beforeSettlementHandlerHook(loan);
if (
Settlement(loan.terms.settlement).postRepayment{gas: 100_000}(loan, fulfiller)
!= Settlement.postRepayment.selector
) {
if (Settlement(loan.terms.settlement).postRepayment(loan, fulfiller) != Settlement.postRepayment.selector) {
revert InvalidPostRepayment();
}
_afterSettlementHandlerHook(loan);
Expand Down
15 changes: 15 additions & 0 deletions src/Starport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {CaveatEnforcer} from "starport-core/enforcers/CaveatEnforcer.sol";
import {Ownable} from "solady/src/auth/Ownable.sol";
import {SafeTransferLib} from "solady/src/utils/SafeTransferLib.sol";
import {PausableNonReentrant} from "starport-core/lib/PausableNonReentrant.sol";
import {Settlement} from "starport-core/settlement/Settlement.sol";

contract Starport is ERC721, PausableNonReentrant {
using FixedPointMathLib for uint256;
Expand Down Expand Up @@ -121,6 +122,7 @@ contract Starport is ERC721, PausableNonReentrant {
error UnauthorizedAdditionalTransferIncluded();
error InvalidCaveatSigner();
error MalformedRefinance();
error InvalidPostRepayment();

constructor(ConsiderationInterface seaport_) {
address custodian = address(new Custodian(this, seaport_));
Expand Down Expand Up @@ -227,6 +229,7 @@ contract Starport is ERC721, PausableNonReentrant {
) = Pricing(loan.terms.pricing).getRefinanceConsideration(loan, pricingData, msg.sender);

_settle(loan);
_postRepaymentExecute(loan, msg.sender);
loan = applyRefinanceConsiderationToLoan(loan, considerationPayment, carryPayment, pricingData);

StarportLib.transferSpentItems(considerationPayment, lender, loan.issuer, false);
Expand All @@ -251,6 +254,18 @@ contract Starport is ERC721, PausableNonReentrant {
_issueLoan(loan);
}

/**
* @dev settle the loan with the LoanManager
*
* @param loan The the loan that is settled
* @param fulfiller The address executing seaport
*/
function _postRepaymentExecute(Starport.Loan memory loan, address fulfiller) internal virtual {
if (Settlement(loan.terms.settlement).postRepayment(loan, fulfiller) != Settlement.postRepayment.selector) {
revert InvalidPostRepayment();
}
}

function applyRefinanceConsiderationToLoan(
Starport.Loan memory loan,
SpentItem[] memory considerationPayment,
Expand Down
17 changes: 11 additions & 6 deletions src/settlement/AstariaV1Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,20 @@ contract AstariaV1Settlement is DutchAuctionSettlement {
override
returns (bytes4)
{
// TODO: do we need the commented out code if we dont care about reverts anyways, seems like extra gas
// (address recaller, uint64 recallStart) = BaseRecall(loan.terms.status).recalls(loan.getId());
// if (recallStart != 0 || recaller != address(0)) {
//we dont wanna revert if theres ever a halt in the underlying call, settlement must complete
loan.terms.status.call(abi.encodeWithSelector(BaseRecall.withdraw.selector, loan, fulfiller));
// }
_executeWithdraw(loan, fulfiller);
return Settlement.postSettlement.selector;
}

function postRepayment(Starport.Loan calldata loan, address fulfiller) external virtual override returns (bytes4) {
_executeWithdraw(loan, fulfiller);

return Settlement.postRepayment.selector;
}

function _executeWithdraw(Starport.Loan calldata loan, address fulfiller) internal {
loan.terms.status.call(abi.encodeWithSelector(BaseRecall.withdraw.selector, loan, fulfiller));
}

function validate(Starport.Loan calldata loan) external view virtual override returns (bool) {
if (loan.terms.settlement != address(this)) {
revert InvalidHandler();
Expand Down
4 changes: 1 addition & 3 deletions src/settlement/DutchAuctionSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {Starport, Settlement} from "starport-core/settlement/Settlement.sol";
import {BasePricing} from "starport-core/pricing/BasePricing.sol";

abstract contract DutchAuctionSettlement is Settlement, AmountDeriver {
constructor(Starport SP_) Settlement(SP_) {
SP = SP_;
}
constructor(Starport SP_) Settlement(SP_) {}

using FixedPointMathLib for uint256;

Expand Down
2 changes: 1 addition & 1 deletion src/settlement/Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {SpentItem, ReceivedItem} from "seaport-types/src/lib/ConsiderationStruct
import {TokenReceiverInterface} from "starport-core/interfaces/TokenReceiverInterface.sol";

abstract contract Settlement is TokenReceiverInterface {
Starport SP;
Starport public immutable SP;

constructor(Starport SP_) {
SP = SP_;
Expand Down
Loading