Skip to content

Commit

Permalink
Merge branch 'main' into feat/pricing-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justingreenberg authored Nov 2, 2023
2 parents a446250 + 90411a2 commit d356655
Show file tree
Hide file tree
Showing 34 changed files with 1,396 additions and 621 deletions.
227 changes: 127 additions & 100 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,114 +1,141 @@
DiffFuzzTestStarPortLib:testSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 880501, ~: 882340)
DiffFuzzTestStarPortLib:testSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 880433, ~: 883031)
DiffFuzzTestStarPortLib:testUnboundSpentToReceived((uint8,address,uint256,uint256)[]) (runs: 256, μ: 232899, ~: 237832)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallBase() (gas: 1041013)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLender() (gas: 693016)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLiquidation() (gas: 772585)
TestBorrowerEnforcer:testBERevertAdditionalTransfers() (gas: 73101)
TestAstariaV1Handler:testGetAuctionStart() (gas: 425169)
TestAstariaV1Handler:testGetAuctionStartNotStarted() (gas: 424764)
TestAstariaV1Handler:testGetCurrentAuctionPrice() (gas: 440046)
TestAstariaV1Handler:testGetCurrentAuctionPriceNoAuction() (gas: 428373)
TestAstariaV1Handler:testGetSettlementDutchAuctionSettlementAbove() (gas: 482578)
TestAstariaV1Handler:testGetSettlementFailedDutchAuction() (gas: 440369)
TestAstariaV1Handler:testGetSettlementLoanNotRecalled() (gas: 430871)
TestAstariaV1Handler:testV1SettlementHandlerExecute() (gas: 411378)
TestAstariaV1Handler:testV1SettlementHandlerValidate() (gas: 411490)
TestAstariaV1Handler:testV1SettlementHandlerValidateInvalidHandler() (gas: 411614)
TestAstariaV1Hook:testCannotRecallTwice() (gas: 567550)
TestAstariaV1Hook:testCannotWithdrawLoanHasNotBeenRefinanced() (gas: 417239)
TestAstariaV1Hook:testCannotWithdrawWithdrawDoesNotExist() (gas: 423656)
TestAstariaV1Hook:testGenerateRecallConsideration() (gas: 466708)
TestAstariaV1Hook:testInvalidRecallInvalidStakeType() (gas: 483833)
TestAstariaV1Hook:testInvalidRecallLoanDoesNotExist() (gas: 513060)
TestAstariaV1Hook:testIsActive() (gas: 424376)
TestAstariaV1Hook:testIsRecalledInsideWindow() (gas: 560673)
TestAstariaV1Hook:testIsRecalledOutsideWindow() (gas: 558574)
TestAstariaV1Hook:testRecallRateActiveRecall() (gas: 546234)
TestAstariaV1Hook:testRecallRateEmptyRecall() (gas: 421919)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallBase() (gas: 1007784)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLender() (gas: 717605)
TestAstariaV1Loan:testNewLoanERC721CollateralDefaultTermsRecallLiquidation() (gas: 742743)
TestBorrowerEnforcer:testBERevertAdditionalTransfers() (gas: 73128)
TestBorrowerEnforcer:testBERevertInvalidLoanTerms() (gas: 78338)
TestBorrowerEnforcer:testBEValidLoanTerms() (gas: 69429)
TestBorrowerEnforcer:testBEValidLoanTermsAnyIssuer() (gas: 69581)
TestCustodian:testCannotLazyMintTwice() (gas: 76686)
TestCustodian:testCannotMintInvalidLoanInvalidCustodian() (gas: 66883)
TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 72511)
TestCustodian:testCustodySelector() (gas: 2543980)
TestCustodian:testDefaultCustodySelectorRevert() (gas: 70105)
TestCustodian:testGenerateOrderInvalidHandlerExecution() (gas: 132855)
TestCustodian:testGenerateOrderRepay() (gas: 164353)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 190000)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNative() (gas: 847956)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNativeHandlerAuthorized() (gas: 789588)
TestCustodian:testGenerateOrderRepayERC1155WithRevert() (gas: 520259)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 90249)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 84653)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 96449)
TestCustodian:testGenerateOrderSettlement() (gas: 151359)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160399)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 155598)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 94219)
TestCustodian:testGetBorrower() (gas: 76234)
TestCustodian:testInvalidAction() (gas: 114489)
TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 117416)
TestCustodian:testInvalidActionSettleActiveLoan() (gas: 117376)
TestCustodian:testName() (gas: 7120)
TestCustodian:testCannotLazyMintTwice() (gas: 76698)
TestCustodian:testCannotMintInvalidLoanInvalidCustodian() (gas: 66861)
TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 72501)
TestCustodian:testCustodySelector() (gas: 2625664)
TestCustodian:testDefaultCustodySelectorRevert() (gas: 70083)
TestCustodian:testGenerateOrderInvalidHandlerExecution() (gas: 132813)
TestCustodian:testGenerateOrderRepay() (gas: 173924)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 199549)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNative() (gas: 865388)
TestCustodian:testGenerateOrderRepayERC1155AndERC20AndNativeHandlerAuthorized() (gas: 790527)
TestCustodian:testGenerateOrderRepayERC1155WithRevert() (gas: 530139)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 90307)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 84624)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 96398)
TestCustodian:testGenerateOrderSettlement() (gas: 151490)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160486)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 155707)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 94177)
TestCustodian:testGetBorrower() (gas: 76322)
TestCustodian:testInvalidAction() (gas: 114421)
TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 117370)
TestCustodian:testInvalidActionSettleActiveLoan() (gas: 117330)
TestCustodian:testName() (gas: 7098)
TestCustodian:testNonPayableFunctions() (gas: 225770)
TestCustodian:testOnlySeaport() (gas: 17917)
TestCustodian:testPayableFunctions() (gas: 41689)
TestCustodian:testPreviewOrderNoActiveLoan() (gas: 98776)
TestCustodian:testPreviewOrderRepay() (gas: 208195)
TestCustodian:testPreviewOrderSettlement() (gas: 182743)
TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 100577)
TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 106735)
TestCustodian:testRatifyOrder() (gas: 170196)
TestCustodian:testSeaportMetadata() (gas: 8567)
TestCustodian:testSetRepayApproval() (gas: 37883)
TestCustodian:testOnlySeaport() (gas: 17895)
TestCustodian:testPayableFunctions() (gas: 41667)
TestCustodian:testPreviewOrderNoActiveLoan() (gas: 98737)
TestCustodian:testPreviewOrderRepay() (gas: 225878)
TestCustodian:testPreviewOrderSettlement() (gas: 182831)
TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 100655)
TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 106785)
TestCustodian:testRatifyOrder() (gas: 180093)
TestCustodian:testSeaportMetadata() (gas: 8545)
TestCustodian:testSetRepayApproval() (gas: 37861)
TestCustodian:testSupportsInterface() (gas: 9428)
TestCustodian:testSymbol() (gas: 7149)
TestCustodian:testTokenURI() (gas: 64839)
TestCustodian:testTokenURIInvalidLoan() (gas: 13218)
TestLenderEnforcer:testLERevertAdditionalTransfersFromLender() (gas: 73760)
TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 78385)
TestLenderEnforcer:testLEValidLoanTerms() (gas: 69429)
TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 69516)
TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 70757)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 532861)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 501718)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 551584)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 541442)
TestLoanCombinations:testLoanSimpleInterestEnglishFixed() (gas: 546102)
TestLoanManager:testAdditionalTransfers() (gas: 293082)
TestLoanManager:testCannotIssueSameLoanTwice() (gas: 331285)
TestLoanManager:testCannotOriginateWhilePaused() (gas: 87923)
TestLoanManager:testCannotSettleInvalidLoan() (gas: 72594)
TestLoanManager:testCannotSettleUnlessValidCustodian() (gas: 68750)
TestLoanManager:testCaveatEnforcerRevert() (gas: 119155)
TestLoanManager:testDefaultFeeRake() (gas: 352463)
TestLoanManager:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 342734)
TestLoanManager:testInitializedFlagSetProperly() (gas: 65262)
TestLoanManager:testInvalidAmountCollateral() (gas: 152833)
TestLoanManager:testInvalidAmountCollateral721() (gas: 152976)
TestLoanManager:testInvalidAmountDebt() (gas: 177144)
TestLoanManager:testInvalidIdentifierDebt() (gas: 197138)
TestLoanManager:testInvalidItemType() (gas: 138881)
TestLoanManager:testInvalidTransferLengthCollateral() (gas: 161050)
TestLoanManager:testInvalidTransferLengthDebt() (gas: 165593)
TestLoanManager:testIssued() (gas: 67144)
TestLoanManager:testName() (gas: 7184)
TestLoanManager:testNonDefaultCustodianCustodyCallFails() (gas: 190220)
TestLoanManager:testNonDefaultCustodianCustodyCallSuccess() (gas: 258469)
TestLoanManager:testNonPayableFunctions() (gas: 175555)
TestLoanManager:testOverrideFeeRake() (gas: 346202)
TestLoanManager:testPause() (gas: 34222)
TestCustodian:testSymbol() (gas: 7127)
TestCustodian:testTokenURI() (gas: 64817)
TestCustodian:testTokenURIInvalidLoan() (gas: 13196)
TestLenderEnforcer:testLERevertAdditionalTransfersFromLender() (gas: 73765)
TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 78363)
TestLenderEnforcer:testLEValidLoanTerms() (gas: 69496)
TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 69494)
TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 70762)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 553060)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 540665)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 570896)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 560626)
TestLoanCombinations:testLoanSimpleInterestEnglishFixed() (gas: 566100)
TestLoanManager:testActive() (gas: 67135)
TestLoanManager:testAdditionalTransfers() (gas: 293454)
TestLoanManager:testCannotIssueSameLoanTwice() (gas: 331845)
TestLoanManager:testCannotOriginateWhilePaused() (gas: 87814)
TestLoanManager:testCannotSettleInvalidLoan() (gas: 72745)
TestLoanManager:testCannotSettleUnlessValidCustodian() (gas: 68772)
TestLoanManager:testCaveatEnforcerRevert() (gas: 119189)
TestLoanManager:testDefaultFeeRake() (gas: 352859)
TestLoanManager:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 343160)
TestLoanManager:testInitializedFlagSetProperly() (gas: 65234)
TestLoanManager:testInvalidAmountCollateral() (gas: 152921)
TestLoanManager:testInvalidAmountCollateral721() (gas: 153064)
TestLoanManager:testInvalidAmountDebt() (gas: 177254)
TestLoanManager:testInvalidIdentifierDebt() (gas: 197248)
TestLoanManager:testInvalidItemType() (gas: 138969)
TestLoanManager:testInvalidTransferLengthCollateral() (gas: 161133)
TestLoanManager:testInvalidTransferLengthDebt() (gas: 165654)
TestLoanManager:testIssued() (gas: 67084)
TestLoanManager:testName() (gas: 7251)
TestLoanManager:testNonDefaultCustodianCustodyCallFails() (gas: 190362)
TestLoanManager:testNonDefaultCustodianCustodyCallSuccess() (gas: 258841)
TestLoanManager:testNonPayableFunctions() (gas: 175599)
TestLoanManager:testOverrideFeeRake() (gas: 346620)
TestLoanManager:testPause() (gas: 34091)
TestLoanManager:testSupportsInterface() (gas: 9181)
TestLoanManager:testSymbol() (gas: 7235)
TestLoanManager:testTokenNoCodeCollateral() (gas: 137653)
TestLoanManager:testTokenNoCodeDebt() (gas: 170689)
TestLoanManager:testTokenURI() (gas: 64892)
TestLoanManager:testTokenURIInvalidLoan() (gas: 13244)
TestLoanManager:testTransferFromFail() (gas: 80176)
TestLoanManager:testTokenNoCodeCollateral() (gas: 137741)
TestLoanManager:testTokenNoCodeDebt() (gas: 170885)
TestLoanManager:testTokenURI() (gas: 64945)
TestLoanManager:testTokenURIInvalidLoan() (gas: 13384)
TestLoanManager:testTransferFromFail() (gas: 80088)
TestLoanManager:testUnPause() (gas: 14291)
TestNewLoan:testBuyNowPayLater() (gas: 2831719)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 391890)
TestNewLoan:testNewLoanERC721CollateralLessDebtThanOffered() (gas: 2259)
TestNewLoan:testNewLoanRefinanceNew() (gas: 207)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 299336)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 353952)
TestNewLoan:testSettleLoan() (gas: 163)
TestNewLoan:testBuyNowPayLater() (gas: 2830344)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 392228)
TestNewLoan:testNewLoanERC721CollateralLessDebtThanOffered() (gas: 2348)
TestNewLoan:testNewLoanRefinanceNew() (gas: 185)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 299558)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 354228)
TestNewLoan:testSettleLoan() (gas: 252)
TestRefStarPortLib:testSpentToReceived() (gas: 13315)
TestRefStarPortLib:testValidateSalt(address,bytes32) (runs: 256, μ: 33865, ~: 33865)
TestRepayLoan:testRepayLoan() (gas: 207)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 643968)
TestRepayLoan:testRepayLoanBase() (gas: 580372)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 400095)
TestRepayLoan:testRepayLoanInSettlement() (gas: 541092)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 560501)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 849335)
TestStarPortLib:testSpentToReceived() (gas: 13315)
TestStarPortLib:testValidateSalt(address,bytes32) (runs: 256, μ: 33865, ~: 33865)
TestStrategistOriginator:testEncodeWithAccountCounter() (gas: 12307)
TestStrategistOriginator:testGetStrategistData() (gas: 1473217)
TestStrategistOriginator:testIncrementCounterAsStrategist() (gas: 18676)
TestStrategistOriginator:testIncrementCounterNotAuthorized() (gas: 13467)
TestStrategistOriginator:testInvalidCollateral() (gas: 204416)
TestStrategistOriginator:testInvalidDeadline() (gas: 210145)
TestStrategistOriginator:testInvalidDebt() (gas: 206100)
TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 206548)
TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 186903)
TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 206801)
TestStrategistOriginator:testInvalidDebtLength() (gas: 205428)
TestStrategistOriginator:testInvalidOffer() (gas: 396325)
TestStrategistOriginator:testInvalidSigner() (gas: 208639)
TestStrategistOriginator:testSetStrategist() (gas: 17818)
TestStrategistOriginator:testGetStrategistData() (gas: 1471010)
TestStrategistOriginator:testIncrementCounterAsStrategist() (gas: 18654)
TestStrategistOriginator:testIncrementCounterNotAuthorized() (gas: 13445)
TestStrategistOriginator:testInvalidCollateral() (gas: 204438)
TestStrategistOriginator:testInvalidDeadline() (gas: 210167)
TestStrategistOriginator:testInvalidDebt() (gas: 206122)
TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 206570)
TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 186947)
TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 206823)
TestStrategistOriginator:testInvalidDebtLength() (gas: 205450)
TestStrategistOriginator:testInvalidOffer() (gas: 396601)
TestStrategistOriginator:testInvalidSigner() (gas: 208683)
TestStrategistOriginator:testSetStrategist() (gas: 17796)
57 changes: 57 additions & 0 deletions mermaid/origination.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
sequenceDiagram
title Starport Origination Sequence Diagram
participant F as Fulfiller
participant L as Lender
participant B as Borrower


