Skip to content

Commit bc4145d

Browse files
committed
chore(ts-sdk-sui): fully functional ts-sdk example for sui->union
Signed-off-by: kaancaglan <[email protected]>
1 parent 92b4711 commit bc4145d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

ts-sdk-sui/examples/sui-create-client-generate-instruction.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC)
2929

3030
const program = Effect.gen(function* () {
3131

32+
3233
// TODO: Source will be SUI testnet
3334
const source = yield* ChainRegistry.byUniversalId(
3435
UniversalChainId.make("ethereum.17000"),
@@ -44,30 +45,27 @@ const program = Effect.gen(function* () {
4445

4546
const sender = wallet.signer.toSuiAddress();
4647

47-
48-
// deployed contract: union1l0rpy8yauy7nzv4vu6mgz6kjpqzvws85l8mgzm6eansasx90t57sc7k4ue
49-
5048
console.log("sender:", sender)
5149

5250
const tokenOrder = yield* TokenOrder.make({
5351
source,
5452
destination,
55-
sender: "0x06627714f3F17a701f7074a12C02847a5D2Ca487",
56-
receiver: "0x756E696F6E317779637938673876357366663667736A6C3979686A73343371393878706C30357033676E3273",
57-
baseToken: "0x3078323A3A7375693A3A535549",
58-
baseAmount: 100000n,
59-
quoteToken: "0x756E696F6E316C307270793879617579376E7A76347675366D677A366B6A70717A76777338356C386D677A6D3665616E7361737839307435377363376B347565",
60-
quoteAmount: 10000n,
53+
sender: sender,
54+
receiver: "union1wycy8g8v5sff6gsjl9yhjs43q98xpl05p3gn2s",
55+
baseToken: "0x2::sui::SUI",
56+
baseAmount: 10000000n,
57+
quoteToken: "union1y05e0p2jcvhjzf7kcqsrqx93d4g3u93hc2hykaq8hrvkqrp5ltrssagzyd",
58+
quoteAmount: 10000000n,
6159
kind: "solve",
6260
metadata:
63-
"0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040756e696f6e31736b673532343468706b61643630337a7a37376b64656b7a77366666677066726465336c646b387270647a30366e36326b34687163743077346a",
61+
"0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040756e696f6e31793035653070326a6376686a7a66376b63717372717839336434673375393368633268796b6171386872766b717270356c7472737361677a7964",
6462
version: 2,
6563
})
6664

6765
const request = ZkgmClientRequest.make({
6866
source,
6967
destination,
70-
channelId: ChannelId.make(1),
68+
channelId: ChannelId.make(5),
7169
ucs03Address: "union1rfz3ytg6l60wxk5rxsk27jvn2907cyav04sz8kde3xhmmf9nplxqr8y05c",
7270
instruction: tokenOrder,
7371
})
@@ -77,7 +75,6 @@ const program = Effect.gen(function* () {
7775

7876
const response: ZkgmClientResponse.ZkgmClientResponse = yield* zkgmClient.execute(request)
7977

80-
8178
yield* Effect.log("Submission Hash", response.txHash)
8279

8380
const completion = yield* response.waitFor(

ts-sdk-sui/src/internal/zkgmClient.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ export const fromWallet = (
130130

131131
// This 2 will be get by user all the time
132132
const typeArg = "0x2::sui::SUI" // TODO: This should be dynamic based on the token sent
133-
const coinObjectId = "0xfdb7b5b54d61ed21373f2785c7583c1ff6fd85e9b04fa289da50bba563190b62" // TODO: This should be given by user
133+
const coinObjectId = "0x89c430d35fa9f2778b0a635027b178146eb26d70d16292c289304d476ecf76cd" // TODO: This should be given by user
134134
// Note: There can be multiple coins, for simplicity we are using one coin here
135135
// User should be able to provide typeArgs and coinObjectIds array
136136

137-
138137
const hexToBytes = (hex: `0x${string}`): Uint8Array => {
139138
const s = hex.slice(2)
140139
const out = new Uint8Array(s.length / 2)

ts-sdk/src/schema/chain.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type UniversalChainId = typeof UniversalChainId.Type
1616

1717
export const ChainDisplayName = S.String.pipe(S.brand("ChainDisplayName"))
1818

19-
export const RpcType = S.Literal("evm", "cosmos", "aptos")
19+
export const RpcType = S.Literal("evm", "cosmos", "aptos", "sui")
2020
export type RpcType = typeof RpcType.Type
2121

2222
export class ChainFeatures extends S.Class<ChainFeatures>("ChainFeatures")({
@@ -147,6 +147,8 @@ export class Chain extends S.Class<Chain>("Chain")({
147147
case "aptos":
148148
// Aptos uses the canonical format
149149
return Effect.succeed(address)
150+
case "sui":
151+
return Effect.succeed(address)
150152
default:
151153
return Effect.fail(new NotACosmosChainError({ chain: this }))
152154
}

0 commit comments

Comments
 (0)