PoolManager.sol
****PoolManager
contracts each correspond to a collateral pool of the protocol for a stablecoin of the protocol. Each contract manages a single ERC20 token. If the protocol has two stablecoins agUSD and agEUR each accepting USDC as collateral, then there will be two different PoolManager
contracts: one for the USDC/agUSD pair, and one for the USDC/agEUR pair.mint
, deposit
, openPerpetual
or addToPerpetual
transaction goes to this contract.PoolManager
level. Each PoolManager
manages its own internal collateral via strategies voted by the DAO. Those strategies are inspired from Yearn instead of interacting directly with Yearn. This choice was made for the protocol to keep full control on its reserves by removing a third party integration. PoolManager
then reports back to StableMaster
its gains accumulateInterest()
or losses signalLoss().
PoolManager
contract is also the hub when it comes to transmitting changes to all the contracts that are concerned by stablecoin/collateral pair. For instance, if there is a change in a guardian address, then the PoolManager
contract is the one propagating this change to the PerpetualManager
, FeeManager
and Strategy
contracts.FunctionUtils
, AccessControlUpgradeable
and IPoolManager
. The contract is upgradeable.token
: Interface for the underlying token accepted by this contract, it cannot be modifiedperpetualManager
: Reference to the PerpetualManager
for this collateral/stablecoin pairstableMaster
: Reference to the StableMaster
contract corresponding to this PoolManager
feeManager
: FeeManager
contract for this collateral/stablecoin pairstrategies
: All strategies invested in by the PoolManager
. They are represented by a struct with the following parameters:lastReport
: Last time the strategy updated its positiontotalStrategyDebt
: Debt owed by the strategy to the PoolManager
debtRatio
: The share of the total assets that the strategy
has access tototalDebt
: Total amount lent by PoolManager
to all strategiesdebtRatio
: Proportion of the funds managed dedicated to strategiesstrategyList
: List of the current strategiesSTABLEMASTER_ROLE
GUARDIAN_ROLE
GOVERNOR_ROLE
STRATEGY_ROLE
_getTotalAsset
when entering yous should make sure this hasn't be called by a flash loan and look at a mean of past APR.StableMaster
contract propagating changes to its underlying contracts. The PoolManager
takes into account these changes before propagating it to the underlying contracts._guardian
: New guardian addressguardian
: Old guardian address to revokeGOVERNOR
function.stocksUsers
for this collateral, but this is just an approximation as users can claim the collateral of their choice provided that they own a stablecoin.tokenAddress
: Address of the token to recoverto
Address of the contract to send collateral toamountToRecover
: Amount of collateral to transferGUARDIAN_ROLE
, which means the DAO or the multisig if not yet revoked.debtRatio
does not exceeds the 100% threshold as the manager cannot lend collateral that it does not own.strategy
: The address of the Strategy_debtRatio
: The share of the total assets that the strategy
has access tostrategy
for the PoolManager
. Multiple checks are made such that the contract must not already belong to the PoolManager
but also that the tokens considered are consistent in both strategy
and PoolManager
contracts.strategy
: The address of the Strategy to add_debtRatio
: The share of the total assets that the strategy
has access toStrategy
from PoolManager
strategies. The normal way to revoke a strategy should go through in order:strategy.debtRatio
is set to 0.strategy.harvest()
has been called enough time to recover all capital gain/losses and the initial capital.revokeStrategy()
is called .strategy
: The address of the Strategy to revokeamount
from the strategy, as we may not be able to withdraw from the lending protocol the full amount. In this last case we only update the parameters by setting the loss as the gap between what has been asked and what has been returned.strategy
: The address of the Strategyamount
: The amount to withdrawStrategy
or will only make sense if they are called by one of them. They are used by the strategies related to this PoolManager
to either query information from the PoolManager
or transmits information to it.PoolManager
. Since this function is a view function, there is no need to have an access control logic.PoolManager
PoolManager.
The strategy reports back what it has free, then the PoolManager
contract "decides" whether to take some back or give it more. Note that the most it can take is gain + _debtPayment
, and the most it can give is all of the remaining reserves. Anything outside of those bounds is abnormal behavior.gain
: Amount strategy has realized as a gain on its investment since its last report, and is free to be given back to PoolManager
as earningsloss
: Amount strategy has realized as a loss on its investment since its last report, and should be accounted for on the PoolManager
's balance sheet. The loss will reduce the debtRatio
. The next time the strategy will harvest, it will pay back the debt in an attempt to adjust to the new debt limit.debtPayment
: Amount strategy has made available to cover outstanding debt