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

Cow SDK and live Orderbook API are not using the same API - type mismatches #187

Open
devanoneth opened this issue Dec 15, 2023 · 2 comments

Comments

@devanoneth
Copy link

SDK Version: 4.0.3

I've been following the beta docs, they're very nice but not sure if it's too early for that...
https://beta.docs.cow.fi/cow-protocol/reference/sdks/cow-sdk#sign-fetch-post-and-cancel-order

I noticed a few issue which I'd like to summarize here, if you agree with them maybe some of them can be split into separate issues.

The core issue is that a getQuote call with the following OrderQuoteRequest:

{
        sellToken: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
        buyToken: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        from: fromAddress,
        receiver: fromAddress,
        sellAmountBeforeFee: "100",
        kind: OrderQuoteSideKindSell.SELL,
        validFor: 120, 
      };

returns a Bad Request error rather than the expected quote OrderQuoteResponse. It seems as though the Orderbook API and this SDK are using completely different request bodies. At least that's what I notice when checking the live Orderbook swagger docs here: https://beta.docs.cow.fi/cow-protocol/reference/apis/orderbook.

Further to this, there are some type mismatch issues:

  • getQuote returns a OrderQuoteResponse, but signOrder expects an UnsignedOrder. The docs don't cover this conversion and you need to do an ugly typescript cast to get around it.
  • sendOrder expects a SigningScheme but signOrder returns an EcdsaSigningScheme, which again leads to an ugly typescript cast that the docs (linked) don't cover.
@mfw78
Copy link
Contributor

mfw78 commented Jan 3, 2024

Further to this, the OrderQuoteResponse has receiver as an optional value (may be null), however receiver is required for UnsignedOrder. The cow-sdk should adjust the UnsignedOrder such that receiver may also be null, and have signOrder inject the assumptions required.

@0xMazout
Copy link

0xMazout commented Feb 6, 2024

If some one encounter this problem and struggle to find an issue you have a solution here:

from this : https://github.com/cowprotocol/cow-sdk/blob/main/examples/cra/src/pages/quickStart/index.tsx

const { quote } = await orderBookApi.getQuote(quoteRequest)
     // Sign order
     const orderSigningResult = await OrderSigningUtils.signOrder({ ...quote, receiver: account }, chainId, signer)

     // Send order to the order-book
     const orderUid = await orderBookApi.sendOrder({
       ...quote,
       signature: orderSigningResult.signature,
       signingScheme: orderSigningResult.signingScheme as string as SigningScheme,
     })

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

3 participants