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

Add ERC: Swap Order Routing Interface #712

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Haikane
Copy link

@Haikane Haikane commented Nov 9, 2024

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.

@eip-review-bot
Copy link
Collaborator

eip-review-bot commented Nov 9, 2024

File ERCS/erc-7815.md

Requires 1 more reviewers from @g11tech, @SamWilsn, @xinbenlv

ERCS/erc-xxxx.md Outdated Show resolved Hide resolved
ERCS/erc-xxxx.md Outdated
@@ -0,0 +1,262 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
---
---
eip: 7815

Assigning next sequential EIP/ERC/RIP number.
Numbers are assigned by editors & associates.

Please also update the filename.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you! Added.

ERCS/erc-xxxx.md Outdated Show resolved Hide resolved
@eip-review-bot eip-review-bot changed the title Add ERC: Routing Interface Standard Add ERC: Swap Order Routing Interface Nov 10, 2024
@github-actions github-actions bot removed the w-ci label Nov 10, 2024
Copy link

The commit 60af23b (as a parent of f93f442) contains errors.
Please inspect the Run Summary for details.

@github-actions github-actions bot added the w-ci label Nov 10, 2024
@github-actions github-actions bot removed the w-ci label Nov 20, 2024
---
eip: 7815
title: Swap Order Routing Interface
description: An interface to simulate over swap liquidity.
Copy link
Collaborator

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:

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lost paragraph?

Comment on lines +218 to +230
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.
Copy link
Collaborator

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.

Comment on lines +246 to +248
## Reference Implementation

[TODO: Add reference implementation]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
## 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants