xiongzhu %!s(int64=2) %!d(string=hai) anos
pai
achega
3d687c0e0b

+ 4 - 4
src/accounts/entities/account.entity.ts

@@ -55,16 +55,16 @@ export class Account {
     lastThirdBridge: Date
     lastThirdBridge: Date
 
 
     @Column({ nullable: true })
     @Column({ nullable: true })
-    addLiuidityNum: number
+    addLiquidityNum: number
 
 
     @Column({ nullable: true })
     @Column({ nullable: true })
-    lastAddLiuidity: Date
+    lastAddLiquidity: Date
 
 
     @Column({ nullable: true })
     @Column({ nullable: true })
-    removeLiuidityNum: number
+    removeLiquidityNum: number
 
 
     @Column({ nullable: true })
     @Column({ nullable: true })
-    lastRemoveLiuidity: Date
+    lastRemoveLiquidity: Date
 
 
     @Column({ nullable: true })
     @Column({ nullable: true })
     mintNum: number
     mintNum: number

+ 3 - 0
src/task/entities/task-log.entity.ts

@@ -19,6 +19,9 @@ export class TaskLog {
     @Column({ nullable: true })
     @Column({ nullable: true })
     accountName?: string
     accountName?: string
 
 
+    @Column({ nullable: true })
+    amount: string
+
     @Column({ nullable: true })
     @Column({ nullable: true })
     address?: string
     address?: string
 
 

+ 49 - 168
src/task/task.service.ts

@@ -18,6 +18,7 @@ import { setTimeout } from 'timers/promises'
 import schedule from 'node-schedule'
 import schedule from 'node-schedule'
 import { SchedulerRegistry } from '@nestjs/schedule'
 import { SchedulerRegistry } from '@nestjs/schedule'
 import { CronJob } from 'cron'
 import { CronJob } from 'cron'
+import { TaskItem } from './model/task-item.model'
 @Injectable()
 @Injectable()
 export class TaskService implements OnModuleInit {
 export class TaskService implements OnModuleInit {
     constructor(
     constructor(
@@ -81,6 +82,20 @@ export class TaskService implements OnModuleInit {
         return task
         return task
     }
     }
 
 
+    async getAmount(account, taskItem: TaskItem, token: 'eth' | 'zk' | 'usdc' = 'eth') {
+        return taskItem.amountType === 'amount'
+            ? randomAmount(taskItem.amount.min, taskItem.amount.max)
+            : randomBalancePercent(
+                  token === 'eth'
+                      ? await this.accountsService.getEthBalance(account)
+                      : token === 'zk'
+                      ? await this.accountsService.getZkBalance(account)
+                      : await this.accountsService.getUsdcBalance(account),
+                  taskItem.percent.min,
+                  taskItem.percent.max
+              )
+    }
+
     async runTask(task: Task) {
     async runTask(task: Task) {
         if (task.status == TaskStatus.Done) {
         if (task.status == TaskStatus.Done) {
             return
             return
@@ -94,6 +109,7 @@ export class TaskService implements OnModuleInit {
                 taskLog.accountId = accountId
                 taskLog.accountId = accountId
                 taskLog.startTime = new Date()
                 taskLog.startTime = new Date()
                 taskLog.type = taskItem.type
                 taskLog.type = taskItem.type
+                let amount: string
                 try {
                 try {
                     const account = await this.accountsService.findById(accountId)
                     const account = await this.accountsService.findById(accountId)
                     taskLog.address = account.address
                     taskLog.address = account.address
@@ -101,213 +117,77 @@ export class TaskService implements OnModuleInit {
                     let web3Result: Web3Result
                     let web3Result: Web3Result
                     switch (taskItem.type) {
                     switch (taskItem.type) {
                         case TaskType.bridge2zk:
                         case TaskType.bridge2zk:
-                            web3Result = await this.web3Service.zkDeposit(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getEthBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'eth')
+                            web3Result = await this.web3Service.zkDeposit(accountId, amount)
                             break
                             break
                         case TaskType.bridge2eth:
                         case TaskType.bridge2eth:
-                            web3Result = await this.web3Service.zkWithdraw(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.zkWithdraw(accountId, amount)
                             break
                             break
                         case TaskType.orbiter2zk:
                         case TaskType.orbiter2zk:
-                            web3Result = await this.web3Service.orbiterDeposit(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getEthBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'eth')
+                            web3Result = await this.web3Service.orbiterDeposit(accountId, amount)
                             break
                             break
                         case TaskType.orbiter2eth:
                         case TaskType.orbiter2eth:
-                            web3Result = await this.web3Service.orbiterWithdraw(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.orbiterWithdraw(accountId, amount)
                             break
                             break
                         case TaskType.swapUsdc:
                         case TaskType.swapUsdc:
-                            web3Result = await this.web3Service.swapWithExactInput(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'eth'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.swapWithExactInput(accountId, amount, 'eth')
                             break
                             break
                         case TaskType.swapEth:
                         case TaskType.swapEth:
-                            web3Result = await this.web3Service.swapWithExactInput(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getUsdcBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'usdc'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'usdc')
+                            web3Result = await this.web3Service.swapWithExactInput(accountId, amount, 'usdc')
                             break
                             break
                         case TaskType.syncSwapUsdc:
                         case TaskType.syncSwapUsdc:
-                            web3Result = await this.web3Service.swapSyncSwap(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'eth'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.swapSyncSwap(accountId, amount, 'eth')
                             break
                             break
                         case TaskType.syncSwapEth:
                         case TaskType.syncSwapEth:
-                            web3Result = await this.web3Service.swapSyncSwap(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getUsdcBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'usdc'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'usdc')
+                            web3Result = await this.web3Service.swapSyncSwap(accountId, amount, 'usdc')
                             break
                             break
                         case TaskType.muteSwapUsdc:
                         case TaskType.muteSwapUsdc:
-                            web3Result = await this.web3Service.muteSwap(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'eth'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.muteSwap(accountId, amount, 'eth')
                             break
                             break
                         case TaskType.muteSwapEth:
                         case TaskType.muteSwapEth:
-                            web3Result = await this.web3Service.muteSwap(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getUsdcBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'usdc'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'usdc')
+                            web3Result = await this.web3Service.muteSwap(accountId, amount, 'usdc')
                             break
                             break
                         case TaskType.spacefiSwapUsdc:
                         case TaskType.spacefiSwapUsdc:
-                            web3Result = await this.web3Service.spacefiSwap(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'eth'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.spacefiSwap(accountId, amount, 'eth')
                             break
                             break
                         case TaskType.spacefiSwapEth:
                         case TaskType.spacefiSwapEth:
-                            web3Result = await this.web3Service.spacefiSwap(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getUsdcBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      ),
-                                'usdc'
-                            )
+                            amount = await this.getAmount(account, taskItem, 'usdc')
+                            web3Result = await this.web3Service.spacefiSwap(accountId, amount, 'usdc')
                             break
                             break
                         case TaskType.addLiquidity:
                         case TaskType.addLiquidity:
-                            web3Result = await this.web3Service.addLiquidity(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.addLiquidity(accountId, amount)
                             break
                             break
                         case TaskType.removeLiquidity:
                         case TaskType.removeLiquidity:
                             web3Result = await this.web3Service.removeLiquidity(accountId)
                             web3Result = await this.web3Service.removeLiquidity(accountId)
                             break
                             break
                         case TaskType.addLiquiditySyncSwap:
                         case TaskType.addLiquiditySyncSwap:
-                            web3Result = await this.web3Service.addLiquiditySyncSwap(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.addLiquiditySyncSwap(accountId, amount)
                             break
                             break
                         case TaskType.removeLiquiditySyncSwap:
                         case TaskType.removeLiquiditySyncSwap:
                             web3Result = await this.web3Service.removeLiquiditySyncSwap(accountId)
                             web3Result = await this.web3Service.removeLiquiditySyncSwap(accountId)
                             break
                             break
                         case TaskType.addLiquidityMute:
                         case TaskType.addLiquidityMute:
-                            web3Result = await this.web3Service.addLiquidityMute(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.addLiquidityMute(accountId, amount)
                             break
                             break
                         case TaskType.removeLiquidityMute:
                         case TaskType.removeLiquidityMute:
                             web3Result = await this.web3Service.removeLiquidityMute(accountId)
                             web3Result = await this.web3Service.removeLiquidityMute(accountId)
                             break
                             break
                         case TaskType.addLiquiditySpacefi:
                         case TaskType.addLiquiditySpacefi:
-                            web3Result = await this.web3Service.addLiquiditySpacefi(
-                                accountId,
-                                taskItem.amountType === 'amount'
-                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
-                                    : randomBalancePercent(
-                                          await this.accountsService.getZkBalance(account),
-                                          taskItem.percent.min,
-                                          taskItem.percent.max
-                                      )
-                            )
+                            amount = await this.getAmount(account, taskItem, 'zk')
+                            web3Result = await this.web3Service.addLiquiditySpacefi(accountId, amount)
                             break
                             break
                         case TaskType.removeLiquiditySpacefi:
                         case TaskType.removeLiquiditySpacefi:
                             web3Result = await this.web3Service.removeLiquiditySpacefi(accountId)
                             web3Result = await this.web3Service.removeLiquiditySpacefi(accountId)
@@ -325,6 +205,7 @@ export class TaskService implements OnModuleInit {
                     taskLog.status = LogStatus.Failed
                     taskLog.status = LogStatus.Failed
                     taskLog.error = error.message
                     taskLog.error = error.message
                 }
                 }
+                taskLog.amount = amount
                 taskLog.finishTime = new Date()
                 taskLog.finishTime = new Date()
                 await this.taskLogRepository.save(taskLog)
                 await this.taskLogRepository.save(taskLog)
                 task.progress += 1
                 task.progress += 1

+ 20 - 18
src/web3/web3.service.ts

@@ -275,7 +275,7 @@ export class Web3Service {
         if (calling instanceof Array) {
         if (calling instanceof Array) {
             calling = liquidityManagerContract.methods.multicall(mintCalling)
             calling = liquidityManagerContract.methods.multicall(mintCalling)
         }
         }
-        const gasLimit = await calling.estimateGas({ from: zkWallet.address })
+        const gasLimit = await calling.estimateGas({ from: zkWallet.address, value: maxTestA.toFixed(0) })
         Logger.log(`gas limit: ${gasLimit}`, 'addLiquidity')
         Logger.log(`gas limit: ${gasLimit}`, 'addLiquidity')
 
 
         // sign transaction
         // sign transaction
@@ -287,8 +287,8 @@ export class Web3Service {
             gasLimit
             gasLimit
         })
         })
         Logger.log(`tx hash: ${tx.hash}`, 'addLiquidity')
         Logger.log(`tx hash: ${tx.hash}`, 'addLiquidity')
-        account.addLiuidityNum = (account.addLiuidityNum || 0) + 1
-        account.lastAddLiuidity = new Date()
+        account.addLiquidityNum = (account.addLiquidityNum || 0) + 1
+        account.lastAddLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx.hash, web3Config[account.network], true)
         return new Web3Result(account.address, tx.hash, web3Config[account.network], true)
     }
     }
@@ -334,8 +334,8 @@ export class Web3Service {
             gasLimit
             gasLimit
         })
         })
         Logger.log(`transaction sent: ${tx.hash}`, 'addLiquiditySyncSwap')
         Logger.log(`transaction sent: ${tx.hash}`, 'addLiquiditySyncSwap')
-        account.addLiuidityNum = (account.addLiuidityNum || 0) + 1
-        account.lastAddLiuidity = new Date()
+        account.addLiquidityNum = (account.addLiquidityNum || 0) + 1
+        account.lastAddLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx.hash, config, true)
         return new Web3Result(account.address, tx.hash, config, true)
     }
     }
@@ -382,8 +382,8 @@ export class Web3Service {
         })
         })
 
 
         Logger.log(`transaction sent: ${tx.hash}`, 'addLiquidityMute')
         Logger.log(`transaction sent: ${tx.hash}`, 'addLiquidityMute')
-        account.addLiuidityNum = (account.addLiuidityNum || 0) + 1
-        account.lastAddLiuidity = new Date()
+        account.addLiquidityNum = (account.addLiquidityNum || 0) + 1
+        account.lastAddLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx.hash, config, true)
         return new Web3Result(account.address, tx.hash, config, true)
     }
     }
@@ -435,8 +435,8 @@ export class Web3Service {
         })
         })
 
 
         Logger.log(`transaction sent: ${tx.hash}`, 'addLiquiditySpacefi')
         Logger.log(`transaction sent: ${tx.hash}`, 'addLiquiditySpacefi')
-        account.addLiuidityNum = (account.addLiuidityNum || 0) + 1
-        account.lastAddLiuidity = new Date()
+        account.addLiquidityNum = (account.addLiquidityNum || 0) + 1
+        account.lastAddLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx.hash, config, true)
         return new Web3Result(account.address, tx.hash, config, true)
     }
     }
