Unable to add liquidity to pancakeswap

I am trying to clone pancakeswap. After successfully deploying core, farm and periphery contracts, I tried to add liquidity to a pool. The pair was created successfully. Both were erc20 tokens. I tried to add liquidity using a script. Liquidity was successfully added to the pool 2 times but after than no matter how many times i changed the router and factory address and the token amounts it always gave me the same error. Please help me try to remove it and successfully add liquidity. My script and error is below

const Factory = artifacts.require('Factory.sol');
const Router = artifacts.require('Router.sol');
const Pair = artifacts.require('Pair.sol');
const Token1 = artifacts.require('token1.sol');
const Token2 = artifacts.require('token2.sol');

module.exports = async done => {
  try {
    //const [admin, _] = await web3.eth.getAccounts();
    const factory = await Factory.at('0x78A47245BC7BDaa0DB7c19b7B6116E1E11e9fE20');
    const router = await Router.at('0xE1672640636a56E2905B8a303224b65A605286CF');
    const token1 = await Token1.new();
    const token2 = await Token2.new();
    const pairAddress = await factory.createPair.call(token1.address, token2.address);
    const tx = await factory.createPair(token1.address, token2.address);
    await token1.approve(router.address, 10000);
    await token2.approve(router.address, 10000);
    await router.addLiquidity(
      token1.address,
      token2.address,
      9000,
      9000,
      10000,
      10000,
      'mymetamaskaddress',
      Math.floor(Date.now() / 1000) + 60 * 10
    );
    const pair = await Pair.at(pairAddress);
    const balance = await pair.balanceOf("0xe95745a8F4E3cDb1cF5bfFD4A94F0B249e99f489");
    console.log(`balance LP: ${balance.toString()}`);
  } catch (e) {
    console.log(e);
  }
  done();
}
``

**The Error:**

StatusError: Transaction: 0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f exited with an error (status 0). 
    at module.exports (D:\Blockchain\pancake\createpool\scripts\deploypool.js:18:18)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  tx: '0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f',
  receipt: {
    blockHash: '0xc4bea040096811e809c18216d85fc82813b60db9545d4e1bf6ab7c4dd344fe87',
    blockNumber: 8023495,
    contractAddress: null,
    cumulativeGasUsed: 699140,
    from: '0xe95745a8f4e3cdb1cf5bffd4a94f0b249e99f489',
    gasUsed: 29046,
    logs: [],
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    to: '0x7632ae832440032fb4ca93e56873a92a01b06e13',
    transactionHash: '0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f',
    transactionIndex: 2,
    rawLogs: []
  },
  reason: undefined,
  hijackedStack: 'StatusError: Transaction: 0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f exited with an error (status 0). \n' +
    '     Please check that the transaction:\n' +
    '     - satisfies all conditions set by Solidity `require` statements.\n' +
    '     - does not trigger a Solidity `revert` statement.\n' +
    '\n' +
    '    at Object.receipt (C:\\Users\\DELL\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\contract\\lib\\handlers.js:124:1)\n' +
    '    at runMicrotasks (<anonymous>)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:97:5)\n' +
    '    at Function.start (C:\\Users\\DELL\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\contract\\lib\\override.js:49:1)'
1 Like

Hey, welcome!

Sorry, I am not familiar with the BSC-Chain, maybe you should ask for help in their forum: Home | Binance Chain Forum

I am not sure the parameters of the function addLiquidity, I think it should be

await router.addLiquidity(
      token1.address,
      token2.address,
      90000,      // desiredA
      90000,      // desiredB
      10000,     // minA
      10000,     // minB
      'mymetamaskaddress',
      Math.floor(Date.now() / 1000) + 60 * 10
    );

That is minA should be less than(maybe can equal to) desiredA, the same for mintB and desiredB

1 Like