👮Treasury - Stablecoin Accounting
Treasury - Accounting in the Borrowing Module
Contract Name:
Treasury
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 theCoreBorrow
contract of the module which handles all AccessControl logicflashLoanModule
: Flash Loan Module with a minter right on the stablecoinstablecoin
: Stablecoin handled by this contract.surplusManager
: Address responsible for handling the surplus made by the treasuryvaultManagerList
: List of the acceptedVaultManager
of the protocol for this stablecoinvaultManagerMap
: Maps an address to whether it was initialized as aVaultManager
contract
Variables
badDebt
: Amount of bad debt (unbacked stablecoin) accumulated across allVaultManager
contracts linked to this stablecoinsurplusBuffer
: Surplus amount accumulated by the contract waiting to be distributed to governance. Technically only a share of thissurplusBuffer
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 thesurplusBuffer
distributed to governance (inBASE_PARAMS
)
Access Control
Restricted functions are checked upon calling the associated core
contract.
3. Key Mechanisms & Concepts
Keeper Functions
pushSurplus
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.
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
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 theVaultManager
contracts controlled by thisTreasury
contract as well as from the fees of theFlashLoan
module (if initialized)fetchSurplusFromFlashLoan
: Fetches the surplus accrued in the flash loan module and updates thesurplusBuffer
. It reverts if theflashLoanModule
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 stablecoinaddVaultManager
: Adds a newVaultManager
removeMinter
: Removes a minter from the stablecoin contractremoveVaultManager
: Removes aVaultManager
recoverERC20
: For governance to recover tokens mistakenly sent or accruing to this contractsetTreasury
: Changes the treasury contract and communicates this change to allVaultManager
contractsetSurplusForGovernance
: Sets thesurplusForGovernance
parametersetSurplusManager
: Sets thesurplusManager
contract responsible for handling the surplus of the protocolsetCore
: Sets a newCoreBorrow
contractsetFlashLoanModule
: 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 aVaultManager
isGovernor
: Checks whether an address has theGOVERNOR_ROLE
in the associatedCoreBorrow
contractisGovernorOrGuardian
: Checks whether an address has theGUARDIAN_ROLE
Last updated