✨ Starport: Lending Kernel

Starport is a kernel for building lending protocols. A lending protocol can be implemented by inheriting and implementing the interfaces Pricing, Status, and Settlement. To learn more about how Starport works read the Starport whitepaper.

Deployments

Canonical Cross-chain Deployment Addresses

Contract Canonical Cross-chain Deployment Address
Starport 0x0000000000b1827b4959F2805E4b480D8799FCbB
Custodian 0x00000000c0c2Bae0eAA1b666fC2568CcaA9A9b3d

Note: The canonical contracts for Starport, do not include modules. The modules included in this repository should be considered unsafe unless explicitly named in the audit report.

Deployments By EVM Chain

Network Starport Custodian
Ethereum 0x0000000000b1827b4959F2805E4b480D8799FCbB 0x00000000000001ad428e4906aE43D8F9852d0dD6

Install

To install dependencies and compile contracts:

git clone --recurse-submodules https://github.com/AstariaXYZ/starport.git && cd starport
yarn install
forge build

Usage

To run forge tests written in Solidity:

yarn test

Audits

Astaria engaged Certora to audit and formally verify the security of Starport. From September 27th 2023 to January 24th 2024, a team of Certora auditors and formal verifiers conducted a security review of Starport. The audit did not uncover significant flaws that could result in the compromise of a smart contract, loss of funds, or unexpected behavior in the target system. The full report will me made available shortly.

License

BUSL-1.1 Copyright 2023 Astaria Labs, Inc.

Contents

BorrowerEnforcer

Git Source

Inherits: CaveatEnforcer

Functions

validate

Enforces that the loan terms are identical except for the issuer The issuer is allowed to be any address No additional transfers are permitted

function validate(
    AdditionalTransfer[] calldata additionalTransfers,
    Starport.Loan calldata loan,
    bytes calldata caveatData
) public view virtual override returns (bytes4 selector);

Parameters

NameTypeDescription
additionalTransfersAdditionalTransfer[]The additional transfers to be made
loanStarport.LoanThe loan terms
caveatDatabytesThe borrowers encoded details

_validate

function _validate(
    AdditionalTransfer[] calldata additionalTransfers,
    Starport.Loan calldata loan,
    Details memory details
) internal pure;

Errors

BorrowerOnlyEnforcer

error BorrowerOnlyEnforcer();

InvalidLoanTerms

error InvalidLoanTerms();

InvalidAdditionalTransfer

error InvalidAdditionalTransfer();

Structs

Details

struct Details {
    Starport.Loan loan;
}

BorrowerEnforcerBNPL

Git Source

Inherits: CaveatEnforcer

Functions

validate

Enforces that the loan terms are identical except for the issuer The issuer is allowed to be any address

function validate(
    AdditionalTransfer[] calldata additionalTransfers,
    Starport.Loan calldata loan,
    bytes calldata caveatData
) public view virtual override returns (bytes4 selector);

Parameters

NameTypeDescription
additionalTransfersAdditionalTransfer[]The additional transfers to be made
loanStarport.LoanThe loan terms
caveatDatabytesThe borrowers encoded details

Errors

BorrowerOnlyEnforcer

error BorrowerOnlyEnforcer();

InvalidLoanTerms

error InvalidLoanTerms();

InvalidAdditionalTransfer

error InvalidAdditionalTransfer();

OrderInvalid

error OrderInvalid();

Structs

Details

struct Details {
    Starport.Loan loan;
    address seaport;
    bytes32 offerHash;
    AdditionalTransfer additionalTransfer;
}

CaveatEnforcer

Git Source

Functions

validate

Enforces that the loan terms are identical except for the issuer

function validate(AdditionalTransfer[] calldata solution, Starport.Loan calldata loan, bytes calldata caveatData)
    public
    view
    virtual
    returns (bytes4);

Parameters

NameTypeDescription
solutionAdditionalTransfer[]The additional transfers to be made
loanStarport.LoanThe loan terms
caveatDatabytesThe borrowers encoded details

Structs

Caveat

struct Caveat {
    address enforcer;
    bytes data;
}

SignedCaveats

struct SignedCaveats {
    bool singleUse;
    uint256 deadline;
    bytes32 salt;
    Caveat[] caveats;
    bytes signature;
}

LenderEnforcer

Git Source

Inherits: CaveatEnforcer

Functions

validate

Enforces that the loan terms are identical except for the issuer The borrower is allowed to be any address No additional transfers from the issuer are permitted

function validate(
    AdditionalTransfer[] calldata additionalTransfers,
    Starport.Loan calldata loan,
    bytes calldata caveatData
) public view virtual override returns (bytes4 selector);

Parameters

NameTypeDescription
additionalTransfersAdditionalTransfer[]The additional transfers to be made
loanStarport.LoanThe loan terms
caveatDatabytesThe borrowers encoded details

_validate

function _validate(
    AdditionalTransfer[] calldata additionalTransfers,
    Starport.Loan calldata loan,
    Details memory details
) internal pure;

Errors

InvalidLoanTerms

error InvalidLoanTerms();

InvalidAdditionalTransfer

error InvalidAdditionalTransfer();

Structs

Details

struct Details {
    Starport.Loan loan;
}

