Skip to content

Commit

Permalink
minor conduit helper cleanup, likely will serve as ref impl
Browse files Browse the repository at this point in the history
  • Loading branch information
0xgregthedev committed Sep 16, 2023
1 parent a0ccc99 commit 5929bea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
22 changes: 14 additions & 8 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -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)
TestStarLiteUtils:testSpentToReceived() (gas: 17796)
32 changes: 9 additions & 23 deletions src/ConduitHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit 5929bea

Please sign in to comment.