| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import { web3 } from "hardhat"
- import { ethers } from "hardhat"
- import deployer from '../.secret'
- import contracts from '../config/contracts'
- import fee from '../config/fee'
- describe('Base operation test', () => {
- it('Parse ether test', async () => {
- console.log(web3.utils.toWei('1', 'gwei'))
- })
- it('Get block number test', async () => {
- console.log(await web3.eth.getBlockNumber())
- })
- it('Get balance test', async () => {
- console.log(await web3.eth.getBalance(deployer.address))
- })
- it('Transfer test', async () => {
- let rawTx = {
- from: deployer.address,
- nonce: await web3.eth.getTransactionCount(deployer.address),
- gasPrice: web3.utils.toWei('2', 'gwei'),
- gasLimit: 1_000_000,
- to: contracts.ZERO,
- value: 1e9
- }
- await web3.eth.sendTransaction(rawTx).then(console.log)
- })
- it('Weth withdraw test', async () => {
- const WETH_ABI = require('../abi/WETH_ABI').default
- const WETH_ADDR = contracts.WETH
- let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
- // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
- let rawTx = {
- from: deployer.address,
- nonce: await web3.eth.getTransactionCount(deployer.address),
- gasPrice: web3.utils.toWei('2', 'gwei'),
- gasLimit: 1_000_000
- }
- await weth_contract.methods.withdraw(1e15).send(rawTx).then(console.log)
- })
- it ('Weth approve test', async () => {
- const WETH_ABI = require('../abi/WETH_ABI').default
- const WETH_ADDR = contracts.WETH
- let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
- // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
- let rawTx = {
- from: deployer.address,
- nonce: await web3.eth.getTransactionCount(deployer.address),
- gasPrice: web3.utils.toWei('2', 'gwei'),
- gasLimit: 1_000_000
- }
- await weth_contract.methods.approve(contracts.UNIV3, 1e18.toString()).send(rawTx).then(console.log)
- })
- it('Univ3 swap test', async () => {
- const UNIV3_ABI = require('../abi/UNIV3_ABI').default
- 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 = 1_000_000
- 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_ABI').default
- 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 amountIn = 1e9
- let amountOutMin = 1
- let deadline = parseInt(String(new Date().getTime() / 1e3))
- let path = [contracts.WETH, fee._5_per_10000, contracts.USDT]
- let to = deployer.address
- let params = {
- path: ethers.utils.solidityPack(['address', 'uint24', 'address'], path),
- recipient: to,
- deadline: deadline,
- amountIn: amountIn,
- amountOutMinimum: amountOutMin
- }
- await univ3_contract.methods
- .exactInput(params)
- .send(rawTx).then(console.log)
- })
- })
|