While using the 0xAPI I noticed that when executing "MultiHop" swaps against my local mainnet fork it sometimes obtains less than the specified buyAmount
without reverting.
Is this expected behaviour? I assumed that a trade with specified buyAmount
should revert if it obtains less than that amount, which seems to be true for all other types / liquidity sources.
More Detail:
This seems to be true only when I set slippagePercentage
> 0. Without slippagePercentage
the trade reverts with MultiplexFeature::_multiplexMultiHopSell/UNDERBOUGHT
.
However from the Api documentation I assumed that this slippagePercentage only affects the side of the trade that is not "fixed". (i.e. the sellAmount
in this case).
For example (at the time of posting this question) with this api query:
https://api.0x.org/swap/v1/quote?buyToken=0x6B3595068778DD592e39A122f4f5a5cF09C90fE2&sel lToken=0x6b175474e89094c44da98b954eedeac495271d0f&buyAmount=100000000000000000000000&slippagePercentage=0.2
I got the following "sources" in the api response:
[
{
proportion: '1',
intermediateToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
hops: [ 'Uniswap_V3', 'SushiSwap' ],
name: 'MultiHop'
}
]
But when executing the swap it only obtained 96468.20
instead of the specified 100000
Sushi Tokens.
The code to rerun this Test / Experiment can be found here: https://github.com/ckoopmann/0xApiExperiments/blob/main/test/index.ts