import { BaseClient } from './BaseClient' import { bcs, Coin, Coins, Fee, MsgExecute } from '@initia/initia.js' import { getAxiosClient } from './utils' export abstract class JennieModule extends BaseClient { protected constructor(mnemonic: string, useProxy: boolean = false) { super(mnemonic, useProxy) } async getXpAmount() { const viewResult = await this.lcd.move.viewFunction( '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'initia_xp', 'get_xp_amount', undefined, [bcs.address().serialize(this.key.accAddress).toBase64()], ) return viewResult } async drawFood() { const res = await this.claimableXp() if (res != `done`) { return `needFood` } const xp = await this.getXpAmount() if (Number(xp) < 700 && Number(xp) > 200) { const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'draw_food', [], ['AQ=='], ) return await this.broadcast(msg) } else if (Number(xp) >= 700 && Number(xp) < 1200) { const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'draw_food', [], ['Ag=='], ) return await this.broadcast(msg) } else if (Number(xp) >= 1200) { const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'draw_food', [], ['Aw=='], ) return await this.broadcast(msg) } else { return `done` } } async feedJennie() { const viewResult: { hp: string; update_at: string } = await this.lcd.move.viewFunction( '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'get_jennie_state', undefined, [bcs.address().serialize(this.key.accAddress).toBase64()], ) // const stageInfo: { // current_stage: number // stage_interval: number // start_timestamp: number // } = await this.lcd.move.viewFunction( // '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', // 'jennie', // 'stage_info', // undefined, // [], // ) const kt = Number(viewResult.update_at) const now = 1718765974 // const currentStage = stageInfo.current_stage // const stageInternal = stageInfo.stage_interval // const stTimestamp = stageInfo.start_timestamp // const yt = // stTimestamp + // Math.floor(((currentStage ?? 1) - 1) / 7) * stageInternal * 7 // const St = // stTimestamp + // (Math.floor(((currentStage ?? 1) - 1) / 7) + 1) * stageInternal * 7 // const canFeed = kt < Math.floor(yt / 1000000) if (!(kt < now)) { return `done` } const rep = await getAxiosClient(true).get( `${this.rpcUrlUsing}initia/move/v1/accounts/${this.key.accAddress}/resources/by_struct_tag?struct_tag=0x9065fda28f52bb14ade545411f02e8e07a9cb4ba::jennie::FoodStore`, ) const store = JSON.parse(rep.data.resource.move_resource) const data = store.data if (Number(data.tier2) > 0) { const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'feed_jennie', [], [bcs.u8().serialize(2).toBase64()], ) return await this.broadcast(msg) } else if (Number(data.tier3) > 0) { const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'feed_jennie', [], [bcs.u8().serialize(3).toBase64()], ) return await this.broadcast(msg) } else if (Number(data.tier1) > 0) { const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'feed_jennie', [], [bcs.u8().serialize(1).toBase64()], ) return await this.broadcast(msg) } else { await this.drawFood() return `needFood` } } async mintJennie() { // Fetch mint progress details for 'jennie' const mintProgress: MintProgress = await this.lcd.move.viewFunction( '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'get_jennie_mint_progress', [], [bcs.address().serialize(this.key.accAddress).toBase64()], ) console.log(mintProgress) // Check if 'jennie' is already minted if (mintProgress.is_minted) { return `done` } // Initialize a flag to determine if all parts are minted let allPartsMinted = true // Iterate over each part progress for (const partProgress of mintProgress.jennie_part_progresses) { // If any part is not minted, set the flag to false if (!partProgress.is_minted) { allPartsMinted = false break // No need to check further parts } } // If not all parts are minted, exit the function if (!allPartsMinted) { return `undone` } // Prepare the minting message const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'mint_jennie', [], [], ) // Broadcast the minting message return await this.broadcast(msg) } async mintPartApprovedAll() { const axios = getAxiosClient(true) const res = await axios.get( `https://xp-api.initiation-1.initia.xyz/xp/mint_parts/${this.key.accAddress}`, ) const data = res.data let undone = [1, 2, 3, 4, 5, 6] for (const item of data) { const task = Number(item.task_id) + 1 undone = undone.filter(value => value !== task) } console.log(undone) return undone } async mintPart() { // 获取 'jennie' 的铸造进度 const axios = getAxiosClient(true) const res = await axios.get( `https://xp-api.initiation-1.initia.xyz/xp/mint_parts/${this.key.accAddress}`, ) const data = res.data if (data.length !== 6) { return `undone` } const msgs = [] const mintProgress: MintProgress = await this.lcd.move.viewFunction( '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'get_jennie_mint_progress', [], [bcs.address().serialize(this.key.accAddress).toBase64()], ) const progresses = mintProgress.jennie_part_progresses console.log(progresses) for (const item of progresses) { if (item.is_minted) { continue } for (let i = 0; i < data.length; i++) { if (Number(data[i].task_id) === Number(item.task)) { const sig = data[i] const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'jennie', 'mint_part_v2', [], [ bcs.u8().serialize(sig.task_id).toBase64(), bcs .vector(bcs.u8()) .serialize(Buffer.from(sig.signature, 'base64')) .toBase64(), ], ) msgs.push(msg) } } } // 初始化消息数组 if (msgs.length === 0) { return `done` } return await this.broadcast(msgs) } async claimableXp() { //https://xp-api.initiation-1.initia.xyz/xp/claimable/init1w6ftxlsv7y5putq955ymxh2kd0wru7nqshetka const res = getAxiosClient(true) const data = await res.get( `https://xp-api.initiation-1.initia.xyz/xp/claimable/${this.key.accAddress}`, ) if (data.data.claimable_list.length > 0) { const msgs = [] for (let i = 0; i < data.data.claimable_list.length; i++) { const proofs = data.data.claimable_list[i].merkle_proofs const proofsu8vec = proofs.map(p => Uint8Array.from(Buffer.from(p, 'base64')), ) const sd = bcs .vector(bcs.vector(bcs.u8())) .serialize(proofsu8vec) .toBase64() const msg = new MsgExecute( this.key.accAddress, '0x9065fda28f52bb14ade545411f02e8e07a9cb4ba', 'initia_xp', 'claim_point', [], [ bcs.u64().serialize(data.data.claimable_list[i].stage).toBase64(), sd, bcs .u64() .serialize(data.data.claimable_list[i].task_point) .toBase64(), bcs .u64() .serialize(data.data.claimable_list[i].referral_point) .toBase64(), ], ) msgs.push(msg) } return await this.broadcast(msgs) // console.log(broadcast.raw_log) // console.log(this.key.accAddress) } else { return `done` } } }