Rebalancing

Whitelisting

Before rebalancing, the chosen contract to interact with must be whitelisted.

https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L699
  function allowSwapContract(address contractAddress) external onlyOwner {

This of course can be reverted here:

https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L717
  function disallowSwapContract(address contractAddress) external onlyOwner {

Rebalance

In order to rebalance, you should build the calldata in order to swap, and pass the target. Slippage protection can be enforced. To put trust towards user, a slippage protection relative to the current oracle price can be set.

https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L881-L886
  /**
   * @notice Sets the maximum price spread for the rebalance function
   * @dev This function can only be called by the owner of the contract
   * @param newMaxPriceSpread The new maximum price spread to be set
   */
  function setMaxPriceSpread(uint256 newMaxPriceSpread) external onlyOwner {

The rebalancing can then be done via this function:

https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L744-L748
  function swap(address target, bytes calldata data, uint256 amountOut, uint256 amountInMin, bool sell)
    external
    onlyOwnerOrManager
    nonReentrant
    returns (int256 netBaseChange, int256 netQuoteChange)

or be accompanied by a position change like this:

https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L765-L772
  function swapAndSetPosition(
    address target,
    bytes calldata data,
    uint256 amountOut,
    uint256 amountInMin,
    bool sell,
    KandelPosition memory position
  ) external onlyOwnerOrManager nonReentrant returns (int256 netBaseChange, int256 netQuoteChange) {

Last updated