I wrote that contract :-D
It's a basic Safemoon fork that includes fixes for all of the issues found in the HashEx and CertiK audits. That plus there's a dev fee feature that taxes individual transactions so devs can earn something without having to do the traditional "team wallet" method of compensation that so many traders are weary of.
The whole reason behind the openTrading() function is that I didn't want certain "listing" bots to list the token before we were ready to launch. Other parts of the contract require the token's Uniswap pair address in order to enforce conditions designed to prevent "sniping" bots from buying too many tokens too early, but I couldn't create that pair address without those listing bots noticing. Those listing bots listen to any createPair() function calls made to the Uniswap factory contract. If I called createPair() in the constructor, which would create the pair as soon as the contract was deployed, then those bots would list the token as not sellable (which is accurate, there's no liquidity at that point), and that would scare off a lot of traders. If I used the Uniswap UI to add liquidity like normal (which also does a createPair() call), then I wouldn't be able to set the pair address in the contract, so the sniping bots would get in. I could have used a setPair() type of function that would be called after adding liquidity through the Uniswap UI, but that would create a window between adding liquidity and setting the pair address where the sniping bots could get in.
openTrading() seemed like the best solution to these problems. It creates the pair, then adds liquidity, then enables the anti-sniping bot protections, all in the same transaction. So the listing bots are happy, and no more window where the sniping bots can get in.
I didn't include any sanity checks (or instructions) for the parameters given to addLiquidityETH() because I didn't expect anyone else to use this code. It seems to have gained some popularity though.
The address(this).balance
in the addLiquidityETH() call refers to the ETH balance of the contract itself. That's used for the initial liquidity of the Uniswap pair, and it gets converted to WETH by addLiquidityETH(). The other half of the liquidity pair would be the ERC20 tokens themselves, which is what that balanceOf(address(this))
is referring to. owner()
in that line is used by Uniswap as the address that will receive the LP tokens that represent the pooled WETH/ERC20 tokens.
TLDR
You need to send the tokens and the ETH you plan on using for the initial liquidity to the contract itself. Once you do that, you should be able to call the openTrading() function. If something goes horribly wrong, you can use the manualsend() function to send the ETH from the contract to the first dev fee address. Also, that function can only be called by that first dev fee address, not the owner.
P.S.
The 4250000000 in the line _maxTxAmount = 4250000000 * 10**9;
sets the maximum amount of tokens you're allowed to buy to 4.25 billion. Our initial liquidity was 850,000,000,000 tokens (1 trillion total supply, 15% burned), so 4.25 billion would be 0.5%, which seemed like a low enough number that it would prevent anyone from becoming a whale too early. After a minute or so the limit was raised to 1%, then 10%, then 100% (disabling the limit).
Best Answer
Here's the
deposit
method:https://etherscan.io/token/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#writeContract#F5
After calling
deposit
method, the caller will receivedWETH
equal to theETH
amount paid to the contract.As usual, double-check and triple-check the contract is actually authentic.
How to interact with contract in ethers.js or web3.js should already be covered in their documentation.