IEToken
Interface for EToken smart contracts, these are the capital pools.
Types
Parameter
Enum of the configurable parameters in an EToken.
These are the supported parameter types: - liquidityRequirement: target solvency/liquidity constraint (typically 1, scales the SCR to lock more) - minUtilizationRate: lower bound for utilization rate after deposits (prevents excess idle liquidity) - maxUtilizationRate: upper bound for utilization rate after capital lock (prevents locking all the capital) - internalLoanInterestRate: annualized rate charged on internal loans (wad)
enum Parameter {
liquidityRequirement,
minUtilizationRate,
maxUtilizationRate,
internalLoanInterestRate
}
Events
SCRLocked
event SCRLocked(uint256 policyId, uint256 interestRate, uint256 value)
Event emitted when part of the funds of the eToken are locked as solvency capital.
Parameters
| Name | Type | Description |
|---|---|---|
| policyId | uint256 | The id of the policy that locks the capital |
| interestRate | uint256 | The annualized interestRate paid for the capital (wad) |
| value | uint256 | The amount locked |
SCRUnlocked
event SCRUnlocked(uint256 policyId, uint256 interestRate, uint256 value, int256 adjustment)
Event emitted when the locked funds are unlocked and no longer used as solvency capital.
Parameters
| Name | Type | Description |
|---|---|---|
| policyId | uint256 | The id of the policy that unlocks the capital (should be the that locked before with SCRLocked) |
| interestRate | uint256 | The annualized interestRate that was paid for the capital (wad) |
| value | uint256 | The amount unlocked |
| adjustment | int256 | Discrete amount of adjustment done to the totalSupply to reflect when more or less than the received cost of capital has been accrued since the SCR was locked. |
Public Functions
scr
function scr() external view returns (uint256)
Returns the amount of capital that's locked as solvency capital for active policies.
lockScr
function lockScr(uint256 policyId, uint256 scrAmount, uint256 policyInterestRate) external
Locks part of the liquidity of the EToken as solvency capital.
Parameters
| Name | Type | Description |
|---|---|---|
| policyId | uint256 | The id of the policy that locks the capital |
| scrAmount | uint256 | The amount to lock |
| policyInterestRate | uint256 | The annualized interest rate (wad) to be paid for the scrAmount |
Pre-conditions
- Must be called by a borrower (PremiumsAccount) previously added with
addBorrower. scrAmount<=fundsAvailableToLock()
Emits
- SCRLocked
unlockScr
function unlockScr(uint256 policyId, uint256 scrAmount, uint256 policyInterestRate, int256 adjustment) external
Unlocks solvency capital previously locked with lockScr.
The capital no longer needed as solvency, enabling withdrawal.
Parameters
| Name | Type | Description |
|---|---|---|
| policyId | uint256 | The id of the policy that locked the scr originally |
| scrAmount | uint256 | The amount to unlock |
| policyInterestRate | uint256 | The annualized interest rate that was paid for the scrAmount, must be the same that was sent in lockScr call. |
| adjustment | int256 | Discrete amount of adjustment done to the totalSupply to reflect when more or less than the received cost of capital has been accrued since the SCR was locked. |
Pre-conditions
- Must be called by a borrower (PremiumsAccount) previously added with
addBorrower. scrAmountmust be <= {scr}
Emits
- SCRUnlocked
unlockScrWithRefund
function unlockScrWithRefund(uint256 policyId, uint256 scrAmount, uint256 policyInterestRate, int256 adjustment, address receiver, uint256 refundAmount) external
Unlocks solvency capital previously locked with lockScr, doing a refund of the CoC previously received
The capital no longer needed as solvency . It refunds part of the Coc received that wasn't accrued (or if it was already accrued, it is adjusted). The refund doesn't affect the totalSupply. It just changes the reserves.
Parameters
| Name | Type | Description |
|---|---|---|
| policyId | uint256 | The id of the policy that locked the scr originally |
| scrAmount | uint256 | The amount to unlock |
| policyInterestRate | uint256 | The annualized interest rate that was paid for the scrAmount, must be the same that was sent in lockScr call. |
| adjustment | int256 | |
| receiver | address | The address of the receiver of the refund |
| refundAmount | uint256 | The amount to refund |
Pre-conditions
- Must be called by a borrower previously added with
addBorrower.
Emits
- SCRUnlocked
- CoCRefunded
deposit
function deposit(uint256 amount, address caller, address receiver) external
Registers a deposit of liquidity in the pool.
Called from the PolicyPool, assumes the amount has already been transferred. amount of eToken are minted
and given to the provider in exchange of the liquidity provided.
Parameters
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount deposited. |
| caller | address | The user that initiates the deposit |
| receiver | address | The user that will receive the minted eTokens |
Pre-conditions
- Must be called by
policyPool() - The amount was transferred
utilizationRate()after the deposit is >=minUtilizationRate()- If there is a whitelist, caller must be authorized to deposit. If caller != receiver, then transfer from caller
- to received must be authorized
Emits
- Transfer
- with `from` = 0x0 and to = `provider` (mint)
withdraw
function withdraw(uint256 amount, address caller, address owner, address receiver) external returns (uint256 withdrawn)
Withdraws an amount from an eToken.
withdrawn eTokens are be burned and the user receives the same amount in currency().
If amount == type(uint256).max, it withdraws up to maxWithdraw (i.e., as much as possible).
Otherwise, it reverts if amount > maxWithdraw.
Parameters
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount to withdraw. If amount == type(uint256).max, withdraws up to maxWithdraw. |
| caller | address | The user that initiates the withdrawal |
| owner | address | The owner of the eTokens (either caller==owner or caller has allowance) |
| receiver | address | The address that will receive the resulting currency() |
Pre-conditions
- Must be called by
policyPool()
Emits
- Transfer
- with `from` = `provider` and to = `0x0` (burn)
totalWithdrawable
function totalWithdrawable() external view returns (uint256)
Returns the total amount that can be withdrawn
addBorrower
function addBorrower(address borrower) external
Adds an authorized borrower to the eToken. This borrower will be allowed to lock/unlock funds and to take loans.
Borrowers (typically PremiumsAccounts) can: - lock/unlock SCR via {lockScr}/{unlockScr}/{unlockScrWithRefund} - take internal loans via {internalLoan}
Parameters
| Name | Type | Description |
|---|---|---|
| borrower | address | The address of the borrower, a PremiumsAccount that has this eToken as senior or junior eToken. |
Pre-conditions
- Must be called by
policyPool()
Emits
- InternalBorrowerAdded
removeBorrower
function removeBorrower(address borrower) external
Removes an authorized borrower to the eToken. The borrower can't no longer lock funds or take loans.
Parameters
| Name | Type | Description |
|---|---|---|
| borrower | address | The address of the borrower, a PremiumsAccount that has this eToken as senior or junior eToken. |
Pre-conditions
- Must be called by
policyPool()
Emits
- InternalBorrowerRemoved
- with the defaulted debt
internalLoan
function internalLoan(uint256 amount, address receiver) external returns (uint256)
Lends amount to the borrower (msg.sender), transferring the money to receiver.
This reduces the totalSupply() of the eToken, and stores a debt that will be repaid (hopefully) with
repayLoan.
Parameters
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount required |
| receiver | address | The received of the funds lent. This is usually the policyholder if the loan is used for a payout. |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | Returns the amount that wasn't able to fulfil. amount - lent |
Pre-conditions
- Must be called by a borrower previously added with
addBorrower.
Emits
- {InternalLoan}
- {ERC20-Transfer}
- transferring `lent` to `receiver`
repayLoan
function repayLoan(uint256 amount, address onBehalfOf) external
Repays a loan taken with internalLoan.
Parameters
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount to repaid, that will be transferred from msg.sender balance. |
| onBehalfOf | address | The address of the borrower that took the loan. Usually onBehalfOf == msg.sender but we keep it open because in some cases with might need someone else pays the debt. |
Pre-conditions
msg.senderapproved the spending ofcurrency()for at leastamount
Emits
- {InternalLoanRepaid}
- {ERC20-Transfer}
- transferring `amount` from `msg.sender` to `this`
getLoan
function getLoan(address borrower) external view returns (uint256)
Returns the updated debt (principal + interest) of the borrower.
tokenInterestRate
function tokenInterestRate() external view returns (uint256)
The annualized interest rate at which the totalSupply() grows
scrInterestRate
function scrInterestRate() external view returns (uint256)
The weighted average annualized interest rate paid by the currently locked scr().
getCurrentScale
function getCurrentScale(bool updated) external view returns (uint256)
Returns the number that scales the shares to reflect the earnings or losses (rebasing token)
Parameters
| Name | Type | Description |
|---|---|---|
| updated | bool | When it's false, it returns the last scale stored. When it's true, it projects that scale applying the accrued returns of the scr |
redistribute
function redistribute(uint256 amount) external
Redistributes a given amount of eTokens of the caller between the remaining LPs
Parameters
| Name | Type | Description |
|---|---|---|
| amount | uint256 | The amount of eTokens to burn |
cooler
function cooler() external view returns (address)
Returns the cooler contract plugged into the eToken