@layerzerolabs/lz-sui-sdk-v2 3.0.134 → 3.0.135

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 (163) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/deployments/sui-sandbox-local/blocked_message_lib.json +22 -22
  3. package/deployments/sui-sandbox-local/blocked_msglib_ptb_builder.json +22 -22
  4. package/deployments/sui-sandbox-local/counter.json +79 -44
  5. package/deployments/sui-sandbox-local/dvn.json +23 -22
  6. package/deployments/sui-sandbox-local/dvn_call_type.json +28 -28
  7. package/deployments/sui-sandbox-local/dvn_fee_lib.json +27 -27
  8. package/deployments/sui-sandbox-local/dvn_layerzero.json +17 -17
  9. package/deployments/sui-sandbox-local/dvn_ptb_builder.json +21 -21
  10. package/deployments/sui-sandbox-local/endpoint_ptb_builder.json +30 -30
  11. package/deployments/sui-sandbox-local/endpoint_v2.json +25 -25
  12. package/deployments/sui-sandbox-local/executor.json +15 -14
  13. package/deployments/sui-sandbox-local/executor_call_type.json +28 -28
  14. package/deployments/sui-sandbox-local/executor_fee_lib.json +28 -28
  15. package/deployments/sui-sandbox-local/executor_layerzero.json +17 -17
  16. package/deployments/sui-sandbox-local/executor_ptb_builder.json +14 -14
  17. package/deployments/sui-sandbox-local/layerzero_views.json +21 -21
  18. package/deployments/sui-sandbox-local/message_lib_common.json +21 -21
  19. package/deployments/sui-sandbox-local/msglib_ptb_builder_call_types.json +13 -13
  20. package/deployments/sui-sandbox-local/oapp.json +15 -13
  21. package/deployments/sui-sandbox-local/object-BlockedMessageLib.json +5 -5
  22. package/deployments/sui-sandbox-local/object-BlockedMsglibPtbBuilder.json +5 -5
  23. package/deployments/sui-sandbox-local/object-Counter.json +5 -5
  24. package/deployments/sui-sandbox-local/object-CounterAdminCap.json +5 -5
  25. package/deployments/sui-sandbox-local/object-CounterOApp.json +5 -5
  26. package/deployments/sui-sandbox-local/object-DVN.json +2 -2
  27. package/deployments/sui-sandbox-local/object-DVNCap.json +4 -4
  28. package/deployments/sui-sandbox-local/object-DVNFeeLib.json +5 -5
  29. package/deployments/sui-sandbox-local/object-EndpointPtbBuilder.json +5 -5
  30. package/deployments/sui-sandbox-local/object-EndpointPtbBuilderAdminCap.json +5 -5
  31. package/deployments/sui-sandbox-local/object-EndpointV2.json +5 -5
  32. package/deployments/sui-sandbox-local/object-EndpointV2AdminCap.json +5 -5
  33. package/deployments/sui-sandbox-local/object-Executor.json +2 -2
  34. package/deployments/sui-sandbox-local/object-ExecutorCap.json +4 -4
  35. package/deployments/sui-sandbox-local/object-ExecutorFeeLib.json +5 -5
  36. package/deployments/sui-sandbox-local/object-ExecutorOwnerCap.json +2 -2
  37. package/deployments/sui-sandbox-local/object-PackageWhitelistValidator.json +5 -5
  38. package/deployments/sui-sandbox-local/object-PriceFeed.json +5 -5
  39. package/deployments/sui-sandbox-local/object-PriceFeedOwnerCap.json +5 -5
  40. package/deployments/sui-sandbox-local/object-SimpleMessageLib.json +5 -5
  41. package/deployments/sui-sandbox-local/object-SimpleMessageLibAdminCap.json +5 -5
  42. package/deployments/sui-sandbox-local/object-SmlPtbBuilder.json +5 -5
  43. package/deployments/sui-sandbox-local/object-Treasury.json +5 -5
  44. package/deployments/sui-sandbox-local/object-TreasuryAdminCap.json +5 -5
  45. package/deployments/sui-sandbox-local/object-ULN302.json +5 -5
  46. package/deployments/sui-sandbox-local/object-ULN302AdminCap.json +5 -5
  47. package/deployments/sui-sandbox-local/object-Uln302PtbBuilder.json +5 -5
  48. package/deployments/sui-sandbox-local/object-Uln302Verification.json +5 -5
  49. package/deployments/sui-sandbox-local/object-WorkerRegistry.json +9 -0
  50. package/deployments/sui-sandbox-local/package_whitelist_validator.json +51 -51
  51. package/deployments/sui-sandbox-local/price_feed.json +39 -39
  52. package/deployments/sui-sandbox-local/price_feed_call_types.json +19 -19
  53. package/deployments/sui-sandbox-local/ptb_move_call.json +20 -20
  54. package/deployments/sui-sandbox-local/sequential_multi_call.json +45 -0
  55. package/deployments/sui-sandbox-local/simple_message_lib.json +33 -33
  56. package/deployments/sui-sandbox-local/simple_msglib_ptb_builder.json +22 -22
  57. package/deployments/sui-sandbox-local/treasury.json +40 -40
  58. package/deployments/sui-sandbox-local/uln_302.json +35 -39
  59. package/deployments/sui-sandbox-local/uln_302_ptb_builder.json +25 -25
  60. package/deployments/sui-sandbox-local/uln_common.json +49 -0
  61. package/deployments/sui-sandbox-local/worker_common.json +15 -14
  62. package/deployments/sui-sandbox-local/worker_registry.json +58 -0
  63. package/deployments/sui-testnet/blocked_message_lib.json +22 -22
  64. package/deployments/sui-testnet/blocked_msglib_ptb_builder.json +29 -29
  65. package/deployments/sui-testnet/call.json +21 -21
  66. package/deployments/sui-testnet/counter.json +40 -40
  67. package/deployments/sui-testnet/dvn.json +22 -21
  68. package/deployments/sui-testnet/dvn_call_type.json +19 -19
  69. package/deployments/sui-testnet/dvn_fee_lib.json +26 -26
  70. package/deployments/sui-testnet/dvn_layerzero.json +24 -24
  71. package/deployments/sui-testnet/dvn_ptb_builder.json +20 -20
  72. package/deployments/sui-testnet/endpoint_ptb_builder.json +30 -30
  73. package/deployments/sui-testnet/endpoint_v2.json +26 -26
  74. package/deployments/sui-testnet/executor.json +22 -21
  75. package/deployments/sui-testnet/executor_call_type.json +19 -19
  76. package/deployments/sui-testnet/executor_fee_lib.json +18 -18
  77. package/deployments/sui-testnet/executor_layerzero.json +25 -25
  78. package/deployments/sui-testnet/executor_ptb_builder.json +20 -20
  79. package/deployments/sui-testnet/layerzero_views.json +13 -13
  80. package/deployments/sui-testnet/message_lib_common.json +21 -21
  81. package/deployments/sui-testnet/msglib_ptb_builder_call_types.json +13 -13
  82. package/deployments/sui-testnet/oapp.json +15 -13
  83. package/deployments/sui-testnet/object-BlockedMessageLib.json +5 -5
  84. package/deployments/sui-testnet/object-BlockedMsglibPtbBuilder.json +5 -5
  85. package/deployments/sui-testnet/object-Counter.json +5 -5
  86. package/deployments/sui-testnet/object-CounterAdminCap.json +5 -5
  87. package/deployments/sui-testnet/object-CounterOApp.json +5 -5
  88. package/deployments/sui-testnet/object-DVN.json +2 -2
  89. package/deployments/sui-testnet/object-DVNCap.json +5 -5
  90. package/deployments/sui-testnet/object-DVNFeeLib.json +5 -5
  91. package/deployments/sui-testnet/object-EndpointPtbBuilder.json +5 -5
  92. package/deployments/sui-testnet/object-EndpointPtbBuilderAdminCap.json +5 -5
  93. package/deployments/sui-testnet/object-EndpointV2.json +5 -5
  94. package/deployments/sui-testnet/object-EndpointV2AdminCap.json +5 -5
  95. package/deployments/sui-testnet/object-Executor.json +2 -2
  96. package/deployments/sui-testnet/object-ExecutorCap.json +5 -5
  97. package/deployments/sui-testnet/object-ExecutorFeeLib.json +5 -5
  98. package/deployments/sui-testnet/object-ExecutorOwnerCap.json +2 -2
  99. package/deployments/sui-testnet/object-PackageWhitelistValidator.json +5 -5
  100. package/deployments/sui-testnet/object-PriceFeed.json +5 -5
  101. package/deployments/sui-testnet/object-PriceFeedOwnerCap.json +5 -5
  102. package/deployments/sui-testnet/object-SimpleMessageLib.json +5 -5
  103. package/deployments/sui-testnet/object-SimpleMessageLibAdminCap.json +5 -5
  104. package/deployments/sui-testnet/object-SmlPtbBuilder.json +5 -5
  105. package/deployments/sui-testnet/object-Treasury.json +5 -5
  106. package/deployments/sui-testnet/object-TreasuryAdminCap.json +5 -5
  107. package/deployments/sui-testnet/object-ULN302.json +5 -5
  108. package/deployments/sui-testnet/object-ULN302AdminCap.json +5 -5
  109. package/deployments/sui-testnet/object-Uln302PtbBuilder.json +5 -5
  110. package/deployments/sui-testnet/object-Uln302Verification.json +5 -5
  111. package/deployments/sui-testnet/object-WorkerRegistry.json +9 -0
  112. package/deployments/sui-testnet/object-ZroCoinMetadata.json +5 -5
  113. package/deployments/sui-testnet/object-ZroTreasuryCap.json +5 -5
  114. package/deployments/sui-testnet/package_whitelist_validator.json +44 -44
  115. package/deployments/sui-testnet/price_feed.json +25 -25
  116. package/deployments/sui-testnet/price_feed_call_types.json +12 -12
  117. package/deployments/sui-testnet/ptb_move_call.json +21 -21
  118. package/deployments/sui-testnet/sequential_multi_call.json +45 -0
  119. package/deployments/sui-testnet/simple_message_lib.json +29 -29
  120. package/deployments/sui-testnet/simple_msglib_ptb_builder.json +26 -26
  121. package/deployments/sui-testnet/treasury.json +30 -58
  122. package/deployments/sui-testnet/uln_302.json +28 -32
  123. package/deployments/sui-testnet/uln_302_ptb_builder.json +25 -25
  124. package/deployments/sui-testnet/uln_common.json +49 -0
  125. package/deployments/sui-testnet/utils.json +12 -12
  126. package/deployments/sui-testnet/worker_common.json +21 -20
  127. package/deployments/sui-testnet/worker_registry.json +58 -0
  128. package/deployments/sui-testnet/zro.json +28 -28
  129. package/dist/index.cjs +1193 -418
  130. package/dist/index.cjs.map +1 -1
  131. package/dist/index.d.mts +702 -352
  132. package/dist/index.d.ts +702 -352
  133. package/dist/index.mjs +1182 -418
  134. package/dist/index.mjs.map +1 -1
  135. package/package.json +7 -7
  136. package/src/bcs/index.ts +2 -1
  137. package/src/bcs/oapp.ts +14 -0
  138. package/src/generated/addresses.ts +123 -105
  139. package/src/module-manager.ts +15 -3
  140. package/src/modules/call.ts +16 -6
  141. package/src/modules/endpoint.ts +12 -4
  142. package/src/modules/message-libs/simple-message-lib.ts +3 -2
  143. package/src/modules/message-libs/uln302.ts +28 -26
  144. package/src/modules/oapps/counter.ts +34 -50
  145. package/src/modules/oapps/oapp.ts +489 -74
  146. package/src/modules/ptb-builders/endpoint-ptb-builder.ts +9 -3
  147. package/src/modules/ptb-builders/ptb-builder.ts +19 -4
  148. package/src/modules/ptb-builders/uln302-ptb-builder.ts +5 -0
  149. package/src/modules/workers/dvn-layerzero.ts +9 -0
  150. package/src/modules/workers/dvn.ts +214 -6
  151. package/src/modules/workers/executor-fee-lib.ts +11 -3
  152. package/src/modules/workers/executor-layerzero.ts +9 -0
  153. package/src/modules/workers/executor.ts +115 -0
  154. package/src/modules/workers/index.ts +1 -0
  155. package/src/modules/workers/treasury.ts +4 -4
  156. package/src/modules/workers/worker-registry.ts +110 -0
  157. package/src/resource.ts +3 -0
  158. package/src/sdk.ts +7 -2
  159. package/src/types/endpoint.ts +2 -1
  160. package/src/types/modules.ts +1 -0
  161. package/src/types/oapp.ts +6 -0
  162. package/src/types/options.ts +15 -0
  163. package/src/utils/transaction.ts +3 -3
@@ -0,0 +1,110 @@
1
+ import { SuiClient } from '@mysten/sui/client'
2
+ import { Transaction, TransactionArgument, TransactionResult } from '@mysten/sui/transactions'
3
+
4
+ import { ModuleManager } from '../../module-manager'
5
+ import { ObjectOptions } from '../../types'
6
+ import { asAddress, executeSimulate } from '../../utils'
7
+
8
+ const MODULE_NAME = 'worker_registry'
9
+
10
+ export const WorkerRegistryErrorCode = {
11
+ // WorkerRegistry related errors (matching worker_registry.move)
12
+ EWorkerInfoInvalid: 1,
13
+ EWorkerInfoNotFound: 2,
14
+ } as const
15
+
16
+ /**
17
+ * WorkerRegistry provides access to the worker registry contract functionality
18
+ * This module maintains mappings between worker addresses and their associated information.
19
+ */
20
+ export class WorkerRegistry {
21
+ public packageId: string
22
+ public readonly client: SuiClient
23
+ private readonly objects: ObjectOptions
24
+
25
+ /**
26
+ * Create a new WorkerRegistry instance
27
+ * @param packageId - The package ID of the worker registry contract
28
+ * @param client - The Sui client instance
29
+ * @param objects - Object options containing contract object IDs
30
+ * @param moduleManager - Module manager for handling dependencies
31
+ */
32
+ constructor(
33
+ packageId: string,
34
+ client: SuiClient,
35
+ objects: ObjectOptions,
36
+ private readonly moduleManager: ModuleManager
37
+ ) {
38
+ this.packageId = packageId
39
+ this.client = client
40
+ this.objects = objects
41
+ }
42
+
43
+ // === View Functions ===
44
+
45
+ /**
46
+ * Get worker info for a specific worker address (as a move call)
47
+ * This creates a move call that can be used in a PTB (Programmable Transaction Block)
48
+ * @param tx - The transaction to add the move call to
49
+ * @param worker - The worker address or transaction argument
50
+ * @returns TransactionResult - The move call result containing worker info bytes
51
+ * @throws Will throw an error if worker info is not found (EWorkerInfoNotFound)
52
+ */
53
+ getWorkerInfoMoveCall(tx: Transaction, worker: string | TransactionArgument): TransactionResult {
54
+ return tx.moveCall({
55
+ target: this.#target('get_worker_info'),
56
+ arguments: [tx.object(this.objects.workerRegistry), asAddress(tx, worker)],
57
+ })
58
+ }
59
+
60
+ /**
61
+ * Get worker info for a specific worker address
62
+ * Executes the get_worker_info function and returns the worker information bytes
63
+ * @param worker - The worker address to get info for
64
+ * @returns Promise<Uint8Array> - The worker information bytes containing encoded worker data
65
+ * @throws Will throw an error if worker info is not found (EWorkerInfoNotFound)
66
+ */
67
+ async getWorkerInfo(worker: string): Promise<Uint8Array> {
68
+ return executeSimulate(
69
+ this.client,
70
+ (tx) => {
71
+ this.getWorkerInfoMoveCall(tx, worker)
72
+ },
73
+ (result) => {
74
+ return result[0].value
75
+ }
76
+ )
77
+ }
78
+
79
+ /**
80
+ * Check if worker info exists for a specific worker address
81
+ * This is a convenience method that catches EWorkerInfoNotFound errors
82
+ * @param worker - The worker address to check
83
+ * @returns Promise<boolean> - True if worker info exists, false if not found
84
+ * @throws Will re-throw any errors other than EWorkerInfoNotFound
85
+ */
86
+ async hasWorkerInfo(worker: string): Promise<boolean> {
87
+ try {
88
+ await this.getWorkerInfo(worker)
89
+ return true
90
+ } catch (error) {
91
+ // If the error is EWorkerInfoNotFound, return false
92
+ if (error instanceof Error && error.message.includes('EWorkerInfoNotFound')) {
93
+ return false
94
+ }
95
+ // Re-throw other errors
96
+ throw error
97
+ }
98
+ }
99
+
100
+ // === Private Functions ===
101
+
102
+ /**
103
+ * Generate the target string for move calls
104
+ * @param functionName - The function name to call
105
+ * @returns The fully qualified target string for the move call
106
+ */
107
+ #target(functionName: string): string {
108
+ return `${this.packageId}::${MODULE_NAME}::${functionName}`
109
+ }
110
+ }
package/src/resource.ts CHANGED
@@ -33,6 +33,8 @@ const PACKAGE_ADDRESS_MAP: { [K in keyof PackageOptions]: Partial<{ [S in Stage]
33
33
  oapp: AddressConstants.PACKAGE_OAPP_ADDRESS,
34
34
  layerzeroViews: AddressConstants.PACKAGE_LAYERZERO_VIEWS_ADDRESS,
35
35
  packageWhitelistValidator: AddressConstants.PACKAGE_PACKAGE_WHITELIST_VALIDATOR_ADDRESS,
36
+ workerRegistry: AddressConstants.PACKAGE_WORKER_REGISTRY_ADDRESS,
37
+ workerCommon: AddressConstants.PACKAGE_WORKER_COMMON_ADDRESS,
36
38
  }
37
39
 
38
40
  /**
@@ -67,6 +69,7 @@ const OBJECT_ADDRESS_MAP: { [K in keyof ObjectOptions]: Partial<{ [S in Stage]:
67
69
  priceFeed: AddressConstants.OBJECT_PRICE_FEED_ADDRESS,
68
70
  priceFeedOwnerCap: AddressConstants.OBJECT_PRICE_FEED_OWNER_CAP_ADDRESS,
69
71
  packageWhitelistValidator: AddressConstants.OBJECT_PACKAGE_WHITELIST_VALIDATOR_ADDRESS,
72
+ workerRegistry: AddressConstants.OBJECT_WORKER_REGISTRY_ADDRESS,
70
73
  }
71
74
 
72
75
  /**
package/src/sdk.ts CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  Uln302,
30
30
  Uln302PtbBuilder,
31
31
  Utils,
32
+ WorkerRegistry,
32
33
  Zro,
33
34
  } from './modules'
34
35
  import { ResourceManager } from './resource'
@@ -106,8 +107,8 @@ export class SDK {
106
107
  return this.moduleManager.getLayerZeroViews()
107
108
  }
108
109
 
109
- getOApp(): OApp {
110
- return this.moduleManager.getOApp()
110
+ getOApp(callCapId: string, options?: ModuleOptions): OApp {
111
+ return this.moduleManager.getOApp(this.client, callCapId, options)
111
112
  }
112
113
 
113
114
  // === Non-Core Module Getters (created on-demand with caching) ===
@@ -172,6 +173,10 @@ export class SDK {
172
173
  return this.moduleManager.getBlockedMessageLibPtbBuilder(this.client, options)
173
174
  }
174
175
 
176
+ getWorkerRegistry(options?: ModuleOptions): WorkerRegistry {
177
+ return this.moduleManager.getWorkerRegistry(this.client, options)
178
+ }
179
+
175
180
  getOrCreateModule<T>(moduleName: string, options: ModuleOptions | undefined, factory: () => T): T {
176
181
  return this.moduleManager.getOrCreateModule(moduleName, options, factory)
177
182
  }
@@ -11,5 +11,6 @@ export interface Timeout {
11
11
  * LayerZero protocol version constants
12
12
  */
13
13
 
14
- export const LzReceiveVersion = { VERSION_1: 1 } as const
14
+ export const OAppInfoVersion = { VERSION_1: 1, VERSION_2: 2 } as const
15
+ export const LzReceiveVersion = { VERSION_1: 1 } as const
15
16
  export const LzComposeVersion = { VERSION_1: 1 } as const
@@ -32,4 +32,5 @@ export enum Modules {
32
32
  Counter = 'counter',
33
33
  DvnPtbBuilder = 'dvnPtbBuilder',
34
34
  ExecutorPtbBuilder = 'executorPtbBuilder',
35
+ WorkerRegistry = 'workerRegistry',
35
36
  }
@@ -0,0 +1,6 @@
1
+ export interface OAppInfoV1 {
2
+ oapp_object: string
3
+ next_nonce_info: number[]
4
+ lz_receive_info: number[]
5
+ extra_info: number[]
6
+ }
@@ -136,6 +136,16 @@ export interface PackageOptions {
136
136
  */
137
137
  blockedMessageLibPtbBuilder: string
138
138
 
139
+ /**
140
+ * The worker registry address.
141
+ */
142
+ workerRegistry: string
143
+
144
+ /**
145
+ * The worker common address.
146
+ */
147
+ workerCommon: string
148
+
139
149
  /**
140
150
  * Allow additional properties beyond the explicitly defined ones
141
151
  */
@@ -285,6 +295,11 @@ export interface ObjectOptions {
285
295
  */
286
296
  packageWhitelistValidator: string
287
297
 
298
+ /**
299
+ * The worker registry object address.
300
+ */
301
+ workerRegistry: string
302
+
288
303
  /**
289
304
  * Allow additional properties beyond the explicitly defined ones
290
305
  */
@@ -101,17 +101,17 @@ export async function validateTransaction(
101
101
  /**
102
102
  * Execute simulate using a moveCall function
103
103
  * @param client - The Sui client
104
- * @param moveCallFn - Function that adds moveCall to the transaction
104
+ * @param moveCallFn - Function that adds moveCall to the transaction (supports both sync and async, any return type)
105
105
  * @param parser - Function to parse the result
106
106
  * @returns The parsed result
107
107
  */
108
108
  export async function executeSimulate<T>(
109
109
  client: SuiClient,
110
- moveCallFn: (tx: Transaction) => void,
110
+ moveCallFn: (tx: Transaction) => unknown,
111
111
  parser: (result: { value: Uint8Array }[]) => T
112
112
  ): Promise<T> {
113
113
  const tx = new Transaction()
114
- moveCallFn(tx)
114
+ await moveCallFn(tx)
115
115
  const result = await simulateTransaction(client, tx)
116
116
  return parser(result)
117
117
  }