Skip to content

Commit

Permalink
Merge branch 'main' of github.com:AstariaXYZ/starport into feat/diff-…
Browse files Browse the repository at this point in the history
…fuzz
  • Loading branch information
0xgregthedev committed Oct 30, 2023
2 parents 76777aa + cc94101 commit 4ea90dc
Show file tree
Hide file tree
Showing 28 changed files with 2,440 additions and 3,187 deletions.
177 changes: 78 additions & 99 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,106 +1,85 @@
DiffFuzzTestStarPortLib:testSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 880511, ~: 882230)
DiffFuzzTestStarPortLib:testSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 880466, ~: 883301)
DiffFuzzTestStarPortLib:testUnboundSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 232905, ~: 237832)
EnforcerTest:testCollateralEnforcer() (gas: 954065)
EnforcerTest:testFailCollateralEnforcerDifferentCollateral() (gas: 834084)
EnforcerTest:testFailRateEnforcerMaxCarryRate() (gas: 789220)
EnforcerTest:testFailRateEnforcerMaxRate() (gas: 789192)
EnforcerTest:testFailRateEnforcerMaxRateAndMaxCarryRate() (gas: 789057)
EnforcerTest:testRateEnforcerBasic() (gas: 911238)
EnforcerTest:testTermEnforcerBasic() (gas: 983566)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallBase() (gas: 1218188)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLender() (gas: 858353)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLiquidation() (gas: 894602)
TestCustodian:testCannotLazyMintTwice() (gas: 76663)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallBase() (gas: 1039242)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLender() (gas: 691152)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLiquidation() (gas: 770721)
TestCustodian:testCannotLazyMintTwice() (gas: 76597)
TestCustodian:testCannotMintInvalidLoanInvalidCustodian() (gas: 66883)
TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 72400)
TestCustodian:testCustodySelector() (gas: 2818119)
TestCustodian:testDefaultCustodySelectorRevert() (gas: 11672)
TestCustodian:testGenerateOrderInvalidHandlerExecution() (gas: 139368)
TestCustodian:testGenerateOrderRepay() (gas: 176877)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 202524)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNative() (gas: 1115040)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNativeHandlerAuthorized() (gas: 1028737)
TestCustodian:testGenerateOrderRepayERC1155WithRevert() (gas: 524739)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 96790)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 91194)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 102990)
TestCustodian:testGenerateOrderSettlement() (gas: 158129)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 167257)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 162422)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 100769)
TestCustodian:testGetBorrower() (gas: 76157)
TestCustodian:testInvalidAction() (gas: 121504)
TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 124409)
TestCustodian:testInvalidActionSettleActiveLoan() (gas: 124413)
TestCustodian:testName() (gas: 7098)
TestCustodian:testNonPayableFunctions() (gas: 219009)
TestCustodian:testOnlySeaport() (gas: 17975)
TestCustodian:testPayableFunctions() (gas: 43468)
TestCustodian:testPreviewOrderNoActiveLoan() (gas: 105228)
TestCustodian:testPreviewOrderRepay() (gas: 227912)
TestCustodian:testPreviewOrderSettlement() (gas: 190065)
TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 107146)
TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 113276)
TestCustodian:testRatifyOrder() (gas: 183062)
TestCustodian:testSafeTransfer1155Receive() (gas: 115587)
TestCustodian:testSeaportMetadata() (gas: 8589)
TestCustodian:testSetRepayApproval() (gas: 37839)
TestCustodian:testSupportsInterface() (gas: 9406)
TestCustodian:testSymbol() (gas: 7171)
TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 72422)
TestCustodian:testCustodySelector() (gas: 2543980)
TestCustodian:testDefaultCustodySelectorRevert() (gas: 70105)
TestCustodian:testGenerateOrderInvalidHandlerExecution() (gas: 132855)
TestCustodian:testGenerateOrderRepay() (gas: 164375)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 190022)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNative() (gas: 843710)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNativeHandlerAuthorized() (gas: 785342)
TestCustodian:testGenerateOrderRepayERC1155WithRevert() (gas: 518146)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 90249)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 84653)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 96449)
TestCustodian:testGenerateOrderSettlement() (gas: 151381)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160421)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 155620)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 94219)
TestCustodian:testGetBorrower() (gas: 76234)
TestCustodian:testInvalidAction() (gas: 114400)
TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 117327)
TestCustodian:testInvalidActionSettleActiveLoan() (gas: 117287)
TestCustodian:testName() (gas: 7120)
TestCustodian:testNonPayableFunctions() (gas: 225770)
TestCustodian:testOnlySeaport() (gas: 17917)
TestCustodian:testPayableFunctions() (gas: 41689)
TestCustodian:testPreviewOrderNoActiveLoan() (gas: 98687)
TestCustodian:testPreviewOrderRepay() (gas: 208128)
TestCustodian:testPreviewOrderSettlement() (gas: 182676)
TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 100488)
TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 106646)
TestCustodian:testRatifyOrder() (gas: 170218)
TestCustodian:testSeaportMetadata() (gas: 8567)
TestCustodian:testSetRepayApproval() (gas: 37883)
TestCustodian:testSupportsInterface() (gas: 9428)
TestCustodian:testSymbol() (gas: 7149)
TestCustodian:testTokenURI() (gas: 64839)
TestCustodian:testTokenURIInvalidLoan() (gas: 13196)
TestExoticLoans:testSwap() (gas: 1353169)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 164)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 517422)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 711981)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 541506)
TestLoanCombinations:testLoanSimpleInterestEnglishFixed() (gas: 701482)
TestLoanManager:testCannotIssueSameLoanTwice() (gas: 1529536)
TestLoanManager:testCannotSettleInvalidLoan() (gas: 72844)
TestLoanManager:testCannotSettleUnlessValidCustodian() (gas: 68990)
TestLoanManager:testCaveatEnforcerInvalidOrigination() (gas: 1797017)
TestLoanManager:testDefaultFeeRake() (gas: 403187)
TestLoanManager:testExoticDebtWithNoCaveatsAsBorrower() (gas: 1587178)
TestLoanManager:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 1677080)
TestLoanManager:testGenerateOrder() (gas: 1495054)
TestLoanManager:testGenerateOrderInvalidAction() (gas: 1354698)
TestLoanManager:testGenerateOrderNotSeaport() (gas: 13023)
TestLoanManager:testInitializedFlagSetProperly() (gas: 65194)
TestLoanManager:testInvalidDebtLength() (gas: 39181)
TestLoanManager:testInvalidDebtType() (gas: 1364303)
TestLoanManager:testInvalidMaximumSpentEmpty() (gas: 50192)
TestLoanManager:testIssued() (gas: 67041)
TestLoanManager:testName() (gas: 7209)
TestLoanManager:testNativeDebtWithNoCaveatsAsBorrower() (gas: 1500521)
TestLoanManager:testNativeDebtWithNoCaveatsNotAsBorrower() (gas: 1541418)
TestLoanManager:testNativeDebtWithNoCaveatsNotAsBorrowerFeesOn() (gas: 1604810)
TestLoanManager:testNonDefaultCustodianCustodyCallFails() (gas: 23953)
TestLoanManager:testNonDefaultCustodianCustodyCallSuccess() (gas: 25327)
TestLoanManager:testNonPayableFunctions() (gas: 109562)
TestLoanManager:testOverrideFeeRake() (gas: 404503)
TestLoanManager:testPayableFunctions() (gas: 55281)
TestLoanManager:testPreviewOrderInvalidAction() (gas: 1299017)
TestLoanManager:testPreviewOrderOriginationWithNoCaveatsSetAsBorrowerFeeOn() (gas: 1345487)
TestLoanManager:testPreviewOrderOriginationWithNoCaveatsSetAsBorrowerNoFee() (gas: 1313690)
TestLoanManager:testPreviewOrderOriginationWithNoCaveatsSetNotBorrowerFeeOn() (gas: 1354173)
TestLoanManager:testPreviewOrderOriginationWithNoCaveatsSetNotBorrowerNoFee() (gas: 1322064)
TestLoanManager:testPreviewOrderRefinanceAsRefinancerFeeOff() (gas: 1373981)
TestLoanManager:testPreviewOrderRefinanceAsRefinancerFeeOn() (gas: 1399308)
TestLoanManager:testRefinanceNoRefinanceConsideration() (gas: 1386463)
TestLoanManager:testSafeTransfer1155Receive() (gas: 54338)
TestLoanManager:testSeaportMetadata() (gas: 8667)
TestLoanManager:testSupportsInterface() (gas: 9580)
TestLoanManager:testSymbol() (gas: 7238)
TestLoanManager:testTokenURI() (gas: 64967)
TestLoanManager:testTokenURIInvalidLoan() (gas: 13290)
TestLoanManager:testTransferFromFailFromSeaport() (gas: 82187)
TestNewLoan:testBuyNowPayLater() (gas: 1143299)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 982366)
TestNewLoan:testNewLoanERC721CollateralLessDebtThanOffered() (gas: 982700)
TestNewLoan:testNewLoanRefinanceNew() (gas: 702267)
TestNewLoan:testSettleLoan() (gas: 1223445)
TestCustodian:testTokenURIInvalidLoan() (gas: 13218)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 530961)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 499798)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 549718)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 539542)
TestLoanCombinations:testLoanSimpleInterestEnglishFixed() (gas: 544202)
TestLoanManager:testAdditionalTransfers() (gas: 293098)
TestLoanManager:testCannotIssueSameLoanTwice() (gas: 331317)
TestLoanManager:testCannotSettleInvalidLoan() (gas: 72594)
TestLoanManager:testCannotSettleUnlessValidCustodian() (gas: 68772)
TestLoanManager:testCaveatEnforcerRevert() (gas: 116691)
TestLoanManager:testDefaultFeeRake() (gas: 350066)
TestLoanManager:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 342790)
TestLoanManager:testInitializedFlagSetProperly() (gas: 65252)
TestLoanManager:testInvalidAmountCollateral() (gas: 152889)
TestLoanManager:testInvalidAmountCollateral721() (gas: 152987)
TestLoanManager:testInvalidAmountDebt() (gas: 177200)
TestLoanManager:testInvalidItemType() (gas: 138937)
TestLoanManager:testInvalidTransferLengthCollateral() (gas: 161128)
TestLoanManager:testInvalidTransferLengthDebt() (gas: 165661)
TestLoanManager:testIssued() (gas: 67055)
TestLoanManager:testName() (gas: 7184)
TestLoanManager:testNonDefaultCustodianCustodyCallFails() (gas: 190232)
TestLoanManager:testNonDefaultCustodianCustodyCallSuccess() (gas: 258505)
TestLoanManager:testNonPayableFunctions() (gas: 173085)
TestLoanManager:testOverrideFeeRake() (gas: 343904)
TestLoanManager:testSupportsInterface() (gas: 9181)
TestLoanManager:testSymbol() (gas: 7127)
TestLoanManager:testTokenNoCodeCollateral() (gas: 137709)
TestLoanManager:testTokenNoCodeDebt() (gas: 170767)
TestLoanManager:testTokenURI() (gas: 64914)
TestLoanManager:testTokenURIInvalidLoan() (gas: 13244)
TestLoanManager:testTransferFromFail() (gas: 80088)
TestNewLoan:testBuyNowPayLater() (gas: 208)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 389485)
TestNewLoan:testNewLoanERC721CollateralLessDebtThanOffered() (gas: 2259)
TestNewLoan:testNewLoanRefinanceNew() (gas: 207)
TestNewLoan:testSettleLoan() (gas: 163)
TestRefStarPortLib:testSpentToReceived() (gas: 13315)
TestRefStarPortLib:testValidateSalt(address,bytes32) (runs: 256, μ: 33865, ~: 33865)
TestRepayLoan:testRepayLoan() (gas: 683942)
TestRepayLoan:testRepayLoan() (gas: 207)
TestStarPortLib:testSpentToReceived() (gas: 13315)
TestStarPortLib:testValidateSalt(address,bytes32) (runs: 256, μ: 33865, ~: 33865)
43 changes: 15 additions & 28 deletions src/Custodian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {
_beforeApprovalsSetHook(fulfiller, maximumSpent, context);
_setOfferApprovalsWithSeaport(offer);

(ReceivedItem[] memory paymentConsiderations, ReceivedItem[] memory carryFeeConsideration) =
(SpentItem[] memory paymentConsiderations, SpentItem[] memory carryFeeConsideration) =
Pricing(loan.terms.pricing).getPaymentConsideration(loan);

consideration = _mergeConsiderations(paymentConsiderations, carryFeeConsideration, new ReceivedItem[](0));
consideration = _removeZeroAmounts(consideration);
// consideration = _mergeConsiderations(paymentConsiderations, carryFeeConsideration, new ReceivedItem[](0));
// consideration = _removeZeroAmounts(consideration);

_settleLoan(loan);
} else if (action == Actions.Settlement && !SettlementHook(loan.terms.hook).isActive(loan)) {
Expand Down Expand Up @@ -252,20 +252,12 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {
}

/**
* @dev previews the order for this contract offerer.
* @dev If any additional state updates are needed when taking custody of a loan
*
* @param consideration The items received from the order completing
* @param orderHashes The hashes of the orders completed
* @param contractNonce The nonce of the contract in seaport
* @param context The abi encoded bytes passed with the order
* @param loan The loan that was just placed into custody
* @return selector The function selector of the custody method
*/
function custody(
ReceivedItem[] calldata consideration,
bytes32[] calldata orderHashes,
uint256 contractNonce,
bytes calldata context
) external virtual onlyLoanManager returns (bytes4 selector) {
function custody(LoanManager.Loan memory loan) external virtual onlyLoanManager returns (bytes4 selector) {
revert ImplementInChild();
}

Expand Down Expand Up @@ -317,11 +309,11 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {
}
offer = loan.collateral;

(ReceivedItem[] memory paymentConsiderations, ReceivedItem[] memory carryFeeConsideration) =
(SpentItem[] memory paymentConsiderations, SpentItem[] memory carryFeeConsideration) =
Pricing(loan.terms.pricing).getPaymentConsideration(loan);

consideration = _mergeConsiderations(paymentConsiderations, carryFeeConsideration, new ReceivedItem[](0));
consideration = _removeZeroAmounts(consideration);
// consideration = _mergeConsiderations(paymentConsiderations, carryFeeConsideration, new ReceivedItem[](0));
// consideration = _removeZeroAmounts(consideration);
} else if (action == Actions.Settlement && !loanActive) {
address authorized;
(consideration, authorized) = SettlementHandler(loan.terms.handler).getSettlement(loan);
Expand All @@ -343,9 +335,10 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {
* revert with NotEnteredViaSeaport()
*/
function onERC1155Received(address, address, uint256, uint256, bytes calldata) public virtual returns (bytes4) {
try seaport.incrementCounter() {
revert NotEnteredViaSeaport();
} catch {}
// commenting out because, we are not entering this flow via Seaport after teh new origiantion changes
// try seaport.incrementCounter() {
// revert NotEnteredViaSeaport();
// } catch {}
return this.onERC1155Received.selector;
}

Expand All @@ -358,9 +351,7 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {
*/
function _enableAssetWithSeaport(SpentItem memory offer) internal {
//approve consideration based on item type
if (offer.itemType == ItemType.NATIVE) {
payable(address(seaport)).call{value: offer.amount}("");
} else if (offer.itemType == ItemType.ERC721) {
if (offer.itemType == ItemType.ERC721) {
ERC721(offer.token).approve(address(seaport), offer.identifier);
} else if (offer.itemType == ItemType.ERC1155) {
ERC1155(offer.token).setApprovalForAll(address(seaport), true);
Expand Down Expand Up @@ -388,9 +379,7 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {

function _transferCollateralToHandler(SpentItem memory offer, address handler) internal {
//approve consideration based on item type
if (offer.itemType == ItemType.NATIVE) {
payable(address(handler)).call{value: offer.amount}("");
} else if (offer.itemType == ItemType.ERC721) {
if (offer.itemType == ItemType.ERC721) {
ERC721(offer.token).transferFrom(address(this), handler, offer.identifier);
} else if (offer.itemType == ItemType.ERC1155) {
ERC1155(offer.token).safeTransferFrom(address(this), handler, offer.identifier, offer.amount, "");
Expand Down Expand Up @@ -480,6 +469,4 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {
* @param loan The loan being settled
*/
function _afterSettleLoanHook(LoanManager.Loan memory loan) internal virtual {}

receive() external payable onlySeaport {}
}
Loading

0 comments on commit 4ea90dc

Please sign in to comment.