0

Based on the documentation here: https://0x.org/docs/api#request-1, I expected the 0xApi to obtain the exact amount of buyToken specified in the request, while applying the "slippageTolerance" to the sellAmount.

However the api / router seems to buy overbuy the buyToken returning roughly (1+slippagePercentage)*buyAmount instead of the actual specified amount.

Did I misunderstand the documentation or is this an error in the api / router ?

To reproduce you can run this test against a local mainnet fork : https://github.com/ckoopmann/0xApiExperiments/blob/main/test/index.ts

Which resulted in the following output for me (note that the api was queried for a fixed buyAmount of 100 sushi tokens with 5% slippage and ended up buying slightly more than 105 tokens: enter image description here

1 Answer 1

0

When using buyAmount in 0xAPI, the buyAmount is guaranteed as a minimum. Not all underlying liquidity sources provide buyExact functionality so buys are converted to sells.

The settlement will revert if boughtAmount < buyAmount. So it is often the case that when using buyAmount the trader buys more than expected.

Your Answer

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

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