I am coding a token where you can give the token price a range to be traded in.
Example: Initial token price is $10, range is $5. Token price can go as high as $15 and as low as $5
After each buy or sell, I call a function internally to check the reserves of the liquidity pair to calculate the price after the trade to see if a buyback or sell is needed to bring the price back into range.
This works perfectly when I test in a bsc mainnet fork on hardhat if I run the function as a public function to be called after the buy/sell to stabilize the price.
My error comes when I have the stabilize price function called internally after the transfer is done.
My revert string is the least helpful pancake swap message: ‘Pancake: TRANSFER_FAILED’
Checklist of things I have made sure of for this to work:
-
I have given the trading pair enough liquidity of BUSD/Token
-
I have approved the router to transfer busd and the token on behalf of the contract, from the contract
-
The contract has more enough busd and tokens to trade to stabilize the price within range
-
I am getting the correct values when I call getReserves()
Any help or suggestions would be appreciated