|
1 |
| -import { cosmosChainId, evmChainFromChainId, type EvmChainId, evmChainId, GRAQPHQL_URL } from "#mod" |
| 1 | +import { |
| 2 | + aptosChainId, |
| 3 | + cosmosChainId, |
| 4 | + evmChainFromChainId, |
| 5 | + type EvmChainId, |
| 6 | + evmChainId, |
| 7 | + GRAQPHQL_URL |
| 8 | +} from "#mod" |
2 | 9 | import { graphql } from "gql.tada"
|
3 | 10 | import { request } from "graphql-request"
|
4 | 11 | import { createPublicClient, fromHex, http, isHex, type Hex } from "viem"
|
5 | 12 | import { err, ok, ResultAsync, type Result } from "neverthrow"
|
6 | 13 | import { ucs03ZkgmAbi } from "#abi/ucs-03"
|
7 | 14 | import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate"
|
8 | 15 | import { cosmosRpcs, type CosmosChainId } from "#cosmos/client"
|
| 16 | +import { Aptos, AptosConfig, Network, Deserializer, MoveVector } from "@aptos-labs/ts-sdk" |
9 | 17 |
|
10 | 18 | const channelsQuery = graphql(/* GraphQL */ `
|
11 | 19 | query Ucs03Channels {
|
@@ -172,6 +180,57 @@ export const getQuoteToken = async (
|
172 | 180 | return ok({ type: "NEW_WRAPPED", quote_token: predictedQuoteToken.value[0] })
|
173 | 181 | }
|
174 | 182 |
|
| 183 | + // aptos token prediction |
| 184 | + if (aptosChainId.includes(channel.destination_chain_id)) { |
| 185 | + let network: Network |
| 186 | + let rpcUrl = "" |
| 187 | + if (channel.destination_chain_id === "126") { |
| 188 | + network = Network.MAINNET |
| 189 | + } else if (channel.destination_chain_id === "250") { |
| 190 | + network = Network.TESTNET |
| 191 | + rpcUrl = "https://aptos.testnet.bardock.movementlabs.xyz/v1" |
| 192 | + } else { |
| 193 | + return err(new Error(`Unsupported Aptos network: ${channel.destination_chain_id}`)) |
| 194 | + } |
| 195 | + |
| 196 | + const config = new AptosConfig({ network: network, fullnode: rpcUrl }) |
| 197 | + const aptos = new Aptos(config) |
| 198 | + |
| 199 | + // Define the Move function call. |
| 200 | + // Replace <MODULE_ADDRESS> and <MODULE_NAME> with your contract's module address and name. |
| 201 | + // const functionCall = |
| 202 | + // Build the transaction payload. |
| 203 | + |
| 204 | + const receiverVec = MoveVector.U8("0x6d756e6f") |
| 205 | + const output = await aptos.experimental.viewBinary({ |
| 206 | + payload: { |
| 207 | + function: `${channel.destination_port_id}::ibc_app::predict_wrapped_token`, |
| 208 | + typeArguments: [], |
| 209 | + // Adjust functionArguments as needed. |
| 210 | + functionArguments: [ |
| 211 | + 0, // path |
| 212 | + channel.destination_channel_id, // channel |
| 213 | + receiverVec |
| 214 | + ] |
| 215 | + } |
| 216 | + }) |
| 217 | + |
| 218 | + console.info("base_token:", base_token) |
| 219 | + console.info("transaction:", output) |
| 220 | + console.info("channel.destination_channel_id:", channel.destination_channel_id) |
| 221 | + console.info("channel.destination_port_id:", channel.destination_port_id) |
| 222 | + const deserializer = new Deserializer(output.slice(1)) |
| 223 | + const addressBytes = deserializer.deserializeFixedBytes(32) |
| 224 | + const wrappedAddressHex = "0x" + Buffer.from(addressBytes).toString("hex") |
| 225 | + |
| 226 | + // // 2) The second return value is the salt (vector<u8>) |
| 227 | + // const saltBytes = deserializer.deserializeBytes() |
| 228 | + // const saltHex = "0x" + Buffer.from(saltBytes).toString("hex") |
| 229 | + |
| 230 | + console.log("Wrapped address:", wrappedAddressHex) |
| 231 | + return ok({ type: "NEW_WRAPPED", quote_token: wrappedAddressHex }) |
| 232 | + } |
| 233 | + |
175 | 234 | return err(new Error("unknown chain in token prediction"))
|
176 | 235 | }
|
177 | 236 |
|
|
0 commit comments