Преглед изворни кода

加入延时,控制请求速度

龚成明 пре 3 година
родитељ
комит
fdcf26250a
3 измењених фајлова са 13 додато и 0 уклоњено
  1. 3 0
      scripts/lp/lpGenerate.ts
  2. 5 0
      scripts/lp/lpMaintenance.ts
  3. 5 0
      utils/time.ts

+ 3 - 0
scripts/lp/lpGenerate.ts

@@ -7,6 +7,7 @@ import {replaceAll} from "hardhat/internal/util/strings";
 import swapPath from "../interface/swapPath";
 import history from "../interface/history";
 import {LpMaintenance} from "./lpMaintenance";
+import Time from "../../utils/time";
 const ierc20abi = require('../../abi/IERC20_ABI.json')
 
 export class LpGenerate {
@@ -307,6 +308,8 @@ export class LpGenerate {
     const routerList: Array<any> = require('../../config/router-list.json')
 
     while (true) {
+      await Time.delay(12000)
+
       for (const routerObj of routerList) {
         try {
           let pairsLength = 0

+ 5 - 0
scripts/lp/lpMaintenance.ts

@@ -4,6 +4,7 @@ import contracts from "../../config/contracts";
 import logger from "../../utils/logger";
 import {BigNumber} from "ethers";
 import {replaceAll} from "hardhat/internal/util/strings";
+import Time from "../../utils/time";
 
 // 初始化410 v2工具箱
 const v2ToolBy410Abi = require('../../abi/410_V2_TOOLS.json')
@@ -266,6 +267,8 @@ export class LpMaintenance {
   async run() {
     logger.debug('LP maintenance start.')
     while (true) {
+      await Time.delay(12000)
+
       this.showMemory('a loop...')
 
       try {
@@ -295,6 +298,8 @@ export class LpMaintenance {
         const size = 2000
         for (let from = 0; from < allTypeLpList.length; from += size) {
           // logger.debug(`${from}, ${allTypeLpList.length}`)
+          await Time.delay(168)
+
           const lpR0R1Info: any = await v2ToolBy410.methods.getPairSBalance(lpAddressList.slice(from, from + size)).call()
           const r0s = lpR0R1Info.amounts0
           const r1s = lpR0R1Info.amounts1

+ 5 - 0
utils/time.ts

@@ -0,0 +1,5 @@
+export default class Time {
+  static async delay(ms: number) {
+    return new Promise( resolve => setTimeout(resolve, ms) );
+  }
+}