helium3@sina.com há 1 ano atrás
pai
commit
dd9d0d39b7

+ 1 - 1
package.json

@@ -52,7 +52,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",
-    "feedTask": "yarn build && node build/src/onchain/finalTask.js",
+    "finalTask": "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",

+ 68 - 11
src/InitiaClient.ts

@@ -49,17 +49,10 @@ export class InitiaClient extends InitiaTask {
   }
 
   async transfer(to: string, amount: number) {
-    const msg = new MsgSend(
-      this.wallet.key.accAddress,
-      to,
-      `${amount * Math.pow(10, 6)}uinit`,
-    )
-    const signed = await this.wallet.createAndSignTx({
-      // sequence: 3,
-      msgs: [msg],
-    })
-    const broadcast = await this.lcd.tx.broadcastAsync(signed)
-    return broadcast.txhash
+    const msg = new MsgSend(this.wallet.key.accAddress, to, [
+      new Coin('uinit', amount.toString()),
+    ])
+    return await this.broadcast(msg)
   }
 
   async week2Task2(toAddr: string) {
@@ -1586,4 +1579,68 @@ export class InitiaClient extends InitiaTask {
       return `error`
     }
   }
+  async quest2Task1() {
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x1',
+      'stableswap',
+      'provide_liquidity_script',
+      [],
+      [
+        'Q2BFcWnO12V3uhjV54FrL+RXN+HIqLtuIVR1ix7GVFw=',
+        'AqCGAQAAAAAAAAAAAAAAAAA=',
+        'AA==',
+      ],
+    )
+    await this.broadcast(msg)
+  }
+  async quest2Task2() {
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a',
+      'minitswap',
+      'provide',
+      [],
+      ['oIYBAAAAAAA=', 'AA=='],
+    )
+    await this.broadcast(msg)
+  }
+  async quest2Task3() {
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a',
+      'minitswap_router',
+      'swap',
+      [],
+      [
+        'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+        'MaT2Csca1vMydHLPGphV211CBZwKsp4Wv7byEuusLRw=',
+        'ECcAAAAAAAA=',
+        bcs.address().serialize(this.wallet.key.accAddress).toBase64(),
+        'AA==',
+        'AA==',
+        'AXImAAAAAAAA',
+        'AQEAAAAAAAAA',
+      ],
+    )
+    const res = await this.broadcast(msg)
+    console.log(res)
+  }
+  async quest2Task4() {
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x1',
+      'dex',
+      'single_asset_provide_liquidity_script',
+      [],
+      [
+        's/TSKnNzlI0a/OECOi6HVCXMwYLYI7cU4Zp6iX/bF9U=',
+        'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+        'oIYBAAAAAAA=',
+        'AeC+AAAAAAAA',
+      ],
+    )
+    const res = await this.broadcast(msg)
+    console.log(res)
+  }
 }

+ 75 - 0
src/JennieModule.ts

@@ -353,4 +353,79 @@ export abstract class JennieModule extends BaseClient {
       return `done`
     }
   }
