Skip to content

Commit a0aa234

Browse files
committed
chore(ts-sdk-sui): working POC added
Signed-off-by: kaancaglan <[email protected]>
1 parent 0622d51 commit a0aa234

File tree

4 files changed

+54
-47
lines changed

4 files changed

+54
-47
lines changed

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,30 @@ import * as TokenOrder from "@unionlabs/sdk/TokenOrder"
2121
import { UniversalChainId } from "@unionlabs/sdk/schema/chain"
2222
import { ChainRegistry } from "@unionlabs/sdk/ChainRegistry"
2323

24-
const MNEMONIC = process.env.MNEMONIC ?? "fix auto gallery heart practice drip joke nice decline lift attend bread"
24+
const MNEMONIC = process.env.SUI_MNEMONIC ?? "..."
2525
const RECIPIENT = process.env.RECIPIENT ?? "0x03ff9dd9e093387bdd4432c6a3eb6a1bd5a8f39a530042ac7efe576f18d3232b"
2626

2727
const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC)
2828

2929

3030
const program = Effect.gen(function* () {
31+
32+
// TODO: Source will be SUI testnet
3133
const source = yield* ChainRegistry.byUniversalId(
3234
UniversalChainId.make("ethereum.17000"),
3335
)
3436

3537
console.log("source", source)
38+
39+
// TODO: Destination will be somewhere
3640
const destination = yield* ChainRegistry.byUniversalId(
3741
UniversalChainId.make("ethereum.11155111"),
3842
)
39-
const { client } = yield* PublicClient
43+
const wallet = yield* WalletClient
44+
45+
const sender = wallet.signer.toSuiAddress();
4046

47+
// TODO: Fix this tokenOrder and write something working
4148
const tokenOrder = yield* TokenOrder.make({
4249
source,
4350
destination,
@@ -56,32 +63,27 @@ const program = Effect.gen(function* () {
5663

5764
yield* Effect.log("Token Order V2", tokenOrder)
5865

66+
// TODO: Fix this request too
5967
const request = ZkgmClientRequest.make({
6068
source,
6169
destination,
62-
channelId: ChannelId.make(2),
70+
channelId: ChannelId.make(1),
6371
ucs03Address: "0x5fbe74a283f7954f10aa04c2edf55578811aeb03",
6472
kind: "simulateAndExecute",
6573
instruction: tokenOrder,
6674
})
6775

6876
const zkgmClient = yield* ZkgmClient.ZkgmClient
6977

70-
// NOTE: 1. switch chain is assumed
71-
// NOTE: 2. write in progress
72-
7378
const response: ZkgmClientResponse.ZkgmClientResponse = yield* zkgmClient.execute(request)
7479

75-
// NOTE: 3. write complete (with tx hash)
7680

7781
yield* Effect.log("Submission Hash", response.txHash)
7882

7983
const completion = yield* response.waitFor(
8084
ZkgmIncomingMessage.LifecycleEvent.$is("EvmTransactionReceiptComplete"),
8185
)
8286

83-
// NOTE: 4. tx complete
84-
8587
yield* Effect.log("Completion", completion)
8688

8789

@@ -90,14 +92,20 @@ const program = Effect.gen(function* () {
9092
Effect.provide(PublicClient.Live({ url: getFullnodeUrl("testnet") })),
9193
Effect.provide(
9294
WalletClient.Live({
93-
url: getFullnodeUrl("testnet"),
94-
account: keypair, // signer
95-
chain: "sui-testnet" as any, // placeholder; not used internally
96-
}),
95+
url: getFullnodeUrl("testnet"),
96+
signer: keypair, // ✅ Sui signer
97+
}),
9798
),
9899

99100
Effect.provide(ChainRegistry.Default),
100101
Effect.provide(Logger.replace(Logger.defaultLogger, Logger.prettyLoggerDefault)),
101102
)
102103

103-
Effect.runPromise(program).catch(console.error)
104+
Effect.runPromise(program).catch((e: any) => {
105+
console.error("\n--- TOP-LEVEL ERROR ---")
106+
console.dir(e, { depth: 10 })
107+
if (e?.cause) {
108+
console.error("\n--- ORIGINAL CAUSE ---")
109+
console.dir(e.cause, { depth: 10 })
110+
}
111+
})

ts-sdk-sui/examples/sui-create-client-write-contract.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC)
1919

2020
const program = Effect.gen(function* () {
2121
const { client } = yield* PublicClient
22+
yield* Effect.log("Sui public client initialized", client.network )
23+
const meta = yield* readCoinMetadata("0x2::sui::SUI" as any)
24+
yield* Effect.log("SUI metadata", meta)
25+
26+
yield* Effect.log("keypair.getPublicKey().toSuiAddress()", keypair.getPublicKey().toSuiAddress())
27+
const balances = yield* readCoinBalances("0x2::sui::SUI" as any, keypair.getPublicKey().toSuiAddress() as any)
28+
yield* Effect.log("SUI balances", balances)
29+
30+
31+
const wallet = yield* WalletClient
2232
const amountMist = 10_000_000n // 0.01 SUI
2333

2434
const tx = new Transaction()
@@ -43,10 +53,9 @@ const program = Effect.gen(function* () {
4353
Effect.provide(PublicClient.Live({ url: getFullnodeUrl("testnet") })),
4454
Effect.provide(
4555
WalletClient.Live({
46-
url: getFullnodeUrl("testnet"),
47-
account: keypair, // signer
48-
chain: "sui-testnet" as any, // placeholder; not used internally
49-
}),
56+
url: getFullnodeUrl("testnet"),
57+
signer: keypair, // ✅ Sui signer
58+
}),
5059
),
5160

5261
Effect.provide(Logger.replace(Logger.defaultLogger, Logger.prettyLoggerDefault)),

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

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,25 @@ export const publicClientLayer = <
2929
),
3030
)
3131

32+
3233
/** @internal */
33-
export const walletClientLayer = <
34-
Id,
35-
>(tag: Context.Tag<Id, Sui.Sui.WalletClient>) =>
36-
(
37-
// interface unchanged
38-
options: Parameters<typeof Object>[0] & {
39-
account: Ed25519Keypair
40-
chain: unknown
41-
},
42-
): Layer.Layer<Id, Sui.CreateWalletClientError> =>
34+
export const walletClientLayer = <Id>(
35+
tag: Context.Tag<Id, Sui.Sui.WalletClient>,
36+
) =>
37+
(opts: { url: string; signer: Ed25519Keypair }): Layer.Layer<Id, Sui.CreateWalletClientError> =>
4338
Layer.effect(
4439
tag,
45-
pipe(
46-
Effect.try({
47-
try: () => ({
48-
client: new SuiClient(options as unknown as SuiClientOptions),
49-
signer: options.account as Ed25519Keypair,
40+
Effect.try({
41+
try: () => {
42+
if (!opts?.signer || typeof opts.signer.getPublicKey !== "function") {
43+
throw new Error("Invalid Sui signer: expected Ed25519Keypair")
44+
}
45+
const client = new SuiClient({ url: opts.url } satisfies SuiClientOptions)
46+
return { client, signer: opts.signer } // <-- matches Sui.Sui.WalletClient interface
47+
},
48+
catch: (err) =>
49+
new Sui.CreateWalletClientError({
50+
cause: Utils.extractErrorDetails(err as Error),
5051
}),
51-
catch: (err) =>
52-
new Sui.CreateWalletClientError({
53-
cause: Utils.extractErrorDetails(err as Sui.SuiCreateWalletClientErrorType),
54-
}),
55-
}),
56-
// return the *same* payload shape you had before
57-
Effect.map(({ client }) => ({
58-
client,
59-
account: options.account,
60-
chain: options.chain,
61-
})),
62-
),
63-
)
52+
}),
53+
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const fromWallet = (
124124
const relayStoreId = "0x393a99c6d55d9a79efa52dea6ea253fef25d2526787127290b985222cc20a924" // TODO: This should be fetched from somewhere
125125
const vaultId = "0x7c4ade19208295ed6bf3c4b58487aa4b917ba87d31460e9e7a917f7f12207ca3" // TODO: This should be fetched from somewhere
126126
const ibcStoreId = "0xac7814eebdfbf975235bbb796e07533718a9d83201346769e5f281dc90009175" // TODO: This should be fetched from somewhere
127-
const coinObjectId = "0x3997d4c40cb190283291270d326401fd77320af42cd7a891ded2eba3e52f4b16" // TODO: This should be given by user
127+
const coinObjectId = "0xc2c61b8de5aa6167dc744d6db61854fa29b53257d5e54a40c2f5b7dcc6f04d0b" // TODO: This should be given by user
128128

129129
// helpers
130130
const hexToBytes = (hex: `0x${string}`): Uint8Array => {

0 commit comments

Comments
 (0)