// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.0; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title IEToken interface * @dev Interface for EToken smart contracts, these are the capital pools. * @author Ensuro */ interface IEToken is IERC20 { /** * @dev Enum of the different parameters that are configurable in an EToken. */ enum Parameter { liquidityRequirement, minUtilizationRate, maxUtilizationRate, internalLoanInterestRate } /** * @dev Event emitted when part of the funds of the eToken are locked as solvency capital. * @param interestRate The annualized interestRate paid for the capital (wad) * @param value The amount locked */ event SCRLocked(uint256 interestRate, uint256 value); /** * @dev Event emitted when the locked funds are unlocked and no longer used as solvency capital. * @param interestRate The annualized interestRate that was paid for the capital (wad) * @param value The amount unlocked */ event SCRUnlocked(uint256 interestRate, uint256 value); /** * @dev Returns the amount of capital that's locked as solvency capital for active policies. */ function scr() external view returns (uint256); /** * @dev 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} * * @param scrAmount The amount to lock * @param policyInterestRate The annualized interest rate (wad) to be paid for the `scrAmount` */ function lockScr(uint256 scrAmount, uint256 policyInterestRate) external; /** * @dev 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} * * @param scrAmount The amount to unlock * @param policyInterestRate The annualized interest rate that was paid for the `scrAmount`, must be the same that was * sent in `lockScr` call. */ function unlockScr(uint256 scrAmount, uint256 policyInterestRate, int256 adjustment) external; /** * @dev 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` * * @param provider The address of the liquidity provider * @param amount The amount deposited. * @return The actual balance of the provider */ function deposit(address provider, uint256 amount) external returns (uint256); /** * @dev 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` * * @param provider The address of the liquidity provider * @param amount The amount to withdraw. If `amount` == `type(uint256).max`, then tries to withdraw all the balance. * @return withdrawn The actual amount that withdrawn. `withdrawn <= amount && withdrawn <= balanceOf(provider)` */ function withdraw(address provider, uint256 amount) external returns (uint256 withdrawn); /** * @dev Returns the total amount that can be withdrawn */ function totalWithdrawable() external view returns (uint256); /** * @dev 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} * * @param borrower The address of the _borrower_, a PremiumsAccount that has this eToken as senior or junior eToken. */ function addBorrower(address borrower) external; /** * @dev 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 * * @param borrower The address of the _borrower_, a PremiumsAccount that has this eToken as senior or junior eToken. */ function removeBorrower(address borrower) external; /** * @dev 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` * * @param amount The amount required * @param receiver The received of the funds lent. This is usually the policyholder if the loan is used for a payout. * @return Returns the amount that wasn't able to fulfil. `amount - lent` */ function internalLoan(uint256 amount, address receiver) external returns (uint256); /** * @dev 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` * * @param amount The amount to repaid, that will be transferred from `msg.sender` balance. * @param onBehalfOf 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. */ function repayLoan(uint256 amount, address onBehalfOf) external; /** * @dev Returns the updated debt (principal + interest) of the `borrower`. */ function getLoan(address borrower) external view returns (uint256); /** * @dev The annualized interest rate at which the `totalSupply()` grows */ function tokenInterestRate() external view returns (uint256); /** * @dev The weighted average annualized interest rate paid by the currently locked `scr()`. */ function scrInterestRate() external view returns (uint256); }