ERC4626CashFlowLender
Implements the ERC-4626 standard tracking how much liquidity was provided by each LP. The assets managed by the vault are a mix of liquid USDC + the _debt
tracked by the CFL. The _debt
can be negative, in that case, the CFL owes to the customer.
Roles
The roles and functions of the contract are as follows:
Role | Description | Methods Accessible |
---|---|---|
CHANGE_RM_ROLE | Sets the risk module for the contract. |
|
LP_ROLE | Manages withdrawing assets for LPs. |
|
CUSTOMER_ROLE | Enables to cash out payouts. |
|
BORROWER_ROLE | Borrows funds from the CFL. |
|
POLICY_CREATOR_ROLE | Creates new policies. |
|
RESOLVER_ROLE | Resolves policies. |
|
This contract does not use Access Manager as an access control solution. It has its own access control mechanism.
Events
DebtChanged
Event emitted when the debt is changed. Could be positive or negative.
When policy is created, the debt increases.
When the customer borrows, the debt increases.
When policy is resolved, the debt decreases.
Name | Type | Description |
---|---|---|
currentDebt | int256 | The new debt |
RiskModuleChanged
Event emitted when the risk module changed.
Name | Type | Description |
---|---|---|
newRiskModule | The new risk module |
CashOutPayout
Event emitted when a customer cashes out a payout.
When the customer cashes out, the debt increases.
Name | Type | Description |
---|---|---|
destination | address | The address where the payout will be transferred. |
amount | uint256 | The amount to pay |
Borrow
Event emitted when a customer borrows funds.
Name | Type | Description |
---|---|---|
destination | address | The address where the borrowed funds will be transferred. |
amount | uint256 | The amount of funds to be borrowed. |
External Methods
currentDebt
Returns the current debt. If negative, the customer can cash out.
cashOutPayouts
Requirements:
Caller must have CUSTOMER_ROLE
The debt must be lower than the amount to pay.
The contract's balance must be sufficient to pay the amount.
If the debt is negative, the customer can cash out. This function facilitates cashing out by customers, transferring the payout to the customer.
Emits:
{CashOutPayout}
Name | Type | Description |
---|---|---|
amount | uint256 | The amount to pay |
destination | address | The address where the payout will be transferred. |
borrow
Allows a customer to borrow funds.
This function facilitates borrowing by customers, increasing their debt and transferring the borrowed funds.
Requirements:
Caller must have BORROWER_ROLE.
The contract's balance must be sufficient for the borrowing amount.
Emits:
{Borrow}
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of funds to be borrowed. |
destination | address | The address where the borrowed funds will be transferred. |
newPolicyWithRm
Creates a new policy paid by this contract and increases the debt.
If it is a RiskModule without bucket, send type(uint256).max If it is a RiskModule with bucket, send the bucketId
Requirements:
Caller must have POLICY_CREATOR_ROLE
_balance() >= than the amount of the premium
Emits:
{PolicyPool.NewPolicy}
{NewSignedPolicy}
Name | Type | Description |
---|---|---|
riskModule_ | address | The address of the risk module that will be used to create the policy |
payout | uint256 | The exposure (maximum payout) of the policy |
premium | uint256 | The premium that will be paid by the payer |
lossProb | uint256 | The probability of having to pay the maximum payout (wad) |
expiration | uint40 | The expiration of the policy (timestamp) |
policyData | bytes32 | A hash of the private details of the policy. The last 96 bits will be used as internalId |
bucketId | uint256 | The bucketId. If the risk module doesn't use buckets, send type(uint256).max |
quoteSignatureR | bytes32 | The signature of the quote. R component (EIP-2098 signature) |
quoteSignatureVS | bytes32 | The signature of the quote. VS component (EIP-2098 signature) |
quoteValidUntil | uint40 | The expiration of the quote |
Name | Type | Description |
---|---|---|
[0] | uint256 | Returns the id of the created policy |
newPoliciesInBatchWithRm
Creates several policies paid by this contract and increases the debt.
If it is a RiskModule without bucket, send type(uint256).max If it is a RiskModule with bucket, send the bucketId
Requirements:
Caller must have POLICY_CREATOR_ROLE
_balance() >= than the amount of the premium
Emits:
{PolicyPool.NewPolicy}
{NewSignedPolicy}
Name | Type | Description |
---|---|---|
riskModules | address[] | The addresses of the risk module that will be used to create the policy |
payout | uint256[] | The exposure (maximum payout) of each policy |
premium | uint256[] | The premium that will be paid by the payer |
lossProb | uint256[] | The probability of having to pay the maximum payout (wad) |
expiration | uint40[] | The expiration of each policy (timestamp) |
policyData | bytes32[] | A hash of the private details of each policy. The last 96 bits will be used as internalId |
bucketId | uint256[] | The bucketId. If the risk module doesn't use buckets, send type(uint256).max |
quoteSignatureR | bytes32[] | The signature of each quote. R component (EIP-2098 signature) |
quoteSignatureVS | bytes32[] | The signature of each quote. VS component (EIP-2098 signature) |
quoteValidUntil | uint40[] | The expiration of each quote |
newPolicy
Creates a new policy paid by this contract and increases the debt. See {SignedQuoteRiskModule.newPolicy}
Requirements:
Caller must have POLICY_CREATOR_ROLE
_balance() >= than the amount of the premium
newPoliciesInBatch
Creates several policies paid by this contract and increases the debt. See {SignedQuoteRiskModule.newPolicy}
Requirements:
Caller must have POLICY_CREATOR_ROLE
_balance() >= than the amount of the premium
resolvePolicy
Resolves a policy with a payout. See {SignedQuoteRiskModule.resolvePolicy}
Requirements:
Caller must have RESOLVER_ROLE
resolvePolicyFullPayout
Resolves a policy with a payout that can be either 0 or the maximum payout of the policy. See {SignedQuoteRiskModule.resolvePolicyFullPayout}
Requirements:
Caller must have RESOLVER_ROLE
resolvePoliciesInBatch
Resolves several policies paid by this contract and decreases the debt. See {SignedQuoteRiskModule.resolvePolicy}
Requirements:
Caller must have RESOLVER_ROLE
Last updated