Skip to content

Commit

Permalink
feat: conventions and contract organization
Browse files Browse the repository at this point in the history
  • Loading branch information
justingreenberg committed Nov 20, 2023
1 parent 036beea commit 6ec069e
Show file tree
Hide file tree
Showing 24 changed files with 1,309 additions and 431 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: 2869909)
TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 587267)
TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 594458)
TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 585466)
TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 575371)
TestNewLoan:testBuyNowPayLater() (gas: 2869906)
TestNewLoan:testInvalidSenderBNPL() (gas: 1613720)
TestNewLoan:testInvalidUserDataHashBNPL() (gas: 1616299)
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)
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## ✨ Starport

<!-- TODO -->
<!-- ![Seaport](img/Seaport-banner.png) -->

[![Version][version-badge]][version-link]
[![Test CI][ci-badge]][ci-link]
[![Code Coverage][coverage-badge]][coverage-link]
[![License][license-badge]][license-link]
[![Docs][docs-badge]][docs-link]
[![Discussions][discussions-badge]][discussions-link]
[![JS Library][js-library-badge]][js-library-link]
[![Discord][discord-badge]][discord-link]

## License

[BUSL-1.1](LICENSE) Copyright 2023 Astaria Labs, Inc.

[version-badge]: https://img.shields.io/github/package-json/v/ProjectOpenSea/seaport
[version-link]: https://github.com/ProjectOpenSea/seaport/releases
[ci-badge]: https://github.com/ProjectOpenSea/seaport/actions/workflows/test.yml/badge.svg
[ci-link]: https://github.com/ProjectOpenSea/seaport/actions/workflows/test.yml
[coverage-badge]: https://codecov.io/gh/ProjectOpenSea/seaport/branch/main/graph/badge.svg
[coverage-link]: https://codecov.io/gh/ProjectOpenSea/seaport
[license-badge]: https://img.shields.io/github/license/ProjectOpenSea/seaport
[license-link]: https://github.com/ProjectOpenSea/seaport/blob/main/LICENSE
[docs-badge]: https://img.shields.io/badge/Seaport-documentation-informational
[docs-link]: https://github.com/ProjectOpenSea/seaport/tree/main/docs
[discussions-badge]: https://img.shields.io/badge/Seaport-discussions-blueviolet
[discussions-link]: https://github.com/ProjectOpenSea/seaport/discussions
[js-library-badge]: https://img.shields.io/badge/Seaport.js-library-red
[js-library-link]: https://github.com/ProjectOpenSea/seaport-js
[discord-badge]: https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue
[discord-link]: https://discord.gg/ADXcTXpqry
60 changes: 53 additions & 7 deletions src/BNPLHelper.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
// SPDX-License-Identifier: BUSL-1.1
// Copyright (c) 2023 Astaria Labs
//
// ↑↑↑↑ ↑↑
// ↑↑↑↑ ↑↑↑↑↑
// ↑↑↑↑ ↑ ↑
// ↑↑↑↑ ↑↑↑↑↑
// ↑ ↑↑↑↑ ↑ ↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑ ↑↑ ↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑↑
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑↑
// ↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑↑↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑↑↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑↑ ↑↑ ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑ ↑↑ ↑↑↑ ↑↑↑↑↑↑ ↑↑↑↑↑↑ ↑↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑↑ ↑↑↑
// ↑↑↑↑↑ ↑↑↑↑ ↑↑↑↑ ↑↑↑ Starport: Lending Kernel
// ↑ ↑↑↑↑ ↑↑↑↑↑
// ↑↑↑↑ ↑↑↑↑↑ Designed with love by Astaria Labs, Inc
// ↑↑↑↑ ↑
// ↑↑↑↑
// ↑↑↑↑
// ↑↑↑↑
// ↑↑↑↑

pragma solidity ^0.8.17;

Expand All @@ -19,6 +43,10 @@ import {
SpentItem
} from "seaport-types/src/lib/ConsiderationStructs.sol";

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

interface IVault {
function flashLoan(
IFlashLoanRecipient recipient,
Expand All @@ -42,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 @@ -57,18 +106,14 @@ contract BNPLHelper is IFlashLoanRecipient {
Fulfillment[] fulfillments;
}

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

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 @@ -83,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 6ec069e

Please sign in to comment.