فهرست منبع

Merge remote-tracking branch 'origin/main'

Shawn Lu 1 سال پیش
والد
کامیت
76590eae67
6فایلهای تغییر یافته به همراه67 افزوده شده و 30 حذف شده
  1. 1 1
      package.json
  2. 35 7
      src/BaseClient.ts
  3. 2 1
      src/JennieModule.ts
  4. 20 19
      src/onchain/finalTask.ts
  5. 9 1
      src/onchain/week3/randomWeek3.ts
  6. 0 1
      src/onchain/week3/task3check.ts

+ 1 - 1
package.json

@@ -47,7 +47,7 @@
     "task3Balance": "yarn build && node build/src/onchain/week3/task3Balance.js",
     "runWeek2Task2": "yarn build && node build/src/onchain/week2/week2task2.js",
     "randomTask": "yarn build && node build/src/onchain/randomTask.js",
-    "finalTask": "yarn build && node build/src/onchain/finalTask.js",
+    "feedTask": "yarn build && node build/src/onchain/finalTask.js",
     "mintJennie": "yarn build && node build/src/onchain/mintJennie.js",
     "wrongTask": "yarn build && node build/src/onchain/wrongTask.js",
     "decode": "yarn build && node build/src/decodeFunction.js"

+ 35 - 7
src/BaseClient.ts

@@ -16,15 +16,15 @@ import {
   MsgTransfer,
   Wallet,
 } from '@initia/initia.js'
