import { AccAddress, MnemonicKey, RawKey } from '@initia/initia.js' import { InitiaClient } from './InitiaClient' import polly from 'polly-js' import { v4 as uuidv4 } from 'uuid' import { DBClient } from './singletons' import { solveChallenge } from 'shawnlu96-altcha-lib' import { forEachAsync, getAxiosClient, getProxyAgent } from './utils' import { getAltchaPayload, solveHCaptcha } from './faucet/captcha' import axios from 'axios' import toHex = AccAddress.toHex import xrpl from 'xrpl' import { ethers } from 'ethers' // await polly() // .waitAndRetry(4) // .executeForPromise(async () => { // const key = new MnemonicKey() // console.log(key.accAddress) // console.log(key.mnemonic) // await faucetAccount(key.accAddress) // }) async function createAccounts(count: number) { const accounts = [] for (let i = 0; i < count; i++) { console.log(`creating account ${i}/${count}`) const key = new MnemonicKey() const account = { mnemonic: key.mnemonic, address: key.accAddress, } accounts.push(account) } await DBClient.instance.account.createMany({ data: accounts }) } async function createDummyAddresses() { let total = 0 function getTargets() { return DBClient.instance.randomTask2.findMany({ where: { toAddress: null, }, take: 40, }) } let targets = await getTargets() while (targets.length > 0) { await forEachAsync(targets, 15, async task => { const key = new MnemonicKey() task.toAddress = key.accAddress await DBClient.instance.randomTask2.update({ where: { id: task.id }, data: { toAddress: key.accAddress }, }) }) total += targets.length console.log(total) targets = await getTargets() } } async function testFaucet() { const key = new MnemonicKey() const evmWallet = new ethers.Wallet(key.privateKey.toString('hex')) const evmAddress = toHex(key.accAddress) const message = JSON.stringify({ signedAt: new Date().toISOString() }) const duid = uuidv4().toUpperCase() const client = axios.create({ headers: { 'user-agent': 'Lunch/1.0 (xyz.lunchlunch.app; build:41; iOS 17.4.1) Alamofire/5.8.0', 'lunch-app-version': 41, 'lunch-fiat-currency': 'USD', 'lunch-app-duid': duid, }, }) const resp = await client.post('https://api.lunchlunch.xyz/v1/auth/sign-in', { walletAddress: evmWallet.address, signedMessage: await evmWallet.signMessage(message), rawMessage: message, }) console.log(resp.data) client.defaults.headers['authorization'] = `Bearer ${resp.data.accessToken}` const register = await client.post( 'https://api.lunchlunch.xyz/v1/member/register', { evmWalletAddress: evmWallet.address, initiaWalletAddress: key.accAddress, isImportedWallet: true, firstInitiaWalletAddress: key.accAddress, email: 'xsdacds@gmail.com', xrplWalletAddress: xrpl.Wallet.generate().address, }, ) console.log(register.data) try { const airdropResp = await client.post( 'https://api.lunchlunch.xyz/v1/dish/submit-action/airdrop', { dishId: 42, }, ) console.log(airdropResp.data) } catch (e) { console.log(e) } } async function testL2WithProxy() { const agent = getProxyAgent() const client = axios.create({ httpsAgent: agent, }) const resp = await client.get( 'https://maze-rest-617bacff-7d34-4eb8-87f4-ee16fb4e0ac7.ue1-prod.newmetric.xyz/cosmos/bank/v1beta1/balances/init1ckyxek0ckfszwgpqf6j9a4sawveazpyrlgpj4s/by_denom?denom=l2/aadf1a9da6a38b7e7e11839364ee42002260eff1657f403b9ce608337bcb986b', ) console.log(resp.data) } await testL2WithProxy() // await testFaucet() // await createDummyAddresses() // await createAccounts(10000) // await faucetAccount('init1xj0ekwu5n3t4c8aj2xfxr9l94lwr0sssl4rkxy') // await getAltchaPayload(getAxiosClient(true)) // const client = new InitiaClient( // 'scheme address way popular shrug fall rail eyebrow buzz learn cross involve spatial rookie ostrich grocery chest ice glory security slogan summer also comfort', // ) // console.log(client.key.accAddress)