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
}