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:
CHANGE_RM_ROLE
Sets the risk module for the contract.
setRiskModule: Sets the risk module.
LP_ROLE
Manages withdrawing assets for LPs.
withdraws: Withdraws assets from the contract.
POLICY_CREATOR_ROLE
Creates new policies.
newPolicyWithRm: Creates a new policy with the specified risk module.
newPoliciesInBatchWithRm: Creates multiple policies with the specified risk modules.
newPolicy: Creates a new policy.
newPoliciesInBatch: Creates multiple policies.
RESOLVER_ROLE
Resolves policies.
resolvePolicyFullPayout: Resolves a single policy with full payout
resolvePoliciesInBatch: Resolves multiple policies
This contract does not use Access Manager as an access control solution. It has its own access control mechanism.
Events
DebtChanged
event DebtChanged(int256 currentDebt)
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.
currentDebt
int256
The new debt
RiskModuleChanged
event RiskModuleChanged(contract SignedQuoteRiskModule newRiskModule)
Event emitted when the risk module changed.
CashOutPayout
event CashOutPayout(address destination, uint256 amount)
Event emitted when a customer cashes out a payout.
When the customer cashes out, the debt increases.
destination
address
The address where the payout will be transferred.
amount
uint256
The amount to pay
Borrow
event Borrow(address destination, uint256 amount)
Event emitted when a customer borrows funds.
destination
address
The address where the borrowed funds will be transferred.
amount
uint256
The amount of funds to be borrowed.
External Methods
currentDebt
function currentDebt() external view returns (int256)
Returns the current debt. If negative, the customer can cash out.
cashOutPayouts
function cashOutPayouts(uint256 amount, address destination) external
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}
amount
uint256
The amount to pay
destination
address
The address where the payout will be transferred.
borrow
function borrow(uint256 amount, address destination) external
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}
amount
uint256
The amount of funds to be borrowed.
destination
address
The address where the borrowed funds will be transferred.
newPolicyWithRm
function newPolicyWithRm(address riskModule_, uint256 payout, uint256 premium, uint256 lossProb, uint40 expiration, bytes32 policyData, uint256 bucketId, bytes32 quoteSignatureR, bytes32 quoteSignatureVS, uint40 quoteValidUntil) external returns (uint256 policyId)
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}
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
[0]
uint256
Returns the id of the created policy
newPoliciesInBatchWithRm
function newPoliciesInBatchWithRm(address[] riskModules, uint256[] payout, uint256[] premium, uint256[] lossProb, uint40[] expiration, bytes32[] policyData, uint256[] bucketId, bytes32[] quoteSignatureR, bytes32[] quoteSignatureVS, uint40[] quoteValidUntil) external
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}
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
function newPolicy(uint256 payout, uint256 premium, uint256 lossProb, uint40 expiration, address, bytes32 policyData, bytes32 quoteSignatureR, bytes32 quoteSignatureVS, uint40 quoteValidUntil) external returns (uint256 policyId)
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
function newPoliciesInBatch(uint256[] payout, uint256[] premium, uint256[] lossProb, uint40[] expiration, bytes32[] policyData, bytes32[] quoteSignatureR, bytes32[] quoteSignatureVS, uint40[] quoteValidUntil) external
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
function resolvePolicy(struct Policy.PolicyData policy, uint256 payout) external
Resolves a policy with a payout. See {SignedQuoteRiskModule.resolvePolicy}
Requirements:
Caller must have RESOLVER_ROLE
resolvePolicyFullPayout
function resolvePolicyFullPayout(struct Policy.PolicyData policy, bool customerWon) external
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
function resolvePoliciesInBatch(struct Policy.PolicyData[] policy, uint256[] payout) external
Resolves several policies paid by this contract and decreases the debt. See {SignedQuoteRiskModule.resolvePolicy}
Requirements:
Caller must have RESOLVER_ROLE
Last updated