@@ -507,8 +507,8 @@ export class Web3Service {
             gasLimit
             gasLimit
         })
         })
         Logger.log(`transaction sent: ${tx0.hash}`, 'removeLiquidity')
         Logger.log(`transaction sent: ${tx0.hash}`, 'removeLiquidity')
-        account.removeLiuidityNum = (account.removeLiuidityNum || 0) + 1
-        account.lastRemoveLiuidity = new Date()
+        account.removeLiquidityNum = (account.removeLiquidityNum || 0) + 1
+        account.lastRemoveLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx0.hash, web3Config[account.network], true)
         return new Web3Result(account.address, tx0.hash, web3Config[account.network], true)
     }
     }
@@ -552,8 +552,8 @@ export class Web3Service {
             gasLimit
             gasLimit
         })
         })
         Logger.log(`transaction sent: ${tx.hash}`, 'removeLiquiditySyncSwap')
         Logger.log(`transaction sent: ${tx.hash}`, 'removeLiquiditySyncSwap')
-        account.removeLiuidityNum = (account.removeLiuidityNum || 0) + 1
-        account.lastRemoveLiuidity = new Date()
+        account.removeLiquidityNum = (account.removeLiquidityNum || 0) + 1
+        account.lastRemoveLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx.hash, config, true)
         return new Web3Result(account.address, tx.hash, config, true)
     }
     }
