import { DBClient } from '../../singletons' import { InitiaClient } from '../../InitiaClient' import { forEachAsync } from 'useless-helpers' import { getAxiosClient } from '../../utils' import polly from 'polly-js' async function startCheck(concurrency) { const accountsRaw = await DBClient.instance.randomTask2.findMany({ where: { finish: 0, }, take: 4000, orderBy: { id: 'asc', }, }) await forEachAsync(accountsRaw, concurrency, async (account, index) => { console.log( `${index}/${accountsRaw.length}: processing ${account.address},account id: ${account.id}`, ) const res = await polly() .waitAndRetry(10) .executeForPromise(async () => { const axios = getAxiosClient(true) return await axios.get( `https://xp-api.initiation-1.initia.xyz/xp/weekly/${account.address}/9`, ) }) if (res.data.finished_tasks.length === 4) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task1: 1, task2: 1, task3: 1, task4: 1, finish: 1 }, }) return } //bridge_op_deposit if (res.data.finished_tasks.includes(`bridge_op_deposit`)) { account.task1 = 1 } else { account.task1 = 0 } // if (res.data.finished_tasks.includes(`bridge_op_withdraw`)) { account.task2 = 1 } else { account.task2 = 0 } //bridge_ibc_transfer if (res.data.finished_tasks.includes(`bridge_ibc_transfer`)) { account.task3 = 1 } else { account.task3 = 0 } //milkyway_mint_milk_init if (res.data.finished_tasks.includes(`milkyway_mint_milk_init`)) { account.task4 = 1 } else { account.task4 = 0 } try { // await faucetAccount(account.address) const notDone = [] if (account.task1 === 0) { notDone.push(1) } if (account.task2 === 0) { notDone.push(2) } if (account.task3 === 0) { notDone.push(3) } if (account.task4 === 0) { notDone.push(4) } if (account.task5 === 0) { // notDone.push(5) } if (account.task6 === 0) { // notDone.push(6) } console.log( `${index}/${accountsRaw.length}: processing ${account.address} notDone`, notDone, ) if (notDone.length === 0) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { finish: 1 }, }) return } const randomPick = notDone[Math.floor(Math.random() * notDone.length)] const client = new InitiaClient(account.mnemonic, true) // const gasGot = await client.gasGot() // if (!gasGot) { // // await DBClient.instance.randomTask2.update({ // // where: { id: account.id }, // // data: { finish: -1 }, // // }) // return // } if (randomPick === 1) { console.log( `${index}/${accountsRaw.length}: processing ${account.address},task1`, ) const bool = await client.questBridge() console.log( `${index}/${accountsRaw.length}: processing ${account.address},task1`, bool, ) if (bool === `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: account, }) } } else if (randomPick === 2) { console.log( `${index}/${accountsRaw.length}: processing ${account.address},task2`, ) const bool = await client.questTask2() console.log( `${index}/${accountsRaw.length}: processing ${account.address},task2`, bool, ) if (bool === `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: account, }) } } else if (randomPick === 3) { console.log( `${index}/${accountsRaw.length}: processing ${account.address},task3`, ) const bool = await client.questTask3() console.log( `${index}/${accountsRaw.length}: processing ${account.address},task3`, bool, ) if (bool === `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: account, }) } } else if (randomPick === 4) { console.log( `${index}/${accountsRaw.length}: processing ${account.address},task4`, ) const bool = await client.questTask4() console.log( `${index}/${accountsRaw.length}: processing ${account.address},task4`, bool, ) if (bool === `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task4: 1 }, }) } } else if (randomPick === 5) { console.log( `${index}/${accountsRaw.length}: processing ${account.address},task5`, ) const bool = await client.week5Task5() console.log( `${index}/${accountsRaw.length}: processing ${account.address},task5`, bool, ) if (bool === `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task5: 1 }, }) } } else if (randomPick === 6) { console.log( `${index}/${accountsRaw.length}: processing ${account.address},task6`, ) const bool = await client.week5Task6() console.log( `${index}/${accountsRaw.length}: processing ${account.address},task6`, bool, ) if (bool === `done`) { await DBClient.instance.randomTask2.update({ where: { id: account.id }, data: { task6: 1 }, }) } } } catch (e) { console.log(e.message) // process.exit(0) return // await DBClient.instance.account.update({ // where: { id: account.id }, // data: { status: Status.MayQueued, message: e.message }, // }) } }) } startCheck(30)