1
1
import { Transaction } from "@mysten/sui/transactions"
2
- import { Indexer , ZkgmIncomingMessage } from "@unionlabs/sdk"
3
2
import * as Call from "@unionlabs/sdk/Call"
4
3
import type { Hex } from "@unionlabs/sdk/schema/hex"
5
- import * as Token from "@unionlabs/sdk/Token"
6
4
import * as TokenOrder from "@unionlabs/sdk/TokenOrder"
7
5
import * as Ucs03 from "@unionlabs/sdk/Ucs03"
8
6
import * as Utils from "@unionlabs/sdk/Utils"
@@ -12,17 +10,14 @@ import * as ClientRequest from "@unionlabs/sdk/ZkgmClientRequest"
12
10
import * as ClientResponse from "@unionlabs/sdk/ZkgmClientResponse"
13
11
import * as IncomingMessage from "@unionlabs/sdk/ZkgmIncomingMessage"
14
12
import * as ZkgmInstruction from "@unionlabs/sdk/ZkgmInstruction"
15
- import { Brand , Chunk , flow , Match , ParseResult , pipe , Predicate , Tuple } from "effect"
13
+ import { Match , ParseResult , pipe , Predicate } from "effect"
16
14
import * as A from "effect/Array"
17
15
import * as Effect from "effect/Effect"
18
16
import * as Inspectable from "effect/Inspectable"
19
- import * as O from "effect/Option"
20
17
import * as S from "effect/Schema"
21
18
import * as Stream from "effect/Stream"
22
- import * as Safe from "../Safe.js"
23
19
import * as Sui from "../Sui.js"
24
20
25
- // import { Sui } from "../index.js"
26
21
27
22
export const fromWallet = (
28
23
opts : { client : Sui . Sui . PublicClient ; wallet : Sui . Sui . WalletClient } ,
@@ -84,6 +79,8 @@ export const fromWallet = (
84
79
85
80
console . log ( "[@unionlabs/sdk-sui/internal/zkgmClient]" , { wallet, client } )
86
81
82
+
83
+
87
84
const timeoutTimestamp = Utils . getTimeoutInNanoseconds24HoursFromNow ( )
88
85
const salt = yield * Utils . generateSalt ( "sui" ) . pipe (
89
86
Effect . mapError ( ( cause ) =>
@@ -117,18 +114,36 @@ export const fromWallet = (
117
114
const tHeight = 0n
118
115
const module = "zkgm" // zkgm module name
119
116
120
- // These will be fetched from hubble or from deployments.json
121
- const packageId = "0x8675045186976da5b60baf20dc94413fb5415a7054052dc14d93c13d3dbdf830" // zkgm package id
122
- // TODO: packageId can be changed when zkgm updated
123
- const relayStoreId = "0x393a99c6d55d9a79efa52dea6ea253fef25d2526787127290b985222cc20a924" // This won't be changed for a while
124
- const vaultId = "0x7c4ade19208295ed6bf3c4b58487aa4b917ba87d31460e9e7a917f7f12207ca3" // This won't be changed for a while
125
- const ibcStoreId = "0xac7814eebdfbf975235bbb796e07533718a9d83201346769e5f281dc90009175" // This won't be changed
126
117
127
- // This 2 will be get by user all the time
128
- const typeArg = "0x2::sui::SUI" // TODO: This should be dynamic based on the token sent
129
- const coinObjectId = "0x89c430d35fa9f2778b0a635027b178146eb26d70d16292c289304d476ecf76cd" // TODO: This should be given by user
130
- // Note: There can be multiple coins, for simplicity we are using one coin here
131
- // User should be able to provide typeArgs and coinObjectIds array
118
+
119
+ const suiParams = request . transport ?. sui
120
+ console . log ( "request.transport:" , request . transport )
121
+ if ( ! suiParams ) {
122
+ return yield * Effect . fail (
123
+ new ClientError . RequestError ( {
124
+ reason : "Transport" ,
125
+ request,
126
+ cause : new Error ( "Missing Sui transport params on ZkgmClientRequest.transport.sui" ) ,
127
+ description : "Provide relayStoreId/vaultId/ibcStoreId and coins[]" ,
128
+ } ) ,
129
+ )
130
+ }
131
+
132
+ const { relayStoreId, vaultId, ibcStoreId, coins } = suiParams
133
+
134
+ console . log ( "[@unionlabs/sdk-sui/internal/zkgmClient]" , { relayStoreId, vaultId, ibcStoreId, coins } )
135
+ // // These will be fetched from hubble or from deployments.json
136
+ // const packageId = "0x8675045186976da5b60baf20dc94413fb5415a7054052dc14d93c13d3dbdf830" // zkgm package id
137
+ // // TODO: packageId can be changed when zkgm updated
138
+ // const relayStoreId = "0x393a99c6d55d9a79efa52dea6ea253fef25d2526787127290b985222cc20a924" // This won't be changed for a while
139
+ // const vaultId = "0x7c4ade19208295ed6bf3c4b58487aa4b917ba87d31460e9e7a917f7f12207ca3" // This won't be changed for a while
140
+ // const ibcStoreId = "0xac7814eebdfbf975235bbb796e07533718a9d83201346769e5f281dc90009175" // This won't be changed
141
+
142
+ // // This 2 will be get by user all the time
143
+ // const typeArg = "0x2::sui::SUI" // TODO: This should be dynamic based on the token sent
144
+ // const coinObjectId = "0x89c430d35fa9f2778b0a635027b178146eb26d70d16292c289304d476ecf76cd" // TODO: This should be given by user
145
+ // // Note: There can be multiple coins, for simplicity we are using one coin here
146
+ // // User should be able to provide typeArgs and coinObjectIds array
132
147
133
148
const hexToBytes = ( hex : `0x${string } `) : Uint8Array => {
134
149
const s = hex . slice ( 2 )
@@ -141,33 +156,36 @@ export const fromWallet = (
141
156
142
157
// 1) begin_send(channel_id: u32, salt: vector<u8>) -> SendCtx
143
158
let sendCtx = tx . moveCall ( {
144
- target : `${ packageId } ::${ module } ::begin_send` ,
159
+ target : `${ request . ucs03Address } ::${ module } ::begin_send` ,
145
160
typeArguments : [ ] ,
146
161
arguments : [
147
162
tx . pure . u32 ( Number ( request . channelId ) ) ,
148
163
tx . pure . vector ( "u8" , hexToBytes ( salt as `0x${string } `) ) ,
149
164
] ,
150
165
} )
151
166
152
- // 2) send_with_coin<T>(relay_store, vault, ibc_store, coin, version, opcode, operand, ctx) -> SendCtx
153
- sendCtx = tx . moveCall ( {
154
- target : `${ packageId } ::${ module } ::send_with_coin` ,
155
- typeArguments : [ typeArg ] ,
156
- arguments : [
157
- tx . object ( relayStoreId ) ,
158
- tx . object ( vaultId ) ,
159
- tx . object ( ibcStoreId ) ,
160
- tx . object ( coinObjectId ) ,
161
- tx . pure . u8 ( Number ( request . instruction . version ) ) ,
162
- tx . pure . u8 ( Number ( request . instruction . opcode ) ) ,
163
- tx . pure . vector ( "u8" , hexToBytes ( operand as `0x${string } `) ) ,
164
- sendCtx ,
165
- ] ,
166
- } )
167
+ // 2) For each coin: send_with_coin<T>(relay_store, vault, ibc_store, coin, version, opcode, operand, ctx) -> SendCtx
168
+ for ( const { typeArg, objectId } of coins ) {
169
+ sendCtx = tx . moveCall ( {
170
+ target : `${ request . ucs03Address } ::${ module } ::send_with_coin` ,
171
+ typeArguments : [ typeArg ] ,
172
+ arguments : [
173
+ tx . object ( relayStoreId ) ,
174
+ tx . object ( vaultId ) ,
175
+ tx . object ( ibcStoreId ) ,
176
+ tx . object ( objectId ) ,
177
+ tx . pure . u8 ( Number ( request . instruction . version ) ) ,
178
+ tx . pure . u8 ( Number ( request . instruction . opcode ) ) ,
179
+ tx . pure . vector ( "u8" , hexToBytes ( operand as `0x${string } `) ) ,
180
+ sendCtx ,
181
+ ] ,
182
+ } )
183
+ }
184
+
167
185
168
186
// 3) end_send(ibc_store, clock, t_height: u64, timeout_ns: u64, ctx)
169
187
tx . moveCall ( {
170
- target : `${ packageId } ::${ module } ::end_send` ,
188
+ target : `${ request . ucs03Address } ::${ module } ::end_send` ,
171
189
typeArguments : [ ] ,
172
190
arguments : [
173
191
tx . object ( ibcStoreId ) ,
0 commit comments