Contents

TokenReceiverInterface

Git Source

Functions

onERC721Received

function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
    external
    returns (bytes4);

onERC1155Received

function onERC1155Received(address, address, uint256, uint256, bytes calldata) external returns (bytes4);

onERC1155BatchReceived

function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
    external
    returns (bytes4);

Contents

PausableNonReentrant

Git Source

Inherits: Ownable

State Variables

_UNLOCKED

uint256 private constant _UNLOCKED = 0x1;

_LOCKED

uint256 private constant _LOCKED = 0x2;

_PAUSED

uint256 private constant _PAUSED = 0x3;

_state

uint256 private _state = _UNLOCKED;

Functions

pausableNonReentrant

modifier pausableNonReentrant();

pause

function pause() external onlyOwner;

unpause

function unpause() external onlyOwner;

paused

function paused() external view returns (bool);

Events

Paused

event Paused();

Unpaused

event Unpaused();

Errors

IsPaused

error IsPaused();

IsLocked

error IsLocked();

NotPaused

error NotPaused();

Actions

Git Source

enum Actions {
    Nothing,
    Origination,
    Refinance,
    Repayment,
    Settlement
}

RefStarportLib

Git Source

Functions

validateSalt

function validateSalt(mapping(address => mapping(bytes32 => bool)) storage usedSalts, address validator, bytes32 salt)
    internal;

Errors

InvalidSalt

error InvalidSalt();

Actions

Git Source

enum Actions {
    Nothing,
    Repayment,
    Settlement
}

AdditionalTransfer

Git Source

struct AdditionalTransfer {
    ItemType itemType;
    address token;
    address from;
    address to;
    uint256 identifier;
    uint256 amount;
}

StarportLib

Git Source

State Variables

_INVALID_SALT

uint256 internal constant _INVALID_SALT = 0x81e69d9b00000000000000000000000000000000000000000000000000000000;

Functions

calculateSimpleInterest

function calculateSimpleInterest(uint256 delta_t, uint256 amount, uint256 rate, uint256 decimals)
    public
    pure
    returns (uint256);

getId

function getId(Starport.Loan memory loan) internal pure returns (uint256 loanId);

validateSalt

function validateSalt(mapping(address => mapping(bytes32 => bool)) storage usedSalts, address validator, bytes32 salt)
    internal;

mergeSpentItemsToReceivedItems

Merges an array of SpentItems into ReceivedItems

function mergeSpentItemsToReceivedItems(
    SpentItem[] memory payment,
    address paymentRecipient,
    SpentItem[] memory carry,
    address carryRecipient
) internal pure returns (ReceivedItem[] memory consideration);

Parameters

NameTypeDescription
paymentSpentItem[]The SpentItem[] for payment
paymentRecipientaddressThe recipient address of the payment
carrySpentItem[]The SpentItem[] for carry
carryRecipientaddressThe recipient address of the carry

Returns

NameTypeDescription
considerationReceivedItem[]An array of ReceivedItems

removeZeroAmountItems

Removes ReceivedItems with zero amounts

function removeZeroAmountItems(ReceivedItem[] memory consideration)
    internal
    pure
    returns (ReceivedItem[] memory newConsideration);

Parameters

NameTypeDescription
considerationReceivedItem[]The ReceivedItem[] for payment

Returns

NameTypeDescription
newConsiderationReceivedItem[]An array of ReceivedItems with zero amounts removed

transferAdditionalTransfersCalldata

function transferAdditionalTransfersCalldata(AdditionalTransfer[] calldata transfers) internal;

transferAdditionalTransfers

function transferAdditionalTransfers(AdditionalTransfer[] memory transfers) internal;

transferSpentItems

function transferSpentItems(SpentItem[] memory transfers, address from, address to, bool safe) internal;

transferSpentItemsSelf

function transferSpentItemsSelf(SpentItem[] memory transfers, address to) internal;

_transferItem

function _transferItem(
    ItemType itemType,
    address token,
    uint256 identifier,
    uint256 amount,
    address from,
    address to,
    bool safe
) internal;

_transferItem

function _transferItem(ItemType itemType, address token, uint256 identifier, uint256 amount, address from, address to)
    internal;

Errors

InvalidSalt

error InvalidSalt();

InvalidItemAmount

error InvalidItemAmount();

NativeAssetsNotSupported

error NativeAssetsNotSupported();

InvalidItemTokenNoCode

error InvalidItemTokenNoCode();

InvalidItemIdentifier

error InvalidItemIdentifier();

InvalidItemType

error InvalidItemType();

InvalidTransferLength

error InvalidTransferLength();

Validation

Git Source

Functions

validate

function validate(Starport.Loan calldata) external view virtual returns (bytes4);

Contents

Originator

Git Source

Functions

originate

Accepts a request with signed data that is decoded by the originator communicates with Starport to originate a loan

function originate(Request calldata params) external virtual;

Parameters

NameTypeDescription
paramsRequestThe request for the origination

Structs

Request

struct Request {
    address borrower;
    CaveatEnforcer.SignedCaveats borrowerCaveat;
    SpentItem[] collateral;
    SpentItem[] debt;
    bytes details;
    bytes approval;
}

