Active LP Optimiser
Documentation on a simple LP optimizer built on top of Voltz.
The Active LP Optimiser contract allows LPs to passively and constantly rebalance their positions so that they can maximise their returns on fees. Effectively, if an LP deposits liquidity into the protocol within a specified fixed APR range then they may only collect fees on trades between fixed takers and variable takers which happen in this range. This is sub-optimal and can improved by constantly rebalancing the inactive liquidity to maximise the LP fee returns. Assuming that rebalancing happens approximately every two days this optimiser can bring an APY improvement of 100-200%.

setMarginEngineAndVAMM

The function setMarginEngineAndVAMM() lets us set the Margin Engine and VAMM contracts so that the LP optimiser can interact with a given pool.
1
function setMarginEngineAndVAMM(
2
IMarginEngine _marginEngine,
3
IPeriphery _periphery
4
) external onlyOwner
Copied!

_burn

The function _burn() lets us burn liquidity from the pool when an LP would like to rebalance their position or completely get rid of positions they do not want to support.
1
function _burn() internal
Copied!

_mintAll

The function _mintAll() effectively picks up all of the inactive margin in a contract (margin not deployed) and calculates the notional amount to mint from this. The notional amount to mint is the product of the amount of inactive margin and leverage. Then the underlying tokens need to be approved so they are transferable from the LP Optimiser contract to the Periphery.sol contract. The Periphery.sol contract does the minting or burning. The mintOrBurn function of the periphery needs the upper and lower ticks, notional to mint, and margin delta to support the notional.
1
function _mintAll() internal
Copied!

_mint

The mint() function is analogous to the mintAll() function but it does not mint the entire inactive margin in a contract. It takes the marginDelta as an input to support the notional to be minted.
1
function _mint(uint256 _marginDelta) internal
Copied!

Parameters

Name
Type
Description
_marginDelta
uint256
...

deposit

The deposit() function lets a given trader passively deposit liquidity into the protocol and then lets the LP optimiser vault manager the liquidity provision on their behalf. For example, as a passive retail investor you can deposit liquidity and define the underlying tokens you want to deposit. Behind the scenes the optimiser vault will mint liquidity on your behalf and constantly rebalance the your position depending on changing market conditions. This ensure your liquidity remains in range.
1
function deposit(uint256 depositAmountInUnderlyingTokens) external
Copied!

Parameters

Name
Type
Description
depositAmountInUnderlyingTokens
uint256
The amount of liquidity to be deposited in underlying tokens e.g. USDC

calculateMarginToWithdraw

The function calculateMarginToWithdraw() computes the amount of margin you can withdraw as an LP assuming you have no un-netted variable liabilities. Effectively, this is the amount of margin you can withdraw which is not utilised to support un-netted positions. This function can only be called by the owner of the LP Optimiser contract.
1
function rebalance(int24 _updatedTickLower, int24 _updatedTickUpper)
2
external
3
onlyOwner
Copied!

rebalance

The rebalance() function is only callable by the owner of the LP Optimiser contract. It burns all liquidity currently available (liquidity deposited in the LP Optimiser vault so you can extract margin and deposit the liquidity in a new fixed APR range). This function calls on the calculateMarginToWithdraw function.
1
function rebalance(int24 _updatedTickLower, int24 _updatedTickUpper)
2
external
3
onlyOwner
Copied!

Parameters

Name
Type
Description
_updatedTickLower
int24
The latest lower tick for the fixed APR range to be set for deposited liquidity.
_updatedTickUpper
int24
The latest upper tick for the fixed APR range to be set for deposited liquidity.