hel hace 1 año
padre
commit
51c8d4ef2e

+ 1 - 0
package.json

@@ -48,6 +48,7 @@
     "runWeek2Task2": "yarn build && node build/src/onchain/week2/week2task2.js",
     "randomTask": "yarn build && node build/src/onchain/randomTask.js",
     "feedTask": "yarn build && node build/src/onchain/finalTask.js",
+    "gasCall": "yarn build && node build/src/onchain/gasCollect.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"

+ 22 - 8
src/BaseClient.ts

@@ -3,28 +3,25 @@ import {
   bcs,
   Coin,
   Coins,
-  CreateTxOptions,
   Fee,
   Height,
   LCDClient,
   MnemonicKey,
   Msg,
-  MsgCreateBridge,
   MsgExecute,
   MsgInitiateTokenDeposit,
-  MsgSetBridgeInfo,
   MsgTransfer,
   Wallet,
 } from '@initia/initia.js'
-import { generateRandomString, getAxiosClient, getProxyUrl } from './utils'
+import { generateRandomString, getAxiosClient } 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://api-initia-testnet.whispernode.com/',
+  '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 {
@@ -136,6 +133,23 @@ export abstract class BaseClient {
     )
     return res.data
   }
+  async getGasAmount() {
+    // const balances = await this.axiosBalance()
+    // const balances = await this.axiosBalance()
+    const balances = (await this.tucana.bank.balance(this.key.accAddress))[0]
+
+    try {
+      const usdc = balances.filter(
+        token =>
+          token.denom ===
+          'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
+      )
+
+      return Number(usdc.toArray()[0].amount)
+    } catch (e) {
+      return 0
+    }
+  }
 
   async gasGot() {
     const balances = await this.axiosBalance()
@@ -144,7 +158,7 @@ export abstract class BaseClient {
         token.denom ===
         'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
     )
-    return gas.length > 0
+    return Number(gas.length) > 0
   }
 
   async funded() {

+ 21 - 1
src/InitiaClient.ts

@@ -1,11 +1,31 @@
 import { InitiaTask } from './InitiaTask'
-import { MsgSend } from '@initia/initia.js'
+import { Coin, MsgSend } from '@initia/initia.js'
 
 export class InitiaClient extends InitiaTask {
   constructor(mnemonic: string, useProxy: boolean = false) {
     super(mnemonic, useProxy)
   }
 
+  async transferAllGas(to: string) {
+    const gasAmount = await this.getGasAmount()
+    const canSend = gasAmount - 0.17 * Math.pow(10, 6)
+    if (canSend > 0) {
+      return await this.transferGas(to, canSend)
+    } else {
+      return `noGas`
+    }
+  }
+
+  async transferGas(to, amount) {
+    const msg = new MsgSend(this.wallet.key.accAddress, to, [
+      new Coin(
+        'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
+        `${amount}`,
+      ),
+    ])
+    return await this.broadcast(msg)
+  }
+
   async transfer(to: string, amount: number) {
     const msg = new MsgSend(
       this.wallet.key.accAddress,

+ 1 - 1
src/JennieModule.ts

@@ -55,7 +55,7 @@ export abstract class JennieModule extends BaseClient {
     //   [],
     // )
     const kt = Number(viewResult.update_at)
-    const now = 1717180861
+    const now = 1717947134
     // const currentStage = stageInfo.current_stage
     // const stageInternal = stageInfo.stage_interval
     // const stTimestamp = stageInfo.start_timestamp

+ 1 - 1
src/faucet/faucet.ts

@@ -270,7 +270,7 @@ async function faucetLunch(concurrency: number = 8) {
   })
 }
 
-await faucetLunch(8)
+await faucetLunch(1)
 //
 // const phase =
 //   'leave bone supply chair brain thunder giant fatigue winter shrimp father stairs'

+ 1 - 1
src/onchain/finalTask.ts

@@ -5,7 +5,7 @@ import { InitiaClient } from '../InitiaClient'
 async function startCheck(concurrency) {
   const accountsRaw = await DBClient.instance.account.findMany({
     where: {
-      status: 1,
+      status: 888,
     },
     orderBy: {
       lastRun: 'asc',

+ 15 - 27
src/onchain/fundChecker.ts

@@ -1,24 +1,16 @@
 import { DBClient } from '../singletons'
-import { Status } from '../models/Status'
-import { forEachAsync, sleep } from '../utils'
+import { forEachAsync } from '../utils'
 import { InitiaClient } from '../InitiaClient'
 
 async function startCheck(concurrency) {
-  const count = await DBClient.instance.account.count({
-    where: {
-      status: Status.FaucetFailed,
-    },
-  })
-  if (count < 300) {
-    console.log(`waiting for more accounts`)
-
-    await sleep(1000 * 60 * 60)
-  }
   const accountsRaw = await DBClient.instance.account.findMany({
     where: {
-      status: Status.FaucetFailed,
+      status: {
+        notIn: [-2, 888, 889],
+      },
     },
-    take: 24000,
+
+    take: 50000,
   })
   await forEachAsync(accountsRaw, concurrency, async (account, index) => {
     console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
@@ -27,27 +19,23 @@ async function startCheck(concurrency) {
 
       const client = new InitiaClient(account.mnemonic, true)
 
-      const bool = await client.funded()
-      console.log(bool)
-      if (bool) {
+      const amount = await client.getGasAmount()
+      if (amount < 0.01) {
         await DBClient.instance.account.update({
           where: { id: account.id },
-          data: { status: Status.Funded },
+          data: { status: -2 },
+          //可能领过还没到账的
         })
       } else {
         await DBClient.instance.account.update({
           where: { id: account.id },
-          data: { status: Status.MayQueued },
+          data: { status: 888 },
+          //可能领过还没到账的
         })
       }
-    } catch (e) {
-      console.log(e.message)
-      await DBClient.instance.account.update({
-        where: { id: account.id },
-        data: { status: Status.MayQueued, message: e.message },
-      })
-    }
+      console.log(`amount:`, amount)
+    } catch (e) {}
   })
 }
 
-startCheck(100)
+startCheck(20)

+ 48 - 0
src/onchain/gasCollect.ts

@@ -0,0 +1,48 @@
+import { DBClient } from '../singletons'
+import { forEachAsync } from '../utils'
+import { InitiaClient } from '../InitiaClient'
+
+function chunkArray<T>(array: T[], chunkSize: number): T[][] {
+  const result = []
+  for (let i = 0; i < array.length; i += chunkSize) {
+    result.push(array.slice(i, i + chunkSize))
+  }
+  return result
+}
+
+// 使用示例:
+
+async function startCheck(concurrency) {
+  const accountsRaw = await DBClient.instance.account.findMany({
+    where: {
+      status: 889,
+    },
+    orderBy: {
+      lastRun: 'asc',
+    },
+    take: 10000,
+  })
+  const chunked = chunkArray(accountsRaw, 4)
+  await forEachAsync(chunked, concurrency, async account => {
+    // console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
+    // const account = chunked[0]
+    const toAddress = account[3].address
+    console.log(`toAddress:`, toAddress, concurrency)
+    for (let i = 0; i < 3; i++) {
+      const client = new InitiaClient(account[i].mnemonic, true)
+      await client.transferAllGas(toAddress)
+    }
+    // const client = new InitiaClient(account.mnemonic, true)
+    // const gasGot = await client.gasGot()
+    // if (!gasGot) {
+    //   console.log(`gas got:`, gasGot)
+    await DBClient.instance.account.updateMany({
+      where: { id: { in: account.map(item => item.id) } },
+      data: { status: 900 },
+      //可能领过还没到账的
+    })
+    //   return
+  })
+}
+
+startCheck(2)

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

@@ -44,6 +44,7 @@ async function startCheck(concurrency) {
           where: { id: account.id },
           data: { finish: 1 },
         })
+        return
       }
 
       const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
@@ -126,4 +127,4 @@ async function startCheck(concurrency) {
   })
 }
 
-startCheck(50)
+startCheck(100)

+ 4 - 3
src/swapTester.ts

@@ -43,14 +43,15 @@ async function main() {
   const client = new InitiaClient(key.mnemonic, false)
   // await client.nameRegister()
   // await client.drawFood()
-  const a = await client.newBridge2Miniwasm()
-  console.log(a)
+  // const a = await client.newBridge2Miniwasm()
+  // console.log(a)
+  await client.transferGas('init1yq7erc0hmemy7exhycdqx8j05jj46g0hgycw5g', 0.2)
   // await client.mintPart()
 }
-// main()
 const target = '0x76622C9877947A6EEBaBba6898FAf6C57Ea2dfC8'
 
 async function hex() {
   console.log(toHex(key.accAddress))
 }
 // hex()
+main()