Last active
October 3, 2021 08:49
-
-
Save thanhson1085/e17fea10301ba029d2661e2eb53c56d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use ethers JS libray | |
// Required ERC20 Abi | |
// Required Uniswap/Pancakeswap Router Abi | |
// Required Provider wallet (who provide the liquidity) | |
// Required Buyer wallet (who want to buy TEST token) | |
// Read docs https://docs.uniswap.org/protocol/V2/reference/smart-contracts/router-02#addliquidityeth | |
// Read docs https://docs.uniswap.org/protocol/V2/reference/smart-contracts/router-02#swapexacttokensfortokens | |
console.log('addLiquidity TEST BUSD ...') | |
let amm = new ethers.Contract(config.get('AMMRouterAddress'), ammRouterAbi, provider) | |
await (await test.approve(config.get('AMMRouterAddress'), ethers.constants.MaxInt256, {nonce: nonce})).wait() | |
nonce += 1 | |
await (await busd.approve(config.get('AMMRouterAddress'), ethers.constants.MaxInt256, {nonce: nonce})).wait() | |
nonce += 1 | |
await (await amm.addLiquidity( | |
test.address, | |
busd.address, | |
ethers.utils.parseUnits('1000', 18), | |
ethers.utils.parseUnits('1000', 18), | |
ethers.utils.parseUnits('995', 18), | |
ethers.utils.parseUnits('995', 18), | |
provider.address, | |
Math.floor(new Date().getTime() / 1000) + 1000, | |
{nonce : nonce} | |
)).wait() | |
nonce += 1 | |
console.log('Buyer approve TEST ...') | |
let nonceBuyer = await buyer.getTransactionCount() | |
await (await test.connect(buyer).approve(config.get('AMMRouterAddress'), ethers.constants.MaxInt256, {nonce: nonceBuyer})).wait() | |
nonceBuyer += 1 | |
console.log('swapExactTokensForTokens Buyer swap TEST BUSD ...') | |
await (await amm.connect(buyer).swapExactTokensForTokens( | |
ethers.utils.parseUnits('10', 18), | |
ethers.utils.parseUnits('0', 18), | |
[ test.address, busd.address ], | |
buyer.address, | |
Math.floor(new Date().getTime() / 1000) + 1000, | |
{nonce : nonceBuyer} | |
)).wait() | |
nonceBuyer += 1 | |
nonce += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment