PoolAccountant

PoolAccountant

This contract is the "accountant" for Vesper pools which keeps records of strategies. Each deployed pool has one associated accountant.

VERSION

string VERSION

MAX_BPS

uint256 MAX_BPS

EarningReported

event EarningReported(address strategy, uint256 profit, uint256 loss, uint256 payback, uint256 strategyDebt, uint256 poolDebt, uint256 creditLine)

LossReported

event LossReported(address strategy, uint256 loss)

StrategyAdded

event StrategyAdded(address strategy, uint256 debtRatio, uint256 externalDepositFee)

StrategyRemoved

event StrategyRemoved(address strategy)

StrategyMigrated

event StrategyMigrated(address oldStrategy, address newStrategy)

UpdatedExternalDepositFee

event UpdatedExternalDepositFee(address strategy, uint256 oldFee, uint256 newFee)

UpdatedPoolExternalDepositFee

event UpdatedPoolExternalDepositFee(uint256 oldFee, uint256 newFee)

UpdatedStrategyDebtRatio

event UpdatedStrategyDebtRatio(address strategy, uint256 oldDebtRatio, uint256 newDebtRatio)

init

function init(address _pool) public

This init function meant to be called after proxy deployment. DO NOT CALL it with proxy deploy; only after the proxy has been successfully deployed.

addStrategy

function addStrategy(address _strategy, uint256 _debtRatio, uint256 _externalDepositFee) public

Add strategy. Once a strategy is added it can call rebalance and borrow funds from the pool and invest those funds in a provider/lender.

Recalculate pool level external deposit fee after all state variables are updated.

setup

function setup() external

OnlyPool:: Helper function for V5 upgrade

removeStrategy

function removeStrategy(uint256 _index) external

Remove strategy and recalculate the pool level external deposit fee.

Revoke and remove strategy from the strategy array. Update withdraw queue. Withdraw queue order should not change after remove. Strategy can be removed only after it has paid all debt. Use he migratestrategy function if debt is not paid and you want to upgrade the strategy.

updateExternalDepositFee

function updateExternalDepositFee(address _strategy, uint256 _externalDepositFee) external

Update external deposit fee of the strategy and recalculate the pool level external deposit fee.

recalculatePoolExternalDepositFee

function recalculatePoolExternalDepositFee() external

Recalculate the pool external deposit fee. It is calculated using debtRatio and the external deposit fee of each strategy.

Whenever debtRatio changes, recalculation is required. DebtRatio changes if a strategy reports loss, in which case an off-chain application can watch for it and take action accordingly. This function is 'gas heavy', so we do not want to call it during reportLoss.

sweepERC20

function sweepERC20(address _fromToken) external virtual

Transfer given ERC20 token to pool

updateDebtRatio

function updateDebtRatio(address _strategy, uint256 _debtRatio) external

Update debt ratio.

A strategy is retired when its debtRatio is 0. As debtRatio impacts pool level external deposit fee, it must be recalculated after updating debtRatio.

updateWithdrawQueue

function updateWithdrawQueue(address[] _withdrawQueue) external

Update withdraw queue. Withdraw queue is a list of strategies in the order in which funds should be withdrawn.

Pool always keeps some buffer amount to satisfy withdrawal requests. Any withdrawal request higher than what is in the buffer will cause withdrawal from the withdraw queue. So withdrawQueue[0] will be the first strategy where withdrawal request will be sent.

migrateStrategy

function migrateStrategy(address _old, address _new) external

Migrate an existing strategy to new strategy.

Migrating strategy aka old and new strategy should be of same type. New strategy will replace old strategy in strategy mapping, strategies array, withdraw queue.

reportEarning

function reportEarning(address _strategy, uint256 _profit, uint256 _loss, uint256 _payback) external returns (uint256 _actualPayback, uint256 _creditLine)

Strategy calls this at regular intervals.

reportLoss

function reportLoss(address _strategy, uint256 _loss) external

Update strategy loss.

decreaseDebt

function decreaseDebt(address _strategy, uint256 _decreaseBy) external

Decrease debt of strategy; this also decreases totalDebt.

In case of withdraw from strategy, pool will decrease debt by the amount withdrawn

availableCreditLimit

function availableCreditLimit(address _strategy) external view returns (uint256)

Get available credit limit of strategy. This is the amount strategy can borrow from the pool.

Available credit limit is calculated based on current debt of pool and strategy and the current debt limit of pool and strategy. credit available = min(pool's debt limit, strategy's debt limit, max debt per rebalance). When any strategy does not pay back its outstanding debt, this impacts the credit line of other strategies if totalDebt of pool >= debtLimit of pool

excessDebt

function excessDebt(address _strategy) external view returns (uint256)

Debt above current debt limit

getStrategies

function getStrategies() external view returns (address[])

Return the strategies array.

getWithdrawQueue

function getWithdrawQueue() external view returns (address[])

Return withdrawQueue array.

totalDebtOf

function totalDebtOf(address _strategy) external view returns (uint256)

Get total debt of given strategy.

Last updated