Univ3Test.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. let inAmount = 1e15.toString()
  7. it('Univ3 swap test', async () => {
  8. const UNIV3_ABI = require('../abi/UNIV3_ROUTER_ABI.json')
  9. let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
  10. let rawTx = {
  11. from: deployer.address,
  12. nonce: await web3.eth.getTransactionCount(deployer.address),
  13. gasPrice: web3.utils.toWei('2', 'gwei'),
  14. gasLimit: 1_000_000
  15. }
  16. let amountIn = inAmount
  17. let amountOutMin = 1
  18. let path = [contracts.WETH, contracts.HEX]
  19. let to = deployer.address
  20. await univ3_contract.methods
  21. .swapExactTokensForTokens(amountIn, amountOutMin, path, to)
  22. .send(rawTx).then(console.log)
  23. })
  24. it('Univ3 `exactInput` test', async () => {
  25. const UNIV3_ABI = require('../abi/UNIV3_ROUTER_ABI.json')
  26. let univ3_contract = new web3.eth.Contract(UNIV3_ABI, contracts.UNIV3)
  27. let rawTx = {
  28. from: deployer.address,
  29. nonce: await web3.eth.getTransactionCount(deployer.address),
  30. gasPrice: web3.utils.toWei('2', 'gwei'),
  31. gasLimit: 1e6
  32. }
  33. let amountOutMin = 1
  34. let deadline = parseInt(String(new Date().getTime() / 1e3)) + 60
  35. let path = [contracts.WETH, fee._30_per_10000, contracts.USDT]
  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: inAmount,
  42. amountOutMinimum: amountOutMin
  43. }
  44. await univ3_contract.methods
  45. .exactInput(params)
  46. .send(rawTx).then(console.log)
  47. })
  48. it('Quoter calc test', async () => {
  49. const QUOTER_ABI = require('../abi/QUOTER_ABI.json')
  50. let quoter = new web3.eth.Contract(QUOTER_ABI, contracts.QUOTER)
  51. await quoter.methods
  52. .quoteExactInputSingle(contracts.WETH, contracts.USDT, fee._30_per_10000, inAmount, 0)
  53. .call().then(console.log)
  54. })
  55. it('Univ3 swap test', async () => {
  56. const FLASH_ABI = require('../artifacts/contracts/Flash.sol').abi
  57. let flash = new web3.eth.Contract(FLASH_ABI, contracts.FLASH)
  58. let rawTx = {
  59. from: deployer.address,
  60. nonce: await web3.eth.getTransactionCount(deployer.address),
  61. gasPrice: web3.utils.toWei('2', 'gwei'),
  62. gasLimit: 1e6
  63. }
  64. const WETH_USDT_POOL_CONTRACT = '0x4e68Ccd3E89f51C3074ca5072bbAC773960dFa36'
  65. await flash.methods
  66. .swap()
  67. .send(rawTx).then(console.log)
  68. })
  69. })