Skip to content

Commit

Permalink
Merge branch 'master' into feat/license-cleanup-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
justingreenberg authored Nov 18, 2023
2 parents 8f5ce7d + 4c8a6b7 commit 0882036
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 203 deletions.
158 changes: 79 additions & 79 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 369610)
IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 323357)
IntegrationTestCaveats:testOriginateWCaveats() (gas: 297466)
IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 177229)
IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 205795)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 303711)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 179716)
IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 323433)
IntegrationTestCaveats:testRefinanceAsLender() (gas: 1088462)
IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 437545)
IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 384815)
IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 495425)
IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 414216)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 437533)
ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 436184)
ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 439051)
ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 435174)
ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 435995)
ModuleTesting:testModuleValidation() (gas: 1272825)
IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 366712)
IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 320478)
IntegrationTestCaveats:testOriginateWCaveats() (gas: 294572)
IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 177232)
IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 205798)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 300823)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 179750)
IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 320554)
IntegrationTestCaveats:testRefinanceAsLender() (gas: 1082795)
IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 434517)
IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 381921)
IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 489763)
IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 411188)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 431878)
ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 433286)
ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 436153)
ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 432276)
ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 433097)
ModuleTesting:testModuleValidation() (gas: 1269927)
PausableNonReentrantImpl:test() (gas: 2442)
PausableNonReentrantImpl:testReentrancy() (gas: 2735)
TestBorrowerEnforcer:testBERevertAdditionalTransfers() (gas: 75662)
TestBorrowerEnforcer:testBERevertInvalidLoanTerms() (gas: 80937)
TestBorrowerEnforcer:testBERevertAdditionalTransfersFromBorrower() (gas: 76218)
TestBorrowerEnforcer:testBERevertInvalidLoanTerms() (gas: 81026)
TestBorrowerEnforcer:testBEValidLoanTerms() (gas: 72021)
TestBorrowerEnforcer:testBEValidLoanTermsAnyIssuer() (gas: 72085)
TestCustodian:testCannotLazyMintTwice() (gas: 78796)
TestCustodian:testCannotMintInvalidLoanInvalidCustodian() (gas: 69031)
TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 74555)
TestCustodian:testCustodySelector() (gas: 2908178)
TestCustodian:testCustodySelector() (gas: 2861655)
TestCustodian:testDefaultCustodySelectorRevert() (gas: 72312)
TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 173324)
TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 173056)
TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 163179)
TestCustodian:testGenerateOrderRepay() (gas: 177479)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193948)
TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 874174)
TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 803567)
TestCustodian:testGenerateOrderRepay() (gas: 177211)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193680)
TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 868121)
TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 797782)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 97601)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 91984)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 106839)
TestCustodian:testGenerateOrderSettlement() (gas: 154934)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160331)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 163342)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 101813)
TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 461050)
TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 458156)
TestCustodian:testGetBorrower() (gas: 78641)
TestCustodian:testInvalidAction() (gas: 173284)
TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 130104)
TestCustodian:testInvalidActionSettleActiveLoan() (gas: 130086)
TestCustodian:testInvalidEncodedData() (gas: 26192)
TestCustodian:testMintWithApprovalSetAsBorrower() (gas: 362794)
TestCustodian:testMintWithApprovalSetAsBorrower() (gas: 359900)
TestCustodian:testMintWithApprovalSetAsBorrowerInvalidLoan() (gas: 60792)
TestCustodian:testMintWithApprovalSetNotAuthorized() (gas: 76759)
TestCustodian:testName() (gas: 7121)
TestCustodian:testNonPayableFunctions() (gas: 215173)
TestCustodian:testOnlySeaport() (gas: 17829)
TestCustodian:testPreviewOrderNoActiveLoan() (gas: 105805)
TestCustodian:testPreviewOrderRepay() (gas: 230692)
TestCustodian:testPreviewOrderRepay() (gas: 230156)
TestCustodian:testPreviewOrderSettlement() (gas: 191848)
TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 108234)
TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 116961)
TestCustodian:testRatifyOrder() (gas: 184300)
TestCustodian:testRatifyOrder() (gas: 184032)
TestCustodian:testSeaportMetadata() (gas: 8632)
TestCustodian:testSupportsInterface() (gas: 9428)
TestCustodian:testSymbol() (gas: 7105)
Expand All @@ -69,76 +69,76 @@ TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 80962)
TestLenderEnforcer:testLEValidLoanTerms() (gas: 71955)
TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 72087)
TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 73310)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 589923)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 597136)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 588217)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 578027)
TestNewLoan:testBuyNowPayLater() (gas: 2872538)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 586757)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 593970)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 585051)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 574861)
TestNewLoan:testBuyNowPayLater() (gas: 2869372)
TestNewLoan:testInvalidSenderBNPL() (gas: 1613720)
TestNewLoan:testInvalidUserDataHashBNPL() (gas: 1616299)
TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 864172)
TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 873554)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 427348)
TestNewLoan:testNewLoanRefinance() (gas: 588879)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 328412)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 384718)
TestNewLoan:testSettleLoan() (gas: 639407)
TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 861278)
TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 870656)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 424450)
TestNewLoan:testNewLoanRefinance() (gas: 583073)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 325542)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 381839)
TestNewLoan:testSettleLoan() (gas: 636143)
TestPausableNonReentrant:testNotOwner() (gas: 21254)
TestPausableNonReentrant:testPauseAndUnpause() (gas: 22555)
TestPausableNonReentrant:testReentrancy() (gas: 15360)
TestPausableNonReentrant:testUnpauseWhenNotPaused() (gas: 12582)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 661913)
TestRepayLoan:testRepayLoanBase() (gas: 598116)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 436379)
TestRepayLoan:testRepayLoanInSettlement() (gas: 583443)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 601774)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 857423)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 658479)
TestRepayLoan:testRepayLoanBase() (gas: 594682)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 433481)
TestRepayLoan:testRepayLoanInSettlement() (gas: 580179)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 598608)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 853185)
TestSimpleInterestPricing:test_calculateInterest() (gas: 895930)
TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 943140)
TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 933907)
TestStarport:testActive() (gas: 69320)
TestStarport:testAdditionalTransfers() (gas: 301282)
TestStarport:testAdditionalTransfersOriginate() (gas: 276000)
TestStarport:testAdditionalTransfersRefinance() (gas: 214275)
TestStarport:testAdditionalTransfers() (gas: 298120)
TestStarport:testAdditionalTransfersOriginate() (gas: 272838)
TestStarport:testAdditionalTransfersRefinance() (gas: 211072)
TestStarport:testApplyRefinanceConsiderationToLoanMalformed() (gas: 121896)
TestStarport:testCannotIssueSameLoanTwice() (gas: 364572)
TestStarport:testCannotIssueSameLoanTwice() (gas: 358910)
TestStarport:testCannotOriginateWhilePaused() (gas: 73457)
TestStarport:testCannotSettleInvalidLoan() (gas: 74915)
TestStarport:testCannotSettleUnlessValidCustodian() (gas: 70985)
TestStarport:testCaveatEnforcerRevert() (gas: 99211)
TestStarport:testDefaultFeeRake() (gas: 361418)
TestStarport:testDefaultFeeRakeExoticDebt() (gas: 370930)
TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 377404)
TestStarport:testCaveatEnforcerRevert() (gas: 99214)
TestStarport:testDefaultFeeRake() (gas: 357730)
TestStarport:testDefaultFeeRakeExoticDebt() (gas: 367863)
TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 374121)
TestStarport:testIncrementCaveatNonce() (gas: 35208)
TestStarport:testInitializedFlagSetProperly() (gas: 67393)
TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 228469)
TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 163974)
TestStarport:testInvalidAmountCollateral() (gas: 163481)
TestStarport:testInvalidAmountCollateral721() (gas: 163481)
TestStarport:testInvalidItemType() (gas: 149429)
TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 227780)
TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 163706)
TestStarport:testInvalidAmountCollateral() (gas: 163345)
TestStarport:testInvalidAmountCollateral721() (gas: 163345)
TestStarport:testInvalidItemType() (gas: 149293)
TestStarport:testInvalidTransferLengthCollateral() (gas: 151635)
TestStarport:testInvalidTransferLengthDebt() (gas: 173436)
TestStarport:testInvalidateCaveatSalt() (gas: 33463)
TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 264447)
TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 290660)
TestStarport:testNonPayableFunctions() (gas: 112040)
TestStarport:testOverrideFeeRake() (gas: 357314)
TestStarport:testInvalidTransferLengthDebt() (gas: 173302)
TestStarport:testInvalidateCaveatSalt() (gas: 33494)
TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 261553)
TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 287766)
TestStarport:testNonPayableFunctions() (gas: 112043)
TestStarport:testOverrideFeeRake() (gas: 354048)
TestStarport:testPause() (gas: 18093)
TestStarport:testRefinancePostRepaymentFails() (gas: 120803)
TestStarport:testTokenNoCodeCollateral() (gas: 148242)
TestStarport:testTokenNoCodeDebt() (gas: 178649)
TestStarport:testTokenNoCodeCollateral() (gas: 148106)
TestStarport:testTokenNoCodeDebt() (gas: 178379)
TestStarport:testUnpause() (gas: 17198)
TestStrategistOriginator:testEncodeWithAccountCounter() (gas: 12307)
TestStrategistOriginator:testGetStrategistData() (gas: 1489933)
TestStrategistOriginator:testIncrementCounterAsStrategist() (gas: 18676)
TestStrategistOriginator:testIncrementCounterNotAuthorized() (gas: 13401)
TestStrategistOriginator:testInvalidCollateral() (gas: 209785)
TestStrategistOriginator:testInvalidDeadline() (gas: 215500)
TestStrategistOriginator:testInvalidDebt() (gas: 211423)
TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 211784)
TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 212083)
TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 212037)
TestStrategistOriginator:testInvalidDebtLength() (gas: 210666)
TestStrategistOriginator:testInvalidOffer() (gas: 427287)
TestStrategistOriginator:testInvalidSigner() (gas: 213994)
TestStrategistOriginator:testInvalidCollateral() (gas: 209797)
TestStrategistOriginator:testInvalidDeadline() (gas: 215512)
TestStrategistOriginator:testInvalidDebt() (gas: 211435)
TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 211796)
TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 212095)
TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 212049)
TestStrategistOriginator:testInvalidDebtLength() (gas: 210678)
TestStrategistOriginator:testInvalidOffer() (gas: 424408)
TestStrategistOriginator:testInvalidSigner() (gas: 214006)
TestStrategistOriginator:testSetStrategist() (gas: 17796)
42 changes: 20 additions & 22 deletions src/Starport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contract Starport is PausableNonReentrant {
address custodian = address(new Custodian(this, seaport_));

bytes32 defaultCustodianCodeHash;
assembly {
assembly ("memory-safe") {
defaultCustodianCodeHash := extcodehash(custodian)
}
defaultCustodian = payable(custodian);
Expand Down Expand Up @@ -281,7 +281,7 @@ contract Starport is PausableNonReentrant {
address custodian = loan.custodian;
// Comparing the retrieved code hash with a known hash
bytes32 codeHash;
assembly {
assembly ("memory-safe") {
codeHash := extcodehash(custodian)
}
if (
Expand Down Expand Up @@ -329,10 +329,8 @@ contract Starport is PausableNonReentrant {
) internal pure {
uint256 i = 0;
for (; i < additionalTransfers.length;) {
if (
additionalTransfers[i].from != borrower && additionalTransfers[i].from != lender
&& additionalTransfers[i].from != fulfiller
) {
address from = additionalTransfers[i].from;
if (from != borrower && from != lender && from != fulfiller) {
revert UnauthorizedAdditionalTransferIncluded();
}
unchecked {
Expand Down Expand Up @@ -430,7 +428,7 @@ contract Starport is PausableNonReentrant {
* @param salt The salt to invalidate
*/
function invalidateCaveatSalt(bytes32 salt) external {
invalidSalts[msg.sender][salt] = true;
invalidSalts.validateSalt(msg.sender, salt);
emit CaveatSaltInvalidated(msg.sender, salt);
}

Expand Down Expand Up @@ -518,33 +516,35 @@ contract Starport is PausableNonReentrant {
uint256 totalFeeItems;
for (uint256 i = 0; i < debt.length;) {
uint256 amount;
if (debt[i].itemType == ItemType.ERC20) {
Fee memory feeOverride = feeOverrides[debt[i].token];
feeItems[i].identifier = 0;
amount = debt[i].amount.mulDiv(
!feeOverride.enabled ? defaultFeeRake : feeOverride.amount, 10 ** ERC20(debt[i].token).decimals()
SpentItem memory debtItem = debt[i];
if (debtItem.itemType == ItemType.ERC20) {
Fee memory feeOverride = feeOverrides[debtItem.token];
SpentItem memory feeItem = feeItems[i];
feeItem.identifier = 0;
amount = debtItem.amount.mulDiv(
!feeOverride.enabled ? defaultFeeRake : feeOverride.amount, 10 ** ERC20(debtItem.token).decimals()
);

if (amount > 0) {
feeItems[i].amount = amount;
feeItems[i].token = debt[i].token;
feeItems[i].itemType = debt[i].itemType;
feeItem.amount = amount;
feeItem.token = debtItem.token;
feeItem.itemType = debtItem.itemType;

++totalFeeItems;
}
}
paymentToBorrower[i] = SpentItem({
token: debt[i].token,
itemType: debt[i].itemType,
identifier: debt[i].identifier,
amount: debt[i].amount - amount
token: debtItem.token,
itemType: debtItem.itemType,
identifier: debtItem.identifier,
amount: debtItem.amount - amount
});
unchecked {
++i;
}
}

assembly {
assembly ("memory-safe") {
mstore(feeItems, totalFeeItems)
}
}
Expand All @@ -557,8 +557,6 @@ contract Starport is PausableNonReentrant {
loan.start = block.timestamp;
loan.originator = loan.originator != address(0) ? loan.originator : msg.sender;

bytes memory encodedLoan = abi.encode(loan);

uint256 loanId = loan.getId();
if (active(loanId)) {
revert LoanExists();
Expand Down
11 changes: 9 additions & 2 deletions src/enforcers/BorrowerEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ contract BorrowerEnforcer is CaveatEnforcer {

if (keccak256(abi.encode(loan)) != keccak256(abi.encode(details.loan))) revert InvalidLoanTerms();

// Should additional transfers from the accounts other than the borrower be allowed?
if (additionalTransfers.length > 0) revert InvalidAdditionalTransfer();
if (additionalTransfers.length > 0) {
uint256 i = 0;
for (; i < additionalTransfers.length;) {
if (additionalTransfers[i].from == loan.borrower) revert InvalidAdditionalTransfer();
unchecked {
++i;
}
}
}
}
}
8 changes: 4 additions & 4 deletions src/lib/PausableNonReentrant.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract contract PausableNonReentrant is Ownable {
* @dev modifier to ensure that the contract is not paused or locked
*/
modifier pausableNonReentrant() {
assembly {
assembly ("memory-safe") {
//If locked or paused, handle revert cases
if gt(sload(_state.slot), _UNLOCKED) {
if gt(sload(_state.slot), _LOCKED) {
Expand All @@ -36,7 +36,7 @@ abstract contract PausableNonReentrant is Ownable {
sstore(_state.slot, _LOCKED)
}
_;
assembly {
assembly ("memory-safe") {
sstore(_state.slot, _UNLOCKED)
}
}
Expand All @@ -45,7 +45,7 @@ abstract contract PausableNonReentrant is Ownable {
* @dev Pause the contract if not paused or locked
*/
function pause() external onlyOwner {
assembly {
assembly ("memory-safe") {
//If locked, prevent owner from overriding state
if eq(sload(_state.slot), _LOCKED) {
//Revert IsLocked
Expand All @@ -61,7 +61,7 @@ abstract contract PausableNonReentrant is Ownable {
* @dev unpause the contract if not paused or locked
*/
function unpause() external onlyOwner {
assembly {
assembly ("memory-safe") {
//If not paused, prevent owner from overriding state
if lt(sload(_state.slot), _PAUSED) {
//Revert NotPaused
Expand Down
Loading

0 comments on commit 0882036

Please sign in to comment.