faucet.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { forEachAsync, getAxiosClient } from '../utils'
  2. import { getAltchaPayload, getRecaptcha, solveHCaptcha } from './captcha'
  3. import { DBClient } from '../singletons'
  4. import { Status } from '../models/Status'
  5. export async function faucetAccount(address: string) {
  6. const client = getAxiosClient(true)
  7. const altcha = await getAltchaPayload(client)
  8. const hCaptcha = await solveHCaptcha(address)
  9. try {
  10. const res = await client.post(
  11. `https://faucet-api.initiation-1.initia.xyz/claim`,
  12. {
  13. address: address,
  14. altcha_payload: altcha,
  15. denom: 'uinit',
  16. h_captcha: hCaptcha,
  17. },
  18. )
  19. console.log(JSON.stringify(res.data))
  20. } catch (e) {
  21. console.log(e)
  22. throw e
  23. }
  24. }
  25. async function startFaucet(concurrency = 10) {
  26. const accountsRaw = await DBClient.instance.account.findMany({
  27. where: {
  28. status: Status.Inited,
  29. },
  30. })
  31. const accounts = accountsRaw
  32. // .filter(account => account.id)
  33. await forEachAsync(accounts, concurrency, async (account, index) => {
  34. console.log(`${index}/${accounts.length}: processing ${account.address}`)
  35. try {
  36. await faucetAccount(account.address)
  37. await DBClient.instance.account.update({
  38. where: { id: account.id },
  39. data: { status: Status.Fauceted },
  40. })
  41. } catch (e) {
  42. console.log(e)
  43. await DBClient.instance.account.update({
  44. where: { id: account.id },
  45. data: { status: Status.FaucetFailed, message: e.message },
  46. })
  47. }
  48. })
  49. }
  50. await startFaucet(2)