Skip to content

Commit

Permalink
Adds licensing, import conventions, inline documentation (#74)
Browse files Browse the repository at this point in the history
* chore(src): adds licensing, import conventions, inline documentation

* fix: formatting

* chore: update gas snapshot

* feat: conventions and contract organization

* feat: update snapshot

* chore: cleanup comment

* chore: update readme, add license
  • Loading branch information
justingreenberg authored Nov 20, 2023
1 parent 66e489b commit 15f71cf
Show file tree
Hide file tree
Showing 24 changed files with 1,514 additions and 754 deletions.
94 changes: 47 additions & 47 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 327589)
IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 281025)
IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 327586)
IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 281010)
IntegrationTestCaveats:testOriginateWCaveatsAsBorrower() (gas: 303246)
IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 157439)
IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 166170)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 281363)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 140101)
IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 281057)
IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 157436)
IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 166167)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 281357)
IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 140098)
IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 281042)
IntegrationTestCaveats:testRefinanceAsLender() (gas: 1043289)
IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 395348)
IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 342963)
IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 443624)
IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 364730)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 392349)
ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 433475)
ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 436253)
ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 432487)
ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 433286)
ModuleTesting:testModuleValidation() (gas: 1269674)
IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 392337)
ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 433472)
ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 436250)
ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 432484)
ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 433283)
ModuleTesting:testModuleValidation() (gas: 1269671)
PausableNonReentrantImpl:test() (gas: 2442)
PausableNonReentrantImpl:testReentrancy() (gas: 2735)
TestBorrowerEnforcer:testBERevertAdditionalTransfersFromBorrower() (gas: 76318)
Expand All @@ -32,16 +32,16 @@ TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 172968)
TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 163091)
TestCustodian:testGenerateOrderRepay() (gas: 177123)
TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193592)
TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 868471)
TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 798132)
TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 868465)
TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 798126)
TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 97601)
TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 91984)
TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 106839)
TestCustodian:testGenerateOrderSettlement() (gas: 154846)
TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160243)
TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 163308)
TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 101791)
TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 458397)
TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 458394)
TestCustodian:testGetBorrower() (gas: 78619)
TestCustodian:testInvalidAction() (gas: 173196)
TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 130060)
Expand Down Expand Up @@ -69,30 +69,30 @@ TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 81062)
TestLenderEnforcer:testLEValidLoanTerms() (gas: 72055)
TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 72098)
TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 73410)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 587270)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 594461)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 585469)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 575374)
TestNewLoan:testBuyNowPayLater() (gas: 2869309)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 587267)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 594458)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 585466)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 575371)
TestNewLoan:testBuyNowPayLater() (gas: 2869306)
TestNewLoan:testInvalidSenderBNPL() (gas: 1613120)
TestNewLoan:testInvalidUserDataHashBNPL() (gas: 1615699)
TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 861457)
TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 871145)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 424965)
TestNewLoan:testNewLoanRefinance() (gas: 577284)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 325441)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 382057)
TestNewLoan:testSettleLoan() (gas: 636584)
TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 871142)
TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 424962)
TestNewLoan:testNewLoanRefinance() (gas: 577281)
TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 325414)
TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 382042)
TestNewLoan:testSettleLoan() (gas: 636581)
TestPausableNonReentrant:testNotOwner() (gas: 21254)
TestPausableNonReentrant:testPauseAndUnpause() (gas: 22555)
TestPausableNonReentrant:testReentrancy() (gas: 15360)
TestPausableNonReentrant:testUnpauseWhenNotPaused() (gas: 12582)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 658789)
TestRepayLoan:testRepayLoanBase() (gas: 595065)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 434107)
TestRepayLoan:testRepayLoanInSettlement() (gas: 580650)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 599079)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 853478)
TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 658786)
TestRepayLoan:testRepayLoanBase() (gas: 595062)
TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 434104)
TestRepayLoan:testRepayLoanInSettlement() (gas: 580647)
TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 599076)
TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 853475)
TestSimpleInterestPricing:test_calculateInterest() (gas: 899536)
TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 946746)
TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 937602)
Expand All @@ -105,9 +105,9 @@ TestStarport:testCannotIssueSameLoanTwice() (gas: 359427)
TestStarport:testCannotOriginateWhilePaused() (gas: 73501)
TestStarport:testCannotSettleInvalidLoan() (gas: 74881)
TestStarport:testCannotSettleUnlessValidCustodian() (gas: 70985)
TestStarport:testCaveatEnforcerRevert() (gas: 99214)
TestStarport:testDefaultFeeRake() (gas: 358092)
TestStarport:testDefaultFeeRakeExoticDebt() (gas: 368247)
TestStarport:testCaveatEnforcerRevert() (gas: 99211)
TestStarport:testDefaultFeeRake() (gas: 358089)
TestStarport:testDefaultFeeRakeExoticDebt() (gas: 368244)
TestStarport:testExoticDebtWithCustomPricingAndRepayment() (gas: 1235383)
TestStarport:testExoticDebtWithCustomPricingAndSettlement() (gas: 1690431)
TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 374504)
Expand All @@ -123,8 +123,8 @@ TestStarport:testInvalidTransferLengthDebt() (gas: 173547)
TestStarport:testInvalidateCaveatSalt() (gas: 33538)
TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 261852)
TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 288087)
TestStarport:testNonPayableFunctions() (gas: 112087)
TestStarport:testOverrideFeeRake() (gas: 354454)
TestStarport:testNonPayableFunctions() (gas: 112084)
TestStarport:testOverrideFeeRake() (gas: 354451)
TestStarport:testPause() (gas: 18115)
TestStarport:testRefinancePostRepaymentFails() (gas: 120853)
TestStarport:testTokenNoCodeCollateral() (gas: 148380)
Expand All @@ -134,13 +134,13 @@ TestStrategistOriginator:testEncodeWithAccountCounter() (gas: 12307)
TestStrategistOriginator:testGetStrategistData() (gas: 1489933)
TestStrategistOriginator:testIncrementCounterAsStrategist() (gas: 18676)
TestStrategistOriginator:testIncrementCounterNotAuthorized() (gas: 13445)
TestStrategistOriginator:testInvalidCollateral() (gas: 209574)
TestStrategistOriginator:testInvalidDeadline() (gas: 215208)
TestStrategistOriginator:testInvalidDebt() (gas: 211256)
TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 211573)
TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 211872)
TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 211826)
TestStrategistOriginator:testInvalidDebtLength() (gas: 210368)
TestStrategistOriginator:testInvalidOffer() (gas: 424415)
TestStrategistOriginator:testInvalidSigner() (gas: 213725)
TestStrategistOriginator:testInvalidCollateral() (gas: 209562)
TestStrategistOriginator:testInvalidDeadline() (gas: 215196)
TestStrategistOriginator:testInvalidDebt() (gas: 211244)
TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 211561)
TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 211860)
TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 211814)
TestStrategistOriginator:testInvalidDebtLength() (gas: 210356)
TestStrategistOriginator:testInvalidOffer() (gas: 424400)
TestStrategistOriginator:testInvalidSigner() (gas: 213713)
TestStrategistOriginator:testSetStrategist() (gas: 17796)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## ✨ Starport

