Bladeren bron

计算初步测试成功,环境问题。。。。

龚成明 3 jaren geleden
bovenliggende
commit
4439f7afba
7 gewijzigde bestanden met toevoegingen van 60 en 10 verwijderingen
  1. 1 1
      README.md
  2. 36 0
      abi/Calc_ABI.ts
  3. 2 1
      config/contracts.ts
  4. 1 1
      contracts/Calc.sol
  5. 3 4
      scripts/deployCalc.ts
  6. 14 0
      test/CalcTest.ts
  7. 3 3
      test/Univ3Test.ts

+ 1 - 1
README.md

@@ -13,5 +13,5 @@ npx hardhat help
 npx hardhat test
 REPORT_GAS=true npx hardhat test
 npx hardhat node
-npx hardhat run scripts/deploy.ts
+npx hardhat run scripts/deployCalc.ts
 ```

+ 36 - 0
abi/Calc_ABI.ts

@@ -0,0 +1,36 @@
+export default [
+  {
+    "inputs": [
+      {
+        "internalType": "address",
+        "name": "tokenA",
+        "type": "address"
+      },
+      {
+        "internalType": "uint256",
+        "name": "amountA",
+        "type": "uint256"
+      },
+      {
+        "internalType": "address",
+        "name": "tokenB",
+        "type": "address"
+      },
+      {
+        "internalType": "uint24",
+        "name": "fee",
+        "type": "uint24"
+      }
+    ],
+    "name": "getQuote",
+    "outputs": [
+      {
+        "internalType": "uint256",
+        "name": "amountB",
+        "type": "uint256"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  }
+]

+ 2 - 1
config/contracts.ts

@@ -4,5 +4,6 @@ export default {
   USDT: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
   UNIV3: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
   UNIV3_FACTORY: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
-  ZERO: '0x0000000000000000000000000000000000000000'
+  ZERO: '0x0000000000000000000000000000000000000000',
+  CALC: '0x72fe77C67a8028cf9A14422062A3F718C4151EF1'
 }

+ 1 - 1
contracts/CalcTest.sol → contracts/Calc.sol

@@ -6,7 +6,7 @@ import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
 
 import 'hardhat/console.sol';
 
-contract CalcTest {
+contract Calc {
     IUniswapV3Factory factory = IUniswapV3Factory(0x1F98431c8aD98523631AE4a59f267346ea31F984);
 
     function getQuote(address tokenA, uint amountA, address tokenB, uint24 fee) public view returns (uint256 amountB) {

+ 3 - 4
scripts/deploy.ts → scripts/deployCalc.ts

@@ -1,13 +1,12 @@
 import { ethers } from "hardhat";
 
 async function main() {
-  const CalcTest = await ethers.getContractFactory("CalcTest");
-  const calc = await CalcTest.deploy();
+  const Calc = await ethers.getContractFactory("Calc");
+  const calc = await Calc.deploy();
 
   await calc.deployed();
 
-  console.log(`Lock deployed to ${calc.address}`);
-  //0xA56768f700434321765a373B040c17BBB25eB803
+  console.log(`Calc deployed to ${calc.address}`);
 }
 
 // We recommend this pattern to be able to use async/await everywhere

+ 14 - 0
test/CalcTest.ts

@@ -0,0 +1,14 @@
+import {web3} from "hardhat";
+import fee from "../config/fee";
+import contracts from "../config/contracts";
+
+describe('Calc test', () => {
+  it('Univ3 swap test', async () => {
+    const Calc_ABI = require('../abi/Calc_ABI').default
+
+    let calc = new web3.eth.Contract(Calc_ABI, contracts.CALC)
+
+    // 1450752979
+    console.log(await calc.methods.getQuote(contracts.WETH, 1e15, contracts.HEX, fee._30_per_10000).call())
+  })
+})

+ 3 - 3
test/Univ3Test.ts

@@ -38,10 +38,10 @@ describe('Uniswap v3 test', () => {
             gasLimit: 1e6
         }
 
-        let amountIn = 1e9
+        let amountIn = 1e15
         let amountOutMin = 1
         let deadline = parseInt(String(new Date().getTime() / 1e3)) + 60
-        let path = [contracts.WETH, fee._5_per_10000, contracts.USDT]
+        let path = [contracts.WETH, fee._30_per_10000, contracts.HEX]
         let to = deployer.address
 
         let params = {
@@ -56,4 +56,4 @@ describe('Uniswap v3 test', () => {
             .exactInput(params)
             .send(rawTx).then(console.log)
     })
-})
+})