hel 1 rok pred
rodič
commit
be853c49a9

+ 33 - 13
src/BaseClient.ts

@@ -42,16 +42,16 @@ export abstract class BaseClient {
     const rpc = rpcUrl[Math.floor(Math.random() * rpcUrl.length)]
     this.rpcUrlUsing = rpc
     const pass = `test1234_session-${generateRandomString(8)}_lifetime-20m`
-    // const proxyAgent = useProxy
-    //   ? new HttpsProxyAgent(`http://tuxla:${pass}@geo.iproyal.com:12321`)
-    //   : undefined
+    const proxyAgent = useProxy
+      ? new HttpsProxyAgent(`http://tuxla:${pass}@geo.iproyal.com:12321`)
+      : undefined
     const username = `u3e4c2852572e05c5-zone-custom-session-${generateRandomString(
       9,
     )}-sessTime-20`
     const password = 'u3e4c2852572e05c5'
-    const proxyAgent = new HttpsProxyAgent(
-      `http://${username}:${password}@43.152.113.55:2334`,
-    )
+    // const proxyAgent = new HttpsProxyAgent(
+    //   `http://${username}:${password}@43.152.113.55:2334`,
+    // )
 
     const requester = new APIRequester(rpc, {
       httpsAgent: proxyAgent,
@@ -142,8 +142,12 @@ export abstract class BaseClient {
   }
   async checkEthSwaped() {
     const tokens = await this.checkBalance()
-    const usdc = tokens.filter(token => token.denom === 'ueth')[0]
-    return !!usdc
+    try {
+      const usdc = tokens.filter(token => token.denom === 'ueth')[0]
+      return !!usdc
+    } catch (e) {
+      return false
+    }
   }
 
   async getUsdcAmount() {
@@ -151,17 +155,33 @@ export abstract class BaseClient {
     const usdc = tokens.filter(token => token.denom === 'uusdc')[0]
     return usdc.amount
   }
+  async getInitAmount() {
+    const tokens = await this.checkBalance()
+    try {
+      const usdc = tokens.filter(token => token.denom === 'uinit')[0]
+      return usdc.amount
+    } catch (e) {
+      return 0
+    }
+  }
   async getTiaAmount() {
     const tokens = await this.checkBalance()
-    const usdc = tokens.filter(token => token.denom === 'utia')[0]
-    return usdc.amount
+    try {
+      const usdc = tokens.filter(token => token.denom === 'utia')[0]
+      return usdc.amount
+    } catch (e) {
+      return 0
+    }
   }
-  //todo
   async getEthAmount() {
     const tokens = await this.checkBalance()
     console.log(tokens)
-    const usdc = tokens.filter(token => token.denom === 'ueth')[0]
-    return usdc.amount
+    try {
+      const usdc = tokens.filter(token => token.denom === 'ueth')[0]
+      return usdc.amount
+    } catch (e) {
+      return 0
+    }
   }
 
   async bridge() {

+ 10 - 1
src/InitiaClient.ts

@@ -17,6 +17,15 @@ export class InitiaClient extends InitiaTask {
       msgs: [msg],
     })
     const broadcast = await this.lcd.tx.broadcast(signed)
-    console.log(broadcast)
+    return broadcast.txhash
+  }
+
+  async week2Task2(toAddr: string) {
+    const uinitAmount = await this.getInitAmount()
+    if (Number(uinitAmount) > 0) {
+      return `done`
+    } else {
+      return await this.transfer(toAddr, 1)
+    }
   }
 }

+ 12 - 5
src/InitiaTask.ts

@@ -1,6 +1,7 @@
 import { JennieModule } from './JennieModule'
 import {
   bcs,
+  Coins,
   MsgDelegate,
   MsgExecute,
   MsgWithdrawDelegatorReward,
@@ -134,8 +135,10 @@ export abstract class InitiaTask extends JennieModule {
   async stakeSingle() {
     const res = await this.getDelegationInfo()
     const flag = res.some((item: any) => {
+      const coin: Coins = item.balance
+      const data = coin.toData()
       return (
-        item.balance.denom()[0] ===
+        data[0].denom ===
         'move/dbf06c48af3984ec6d9ae8a9aa7dbb0bb1e784aa9b8c4a5681af660cf8558d7d'
       )
     })
@@ -179,8 +182,10 @@ export abstract class InitiaTask extends JennieModule {
   async stakeTiaSingle() {
     const res = await this.getDelegationInfo()
     const flag = res.some((item: any) => {
+      const coin: Coins = item.balance
+      const data = coin.toData()
       return (
-        item.balance.denom()[0] ===
+        data[0].denom ===
         'move/b134ae6786f10ef74294e627d2519b63b7c742a6735f98682929fea9a84744d2'
       )
     })
@@ -190,7 +195,7 @@ export abstract class InitiaTask extends JennieModule {
     //move/b134ae6786f10ef74294e627d2519b63b7c742a6735f98682929fea9a84744d2
     const usdcAmount = await this.getTiaAmount()
     if (Number(usdcAmount) < 1000) {
-      await this.swapScript()
+      await this.swapTiaScript()
       return `needMint`
     }
     const randomValidator =
@@ -223,8 +228,10 @@ export abstract class InitiaTask extends JennieModule {
   async stakeEthSingle() {
     const res = await this.getDelegationInfo()
     const flag = res.some((item: any) => {
+      const coin: Coins = item.balance
+      const data = coin.toData()
       return (
-        item.balance.denom()[0] ===
+        data[0].denom ===
         'move/a2b0d3c8e53e379ede31f3a361ff02716d50ec53c6b65b8c48a81d5b06548200'
       )
     })
@@ -234,7 +241,7 @@ export abstract class InitiaTask extends JennieModule {
 
     const usdcAmount = await this.getEthAmount()
     if (Number(usdcAmount) < 1000) {
-      await this.swapScript()
+      await this.swapEthScript()
       return `needMint`
     }
     const randomValidator =

+ 23 - 22
src/JennieModule.ts

@@ -43,29 +43,30 @@ export abstract class JennieModule extends BaseClient {
         undefined,
         [bcs.address().serialize(this.key.accAddress).toBase64()],
       )
-    const stageInfo: {
-      current_stage: number
-      stage_interval: number
-      start_timestamp: number
-    } = await this.lcd.move.viewFunction(
-      '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
-      'jennie',
-      'stage_info',
-      undefined,
-      [],
-    )
+    // const stageInfo: {
+    //   current_stage: number
+    //   stage_interval: number
+    //   start_timestamp: number
+    // } = await this.lcd.move.viewFunction(
+    //   '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+    //   'jennie',
+    //   'stage_info',
+    //   undefined,
+    //   [],
+    // )
     const kt = Number(viewResult.update_at)
-    const currentStage = stageInfo.current_stage
-    const stageInternal = stageInfo.stage_interval
-    const stTimestamp = stageInfo.start_timestamp
-    const yt =
-      stTimestamp +
-      Math.floor(((currentStage ?? 1) - 1) / 7) * stageInternal * 7
-    const St =
-      stTimestamp +
-      (Math.floor(((currentStage ?? 1) - 1) / 7) + 1) * stageInternal * 7
-    const canFeed = kt < St && kt > yt ? St : !1
-    if (!canFeed) {
+    const now = 1716523200
+    // const currentStage = stageInfo.current_stage
+    // const stageInternal = stageInfo.stage_interval
+    // const stTimestamp = stageInfo.start_timestamp
+    // const yt =
+    //   stTimestamp +
+    //   Math.floor(((currentStage ?? 1) - 1) / 7) * stageInternal * 7
+    // const St =
+    //   stTimestamp +
+    //   (Math.floor(((currentStage ?? 1) - 1) / 7) + 1) * stageInternal * 7
+    // const canFeed = kt < Math.floor(yt / 1000000)
+    if (!(kt < now)) {
       return `done`
     }
     const rep = await getAxiosClient(true).get(

+ 11 - 11
src/onchain/week2/randomWeek2.ts

@@ -48,19 +48,19 @@ async function startCheck(concurrency) {
 
       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.randomTask2.update({
-        //     where: { id: account.id },
-        //     data: { task2: 1 },
-        //   })
-        // }
+        console.log(`task2`)
+        const bool = await client.week2Task2(account.toAddress)
+        console.log(bool)
+        if (bool == `done`) {
+          await DBClient.instance.randomTask2.update({
+            where: { id: account.id },
+            data: { task2: 1 },
+          })
+        }
       } else if (randomPick === 3) {
         console.log(`task3`)
-        const bool = await client.drawFood()
-        await client.feedJennie()
+        await client.drawFood()
+        const bool = await client.feedJennie()
         console.log(bool)
         if (bool == `done`) {
           await DBClient.instance.randomTask2.update({

+ 6 - 3
src/swapTester.ts

@@ -4,7 +4,8 @@ import { InitiaClient } from './InitiaClient'
 const key = new MnemonicKey({
   mnemonic:
     // 'deal earth suggest craft impact vocal outdoor perfect winter nice unhappy lizard',
-    'language tooth rug border arm essence badge rough ahead unaware bag night stay auto spawn february odor equip hub demand three setup used sentence',
+    // 'language tooth rug border arm essence badge rough ahead unaware bag night stay auto spawn february odor equip hub demand three setup used sentence',
+    'grass spawn flavor cancel borrow only furnace must planet they hub mask dignity rotate report bubble nurse renew ten eagle purity mass dial fever',
 })
 console.log('mnemonic:', key.mnemonic)
 // mnemonic: beauty sniff protect...
@@ -31,9 +32,11 @@ const lcd = new LCDClient('https://api-initia-testnet.whispernode.com/', {
 // )
 
 async function main() {
-  const client = new InitiaClient(key.mnemonic,false)
+  const client = new InitiaClient(key.mnemonic, false)
   // await client.nameRegister()
-  await client.getDelegationInfo()
+  // await client.drawFood()
+  const a = await client.claimableXp()
+  console.log(a)
   // await client.mintPart()
 }
 main()