Developers
Searchโ€ฆ
๐Ÿ‘ฎ
Treasury - Stablecoin Accounting
Treasury - Accounting in the Borrowing Module
This contract associated to Angle Borrowing Module is not yet available and will soon be open-sourced.

1. Introduction

The Treasury contract is the contract handling the accounting across all the VaultManager contracts of a stablecoin. It is the one which responsible to redistribute profits to governance. The role of the Treasury contract is also to manage the different VaultManager contracts by granting minting rights on the AgToken to new contracts or by removing this right to others.
This contract has some externally accessible functions for keepers. Otherwise, most of these functions are governance functions.
There is therefore one Treasury contract per stablecoin of the protocol within this module.

2. Contract Details

Interfaces

Implements ITreasury, Initializable. This contract is upgradeable.

References

  • core: Reference to the CoreBorrow contract of the module which handles all AccessControl logic
  • flashLoanModule: Flash Loan Module with a minter right on the stablecoin
  • stablecoin: Stablecoin handled by this contract.
  • surplusManager: Address responsible for handling the surplus made by the treasury
  • vaultManagerList: List of the accepted VaultManager of the protocol for this stablecoin
  • vaultManagerMap: Maps an address to whether it was initialized as a VaultManager contract

Variables

  • badDebt: Amount of bad debt (unbacked stablecoin) accumulated across all VaultManager contracts linked to this stablecoin
  • surplusBuffer: Surplus amount accumulated by the contract waiting to be distributed to governance. Technically only a share of this surplusBuffer will go to governance. Once a share of the surplus buffer has been given to governance, then this surplus is reset

Parameter

  • surplusForGovernance: Share of the surplusBuffer distributed to governance (in BASE_PARAMS)

Access Control

Restricted functions are checked upon calling the associated core contract.

3. Key Mechanisms & Concepts

Keeper Functions

pushSurplus

1
function pushSurplus() external returns (uint256 governanceAllocation);
Copied!
Pushes the surplus buffer to the surplusManager contract. This function makes sure to fetch surplus from all VaultManager contracts and from the flashloan module if it is initialized to make sure no surplus is given to governance if bad debt accrued somewhere. Typically this function is to be called once every week by a keeper to distribute rewards to veANGLE holders.
Concretely, this function pulls surplus and bad debt from all contracts handled by this treasury (flashloan module and VaultManager). If surplus is bigger than bad debt (or is bigger than the bad debt accrued during previous calls), then a buffer is stored and this function splits this buffer between a portion for governance and a portion for the protocol's reserves. The portion for governance is sent to the surplusManager address. There is no storage variable which keeps track of the protocol's reserves.
There are so far no rewards given to keepers calling this function.
Return Value:
  • governanceAllocation: Amount of stablecoins for governance

updateBadDebt

1
function updateBadDebt(uint256 amount) external returns (uint256 badDebtValue);
Copied!
This function can be called by a keeper to update the bad debt of the protocol in the case where the protocol has accumulated some revenue from an external source. The rationale for this function is that if the protocol has made some profit, it needs to be notified of it, and eliminate its bad debt.
It leaves the opportunity to the keeper to specify the amount of bad debt to erase, and returns the new value of the bad debt.
The function will necessarily revert if the amount is greater than the current value of the badDebt.

Other Keeper Functions

There are other utility functions which are helpers to fetch surplus across different contracts. They cannot suffice for a surplus distribution: only the pushSurplus function can be used for this.
These functions are:
  • fetchSurplusFromAll: Fetches the surplus accrued across all the VaultManager contracts controlled by this Treasury contract as well as from the fees of the FlashLoan module (if initialized)
  • fetchSurplusFromFlashLoan: Fetches the surplus accrued in the flash loan module and updates the surplusBuffer. It reverts if the flashLoanModule has not been initialized

Governance Functions

There are several functions available for governance in this contract to manage different VaultManager or the flashloan module:
  • addMinter: Adds a new minter for the stablecoin
  • addVaultManager: Adds a new VaultManager
  • removeMinter: Removes a minter from the stablecoin contract
  • removeVaultManager: Removes a VaultManager
  • recoverERC20: For governance to recover tokens mistakenly sent or accruing to this contract
  • setTreasury: Changes the treasury contract and communicates this change to all VaultManager contract
  • setSurplusForGovernance: Sets the surplusForGovernance parameter
  • setSurplusManager: Sets the surplusManager contract responsible for handling the surplus of the protocol
  • setCore: Sets a new CoreBorrow contract
  • setFlashLoanModule: Sets a new flash loan module for this stablecoin

View Functions

There are some view functions for VaultManager contracts to verify roles of addresses calling it:
  • isVaultManager: Checks whether an address is a VaultManager
  • isGovernor: Checks whether an address has the GOVERNOR_ROLE in the associated CoreBorrow contract
  • isGovernorOrGuardian: Checks whether an address has the GUARDIAN_ROLE