Rebalancing a Leverage Token

Once a Leverage Token is created and properly configured with the corresponding leverage strategy, we need to make sure the Set is well maintained in its leverage ratio bounds over time. Otherwise, if the leverage ratio inches too high and approaches its margin requirement, we're at risk of getting liquidated!

There are a few approaches to Set maintenance. Developers/Managers can rebalance Leverage Sets using the corresponding LeverageModule directly (based on what lending platform your strategy uses), but this is the most complex approach.

Lending PlatformModule NameSupported Networks

Aave

EthereumPolygonAvalanche

Compound

Ethereum

Perpetual Protocol

Optimism

To learn more about trading via Perpetual Protocol directly, follow the trading guide.

The most common approach involves Developers/Managers using the rebalance API functions exposed by the Strategy contract (aka rebalance, iterateRebalance, and if under dire circumstances, ripcord).

Lending PlatformStrategy Contract

Aave

FlexibleLeverageStrategyExtension

Compound

FlexibleLeverageStrategyExtension

Perpetual Protocol

The rebalance functions exposed by the strategy extension contract can always be called manually to help keep a Perpetual Leverage Token within its leverage ratios, but this is certainly not scalable.

We recommend implementing a keeper "bot" that continuously monitors the shouldRebalance or shouldRebalanceWithBounds state to determine whether or not the bot should submit a new rebalance transaction. Check the strategy contract's documentation for more information on what values shouldRebalance returns, to help inform your bot what next steps it should take.

We have prepared a very simple Python bot example to help developers get started with their automated rebalancing infrastructure!

Unfortunately, popular existing keeper network solutions, such as OpenZeppelin's Defender and Gelato Network, are not yet available on Optimism. When they launch, we recommend creating a simple Task to periodically check the rebalance status of your product and rebalance as necessary, as this abstracts away a lot of the complexity overhead of running your own bot.

Here is a sample source code of an OpenZeppelin (OZ) Defender monitoring a Strategy Contract, and rebalancing when the getter returns nonzero. When OZ supports Optimism, asset managers can copy this source as an AutoTask.

NOTE: Keep in mind that rebalancing maintenance, whether powered by manual transactions, an in-house keeper bot, or an existing keeper network, costs gas. Be sure you have a product plan to profitability (such as using streaming fees) to justify your maintenance costs!

Last updated