Comment on page
Treasury - Stablecoin Accounting
Treasury - Accounting in the Borrowing Module
Treasurycontract is the contract handling the accounting across all the
VaultManagercontracts of a stablecoin. It is the one which responsible to redistribute profits to governance. The role of the
Treasurycontract is also to manage the different
VaultManagercontracts 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
Treasurycontract per stablecoin of the protocol within this module.
Initializable. This contract is upgradeable.
core: Reference to the
CoreBorrowcontract 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
VaultManagerof the protocol for this stablecoin
vaultManagerMap: Maps an address to whether it was initialized as a
badDebt: Amount of bad debt (unbacked stablecoin) accumulated across all
VaultManagercontracts linked to this stablecoin
surplusBuffer: Surplus amount accumulated by the contract waiting to be distributed to governance. Technically only a share of this
surplusBufferwill go to governance. Once a share of the surplus buffer has been given to governance, then this surplus is reset
surplusForGovernance: Share of the
surplusBufferdistributed to governance (in
Restricted functions are checked upon calling the associated
function pushSurplus() external returns (uint256 governanceAllocation);
Pushes the surplus buffer to the
surplusManagercontract. This function makes sure to fetch surplus from all
VaultManagercontracts 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
surplusManageraddress. 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.
governanceAllocation: Amount of stablecoins for governance
function updateBadDebt(uint256 amount) external returns (uint256 badDebtValue);
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
amountis greater than the current value of the
There are other utility functions which are helpers to fetch surplus across different contracts. They cannot suffice for a surplus distribution: only the
pushSurplusfunction can be used for this.
These functions are:
fetchSurplusFromAll: Fetches the surplus accrued across all the
VaultManagercontracts controlled by this
Treasurycontract as well as from the fees of the
FlashLoanmodule (if initialized)
fetchSurplusFromFlashLoan: Fetches the surplus accrued in the flash loan module and updates the
surplusBuffer. It reverts if the
flashLoanModulehas not been initialized
There are several functions available for governance in this contract to manage different
VaultManageror the flashloan module:
addMinter: Adds a new minter for the stablecoin
addVaultManager: Adds a new
removeMinter: Removes a minter from the stablecoin contract
removeVaultManager: Removes a
recoverERC20: For governance to recover tokens mistakenly sent or accruing to this contract
setTreasury: Changes the treasury contract and communicates this change to all
setSurplusForGovernance: Sets the
setSurplusManager: Sets the
surplusManagercontract responsible for handling the surplus of the protocol
setCore: Sets a new
setFlashLoanModule: Sets a new flash loan module for this stablecoin
There are some view functions for
VaultManagercontracts to verify roles of addresses calling it:
isVaultManager: Checks whether an address is a
isGovernor: Checks whether an address has the
GOVERNOR_ROLEin the associated
isGovernorOrGuardian: Checks whether an address has the