EToken
Last updated
Last updated
This is an ERC20 compatible contract that represents the capital of each liquidity provider in a given pool. The valuation is one-to-one with the underlying stablecoin. The view scr()
returns the amount of capital that's locked backing up policies. For this capital locked, the pool receives an interest (scrInterestRate() / tokenInterestRate()) that is continuously accrued in the balance of eToken holders. See more.
The specific roles and functions of the contract are as follows:
Role | Global* | Description | Methods Accessible |
---|---|---|---|
LEVEL1_ROLE | High impact changes like upgrades or other critical operations. |
| |
LEVEL2_ROLE | Mid-impact changes like changing some parameters. |
| |
LEVEL3_ROLE | Low-impact changes like changing some parameters up to given percentage (tweaks). |
| |
GUARDIAN_ROLE | For emergency operations oriented to protect the protocol in case of attacks or hacking. |
|
( * ) Global means that the role can be delegated to a user at the protocol level (for all components) or only for a specific component. Non-global roles can only be granted for a specific component.
Field | Type | Description |
---|---|---|
liquidityRequirement | uint256 (wad) | Usually 1.0, used on withdrawal to scale the scr locked. |
minUtilizationRatio | uint256 (wad) | Used to prevent deposits to overdilute the returns. |
maxUtilizationRatio | uint256 (wad) | Prevents taking locking scr (taking new policies) if utilization ratio exceeds this parameter. |
internalLoanInterestRate | uint256 (wad) | Interest rate charged for internal loans. |
whitelist | address (ILPWhitelist) | Optional contract that, if present, controls who can deposit funds in the eToken. See ILPWhitelist. |
assetManager | address (IAssetManager) | Optional contract that, if present, implements the asset management strategy. See IAssetManager. |
To save gas, the parameters are stored in a packed struct that fits in 256bits (a word in the EVM). This is not visible externally, but put's limits on the precision of the parameters. The wad ones, have 4 decimals as precision, so 1.12345 will be truncated to 1.1234.
Event emitted when part of the funds of the eToken are locked as solvency capital.
Name | Type | Description |
---|---|---|
interestRate | uint256 | The annualized interestRate paid for the capital (wad) |
value | uint256 | The amount locked |
Event emitted when the locked funds are unlocked and no longer used as solvency capital.
Name | Type | Description |
---|---|---|
interestRate | uint256 | The annualized interestRate that was paid for the capital (wad) |
value | uint256 | The amount unlocked |
Event emitted when value
tokens are moved from one account (from
) to another (to
).
Name | Type | Description |
---|---|---|
from | address | The current owner of the token. |
to | address | The destination of the tokens if the transfer is accepted. |
value | uint256 | TThe amount of tokens to be transferred. |
Event emitted when PremiumsAccount borrow money from the eTokens to cover the payouts.
Name | Type | Description |
---|---|---|
borrower | address | The address of the borrower. |
value | uint256 | The amount to borrow. |
amountAsked | uint256 | The amount asked to borrow. |
Event emitted when the premiums account has a surplus (losses less than expected) and repay to eTokens.
Name | Type | Description |
---|---|---|
borrower | address | The address of the borrower. |
value | uint256 | The amount to repay. |
Event emitted when PolicyPool adds an authorized borrower to the eToken.
Name | Type | Description |
---|---|---|
borrower | address | The address of the borrower. |
Event emitted when PolicyPool removes an authorized borrower to the eToken.
Name | Type | Description |
---|---|---|
borrower | address | The address of the borrower. |
defaultedDebt | uint256 | The amount debt of the borrower. |
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.
Requirements:
Must be called by policyPool()
The amount was transferred
utilizationRate()
after the deposit is >= minUtilizationRate()
Events:
Emits {Transfer} with from
= 0x0 and to = provider
Name | Type | Description |
---|---|---|
provider | address | The address of the liquidity provider |
amount | uint256 | The amount deposited. |
Name | Type | Description |
---|---|---|
[0] | uint256 | The actual balance of the provider |
Withdraws an amount from an eToken. withdrawn
eTokens are be burned and the user receives the same amount in currency()
. If the asked amount
can't be withdrawn, it withdraws as much as possible
Requirements:
Must be called by policyPool()
Events:
Emits {Transfer} with from
= provider
and to = 0x0
Name | Type | Description |
---|---|---|
provider | address | The address of the liquidity provider |
amount | uint256 | The amount to withdraw. If |
Name | Type | Description |
---|---|---|
withdrawn | uint256 | The actual amount that withdrawn. |
Adds an authorized borrower to the eToken. This borrower will be allowed to lock/unlock funds and to take loans.
Requirements:
Must be called by policyPool()
Events:
Emits {InternalBorrowerAdded}
Name | Type | Description |
---|---|---|
borrower | address | The address of the borrower, a PremiumsAccount that has this eToken as senior or junior eToken. |
Removes an authorized borrower to the eToken. The borrower can't no longer lock funds or take loans.
Requirements:
Must be called by policyPool()
Events:
Emits {InternalBorrowerRemoved} with the defaulted debt
Name | Type | Description |
---|---|---|
borrower | address | The address of the borrower, a PremiumsAccount that has this eToken as senior or junior eToken. |
Returns the amount of capital that's locked as solvency capital for active policies.
Locks part of the liquidity of the EToken as solvency capital.
Requirements:
Must be called by a borrower previously added with addBorrower
.
scrAmount
<= fundsAvailableToLock()
Events:
Emits {SCRLocked}
Name | Type | Description |
---|---|---|
scrAmount | uint256 | The amount to lock |
policyInterestRate | uint256 | The annualized interest rate (wad) to be paid for the |
Unlocks solvency capital previously locked with lockScr
. The capital no longer needed as solvency.
Requirements:
Must be called by a borrower previously added with addBorrower
.
scrAmount <= scr()
Events:
Emits {SCRUnlocked}
Name | Type | Description |
---|---|---|
scrAmount | uint256 | The amount to unlock |
policyInterestRate | uint256 | The annualized interest rate that was paid for the |
adjustment | int256 |
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
.
Requirements:
Must be called by a borrower previously added with addBorrower
.
Events:
Emits {InternalLoan}
Emits {ERC20-Transfer} transferring lent
to receiver
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. |
fromAvailable | bool | If |
Name | Type | Description |
---|---|---|
[0] | uint256 | Returns the amount that wasn't able to fulfil. |
Repays a loan taken with internalLoan
.
Requirements:
msg.sender
approved the spending of currency()
for at least amount
Events:
Emits {InternalLoanRepaid}
Emits {ERC20-Transfer} transferring amount
from msg.sender
to this
Name | Type | Description |
---|---|---|
amount | uint256 | The amount to repaid, that will be transferred from |
onBehalfOf | address | The address of the borrower that took the loan. Usually |
Returns the updated debt (principal + interest) of the borrower
.
Usually, LEVEL2_ROLE or LEVEL3_ROLE is requested for performing operations that change numerical parameters of the components. Both global and component role are accepted. If the user has LEVEL3_ROLE the changes might be restricted to small tweaks.
Returns the address of the asset manager for this reserve. The asset manager is the contract that manages the funds to generate additional yields. Can be address(0)
if no asset manager has been set.
Sets the asset manager for this reserve. If the reserve had previously an asset manager, it will deinvest all the funds, making all of the liquid in the reserve balance.
Requirements:
The caller must have been granted of global or component roles GUARDIAN_ROLE or LEVEL1_ROLE.
Events:
Emits ComponentChanged with action setAssetManager or setAssetManagerForced
Name | Type | Description |
---|---|---|
newAM | contract IAssetManager | The address of the new asset manager to assign to the reserve. If is |
force | bool | When a previous asset manager exists, before setting the new one, the funds are deinvested. When |
Calls {IAssetManager-rebalance} of the assigned asset manager (fails if no asset manager). This operation is intended to give the opportunity to rebalance the liquid and invested for better returns and/or gas optimization.
Emits {IAssetManager-MoneyInvested} or {IAssetManager-MoneyDeinvested}
Calls {IAssetManager-recordEarnings} of the assigned asset manager (fails if no asset manager). The asset manager will return the earnings since last time the earnings where recorded. It then calls _assetEarnings
to reflect the earnings in the way defined for each reserve.
Emits {IAssetManager-EarningsRecorded}
Function that calls both recordEarnings()
and rebalance()
(in that order). Usually scheduled to run once a day by a keeper or crontask.
This function allows to call custom functions of the asset manager (for example for setting parameters). This functions will be called with delegatecall
, in the context of the reserve.
Requirements:
The caller must have been granted of global or component roles LEVEL2ROLE.
Name | Type | Description |
---|---|---|
functionCall | bytes | Abi encoded function call to make. |
Name | Type | Description |
---|---|---|
[0] | bytes | Returns the return value of the function called, to be decoded by the receiver. |