Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add chosing an exponentAtPriceOne docs #4919

Merged
merged 11 commits into from
May 19, 2023
45 changes: 40 additions & 5 deletions x/concentrated-liquidity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,43 @@ a) Preventing trade at a desirable spot price or
b) Having the front end round the tick's actual price to the nearest
human readable/desirable spot price

## Chosing an Exponent At Price One Value

The creator of a pool is required to choose an exponenetAtPriceOne as one of the input parameters. As explained previously, this value determines how much the spot price increases or decreases when traversing ticks. The following equation will assist in selecting this value:

$$exponentAtPriceOne=log_{10}(\frac{D}{P})$$

$$P=(\frac{baseAssetInUSD}{quoteAssetInUSD})$$

$$D=P-(\frac{baseAssetInUSD}{quoteAssetInUSD+desiredIncrementOfQuoteInUSD})$$
Comment on lines +290 to +294
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be determining exponent at price one programmatically at pool creation via twap over the past day?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be really cool that if a user provides a desired price increment that the exponent gets selected automatically! Otherwise if the user provides an exponent then it is assumed that they know what they are doing. I will create an issue for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


### Example 1

SHIB is trading at $0.00001070 per SHIB
BTC is trading at $28,000 per BTC

We want to create a SHIB/BTC concentrated liquidity pool where SHIB is the baseAsset (asset0) and BTC is the quoteAsset (asset1). In terms of the quoteAsset, we want to increment in 10 cent values.

$$P=(\frac{0.00001070}{28,000})=0.000000000382142857$$

$$D=(0.000000000382142857)-(\frac{0.00001070}{28,000+0.10})=0.0000000000000013647910441136$$

$$exponentAtPriceOne=log_{10}(\frac{0.0000000000000013647910441136}{0.000000000382142857})=-5.447159582$$

We can therefore conclude that we can use an exponent at price one of -5 (slightly under precise) or -6 (slightly over precise) for this base/quote pair and desired price granularity.

### Example 2

Flipping the quoteAsset/baseAsset, for BTC/SHIB, lets determine what the exponentAtPriceOne should be. For SHIB as a quote, centralized exchanges list prices at the 10^-8, so we will set our desired increment to this value.

$$P=(\frac{28,000}{0.00001070})=2616822429$$

$$D=(2616822429)-(\frac{28,000}{0.00001070+0.00000001})=2443345$$

$$exponentAtPriceOne=-log_{10}(\frac{2443345}{2616822429})=-3.0297894598783$$

We can therefore conclude that we can use an exponent at price one of -3 for this base/quote pair and desired price granularity.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need to update since exponent at price one is -6 now with 100 tick spacing?


## Concentrated Liquidity Module Messages

### `MsgCreatePosition`
Expand Down Expand Up @@ -490,7 +527,7 @@ is associated with the `concentrated-liquidity` pool, the swap is routed
into the relevant module. The routing is done via the mapping from state that was
discussed in the "Pool Creation" section.

### Liquidity Provision
## Liquidity Provision

> As an LP, I want to provide liquidity in ranges so that I can achieve greater
capital efficiency
Expand Down Expand Up @@ -591,7 +628,7 @@ func (k Keeper) withdrawPosition(
}
```

### Swapping
## Swapping

> As a trader, I want to be able to swap over a concentrated liquidity pool so
that my trades incur lower slippage
Expand Down Expand Up @@ -1462,16 +1499,14 @@ This listener executes after a swap in a concentrated liquidity pool.

At the time of this writing, it is only utilized by the `x/twap` module.

### State
## State

- global (per-pool)

- per-tick

- per-position

### Placeholder

## Terminology

We will use the following terms throughout the document:
Expand Down