✨ 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
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
Name | Type | Description |
---|---|---|
additionalTransfers | AdditionalTransfer[] | The additional transfers to be made |
loan | Starport.Loan | The loan terms |
caveatData | bytes | The 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
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
Name | Type | Description |
---|---|---|
additionalTransfers | AdditionalTransfer[] | The additional transfers to be made |
loan | Starport.Loan | The loan terms |
caveatData | bytes | The 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
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
Name | Type | Description |
---|---|---|
solution | AdditionalTransfer[] | The additional transfers to be made |
loan | Starport.Loan | The loan terms |
caveatData | bytes | The 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
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
Name | Type | Description |
---|---|---|
additionalTransfers | AdditionalTransfer[] | The additional transfers to be made |
loan | Starport.Loan | The loan terms |
caveatData | bytes | The 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
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
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
enum Actions {
Nothing,
Origination,
Refinance,
Repayment,
Settlement
}
RefStarportLib
Functions
validateSalt
function validateSalt(mapping(address => mapping(bytes32 => bool)) storage usedSalts, address validator, bytes32 salt)
internal;
Errors
InvalidSalt
error InvalidSalt();
Actions
enum Actions {
Nothing,
Repayment,
Settlement
}
AdditionalTransfer
struct AdditionalTransfer {
ItemType itemType;
address token;
address from;
address to;
uint256 identifier;
uint256 amount;
}
StarportLib
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
Name | Type | Description |
---|---|---|
payment | SpentItem[] | The SpentItem[] for payment |
paymentRecipient | address | The recipient address of the payment |
carry | SpentItem[] | The SpentItem[] for carry |
carryRecipient | address | The recipient address of the carry |
Returns
Name | Type | Description |
---|---|---|
consideration | ReceivedItem[] | An array of ReceivedItems |
removeZeroAmountItems
Removes ReceivedItems with zero amounts
function removeZeroAmountItems(ReceivedItem[] memory consideration)
internal
pure
returns (ReceivedItem[] memory newConsideration);
Parameters
Name | Type | Description |
---|---|---|
consideration | ReceivedItem[] | The ReceivedItem[] for payment |
Returns
Name | Type | Description |
---|---|---|
newConsideration | ReceivedItem[] | 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
Functions
validate
function validate(Starport.Loan calldata) external view virtual returns (bytes4);
Contents
Originator
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
Name | Type | Description |
---|---|---|
params | Request | The request for the origination |
Structs
Request
struct Request {
address borrower;
CaveatEnforcer.SignedCaveats borrowerCaveat;
SpentItem[] collateral;
SpentItem[] debt;
bytes details;
bytes approval;
}
StrategistOriginator
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
Name | Type | Description |
---|---|---|
newStrategist | address | The 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
Name | Type | Description |
---|---|---|
params | Request | The request for the origination |
encodeWithAccountCounter
Returns data that is encodePacked for signing
function encodeWithAccountCounter(bytes32 contextHash) public view virtual returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
contextHash | bytes32 | The hash of the data being signed |
getCounter
Returns the nonce of the contract
function getCounter() public view virtual returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | _counter |
domainSeparator
Returns the domain separator
function domainSeparator() public view virtual returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<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
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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan to compute the interest for |
rate | uint256 | The interest rate |
start | uint256 | The start time frame |
end | uint256 | The end time frame |
index | uint256 | The index of the debt to compute the interest for |
decimals | uint256 | The 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
Name | Type | Description |
---|---|---|
delta_t | uint256 | The time delta |
amount | uint256 | The amount to compute the interest for |
rate | uint256 | The interest rate |
decimals | uint256 | The decimals of the base asset |
Structs
Details
struct Details {
uint256 rate;
uint256 carryRate;
uint256 decimals;
}
Pricing
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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan to compute the payment details for |
newPricingData | bytes | The new pricing data being offered |
fulfiller | address | The address of the fulfiller |
Errors
InvalidRefinance
error InvalidRefinance();
SimpleInterestPricing
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
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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being referenced |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | uint256 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
Inherits: DutchAuctionSettlement
Functions
constructor
constructor(Starport SP_) DutchAuctionSettlement(SP_);
getAuctionStart
function getAuctionStart(Starport.Loan calldata loan) public view virtual override returns (uint256);
Settlement
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
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
Inherits: Validation
Functions
isActive
function isActive(Starport.Loan calldata loan, bytes calldata extraData) external view virtual returns (bool);
IVault
Functions
flashLoan
function flashLoan(
IFlashLoanRecipient recipient,
address[] calldata tokens,
uint256[] calldata amounts,
bytes memory userData
) external;
IFlashLoanRecipient
Functions
receiveFlashLoan
function receiveFlashLoan(
address[] calldata tokens,
uint256[] calldata amounts,
uint256[] calldata feeAmounts,
bytes memory userData
) external;
ERC20
Functions
transfer
function transfer(address, uint256) external returns (bool);
BNPLHelper
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
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
Name | Type | Description |
---|---|---|
<none> | string | string The name of the contract |
symbol
The symbol of the ERC721 contract
function symbol() public pure override returns (string memory);
Returns
Name | Type | Description |
---|---|---|
<none> | string | string The symbol of the contract |
tokenURI
ERC-721 tokenURI override
function tokenURI(uint256 loanId) public view override returns (string memory);
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | The id of the custody token/loan |
Returns
Name | Type | Description |
---|---|---|
<none> | string | string 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
Name | Type | Description |
---|---|---|
interfaceId | bytes4 | The interface to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan to mint a custody token for |
approvedTo | address | The 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The 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
Name | Type | Description |
---|---|---|
ratifyOrderMagicValue | bytes4 | The 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
Name | Type | Description |
---|---|---|
fulfiller | address | The address of the contract fulfiller |
<none> | SpentItem[] | |
<none> | SpentItem[] | |
context | bytes | The context of the order |
Returns
Name | Type | Description |
---|---|---|
offer | SpentItem[] | The items spent by the order |
consideration | ReceivedItem[] | 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan that was just placed into custody |
Returns
Name | Type | Description |
---|---|---|
selector | bytes4 | The 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
Name | Type | Description |
---|---|---|
<none> | string | string The name of the contract |
schemas | Schema[] | 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | Loan to get the borrower of |
Returns
Name | Type | Description |
---|---|---|
<none> | address | address 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
Name | Type | Description |
---|---|---|
caller | address | The address of the seaport contract |
fulfiller | address | The address of the contract fulfiller |
<none> | SpentItem[] | |
<none> | SpentItem[] | |
context | bytes | The context of the order |
Returns
Name | Type | Description |
---|---|---|
offer | SpentItem[] | The items spent by the order |
consideration | ReceivedItem[] | The items received by the order |
_enableAssetWithSeaport
Enables the collateral deposited to be spent via seaport
function _enableAssetWithSeaport(SpentItem memory offer) internal;
Parameters
Name | Type | Description |
---|---|---|
offer | SpentItem | The 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being settled |
_transferCollateralAuthorized
transfers out the collateral to the handler address
function _transferCollateralAuthorized(SpentItem memory offer, address authorized) internal;
Parameters
Name | Type | Description |
---|---|---|
offer | SpentItem | The item to send out of the Custodian |
authorized | address | The 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
Name | Type | Description |
---|---|---|
offer | SpentItem[] | The SpentItem array to send out of the Custodian |
authorized | address | The address handling the asset further |
_postSettlementExecute
settle the loan with Starport
function _postSettlementExecute(Starport.Loan memory loan, address fulfiller) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The the loan that is settled |
fulfiller | address | The address executing seaport |
_postRepaymentExecute
settle the loan with Starport
function _postRepaymentExecute(Starport.Loan memory loan, address fulfiller) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The the loan that is settled |
fulfiller | address | The address executing seaport |
_settleLoan
settle the loan with Starport
function _settleLoan(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The the loan to settle |
_beforeApprovalsSetHook
hook to call before the approvals are set
function _beforeApprovalsSetHook(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being settled |
_beforeGetSettlementConsideration
Hook to call before the loan get settlement call
function _beforeGetSettlementConsideration(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being settled |
_afterGetSettlementConsideration
Hook to call after the loan get settlement call
function _afterGetSettlementConsideration(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being settled |
_beforeSettlementHandlerHook
Hook to call before the the loan settlement handler execute call
function _beforeSettlementHandlerHook(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being settled |
_afterSettlementHandlerHook
Hook to call after the the loan settlement handler execute call
function _afterSettlementHandlerHook(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being settled |
_beforeSettleLoanHook
Hook to call before the loan is settled with the Starport
function _beforeSettleLoanHook(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The loan being settled |
_afterSettleLoanHook
Hook to call after the loan is settled with the Starport
function _afterSettleLoanHook(Starport.Loan memory loan) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The 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
Functions
getOwner
function getOwner(address) external returns (address);
Starport
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
Name | Type | Description |
---|---|---|
who | address | The address of who is being approved |
approvalType | ApprovalType | The 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
Name | Type | Description |
---|---|---|
additionalTransfers | AdditionalTransfer[] | Additional transfers to be made after the loan is issued |
borrowerCaveat | CaveatEnforcer.SignedCaveats | The borrower caveat to be validated |
lenderCaveat | CaveatEnforcer.SignedCaveats | The lender caveat to be validated |
loan | Starport.Loan | The 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
Name | Type | Description |
---|---|---|
lender | address | The new lender |
lenderCaveat | CaveatEnforcer.SignedCaveats | The lender caveat to be validated |
loan | Starport.Loan | The loan to be issued |
pricingData | bytes | The new pricing data |
extraData | bytes |
settle
Helper to settle a loan guarded to ensure only the loan.custodian can call it
function settle(Loan memory loan) external;
Parameters
Name | Type | Description |
---|---|---|
loan | Loan | The 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
Name | Type | Description |
---|---|---|
salt | bytes32 | The salt to invalidate |
setFeeData
Sets the default fee data, only owner can call
function setFeeData(address feeTo_, uint88 defaultFeeRakeBps_) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
feeTo_ | address | The feeToAddress |
defaultFeeRakeBps_ | uint88 | The 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
Name | Type | Description |
---|---|---|
token | address | The token to override |
bpsOverride | uint88 | The new basis points to override to (1 = 0.01%) |
enabled | bool | Whether 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
Name | Type | Description |
---|---|---|
considerationPayment | SpentItem[] | the payment consideration |
carryPayment | SpentItem[] | 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
Name | Type | Description |
---|---|---|
account | address | The account that is originating the loan |
singleUse | bool | Whether to invalidate the salt after validation |
salt | bytes32 | The salt to use |
deadline | uint256 | The deadline of the caveat |
caveats | CaveatEnforcer.Caveat[] | The caveats to hash |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | bytes32 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
Name | Type | Description |
---|---|---|
caveat | CaveatEnforcer.Caveat | The caveat to hash. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The hash. |
open
Helper to check if a loan is open
function open(uint256 loanId) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | The id of the loan |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool True if the loan is open |
closed
Helper to check if a loan is closed
function closed(uint256 loanId) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
loanId | uint256 | The id of the loan |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The the loan that is being refrenced |
fulfiller | address | The 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
Name | Type | Description |
---|---|---|
loan | Starport.Loan | The 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
Name | Type | Description |
---|---|---|
lender | address | The lender of the loan |
fulfiller | address | The fulfiller of the loan |
additionalTransfers | AdditionalTransfer[] | 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
Name | Type | Description |
---|---|---|
borrower | address | The borrower of the loan |
lender | address | The lender of the loan |
fulfiller | address | The fulfiller of the loan |
additionalTransfers | AdditionalTransfer[] | 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
Name | Type | Description |
---|---|---|
signedCaveats | CaveatEnforcer.SignedCaveats | The signed caveats to validate |
validator | address | The validator of the caveats |
additionalTransfers | AdditionalTransfer[] | The additional transfers to validate |
loan | Starport.Loan | The loan to validate |
_settle
Internal helper to settle a loan
function _settle(Loan memory loan) internal;
Parameters
Name | Type | Description |
---|---|---|
loan | Loan | The 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
Name | Type | Description |
---|---|---|
debt | SpentItem[] | The debt to rake |
Returns
Name | Type | Description |
---|---|---|
feeItems | SpentItem[] | SpentItem[] of fees |
paymentToBorrower | SpentItem[] |
acquireTokens
function acquireTokens(SpentItem[] memory items) external;
_issueLoan
Changes loanId status to open for the specified loan
function _issueLoan(Loan memory loan) internal;
Parameters
Name | Type | Description |
---|---|---|
loan | Loan | The 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
}