faucetTuc.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { getAxiosClient } from '../utils'
  2. import { DBClient } from '../singletons'
  3. import { Status } from '../models/Status'
  4. import polly from 'polly-js'
  5. import { forEachAsync } from 'useless-helpers'
  6. async function faucetTuc(address: string) {
  7. await polly()
  8. .waitAndRetry(3)
  9. .executeForPromise(async () => {
  10. const client = getAxiosClient(true)
  11. const res = await client.post(
  12. 'https://birdee-faucet.testnet.mesoops.net/',
  13. {
  14. address: address,
  15. coins: ['10000000utuc'],
  16. },
  17. )
  18. if (res.data.error) {
  19. throw new Error(res.data.error)
  20. }
  21. })
  22. }
  23. async function startFaucet(concurrency: number) {
  24. const accounts = await DBClient.instance.faucet.findMany()
  25. await forEachAsync(accounts, concurrency, async account => {
  26. try {
  27. await faucetTuc(account.address)
  28. await DBClient.instance.faucet.update({
  29. where: { id: account.id },
  30. data: { tucStatus: Status.Fauceted },
  31. })
  32. } catch (e) {
  33. console.log(e)
  34. await DBClient.instance.faucet.update({
  35. where: { id: account.id },
  36. data: { tucStatus: Status.FaucetFailed },
  37. })
  38. }
  39. })
  40. }
  41. await startFaucet(5)