Hi
I am currently testing over the UI how to add and remove liquidity for Uniswap or Pancakeswap fork.
For some reason I am getting an error for tokens which has tokenomics or supporting fees:
Fail with error '_safeTransfer: TRANSFER_FAILED'
Which comes from UnisswapV2Pair Contract:
function _safeTransfer(address token, address to, uint value) private {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
}
The function I call is:
removeLiquidity = async (liquidityAmount: any) => {
const deadline = Math.floor(Date.now() / 1000) + 60 * 20;
try {
const tx1 = await this.state.Pair.approve(
this.state.router.address,
liquidityAmount,
{
from: this.state.account,
...this.overrides,
}
);
await tx1.wait();
const tx2 = await this.state.router.removeLiquidity(
this.state.tokenAData.address,
this.state.tokenBData.address,
liquidityAmount,
0,
0,
this.state.account,
deadline,
{
from: this.state.account,
...this.overrides,
}
);
await tx1.wait();
return true;
} catch (e: any) {
console.log(e);
console.log('Could not remove liquidity');
this.setState({
loading: false,
});
}
};
I tried also with
removeLiquidityETHSupportingFeeOnTransferTokens
but same issue. Any idea what the problem could be?