-
Notifications
You must be signed in to change notification settings - Fork 487
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
Add ERC: Swap Order Routing Interface #712
base: master
Are you sure you want to change the base?
Conversation
Add ERC draft.
ERCS/erc-xxxx.md
Outdated
@@ -0,0 +1,262 @@ | |||
--- |
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.
--- | |
--- | |
eip: 7815 |
Assigning next sequential EIP/ERC/RIP number.
Numbers are assigned by editors & associates.
Please also update the filename.
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.
Thank you! Added.
The commit 60af23b (as a parent of f93f442) contains errors. |
Adding comma
--- | ||
eip: 7815 | ||
title: Swap Order Routing Interface | ||
description: An interface to simulate over swap liquidity. |
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.
I'd definitely drop "An interface", and maybe elaborate a bit on the content of the proposal. Perhaps:
description: An interface to simulate over swap liquidity. | |
description: Calculate price, swap tokens, retrieve trading limits, and query capabilities of liquidity pools. |
} | ||
``` | ||
|
||
Retrieves tokens for a given pool. This function is OPTIONAL. |
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.
Lost paragraph?
Here are common and important pieces of different routing algorithms, that inspired the design of this ERC: | ||
|
||
**Marginal Price**: The marginal price is the first derivative of the swap (amount out) function at a particular trade amount. The spot price, i.e. the current price, is the marginal price at trade amount 0. Having easy access to the marginal price at different trade amounts is essential to: | ||
|
||
- **Filter pools**: Pools with the best spot price have the best "instantaneous swap rate" for the token pair – making them a good candidate to include in a swap route. Second derivatives help judge even better which pool will provide the highest amount out for the swap (area under the swap curve). | ||
- **Determine swap amounts**: Marginal prices are also very good for sizing steps in iterative algorithms: Swap on the pool with the best marginal price until it reaches the marginal price of the second best pool, then split between both until you reach the marginal price of the third best pool etc. | ||
- **Curve interpolation**: Solvers can also use marginal prices to construct analytical interpolations of price functions that might not have simple analytical representations. Sample at multiple points and then build an interpolation. Analytical interpolation are useful to find analytical solutions to trade and split amounts – before using iterative approaches for fine-tuning the splits. | ||
- **Price after swap equivalence**: Besides discontinuous price functions and discrete gas costs, optimal solutions to route splitting must equalise the marginal prices of all pools included in the split. | ||
- **Convex optimisation**: Framing the optimal routing problem as a convex optimisation problem, which has gained more popularity recently, also relies on fast and accurate access to marginal prices. | ||
From these uses in different routing approaches we derived the need for: | ||
- **price**: A price function that can provide the spot price (marginal price at 0 amount in) and the marginal price *after* any trade amount. | ||
- **priceDerivative**: Derivatives of marginal prices, i.e. second derivatives of the swap function, are very useful for choosing pools, and for analytically interpolating the swap function. | ||
- **swap to price**: A direct analytical derivation of the trade amount needed to move the liquidity pool to a specific marginal price speeds up routers, by avoiding iterative queries to the price function. |
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.
This seems like general background information, or at least I'm having a hard time linking it to decisions made in your proposal. The rationale section should be used to explain why you made a particular technical choice within the specification. For example, you could explain why you chose an enum over a string for capabilities.
## Reference Implementation | ||
|
||
[TODO: Add reference implementation] |
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.
## Reference Implementation | |
[TODO: Add reference implementation] |
Just remove this for now.
|
||
None of the above methods are supposed to be called onchain. This interface is purely for indexing liquidity and efficiently simulating over it's properties to arrive at the most efficient trade amount during solving. | ||
|
||
It is an interface designed purely for reading. As such it presents to risk to the protocol. |
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.
It is an interface designed purely for reading. As such it presents to risk to the protocol. | |
It is an interface designed purely for reading. As such it presents no risk to the protocol. |
A standardized interface for on-chain swap liquidity. Defines methods to calculate price, swap tokens, retrieve trading limits, and query capabilities of liquidity pools – to simplify off-chain simulation over DEX liquidity for solvers and routers.