From b02ca285fbe20b0e04dcf918ad5de618c6d6b409 Mon Sep 17 00:00:00 2001 From: Kaan Caglan Date: Thu, 6 Mar 2025 15:28:20 +0300 Subject: [PATCH] chore(app): applied nix-fmt Signed-off-by: Kaan Caglan --- .../components/Cube/faces/Transfer.svelte | 20 +++--- .../lib/components/TransferCube/index.svelte | 21 +++--- app/src/lib/components/connect/connect.svelte | 2 +- app/src/lib/stores/balances.ts | 18 ++--- .../playground/movement-to-stride.ts | 2 +- .../playground/movement-to-union.ts | 2 +- .../playground/stride-to-movement.ts | 11 ++- .../playground/union-to-movement.ts | 5 +- typescript-sdk/src/aptos/client.ts | 69 +++++++++---------- .../src/query/offchain/ucs03-channels.ts | 2 +- 10 files changed, 70 insertions(+), 82 deletions(-) diff --git a/app/src/lib/components/TransferCube/components/Cube/faces/Transfer.svelte b/app/src/lib/components/TransferCube/components/Cube/faces/Transfer.svelte index 639b98cb49..4bc4cafaed 100644 --- a/app/src/lib/components/TransferCube/components/Cube/faces/Transfer.svelte +++ b/app/src/lib/components/TransferCube/components/Cube/faces/Transfer.svelte @@ -88,14 +88,13 @@ const transfer = async () => { // @ts-ignore transferState.set({ kind: "SWITCHING_TO_CHAIN" }) - let rpcUrl = sourceChain.rpcs.find((rpc) => rpc.type === "rpc")?.url; - if (!rpcUrl) - return toast.error(`no rpc available for ${sourceChain.display_name}`); + let rpcUrl = sourceChain.rpcs.find(rpc => rpc.type === "rpc")?.url + if (!rpcUrl) return toast.error(`no rpc available for ${sourceChain.display_name}`) - if (!rpcUrl.endsWith("/v1", rpcUrl.length - 3)) { - rpcUrl = rpcUrl + "/v1"; - } - rpcUrl = "https://aptos.testnet.bardock.movementlabs.xyz/v1"; //TODO: Remove this later its for test + if (!rpcUrl.endsWith("/v1", rpcUrl.length - 3)) { + rpcUrl = rpcUrl + "/v1" + } + rpcUrl = "https://aptos.testnet.bardock.movementlabs.xyz/v1" //TODO: Remove this later its for test if (stepBefore($transferState, "CONFIRMING_TRANSFER")) { const chainInfo = await wallet.getNetwork() @@ -114,7 +113,7 @@ const transfer = async () => { if (stepBefore($transferState, "TRANSFERRING")) { try { - let account = await wallet?.getAccount(); + let account = await wallet?.getAccount() const client = createUnionClient({ chainId: sourceChain.chain_id as AptosChainId, account: account, @@ -141,8 +140,7 @@ const transfer = async () => { return } } - } - else if (sourceChain.rpc_type === "cosmos" && transferArgs !== "NO_QUOTE_AVAILABLE") { + } else if (sourceChain.rpc_type === "cosmos" && transferArgs !== "NO_QUOTE_AVAILABLE") { const { connectedWallet, connectionStatus } = get(cosmosStore) if ($userAddrCosmos === null) return toast.error("No Cosmos user address found") @@ -263,7 +261,7 @@ const transfer = async () => { receiver: transferArgs.receiver, baseToken: fromHex(transferArgs.baseToken, "string") } - + if (destChain.rpc_type !== "aptos") { realArgs.receiver = toHex(transferArgs.receiver) } diff --git a/app/src/lib/components/TransferCube/index.svelte b/app/src/lib/components/TransferCube/index.svelte index 05a41b81f7..9d21221a93 100644 --- a/app/src/lib/components/TransferCube/index.svelte +++ b/app/src/lib/components/TransferCube/index.svelte @@ -179,19 +179,16 @@ onMount(() => { const unsubscribe = transfer.subscribe(trans => { const chain = trans.intents.sourceChain if (chain) { - let userAddr; + let userAddr if (chain.rpc_type === "evm") { - userAddr = $userAddress.evm?.canonical.toLowerCase(); - } else if ( - chain.rpc_type === "aptos" || - chain.chain_id === "movement" - ) { - // Use the aptos field for Movement - userAddr = $userAddress.aptos?.canonical.toLowerCase(); - } else { - // Fallback to cosmos conversion if needed - userAddr = $userAddrCosmos?.canonical; - } + userAddr = $userAddress.evm?.canonical.toLowerCase() + } else if (chain.rpc_type === "aptos" || chain.chain_id === "movement") { + // Use the aptos field for Movement + userAddr = $userAddress.aptos?.canonical.toLowerCase() + } else { + // Fallback to cosmos conversion if needed + userAddr = $userAddrCosmos?.canonical + } if (userAddr && (previousSourceChain !== chain.chain_id || previousUserAddr !== userAddr)) { previousUserAddr = userAddr previousSourceChain = chain.chain_id diff --git a/app/src/lib/components/connect/connect.svelte b/app/src/lib/components/connect/connect.svelte index 2a548ce7cc..738e8b21a1 100644 --- a/app/src/lib/components/connect/connect.svelte +++ b/app/src/lib/components/connect/connect.svelte @@ -34,7 +34,7 @@ let connectedWallets = derived( ) // Set to 3 when shipping aptos. - const WALLET_COUNT = 3; +const WALLET_COUNT = 3 $: if ($connectedWallets >= 1) { buttonText = diff --git a/app/src/lib/stores/balances.ts b/app/src/lib/stores/balances.ts index 53f45723f1..bd8f2ecde4 100644 --- a/app/src/lib/stores/balances.ts +++ b/app/src/lib/stores/balances.ts @@ -64,10 +64,10 @@ export async function queryBalances(chain: Chain, address: string) { } export async function updateBalancesAptos(chain: Chain, address: Address) { // Optionally mark expected tokens as "loading" (if chain.tokens exists) - if (chain.tokens && chain.tokens.length) { + if (chain.tokens && chain.tokens.length > 0) { chain.tokens.forEach(token => updateBalance(chain.chain_id, token.denom, { kind: "loading", timestamp: Date.now() }) - ); + ) } // Define the GraphQL query and variables. @@ -88,18 +88,18 @@ export async function updateBalancesAptos(chain: Chain, address: Address) { } } } - `; + ` const variables = { owner_address: address, limit: 200, offset: 0 - }; + } // Set up the fetch options with appropriate headers. const fetchOptions: RequestInit = { method: "POST", - body: JSON.stringify({ query, variables }), - }; + body: JSON.stringify({ query, variables }) + } try { // Send the request to the Aptos indexer. @@ -110,9 +110,9 @@ export async function updateBalancesAptos(chain: Chain, address: Address) { if (response.isErr()) { throw new Error(response.error.message) } - const data = response.value.data; + const data = response.value.data if (!data || !data.current_fungible_asset_balances) { - throw new Error("Invalid response data"); + throw new Error("Invalid response data") } const aptosBalances = data.current_fungible_asset_balances @@ -133,7 +133,7 @@ export async function updateBalancesAptos(chain: Chain, address: Address) { } catch (error: any) { console.error("Error fetching Aptos balances", error) // On error, update the balances for all tokens with an error state. - if (chain.tokens && chain.tokens.length) { + if (chain.tokens?.length) { chain.tokens.forEach(token => updateBalance(chain.chain_id, token.denom, { kind: "error", diff --git a/typescript-sdk/playground/movement-to-stride.ts b/typescript-sdk/playground/movement-to-stride.ts index 0ffedf5590..aaf8144a55 100644 --- a/typescript-sdk/playground/movement-to-stride.ts +++ b/typescript-sdk/playground/movement-to-stride.ts @@ -2,7 +2,7 @@ import { http } from "viem" import { parseArgs } from "node:util" import { consola } from "scripts/logger" import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk" -import { createUnionClient, bech32AddressToHex } from "#mod.ts" +import { createUnionClient } from "#mod.ts" import { getChannelInfo, diff --git a/typescript-sdk/playground/movement-to-union.ts b/typescript-sdk/playground/movement-to-union.ts index 2e3dcce29e..8812ea274b 100644 --- a/typescript-sdk/playground/movement-to-union.ts +++ b/typescript-sdk/playground/movement-to-union.ts @@ -2,7 +2,7 @@ import { http } from "viem" import { parseArgs } from "node:util" import { consola } from "scripts/logger" import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk" -import { createUnionClient, bech32AddressToHex } from "#mod.ts" +import { createUnionClient } from "#mod.ts" import { getChannelInfo, diff --git a/typescript-sdk/playground/stride-to-movement.ts b/typescript-sdk/playground/stride-to-movement.ts index db86a7b1ef..817644151d 100644 --- a/typescript-sdk/playground/stride-to-movement.ts +++ b/typescript-sdk/playground/stride-to-movement.ts @@ -63,21 +63,19 @@ if (channel_info === null) { consola.info("no channel found") channel_info = { source_chain_id: SOURCE_CHAIN_ID, - source_port_id: "7374726964653178326a7a65757037757766786a78787274666e61326b746375676c746e746775366b766330656561796b306438326c3234376371333570727573", + source_port_id: + "7374726964653178326a7a65757037757766786a78787274666e61326b746375676c746e746775366b766330656561796b306438326c3234376371333570727573", source_channel_id: 5, source_connection_id: 333333333, destination_chain_id: DESTINATION_CHAIN_ID, - destination_port_id: - "80a825c8878d4e22f459f76e581cb477d82f0222e136b06f01ad146e2ae9ed84", + destination_port_id: "80a825c8878d4e22f459f76e581cb477d82f0222e136b06f01ad146e2ae9ed84", destination_channel_id: 4, destination_connection_id: 333333333 } } consola.info("channel", channel_info) -let quoteToken = await getQuoteToken(SOURCE_CHAIN_ID, MUNO_HEX, channel_info - -) +let quoteToken = await getQuoteToken(SOURCE_CHAIN_ID, MUNO_HEX, channel_info) if (quoteToken.isErr()) { consola.info("could not get quote token") consola.error(quoteToken.error) @@ -96,7 +94,6 @@ if (!PRIVATE_KEY) { process.exit(1) } - const unionClient = createUnionClient({ chainId: SOURCE_CHAIN_ID, account: await DirectSecp256k1Wallet.fromKey(Uint8Array.from(hexToBytes(PRIVATE_KEY)), "stride"), diff --git a/typescript-sdk/playground/union-to-movement.ts b/typescript-sdk/playground/union-to-movement.ts index 7d6fe9ccbd..362a9232fc 100644 --- a/typescript-sdk/playground/union-to-movement.ts +++ b/typescript-sdk/playground/union-to-movement.ts @@ -65,9 +65,7 @@ if (channel_info === null) { } consola.info("channel", channel_info) -let quoteToken = await getQuoteToken(SOURCE_CHAIN_ID, MUNO_HEX, channel_info - -) +let quoteToken = await getQuoteToken(SOURCE_CHAIN_ID, MUNO_HEX, channel_info) if (quoteToken.isErr()) { consola.info("could not get quote token") consola.error(quoteToken.error) @@ -86,7 +84,6 @@ if (!PRIVATE_KEY) { process.exit(1) } - const unionClient = createUnionClient({ chainId: SOURCE_CHAIN_ID, account: await DirectSecp256k1Wallet.fromKey(Uint8Array.from(hexToBytes(PRIVATE_KEY)), "union"), diff --git a/typescript-sdk/src/aptos/client.ts b/typescript-sdk/src/aptos/client.ts index 7138ecff69..896ab82c29 100644 --- a/typescript-sdk/src/aptos/client.ts +++ b/typescript-sdk/src/aptos/client.ts @@ -14,9 +14,9 @@ export type AptosSigner = AptosAccount | (AptosBrowserWallet & { accountAddress: export type { AptosAccount, AptosBrowserWallet } export const aptosChainId = [ - "2", // aptos testnet + "2", // aptos testnet "177", // movement porto - "250" // movement bardock + "250" // movement bardock ] as const export type AptosChainId = `${(typeof aptosChainId)[number]}` @@ -33,19 +33,23 @@ export type AptosClientParameters = { | { account: AptosAccount; transport: HttpTransport } | { account?: AptosPublicAccountInfo; transport: AptosWindowTransport } ) -export type WalletSigner = AptosBrowserWallet & { accountAddress: string }; +export type WalletSigner = AptosBrowserWallet & { accountAddress: string } /** * Overloads for retrieving an Aptos client. */ async function getAptosClient( parameters: AptosClientParameters & { authAccess: "key" } -): Promise<{ authAccess: "key"; aptos: Aptos; signer: AptosSigner; transport: HttpTransport }>; +): Promise<{ authAccess: "key"; aptos: Aptos; signer: AptosSigner; transport: HttpTransport }> async function getAptosClient( parameters: AptosClientParameters & { authAccess: "wallet" } -): Promise<{ authAccess: "wallet"; aptos: Aptos; signer: AptosSigner; transport: AptosWindowTransport }>; - +): Promise<{ + authAccess: "wallet" + aptos: Aptos + signer: AptosSigner + transport: AptosWindowTransport +}> async function getAptosClient( parameters: AptosClientParameters & { authAccess: AuthAccess } @@ -76,22 +80,20 @@ async function getAptosClient( throw new Error("Invalid Aptos transport") } const networkInfo = await parameters.transport.getNetwork() - const network = - networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET + const network = networkInfo.name.toLowerCase() === "mainnet" ? Network.MAINNET : Network.TESTNET const config = new AptosConfig({ fullnode: networkInfo.url, network }) - + // Get the connected account - const account = await parameters.transport.getAccount?.() || - { address: "" } + const account = (await parameters.transport.getAccount?.()) || { address: "" } if (!account.address) { throw new Error("No account address found from the wallet") } - + // Create a signer by merging the wallet’s methods with the account address. const signer = Object.assign({}, parameters.transport, { accountAddress: account.address - }) as unknown as AptosAccount // <== Force-cast to AptosAccount - + }) as unknown as AptosAccount // <== Force-cast to AptosAccount + return { authAccess: "wallet", aptos: new Aptos(config), @@ -99,7 +101,6 @@ async function getAptosClient( transport: parameters.transport } } - throw new Error("Invalid Aptos transport") } @@ -129,10 +130,9 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => { if (typeof clientParameters.transport === "function") { console.info("returning key-based client") return await getAptosClient({ ...clientParameters, authAccess: "key" }) - } else { - console.info("returning wallet-based client") - return await getAptosClient({ ...clientParameters, authAccess: "wallet" }) } + console.info("returning wallet-based client") + return await getAptosClient({ ...clientParameters, authAccess: "wallet" }) } })) .extend(client => ({ @@ -154,12 +154,12 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => { sourceChannelId, ucs03address }: TransferAssetParameters): Promise> => { - const { aptos, signer, authAccess, transport } = await client.getAptosClient(); + const { aptos, signer, authAccess, transport } = await client.getAptosClient() const quoteTokenVec = MoveVector.U8(quoteToken) const receiverVec = MoveVector.U8(receiver) - const rawSalt = new Uint8Array(14) + const rawSalt = new Uint8Array(14) crypto.getRandomValues(rawSalt) const salt = MoveVector.U8(rawSalt) @@ -189,11 +189,11 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => { const txn = await aptos.signAndSubmitTransaction({ signer: signer as AptosAccount, transaction: payload - }); - const receipt = await waitForTransactionReceipt({ aptos, hash: txn.hash }); - return receipt; - } - const saltHex = toHex(new Uint8Array(14) ); + }) + const receipt = await waitForTransactionReceipt({ aptos, hash: txn.hash }) + return receipt + } + const saltHex = toHex(new Uint8Array(14)) // 14 bytes + 0x 2 bytes and that walletPayload encodes it in it // so it becomes 32 byte. const walletPayload = { @@ -210,14 +210,13 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => { 18446744073709551615n.toString(), saltHex ] - }; + } try { - const signedTxn = await transport.signAndSubmitTransaction({ payload: walletPayload }); - return ok(signedTxn.hash); // Wrap the string in a successful Result + const signedTxn = await transport.signAndSubmitTransaction({ payload: walletPayload }) + return ok(signedTxn.hash) // Wrap the string in a successful Result } catch (error) { - return err(new Error("Transaction signing failed")); + return err(new Error("Transaction signing failed")) } - } catch (error) { console.info("error is:", error) return err(new Error("failed to execute aptos call", { cause: error as Error })) @@ -228,17 +227,17 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => { function toHex(uint8array: Uint8Array): string { return `0x${Array.from(uint8array) .map(b => b.toString(16).padStart(2, "0")) - .join("")}`; + .join("")}` } function hexToAscii(hexString: string): string { // Remove the "0x" prefix if present. if (hexString.startsWith("0x") || hexString.startsWith("0X")) { - hexString = hexString.slice(2); + hexString = hexString.slice(2) } - let ascii = ""; + let ascii = "" for (let i = 0; i < hexString.length; i += 2) { - ascii += String.fromCharCode(parseInt(hexString.substr(i, 2), 16)); + ascii += String.fromCharCode(Number.parseInt(hexString.substr(i, 2), 16)) } - return ascii; + return ascii } diff --git a/typescript-sdk/src/query/offchain/ucs03-channels.ts b/typescript-sdk/src/query/offchain/ucs03-channels.ts index c2c73d47fb..4064b1db51 100644 --- a/typescript-sdk/src/query/offchain/ucs03-channels.ts +++ b/typescript-sdk/src/query/offchain/ucs03-channels.ts @@ -13,7 +13,7 @@ import { err, ok, ResultAsync, type Result } from "neverthrow" import { ucs03ZkgmAbi } from "#abi/ucs-03" import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate" import { cosmosRpcs, type CosmosChainId } from "#cosmos/client" -import { Aptos, AptosConfig, Network, Deserializer, MoveVector } from "@aptos-labs/ts-sdk" +import { Aptos, AptosConfig, Network, MoveVector } from "@aptos-labs/ts-sdk" const channelsQuery = graphql(/* GraphQL */ ` query Ucs03Channels {