From ec971e1f2d3a16a441e52b48ad55a7533fcac7c9 Mon Sep 17 00:00:00 2001 From: Joseph Delong Date: Wed, 24 Jan 2024 16:35:54 -0600 Subject: [PATCH] fix: gas optimization of assignment --- .gas-snapshot | 64 +++++++++++------------ src/lib/StarportLib.sol | 8 +-- src/originators/StrategistOriginator.sol | 3 +- src/pricing/BasePricing.sol | 3 +- src/settlement/DutchAuctionSettlement.sol | 2 +- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index eed353cc..bc56af2e 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -16,10 +16,10 @@ IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 377103) IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 402755) ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 437989) ModuleTesting:testFixedTermDutchAuctionSettlementAuctionNotStarted() (gas: 441365) -ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 440814) +ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 440758) ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 437043) ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 437950) -ModuleTesting:testModuleValidation() (gas: 1274270) +ModuleTesting:testModuleValidation() (gas: 1262841) PausableNonReentrantImpl:test() (gas: 2464) PausableNonReentrantImpl:testReentrancy() (gas: 2757) TestBorrowerEnforcer:testBERevertAdditionalTransfersFromBorrower() (gas: 76462) @@ -32,12 +32,12 @@ TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 77987) TestCustodian:testCustodianCannotBeAuthorized() (gas: 142011) TestCustodian:testCustodySelector() (gas: 2717132) TestCustodian:testDefaultCustodySelectorRevert() (gas: 72478) -TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 172910) +TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 172811) TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 163090) -TestCustodian:testGenerateOrderRepay() (gas: 177070) -TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193538) -TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 875643) -TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 804243) +TestCustodian:testGenerateOrderRepay() (gas: 176971) +TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193439) +TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 875233) +TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 804051) TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 97556) TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 91917) TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 106827) @@ -45,7 +45,7 @@ TestCustodian:testGenerateOrderSettlement() (gas: 154803) TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160200) TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 163286) TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 101809) -TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 461569) +TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 461377) TestCustodian:testGetBorrower() (gas: 78603) TestCustodian:testInvalidAction() (gas: 179778) TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 130080) @@ -58,11 +58,11 @@ TestCustodian:testName() (gas: 7077) TestCustodian:testNonPayableFunctions() (gas: 215289) TestCustodian:testOnlySeaport() (gas: 17918) TestCustodian:testPreviewOrderNoActiveLoan() (gas: 105714) -TestCustodian:testPreviewOrderRepay() (gas: 229947) +TestCustodian:testPreviewOrderRepay() (gas: 229749) TestCustodian:testPreviewOrderSettlement() (gas: 191710) TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 108205) TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 116898) -TestCustodian:testRatifyOrder() (gas: 183891) +TestCustodian:testRatifyOrder() (gas: 183792) TestCustodian:testSeaportMetadata() (gas: 8588) TestCustodian:testSupportsInterface() (gas: 9428) TestCustodian:testSymbol() (gas: 7194) @@ -73,37 +73,37 @@ TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 81096) TestLenderEnforcer:testLEValidLoanTerms() (gas: 72169) TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 72234) TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 73525) -TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 592516) -TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 599729) -TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 589880) -TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 579764) +TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 592318) +TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 599531) +TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 589682) +TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 579566) TestNewLoan:testBuyNowPayLater() (gas: 3018379) TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 874045) TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 885070) TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 429501) -TestNewLoan:testNewLoanRefinance() (gas: 589921) -TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 324584) -TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 383414) +TestNewLoan:testNewLoanRefinance() (gas: 589822) +TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 324529) +TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 383347) TestNewLoan:testSettleLoan() (gas: 641934) TestPausableNonReentrant:testNotOwner() (gas: 21276) TestPausableNonReentrant:testPauseAndUnpause() (gas: 22643) TestPausableNonReentrant:testReentrancy() (gas: 15404) TestPausableNonReentrant:testUnpauseWhenNotPaused() (gas: 12604) -TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 666737) -TestRepayLoan:testRepayLoanBase() (gas: 599559) +TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 666539) +TestRepayLoan:testRepayLoanBase() (gas: 599361) TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 438643) TestRepayLoan:testRepayLoanInSettlement() (gas: 585543) -TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 603652) -TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 857883) -TestSimpleInterestPricing:test_calculateInterest() (gas: 881296) -TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 928510) -TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 919314) +TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 603553) +TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 857388) +TestSimpleInterestPricing:test_calculateInterest() (gas: 869870) +TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 916886) +TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 907796) TestStarport:testAcquireTokensFail() (gas: 60386) -TestStarport:testAcquireTokensSuccess() (gas: 162955) +TestStarport:testAcquireTokensSuccess() (gas: 162757) TestStarport:testActive() (gas: 69291) TestStarport:testAdditionalTransfers() (gas: 300688) TestStarport:testAdditionalTransfersOriginate() (gas: 275384) -TestStarport:testAdditionalTransfersRefinance() (gas: 218214) +TestStarport:testAdditionalTransfersRefinance() (gas: 218115) TestStarport:testApplyRefinanceConsiderationToLoanMalformed() (gas: 129820) TestStarport:testCannotIssueSameLoanTwice() (gas: 363991) TestStarport:testCannotOriginateWhilePaused() (gas: 73523) @@ -112,15 +112,15 @@ TestStarport:testCannotSettleUnlessValidCustodian() (gas: 70919) TestStarport:testCaveatEnforcerRevert() (gas: 102534) TestStarport:testDefaultFeeRake1() (gas: 387913) TestStarport:testDefaultFeeRake2() (gas: 450256) -TestStarport:testDefaultFeeRakeExoticDebt() (gas: 397742) +TestStarport:testDefaultFeeRakeExoticDebt() (gas: 397546) TestStarport:testEIP712Signing() (gas: 83056) TestStarport:testExoticDebtWithCustomPricingAndRepayment() (gas: 1237672) TestStarport:testExoticDebtWithCustomPricingAndSettlement() (gas: 1695711) -TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 376786) +TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 376594) TestStarport:testIncrementCaveatNonce() (gas: 35183) TestStarport:testInitializedFlagSetProperly() (gas: 67416) TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 230359) -TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 170774) +TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 170675) TestStarport:testInvalidAmountCollateral() (gas: 165901) TestStarport:testInvalidAmountCollateral721() (gas: 165901) TestStarport:testInvalidItemType() (gas: 151849) @@ -132,7 +132,7 @@ TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 290347) TestStarport:testNonPayableFunctions() (gas: 114479) TestStarport:testOverrideFeeRake() (gas: 384236) TestStarport:testPause() (gas: 18193) -TestStarport:testRefinancePostRepaymentFails() (gas: 127864) +TestStarport:testRefinancePostRepaymentFails() (gas: 127765) TestStarport:testStargateGetOwner() (gas: 8786) TestStarport:testTokenNoCodeCollateral() (gas: 150640) TestStarport:testTokenNoCodeDebt() (gas: 180913) @@ -147,7 +147,7 @@ TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 2125 TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 212772) TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 212707) TestStrategistOriginator:testInvalidDebtLength() (gas: 211362) -TestStrategistOriginator:testInvalidOffer() (gas: 427184) +TestStrategistOriginator:testInvalidOffer() (gas: 427117) TestStrategistOriginator:testInvalidSigner() (gas: 214522) TestStrategistOriginator:testSetStrategist() (gas: 17852) -TestStrategistOriginator:testWithdraw() (gas: 167942) \ No newline at end of file +TestStrategistOriginator:testWithdraw() (gas: 167733) \ No newline at end of file diff --git a/src/lib/StarportLib.sol b/src/lib/StarportLib.sol index f951188b..5c74e8c1 100644 --- a/src/lib/StarportLib.sol +++ b/src/lib/StarportLib.sol @@ -250,7 +250,7 @@ library StarportLib { // erc1155 transfer if (transfer.amount > 0) { ERC1155(transfer.token).safeTransferFrom( - transfer.from, transfer.to, transfer.identifier, transfer.amount, new bytes(0) + transfer.from, transfer.to, transfer.identifier, transfer.amount, "" ); } } else { @@ -281,7 +281,7 @@ library StarportLib { // erc1155 transfer if (transfer.amount > 0) { ERC1155(transfer.token).safeTransferFrom( - transfer.from, transfer.to, transfer.identifier, transfer.amount, new bytes(0) + transfer.from, transfer.to, transfer.identifier, transfer.amount, "" ); } } else { @@ -360,7 +360,7 @@ library StarportLib { revert InvalidItemAmount(); } // erc1155 transfer - ERC1155(token).safeTransferFrom(from, to, identifier, amount, new bytes(0)); + ERC1155(token).safeTransferFrom(from, to, identifier, amount, ""); } else { revert InvalidItemType(); } @@ -384,7 +384,7 @@ library StarportLib { ERC721(token).transferFrom(from, to, identifier); } else if (itemType == ItemType.ERC1155) { // erc1155 transfer - ERC1155(token).safeTransferFrom(from, to, identifier, amount, new bytes(0)); + ERC1155(token).safeTransferFrom(from, to, identifier, amount, ""); } else { revert InvalidItemType(); } diff --git a/src/originators/StrategistOriginator.sol b/src/originators/StrategistOriginator.sol index 75e2ded7..01cedbb4 100644 --- a/src/originators/StrategistOriginator.sol +++ b/src/originators/StrategistOriginator.sol @@ -173,7 +173,8 @@ contract StrategistOriginator is Ownable, Originator, TokenReceiverInterface { }); CaveatEnforcer.SignedCaveats memory le; - SP.originate(new AdditionalTransfer[](0), params.borrowerCaveat, le, loan); + AdditionalTransfer[] memory at; + SP.originate(at, params.borrowerCaveat, le, loan); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ diff --git a/src/pricing/BasePricing.sol b/src/pricing/BasePricing.sol index 7a1590d6..189445dd 100644 --- a/src/pricing/BasePricing.sol +++ b/src/pricing/BasePricing.sol @@ -76,9 +76,8 @@ abstract contract BasePricing is Pricing { Details memory details = abi.decode(loan.terms.pricingData, (Details)); if (details.carryRate > 0 && loan.issuer != loan.originator) { carryConsideration = new SpentItem[](loan.debt.length); - } else { - carryConsideration = new SpentItem[](0); } + repayConsideration = new SpentItem[](loan.debt.length); uint256 i = 0; diff --git a/src/settlement/DutchAuctionSettlement.sol b/src/settlement/DutchAuctionSettlement.sol index 14e5dda2..ead92d13 100644 --- a/src/settlement/DutchAuctionSettlement.sol +++ b/src/settlement/DutchAuctionSettlement.sol @@ -125,7 +125,7 @@ abstract contract DutchAuctionSettlement is Settlement, AmountDeriver { } // DutchAuction has failed, allow lender to redeem if (start + details.window < block.timestamp) { - return (new ReceivedItem[](0), loan.issuer); + return (consideration, loan.issuer); } uint256 settlementPrice = _locateCurrentAmount({