@layerzerolabs/oft-iota-sdk 0.0.0-stage → 1.2.100

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.
@@ -0,0 +1,1296 @@
1
+ import { parseOFTReceipt, parseOFTFeeDetails, parseOFTLimit, parseOFTInfoV1 } from './CDSWWWJ7.js';
2
+ import { __name } from './VUOMXK5T.js';
3
+ import { bcs } from '@iota/iota-sdk/bcs';
4
+ import { Transaction } from '@iota/iota-sdk/transactions';
5
+ import { asObject, asU8, executeSimulate, asBytes, asBool, asAddress, asU64, asU32, isTransactionArgument, asArgWithTx, asArgWithTxAsync, asBytes32 } from '@layerzerolabs/lz-iotal1-sdk-v2';
6
+
7
+ var MODULE_NAME = "oft";
8
+ var OFT_SENDER_MODULE_NAME = "oft_sender";
9
+ var OFT_IMPL_MODULE_NAME = "oft_impl";
10
+ var OFT_PTB_BUILDER_MODULE_NAME = "oft_ptb_builder";
11
+ var OFTErrorCode = {
12
+ // OFT related errors
13
+ EComposeMsgNotAllowed: 1,
14
+ EComposeMsgRequired: 2,
15
+ EInsufficientBalance: 3,
16
+ EInvalidAdminCap: 4,
17
+ EInvalidComposeQueue: 5,
18
+ EInvalidLocalDecimals: 6,
19
+ EInvalidMigrationCap: 7,
20
+ EInvalidSendContext: 8,
21
+ ESlippageExceeded: 9,
22
+ EWrongPackageVersion: 10
23
+ };
24
+ var OFT = class {
25
+ static {
26
+ __name(this, "OFT");
27
+ }
28
+ /** Iota client for blockchain interactions */
29
+ client;
30
+ /** The OFTCallCap ID */
31
+ oftCallCapId;
32
+ /** The package ID of the OFT */
33
+ oftPackageId;
34
+ /** LayerZero protocol object references (endpoint, messaging channels, etc.) */
35
+ objects;
36
+ /** The unique object ID of this OFT instance on Iota */
37
+ oftObjectId;
38
+ /** Admin capability object ID for privileged operations (retrieved dynamically when needed) */
39
+ adminCapId;
40
+ /** The Iota coin type this OFT represents (e.g., "0x123::mycoin::MYCOIN") */
41
+ coinType;
42
+ /** The unique object ID of the associated OApp instance on Iota */
43
+ oappObjectId;
44
+ /** Reference to the LayerZero protocol SDK for cross-chain operations */
45
+ protocolSDK;
46
+ /** The OFTInfoV1 structure */
47
+ oftInfo;
48
+ /**
49
+ * Creates a new OFT instance for interacting with an Omnichain Fungible Token
50
+ *
51
+ * @param protocolSDK - The LayerZero protocol SDK instance providing core cross-chain functionality
52
+ * @param oftCallCapId - The OFT call capability ID used for OFT operations and accessing OFT information
53
+ * @param oftObjectId - Optional OFT object ID on Iota blockchain for direct OFT instance access
54
+ * @param coinType - Optional Iota coin type string (e.g., "0x123::mycoin::MYCOIN") that this OFT represents
55
+ * @param oappObjectId - Optional associated OApp object ID for cross-chain messaging operations
56
+ * @param adminCapId - Optional admin capability object ID for privileged operations
57
+ */
58
+ constructor(protocolSDK, oftCallCapId, oftObjectId, coinType, oappObjectId, adminCapId) {
59
+ this.protocolSDK = protocolSDK;
60
+ this.oftCallCapId = oftCallCapId;
61
+ this.client = protocolSDK.client;
62
+ this.objects = protocolSDK.objects;
63
+ this.oftObjectId = oftObjectId;
64
+ this.oappObjectId = oappObjectId;
65
+ this.adminCapId = adminCapId;
66
+ this.coinType = coinType;
67
+ }
68
+ /**
69
+ * Updates the associated OApp object ID
70
+ * @param oappObjectId - The new OApp object ID
71
+ */
72
+ setOappObjectId(oappObjectId) {
73
+ this.oappObjectId = oappObjectId;
74
+ }
75
+ // ==========================================
76
+ // INITIALIZATION FUNCTIONS
77
+ // ==========================================
78
+ // These functions are used to initialize OFT instances from OFTCreationTicket
79
+ /**
80
+ * Initialize an OFT instance with a treasury capability
81
+ * Creates a new OFT that mints its own tokens
82
+ * @param tx - The transaction to add the move call to
83
+ * @param coinType - The Iota coin type string (e.g., "0x123::mycoin::MYCOIN")
84
+ * @param ticket - The OFTCreationTicket object ID or TransactionArgument
85
+ * @param oapp - The OApp object ID or TransactionArgument
86
+ * @param treasury - The TreasuryCap object ID or TransactionArgument for the coin type
87
+ * @param metadata - The CoinMetadata object ID or TransactionArgument for the coin type
88
+ * @param sharedDecimals - Number of decimals to use for cross-chain operations
89
+ * @returns TransactionResult array containing [AdminCap, MigrationCap] - MigrationCap must be transferred or stored
90
+ */
91
+ initOftMoveCall(tx, coinType, ticket, oapp, treasury, metadata, sharedDecimals) {
92
+ return tx.moveCall({
93
+ target: `${this.oftCallCapId}::${OFT_IMPL_MODULE_NAME}::init_oft`,
94
+ typeArguments: [
95
+ coinType
96
+ ],
97
+ arguments: [
98
+ asObject(tx, ticket),
99
+ asObject(tx, oapp),
100
+ asObject(tx, treasury),
101
+ asObject(tx, metadata),
102
+ asU8(tx, sharedDecimals)
103
+ ]
104
+ });
105
+ }
106
+ /**
107
+ * Initialize an OFT adapter instance
108
+ * Creates an OFT adapter that wraps an existing coin type
109
+ * @param tx - The transaction to add the move call to
110
+ * @param coinType - The Iota coin type string (e.g., "0x123::mycoin::MYCOIN")
111
+ * @param ticket - The OFTCreationTicket object ID or TransactionArgument
112
+ * @param oapp - The OApp object ID or TransactionArgument
113
+ * @param metadata - The CoinMetadata object ID or TransactionArgument for the coin type
114
+ * @param sharedDecimals - Number of decimals to use for cross-chain operations
115
+ * @returns TransactionResult array containing [AdminCap, MigrationCap] - MigrationCap must be transferred or stored
116
+ */
117
+ initOftAdapterMoveCall(tx, coinType, ticket, oapp, metadata, sharedDecimals) {
118
+ return tx.moveCall({
119
+ target: `${this.oftCallCapId}::${OFT_IMPL_MODULE_NAME}::init_oft_adapter`,
120
+ typeArguments: [
121
+ coinType
122
+ ],
123
+ arguments: [
124
+ asObject(tx, ticket),
125
+ asObject(tx, oapp),
126
+ asObject(tx, metadata),
127
+ asU8(tx, sharedDecimals)
128
+ ]
129
+ });
130
+ }
131
+ // ==========================================
132
+ // ADMIN FUNCTIONS
133
+ // ==========================================
134
+ // These functions require admin privileges and are used for OFT configuration
135
+ // and management. The admin capability is automatically retrieved from the OFT instance.
136
+ /**
137
+ * Get LayerZero receive information for OFT registration
138
+ *
139
+ * This function prepares the necessary metadata for registering an OFT
140
+ * with the LayerZero endpoint, enabling it to receive cross-chain messages.
141
+ *
142
+ * @param tx - The transaction to add the move call to
143
+ * @param composerManager - The composer manager object ID for routing compose transfers
144
+ * @returns TransactionResult containing serialized execution metadata for endpoint registration
145
+ */
146
+ async lzReceiveInfoMoveCall(tx, composerManager) {
147
+ return tx.moveCall({
148
+ target: await this.#target("lz_receive_info", OFT_PTB_BUILDER_MODULE_NAME),
149
+ typeArguments: [
150
+ await this.#coinType()
151
+ ],
152
+ arguments: [
153
+ tx.object(await this.#oftObjectId()),
154
+ tx.object(this.objects.endpointV2),
155
+ asObject(tx, composerManager),
156
+ tx.object.clock()
157
+ ]
158
+ });
159
+ }
160
+ /**
161
+ * Register OFT as an OApp with LayerZero endpoint
162
+ * @param tx - The transaction to add the move call to
163
+ * @param coinType - The Iota coin type string (e.g., "0x123::mycoin::MYCOIN")
164
+ * @param oftObjectId - The OFT object ID
165
+ * @param oappObjectId - The OApp object ID
166
+ * @param composerManager - The composer manager object ID or TransactionArgument
167
+ * @param lzReceiveInfo - Optional LayerZero receive info as Uint8Array or TransactionArgument
168
+ */
169
+ async registerOAppMoveCall(tx, coinType, oftObjectId, oappObjectId, composerManager, lzReceiveInfo) {
170
+ const adminCapId = await executeSimulate(this.client, (tx2) => {
171
+ tx2.moveCall({
172
+ target: `${this.oftCallCapId}::${MODULE_NAME}::admin_cap`,
173
+ typeArguments: [
174
+ coinType
175
+ ],
176
+ arguments: [
177
+ tx2.object(oftObjectId)
178
+ ]
179
+ });
180
+ }, (result) => bcs.Address.parse(result[0].value));
181
+ if (lzReceiveInfo === void 0) {
182
+ lzReceiveInfo = tx.moveCall({
183
+ target: `${this.oftCallCapId}::${OFT_PTB_BUILDER_MODULE_NAME}::lz_receive_info`,
184
+ typeArguments: [
185
+ coinType
186
+ ],
187
+ arguments: [
188
+ tx.object(oftObjectId),
189
+ tx.object(this.objects.endpointV2),
190
+ asObject(tx, composerManager),
191
+ tx.object.clock()
192
+ ]
193
+ });
194
+ }
195
+ tx.moveCall({
196
+ target: `${this.oftCallCapId}::${MODULE_NAME}::register_oapp`,
197
+ typeArguments: [
198
+ coinType
199
+ ],
200
+ arguments: [
201
+ tx.object(oftObjectId),
202
+ tx.object(oappObjectId),
203
+ tx.object(adminCapId),
204
+ tx.object(this.objects.endpointV2),
205
+ asBytes(tx, lzReceiveInfo)
206
+ ]
207
+ });
208
+ }
209
+ /**
210
+ * Set pause state for OFT operations
211
+ * @param tx - The transaction to add the move call to
212
+ * @param pause - Whether to pause or unpause operations
213
+ */
214
+ async setPauseMoveCall(tx, pause) {
215
+ tx.moveCall({
216
+ target: await this.#target("set_pause"),
217
+ typeArguments: [
218
+ await this.#coinType()
219
+ ],
220
+ arguments: [
221
+ tx.object(await this.#oftObjectId()),
222
+ tx.object(await this.#adminCapId()),
223
+ asBool(tx, pause)
224
+ ]
225
+ });
226
+ }
227
+ // ==========================================
228
+ // FEE MANAGEMENT ADMIN FUNCTIONS
229
+ // ==========================================
230
+ // Configure fee collection and distribution for OFT transfers
231
+ /**
232
+ * Set fee deposit address for OFT fees
233
+ * @param tx - The transaction to add the move call to
234
+ * @param feeDepositAddress - The new fee deposit address
235
+ */
236
+ async setFeeDepositAddressMoveCall(tx, feeDepositAddress) {
237
+ tx.moveCall({
238
+ target: await this.#target("set_fee_deposit_address"),
239
+ typeArguments: [
240
+ await this.#coinType()
241
+ ],
242
+ arguments: [
243
+ tx.object(await this.#oftObjectId()),
244
+ tx.object(await this.#adminCapId()),
245
+ asAddress(tx, feeDepositAddress)
246
+ ]
247
+ });
248
+ }
249
+ /**
250
+ * Set default fee basis points for OFT transfers
251
+ * @param tx - The transaction to add the move call to
252
+ * @param feeBps - Default fee rate in basis points (0-10,000, where 10,000 = 100%)
253
+ */
254
+ async setDefaultFeeBpsMoveCall(tx, feeBps) {
255
+ tx.moveCall({
256
+ target: await this.#target("set_default_fee_bps"),
257
+ typeArguments: [
258
+ await this.#coinType()
259
+ ],
260
+ arguments: [
261
+ tx.object(await this.#oftObjectId()),
262
+ tx.object(await this.#adminCapId()),
263
+ asU64(tx, feeBps)
264
+ ]
265
+ });
266
+ }
267
+ /**
268
+ * Set fee basis points for a specific destination chain
269
+ * @param tx - The transaction to add the move call to
270
+ * @param dstEid - Destination endpoint ID
271
+ * @param feeBps - Fee rate in basis points (0-10,000, where 10,000 = 100%)
272
+ */
273
+ async setFeeBpsMoveCall(tx, dstEid, feeBps) {
274
+ tx.moveCall({
275
+ target: await this.#target("set_fee_bps"),
276
+ typeArguments: [
277
+ await this.#coinType()
278
+ ],
279
+ arguments: [
280
+ tx.object(await this.#oftObjectId()),
281
+ tx.object(await this.#adminCapId()),
282
+ asU32(tx, dstEid),
283
+ asU64(tx, feeBps)
284
+ ]
285
+ });
286
+ }
287
+ /**
288
+ * Removes the fee rate for a specific destination chain
289
+ * @param tx - The transaction to add the move call to
290
+ * @param dstEid - Destination endpoint ID
291
+ */
292
+ async unsetFeeBpsMoveCall(tx, dstEid) {
293
+ tx.moveCall({
294
+ target: await this.#target("unset_fee_bps"),
295
+ typeArguments: [
296
+ await this.#coinType()
297
+ ],
298
+ arguments: [
299
+ tx.object(await this.#oftObjectId()),
300
+ tx.object(await this.#adminCapId()),
301
+ asU32(tx, dstEid)
302
+ ]
303
+ });
304
+ }
305
+ // ==========================================
306
+ // MIGRATION ADMIN FUNCTIONS
307
+ // ==========================================
308
+ // Handle OFT migration to new contracts
309
+ /**
310
+ * Migrate OFT instance to a new contract
311
+ * @param tx - The transaction to add the move call to
312
+ * @param migrationCap - Migration capability object ID or transaction argument
313
+ * @returns TransactionResult containing the migration ticket
314
+ */
315
+ async migrateMoveCall(tx, migrationCap) {
316
+ return tx.moveCall({
317
+ target: await this.#target("migrate"),
318
+ typeArguments: [
319
+ await this.#coinType()
320
+ ],
321
+ arguments: [
322
+ tx.object(await this.#oftObjectId()),
323
+ asObject(tx, migrationCap)
324
+ ]
325
+ });
326
+ }
327
+ // ==========================================
328
+ // RATE LIMITER ADMIN FUNCTIONS
329
+ // ==========================================
330
+ // Configure transfer rate limits for security and compliance
331
+ /**
332
+ * Set rate limit for OFT transfers
333
+ * @param tx - The transaction to add the move call to
334
+ * @param eid - Endpoint ID
335
+ * @param inbound - Whether this is for inbound or outbound transfers
336
+ * @param rateLimit - Rate limit amount
337
+ * @param windowSeconds - Time window in seconds
338
+ */
339
+ async setRateLimitMoveCall(tx, eid, inbound, rateLimit, windowSeconds) {
340
+ tx.moveCall({
341
+ target: await this.#target("set_rate_limit"),
342
+ typeArguments: [
343
+ await this.#coinType()
344
+ ],
345
+ arguments: [
346
+ tx.object(await this.#oftObjectId()),
347
+ tx.object(await this.#adminCapId()),
348
+ asU32(tx, eid),
349
+ asBool(tx, inbound),
350
+ asU64(tx, rateLimit),
351
+ asU64(tx, windowSeconds),
352
+ tx.object.clock()
353
+ ]
354
+ });
355
+ }
356
+ /**
357
+ * Remove rate limit for OFT transfers
358
+ * @param tx - The transaction to add the move call to
359
+ * @param eid - Endpoint ID
360
+ * @param inbound - Whether this is for inbound or outbound transfers
361
+ */
362
+ async unsetRateLimitMoveCall(tx, eid, inbound) {
363
+ tx.moveCall({
364
+ target: await this.#target("unset_rate_limit"),
365
+ typeArguments: [
366
+ await this.#coinType()
367
+ ],
368
+ arguments: [
369
+ tx.object(await this.#oftObjectId()),
370
+ tx.object(await this.#adminCapId()),
371
+ asU32(tx, eid),
372
+ asBool(tx, inbound)
373
+ ]
374
+ });
375
+ }
376
+ // ==========================================
377
+ // CORE FUNCTIONS
378
+ // ==========================================
379
+ // Primary OFT operations for token transfers and coin management
380
+ /**
381
+ * Splits specified amount of coins from user's wallet
382
+ * @param tx - The transaction to add the move call to
383
+ * @param owner - Address of the user whose coins to split
384
+ * @param amount - Amount of coins to split (in smallest units)
385
+ * @param limit - Maximum total number of coins to collect across all pages (default: 200)
386
+ * @param pageSize - Maximum number of coins to fetch per page (default: 50)
387
+ * @returns Promise resolving to split coin as TransactionResult
388
+ * @throws Error if insufficient coins balance or no coins found
389
+ */
390
+ async splitCoinMoveCall(tx, owner, amount, limit = 200, pageSize = 50) {
391
+ return this.protocolSDK.getUtils().splitCoinMoveCall(tx, await this.#coinType(), owner, amount, limit, pageSize);
392
+ }
393
+ /**
394
+ * Send OFT tokens to destination chain
395
+ * @param tx - The transaction to add the move call to
396
+ * @param sender - Sender address for ZRO token operations
397
+ * @param sendParam - Send parameters including destination and amounts
398
+ * @param coinProvided - Coin object ID or transaction result to send
399
+ * @param nativeFee - Native token fee amount
400
+ * @param zroFee - ZRO token fee amount
401
+ * @param refundAddress - Address for fee refunds
402
+ * @param validators - Optional PTB validators for transaction validation
403
+ * @param maxSimulationTimes - Optional maximum number of simulation attempts
404
+ * @returns Promise<void> - Completes when the send operation is processed
405
+ */
406
+ async sendMoveCall(tx, sender, sendParam, coinProvided, nativeFee, zroFee, refundAddress, validators, maxSimulationTimes) {
407
+ const sendParamArg = isTransactionArgument(sendParam) ? sendParam : await this.#buildSendParam(tx, sendParam);
408
+ const txSender = await this.txSenderMoveCall(tx);
409
+ const addressArg = isTransactionArgument(refundAddress) ? refundAddress : tx.pure.option("address", refundAddress);
410
+ const transactionResult = tx.moveCall({
411
+ target: await this.#target("send"),
412
+ typeArguments: [
413
+ await this.#coinType()
414
+ ],
415
+ arguments: [
416
+ tx.object(await this.#oftObjectId()),
417
+ tx.object(await this.#oappObjectId()),
418
+ txSender,
419
+ sendParamArg,
420
+ asObject(tx, coinProvided),
421
+ asArgWithTx(tx, nativeFee, (tx2, val) => tx2.splitCoins(tx2.gas, [
422
+ asU64(tx2, val)
423
+ ])[0]),
424
+ await asArgWithTxAsync(tx, zroFee, async (tx2, val) => this.protocolSDK.getZro().splitOptionZroTokenMoveCall(tx2, sender, val)),
425
+ addressArg,
426
+ tx.object.clock()
427
+ ]
428
+ });
429
+ const endpointCall = transactionResult[0];
430
+ const oftSendContext = transactionResult[1];
431
+ await this.protocolSDK.getEndpoint().populateSendTransaction(tx, endpointCall, sender, validators, maxSimulationTimes);
432
+ const confirmSendResult = tx.moveCall({
433
+ target: await this.#target("confirm_send"),
434
+ typeArguments: [
435
+ await this.#coinType()
436
+ ],
437
+ arguments: [
438
+ tx.object(await this.#oftObjectId()),
439
+ tx.object(await this.#oappObjectId()),
440
+ txSender,
441
+ endpointCall,
442
+ oftSendContext
443
+ ]
444
+ });
445
+ const nativeCoin = confirmSendResult[2];
446
+ const zroCoin = confirmSendResult[3];
447
+ tx.moveCall({
448
+ target: "0x1::option::destroy_none",
449
+ arguments: [
450
+ nativeCoin
451
+ ],
452
+ typeArguments: [
453
+ `0x2::coin::Coin<0x2::iota::IOTA>`
454
+ ]
455
+ });
456
+ tx.moveCall({
457
+ target: "0x1::option::destroy_none",
458
+ arguments: [
459
+ zroCoin
460
+ ],
461
+ typeArguments: [
462
+ `0x2::coin::Coin<${this.protocolSDK.getZro().zroType}>`
463
+ ]
464
+ });
465
+ }
466
+ /**
467
+ * Process inbound cross-chain token transfers
468
+ * @param tx - The transaction to add the move call to
469
+ * @param call - LayerZero receive call containing the verified cross-chain message
470
+ * @returns TransactionResult containing the processed transfer
471
+ */
472
+ async lzReceiveMoveCall(tx, call) {
473
+ return tx.moveCall({
474
+ target: await this.#target("lz_receive"),
475
+ typeArguments: [
476
+ await this.#coinType()
477
+ ],
478
+ arguments: [
479
+ tx.object(await this.#oftObjectId()),
480
+ tx.object(await this.#oappObjectId()),
481
+ asObject(tx, call),
482
+ tx.object.clock()
483
+ ]
484
+ });
485
+ }
486
+ /**
487
+ * Process inbound cross-chain token transfers with compose functionality
488
+ * @param tx - The transaction to add the move call to
489
+ * @param composeQueue - The composer's message queue for sequencing operations
490
+ * @param composerManager - Manager managing token deposits for composers
491
+ * @param call - LayerZero receive call containing the verified cross-chain message
492
+ * @returns TransactionResult containing the processed transfer
493
+ */
494
+ async lzReceiveWithComposeMoveCall(tx, composeQueue, composerManager, call) {
495
+ return tx.moveCall({
496
+ target: await this.#target("lz_receive_with_compose"),
497
+ typeArguments: [
498
+ await this.#coinType()
499
+ ],
500
+ arguments: [
501
+ tx.object(await this.#oftObjectId()),
502
+ tx.object(await this.#oappObjectId()),
503
+ asObject(tx, composeQueue),
504
+ asObject(tx, composerManager),
505
+ asObject(tx, call),
506
+ tx.object.clock()
507
+ ]
508
+ });
509
+ }
510
+ /**
511
+ * Confirms and extracts results from a quote operation
512
+ * @param tx - The transaction to add the move call to
513
+ * @param call - Completed Call object from quote_send() execution
514
+ * @returns TransactionResult containing the messaging fee
515
+ */
516
+ async confirmQuoteSendMoveCall(tx, call) {
517
+ return tx.moveCall({
518
+ target: await this.#target("confirm_quote_send"),
519
+ typeArguments: [
520
+ await this.#coinType()
521
+ ],
522
+ arguments: [
523
+ tx.object(await this.#oftObjectId()),
524
+ tx.object(await this.#oappObjectId()),
525
+ asObject(tx, call)
526
+ ]
527
+ });
528
+ }
529
+ // ==========================================
530
+ // QUOTE FUNCTIONS
531
+ // ==========================================
532
+ // Calculate fees, limits, and receipts before executing operations
533
+ /**
534
+ * Quote OFT sending operation with detailed fee breakdown
535
+ * @param sendParam - Send parameters for the OFT operation
536
+ * @returns Promise with limit, fee details, and receipt information
537
+ */
538
+ async quoteOft(sendParam) {
539
+ return executeSimulate(this.client, async (tx) => {
540
+ const sendParamArg = isTransactionArgument(sendParam) ? sendParam : await this.#buildSendParam(tx, sendParam);
541
+ tx.moveCall({
542
+ target: await this.#target("quote_oft"),
543
+ typeArguments: [
544
+ await this.#coinType()
545
+ ],
546
+ arguments: [
547
+ tx.object(await this.#oftObjectId()),
548
+ sendParamArg,
549
+ tx.object.clock()
550
+ ]
551
+ });
552
+ }, (result) => {
553
+ return {
554
+ limit: parseOFTLimit(result[0].value),
555
+ feeDetails: parseOFTFeeDetails(result[1].value),
556
+ receipt: parseOFTReceipt(result[2].value)
557
+ };
558
+ });
559
+ }
560
+ /**
561
+ * Quote messaging fees for OFT sending
562
+ * @param sender - Sender address
563
+ * @param sendParam - Send parameters for the OFT operation
564
+ * @param payInZro - Whether to pay in ZRO tokens
565
+ * @param validators - Optional PTB validators for transaction validation
566
+ * @param maxSimulationTimes - Optional maximum number of simulation attempts
567
+ * @returns Promise<MessagingFee> - The calculated messaging fees
568
+ */
569
+ async quoteSend(sender, sendParam, payInZro, validators, maxSimulationTimes) {
570
+ const tx = new Transaction();
571
+ const sendParamArg = isTransactionArgument(sendParam) ? sendParam : await this.#buildSendParam(tx, sendParam);
572
+ const quoteCall = tx.moveCall({
573
+ target: await this.#target("quote_send"),
574
+ typeArguments: [
575
+ await this.#coinType()
576
+ ],
577
+ arguments: [
578
+ tx.object(await this.#oftObjectId()),
579
+ tx.object(await this.#oappObjectId()),
580
+ asAddress(tx, sender),
581
+ sendParamArg,
582
+ asBool(tx, payInZro)
583
+ ]
584
+ });
585
+ return this.protocolSDK.getEndpoint().quote(tx, quoteCall, sender, validators, maxSimulationTimes);
586
+ }
587
+ // ==========================================
588
+ // VIEW FUNCTIONS
589
+ // ==========================================
590
+ // Read-only functions to query OFT state and configuration
591
+ /**
592
+ * Get the upgrade version of this OFT instance
593
+ * @param tx - The transaction to add the move call to
594
+ * @returns Transaction result containing the upgrade version
595
+ */
596
+ async upgradeVersionMoveCall(tx) {
597
+ return tx.moveCall({
598
+ target: await this.#target("upgrade_version"),
599
+ typeArguments: [
600
+ await this.#coinType()
601
+ ],
602
+ arguments: [
603
+ tx.object(await this.#oftObjectId())
604
+ ]
605
+ });
606
+ }
607
+ /**
608
+ * Get the upgrade version of this OFT instance
609
+ * @returns Promise<bigint> - The upgrade version
610
+ */
611
+ async upgradeVersion() {
612
+ return executeSimulate(this.client, async (tx) => {
613
+ await this.upgradeVersionMoveCall(tx);
614
+ }, (result) => BigInt(bcs.U64.parse(result[0].value)));
615
+ }
616
+ /**
617
+ * Get the associated OApp object address
618
+ * @param tx - The transaction to add the move call to
619
+ * @returns Transaction result containing the OApp object address
620
+ */
621
+ async oappObjectMoveCall(tx) {
622
+ return tx.moveCall({
623
+ target: await this.#target("oapp_object"),
624
+ typeArguments: [
625
+ await this.#coinType()
626
+ ],
627
+ arguments: [
628
+ tx.object(await this.#oftObjectId())
629
+ ]
630
+ });
631
+ }
632
+ /**
633
+ * Get the associated OApp object address
634
+ * @returns Promise<string> - The OApp object address
635
+ */
636
+ async oappObject() {
637
+ return executeSimulate(this.client, async (tx) => {
638
+ await this.oappObjectMoveCall(tx);
639
+ }, (result) => bcs.Address.parse(result[0].value));
640
+ }
641
+ /**
642
+ * Get OFT version information
643
+ * @param tx - The transaction to add the move call to
644
+ * @returns Transaction result containing version information
645
+ */
646
+ async oftVersionMoveCall(tx) {
647
+ return tx.moveCall({
648
+ target: await this.#target("oft_version"),
649
+ typeArguments: [
650
+ await this.#coinType()
651
+ ],
652
+ arguments: [
653
+ tx.object(await this.#oftObjectId())
654
+ ]
655
+ });
656
+ }
657
+ /**
658
+ * Get OFT version information
659
+ * @returns Promise<{ major: number; minor: number }> - The OFT version
660
+ */
661
+ async oftVersion() {
662
+ return executeSimulate(this.client, async (tx) => {
663
+ await this.oftVersionMoveCall(tx);
664
+ }, (result) => {
665
+ const major = Number(bcs.U64.parse(result[0].value));
666
+ const minor = Number(bcs.U64.parse(result[1].value));
667
+ return {
668
+ major,
669
+ minor
670
+ };
671
+ });
672
+ }
673
+ /**
674
+ * Get the OFT capability ID
675
+ * @param tx - The transaction to add the move call to
676
+ * @returns Transaction result containing the OFT capability ID
677
+ */
678
+ async oftCapIdMoveCall(tx) {
679
+ return tx.moveCall({
680
+ target: await this.#target("oft_cap_id"),
681
+ typeArguments: [
682
+ await this.#coinType()
683
+ ],
684
+ arguments: [
685
+ tx.object(await this.#oftObjectId())
686
+ ]
687
+ });
688
+ }
689
+ /**
690
+ * Get the OFT capability ID
691
+ * @returns Promise<string> - The OFT capability ID
692
+ */
693
+ async oftCapId() {
694
+ return executeSimulate(this.client, async (tx) => {
695
+ await this.oftCapIdMoveCall(tx);
696
+ }, (result) => bcs.Address.parse(result[0].value));
697
+ }
698
+ /**
699
+ * Get the migration capability address for this OFT
700
+ * @param tx - The transaction to add the move call to
701
+ * @returns Transaction result containing the migration capability address
702
+ */
703
+ async migrationCapMoveCall(tx) {
704
+ return tx.moveCall({
705
+ target: await this.#target("migration_cap"),
706
+ typeArguments: [
707
+ await this.#coinType()
708
+ ],
709
+ arguments: [
710
+ tx.object(await this.#oftObjectId())
711
+ ]
712
+ });
713
+ }
714
+ /**
715
+ * Get the migration capability address for this OFT
716
+ * @returns Promise<string> - The migration capability address
717
+ */
718
+ async migrationCap() {
719
+ return executeSimulate(this.client, async (tx) => {
720
+ await this.migrationCapMoveCall(tx);
721
+ }, (result) => bcs.Address.parse(result[0].value));
722
+ }
723
+ async messagingChannel() {
724
+ return executeSimulate(this.client, async (tx) => {
725
+ const oftCapId = await this.oftCapIdMoveCall(tx);
726
+ this.protocolSDK.getEndpoint().getMessagingChannelMoveCall(tx, oftCapId);
727
+ }, (result) => bcs.Address.parse(result[0].value));
728
+ }
729
+ /**
730
+ * Get coin metadata address
731
+ * @param tx - The transaction to add the move call to
732
+ * @returns Transaction result containing coin metadata address
733
+ */
734
+ async coinMetadataMoveCall(tx) {
735
+ return tx.moveCall({
736
+ target: await this.#target("coin_metadata"),
737
+ typeArguments: [
738
+ await this.#coinType()
739
+ ],
740
+ arguments: [
741
+ tx.object(await this.#oftObjectId())
742
+ ]
743
+ });
744
+ }
745
+ /**
746
+ * Get coin metadata address
747
+ * @returns Promise<string> - The coin metadata address
748
+ */
749
+ async coinMetadata() {
750
+ return executeSimulate(this.client, async (tx) => {
751
+ await this.coinMetadataMoveCall(tx);
752
+ }, (result) => bcs.Address.parse(result[0].value));
753
+ }
754
+ /**
755
+ * Get OFT admin capability address
756
+ * @param tx - The transaction to add the move call to
757
+ * @returns Transaction result containing the admin capability address
758
+ */
759
+ async adminCapMoveCall(tx) {
760
+ return tx.moveCall({
761
+ target: await this.#target("admin_cap"),
762
+ typeArguments: [
763
+ await this.#coinType()
764
+ ],
765
+ arguments: [
766
+ tx.object(await this.#oftObjectId())
767
+ ]
768
+ });
769
+ }
770
+ /**
771
+ * Get OFT admin capability address
772
+ * @returns Promise<string> - The admin capability address
773
+ */
774
+ async adminCap() {
775
+ return executeSimulate(this.client, async (tx) => {
776
+ await this.adminCapMoveCall(tx);
777
+ }, (result) => bcs.Address.parse(result[0].value));
778
+ }
779
+ /**
780
+ * Get shared decimals for cross-chain compatibility
781
+ * @param tx - The transaction to add the move call to
782
+ * @returns Transaction result containing shared decimals
783
+ */
784
+ async sharedDecimalsMoveCall(tx) {
785
+ return tx.moveCall({
786
+ target: await this.#target("shared_decimals"),
787
+ typeArguments: [
788
+ await this.#coinType()
789
+ ],
790
+ arguments: [
791
+ tx.object(await this.#oftObjectId())
792
+ ]
793
+ });
794
+ }
795
+ /**
796
+ * Get shared decimals for cross-chain compatibility
797
+ * @returns Promise<number> - The shared decimal precision
798
+ */
799
+ async sharedDecimals() {
800
+ return executeSimulate(this.client, async (tx) => {
801
+ await this.sharedDecimalsMoveCall(tx);
802
+ }, (result) => bcs.U8.parse(result[0].value));
803
+ }
804
+ /**
805
+ * Get the decimal conversion rate for this OFT
806
+ * @param tx - The transaction to add the move call to
807
+ * @returns Transaction result containing the decimal conversion rate
808
+ */
809
+ async decimalConversionRateMoveCall(tx) {
810
+ return tx.moveCall({
811
+ target: await this.#target("decimal_conversion_rate"),
812
+ typeArguments: [
813
+ await this.#coinType()
814
+ ],
815
+ arguments: [
816
+ tx.object(await this.#oftObjectId())
817
+ ]
818
+ });
819
+ }
820
+ /**
821
+ * Get the decimal conversion rate for this OFT
822
+ * @returns Promise<bigint> - The decimal conversion rate multiplier
823
+ */
824
+ async decimalConversionRate() {
825
+ return executeSimulate(this.client, async (tx) => {
826
+ await this.decimalConversionRateMoveCall(tx);
827
+ }, (result) => BigInt(bcs.U64.parse(result[0].value)));
828
+ }
829
+ /**
830
+ * Check if OFT is paused
831
+ * @param tx - The transaction to add the move call to
832
+ * @returns Transaction result containing the paused status
833
+ */
834
+ async isPausedMoveCall(tx) {
835
+ return tx.moveCall({
836
+ target: await this.#target("is_paused"),
837
+ typeArguments: [
838
+ await this.#coinType()
839
+ ],
840
+ arguments: [
841
+ tx.object(await this.#oftObjectId())
842
+ ]
843
+ });
844
+ }
845
+ /**
846
+ * Check if OFT is paused
847
+ * @returns Promise<boolean> - True if OFT is paused
848
+ */
849
+ async isPaused() {
850
+ return executeSimulate(this.client, async (tx) => {
851
+ await this.isPausedMoveCall(tx);
852
+ }, (result) => bcs.Bool.parse(result[0].value));
853
+ }
854
+ /**
855
+ * Check if this OFT is an adapter (wraps existing token)
856
+ * @param tx - The transaction to add the move call to
857
+ * @returns Transaction result containing the adapter status
858
+ */
859
+ async isAdapterMoveCall(tx) {
860
+ return tx.moveCall({
861
+ target: await this.#target("is_adapter"),
862
+ typeArguments: [
863
+ await this.#coinType()
864
+ ],
865
+ arguments: [
866
+ tx.object(await this.#oftObjectId())
867
+ ]
868
+ });
869
+ }
870
+ /**
871
+ * Check if this OFT is an adapter (wraps existing token)
872
+ * @returns Promise<boolean> - True if this is an OFT adapter
873
+ */
874
+ async isAdapter() {
875
+ return executeSimulate(this.client, async (tx) => {
876
+ await this.isAdapterMoveCall(tx);
877
+ }, (result) => bcs.Bool.parse(result[0].value));
878
+ }
879
+ /**
880
+ * Decode OFTInfoV1 from encoded bytes
881
+ * @param tx - The transaction to add the move call to
882
+ * @param encodedBytes - The encoded OFTInfoV1 bytes to decode
883
+ * @returns Transaction result containing the decoded OFTInfoV1
884
+ */
885
+ decodeOftInfoV1MoveCall(tx, encodedBytes) {
886
+ return tx.moveCall({
887
+ target: `${this.oftCallCapId}::oft_info_v1::decode`,
888
+ arguments: [
889
+ asBytes(tx, encodedBytes)
890
+ ]
891
+ });
892
+ }
893
+ /**
894
+ * Decode OFTInfoV1 from encoded bytes
895
+ * @param encodedBytes - The encoded OFTInfoV1 bytes to decode
896
+ * @returns Promise<OFTInfoV1> - The decoded OFTInfoV1 structure
897
+ */
898
+ async decodeOftInfoV1(encodedBytes) {
899
+ return executeSimulate(this.client, (tx) => {
900
+ this.decodeOftInfoV1MoveCall(tx, encodedBytes);
901
+ }, (result) => parseOFTInfoV1(result[0].value));
902
+ }
903
+ // ==========================================
904
+ // FEE VIEW FUNCTIONS
905
+ // ==========================================
906
+ // Query current fee configuration and settings
907
+ /**
908
+ * Check if the OFT has a fee rate greater than 0 for the specified destination
909
+ * @param tx - The transaction to add the move call to
910
+ * @param dstEid - Destination endpoint ID
911
+ * @returns Transaction result containing whether fee exists
912
+ */
913
+ async hasOftFeeMoveCall(tx, dstEid) {
914
+ return tx.moveCall({
915
+ target: await this.#target("has_oft_fee"),
916
+ typeArguments: [
917
+ await this.#coinType()
918
+ ],
919
+ arguments: [
920
+ tx.object(await this.#oftObjectId()),
921
+ asU32(tx, dstEid)
922
+ ]
923
+ });
924
+ }
925
+ /**
926
+ * Check if the OFT has a fee rate greater than 0 for the specified destination
927
+ * @param dstEid - Destination endpoint ID
928
+ * @returns Promise<boolean> - True if fee exists
929
+ */
930
+ async hasOftFee(dstEid) {
931
+ return executeSimulate(this.client, async (tx) => {
932
+ await this.hasOftFeeMoveCall(tx, dstEid);
933
+ }, (result) => bcs.Bool.parse(result[0].value));
934
+ }
935
+ /**
936
+ * Get the effective fee rate for a specific destination chain
937
+ * @param tx - The transaction to add the move call to
938
+ * @param dstEid - Destination endpoint ID
939
+ * @returns Transaction result containing the effective fee basis points
940
+ */
941
+ async effectiveFeeBpsMoveCall(tx, dstEid) {
942
+ return tx.moveCall({
943
+ target: await this.#target("effective_fee_bps"),
944
+ typeArguments: [
945
+ await this.#coinType()
946
+ ],
947
+ arguments: [
948
+ tx.object(await this.#oftObjectId()),
949
+ asU32(tx, dstEid)
950
+ ]
951
+ });
952
+ }
953
+ /**
954
+ * Get the effective fee rate for a specific destination chain
955
+ * @param dstEid - Destination endpoint ID
956
+ * @returns Promise<bigint> - The effective fee in basis points
957
+ */
958
+ async effectiveFeeBps(dstEid) {
959
+ return executeSimulate(this.client, async (tx) => {
960
+ await this.effectiveFeeBpsMoveCall(tx, dstEid);
961
+ }, (result) => BigInt(bcs.U64.parse(result[0].value)));
962
+ }
963
+ /**
964
+ * Get the default fee rate
965
+ * @param tx - The transaction to add the move call to
966
+ * @returns Transaction result containing the default fee basis points
967
+ */
968
+ async defaultFeeBpsMoveCall(tx) {
969
+ return tx.moveCall({
970
+ target: await this.#target("default_fee_bps"),
971
+ typeArguments: [
972
+ await this.#coinType()
973
+ ],
974
+ arguments: [
975
+ tx.object(await this.#oftObjectId())
976
+ ]
977
+ });
978
+ }
979
+ /**
980
+ * Get the default fee rate
981
+ * @returns Promise<bigint> - The default fee in basis points
982
+ */
983
+ async defaultFeeBps() {
984
+ return executeSimulate(this.client, async (tx) => {
985
+ await this.defaultFeeBpsMoveCall(tx);
986
+ }, (result) => BigInt(bcs.U64.parse(result[0].value)));
987
+ }
988
+ /**
989
+ * Get fee basis points for a specific destination chain
990
+ * @param tx - The transaction to add the move call to
991
+ * @param dstEid - Destination endpoint ID
992
+ * @returns Transaction result containing the fee basis points
993
+ */
994
+ async feeBpsMoveCall(tx, dstEid) {
995
+ return tx.moveCall({
996
+ target: await this.#target("fee_bps"),
997
+ typeArguments: [
998
+ await this.#coinType()
999
+ ],
1000
+ arguments: [
1001
+ tx.object(await this.#oftObjectId()),
1002
+ asU32(tx, dstEid)
1003
+ ]
1004
+ });
1005
+ }
1006
+ /**
1007
+ * Get fee basis points for a specific destination chain
1008
+ * @param dstEid - Destination endpoint ID
1009
+ * @returns Promise<bigint> - The fee in basis points
1010
+ */
1011
+ async feeBps(dstEid) {
1012
+ return executeSimulate(this.client, async (tx) => {
1013
+ await this.feeBpsMoveCall(tx, dstEid);
1014
+ }, (result) => BigInt(bcs.U64.parse(result[0].value)));
1015
+ }
1016
+ /**
1017
+ * Get fee deposit address for OFT
1018
+ * @param tx - The transaction to add the move call to
1019
+ * @returns Transaction result containing the fee deposit address
1020
+ */
1021
+ async feeDepositAddressMoveCall(tx) {
1022
+ return tx.moveCall({
1023
+ target: await this.#target("fee_deposit_address"),
1024
+ typeArguments: [
1025
+ await this.#coinType()
1026
+ ],
1027
+ arguments: [
1028
+ tx.object(await this.#oftObjectId())
1029
+ ]
1030
+ });
1031
+ }
1032
+ /**
1033
+ * Get fee deposit address for OFT
1034
+ * @returns Promise<string> - The fee deposit address
1035
+ */
1036
+ async feeDepositAddress() {
1037
+ return executeSimulate(this.client, async (tx) => {
1038
+ await this.feeDepositAddressMoveCall(tx);
1039
+ }, (result) => bcs.Address.parse(result[0].value));
1040
+ }
1041
+ // ==========================================
1042
+ // RATE LIMITER VIEW FUNCTIONS
1043
+ // ==========================================
1044
+ // Query current rate limiting configuration and status
1045
+ /**
1046
+ * Get rate limit configuration for an endpoint
1047
+ * @param tx - The transaction to add the move call to
1048
+ * @param eid - Endpoint ID
1049
+ * @param inbound - Whether this is for inbound or outbound transfers
1050
+ * @returns Transaction result containing rate limit configuration
1051
+ */
1052
+ async rateLimitConfigMoveCall(tx, eid, inbound) {
1053
+ return tx.moveCall({
1054
+ target: await this.#target("rate_limit_config"),
1055
+ typeArguments: [
1056
+ await this.#coinType()
1057
+ ],
1058
+ arguments: [
1059
+ tx.object(await this.#oftObjectId()),
1060
+ asU32(tx, eid),
1061
+ asBool(tx, inbound)
1062
+ ]
1063
+ });
1064
+ }
1065
+ /**
1066
+ * Get rate limit configuration for an endpoint
1067
+ * @param eid - Endpoint ID
1068
+ * @param inbound - Whether this is for inbound or outbound transfers
1069
+ * @returns Promise<{ limit: bigint; windowSeconds: bigint }> - Rate limit configuration
1070
+ */
1071
+ async rateLimitConfig(eid, inbound) {
1072
+ return executeSimulate(this.client, async (tx) => {
1073
+ await this.rateLimitConfigMoveCall(tx, eid, inbound);
1074
+ }, (result) => {
1075
+ const limit = BigInt(bcs.U64.parse(result[0].value));
1076
+ const windowSeconds = BigInt(bcs.U64.parse(result[1].value));
1077
+ return {
1078
+ limit,
1079
+ windowSeconds
1080
+ };
1081
+ });
1082
+ }
1083
+ /**
1084
+ * Get current in-flight amount for rate limiting
1085
+ * @param tx - The transaction to add the move call to
1086
+ * @param eid - Endpoint ID
1087
+ * @param inbound - Whether this is for inbound or outbound transfers
1088
+ * @returns Transaction result containing in-flight amount
1089
+ */
1090
+ async rateLimitInFlightMoveCall(tx, eid, inbound) {
1091
+ return tx.moveCall({
1092
+ target: await this.#target("rate_limit_in_flight"),
1093
+ typeArguments: [
1094
+ await this.#coinType()
1095
+ ],
1096
+ arguments: [
1097
+ tx.object(await this.#oftObjectId()),
1098
+ asU32(tx, eid),
1099
+ asBool(tx, inbound),
1100
+ tx.object.clock()
1101
+ ]
1102
+ });
1103
+ }
1104
+ /**
1105
+ * Get current in-flight amount for rate limiting
1106
+ * @param eid - Endpoint ID
1107
+ * @param inbound - Whether this is for inbound or outbound transfers
1108
+ * @returns Promise<bigint> - Current in-flight amount
1109
+ */
1110
+ async rateLimitInFlight(eid, inbound) {
1111
+ return executeSimulate(this.client, async (tx) => {
1112
+ await this.rateLimitInFlightMoveCall(tx, eid, inbound);
1113
+ }, (result) => BigInt(bcs.U64.parse(result[0].value)));
1114
+ }
1115
+ /**
1116
+ * Get rate limit capacity (remaining available amount)
1117
+ * @param tx - The transaction to add the move call to
1118
+ * @param eid - Endpoint ID
1119
+ * @param inbound - Whether this is for inbound or outbound transfers
1120
+ * @returns Transaction result containing rate limit capacity
1121
+ */
1122
+ async rateLimitCapacityMoveCall(tx, eid, inbound) {
1123
+ return tx.moveCall({
1124
+ target: await this.#target("rate_limit_capacity"),
1125
+ typeArguments: [
1126
+ await this.#coinType()
1127
+ ],
1128
+ arguments: [
1129
+ tx.object(await this.#oftObjectId()),
1130
+ asU32(tx, eid),
1131
+ asBool(tx, inbound),
1132
+ tx.object.clock()
1133
+ ]
1134
+ });
1135
+ }
1136
+ /**
1137
+ * Get rate limit capacity (remaining available amount)
1138
+ * @param eid - Endpoint ID
1139
+ * @param inbound - Whether this is for inbound or outbound transfers
1140
+ * @returns Promise<bigint> - Remaining rate limit capacity
1141
+ */
1142
+ async rateLimitCapacity(eid, inbound) {
1143
+ return executeSimulate(this.client, async (tx) => {
1144
+ await this.rateLimitCapacityMoveCall(tx, eid, inbound);
1145
+ }, (result) => BigInt(bcs.U64.parse(result[0].value)));
1146
+ }
1147
+ // ==========================================
1148
+ // OFT SENDER
1149
+ // ==========================================
1150
+ /**
1151
+ * Create a transaction sender object for OFT operations
1152
+ * @param tx - The transaction to add the move call to
1153
+ * @returns Transaction result containing the transaction sender object
1154
+ */
1155
+ async txSenderMoveCall(tx) {
1156
+ return tx.moveCall({
1157
+ target: await this.#target("tx_sender", OFT_SENDER_MODULE_NAME)
1158
+ });
1159
+ }
1160
+ // ==========================================
1161
+ // PRIVATE HELPER FUNCTIONS
1162
+ // ==========================================
1163
+ // Internal utility functions for OFT operations
1164
+ /**
1165
+ * Build SendParam struct for OFT operations
1166
+ * @param tx - The transaction to add the move call to
1167
+ * @param param - Send parameters to build
1168
+ * @returns Transaction result containing the SendParam struct
1169
+ * @private
1170
+ */
1171
+ async #buildSendParam(tx, param) {
1172
+ return tx.moveCall({
1173
+ target: await this.#target("create", "send_param"),
1174
+ arguments: [
1175
+ asU32(tx, param.dstEid),
1176
+ asBytes32(tx, param.to, this.protocolSDK.getUtils()),
1177
+ asU64(tx, param.amountLd),
1178
+ asU64(tx, param.minAmountLd),
1179
+ asBytes(tx, param.extraOptions),
1180
+ asBytes(tx, param.composeMsg),
1181
+ asBytes(tx, param.oftCmd)
1182
+ ]
1183
+ });
1184
+ }
1185
+ /**
1186
+ * Generate the full target path for move calls
1187
+ * @param name - The function name to call
1188
+ * @param module_name - The module name (defaults to 'oft')
1189
+ * @returns The full module path for the move call
1190
+ * @private
1191
+ */
1192
+ async #target(name, module_name = MODULE_NAME) {
1193
+ return `${await this.#oftPackageId()}::${module_name}::${name}`;
1194
+ }
1195
+ /**
1196
+ * Get the OApp object ID, throwing an error if not available
1197
+ * @returns The OApp object ID
1198
+ * @throws Error if OApp object ID was not set
1199
+ * @private
1200
+ */
1201
+ async #oappObjectId() {
1202
+ if (this.oappObjectId === void 0) {
1203
+ const oappSdk = this.protocolSDK.getOApp(this.oftCallCapId);
1204
+ const oappInfo = await oappSdk.getOAppInfoV1();
1205
+ this.oappObjectId = oappInfo.oapp_object;
1206
+ }
1207
+ return this.oappObjectId;
1208
+ }
1209
+ /**
1210
+ * Get the OFT object ID, automatically retrieving it from the OFT info if not cached
1211
+ * @returns The OFT object ID
1212
+ * @throws Error if OFT object ID cannot be retrieved
1213
+ * @private
1214
+ */
1215
+ async #oftObjectId() {
1216
+ if (this.oftObjectId === void 0) {
1217
+ const oftInfo = await this.#OftInfo();
1218
+ this.oftObjectId = oftInfo.oftObject;
1219
+ }
1220
+ return this.oftObjectId;
1221
+ }
1222
+ /**
1223
+ * Get the admin capability ID, automatically retrieving it from the OFT instance if not cached
1224
+ * @returns The admin capability ID
1225
+ * @throws Error if admin capability cannot be retrieved from the OFT instance
1226
+ * @private
1227
+ */
1228
+ async #adminCapId() {
1229
+ if (this.adminCapId === void 0) {
1230
+ this.adminCapId = await this.adminCap();
1231
+ }
1232
+ return this.adminCapId;
1233
+ }
1234
+ /**
1235
+ * Get the coin type, automatically extracting it from the OFT object if not cached
1236
+ * @returns The coin type string (e.g., "0x123::mycoin::MYCOIN")
1237
+ * @throws Error if coin type cannot be extracted from the OFT object
1238
+ * @private
1239
+ */
1240
+ async #coinType() {
1241
+ if (this.coinType === void 0) {
1242
+ const oftInfo = await this.client.getObject({
1243
+ id: await this.#oftObjectId(),
1244
+ options: {
1245
+ showContent: true
1246
+ }
1247
+ });
1248
+ const content = oftInfo.data?.content;
1249
+ if (content?.dataType !== "moveObject" || content.type == null || content.type.length === 0) {
1250
+ throw new Error("Invalid OFT object data or missing type field");
1251
+ }
1252
+ const typeStr = content.type;
1253
+ const angleBracketMatch = typeStr.match(/<([^>]+)>/);
1254
+ const coinType = angleBracketMatch?.[1];
1255
+ if (coinType === void 0 || coinType === "") {
1256
+ throw new Error("Failed to extract coinType from object type");
1257
+ }
1258
+ this.coinType = coinType;
1259
+ }
1260
+ return this.coinType;
1261
+ }
1262
+ /**
1263
+ * Get OApp info, throwing if not set
1264
+ * @returns The OApp info
1265
+ * @throws Error if OApp info is not set
1266
+ * @private
1267
+ */
1268
+ async #OftInfo() {
1269
+ if (!this.oftInfo) {
1270
+ const oappSdk = this.protocolSDK.getOApp(this.oftCallCapId);
1271
+ this.oftInfo = await executeSimulate(this.client, (tx) => {
1272
+ const oappInfo = oappSdk.getOAppInfoV1MoveCall(tx);
1273
+ const extraInfo = oappSdk.getOAppInfoV1ExtraInfoMoveCall(tx, oappInfo);
1274
+ this.decodeOftInfoV1MoveCall(tx, extraInfo);
1275
+ }, (result) => parseOFTInfoV1(result[0].value));
1276
+ }
1277
+ return this.oftInfo;
1278
+ }
1279
+ /**
1280
+ * Get the OFT package ID, automatically retrieving it from the OFT info if not cached
1281
+ * @returns The OFT package ID
1282
+ * @throws Error if OFT package ID cannot be retrieved
1283
+ * @private
1284
+ */
1285
+ async #oftPackageId() {
1286
+ if (this.oftPackageId === void 0) {
1287
+ const oftInfo = await this.#OftInfo();
1288
+ this.oftPackageId = oftInfo.oftPackage;
1289
+ }
1290
+ return this.oftPackageId;
1291
+ }
1292
+ };
1293
+
1294
+ export { OFT, OFTErrorCode };
1295
+ //# sourceMappingURL=LA2Z3PK4.js.map
1296
+ //# sourceMappingURL=LA2Z3PK4.js.map