-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: allowed empty AMM levels #2358
Draft
cdummett
wants to merge
5
commits into
suzukacastle_II
Choose a base branch
from
feat/empty_amm_levels
base: suzukacastle_II
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b48127
chore: correct spec so curve is fixed
cdummett ad45701
feat: add best bid ask calculations
cdummett 705a118
feat: allowed empty amm levels
cdummett 3b477bd
fix: update formula and inequalities
cdummett ddfb9f8
Apply suggestions from code review
cdummett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -167,7 +167,7 @@ $$ | |||||
P_{v_u} = \frac{r_f b}{p_u (1 + r_f) - r_f p_a} , | ||||||
$$ | ||||||
|
||||||
where $r_f$ is the `short` factor for the upper range and the `long` factor for the lower range, `b` is the current total balance of the vAMM across all accounts, $P_{v_l}$ is the theoretical volume and the bottom of the lower bound and $P_{v_u}$ is the (absolute value of the) theoretical volume at the top of the upper bound. The final $L$ scores can then be reached with the equation | ||||||
where $r_f$ is the `short` factor for the upper range and the `long` factor for the lower range, `b` is the commitment amount, $P_{v_l}$ is the theoretical volume and the bottom of the lower bound and $P_{v_u}$ is the (absolute value of the) theoretical volume at the top of the upper bound. The final $L$ scores can then be reached with the equation | ||||||
|
||||||
$$ | ||||||
L = P_v \cdot \frac{\sqrt{p_u} \sqrt{p_l}}{\sqrt{p_u} - \sqrt{p_l}} = P_v L_u, | ||||||
|
@@ -235,6 +235,62 @@ $$ | |||||
|
||||||
Then simply return the absolute difference between these two prices. | ||||||
|
||||||
## Best bid / best ask | ||||||
|
||||||
As the volume provided between two ticks can theoretically be less than the smallest unit of volume supported by the market's position decimals, the best-bid and ask will not always simply be one tick greater or less than the AMMs current fair price. | ||||||
|
||||||
Instead the best-bid and best-ask of an AMM curve is defined as the price levels at which the AMM will quote at least one unit of volume between those prices and the current fair price. Re-arranging the formulas defined in the prior [section](#volume-between-two-prices) yields the following: | ||||||
|
||||||
$$ | ||||||
p_{bb} = \bigg(\frac{L\cdot\sqrt{p_f}}{L + \Delta{P}\cdot \sqrt{p_f}}\bigg)^2 | ||||||
$$ | ||||||
|
||||||
$$ | ||||||
p_{ba} = \bigg(\frac{L\cdot\sqrt{p_f}}{L - \Delta{P}\cdot \sqrt{p_f}}\bigg)^2 | ||||||
$$ | ||||||
|
||||||
Where: | ||||||
|
||||||
- $P_{bb}$ is the calculated best bid | ||||||
- $P_{ba}$ is the calculated best ask | ||||||
- $p_{f}$ is the current fair price as calculated [here](#fair-price) | ||||||
- $L$ is the liquidity score for the current curve as calculated [here](#determining-volumes-and-prices) | ||||||
- $\Delta{P}$ is the smallest possible position supported by the markets position decimals, i.e. 1 unit of volume. | ||||||
|
||||||
Note, there is no need to handle the complexity where the fair price is currently on the lower curve but the best ask exists on the upper curve (or visa-versa) as by definition if the party has the smallest possible position $\Delta{P}$, their fair price should be such that between that price and the base price they quote at least $\Delta{P}$. In short: | ||||||
|
||||||
- if the fair price is currently on the lower curve, the best-ask will also be on the lower curve | ||||||
- if the fair price is currently on the upper curve, the best-bid will also be on the upper curve | ||||||
|
||||||
## Curve validity | ||||||
|
||||||
To prevent the protocol evaluating AMMs providing little liquidity to the network, the network will reject AMM submissions or amendments which cause an AMMs liquidity to be spread too thinly across it's entire range. | ||||||
|
||||||
If the number of ticks in the largest price range in which the AMM quotes zero volume is more than the parameter $allowedEmptyAmmLevels$, then the submission or amendment will be rejected. Note this parameter is defined on each market to allow different markets with varying volatility to be configured appropriately. | ||||||
|
||||||
- for the lower curve, this range is between the base price and the best bid price when the fair price is the base price. | ||||||
- for the upper curve, this range is between the upper bound and the best bid price when the fair price is the upper bound. | ||||||
|
||||||
The above definitions yield the following inequality which must be satisfied for both the upper and lower curve (providing they are defined) for the AMM to be valid. | ||||||
|
||||||
$$ | ||||||
n\cdot\Delta{p} \geq (p_u - p_{bb}) | ||||||
$$ | ||||||
|
||||||
$$ | ||||||
n\cdot\Delta{p} \geq {p_u} - (\frac{L\cdot\sqrt{p_u}}{L + \Delta{P}\cdot \sqrt{p_u}})^2 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$$ | ||||||
|
||||||
Where: | ||||||
|
||||||
- $\Delta{p}$ is the smallest price movement supported by the market's price decimals and tick size | ||||||
- $\Delta{P}$ is the smallest position size supported by the market's position decimals | ||||||
- $n$ is the market parameter $allowedEmptyAmmLevels$ | ||||||
- $L$ is the liquidity score for the relevant curve | ||||||
- $p_u$ is the upper price (the base price for the lower curve and the upper bound for the upper curve) | ||||||
|
||||||
Note, if the market parameter $allowedEmptyAmmLevels$ is updated via governance all existing pools that would no longer satisfy the inequality **must not** be cancelled. Amends to these pools should be evaluated and rejected if necessary and any cancellations should be accepted. | ||||||
|
||||||
## Determining Liquidity Contribution | ||||||
|
||||||
The provided liquidity from an AMM commitment must be determined for two reasons. Firstly to decide instantaneous distribution of liquidity fees between the various liquidity types and secondly to calculate a virtual liquidity commitment amount for assigning AMM users with an ELS value. This will be used for determining the distribution of ELS-eligible fees on a market along with voting weight in market change proposals. | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.