Skip to content

Commit 49a6bd6

Browse files
committed
chore(app): adding predict token wrapped for aptos wip
Signed-off-by: Kaan Caglan <[email protected]>
1 parent be65835 commit 49a6bd6

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

typescript-sdk/playground/union-to-movement.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ const DESTINATION_CHAIN_ID = "250"
5757
const channels = await getRecommendedChannels()
5858

5959
let channel_info = getChannelInfo(SOURCE_CHAIN_ID, DESTINATION_CHAIN_ID, channels)
60-
if (channel_info === null) {
60+
if (channel_info === null || true) {
6161
// Creating movement channel since its not found in hubble.
6262
channel_info = {
6363
source_chain_id: SOURCE_CHAIN_ID,
6464
source_port_id:
6565
"756e696f6e3178326a7a65757037757766786a78787274666e61326b746375676c746e746775366b766330656561796b306438326c32343763717a3636396565",
66-
source_channel_id: 18,
67-
source_connection_id: 23,
66+
source_channel_id: 27,
67+
source_connection_id: 36,
6868
destination_chain_id: DESTINATION_CHAIN_ID,
69-
destination_port_id: "0x7e385b7c720b279f6871bbd409dd2fb026d3193e2b40c705e8896d51141c1076",
70-
destination_channel_id: 1,
69+
destination_port_id: "0x80a825c8878d4e22f459f76e581cb477d82f0222e136b06f01ad146e2ae9ed84",
70+
destination_channel_id: 2,
7171
destination_connection_id: 1
7272
}
7373
}
@@ -80,12 +80,13 @@ let quoteToken = await getQuoteToken(SOURCE_CHAIN_ID, MUNO_DENOM, channel_info)
8080
// consola.error(quoteToken.error)
8181
// process.exit(1)
8282
// }
83-
83+
console.info("quote token", quoteToken)
84+
process.exit(1)
8485
// manual quote token:
8586
quoteToken = {
8687
type: "UNWRAPPED",
8788
value: {
88-
quote_token: `0x5b8dc541f42c8f31fceaf74f40e3e450a058406ca370779f96b25776c88f672e`
89+
quote_token: `0x188b41399546602e35658962477fdf72bd52443474a899d9d48636e8bc299c2c`
8990
}
9091
}
9192

typescript-sdk/src/query/offchain/ucs03-channels.ts

+60-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
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"
29
import { graphql } from "gql.tada"
310
import { request } from "graphql-request"
411
import { createPublicClient, fromHex, http, isHex, type Hex } from "viem"
512
import { err, ok, ResultAsync, type Result } from "neverthrow"
613
import { ucs03ZkgmAbi } from "#abi/ucs-03"
714
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate"
815
import { cosmosRpcs, type CosmosChainId } from "#cosmos/client"
16+
import { Aptos, AptosConfig, Network, Deserializer, MoveVector } from "@aptos-labs/ts-sdk"
917

1018
const channelsQuery = graphql(/* GraphQL */ `
1119
query Ucs03Channels {
@@ -172,6 +180,57 @@ export const getQuoteToken = async (
172180
return ok({ type: "NEW_WRAPPED", quote_token: predictedQuoteToken.value[0] })
173181
}
174182

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+
175234
return err(new Error("unknown chain in token prediction"))
176235
}
177236

0 commit comments

Comments
 (0)