@@ -594,8 +594,8 @@ export class Web3Service {
         })
         })
 
 
         Logger.log(`transaction sent: ${tx.hash}`, 'removeLiquidityMute')
         Logger.log(`transaction sent: ${tx.hash}`, 'removeLiquidityMute')
-        account.removeLiuidityNum = (account.removeLiuidityNum || 0) + 1
-        account.lastRemoveLiuidity = new Date()
+        account.removeLiquidityNum = (account.removeLiquidityNum || 0) + 1
+        account.lastRemoveLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx.hash, config, true)
         return new Web3Result(account.address, tx.hash, config, true)
     }
     }
@@ -637,8 +637,8 @@ export class Web3Service {
         })
         })
 
 
         Logger.log(`transaction sent: ${tx.hash}`, 'removeLiquiditySpacefi')
         Logger.log(`transaction sent: ${tx.hash}`, 'removeLiquiditySpacefi')
-        account.removeLiuidityNum = (account.removeLiuidityNum || 0) + 1
-        account.lastRemoveLiuidity = new Date()
+        account.removeLiquidityNum = (account.removeLiquidityNum || 0) + 1
+        account.lastRemoveLiquidity = new Date()
         await this.accountService.save([account])
         await this.accountService.save([account])
         return new Web3Result(account.address, tx.hash, config, true)
         return new Web3Result(account.address, tx.hash, config, true)
     }
     }
@@ -851,6 +851,7 @@ export class Web3Service {
         Logger.log(`poolAddress: ${poolAddress}`, 'swapSyncSwap')
         Logger.log(`poolAddress: ${poolAddress}`, 'swapSyncSwap')
 
 
         const router = new web3.eth.Contract(SyncSwapRouterAbi, config.syncSwapRouterAddress)
         const router = new web3.eth.Contract(SyncSwapRouterAbi, config.syncSwapRouterAddress)
+
         const value = inputToken === 'eth' ? ethers.utils.parseEther(amount) : ethers.utils.parseUnits(amount, 6)
         const value = inputToken === 'eth' ? ethers.utils.parseEther(amount) : ethers.utils.parseUnits(amount, 6)
         const params = [
         const params = [
             [
             [
@@ -885,7 +886,8 @@ export class Web3Service {
         )
         )
 
 
         const gasLimit = await swap.estimateGas({
         const gasLimit = await swap.estimateGas({
-            from: zkWallet.address
+            from: zkWallet.address,
+            value: inputToken === 'eth' ? value.toHexString() : '0x00'
         })
         })
         const tx = await zkWallet.sendTransaction({
         const tx = await zkWallet.sendTransaction({
             // from: wallet.address,
             // from: wallet.address,