hel 1 tahun lalu
induk
melakukan
b0e53fd664
3 mengubah file dengan 40 tambahan dan 184 penghapusan
  1. 1 1
      src/InitiaClient.ts
  2. 39 7
      src/LunchClient.ts
  3. 0 176
      src/lunchClient.ts

+ 1 - 1
src/InitiaClient.ts

@@ -10,7 +10,7 @@ import {
   Wallet,
 } from '@initia/initia.js'
 import polly from 'polly-js'
-import { LunchClient } from './lunchClient'
+import { LunchClient } from './LunchClient'
 import { sleep } from 'useless-helpers'
 
 export class InitiaClient extends InitiaTask {

+ 39 - 7
src/LunchClient.ts

@@ -21,6 +21,7 @@ export class LunchClient {
   axiosClient: AxiosInstance
   proxyAgent: HttpsProxyAgent<any>
   key: MnemonicKey
+  isLogin: boolean = false
   constructor(mnemonic: string, useProxy: boolean = true) {
     this.mnemonic = mnemonic
     this.proxyAgent = useProxy ? getProxyAgent() : undefined
@@ -105,13 +106,13 @@ export class LunchClient {
     ] = `Bearer ${resp.data.accessToken}`
     const xrplWallet = xrpl.Wallet.fromSeed(account.xrpPrivateKey)
     let needRegister = false
-    try {
-      await this.axiosClient.get('https://api.lunchlunch.xyz/v1/member')
-    } catch (e) {
-      if (e.response.status === 404) {
-        needRegister = true
-      }
-    }
+    // try {
+    //   await this.axiosClient.get('https://api.lunchlunch.xyz/v1/member')
+    // } catch (e) {
+    //   if (e.response.status === 404) {
+    //     needRegister = true
+    //   }
+    // }
     if (needRegister) {
       await this.axiosClient.post(
         'https://api.lunchlunch.xyz/v1/member/register',
@@ -140,5 +141,36 @@ export class LunchClient {
         deviceOS: account.deviceOS,
       },
     })
+    this.isLogin = true
+  }
+
+  async submitOnchain(txHash: string) {
+    if (!this.isLogin) throw new Error('Please login first')
+    return await this.axiosClient.post(
+      `https://api.lunchlunch.xyz/v1/dish/submit-action/onchain`,
+      {
+        dishId: 7,
+        txHash: txHash,
+      },
+    )
+  }
+
+  async claimEgg(txHash: string) {
+    if (!this.isLogin) throw new Error('Please login first')
+    await this.axiosClient.post(
+      `https://api.lunchlunch.xyz/v1/dish/submit-claim/egg`,
+      {
+        dishId: 7,
+        txHash: txHash,
+      },
+    )
+  }
+
+  async getEggBalance() {
+    if (!this.isLogin) throw new Error('Please login first')
+    const resp = await this.axiosClient.get(
+      'https://api.lunchlunch.xyz/v1/member/egg/balance',
+    )
+    return resp.data
   }
 }

+ 0 - 176
src/lunchClient.ts

@@ -1,176 +0,0 @@
-import axios, { AxiosInstance } from 'axios'
-import { HttpsProxyAgent } from 'https-proxy-agent'
-import { generateRandomString, getProxyAgent } from './utils'
-import { DBClient } from './singletons'
-import { MnemonicKey } from '@initia/initia.js'
-import xrpl from 'xrpl'
-import { ethers } from 'ethers'
-import { v4 as uuidv4 } from 'uuid'
-import {
-  formatDateTime,
-  getAndroidModel,
-  getAndroidOS,
-  getDeviceId,
-  getIOS,
-  getRawMessage,
-} from './faucet/faucetLunch'
-import { Status } from './models/Status'
-
-export class LunchClient {
-  mnemonic: string
-  axiosClient: AxiosInstance
-  proxyAgent: HttpsProxyAgent<any>
-  key: MnemonicKey
-  isLogin: boolean = false
-  constructor(mnemonic: string, useProxy: boolean = true) {
-    this.mnemonic = mnemonic
-    this.proxyAgent = useProxy ? getProxyAgent() : undefined
-    this.key = new MnemonicKey({ mnemonic: mnemonic })
-  }
-
-  async login() {
-    const account = await DBClient.instance.account.findFirst({
-      where: { address: this.key.accAddress },
-    })
-    if (!account.gmail) {
-      account.gmail = `${generateRandomString(8)}@gmail.com`
-    }
-    if (!account.xrpPrivateKey) {
-      account.xrpPrivateKey = xrpl.Wallet.generate().seed
-    }
-    const evmWallet = new ethers.Wallet(this.key.privateKey.toString('hex'))
-    const message = JSON.stringify({
-      signedAt: formatDateTime(new Date()),
-    })
-    const evmSignedMessage = await evmWallet.signMessage(message)
-    const proxyAgent = undefined
-    // let isAndroid = Math.random() > 0.5
-    let isAndroid = false
-    if (account.duid) {
-      isAndroid = !account.duid.includes('-')
-    }
-    if (isAndroid && !account.deviceModel) {
-      account.deviceModel = getAndroidModel()
-    }
-    if (!account.duid) {
-      account.duid = isAndroid
-        ? await getDeviceId(isAndroid, account.deviceModel, proxyAgent)
-        : uuidv4().toUpperCase()
-    }
-    if (!account.deviceOS) {
-      account.deviceOS = isAndroid ? getAndroidOS() : getIOS()
-    }
-    const rawMessage = await getRawMessage(
-      evmWallet.address,
-      message,
-      account.duid,
-    )
-    this.axiosClient = isAndroid
-      ? axios.create({
-          headers: {
-            'Lunch-Language': 'EN',
-            'lunch-fiat-currency': 'USD',
-            'lunch-app-duid': account.duid,
-            'lunch-app-version': '0.17.3',
-            'lun-app-build': 46,
-            'Lunch-Device-Model': account.deviceModel,
-            'Lunch-Device-OS': account.deviceOS,
-            'Lunch-Platform': 'Android',
-            'user-agent': `lunch/0.17.3(46) (Linux; ${account.deviceOS}; ${account.deviceModel} Build/PQ3B.190801.05281822)`,
-          },
-          httpsAgent: proxyAgent,
-        })
-      : axios.create({
-          headers: {
-            'lunch-language': 'en',
-            'lunch-app-platform': 'iOS',
-            'lunch-app-version': '45',
-            'lunch-fiat-currency': 'USD',
-            'lunch-app-duid': account.duid,
-            'user-agent': `Lunch/1.0 (xyz.lunchlunch.app; build:45; ${account.deviceOS}) Alamofire/5.8.0`,
-          },
-        })
-
-    const resp = await this.axiosClient.post(
-      'https://api.lunchlunch.xyz/v1/auth/sign-in',
-      {
-        walletAddress: evmWallet.address,
-        signedMessage: evmSignedMessage,
-        rawMessage: rawMessage,
-      },
-    )
-    console.log(`${account.address}: sign-in success.`)
-    // register
-    this.axiosClient.defaults.headers[
-      'authorization'
-    ] = `Bearer ${resp.data.accessToken}`
-    const xrplWallet = xrpl.Wallet.fromSeed(account.xrpPrivateKey)
-    let needRegister = false
-    // try {
-    //   await this.axiosClient.get('https://api.lunchlunch.xyz/v1/member')
-    // } catch (e) {
-    //   if (e.response.status === 404) {
-    //     needRegister = true
-    //   }
-    // }
-    if (needRegister) {
-      await this.axiosClient.post(
-        'https://api.lunchlunch.xyz/v1/member/register',
-        {
-          evmWalletAddress: evmWallet.address,
-          initiaWalletAddress: this.key.accAddress,
-          isImportedWallet: true,
-          firstInitiaWalletAddress: this.key.accAddress,
-          email: account.gmail,
-          xrplWalletAddress: xrplWallet.address,
-        },
-      )
-      console.log(`${this.key.accAddress}: register done`)
-    } else {
-      console.log(`${this.key.accAddress}: already registered`)
-    }
-    await DBClient.instance.account.update({
-      where: { id: account.id },
-      data: {
-        status: Status.Fauceted,
-        lastRun: new Date(),
-        xrpPrivateKey: account.xrpPrivateKey,
-        gmail: account.gmail,
-        duid: account.duid,
-        deviceModel: account.deviceModel,
-        deviceOS: account.deviceOS,
-      },
-    })
-    this.isLogin = true
-  }
-
-  async submitOnchain(txHash: string) {
-    if (!this.isLogin) throw new Error('Please login first')
-    return await this.axiosClient.post(
-      `https://api.lunchlunch.xyz/v1/dish/submit-action/onchain`,
-      {
-        dishId: 7,
-        txHash: txHash,
-      },
-    )
-  }
-
-  async claimEgg(txHash: string) {
-    if (!this.isLogin) throw new Error('Please login first')
-    await this.axiosClient.post(
-      `https://api.lunchlunch.xyz/v1/dish/submit-claim/egg`,
-      {
-        dishId: 7,
-        txHash: txHash,
-      },
-    )
-  }
-
-  async getEggBalance() {
-    if (!this.isLogin) throw new Error('Please login first')
-    const resp = await this.axiosClient.get(
-      'https://api.lunchlunch.xyz/v1/member/egg/balance',
-    )
-    return resp.data
-  }
-}