Hey guys, with Safemoon we discovered a huge problem. They hardcoded Pancake v1 Router so all the people that are trying to fork Safemoon will run into the same problem. If you want to leave it hardcoded, then just change it with Pancake v2 Router address 0x10ED43C718714eb63d5aA57B78B54704E256024E.
Otherwise, if you want to avoid another time this situation... maybe with Pancake v3... you can add these lines of code.
//New Pancakeswap router version?
//No problem, just change it!
function setRouterAddress(address newRouter) public onlyOwner() {
//Thank you FreezyEx
IUniswapV2Router02 _newPancakeRouter = IUniswapV2Router02(newRouter);
uniswapV2Pair = IUniswapV2Factory(_newPancakeRouter.factory()).createPair(address(this), _newPancakeRouter.WETH());
uniswapV2Router = _newPancakeRouter;
}
I didn't test it, so let me know if there are any problems. I hope it works
Thanks for sharing @FreezyEx! Just edited your post’s title so it says more to someone scrolling through the guides, please be mindful of it next time!
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) public {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(uniswapV2Router), tokenAmount);
// add the liquidity
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
owner(),
block.timestamp
);
}
The error comes from the code above.
The pair is working as i can check for it but can’t add.
Even with the safemoon adding liquidity if the contract goes above 500000 * 10**6 * 10**9, it won’t work because then it tells me that there isn’t enough liquidity, although, this makes sense because i never added any. Or? Should it just work regardless and add tthe BNB/SAFEMOON>?
The token i am building isn’t a copy of safemoon but it does include a pricing floor similar to safemoon so i need to be able to provide liquidity on demand
I figured since theres works, i could just copy it but i ran into the same issues
A quick update. I was able to create a pair on 2 test tokens i made with createPair
I then used the same thing but with addLiquidityETH but i get the same error. I’ve tried from remix, truffle, genache, and web3 through module.exports but i still get the same error…
StatusError: Transaction: 0x000.... exited with an error (status 0)
Well yeah i’m trying to test on pancake testnet but i couldnt add liquidity so i grabbed safemoon since i new they’re doing it but same issues. so now im just using their file until i figure it out.
You able to addd liquidity to their testnet?
I was able to ddo it with 2 tokens i made together but not WBNB or BNB
Although i am having an issue in rinkbey adding liquidity manually into uniswap. I get
Something went wrong
RangeError: Division by zero
at Function.value (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:46528)
at t.get (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:31545)
at new t (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:31890)
at Function.t.fromFractionalAmount (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:32113)
at t.r.divide (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:32772)
at e.get (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:238684)
at e.t.priceOf (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:235699)
at https://app.uniswap.org/static/js/main.8d689671.chunk.js:1:525377
at Object.Eo [as useMemo] (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:1485830)
at t.useMemo (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:1405284)
I cant even launch safemoon on ropsten due to a gas issue. Unsure if it is remix or not.
This same error happens on kovan as well. If i use a normal erc20 like openzepp default, it works. I assume this may be some deflationary issue. although i can add liq on v3