Explorar el Código

信息合约已部署

龚成明 hace 3 años
padre
commit
5cad172313
Se han modificado 5 ficheros con 81 adiciones y 1 borrados
  1. 0 0
      abi/UNIV3_POSITION_MANAGER_ABI.json
  2. 1 1
      config/contracts.ts
  3. 48 0
      contracts/V3Tool.sol
  4. 20 0
      scripts/deployV3Tool.ts
  5. 12 0
      test/Univ3Test.ts

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
abi/UNIV3_POSITION_MANAGER_ABI.json


+ 1 - 1
config/contracts.ts

@@ -10,5 +10,5 @@ export default {
   CALC: '0x30c34b111121aCDb423eF2C0e39235Dc68a793A4',
   FLASH: '0x672746E54B6FB7Bf6748De46271b68B112B79a66',
   TOOLS_410_V2: '0x8c72ef5448274f9a79d2a5addb10374dc3f58f08',
-  TOOLS_410_V3: '0xDE93d2cd45b7E0056671A542FfB4343DFd67dA51'
+  TOOLS_V3: '0x5261aD5CB71fE1A37a3722c40E93a80e84f62613'
 }

+ 48 - 0
contracts/V3Tool.sol

@@ -0,0 +1,48 @@
+//SPDX-License-Identifier: Unlicense
+pragma solidity ^0.7.6;
+pragma abicoder v2;
+
+import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
+import '@uniswap/v3-periphery/contracts/NonfungiblePositionManager.sol';
+import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
+
+contract V3Tool {
+    NonfungiblePositionManager private positionManager;
+    IUniswapV3Factory private factory;
+
+    constructor(address payable _positionManager, address payable _factory) {
+        positionManager = NonfungiblePositionManager(_positionManager);
+        factory = IUniswapV3Factory(_factory);
+    }
+
+    struct PositionInfo {
+        address lp;
+        address token0;
+        string symbol0;
+        uint24 decimals0;
+        uint256 r0;
+        address token1;
+        string symbol1;
+        uint24 decimals1;
+        uint256 r1;
+        uint24 feei;
+    }
+
+    function getMoreInfo(address token0, address token1, uint24 fee) public view returns (
+        address lp,
+        string memory symbol0,
+        uint24 decimals0,
+        uint256 r0,
+        string memory symbol1,
+        uint24 decimals1,
+        uint256 r1
+    ) {
+        ERC20 token0Obj = ERC20(token0);
+        ERC20 token1Obj = ERC20(token1);
+
+        address lp = factory.getPool(token0, token1, fee);
+
+        return (lp, token0Obj.symbol(), token0Obj.decimals(), token0Obj.balanceOf(lp),
+        token1Obj.symbol(), token1Obj.decimals(), token1Obj.balanceOf(lp));
+    }
+}

+ 20 - 0
scripts/deployV3Tool.ts

@@ -0,0 +1,20 @@
+import { ethers } from "hardhat";
+import contracts from "../config/contracts";
+
+async function main() {
+  const contractName = 'V3Tool'
+
+  const Contract = await ethers.getContractFactory(contractName);
+  console.log('deploying...')
+  const contract = await Contract.deploy(contracts.UNIV3_POSITION, contracts.UNIV3_FACTORY);
+  console.log(`${ contractName } deployed, confirm...`)
+  await contract.deployed();
+  console.log(`${ contractName } deployed to ${contract.address}`);
+}
+
+// We recommend this pattern to be able to use async/await everywhere
+// and properly handle errors.
+main().catch((error) => {
+  console.error(error);
+  process.exitCode = 1;
+});

+ 12 - 0
test/Univ3Test.ts

@@ -67,4 +67,16 @@ describe('Uniswap v3 test', () => {
       .quoteExactInputSingle(contracts.WETH, contracts.USDT, fee._30_per_10000, inAmount, 0)
       .call().then(console.log)
   })
+
+  it('V3 tool test', async () => {
+    const TOOL_V3_ABI = require('../artifacts/contracts/V3Tool.sol/V3Tool.json').abi
+
+    let v3_tool = new web3.eth.Contract(TOOL_V3_ABI, contracts.TOOLS_V3)
+
+    const rst = await v3_tool.methods
+        .getMoreInfo(contracts.WETH, contracts.USDT, fee._30_per_10000)
+        .call()
+
+    console.log(JSON.stringify(rst))
+  })
 })

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio