import { forEachAsync, getAxiosClient } from '../utils' import { getAltchaPayload, getRecaptcha, solveHCaptcha } from './captcha' import { DBClient } from '../singletons' import { Status } from '../models/Status' export async function faucetAccount(address: string) { const client = getAxiosClient(true) const altcha = await getAltchaPayload(client) const hCaptcha = await solveHCaptcha(address) try { const res = await client.post( `https://faucet-api.initiation-1.initia.xyz/claim`, { address: address, altcha_payload: altcha, denom: 'uinit', h_captcha: hCaptcha, }, ) console.log(JSON.stringify(res.data)) } catch (e) { console.log(e) throw e } } async function startFaucet(concurrency = 10) { const accountsRaw = await DBClient.instance.account.findMany({ where: { status: Status.Inited, }, }) const accounts = accountsRaw // .filter(account => account.id) await forEachAsync(accounts, concurrency, async (account, index) => { console.log(`${index}/${accounts.length}: processing ${account.address}`) try { await faucetAccount(account.address) await DBClient.instance.account.update({ where: { id: account.id }, data: { status: Status.Fauceted }, }) } catch (e) { console.log(e) await DBClient.instance.account.update({ where: { id: account.id }, data: { status: Status.FaucetFailed, message: e.message }, }) } }) } await startFaucet(2)