0

Does the 0x API correctly determine a sellAmount when given a buyAmount and a specific slippage?

In the documentation is says the following about the slippage parameter

(Optional) The maximum acceptable slippage of the buyToken amount if sellAmount is provided; The maximum acceptable slippage of the sellAmount amount if buyAmount is provided. E.g 0.03 for 3% slippage allowed.

But both of these /swap/v1/quote requests produce the same takerAmount even with very different slippage.

slippage set to 0.1

{
  "buyToken": "0xfa5047c9c78b8877af97bdcb85db743fd7313d4a",
  "sellToken": "0x7ff4169a6b5122b664c51c95727d87750ec07c84",
  "slippagePercentage": 0.1,
  "skipValidation": "true",
  "intentOnFilling": "true",
  "buyAmount": 1000000000000000000000
}

slippage set to 0.5

{
  "buyToken": "0xfa5047c9c78b8877af97bdcb85db743fd7313d4a",
  "sellToken": "0x7ff4169a6b5122b664c51c95727d87750ec07c84",
  "slippagePercentage": 0.5,
  "skipValidation": "true",
  "intentOnFilling": "true",
  "buyAmount": 1000000000000000000000
}

API response

{
  "makerToken": "0xfa5047c9c78b8877af97bdcb85db743fd7313d4a",
  "takerToken": "0x7ff4169a6b5122b664c51c95727d87750ec07c84",
  "makerAmount": "1000000000000000000000",
  "takerAmount": "41002212925764457213198",
  "fillData": {
    "tokenAddressPath": [
      "0x7ff4169a6b5122b664c51c95727d87750ec07c84",
      "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "0xfa5047c9c78b8877af97bdcb85db743fd7313d4a"
    ],
    "router": "0xf164fc0ec4e93095b804a4795bbe1e041497b92a"
  },
  "source": "Uniswap_V2",
  "sourcePathId": "0x1cf4a7984db8f5cc1ec4dccfeae82934796000f1cc836d50a0bdbd86ec264f5e",
  "type": 0
}

1 Answer 1

0

The orders field in the response is mostly informational. They're not even fillable anywhere. The data field should have the actual sell amount adjusted for slippage (takerAmount) encoded as part of the calldata.

1
  • so where in the API response can I see the amount that is going into the trade? as set by slippage?
    – Griffin
    Apr 22, 2022 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.