+
+  async claimWeek1() {
+    const finished = await this.lcd.move.viewFunction(
+      '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+      'jennie',
+      'get_jennie_frame',
+      undefined,
+      [bcs.address().serialize(this.key.accAddress).toBase64()],
+    )
+    console.log(finished)
+    if (finished[0]) {
+      return `done`
+    }
+    const res = await polly()
+      .waitAndRetry(10)
+      .executeForPromise(async () => {
+        const axios = getAxiosClient(true)
+
+        return await axios.get(
+          `https://xp-api.initiation-1.initia.xyz/xp/weekly/${this.key.accAddress}/9`,
+        )
+      })
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+      'jennie',
+      'upgrade_frame',
+      [],
+      [
+        bcs.u8().serialize(res.data.week).toBase64(),
+        bcs
+          .vector(bcs.u8())
+          .serialize(Uint8Array.from(Buffer.from(res.data.signature, 'base64')))
+          .toBase64(),
+      ],
+    )
+    return await this.broadcast(msg)
+  }
+  async claimWeek2() {
+    const finished = await this.lcd.move.viewFunction(
+      '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+      'jennie',
+      'get_jennie_frame',
+      undefined,
+      [bcs.address().serialize(this.key.accAddress).toBase64()],
+    )
+    console.log(finished)
+    if (finished[1]) {
+      return `done`
+    }
+    const res = await polly()
+      .waitAndRetry(10)
+      .executeForPromise(async () => {
+        const axios = getAxiosClient(true)
+
+        return await axios.get(
+          `https://xp-api.initiation-1.initia.xyz/xp/weekly/${this.key.accAddress}/10`,
+        )
+      })
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+      'jennie',
+      'upgrade_frame',
+      [],
+      [
+        bcs.u8().serialize(res.data.week).toBase64(),
+        bcs
+          .vector(bcs.u8())
+          .serialize(Uint8Array.from(Buffer.from(res.data.signature, 'base64')))
+          .toBase64(),
+      ],
+    )
+    return await this.broadcast(msg)
+  }
 }

+ 31 - 30
src/decodeFunction.ts

