Skip to content

Commit 99ed826

Browse files
committed
chore(ts-sdk-sui): fromWallet function is being called, error fixed on example
Signed-off-by: kaancaglan <[email protected]>
1 parent a1b6f08 commit 99ed826

File tree

2 files changed

+91
-53
lines changed

2 files changed

+91
-53
lines changed

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

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ import { Effect, Logger } from "effect"
99
import { getFullnodeUrl } from "@mysten/sui/client"
1010
import { PublicClient, WalletClient, writeContract, readCoinMetadata, readCoinBalances, sendInstruction } from "../src/Sui.js"
1111
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
12+
import * as ZkgmClientRequest from "@unionlabs/sdk/ZkgmClientRequest"
13+
import * as ZkgmClientResponse from "@unionlabs/sdk/ZkgmClientResponse"
14+
import { ChannelId } from "@unionlabs/sdk/schema/channel"
15+
import * as ZkgmIncomingMessage from "@unionlabs/sdk/ZkgmIncomingMessage"
16+
import * as ZkgmClient from "@unionlabs/sdk/ZkgmClient"
17+
import { layerWithoutWallet } from "../src/SuiZkgmClient.js"
18+
1219
import { Transaction } from "@mysten/sui/transactions"
20+
import * as TokenOrder from "@unionlabs/sdk/TokenOrder"
21+
import { UniversalChainId } from "@unionlabs/sdk/schema/chain"
22+
import { ChainRegistry } from "@unionlabs/sdk/ChainRegistry"
1323

1424
const MNEMONIC = process.env.MNEMONIC ?? "fix auto gallery heart practice drip joke nice decline lift attend bread"
1525
const RECIPIENT = process.env.RECIPIENT ?? "0x03ff9dd9e093387bdd4432c6a3eb6a1bd5a8f39a530042ac7efe576f18d3232b"
@@ -18,38 +28,65 @@ const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC)
1828

1929

2030
const program = Effect.gen(function* () {
31+
const source = yield* ChainRegistry.byUniversalId(
32+
UniversalChainId.make("ethereum.17000"),
33+
)
34+
35+
console.log("source", source)
36+
const destination = yield* ChainRegistry.byUniversalId(
37+
UniversalChainId.make("ethereum.11155111"),
38+
)
2139
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
32-
const amountMist = 10_000_000n // 0.01 SUI
33-
34-
const tx = new Transaction()
35-
const coin = tx.splitCoins(tx.gas, [tx.pure.u64(amountMist)])
36-
const recipient = tx.pure.address(RECIPIENT)
37-
38-
const res = yield* writeContract(
39-
client,
40-
keypair,
41-
"0x2", // packageId: Sui framework
42-
"transfer", // module: sui::transfer
43-
"public_transfer", // function
44-
["0x2::coin::Coin<0x2::sui::SUI>"], // type arg T
45-
[coin, recipient], // (obj: T, recipient: address)
46-
tx,
40+
41+
const tokenOrder = yield* TokenOrder.make({
42+
source,
43+
destination,
44+
sender: "0x06627714f3F17a701f7074a12C02847a5D2Ca487",
45+
receiver: "0x50A22f95bcB21E7bFb63c7A8544AC0683dCeA302",
46+
// LINK on Holesky
47+
baseToken: "0x685ce6742351ae9b618f383883d6d1e0c5a31b4b",
48+
baseAmount: 10n,
49+
// Holesky LINK on Sepolia
50+
quoteToken: "0x80fdbf104ec58a527ec40f7b03f88c404ef4ba63",
51+
quoteAmount: 10n,
52+
kind: "escrow",
53+
metadata: undefined,
54+
version: 2,
55+
})
56+
57+
yield* Effect.log("Token Order V2", tokenOrder)
58+
59+
const request = ZkgmClientRequest.make({
60+
source,
61+
destination,
62+
channelId: ChannelId.make(2),
63+
ucs03Address: "0x5fbe74a283f7954f10aa04c2edf55578811aeb03",
64+
kind: "simulateAndExecute",
65+
instruction: tokenOrder,
66+
})
67+
68+
const zkgmClient = yield* ZkgmClient.ZkgmClient
69+
70+
// NOTE: 1. switch chain is assumed
71+
// NOTE: 2. write in progress
72+
73+
const response: ZkgmClientResponse.ZkgmClientResponse = yield* zkgmClient.execute(request)
74+
75+
// NOTE: 3. write complete (with tx hash)
76+
77+
yield* Effect.log("Submission Hash", response.txHash)
78+
79+
const completion = yield* response.waitFor(
80+
ZkgmIncomingMessage.LifecycleEvent.$is("EvmTransactionReceiptComplete"),
4781
)
4882

49-
yield* Effect.log("Transfer submitted", res)
83+
// NOTE: 4. tx complete
84+
85+
yield* Effect.log("Completion", completion)
5086

5187

5288
}).pipe(
89+
Effect.provide(layerWithoutWallet),
5390
Effect.provide(PublicClient.Live({ url: getFullnodeUrl("testnet") })),
5491
Effect.provide(
5592
WalletClient.Live({
@@ -59,6 +96,7 @@ const program = Effect.gen(function* () {
5996
}),
6097
),
6198

99+
Effect.provide(ChainRegistry.Default),
62100
Effect.provide(Logger.replace(Logger.defaultLogger, Logger.prettyLoggerDefault)),
63101
)
64102

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const fromWallet = (
5858
(v1) =>
5959
Effect.gen(function*() {
6060
const meta = yield* pipe(
61-
Sui.readCoinMetadata(
61+
Sui.readCoinMeta(
6262
v1.baseToken.address as unknown as any
6363
),
6464
Effect.provideService(Sui.PublicClient, client),
@@ -136,32 +136,32 @@ export const fromWallet = (
136136

137137
console.log("[@unionlabs/sdk-sui/internal/zkgmClient]", { args })
138138

139-
// // TODO: Fix writecontract calling, decide parameters etc.
140-
// const sendInstruction = Sui.writeContract({
141-
// client: client,
142-
// account: wallet.signer,
143-
// abi: Ucs03.Abi,
144-
// chain: wallet.chain,
145-
// functionName: "send",
146-
// address: request.ucs03Address as unknown as any,
147-
// args,
148-
// value: funds,
149-
// }).pipe(
150-
// Effect.mapError((cause) =>
151-
// new ClientError.RequestError({
152-
// reason: "Transport",
153-
// request,
154-
// cause,
155-
// description: "writeContract",
156-
// })
157-
// ),
158-
// Effect.provideService(Evm.WalletClient, wallet),
159-
// )
160-
161-
// return yield* pipe(
162-
// sendInstruction,
163-
// Effect.map((txHash) => new ClientResponseImpl(request, client, txHash)),
164-
// )
139+
// TODO: Fix writecontract calling, decide parameters etc.
140+
const sendInstruction = Sui.writeContract({
141+
client: client,
142+
account: wallet.signer,
143+
abi: Ucs03.Abi,
144+
chain: wallet.chain,
145+
functionName: "send",
146+
address: request.ucs03Address as unknown as any,
147+
args,
148+
value: funds,
149+
}).pipe(
150+
Effect.mapError((cause) =>
151+
new ClientError.RequestError({
152+
reason: "Transport",
153+
request,
154+
cause,
155+
description: "writeContract",
156+
})
157+
),
158+
Effect.provideService(Evm.WalletClient, wallet),
159+
)
160+
161+
return yield* pipe(
162+
sendInstruction,
163+
Effect.map((txHash) => new ClientResponseImpl(request, client, txHash)),
164+
)
165165
})
166166
)
167167

0 commit comments

Comments
 (0)