Skip to content

Commit

Permalink
fix: gas optimization of assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerousfood committed Jan 24, 2024
1 parent 04c504e commit ec971e1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
64 changes: 32 additions & 32 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,20 +32,20 @@ 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)
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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
TestStrategistOriginator:testWithdraw() (gas: 167733)
8 changes: 4 additions & 4 deletions src/lib/StarportLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/originators/StrategistOriginator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
Expand Down
3 changes: 1 addition & 2 deletions src/pricing/BasePricing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/settlement/DutchAuctionSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit ec971e1

Please sign in to comment.