StrategistOriginator

Git Source

Inherits: Ownable, Originator, TokenReceiverInterface

State Variables

SP

Starport public immutable SP;

EIP_DOMAIN

bytes32 public constant EIP_DOMAIN = keccak256("EIP712Domain(string version,uint256 chainId,address verifyingContract)");

ORIGINATOR_DETAILS_TYPEHASH

bytes32 public constant ORIGINATOR_DETAILS_TYPEHASH = keccak256("Origination(uint256 nonce,bytes32 hash)");

VERSION

bytes32 public constant VERSION = keccak256("0");

_DOMAIN_SEPARATOR

bytes32 internal immutable _DOMAIN_SEPARATOR;

usedHashes

mapping(bytes32 => bool) public usedHashes;

strategist

address public strategist;

_counter

uint256 private _counter;

Functions

constructor

constructor(Starport SP_, address strategist_, address owner);

setStrategist

Sets the strategist address

function setStrategist(address newStrategist) external onlyOwner;

Parameters

NameTypeDescription
newStrategistaddressThe new strategist address

incrementCounter

increments the Counter to invalidate any open offers

function incrementCounter() external;

originate

Accepts a request with signed data that is decoded by the originator communicates with Starport to originate a loan

function originate(Request calldata params) external virtual override;

Parameters

NameTypeDescription
paramsRequestThe request for the origination

encodeWithAccountCounter

Returns data that is encodePacked for signing

function encodeWithAccountCounter(bytes32 contextHash) public view virtual returns (bytes memory);

Parameters

NameTypeDescription
contextHashbytes32The hash of the data being signed

getCounter

Returns the nonce of the contract

function getCounter() public view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256_counter

domainSeparator

Returns the domain separator

function domainSeparator() public view virtual returns (bytes32);

Returns

NameTypeDescription
<none>bytes32_DOMAIN_SEPARATOR

_validateAsk

function _validateAsk(Request calldata request, Details memory details) internal virtual;

_validateOffer

function _validateOffer(Request calldata request, Details memory details) internal virtual;

_validateSignature

function _validateSignature(bytes32 hash, bytes memory signature) internal view virtual;

withdraw

function withdraw(SpentItem[] memory transfers, address recipient) external onlyOwner;

onERC721Received

function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
    public
    pure
    virtual
    override
    returns (bytes4);

onERC1155Received

function onERC1155Received(address, address, uint256, uint256, bytes calldata)
    external
    pure
    virtual
    override
    returns (bytes4);

onERC1155BatchReceived

function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
    external
    pure
    virtual
    override
    returns (bytes4);

Events

CounterUpdated

event CounterUpdated(uint256);

HashInvalidated

event HashInvalidated(bytes32 hash);

StrategistTransferred

event StrategistTransferred(address newStrategist);

Errors

AdditionalTransferError

error AdditionalTransferError();

InvalidCollateral

error InvalidCollateral();

InvalidDeadline

error InvalidDeadline();

InvalidDebt

error InvalidDebt();

InvalidDebtAmount

error InvalidDebtAmount();

InvalidDebtLength

error InvalidDebtLength();

InvalidOffer

error InvalidOffer();

InvalidSigner

error InvalidSigner();

NotAuthorized

error NotAuthorized();

NotStarport

error NotStarport();

Structs

Details

struct Details {
    address custodian;
    address issuer;
    uint256 deadline;
    Offer offer;
}

Offer

struct Offer {
    bytes32 salt;
    Starport.Terms terms;
    SpentItem[] collateral;
    SpentItem[] debt;
}

Contents

BasePricing

Git Source

Inherits: Pricing

Functions

validate

function validate(Starport.Loan calldata loan) external view virtual override returns (bytes4);

getPaymentConsideration

function getPaymentConsideration(Starport.Loan calldata loan)
    public
    view
    virtual
    override
    returns (SpentItem[] memory repayConsideration, SpentItem[] memory carryConsideration);

getInterest

Computes the interest for a given loan

function getInterest(
    Starport.Loan calldata loan,
    uint256 rate,
    uint256 start,
    uint256 end,
    uint256 index,
    uint256 decimals
) public pure returns (uint256);

Parameters

NameTypeDescription
loanStarport.LoanThe loan to compute the interest for
rateuint256The interest rate
startuint256The start time frame
enduint256The end time frame
indexuint256The index of the debt to compute the interest for
decimalsuint256The decimals of the debt asset

calculateInterest

Computes the interest

function calculateInterest(uint256 delta_t, uint256 amount, uint256 rate, uint256 decimals)
    public
    pure
    virtual
    returns (uint256);

Parameters

NameTypeDescription
delta_tuint256The time delta
amountuint256The amount to compute the interest for
rateuint256The interest rate
decimalsuint256The decimals of the base asset

Structs

Details

struct Details {
    uint256 rate;
    uint256 carryRate;
    uint256 decimals;
}

Pricing

Git Source

Inherits: Validation

State Variables

SP

Starport public immutable SP;

Functions

constructor

constructor(Starport SP_);

getPaymentConsideration

computes the payment details for a loan

function getPaymentConsideration(Starport.Loan calldata loan)
    public
    view
    virtual
    returns (SpentItem[] memory, SpentItem[] memory);

