Overview of the organization of the code of Borrowing Module of the Angle Protocol
Angle Protocol Borrowing Module Architecture
The main contracts in Angle Borrowing Module and their purposes are:
This is the main contract of this borrowing module. It is at the level of this contract that users can deposit collateral, take loans against this collateral by borrowing stablecoins, repaying stablecoins. There is one
VaultManagercontract per collateral type for each stablecoin. The same collateral could also have different associated
VaultManagercontracts if different parameters are used.
The main interactions agents have with this contract happen with the following methods:
createVault(): for a user to create a vault within the contract
angle(): for a user to compose actions with the contract. It can be used to create a vault, add collateral to it, borrow stablecoins against it, remove collateral from a vault, repay debt in a vault, approve the contract for a token through the
permitinterface for tokens that allow it, or even get debt in a vault from another vault
Keepers monitoring the state of the protocol can participate in the liquidations of unhealthy vaults by calling the
liquidate()function. They may call the
checkLiquidation()before that to simplify and pass the right parameters to the contract.
VaultManagercontracts implement the ERC-721 standard and have minting right on their corresponding AgToken.
Beyond the common ERC-721 functions, Angle leaves the implementations to grant or revoke to an address for all your vaults with a simple permit signature.
This is the core contract of the borrowing module. This contract handles the access control across all contracts (it is read by all treasury contracts), and manages the
flashLoanModule. It has no minting rights over the stablecoin contracts.
This contract is responsible for doing the accounting across all the different
VaultManagercontracts associated to a stablecoin. There is one such
Treasurycontract per stablecoin on mainnet.
It is at the level of a
Treasurycontract that profits and losses from
FlashLoancontracts are pooled before a portion is distributed (or not) to veANGLE holders.
Treasurycontract has the ability to grant minting rights on its associated AgToken: it is hence the contract granting permissions to each new
Oracle contracts in Angle Borrowing module differ from those in the Core Module of the protocol. Each oracle implementation is different within this new module to optimize for gas cost.
Settlementcontracts can be used to settle that is to say to remove a
VaultManagerfrom the protocol. Global settlement corresponds to the situation where all
VaultManagercontracts associated to one stablecoin are settled at the same time.
In the settlement process, collateral from each
VaultManageris transferred to the
Settlementcontract to first allow owners of over-collateralized vault to claim their collateral upon repaying all their debt. Then owners of stablecoins can redeem collateral at oracle value (if there is enough left).
This side contract facilitates auto-leverage and liquidations. It can be used to swap from one asset to another hence allowing for instance swaps of stablecoin to collateral to enable users to increase their leverage on the collateral they're using to borrow. The contract implemented by the Angle Core Team is built to optimize interactions with Angle Core Module.
In this module, there is only one place where roles are stored: it is in the
CoreBorrowcontract which maintains the integrity of the roles at the module-level.
When a governor or guardian function is called on a contract, this reads (directly or indirectly) in the
CoreBorrowcontract whether the
msg.senderhas the correct role.
Beyond the two main guardian and governor roles, the
CoreBorrowcontract also introduces a
Treasurycontracts associated to stablecoins on which flash loans can be taken.