# Algorithm

## Introduction

It’s clear that synthetic tokens need better strategies to manage its basket. Since all underlying assets of the same basket tend to have similar prices, e.g. the mUSD basket contains all sorts of different stable coins, it’s natural to consider using a stable coin DEX algorithm to balance the basket portfolio. Curve.fi is currently the best stable coin DEX on ethereum, and it’s built on top of the following invariant:

This invariant has the following properties:

When the token prices are closed to equilibrium(1 to 1), it’s performing close to a constant sum curve;

When the token prices are shifted away from the equilibrium, it’s performing close to a constant product curve.

The further the token prices are shifted away, the more slippage the invariant produces. This ensures that the pool can always provide liquidity even at extreme prices.

## Parameters

Curve's StableSwap invariant above contains two parameters: A and D. Both parameters determine the behavior of the basket.

A controls the “wideness” of the curve: The bigger the value of A is, the closer is the invariant to constant sum; the smaller the value of A is, the closer is the invariant to constant product. Therefore, if we want to make sure that all tokens in the baskets have similar percentages, we could use a small A vault. Otherwise, if we want to promote liquidity and can tolerate some degree of basket imbalance, we could use a larger A vault.

The parameter D, on the other hand, can be seen as the total number of tokens in the basket when their prices are equal. When that situation happens, all tokens have the same amount(i.e. D/n), and the total number of tokens reaches its minimum (i.e. D). Therefore, we could assume that D is the intrinsic value of the basket with the following reasons:

D represents the total amount of tokens in the basket when they are in equilibrium(i.e. when their prices and quantities are the same). Since all tokens in the basket are of the same peg(e.g. stable coins or ERC20 BTCs), they are expected to reach such an equilibrium on a long term;

D represents the smallest token total amount in the basket when no tokens are added to/removed from the basket. When some token prices deviate from the peg, the basket has more than D tokens in total. This is reasonable as price deviation usually implies (temporary) malfunctions of a certain token. In such case, there will be more tokens in the basket the keep the intrinsic value of the basket;

Swapping any tokens in the pool does not affect the value of D if A remains constant. This makes it possible to use the basket as a swap between underlying tokens.

## Implementation

With these reasons in mind, if there exists a synthetic token which is backed by such a basket, there should be exactly D tokens available. In short:

When a user deposits underlying tokens to mint new synthetic tokens, the amount of synthetic tokens to mint is equal to the increase in value of D;

When a user redeems synthetic tokens to retrieve underlying tokens, the amount of synthetic tokens to burn is equal to the decrease in value of D;

Transaction fees, including mint/redeem/swap fees, will lead to an increase of value D. The transaction fee which is charged in synthetic token is equal to the increase of value D.

This is exactly how ACoconut introduces its synthetic token ACoconut BTC/acBTC, which is a synthetic ERC20 BTC token backed by a basket of ERC20 BTC tokens including WBTC and renBTC. For more information about the detailed implementation, please refer to the section acSwap.

Please note that changing the value of A also changes the value of D unless the basket is in equilibrium, which means that the total supply of acBTC is affected if A is unchanged. We do not see this as a big issue as the A value is not expected to be changed.

In fact, Curve.fi’s Ren pool uses 100 for a long time and it proves to stabilize the pool well. If we must update the value of A, for example, as voted by the ACoconut Community, we could use the acBTC treasury to address the total supply difference. If more acBTC is minted after changing A, they are stored in acBTC treasury; if less acBTC is minted after changing A, we are going to cover the difference by burning acBTC in the treasury.

Last updated