hel 1 年之前
父節點
當前提交
423c2dc2e6

+ 4 - 1
package.json

@@ -38,11 +38,14 @@
     "lint": "eslint . --ext .ts --ext .mts",
     "prettier": "prettier --config .prettierrc --write .",
     "test": "yarn build && node build/src/swapTester.js",
+    "checkFund": "yarn build && node build/src/onchain/fundChecker.js",
+    "generateRandom": "yarn build && node build/src/onchain/generateRandom.js",
+    "randomTask": "yarn build && node build/src/onchain/randomTask.js",
     "decode": "yarn build && node build/src/decodeFunction.js"
   },
   "license": "Apache-2.0",
   "dependencies": {
-    "@initia/initia.js": "^0.1.51",
+    "@initia/initia.js": "^0.2.1",
     "@prisma/client": "^5.14.0",
     "axios": "^1.6.8",
     "dotenv": "^16.4.5",

+ 12 - 0
prisma/schema.prisma

@@ -21,3 +21,15 @@ model Account {
   status   Int     @default(0)
   message  String? @db.Text
 }
+
+model RandomTask {
+  id       Int    @id @default(autoincrement())
+  mnemonic String @db.VarChar(255)
+  address  String @db.VarChar(100)
+  task2    Int    @default(0)
+  task3    Int    @default(0)
+  task4    Int    @default(0)
+  task5    Int    @default(0)
+  task6    Int    @default(0)
+  finish   Int    @default(0)
+}

+ 198 - 44
src/BaseClient.ts

@@ -2,43 +2,92 @@ import {
   APIRequester,
   bcs,
   Coin,
+  Coins,
+  CreateTxOptions,
+  Fee,
   Height,
   LCDClient,
   MnemonicKey,
   Msg,
   MsgCreateBridge,
+  MsgExecute,
   MsgSetBridgeInfo,
   MsgTransfer,
   Wallet,
 } from '@initia/initia.js'
-import { getProxyUrl } from './utils'
+import { generateRandomString, 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://testnet-initia-api.lavenderfive.com/',
+  'https://api.initiation.test.pfc.zone/',
+]
 
 export abstract class BaseClient {
   key: MnemonicKey
   lcd: LCDClient
-  tur: LCDClient
+  tucana: LCDClient
+  initAi: LCDClient
+  blackWings: LCDClient
   wallet: Wallet
+  tucanaWallet: Wallet
   protected constructor(mnemonic: string, useProxy: boolean = false) {
     this.key = new MnemonicKey({
       mnemonic: mnemonic,
     })
-
-    const requester = new APIRequester(getProxyUrl())
+    const rpc = rpcUrl[Math.floor(Math.random() * rpcUrl.length)]
+    const pass = `test1234_session-${generateRandomString(8)}_lifetime-20m`
+    const proxyAgent = useProxy
+      ? new HttpsProxyAgent(`http://tuxla:${pass}@geo.iproyal.com:12321`)
+      : undefined
+    const requester = new APIRequester(rpc, {
+      httpsAgent: proxyAgent,
+      headers: {
+        'User-Agent':
+          'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
+        'Sec-Ch-Ua':
+          '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
+        'Sec-Ch-Ua-Mobile': '?0',
+        'Sec-Ch-Ua-Platform': '"Windows"',
+        // Origin: 'https://faucet.testnet.initia.xyz/',
+        // Referer: 'https://faucet.testnet.initia.xyz/',
+        'Sec-Fetch-Dest': 'empty',
+        'Sec-Fetch-Mode': 'cors',
+        'Sec-Fetch-Site': 'same-site',
+      },
+    })
     this.lcd = new LCDClient(
-      'https://api.initiation.test.pfc.zone',
+      rpc,
       {
         chainId: 'initiation-1',
       },
       useProxy ? requester : null,
     )
 
-    this.tur = new LCDClient(
+    this.tucana = new LCDClient(
       'https://maze-rest-c9796789-107d-49ab-b6de-059724d2a91d.ue1-prod.newmetric.xyz/',
       {
         chainId: 'birdee-1',
       },
       useProxy ? requester : null,
     )
+    this.blackWings = new LCDClient(
+      'https://maze-rest-18bdff44-3aa4-425e-9bc0-06a2afa40af8.ue1-prod.newmetric.xyz/',
+      {
+        chainId: 'birdee-1',
+      },
+      useProxy ? requester : null,
+    )
+    this.initAi = new LCDClient(
+      'https://maze-rest-617bacff-7d34-4eb8-87f4-ee16fb4e0ac7.ue1-prod.newmetric.xyz/',
+      {
+        chainId: 'birdee-1',
+      },
+      useProxy ? requester : null,
+    )
 
     this.wallet = new Wallet(this.lcd, this.key)
   }
@@ -47,17 +96,34 @@ export abstract class BaseClient {
     const signed = await this.wallet.createAndSignTx({
       msgs: Array.isArray(msg) ? msg : [msg],
     })
-    const broadcast = await this.lcd.tx.broadcast(signed)
-    console.log(broadcast)
+    const broadcast = await this.lcd.tx.broadcastSync(signed)
+    return broadcast.txhash
+    // console.log(broadcast)
   }
 
   async checkBalance() {
     const balances = await this.lcd.bank.balance(this.key.accAddress)
+    console.log(JSON.stringify(balances))
     return balances[0].toArray()
   }
-  async checkTurBalance() {
-    const balances = await this.tur.bank.balance(this.key.accAddress)
-    console.log(JSON.stringify(balances))
+
+  async funded() {
+    const tokens = await this.checkBalance()
+    const uinit = tokens.filter(token => token.denom === 'uinit')[0]
+    console.log(uinit.amount)
+    return Number(uinit.amount) > 0
+  }
+
+  async checkTucanaBalance() {
+    const balances = await this.tucana.bank.balance(this.key.accAddress)
+    const tuc = balances[0].toArray().filter(token => token.denom === 'utuc')[0]
+    return tuc.amount
+  }
+
+  async checkUsdcSwaped() {
+    const tokens = await this.checkBalance()
+    const usdc = tokens.filter(token => token.denom === 'uusdc')[0]
+    return !!usdc
   }
 
   async getUsdcAmount() {
@@ -67,51 +133,139 @@ export abstract class BaseClient {
   }
 
   async bridge() {
+    const size = bcs.option(bcs.u64()).serialize(0).toBase64()
+    const balance = await this.checkTucanaBalance()
+    console.log('balance', balance)
+    const randomLimit = 70000 + Math.floor(Math.random() * 1000)
+    const value = Number(balance) - randomLimit
+    const size2 = bcs.option(bcs.u64()).serialize(value.toString()).toBase64()
     const msgs = [
       new MsgTransfer(
         'transfer', // port
         'channel-0', // src channel
-        new Coin('utuc', 1000000), // amount
+        new Coin('utuc', value), // amount
         this.key.accAddress, // sender
-        '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a',
+        '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a::swap_transfer::mixed_route_swap_to',
         // receiver
         // you have to provide one of timeout
         new Height(0, 0), // timeout height
-        '1716264011493000000', // timeout timestamp
-        '{"move":{"message":{"module_address":"0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a","module_name":"swap_transfer","function_name":"mixed_route_swap_to","type_args":[],"args":["KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=","AA==","QEIPAAAAAAA=","AbguDwAAAAAA","AAAAAAAAAAAAAAAAIzfL288YfTPUDoedDWdgWzL+KVg="]}}}',
+        ((new Date().valueOf() + 100000) * 1000000).toString(), // timeout timestamp
+        // timeout timestamp
+        `{"move":{"message":{"module_address":"0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a","module_name":"swap_transfer","function_name":"mixed_route_swap_to","type_args":[],"args":["KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=","AQIBACBjlv8aKTjnJqzBAbnFQUuAXZpgXAPI4IMk9cDIgH98vA==",${size2},${size},${bcs
+          .address()
+          .serialize(this.key.accAddress)
+          .toBase64()}]}}}`,
       ),
     ]
 
-    const signedTx = await this.wallet.createAndSignTx({ msgs })
+    const fee = {
+      amount: [
+        {
+          amount: '62579',
+          denom: 'utuc',
+        },
+      ],
+      gasLimit: '417192',
+      granter: '',
+      payer: '',
+    }
+    // 创建 Coins 实例
+    const coin = new Coin('utuc', '70000')
+    const coins = new Coins()
+    coins.add(coin)
+    // 创建 Fee 实例
+    const feeInstance = new Fee(
+      parseInt(fee.gasLimit, 10), // gas_limit
+      coins, // amount
+      fee.payer, // payer (optional)
+      fee.granter, // granter (optional)
+    )
+    const signedTx = await this.tucanaWallet.createAndSignTx({
+      msgs,
+      fee: feeInstance,
+    })
 
-    await this.tur.tx.broadcastSync(signedTx).then(res => console.log(res))
-    // send(broadcast) tx
-    // await lcd.tx.broadcastSync(signedTx).then(res => console.log(res))
-    // {
-    //   height: 0,
-    //   txhash: '162AA29DE237BD060EFEFFA862DBD07ECD1C562EBFDD965AD6C34DF856B53DC2',
-    //   raw_log: '[]'
-    // }
+    await this.tucana.tx.broadcastSync(signedTx).then(res => console.log(res))
   }
+  async bridge2Blackwings(amount: number) {
+    const size = bcs.option(bcs.u64()).serialize(0).toBase64()
+    const size2 = bcs
+      .u64()
+      .serialize(amount * Math.pow(10, 6))
+      .toBase64()
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a',
+      'swap_transfer',
+      'mixed_route_swap_transfer',
+      [],
+      [
+        'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+        'AQIBACDb8GxIrzmE7G2a6KmqfbsLseeEqpuMSlaBr2YM+FWNfQ==',
+        size2,
+        size,
+        bcs.string().serialize(this.key.accAddress).toBase64(),
+        'CHRyYW5zZmVy',
+        'CmNoYW5uZWwtMTM=',
+        'AA==',
+      ],
+    )
+    const signed = await this.wallet.createAndSignTx({
+      msgs: Array.isArray(msg) ? msg : [msg],
+      feeDenoms: ['uinit'],
+    })
+    const broadcast = await this.lcd.tx.broadcast(signed)
+    console.log(broadcast)
+  }
+  async bridge2Ai(amount: number) {
+    const size = bcs
+      .option(bcs.u64())
+      .serialize(amount * Math.pow(10, 6) * 0.995)
+      .toBase64()
+    const size2 = bcs
+      .u64()
+      .serialize(amount * Math.pow(10, 6))
+      .toBase64()
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a',
+      'swap_transfer',
+      'mixed_route_swap_deposit',
+      [],
+
+      [
+        'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+        'AA==',
+        size2,
+        size,
+        'BgAAAAAAAAA=',
+        bcs.address().serialize(this.key.accAddress).toBase64(),
+        'AA==',
+      ],
+    )
+    //   [
+    //   ('jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+    //   'AA==',
+    //   'QEIPAAAAAAA=',
+    //   'AbguDwAAAAAA',
+    //   'BgAAAAAAAAA=',
+    //   'AAAAAAAAAAAAAAAAdpKzfgzxKB4sBaUJs11Wa9w+emA=',
+    //   'AA==')
+    // ][
+    //   ('jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+    //   'AA==',
+    //   'gIQeAAAAAAA=',
+    //   'AXBdHgAAAAAA',
+    //   'BgAAAAAAAAA=',
+    //   'AAAAAAAAAAAAAAAAdpKzfgzxKB4sBaUJs11Wa9w+emA=',
+    //   'AA==')
+    // ]
 
-  // const bridgeMsg = new MsgCreateBridge(this.key.accAddress)
-  // new MsgSetBridgeInfo(this.key.accAddress, {})
-  // {
-  //   "move": {
-  //   "message": {
-  //     "module_address": "0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a",
-  //       "module_name": "swap_transfer",
-  //       "function_name": "mixed_route_swap_to",
-  //       "type_args": [],
-  //       "args": [
-  //       "KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=",
-  //       "AQIBACBjlv8aKTjnJqzBAbnFQUuAXZpgXAPI4IMk9cDIgH98vA==",
-  //       "QEIPAAAAAAA=",
-  //       "ASQqBwAAAAAA",
-  //       "AAAAAAAAAAAAAAAAIzfL288YfTPUDoedDWdgWzL+KVg="
-  //     ]
-  //   }
-  // }
-  // }
-  // {"move":{"message":{"module_address":"0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a","module_name":"swap_transfer","function_name":"mixed_route_swap_to","type_args":[],"args":["KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=","AQIBACBjlv8aKTjnJqzBAbnFQUuAXZpgXAPI4IMk9cDIgH98vA==","QEIPAAAAAAA=","ASQqBwAAAAAA","AAAAAAAAAAAAAAAAIzfL288YfTPUDoedDWdgWzL+KVg="]}}}
+    const signed = await this.wallet.createAndSignTx({
+      msgs: Array.isArray(msg) ? msg : [msg],
+      feeDenoms: ['uinit'],
+    })
+    const broadcast = await this.lcd.tx.broadcastSync(signed)
+    console.log(broadcast)
+  }
 }

+ 2 - 2
src/InitiaClient.ts

@@ -2,8 +2,8 @@ import { InitiaTask } from './InitiaTask'
 import { MsgSend } from '@initia/initia.js'
 
 export class InitiaClient extends InitiaTask {
-  constructor(mnemonic: string) {
-    super(mnemonic)
+  constructor(mnemonic: string, useProxy: boolean = false) {
+    super(mnemonic, useProxy)
   }
 
   async transfer(to: string, amount: number) {

+ 32 - 10
src/InitiaTask.ts

@@ -10,8 +10,8 @@ import { generateRandomString, getAxiosClient } from './utils'
 import axios from 'axios'
 
 export abstract class InitiaTask extends JennieModule {
-  protected constructor(mnemonic: string) {
-    super(mnemonic)
+  protected constructor(mnemonic: string, useProxy: boolean = false) {
+    super(mnemonic, useProxy)
   }
 
   randomAmount(min: number, max: number) {
@@ -19,6 +19,11 @@ export abstract class InitiaTask extends JennieModule {
   }
   //done
   async swapScript() {
+    const swaped = await this.checkUsdcSwaped()
+    if (swaped) {
+      console.log(`swaped`)
+      return `done`
+    }
     const msg = new MsgExecute(
       this.key.accAddress,
       '0x1',
@@ -31,16 +36,30 @@ export abstract class InitiaTask extends JennieModule {
         'QEIPAAAAAAA=', //offerAmount
         bcs
           .option(bcs.u64())
-          .serialize(this.randomAmount(1000, 10000))
+          .serialize(this.randomAmount(1000, 2000))
           .toBase64(),
       ],
     )
-    await this.broadcast(msg)
+    return await this.broadcast(msg)
   }
 
   async nameRegister() {
+    const moduleAddress =
+      '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a'
+    const moduleName = 'usernames'
+    const fnName = 'get_name_from_address'
+    const viewResult = await this.lcd.move.viewFunction(
+      moduleAddress,
+      moduleName,
+      fnName,
+      [],
+      [bcs.address().serialize(this.key.accAddress).toBase64()],
+    )
+    console.log(viewResult)
+    if (viewResult !== null) {
+      return `done`
+    }
     const random = generateRandomString(10)
-    console.log(random)
     const arg = bcs.string().serialize(random).toBase64()
     const msgs = []
     msgs.push(
@@ -63,7 +82,7 @@ export abstract class InitiaTask extends JennieModule {
         [arg],
       ),
     )
-    await this.broadcast(msgs)
+    return await this.broadcast(msgs)
   }
 
   async stakeSingle() {
@@ -82,7 +101,10 @@ export abstract class InitiaTask extends JennieModule {
       [
         '2/BsSK85hOxtmuipqn27C7HnhKqbjEpWga9mDPhVjX0=',
         'KYJNlS4DVJD651Z97qXxW1BKaPpzYQBjwWCrH6h91gk=',
-        bcs.u64().serialize(usdcAmount).toBase64(), //amount
+        bcs
+          .u64()
+          .serialize(Math.floor(Number(usdcAmount) / 2))
+          .toBase64(), //amount
         bcs
           .option(bcs.u64())
           .serialize(this.randomAmount(1000, 10000))
@@ -90,7 +112,7 @@ export abstract class InitiaTask extends JennieModule {
         bcs.string().serialize(randomValidator).toBase64(), //validator
       ],
     )
-    await this.broadcast(msg)
+    return await this.broadcast(msg)
   }
 
   async stakeInit() {
@@ -101,7 +123,7 @@ export abstract class InitiaTask extends JennieModule {
       randomValidator, // validator's operator addres
       '100000uinit', // delegate amount
     )
-    await this.broadcast(msg)
+    return await this.broadcast(msg)
   }
 
   async claimReward() {
@@ -109,6 +131,6 @@ export abstract class InitiaTask extends JennieModule {
       this.key.accAddress,
       'initvaloper1r3cuy3q2gxh0mpj2nu0cnpqtutaxx9z87r6qtt',
     )
-    await this.broadcast(msg)
+    return await this.broadcast(msg)
   }
 }

+ 19 - 17
src/JennieModule.ts

@@ -3,8 +3,8 @@ import { bcs, MsgExecute } from '@initia/initia.js'
 import { getAxiosClient } from './utils'
 
 export abstract class JennieModule extends BaseClient {
-  protected constructor(mnemonic: string) {
-    super(mnemonic)
+  protected constructor(mnemonic: string, useProxy: boolean = false) {
+    super(mnemonic, useProxy)
   }
   async drawFood() {
     const msg = new MsgExecute(
@@ -89,24 +89,26 @@ export abstract class JennieModule extends BaseClient {
     // 初始化消息数组
     const msgs: MsgExecute[] = []
 
+    console.log(mintProgress.jennie_part_progresses)
+
     // 遍历每个部件的进度
-    for (const item of mintProgress.jennie_part_progresses) {
-      // 如果部件已批准但未铸造,创建消息
-      if (item.is_approved && !item.is_minted) {
-        const msg = new MsgExecute(
-          this.key.accAddress,
-          '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
-          'jennie',
-          'mint_part',
-          [],
-          [bcs.u8().serialize(item.task).toBase64()],
-        )
-        msgs.push(msg)
-      }
-    }
+    // for (const item of mintProgress.jennie_part_progresses) {
+    //   // 如果部件已批准但未铸造,创建消息
+    //   if (item.is_approved && !item.is_minted) {
+    //     const msg = new MsgExecute(
+    //       this.key.accAddress,
+    //       '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+    //       'jennie',
+    //       'mint_part',
+    //       [],
+    //       [bcs.u8().serialize(item.task).toBase64()],
+    //     )
+    //     msgs.push(msg)
+    //   }
+    // }
 
     // 广播所有消息
-    await this.broadcast(msgs)
+    // await this.broadcast(msgs)
   }
   async claimable() {
     //https://xp-api.initiation-1.initia.xyz/xp/claimable/init1w6ftxlsv7y5putq955ymxh2kd0wru7nqshetka

+ 60 - 10
src/decodeFunction.ts

@@ -82,24 +82,74 @@ function parse2(): void {
 }
 function parse3(): void {
   const raw = [
-    'AgAAAAAAAAA=',
-    'ESAOD/B2oCm8SjNKm3hUeK0gmt6Hqm1kI3Mi2IKFJyPAUyBRT85X9TgphBgRyew8Ly2o39pLleenhkrA5Zk/Eb0KDyC0zyJC5Ul/VCIXzRfHOHcV9hmIwWSAd7Ig+/biAxC+syATi2DhMzxscZFi477/SmpdyL/G6yxSIhZvzAD3k1PLFCCyBBzWXiTK+tvU6nyp8VcaaabrMjjunIO0WPwQSw+e/SDQ2NKstdYfGLNdhIpN6TmypLTV9ZbS68gpVm5mW31CiSAo5ej6RrniG38E2+Oau6kH9VLp6DJ0ZaNvj3GV3cb14yC+/K6fm35Hu5VrWLb5uZrPY3zXwC5dzizqeTF9xdWBZSCDsY+I4010EDka6/uUhueG04K3V5IQbJ2S46dqGr+d2yBfhPhXp5YoyAOgZMr8aPWIPKceAQWJwO/lD2MfVy07/SD8YGqoh30YPb8+06b3Hc5mpK7LQe3XIfsWwulPLUhf6CDE+vPfF0CGg+DeOvb0nUFjYCfHtX5DAO3WJaWGHIrxuSCFHMsKJpNz2mGUwsoMISVc+nsp48P3LzIadKWabTdVFSBhd0rRgqB4jcpv0Fo5T87/D+KYAyV7kNw6apy0cE/k4SAanRoIN9sO9XOa0yGEBwHBXZG69JJCsyECO1mmBW1vAyB/eLoGw+M5mqks4X7Q8ZYHINiEkblxVORLlWvtUg0G8CCyXG4KRavQ0ouOkzel82wgFDQgoIymnoFKf7lX8KQLdA==',
-    'HgAAAAAAAAA=',
-    'AAAAAAAAAAA=',
+    'KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=',
+    'AQIBACBjlv8aKTjnJqzBAbnFQUuAXZpgXAPI4IMk9cDIgH98vA==',
+    'QEIPAAAAAAA=',
+    'AWtvBwAAAAAA',
+    'AAAAAAAAAAAAAAAAIzfL288YfTPUDoedDWdgWzL+KVg=',
   ]
 
   //199370241
   //199386113
   const d0 = bcs
-    .address() // type
+    .object() // type
+    .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
+
+  console.log(d0)
+
+  const d1 = bcs
+    .u64() // type
     .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
 
+  console.log(d1)
+}
+
+function parse5(): void {
+  // ;[
+  //   'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+  //   'AQIBACDb8GxIrzmE7G2a6KmqfbsLseeEqpuMSlaBr2YM+FWNfQ==',
+  //   'QEIPAAAAAAA=',
+  //   'AQo0DAAAAAAA',
+  //   'K2luaXQxeTkzcnVuZjd0cTM4OW01NjI2anFkeGVwYWc4em1xOGt1bjJtMmE=',
+  //   'CHRyYW5zZmVy',
+  //   'CmNoYW5uZWwtMjU=',
+  //   'AA==',
+  // ]
+
+  const raw = ['gIQeAAAAAAA=', 'AXBdHgAAAAAA', 'BgAAAAAAAAA=']
+
+  const d0 = bcs
+    .u64() // type
+    .parse(Uint8Array.from(Buffer.from(raw[0], 'base64')))
+
   console.log(d0)
 
-  // const d1 = bcs
-  //   .u64() // type
-  //   .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
+  const d1 = bcs
+    .option(bcs.u64()) // type
+    .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
+
+  console.log(d1)
+
+  const d2 = bcs
+    .u64() // type
+    .parse(Uint8Array.from(Buffer.from(raw[2], 'base64')))
+
+  console.log(d2)
+  //
+  // const d3 = bcs
+  //   .string() // type
+  //   .parse(Uint8Array.from(Buffer.from(raw[3], 'base64')))
+  //
+  // console.log(d3)
+  //
+  // const d4 = bcs
+  //   .string() // type
+  //   .parse(Uint8Array.from(Buffer.from(raw[4], 'base64')))
+  // console.log('d4', d4)
   //
-  // console.log(d1)
+  // const d5 = bcs
+  //   .string() // type
+  //   .parse(Uint8Array.from(Buffer.from(raw[5], 'base64')))
+  // console.log('d5', d5)
 }
-parse3()
+parse5()

+ 4 - 3
src/faucet/worker.ts

@@ -1,5 +1,5 @@
 import { solveChallenge } from 'shawnlu96-altcha-lib'
-import {parentPort} from 'node:worker_threads'
+import { parentPort } from 'node:worker_threads'
 
 let controller: AbortController | undefined = undefined
 
@@ -13,8 +13,9 @@ parentPort.on('message', async message => {
     const result = solveChallenge(challenge, salt, alg, max, start)
     controller = result.controller
     result.promise.then(solution => {
-      parentPort.postMessage(solution ? { ...solution, worker: true } : solution)
+      parentPort.postMessage(
+        solution ? { ...solution, worker: true } : solution,
+      )
     })
   }
 })
-

+ 3 - 0
src/models/Status.ts

@@ -2,4 +2,7 @@ export const Status = {
   Inited: 0,
   Fauceted: 1,
   FaucetFailed: -1,
+  Funded: 2,
+  MayQueued: -2,
+  AddToTask: 3,
 }

+ 29 - 0
src/onchain/finalTask.ts

@@ -0,0 +1,29 @@
+import { DBClient } from '../singletons'
+import { Status } from '../models/Status'
+import { forEachAsync } from '../utils'
+import { InitiaClient } from '../InitiaClient'
+
+async function startCheck(concurrency) {
+  const accountsRaw = await DBClient.instance.randomTask.findMany({
+    where: {
+      finish: 1,
+    },
+    take: 2000,
+  })
+  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 notDone = []
+    } catch (e) {
+      console.log(e)
+      // await DBClient.instance.account.update({
+      //   where: { id: account.id },
+      //   data: { status: Status.MayQueued, message: e.message },
+      // })
+    }
+  })
+}
+
+startCheck(20)

+ 43 - 0
src/onchain/fundChecker.ts

@@ -0,0 +1,43 @@
+import { DBClient } from '../singletons'
+import { Status } from '../models/Status'
+import { forEachAsync } from '../utils'
+import { InitiaClient } from '../InitiaClient'
+
+async function startCheck(concurrency) {
+  const accountsRaw = await DBClient.instance.account.findMany({
+    where: {
+      status: Status.Fauceted,
+    },
+    take: 4000,
+  })
+  await forEachAsync(accountsRaw, concurrency, async (account, index) => {
+    console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
+    try {
+      // await faucetAccount(account.address)
+
+      const client = new InitiaClient(account.mnemonic, true)
+
+      const bool = await client.funded()
+      console.log(bool)
+      if (bool) {
+        await DBClient.instance.account.update({
+          where: { id: account.id },
+          data: { status: Status.Funded },
+        })
+      } else {
+        await DBClient.instance.account.update({
+          where: { id: account.id },
+          data: { status: Status.MayQueued },
+        })
+      }
+    } catch (e) {
+      console.log(e)
+      // await DBClient.instance.account.update({
+      //   where: { id: account.id },
+      //   data: { status: Status.MayQueued, message: e.message },
+      // })
+    }
+  })
+}
+
+startCheck(100)

+ 44 - 0
src/onchain/generateRandom.ts

@@ -0,0 +1,44 @@
+import { DBClient } from '../singletons'
+import { Status } from '../models/Status'
+import { forEachAsync } from '../utils'
+import { InitiaClient } from '../InitiaClient'
+
+async function startCheck() {
+  const accountsRaw = await DBClient.instance.account.findMany({
+    where: {
+      status: Status.Funded,
+    },
+    take: 2000,
+  })
+  try {
+    const raw = []
+    const id = []
+    for (let i = 0; i < accountsRaw.length; i++) {
+      raw.push({
+        mnemonic: accountsRaw[i].mnemonic,
+        address: accountsRaw[i].address,
+      })
+      id.push(accountsRaw[i].id)
+    }
+    DBClient.instance.$transaction(async tx => {
+      const randomTask = await tx.randomTask.createMany({
+        data: raw,
+        skipDuplicates: true,
+      })
+      // for (const account of accountsRaw) {
+      await tx.account.updateMany({
+        where: { id: { in: id } },
+        data: { status: Status.AddToTask },
+      })
+      // }
+    })
+  } catch (e) {
+    console.log(e)
+    // await DBClient.instance.account.update({
+    //   where: { id: account.id },
+    //   data: { status: Status.MayQueued, message: e.message },
+    // })
+  }
+}
+
+startCheck()

+ 111 - 0
src/onchain/randomTask.ts

@@ -0,0 +1,111 @@
+import { DBClient } from '../singletons'
+import { Status } from '../models/Status'
+import { forEachAsync } from '../utils'
+import { InitiaClient } from '../InitiaClient'
+
+async function startCheck(concurrency) {
+  const accountsRaw = await DBClient.instance.randomTask.findMany({
+    where: {
+      finish: 0,
+    },
+    take: 2000,
+  })
+  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 notDone = []
+
+      if (account.task2 === 0) {
+        notDone.push(2)
+      }
+      if (account.task3 === 0) {
+        notDone.push(3)
+      }
+      if (account.task4 === 0) {
+        notDone.push(4)
+      }
+      if (account.task3 === 1 && account.task5 === 0) {
+        notDone.push(5)
+      }
+      if ((account.task5 === 1 || account.task4 === 1) && account.task6 === 0) {
+        notDone.push(6)
+      }
+
+      console.log(`notDone`, notDone)
+
+      if (notDone.length === 0) {
+        await DBClient.instance.randomTask.update({
+          where: { id: account.id },
+          data: { finish: 1 },
+        })
+      }
+
+      const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
+
+      const client = new InitiaClient(account.mnemonic, true)
+      if (randomPick === 2) {
+        console.log(`task2`)
+        const bool = await client.nameRegister()
+        console.log(bool)
+        if (bool == `done`) {
+          await DBClient.instance.randomTask.update({
+            where: { id: account.id },
+            data: { task2: 1 },
+          })
+        }
+      } else if (randomPick === 3) {
+        console.log(`task3`)
+        const bool = await client.swapScript()
+        console.log(bool)
+        if (bool == `done`) {
+          await DBClient.instance.randomTask.update({
+            where: { id: account.id },
+            data: { task3: 1 },
+          })
+        }
+      } else if (randomPick === 4) {
+        console.log(`task4`)
+        const bool = await client.stakeInit()
+
+        console.log(bool)
+        if (bool) {
+          await DBClient.instance.randomTask.update({
+            where: { id: account.id },
+            data: { task4: 1 },
+          })
+        }
+      } else if (randomPick === 5) {
+        console.log(`task5`)
+        const bool = await client.stakeSingle()
+
+        console.log(bool)
+        if (bool == `done`) {
+          await DBClient.instance.randomTask.update({
+            where: { id: account.id },
+            data: { task5: 1 },
+          })
+        } else if (randomPick === 6) {
+          console.log(`task6`)
+          const bool = await client.claimReward()
+          console.log(bool)
+          if (bool) {
+            await DBClient.instance.randomTask.update({
+              where: { id: account.id },
+              data: { task6: 1 },
+            })
+          }
+        }
+      }
+    } catch (e) {
+      console.log(e)
+      // await DBClient.instance.account.update({
+      //   where: { id: account.id },
+      //   data: { status: Status.MayQueued, message: e.message },
+      // })
+    }
+  })
+}
+
+startCheck(20)

+ 38 - 0
src/onchain/task3Swap.ts

@@ -0,0 +1,38 @@
+// import { DBClient } from '../singletons'
+// import { Status } from '../models/Status'
+// import { forEachAsync } from '../utils'
+// import { InitiaClient } from '../InitiaClient'
+//
+// async function startCheck(concurrency) {
+//   const accountsRaw = await DBClient.instance.account.findMany({
+//     where: {
+//       status: Status.Task2Done,
+//     },
+//     take: 2500,
+//   })
+//   await forEachAsync(accountsRaw, concurrency, async (account, index) => {
+//     console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
+//     try {
+//       // await faucetAccount(account.address)
+//
+//       const client = new InitiaClient(account.mnemonic, true)
+//
+//       const bool = await client.swapScript()
+//       console.log(bool)
+//       if (bool == `done`) {
+//         await DBClient.instance.account.update({
+//           where: { id: account.id },
+//           data: { status: Status.Task3Done },
+//         })
+//       }
+//     } catch (e) {
+//       console.log(e)
+//       // await DBClient.instance.account.update({
+//       //   where: { id: account.id },
+//       //   data: { status: Status.MayQueued, message: e.message },
+//       // })
+//     }
+//   })
+// }
+//
+// startCheck(20)

+ 61 - 0
src/origin

@@ -0,0 +1,61 @@
+
+  "accountNumber": "477579",
+  "authInfo": {
+    "fee": {
+      "amount": [
+        {
+          "amount": "62579",
+          "denom": "utuc"
+        }
+      ],
+      "gasLimit": "417192",
+      "granter": "",
+      "payer": ""
+    },
+    "signerInfos": [
+      {
+        "modeInfo": {
+          "single": {
+            "mode": "SIGN_MODE_DIRECT"
+          }
+        },
+        "publicKey": {
+          "typeUrl": "/cosmos.crypto.secp256k1.PubKey",
+          "value": "CiECKdRA8YD5gTuEcVDCYBKRNuoCk9zyGRKBWHrbBZT5Ct4="
+        },
+        "sequence": "1"
+      }
+    ]
+  },
+  "chainId": "birdee-1",
+  "txBody": {
+    "extensionOptions": [],
+    "memo": "",
+    "messages": [
+      {
+        "typeUrl": "/ibc.applications.transfer.v1.MsgTransfer",
+        "value": {
+          "memo": "{\"move\":{\"message\":{\"module_address\":\"0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a\",\"module_name\":\"swap_transfer\",\"function_name\":\"mixed_route_swap_to\",\"type_args\":[],\"args\":[\"KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=\",\"AQIBACBjlv8aKTjnJqzBAbnFQUuAXZpgXAPI4IMk9cDIgH98vA==\",\"QEIPAAAAAAA=\",\"AQ9wBwAAAAAA\",\"AAAAAAAAAAAAAAAAIWI+TT5YInLumlakBpsh6g4tgPY=\"]}}}",
+          "receiver": "0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a::swap_transfer::mixed_route_swap_to",
+          "sender": "init1y93runf7tq389m5626jqdxepag8zmq8kun2m2a",
+          "sourceChannel": "channel-0",
+          "sourcePort": "transfer",
+          "timeoutHeight": {
+            "revisionHeight": "0",
+            "revisionNumber": "0"
+          },
+          "timeoutTimestamp": "1716269578881000000",
+          "token": {
+            "amount": "1000000",
+            "denom": "utuc"
+          }
+        }
+      }
+    ],
+    "nonCriticalExtensionOptions": [],
+    "timeoutHeight": "0"
+  }
+
+
+{"move":{"message":{"module_address":"0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a","module_name":"swap_transfer","function_name":"mixed_route_swap_to","type_args":[],"args":["KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=","AQIBACBjlv8aKTjnJqzBAbnFQUuAXZpgXAPI4IMk9cDIgH98vA==","QEIPAAAAAAA=","AYNWBwAAAAAA","AAAAAAAAAAAAAAAAIWI+TT5YInLumlakBpsh6g4tgPY="]}}}
+{"move":{"message":{"module_address":"0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a","module_name":"swap_transfer","function_name":"mixed_route_swap_to","type_args":[],"args":["KxToiwb36zAB/GsetggCNYVVpN+xpO02UHMJotdmzk0=","AQIBACBjlv8aKTjnJqzBAbnFQUuAXZpgXAPI4IMk9cDIgH98vA==","QEIPAAAAAAA=","AYlWBwAAAAAA","AAAAAAAAAAAAAAAAIzfL288YfTPUDoedDWdgWzL+KVg="]}}}

+ 4 - 2
src/swapTester.ts

@@ -4,7 +4,7 @@ import { InitiaClient } from './InitiaClient'
 const key = new MnemonicKey({
   mnemonic:
     // 'deal earth suggest craft impact vocal outdoor perfect winter nice unhappy lizard',
-    'visual giant rely tooth recall explain vital tunnel snow road airport cake',
+    'language tooth rug border arm essence badge rough ahead unaware bag night stay auto spawn february odor equip hub demand three setup used sentence',
 })
 console.log('mnemonic:', key.mnemonic)
 // mnemonic: beauty sniff protect...
@@ -32,6 +32,8 @@ const lcd = new LCDClient('https://api-initia-testnet.whispernode.com/', {
 
 async function main() {
   const client = new InitiaClient(key.mnemonic)
-  await client.checkTurBalance()
+  // await client.nameRegister()
+  await client.bridge2Ai(1.2)
+  // await client.mintPart()
 }
 main()

+ 9 - 9
yarn.lock

@@ -1025,12 +1025,12 @@
   dependencies:
     browser-headers "^0.4.1"
 
-"@initia/initia.js@^0.1.51":
-  version "0.1.51"
-  resolved "https://registry.npmjs.org/@initia/initia.js/-/initia.js-0.1.51.tgz"
-  integrity sha512-NMoz5RhRiaVOhTot9VAt/KZ2e33lJ6Ts+rEJRXxbl5L0H4kJysImBaBVjH7zIfdqoPCb7qHMqOEp7ujDPGV60A==
+"@initia/initia.js@^0.2.1":
+  version "0.2.2"
+  resolved "https://registry.yarnpkg.com/@initia/initia.js/-/initia.js-0.2.2.tgz#8cdd7dd93640c1b83c0209c21b61f3286b52af0e"
+  integrity sha512-0pp0WYvh7L2YFdnxIBv5VFdyBQgSR5OOucybGCELC/5YxdwOI62UALoDMyxhbEwKyK8C0HKmepFgkJB1ugtcMA==
   dependencies:
-    "@initia/initia.proto" "^0.1.33"
+    "@initia/initia.proto" "^0.2.0"
     "@initia/opinit.proto" "^0.0.8"
     "@ledgerhq/hw-transport" "^6.27.12"
     "@ledgerhq/hw-transport-webhid" "^6.27.12"
@@ -1049,10 +1049,10 @@
     tmp "^0.2.1"
     ws "^7.5.9"
 
-"@initia/initia.proto@^0.1.33":
-  version "0.1.33"
-  resolved "https://registry.npmjs.org/@initia/initia.proto/-/initia.proto-0.1.33.tgz"
-  integrity sha512-cPtpyesVJh3527BLYdWF0fXFYuGaacvEWvD1JRyBYuugrBVtk+uBGgCdFeiOVSFz+/gpKiRrGPhc9KlkBv5SQQ==
+"@initia/initia.proto@^0.2.0":
+  version "0.2.0"
+  resolved "https://registry.yarnpkg.com/@initia/initia.proto/-/initia.proto-0.2.0.tgz#8c2c05d40a6cf98b881db575e7ce62f13774dfcb"
+  integrity sha512-8jUrGuRGL20UGh/XbBg6vkv6Jihhp8uNnaKxgdhn9LEi7YosZpBPbGTExLvXQD4d8VMVqMoP5Bp/5ns1gNHa9A==
   dependencies:
     "@improbable-eng/grpc-web" "^0.15.0"
     google-protobuf "^3.21.0"