F->>LoanManager: originate

opt F is not Borrower
loop 1->n
LoanManager->>CaveatEnforcer: validate
end
end
opt F is not Lender
loop 1->n
LoanManager->>CaveatEnforcer: validate
end
end
loop Transfer 1->n collateral items
B->>Custodian: Move Collateral to Custodian
end
opt Custodian is not default
LoanManager->>Custodian: custody (optional)
end

alt Fees Disabled
loop Transfer 1->n debt items
L->>B: Move debt to borrower
end
else Fees Enabled
LoanManager->>LoanManager: compute feeRake
opt FeeItems length > 0
loop Transfer 1->n fee items
L->>FeeRecipient: Move Fee to FeeRecipient
end
end
loop Transfer 1->n debt items
L->>B: Move debt to Borrower
end
end

opt AdditionalTransferItems length > 0
loop 1->n
alt From is Borrower
B->>AdditionalTransferRecipient: AdditionalTransferItem from Borrower => AdditionalTransferRecipient
else From is Lender
L->>AdditionalTransferRecipient: AdditionalTransferItem from Lender => AdditionalTransferRecipient
else From is F
F->>AdditionalTransferRecipient: AdditionalTransferItem from Fulfiller => AdditionalTransferRecipient
end
end
end

opt Lender is contract
LoanManager->>L: onERC721Received
end
1 change: 1 addition & 0 deletions mermaid/origination.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/BNPLHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ItemType,
Fulfillment
} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {ConduitTransfer, ConduitItemType} from "seaport-types/src/conduit/lib/ConduitStructs.sol";
import {AdditionalTransfer} from "starport-core/lib/StarPortLib.sol";

import {Seaport} from "seaport/contracts/Seaport.sol";
import {LoanManager} from "./LoanManager.sol";
Expand Down Expand Up @@ -113,10 +113,10 @@ contract BNPLHelper is IFlashLoanRecipient {
execution.orders, execution.resolvers, execution.fulfillments, execution.borrower
);

ConduitTransfer[] memory transfers = new ConduitTransfer[](tokens.length);
AdditionalTransfer[] memory transfers = new AdditionalTransfer[](tokens.length);
for (uint256 i = 0; i < tokens.length;) {
transfers[i] = ConduitTransfer({
itemType: ConduitItemType.ERC20,
transfers[i] = AdditionalTransfer({
itemType: ItemType.ERC20,
identifier: 0,
token: tokens[0],
from: execution.borrower,
Expand Down
Loading

0 comments on commit d356655

Please sign in to comment.