Przeglądaj źródła

Merge remote-tracking branch 'origin/main'

Shawn Lu 1 rok temu
rodzic
commit
1e0043d3c5
8 zmienionych plików z 777 dodań i 592 usunięć
  1. 41 1
      src/BaseClient.ts
  2. 148 1
      src/InitiaClient.ts
  3. 1 1
      src/InitiaTask.ts
  4. 10 10
      src/LunchClient.ts
  5. 34 44
      src/decodeFunction.ts
  6. 5 5
      src/onchain/week3/randomWeek3.ts
  7. 4 3
      src/swapTester.ts
  8. 534 527
      yarn.lock

+ 41 - 1
src/BaseClient.ts

@@ -274,6 +274,46 @@ export abstract class BaseClient {
     const broadcast = await this.lcd.tx.broadcastAsync(signed)
     return broadcast.txhash
   }
+  async broadcastWaiting(msg: Msg | Msg[]) {
+    // const randLimit = 160000 + Math.floor(Math.random() * 10000)
+
+    const simulate = await this.lcd.tx.estimateFee(
+      [{ sequenceNumber: await this.wallet.sequence() }],
+      {
+        msgs: Array.isArray(msg) ? msg : [msg],
+      },
+    )
+    // console.log('simulate', simulate)
+    // console.log('simulate2', simulate.amount.toArray()[0].amount)
+    const signed = await this.wallet.createAndSignTx({
+      msgs: Array.isArray(msg) ? msg : [msg],
+      fee: new Fee(
+        simulate.gas_limit,
+        new Coins([
+          new Coin(
+            'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
+            simulate.amount.toArray()[0].amount,
+          ),
+        ]),
+      ),
+    })
+    // return `1`
+    // const signed2 = await this.wallet.createAndSignTx({
+    //   msgs: Array.isArray(msg) ? msg : [msg],
+    //   fee: new Fee(
+    //     Math.floor(Number(simulate) * 1.1),
+    //     new Coins([
+    //       new Coin(
+    //         'move/944f8dd8dc49f96c25fea9849f16436dcfa6d564eec802f3ef7f8b3ea85368ff',
+    //         Math.floor(Number(simulate) * 1.05),
+    //       ),
+    //     ]),
+    //   ),
+    // })
+    const broadcast = await this.lcd.tx.broadcast(signed)
+    console.log(broadcast.txhash)
+    return broadcast.txhash
+  }
   randomAmount(min: number, max: number) {
     return Math.floor(Math.random() * (max - min) + min)
   }
