hel 1 жил өмнө
parent
commit
609a9c776f

+ 1 - 0
package.json

@@ -40,6 +40,7 @@
     "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",
+    "generateRandomW2": "yarn build && node build/src/onchain/week2/generateRandomW2.js",
     "randomTask": "yarn build && node build/src/onchain/randomTask.js",
     "finalTask": "yarn build && node build/src/onchain/finalTask.js",
     "mintJennie": "yarn build && node build/src/onchain/mintJennie.js",

+ 13 - 0
prisma/schema.prisma

@@ -33,3 +33,16 @@ model RandomTask {
   task6    Int    @default(0)
   finish   Int    @default(0)
 }
+
+model RandomTask2 {
+  id       Int    @id @default(autoincrement())
+  mnemonic String @db.VarChar(255)
+  address  String @db.VarChar(100)
+  task1    Int    @default(0)
+  task2    Int    @default(0)
+  task3    Int    @default(0)
+  task4    Int    @default(0)
+  task5    Int    @default(0)
+  task6    Int    @default(0)
+  finish   Int    @default(0)
+}

+ 4 - 4
src/BaseClient.ts

@@ -19,11 +19,11 @@ 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://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/',
+  // 'https://testnet-initia-api.lavenderfive.com/',
+  // 'https://api.initiation.test.pfc.zone/',
 ]
 
 export abstract class BaseClient {

+ 17 - 2
src/InitiaTask.ts

@@ -144,6 +144,11 @@ export abstract class InitiaTask extends JennieModule {
     }
     const usdcAmount = await this.getUsdcAmount()
 
+    if (Number(usdcAmount) < 1000) {
+      await this.swapScript()
+      return `needMint`
+    }
+
     const randomValidator =
       validatorArray[Math.floor(Math.random() * validatorArray.length)]
     // console.log(bcs.u64().serialize(usdcAmount).toBase64())
@@ -184,7 +189,10 @@ export abstract class InitiaTask extends JennieModule {
     }
     //move/b134ae6786f10ef74294e627d2519b63b7c742a6735f98682929fea9a84744d2
     const usdcAmount = await this.getTiaAmount()
-
+    if (Number(usdcAmount) < 1000) {
+      await this.swapScript()
+      return `needMint`
+    }
     const randomValidator =
       validatorArray[Math.floor(Math.random() * validatorArray.length)]
     // console.log(bcs.u64().serialize(usdcAmount).toBase64())
@@ -225,7 +233,10 @@ export abstract class InitiaTask extends JennieModule {
     }
 
     const usdcAmount = await this.getEthAmount()
-
+    if (Number(usdcAmount) < 1000) {
+      await this.swapScript()
+      return `needMint`
+    }
     const randomValidator =
       validatorArray[Math.floor(Math.random() * validatorArray.length)]
     // console.log(bcs.u64().serialize(usdcAmount).toBase64())
@@ -285,6 +296,10 @@ export abstract class InitiaTask extends JennieModule {
   async claimReward() {
     const axiosClient = getAxiosClient(true)
 
+    // const res = await axiosClient.get('https://api.ipify.org?format=json')
+    // console.log(res.data.ip)
+    // return ``
+
     const data = await axiosClient.get(
       `https://b545809c-5562-4e60-b5a1-22e83df57748.initiation-1.mesa-rest.ue1-prod.newmetric.xyz/initia/mstaking/v1/delegations/${this.key.accAddress}`,
     )

+ 17 - 2
src/JennieModule.ts

@@ -6,7 +6,22 @@ export abstract class JennieModule extends BaseClient {
   protected constructor(mnemonic: string, useProxy: boolean = false) {
     super(mnemonic, useProxy)
   }
+
+  async getXpAmount() {
+    const viewResult = await this.lcd.move.viewFunction(
+      '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
+      'initia_xp',
+      'get_xp_amount',
+      undefined,
+      [bcs.address().serialize(this.key.accAddress).toBase64()],
+    )
+    return viewResult
+  }
   async drawFood() {
+    const xp = await this.getXpAmount()
+    if (Number(xp) < 200) {
+      return `done`
+    }
     const msg = new MsgExecute(
       this.key.accAddress,
       '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba',
@@ -16,7 +31,7 @@ export abstract class JennieModule extends BaseClient {
       ['AQ=='],
     )
 
-    await this.broadcast(msg)
+    return await this.broadcast(msg)
   }
 
   async feedJennie() {
@@ -28,7 +43,7 @@ export abstract class JennieModule extends BaseClient {
       [],
       ['AQ=='],
     )
-    await this.broadcast(msg)
+    return await this.broadcast(msg)
   }
 
   async mintJennie() {

+ 1 - 1
src/onchain/randomTask.ts

@@ -106,4 +106,4 @@ async function startCheck(concurrency) {
   })
 }
 
-startCheck(120)
+startCheck(100)

+ 53 - 0
src/onchain/week2/generateRandomW2.ts

@@ -0,0 +1,53 @@
+import { DBClient } from '../../singletons'
+import { GroupProposal } from '@initia/initia.js'
+import Status = GroupProposal.Status
+import { sleep } from '../../utils'
+
+async function startCheck() {
+  const count = await DBClient.instance.randomTask.count({
+    where: {
+      finish: 3,
+    },
+  })
+  if (count < 200) {
+    console.log(`waiting for more accounts`)
+    await sleep(1000 * 60 * 60)
+  }
+  const accountsRaw = await DBClient.instance.randomTask.findMany({
+    where: {
+      finish: 3,
+    },
+    take: 20000,
+  })
+  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.randomTask2.createMany({
+        data: raw,
+        skipDuplicates: true,
+      })
+      // for (const account of accountsRaw) {
+      await tx.randomTask.updateMany({
+        where: { id: { in: id } },
+        data: { finish: 4 },
+      })
+      // }
+    })
+  } catch (e) {
+    console.log(e)
+    // await DBClient.instance.account.update({
+    //   where: { id: account.id },
+    //   data: { status: Status.MayQueued, message: e.message },
+    // })
+  }
+}
+
+startCheck()

+ 121 - 0
src/onchain/week2/randomWeek2.ts

@@ -0,0 +1,121 @@
+import { forEachAsync } from '../../utils'
+import { DBClient } from '../../singletons'
+import { InitiaClient } from '../../InitiaClient'
+
+async function startCheck(concurrency) {
+  const accountsRaw = await DBClient.instance.randomTask2.findMany({
+    where: {
+      finish: 0,
+    },
+    take: 10000,
+  })
+  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.task1 === 0) {
+        notDone.push(1)
+      }
+      if (account.task2 === 0) {
+        notDone.push(2)
+      }
+      if (account.task3 === 0) {
+        notDone.push(3)
+      }
+      if (account.task4 === 0) {
+        notDone.push(4)
+      }
+      if (account.task5 === 0) {
+        notDone.push(5)
+      }
+      if (account.task6 === 0) {
+        notDone.push(6)
+      }
+
+      console.log(`notDone`, notDone)
+
+      if (notDone.length === 0) {
+        await DBClient.instance.randomTask2.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.randomTask2.update({
+        //     where: { id: account.id },
+        //     data: { task2: 1 },
+        //   })
+        // }
+      } else if (randomPick === 3) {
+        console.log(`task3`)
+        //todo feed
+        const bool = await client.drawFood()
+        console.log(bool)
+        if (bool == `done`) {
+          await DBClient.instance.randomTask2.update({
+            where: { id: account.id },
+            data: { task3: 1 },
+          })
+        }
+      } else if (randomPick === 4) {
+        console.log(`task4`)
+        const bool = await client.stakeSingle()
+
+        if (bool == `done`) {
+          await DBClient.instance.randomTask2.update({
+            where: { id: account.id },
+            data: { task4: 1 },
+          })
+        }
+      } else if (randomPick === 5) {
+        console.log(`task5`)
+        const bool = await client.stakeTiaSingle()
+
+        console.log(bool)
+        if (bool == `done`) {
+          await DBClient.instance.randomTask2.update({
+            where: { id: account.id },
+            data: { task5: 1 },
+          })
+        }
+      } else if (randomPick === 6) {
+        console.log(`task6`)
+        const bool = await client.stakeEthSingle()
+        if (bool == `done`) {
+          await DBClient.instance.randomTask2.update({
+            where: { id: account.id },
+            data: { task6: 1 },
+          })
+        }
+      } else if (randomPick === 1) {
+        console.log(`task6`)
+        const bool = await client.claimableXp()
+        if (bool == `done`) {
+          await DBClient.instance.randomTask2.update({
+            where: { id: account.id },
+            data: { task1: 1 },
+          })
+        }
+      }
+    } catch (e) {
+      console.log(e)
+      // await DBClient.instance.account.update({
+      //   where: { id: account.id },
+      //   data: { status: Status.MayQueued, message: e.message },
+      // })
+    }
+  })
+}
+
+startCheck(120)

+ 1 - 1
src/swapTester.ts

@@ -33,7 +33,7 @@ const lcd = new LCDClient('https://api-initia-testnet.whispernode.com/', {
 async function main() {
   const client = new InitiaClient(key.mnemonic,false)
   // await client.nameRegister()
-  await client.claimableXp()
+  await client.getXpAmount()
   // await client.mintPart()
 }
 main()

+ 4 - 3
src/utils/index.ts

@@ -21,7 +21,7 @@ export function getProxyUrl() {
 }
 
 export function getAxiosClient(useProxy: boolean) {
-  const pass = `test1234_session-${generateRandomString(8)}_lifetime-20m`
+  const pass = `test1234_session-${generateRandomString(8)}_lifetime-1h`
   const proxyAgent = useProxy
     ? new HttpsProxyAgent(`http://tuxla:${pass}@geo.iproyal.com:12321`)
     : undefined
@@ -34,12 +34,13 @@ export function getAxiosClient(useProxy: boolean) {
         '"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/',
+      // 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',
     },
+    withCredentials: true,
   })
 }