randomWeek3.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import { DBClient } from '../../singletons'
  2. import { InitiaClient } from '../../InitiaClient'
  3. import { forEachAsync } from 'useless-helpers'
  4. import { getAxiosClient } from '../../utils'
  5. import polly from 'polly-js'
  6. async function startCheck(concurrency) {
  7. const accountsRaw = await DBClient.instance.randomTask2.findMany({
  8. where: {
  9. finish: 0,
  10. },
  11. take: 4000,
  12. orderBy: {
  13. id: 'asc',
  14. },
  15. })
  16. await forEachAsync(accountsRaw, concurrency, async (account, index) => {
  17. console.log(
  18. `${index}/${accountsRaw.length}: processing ${account.address},account id: ${account.id}`,
  19. )
  20. const res = await polly()
  21. .waitAndRetry(10)
  22. .executeForPromise(async () => {
  23. const axios = getAxiosClient(true)
  24. return await axios.get(
  25. `https://xp-api.initiation-1.initia.xyz/xp/weekly/${account.address}/9`,
  26. )
  27. })
  28. if (res.data.finished_tasks.length === 4) {
  29. await DBClient.instance.randomTask2.update({
  30. where: { id: account.id },
  31. data: { task1: 1, task2: 1, task3: 1, task4: 1, finish: 1 },
  32. })
  33. return
  34. }
  35. //bridge_op_deposit
  36. if (res.data.finished_tasks.includes(`bridge_op_deposit`)) {
  37. account.task1 = 1
  38. } else {
  39. account.task1 = 0
  40. }
  41. //
  42. if (res.data.finished_tasks.includes(`bridge_op_withdraw`)) {
  43. account.task2 = 1
  44. } else {
  45. account.task2 = 0
  46. }
  47. //bridge_ibc_transfer
  48. if (res.data.finished_tasks.includes(`bridge_ibc_transfer`)) {
  49. account.task3 = 1
  50. } else {
  51. account.task3 = 0
  52. }
  53. //milkyway_mint_milk_init
  54. if (res.data.finished_tasks.includes(`milkyway_mint_milk_init`)) {
  55. account.task4 = 1
  56. } else {
  57. account.task4 = 0
  58. }
  59. try {
  60. // await faucetAccount(account.address)
  61. const notDone = []
  62. if (account.task1 === 0) {
  63. notDone.push(1)
  64. }
  65. if (account.task2 === 0) {
  66. notDone.push(2)
  67. }
  68. if (account.task3 === 0) {
  69. notDone.push(3)
  70. }
  71. if (account.task4 === 0) {
  72. notDone.push(4)
  73. }
  74. if (account.task5 === 0) {
  75. // notDone.push(5)
  76. }
  77. if (account.task6 === 0) {
  78. // notDone.push(6)
  79. }
  80. console.log(
  81. `${index}/${accountsRaw.length}: processing ${account.address} notDone`,
  82. notDone,
  83. )
  84. if (notDone.length === 0) {
  85. await DBClient.instance.randomTask2.update({
  86. where: { id: account.id },
  87. data: { finish: 1 },
  88. })
  89. return
  90. }
  91. const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
  92. const client = new InitiaClient(account.mnemonic, true)
  93. // const gasGot = await client.gasGot()
  94. // if (!gasGot) {
  95. // // await DBClient.instance.randomTask2.update({
  96. // // where: { id: account.id },
  97. // // data: { finish: -1 },
  98. // // })
  99. // return
  100. // }
  101. if (randomPick === 1) {
  102. console.log(
  103. `${index}/${accountsRaw.length}: processing ${account.address},task1`,
  104. )
  105. const bool = await client.questBridge()
  106. console.log(
  107. `${index}/${accountsRaw.length}: processing ${account.address},task1`,
  108. bool,
  109. )
  110. if (bool === `done`) {
  111. await DBClient.instance.randomTask2.update({
  112. where: { id: account.id },
  113. data: account,
  114. })
  115. }
  116. } else if (randomPick === 2) {
  117. console.log(
  118. `${index}/${accountsRaw.length}: processing ${account.address},task2`,
  119. )
  120. const bool = await client.questTask2()
  121. console.log(
  122. `${index}/${accountsRaw.length}: processing ${account.address},task2`,
  123. bool,
  124. )
  125. if (bool === `done`) {
  126. await DBClient.instance.randomTask2.update({
  127. where: { id: account.id },
  128. data: account,
  129. })
  130. }
  131. } else if (randomPick === 3) {
  132. console.log(
  133. `${index}/${accountsRaw.length}: processing ${account.address},task3`,
  134. )
  135. const bool = await client.questTask3()
  136. console.log(
  137. `${index}/${accountsRaw.length}: processing ${account.address},task3`,
  138. bool,
  139. )
  140. if (bool === `done`) {
  141. await DBClient.instance.randomTask2.update({
  142. where: { id: account.id },
  143. data: account,
  144. })
  145. }
  146. } else if (randomPick === 4) {
  147. console.log(
  148. `${index}/${accountsRaw.length}: processing ${account.address},task4`,
  149. )
  150. const bool = await client.questTask4()
  151. console.log(
  152. `${index}/${accountsRaw.length}: processing ${account.address},task4`,
  153. bool,
  154. )
  155. if (bool === `done`) {
  156. await DBClient.instance.randomTask2.update({
  157. where: { id: account.id },
  158. data: { task4: 1 },
  159. })
  160. }
  161. } else if (randomPick === 5) {
  162. console.log(
  163. `${index}/${accountsRaw.length}: processing ${account.address},task5`,
  164. )
  165. const bool = await client.week5Task5()
  166. console.log(
  167. `${index}/${accountsRaw.length}: processing ${account.address},task5`,
  168. bool,
  169. )
  170. if (bool === `done`) {
  171. await DBClient.instance.randomTask2.update({
  172. where: { id: account.id },
  173. data: { task5: 1 },
  174. })
  175. }
  176. } else if (randomPick === 6) {
  177. console.log(
  178. `${index}/${accountsRaw.length}: processing ${account.address},task6`,
  179. )
  180. const bool = await client.week5Task6()
  181. console.log(
  182. `${index}/${accountsRaw.length}: processing ${account.address},task6`,
  183. bool,
  184. )
  185. if (bool === `done`) {
  186. await DBClient.instance.randomTask2.update({
  187. where: { id: account.id },
  188. data: { task6: 1 },
  189. })
  190. }
  191. }
  192. } catch (e) {
  193. console.log(e.message)
  194. // process.exit(0)
  195. return
  196. // await DBClient.instance.account.update({
  197. // where: { id: account.id },
  198. // data: { status: Status.MayQueued, message: e.message },
  199. // })
  200. }
  201. })
  202. }
  203. startCheck(30)