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

chore: Enable quoting with JIT orders liquidity #3082

Open
1 of 4 tasks
squadgazzz opened this issue Oct 24, 2024 · 2 comments
Open
1 of 4 tasks

chore: Enable quoting with JIT orders liquidity #3082

squadgazzz opened this issue Oct 24, 2024 · 2 comments
Assignees

Comments

@squadgazzz
Copy link
Contributor

squadgazzz commented Oct 24, 2024

Background

From #3027:

Currently CoW Protocol is in an awkward spot because it can not be the only source of liquidity yet. If all liquidity for a token rests in CoW Protocol's orderbook or some CoW AMM solvers would have no way of using it to quote a price for a given token.

Details

Previous attempts to implement it(#3033 and #3038) showed that this is a more involved change than anticipated, which also requires breaking API changes.

Currently, JIT orders get simulated on limit prices which means they will not get any surplus. Any surplus that can be generated by using a CoW AMM would, therefore, go to the user quote. In reality, the user order that comes out of the quote would be settled at a worse price because if it gets settled against a CoW AMM order surplus will have to be shared. So, the solvers should be able to tell us at which price things should get settled so that we can reason about distributing surplus even in quotes.

To fix that we should allow solvers to return pre-interactions, JIT orders and uniform clearing prices with their quote. That way solvers could quote with CoW AMMs (require JIT orders, pre-interactions and UCP). They could also index the orderbook and return resting limit orders as JIT orders.

Tasks

  • Update the driver's OpenAPI schema quote object with an enum with the old and new versions. Trade verifier returns error in case a new version is received.
Example
Quote:
  type: object
  properties:
    ..existing fields
Quote:
  oneOf:
    - $ref: "#/components/schemas/LegacyQuote"
    - $ref: "#/components/schemas/QuoteWithJitOrders"
  
LegacyQuote:
  type: object
  properties:
    ..existing fields

QuoteWithJitOrders:
  type: object
  properties:
    ..existing fields, where out_amount is replaced with the clearingPrices

    clearingPrices:
      type: array
      items:
        $ref: "#/components/schemas/Price"
      nullable: true
    jitOrders:
      type: array
      items:
        $ref: "#/components/schemas/JITOrder"
      nullable: true
    preInteractions:
      type: array
      items:
        $ref: "#/components/schemas/Interaction"
      nullable: true
  • In a separate PR, support the new quote version in the trade verifier. This would be properly tested only in the following task since it requires an e2e test with all the components that already support the feature.
  • Support the feature in the driver crate and start sending the new quote version. Implement e2e tests.
  • Remove the legacy quote version once all the external drivers have switched to the new API.
@squadgazzz squadgazzz changed the title chore: Enable JIT orders liquidity quoting chore: Enable quoting with JIT orders liquidity Oct 24, 2024
@MartinquaXD
Copy link
Contributor

nit: The new quote struct should have the uniform clearing prices instead of out_amount because the out_amount can be computed based on the prices. Other than that the plan looks good.
Also clearingPrices currently contains JITOrders in your suggested openapispec. But I assume this was more for demonstration purposes anyway.

@squadgazzz
Copy link
Contributor Author

The new quote struct should have the uniform clearing prices instead of out_amount because the out_amount can be computed based on the prices. Other than that the plan looks good.

Ah, right. Updated the example.

Also clearingPrices currently contains JITOrders in your suggested openapispec. But I assume this was more for demonstration purposes anyway.

Thanks, it was a typo, replaced with a Price object.

@squadgazzz squadgazzz self-assigned this Oct 24, 2024
squadgazzz added a commit that referenced this issue Oct 28, 2024
# Description
Closes task n1 from #3082.

Introduces a new version of the driver's `/quote` response in the API
schema in order to support a gradual migration to the quote with jit
orders making the changes backward compatible.

The driver changes are expected in the future PRs.

# Changes
> Update the driver's OpenAPI schema quote object with an enum with the
old and new versions. Trade verifier returns error in case a new version
is received.

## How to test
Existing tests. I was thinking about how to test it properly, but it
still requires e2e tests. So, it should be implemented in the next PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants