@layerzerolabs/lz-sui-oft-sdk-v2 3.0.127 → 3.0.128-sui.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/lz-sui-oft-sdk-v2",
3
- "version": "3.0.127",
3
+ "version": "3.0.128-sui.1",
4
4
  "license": "BUSL-1.1",
5
5
  "exports": {
6
6
  ".": {
@@ -28,16 +28,16 @@
28
28
  "typecheck": "tsc --noEmit"
29
29
  },
30
30
  "dependencies": {
31
- "@layerzerolabs/lz-definitions": "^3.0.128",
32
- "@layerzerolabs/lz-sui-sdk-v2": "^3.0.128",
31
+ "@layerzerolabs/lz-definitions": "^3.0.128-sui.1",
32
+ "@layerzerolabs/lz-sui-sdk-v2": "^3.0.128-sui.1",
33
33
  "@mysten/sui": "^1.33.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@layerzerolabs/lz-foundation": "^3.0.128",
37
- "@layerzerolabs/lz-utilities": "^3.0.128",
38
- "@layerzerolabs/lz-v2-utilities": "^3.0.128",
39
- "@layerzerolabs/tsup-config-next": "^3.0.128",
40
- "@layerzerolabs/typescript-config-next": "^3.0.128",
36
+ "@layerzerolabs/lz-foundation": "^3.0.128-sui.1",
37
+ "@layerzerolabs/lz-utilities": "^3.0.128-sui.1",
38
+ "@layerzerolabs/lz-v2-utilities": "^3.0.128-sui.1",
39
+ "@layerzerolabs/tsup-config-next": "^3.0.128-sui.1",
40
+ "@layerzerolabs/typescript-config-next": "^3.0.128-sui.1",
41
41
  "@types/chai": "^4.3.11",
42
42
  "@types/chai-as-promised": "^7.1.0",
43
43
  "@types/mocha": "^10.0.6",
@@ -17,12 +17,13 @@ import {
17
17
  executeSimulate,
18
18
  isTransactionArgument,
19
19
  } from '@layerzerolabs/lz-sui-sdk-v2'
20
- import type { MessagingFee, ObjectOptions } from '@layerzerolabs/lz-sui-sdk-v2'
20
+ import type { MessagingFee, ObjectOptions, IPTBValidator } from '@layerzerolabs/lz-sui-sdk-v2'
21
21
 
22
22
  import { parseOFTFeeDetails, parseOFTLimit, parseOFTReceipt } from '../bcs/oft'
23
23
  import { OFTFeeDetail, OFTLimit, OFTReceipt, SendParam } from '../types'
24
24
 
25
25
  const MODULE_NAME = 'oft'
26
+ const OFT_SENDER_MODULE_NAME = 'oft_sender'
26
27
 
27
28
  // ==========================================
28
29
  // ERROR CODES
@@ -67,10 +68,8 @@ export const OFTErrorCode = {
67
68
  export class OFT {
68
69
  /** Sui client for blockchain interactions */
69
70
  public readonly client: SuiClient
70
- /** The package ID of the OFT implementation (specific token contract) */
71
- public packageId: string
72
71
  /** The package ID of the core OFT framework (shared OFT functionality) */
73
- public corePackageId: string
72
+ public oftPackageId: string
74
73
  /** LayerZero protocol object references (endpoint, messaging channels, etc.) */
75
74
  private readonly objects: ObjectOptions
76
75
  /** The unique object ID of this OFT instance on Sui */
@@ -86,23 +85,20 @@ export class OFT {
86
85
  * Creates a new OFT instance for interacting with an Omnichain Fungible Token
87
86
  *
88
87
  * @param protocolSDK - The LayerZero protocol SDK instance providing core cross-chain functionality
89
- * @param corePackageId - The package ID of the core OFT framework (shared across all OFT implementations)
90
- * @param packageId - The package ID of the specific OFT token implementation
88
+ * @param oftPackageId - The package ID of the core OFT framework (shared across all OFT implementations)
91
89
  * @param oftObjectId - The unique object ID of this OFT instance
92
90
  * @param coinType - The Sui coin type string (e.g., "0x123::mycoin::MYCOIN")
93
91
  * @param adminCapId - Optional admin capability object ID for privileged operations (required for admin functions)
94
92
  */
95
93
  constructor(
96
94
  protocolSDK: SDK,
97
- corePackageId: string, // the OFT package id
98
- packageId: string, // the Implementation's package id
95
+ oftPackageId: string, // the OFT package id
99
96
  oftObjectId: string,
100
97
  coinType: string,
101
98
  adminCapId?: string
102
99
  ) {
103
100
  this.protocolSDK = protocolSDK
104
- this.packageId = packageId
105
- this.corePackageId = corePackageId
101
+ this.oftPackageId = oftPackageId
106
102
  this.client = protocolSDK.client
107
103
  this.objects = protocolSDK.objects
108
104
  this.oftObjectId = oftObjectId
@@ -337,9 +333,8 @@ export class OFT {
337
333
  * Send OFT tokens to destination chain
338
334
  * @param tx - The transaction to add the move call to
339
335
  * @param sender - Sender address for ZRO token operations
340
- * @param coinProvided - Coin object ID or transaction result to send
341
- * @param messagingChannel - The messaging channel object ID
342
336
  * @param sendParam - Send parameters including destination and amounts
337
+ * @param coinProvided - Coin object ID or transaction result to send
343
338
  * @param nativeFee - Native token fee amount
344
339
  * @param zroFee - ZRO token fee amount
345
340
  * @param refundAddress - Address for fee refunds
@@ -348,16 +343,19 @@ export class OFT {
348
343
  async sendMoveCall(
349
344
  tx: Transaction,
350
345
  sender: string,
351
- coinProvided: string | TransactionArgument,
352
346
  sendParam: SendParam | TransactionArgument,
347
+ coinProvided: string | TransactionArgument,
353
348
  nativeFee: bigint | TransactionArgument,
354
349
  zroFee: bigint | TransactionArgument,
355
350
  refundAddress: string | TransactionArgument,
356
- messagingChannel?: string | undefined
351
+ validators?: IPTBValidator[],
352
+ maxSimulationTimes?: number
357
353
  ): Promise<void> {
358
354
  const sendParamArg = isTransactionArgument(sendParam) ? sendParam : this.#buildSendParam(tx, sendParam)
359
- const messagingChannelArg =
360
- messagingChannel ?? (await this.protocolSDK.getEndpoint().getMessagingChannel(this.packageId))
355
+ const txSender = this.txSenderMoveCall(tx)
356
+ const addressArg = isTransactionArgument(refundAddress)
357
+ ? refundAddress
358
+ : tx.pure.option('address', refundAddress)
361
359
 
362
360
  // The oft::send returns a tuple (Call<EndpointSendParam, MessagingReceipt>, OFTReceipt)
363
361
  const transactionResult = tx.moveCall({
@@ -365,28 +363,47 @@ export class OFT {
365
363
  typeArguments: [this.coinType],
366
364
  arguments: [
367
365
  tx.object(this.oftObjectId),
368
- asObject(tx, coinProvided),
369
- tx.object(this.objects.endpointV2),
370
- tx.object(messagingChannelArg),
366
+ txSender,
371
367
  sendParamArg,
368
+ asObject(tx, coinProvided),
372
369
  asArgWithTx(tx, nativeFee, (tx, val) => tx.splitCoins(tx.gas, [asU64(tx, val)])[0]),
373
370
  await asArgWithTxAsync(tx, zroFee, async (tx, val) =>
374
371
  this.protocolSDK.getZro().splitOptionZroTokenMoveCall(tx, sender, val)
375
372
  ),
376
- asAddress(tx, refundAddress),
373
+ addressArg,
377
374
  tx.object.clock(),
378
375
  ],
379
376
  })
380
377
  const endpointCall = transactionResult[0]
378
+ const oftSendContext = transactionResult[1]
381
379
 
382
380
  await this.protocolSDK
383
381
  .getEndpoint()
384
- .populateSendTransaction(tx, endpointCall as unknown as TransactionResult, sender)
385
-
386
- tx.moveCall({
382
+ .populateSendTransaction(
383
+ tx,
384
+ endpointCall as unknown as TransactionResult,
385
+ sender,
386
+ validators,
387
+ maxSimulationTimes
388
+ )
389
+
390
+ const confirmSendResult = tx.moveCall({
387
391
  target: this.#target('confirm_send'),
388
392
  typeArguments: [this.coinType],
389
- arguments: [tx.object(this.oftObjectId), endpointCall],
393
+ arguments: [tx.object(this.oftObjectId), txSender, endpointCall, oftSendContext],
394
+ })
395
+ // destroy the empty coins
396
+ const nativeCoin = confirmSendResult[2]
397
+ const zroCoin = confirmSendResult[3]
398
+ tx.moveCall({
399
+ target: '0x1::option::destroy_none',
400
+ arguments: [nativeCoin],
401
+ typeArguments: [`0x2::coin::Coin<0x2::sui::SUI>`],
402
+ })
403
+ tx.moveCall({
404
+ target: '0x1::option::destroy_none',
405
+ arguments: [zroCoin],
406
+ typeArguments: [`0x2::coin::Coin<${this.protocolSDK.getZro().zroType}>`],
390
407
  })
391
408
  }
392
409
 
@@ -431,9 +448,11 @@ export class OFT {
431
448
  * @returns Promise<MessagingFee> - The calculated messaging fees
432
449
  */
433
450
  async quoteSend(
434
- sender: string | TransactionArgument,
451
+ sender: string,
435
452
  sendParam: SendParam | TransactionArgument,
436
- payInZro: boolean | TransactionArgument
453
+ payInZro: boolean | TransactionArgument,
454
+ validators?: IPTBValidator[],
455
+ maxSimulationTimes?: number
437
456
  ): Promise<MessagingFee> {
438
457
  const tx = new Transaction()
439
458
  const sendParamArg = isTransactionArgument(sendParam) ? sendParam : this.#buildSendParam(tx, sendParam)
@@ -444,7 +463,7 @@ export class OFT {
444
463
  arguments: [tx.object(this.oftObjectId), asAddress(tx, sender), sendParamArg, asBool(tx, payInZro)],
445
464
  })
446
465
 
447
- return this.protocolSDK.getEndpoint().quote(tx, quoteCall)
466
+ return this.protocolSDK.getEndpoint().quote(tx, quoteCall, sender, validators, maxSimulationTimes)
448
467
  }
449
468
 
450
469
  // ==========================================
@@ -483,6 +502,33 @@ export class OFT {
483
502
  )
484
503
  }
485
504
 
505
+ oftAddressMoveCall(tx: Transaction): TransactionResult {
506
+ return tx.moveCall({
507
+ target: this.#target('oft_address'),
508
+ typeArguments: [this.coinType],
509
+ arguments: [tx.object(this.oftObjectId)],
510
+ })
511
+ }
512
+
513
+ async oftAddress(): Promise<string> {
514
+ return executeSimulate(
515
+ this.client,
516
+ (tx) => this.oftAddressMoveCall(tx),
517
+ (result) => bcs.Address.parse(result[0].value)
518
+ )
519
+ }
520
+
521
+ async messagingChannel(): Promise<string> {
522
+ return executeSimulate(
523
+ this.client,
524
+ (tx) => {
525
+ const oftAddress = this.oftAddressMoveCall(tx)
526
+ this.protocolSDK.getEndpoint().getMessagingChannelMoveCall(tx, oftAddress)
527
+ },
528
+ (result) => bcs.Address.parse(result[0].value)
529
+ )
530
+ }
531
+
486
532
  /**
487
533
  * Get coin metadata address
488
534
  * @param tx - The transaction to add the move call to
@@ -925,6 +971,16 @@ export class OFT {
925
971
  )
926
972
  }
927
973
 
974
+ // ==========================================
975
+ // OFT SENDER
976
+ // ==========================================
977
+
978
+ txSenderMoveCall(tx: Transaction): TransactionResult {
979
+ return tx.moveCall({
980
+ target: this.#target('tx_sender', OFT_SENDER_MODULE_NAME),
981
+ })
982
+ }
983
+
928
984
  // ==========================================
929
985
  // PRIVATE HELPER FUNCTIONS
930
986
  // ==========================================
@@ -960,7 +1016,7 @@ export class OFT {
960
1016
  * @private
961
1017
  */
962
1018
  #target(name: string, module_name = MODULE_NAME): string {
963
- return `${this.corePackageId}::${module_name}::${name}`
1019
+ return `${this.oftPackageId}::${module_name}::${name}`
964
1020
  }
965
1021
 
966
1022
  /**