skyfffire 3 éve
szülő
commit
2b42a23ac9
5 módosított fájl, 276 hozzáadás és 121 törlés
  1. 250 69
      abi/410_V2_TOOLS.json
  2. 0 8
      config/router-list.json
  3. 1 0
      package.json
  4. 16 11
      scripts/lp/lpGenerateFromDb.ts
  5. 9 33
      test/BaseOperationTest.ts

+ 250 - 69
abi/410_V2_TOOLS.json

@@ -3,43 +3,78 @@
 		"inputs": [
 			{
 				"internalType": "address",
-				"name": "rounteAddr",
+				"name": "tokenIn",
+				"type": "address"
+			},
+			{
+				"internalType": "address",
+				"name": "tokenOut",
 				"type": "address"
+			},
+			{
+				"internalType": "uint24",
+				"name": "fee",
+				"type": "uint24"
+			},
+			{
+				"internalType": "uint256",
+				"name": "amountOut",
+				"type": "uint256"
+			},
+			{
+				"internalType": "uint160",
+				"name": "sqrtPriceLimitX96",
+				"type": "uint160"
 			}
 		],
-		"name": "fee_Cal",
+		"name": "getAmountInV3",
 		"outputs": [
 			{
 				"internalType": "uint256",
-				"name": "",
+				"name": "amountIn",
 				"type": "uint256"
 			}
 		],
-		"stateMutability": "view",
+		"stateMutability": "nonpayable",
 		"type": "function"
 	},
 	{
 		"inputs": [
 			{
 				"internalType": "address",
-				"name": "rounteAddr",
+				"name": "tokenIn",
 				"type": "address"
+			},
+			{
+				"internalType": "address",
+				"name": "tokenOut",
+				"type": "address"
+			},
+			{
+				"internalType": "uint24",
+				"name": "fee",
+				"type": "uint24"
+			},
+			{
+				"internalType": "uint256",
+				"name": "amountIn",
+				"type": "uint256"
+			},
+			{
+				"internalType": "uint160",
+				"name": "sqrtPriceLimitX96",
+				"type": "uint160"
 			}
 		],
-		"name": "feeCal1",
+		"name": "getAmountOutV3",
 		"outputs": [
 			{
 				"internalType": "uint256",
-				"name": "",
+				"name": "amountOut",
 				"type": "uint256"
-			},
-			{
-				"internalType": "address",
-				"name": "",
-				"type": "address"
 			}
 		],
-		"stateMutability": "view",
+		"stateMutability": "nonpayable",
 		"type": "function"
 	},
 	{
@@ -118,6 +153,35 @@
 		"stateMutability": "view",
 		"type": "function"
 	},
