Skip to content

feat: v1 quote interface proposal#837

Merged
kayibal merged 15 commits into
mainfrom
ah/v1-quote-interface
Feb 20, 2026
Merged

feat: v1 quote interface proposal#837
kayibal merged 15 commits into
mainfrom
ah/v1-quote-interface

Conversation

@kayibal
Copy link
Copy Markdown
Contributor

@kayibal kayibal commented Feb 2, 2026

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:

  • All methods take parameter structs
  • All methods return result structs
  • All return values are wrapped in Result
  • All parameter structs have a Context struct which can contain:
    • Already used protocols to adjust gas estimates
    • Next block information for twap protocols
    • etc.
  • Each SwapQuoter instances exposes access to component and tokens: ProtocolComponent<Arc<Token>>
  • All token references now use &Address instead of &Token
  • Limits allow expressing minimum amounts
  • quote() supports fixed in or fixed out, only clones state if requested
  • New methods:
    • quotable_pairs
    • component
  • Removed methods:
    • as_any
    • as_any_mut
    • eq (moved from core trait to new testing trait in case we need it)
  • Each struct implementing SwapQuoter automatically implements ProtocolSim for backwards compatibility (with some limitations, the trait should be considered be deprecated though)

Copy link
Copy Markdown
Contributor

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

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.

Comment thread tycho-common/src/models/protocol.rs Outdated
models::{
blockchain::Transaction, Address, AttrStoreKey, Balance, Chain, ChangeType, ComponentId,
MergeError, StoreVal, TxHash,
blockchain::Transaction, token::Token, Address, AttrStoreKey, Balance, Chain, ChangeType,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Address is just Bytes right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and Bytes that is already defined in tycho-common 😬 do we need so many aliases? (this always confused me tbh)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 😕

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread tycho-common/src/simulation/swap.rs
Comment thread tycho-common/src/simulation/swap.rs
Comment thread tycho-common/src/simulation/swap.rs Outdated
Comment thread tycho-common/src/simulation/swap.rs
Comment thread tycho-common/src/simulation/swap.rs Outdated
Comment thread tycho-common/src/simulation/swap.rs
Comment thread tycho-common/src/simulation/protocol_sim.rs
Copy link
Copy Markdown
Collaborator

@louise-poole louise-poole left a comment

Choose a reason for hiding this comment

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

I really like this! Feels a lot more advanced, cleaner and useful in a broader sense. All my comments are minor/doc related.

Comment thread tycho-common/src/simulation/swap.rs Outdated
Comment thread tycho-common/src/simulation/swap.rs Outdated
Comment thread tycho-common/src/simulation/swap.rs Outdated
Comment thread tycho-common/src/simulation/swap.rs
Comment thread tycho-common/src/simulation/swap.rs Outdated
Comment thread tycho-common/src/simulation/swap.rs
Comment thread tycho-common/src/simulation/swap.rs
Comment thread tycho-common/src/simulation/swap.rs Outdated
Comment thread tycho-common/src/simulation/swap.rs Outdated
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Tycho Feb 4, 2026
Comment thread tycho-common/Cargo.toml Outdated
Comment thread tycho-common/src/simulation/swap.rs
/// 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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

@kayibal kayibal Feb 19, 2026

Choose a reason for hiding this comment

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

This is basically ported almost 1-1 from ProtocolSim trait. There is a default implementation for it afaik yes.

Comment on lines +446 to +450
/// 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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

@kayibal kayibal force-pushed the ah/v1-quote-interface branch from 1abe356 to 94cf052 Compare February 19, 2026 21:03
Copy link
Copy Markdown
Contributor

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

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.
@kayibal kayibal force-pushed the ah/v1-quote-interface branch from 94cf052 to feade46 Compare February 20, 2026 16:45
@kayibal kayibal force-pushed the ah/v1-quote-interface branch from feade46 to bccd3a4 Compare February 20, 2026 21:48
@kayibal kayibal enabled auto-merge February 20, 2026 21:48
@kayibal kayibal merged commit a448aae into main Feb 20, 2026
6 checks passed
@kayibal kayibal deleted the ah/v1-quote-interface branch February 20, 2026 21:53
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Tycho Feb 20, 2026
propellerci Bot pushed a commit that referenced this pull request Feb 20, 2026
## [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))
@propellerci
Copy link
Copy Markdown
Contributor

propellerci Bot commented Feb 20, 2026

This PR is included in version 0.144.0 🎉

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants