|
@@ -4,12 +4,14 @@ import {
|
|
Coin,
|
|
Coin,
|
|
Coins,
|
|
Coins,
|
|
Fee,
|
|
Fee,
|
|
- Msg,
|
|
|
|
|
|
+ MsgExecute,
|
|
MsgSend,
|
|
MsgSend,
|
|
MsgTransfer,
|
|
MsgTransfer,
|
|
Wallet,
|
|
Wallet,
|
|
} from '@initia/initia.js'
|
|
} from '@initia/initia.js'
|
|
import polly from 'polly-js'
|
|
import polly from 'polly-js'
|
|
|
|
+import { LunchClient } from './LunchClient'
|
|
|
|
+import { sleep } from 'useless-helpers'
|
|
|
|
|
|
export class InitiaClient extends InitiaTask {
|
|
export class InitiaClient extends InitiaTask {
|
|
constructor(mnemonic: string, useProxy: boolean = false) {
|
|
constructor(mnemonic: string, useProxy: boolean = false) {
|
|
@@ -930,10 +932,155 @@ export class InitiaClient extends InitiaTask {
|
|
// const res = await this.newBridge2BlackWings()
|
|
// const res = await this.newBridge2BlackWings()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async week6task1() {
|
|
|
|
+ const lunch = new LunchClient(this.key.mnemonic)
|
|
|
|
+ await lunch.login()
|
|
|
|
+ const eggBalance = await lunch.getEggBalance()
|
|
|
|
+ if (Number(eggBalance) > 0) {
|
|
|
|
+ return `done`
|
|
|
|
+ }
|
|
|
|
+ //todo balanceChecker
|
|
|
|
+ const uinit = await this.lcd.bank.balanceByDenom(
|
|
|
|
+ this.key.accAddress,
|
|
|
|
+ 'uinit',
|
|
|
|
+ )
|
|
|
|
+ if (Number(uinit.amount) < 1000000) {
|
|
|
|
+ return `notEnoughUinit`
|
|
|
|
+ }
|
|
|
|
+ const randomNum = this.randomAmount(1000000, 2000000)
|
|
|
|
+ const swapMsg = new MsgExecute(
|
|
|
|
+ this.key.accAddress,
|
|
|
|
+ '0x1',
|
|
|
|
+ 'dex',
|
|
|
|
+ 'swap_script',
|
|
|
|
+ [],
|
|
|
|
+ [
|
|
|
|
+ '2/BsSK85hOxtmuipqn27C7HnhKqbjEpWga9mDPhVjX0=', //liquidityTOken
|
|
|
|
+ 'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=', //offerCoin
|
|
|
|
+ bcs.u64().serialize(randomNum).toBase64(), //offerAmount
|
|
|
|
+ bcs
|
|
|
|
+ .option(bcs.u64())
|
|
|
|
+ .serialize(this.randomAmount(1000, 2000))
|
|
|
|
+ .toBase64(),
|
|
|
|
+ ],
|
|
|
|
+ )
|
|
|
|
+ const swapHash = await this.broadcast(swapMsg)
|
|
|
|
+
|
|
|
|
+ //todo commit
|
|
|
|
+ await sleep(5000)
|
|
|
|
+ const submitRes = await lunch.submitOnchain(swapHash)
|
|
|
|
+
|
|
|
|
+ const noonWallet = new Wallet(this.noon, this.wallet.key)
|
|
|
|
+ const msg = new MsgExecute(
|
|
|
|
+ this.key.accAddress,
|
|
|
|
+ '0x225dd873693460a600cc8f592695ed15bbcca1a',
|
|
|
|
+ 'egg_1',
|
|
|
|
+ 'claim_all_v2',
|
|
|
|
+ [],
|
|
|
|
+ [`${bcs.u64().serialize(7).toBase64()}`],
|
|
|
|
+ )
|
|
|
|
+ const trans = await noonWallet.createAndSignTx({ msgs: [msg] })
|
|
|
|
+ const res = await this.noon.tx.broadcast(trans)
|
|
|
|
+ const txhash = res.txhash
|
|
|
|
+ //todo claim
|
|
|
|
+ await lunch.claimEgg(txhash)
|
|
|
|
+ return `worked`
|
|
|
|
+ }
|
|
async week6task2() {
|
|
async week6task2() {
|
|
const tucBalance = await this.tucana.bank.balanceByDenom(
|
|
const tucBalance = await this.tucana.bank.balanceByDenom(
|
|
this.key.accAddress,
|
|
this.key.accAddress,
|
|
'utuc',
|
|
'utuc',
|
|
)
|
|
)
|
|
|
|
+ console.log(tucBalance.amount)
|
|
|
|
+ if (Number(tucBalance.amount) < 2000000) {
|
|
|
|
+ return `tuc`
|
|
|
|
+ }
|
|
|
|
+ const msg = new MsgExecute(
|
|
|
|
+ this.key.accAddress,
|
|
|
|
+ '0x298A9DC53EDA7750A5683960B01775D3A34DDB5F',
|
|
|
|
+ 'router',
|
|
|
|
+ 'add_liquidity',
|
|
|
|
+ [],
|
|
|
|
+ [
|
|
|
|
+ bcs
|
|
|
|
+ .u64()
|
|
|
|
+ .serialize(Number(tucBalance.amount) / 10)
|
|
|
|
+ .toBase64(),
|
|
|
|
+ '64WvP6wAJgs/gCqhuEQ9pXGrKKgjuk08mCVTuXJ2Jd8=',
|
|
|
|
+ bcs.address().serialize(this.wallet.key.accAddress).toBase64(),
|
|
|
|
+ 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
|
|
|
|
+ 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
|
|
|
|
+ ],
|
|
|
|
+ )
|
|
|
|
+ const tucanaWallet = new Wallet(this.tucana, this.wallet.key)
|
|
|
|
+ const simulate = await this.tucana.tx.estimateFee(
|
|
|
|
+ [{ sequenceNumber: await tucanaWallet.sequence() }],
|
|
|
|
+ {
|
|
|
|
+ msgs: [msg],
|
|
|
|
+ feeDenoms: ['utuc'],
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ const signed = await tucanaWallet.createAndSignTx({
|
|
|
|
+ msgs: [msg],
|
|
|
|
+ fee: new Fee(
|
|
|
|
+ simulate.gas_limit,
|
|
|
|
+ new Coins([new Coin('utuc', simulate.amount.toArray()[0].amount)]),
|
|
|
|
+ ),
|
|
|
|
+ })
|
|
|
|
+ try {
|
|
|
|
+ await this.tucana.tx.broadcast(signed)
|
|
|
|
+ return `done`
|
|
|
|
+ } catch (e) {
|
|
|
|
+ return `error`
|
|
|
|
+ }
|
|
|
|
+ // ["gIQeAAAAAAA=","64WvP6wAJgs/gCqhuEQ9pXGrKKgjuk08mCVTuXJ2Jd8=","AAAAAAAAAAAAAAAAfwBn58DHXySh7OLySf/MheBSfzg=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="]
|
|
|
|
+ //["AAk9AAAAAAA=","64WvP6wAJgs/gCqhuEQ9pXGrKKgjuk08mCVTuXJ2Jd8=","AAAAAAAAAAAAAAAAfwBn58DHXySh7OLySf/MheBSfzg=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=","AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async week6task3() {
|
|
|
|
+ const civiInitBalance = await this.civi.bank.balanceByDenom(
|
|
|
|
+ this.key.accAddress,
|
|
|
|
+ 'l2/afaa3f4e1717c75712f8e8073e41f051a4e516cd25daa82d948c4729388edefd',
|
|
|
|
+ )
|
|
|
|
+ if (Number(civiInitBalance.amount) < 500000) {
|
|
|
|
+ await this.newBridge2Civi()
|
|
|
|
+ return `civi`
|
|
|
|
+ }
|
|
|
|
+ const msg = new MsgExecute(
|
|
|
|
+ this.key.accAddress,
|
|
|
|
+ 'init1nyfj6va42hx32ew9nnhpurj075hmclahrjs2qe',
|
|
|
|
+ 'civitia',
|
|
|
|
+ 'roll_dice',
|
|
|
|
+ [],
|
|
|
|
+ [],
|
|
|
|
+ )
|
|
|
|
+ const civiWallet = new Wallet(this.civi, this.wallet.key)
|
|
|
|
+ const simulate = await this.civi.tx.estimateFee(
|
|
|
|
+ [{ sequenceNumber: await civiWallet.sequence() }],
|
|
|
|
+ {
|
|
|
|
+ msgs: [msg],
|
|
|
|
+ feeDenoms: [
|
|
|
|
+ 'l2/afaa3f4e1717c75712f8e8073e41f051a4e516cd25daa82d948c4729388edefd',
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ const signed = await civiWallet.createAndSignTx({
|
|
|
|
+ msgs: [msg],
|
|
|
|
+ fee: new Fee(
|
|
|
|
+ simulate.gas_limit,
|
|
|
|
+ new Coins([
|
|
|
|
+ new Coin(
|
|
|
|
+ 'l2/afaa3f4e1717c75712f8e8073e41f051a4e516cd25daa82d948c4729388edefd',
|
|
|
|
+ simulate.amount.toArray()[0].amount,
|
|
|
|
+ ),
|
|
|
|
+ ]),
|
|
|
|
+ ),
|
|
|
|
+ })
|
|
|
|
+ try {
|
|
|
|
+ await this.civi.tx.broadcastAsync(signed)
|
|
|
|
+ return `done`
|
|
|
|
+ } catch (e) {
|
|
|
|
+ return `error`
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|