Parameters

NameTypeDescription
loanStarport.LoanThe loan to compute the payment details for

getRefinanceConsideration

computes the refinance details for a loan

function getRefinanceConsideration(Starport.Loan calldata loan, bytes calldata newPricingData, address fulfiller)
    external
    view
    virtual
    returns (SpentItem[] memory, SpentItem[] memory, AdditionalTransfer[] memory);

Parameters

NameTypeDescription
loanStarport.LoanThe loan to compute the payment details for
newPricingDatabytesThe new pricing data being offered
fulfilleraddressThe address of the fulfiller

Errors

InvalidRefinance

error InvalidRefinance();

SimpleInterestPricing

Git Source

Inherits: BasePricing

Functions

constructor

constructor(Starport SP_) Pricing(SP_);

calculateInterest

function calculateInterest(uint256 delta_t, uint256 amount, uint256 rate, uint256 decimals)
    public
    pure
    override
    returns (uint256);

validate

function validate(Starport.Loan calldata loan) external pure override returns (bytes4);

getRefinanceConsideration

function getRefinanceConsideration(Starport.Loan calldata loan, bytes memory newPricingData, address)
    external
    view
    virtual
    override
    returns (
        SpentItem[] memory repayConsideration,
        SpentItem[] memory carryConsideration,
        AdditionalTransfer[] memory additionalConsideration
    );

Contents

DutchAuctionSettlement

Git Source

Inherits: Settlement, AmountDeriver

Functions

constructor

constructor(Starport SP_) Settlement(SP_);

postSettlement

function postSettlement(Starport.Loan calldata loan, address fulfiller) external virtual override returns (bytes4);

postRepayment

function postRepayment(Starport.Loan calldata, address) external virtual override returns (bytes4);

validate

function validate(Starport.Loan calldata loan) external view virtual override returns (bytes4);

getAuctionStart

Get the start of the auction

function getAuctionStart(Starport.Loan calldata loan) public view virtual returns (uint256);

Parameters

NameTypeDescription
loanStarport.LoanThe loan being referenced

Returns

NameTypeDescription
<none>uint256uint256 The start of the auction

getSettlementConsideration

function getSettlementConsideration(Starport.Loan calldata loan)
    public
    view
    virtual
    override
    returns (ReceivedItem[] memory consideration, address authorized);

Errors

AuctionNotStarted

error AuctionNotStarted();

Structs

Details

struct Details {
    uint256 startingPrice;
    uint256 endingPrice;
    uint256 window;
}

FixedTermDutchAuctionSettlement

Git Source

Inherits: DutchAuctionSettlement

Functions

constructor

constructor(Starport SP_) DutchAuctionSettlement(SP_);

getAuctionStart

function getAuctionStart(Starport.Loan calldata loan) public view virtual override returns (uint256);

Settlement

Git Source

Inherits: Validation

State Variables

SP

Starport public immutable SP;

Functions

constructor

constructor(Starport SP_);

postSettlement

function postSettlement(Starport.Loan calldata loan, address fulfiller) external virtual returns (bytes4);

postRepayment

function postRepayment(Starport.Loan calldata loan, address fulfiller) external virtual returns (bytes4);

getSettlementConsideration

function getSettlementConsideration(Starport.Loan calldata loan)
    public
    view
    virtual
    returns (ReceivedItem[] memory consideration, address authorized);

onERC1155Received

function onERC1155Received(address, address, uint256, uint256, bytes calldata) external view returns (bytes4);

Contents

FixedTermStatus

Git Source

Inherits: Status

Functions

isActive

function isActive(Starport.Loan calldata loan, bytes calldata extraData) external view override returns (bool);

validate

function validate(Starport.Loan calldata loan) external view override returns (bytes4);

Structs

Details

struct Details {
    uint256 loanDuration;
}

Status

Git Source

Inherits: Validation

Functions

isActive

function isActive(Starport.Loan calldata loan, bytes calldata extraData) external view virtual returns (bool);

IVault

Git Source

Functions

flashLoan

function flashLoan(
    IFlashLoanRecipient recipient,
    address[] calldata tokens,
    uint256[] calldata amounts,
    bytes memory userData
) external;

IFlashLoanRecipient

Git Source

Functions

receiveFlashLoan

function receiveFlashLoan(
    address[] calldata tokens,
    uint256[] calldata amounts,
    uint256[] calldata feeAmounts,
    bytes memory userData
) external;

ERC20

Git Source

Functions

transfer

function transfer(address, uint256) external returns (bool);

BNPLHelper

Git Source

Inherits: IFlashLoanRecipient, Ownable

State Variables

vault

address private vault;

Functions

constructor

constructor(address _vault, address owner);

makeFlashLoan

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

receiveFlashLoan

function receiveFlashLoan(
    address[] calldata tokens,
    uint256[] calldata amounts,
    uint256[] calldata feeAmounts,
    bytes calldata userData
) external override;

setFlashVault

function setFlashVault(address _vault) external onlyOwner;

Errors

InvalidUserDataProvided

error InvalidUserDataProvided();

SenderNotVault

error SenderNotVault();

Structs

Execution

