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:
LEVEL1_ROLE
High impact changes like upgrades or other critical operations.
setWhiteList: Set the contract used for whitelisting LPs
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.
setWhiteList: Set the contract used for whitelisting LPs
( * ) 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.
liquidityRequirement
uint256 (wad)
minUtilizationRatio
uint256 (wad)
maxUtilizationRatio
uint256 (wad)
internalLoanInterestRate
uint256 (wad)
whitelist
address (ILPWhitelist)
assetManager
address (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.
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.
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
).
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.
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.
borrower
address
The address of the borrower.
value
uint256
The amount to repay.
Event emitted when PolicyPool adds an authorized borrower to the eToken.
borrower
address
The address of the borrower.
Event emitted when PolicyPool removes an authorized borrower to the eToken.
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
provider
address
The address of the liquidity provider
amount
uint256
The amount deposited.
[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
provider
address
The address of the liquidity provider
amount
uint256
The amount to withdraw. If amount
== type(uint256).max
, then tries to withdraw all the balance.
withdrawn
uint256
The actual amount that withdrawn. withdrawn <= amount && withdrawn <= balanceOf(provider)
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}
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
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}
scrAmount
uint256
The amount to lock
policyInterestRate
uint256
The annualized interest rate (wad) to be paid for the scrAmount
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}
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
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
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 true
, the funds that can be lent are only the available ones, i.e., excluding the funds locked as scr()
. If false
, all the totalSupply()
is available to be lent.
[0]
uint256
Returns the amount that wasn't able to fulfil. amount - lent
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
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.
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
newAM
contract IAssetManager
The address of the new asset manager to assign to the reserve. If is address(0)
it means the reserve will not have an asset manager. If not address(0)
it MUST be a contract following the IAssetManager interface.
force
bool
When a previous asset manager exists, before setting the new one, the funds are deinvested. When force
is true, an error in the deinvestAll() operation is ignored. When force
is false, if deinvestAll()
fails, it reverts.
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.
functionCall
bytes
Abi encoded function call to make.
[0]
bytes
Returns the return value of the function called, to be decoded by the receiver.
: Implements the asset management strategy
: Call custom functions of the asset manager (for example for setting parameters)
: Set parameters.
: Set parameters.
: Implements the asset management strategy
Usually 1.0, used on to scale the scr locked.
Used to prevent to overdilute the returns.
Prevents taking (taking new policies) if utilization ratio exceeds this parameter.
Interest rate charged for .
Optional contract that, if present, controls who can deposit funds in the eToken. See .
Optional contract that, if present, implements the asset management strategy. See .