+	{
+		"inputs": [
+			{
+				"internalType": "address[]",
+				"name": "factoryAddr",
+				"type": "address[]"
+			},
+			{
+				"internalType": "address",
+				"name": "token0",
+				"type": "address"
+			},
+			{
+				"internalType": "address",
+				"name": "token1",
+				"type": "address"
+			}
+		],
+		"name": "getPairAddS",
+		"outputs": [
+			{
+				"internalType": "address[]",
+				"name": "pairAdds",
+				"type": "address[]"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
 	{
 		"inputs": [
 			{
@@ -134,9 +198,14 @@
 				"internalType": "address",
 				"name": "token1",
 				"type": "address"
+			},
+			{
+				"internalType": "bool",
+				"name": "stable",
+				"type": "bool"
 			}
 		],
-		"name": "getPairAdd",
+		"name": "getPairAddV1",
 		"outputs": [
 			{
 				"internalType": "address",
@@ -150,9 +219,9 @@
 	{
 		"inputs": [
 			{
-				"internalType": "address[]",
+				"internalType": "address",
 				"name": "factoryAddr",
-				"type": "address[]"
+				"type": "address"
 			},
 			{
 				"internalType": "address",
@@ -165,12 +234,12 @@
 				"type": "address"
 			}
 		],
-		"name": "getPairAddS",
+		"name": "getPairAddV2",
 		"outputs": [
 			{
-				"internalType": "address[]",
-				"name": "pairAdds",
-				"type": "address[]"
+				"internalType": "address",
+				"name": "",
+				"type": "address"
 			}
 		],
 		"stateMutability": "view",
@@ -187,14 +256,14 @@
 		"name": "getPairBalance",
 		"outputs": [
 			{
-				"internalType": "uint256",
+				"internalType": "uint112",
 				"name": "amount0",
-				"type": "uint256"
+				"type": "uint112"
 			},
 			{
-				"internalType": "uint256",
+				"internalType": "uint112",
 				"name": "amount1",
-				"type": "uint256"
+				"type": "uint112"
 			}
 		],
 		"stateMutability": "view",
@@ -204,7 +273,7 @@
 		"inputs": [
 			{
 				"internalType": "address",
-				"name": "rounteAddr",
+				"name": "factoryAddr",
 				"type": "address"
 			},
 			{
@@ -268,7 +337,7 @@
 		"inputs": [
 			{
 				"internalType": "address",
-				"name": "rounteAddr",
+				"name": "factoryAddr",
 				"type": "address"
 			},
 			{
@@ -339,49 +408,132 @@
 		"name": "getPairInfo",
 		"outputs": [
 			{
-				"internalType": "address",
-				"name": "",
-				"type": "address"
-			},
-			{
-				"internalType": "address",
-				"name": "",
-				"type": "address"
-			},
-			{
-				"internalType": "string",
-				"name": "",
-				"type": "string"
-			},
-			{
-				"internalType": "uint8",
-				"name": "",
-				"type": "uint8"
-			},
+				"components": [
+					{
+						"internalType": "address",
+						"name": "lp",
+						"type": "address"
+					},
+					{
+						"internalType": "address",
+						"name": "token0",
+						"type": "address"
+					},
+					{
+						"internalType": "string",
+						"name": "symbol0",
+						"type": "string"
+					},
+					{
+						"internalType": "uint8",
+						"name": "decimals0",
+						"type": "uint8"
+					},
+					{
+						"internalType": "uint256",
+						"name": "r0",
+						"type": "uint256"
+					},
+					{
+						"internalType": "address",
+						"name": "token1",
+						"type": "address"
+					},
+					{
+						"internalType": "string",
+						"name": "symbol1",
+						"type": "string"
+					},
+					{
+						"internalType": "uint8",
+						"name": "decimals1",
+						"type": "uint8"
+					},
+					{
+						"internalType": "uint256",
+						"name": "r1",
+						"type": "uint256"
+					},
+					{
+						"internalType": "uint24",
+						"name": "fee",
+						"type": "uint24"
+					}
+				],
+				"internalType": "struct dexInfoTools.PairInfo",
+				"name": "pairInfo",
+				"type": "tuple"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [
 			{
 				"internalType": "uint256",
-				"name": "",
+				"name": "id",
 				"type": "uint256"
-			},
-			{
-				"internalType": "address",
-				"name": "",
-				"type": "address"
-			},
-			{
-				"internalType": "string",
-				"name": "",
-				"type": "string"
-			},
-			{
-				"internalType": "uint8",
-				"name": "",
-				"type": "uint8"
-			},
+			}
+		],
+		"name": "getPairInfoV3",
+		"outputs": [
 			{
-				"internalType": "uint256",
-				"name": "",
-				"type": "uint256"
+				"components": [
+					{
+						"internalType": "address",
+						"name": "lp",
+						"type": "address"
+					},
+					{
+						"internalType": "address",
+						"name": "token0",
+						"type": "address"
+					},
+					{
+						"internalType": "string",
+						"name": "symbol0",
+						"type": "string"
+					},
+					{
+						"internalType": "uint8",
+						"name": "decimals0",
+						"type": "uint8"
+					},
+					{
+						"internalType": "uint256",
+						"name": "r0",
+						"type": "uint256"
+					},
+					{
+						"internalType": "address",
+						"name": "token1",
+						"type": "address"
+					},
+					{
+						"internalType": "string",
+						"name": "symbol1",
+						"type": "string"
+					},
+					{
+						"internalType": "uint8",
+						"name": "decimals1",
+						"type": "uint8"
+					},
+					{
+						"internalType": "uint256",
+						"name": "r1",
+						"type": "uint256"
+					},
+					{
+						"internalType": "uint24",
+						"name": "fee",
+						"type": "uint24"
+					}
+				],
+				"internalType": "struct dexInfoTools.PairInfo",
+				"name": "pairInfo",
+				"type": "tuple"
 			}
 		],
 		"stateMutability": "view",
@@ -398,14 +550,43 @@
 		"name": "getPairSBalance",
 		"outputs": [
 			{
-				"internalType": "uint256[]",
+				"internalType": "uint112[]",
 				"name": "amounts0",
-				"type": "uint256[]"
+				"type": "uint112[]"
 			},
 			{
-				"internalType": "uint256[]",
+				"internalType": "uint112[]",
 				"name": "amounts1",
-				"type": "uint256[]"
+				"type": "uint112[]"
+			}
+		],
+		"stateMutability": "view",
+		"type": "function"
+	},
+	{
+		"inputs": [
+			{
+				"internalType": "address",
+				"name": "tokenA",
+				"type": "address"
+			},
+			{
+				"internalType": "address",
+				"name": "tokenB",
+				"type": "address"
+			},
+			{
+				"internalType": "uint24",
+				"name": "fee",
+				"type": "uint24"
+			}
+		],
+		"name": "getPoolV3",
+		"outputs": [
+			{
+				"internalType": "address",
+				"name": "pool",
+				"type": "address"
 			}
 		],
 		"stateMutability": "view",

+ 0 - 8
config/router-list.json

@@ -1,12 +1,4 @@
 [
-  {
-    "name": "Soul",
-    "router": "0x0000000000000000000000000000000000000000",
-    "factory": "0x1120e150da9def6fe930f4feded18ef57c0ca7ef",
-    "fee": "3000",
-    "type": "univ2",
-    "chain": "ftm"
-  },
   {
     "name": "V1.Solidly",
     "router": "0x0000000000000000000000000000000000000000",

+ 1 - 0
package.json

@@ -3,6 +3,7 @@
     "speedTest": "hardhat run test/speed/Web3SpeedTest.ts",
     "requestTest": "hardhat run test/speed/RequestTest.ts",
     "lpGenerate": "hardhat run scripts/lp/lpGenerate.ts",
+    "lpGenerateFromDb": "hardhat run scripts/lp/lpGenerateFromDb.ts",
     "lpMaintenance": "hardhat run scripts/lp/lpMaintenance.ts",
     "level2": "hardhat run scripts/path/level2Generate.ts"
   },

+ 16 - 11
scripts/lp/lpGenerateFromDb.ts

@@ -38,7 +38,10 @@ export class LpGenerate {
         token1: info['5']
       }
     } catch (e) {
-      logger.info(e)
+      const strE = e + ''
+      if (strE !== 'Error: Returned error: execution reverted') {
+        logger.debug(e + '')
+      }
     }
 
     return undefined
@@ -99,17 +102,17 @@ export class LpGenerate {
     return router.factoryObj
   }
 
-  async handleLp(lp: any, hash: string) {
+  async handleLp(lp: any, hash: string, now: number, max: number) {
     if (lp) {
-      logger.debug(`new lp: ${hash}.`)
-      // // 2. 保存Lp信息
-      // await this.saveLp(lp, 'lp')
-      // // 3. 保存Lp的Token到Token表
-      // await this.saveToken(lp, 'token')
+      logger.debug(`new lp: ${hash}.    ${now}/${max}`)
+      // 2. 保存Lp信息
+      await this.saveLp(lp, 'lp')
+      // 3. 保存Lp的Token到Token表
+      await this.saveToken(lp, 'token')
     } else {
-      logger.debug(`not lp: ${hash}.`)
+      logger.debug(`not lp: ${hash}.    ${now}/${max}`)
       // 4. 非lp放到非lp类型
-      // await this.saveLp(lp, 'notLp')
+      await this.saveLp(lp, 'notLp')
     }
   }
 
@@ -124,12 +127,14 @@ export class LpGenerate {
       const maybeLpPullRst = await History.findByBlock('maybeLp')
       if (!maybeLpPullRst.state) continue
       const maybeLpList = maybeLpPullRst.data
+      const maxLength = maybeLpList.length
 
-      for (const lpDb of maybeLpList) {
+      for (let index = 0; index < maxLength; index++) {
+        const lpDb = maybeLpList[index]
         try {
           const lp = await this.getV2PoolByAddress(lpDb.hash, v2ToolBy410)
           // 挨个处理lp信息
-          await this.handleLp(lp, lpDb.hash)
+          await this.handleLp(lp, lpDb.hash, index, maxLength)
         } catch (e) {
           logger.debug(e)
         }

+ 9 - 33
test/BaseOperationTest.ts

@@ -29,39 +29,6 @@ describe('Base operation test', () => {
     await web3.eth.sendTransaction(rawTx).then(console.log)
   })
 
-  it('Weth withdraw test', async () => {
-    const WETH_ABI = require('../abi/WETH_ABI.json')
-    const WETH_ADDR = contracts.WETH
-
-    let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
-    // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
-
-    let rawTx = {
-      from: deployer.address,
-      nonce: await web3.eth.getTransactionCount(deployer.address),
-      gasPrice: web3.utils.toWei('2', 'gwei'),
-      gasLimit: 1_000_000
-    }
-    await weth_contract.methods.withdraw(1e15).send(rawTx).then(console.log)
-  })
-
-  it ('Weth approve test', async () => {
-    const WETH_ABI = require('../abi/WETH_ABI.json')
-    const WETH_ADDR = contracts.WETH
-
-    let weth_contract = new web3.eth.Contract(WETH_ABI, WETH_ADDR)
-    // await weth_contract.methods.balanceOf(deployer.address).call().then(console.log)
-
-    let rawTx = {
-      from: deployer.address,
-      nonce: await web3.eth.getTransactionCount(deployer.address),
-      gasPrice: web3.utils.toWei('2', 'gwei'),
-      gasLimit: 1_000_000
-    }
-
-    await weth_contract.methods.approve(contracts.UNIV3, 1e18.toString()).send(rawTx).then(console.log)
-  })
-
   it ('IERC20 name test', async () => {
     const IERC20_ABI = require('../abi/IERC20_ABI.json')
     const IERC20_ADDRESS = web3.utils.toChecksumAddress('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48')
@@ -71,4 +38,13 @@ describe('Base operation test', () => {
     logger.debug(await ierc20_contract.methods.name().call())
     logger.debug(await ierc20_contract.methods.symbol().call())
   })
+
+  it('410 test', async () => {
+    const v2ToolBy410Abi = require('../abi/410_V2_TOOLS.json')
+    const v2ToolBy410 = new web3.eth.Contract(v2ToolBy410Abi, contracts.V2_TOOLS_BY_410)
+
+    const info = await v2ToolBy410.methods.getPairInfo('0x613BF4E46b4817015c01c6Bb31C7ae9edAadc26e').call()
+
+    logger.debug(info)
+  })
 })