|
|
@@ -4,85 +4,67 @@ import deployer from "../.secret";
|
|
|
import fee from "../config/fee";
|
|
|
|
|
|
describe('Uniswap v3 test', () => {
|
|
|
- let inAmount = 1e15.toString()
|
|
|
-
|
|
|
- it('Univ3 swap test', async () => {
|
|
|
- const UNIV3_ABI = require('../abi/UNIV3_ROUTER_ABI.json')
|
|
|
-
|
|
|
- let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
|
|
|
-
|
|
|
- let rawTx = {
|
|
|
- from: deployer.address,
|
|
|
- nonce: await web3.eth.getTransactionCount(deployer.address),
|
|
|
- gasPrice: web3.utils.toWei('2', 'gwei'),
|
|
|
- gasLimit: 1_000_000
|
|
|
- }
|
|
|
-
|
|
|
- let amountIn = inAmount
|
|
|
- let amountOutMin = 1
|
|
|
- let path = [contracts.WETH, contracts.HEX]
|
|
|
- let to = deployer.address
|
|
|
-
|
|
|
- await univ3_contract.methods
|
|
|
- .swapExactTokensForTokens(amountIn, amountOutMin, path, to)
|
|
|
- .send(rawTx).then(console.log)
|
|
|
- })
|
|
|
-
|
|
|
- it('Univ3 `exactInput` test', async () => {
|
|
|
- const UNIV3_ABI = require('../abi/UNIV3_ROUTER_ABI.json')
|
|
|
-
|
|
|
- let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
|
|
|
-
|
|
|
- let rawTx = {
|
|
|
- from: deployer.address,
|
|
|
- nonce: await web3.eth.getTransactionCount(deployer.address),
|
|
|
- gasPrice: web3.utils.toWei('2', 'gwei'),
|
|
|
- gasLimit: 1e6
|
|
|
- }
|
|
|
-
|
|
|
- let amountOutMin = 1
|
|
|
- let deadline = parseInt(String(new Date().getTime() / 1e3)) + 60
|
|
|
- let path = [contracts.WETH, fee._30_per_10000, contracts.USDT]
|
|
|
- let to = deployer.address
|
|
|
-
|
|
|
- let params = {
|
|
|
- path: ethers.utils.solidityPack(['address', 'uint24', 'address'], path),
|
|
|
- recipient: to,
|
|
|
- deadline: deadline,
|
|
|
- amountIn: inAmount,
|
|
|
- amountOutMinimum: amountOutMin
|
|
|
- }
|
|
|
-
|
|
|
- await univ3_contract.methods
|
|
|
- .exactInput(params)
|
|
|
- .send(rawTx).then(console.log)
|
|
|
- })
|
|
|
-
|
|
|
- it('Quoter calc test', async () => {
|
|
|
- const QUOTER_ABI = require('../abi/QUOTER_ABI.json')
|
|
|
-
|
|
|
- let quoter = new web3.eth.Contract(QUOTER_ABI, contracts.QUOTER)
|
|
|
-
|
|
|
- await quoter.methods
|
|
|
- .quoteExactInputSingle(contracts.WETH, contracts.USDT, fee._30_per_10000, inAmount, 0)
|
|
|
- .call().then(console.log)
|
|
|
- })
|
|
|
-
|
|
|
- it('Univ3 swap test', async () => {
|
|
|
- const FLASH_ABI = require('../artifacts/contracts/Flash.sol').abi
|
|
|
-
|
|
|
- let flash = new web3.eth.Contract(FLASH_ABI, contracts.FLASH)
|
|
|
-
|
|
|
- let rawTx = {
|
|
|
- from: deployer.address,
|
|
|
- nonce: await web3.eth.getTransactionCount(deployer.address),
|
|
|
- gasPrice: web3.utils.toWei('2', 'gwei'),
|
|
|
- gasLimit: 1e6
|
|
|
- }
|
|
|
-
|
|
|
- const WETH_USDT_POOL_CONTRACT = '0x4e68Ccd3E89f51C3074ca5072bbAC773960dFa36'
|
|
|
- await flash.methods
|
|
|
- .swap()
|
|
|
- .send(rawTx).then(console.log)
|
|
|
- })
|
|
|
+ let inAmount = 1e15.toString()
|
|
|
+
|
|
|
+ it('Univ3 swap test', async () => {
|
|
|
+ const UNIV3_ABI = require('../abi/UNIV3_ROUTER_ABI.json')
|
|
|
+
|
|
|
+ let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
|
|
|
+
|
|
|
+ let rawTx = {
|
|
|
+ from: deployer.address,
|
|
|
+ nonce: await web3.eth.getTransactionCount(deployer.address),
|
|
|
+ gasPrice: web3.utils.toWei('2', 'gwei'),
|
|
|
+ gasLimit: 1_000_000
|
|
|
+ }
|
|
|
+
|
|
|
+ let amountIn = inAmount
|
|
|
+ let amountOutMin = 1
|
|
|
+ let path = [contracts.WETH, contracts.HEX]
|
|
|
+ let to = deployer.address
|
|
|
+
|
|
|
+ await univ3_contract.methods
|
|
|
+ .swapExactTokensForTokens(amountIn, amountOutMin, path, to)
|
|
|
+ .send(rawTx).then(console.log)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('Univ3 `exactInput` test', async () => {
|
|
|
+ const UNIV3_ABI = require('../abi/UNIV3_ROUTER_ABI.json')
|
|
|
+
|
|
|
+ let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
|
|
|
+
|
|
|
+ let rawTx = {
|
|
|
+ from: deployer.address,
|
|
|
+ nonce: await web3.eth.getTransactionCount(deployer.address),
|
|
|
+ gasPrice: web3.utils.toWei('2', 'gwei'),
|
|
|
+ gasLimit: 1e6
|
|
|
+ }
|
|
|
+
|
|
|
+ let amountOutMin = 1
|
|
|
+ let deadline = parseInt(String(new Date().getTime() / 1e3)) + 60
|
|
|
+ let path = [contracts.WETH, fee._30_per_10000, contracts.USDT]
|
|
|
+ let to = deployer.address
|
|
|
+
|
|
|
+ let params = {
|
|
|
+ path: ethers.utils.solidityPack(['address', 'uint24', 'address'], path),
|
|
|
+ recipient: to,
|
|
|
+ deadline: deadline,
|
|
|
+ amountIn: inAmount,
|
|
|
+ amountOutMinimum: amountOutMin
|
|
|
+ }
|
|
|
+
|
|
|
+ await univ3_contract.methods
|
|
|
+ .exactInput(params)
|
|
|
+ .send(rawTx).then(console.log)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('Quoter calc test', async () => {
|
|
|
+ const QUOTER_ABI = require('../abi/QUOTER_ABI.json')
|
|
|
+
|
|
|
+ let quoter = new web3.eth.Contract(QUOTER_ABI, contracts.QUOTER)
|
|
|
+
|
|
|
+ await quoter.methods
|
|
|
+ .quoteExactInputSingle(contracts.WETH, contracts.USDT, fee._30_per_10000, inAmount, 0)
|
|
|
+ .call().then(console.log)
|
|
|
+ })
|
|
|
})
|