# Rebalancing

### Whitelisting

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

{% @github-files/github-code-block url="<https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L699>" %}

This of course can be reverted here:

{% @github-files/github-code-block url="<https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L717>" %}

### 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.

{% @github-files/github-code-block url="<https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L881-L886>" %}

The rebalancing can then be done via this function:

{% @github-files/github-code-block url="<https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L744-L748>" %}

or be accompanied by a position change like this:

{% @github-files/github-code-block url="<https://github.com/mangrovedao/mangrove-vault/blob/899abdb187f1801ba44621c0e25a697edda859e7/src/MangroveVault.sol#L765-L772>" %}