@@ -648,7 +688,7 @@ export abstract class BaseClient {
     return await this.broadcast(msg)
   }
   async newBridge2Civi() {
-    const random = this.randomAmount(1500000, 2000000)
+    const random = this.randomAmount(1000000, 2000000)
 
     const msg = new MsgInitiateTokenDeposit(
       this.key.accAddress,

+ 148 - 1
src/InitiaClient.ts

@@ -4,12 +4,14 @@ import {
   Coin,
   Coins,
   Fee,
-  Msg,
+  MsgExecute,
   MsgSend,
   MsgTransfer,
   Wallet,
 } from '@initia/initia.js'
 import polly from 'polly-js'
+import { LunchClient } from './LunchClient'
+import { sleep } from 'useless-helpers'
 
 export class InitiaClient extends InitiaTask {
   constructor(mnemonic: string, useProxy: boolean = false) {
@@ -930,10 +932,155 @@ export class InitiaClient extends InitiaTask {
     // const res = await this.newBridge2BlackWings()
   }
 
+  async week6task1() {
+    const lunch = new LunchClient(this.key.mnemonic)
+    await lunch.login()
+    const eggBalance = await lunch.getEggBalance()
+    if (Number(eggBalance) > 0) {
+      return `done`
+    }
+    //todo balanceChecker
+    const uinit = await this.lcd.bank.balanceByDenom(
+      this.key.accAddress,
+      'uinit',
+    )
+    if (Number(uinit.amount) < 1000000) {
+      return `notEnoughUinit`
+    }
+    const randomNum = this.randomAmount(1000000, 2000000)
+    const swapMsg = new MsgExecute(
+      this.key.accAddress,
+      '0x1',
+      'dex',
+      'swap_script',
+      [],
+      [
+        '2/BsSK85hOxtmuipqn27C7HnhKqbjEpWga9mDPhVjX0=', //liquidityTOken
+        'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=', //offerCoin
+        bcs.u64().serialize(randomNum).toBase64(), //offerAmount
+        bcs
+          .option(bcs.u64())
+          .serialize(this.randomAmount(1000, 2000))
+          .toBase64(),
+      ],
+    )
+    const swapHash = await this.broadcast(swapMsg)
+
+    //todo commit
+    await sleep(5000)
+    const submitRes = await lunch.submitOnchain(swapHash)
+
+    const noonWallet = new Wallet(this.noon, this.wallet.key)
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x225dd873693460a600cc8f592695ed15bbcca1a',
+      'egg_1',
+      'claim_all_v2',
+      [],
+      [`${bcs.u64().serialize(7).toBase64()}`],
+    )
+    const trans = await noonWallet.createAndSignTx({ msgs: [msg] })
+    const res = await this.noon.tx.broadcast(trans)
+    const txhash = res.txhash
+    //todo claim
+    await lunch.claimEgg(txhash)
+    return `worked`
+  }
   async week6task2() {
     const tucBalance = await this.tucana.bank.balanceByDenom(
       this.key.accAddress,
       'utuc',
     )
+    console.log(tucBalance.amount)
+    if (Number(tucBalance.amount) < 2000000) {
+      return `tuc`
+    }
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x298A9DC53EDA7750A5683960B01775D3A34DDB5F',
+      'router',
+      'add_liquidity',
+      [],
+      [
+        bcs
+          .u64()
+          .serialize(Number(tucBalance.amount) / 10)
+          .toBase64(),
+        '64WvP6wAJgs/gCqhuEQ9pXGrKKgjuk08mCVTuXJ2Jd8=',
+        bcs.address().serialize(this.wallet.key.accAddress).toBase64(),
+        'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
+        'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
+      ],
+    )
+    const tucanaWallet = new Wallet(this.tucana, this.wallet.key)
+    const simulate = await this.tucana.tx.estimateFee(
+      [{ sequenceNumber: await tucanaWallet.sequence() }],
+      {
+        msgs: [msg],
+        feeDenoms: ['utuc'],
+      },
+    )
+    const signed = await tucanaWallet.createAndSignTx({
+      msgs: [msg],
+      fee: new Fee(
+        simulate.gas_limit,
+        new Coins([new Coin('utuc', simulate.amount.toArray()[0].amount)]),
+      ),
+    })
+    try {
+      await this.tucana.tx.broadcast(signed)
+      return `done`
+    } catch (e) {
+      return `error`
+    }
+    // ["gIQeAAAAAAA=","64WvP6wAJgs/gCqhuEQ9pXGrKKgjuk08mCVTuXJ2Jd8=","AAAAAAAAAAAAAAAAfwBn58DHXySh7OLySf/MheBSfzg=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="]
+    //["AAk9AAAAAAA=","64WvP6wAJgs/gCqhuEQ9pXGrKKgjuk08mCVTuXJ2Jd8=","AAAAAAAAAAAAAAAAfwBn58DHXySh7OLySf/MheBSfzg=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="]
+  }
+
+  async week6task3() {
+    const civiInitBalance = await this.civi.bank.balanceByDenom(
+      this.key.accAddress,
+      'l2/afaa3f4e1717c75712f8e8073e41f051a4e516cd25daa82d948c4729388edefd',
+    )
+    if (Number(civiInitBalance.amount) < 500000) {
+      await this.newBridge2Civi()
+      return `civi`
+    }
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      'init1nyfj6va42hx32ew9nnhpurj075hmclahrjs2qe',
+      'civitia',
+      'roll_dice',
+      [],
+      [],
+    )
+    const civiWallet = new Wallet(this.civi, this.wallet.key)
+    const simulate = await this.civi.tx.estimateFee(
+      [{ sequenceNumber: await civiWallet.sequence() }],
+      {
+        msgs: [msg],
+        feeDenoms: [
+          'l2/afaa3f4e1717c75712f8e8073e41f051a4e516cd25daa82d948c4729388edefd',
+        ],
+      },
+    )
+    const signed = await civiWallet.createAndSignTx({
+      msgs: [msg],
+      fee: new Fee(
+        simulate.gas_limit,
+        new Coins([
+          new Coin(
+            'l2/afaa3f4e1717c75712f8e8073e41f051a4e516cd25daa82d948c4729388edefd',
+            simulate.amount.toArray()[0].amount,
+          ),
+        ]),
+      ),
+    })
+    try {
+      await this.civi.tx.broadcastAsync(signed)
+      return `done`
+    } catch (e) {
+      return `error`
+    }
   }
 }