-import { generateRandomString, getProxyUrl } from './utils'
+import { generateRandomString, getAxiosClient, getProxyUrl } from './utils'
 import { HttpsProxyAgent } from 'https-proxy-agent'
 
 const rpcUrl = [
   'https://lcd.initiation-1.initia.xyz/',
   'https://api-initia-testnet.whispernode.com/',
-  'https://initia-testnet-lcd.orbitalcommand.io/',
+  // 'https://initia-testnet-lcd.orbitalcommand.io/',
   'https://testnet-initia-api.lavenderfive.com/',
-  'https://api.initiation.test.pfc.zone/',
+  // 'https://api.initiation.test.pfc.zone/',
 ]
 
 export abstract class BaseClient {
@@ -36,7 +36,7 @@ export abstract class BaseClient {
   wallet: Wallet
   tucanaWallet: Wallet
   rpcUrlUsing: string
-  protected constructor(mnemonic: string, useProxy: boolean = false) {
+  protected constructor(mnemonic: string, useProxy: boolean = true) {
     this.key = new MnemonicKey({
       mnemonic: mnemonic,
     })
@@ -104,12 +104,22 @@ export abstract class BaseClient {
   }
 
   async broadcast(msg: Msg | Msg[]) {
+    const randLimit = 160000 + Math.floor(Math.random() * 10000)
     const signed = await this.wallet.createAndSignTx({
       msgs: Array.isArray(msg) ? msg : [msg],
-      feeDenoms: ['uinit'],
+      fee: new Fee(
+        randLimit,
+        new Coins([
+          new Coin(
+            'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
+            randLimit.toString(),
+          ),
+        ]),
+      ),
     })
-    const broadcast = await this.lcd.tx.broadcast(signed)
-    console.log(broadcast)
+    const broadcast = await this.lcd.tx.broadcastAsync(signed)
+    // console.log(broadcast.raw_log)
+    // console.log(this.key.accAddress)
     return broadcast.txhash
     // console.log(broadcast)
   }
@@ -119,6 +129,24 @@ export abstract class BaseClient {
     return balances[0].toArray()
   }
 
+  async axiosBalance() {
+    const axios = getAxiosClient(true)
+    const res = await axios.get(
+      `https://celatone-api-prod.alleslabs.dev/v1/initia/initiation-1/accounts/${this.key.accAddress}/balances`,
+    )
+    return res.data
+  }
+
+  async gasGot() {
+    const balances = await this.axiosBalance()
+    const gas = balances.filter(
+      token =>
+        token.denom ===
+        'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
+    )
+    return gas.length > 0
+  }
+
   async funded() {
     const tokens = await this.checkBalance()
     const uinit = tokens.filter(token => token.denom === 'uinit')[0]

+ 2 - 1
src/JennieModule.ts

@@ -55,7 +55,7 @@ export abstract class JennieModule extends BaseClient {
     //   [],
     // )
     const kt = Number(viewResult.update_at)
-    const now = 1716523200
+    const now = 1717180861
     // const currentStage = stageInfo.current_stage
     // const stageInternal = stageInfo.stage_interval
     // const stTimestamp = stageInfo.start_timestamp
@@ -105,6 +105,7 @@ export abstract class JennieModule extends BaseClient {
       )
       return await this.broadcast(msg)
     } else {
+      await this.drawFood()
       return `needFood`
     }
   }

+ 20 - 19
src/onchain/finalTask.ts

@@ -3,40 +3,41 @@ import { forEachAsync } from '../utils'
 import { InitiaClient } from '../InitiaClient'
 
 async function startCheck(concurrency) {
-  const accountsRaw = await DBClient.instance.randomTask.findMany({
+  const accountsRaw = await DBClient.instance.account.findMany({
     where: {
-      finish: 1,
+      status: 1,
     },
-    take: 10000,
+    orderBy: {
+      lastRun: 'asc',
+    },
+    take: 100000,
   })
   await forEachAsync(accountsRaw, concurrency, async (account, index) => {
     console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
-    console.log(account.id)
     try {
-      // await faucetAccount(account.address)
       const client = new InitiaClient(account.mnemonic, true)
-      const done = await client.mintPart()
-      console.log(done)
-      if (done != `undone`) {
-        await DBClient.instance.randomTask.update({
+      const gasGot = await client.gasGot()
+      if (!gasGot) {
+        console.log(`gas got:`, gasGot)
+        await DBClient.instance.account.update({
           where: { id: account.id },
-          data: { finish: 2 },
+          data: { status: -2 },
+          //可能领过还没到账的
         })
-      } else if (done == `undone`) {
-        await DBClient.instance.randomTask.update({
+        return
+      }
+      const done = await client.feedJennie()
+      if (done == `done`) {
+        console.log(`done work`)
+        await DBClient.instance.account.update({
           where: { id: account.id },
-          data: { finish: -2 },
+          data: { status: 2 },
         })
       }
-      // const unApprovedList = await client.mintJennie()
     } catch (e) {
       console.log(e.message)
-      // await DBClient.instance.account.update({
-      //   where: { id: account.id },
-      //   data: { status: Status.MayQueued, message: e.message },
-      // })
     }
   })
 }
 
-startCheck(120)
+startCheck(50)

+ 9 - 1
src/onchain/week3/randomWeek3.ts

@@ -49,6 +49,14 @@ async function startCheck(concurrency) {
       const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
 
       const client = new InitiaClient(account.mnemonic, true)
+      const gasGot = await client.gasGot()
+      if (!gasGot) {
+        await DBClient.instance.randomTask2.update({
+          where: { id: account.id },
+          data: { finish: -1 },
+        })
+        return
+      }
       if (randomPick === 1) {
         console.log(`task1`)
         const bool = await client.newBridge2BlackWings()
@@ -118,4 +126,4 @@ async function startCheck(concurrency) {
   })
 }
 
-startCheck(200)
+startCheck(50)

+ 0 - 1
src/onchain/week3/task3check.ts

@@ -1,6 +1,5 @@
 import { forEachAsync, getAxiosClient } from '../../utils'
 import { DBClient } from '../../singletons'
-import { InitiaClient } from '../../InitiaClient'
 
 async function startCheck(concurrency) {
   const accountsRaw = await DBClient.instance.randomTask2.findMany({