'swapExactTokensForTokens ignore amountOutMin parameter

In the token swap I am receiving less amount of the output token than that indicated in the parameter "amountOutMin". This is expected, because the token that I am swaping has a tax of 9%. What is not expected is that the transaction occurs. The transaction had to fail with "INSUFFICIENT_OUTPUT_AMOUNT". Since I am receiving less amount of tokens than the one indicated in the parameter "amountOutMin".

The token has 18 decimals (https://bscscan.com/token/0xf7469bad4e3da85b15b02a0dcfadb2c2d219a4b7)

Transaction: https://bscscan.com/tx/0xf8c1af25b432892f7c87ce57beacb938300ce7d6563cf17574ad8ec5e091ab85

Received: 3271.126023249240379059 tokens

amountOutMinParam: 3594640386952184892933 (18 decimal: 3594.640386952184892933)

Relevant code:

const OUTPUT_TOKEN = new Token(ChainId.MAINNET, OutputTokenAddr, OUT_TOKEN_DECIMALS);//OUT_TOKEN_DECIMALS == 18
pair = await Fetcher.fetchPairData(INPUT_TOKEN, OUTPUT_TOKEN, provider);
const route = await new Route([pair], INPUT_TOKEN);
const trade = await new Trade(route, new TokenAmount(INPUT_TOKEN, tradeAmount), TradeType.EXACT_INPUT);
const slippageTolerance = new Percent('1', '1000000');//Almost zero
const amountOutMin = trade.minimumAmountOut(slippageTolerance).raw;
const amountOutMinParam = ethers.BigNumber.from(amountOutMin.toString());//3594640386952184892933

const tx = await pancakeswap.swapExactTokensForTokens(amountInParam,
                        amountOutMinParam, path, to, deadline,                          
                        { gasLimit: ethers.utils.hexlify(300000), gasPrice: ethers.utils.parseUnits("5", "gwei")});

Transaction is done but "INSUFFICIENT_OUTPUT_AMOUNT" is expected.


Edit: the code seems correct. The transaction has occurred even when the amount of output is less than allowed. It seems that there is something important that I am not understanding.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source