skyfffire 3 жил өмнө
parent
commit
49ae841091

+ 1 - 0
contracts.ts → config/contracts.ts

@@ -1,6 +1,7 @@
 export default {
   WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
   HEX: '0x2b591e99afE9f32eAA6214f7B7629768c40Eeb39',
+  USDT: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
   UNIV3: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
   ZERO: '0x0000000000000000000000000000000000000000'
 }

+ 5 - 0
config/fee.ts

@@ -0,0 +1,5 @@
+export default {
+    _5_per_10000: 500,
+    _30_per_10000: 3000,
+    _100_per_10000: 10000,
+}

+ 35 - 3
test/BaseOperationTest.ts

@@ -1,7 +1,8 @@
-import { web3 } from "hardhat";
+import { web3 } from "hardhat"
+import { ethers } from "hardhat"
 import deployer from '../.secret'
-import contracts from '../contracts'
-import {default as WETH_ABI} from "../abi/WETH_ABI";
+import contracts from '../config/contracts'
+import fee from '../config/fee'
 
 describe('Base operation test', () => {
   it('Parse ether test', async () => {
@@ -82,4 +83,35 @@ describe('Base operation test', () => {
         .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)
+  })
 })

+ 1 - 0
utils/encodeUtils.ts

@@ -0,0 +1 @@
+export default class encode {}