@layerzerolabs/lz-sui-sdk-v2 3.0.75 → 3.0.105-mpt.0
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 +0 -40
- package/dist/index.cjs +31 -1169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +24 -353
- package/dist/index.d.ts +24 -353
- package/dist/index.mjs +32 -1138
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -7
- package/src/endpoint.ts +38 -0
- package/src/index.ts +1 -5
- package/src/bcs/index.ts +0 -1
- package/src/bcs/messaging-fee.ts +0 -6
- package/src/modules/counter.ts +0 -239
- package/src/modules/endpoint.ts +0 -303
- package/src/modules/index.ts +0 -5
- package/src/modules/simple-message-lib.ts +0 -240
- package/src/modules/utils.ts +0 -390
- package/src/modules/zro.ts +0 -38
- package/src/sdk.ts +0 -233
- package/src/types.ts +0 -89
- package/src/utils.ts +0 -69
package/dist/index.cjs
CHANGED
|
@@ -1,1182 +1,44 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var lzCorekitSui = require('@layerzerolabs/lz-corekit-sui');
|
|
9
|
-
var lzDefinitions = require('@layerzerolabs/lz-definitions');
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
n.default = e;
|
|
26
|
-
return Object.freeze(n);
|
|
9
|
+
// src/endpoint.ts
|
|
10
|
+
var endpoint_exports = {};
|
|
11
|
+
__export(endpoint_exports, {
|
|
12
|
+
eid: () => eid,
|
|
13
|
+
getConfig: () => getConfig,
|
|
14
|
+
getSendLibrary: () => getSendLibrary,
|
|
15
|
+
initEid: () => initEid,
|
|
16
|
+
populateGetConfigTransaction: () => populateGetConfigTransaction,
|
|
17
|
+
populateQuoteTransaction: () => populateQuoteTransaction,
|
|
18
|
+
populateSendTransaction: () => populateSendTransaction,
|
|
19
|
+
populateSetConfigTransaction: () => populateSetConfigTransaction
|
|
20
|
+
});
|
|
21
|
+
async function initEid() {
|
|
22
|
+
throw new Error("Not implemented");
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
31
|
-
|
|
32
|
-
// src/modules/simple-message-lib.ts
|
|
33
|
-
async function devInspectTransaction(suiClient, tx, sender) {
|
|
34
|
-
const { results, error } = await suiClient.devInspectTransactionBlock({
|
|
35
|
-
transactionBlock: tx,
|
|
36
|
-
sender
|
|
37
|
-
});
|
|
38
|
-
if (error != void 0 && error != null) {
|
|
39
|
-
throw new Error(error);
|
|
40
|
-
}
|
|
41
|
-
return results;
|
|
24
|
+
async function eid() {
|
|
25
|
+
return Promise.resolve(1);
|
|
42
26
|
}
|
|
43
|
-
async function
|
|
44
|
-
|
|
45
|
-
sender = ed25519.Ed25519Keypair.generate().toSuiAddress();
|
|
46
|
-
}
|
|
47
|
-
const result = await devInspectTransaction(suiClient, tx, sender);
|
|
48
|
-
return result ? result[result.length - 1] : null;
|
|
27
|
+
async function getSendLibrary(sender, dst_eid) {
|
|
28
|
+
throw new Error("Not implemented");
|
|
49
29
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
if (!fs__namespace.existsSync(deploymentPath)) {
|
|
53
|
-
return void 0;
|
|
54
|
-
}
|
|
55
|
-
const deployment = JSON.parse(fs__namespace.readFileSync(deploymentPath, "utf8"));
|
|
56
|
-
return deployment.address;
|
|
30
|
+
async function getConfig() {
|
|
31
|
+
throw new Error("Not implemented");
|
|
57
32
|
}
|
|
58
|
-
async function
|
|
59
|
-
tx.setSenderIfNotSet(signer.getPublicKey().toSuiAddress());
|
|
60
|
-
const result = await client.signAndExecuteTransaction({
|
|
61
|
-
signer,
|
|
62
|
-
transaction: tx,
|
|
63
|
-
options: {
|
|
64
|
-
showEffects: true,
|
|
65
|
-
showObjectChanges: true,
|
|
66
|
-
showEvents: true
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
if (result.effects?.status.status !== "success") {
|
|
70
|
-
throw new Error(result.effects?.status.error);
|
|
71
|
-
}
|
|
72
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
73
|
-
return result;
|
|
33
|
+
async function populateQuoteTransaction(tx) {
|
|
74
34
|
}
|
|
75
|
-
|
|
76
|
-
// src/modules/simple-message-lib.ts
|
|
77
|
-
var SimpleMessageLib = class {
|
|
78
|
-
constructor(packageId, client, objects, context) {
|
|
79
|
-
this.context = context;
|
|
80
|
-
this.packageId = packageId;
|
|
81
|
-
this.client = client;
|
|
82
|
-
this.objects = objects;
|
|
83
|
-
if (this.objects.simple_message_lib.trim() === "") {
|
|
84
|
-
throw new Error("simple_message_lib object cannot be empty");
|
|
85
|
-
}
|
|
86
|
-
if (this.objects.endpoint_admin_cap.trim() === "") {
|
|
87
|
-
throw new Error("admin_cap object cannot be empty");
|
|
88
|
-
}
|
|
89
|
-
if (this.objects.endpoint_v2.trim() === "") {
|
|
90
|
-
throw new Error("endpoint_v2 object cannot be empty");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
populateInitializeTransaction() {
|
|
94
|
-
const tx = new transactions.Transaction();
|
|
95
|
-
tx.moveCall({
|
|
96
|
-
target: `${this.packageId}::simple_message_lib::initialize`,
|
|
97
|
-
typeArguments: [],
|
|
98
|
-
arguments: [tx.object(this.objects.endpoint_admin_cap), tx.object(this.objects.endpoint_v2)]
|
|
99
|
-
});
|
|
100
|
-
return tx;
|
|
101
|
-
}
|
|
102
|
-
// === View Functions ===
|
|
103
|
-
async getNativeFee() {
|
|
104
|
-
const tx = new transactions.Transaction();
|
|
105
|
-
tx.moveCall({
|
|
106
|
-
target: `${this.packageId}::simple_message_lib::get_native_fee`,
|
|
107
|
-
typeArguments: [],
|
|
108
|
-
arguments: [tx.object(this.objects.simple_message_lib)]
|
|
109
|
-
});
|
|
110
|
-
const result = await moveView(this.client, tx);
|
|
111
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
112
|
-
return bcs.bcs.U64.parse(bytes);
|
|
113
|
-
}
|
|
114
|
-
async getZroFee() {
|
|
115
|
-
const tx = new transactions.Transaction();
|
|
116
|
-
tx.moveCall({
|
|
117
|
-
target: `${this.packageId}::simple_message_lib::get_zro_fee`,
|
|
118
|
-
typeArguments: [],
|
|
119
|
-
arguments: [tx.object(this.objects.simple_message_lib)]
|
|
120
|
-
});
|
|
121
|
-
const result = await moveView(this.client, tx);
|
|
122
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
123
|
-
return bcs.bcs.U64.parse(bytes);
|
|
124
|
-
}
|
|
125
|
-
async getFeeRecipient() {
|
|
126
|
-
const tx = new transactions.Transaction();
|
|
127
|
-
tx.moveCall({
|
|
128
|
-
target: `${this.packageId}::simple_message_lib::get_fee_recipient`,
|
|
129
|
-
typeArguments: [],
|
|
130
|
-
arguments: [tx.object(this.objects.simple_message_lib)]
|
|
131
|
-
});
|
|
132
|
-
const result = await moveView(this.client, tx);
|
|
133
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
134
|
-
return bcs.bcs.Address.parse(bytes);
|
|
135
|
-
}
|
|
136
|
-
async isRegistered() {
|
|
137
|
-
const tx = new transactions.Transaction();
|
|
138
|
-
tx.moveCall({
|
|
139
|
-
target: `${this.packageId}::simple_message_lib::is_registered`,
|
|
140
|
-
typeArguments: [],
|
|
141
|
-
arguments: [tx.object(this.objects.simple_message_lib), tx.object(this.objects.endpoint_v2)]
|
|
142
|
-
});
|
|
143
|
-
const result = await moveView(this.client, tx);
|
|
144
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
145
|
-
return bcs.bcs.Bool.parse(bytes);
|
|
146
|
-
}
|
|
147
|
-
// === Admin Functions ===
|
|
148
|
-
populateRegisterLibraryTransaction() {
|
|
149
|
-
const tx = new transactions.Transaction();
|
|
150
|
-
tx.moveCall({
|
|
151
|
-
target: `${this.packageId}::simple_message_lib::register_library`,
|
|
152
|
-
typeArguments: [],
|
|
153
|
-
arguments: [
|
|
154
|
-
tx.object(this.objects.simple_message_lib),
|
|
155
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
156
|
-
tx.object(this.objects.endpoint_v2)
|
|
157
|
-
]
|
|
158
|
-
});
|
|
159
|
-
return tx;
|
|
160
|
-
}
|
|
161
|
-
populateSetMessagingFeeTransaction(zroFee, nativeFee) {
|
|
162
|
-
const tx = new transactions.Transaction();
|
|
163
|
-
tx.moveCall({
|
|
164
|
-
target: `${this.packageId}::simple_message_lib::set_messaging_fee`,
|
|
165
|
-
typeArguments: [],
|
|
166
|
-
arguments: [
|
|
167
|
-
tx.object(this.objects.simple_message_lib),
|
|
168
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
169
|
-
tx.pure.u64(zroFee),
|
|
170
|
-
tx.pure.u64(nativeFee)
|
|
171
|
-
]
|
|
172
|
-
});
|
|
173
|
-
return tx;
|
|
174
|
-
}
|
|
175
|
-
populateSetDefaultConfigTransaction(eid, configType, config) {
|
|
176
|
-
const tx = new transactions.Transaction();
|
|
177
|
-
tx.moveCall({
|
|
178
|
-
target: `${this.packageId}::simple_message_lib::set_default_config`,
|
|
179
|
-
typeArguments: [],
|
|
180
|
-
arguments: [
|
|
181
|
-
tx.object(this.objects.simple_message_lib),
|
|
182
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
183
|
-
tx.pure.u32(eid),
|
|
184
|
-
tx.pure.u32(configType),
|
|
185
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(config))
|
|
186
|
-
]
|
|
187
|
-
});
|
|
188
|
-
return tx;
|
|
189
|
-
}
|
|
190
|
-
populateSetFeeRecipientTransaction(feeRecipient) {
|
|
191
|
-
const tx = new transactions.Transaction();
|
|
192
|
-
tx.moveCall({
|
|
193
|
-
target: `${this.packageId}::simple_message_lib::set_fee_recipient`,
|
|
194
|
-
typeArguments: [],
|
|
195
|
-
arguments: [
|
|
196
|
-
tx.object(this.objects.simple_message_lib),
|
|
197
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
198
|
-
tx.pure.address(feeRecipient)
|
|
199
|
-
]
|
|
200
|
-
});
|
|
201
|
-
return tx;
|
|
202
|
-
}
|
|
203
|
-
// === Endpoint Validation ===
|
|
204
|
-
populateValidatePacketTransaction(packetHeader, payloadHash) {
|
|
205
|
-
const tx = new transactions.Transaction();
|
|
206
|
-
const payloadHashBytes32 = this.context.utils.fromBytesMoveCall(tx, payloadHash);
|
|
207
|
-
tx.moveCall({
|
|
208
|
-
target: `${this.packageId}::simple_message_lib::validate_packet`,
|
|
209
|
-
typeArguments: [],
|
|
210
|
-
arguments: [
|
|
211
|
-
tx.object(this.objects.simple_message_lib),
|
|
212
|
-
tx.object(this.objects.endpoint_v2),
|
|
213
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
214
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(packetHeader)),
|
|
215
|
-
payloadHashBytes32,
|
|
216
|
-
tx.object("0x6")
|
|
217
|
-
// Clock Object TODO try to get it from the client or sdk
|
|
218
|
-
]
|
|
219
|
-
});
|
|
220
|
-
return tx;
|
|
221
|
-
}
|
|
222
|
-
// === Protocol Discovery ===
|
|
223
|
-
populateRegisterMessageLibDiscoveryTransaction() {
|
|
224
|
-
const tx = new transactions.Transaction();
|
|
225
|
-
tx.moveCall({
|
|
226
|
-
target: `${this.packageId}::simple_message_lib::register_message_lib_discovery`,
|
|
227
|
-
typeArguments: [],
|
|
228
|
-
arguments: [
|
|
229
|
-
tx.object(this.objects.simple_message_lib),
|
|
230
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
231
|
-
tx.object(this.objects.endpoint_v2),
|
|
232
|
-
tx.object(this.objects.discovery)
|
|
233
|
-
]
|
|
234
|
-
});
|
|
235
|
-
return tx;
|
|
236
|
-
}
|
|
237
|
-
quoteMoveCall(tx, quoteCall) {
|
|
238
|
-
return tx.moveCall({
|
|
239
|
-
target: `${this.packageId}::simple_message_lib::quote`,
|
|
240
|
-
typeArguments: [],
|
|
241
|
-
arguments: [tx.object(this.objects.simple_message_lib), quoteCall]
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
sendMoveCall(tx, sendCall) {
|
|
245
|
-
return tx.moveCall({
|
|
246
|
-
target: `${this.packageId}::simple_message_lib::send`,
|
|
247
|
-
typeArguments: [],
|
|
248
|
-
arguments: [tx.object(this.objects.simple_message_lib), tx.object(this.objects.endpoint_v2), sendCall]
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
// === TODO: Core Message Lib Functions ===
|
|
252
|
-
// These functions are called by the endpoint and require specific parameter types
|
|
253
|
-
// that need to be implemented based on the endpoint_v2 module interfaces
|
|
254
|
-
populateQuoteTransaction(tx) {
|
|
255
|
-
}
|
|
256
|
-
populateSendTransaction(tx) {
|
|
257
|
-
}
|
|
258
|
-
populateSetConfigTransaction(tx) {
|
|
259
|
-
}
|
|
260
|
-
populateGetConfigTransaction(tx) {
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
var Endpoint = class {
|
|
264
|
-
constructor(packageId, client, objects, context) {
|
|
265
|
-
this.context = context;
|
|
266
|
-
this.packageId = packageId;
|
|
267
|
-
this.client = client;
|
|
268
|
-
this.objects = objects;
|
|
269
|
-
if (this.objects.endpoint_v2.trim() === "") {
|
|
270
|
-
throw new Error("endpoint_v2 object cannot be empty");
|
|
271
|
-
}
|
|
272
|
-
if (this.objects.endpoint_admin_cap.trim() === "") {
|
|
273
|
-
throw new Error("endpoint_admin_cap object cannot be empty");
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
async eid() {
|
|
277
|
-
const tx = new transactions.Transaction();
|
|
278
|
-
tx.moveCall({
|
|
279
|
-
target: `${this.packageId}::endpoint_v2::eid`,
|
|
280
|
-
typeArguments: [],
|
|
281
|
-
arguments: [tx.object(this.objects.endpoint_v2)]
|
|
282
|
-
});
|
|
283
|
-
try {
|
|
284
|
-
const result = await moveView(this.client, tx);
|
|
285
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
286
|
-
return bcs.bcs.U32.parse(bytes);
|
|
287
|
-
} catch (e) {
|
|
288
|
-
return 0;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
populateInitEidTransaction(eid) {
|
|
292
|
-
const tx = new transactions.Transaction();
|
|
293
|
-
tx.moveCall({
|
|
294
|
-
target: `${this.packageId}::endpoint_v2::init_eid`,
|
|
295
|
-
typeArguments: [],
|
|
296
|
-
arguments: [
|
|
297
|
-
tx.object(this.objects.endpoint_v2),
|
|
298
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
299
|
-
tx.pure.u32(eid)
|
|
300
|
-
]
|
|
301
|
-
});
|
|
302
|
-
return tx;
|
|
303
|
-
}
|
|
304
|
-
async getDefaultSendLibrary(srcEid) {
|
|
305
|
-
const tx = new transactions.Transaction();
|
|
306
|
-
tx.moveCall({
|
|
307
|
-
target: `${this.packageId}::endpoint_v2::get_default_send_library`,
|
|
308
|
-
typeArguments: [],
|
|
309
|
-
arguments: [tx.object(this.objects.endpoint_v2), tx.pure.u32(srcEid)]
|
|
310
|
-
});
|
|
311
|
-
try {
|
|
312
|
-
const result = await moveView(this.client, tx);
|
|
313
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
314
|
-
return bcs.bcs.Address.parse(bytes);
|
|
315
|
-
} catch (error) {
|
|
316
|
-
return "0x0";
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
populateSetDefaultSendLibraryTransaction(dstEid, newLib) {
|
|
320
|
-
const tx = new transactions.Transaction();
|
|
321
|
-
tx.moveCall({
|
|
322
|
-
target: `${this.packageId}::endpoint_v2::set_default_send_library`,
|
|
323
|
-
typeArguments: [],
|
|
324
|
-
arguments: [
|
|
325
|
-
tx.object(this.objects.endpoint_v2),
|
|
326
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
327
|
-
tx.pure.u32(dstEid),
|
|
328
|
-
tx.pure.address(newLib)
|
|
329
|
-
]
|
|
330
|
-
});
|
|
331
|
-
return tx;
|
|
332
|
-
}
|
|
333
|
-
async getDefaultReceiveLibrary(srcEid) {
|
|
334
|
-
const tx = new transactions.Transaction();
|
|
335
|
-
tx.moveCall({
|
|
336
|
-
target: `${this.packageId}::endpoint_v2::get_default_receive_library`,
|
|
337
|
-
typeArguments: [],
|
|
338
|
-
arguments: [tx.object(this.objects.endpoint_v2), tx.pure.u32(srcEid)]
|
|
339
|
-
});
|
|
340
|
-
try {
|
|
341
|
-
const result = await moveView(this.client, tx);
|
|
342
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
343
|
-
return bcs.bcs.Address.parse(bytes);
|
|
344
|
-
} catch (error) {
|
|
345
|
-
return "0x";
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
populateSetDefaultReceiveLibraryTransaction(srcEid, newLib, gracePeriod) {
|
|
349
|
-
const tx = new transactions.Transaction();
|
|
350
|
-
tx.moveCall({
|
|
351
|
-
target: `${this.packageId}::endpoint_v2::set_default_receive_library`,
|
|
352
|
-
typeArguments: [],
|
|
353
|
-
arguments: [
|
|
354
|
-
tx.object(this.objects.endpoint_v2),
|
|
355
|
-
tx.object(this.objects.endpoint_admin_cap),
|
|
356
|
-
tx.pure.u32(srcEid),
|
|
357
|
-
tx.pure.address(newLib),
|
|
358
|
-
tx.pure.u64(gracePeriod),
|
|
359
|
-
tx.object("0x6")
|
|
360
|
-
// Clock Object TODO try to get it from the client or sdk
|
|
361
|
-
]
|
|
362
|
-
});
|
|
363
|
-
return tx;
|
|
364
|
-
}
|
|
365
|
-
confirmQuoteMoveCall(tx, executedCall) {
|
|
366
|
-
return tx.moveCall({
|
|
367
|
-
target: `${this.packageId}::endpoint_v2::confirm_quote`,
|
|
368
|
-
typeArguments: [],
|
|
369
|
-
arguments: [tx.object(this.objects.endpoint_v2), executedCall]
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
confirmSendMoveCall(tx, executedCall) {
|
|
373
|
-
return tx.moveCall({
|
|
374
|
-
target: `${this.packageId}::endpoint_v2::confirm_send`,
|
|
375
|
-
typeArguments: [],
|
|
376
|
-
arguments: [tx.object(this.objects.endpoint_v2), executedCall]
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
// === Worker Endpoint Required Methods ===
|
|
380
|
-
async getSendLibrary(sender, dstEid) {
|
|
381
|
-
const tx = new transactions.Transaction();
|
|
382
|
-
tx.moveCall({
|
|
383
|
-
target: `${this.packageId}::endpoint_v2::get_send_library`,
|
|
384
|
-
typeArguments: [],
|
|
385
|
-
arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(sender), tx.pure.u32(dstEid)]
|
|
386
|
-
});
|
|
387
|
-
const result = await moveView(this.client, tx);
|
|
388
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
389
|
-
const lib = bcs.bcs.Address.parse(bytes);
|
|
390
|
-
const isDefaultBytes = new Uint8Array(result?.returnValues[1][0]);
|
|
391
|
-
const isDefault = bcs.bcs.Bool.parse(isDefaultBytes);
|
|
392
|
-
return [lib, isDefault];
|
|
393
|
-
}
|
|
394
|
-
async getReceiveLibrary(receiver, srcEid) {
|
|
395
|
-
const tx = new transactions.Transaction();
|
|
396
|
-
tx.moveCall({
|
|
397
|
-
target: `${this.packageId}::endpoint_v2::get_receive_library`,
|
|
398
|
-
typeArguments: [],
|
|
399
|
-
arguments: [tx.object(this.objects.endpoint_v2), tx.pure.address(receiver), tx.pure.u32(srcEid)]
|
|
400
|
-
});
|
|
401
|
-
const result = await moveView(this.client, tx);
|
|
402
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
403
|
-
const lib = bcs.bcs.Address.parse(bytes);
|
|
404
|
-
const isDefaultBytes = new Uint8Array(result?.returnValues[1][0]);
|
|
405
|
-
const isDefault = bcs.bcs.Bool.parse(isDefaultBytes);
|
|
406
|
-
return [lib, isDefault];
|
|
407
|
-
}
|
|
408
|
-
async getInboundNonce(receiver, srcEid, sender) {
|
|
409
|
-
const tx = new transactions.Transaction();
|
|
410
|
-
tx.moveCall({
|
|
411
|
-
target: `${this.packageId}::endpoint_v2::get_inbound_nonce`,
|
|
412
|
-
typeArguments: [],
|
|
413
|
-
arguments: [
|
|
414
|
-
tx.object(this.objects.endpoint_v2),
|
|
415
|
-
tx.pure.address(receiver),
|
|
416
|
-
tx.pure.u32(srcEid),
|
|
417
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(sender))
|
|
418
|
-
]
|
|
419
|
-
});
|
|
420
|
-
const result = await moveView(this.client, tx);
|
|
421
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
422
|
-
return BigInt(bcs.bcs.U64.parse(bytes));
|
|
423
|
-
}
|
|
424
|
-
async getLazyInboundNonce(receiver, srcEid, sender) {
|
|
425
|
-
const tx = new transactions.Transaction();
|
|
426
|
-
tx.moveCall({
|
|
427
|
-
target: `${this.packageId}::endpoint_v2::get_lazy_inbound_nonce`,
|
|
428
|
-
typeArguments: [],
|
|
429
|
-
arguments: [
|
|
430
|
-
tx.object(this.objects.endpoint_v2),
|
|
431
|
-
tx.pure.address(receiver),
|
|
432
|
-
tx.pure.u32(srcEid),
|
|
433
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(sender))
|
|
434
|
-
]
|
|
435
|
-
});
|
|
436
|
-
const result = await moveView(this.client, tx);
|
|
437
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
438
|
-
return BigInt(bcs.bcs.U64.parse(bytes));
|
|
439
|
-
}
|
|
440
|
-
async getOutboundNonce(sender, dstEid, receiver) {
|
|
441
|
-
const tx = new transactions.Transaction();
|
|
442
|
-
tx.moveCall({
|
|
443
|
-
target: `${this.packageId}::endpoint_v2::get_outbound_nonce`,
|
|
444
|
-
typeArguments: [],
|
|
445
|
-
arguments: [
|
|
446
|
-
tx.object(this.objects.endpoint_v2),
|
|
447
|
-
tx.pure.address(sender),
|
|
448
|
-
tx.pure.u32(dstEid),
|
|
449
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(receiver))
|
|
450
|
-
]
|
|
451
|
-
});
|
|
452
|
-
const result = await moveView(this.client, tx);
|
|
453
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
454
|
-
return BigInt(bcs.bcs.U64.parse(bytes));
|
|
455
|
-
}
|
|
456
|
-
async getInboundPayloadHash(receiver, srcEid, sender, nonce) {
|
|
457
|
-
const tx = new transactions.Transaction();
|
|
458
|
-
tx.moveCall({
|
|
459
|
-
target: `${this.packageId}::endpoint_v2::get_inbound_payload_hash`,
|
|
460
|
-
typeArguments: [],
|
|
461
|
-
arguments: [
|
|
462
|
-
tx.object(this.objects.endpoint_v2),
|
|
463
|
-
tx.pure.address(receiver),
|
|
464
|
-
tx.pure.u32(srcEid),
|
|
465
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(sender)),
|
|
466
|
-
tx.pure.u64(nonce)
|
|
467
|
-
]
|
|
468
|
-
});
|
|
469
|
-
try {
|
|
470
|
-
const result = await moveView(this.client, tx);
|
|
471
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
472
|
-
const parsed = bcs.bcs.vector(bcs.bcs.u8()).parse(bytes);
|
|
473
|
-
return Buffer.from(parsed);
|
|
474
|
-
} catch (error) {
|
|
475
|
-
return null;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
async getComposeMessageHash(from, to, guid, index) {
|
|
479
|
-
const tx = new transactions.Transaction();
|
|
480
|
-
tx.moveCall({
|
|
481
|
-
target: `${this.packageId}::endpoint_v2::get_compose_message_hash`,
|
|
482
|
-
typeArguments: [],
|
|
483
|
-
arguments: [
|
|
484
|
-
tx.object(this.objects.endpoint_v2),
|
|
485
|
-
tx.pure.address(from),
|
|
486
|
-
tx.pure.address(to),
|
|
487
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(guid)),
|
|
488
|
-
tx.pure.u16(index)
|
|
489
|
-
]
|
|
490
|
-
});
|
|
491
|
-
const result = await moveView(this.client, tx);
|
|
492
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
493
|
-
const parsed = bcs.bcs.vector(bcs.bcs.u8()).parse(bytes);
|
|
494
|
-
return Buffer.from(parsed);
|
|
495
|
-
}
|
|
496
|
-
// TODO: more view functions to be added here
|
|
497
|
-
populateQuoteTransaction(tx) {
|
|
498
|
-
}
|
|
499
|
-
populateSendTransaction(tx) {
|
|
500
|
-
}
|
|
501
|
-
populateGetConfigTransaction(tx) {
|
|
502
|
-
}
|
|
503
|
-
populateSetConfigTransaction(tx) {
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
var MessagingFeeBcs = bcs.bcs.struct("MessagingFee", {
|
|
507
|
-
native_fee: bcs.bcs.U64,
|
|
508
|
-
zro_fee: bcs.bcs.U64
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
// src/modules/counter.ts
|
|
512
|
-
var Counter = class {
|
|
513
|
-
constructor(packageId, utilsPkgId, client, objects, context) {
|
|
514
|
-
this.context = context;
|
|
515
|
-
this.packageId = packageId;
|
|
516
|
-
this.utilsPkgId = utilsPkgId;
|
|
517
|
-
this.client = client;
|
|
518
|
-
this.objects = objects;
|
|
519
|
-
}
|
|
520
|
-
async getPeer(dstEid) {
|
|
521
|
-
const tx = new transactions.Transaction();
|
|
522
|
-
const peerBytes32 = tx.moveCall({
|
|
523
|
-
target: `${this.packageId}::counter::get_peer`,
|
|
524
|
-
typeArguments: [],
|
|
525
|
-
arguments: [tx.object(this.objects.counter), tx.pure.u32(dstEid)]
|
|
526
|
-
});
|
|
527
|
-
tx.moveCall({
|
|
528
|
-
target: `${this.utilsPkgId}::bytes32::to_address`,
|
|
529
|
-
typeArguments: [],
|
|
530
|
-
arguments: [peerBytes32]
|
|
531
|
-
});
|
|
532
|
-
try {
|
|
533
|
-
const result = await moveView(this.client, tx);
|
|
534
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
535
|
-
return bcs.bcs.Address.parse(bytes);
|
|
536
|
-
} catch (e) {
|
|
537
|
-
return "";
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
async getCount() {
|
|
541
|
-
const tx = new transactions.Transaction();
|
|
542
|
-
tx.moveCall({
|
|
543
|
-
target: `${this.packageId}::counter::get_count`,
|
|
544
|
-
typeArguments: [],
|
|
545
|
-
arguments: [tx.object(this.objects.counter)]
|
|
546
|
-
});
|
|
547
|
-
try {
|
|
548
|
-
const result = await moveView(this.client, tx);
|
|
549
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
550
|
-
const counterStr = bcs.bcs.U64.parse(bytes);
|
|
551
|
-
return Number(counterStr);
|
|
552
|
-
} catch (e) {
|
|
553
|
-
return 0;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
async getComposedCount() {
|
|
557
|
-
const tx = new transactions.Transaction();
|
|
558
|
-
tx.moveCall({
|
|
559
|
-
target: `${this.packageId}::counter::get_composed_count`,
|
|
560
|
-
typeArguments: [],
|
|
561
|
-
arguments: [tx.object(this.objects.counter)]
|
|
562
|
-
});
|
|
563
|
-
try {
|
|
564
|
-
const result = await moveView(this.client, tx);
|
|
565
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
566
|
-
const counterStr = bcs.bcs.U64.parse(bytes);
|
|
567
|
-
return Number(counterStr);
|
|
568
|
-
} catch (e) {
|
|
569
|
-
return 0;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
populateSetPeerTransaction(dstEid, peer) {
|
|
573
|
-
const tx = new transactions.Transaction();
|
|
574
|
-
const peerBytes32 = tx.moveCall({
|
|
575
|
-
target: `${this.utilsPkgId}::bytes32::from_bytes`,
|
|
576
|
-
typeArguments: [],
|
|
577
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(peer))]
|
|
578
|
-
});
|
|
579
|
-
tx.moveCall({
|
|
580
|
-
target: `${this.packageId}::counter::set_peer`,
|
|
581
|
-
typeArguments: [],
|
|
582
|
-
arguments: [
|
|
583
|
-
tx.object(this.objects.counter),
|
|
584
|
-
tx.object(this.objects.counter_admin_cap),
|
|
585
|
-
tx.object(this.objects.endpoint_v2),
|
|
586
|
-
tx.pure.u32(dstEid),
|
|
587
|
-
peerBytes32
|
|
588
|
-
]
|
|
589
|
-
});
|
|
590
|
-
return tx;
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Builds a transaction for calling the lz_receive function on the counter contract.
|
|
594
|
-
*
|
|
595
|
-
* @param srcEid - The source endpoint ID
|
|
596
|
-
* @param sender - The sender address as Bytes32
|
|
597
|
-
* @param nonce - The nonce
|
|
598
|
-
* @param guid - The GUID as Bytes32
|
|
599
|
-
* @param message - The message as vector<u8>
|
|
600
|
-
* @param value - The value to be sent (Coin<SUI>)
|
|
601
|
-
* @param extraData - Extra data as vector<u8>
|
|
602
|
-
* @returns A Transaction object ready to be executed
|
|
603
|
-
*/
|
|
604
|
-
populateLzReceiveTransaction(srcEid, sender, nonce, guid, message, value, extraData = new Uint8Array()) {
|
|
605
|
-
const tx = new transactions.Transaction();
|
|
606
|
-
const senderBytes32 = this.context.utils.fromBytesMoveCall(tx, sender);
|
|
607
|
-
const guidBytes32 = this.context.utils.fromBytesMoveCall(tx, guid);
|
|
608
|
-
const coin = tx.splitCoins(tx.gas, [tx.pure.u64(value)]);
|
|
609
|
-
tx.moveCall({
|
|
610
|
-
target: `${this.packageId}::counter::lz_receive`,
|
|
611
|
-
typeArguments: [],
|
|
612
|
-
arguments: [
|
|
613
|
-
tx.object(this.objects.counter),
|
|
614
|
-
tx.object(this.objects.endpoint_v2),
|
|
615
|
-
tx.pure.u32(srcEid),
|
|
616
|
-
senderBytes32,
|
|
617
|
-
tx.pure.u64(nonce),
|
|
618
|
-
guidBytes32,
|
|
619
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(message)),
|
|
620
|
-
coin,
|
|
621
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(extraData))
|
|
622
|
-
]
|
|
623
|
-
});
|
|
624
|
-
return tx;
|
|
625
|
-
}
|
|
626
|
-
async quote(dstEid, msgType, options, payInZero) {
|
|
627
|
-
const tx = new transactions.Transaction();
|
|
628
|
-
const quoteCall = tx.moveCall({
|
|
629
|
-
target: `${this.packageId}::counter::quote`,
|
|
630
|
-
typeArguments: [],
|
|
631
|
-
arguments: [
|
|
632
|
-
tx.object(this.objects.counter),
|
|
633
|
-
tx.object(this.objects.endpoint_v2),
|
|
634
|
-
tx.pure.u32(dstEid),
|
|
635
|
-
tx.pure.u8(msgType),
|
|
636
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(options)),
|
|
637
|
-
tx.pure.bool(payInZero)
|
|
638
|
-
]
|
|
639
|
-
});
|
|
640
|
-
const executedCall = this.context.simpleMessageLib.quoteMoveCall(tx, quoteCall);
|
|
641
|
-
this.context.endpoint.confirmQuoteMoveCall(tx, executedCall);
|
|
642
|
-
const result = await moveView(this.client, tx);
|
|
643
|
-
const bytes = new Uint8Array(result?.returnValues[0][0]);
|
|
644
|
-
const messageFee = MessagingFeeBcs.parse(bytes);
|
|
645
|
-
return [BigInt(messageFee.native_fee), BigInt(messageFee.zro_fee)];
|
|
646
|
-
}
|
|
647
|
-
async send(sender, dstEid, msgType, options, sendValue, nativeFee, zroFee) {
|
|
648
|
-
const tx = new transactions.Transaction();
|
|
649
|
-
const [nativeToken] = tx.splitCoins(tx.gas, [tx.pure.u64(nativeFee)]);
|
|
650
|
-
const zroToken = this.context.zro.noneOptionMoveCall(tx);
|
|
651
|
-
const incrementCall = tx.moveCall({
|
|
652
|
-
target: `${this.packageId}::counter::increment`,
|
|
653
|
-
typeArguments: [],
|
|
654
|
-
arguments: [
|
|
655
|
-
tx.object(this.objects.counter),
|
|
656
|
-
tx.object(this.objects.endpoint_v2),
|
|
657
|
-
tx.pure.u32(dstEid),
|
|
658
|
-
tx.pure.u8(msgType),
|
|
659
|
-
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(options)),
|
|
660
|
-
nativeToken,
|
|
661
|
-
zroToken,
|
|
662
|
-
tx.pure.u64(sendValue),
|
|
663
|
-
tx.pure.address(sender.toSuiAddress())
|
|
664
|
-
]
|
|
665
|
-
});
|
|
666
|
-
const executedCall = this.context.simpleMessageLib.sendMoveCall(tx, incrementCall);
|
|
667
|
-
this.context.endpoint.confirmSendMoveCall(tx, executedCall);
|
|
668
|
-
return validateTransaction(this.client, sender, tx);
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
var Utils = class {
|
|
672
|
-
constructor(packageId, client, context) {
|
|
673
|
-
this.packageId = packageId;
|
|
674
|
-
this.client = client;
|
|
675
|
-
this.context = context;
|
|
676
|
-
if (this.packageId.trim() === "") {
|
|
677
|
-
throw new Error("utils package ID cannot be empty");
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
// === bytes32 Functions ===
|
|
681
|
-
fromBytesMoveCall(tx, peer) {
|
|
682
|
-
return tx.moveCall({
|
|
683
|
-
target: `${this.packageId}::bytes32::from_bytes`,
|
|
684
|
-
typeArguments: [],
|
|
685
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(peer))]
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
fromBytesLeftPaddedMoveCall(tx, bytes) {
|
|
689
|
-
return tx.moveCall({
|
|
690
|
-
target: `${this.packageId}::bytes32::from_bytes_left_padded`,
|
|
691
|
-
typeArguments: [],
|
|
692
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(bytes))]
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
fromBytesRightPaddedMoveCall(tx, bytes) {
|
|
696
|
-
return tx.moveCall({
|
|
697
|
-
target: `${this.packageId}::bytes32::from_bytes_right_padded`,
|
|
698
|
-
typeArguments: [],
|
|
699
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(bytes))]
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
fromAddressMoveCall(tx, address) {
|
|
703
|
-
return tx.moveCall({
|
|
704
|
-
target: `${this.packageId}::bytes32::from_address`,
|
|
705
|
-
typeArguments: [],
|
|
706
|
-
arguments: [tx.pure.address(address)]
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
fromIdMoveCall(tx, id) {
|
|
710
|
-
return tx.moveCall({
|
|
711
|
-
target: `${this.packageId}::bytes32::from_id`,
|
|
712
|
-
typeArguments: [],
|
|
713
|
-
arguments: [tx.object(id)]
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
zeroBytes32MoveCall(tx) {
|
|
717
|
-
return tx.moveCall({
|
|
718
|
-
target: `${this.packageId}::bytes32::zero_bytes32`,
|
|
719
|
-
typeArguments: [],
|
|
720
|
-
arguments: []
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
ffBytes32MoveCall(tx) {
|
|
724
|
-
return tx.moveCall({
|
|
725
|
-
target: `${this.packageId}::bytes32::ff_bytes32`,
|
|
726
|
-
typeArguments: [],
|
|
727
|
-
arguments: []
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
isZeroMoveCall(tx, bytes32) {
|
|
731
|
-
return tx.moveCall({
|
|
732
|
-
target: `${this.packageId}::bytes32::is_zero`,
|
|
733
|
-
typeArguments: [],
|
|
734
|
-
arguments: [tx.object(bytes32)]
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
isFfMoveCall(tx, bytes32) {
|
|
738
|
-
return tx.moveCall({
|
|
739
|
-
target: `${this.packageId}::bytes32::is_ff`,
|
|
740
|
-
typeArguments: [],
|
|
741
|
-
arguments: [tx.object(bytes32)]
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
toBytesMoveCall(tx, bytes32) {
|
|
745
|
-
return tx.moveCall({
|
|
746
|
-
target: `${this.packageId}::bytes32::to_bytes`,
|
|
747
|
-
typeArguments: [],
|
|
748
|
-
arguments: [tx.object(bytes32)]
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
toAddressMoveCall(tx, bytes32) {
|
|
752
|
-
return tx.moveCall({
|
|
753
|
-
target: `${this.packageId}::bytes32::to_address`,
|
|
754
|
-
typeArguments: [],
|
|
755
|
-
arguments: [tx.object(bytes32)]
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
toIdMoveCall(tx, bytes32) {
|
|
759
|
-
return tx.moveCall({
|
|
760
|
-
target: `${this.packageId}::bytes32::to_id`,
|
|
761
|
-
typeArguments: [],
|
|
762
|
-
arguments: [tx.object(bytes32)]
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
// === Buffer Functions ===
|
|
766
|
-
newReaderMoveCall(tx, buffer) {
|
|
767
|
-
return tx.moveCall({
|
|
768
|
-
target: `${this.packageId}::buffer::new_reader`,
|
|
769
|
-
typeArguments: [],
|
|
770
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(buffer))]
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
newWriterMoveCall(tx) {
|
|
774
|
-
return tx.moveCall({
|
|
775
|
-
target: `${this.packageId}::buffer::new_writer`,
|
|
776
|
-
typeArguments: [],
|
|
777
|
-
arguments: []
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
createWriterMoveCall(tx, buffer) {
|
|
781
|
-
return tx.moveCall({
|
|
782
|
-
target: `${this.packageId}::buffer::create_writer`,
|
|
783
|
-
typeArguments: [],
|
|
784
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(buffer))]
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
// Reader functions
|
|
788
|
-
positionMoveCall(tx, reader) {
|
|
789
|
-
return tx.moveCall({
|
|
790
|
-
target: `${this.packageId}::buffer::position`,
|
|
791
|
-
typeArguments: [],
|
|
792
|
-
arguments: [reader]
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
remainingLengthMoveCall(tx, reader) {
|
|
796
|
-
return tx.moveCall({
|
|
797
|
-
target: `${this.packageId}::buffer::remaining_length`,
|
|
798
|
-
typeArguments: [],
|
|
799
|
-
arguments: [reader]
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
skipMoveCall(tx, reader, len) {
|
|
803
|
-
return tx.moveCall({
|
|
804
|
-
target: `${this.packageId}::buffer::skip`,
|
|
805
|
-
typeArguments: [],
|
|
806
|
-
arguments: [reader, tx.pure.u64(len)]
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
setPositionMoveCall(tx, reader, position) {
|
|
810
|
-
return tx.moveCall({
|
|
811
|
-
target: `${this.packageId}::buffer::set_position`,
|
|
812
|
-
typeArguments: [],
|
|
813
|
-
arguments: [reader, tx.pure.u64(position)]
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
rewindMoveCall(tx, reader, len) {
|
|
817
|
-
return tx.moveCall({
|
|
818
|
-
target: `${this.packageId}::buffer::rewind`,
|
|
819
|
-
typeArguments: [],
|
|
820
|
-
arguments: [reader, tx.pure.u64(len)]
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
readU8MoveCall(tx, reader) {
|
|
824
|
-
return tx.moveCall({
|
|
825
|
-
target: `${this.packageId}::buffer::read_u8`,
|
|
826
|
-
typeArguments: [],
|
|
827
|
-
arguments: [reader]
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
readU16MoveCall(tx, reader) {
|
|
831
|
-
return tx.moveCall({
|
|
832
|
-
target: `${this.packageId}::buffer::read_u16`,
|
|
833
|
-
typeArguments: [],
|
|
834
|
-
arguments: [reader]
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
readU32MoveCall(tx, reader) {
|
|
838
|
-
return tx.moveCall({
|
|
839
|
-
target: `${this.packageId}::buffer::read_u32`,
|
|
840
|
-
typeArguments: [],
|
|
841
|
-
arguments: [reader]
|
|
842
|
-
});
|
|
843
|
-
}
|
|
844
|
-
readU64MoveCall(tx, reader) {
|
|
845
|
-
return tx.moveCall({
|
|
846
|
-
target: `${this.packageId}::buffer::read_u64`,
|
|
847
|
-
typeArguments: [],
|
|
848
|
-
arguments: [reader]
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
readU128MoveCall(tx, reader) {
|
|
852
|
-
return tx.moveCall({
|
|
853
|
-
target: `${this.packageId}::buffer::read_u128`,
|
|
854
|
-
typeArguments: [],
|
|
855
|
-
arguments: [reader]
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
readU256MoveCall(tx, reader) {
|
|
859
|
-
return tx.moveCall({
|
|
860
|
-
target: `${this.packageId}::buffer::read_u256`,
|
|
861
|
-
typeArguments: [],
|
|
862
|
-
arguments: [reader]
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
readBytes32MoveCall(tx, reader) {
|
|
866
|
-
return tx.moveCall({
|
|
867
|
-
target: `${this.packageId}::buffer::read_bytes32`,
|
|
868
|
-
typeArguments: [],
|
|
869
|
-
arguments: [reader]
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
readAddressMoveCall(tx, reader) {
|
|
873
|
-
return tx.moveCall({
|
|
874
|
-
target: `${this.packageId}::buffer::read_address`,
|
|
875
|
-
typeArguments: [],
|
|
876
|
-
arguments: [reader]
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
readFixedLenBytesMoveCall(tx, reader, len) {
|
|
880
|
-
return tx.moveCall({
|
|
881
|
-
target: `${this.packageId}::buffer::read_fixed_len_bytes`,
|
|
882
|
-
typeArguments: [],
|
|
883
|
-
arguments: [reader, tx.pure.u64(len)]
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
readBytesUntilEndMoveCall(tx, reader) {
|
|
887
|
-
return tx.moveCall({
|
|
888
|
-
target: `${this.packageId}::buffer::read_bytes_until_end`,
|
|
889
|
-
typeArguments: [],
|
|
890
|
-
arguments: [reader]
|
|
891
|
-
});
|
|
892
|
-
}
|
|
893
|
-
readerBufferLengthMoveCall(tx, reader) {
|
|
894
|
-
return tx.moveCall({
|
|
895
|
-
target: `${this.packageId}::buffer::reader_buffer_length`,
|
|
896
|
-
typeArguments: [],
|
|
897
|
-
arguments: [reader]
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
readerToBytesMoveCall(tx, reader) {
|
|
901
|
-
return tx.moveCall({
|
|
902
|
-
target: `${this.packageId}::buffer::reader_to_bytes`,
|
|
903
|
-
typeArguments: [],
|
|
904
|
-
arguments: [reader]
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
// Writer functions
|
|
908
|
-
writerBufferLengthMoveCall(tx, writer) {
|
|
909
|
-
return tx.moveCall({
|
|
910
|
-
target: `${this.packageId}::buffer::writer_buffer_length`,
|
|
911
|
-
typeArguments: [],
|
|
912
|
-
arguments: [writer]
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
writerToBytesMoveCall(tx, writer) {
|
|
916
|
-
return tx.moveCall({
|
|
917
|
-
target: `${this.packageId}::buffer::writer_to_bytes`,
|
|
918
|
-
typeArguments: [],
|
|
919
|
-
arguments: [writer]
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
writeU8MoveCall(tx, writer, value) {
|
|
923
|
-
return tx.moveCall({
|
|
924
|
-
target: `${this.packageId}::buffer::write_u8`,
|
|
925
|
-
typeArguments: [],
|
|
926
|
-
arguments: [writer, tx.pure.u8(value)]
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
writeU16MoveCall(tx, writer, value) {
|
|
930
|
-
return tx.moveCall({
|
|
931
|
-
target: `${this.packageId}::buffer::write_u16`,
|
|
932
|
-
typeArguments: [],
|
|
933
|
-
arguments: [writer, tx.pure.u16(value)]
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
writeU32MoveCall(tx, writer, value) {
|
|
937
|
-
return tx.moveCall({
|
|
938
|
-
target: `${this.packageId}::buffer::write_u32`,
|
|
939
|
-
typeArguments: [],
|
|
940
|
-
arguments: [writer, tx.pure.u32(value)]
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
writeU64MoveCall(tx, writer, value) {
|
|
944
|
-
return tx.moveCall({
|
|
945
|
-
target: `${this.packageId}::buffer::write_u64`,
|
|
946
|
-
typeArguments: [],
|
|
947
|
-
arguments: [writer, tx.pure.u64(value)]
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
writeU128MoveCall(tx, writer, value) {
|
|
951
|
-
return tx.moveCall({
|
|
952
|
-
target: `${this.packageId}::buffer::write_u128`,
|
|
953
|
-
typeArguments: [],
|
|
954
|
-
arguments: [writer, tx.pure.u128(value)]
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
writeU256MoveCall(tx, writer, value) {
|
|
958
|
-
return tx.moveCall({
|
|
959
|
-
target: `${this.packageId}::buffer::write_u256`,
|
|
960
|
-
typeArguments: [],
|
|
961
|
-
arguments: [writer, tx.pure.u256(value)]
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
writeBytesMoveCall(tx, writer, bytes) {
|
|
965
|
-
return tx.moveCall({
|
|
966
|
-
target: `${this.packageId}::buffer::write_bytes`,
|
|
967
|
-
typeArguments: [],
|
|
968
|
-
arguments: [writer, tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(bytes))]
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
writeAddressMoveCall(tx, writer, address) {
|
|
972
|
-
return tx.moveCall({
|
|
973
|
-
target: `${this.packageId}::buffer::write_address`,
|
|
974
|
-
typeArguments: [],
|
|
975
|
-
arguments: [writer, tx.pure.address(address)]
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
writeBytes32MoveCall(tx, writer, bytes32) {
|
|
979
|
-
return tx.moveCall({
|
|
980
|
-
target: `${this.packageId}::buffer::write_bytes32`,
|
|
981
|
-
typeArguments: [],
|
|
982
|
-
arguments: [writer, tx.object(bytes32)]
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
// === Hash Functions ===
|
|
986
|
-
blake2b256MoveCall(tx, bytes) {
|
|
987
|
-
return tx.moveCall({
|
|
988
|
-
target: `${this.packageId}::hash::blake2b256`,
|
|
989
|
-
typeArguments: [],
|
|
990
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(bytes))]
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
keccak256MoveCall(tx, bytes) {
|
|
994
|
-
return tx.moveCall({
|
|
995
|
-
target: `${this.packageId}::hash::keccak256`,
|
|
996
|
-
typeArguments: [],
|
|
997
|
-
arguments: [tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(bytes))]
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
};
|
|
1001
|
-
|
|
1002
|
-
// src/modules/zro.ts
|
|
1003
|
-
var Zro = class {
|
|
1004
|
-
constructor(packageId, client, context) {
|
|
1005
|
-
this.context = context;
|
|
1006
|
-
this.packageId = packageId;
|
|
1007
|
-
this.client = client;
|
|
1008
|
-
}
|
|
1009
|
-
zeroOptionMoveCall(tx) {
|
|
1010
|
-
const zroToken = tx.moveCall({
|
|
1011
|
-
target: `0x2::coin::zero`,
|
|
1012
|
-
typeArguments: [`${this.packageId}::zro::ZRO`]
|
|
1013
|
-
});
|
|
1014
|
-
const zroOption = tx.moveCall({
|
|
1015
|
-
target: `0x1::option::some`,
|
|
1016
|
-
typeArguments: [`0x2::coin::Coin<${this.packageId}::zro::ZRO>`],
|
|
1017
|
-
arguments: [zroToken]
|
|
1018
|
-
});
|
|
1019
|
-
return zroOption;
|
|
1020
|
-
}
|
|
1021
|
-
noneOptionMoveCall(tx) {
|
|
1022
|
-
return tx.moveCall({
|
|
1023
|
-
target: `0x1::option::none`,
|
|
1024
|
-
typeArguments: [`0x2::coin::Coin<${this.packageId}::zro::ZRO>`]
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
|
-
};
|
|
1028
|
-
function assertSuiProvider(provider) {
|
|
1029
|
-
if (!(provider instanceof lzCorekitSui.SuiProvider)) {
|
|
1030
|
-
throw new Error("Invalid provider");
|
|
1031
|
-
}
|
|
35
|
+
async function populateSendTransaction(tx) {
|
|
1032
36
|
}
|
|
1033
|
-
function
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
return new SDK({
|
|
1037
|
-
client,
|
|
1038
|
-
stage
|
|
1039
|
-
});
|
|
37
|
+
async function populateGetConfigTransaction(tx) {
|
|
38
|
+
}
|
|
39
|
+
async function populateSetConfigTransaction(tx) {
|
|
1040
40
|
}
|
|
1041
|
-
var SDK = class {
|
|
1042
|
-
/**
|
|
1043
|
-
* Creates an instance of the SDK.
|
|
1044
|
-
*
|
|
1045
|
-
* @param {SdkOptions} options - The SDK options.
|
|
1046
|
-
*/
|
|
1047
|
-
constructor(options) {
|
|
1048
|
-
this.chain = options.chain ?? lzDefinitions.Chain.PLACEHOLDER0;
|
|
1049
|
-
this.stage = options.stage ?? lzDefinitions.Stage.SANDBOX;
|
|
1050
|
-
this.client = options.client;
|
|
1051
|
-
const network = lzDefinitions.chainAndStageToNetwork(this.chain, this.stage, this.stage === lzDefinitions.Stage.SANDBOX);
|
|
1052
|
-
const defaultPackages = {
|
|
1053
|
-
utils: readAddressFromDeployment(network, "utils"),
|
|
1054
|
-
endpoint_v2: readAddressFromDeployment(network, "endpoint_v2"),
|
|
1055
|
-
counter_v2: readAddressFromDeployment(network, "counter"),
|
|
1056
|
-
simple_message_lib: readAddressFromDeployment(network, "simple_message_lib"),
|
|
1057
|
-
zro: readAddressFromDeployment(network, "zro")
|
|
1058
|
-
};
|
|
1059
|
-
this.packages = {
|
|
1060
|
-
...defaultPackages,
|
|
1061
|
-
...options.packages
|
|
1062
|
-
};
|
|
1063
|
-
const defaultObjects = {
|
|
1064
|
-
endpoint_v2: readAddressFromDeployment(network, "object-EndpointV2"),
|
|
1065
|
-
simple_message_lib: readAddressFromDeployment(network, "object-SimpleMessageLib"),
|
|
1066
|
-
uln_302: readAddressFromDeployment(network, "object-ULN302"),
|
|
1067
|
-
blocked_message_lib: readAddressFromDeployment(network, "object-BlockedMessageLib"),
|
|
1068
|
-
discovery: readAddressFromDeployment(network, "object-Discovery"),
|
|
1069
|
-
counter: readAddressFromDeployment(network, "object-Counter"),
|
|
1070
|
-
counter_admin_cap: readAddressFromDeployment(network, "object-CounterAdminCap"),
|
|
1071
|
-
endpoint_admin_cap: readAddressFromDeployment(network, "object-EndpointV2AdminCap"),
|
|
1072
|
-
oapp_core: readAddressFromDeployment(network, "object-OAppCore")
|
|
1073
|
-
};
|
|
1074
|
-
this.objects = {
|
|
1075
|
-
...defaultObjects,
|
|
1076
|
-
...options.objects
|
|
1077
|
-
};
|
|
1078
|
-
const context = {};
|
|
1079
|
-
this.endpoint = new Endpoint(this.packages.endpoint_v2, this.client, this.objects, context);
|
|
1080
|
-
this.counter = new Counter(this.packages.counter_v2, this.packages.utils, this.client, this.objects, context);
|
|
1081
|
-
this.simpleMessageLib = new SimpleMessageLib(
|
|
1082
|
-
this.packages.simple_message_lib,
|
|
1083
|
-
this.client,
|
|
1084
|
-
this.objects,
|
|
1085
|
-
context
|
|
1086
|
-
);
|
|
1087
|
-
this.utils = new Utils(this.packages.utils, this.client, context);
|
|
1088
|
-
this.zro = new Zro(this.packages.zro, this.client, context);
|
|
1089
|
-
context.endpoint = this.endpoint;
|
|
1090
|
-
context.counter = this.counter;
|
|
1091
|
-
context.simpleMessageLib = this.simpleMessageLib;
|
|
1092
|
-
context.utils = this.utils;
|
|
1093
|
-
context.zro = this.zro;
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Gets the Sui client.
|
|
1097
|
-
*
|
|
1098
|
-
* @returns {SuiClient} The Sui client.
|
|
1099
|
-
*/
|
|
1100
|
-
getSuiClient() {
|
|
1101
|
-
return this.client;
|
|
1102
|
-
}
|
|
1103
|
-
/**
|
|
1104
|
-
* Gets the chain.
|
|
1105
|
-
*
|
|
1106
|
-
* @returns {Chain} The chain.
|
|
1107
|
-
*/
|
|
1108
|
-
getChain() {
|
|
1109
|
-
return this.chain;
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Gets the stage.
|
|
1113
|
-
*
|
|
1114
|
-
* @returns {Stage} The stage.
|
|
1115
|
-
*/
|
|
1116
|
-
getStage() {
|
|
1117
|
-
return this.stage;
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Gets the package options.
|
|
1121
|
-
*
|
|
1122
|
-
* @returns {PackageOptions} The package options.
|
|
1123
|
-
*/
|
|
1124
|
-
getPackages() {
|
|
1125
|
-
return this.packages;
|
|
1126
|
-
}
|
|
1127
|
-
/**
|
|
1128
|
-
* Gets the object options.
|
|
1129
|
-
*
|
|
1130
|
-
* @returns {ObjectOptions} The object options.
|
|
1131
|
-
*/
|
|
1132
|
-
getObjects() {
|
|
1133
|
-
return this.objects;
|
|
1134
|
-
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Gets the endpoint module.
|
|
1137
|
-
*
|
|
1138
|
-
* @returns {Endpoint} The endpoint module.
|
|
1139
|
-
*/
|
|
1140
|
-
getEndpoint() {
|
|
1141
|
-
return this.endpoint;
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Gets the counter module.
|
|
1145
|
-
*
|
|
1146
|
-
* @returns {Counter} The counter module.
|
|
1147
|
-
*/
|
|
1148
|
-
getCounter() {
|
|
1149
|
-
return this.counter;
|
|
1150
|
-
}
|
|
1151
|
-
/**
|
|
1152
|
-
* Gets the simple message library module.
|
|
1153
|
-
*
|
|
1154
|
-
* @returns {SimpleMessageLib} The simple message library module.
|
|
1155
|
-
*/
|
|
1156
|
-
getSimpleMessageLib() {
|
|
1157
|
-
return this.simpleMessageLib;
|
|
1158
|
-
}
|
|
1159
|
-
/**
|
|
1160
|
-
* Gets the utils module.
|
|
1161
|
-
*
|
|
1162
|
-
* @returns {Utils} The utils module.
|
|
1163
|
-
*/
|
|
1164
|
-
getUtils() {
|
|
1165
|
-
return this.utils;
|
|
1166
|
-
}
|
|
1167
|
-
};
|
|
1168
41
|
|
|
1169
|
-
exports.
|
|
1170
|
-
exports.Endpoint = Endpoint;
|
|
1171
|
-
exports.MessagingFeeBcs = MessagingFeeBcs;
|
|
1172
|
-
exports.SDK = SDK;
|
|
1173
|
-
exports.SimpleMessageLib = SimpleMessageLib;
|
|
1174
|
-
exports.Utils = Utils;
|
|
1175
|
-
exports.Zro = Zro;
|
|
1176
|
-
exports.devInspectTransaction = devInspectTransaction;
|
|
1177
|
-
exports.getSDKFromProvider = getSDKFromProvider;
|
|
1178
|
-
exports.moveView = moveView;
|
|
1179
|
-
exports.readAddressFromDeployment = readAddressFromDeployment;
|
|
1180
|
-
exports.validateTransaction = validateTransaction;
|
|
42
|
+
exports.endpoint = endpoint_exports;
|
|
1181
43
|
//# sourceMappingURL=index.cjs.map
|
|
1182
44
|
//# sourceMappingURL=index.cjs.map
|