Univ3Test.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {ethers, web3} from "hardhat";
  2. import contracts from "../config/contracts";
  3. import deployer from "../.secret";
  4. import fee from "../config/fee";
  5. describe('Uniswap v3 test', () => {
  6. it('Univ3 swap test', async () => {
  7. const UNIV3_ABI = require('../abi/UNIV3_ABI').default
  8. let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
  9. let rawTx = {
  10. from: deployer.address,
  11. nonce: await web3.eth.getTransactionCount(deployer.address),
  12. gasPrice: web3.utils.toWei('2', 'gwei'),
  13. gasLimit: 1_000_000
  14. }
  15. let amountIn = 1_000_000
  16. let amountOutMin = 1
  17. let path = [contracts.WETH, contracts.HEX]
  18. let to = deployer.address
  19. await univ3_contract.methods
  20. .swapExactTokensForTokens(amountIn, amountOutMin, path, to)
  21. .send(rawTx).then(console.log)
  22. })
  23. it('Univ3 `exactInput` test', async () => {
  24. const UNIV3_ABI = require('../abi/UNIV3_ABI').default
  25. let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
  26. let rawTx = {
  27. from: deployer.address,
  28. nonce: await web3.eth.getTransactionCount(deployer.address),
  29. gasPrice: web3.utils.toWei('2', 'gwei'),
  30. gasLimit: 1e6
  31. }
  32. let amountIn = 1e15
  33. let amountOutMin = 1
  34. let deadline = parseInt(String(new Date().getTime() / 1e3)) + 60
  35. let path = [contracts.WETH, fee._30_per_10000, contracts.HEX]
  36. let to = deployer.address
  37. let params = {
  38. path: ethers.utils.solidityPack(['address', 'uint24', 'address'], path),
  39. recipient: to,
  40. deadline: deadline,
  41. amountIn: amountIn,
  42. amountOutMinimum: amountOutMin
  43. }
  44. await univ3_contract.methods
  45. .exactInput(params)
  46. .send(rawTx).then(console.log)
  47. })
  48. })