Overview of Flow Control

Flow control in Vesper V3

The diagram below illustrates how various contracts interact in the V3 framework. To a first approximation,

  • Users or external (non-Vesper) contracts interact with pools;

  • The (proxied) pool contract interacts with strategies;

  • Pool rewards and pool accountant contract are logically just parts of the pool contract;

  • Strategies are deployed target protocols (for example, Compound, Aave);

  • Keepers, which may be bots or persons, regulate the system.


Mapping the block diagram to smart contracts

The Pool block represents an implementation of the VPool contract.

Pool rewards is a module for calculating and storing any VSP rewards associated with the pool. It is implemented with the PoolRewards and PoolRewardsStorage contracts.

The Pool Accountant keeps track of the strategies used by the pool. It is implemented by the PoolAccountant and PoolAccountantStorage contracts.

Strategy represents one or more strategy contract for deploying assets to generate yield.

With regard to the illustration above, let’s assume this Vesper pool is vDAI pool. That means a user will deposit DAI and receive a vDAI claim ticket in return, the amount of which is based on the value of the pricePerShare variable at the time the deposit is made.

The Target Protocol block represents the protocol to which the pool's assets have been sent, such as, for instance, Curve, Compound or Yearn.

Flow of Control When a Deposit Is Made to a Pool

Here's what happens when a user makes a deposit to a pool. The steps below are labeled to correspond to the pathways in the illustration above.

  1. The user initiates deposit of DAI in the vDAI pool.

  2. If the PoolRewards contract exists, the pool sends an update to to the PoolRewards contract, notifying it that the user is depositing in the pool.

  3. The pool issues shares of vDAI, also known as claim tokens, to the user. These claim tokens go to the user's wallet.

Flow of Control When a Withdrawal from a Pool Occurs

Here's what happens when a user makes a withdrawal from a pool. The steps below are labeled to correspond to the pathways in the illustration above.

a. The user initiates withdrawal of DAI. To do this, the user must hold vDAI in their wallet. This vDAI is now transferred to the pool.

b. If the PoolRewards contract exists, then the pool sends an update that the user is withdrawing from the pool, and any rewards due to the user are calculated.

c. The pool maintains a local reserve of DAI in order to cover withdrawals. If the pool's reserve holds sufficient funds to cover the withdrawal, it burns the user's share of vDAI, and transfers to the user an equivalent amount of DAI. Otherwise, if the local reserve does not have sufficient DAI on hand, the pool initiates withdrawal from one or more of its strategies.

d. Since strategies do not hold any collateral, (DAI in this case), it withdraws DAI from its target protocol.

If the pool employs more than one strategy, the Pool Accountant maintains a list that determines the order in which strategies will be asked for funds to complete a withdrawal.

Flow of Control during Rebalancing

i. Only the keeper can call rebalance on strategies.

ii. Strategies gather data to generate profit/loss and payback statements. In the case of profit and/or payback, each strategy will withdraw funds from its target protocol, given it has deposited funds previously.

iii. The Strategy sends profit/loss and payback statements to the pool.

iv. The Pool passes this information to the PoolAccountant, which is responsible for doing all bookkeeping.

v. The PoolAccountant sends the final standing of the strategy back to the pool and the pool decides whether to give more funds to the strategy or take back from the strategy.

vi. If the strategy has received funds from the pool, it deposits these new funds in the target protocol; otherwise it must withdraw from the target protocol to give funds back to the pool.

Last updated