diff --git a/.gas-snapshot b/.gas-snapshot index 39342dff..00c2484a 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,11 +1,17 @@ -TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecall() (gas: 952394) +TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecall() (gas: 952340) +TestExoticLoans:testSwap() (gas: 1356324) +TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 252) +TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 512461) +TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 735781) +TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 510432) +TestLoanCombinations:testLoanSimpleInterestEnglishFixed() (gas: 721739) TestLoanManager:testStorage() (gas: 2283158165) TestLoanManager:testSupportsInterface() (gas: 6937) -TestNewLoan:testBuyNowPayLater() (gas: 1141902) -TestNewLoan:testNewLoanERC721CollateralDefaultTerms2():((uint256,address,address,address,address,(uint8,address,uint256,uint256)[],(uint8,address,uint256,uint256)[],(address,bytes,address,bytes,address,bytes))) (gas: 987750) -TestNewLoan:testNewLoanERC721CollateralDefaultTermsRefinance() (gas: 648498) -TestNewLoan:testNewLoanERC721CollateralDefaultTermsWithMerkleProof():((uint256,address,address,address,address,(uint8,address,uint256,uint256)[],(uint8,address,uint256,uint256)[],(address,bytes,address,bytes,address,bytes))) (gas: 581604) -TestNewLoan:testSettleLoan() (gas: 1260468) -TestRepayLoan:testRepayLoan() (gas: 718985) +TestNewLoan:testBuyNowPayLater() (gas: 1141920) +TestNewLoan:testNewLoanERC721CollateralDefaultTerms2():((uint256,address,address,address,address,(uint8,address,uint256,uint256)[],(uint8,address,uint256,uint256)[],(address,bytes,address,bytes,address,bytes))) (gas: 987746) +TestNewLoan:testNewLoanERC721CollateralDefaultTermsRefinance() (gas: 648516) +TestNewLoan:testNewLoanERC721CollateralDefaultTermsWithMerkleProof():((uint256,address,address,address,address,(uint8,address,uint256,uint256)[],(uint8,address,uint256,uint256)[],(address,bytes,address,bytes,address,bytes))) (gas: 581600) +TestNewLoan:testSettleLoan() (gas: 1260444) +TestRepayLoan:testRepayLoan() (gas: 718963) TestStarLiteUtils:testEncodeReceivedWithRecipient() (gas: 17955) -TestStarLiteUtils:testSpentToReceived() (gas: 17796) \ No newline at end of file +TestStarLiteUtils:testSpentToReceived() (gas: 17796) diff --git a/src/ConduitHelper.sol b/src/ConduitHelper.sol index 6380b662..967e4ece 100644 --- a/src/ConduitHelper.sol +++ b/src/ConduitHelper.sol @@ -24,11 +24,11 @@ import {Custodian} from "src/Custodian.sol"; import {ECDSA} from "solady/src/utils/ECDSA.sol"; import {SignatureCheckerLib} from "solady/src/utils/SignatureCheckerLib.sol"; import {CaveatEnforcer} from "src/enforcers/CaveatEnforcer.sol"; +import {LoanManager} from "src/LoanManager.sol"; abstract contract ConduitHelper { error RepayCarryLengthMismatch(); - // TODO: Greg pls help us unfuck this mess function _mergeConsiderations( ReceivedItem[] memory repayConsideration, ReceivedItem[] memory carryConsideration, @@ -37,11 +37,9 @@ abstract contract ConduitHelper { if (carryConsideration.length == 0 && additionalConsiderations.length == 0) { return repayConsideration; } - consideration = new ReceivedItem[]( - repayConsideration.length + + consideration = new ReceivedItem[](repayConsideration.length + carryConsideration.length + - additionalConsiderations.length - ); + additionalConsiderations.length); uint256 j = 0; // if there is a carry to handle, subtract it from the amount owed @@ -69,11 +67,9 @@ abstract contract ConduitHelper { } // else just use the consideration payment only else { - uint256 i = 0; - for (; i < repayConsideration.length;) { - consideration[j] = repayConsideration[i]; + for (; j < repayConsideration.length;) { + consideration[j] = repayConsideration[j]; unchecked { - ++i; ++j; } } @@ -82,20 +78,10 @@ abstract contract ConduitHelper { if (additionalConsiderations.length > 0) { uint256 i = 0; for (; i < additionalConsiderations.length;) { - if ( - consideration[i].recipient == additionalConsiderations[i].recipient - && consideration[i].token == additionalConsiderations[i].token - ) { - consideration[i].amount += additionalConsiderations[i].amount; - unchecked { - ++i; - } - } else { - consideration[j] = additionalConsiderations[i]; - unchecked { - ++i; - ++j; - } + consideration[j] = additionalConsiderations[i]; + unchecked { + ++i; + ++j; } } }