struct Execution {
    address starport;
    address seaport;
    address borrower;
    CaveatEnforcer.SignedCaveats borrowerCaveat;
    CaveatEnforcer.SignedCaveats lenderCaveat;
    Starport.Loan loan;
    AdvancedOrder[] orders;
    CriteriaResolver[] resolvers;
    Fulfillment[] fulfillments;
}

Custodian

Git Source

Inherits: ERC721, ContractOffererInterface

State Variables

SP

Starport public immutable SP;

seaport

address public immutable seaport;

Functions

constructor

constructor(Starport SP_, address seaport_);

name

The name of the ERC721 contract

function name() public pure override returns (string memory);

Returns

NameTypeDescription
<none>stringstring The name of the contract

symbol

The symbol of the ERC721 contract

function symbol() public pure override returns (string memory);

Returns

NameTypeDescription
<none>stringstring The symbol of the contract

tokenURI

ERC-721 tokenURI override

function tokenURI(uint256 loanId) public view override returns (string memory);

Parameters

NameTypeDescription
loanIduint256The id of the custody token/loan

Returns

NameTypeDescription
<none>stringstring URI of the custody token/loan

supportsInterface

Helper to determine if an interface is supported by this contract

function supportsInterface(bytes4 interfaceId) public view override (ERC721, ContractOffererInterface) returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4The interface to check

Returns

NameTypeDescription
<none>boolbool Returns true if the interface is supported

onERC1155Received

onERC1155Received handler, if we are able to increment the counter in seaport that means we have not entered into seaport we dont add for ERC-721 as they are able to ignore the on handler call as apart of the spec revert with NotEnteredViaSeaport()

function onERC1155Received(address, address, uint256, uint256, bytes calldata) public virtual returns (bytes4);

mint

Mints a custody token for a loan.

function mint(Starport.Loan calldata loan) external;

Parameters

NameTypeDescription
loanStarport.LoanThe loan to mint a custody token for

mintWithApprovalSet

Mints a custody token for a loan.

function mintWithApprovalSet(Starport.Loan calldata loan, address approvedTo) external;

Parameters

NameTypeDescription
loanStarport.LoanThe loan to mint a custody token for
approvedToaddressThe address with pre approvals set

_validateAndMint

internal helper that validates and mints a custody token for a loan.

function _validateAndMint(Starport.Loan calldata loan) internal returns (uint256 loanId);

Parameters

NameTypeDescription
loanStarport.LoanThe loan to mint a custody token for

ratifyOrder

Generates the order for this contract offerer

function ratifyOrder(SpentItem[] calldata, ReceivedItem[] calldata, bytes calldata, bytes32[] calldata, uint256)
    external
    view
    onlySeaport
    returns (bytes4 ratifyOrderMagicValue);

Returns

NameTypeDescription
ratifyOrderMagicValuebytes4The magic value returned by the ratify

generateOrder

Generates the order for this contract offerer

function generateOrder(address fulfiller, SpentItem[] calldata, SpentItem[] calldata, bytes calldata context)
    external
    onlySeaport
    returns (SpentItem[] memory offer, ReceivedItem[] memory consideration);

Parameters

NameTypeDescription
fulfilleraddressThe address of the contract fulfiller
<none>SpentItem[]
<none>SpentItem[]
contextbytesThe context of the order

Returns

NameTypeDescription
offerSpentItem[]The items spent by the order
considerationReceivedItem[]The items received by the order

custody

If any additional state updates are needed when taking custody of a loan

function custody(Starport.Loan memory loan) external virtual onlyStarport returns (bytes4 selector);

Parameters

NameTypeDescription
loanStarport.LoanThe loan that was just placed into custody

Returns

NameTypeDescription
selectorbytes4The function selector of the custody method

getSeaportMetadata

Returns metadata on how to interact with the offerer contract

function getSeaportMetadata() external pure returns (string memory, Schema[] memory schemas);

Returns

NameTypeDescription
<none>stringstring The name of the contract
schemasSchema[]An array of supported schemas

getBorrower

Fetches the borrower of the loan, first checks to see if we've minted the token for the loan

function getBorrower(Starport.Loan memory loan) public view returns (address);

Parameters

NameTypeDescription
loanStarport.LoanLoan to get the borrower of

Returns

NameTypeDescription
<none>addressaddress The address of the loan borrower(returns the ownerOf the token if any) defaults to loan.borrower

previewOrder

Previews the order for this contract offerer

function previewOrder(
    address caller,
    address fulfiller,
    SpentItem[] calldata,
    SpentItem[] calldata,
    bytes calldata context
) public view returns (SpentItem[] memory offer, ReceivedItem[] memory consideration);

Parameters

NameTypeDescription
calleraddressThe address of the seaport contract
fulfilleraddressThe address of the contract fulfiller
<none>SpentItem[]
<none>SpentItem[]
contextbytesThe context of the order

Returns

NameTypeDescription
offerSpentItem[]The items spent by the order
considerationReceivedItem[]The items received by the order

_enableAssetWithSeaport

Enables the collateral deposited to be spent via seaport

function _enableAssetWithSeaport(SpentItem memory offer) internal;

Parameters

NameTypeDescription
offerSpentItemThe item to make available to seaport

