feat: v1 quote interface proposal#837
Conversation
dianacarvalho1
left a comment
There was a problem hiding this comment.
Thank you @kayibal ! This looks really good! ✨ I only have small suggestions. And another concern: we are changing how we "call" things (get_amount_out -> quote for example). We will need to update all of our docs to match the new nomenclature and make sure we are consistent everywhere.
| models::{ | ||
| blockchain::Transaction, Address, AttrStoreKey, Balance, Chain, ChangeType, ComponentId, | ||
| MergeError, StoreVal, TxHash, | ||
| blockchain::Transaction, token::Token, Address, AttrStoreKey, Balance, Chain, ChangeType, |
There was a problem hiding this comment.
Address is just Bytes right?
There was a problem hiding this comment.
and Bytes that is already defined in tycho-common 😬 do we need so many aliases? (this always confused me tbh)
There was a problem hiding this comment.
I like the aliases - they make it clear what the Bytes represent. Seeing a signature that returns -> (Bytes, Bytes, Bytes) means I need to read docs or the code to understand what's happening and slows me down. Seeing -> (Address, StoreKey, TransactionHash) makes it easy to understand at a glance.
There was a problem hiding this comment.
my dislike comes from the fact that then tycho-common is used in many many places and then there it gets really confusing what alias/type too use 😕
There was a problem hiding this comment.
I would like to raise this discussion again please.
If you still think this is nice then I would advocate to do a full clean of all of Tycho crates and make sure we use these aliases everywhere consistently (because that is not the case atm)
There was a problem hiding this comment.
Are you suggesting to do this as part of this PR? I am not necessarily against it, I just don't think this is worth blocking merging this right now.
There was a problem hiding this comment.
no no, I'm not suggesting doing that as a part of this PR. I'm raising the discussion and if that is decision, we can do this as a part of the v1 interfaces epic
louise-poole
left a comment
There was a problem hiding this comment.
I really like this! Feels a lot more advanced, cleaner and useful in a broader sense. All my comments are minor/doc related.
| /// These constraints allow sophisticated trading strategies by limiting swaps | ||
| /// based on price thresholds or targeting specific pool states. | ||
| #[derive(Debug, Clone, PartialEq)] | ||
| pub enum SwapConstraint { |
There was a problem hiding this comment.
How do you see this being implemented? I really wouldn't want to make integrations more complex than they are right now. Will we have a default implementation on the trait?
Maybe we should add a way to notify which constraint is supported and which one isn't?
There was a problem hiding this comment.
This is basically ported almost 1-1 from ProtocolSim trait. There is a default implementation for it afaik yes.
| /// The tolerance as a fraction to be applied on top of (increasing) the trade | ||
| /// limit price, raising the acceptance threshold. This is used to loosen the acceptance | ||
| /// criteria for implementations of this method, but will never allow violating the trade | ||
| /// limit price itself. | ||
| tolerance: f64, |
There was a problem hiding this comment.
I didn't get this, how can it loosen the acceptance criteria without allowing violating the limit?
This is used to loosen the acceptance criteria for implementations of this method, but will never allow violating the trade limit price itself.
| /// | ||
| /// Implementations should be thread-safe and support cloning for parallel simulations. | ||
| #[typetag::serde(tag = "protocol", content = "state")] | ||
| pub trait SwapQuoter: fmt::Debug + Send + Sync + 'static { |
There was a problem hiding this comment.
So all these are mandatory to implement right? I wonder if we should allow for some optional functions - for example fee?
The motivation is that currently we would be blocking (or hacking) an integration if it doesn't check all these, maybe we would like to add a little flexibility here too
There was a problem hiding this comment.
I think atm you'd need to error if fee is not available. We can consider this though, what exactly would you classify as optional and what not?
1abe356 to
94cf052
Compare
dianacarvalho1
left a comment
There was a problem hiding this comment.
Thank you @kayibal ! This looks good to me ✅
Main changes are: - The use of parameter and return type structs, this allows us to upgrade the interface without breaking it. - Linked component with the state. This requires each state now to hold a reference to the component that describes it. This was requested a lot and indeed makes sense. - Removal of as_any and as_any_mut. These aren't really required except for testing. Added the SwapQuoterTestExt instead which can hold methods that are only used in tests.
94cf052 to
feade46
Compare
feade46 to
bccd3a4
Compare
## [0.144.0](0.143.1...0.144.0) (2026-02-20) ### Features * Blanket implementation for legacy trait ([f54ae4b](f54ae4b)) * Blanket implementation query_pool_swap ([bd79bca](bd79bca)) * expose parameters ([3f9a838](3f9a838)) * Generic protocol component to dto conversion. ([1d3c826](1d3c826)) * get_token helper on ProtocolComponent ([0a7b006](0a7b006)) * implement default quotable pairs ([ade05b6](ade05b6)) * include tokens in protocol component ([9256a41](9256a41)) * Misc fixes to SwapQuoter & docs ([bccd3a4](bccd3a4)) * quotable pair returns full tokens ([cc7ade4](cc7ade4)) * Simplify transition error struct ([713421d](713421d)) * Support for fixed out quotes ([79098ab](79098ab)) * v1 quote interface proposal ([3952d29](3952d29)) * v1 quote interface proposal ([#837](#837)) ([a448aae](a448aae)) ### Bug Fixes * delta_transition error type ([21b3d53](21b3d53)) * force include new state in get_amount_out ([4e76170](4e76170)) * post rebase fixes ([e0123f8](e0123f8))
|
This PR is included in version 0.144.0 🎉 |
The interface is backwards compatible and allows adding new optional parameters without breaking backwards compatibility.
The evolution of the VM Solidity interface please going forward is detailed here: https://propeller-heads.atlassian.net/wiki/spaces/GEN/pages/3406528516/Tycho-Simulation+API+Evolution+Guidelines
Migration of UniswapV2 implementation can be seen here: propeller-heads/tycho-simulation#523
New proposed interface here: https://github.com/propeller-heads/tycho-indexer/blob/7ef585ce5e7f43899046ee33a09f86fdcb37a729/tycho-common/src/simulation/swap.rs
TLDR:
ResultContextstruct which can contain:ProtocolComponent<Arc<Token>>&Addressinstead of&Tokenquote()supports fixed in or fixed out, only clones state if requestedquotable_pairscomponentas_anyas_any_muteq(moved from core trait to new testing trait in case we need it)SwapQuoterautomatically implements ProtocolSim for backwards compatibility (with some limitations, the trait should be considered be deprecated though)