@layerzerolabs/oft-sui-sdk-v2 0.0.0-stage → 1.2.104

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