cowprotocol / cow-sdk

CoW protocol SDK
https://docs.cow.fi/cow-protocol/reference/sdks/cow-sdk
Other
31 stars 9 forks source link

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

Open devanoneth opened 9 months ago

devanoneth commented 9 months ago

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:

mfw78 commented 8 months ago

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 commented 7 months ago

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,
      })