@layerzerolabs/lz-sui-sdk-v2 3.0.73 → 3.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/index.cjs +1169 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +353 -24
- package/dist/index.d.ts +353 -24
- package/dist/index.mjs +1138 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -4
- package/src/bcs/index.ts +1 -0
- package/src/bcs/messaging-fee.ts +6 -0
- package/src/index.ts +5 -1
- package/src/modules/counter.ts +239 -0
- package/src/modules/endpoint.ts +303 -0
- package/src/modules/index.ts +5 -0
- package/src/modules/simple-message-lib.ts +240 -0
- package/src/modules/utils.ts +390 -0
- package/src/modules/zro.ts +38 -0
- package/src/sdk.ts +233 -0
- package/src/types.ts +89 -0
- package/src/utils.ts +69 -0
- package/src/endpoint.ts +0 -38
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs'
|
|
2
|
+
import { SuiClient } from '@mysten/sui/client'
|
|
3
|
+
import { Transaction, TransactionResult } from '@mysten/sui/transactions'
|
|
4
|
+
|
|
5
|
+
import { Context } from '../types'
|
|
6
|
+
|
|
7
|
+
export class Utils {
|
|
8
|
+
public packageId: string
|
|
9
|
+
public readonly client: SuiClient
|
|
10
|
+
private readonly context: Context
|
|
11
|
+
|
|
12
|
+
constructor(packageId: string, client: SuiClient, context: Context) {
|
|
13
|
+
this.packageId = packageId
|
|
14
|
+
this.client = client
|
|
15
|
+
this.context = context
|
|
16
|
+
|
|
17
|
+
// Validate that package ID is not empty
|
|
18
|
+
if (this.packageId.trim() === '') {
|
|
19
|
+
throw new Error('utils package ID cannot be empty')
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// === bytes32 Functions ===
|
|
24
|
+
|
|
25
|
+
fromBytesMoveCall(tx: Transaction, peer: Uint8Array): TransactionResult {
|
|
26
|
+
return tx.moveCall({
|
|
27
|
+
target: `${this.packageId}::bytes32::from_bytes`,
|
|
28
|
+
typeArguments: [],
|
|
29
|
+
arguments: [tx.pure(bcs.vector(bcs.u8()).serialize(peer))],
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fromBytesLeftPaddedMoveCall(tx: Transaction, bytes: Uint8Array): TransactionResult {
|
|
34
|
+
return tx.moveCall({
|
|
35
|
+
target: `${this.packageId}::bytes32::from_bytes_left_padded`,
|
|
36
|
+
typeArguments: [],
|
|
37
|
+
arguments: [tx.pure(bcs.vector(bcs.u8()).serialize(bytes))],
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fromBytesRightPaddedMoveCall(tx: Transaction, bytes: Uint8Array): TransactionResult {
|
|
42
|
+
return tx.moveCall({
|
|
43
|
+
target: `${this.packageId}::bytes32::from_bytes_right_padded`,
|
|
44
|
+
typeArguments: [],
|
|
45
|
+
arguments: [tx.pure(bcs.vector(bcs.u8()).serialize(bytes))],
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fromAddressMoveCall(tx: Transaction, address: string): TransactionResult {
|
|
50
|
+
return tx.moveCall({
|
|
51
|
+
target: `${this.packageId}::bytes32::from_address`,
|
|
52
|
+
typeArguments: [],
|
|
53
|
+
arguments: [tx.pure.address(address)],
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fromIdMoveCall(tx: Transaction, id: string): TransactionResult {
|
|
58
|
+
return tx.moveCall({
|
|
59
|
+
target: `${this.packageId}::bytes32::from_id`,
|
|
60
|
+
typeArguments: [],
|
|
61
|
+
arguments: [tx.object(id)],
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
zeroBytes32MoveCall(tx: Transaction): TransactionResult {
|
|
66
|
+
return tx.moveCall({
|
|
67
|
+
target: `${this.packageId}::bytes32::zero_bytes32`,
|
|
68
|
+
typeArguments: [],
|
|
69
|
+
arguments: [],
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
ffBytes32MoveCall(tx: Transaction): TransactionResult {
|
|
74
|
+
return tx.moveCall({
|
|
75
|
+
target: `${this.packageId}::bytes32::ff_bytes32`,
|
|
76
|
+
typeArguments: [],
|
|
77
|
+
arguments: [],
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
isZeroMoveCall(tx: Transaction, bytes32: string): TransactionResult {
|
|
82
|
+
return tx.moveCall({
|
|
83
|
+
target: `${this.packageId}::bytes32::is_zero`,
|
|
84
|
+
typeArguments: [],
|
|
85
|
+
arguments: [tx.object(bytes32)],
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
isFfMoveCall(tx: Transaction, bytes32: string): TransactionResult {
|
|
90
|
+
return tx.moveCall({
|
|
91
|
+
target: `${this.packageId}::bytes32::is_ff`,
|
|
92
|
+
typeArguments: [],
|
|
93
|
+
arguments: [tx.object(bytes32)],
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
toBytesMoveCall(tx: Transaction, bytes32: string): TransactionResult {
|
|
98
|
+
return tx.moveCall({
|
|
99
|
+
target: `${this.packageId}::bytes32::to_bytes`,
|
|
100
|
+
typeArguments: [],
|
|
101
|
+
arguments: [tx.object(bytes32)],
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
toAddressMoveCall(tx: Transaction, bytes32: string): TransactionResult {
|
|
106
|
+
return tx.moveCall({
|
|
107
|
+
target: `${this.packageId}::bytes32::to_address`,
|
|
108
|
+
typeArguments: [],
|
|
109
|
+
arguments: [tx.object(bytes32)],
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
toIdMoveCall(tx: Transaction, bytes32: string): TransactionResult {
|
|
114
|
+
return tx.moveCall({
|
|
115
|
+
target: `${this.packageId}::bytes32::to_id`,
|
|
116
|
+
typeArguments: [],
|
|
117
|
+
arguments: [tx.object(bytes32)],
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// === Buffer Functions ===
|
|
122
|
+
|
|
123
|
+
newReaderMoveCall(tx: Transaction, buffer: Uint8Array): TransactionResult {
|
|
124
|
+
return tx.moveCall({
|
|
125
|
+
target: `${this.packageId}::buffer::new_reader`,
|
|
126
|
+
typeArguments: [],
|
|
127
|
+
arguments: [tx.pure(bcs.vector(bcs.u8()).serialize(buffer))],
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
newWriterMoveCall(tx: Transaction): TransactionResult {
|
|
132
|
+
return tx.moveCall({
|
|
133
|
+
target: `${this.packageId}::buffer::new_writer`,
|
|
134
|
+
typeArguments: [],
|
|
135
|
+
arguments: [],
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
createWriterMoveCall(tx: Transaction, buffer: Uint8Array): TransactionResult {
|
|
140
|
+
return tx.moveCall({
|
|
141
|
+
target: `${this.packageId}::buffer::create_writer`,
|
|
142
|
+
typeArguments: [],
|
|
143
|
+
arguments: [tx.pure(bcs.vector(bcs.u8()).serialize(buffer))],
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Reader functions
|
|
148
|
+
positionMoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
149
|
+
return tx.moveCall({
|
|
150
|
+
target: `${this.packageId}::buffer::position`,
|
|
151
|
+
typeArguments: [],
|
|
152
|
+
arguments: [reader],
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
remainingLengthMoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
157
|
+
return tx.moveCall({
|
|
158
|
+
target: `${this.packageId}::buffer::remaining_length`,
|
|
159
|
+
typeArguments: [],
|
|
160
|
+
arguments: [reader],
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
skipMoveCall(tx: Transaction, reader: TransactionResult, len: number): TransactionResult {
|
|
165
|
+
return tx.moveCall({
|
|
166
|
+
target: `${this.packageId}::buffer::skip`,
|
|
167
|
+
typeArguments: [],
|
|
168
|
+
arguments: [reader, tx.pure.u64(len)],
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
setPositionMoveCall(tx: Transaction, reader: TransactionResult, position: number): TransactionResult {
|
|
173
|
+
return tx.moveCall({
|
|
174
|
+
target: `${this.packageId}::buffer::set_position`,
|
|
175
|
+
typeArguments: [],
|
|
176
|
+
arguments: [reader, tx.pure.u64(position)],
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
rewindMoveCall(tx: Transaction, reader: TransactionResult, len: number): TransactionResult {
|
|
181
|
+
return tx.moveCall({
|
|
182
|
+
target: `${this.packageId}::buffer::rewind`,
|
|
183
|
+
typeArguments: [],
|
|
184
|
+
arguments: [reader, tx.pure.u64(len)],
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
readU8MoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
189
|
+
return tx.moveCall({
|
|
190
|
+
target: `${this.packageId}::buffer::read_u8`,
|
|
191
|
+
typeArguments: [],
|
|
192
|
+
arguments: [reader],
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
readU16MoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
197
|
+
return tx.moveCall({
|
|
198
|
+
target: `${this.packageId}::buffer::read_u16`,
|
|
199
|
+
typeArguments: [],
|
|
200
|
+
arguments: [reader],
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
readU32MoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
205
|
+
return tx.moveCall({
|
|
206
|
+
target: `${this.packageId}::buffer::read_u32`,
|
|
207
|
+
typeArguments: [],
|
|
208
|
+
arguments: [reader],
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
readU64MoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
213
|
+
return tx.moveCall({
|
|
214
|
+
target: `${this.packageId}::buffer::read_u64`,
|
|
215
|
+
typeArguments: [],
|
|
216
|
+
arguments: [reader],
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
readU128MoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
221
|
+
return tx.moveCall({
|
|
222
|
+
target: `${this.packageId}::buffer::read_u128`,
|
|
223
|
+
typeArguments: [],
|
|
224
|
+
arguments: [reader],
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
readU256MoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
229
|
+
return tx.moveCall({
|
|
230
|
+
target: `${this.packageId}::buffer::read_u256`,
|
|
231
|
+
typeArguments: [],
|
|
232
|
+
arguments: [reader],
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
readBytes32MoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
237
|
+
return tx.moveCall({
|
|
238
|
+
target: `${this.packageId}::buffer::read_bytes32`,
|
|
239
|
+
typeArguments: [],
|
|
240
|
+
arguments: [reader],
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
readAddressMoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
245
|
+
return tx.moveCall({
|
|
246
|
+
target: `${this.packageId}::buffer::read_address`,
|
|
247
|
+
typeArguments: [],
|
|
248
|
+
arguments: [reader],
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
readFixedLenBytesMoveCall(tx: Transaction, reader: TransactionResult, len: number): TransactionResult {
|
|
253
|
+
return tx.moveCall({
|
|
254
|
+
target: `${this.packageId}::buffer::read_fixed_len_bytes`,
|
|
255
|
+
typeArguments: [],
|
|
256
|
+
arguments: [reader, tx.pure.u64(len)],
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
readBytesUntilEndMoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
261
|
+
return tx.moveCall({
|
|
262
|
+
target: `${this.packageId}::buffer::read_bytes_until_end`,
|
|
263
|
+
typeArguments: [],
|
|
264
|
+
arguments: [reader],
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
readerBufferLengthMoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
269
|
+
return tx.moveCall({
|
|
270
|
+
target: `${this.packageId}::buffer::reader_buffer_length`,
|
|
271
|
+
typeArguments: [],
|
|
272
|
+
arguments: [reader],
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
readerToBytesMoveCall(tx: Transaction, reader: TransactionResult): TransactionResult {
|
|
277
|
+
return tx.moveCall({
|
|
278
|
+
target: `${this.packageId}::buffer::reader_to_bytes`,
|
|
279
|
+
typeArguments: [],
|
|
280
|
+
arguments: [reader],
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Writer functions
|
|
285
|
+
writerBufferLengthMoveCall(tx: Transaction, writer: TransactionResult): TransactionResult {
|
|
286
|
+
return tx.moveCall({
|
|
287
|
+
target: `${this.packageId}::buffer::writer_buffer_length`,
|
|
288
|
+
typeArguments: [],
|
|
289
|
+
arguments: [writer],
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
writerToBytesMoveCall(tx: Transaction, writer: TransactionResult): TransactionResult {
|
|
294
|
+
return tx.moveCall({
|
|
295
|
+
target: `${this.packageId}::buffer::writer_to_bytes`,
|
|
296
|
+
typeArguments: [],
|
|
297
|
+
arguments: [writer],
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
writeU8MoveCall(tx: Transaction, writer: TransactionResult, value: number): TransactionResult {
|
|
302
|
+
return tx.moveCall({
|
|
303
|
+
target: `${this.packageId}::buffer::write_u8`,
|
|
304
|
+
typeArguments: [],
|
|
305
|
+
arguments: [writer, tx.pure.u8(value)],
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
writeU16MoveCall(tx: Transaction, writer: TransactionResult, value: number): TransactionResult {
|
|
310
|
+
return tx.moveCall({
|
|
311
|
+
target: `${this.packageId}::buffer::write_u16`,
|
|
312
|
+
typeArguments: [],
|
|
313
|
+
arguments: [writer, tx.pure.u16(value)],
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
writeU32MoveCall(tx: Transaction, writer: TransactionResult, value: number): TransactionResult {
|
|
318
|
+
return tx.moveCall({
|
|
319
|
+
target: `${this.packageId}::buffer::write_u32`,
|
|
320
|
+
typeArguments: [],
|
|
321
|
+
arguments: [writer, tx.pure.u32(value)],
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
writeU64MoveCall(tx: Transaction, writer: TransactionResult, value: number): TransactionResult {
|
|
326
|
+
return tx.moveCall({
|
|
327
|
+
target: `${this.packageId}::buffer::write_u64`,
|
|
328
|
+
typeArguments: [],
|
|
329
|
+
arguments: [writer, tx.pure.u64(value)],
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
writeU128MoveCall(tx: Transaction, writer: TransactionResult, value: string): TransactionResult {
|
|
334
|
+
return tx.moveCall({
|
|
335
|
+
target: `${this.packageId}::buffer::write_u128`,
|
|
336
|
+
typeArguments: [],
|
|
337
|
+
arguments: [writer, tx.pure.u128(value)],
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
writeU256MoveCall(tx: Transaction, writer: TransactionResult, value: string): TransactionResult {
|
|
342
|
+
return tx.moveCall({
|
|
343
|
+
target: `${this.packageId}::buffer::write_u256`,
|
|
344
|
+
typeArguments: [],
|
|
345
|
+
arguments: [writer, tx.pure.u256(value)],
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
writeBytesMoveCall(tx: Transaction, writer: TransactionResult, bytes: Uint8Array): TransactionResult {
|
|
350
|
+
return tx.moveCall({
|
|
351
|
+
target: `${this.packageId}::buffer::write_bytes`,
|
|
352
|
+
typeArguments: [],
|
|
353
|
+
arguments: [writer, tx.pure(bcs.vector(bcs.u8()).serialize(bytes))],
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
writeAddressMoveCall(tx: Transaction, writer: TransactionResult, address: string): TransactionResult {
|
|
358
|
+
return tx.moveCall({
|
|
359
|
+
target: `${this.packageId}::buffer::write_address`,
|
|
360
|
+
typeArguments: [],
|
|
361
|
+
arguments: [writer, tx.pure.address(address)],
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
writeBytes32MoveCall(tx: Transaction, writer: TransactionResult, bytes32: string): TransactionResult {
|
|
366
|
+
return tx.moveCall({
|
|
367
|
+
target: `${this.packageId}::buffer::write_bytes32`,
|
|
368
|
+
typeArguments: [],
|
|
369
|
+
arguments: [writer, tx.object(bytes32)],
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// === Hash Functions ===
|
|
374
|
+
|
|
375
|
+
blake2b256MoveCall(tx: Transaction, bytes: Uint8Array): TransactionResult {
|
|
376
|
+
return tx.moveCall({
|
|
377
|
+
target: `${this.packageId}::hash::blake2b256`,
|
|
378
|
+
typeArguments: [],
|
|
379
|
+
arguments: [tx.pure(bcs.vector(bcs.u8()).serialize(bytes))],
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
keccak256MoveCall(tx: Transaction, bytes: Uint8Array): TransactionResult {
|
|
384
|
+
return tx.moveCall({
|
|
385
|
+
target: `${this.packageId}::hash::keccak256`,
|
|
386
|
+
typeArguments: [],
|
|
387
|
+
arguments: [tx.pure(bcs.vector(bcs.u8()).serialize(bytes))],
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client'
|
|
2
|
+
import { Transaction, TransactionResult } from '@mysten/sui/transactions'
|
|
3
|
+
|
|
4
|
+
import { Context } from '../types'
|
|
5
|
+
|
|
6
|
+
export class Zro {
|
|
7
|
+
public packageId: string
|
|
8
|
+
public readonly client: SuiClient
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
packageId: string,
|
|
12
|
+
client: SuiClient,
|
|
13
|
+
private readonly context: Context
|
|
14
|
+
) {
|
|
15
|
+
this.packageId = packageId
|
|
16
|
+
this.client = client
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
zeroOptionMoveCall(tx: Transaction): TransactionResult {
|
|
20
|
+
const zroToken = tx.moveCall({
|
|
21
|
+
target: `0x2::coin::zero`,
|
|
22
|
+
typeArguments: [`${this.packageId}::zro::ZRO`],
|
|
23
|
+
})
|
|
24
|
+
const zroOption = tx.moveCall({
|
|
25
|
+
target: `0x1::option::some`,
|
|
26
|
+
typeArguments: [`0x2::coin::Coin<${this.packageId}::zro::ZRO>`],
|
|
27
|
+
arguments: [zroToken],
|
|
28
|
+
})
|
|
29
|
+
return zroOption
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
noneOptionMoveCall(tx: Transaction): TransactionResult {
|
|
33
|
+
return tx.moveCall({
|
|
34
|
+
target: `0x1::option::none`,
|
|
35
|
+
typeArguments: [`0x2::coin::Coin<${this.packageId}::zro::ZRO>`],
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client'
|
|
2
|
+
|
|
3
|
+
import { Provider } from '@layerzerolabs/lz-core'
|
|
4
|
+
import { SuiProvider } from '@layerzerolabs/lz-corekit-sui'
|
|
5
|
+
import { Chain, Stage, chainAndStageToNetwork } from '@layerzerolabs/lz-definitions'
|
|
6
|
+
|
|
7
|
+
import { Counter } from './modules/counter'
|
|
8
|
+
import { Endpoint } from './modules/endpoint'
|
|
9
|
+
import { SimpleMessageLib } from './modules/simple-message-lib'
|
|
10
|
+
import { Utils } from './modules/utils'
|
|
11
|
+
import { Zro } from './modules/zro'
|
|
12
|
+
import { Context, ObjectOptions, PackageOptions } from './types'
|
|
13
|
+
import { readAddressFromDeployment } from './utils'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Asserts that the given provider is an instance of SuiProvider.
|
|
17
|
+
*
|
|
18
|
+
* @param {unknown} provider - The provider to check.
|
|
19
|
+
* @throws {Error} If the provider is not an instance of SuiProvider.
|
|
20
|
+
*/
|
|
21
|
+
function assertSuiProvider(provider: Provider): asserts provider is SuiProvider {
|
|
22
|
+
if (!(provider instanceof SuiProvider)) {
|
|
23
|
+
throw new Error('Invalid provider')
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of the SDK from the given provider.
|
|
29
|
+
*
|
|
30
|
+
* @param {unknown} provider - The provider of the current chain.
|
|
31
|
+
* @param {Stage} [stage] - The stage of the SDK. {@link Stage}
|
|
32
|
+
* @returns {SDK} The initialized SDK instance.
|
|
33
|
+
*/
|
|
34
|
+
export function getSDKFromProvider(provider: Provider, stage?: Stage): SDK {
|
|
35
|
+
assertSuiProvider(provider)
|
|
36
|
+
const client = provider.native
|
|
37
|
+
|
|
38
|
+
return new SDK({
|
|
39
|
+
client,
|
|
40
|
+
stage,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Options for initializing the SDK.
|
|
46
|
+
*/
|
|
47
|
+
export interface SdkOptions {
|
|
48
|
+
/**
|
|
49
|
+
* The chain for the SDK (optional).
|
|
50
|
+
* default value is Chain.SUI
|
|
51
|
+
*/
|
|
52
|
+
chain?: Chain
|
|
53
|
+
/**
|
|
54
|
+
* The Sui client for the SDK.
|
|
55
|
+
*/
|
|
56
|
+
client: SuiClient
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The stage of the SDK (optional).
|
|
60
|
+
* default value is Stage.SANDBOX
|
|
61
|
+
*/
|
|
62
|
+
stage?: Stage
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The package options for the SDK.
|
|
66
|
+
*/
|
|
67
|
+
packages?: Partial<PackageOptions>
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The object options for the SDK.
|
|
71
|
+
*/
|
|
72
|
+
objects?: Partial<ObjectOptions>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The SDK class provides methods to interact with LayerZero on Sui.
|
|
77
|
+
* It initializes all modules at once and provides access to them.
|
|
78
|
+
*/
|
|
79
|
+
export class SDK {
|
|
80
|
+
chain: Chain
|
|
81
|
+
stage: Stage
|
|
82
|
+
client: SuiClient
|
|
83
|
+
public readonly packages: PackageOptions
|
|
84
|
+
public readonly objects: ObjectOptions
|
|
85
|
+
|
|
86
|
+
// Module instances
|
|
87
|
+
endpoint: Endpoint
|
|
88
|
+
counter: Counter
|
|
89
|
+
simpleMessageLib: SimpleMessageLib
|
|
90
|
+
utils: Utils
|
|
91
|
+
zro: Zro
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates an instance of the SDK.
|
|
95
|
+
*
|
|
96
|
+
* @param {SdkOptions} options - The SDK options.
|
|
97
|
+
*/
|
|
98
|
+
constructor(options: SdkOptions) {
|
|
99
|
+
this.chain = options.chain ?? Chain.PLACEHOLDER0
|
|
100
|
+
this.stage = options.stage ?? Stage.SANDBOX
|
|
101
|
+
this.client = options.client
|
|
102
|
+
const network = chainAndStageToNetwork(this.chain, this.stage, this.stage === Stage.SANDBOX)
|
|
103
|
+
const defaultPackages = {
|
|
104
|
+
utils: readAddressFromDeployment(network, 'utils')!,
|
|
105
|
+
endpoint_v2: readAddressFromDeployment(network, 'endpoint_v2')!,
|
|
106
|
+
counter_v2: readAddressFromDeployment(network, 'counter')!,
|
|
107
|
+
simple_message_lib: readAddressFromDeployment(network, 'simple_message_lib')!,
|
|
108
|
+
zro: readAddressFromDeployment(network, 'zro')!,
|
|
109
|
+
}
|
|
110
|
+
this.packages = {
|
|
111
|
+
...defaultPackages,
|
|
112
|
+
...options.packages,
|
|
113
|
+
}
|
|
114
|
+
const defaultObjects = {
|
|
115
|
+
endpoint_v2: readAddressFromDeployment(network, 'object-EndpointV2')!,
|
|
116
|
+
simple_message_lib: readAddressFromDeployment(network, 'object-SimpleMessageLib')!,
|
|
117
|
+
uln_302: readAddressFromDeployment(network, 'object-ULN302')!,
|
|
118
|
+
blocked_message_lib: readAddressFromDeployment(network, 'object-BlockedMessageLib')!,
|
|
119
|
+
discovery: readAddressFromDeployment(network, 'object-Discovery')!,
|
|
120
|
+
counter: readAddressFromDeployment(network, 'object-Counter')!,
|
|
121
|
+
counter_admin_cap: readAddressFromDeployment(network, 'object-CounterAdminCap')!,
|
|
122
|
+
endpoint_admin_cap: readAddressFromDeployment(network, 'object-EndpointV2AdminCap')!,
|
|
123
|
+
oapp_core: readAddressFromDeployment(network, 'object-OAppCore')!,
|
|
124
|
+
}
|
|
125
|
+
this.objects = {
|
|
126
|
+
...defaultObjects,
|
|
127
|
+
...options.objects,
|
|
128
|
+
}
|
|
129
|
+
const context: Context = {} as unknown as Context
|
|
130
|
+
// Initialize all modules
|
|
131
|
+
this.endpoint = new Endpoint(this.packages.endpoint_v2, this.client, this.objects, context)
|
|
132
|
+
|
|
133
|
+
this.counter = new Counter(this.packages.counter_v2, this.packages.utils, this.client, this.objects, context)
|
|
134
|
+
|
|
135
|
+
this.simpleMessageLib = new SimpleMessageLib(
|
|
136
|
+
this.packages.simple_message_lib,
|
|
137
|
+
this.client,
|
|
138
|
+
this.objects,
|
|
139
|
+
context
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
this.utils = new Utils(this.packages.utils, this.client, context)
|
|
143
|
+
|
|
144
|
+
this.zro = new Zro(this.packages.zro, this.client, context)
|
|
145
|
+
|
|
146
|
+
context.endpoint = this.endpoint
|
|
147
|
+
context.counter = this.counter
|
|
148
|
+
context.simpleMessageLib = this.simpleMessageLib
|
|
149
|
+
context.utils = this.utils
|
|
150
|
+
context.zro = this.zro
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Gets the Sui client.
|
|
155
|
+
*
|
|
156
|
+
* @returns {SuiClient} The Sui client.
|
|
157
|
+
*/
|
|
158
|
+
getSuiClient(): SuiClient {
|
|
159
|
+
return this.client
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Gets the chain.
|
|
164
|
+
*
|
|
165
|
+
* @returns {Chain} The chain.
|
|
166
|
+
*/
|
|
167
|
+
getChain(): Chain {
|
|
168
|
+
return this.chain
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets the stage.
|
|
173
|
+
*
|
|
174
|
+
* @returns {Stage} The stage.
|
|
175
|
+
*/
|
|
176
|
+
getStage(): Stage {
|
|
177
|
+
return this.stage
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Gets the package options.
|
|
182
|
+
*
|
|
183
|
+
* @returns {PackageOptions} The package options.
|
|
184
|
+
*/
|
|
185
|
+
getPackages(): PackageOptions {
|
|
186
|
+
return this.packages
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Gets the object options.
|
|
191
|
+
*
|
|
192
|
+
* @returns {ObjectOptions} The object options.
|
|
193
|
+
*/
|
|
194
|
+
getObjects(): ObjectOptions {
|
|
195
|
+
return this.objects
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets the endpoint module.
|
|
200
|
+
*
|
|
201
|
+
* @returns {Endpoint} The endpoint module.
|
|
202
|
+
*/
|
|
203
|
+
getEndpoint(): Endpoint {
|
|
204
|
+
return this.endpoint
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Gets the counter module.
|
|
209
|
+
*
|
|
210
|
+
* @returns {Counter} The counter module.
|
|
211
|
+
*/
|
|
212
|
+
getCounter(): Counter {
|
|
213
|
+
return this.counter
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Gets the simple message library module.
|
|
218
|
+
*
|
|
219
|
+
* @returns {SimpleMessageLib} The simple message library module.
|
|
220
|
+
*/
|
|
221
|
+
getSimpleMessageLib(): SimpleMessageLib {
|
|
222
|
+
return this.simpleMessageLib
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Gets the utils module.
|
|
227
|
+
*
|
|
228
|
+
* @returns {Utils} The utils module.
|
|
229
|
+
*/
|
|
230
|
+
getUtils(): Utils {
|
|
231
|
+
return this.utils
|
|
232
|
+
}
|
|
233
|
+
}
|