Skip to content

Commit

Permalink
chore(app): applied nix-fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Kaan Caglan <[email protected]>
  • Loading branch information
Caglankaan committed Mar 6, 2025
1 parent 0108236 commit b02ca28
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down
21 changes: 9 additions & 12 deletions app/src/lib/components/TransferCube/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/components/connect/connect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
18 changes: 9 additions & 9 deletions app/src/lib/stores/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion typescript-sdk/playground/movement-to-stride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion typescript-sdk/playground/movement-to-union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions typescript-sdk/playground/stride-to-movement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
Expand Down
5 changes: 1 addition & 4 deletions typescript-sdk/playground/union-to-movement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
Expand Down
69 changes: 34 additions & 35 deletions typescript-sdk/src/aptos/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`

Expand All @@ -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 }
Expand Down Expand Up @@ -76,30 +80,27 @@ 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),
signer: signer,
transport: parameters.transport
}
}


throw new Error("Invalid Aptos transport")
}
Expand Down Expand Up @@ -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 => ({
Expand All @@ -154,12 +154,12 @@ export const createAptosClient = (clientParameters: AptosClientParameters) => {
sourceChannelId,
ucs03address
}: TransferAssetParameters<AptosChainId>): Promise<Result<string, Error>> => {
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)

Expand Down Expand Up @@ -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 = {
Expand All @@ -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 }))
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion typescript-sdk/src/query/offchain/ucs03-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b02ca28

Please sign in to comment.