Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AstariaXYZ/starport into feat/fuz…
Browse files Browse the repository at this point in the history
…z-updates-w-enforcer-originator-update
  • Loading branch information
androolloyd committed Nov 18, 2023
2 parents 5ce193a + 4c8a6b7 commit 664b5b4
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 192 deletions.
134 changes: 67 additions & 67 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 327463)
IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 281035)
IntegrationTestCaveats:testOriginateWCaveatsAsBorrower() (gas: 303196)
IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 327195)
IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 280767)
IntegrationTestCaveats:testOriginateWCaveatsAsBorrower() (gas: 302928)
IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 157332)
IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 166063)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 281280)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 139941)
IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 281111)
IntegrationTestCaveats:testRefinanceAsLender() (gas: 1043639)
IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 395726)
IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 342926)
IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 450960)
IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 372181)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 392766)
ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 433859)
ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 436726)
ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 432849)
ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 433670)
ModuleTesting:testModuleValidation() (gas: 1270500)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 281012)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 139972)
IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 280843)
IntegrationTestCaveats:testRefinanceAsLender() (gas: 1043237)
IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 395324)
IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 342658)
IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 450558)
IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 371779)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 392364)
ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 433591)
ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 436458)
ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 432581)
ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 433402)
ModuleTesting:testModuleValidation() (gas: 1270232)
PausableNonReentrantImpl:test() (gas: 2442)
PausableNonReentrantImpl:testReentrancy() (gas: 2735)
TestBorrowerEnforcer:testBERevertAdditionalTransfers() (gas: 75878)
TestBorrowerEnforcer:testBERevertInvalidLoanTerms() (gas: 81153)
TestBorrowerEnforcer:testBERevertAdditionalTransfersFromBorrower() (gas: 76434)
TestBorrowerEnforcer:testBERevertInvalidLoanTerms() (gas: 81242)
TestBorrowerEnforcer:testBEValidLoanTerms() (gas: 72237)
TestBorrowerEnforcer:testBEValidLoanTermsAnyIssuer() (gas: 72301)
TestCustodian:testCannotLazyMintTwice() (gas: 78788)
TestCustodian:testCannotMintInvalidLoanInvalidCustodian() (gas: 69031)
TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 74547)
TestCustodian:testCustodySelector() (gas: 2908178)
TestCustodian:testCustodySelector() (gas: 2861655)
TestCustodian:testDefaultCustodySelectorRevert() (gas: 72312)
TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 173178)
TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 172910)
TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 163033)
TestCustodian:testGenerateOrderRepay() (gas: 177333)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193802)
TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 868811)
TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 798204)
TestCustodian:testGenerateOrderRepay() (gas: 177065)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193534)
TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 868007)
TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 797668)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 97601)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 91984)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 106839)
TestCustodian:testGenerateOrderSettlement() (gas: 154788)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160185)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 163250)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 101813)
TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 458513)
TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 458245)
TestCustodian:testGetBorrower() (gas: 78641)
TestCustodian:testInvalidAction() (gas: 173196)
TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 130060)
TestCustodian:testInvalidActionSettleActiveLoan() (gas: 130042)
TestCustodian:testInvalidEncodedData() (gas: 26192)
TestCustodian:testMintWithApprovalSetAsBorrower() (gas: 360252)
TestCustodian:testMintWithApprovalSetAsBorrower() (gas: 359984)
TestCustodian:testMintWithApprovalSetAsBorrowerInvalidLoan() (gas: 60792)
TestCustodian:testMintWithApprovalSetNotAuthorized() (gas: 76751)
TestCustodian:testName() (gas: 7121)
TestCustodian:testNonPayableFunctions() (gas: 215173)
TestCustodian:testOnlySeaport() (gas: 17829)
TestCustodian:testPreviewOrderNoActiveLoan() (gas: 105761)
TestCustodian:testPreviewOrderRepay() (gas: 230502)
TestCustodian:testPreviewOrderRepay() (gas: 229966)
TestCustodian:testPreviewOrderSettlement() (gas: 191658)
TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 108190)
TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 116917)
TestCustodian:testRatifyOrder() (gas: 184154)
TestCustodian:testRatifyOrder() (gas: 183886)
TestCustodian:testSeaportMetadata() (gas: 8632)
TestCustodian:testSupportsInterface() (gas: 9428)
TestCustodian:testSymbol() (gas: 7105)
Expand All @@ -69,64 +69,64 @@ TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 81178)
TestLenderEnforcer:testLEValidLoanTerms() (gas: 72171)
TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 72303)
TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 73526)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 587408)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 594621)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 585694)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 575512)
TestNewLoan:testBuyNowPayLater() (gas: 2870235)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 586872)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 594085)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 585158)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 574976)
TestNewLoan:testBuyNowPayLater() (gas: 2869677)
TestNewLoan:testInvalidSenderBNPL() (gas: 1613720)
TestNewLoan:testInvalidUserDataHashBNPL() (gas: 1616299)
TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 861567)
TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 871197)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 425023)
TestNewLoan:testNewLoanRefinance() (gas: 583685)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 325727)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 382218)
TestNewLoan:testSettleLoan() (gas: 636936)
TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 861299)
TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 870929)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 424755)
TestNewLoan:testNewLoanRefinance() (gas: 583149)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 325459)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 381950)
TestNewLoan:testSettleLoan() (gas: 636302)
TestPausableNonReentrant:testNotOwner() (gas: 21254)
TestPausableNonReentrant:testPauseAndUnpause() (gas: 22555)
TestPausableNonReentrant:testReentrancy() (gas: 15360)
TestPausableNonReentrant:testUnpauseWhenNotPaused() (gas: 12582)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 659390)
TestRepayLoan:testRepayLoanBase() (gas: 595601)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 434054)
TestRepayLoan:testRepayLoanInSettlement() (gas: 581074)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 599405)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 854680)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 658586)
TestRepayLoan:testRepayLoanBase() (gas: 594797)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 433786)
TestRepayLoan:testRepayLoanInSettlement() (gas: 580440)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 598869)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 853072)
TestSimpleInterestPricing:test_calculateInterest() (gas: 895930)
TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 943140)
TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 933907)
TestStarport:testActive() (gas: 69312)
TestStarport:testAdditionalTransfers() (gas: 298767)
TestStarport:testAdditionalTransfersOriginate() (gas: 273485)
TestStarport:testAdditionalTransfersRefinance() (gas: 211382)
TestStarport:testAdditionalTransfers() (gas: 298209)
TestStarport:testAdditionalTransfersOriginate() (gas: 272927)
TestStarport:testAdditionalTransfersRefinance() (gas: 210821)
TestStarport:testApplyRefinanceConsiderationToLoanMalformed() (gas: 121962)
TestStarport:testCannotIssueSameLoanTwice() (gas: 359673)
TestStarport:testCannotIssueSameLoanTwice() (gas: 359137)
TestStarport:testCannotOriginateWhilePaused() (gas: 73479)
TestStarport:testCannotSettleInvalidLoan() (gas: 74823)
TestStarport:testCannotSettleUnlessValidCustodian() (gas: 70985)
TestStarport:testCaveatEnforcerRevert() (gas: 99214)
TestStarport:testDefaultFeeRake() (gas: 358915)
TestStarport:testDefaultFeeRakeExoticDebt() (gas: 368427)
TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 374612)
TestStarport:testDefaultFeeRake() (gas: 357863)
TestStarport:testDefaultFeeRakeExoticDebt() (gas: 367996)
TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 374210)
TestStarport:testIncrementCaveatNonce() (gas: 35230)
TestStarport:testInitializedFlagSetProperly() (gas: 67349)
TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 228685)
TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 163850)
TestStarport:testInvalidAmountCollateral() (gas: 163697)
TestStarport:testInvalidAmountCollateral721() (gas: 163697)
TestStarport:testInvalidItemType() (gas: 149645)
TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 227996)
TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 163582)
TestStarport:testInvalidAmountCollateral() (gas: 163561)
TestStarport:testInvalidAmountCollateral721() (gas: 163561)
TestStarport:testInvalidItemType() (gas: 149509)
TestStarport:testInvalidTransferLengthCollateral() (gas: 151851)
TestStarport:testInvalidTransferLengthDebt() (gas: 173652)
TestStarport:testInvalidateCaveatSalt() (gas: 33485)
TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 261910)
TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 288123)
TestStarport:testInvalidTransferLengthDebt() (gas: 173518)
TestStarport:testInvalidateCaveatSalt() (gas: 33516)
TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 261642)
TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 287855)
TestStarport:testNonPayableFunctions() (gas: 112065)
TestStarport:testOverrideFeeRake() (gas: 354826)
TestStarport:testOverrideFeeRake() (gas: 354203)
TestStarport:testPause() (gas: 18115)
TestStarport:testRefinancePostRepaymentFails() (gas: 120679)
TestStarport:testTokenNoCodeCollateral() (gas: 148458)
TestStarport:testTokenNoCodeDebt() (gas: 178865)
TestStarport:testTokenNoCodeCollateral() (gas: 148322)
TestStarport:testTokenNoCodeDebt() (gas: 178595)
TestStarport:testUnpause() (gas: 17220)
TestStrategistOriginator:testEncodeWithAccountCounter() (gas: 12307)
TestStrategistOriginator:testGetStrategistData() (gas: 1489933)
Expand All @@ -139,6 +139,6 @@ TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 2118
TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 212117)
TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 212071)
TestStrategistOriginator:testInvalidDebtLength() (gas: 210700)
TestStrategistOriginator:testInvalidOffer() (gas: 424787)
TestStrategistOriginator:testInvalidOffer() (gas: 424519)
TestStrategistOriginator:testInvalidSigner() (gas: 214028)
TestStrategistOriginator:testSetStrategist() (gas: 17796)
40 changes: 20 additions & 20 deletions src/Starport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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 @@ -289,7 +289,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 @@ -324,10 +324,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 @@ -402,7 +400,7 @@ contract Starport is PausableNonReentrant {
}

function invalidateCaveatSalt(bytes32 salt) external {
invalidSalts[msg.sender][salt] = true;
invalidSalts.validateSalt(msg.sender, salt);
emit CaveatSaltInvalidated(msg.sender, salt);
}

Expand Down Expand Up @@ -502,33 +500,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 Down
11 changes: 9 additions & 2 deletions src/enforcers/BorrowerEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ contract BorrowerEnforcer is CaveatEnforcer {
details.loan.originator = loan.originator;
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 @@ -18,7 +18,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 @@ -33,7 +33,7 @@ abstract contract PausableNonReentrant is Ownable {
sstore(_state.slot, _LOCKED)
}
_;
assembly {
assembly ("memory-safe") {
sstore(_state.slot, _UNLOCKED)
}
}
Expand All @@ -42,7 +42,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 @@ -58,7 +58,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 664b5b4

Please sign in to comment.