_setOfferApprovalsWithSeaport

Sets approvals for the collateral deposited to be spent via seaport

function _setOfferApprovalsWithSeaport(Starport.Loan memory loan) internal;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

_transferCollateralAuthorized

transfers out the collateral to the handler address

function _transferCollateralAuthorized(SpentItem memory offer, address authorized) internal;

Parameters

NameTypeDescription
offerSpentItemThe item to send out of the Custodian
authorizedaddressThe address handling the asset further

_moveCollateralToAuthorized

transfers out the collateral of SpentItem to the handler address

function _moveCollateralToAuthorized(SpentItem[] memory offer, address authorized) internal;

Parameters

NameTypeDescription
offerSpentItem[]The SpentItem array to send out of the Custodian
authorizedaddressThe address handling the asset further

_postSettlementExecute

settle the loan with Starport

function _postSettlementExecute(Starport.Loan memory loan, address fulfiller) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe the loan that is settled
fulfilleraddressThe address executing seaport

_postRepaymentExecute

settle the loan with Starport

function _postRepaymentExecute(Starport.Loan memory loan, address fulfiller) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe the loan that is settled
fulfilleraddressThe address executing seaport

_settleLoan

settle the loan with Starport

function _settleLoan(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe the loan to settle

_beforeApprovalsSetHook

hook to call before the approvals are set

function _beforeApprovalsSetHook(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

_beforeGetSettlementConsideration

Hook to call before the loan get settlement call

function _beforeGetSettlementConsideration(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

_afterGetSettlementConsideration

Hook to call after the loan get settlement call

function _afterGetSettlementConsideration(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

_beforeSettlementHandlerHook

Hook to call before the the loan settlement handler execute call

function _beforeSettlementHandlerHook(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

_afterSettlementHandlerHook

Hook to call after the the loan settlement handler execute call

function _afterSettlementHandlerHook(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

_beforeSettleLoanHook

Hook to call before the loan is settled with the Starport

function _beforeSettleLoanHook(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

_afterSettleLoanHook

Hook to call after the loan is settled with the Starport

function _afterSettleLoanHook(Starport.Loan memory loan) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being settled

onlyStarport

only allows Starport to execute the function

modifier onlyStarport();

onlySeaport

only allows seaport to execute the function

modifier onlySeaport();

Events

SeaportCompatibleContractDeployed

event SeaportCompatibleContractDeployed();

Errors

CustodianCannotBeAuthorized

error CustodianCannotBeAuthorized();

ImplementInChild

error ImplementInChild();

InvalidAction

error InvalidAction();

InvalidFulfiller

error InvalidFulfiller();

InvalidLoan

error InvalidLoan();

InvalidPostRepayment

error InvalidPostRepayment();

InvalidPostSettlement

error InvalidPostSettlement();

InvalidRepayer

error InvalidRepayer();

NotAuthorized

error NotAuthorized();

NotEnteredViaSeaport

error NotEnteredViaSeaport();

NotSeaport

error NotSeaport();

NotStarport

error NotStarport();

Structs

Command

struct Command {
    Actions action;
    Starport.Loan loan;
    bytes extraData;
}

Stargate

Git Source

Functions

getOwner

function getOwner(address) external returns (address);

Starport

Git Source

Inherits: PausableNonReentrant

State Variables

MAX_FEE_RAKE_BPS

uint88 public constant MAX_FEE_RAKE_BPS = 500;

BPS_DENOMINATOR

uint88 public constant BPS_DENOMINATOR = 10_000;

LOAN_CLOSED_FLAG

uint256 public constant LOAN_CLOSED_FLAG = 0x0;

LOAN_OPEN_FLAG

uint256 public constant LOAN_OPEN_FLAG = 0x1;

_INVALID_LOAN

bytes32 private constant _INVALID_LOAN = 0x045f33d100000000000000000000000000000000000000000000000000000000;

_LOAN_EXISTS

bytes32 private constant _LOAN_EXISTS = 0x14ec57fc00000000000000000000000000000000000000000000000000000000;

SG

Stargate public immutable SG;

chainId

uint256 public immutable chainId;

DEFAULT_CUSTODIAN_CODE_HASH

bytes32 public immutable DEFAULT_CUSTODIAN_CODE_HASH;

CACHED_DOMAIN_SEPARATOR

bytes32 public immutable CACHED_DOMAIN_SEPARATOR;

EIP_DOMAIN

bytes32 public constant EIP_DOMAIN =
    keccak256("EIP712Domain(" "string name," "string version," "uint256 chainId," "address verifyingContract" ")");

VERSION

bytes32 public constant VERSION = keccak256(bytes("0"));

NAME

bytes32 public constant NAME = keccak256(bytes("Starport"));

INTENT_ORIGINATION_TYPEHASH

bytes32 public constant INTENT_ORIGINATION_TYPEHASH = keccak256(
    "Origination(" "address account," "uint256 accountNonce," "bool singleUse," "bytes32 salt," "uint256 deadline,"
    "Caveat[] caveats" ")" "Caveat(" "address enforcer," "bytes data" ")"
);

CAVEAT_TYPEHASH

bytes32 public constant CAVEAT_TYPEHASH = keccak256("Caveat(" "address enforcer," "bytes data" ")");

feeTo

address public feeTo;

defaultFeeRakeBps

uint256 public defaultFeeRakeBps;

feeOverrides

mapping(address => FeeOverride) public feeOverrides;

approvals

mapping(address => mapping(address => ApprovalType)) public approvals;

invalidSalts

mapping(address => mapping(bytes32 => bool)) public invalidSalts;

caveatNonces

mapping(address => uint256) public caveatNonces;

loanState

mapping(uint256 => uint256) public loanState;

Functions

constructor

constructor(address seaport_, Stargate stargate_, address owner_);

domainSeparator

function domainSeparator() public view returns (bytes32);

setOriginateApproval

Sets approval to originate loans without having to check caveats

function setOriginateApproval(address who, ApprovalType approvalType) external;

Parameters

NameTypeDescription
whoaddressThe address of who is being approved
approvalTypeApprovalTypeThe type of approval (Borrower, Lender) (cant be both)

originate

The loan origination method, new loan data is passed in and validated before being issued

function originate(
    AdditionalTransfer[] calldata additionalTransfers,
    CaveatEnforcer.SignedCaveats calldata borrowerCaveat,
    CaveatEnforcer.SignedCaveats calldata lenderCaveat,
    Starport.Loan memory loan
) external payable pausableNonReentrant;

Parameters

NameTypeDescription
additionalTransfersAdditionalTransfer[]Additional transfers to be made after the loan is issued
borrowerCaveatCaveatEnforcer.SignedCaveatsThe borrower caveat to be validated
lenderCaveatCaveatEnforcer.SignedCaveatsThe lender caveat to be validated
loanStarport.LoanThe loan to be issued

refinance

Refinances an existing loan with new pricing data, its the only thing that can be changed

function refinance(
    address lender,
    CaveatEnforcer.SignedCaveats calldata lenderCaveat,
    Starport.Loan memory loan,
    bytes calldata pricingData,
    bytes calldata extraData
) external pausableNonReentrant;

Parameters

NameTypeDescription
lenderaddressThe new lender
lenderCaveatCaveatEnforcer.SignedCaveatsThe lender caveat to be validated
loanStarport.LoanThe loan to be issued
pricingDatabytesThe new pricing data
extraDatabytes

settle

Helper to settle a loan guarded to ensure only the loan.custodian can call it

function settle(Loan memory loan) external;

Parameters

NameTypeDescription
loanLoanThe entire loan struct

incrementCaveatNonce

Increments caveat nonce for sender and emits event

function incrementCaveatNonce() external;

invalidateCaveatSalt

Invalidates a caveat salt

function invalidateCaveatSalt(bytes32 salt) external;

Parameters

NameTypeDescription
saltbytes32The salt to invalidate

setFeeData

Sets the default fee data, only owner can call

function setFeeData(address feeTo_, uint88 defaultFeeRakeBps_) external onlyOwner;

Parameters

NameTypeDescription
feeTo_addressThe feeToAddress
defaultFeeRakeBps_uint88The default fee rake in basis points

setFeeOverride

Sets fee overrides for specific tokens, only owner can call

function setFeeOverride(address token, uint88 bpsOverride, bool enabled) external onlyOwner;

Parameters

NameTypeDescription
tokenaddressThe token to override
bpsOverrideuint88The new basis points to override to (1 = 0.01%)
enabledboolWhether or not the override is enabled

applyRefinanceConsiderationToLoan

Refinances an existing loan with new pricing data, its the only thing that can be changed

function applyRefinanceConsiderationToLoan(SpentItem[] memory considerationPayment, SpentItem[] memory carryPayment)
    public
    pure
    returns (SpentItem[] memory newDebt);

Parameters

NameTypeDescription
considerationPaymentSpentItem[]the payment consideration
carryPaymentSpentItem[]The loan to be issued

hashCaveatWithSaltAndNonce

Helper to hash a caveat with a salt and nonce

function hashCaveatWithSaltAndNonce(
    address account,
    bool singleUse,
    bytes32 salt,
    uint256 deadline,
    CaveatEnforcer.Caveat[] calldata caveats
) public view virtual returns (bytes32);

Parameters

NameTypeDescription
accountaddressThe account that is originating the loan
singleUseboolWhether to invalidate the salt after validation
saltbytes32The salt to use
deadlineuint256The deadline of the caveat
caveatsCaveatEnforcer.Caveat[]The caveats to hash

Returns

NameTypeDescription
<none>bytes32bytes32 The hash of the caveat

_hashCaveat

Internal view function to derive the EIP-712 hash for a caveat

function _hashCaveat(CaveatEnforcer.Caveat memory caveat) internal pure returns (bytes32);

Parameters

NameTypeDescription
caveatCaveatEnforcer.CaveatThe caveat to hash.

Returns

NameTypeDescription
<none>bytes32The hash.

open

Helper to check if a loan is open

function open(uint256 loanId) public view returns (bool);

Parameters

NameTypeDescription
loanIduint256The id of the loan

Returns

NameTypeDescription
<none>boolbool True if the loan is open

closed

Helper to check if a loan is closed

function closed(uint256 loanId) public view returns (bool);

Parameters

NameTypeDescription
loanIduint256The id of the loan

Returns

NameTypeDescription
<none>boolbool True if the loan is closed

_postRepaymentExecute

Calls postRepayment hook on loan Settlement module

function _postRepaymentExecute(Starport.Loan memory loan, address fulfiller) internal virtual;

Parameters

NameTypeDescription
loanStarport.LoanThe the loan that is being refrenced
fulfilleraddressThe address executing the settle

_callCustody

Internal method to call the custody selector of the custodian if it does not share the same codehash as the default custodian

function _callCustody(Starport.Loan memory loan) internal;

Parameters

NameTypeDescription
loanStarport.LoanThe loan being placed into custody

_validateAdditionalTransfersRefinance

Internal method to validate additional transfers, only transfer from lender and fullfiller are valid

function _validateAdditionalTransfersRefinance(
    address lender,
    address fulfiller,
    AdditionalTransfer[] memory additionalTransfers
) internal pure;

Parameters

NameTypeDescription
lenderaddressThe lender of the loan
fulfilleraddressThe fulfiller of the loan
additionalTransfersAdditionalTransfer[]The additional transfers to validate

_validateAdditionalTransfersOriginate

Internal method to validate additional transfers, only transfers from borrower, lender, and fullfiller are valid

function _validateAdditionalTransfersOriginate(
    address borrower,
    address lender,
    address fulfiller,
    AdditionalTransfer[] calldata additionalTransfers
) internal pure;

Parameters

NameTypeDescription
borroweraddressThe borrower of the loan
lenderaddressThe lender of the loan
fulfilleraddressThe fulfiller of the loan
additionalTransfersAdditionalTransfer[]The additional transfers to validate

_validateAndEnforceCaveats

Internal method to validate and enforce caveats

function _validateAndEnforceCaveats(
    CaveatEnforcer.SignedCaveats calldata signedCaveats,
    address validator,
    AdditionalTransfer[] memory additionalTransfers,
    Starport.Loan memory loan
) internal;

Parameters

NameTypeDescription
signedCaveatsCaveatEnforcer.SignedCaveatsThe signed caveats to validate
validatoraddressThe validator of the caveats
additionalTransfersAdditionalTransfer[]The additional transfers to validate
loanStarport.LoanThe loan to validate

_settle

Internal helper to settle a loan

function _settle(Loan memory loan) internal;

Parameters

NameTypeDescription
loanLoanThe entire loan struct

_feeRake

Sets fee overrides for specific tokens, only owner can call

function _feeRake(SpentItem[] memory debt)
    internal
    view
    returns (SpentItem[] memory feeItems, SpentItem[] memory paymentToBorrower);

Parameters

NameTypeDescription
debtSpentItem[]The debt to rake

Returns

NameTypeDescription
feeItemsSpentItem[]SpentItem[] of fees
paymentToBorrowerSpentItem[]

acquireTokens

function acquireTokens(SpentItem[] memory items) external;

_issueLoan

Changes loanId status to open for the specified loan

function _issueLoan(Loan memory loan) internal;

Parameters

NameTypeDescription
loanLoanThe loan to issue

Events

ApprovalSet

event ApprovalSet(address indexed owner, address indexed spender, uint8 approvalType);

CaveatFilled

event CaveatFilled(address owner, bytes32 hash, bytes32 salt);

CaveatNonceIncremented

event CaveatNonceIncremented(address owner, uint256 newNonce);

CaveatSaltInvalidated

event CaveatSaltInvalidated(address owner, bytes32 salt);

Close

event Close(uint256 loanId);

FeeDataUpdated

event FeeDataUpdated(address feeTo, uint88 defaultFeeRakeBps);

FeeOverrideUpdated

event FeeOverrideUpdated(address token, uint88 overrideBps, bool enabled);

Open

event Open(uint256 loanId, Starport.Loan loan);

Errors

CaveatDeadlineExpired

error CaveatDeadlineExpired();

InvalidFeeRakeBps

error InvalidFeeRakeBps();

InvalidCaveat

error InvalidCaveat();

InvalidCaveatLength

error InvalidCaveatLength();

InvalidCaveatSigner

error InvalidCaveatSigner();

InvalidCustodian

error InvalidCustodian();

InvalidLoan

error InvalidLoan();

InvalidLoanState

error InvalidLoanState();

InvalidPostRepayment

error InvalidPostRepayment();

LoanExists

error LoanExists();

MalformedRefinance

error MalformedRefinance();

NotLoanCustodian

error NotLoanCustodian();

UnauthorizedAdditionalTransferIncluded

error UnauthorizedAdditionalTransferIncluded();

Structs

Terms

struct Terms {
    address status;
    bytes statusData;
    address pricing;
    bytes pricingData;
    address settlement;
    bytes settlementData;
}

Loan

struct Loan {
    uint256 start;
    address custodian;
    address borrower;
    address issuer;
    address originator;
    SpentItem[] collateral;
    SpentItem[] debt;
    Terms terms;
}

FeeOverride

struct FeeOverride {
    bool enabled;
    uint88 bpsOverride;
}

Enums

ApprovalType

enum ApprovalType {
    NOTHING,
    BORROWER,
    LENDER
}