🔜Architecture Overview

Overview of the organization of the code of Borrowing Module of the Angle Protocol

The repository for the Borrowing Module of Angle Protocol can be found on Github here, it is the borrow-contracts repo.

Main Contracts

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 VaultManager contract per collateral type for each stablecoin. The same collateral could also have different associated VaultManager contracts 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 permit interface 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.

VaultManager contracts 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.

Supporting Contracts

This contract is responsible for doing the accounting across all the different VaultManager contracts associated to a stablecoin. There is one such Treasury contract per stablecoin on mainnet.

It is at the level of a Treasury contract that profits and losses from VaultManager and FlashLoan contracts are pooled.

Each Treasury contract has the ability to grant minting rights on its associated AgToken: it is hence the contract granting permissions to each new VaultManager.

Oracle contracts in Angle Borrowing module all have a different implementation to optimize for gas costs.

Settlement contracts can be used to settle that is to say to remove a VaultManager from the protocol. Global settlement corresponds to the situation where all VaultManager contracts associated to one stablecoin are settled at the same time.

In the settlement process, collateral from each VaultManager is transferred to the Settlement contract 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.

Access Control Conventions and Roles

In this module, there is only one place where roles are stored: it is in the CoreBorrow contract 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 CoreBorrow contract whether the msg.sender has the correct role.

Beyond the two main guardian and governor roles, the CoreBorrow contract also introduces a FLASHLOANER_TREASURY_ROLE given to Treasury contracts associated to stablecoins on which flash loans can be taken.

Last updated