hel 1 年之前
父节点
当前提交
0681c2c0f9
共有 6 个文件被更改,包括 541 次插入104 次删除
  1. 3 1
      package.json
  2. 7 0
      src/accountCreate.ts
  3. 61 0
      src/initiaClient.ts
  4. 39 0
      src/swapTester.ts
  5. 10 0
      src/validatorArray.ts
  6. 421 103
      yarn.lock

+ 3 - 1
package.json

@@ -28,10 +28,12 @@
     "build:watch": "tsc -w -p tsconfig.json && tsc-alias",
     "build:release": "npm run clean && tsc -p tsconfig.release.json && tsc-alias",
     "lint": "eslint . --ext .ts --ext .mts",
-    "prettier": "prettier --config .prettierrc --write ."
+    "prettier": "prettier --config .prettierrc --write .",
+    "test": "yarn build && node build/src/swapTester.js"
   },
   "license": "Apache-2.0",
   "dependencies": {
+    "@initia/initia.js": "^0.1.51",
     "@prisma/client": "^5.14.0",
     "axios": "^1.6.8",
     "https-proxy-agent": "^7.0.4",

+ 7 - 0
src/accountCreate.ts

@@ -0,0 +1,7 @@
+import { MnemonicKey } from '@initia/initia.js'
+
+const key = new MnemonicKey()
+console.log('mnemonic:', key.mnemonic)
+// mnemonic: beauty sniff protect...
+console.log('account address:', key.accAddress)
+// account address: init10m5nnevplkzvv5svqf0xjx6dc4705u5dxfn2st

+ 61 - 0
src/initiaClient.ts

@@ -0,0 +1,61 @@
+import {
+  LCDClient,
+  MnemonicKey,
+  MsgDelegate,
+  MsgExecute,
+  Wallet,
+} from '@initia/initia.js'
+
+class InitiaClient {
+  key: MnemonicKey
+  lcd: LCDClient
+  wallet: Wallet
+  constructor(mnemonic: string) {
+    this.key = new MnemonicKey({
+      mnemonic: mnemonic,
+    })
+
+    this.lcd = new LCDClient('https://api-initia-testnet.whispernode.com/', {
+      chainId: 'initiation-1',
+    })
+
+    this.wallet = new Wallet(this.lcd, this.key)
+  }
+
+  async checkBalance() {
+    const balances = await this.lcd.bank.balance(
+      'init14l3c2vxrdvu6y0sqykppey930s4kufsvt97aeu',
+    )
+    console.log(balances)
+    //todo filter balance
+  }
+
+  async swapScript() {
+    const msg = new MsgExecute(
+      this.key.accAddress,
+      '0x1',
+      'dex',
+      'swap_script',
+      [],
+      [
+        'sTSuZ4bxDvdClOYn0lGbY7fHQqZzX5hoKSn+qahHRNI=',
+        'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+        'QEIPAAAAAAA=',
+        'AdWGAQAAAAAA',
+      ],
+    )
+    const signed = await this.wallet.createAndSignTx({
+      msgs: [msg],
+    })
+    const broadcast = await this.lcd.tx.broadcast(signed)
+    console.log(broadcast)
+  }
+
+  async stakeInit() {
+    const msg = new MsgDelegate(
+      'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // delegator address
+      'init18sj3x80fdjc6gzfvwl7lf8sxcvuvqjpvcmp6np', // validator's operator addres
+      '100000uinit', // delegate amount
+    )
+  }
+}

+ 39 - 0
src/swapTester.ts

@@ -0,0 +1,39 @@
+import { LCDClient, MnemonicKey, MsgExecute, Wallet } from '@initia/initia.js'
+
+const key = new MnemonicKey({
+  mnemonic:
+    'deal earth suggest craft impact vocal outdoor perfect winter nice unhappy lizard',
+})
+console.log('mnemonic:', key.mnemonic)
+// mnemonic: beauty sniff protect...
+console.log('account address:', key.accAddress)
+// account address: init10m5nnevplkzvv5svqf0xjx6dc4705u5dxfn2st
+
+const lcd = new LCDClient('https://api-initia-testnet.whispernode.com/', {
+  chainId: 'initiation-1',
+})
+
+const wallet = new Wallet(lcd, key)
+const msg = new MsgExecute(
+  key.accAddress,
+  '0x1',
+  'dex',
+  'swap_script',
+  [],
+  [
+    'sTSuZ4bxDvdClOYn0lGbY7fHQqZzX5hoKSn+qahHRNI=',
+    'jkczvavPfUr8PRTw3UbJv1L7D86eS5lsk54ZW4vIkdk=',
+    'QEIPAAAAAAA=',
+    'AdWGAQAAAAAA',
+  ],
+)
+
+async function main() {
+  const signed = await wallet.createAndSignTx({
+    msgs: [msg],
+    memo: '',
+  })
+  const broadcast = await lcd.tx.broadcast(signed)
+  console.log(broadcast)
+}
+main()

+ 10 - 0
src/validatorArray.ts

@@ -0,0 +1,10 @@
+export const validatorArray = [
+  'initvaloper10jwqn04rmfd9lkdk9srzuc4l75gjw6c6nq335s',
+  'initvaloper1jt9w26mpxxjsk63mvd4m2ynj0af09cslej8vvr',
+  'initvaloper1zlu3v7jan5vj0wff8ggl5f3n0n7d0yjlmskdrm',
+  'initvaloper1r3cuy3q2gxh0mpj2nu0cnpqtutaxx9z87r6qtt',
+  'initvaloper1xxae4payg8jvs6tk9p8y5zdx43fn30zx6mje5c',
+  'initvaloper10jwqn04rmfd9lkdk9srzuc4l75gjw6c6nq335s',
+  'initvaloper16we96acr8p3y7khq3held9pa6n9jdpwhthf5fk',
+  'initvaloper1vem4deerwx34p0w67yce2umsrjasmps2sfmzav',
+]

文件差异内容过多而无法显示
+ 421 - 103
yarn.lock


部分文件因为文件数量过多而无法显示