test.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { AccAddress, MnemonicKey, RawKey } from '@initia/initia.js'
  2. import { InitiaClient } from './InitiaClient'
  3. import polly from 'polly-js'
  4. import { v4 as uuidv4 } from 'uuid'
  5. import { DBClient } from './singletons'
  6. import { solveChallenge } from 'shawnlu96-altcha-lib'
  7. import { forEachAsync, getAxiosClient, getProxyAgent } from './utils'
  8. import { getAltchaPayload, solveHCaptcha } from './faucet/captcha'
  9. import axios from 'axios'
  10. import toHex = AccAddress.toHex
  11. import xrpl from 'xrpl'
  12. import { ethers } from 'ethers'
  13. // await polly()
  14. // .waitAndRetry(4)
  15. // .executeForPromise(async () => {
  16. // const key = new MnemonicKey()
  17. // console.log(key.accAddress)
  18. // console.log(key.mnemonic)
  19. // await faucetAccount(key.accAddress)
  20. // })
  21. async function createAccounts(count: number) {
  22. const accounts = []
  23. for (let i = 0; i < count; i++) {
  24. console.log(`creating account ${i}/${count}`)
  25. const key = new MnemonicKey()
  26. const account = {
  27. mnemonic: key.mnemonic,
  28. address: key.accAddress,
  29. }
  30. accounts.push(account)
  31. }
  32. await DBClient.instance.account.createMany({ data: accounts })
  33. }
  34. async function createDummyAddresses() {
  35. let total = 0
  36. function getTargets() {
  37. return DBClient.instance.randomTask2.findMany({
  38. where: {
  39. toAddress: null,
  40. },
  41. take: 40,
  42. })
  43. }
  44. let targets = await getTargets()
  45. while (targets.length > 0) {
  46. await forEachAsync(targets, 15, async task => {
  47. const key = new MnemonicKey()
  48. task.toAddress = key.accAddress
  49. await DBClient.instance.randomTask2.update({
  50. where: { id: task.id },
  51. data: { toAddress: key.accAddress },
  52. })
  53. })
  54. total += targets.length
  55. console.log(total)
  56. targets = await getTargets()
  57. }
  58. }
  59. async function testFaucet() {
  60. const key = new MnemonicKey()
  61. const evmWallet = new ethers.Wallet(key.privateKey.toString('hex'))
  62. const evmAddress = toHex(key.accAddress)
  63. const message = JSON.stringify({ signedAt: new Date().toISOString() })
  64. const duid = uuidv4().toUpperCase()
  65. const client = axios.create({
  66. headers: {
  67. 'user-agent':
  68. 'Lunch/1.0 (xyz.lunchlunch.app; build:41; iOS 17.4.1) Alamofire/5.8.0',
  69. 'lunch-app-version': 41,
  70. 'lunch-fiat-currency': 'USD',
  71. 'lunch-app-duid': duid,
  72. },
  73. })
  74. const resp = await client.post('https://api.lunchlunch.xyz/v1/auth/sign-in', {
  75. walletAddress: evmWallet.address,
  76. signedMessage: await evmWallet.signMessage(message),
  77. rawMessage: message,
  78. })
  79. console.log(resp.data)
  80. client.defaults.headers['authorization'] = `Bearer ${resp.data.accessToken}`
  81. const register = await client.post(
  82. 'https://api.lunchlunch.xyz/v1/member/register',
  83. {
  84. evmWalletAddress: evmWallet.address,
  85. initiaWalletAddress: key.accAddress,
  86. isImportedWallet: true,
  87. firstInitiaWalletAddress: key.accAddress,
  88. email: 'xsdacds@gmail.com',
  89. xrplWalletAddress: xrpl.Wallet.generate().address,
  90. },
  91. )
  92. console.log(register.data)
  93. try {
  94. const airdropResp = await client.post(
  95. 'https://api.lunchlunch.xyz/v1/dish/submit-action/airdrop',
  96. {
  97. dishId: 42,
  98. },
  99. )
  100. console.log(airdropResp.data)
  101. } catch (e) {
  102. console.log(e)
  103. }
  104. }
  105. async function testL2WithProxy() {
  106. const agent = getProxyAgent()
  107. const client = axios.create({
  108. httpsAgent: agent,
  109. })
  110. const resp = await client.get(
  111. 'https://maze-rest-617bacff-7d34-4eb8-87f4-ee16fb4e0ac7.ue1-prod.newmetric.xyz/cosmos/bank/v1beta1/balances/init1ckyxek0ckfszwgpqf6j9a4sawveazpyrlgpj4s/by_denom?denom=l2/aadf1a9da6a38b7e7e11839364ee42002260eff1657f403b9ce608337bcb986b',
  112. )
  113. console.log(resp.data)
  114. }
  115. await testL2WithProxy()
  116. // await testFaucet()
  117. // await createDummyAddresses()
  118. // await createAccounts(10000)
  119. // await faucetAccount('init1xj0ekwu5n3t4c8aj2xfxr9l94lwr0sssl4rkxy')
  120. // await getAltchaPayload(getAxiosClient(true))
  121. // const client = new InitiaClient(
  122. // 'scheme address way popular shrug fall rail eyebrow buzz learn cross involve spatial rookie ostrich grocery chest ice glory security slogan summer also comfort',
  123. // )
  124. // console.log(client.key.accAddress)