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
}