@@ -163,12 +163,12 @@ function parse5(): void {
 
   const s = [
     'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
-    'lyGI4ysszsVX7tmLvqnUKhptwnDakAmSY2Xet8Sdt90=',
-    'QEIPAAAAAAA=',
-    'AAAAAAAAAAAAAAAAdnXQI1OzWD3V9Rml0R9tOF89kak=',
-    'AQ==',
+    '3q94txYi6eJFzU4BRaundwETCEiD5/iM04i7qTkyRpM=',
+    'ECcAAAAAAAA=',
+    'AAAAAAAAAAAAAAAA5pVZvzjokiM5j4YBo+nX4GRfmMA=',
+    'AA==',
     'AA==',
-    'AVg+DwAAAAAA',
+    'Af0mAAAAAAAA',
     'AQEAAAAAAAAA',
   ]
 
@@ -179,38 +179,39 @@ function parse5(): void {
   console.log(d0)
 
   const d1 = bcs
-    .object() // type
+    .vector(bcs.u64()) // type
     .parse(Uint8Array.from(Buffer.from(s[1], 'base64')))
   console.log(d1)
 
+  console.log()
   const d2 = bcs
-    .u64() // type
+    .option(bcs.u64()) // type
     .parse(Uint8Array.from(Buffer.from(s[2], 'base64')))
 
   console.log(d2)
 
-  const d3 = bcs
-    .address() // type
-    .parse(Uint8Array.from(Buffer.from(s[3], 'base64')))
-
-  console.log(d3)
-
-  const d4 = bcs
-    .bool() // type
-    .parse(Uint8Array.from(Buffer.from(s[4], 'base64')))
-  console.log('d4', d4)
-
-  const d5 = bcs
-    .option(bcs.u8()) // type
-    .parse(Uint8Array.from(Buffer.from(s[5], 'base64')))
-  console.log('d5', d5)
-  const d6 = bcs
-    .option(bcs.u64()) // type
-    .parse(Uint8Array.from(Buffer.from(s[6], 'base64')))
-  console.log('d6', d6)
-  const d7 = bcs
-    .option(bcs.u64()) // type
-    .parse(Uint8Array.from(Buffer.from(s[7], 'base64')))
-  console.log('d7', d7)
+  // const d3 = bcs
+  //   .address() // type
+  //   .parse(Uint8Array.from(Buffer.from(s[3], 'base64')))
+  //
+  // console.log(d3)
+  //
+  // const d4 = bcs
+  //   .bool() // type
+  //   .parse(Uint8Array.from(Buffer.from(s[4], 'base64')))
+  // console.log('d4', d4)
+  //
+  // const d5 = bcs
+  //   .option(bcs.u8()) // type
+  //   .parse(Uint8Array.from(Buffer.from(s[5], 'base64')))
+  // console.log('d5', d5)
+  // const d6 = bcs
+  //   .option(bcs.u64()) // type
+  //   .parse(Uint8Array.from(Buffer.from(s[6], 'base64')))
+  // console.log('d6', d6)
+  // const d7 = bcs
+  //   .option(bcs.u64()) // type
+  //   .parse(Uint8Array.from(Buffer.from(s[7], 'base64')))
+  // console.log('d7', d7)
 }
 parse5()

+ 11 - 52
src/onchain/finalTask.ts

@@ -3,12 +3,9 @@ import { InitiaClient } from '../InitiaClient'
 import { forEachAsync } from 'useless-helpers'
 
 async function startCheck(concurrency) {
-  const accountsRaw = await DBClient.instance.account.findMany({
+  const accountsRaw = await DBClient.instance.randomTask2.findMany({
     where: {
-      status: 4,
-    },
-    orderBy: {
-      lastRun: 'asc',
+      finish: 1,
     },
     take: 10000,
   })
@@ -19,47 +16,9 @@ async function startCheck(concurrency) {
       //   return
       // }
       const client = new InitiaClient(account.mnemonic, true)
-      // const gasGot = await client.lcd.bank.balanceByDenom(
-      //   account.address,
-      //   `move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff`,
-      // )
-      // if (Number(gasGot.amount) < 300000) {
-      //   // await DBClient.instance.account.update({
-      //   //   where: { id: account.id },
-      //   //   data: { status: -5 },
-      //   //   //可能领过还没到账的
-      //   // })
-      //   console.log(`${account.address}:balance not enough,${gasGot.amount}`)
-      //   return
-      // }
-      // if (!gasGot) {
-      //   console.log(`gas got:`, gasGot)
-      //   await DBClient.instance.account.update({
-      //     where: { id: account.id },
-      //     data: { status: -2 },
-      //     //可能领过还没到账的
-      //   })
-      //   return
-      // }
 
-      //roll dice 20xp
-      // const done = await client.week6task3()
-      // const done = await client.swapScript()
-      //99=done
-      // const done = await client.drawFood()
-      //swap 50xp
-      // const done = await client.tucSawap()
-      //mint 50xp
-      // const done = await client.week7task3()
-      // addLiquidity 50xp
-      const done = await client.week6task2()
-      if (done == `done`) {
-        console.log(`done work`)
-        await DBClient.instance.account.update({
-          where: { id: account.id },
-          data: { status: 3 },
-        })
-      }
+      const res = await client.claimWeek2()
+
       // else if (done == `undone`) {
       //   console.log(`undone work`)
       //   await DBClient.instance.account.update({
@@ -67,12 +26,12 @@ async function startCheck(concurrency) {
       //     data: { status: 3 },
       //   })
       // }
-      // if (done == `needTask`) {
-      //   await DBClient.instance.account.update({
-      //     where: { id: account.id },
-      //     data: { status: 5 },
-      //   })
-      // }
+      if (res == `done`) {
+        await DBClient.instance.randomTask2.update({
+          where: { id: account.id },
+          data: { finish: 2 },
+        })
+      }
     } catch (e) {
       // console.log(e)
       console.log(
@@ -85,4 +44,4 @@ async function startCheck(concurrency) {
   })
 }
 
-startCheck(200)
+startCheck(30)

+ 41 - 25
src/onchain/gasCollect.ts

@@ -1,6 +1,7 @@
 import { DBClient } from '../singletons'
 import { forEachAsync } from '../utils'
 import { InitiaClient } from '../InitiaClient'
+import { isForInOrOfStatement } from 'ts-api-utils'
 
 function chunkArray<T>(array: T[], chunkSize: number): T[][] {
   const result = []
@@ -12,49 +13,64 @@ function chunkArray<T>(array: T[], chunkSize: number): T[][] {
 
 // 使用示例:
 
-async function startCheck(concurrency) {
+async function startCheck() {
+  const token = 'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff'
+  // const token = 'uinit'
   const accountsRaw = await DBClient.instance.randomTask2.findMany({
     where: {
-      finish: 0,
+      finish: 2,
     },
     take: 10000,
   })
-  const needList = await DBClient.instance.account.findMany({
+  const needList = await DBClient.instance.randomTask2.findMany({
     where: {
-      status: -5,
+      // task1: 1,
+      // task4: 0,
+      finish: 1,
     },
     take: 10000,
   })
   const canSend = []
   // console.log(needList[0])
-  let index = 0
-  await forEachAsync(accountsRaw, concurrency, async account => {
-    // console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
-    // const account = chunked[0]
+  const index = 0
+  // await forEachAsync(accountsRaw, concurrency, async account => {
+  // console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
+  // const account = chunked[0]
+  for (let i = 0; i < needList.length; i++) {
+    console.log(`index:`, i)
     try {
-      const client = new InitiaClient(account.mnemonic, true)
-      const balances = await client.lcd.bank.balanceByDenom(
-        client.key.accAddress,
-        'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
+      const need = new InitiaClient(needList[i].mnemonic, true)
+
+      const sendTo = await need.lcd.bank.balanceByDenom(
+        needList[i].address,
+        token,
       )
+      if (Number(sendTo.amount) > 5000000) {
+        console.log(`skip ${needList[i].address}`)
+        continue
+      }
       // console.log(client.key.accAddress, Number(balances.amount))
-      if (Number(balances.amount) > 10000000) {
-        if (index < needList.length) {
-          index++
-          await client.transferGas(needList[index].address, 5000000)
-          console.log(`send to ${needList[index].address}`)
-
-          await DBClient.instance.account.update({
-            where: { id: needList[index].id },
-            data: { status: -4 },
-          })
+      for (let j = 0; j < 5; j++) {
+        const random = Math.floor(Math.random() * accountsRaw.length)
+        const client = new InitiaClient(accountsRaw[random].mnemonic, true)
+        const balances = await client.lcd.bank.balanceByDenom(
+          client.key.accAddress,
+          token,
+        )
+        if (Number(balances.amount) > 20000000) {
+          await client.transferGas(needList[index].address, 10000000)
+          // await client.transfer(needList[i].address, 10000000)
+          console.log(`send to ${needList[i].address}`)
+          break
         }
       }
     } catch (e) {
       console.log(e.message)
     }
-    //   return
-  })
+  }
+
+  //   return
+  // })
   // for (let i = 0; i < needList.length; i++) {
   //   const account = canSend[i]
   //   const client = new InitiaClient(account.mnemonic, true)
@@ -66,4 +82,4 @@ async function startCheck(concurrency) {
   // }
 }
 
-startCheck(100)
+startCheck()

+ 33 - 33
src/onchain/week3/randomWeek3.ts

@@ -25,7 +25,7 @@ async function startCheck(concurrency) {
         const axios = getAxiosClient(true)
 
         return await axios.get(
-          `https://xp-api.initiation-1.initia.xyz/xp/weekly/${account.address}/9`,
+          `https://xp-api.initiation-1.initia.xyz/xp/weekly/${account.address}/10`,
         )
       })
 
@@ -37,25 +37,25 @@ async function startCheck(concurrency) {
       return
     }
     //bridge_op_deposit
-    if (res.data.finished_tasks.includes(`bridge_op_deposit`)) {
+    if (res.data.finished_tasks.includes(`bridge_provide_stable`)) {
       account.task1 = 1
     } else {
       account.task1 = 0
     }
     //
-    if (res.data.finished_tasks.includes(`bridge_op_withdraw`)) {
+    if (res.data.finished_tasks.includes(`bridge_provide_virtual`)) {
       account.task2 = 1
     } else {
       account.task2 = 0
     }
     //bridge_ibc_transfer
-    if (res.data.finished_tasks.includes(`bridge_ibc_transfer`)) {
+    if (res.data.finished_tasks.includes(`bridge_swap_init`)) {
       account.task3 = 1
     } else {
       account.task3 = 0
     }
     //milkyway_mint_milk_init
-    if (res.data.finished_tasks.includes(`milkyway_mint_milk_init`)) {
+    if (res.data.finished_tasks.includes(`provide_liquidity_milk`)) {
       account.task4 = 1
     } else {
       account.task4 = 0
@@ -112,62 +112,62 @@ async function startCheck(concurrency) {
           `${index}/${accountsRaw.length}: processing ${account.address},task1`,
         )
 
-        const bool = await client.questBridge()
+        const bool = await client.quest2Task1()
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task1`,
           bool,
         )
-        if (bool === `done`) {
-          await DBClient.instance.randomTask2.update({
-            where: { id: account.id },
-            data: account,
-          })
-        }
+        // if (bool === `done`) {
+        //   await DBClient.instance.randomTask2.update({
+        //     where: { id: account.id },
+        //     data: account,
+        //   })
+        // }
       } else if (randomPick === 2) {
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task2`,
         )
-        const bool = await client.questTask2()
+        const bool = await client.quest2Task2()
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task2`,
           bool,
         )
-        if (bool === `done`) {
-          await DBClient.instance.randomTask2.update({
-            where: { id: account.id },
-            data: account,
-          })
-        }
+        // if (bool === `done`) {
+        //   await DBClient.instance.randomTask2.update({
+        //     where: { id: account.id },
+        //     data: account,
+        //   })
+        // }
       } else if (randomPick === 3) {
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task3`,
         )
-        const bool = await client.questTask3()
+        const bool = await client.quest2Task3()
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task3`,
           bool,
         )
-        if (bool === `done`) {
-          await DBClient.instance.randomTask2.update({
-            where: { id: account.id },
-            data: account,
-          })
-        }
+        // if (bool === `done`) {
+        //   await DBClient.instance.randomTask2.update({
+        //     where: { id: account.id },
+        //     data: account,
+        //   })
+        // }
       } else if (randomPick === 4) {
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task4`,
         )
-        const bool = await client.questTask4()
+        const bool = await client.quest2Task4()
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task4`,
           bool,
         )
-        if (bool === `done`) {
-          await DBClient.instance.randomTask2.update({
-            where: { id: account.id },
-            data: { task4: 1 },
-          })
-        }
+        // if (bool === `done`) {
+        //   await DBClient.instance.randomTask2.update({
+        //     where: { id: account.id },
+        //     data: { task4: 1 },
+        //   })
+        // }
       } else if (randomPick === 5) {
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task5`,

+ 3 - 2
src/swapTester.ts

@@ -12,7 +12,8 @@ const key = new MnemonicKey({
   mnemonic:
     // 'visual giant rely tooth recall explain vital tunnel snow road airport cake',
     // 'deal earth suggest craft impact vocal outdoor perfect winter nice unhappy lizard',
-    'educate shock jaguar unfold famous bag legend damp fence trumpet steak again body party carbon index daughter unusual miracle hen dove brand loan beach',
+    'recipe bind slow color mammal wave slush clump filter spot retire faculty area room enough pill become cluster cheap repair riot safe grit smile',
+  // 'educate shock jaguar unfold famous bag legend damp fence trumpet steak again body party carbon index daughter unusual miracle hen dove brand loan beach',
   // 'nut chalk dilemma solve same correct hood lava earn window under coral picture rabbit inform room maximum puppy mixed valley giggle glue mail frame',
   // 'recipe bind slow color mammal wave slush clump filter spot retire faculty area room enough pill become cluster cheap repair riot safe grit smile',
   // 'language tooth rug border arm essence badge rough ahead unaware bag night stay auto spawn february odor equip hub demand three setup used sentence',
@@ -52,7 +53,7 @@ async function main() {
   // await client.transferGas('init1yq7erc0hmemy7exhycdqx8j05jj46g0hgycw5g', 0.2)
   // await client.mintPart()
   // const res = await client.questBridge()
-  const res = await client.questTask4()
+  const res = await client.quest2Task1()
   // const res = ((new Date().valueOf() + 1500000) * 1000000).toString()
   console.log(res)
   // console.log(`1718639224520000000`)