<!-- TODO -->

### License

[BUSL-1.1](LICENSE) Copyright 2023 Astaria Labs, Inc.
79 changes: 64 additions & 15 deletions src/BNPLHelper.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
// SPDX-License-Identifier: BUSL-1.1
//
// ↑↑↑↑ ↑↑
// ↑↑↑↑ ↑↑↑↑↑
// ↑↑↑↑ ↑ ↑
// ↑↑↑↑ ↑↑↑↑↑
// ↑ ↑↑↑↑ ↑ ↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑ ↑↑ ↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑↑
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑↑
// ↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑↑↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑ ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑↑↑↑ ↑↑↑↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑ Starport: Lending Kernel
// ↑ ↑↑↑↑ ↑↑↑↑↑
// ↑↑↑↑ ↑↑↑↑↑ Designed with love by Astaria Labs, Inc
// ↑↑↑↑ ↑
// ↑↑↑↑
// ↑↑↑↑
// ↑↑↑↑
// ↑↑↑↑

pragma solidity ^0.8.17;

import {Starport} from "starport-core/Starport.sol";
import {CaveatEnforcer} from "starport-core/enforcers/CaveatEnforcer.sol";
import {AdditionalTransfer} from "starport-core/lib/StarportLib.sol";

import {Seaport} from "seaport/contracts/Seaport.sol";
import {
OfferItem,
SpentItem,
ConsiderationItem,
AdvancedOrder,
OrderParameters,
ConsiderationItem,
CriteriaResolver,
Fulfillment,
ItemType,
Fulfillment
OfferItem,
OrderParameters,
SpentItem
} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {AdditionalTransfer} from "starport-core/lib/StarportLib.sol";

import {Seaport} from "seaport/contracts/Seaport.sol";
import {Starport} from "./Starport.sol";
import {CaveatEnforcer} from "./enforcers/CaveatEnforcer.sol";
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERFACES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

interface IVault {
function flashLoan(
Expand All @@ -39,9 +70,30 @@ interface ERC20 {
}

contract BNPLHelper is IFlashLoanRecipient {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

error DoNotSendETH();
error InvalidUserDataProvided();
error SenderNotVault();

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS AND IMMUTABLES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

address private constant vault = address(0xBA12222222228d8Ba445958a75a0704d566BF2C8);

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

bytes32 private activeUserDataHash;

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRUCTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

struct Execution {
address lm;
address seaport;
Expand All @@ -54,18 +106,14 @@ contract BNPLHelper is IFlashLoanRecipient {
Fulfillment[] fulfillments;
}

error SenderNotVault();
error DoNotSendETH();
error InvalidUserDataProvided();

function makeFlashLoan(address[] calldata tokens, uint256[] calldata amounts, bytes calldata userData) external {
activeUserDataHash = keccak256(userData);

IVault(vault).flashLoan(this, tokens, amounts, userData);
}

function receiveFlashLoan(
address[] calldata tokens, // are all erc20s
address[] calldata tokens, // Are all ERC-20s
uint256[] calldata amounts,
uint256[] calldata feeAmounts,
bytes calldata userData
Expand All @@ -80,7 +128,8 @@ contract BNPLHelper is IFlashLoanRecipient {
delete activeUserDataHash;

Execution memory execution = abi.decode(userData, (Execution));
//approve seaport

// Approve seaport
for (uint256 i = 0; i < tokens.length;) {
ERC20(tokens[i]).transfer(execution.borrower, amounts[i]);
unchecked {
Expand Down
Loading

0 comments on commit 15f71cf

Please sign in to comment.