0

The token that I am trading is a token pair that is deployed on the pancakeswap V2 pool. However, the token that I am dealing with includes token tax which triggers the STF error when other token pairs work perfectly. I have made sure that the pancakeswap router has enough approval (set to maxuint256) and that the swapping account has enough tokens for the token swap as well as gas fee.

import {
  SmartRouter,
} from '@pancakeswap/smart-router/evm';
    // deadline is 20 minutes from now
    const deadline = Math.floor(Date.now() / 1000) + 60 * 20;

    // create swap options
    const swapOption: SwapOptions = {
            slippageTolerance: slippage
            recipient,
            deadlineOrPreviousBlockhash: deadline,
          };

    const calldata = SwapRouter.swapCallParameters(trade, swapOption);

    return calldata;

I have used the swap call parameters from the swap router to obtain the swap calldata that is included in a raw tx object and send with ethers.js such as below

const tx = {
        to: pancakeV3Routers,
        data: calldata,
        value: value,
        gasPrice: parseUnits(swap.gasPrice, 'gwei'),
        gasLimit: Number(swap.trade.estimatedGas),
      };

const voidSigner = new ethers.VoidSigner(walletPublicKey, provider);
      await voidSigner.estimateGas(tx);
const result = await item.wallet.sendTransaction(tx);

The STF error is almost always caught during the estimate gas step, and even if it is commented away, a transaction that fails with STF will show in bscscan.

The weird thing is that I manage to produce a call data that is slightly different in terms of original hex but have the same decoded input. The two decoded hex data provided below is compared between the calldata from my function and the calldata copied from the exact same trade through the pancakeswap.finance dapp.

PS: The function is called by wrapping the pancakeswap v2 contract call - swapExactTokensForTokens within a multicall(bytes[], uint256) pancakeswap v3 contract call.

DECODED HEX DATA 1 (my function)
[
    {
        "type": "BigNumber",
        "hex": "0x3635c9adc5dea00000" // amount in
    },
    {
        "type": "BigNumber",
        "hex": "0x14a95b5476bc" // min amount out
    },
    [
        "0x...",
        "0x..." 
    ],            // path
    "0x..." // recipient
]

DECODED HEX DATA 2 (pancake dapp)
[
    {
        "type": "BigNumber",
        "hex": "0x3635c9adc5dea00000" // amount in
    },
    {
        "type": "BigNumber",
        "hex": "0x14a95b5476bc" // min amount out
    },
    [
        "0x...",
        "0x..." 
    ],         // path
    "0x..." // recipient
]
Jasper
  • 1
  • 1

0 Answers0