@layerzerolabs/lz-sui-sdk-v2 3.0.133 → 3.0.134-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.
Files changed (96) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/deployments/sui-sandbox-local/blocked_message_lib.json +26 -26
  3. package/deployments/sui-sandbox-local/blocked_msglib_ptb_builder.json +29 -29
  4. package/deployments/sui-sandbox-local/counter.json +79 -44
  5. package/deployments/sui-sandbox-local/dvn.json +15 -14
  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 +24 -24
  9. package/deployments/sui-sandbox-local/dvn_ptb_builder.json +14 -14
  10. package/deployments/sui-sandbox-local/endpoint_ptb_builder.json +25 -25
  11. package/deployments/sui-sandbox-local/endpoint_v2.json +29 -29
  12. package/deployments/sui-sandbox-local/executor.json +12 -11
  13. package/deployments/sui-sandbox-local/executor_call_type.json +21 -21
  14. package/deployments/sui-sandbox-local/executor_fee_lib.json +19 -19
  15. package/deployments/sui-sandbox-local/executor_layerzero.json +22 -22
  16. package/deployments/sui-sandbox-local/executor_ptb_builder.json +11 -11
  17. package/deployments/sui-sandbox-local/layerzero_views.json +21 -21
  18. package/deployments/sui-sandbox-local/message_lib_common.json +13 -13
  19. package/deployments/sui-sandbox-local/msglib_ptb_builder_call_types.json +20 -20
  20. package/deployments/sui-sandbox-local/oapp.json +23 -21
  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 +3 -3
  35. package/deployments/sui-sandbox-local/object-ExecutorFeeLib.json +4 -4
  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 +4 -4
  39. package/deployments/sui-sandbox-local/object-PriceFeedOwnerCap.json +4 -4
  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 +50 -50
  51. package/deployments/sui-sandbox-local/price_feed.json +26 -26
  52. package/deployments/sui-sandbox-local/price_feed_call_types.json +19 -19
  53. package/deployments/sui-sandbox-local/ptb_move_call.json +12 -12
  54. package/deployments/sui-sandbox-local/sequential_multi_call.json +45 -0
  55. package/deployments/sui-sandbox-local/simple_message_lib.json +30 -30
  56. package/deployments/sui-sandbox-local/simple_msglib_ptb_builder.json +26 -26
  57. package/deployments/sui-sandbox-local/treasury.json +39 -39
  58. package/deployments/sui-sandbox-local/uln_302.json +42 -42
  59. package/deployments/sui-sandbox-local/uln_302_ptb_builder.json +25 -25
  60. package/deployments/sui-sandbox-local/worker_common.json +21 -20
  61. package/deployments/sui-sandbox-local/worker_registry.json +58 -0
  62. package/dist/index.cjs +972 -341
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.mts +636 -343
  65. package/dist/index.d.ts +636 -343
  66. package/dist/index.mjs +961 -341
  67. package/dist/index.mjs.map +1 -1
  68. package/package.json +7 -7
  69. package/src/bcs/index.ts +2 -1
  70. package/src/bcs/oapp.ts +14 -0
  71. package/src/generated/addresses.ts +69 -51
  72. package/src/module-manager.ts +15 -3
  73. package/src/modules/call.ts +16 -6
  74. package/src/modules/endpoint.ts +12 -4
  75. package/src/modules/message-libs/simple-message-lib.ts +3 -2
  76. package/src/modules/message-libs/uln302.ts +23 -5
  77. package/src/modules/oapps/counter.ts +34 -50
  78. package/src/modules/oapps/oapp.ts +489 -74
  79. package/src/modules/ptb-builders/endpoint-ptb-builder.ts +9 -3
  80. package/src/modules/ptb-builders/ptb-builder.ts +19 -4
  81. package/src/modules/ptb-builders/uln302-ptb-builder.ts +5 -0
  82. package/src/modules/workers/dvn-layerzero.ts +6 -0
  83. package/src/modules/workers/dvn.ts +74 -0
  84. package/src/modules/workers/executor-fee-lib.ts +11 -3
  85. package/src/modules/workers/executor-layerzero.ts +6 -0
  86. package/src/modules/workers/executor.ts +63 -0
  87. package/src/modules/workers/index.ts +1 -0
  88. package/src/modules/workers/treasury.ts +4 -4
  89. package/src/modules/workers/worker-registry.ts +110 -0
  90. package/src/resource.ts +3 -0
  91. package/src/sdk.ts +7 -2
  92. package/src/types/endpoint.ts +2 -1
  93. package/src/types/modules.ts +1 -0
  94. package/src/types/oapp.ts +6 -0
  95. package/src/types/options.ts +15 -0
  96. package/src/utils/transaction.ts +3 -3
