3
0

2 Commits b0e53fd664 ... 1e0043d3c5

Autor SHA1 Nachricht Datum
  Shawn Lu 1e0043d3c5 Merge remote-tracking branch 'origin/main' vor 1 Jahr
  Shawn Lu d74c811ee7 remove comment vor 1 Jahr
1 geänderte Dateien mit 37 neuen und 22 gelöschten Zeilen
  1. 37 22
      src/faucet/faucet.ts

+ 37 - 22
src/faucet/faucet.ts

@@ -1,11 +1,12 @@
 import { ethers } from 'ethers'
 import { ethers } from 'ethers'
-import { forEachAsync, getAxiosClient } from '../utils'
+import { getAxiosClient } from '../utils'
 import { getAltchaPayload } from './captcha'
 import { getAltchaPayload } from './captcha'
 import { DBClient } from '../singletons'
 import { DBClient } from '../singletons'
 import { InitiaClient } from '../InitiaClient'
 import { InitiaClient } from '../InitiaClient'
 import { Faucet } from '@prisma/client'
 import { Faucet } from '@prisma/client'
 import polly from 'polly-js'
 import polly from 'polly-js'
 import cron from 'node-cron'
 import cron from 'node-cron'
+import { forEachAsync } from 'useless-helpers'
 
 
 export async function faucetAccount(address: string, passportPK: string) {
 export async function faucetAccount(address: string, passportPK: string) {
   const passportWallet = new ethers.Wallet(passportPK)
   const passportWallet = new ethers.Wallet(passportPK)
@@ -63,32 +64,45 @@ https://faucet-api.initiation-1.initia.xyz/status/${passportWallet.address}`)
   }
   }
 }
 }
 
 
+// [0,1,2,3,4,5,6,7,8]
+// 5
+// i * 4 + 0
+// i * 4 + 1
+// i * 4 + 2
+// i * 4 + 3
+
 async function checkFaucetBalance() {
 async function checkFaucetBalance() {
   const accounts = await DBClient.instance.faucet.findMany({
   const accounts = await DBClient.instance.faucet.findMany({
-    where: { balance: 0 },
+    where: { balance: { lt: 1000000 } },
+    // take: 50,
   })
   })
-  await forEachAsync(accounts, 10, async (account, index) => {
-    try {
-      console.log(`checking ${index}/${accounts.length}`)
-      await polly()
-        .waitAndRetry(5)
-        .executeForPromise(async () => {
-          const client = new InitiaClient(account.mnemonic, true)
-          const gasAmount = await client.getGasAmount()
-          console.log(index, gasAmount)
-          await DBClient.instance.faucet.update({
-            where: { id: account.id },
-            data: { balance: gasAmount },
+  await forEachAsync(
+    accounts,
+    20,
+    async (account, index) => {
+      try {
+        console.log(`checking ${index}/${accounts.length}`)
+        await polly()
+          .waitAndRetry(5)
+          .executeForPromise(async () => {
+            const client = new InitiaClient(account.mnemonic, true)
+            const gasAmount = await client.getGasAmount()
+            console.log(index, gasAmount)
+            await DBClient.instance.faucet.update({
+              where: { id: account.id },
+              data: { balance: gasAmount },
+            })
           })
           })
+      } catch (e) {
+        console.log(`${index}: error`, e)
+        await DBClient.instance.faucet.update({
+          where: { id: account.id },
+          data: { balance: 0 },
         })
         })
-    } catch (e) {
-      console.log(`${index}: error`, e)
-      await DBClient.instance.faucet.update({
-        where: { id: account.id },
-        data: { balance: 0 },
-      })
-    }
-  })
+      }
+    },
+    { timeout: 10000 },
+  )
 }
 }
 
 
 function shuffleArray(array) {
 function shuffleArray(array) {
@@ -146,6 +160,7 @@ async function startFaucet(concurrency: number) {
               availableFrom: new Date(
               availableFrom: new Date(
                 new Date().getTime() + 24 * 60 * 60 * 1000,
                 new Date().getTime() + 24 * 60 * 60 * 1000,
               ),
               ),
+              message: 'success',
             },
             },
           })
           })
         })
         })