ITinteroLoan
Interface for TinteroLoan contract
Inherits: ITinteroLoanEvents, ITinteroLoanErrors
Interface for a loan contract that uses an ERC721 token as collateral. The loan is funded with an ERC20 token and structured in a series of payments and tranches.
Functions
lendingAsset
Address of the ERC20 token lent.
collateralAsset
Address of the ERC721 token used as collateral.
liquidityProvider
Address of the liquidity provider funding the loan.
tranche
Get the index at which the tranche starts and its recipient. A tranche is a collection of payments from [paymentIndex ?? 0, nextPaymentIndex)
currentTrancheIndex
Get the index of the current tranche.
totalTranches
Total tranches in the loan.
payment
Get payment details. A Payment is a struct with a principal and interest terms.
collateralId
Get the collateral tokenId for a payment.
currentPaymentIndex
Get the index of the current payment yet to be repaid.
totalPayments
Get the total number of payments.
currentFundingIndex
Get the index of the current payment yet to be funded.
beneficiary
Address of the beneficiary of the loan.
defaultThreshold
Amount of missed payments at which the loan is defaulted.
state
Get the current state of the loan.
pushPayments
*Adds a list of payments to the loan.
Requirements:
- The caller MUST be the liquidity provider.
- The loan MUST be in CREATED state.
- The collateral tokenIds and payments arrays MUST have the same length.
- The payments MUST be ordered by maturity date.
- The payments MUST NOT have matured.
- The collateral tokenIds MUST NOT have been added before.
- The collateralTokenIds MUST exist.
- The owner of each collateral tokenId MUST have approved this contract to transfer it (if not the contract itself).
Effects:
- The
totalPayments
is incremented by the length of the payments array. - The
collateralTokenIds
are transferred to this contract. - The
payment
function will return the added payments at their corresponding indexes starting attotalPayments
. - Emits a
PaymentCreated
event for each payment added.*
pushTranches
*Adds a list of tranches to the loan.
Requirements:
- The caller MUST be the liquidity provider.
- The loan MUST be in CREATED state.
- The tranchePaymentIndexes and trancheRecipients arrays MUST have the same length.
- The tranche indexes MUST be strictly increasing.
- The total number of tranches MUST be less than the total number of payments.
Effects:
- The
totalTranches
is incremented by the length of the tranches array. - The
tranche
function will return the added tranches at their corresponding indexes starting attotalTranches
. - The tranches are added to the loan.
- Emits a
TrancheCreated
event for each tranche added.*
fundN
*Funds n
payments from the loan.
Requirements:
- The loan MUST be in CREATED or FUNDING state.
- Tranches MUST include all payments.
- The caller MUST have enough funds to fund the payments
- This contract mus have been approved to transfer the principal amount from the caller.
Effects:
- Moves to FUNDING state
- Moves to ONGOING state if all payments are funded.
- The
currentFundingIndex
is incremented byn
or the remaining payments. - The principal of the funded payments is transferred from the liquidity provider to the beneficiary.
- Sets the
fundedAt
field of the funded payments to the current block timestamp. - Emits a
PaymentsFunded
event with the range of funded payments.*
withdrawPaymentCollateral
*Withdraws the collateral to the beneficiary.
Requirements:
- The loan MUST be in CREATED or CANCELED state.
- Each payment collateral MUST be owned by this contract.
- The caller MUST be the beneficiary.
Effects:
- Moves to CANCELED state.
- Each payment collateral is transferred to the beneficiary.
- Emits a
PaymentsWithdrawn
with the range of payments withdrawn*
repayCurrent
Same as repayN(0, collateralReceiver)
.
repayN
*Repays the current loan and n
future payments.
Requirements:
- The loan MUST be in ONGOING or DEFAULTED state.
- The sender MUST have enough funds to repay the principal of the specified payments
- The sender MUST have approved this contract to transfer the principal amount
- The collateral MUST be owned by this contract.
Effects:
- Moves to ONGOING if paid until below the default threshold.
- Moves to PAID state if all payments are repaid.
- The
currentPaymentIndex
is incremented byn
or the remaining payments. - The principal of the repaid payments is transferred from the sender to the receiver of each payment tranche
- The collateral is transferred to the collateralReceiver if provided, otherwise it is burned.
- Emits a
PaymentsRepaid
event with the range of repaid payments.*
repossess
*Repossess the collateral from payments.
Requirements:
- The loan MUST be in DEFAULTED or REPOSSESSED state.
- The caller MUST be the liquidity provider.
- The collateral MUST be owned by this contract.
- The receiver MUST implement IERC721Receiver to receive the collateral.
Effects:
- Moves to REPOSSESSED state.
- The collateral is transferred to the receiver.
- Emits a
PaymentsRepossessed
event with the range of repossessed payments.*
upgradeLoan
Upgrades the loan to a new implementation. Useful for renegotiating terms.
Events
PaymentCreated
Emitted when a payment is created.
TrancheCreated
Emitted when a tranche is created.
PaymentsFunded
Emitted when a set of payments is funded. (startIndex, endIndex]
PaymentsWithdrawn
Emitted when the collateral is withdrawn from a set of payments. (startIndex, endIndex]
PaymentsRepaid
Emitted when a set of payment is repaid. (startIndex, endIndex]
PaymentsRepossessed
Emitted when a set of payments are repossessed by the liquidity provider. (startIndex, endIndex]
Errors for the ERC721 Collateral Loan.
Errors
PaymentFunded
The loan is already funded so it can’t be funded again.
DuplicatedCollateral
The payment is already defaulted so it can’t be added to the loan.
UnorderedPayments
The payment is already defaulted so it can’t be added to the loan.
OnlyLiquidityProvider
Only the liquidity provider can perform the operation.
InvalidBeneficiary
The beneficiary address is not valid.
OnlyBeneficiary
Only the beneficiary can perform the operation.
MismatchedPaymentCollateralIds
The payments array doesn’t match the collateral tokenIds array.
MismatchedTranchePaymentIndexRecipient
The paymentIndex array doesn’t match the tranche recipients array.
UnincreasingTranchePaymentIndex
The tranche paymentIndex are not strictly increasing.
TooManyTranches
There are more tranches than payments
UntranchedPayments
The current tranches do not include all payments.
UnexpectedLoanState
*The current state of the loan is not the required for performing an operation.
The expectedStates
is a bitmap with the bits enabled for each LoanState enum position
counting from right to left.
If expectedState
is bytes32(0)
, any state is expected.*
The possible states of a loan.