@@ -6,9 +6,15 @@ import { ModuleManager } from '../../module-manager'
6
6
  import { ObjectOptions } from '../../types'
7
7
  import { asAddress, asBool, asU32, executeSimulate } from '../../utils'
8
8
 
9
- export const LibBuilderManagerErrorCode = {
10
- // LibBuilderManager related errors (with LibBuilderManager_ prefix)
11
- LibBuilderManager_EBuilderNotFound: 1,
9
+ export const EndpointPtbBuilderErrorCode = {
10
+ // EndpointPtbBuilder related errors (matching endpoint_ptb_builder.move)
11
+ EndpointPtbBuilder_EBuilderNotFound: 1,
12
+ EndpointPtbBuilder_EBuilderRegistered: 2,
13
+ EndpointPtbBuilder_EBuilderUnsupported: 3,
14
+ EndpointPtbBuilder_EInvalidBounds: 4,
15
+ EndpointPtbBuilder_EInvalidBuilderAddress: 5,
16
+ EndpointPtbBuilder_EInvalidLibrary: 6,
17
+ EndpointPtbBuilder_EUnauthorized: 7,
12
18
  } as const
13
19
 
14
20
  const ModuleName = 'endpoint_ptb_builder'
@@ -2,14 +2,14 @@ import { bcs } from '@mysten/sui/bcs'
2
2
  import { SuiClient } from '@mysten/sui/client'
3
3
  import { Transaction, TransactionResult } from '@mysten/sui/transactions'
4
4
 
5
- import { VectorMoveCallBCS } from '../../bcs'
5
+ import { OAppInfoV1Bcs, VectorMoveCallBCS } from '../../bcs'
6
6
  import {
7
7
  Argument,
8
8
  BuilderPlaceholderInfo,
9
9
  DEFAULT_SIMULATION_TIMES,
10
10
  LzComposeVersion,
11
- LzReceiveVersion,
12
11
  MoveCall,
12
+ OAppInfoVersion,
13
13
  SimulateResult,
14
14
  } from '../../types'
15
15
  import { simulateTransaction } from '../../utils/transaction'
@@ -17,6 +17,15 @@ import { normalizeSuiPackageId } from '../../utils/type-name'
17
17
 
18
18
  const MOVE_CALL_MODULE_NAME = 'move_call'
19
19
 
20
+ export const PtbBuilderErrorCode = {
21
+ // MoveCallsBuilder related errors (matching move_calls_builder.move)
22
+ MoveCallsBuilder_EInvalidMoveCallResult: 1,
23
+ MoveCallsBuilder_EResultIDNotFound: 2,
24
+
25
+ // Argument related errors (matching argument.move)
26
+ Argument_EInvalidArgument: 1,
27
+ } as const
28
+
20
29
  export class PtbBuilder {
21
30
  public packageId: string
22
31
  public readonly client: SuiClient
@@ -48,9 +57,10 @@ export class PtbBuilder {
48
57
  async simulateLzReceivePtb(tx: Transaction, sender?: string): Promise<MoveCall[]> {
49
58
  const ptbCallsResult = await simulateTransaction(this.client, tx, sender)
50
59
  const buffer = Buffer.from(bcs.vector(bcs.u8()).parse(ptbCallsResult[0].value))
60
+
51
61
  const version = buffer.readInt16BE()
52
- if (version === LzReceiveVersion.VERSION_1) {
53
- return this.#decodeMoveCallsBytes(new Uint8Array(buffer.subarray(2)))
62
+ if (version === OAppInfoVersion.VERSION_1) {
63
+ return this.#decodeMoveCallsFromOAppInfoV1(new Uint8Array(buffer.subarray(2)))
54
64
  }
55
65
  throw new Error(`Unknown version: ${version}`)
56
66
  }
@@ -285,6 +295,11 @@ export class PtbBuilder {
285
295
  return this.#decodeMoveCallsBytes(value)
286
296
  }
287
297
 
298
+ #decodeMoveCallsFromOAppInfoV1(bytes: Uint8Array): MoveCall[] {
299
+ const oappInfo = OAppInfoV1Bcs.parse(bytes)
300
+ return this.#decodeMoveCallsBytes(new Uint8Array(oappInfo.lz_receive_info).subarray(2)) // remove the version prefix
301
+ }
302
+
288
303
  /**
289
304
  * Decode move calls from raw bytes
290
305
  * @param bytes - The raw bytes containing encoded move calls
@@ -8,6 +8,11 @@ import { asAddress, executeSimulate } from '../../utils'
8
8
 
9
9
  const MODULE_NAME = 'uln_302_ptb_builder'
10
10
 
11
+ export const Uln302PtbBuilderErrorCode = {
12
+ // ULN302 PTB Builder related errors (matching uln_302_ptb_builder.move)
13
+ Uln302PtbBuilder_EWorkerPtbsNotFound: 1,
14
+ } as const
15
+
11
16
  export class Uln302PtbBuilder {
12
17
  public packageId: string
13
18
  public readonly client: SuiClient
@@ -6,6 +6,11 @@ import { asAddress, asAddressVector, asBytesVector, asObject, asU16, asU32, asU6
6
6
 
7
7
  const MODULE_NAME = 'dvn_layerzero'
8
8
 
9
+ export const DVNLayerzeroErrorCode = {
10
+ // DVNLayerzero related errors (matching dvn_layerzero.move)
11
+ DVNLayerzero_EWorkerCapNotFromPackage: 1,
12
+ } as const
13
+
9
14
  export class DvnLayerZero {
10
15
  public packageId: string
11
16
  public readonly client: SuiClient
@@ -59,6 +64,7 @@ export class DvnLayerZero {
59
64
  asAddressVector(tx, admins),
60
65
  asBytesVector(tx, signers),
61
66
  asU64(tx, quorum),
67
+ tx.object(this.moduleManager.objects.workerRegistry),
62
68
  ],
63
69
  })
64
70
  }
@@ -27,6 +27,21 @@ export const DVNErrorCode = {
27
27
  DVN_EEidNotSupported: 2,
28
28
  DVN_EHashAlreadyUsed: 3,
29
29
  DVN_EPtbBuilderAlreadyInitialized: 4,
30
+
31
+ // Multisig related errors (matching multisig.move)
32
+ Multisig_EDuplicatedSigner: 1,
33
+ Multisig_EInvalidSignatureLength: 2,
34
+ Multisig_EInvalidSignerLength: 3,
35
+ Multisig_EQuorumIsZero: 4,
36
+ Multisig_ESignaturesLessThanQuorum: 5,
37
+ Multisig_ESignerAlreadyExists: 6,
38
+ Multisig_ESignerNotFound: 7,
39
+ Multisig_ESignerNotInCommittee: 8,
40
+ Multisig_ESignersSizeIsLessThanQuorum: 9,
41
+
42
+ // DVNInfoV1 related errors (matching dvn_info_v1.move)
43
+ DVNInfoV1_EInvalidData: 1,
44
+ DVNInfoV1_EInvalidVersion: 2,
30
45
  } as const
31
46
 
32
47
  export class DVN {
@@ -1135,6 +1150,65 @@ export class DVN {
1135
1150
  )
1136
1151
  }
1137
1152
 
1153
+ /**
1154
+ * Get DVN object address from worker registry using this DVN's worker capability (as a move call)
1155
+ * This function chains Move calls to decode worker info and extract the DVN object address
1156
+ * @param tx - The transaction to add the move call to
1157
+ * @returns Transaction result containing the DVN object address
1158
+ */
1159
+ getDvnObjectAddressMoveCall(tx: Transaction): TransactionResult {
1160
+ // Step 1: Get this DVN's worker capability address
1161
+ const workerCapAddress = this.workerCapAddressMoveCall(tx)
1162
+
1163
+ // Step 2: Get worker info bytes from registry
1164
+ const workerInfoBytes = this.moduleManager
1165
+ .getWorkerRegistry(this.client)
1166
+ .getWorkerInfoMoveCall(tx, workerCapAddress)
1167
+
1168
+ // Step 3: Decode worker info using worker_common::worker_info_v1::decode
1169
+ const workerInfo = tx.moveCall({
1170
+ target: `${this.moduleManager.packages.workerCommon}::worker_info_v1::decode`,
1171
+ arguments: [workerInfoBytes],
1172
+ })
1173
+
1174
+ // Step 4: Extract worker_info field from decoded WorkerInfoV1
1175
+ const dvnInfoBytes = tx.moveCall({
1176
+ target: `${this.moduleManager.packages.workerCommon}::worker_info_v1::worker_info`,
1177
+ arguments: [workerInfo],
1178
+ })
1179
+
1180
+ // Step 5: Decode DVN info using dvn::dvn_info_v1::decode
1181
+ const dvnInfo = tx.moveCall({
1182
+ target: `${this.packageId}::dvn_info_v1::decode`,
1183
+ arguments: [dvnInfoBytes],
1184
+ })
1185
+
1186
+ // Step 6: Extract dvn_object address from decoded DVNInfoV1
1187
+ return tx.moveCall({
1188
+ target: `${this.packageId}::dvn_info_v1::dvn_object`,
1189
+ arguments: [dvnInfo],
1190
+ })
1191
+ }
1192
+
1193
+ /**
1194
+ * Get DVN object address from worker registry using this DVN's worker capability
1195
+ * This function uses Move calls to decode worker info and extract the DVN object address
1196
+ * @returns Promise<string> - The DVN object address
1197
+ * @throws Will throw an error if worker info is not found or if decoding fails
1198
+ */
1199
+ async getDvnObjectAddress(): Promise<string> {
1200
+ return executeSimulate(
1201
+ this.client,
1202
+ (tx) => {
1203
+ this.getDvnObjectAddressMoveCall(tx)
1204
+ },
1205
+ (result) => {
1206
+ // The result is the DVN object address directly from the Move call chain
1207
+ return bcs.Address.parse(result[0].value)
1208
+ }
1209
+ )
1210
+ }
1211
+
1138
1212
  // === Witness Functions ===
1139
1213
 
1140
1214
  /**
@@ -7,10 +7,18 @@ import { ObjectOptions } from '../../types'
7
7
  const MODULE_NAME = 'executor_fee_lib'
8
8
 
9
9
  export const ExecutorFeeLibErrorCode = {
10
- // Executor Fee Lib related errors (with ExecutorFeeLib_ prefix)
10
+ // Executor Fee Lib related errors (matching executor_fee_lib.move)
11
11
  ExecutorFeeLib_EEidNotSupported: 1,
12
- ExecutorFeeLib_EInvalidExecutor: 2,
13
- ExecutorFeeLib_EExecutorAlreadySet: 3,
12
+
13
+ // ExecutorOption related errors (matching executor_option.move)
14
+ ExecutorOption_ENoOptions: 1,
15
+ ExecutorOption_EUnsupportedOptionType: 2,
16
+ ExecutorOption_EZeroLzReceiveGasProvided: 3,
17
+ ExecutorOption_EZeroLzComposeGasProvided: 4,
18
+ ExecutorOption_ENativeAmountExceedsCap: 5,
19
+ ExecutorOption_EInvalidLzReceiveOption: 6,
20
+ ExecutorOption_EInvalidNativeDropOption: 7,
21
+ ExecutorOption_EInvalidLzComposeOption: 8,
14
22
  } as const
15
23
 
16
24
  export class ExecutorFeeLib {
@@ -6,6 +6,11 @@ import { asAddress, asAddressVector, asObject, asU16 } from '../../utils'
6
6
 
7
7
  const MODULE_NAME = 'executor_layerzero'
8
8
 
9
+ export const ExecutorLayerzeroErrorCode = {
10
+ // ExecutorLayerzero related errors (matching executor_layerzero.move)
11
+ ExecutorLayerzero_EWorkerCapNotFromPackage: 1,
12
+ } as const
13
+
9
14
  export class ExecutorLayerZero {
10
15
  public packageId: string
11
16
  public readonly client: SuiClient
@@ -53,6 +58,7 @@ export class ExecutorLayerZero {
53
58
  asU16(tx, defaultMultiplierBps),
54
59
  asAddress(tx, owner),
55
60
  asAddressVector(tx, admins),
61
+ tx.object(this.moduleManager.objects.workerRegistry),
56
62
  ],
57
63
  })
58
64
  }
@@ -25,6 +25,10 @@ export const ExecutorErrorCode = {
25
25
  // Executor related errors (with Executor_ prefix)
26
26
  Executor_EEidNotSupported: 1,
27
27
  Executor_EInvalidNativeDropAmount: 2,
28
+
29
+ // ExecutorInfoV1 related errors (matching executor_info_v1.move)
30
+ ExecutorInfoV1_EInvalidData: 1,
31
+ ExecutorInfoV1_EInvalidVersion: 2,
28
32
  } as const
29
33
 
30
34
  export class Executor {
@@ -1029,6 +1033,65 @@ export class Executor {
1029
1033
  )
1030
1034
  }
1031
1035
 
1036
+ /**
1037
+ * Get Executor object address from worker registry using this Executor's worker capability (as a move call)
1038
+ * This function chains Move calls to decode worker info and extract the Executor object address
1039
+ * @param tx - The transaction to add the move call to
1040
+ * @returns Transaction result containing the Executor object address
1041
+ */
1042
+ getExecutorObjectAddressMoveCall(tx: Transaction): TransactionResult {
1043
+ // Step 1: Get this Executor's worker capability address
1044
+ const workerCapAddress = this.workerCapAddressMoveCall(tx)
1045
+
1046
+ // Step 2: Get worker info bytes from registry
1047
+ const workerInfoBytes = this.moduleManager
1048
+ .getWorkerRegistry(this.client)
1049
+ .getWorkerInfoMoveCall(tx, workerCapAddress)
1050
+
1051
+ // Step 3: Decode worker info using worker_common::worker_info_v1::decode
1052
+ const workerInfo = tx.moveCall({
1053
+ target: `${this.moduleManager.packages.workerCommon}::worker_info_v1::decode`,
1054
+ arguments: [workerInfoBytes],
1055
+ })
1056
+
1057
+ // Step 4: Extract worker_info field from decoded WorkerInfoV1
1058
+ const executorInfoBytes = tx.moveCall({
1059
+ target: `${this.moduleManager.packages.workerCommon}::worker_info_v1::worker_info`,
1060
+ arguments: [workerInfo],
1061
+ })
1062
+
1063
+ // Step 5: Decode Executor info using executor::executor_info_v1::decode
1064
+ const executorInfo = tx.moveCall({
1065
+ target: `${this.packageId}::executor_info_v1::decode`,
1066
+ arguments: [executorInfoBytes],
1067
+ })
1068
+
1069
+ // Step 6: Extract executor_object address from decoded ExecutorInfoV1
1070
+ return tx.moveCall({
1071
+ target: `${this.packageId}::executor_info_v1::executor_object`,
1072
+ arguments: [executorInfo],
1073
+ })
1074
+ }
1075
+
1076
+ /**
1077
+ * Get Executor object address from worker registry using this Executor's worker capability
1078
+ * This function uses Move calls to decode worker info and extract the Executor object address
1079
+ * @returns Promise<string> - The Executor object address
1080
+ * @throws Will throw an error if worker info is not found or if decoding fails
1081
+ */
1082
+ async getExecutorObjectAddress(): Promise<string> {
1083
+ return executeSimulate(
1084
+ this.client,
1085
+ (tx) => {
1086
+ this.getExecutorObjectAddressMoveCall(tx)
1087
+ },
1088
+ (result) => {
1089
+ // The result is the Executor object address directly from the Move call chain
1090
+ return bcs.Address.parse(result[0].value)
1091
+ }
1092
+ )
1093
+ }
1094
+
1032
1095
  // === Private Helper Functions ===
1033
1096
 
1034
1097
  private parseDstConfig(data: Uint8Array): DstConfig {
@@ -7,3 +7,4 @@ export * from './executor-fee-lib'
7
7
  export * from './executor-layerzero'
8
8
  export * from './price-feed'
9
9
  export * from './treasury'
10
+ export * from './worker-registry'
@@ -9,10 +9,10 @@ import { asAddress, asBool, asU64, executeSimulate } from '../../utils'
9
9
  const MODULE_NAME = 'treasury'
10
10
 
11
11
  export const TreasuryErrorCode = {
12
- // Treasury related errors
13
- TREASURY_EZroNotEnabled: 1,
14
- TREASURY_EInvalidFeeRecipient: 2,
15
- TREASURY_EInvalidNativeFeeBp: 3,
12
+ // Treasury related errors (matching treasury.move)
13
+ TREASURY_EInvalidFeeRecipient: 1,
14
+ TREASURY_EInvalidNativeFeeBp: 2,
15
+ TREASURY_EZroNotEnabled: 3,
16
16
  } as const
17
17
 
18
18
  export class Treasury {
@@ -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
  }