diff --git a/typescript-sdk/.npmrc b/typescript-sdk/.npmrc index f70cfbc4d3..28850a95ab 100644 --- a/typescript-sdk/.npmrc +++ b/typescript-sdk/.npmrc @@ -1,6 +1,10 @@ +git-checks = false + engine-strict=true package-lock=false +shell-emulator=true git-tag-version=false auto-install-peers=true -node-options="--no-warnings" +node-options="--no-warnings NODE_NO_WARNINGS=1" + @jsr:registry=https://npm.jsr.io diff --git a/typescript-sdk/bun.lockb b/typescript-sdk/bun.lockb index 976f0d03d2..5b19494e38 100755 Binary files a/typescript-sdk/bun.lockb and b/typescript-sdk/bun.lockb differ diff --git a/typescript-sdk/playground/move-to-union.ts b/typescript-sdk/playground/move-to-union.ts index c6a37afdc6..dd8ffe29fc 100644 --- a/typescript-sdk/playground/move-to-union.ts +++ b/typescript-sdk/playground/move-to-union.ts @@ -1,30 +1,23 @@ #!/usr/bin/env bun - import { http } from "viem" import { parseArgs } from "node:util" import { consola } from "scripts/logger" import { raise } from "#utilities/index.ts" -import { createUnionClient, type TransferAssetsParameters } from "#mod.ts" import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk" +import { createUnionClient, type TransferAssetsParameters } from "#mod.ts" -/* npx tsx playground/move-to-union.ts --private-key "e3579557fd55ed8fab0d1e211eb1c05d56d74650e7070b703925493c38fe2aed" --chain-id "2" */ +/* node --import=tsx playground/move-to-union.ts --private-key "e3579557fd55ed8fab0d1e211eb1c05d56d74650e7070b703925493c38fe2aed" */ const { values } = parseArgs({ args: process.argv.slice(2), options: { - "private-key": { type: "string" }, // User's private key - "chain-id": { type: "string" }, // Chain ID for the Move chain - "rpc-url": { type: "string" } // Move RPC URL + "private-key": { type: "string" } // User's private key } }) const PRIVATE_KEY = values["private-key"] -const CHAIN_ID = values["chain-id"] -let RPC_URL = values["rpc-url"] if (!PRIVATE_KEY) raise("Private key not found") -if (!CHAIN_ID) raise("Chain ID not provided") -if (!RPC_URL) RPC_URL = "https://api.testnet.aptoslabs.com/v1" // Convert the hex string private key to a Uint8Array const privateKeyBytes = Uint8Array.from(Buffer.from(PRIVATE_KEY, "hex")) @@ -33,27 +26,26 @@ const moveAccount = Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey(privateKeyBytes) }) -try { - // Create the Move client - const client = createUnionClient({ - account: moveAccount, - chainId: CHAIN_ID as "2", // Adjust according to your setup - transport: http(RPC_URL) - }) - - const transferResult = await client.transferAsset({ - memo: "", - amount: 1n, - receiver: "1363462745291c711144011c1305e737dd74ace69a5576612745e29a2e4fa1b5", - denomAddress: "0x9935a6a334e070bcecf5b1abb1c842c123572e63e70f0539d79610c32954c06c", - destinationChainId: "union-testnet-8" - } satisfies TransferAssetsParameters<"2">) - - consola.success("Transfer result:", transferResult) - consola.success("Move Client created successfully", client) -} catch (error) { - const errorMessage = error instanceof Error ? error.message : error - consola.error("Error creating Move client:", errorMessage) -} finally { - process.exit(0) +// Create the Move client +const client = createUnionClient({ + chainId: "2", + account: moveAccount, + transport: http("https://api.testnet.aptoslabs.com/v1") +}) + +const transferResult = await client.transferAsset({ + memo: "", + amount: 1n, + receiver: "1363462745291c711144011c1305e737dd74ace69a5576612745e29a2e4fa1b5", + denomAddress: "0x9935a6a334e070bcecf5b1abb1c842c123572e63e70f0539d79610c32954c06c", + destinationChainId: "union-testnet-8" +} satisfies TransferAssetsParameters<"2">) + +// consola.success("Move Client created successfully", client) + +if (transferResult.isErr()) { + consola.error("Error transferring asset:", transferResult.error) + process.exit(1) } + +consola.success("Transfer result:", transferResult) diff --git a/typescript-sdk/src/client/move.ts b/typescript-sdk/src/client/move.ts index 1661537c45..6b697dc7d8 100644 --- a/typescript-sdk/src/client/move.ts +++ b/typescript-sdk/src/client/move.ts @@ -1,9 +1,8 @@ -import { createClient, fallback, type HttpTransport } from "viem" import { err, type Result } from "neverthrow" -import type { TransferAssetsParameters } from "./types.ts" -import { consola } from "scripts/logger" -import { transferAssetFromMove } from "src/transfer/move.ts" // Import the Move transfer function import type { Account } from "@aptos-labs/ts-sdk" +import type { TransferAssetsParameters } from "./types.ts" +import { transferAssetFromMove } from "../transfer/move.ts" +import { createClient, fallback, type HttpTransport } from "viem" // Define the list of supported Move chains export const moveChainId = ["2"] as const @@ -18,22 +17,20 @@ export interface MoveClientParameters { /* trunk-ignore(biome/lint/nursery/useExplicitFunctionReturnType) */ export const createMoveClient = (parameters: MoveClientParameters) => - createClient({ transport: fallback([]) }).extend(client => ({ + createClient({ transport: fallback([]) }).extend(_ => ({ transferAsset: async ({ memo, amount, receiver, denomAddress, - destinationChainId, - account = parameters.account, - gasPrice = parameters.gasPrice + destinationChainId: _destinationChainId, + relayContractAddress = "0x52570c4292730a9d81aead22ac75d4bfca3f23d788f679ce72a11ca3fa7d6762", + account = parameters.account }: TransferAssetsParameters): Promise> => { const rpcUrl = parameters.transport({}).value?.url + if (!rpcUrl) return err(new Error("No Move RPC URL found")) if (!account) return err(new Error("No Move account found")) - consola.info(`Move client created for chainId: ${parameters.chainId}`) - consola.info(`RPC URL: ${rpcUrl}`) - consola.info(`account: ${account}`) // const chainDetails = await getHubbleChainDetails({ // destinationChainId, @@ -59,8 +56,6 @@ export const createMoveClient = (parameters: MoveClientParameters) => // const sourceChannel = chainDetails.value.sourceChannel // const relayContractAddress = chainDetails.value.relayContractAddress const sourceChannel = "channel-0" - const relayContractAddress = - "0x52570c4292730a9d81aead22ac75d4bfca3f23d788f679ce72a11ca3fa7d6762" // priv key: 0xe992615114d70429d2920c9d106ac55ec16d9d36a5a017f14f9ee77a85f02467 // account addr: 0xe3579557fd55ed8fab0d1e211eb1c05d56d74650e7070b703925493c38fe2aed diff --git a/typescript-sdk/src/transfer/move.ts b/typescript-sdk/src/transfer/move.ts index 053e337bd2..54e0839510 100644 --- a/typescript-sdk/src/transfer/move.ts +++ b/typescript-sdk/src/transfer/move.ts @@ -1,8 +1,6 @@ import { err, ok, type Result } from "neverthrow" -import { type Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk" -import consola from "consola" -import { raise } from "#utilities/index.ts" import { Hex } from "node_modules/@aptos-labs/ts-sdk/dist/common" +import { type Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk" export type TransferAssetFromMoveParams = { memo?: string @@ -51,20 +49,16 @@ export async function transferAssetFromMove({ }: TransferAssetFromMoveParams): Promise> { try { // Ensure the baseUrl is provided and valid - if (!baseUrl) { - return err(new Error("Base URL for Aptos node not provided")) - } + if (!baseUrl) return err(new Error("Base URL for Aptos node not provided")) // TODO: Handle simulation scenario - if (simulate) { - raise("Simulation not implemented") - } + if (simulate) return err(new Error("Simulation not implemented")) // Setup the Aptos client with the correct network and base URL const config = new AptosConfig({ fullnode: baseUrl, network: Network.TESTNET }) const aptos = new Aptos(config) - consola.info(`Using Aptos fullnode at: ${baseUrl}`) + console.info(`Using Aptos fullnode at: ${baseUrl}`) // Build the transaction using the IBC `send` function (similar to EVM) const transaction = await aptos.transaction.build.simple({ @@ -85,7 +79,7 @@ export async function transferAssetFromMove({ } }) - consola.info("Transaction built successfully") + console.info("Transaction built successfully") // Sign and submit the transaction const senderAuthenticator = aptos.transaction.sign({ @@ -95,7 +89,7 @@ export async function transferAssetFromMove({ const pendingTxn = await aptos.transaction.submit.simple({ transaction, senderAuthenticator }) - consola.info(`Transaction executed! Hash: ${pendingTxn.hash}`) + console.info(`Transaction executed! Hash: ${pendingTxn.hash}`) return ok(pendingTxn.hash) // Return the transaction hash } catch (error) {