diff --git a/typescript-sdk/bun.lockb b/typescript-sdk/bun.lockb index 2b5545f3c7..57aea01f96 100755 Binary files a/typescript-sdk/bun.lockb and b/typescript-sdk/bun.lockb differ diff --git a/typescript-sdk/package.json b/typescript-sdk/package.json index ad6c8d2559..d9e70aee20 100644 --- a/typescript-sdk/package.json +++ b/typescript-sdk/package.json @@ -30,6 +30,7 @@ "@total-typescript/ts-reset": "^0.5.1", "@types/bun": "^1.1.2", "@types/node": "^20.12.12", + "consola": "^3.2.3", "cosmjs-types": "^0.9.0", "patch-package": "^8.0.0", "tsx": "^4.10.5", diff --git a/typescript-sdk/scripts/logger.ts b/typescript-sdk/scripts/logger.ts new file mode 100644 index 0000000000..20d8b5858f --- /dev/null +++ b/typescript-sdk/scripts/logger.ts @@ -0,0 +1,15 @@ +import { createConsola } from "consola" + +export const consola = createConsola({ + formatOptions: { + date: true, + colors: true + } +}) + +export const timestamp = () => { + const d = new Date() + const [date] = d.toISOString().split("T") + const [time] = d.toTimeString().split(" ") + return `${date} ${time}` +} diff --git a/typescript-sdk/scripts/union-to-sepolia.ts b/typescript-sdk/scripts/union-to-sepolia.ts index 5726a54396..93e100ade9 100644 --- a/typescript-sdk/scripts/union-to-sepolia.ts +++ b/typescript-sdk/scripts/union-to-sepolia.ts @@ -1,16 +1,25 @@ #!/usr/bin/env bun +import "#/patch.ts" import { parseArgs } from "node:util" import { UnionClient } from "#/mod.ts" +import { consola, timestamp } from "./logger.ts" +import type { ExecuteInstruction } from "@cosmjs/cosmwasm-stargate" /* `bun scripts/to-sepolia.ts --private-key "..."` */ const { values } = parseArgs({ args: process.argv.slice(2), - options: { "private-key": { type: "string" } } + options: { + "private-key": { type: "string" }, + "tx-count": { type: "string", default: "1" } + } }) const PRIVATE_KEY = values["private-key"] if (!PRIVATE_KEY) throw new Error("Private key not found") +const TX_COUNT = Number(values["tx-count"]) + +consola.box(`Sending ${TX_COUNT} transactions from Union to Sepolia`) const unionClient = await UnionClient.connectWithSecret({ rpcUrl: "https://rpc.testnet.bonlulu.uno", @@ -22,24 +31,33 @@ const unionClient = await UnionClient.connectWithSecret({ }) const contractAddress = "union124t57vjgsyknnhmr3fpkmyvw2543448kpt2xhk5p5hxtmjjsrmzsjyc4n7" -const unoFromUnionToSepolia = await unionClient.transferAssets({ - kind: "cosmwasm", - instructions: [ - { - contractAddress, - msg: { - transfer: { - channel: "channel-0", - receiver: "0x8478B37E983F520dBCB5d7D3aAD8276B82631aBd".slice(2), - memo: "sending UNO from Union to Sepolia" - } - }, - funds: [ - // denom: `factory/union124t57vjgsyknnhmr3fpkmyvw2543448kpt2xhk5p5hxtmjjsrmzsjyc4n7/0xc5775fca1b3285dc8b749d58b227527211c108b8d3` - { amount: "30", denom: `muno` } - ] - } - ] -}) -console.log(unoFromUnionToSepolia.transactionHash) +const unionToSepoliaTransactions: Array = Array.from( + { length: TX_COUNT }, + (_, index) => ({ + contractAddress, + msg: { + transfer: { + channel: "channel-0", + receiver: "0xD0081080Ae8493cf7340458Eaf4412030df5FEEb".slice(2), + memo: `${index} - ${timestamp()} Sending UNO from Union to Sepolia` + } + }, + funds: [{ amount: (index + 1).toString(), denom: `muno` }] + }) +) + +const transactionResults = await Array.fromAsync( + unionToSepoliaTransactions, + async transaction => + unionClient.transferAssets({ kind: "cosmwasm", instructions: [transaction] }), + { concurrency: 1 } +) + +consola.info( + JSON.stringify( + transactionResults.map(item => item.transactionHash), + undefined, + 2 + ) +) diff --git a/typescript-sdk/src/mod.ts b/typescript-sdk/src/mod.ts index 1a700c50c0..e956a146b2 100644 --- a/typescript-sdk/src/mod.ts +++ b/typescript-sdk/src/mod.ts @@ -215,7 +215,7 @@ export class UnionClient implements IUnionClient { public async cosmwasmMessageExecuteContract( instructions: Array ): Promise { - const { address: signerAddress } = await this.getAccount() + const { address: signerAddress, algo, pubkey } = await this.getAccount() const cosmwasmClient = await this.signingCosmWasmClient() const response = await cosmwasmClient.executeMultiple(signerAddress, instructions, "auto") return response