+ 1 - 1
src/InitiaTask.ts

@@ -34,7 +34,7 @@ export abstract class InitiaTask extends JennieModule {
     //   .parse(Uint8Array.from(Buffer.from('QEtMAAAAAAA=', 'base64')))
     // console.log(amount)
     // return `done`
-    const randomNum = this.randomAmount(5000000, 5000000 * 2)
+    const randomNum = this.randomAmount(1000000, 2000000)
     const msg = new MsgExecute(
       this.key.accAddress,
       '0x1',

+ 10 - 10
src/lunchClient.ts → src/LunchClient.ts

@@ -106,13 +106,13 @@ export class LunchClient {
     ] = `Bearer ${resp.data.accessToken}`
     const xrplWallet = xrpl.Wallet.fromSeed(account.xrpPrivateKey)
     let needRegister = false
-    try {
-      await this.axiosClient.get('https://api.lunchlunch.xyz/v1/member')
-    } catch (e) {
-      if (e.response.status === 404) {
-        needRegister = true
-      }
-    }
+    // try {
+    //   await this.axiosClient.get('https://api.lunchlunch.xyz/v1/member')
+    // } catch (e) {
+    //   if (e.response.status === 404) {
+    //     needRegister = true
+    //   }
+    // }
     if (needRegister) {
       await this.axiosClient.post(
         'https://api.lunchlunch.xyz/v1/member/register',
@@ -146,10 +146,10 @@ export class LunchClient {
 
   async submitOnchain(txHash: string) {
     if (!this.isLogin) throw new Error('Please login first')
-    await this.axiosClient.post(
+    return await this.axiosClient.post(
       `https://api.lunchlunch.xyz/v1/dish/submit-action/onchain`,
       {
-        dishId: 8,
+        dishId: 7,
         txHash: txHash,
       },
     )
@@ -160,7 +160,7 @@ export class LunchClient {
     await this.axiosClient.post(
       `https://api.lunchlunch.xyz/v1/dish/submit-claim/egg`,
       {
-        dishId: 8,
+        dishId: 7,
         txHash: txHash,
       },
     )

+ 34 - 44
src/decodeFunction.ts

@@ -115,65 +115,55 @@ function parse5(): void {
   //   'CmNoYW5uZWwtMjU=',
   //   'AA==',
   // ]
-  const raw = [
-    '2+lWb+7Xy+Fy4RJ3INn8xwr0QQlVvARSifYjl59C9Bc=',
-    'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
-    'QEIPAAAAAAA=',
-    'AQwpDwAAAAAA',
-    'DgAAAAAAAAA=',
-    'AAAAAAAAAAAAAAAAwfIGiv3Te+HINdWz7IkKXwKsGQ4=',
-    'AA==',
-  ]
-  // const a = [
-  //   ('0x1::object::Object<0x1::fungible_asset::Metadata>',
-  //   '0x1::object::Object<0x1::fungible_asset::Metadata>',
-  //   'u64',
-  //   '0x1::option::Option<u64>',
-  //   'u64',
-  //   'address',
-  //   'vector<u8>'),
+
+  // const raw = [
+  //   'BQ==',
+  //   'QKroIsCES99i848oZJPjCeGMr11aDFUGU2Roat7L1LX8LqsTZL5TMJTv3saMfcvo3RjWMK1FtR+fzT715Z+bnh4=',
   // ]
-  const d4 = bcs
+  const s = [
+    'AQ==',
+    'QCzDqo9I8xICLNbNuDICoH4yoxq5QNUeDW+Soq/WbAVxITr1fs+aJpiQuwo3w411O2EogH6qDmVqKSpAAluH2HY=',
+  ]
+  const raw = ['CAAAAAAAAAA=']
+
+  const d0 = bcs
     .u64() // type
-    .parse(Uint8Array.from(Buffer.from(raw[4], 'base64')))
-  console.log('d4', d4)
-  // console.log(
-  //   bcs
-  //     .address()
-  //     .serialize('init1c8eqdzha6da7rjp46ke7ezg2tup2cxgwpazuse')
-  //     .toBase64(),
-  // )
-  //
-  // const d0 = bcs
-  //   .vector(bcs.u8()) // type
-  //   .parse(Uint8Array.from(Buffer.from(raw[0], 'base64')))
-  //
-  // console.log(d0)
-  //
+    .parse(Uint8Array.from(Buffer.from(raw[0], 'base64')))
+
+  console.log(d0)
+
   // const d1 = bcs
   //   .vector(bcs.u8()) // type
-  //   .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
+  //   .parse(Uint8Array.from(Buffer.from(s[1], 'base64')))
   // console.log(d1)
-
-  // const res = bcs.vector(bcs.u8()).serialize(Buffer.from(raw[1], 'base64'))
-  // console.log(res)
   //
-  // console.log(raw.toBase64())
+  // const res = bcs
+  //   .vector(bcs.u8())
+  //   .serialize(
+  //     Buffer.from(
+  //       '3ViG4aV7ED54UmN/QBn2rwhze3muJwLbN+T6sC7uPpo2ev36VsFEZF7oOwj2/qC/6Z1XnP8uxhj8cePQs1D/gQ==',
+  //       'base64',
+  //     ),
+  //   )
+  //
+  // console.log(res.toBase64())
+
   // const d2 = bcs
   //   .u8() // type
-  //   .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
+  //   .parse(Uint8Array.from(Buffer.from(raw[2], 'base64')))
   //
   // console.log(d2)
   //
   // const d3 = bcs
-  //   .u64()// type
-  //   .parse(Uint8Array.from(Buffer.from(raw[1], 'base64')))
+  //   .string() // type
+  //   .parse(Uint8Array.from(Buffer.from(raw[3], 'base64')))
   //
   // console.log(d3)
   //
-  // console.log(
-  //   bcs.string().serialize('init1c8eqdzha6da7rjp46ke7ezg2tup2cxgwpazuse').toBase64(),
-  // )
+  // const d4 = bcs
+  //   .string() // type
+  //   .parse(Uint8Array.from(Buffer.from(raw[4], 'base64')))
+  // console.log('d4', d4)
   //
   // const d5 = bcs
   //   .string() // type

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

@@ -1,13 +1,13 @@
-import { forEachAsync } from '../../utils'
 import { DBClient } from '../../singletons'
 import { InitiaClient } from '../../InitiaClient'
+import { forEachAsync } from 'useless-helpers'
 
 async function startCheck(concurrency) {
   const accountsRaw = await DBClient.instance.randomTask2.findMany({
     where: {
       finish: 0,
     },
-    take: 1,
+    take: 1200,
     orderBy: {
       id: 'asc',
     },
@@ -22,7 +22,7 @@ async function startCheck(concurrency) {
       const notDone = []
 
       if (account.task1 === 0) {
-        notDone.push(1)
+        // notDone.push(1)
       }
       if (account.task2 === 0) {
         notDone.push(2)
@@ -84,7 +84,7 @@ async function startCheck(concurrency) {
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task2`,
         )
-        const bool = await client.week5Task2()
+        const bool = await client.week6task2()
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task2`,
           bool,
@@ -99,7 +99,7 @@ async function startCheck(concurrency) {
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task3`,
         )
-        const bool = await client.week5Task3()
+        const bool = await client.week6task3()
         console.log(
           `${index}/${accountsRaw.length}: processing ${account.address},task3`,
           bool,

+ 4 - 3
src/swapTester.ts

@@ -12,8 +12,9 @@ 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',
-    // 'pumpkin frog pond gauge cat essay key employ shoulder keen stomach breeze history urge duty drink leisure crash genuine acid describe erosion ugly raise',
-    'neutral flight plug goddess marble champion message bottom gentle guilt ketchup way guide obey nominee panda sleep meadow scene sea fine cause upgrade only',
+    'language tooth rug border arm essence badge rough ahead unaware bag night stay auto spawn february odor equip hub demand three setup used sentence',
+  // 'camp rural essay together right oblige shine visa sketch garage legal crush argue calm soup egg forum luxury action cupboard fade myth gospel confirm',
+  // 'neutral flight plug goddess marble champion message bottom gentle guilt ketchup way guide obey nominee panda sleep meadow scene sea fine cause upgrade only',
 })
 console.log('mnemonic:', key.mnemonic)
 // mnemonic: beauty sniff protect...
@@ -47,7 +48,7 @@ async function main() {
   // console.log(a)
   // await client.transferGas('init1yq7erc0hmemy7exhycdqx8j05jj46g0hgycw5g', 0.2)
   // await client.mintPart()
-  const res = await client.week5Task1()
+  const res = await client.week6task1()
   // const res = ((new Date().valueOf() + 1500000) * 1000000).toString()
   console.log(res)
   // console.log(`1718639224520000000`)

Plik diff jest za duży
+ 534 - 527
yarn.lock


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików