Skip to content

Commit

Permalink
feat(sdk): add multi-send
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az authored and cor committed May 29, 2024
1 parent 53db2de commit d783a18
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
Binary file modified typescript-sdk/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions typescript-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions typescript-sdk/scripts/logger.ts
Original file line number Diff line number Diff line change
@@ -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}`
}
60 changes: 39 additions & 21 deletions typescript-sdk/scripts/union-to-sepolia.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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<ExecuteInstruction> = 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
)
)
2 changes: 1 addition & 1 deletion typescript-sdk/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class UnionClient implements IUnionClient {
public async cosmwasmMessageExecuteContract(
instructions: Array<ExecuteInstruction>
): Promise<ExecuteResult> {
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
Expand Down

0 comments on commit d783a18

Please sign in to comment.