образец оформления:
- https://raw.githubusercontent.com/compound-finance/compound-protocol/master/docs/CompoundProtocol.pdf
- https://compound.finance/documents/Compound.Whitepaper.pdf
План документа:
- abstract
- introduction
- use cases
- key terms
- borrowing stablecoin
- CDP
- Minting and burning
- Maintaining the peg
- insurance/deposit
- Uniswap V3 price
- constants
# AlgoEurs Protocol
**Abstract.** AlgoEURS is a decentralized finance (DeFi) protocol on Ethereum blockchain that allows users to borrow AEUR, a stablecoin soft-pegged to the euro, using wide variety of on-chain assets as a collateral, or lend their assets for some interest. The protocol allows borrowers to additionaly secure their collateral by using funds provided to protocol pool by lenders.
## Introduction
## Use cases
https://docs.unit.xyz/protocol-use-cases
https://docs.unit.xyz/
### Obtain liquidity
Some tokens can be difficult to trade quickly, even though they might hold significant value.
### Benefit from the stability of the euro
AlgoEURS stablecoin is pegged against the euro fiat currency. This means its value stays at ~€1 regardless of what's happening in the markets.
### Keep using your funds
Many investors invest their money in liquidity pools such as uniswap. After investing his funds in the pool, the investor continues to be eligible for these funds, but may not always benefit from their possession other than that offered by the pool itself. In the case of uniswap v3, the right to the funds left in the pool reflects the nft lp token, which can also be used as collateral.
### Insure against risks
Market volatility and the operation of liquidation mechanisms in the borrowing protocols can deprive the borrower of his valuable asset, left as collateral, even if the decrease in the collateral price was immediately reversed, appeared during an attack, an error, or was nothing but an oracle failure.
### Earn on a term deposit
The protocol allows investors to flexibly customize their deposit in order to manage the amount of profit and risk.
## Key terms
### Actions
Borrow - AEURs are minted for new borrow position and transfered to borrower.
Repay borrow - a borrow position is partially/fully repaid.
Deposit - new funds are deposited to the pool.
Redeem - the deposits are partially/fully redeemed from the pool.
Pay - payment for insurance of the borrower's collateral.
###
LL (Liquidation Level) - collateral price level in euro for starting liquidation procedure
## Borrowing stablecoin
If we don't take insurance service into account, AlgoEURS protocol works the same way as other popular DeFi protocols for obtaining liquidity with liquidation procedure.
Borrowers receive stablecoins, while leaving their cryptoasset as collateral. When the price of the collateral approaches a certain minimum, depending on the amount of borrowed funds and insurance compensation (if purchased at all by the user), the collateral may become available for the liquidation procedure.
In order to return the collateral, the borrower must bring back all issued funds and a stability fee.
Whenever user leaves some collateral for the first time, a new debt position is created by the protocol.
### Collateral debt position (CDP)
Each CDP is uniquely determined by borrowers wallet address and an asset (ERC-20 token, Uniswap V3 position etc.) used as a collateral.
For each asset, there are following protocol-wise settings:
- collateralization ratio
- liquidation ratio
- stability fee
- liquidation fee
Collateralization ratio determines how much AEUR can be borrowed for collateral.
Liquidation ratio ...
Stability fee ...
Liquidation fee ...
There is no fee for opening CDP.
CDP can be liquidated when liquidation ratio is reached. Anyone can trigger liquidation. Liquidated collateral is sold for AEUR on dutch auction by the protocol.
### AEUR stability mechanisms
AEUR is minted by a borrower from her debt position with respect to collateralization ratio. AEUR is burned whenever debt is repayed.
Protocol uses battle-tested[1] mechanism for maintaining AEUR-euro peg. Namely, it incentivizes users to perform actions that compensate for fluctuations in price of assets that underly AEUR.
When price of some asset underlying AEUR rises, users will mint more AEUR from their CDPs, thus increasing supply of AEUR in the market.
When price of some asset underlying AEUR goes down, users will either repay their debts (thus burning AEUR), put more assets into their CDPs (thus increasing AEUR value) or face liquidation, which will result in some more AEUR being burnt.
[1] ссылка на юнит протокол
## Collateral insurance and earnings
When there are deposits in the pool of funds for insurance, borrowers can purchase the service of insuring their collateral against liquidation for a certain period in case collaterals price in EUR falls below the liquidation price level. With insurance, the value of the collateral may fall below the level of the liquidation price by exactly the amount of euros, that is taken from the deposits pool, including a possibility of a complete guarantee of the absence of liquidation at any market price of the collateral.
The entire amount for which the borrower buys insurance is transferred to the respective investors, whose funds were used for the insurance. The amount is directly proportional to the amount of funds that are taken for insurance, and the period for which they are taken.
In order for a specific borrower to receive insurance services, it is required that the amount of his collateral meets the requirement of the depositor. The insurance is purchased for a specified period from the moment of the purchase. Then the term can be extended.
### Deposit
The main currency for the deposit is the euro stablecoin. The depositor transfers the desired amount of his funds to the protocol pool and specifies two main parameters. The first parameter is the number of days for which the protocol locks his funds for the offer as part of the insurance amount. The second parameter is the requirement for the size of the borrower's collateral as a percentage of the amount of the provided deposit. The protocol provides these parameters for depositors to choose from in order to honestly ensure that each investor evaluates and manages the profitability and risk of their investment.
Deposits with the lowest requirements for the size of the borrower's collateral are used for insurance in the first place, so those investors who are more at risk will receive more profit in the end.
Users always have access to information about what was the backing percentage of the deposit used for insurance at the time of the last purchase of insurance. This will allow investors to better select their backing requirement. Those investors who have indicated too high a percentage to back their funds with collateral, and as a result, their funds are not used for insurance for a long time, can lower the requirement for backing or withdraw their deposit before the expiration of the period specified by them.
### Pool of funds
The pool of funds is created to add collateral insurance and earning opportunities to the lending system, it allows users to make money by depositing their cryptoassets in order to use them to insure other users' collaterals from liquidation when the value of collateral decreases.
Unlike a peer-to-peer platform, where investor’s asset is matched and lent to borrower, the AlgoEURS protocol aggregates the supply of each investor to offer better liquidity and better funds using experience than direct lending.
In the following, more detailed information is provided on the order of using investor deposits in the pool for insurance purposes. The main principle is the need to satisfy the amount and duration of insurance desired by the borrower and available to him in the amount of collateral, as much as the funds in the pool allow.
If several investors in the pool have unused deposits with the same backing requirement and satisfy the use for new insurance, then the funds are taken equally from each of these investors until one of them runs out of unused deposit. Since deposits, which have the lowest requirements for collateralization, are used first, the maximum efficiency of using the amount of collateral to obtain insurance funds is ensured.
### Amount of insurance
If the borrower wants to take funds for insurance, having at the time of purchase of insurance a collateral worth **X** euros, then for him there is a limited amount of insurance **A**, determined by the requirements of investors for their deposits and the minimum insurance period **t** established in the protocol.
Since the collateralization ratio is a specific number for each type of asset and changes only slightly if the governance token holders vote, setting the insurance amount above the level of the liquidation price makes very little practical sense. Therefore, the maximum amount for the borrower for insurance **A** is also limited from above by the price of liquidating his collateral.
When such **A** > 0 exists, then it corresponds to a certain maximum term **T** for which the borrower can purchase the insurance in the amount of **A** euro. The term **T** depends on the remaining locking time of unused deposits at the moment. If this maximum term **T** is greater than the minimum possible insurance term **t** established in the protocol, then the borrower who wants to purchase insurance in the amount of **A** euro, has the opportunity to choose for how long he wants to purchase this insurance between **t** and **T**.
If this borrower wants to purchase insurance for a period of more than **T**, while not increasing the amount of his collateral, he must indicate the desired amount of insurance less than **A**. Then, if there are deposits in the pool that cover a longer period than **T**, but do not allow this borrower to issue insurance in the amount of **A** euro for a collateral with a value of **X**, he will be able to purchase insurance in the amount of less than **A** and for a period of more than **T**.
### Backing requirement and math
When an investor adds his deposit **D1(T1)** to the pool, he indicates the term **T1**, up to which his deposit can be locked in the protocol, and the requirement **B1** > 100% to back his deposit with the borrower's collateral when using the deposit as insurance. This means that the deposit can be used for insurance only until the moment of time **T1** and only in the amount of **x1**/**B1**, where **x1** is a part of the cost of the borrower's collateral, free from backing any other insurance deposits.
If the entire number **n** of currently unused deposits **D1(T1)**, **D2(T2)**, ..., **Dn(Tn)** with the minimum requirement for backing **B1** allow some borrower to take insurance with the maximum size **A** = **D1 + D2 + ... + Dn** and the term **T** for it, then **T** = min (**T1, T2**, ..., **Tn**).
If the number **k** of unused deposits **D1(T1), D2(T2)**, ..., **Dm(Tk)** with different requirements **B1, B2** ... **Bk**, respectively, allow some borrower to take insurance with a maximum term of **T1** = **max (T1, T2, ..., Tk)** = **Tk1** then size **a** = Dk1(Tk1).
## Governance
The aeToken is the governance & staking token. When you stake aeToken, a proportion of the fees we collect (stability and liquidation) are distributed to aeToken stakers.
From the moment aeTokens are staked, they are continuously compounding. Every day 1/30 of the treasury is used to buy up aeToken from the open market. The APR exchange rate changes with each protocol fee. When aeTokens are unstaked, staking tokens are paid out according to the exchange rate at that time.
aeTokens can be staked and unstaked at any time.
## Fees
AlgoEURS protocol collects stability fees when users repay their AlgoEURS and liquidation fees if the collateralized debt position (CDP) has been foreclosed.
Stability fees are the amount of money to pay after using the collateral to create AlgoEURS. This fee represents how much your AlgoEURS debt is going to cost you over 12 months. This capitalizes during every action, such as withdrawing collateral and borrowing more AlgoEURS, reducing the debt/collateral ratio. The stability fee continuously compounds the interest and totals the percentage to be paid at the end of the year. For example, if you borrow $100 worth of AlgoEURS with a 2% stability fee, you will only have to pay back 102 dollars at the end of the year.
The liquidation fee is calculated as a percentage of the loan to be paid by the borrower if liquidation is triggered. The fee is added to the vault’s total outstanding generated AlgoEURS, which will be deducted from the collateral if liquidation is triggered. The proceeds from liquidation fees go to the governance pool to be distributed. This penalty prevents Auction Grinding Attacks, which include exploiting the process by purposefully creating a high-risk collateralized debt position and intentionally allowing the position to go unsafe.
Both of these fees go into AlgoEURS Protocol’s treasury. There's no fee for opening a new collateralized debt position (CDP). Fixed fees for issuing loans are unnecessary, reduce usability, and may significantly limit the demand for short-term loans. AlgoEURS Protocol has no fees for issuing debt, and no fees for closing it out.
## Oracles
Chainlink is used to determine the euro price of ETH.
Tokens are quoted from Uniswap, as well as Uniswap LP tokens with on-chain oracle that uses the Keydonix library with some modifications.
Oracles update every 20 minutes.
## Constants
Поля доступные через VaultParameters
- stabilityFee
- liquidationFee
- liquidationDiscount ???
- tokenDebtLimit - глобальный (по всем юзерам) лимит на выдачу USDP под залог токена
- tokenToOracle
- initialCollateralRatio
- liquidationRatio
- devaluationPeriod ???
- minColPercent ??? / maxColPercent ???
-
## Protocol states
In this section, we provide a formal definition of the states of the AlgoEURS protocol
### Global state
We denote G as the glabal state of the AlgoEURS protocol at time t. For brevity, in the following definitions, we assume that all the values are at a given time t. We define the global state for the AEP as
G = (B,D,L,P)
where B is the state of all loans, D is the state of deposits pool, L is the state of all liquidation processes and P is a set of the prices the Oracle used.
### Constrains
The main currency for the deposit is the STASIS EURO (EURS) token.
https://coinmarketcap.com/currencies/stasis-euro/
The whitelist of of available assets for collateral is determined using the protocol governance mechanism.
### Authentification
Protocol methods can be called on behalf of different entities, and therefore it is required to differentiate access to functions by access types. To provide differentiation, a function modifier is used, which can be defined in a separate contract, for example, Auth contract, from which other contracts that have functions with special access will then inherit.
Access categories:
onlyManager
onlyVault
onlyVaultAccess
Information about the belonging of a particular user to one of the access categories is stored in the corresponding mappings:
mapping(address => bool)
## Vault contract
https://etherscan.io/viewsvg?t=1&a=0xb1cFF81b9305166ff1EFc49A129ad2AfCd7BCf19
Contains collateral left by borrowers, both cryptoassets and tokens as well as collaterals prices, debt amounts, block numbers of liquidation triigger, fees pinned to each position and timestamps of last update in mappings such as:
mapping(address => mapping(address => uint))
Constructor sets the addresses of AlgoEURS, aeToken and WETH tokens.
## AlgoEURS contract
https://etherscan.io/viewsvg?t=1&a=0x1456688345527bE1f37E9e627DA0837D6f08C925
The token contract conforms to the ERC20 token standard which allows wallets, exchanges, and other applications to easily integrate with minimal effort.
18 decimals.
Only vault can mint and burn any balance.
Only manger can burn his balance.
The coin price is pegged to the euro fiat currency via a set of smart contracts designed to reduce the price volatility of AlgoEURS stablecoin, allowing lenders and borrowers to borrow different digital assets without counterparty risk. Decentralized and manipulation-resistant on-chain price oracles are used as data providers.
## VaultParameters contract
https://etherscan.io/viewsvg?t=1&a=0xB46F8CF42e504Efe8BEf895f848741daA55e9f1D
This contract proposes storing and setting asset parameters, and managing access categories.
The values of various commissions and the maximum amount of AlgoEURS issued on loan for each type of asset are stored in mappings:
mapping(address => uint)
## VaultManagerParameters contract
https://etherscan.io/viewsvg?t=1&a=0x203153522B9EAef4aE17c6e99851EE7b2F7D312E
## LiquidationAuction contract
https://etherscan.io/viewsvg?t=1&a=0xaEF1ed4C492BF4C57221bE0706def67813D79955
The asset is held in escrow in our contract through the entire duration of the loan.
If a loan is not paid back in time by the borrower, the asset becomes available for liquidation.
## CDPManager contract
https://etherscan.io/viewsvg?t=1&a=0x0e13ab042eC5AB9Fc6F43979406088B9028F66fA
Each Collateralized Debt Position (CDP) consists of 2 collaterals — asset (main collateral) and aeToken. The decentralized application allows users to earn immediate interest on staked aeToken tokens. Each main collateral has its own restrictions on the minimum and maximum % of aeToken in CDP.
## CDPManagerFallback contract
https://etherscan.io/viewsvg?t=1&a=0xaD3617D11f4c1d30603551eA75e9Ace9CB386e15
## Helpers
TransferHelper
## Libraries
SafeMath
## Ecosystem
https://docs.unit.xyz/technology-questions/smart-contracts
https://github.com/unitprotocol/core/blob/master/CONTRACTS.md
## Appendix