0

I'm very new to this, but I've managed to use the write function swapexacttotkensforeth directly in the browser on bscscan with the pcs router.

The issue is I can only perform a swap if the sum of the value of amountIn and -OutMin is within current market price. If I try to set a higher value in amountOutMin (like setting a limit order) the gas fees go way up to about 0.4bnb.

Ok, so this is "not allowed" apparently. But how does i.e. a bot manage to buy/sell way above current market price? In my mind they have to use the same write function "swapexact...", but some how they manage to buypass "blockage" that I encounter.

Does this make any sense.

Johnny
  • 1

1 Answers1

1

In Uniswap V2 and V3, the amountOutMin (for a exact input swap) or amountInMax (for an exact output swap) is a way to protect against the slippage, not to set limit order (ie in the same block as your swap, other transactions went before you and you end up with an unexpected token ratio/"price" - for instance, without an amountOutMin, say you'd like to buy 1ETH and send 4000DAI to do so, but the slippage drives eth price higher and you end up with 0.75ETH).

Uniswap V2 (and its clones, like Pancakeswap) is an automated market making contract, meaning you don't have an order book were you could set limit orders/place bids&asks, as you (as buyer) takes whatever price the AMM model gives you (Uniswap V3 is a bit particular in this aspect, but this is out of this question's scope).

See this for further info (official Uni V2 doc disappeared) : https://vomtom.at/how-to-use-uniswap-v2-as-a-developer/

DrGorilla.eth
  • 1,276
  • 8
  • 19
  • Thx for replying, I kinda get it. The exact swap function protects against getting a lower price fill. And I know it doesn't have an order book. But what I don't know is how, lets say a bot, is able to get i.e. a 50% higher price for its tokens while I can't. As I understand the AMM will only let me swap if I try to swap tokens at the current market price. If I try to get a higher price for a token then current market price it will just raise the gas value. So there is some kind a blockage in place so non-experts can't try to swap outside market price, without making an advanced script. – Johnny Nov 18 '21 at 20:00
  • Even with "an advanced script", no-one decide of a price (the automatic market maker does, following, for uniswap, the constant product curve -> every swap is made to maintain k constant and equal to x*y (excluding fees for clarity here)) – DrGorilla.eth Nov 18 '21 at 20:22