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