For the complete documentation index, see llms.txt. This page is also available as Markdown.

Tokens rebalancing

The goal of this function is to rebalance a three-token portfolio to reach specific target weights (measured in basis points), using USD valuations and slippage-protected swaps.

For example, suppose the targets are:

  • 50% BTC

  • 30% ETH

  • 20% DAI

If the portfolio currently holds:

  • $6,500 in BTC (65%)

  • $2,500 in ETH (25%)

  • $1,000 in DAI (10%)

Since BTC is overweight while ETH and DAI are underweight, the function will swap $500 worth of BTC into ETH and $1,000 worth of BTC into DAI to restore the target balance.

Function

https://github.com/mimic-protocol/examples/blob/main/examples/10-rebalancing-tokens/src/function.ts

Github link

Manifest

https://github.com/mimic-protocol/examples/blob/main/examples/10-rebalancing-tokens/manifest.yaml

Github link

The ABI used for this example can be downloaded below:

4KB
Open

Last updated