@layerzerolabs/lz-iotal1-sdk-v2 3.0.143

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 (279) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +19 -0
  3. package/deployments/iotal1-mainnet/blocked_message_lib.json +58 -0
  4. package/deployments/iotal1-mainnet/blocked_msglib_ptb_builder.json +58 -0
  5. package/deployments/iotal1-mainnet/call.json +46 -0
  6. package/deployments/iotal1-mainnet/counter.json +85 -0
  7. package/deployments/iotal1-mainnet/dvn.json +49 -0
  8. package/deployments/iotal1-mainnet/dvn_call_type.json +45 -0
  9. package/deployments/iotal1-mainnet/dvn_fee_lib.json +59 -0
  10. package/deployments/iotal1-mainnet/dvn_layerzero.json +56 -0
  11. package/deployments/iotal1-mainnet/dvn_ptb_builder.json +45 -0
  12. package/deployments/iotal1-mainnet/endpoint_ptb_builder.json +70 -0
  13. package/deployments/iotal1-mainnet/endpoint_v2.json +86 -0
  14. package/deployments/iotal1-mainnet/executor.json +49 -0
  15. package/deployments/iotal1-mainnet/executor_call_type.json +45 -0
  16. package/deployments/iotal1-mainnet/executor_fee_lib.json +60 -0
  17. package/deployments/iotal1-mainnet/executor_layerzero.json +56 -0
  18. package/deployments/iotal1-mainnet/executor_ptb_builder.json +45 -0
  19. package/deployments/iotal1-mainnet/layerzero_views.json +46 -0
  20. package/deployments/iotal1-mainnet/message_lib_common.json +47 -0
  21. package/deployments/iotal1-mainnet/msglib_ptb_builder_call_types.json +45 -0
  22. package/deployments/iotal1-mainnet/multi_call.json +45 -0
  23. package/deployments/iotal1-mainnet/oapp.json +50 -0
  24. package/deployments/iotal1-mainnet/object-BlockedMessageLib.json +9 -0
  25. package/deployments/iotal1-mainnet/object-BlockedMsglibPtbBuilder.json +9 -0
  26. package/deployments/iotal1-mainnet/object-Counter.json +9 -0
  27. package/deployments/iotal1-mainnet/object-CounterAdminCap.json +9 -0
  28. package/deployments/iotal1-mainnet/object-CounterOApp.json +9 -0
  29. package/deployments/iotal1-mainnet/object-DVN.json +5 -0
  30. package/deployments/iotal1-mainnet/object-DVNCap.json +9 -0
  31. package/deployments/iotal1-mainnet/object-DVNFeeLib.json +9 -0
  32. package/deployments/iotal1-mainnet/object-EndpointPtbBuilder.json +9 -0
  33. package/deployments/iotal1-mainnet/object-EndpointPtbBuilderAdminCap.json +9 -0
  34. package/deployments/iotal1-mainnet/object-EndpointV2.json +9 -0
  35. package/deployments/iotal1-mainnet/object-EndpointV2AdminCap.json +9 -0
  36. package/deployments/iotal1-mainnet/object-Executor.json +5 -0
  37. package/deployments/iotal1-mainnet/object-ExecutorCap.json +9 -0
  38. package/deployments/iotal1-mainnet/object-ExecutorFeeLib.json +9 -0
  39. package/deployments/iotal1-mainnet/object-ExecutorOwnerCap.json +5 -0
  40. package/deployments/iotal1-mainnet/object-OFTComposerManager.json +9 -0
  41. package/deployments/iotal1-mainnet/object-PackageWhitelistValidator.json +9 -0
  42. package/deployments/iotal1-mainnet/object-PriceFeed.json +9 -0
  43. package/deployments/iotal1-mainnet/object-PriceFeedOwnerCap.json +9 -0
  44. package/deployments/iotal1-mainnet/object-SimpleMessageLib.json +9 -0
  45. package/deployments/iotal1-mainnet/object-SimpleMessageLibAdminCap.json +9 -0
  46. package/deployments/iotal1-mainnet/object-SmlPtbBuilder.json +9 -0
  47. package/deployments/iotal1-mainnet/object-Treasury.json +9 -0
  48. package/deployments/iotal1-mainnet/object-TreasuryAdminCap.json +9 -0
  49. package/deployments/iotal1-mainnet/object-ULN302.json +9 -0
  50. package/deployments/iotal1-mainnet/object-ULN302AdminCap.json +9 -0
  51. package/deployments/iotal1-mainnet/object-Uln302PtbBuilder.json +9 -0
  52. package/deployments/iotal1-mainnet/object-Uln302Verification.json +9 -0
  53. package/deployments/iotal1-mainnet/object-WorkerRegistry.json +9 -0
  54. package/deployments/iotal1-mainnet/object-ZroCoinMetadata.json +9 -0
  55. package/deployments/iotal1-mainnet/object-ZroTreasuryCap.json +9 -0
  56. package/deployments/iotal1-mainnet/oft_common.json +61 -0
  57. package/deployments/iotal1-mainnet/package_whitelist_validator.json +113 -0
  58. package/deployments/iotal1-mainnet/price_feed.json +70 -0
  59. package/deployments/iotal1-mainnet/price_feed_call_types.json +45 -0
  60. package/deployments/iotal1-mainnet/ptb_move_call.json +48 -0
  61. package/deployments/iotal1-mainnet/simple_message_lib.json +69 -0
  62. package/deployments/iotal1-mainnet/simple_msglib_ptb_builder.json +58 -0
  63. package/deployments/iotal1-mainnet/treasury.json +69 -0
  64. package/deployments/iotal1-mainnet/uln_302.json +87 -0
  65. package/deployments/iotal1-mainnet/uln_302_ptb_builder.json +58 -0
  66. package/deployments/iotal1-mainnet/uln_common.json +49 -0
  67. package/deployments/iotal1-mainnet/utils.json +57 -0
  68. package/deployments/iotal1-mainnet/worker_common.json +46 -0
  69. package/deployments/iotal1-mainnet/worker_registry.json +58 -0
  70. package/deployments/iotal1-mainnet/zro.json +67 -0
  71. package/deployments/iotal1-sandbox-local/blocked_message_lib.json +58 -0
  72. package/deployments/iotal1-sandbox-local/blocked_msglib_ptb_builder.json +58 -0
  73. package/deployments/iotal1-sandbox-local/call.json +46 -0
  74. package/deployments/iotal1-sandbox-local/counter.json +148 -0
  75. package/deployments/iotal1-sandbox-local/dvn.json +49 -0
  76. package/deployments/iotal1-sandbox-local/dvn_call_type.json +73 -0
  77. package/deployments/iotal1-sandbox-local/dvn_fee_lib.json +59 -0
  78. package/deployments/iotal1-sandbox-local/dvn_layerzero.json +56 -0
  79. package/deployments/iotal1-sandbox-local/dvn_ptb_builder.json +45 -0
  80. package/deployments/iotal1-sandbox-local/endpoint_ptb_builder.json +70 -0
  81. package/deployments/iotal1-sandbox-local/endpoint_v2.json +86 -0
  82. package/deployments/iotal1-sandbox-local/executor.json +49 -0
  83. package/deployments/iotal1-sandbox-local/executor_call_type.json +73 -0
  84. package/deployments/iotal1-sandbox-local/executor_fee_lib.json +60 -0
  85. package/deployments/iotal1-sandbox-local/executor_layerzero.json +56 -0
  86. package/deployments/iotal1-sandbox-local/executor_ptb_builder.json +45 -0
  87. package/deployments/iotal1-sandbox-local/layerzero_views.json +46 -0
  88. package/deployments/iotal1-sandbox-local/message_lib_common.json +47 -0
  89. package/deployments/iotal1-sandbox-local/msglib_ptb_builder_call_types.json +45 -0
  90. package/deployments/iotal1-sandbox-local/multi_call.json +45 -0
  91. package/deployments/iotal1-sandbox-local/oapp.json +50 -0
  92. package/deployments/iotal1-sandbox-local/object-BlockedMessageLib.json +9 -0
  93. package/deployments/iotal1-sandbox-local/object-BlockedMsglibPtbBuilder.json +9 -0
  94. package/deployments/iotal1-sandbox-local/object-Counter.json +9 -0
  95. package/deployments/iotal1-sandbox-local/object-CounterAdminCap.json +9 -0
  96. package/deployments/iotal1-sandbox-local/object-CounterOApp.json +9 -0
  97. package/deployments/iotal1-sandbox-local/object-DVN.json +5 -0
  98. package/deployments/iotal1-sandbox-local/object-DVNCap.json +9 -0
  99. package/deployments/iotal1-sandbox-local/object-DVNFeeLib.json +9 -0
  100. package/deployments/iotal1-sandbox-local/object-EndpointPtbBuilder.json +9 -0
  101. package/deployments/iotal1-sandbox-local/object-EndpointPtbBuilderAdminCap.json +9 -0
  102. package/deployments/iotal1-sandbox-local/object-EndpointV2.json +9 -0
  103. package/deployments/iotal1-sandbox-local/object-EndpointV2AdminCap.json +9 -0
  104. package/deployments/iotal1-sandbox-local/object-Executor.json +5 -0
  105. package/deployments/iotal1-sandbox-local/object-ExecutorCap.json +9 -0
  106. package/deployments/iotal1-sandbox-local/object-ExecutorFeeLib.json +9 -0
  107. package/deployments/iotal1-sandbox-local/object-ExecutorOwnerCap.json +5 -0
  108. package/deployments/iotal1-sandbox-local/object-PackageWhitelistValidator.json +9 -0
  109. package/deployments/iotal1-sandbox-local/object-PriceFeed.json +9 -0
  110. package/deployments/iotal1-sandbox-local/object-PriceFeedOwnerCap.json +9 -0
  111. package/deployments/iotal1-sandbox-local/object-SimpleMessageLib.json +9 -0
  112. package/deployments/iotal1-sandbox-local/object-SimpleMessageLibAdminCap.json +9 -0
  113. package/deployments/iotal1-sandbox-local/object-SmlPtbBuilder.json +9 -0
  114. package/deployments/iotal1-sandbox-local/object-Treasury.json +9 -0
  115. package/deployments/iotal1-sandbox-local/object-TreasuryAdminCap.json +9 -0
  116. package/deployments/iotal1-sandbox-local/object-ULN302.json +9 -0
  117. package/deployments/iotal1-sandbox-local/object-ULN302AdminCap.json +9 -0
  118. package/deployments/iotal1-sandbox-local/object-Uln302PtbBuilder.json +9 -0
  119. package/deployments/iotal1-sandbox-local/object-Uln302Verification.json +9 -0
  120. package/deployments/iotal1-sandbox-local/object-WorkerRegistry.json +9 -0
  121. package/deployments/iotal1-sandbox-local/object-ZroCoinMetadata.json +9 -0
  122. package/deployments/iotal1-sandbox-local/object-ZroTreasuryCap.json +9 -0
  123. package/deployments/iotal1-sandbox-local/package_whitelist_validator.json +113 -0
  124. package/deployments/iotal1-sandbox-local/price_feed.json +98 -0
  125. package/deployments/iotal1-sandbox-local/price_feed_call_types.json +45 -0
  126. package/deployments/iotal1-sandbox-local/ptb_move_call.json +48 -0
  127. package/deployments/iotal1-sandbox-local/simple_message_lib.json +69 -0
  128. package/deployments/iotal1-sandbox-local/simple_msglib_ptb_builder.json +58 -0
  129. package/deployments/iotal1-sandbox-local/treasury.json +97 -0
  130. package/deployments/iotal1-sandbox-local/uln_302.json +87 -0
  131. package/deployments/iotal1-sandbox-local/uln_302_ptb_builder.json +58 -0
  132. package/deployments/iotal1-sandbox-local/uln_common.json +49 -0
  133. package/deployments/iotal1-sandbox-local/utils.json +78 -0
  134. package/deployments/iotal1-sandbox-local/worker_common.json +46 -0
  135. package/deployments/iotal1-sandbox-local/worker_registry.json +58 -0
  136. package/deployments/iotal1-sandbox-local/zro.json +67 -0
  137. package/deployments/iotal1-testnet/blocked_message_lib.json +58 -0
  138. package/deployments/iotal1-testnet/blocked_msglib_ptb_builder.json +58 -0
  139. package/deployments/iotal1-testnet/call.json +46 -0
  140. package/deployments/iotal1-testnet/counter.json +85 -0
  141. package/deployments/iotal1-testnet/dvn.json +49 -0
  142. package/deployments/iotal1-testnet/dvn_call_type.json +45 -0
  143. package/deployments/iotal1-testnet/dvn_fee_lib.json +59 -0
  144. package/deployments/iotal1-testnet/dvn_layerzero.json +56 -0
  145. package/deployments/iotal1-testnet/dvn_ptb_builder.json +45 -0
  146. package/deployments/iotal1-testnet/endpoint_ptb_builder.json +70 -0
  147. package/deployments/iotal1-testnet/endpoint_v2.json +86 -0
  148. package/deployments/iotal1-testnet/executor.json +49 -0
  149. package/deployments/iotal1-testnet/executor_call_type.json +45 -0
  150. package/deployments/iotal1-testnet/executor_fee_lib.json +60 -0
  151. package/deployments/iotal1-testnet/executor_layerzero.json +56 -0
  152. package/deployments/iotal1-testnet/executor_ptb_builder.json +45 -0
  153. package/deployments/iotal1-testnet/layerzero_views.json +46 -0
  154. package/deployments/iotal1-testnet/message_lib_common.json +47 -0
  155. package/deployments/iotal1-testnet/msglib_ptb_builder_call_types.json +45 -0
  156. package/deployments/iotal1-testnet/multi_call.json +45 -0
  157. package/deployments/iotal1-testnet/oapp.json +50 -0
  158. package/deployments/iotal1-testnet/object-BlockedMessageLib.json +9 -0
  159. package/deployments/iotal1-testnet/object-BlockedMsglibPtbBuilder.json +9 -0
  160. package/deployments/iotal1-testnet/object-Counter.json +9 -0
  161. package/deployments/iotal1-testnet/object-CounterAdminCap.json +9 -0
  162. package/deployments/iotal1-testnet/object-CounterOApp.json +9 -0
  163. package/deployments/iotal1-testnet/object-DVN.json +5 -0
  164. package/deployments/iotal1-testnet/object-DVNCap.json +9 -0
  165. package/deployments/iotal1-testnet/object-DVNFeeLib.json +9 -0
  166. package/deployments/iotal1-testnet/object-EndpointPtbBuilder.json +9 -0
  167. package/deployments/iotal1-testnet/object-EndpointPtbBuilderAdminCap.json +9 -0
  168. package/deployments/iotal1-testnet/object-EndpointV2.json +9 -0
  169. package/deployments/iotal1-testnet/object-EndpointV2AdminCap.json +9 -0
  170. package/deployments/iotal1-testnet/object-Executor.json +5 -0
  171. package/deployments/iotal1-testnet/object-ExecutorCap.json +9 -0
  172. package/deployments/iotal1-testnet/object-ExecutorFeeLib.json +9 -0
  173. package/deployments/iotal1-testnet/object-ExecutorOwnerCap.json +5 -0
  174. package/deployments/iotal1-testnet/object-PackageWhitelistValidator.json +9 -0
  175. package/deployments/iotal1-testnet/object-PriceFeed.json +9 -0
  176. package/deployments/iotal1-testnet/object-PriceFeedOwnerCap.json +9 -0
  177. package/deployments/iotal1-testnet/object-SimpleMessageLib.json +9 -0
  178. package/deployments/iotal1-testnet/object-SimpleMessageLibAdminCap.json +9 -0
  179. package/deployments/iotal1-testnet/object-SmlPtbBuilder.json +9 -0
  180. package/deployments/iotal1-testnet/object-Treasury.json +9 -0
  181. package/deployments/iotal1-testnet/object-TreasuryAdminCap.json +9 -0
  182. package/deployments/iotal1-testnet/object-ULN302.json +9 -0
  183. package/deployments/iotal1-testnet/object-ULN302AdminCap.json +9 -0
  184. package/deployments/iotal1-testnet/object-Uln302PtbBuilder.json +9 -0
  185. package/deployments/iotal1-testnet/object-Uln302Verification.json +9 -0
  186. package/deployments/iotal1-testnet/object-WorkerRegistry.json +9 -0
  187. package/deployments/iotal1-testnet/object-ZroCoinMetadata.json +9 -0
  188. package/deployments/iotal1-testnet/object-ZroTreasuryCap.json +9 -0
  189. package/deployments/iotal1-testnet/package_whitelist_validator.json +113 -0
  190. package/deployments/iotal1-testnet/price_feed.json +70 -0
  191. package/deployments/iotal1-testnet/price_feed_call_types.json +45 -0
  192. package/deployments/iotal1-testnet/ptb_move_call.json +48 -0
  193. package/deployments/iotal1-testnet/simple_message_lib.json +69 -0
  194. package/deployments/iotal1-testnet/simple_msglib_ptb_builder.json +58 -0
  195. package/deployments/iotal1-testnet/treasury.json +69 -0
  196. package/deployments/iotal1-testnet/uln_302.json +87 -0
  197. package/deployments/iotal1-testnet/uln_302_ptb_builder.json +58 -0
  198. package/deployments/iotal1-testnet/uln_common.json +49 -0
  199. package/deployments/iotal1-testnet/utils.json +57 -0
  200. package/deployments/iotal1-testnet/worker_common.json +46 -0
  201. package/deployments/iotal1-testnet/worker_registry.json +58 -0
  202. package/deployments/iotal1-testnet/zro.json +67 -0
  203. package/dist/index.cjs +11279 -0
  204. package/dist/index.cjs.map +1 -0
  205. package/dist/index.d.mts +5824 -0
  206. package/dist/index.d.ts +5824 -0
  207. package/dist/index.mjs +11107 -0
  208. package/dist/index.mjs.map +1 -0
  209. package/package.json +68 -0
  210. package/src/bcs/dvn.ts +7 -0
  211. package/src/bcs/endpoint.ts +7 -0
  212. package/src/bcs/executor.ts +27 -0
  213. package/src/bcs/index.ts +8 -0
  214. package/src/bcs/messaging-fee.ts +6 -0
  215. package/src/bcs/move-call.ts +28 -0
  216. package/src/bcs/oapp.ts +14 -0
  217. package/src/bcs/price-feed.ts +21 -0
  218. package/src/bcs/uln.ts +15 -0
  219. package/src/generated/addresses.ts +344 -0
  220. package/src/index.ts +5 -0
  221. package/src/module-manager.ts +360 -0
  222. package/src/modules/call.ts +245 -0
  223. package/src/modules/endpoint.ts +2417 -0
  224. package/src/modules/index.ts +10 -0
  225. package/src/modules/layerzero-views.ts +205 -0
  226. package/src/modules/message-libs/blocked-message-lib.ts +112 -0
  227. package/src/modules/message-libs/index.ts +4 -0
  228. package/src/modules/message-libs/simple-message-lib.ts +270 -0
  229. package/src/modules/message-libs/uln302.ts +827 -0
  230. package/src/modules/oapps/counter.ts +458 -0
  231. package/src/modules/oapps/index.ts +3 -0
  232. package/src/modules/oapps/oapp.ts +744 -0
  233. package/src/modules/ptb-builders/blocked-message-lib-ptb-builder.ts +49 -0
  234. package/src/modules/ptb-builders/dvn-ptb-builder.ts +58 -0
  235. package/src/modules/ptb-builders/endpoint-ptb-builder.ts +520 -0
  236. package/src/modules/ptb-builders/executor-ptb-builder.ts +58 -0
  237. package/src/modules/ptb-builders/index.ts +9 -0
  238. package/src/modules/ptb-builders/package-whitelist-validator.ts +142 -0
  239. package/src/modules/ptb-builders/ptb-builder.ts +357 -0
  240. package/src/modules/ptb-builders/simple-message-lib-ptb-builder.ts +53 -0
  241. package/src/modules/ptb-builders/uln302-ptb-builder.ts +222 -0
  242. package/src/modules/utils.ts +902 -0
  243. package/src/modules/workers/dvn-fee-lib.ts +89 -0
  244. package/src/modules/workers/dvn-layerzero.ts +85 -0
  245. package/src/modules/workers/dvn.ts +1727 -0
  246. package/src/modules/workers/executor-fee-lib.ts +94 -0
  247. package/src/modules/workers/executor-layerzero.ts +79 -0
  248. package/src/modules/workers/executor.ts +1170 -0
  249. package/src/modules/workers/index.ts +10 -0
  250. package/src/modules/workers/price-feed.ts +575 -0
  251. package/src/modules/workers/treasury.ts +295 -0
  252. package/src/modules/workers/worker-registry.ts +110 -0
  253. package/src/modules/zro.ts +94 -0
  254. package/src/resource.ts +104 -0
  255. package/src/sdk.ts +183 -0
  256. package/src/types/dvn.ts +20 -0
  257. package/src/types/endpoint.ts +16 -0
  258. package/src/types/errors.ts +10 -0
  259. package/src/types/executor.ts +23 -0
  260. package/src/types/index.ts +13 -0
  261. package/src/types/layerzero-views.ts +59 -0
  262. package/src/types/message-lib.ts +38 -0
  263. package/src/types/modules.ts +36 -0
  264. package/src/types/move-types.ts +24 -0
  265. package/src/types/oapp.ts +6 -0
  266. package/src/types/options.ts +333 -0
  267. package/src/types/price-feed.ts +21 -0
  268. package/src/types/ptb-builder.ts +29 -0
  269. package/src/types/simulation.ts +8 -0
  270. package/src/utils/argument.ts +198 -0
  271. package/src/utils/index.ts +8 -0
  272. package/src/utils/move-call-object-fetcher.ts +105 -0
  273. package/src/utils/non-sender-object-validator.ts +102 -0
  274. package/src/utils/package-allowlist-validator.ts +134 -0
  275. package/src/utils/ptb-validator.ts +14 -0
  276. package/src/utils/share-object-validator.ts +37 -0
  277. package/src/utils/transaction.ts +157 -0
  278. package/src/utils/type-name.ts +99 -0
  279. package/src/utils/validate-with-details.ts +50 -0
@@ -0,0 +1,142 @@
1
+ import { bcs } from '@iota/iota-sdk/bcs'
2
+ import { IotaClient } from '@iota/iota-sdk/client'
3
+ import { Transaction, TransactionArgument, TransactionResult } from '@iota/iota-sdk/transactions'
4
+
5
+ import { ModuleManager } from '../../module-manager'
6
+ import { ObjectOptions } from '../../types'
7
+ import { asAddress, executeSimulate } from '../../utils'
8
+
9
+ const MODULE_NAME = 'package_whitelist_validator'
10
+
11
+ export const ValidatorErrorCode = {
12
+ // PTB Whitelist related errors
13
+ EInvalidWitness: 1,
14
+ } as const
15
+
16
+ export class PackageWhitelistValidator {
17
+ public packageId: string
18
+ public readonly client: IotaClient
19
+ private readonly objects: ObjectOptions
20
+
21
+ constructor(
22
+ packageId: string,
23
+ client: IotaClient,
24
+ objects: ObjectOptions,
25
+ private readonly moduleManager: ModuleManager
26
+ ) {
27
+ this.packageId = packageId
28
+ this.client = client
29
+ this.objects = objects
30
+ }
31
+
32
+ // === Whitelist Management Functions ===
33
+
34
+ /**
35
+ * Add a package to the whitelist using a LayerZero witness
36
+ * This function is permissionless and allows packages to self-register
37
+ * by providing a valid LayerZeroWitness type
38
+ * @param tx - The transaction to add the move call to
39
+ * @param witness - The LayerZero witness from the package
40
+ * @template T - The witness type that must be named "_witness::LayerZeroWitness"
41
+ */
42
+ addWhitelistMoveCall(tx: Transaction, witness: TransactionArgument, witnessType: string): void {
43
+ tx.moveCall({
44
+ target: this.#target('add_whitelist'),
45
+ typeArguments: [witnessType],
46
+ arguments: [tx.object(this.objects.packageWhitelistValidator), witness],
47
+ })
48
+ }
49
+
50
+ // === View Functions ===
51
+
52
+ /**
53
+ * Check if a package is whitelisted
54
+ * @param tx - The transaction to add the move call to
55
+ * @param packageAddress - The package address to check
56
+ * @returns Transaction result containing the whitelist status
57
+ */
58
+ isWhitelistedMoveCall(tx: Transaction, packageAddress: string | TransactionArgument): TransactionResult {
59
+ return tx.moveCall({
60
+ target: this.#target('is_whitelisted'),
61
+ arguments: [tx.object(this.objects.packageWhitelistValidator), asAddress(tx, packageAddress)],
62
+ })
63
+ }
64
+
65
+ /**
66
+ * Validate multiple packages at once
67
+ * @param tx - The transaction to add the move call to
68
+ * @param packageAddresses - Array of package addresses to validate
69
+ * @returns Transaction result containing the validation status
70
+ */
71
+ validateMoveCall(tx: Transaction, packageAddresses: string[]): TransactionResult {
72
+ return tx.moveCall({
73
+ target: this.#target('validate'),
74
+ arguments: [
75
+ tx.object(this.objects.packageWhitelistValidator),
76
+ tx.pure(bcs.vector(bcs.Address).serialize(packageAddresses)),
77
+ ],
78
+ })
79
+ }
80
+
81
+ /**
82
+ * Check if a package is whitelisted
83
+ * @param packageAddress - The package address to check
84
+ * @returns Promise<boolean> - True if the package is whitelisted
85
+ */
86
+ async isWhitelisted(packageAddress: string): Promise<boolean> {
87
+ return executeSimulate(
88
+ this.client,
89
+ (tx) => {
90
+ this.isWhitelistedMoveCall(tx, packageAddress)
91
+ },
92
+ (result) => bcs.Bool.parse(result[0].value)
93
+ )
94
+ }
95
+
96
+ // === Utility Functions ===
97
+
98
+ /**
99
+ * Extract package ID from a witness type name
100
+ * @param witnessTypeName - The full type name of the witness
101
+ * @returns string | null - The package ID if extraction is successful
102
+ */
103
+ extractPackageFromWitness(witnessTypeName: string): string | null {
104
+ // Pattern: "0x123abc::my_package_witness::LayerZeroWitness"
105
+ const parts = witnessTypeName.split('::')
106
+ if (parts.length >= 3) {
107
+ const packageId = parts[0]
108
+ if (packageId.startsWith('0x') && packageId.length > 2) {
109
+ return packageId
110
+ }
111
+ }
112
+ return null
113
+ }
114
+
115
+ // === Batch Operations ===
116
+
117
+ /**
118
+ * Validate multiple packages at once using the contract's validate function
119
+ * @param packageAddresses - Array of package addresses to validate
120
+ * @returns Promise<boolean> - True if all packages are whitelisted
121
+ */
122
+ async validate(packageAddresses: string[]): Promise<boolean> {
123
+ return executeSimulate(
124
+ this.client,
125
+ (tx) => {
126
+ this.validateMoveCall(tx, packageAddresses)
127
+ },
128
+ (result) => bcs.Bool.parse(result[0].value)
129
+ )
130
+ }
131
+
132
+ /**
133
+ * Generate the full target path for move calls
134
+ * @param name - The function name to call
135
+ * @param module_name - The module name (defaults to MODULE_NAME)
136
+ * @returns The full module path for the move call
137
+ * @private
138
+ */
139
+ #target(name: string, module_name = MODULE_NAME): string {
140
+ return `${this.packageId}::${module_name}::${name}`
141
+ }
142
+ }
@@ -0,0 +1,357 @@
1
+ import { bcs } from '@iota/iota-sdk/bcs'
2
+ import { IotaClient } from '@iota/iota-sdk/client'
3
+ import { Transaction, TransactionResult } from '@iota/iota-sdk/transactions'
4
+
5
+ import { OAppInfoV1Bcs, VectorMoveCallBCS } from '../../bcs'
6
+ import {
7
+ Argument,
8
+ BuilderPlaceholderInfo,
9
+ DEFAULT_SIMULATION_TIMES,
10
+ LzComposeVersion,
11
+ MoveCall,
12
+ OAppInfoVersion,
13
+ SimulateResult,
14
+ } from '../../types'
15
+ import { simulateTransaction } from '../../utils/transaction'
16
+ import { normalizeIotaPackageId } from '../../utils/type-name'
17
+
18
+ const MOVE_CALL_MODULE_NAME = 'move_call'
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
+
29
+ export class PtbBuilder {
30
+ public packageId: string
31
+ public readonly client: IotaClient
32
+
33
+ constructor(packageId: string, client: IotaClient) {
34
+ this.packageId = packageId
35
+ this.client = client
36
+ }
37
+
38
+ /**
39
+ * Simulate a transaction and decode the resulting move calls
40
+ * @param tx - The transaction to simulate
41
+ * @param sender - Optional sender address for simulation context
42
+ * @returns Promise resolving to array of decoded move calls
43
+ */
44
+ async simulatePtb(tx: Transaction, sender?: string): Promise<MoveCall[]> {
45
+ const ptbCallsResult = await simulateTransaction(this.client, tx, sender)
46
+ return this.#decodeMoveCalls(ptbCallsResult[0])
47
+ }
48
+
49
+ /**
50
+ * Simulate a LayerZero receive transaction and decode the move calls
51
+ * Handles versioned receive data and decodes based on version
52
+ * @param tx - The transaction to simulate
53
+ * @param sender - Optional sender address for simulation context
54
+ * @returns Promise resolving to array of decoded move calls
55
+ * @throws Error if unsupported version is encountered
56
+ */
57
+ async simulateLzReceivePtb(tx: Transaction, sender?: string): Promise<MoveCall[]> {
58
+ const ptbCallsResult = await simulateTransaction(this.client, tx, sender)
59
+ const buffer = Buffer.from(bcs.vector(bcs.u8()).parse(ptbCallsResult[0].value))
60
+
61
+ const version = buffer.readInt16BE()
62
+ if (version === OAppInfoVersion.VERSION_1) {
63
+ return this.#decodeMoveCallsFromOAppInfoV1(new Uint8Array(buffer.subarray(2)))
64
+ }
65
+ throw new Error(`Unknown version: ${version}`)
66
+ }
67
+
68
+ /**
69
+ * Simulate a LayerZero compose transaction and decode the move calls
70
+ * Handles versioned compose data and decodes based on version
71
+ * @param tx - The transaction to simulate
72
+ * @param sender - Optional sender address for simulation context
73
+ * @returns Promise resolving to array of decoded move calls
74
+ * @throws Error if unsupported version is encountered
75
+ */
76
+ async simulateLzComposePtb(tx: Transaction, sender?: string): Promise<MoveCall[]> {
77
+ const ptbCallsResult = await simulateTransaction(this.client, tx, sender)
78
+ const buffer = Buffer.from(bcs.vector(bcs.u8()).parse(ptbCallsResult[0].value))
79
+ const version = buffer.readInt16BE()
80
+ if (version === LzComposeVersion.VERSION_1) {
81
+ return this.#decodeMoveCallsBytes(new Uint8Array(buffer.subarray(2)))
82
+ }
83
+ throw new Error(`Unknown version: ${version}`)
84
+ }
85
+
86
+ /**
87
+ * Builds PTB with move-calls simulated from the transaction
88
+ *
89
+ * This method processes an array of move calls, handling both regular calls and builder calls
90
+ * (which require simulation to expand into actual move calls). It ensures all object arguments
91
+ * are properly validated for PTB compatibility.
92
+ *
93
+ * @param tx - The transaction to append move calls to
94
+ * @param moveCalls - Array of move calls to process and build
95
+ * @param resolutionIDs - Cache mapping call IDs to their transaction results for argument resolution (defaults to empty Map)
96
+ * @param sender - Optional sender address for simulation context (defaults to undefined)
97
+ * @param maxSimulationTimes - Maximum number of simulations allowed for builder calls (defaults to DEFAULT_SIMULATION_TIMES)
98
+ * @param nestedResult - Array storing results from previous calls for NestedResult argument resolution (internal use, defaults to empty array)
99
+ * @param baseOffset - Base offset for calculating nested result indices (internal use, defaults to 0)
100
+ *
101
+ * @returns Promise<[number, MoveCall[]]> - [moveCallCount, finalMoveCalls] tuple
102
+ *
103
+ * @throws Error if simulation limit is exceeded, nested results are unavailable, or objects are not PTB-compatible
104
+ */
105
+ async buildPtb(
106
+ tx: Transaction,
107
+ moveCalls: MoveCall[],
108
+ resolutionIDs = new Map<string, TransactionResult>(), // ID -> TransactionResult
109
+ sender: string | undefined = undefined,
110
+ maxSimulationTimes = DEFAULT_SIMULATION_TIMES,
111
+ // -- below are internal use only --
112
+ nestedResult: TransactionResult[] = [],
113
+ baseOffset = 0
114
+ ): Promise<[number, MoveCall[]]> {
115
+ const finalMoveCalls: MoveCall[] = [] // This array collects all move calls for validation
116
+ const moveCallCount = await this.#buildMoveCalls(
117
+ tx,
118
+ moveCalls,
119
+ resolutionIDs,
120
+ sender,
121
+ maxSimulationTimes,
122
+ finalMoveCalls,
123
+ nestedResult,
124
+ baseOffset
125
+ )
126
+
127
+ return [moveCallCount, finalMoveCalls]
128
+ }
129
+
130
+ /**
131
+ * Internal method to recursively build and process move calls
132
+ * Handles both regular and builder calls with simulation and argument resolution
133
+ * @param tx - The transaction to add move calls to
134
+ * @param moveCalls - Array of move calls to process
135
+ * @param resolutionIDs - Map for resolving call ID arguments
136
+ * @param sender - Optional sender address for simulation
137
+ * @param remainingSimulation - Remaining simulation attempts allowed
138
+ * @param finalMoveCalls - Array collecting all final move calls
139
+ * @param nestedResult - Array of transaction results for nested argument resolution
140
+ * @param baseOffset - Base offset for calculating nested result indices
141
+ * @returns Promise resolving to the number of move calls processed
142
+ * @private
143
+ */
144
+ async #buildMoveCalls(
145
+ tx: Transaction,
146
+ moveCalls: MoveCall[],
147
+ resolutionIDs: Map<string, TransactionResult>, // ID -> TransactionResult
148
+ sender: string | undefined = undefined,
149
+ // -- below are internal use only --
150
+ remainingSimulation: number,
151
+ finalMoveCalls: MoveCall[],
152
+ nestedResult: TransactionResult[] = [],
153
+ baseOffset = 0
154
+ ): Promise<number> {
155
+ if (!moveCalls.length) return 0
156
+ let builderMoveCallCount = 0 // current builder move_calls count
157
+ const placeholderInfos: BuilderPlaceholderInfo[] = []
158
+ for (let currentMoveCallIndex = 0; currentMoveCallIndex < moveCalls.length; currentMoveCallIndex++) {
159
+ const moveCall = moveCalls[currentMoveCallIndex]
160
+ // Create a copy to avoid mutating the original
161
+ const processedMoveCall = {
162
+ ...moveCall,
163
+ arguments: moveCall.arguments.map((arg) => {
164
+ // Adjust the index by the base offset and the placeholder count
165
+ if ('NestedResult' in arg) {
166
+ const [callIndex, resultIndex] = arg.NestedResult
167
+ const newCallIndex = this.#calculateOffset(callIndex, baseOffset, placeholderInfos)
168
+ const result: Argument = { NestedResult: [newCallIndex, resultIndex] }
169
+ return result
170
+ }
171
+ return arg
172
+ }),
173
+ }
174
+
175
+ if (!moveCall.is_builder_call) {
176
+ finalMoveCalls.push(processedMoveCall)
177
+ this.#appendMoveCall(tx, processedMoveCall, resolutionIDs, nestedResult, true)
178
+ } else {
179
+ builderMoveCallCount++
180
+
181
+ if (remainingSimulation <= 0) {
182
+ throw new Error('remainingSimulation is not enough')
183
+ }
184
+ remainingSimulation--
185
+ // The simluate tx is simluated to get the actual move calls of the contract to be replaced in the next layer
186
+ const simulateTx = Transaction.from(tx)
187
+ this.#appendMoveCall(simulateTx, processedMoveCall, resolutionIDs, nestedResult, false)
188
+ const newMoveCalls = await this.simulatePtb(simulateTx, sender)
189
+
190
+ // Replace the placeholder move calls with the actual move calls
191
+ const placeholderMoveCallCount = await this.#buildMoveCalls(
192
+ tx,
193
+ newMoveCalls,
194
+ resolutionIDs,
195
+ sender,
196
+ remainingSimulation,
197
+ finalMoveCalls,
198
+ nestedResult,
199
+ this.#calculateOffset(currentMoveCallIndex, baseOffset, placeholderInfos)
200
+ )
201
+ placeholderInfos.push({ index: currentMoveCallIndex, moveCallCount: placeholderMoveCallCount })
202
+ }
203
+ }
204
+ const placeholderMoveCallCount = placeholderInfos.reduce((acc, item) => acc + item.moveCallCount, 0)
205
+ return moveCalls.length - builderMoveCallCount + placeholderMoveCallCount
206
+ }
207
+
208
+ /**
209
+ * Append a move call to the transaction with argument resolution
210
+ * Handles different argument types and records results for future reference
211
+ * @param tx - The transaction to add the move call to
212
+ * @param moveCall - The move call to append
213
+ * @param resolutionIDs - Map for resolving call ID arguments
214
+ * @param nestedResult - Array to store transaction results
215
+ * @param directCall - Whether this is a direct call (affects result recording)
216
+ * @private
217
+ */
218
+ #appendMoveCall(
219
+ tx: Transaction,
220
+ moveCall: MoveCall,
221
+ resolutionIDs: Map<string, TransactionResult>, // ID -> TransactionResult
222
+ nestedResult: TransactionResult[],
223
+ directCall: boolean
224
+ ): void {
225
+ const moveCallParam = {
226
+ target: `${moveCall.function.package}::${moveCall.function.module_name}::${moveCall.function.name}`,
227
+ arguments: moveCall.arguments.map((arg) => {
228
+ if ('Object' in arg) {
229
+ return tx.object(arg.Object)
230
+ } else if ('Pure' in arg) {
231
+ return tx.pure(arg.Pure)
232
+ } else if ('NestedResult' in arg) {
233
+ const [callIndex, resultIndex] = arg.NestedResult
234
+ const moveCallResult = nestedResult[callIndex]
235
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,@typescript-eslint/strict-boolean-expressions
236
+ if (!moveCallResult || typeof moveCallResult[resultIndex] === 'undefined') {
237
+ throw new Error(`NestedResult resultIndex ${resultIndex} not available in call ${callIndex}`)
238
+ }
239
+ return moveCallResult[resultIndex]
240
+ } else if ('ID' in arg) {
241
+ // Replace the call parameters with the result from the call cache
242
+ const result = resolutionIDs.get(Buffer.from(arg.ID).toString('hex'))
243
+ if (result === undefined) {
244
+ throw new Error(
245
+ `Call substitution not found for "${Buffer.from(arg.ID).toString('hex')}" in cache`
246
+ )
247
+ }
248
+ return result
249
+ }
250
+ throw new Error(`Unknown argument variant: ${JSON.stringify(arg)}`)
251
+ }),
252
+ typeArguments: moveCall.type_arguments,
253
+ }
254
+
255
+ if (directCall) {
256
+ const result = tx.moveCall(moveCallParam)
257
+ // The nestedResult index is actually equal to the move_call's nested result index in the move_call_builder
258
+ nestedResult.push(result)
259
+ // Record output calls for downstream parameter replacement if there are output calls
260
+ if (moveCall.result_ids.length > 0) {
261
+ for (let i = 0; i < moveCall.result_ids.length; i++) {
262
+ const outputID = moveCall.result_ids[i]
263
+ // Validate that the result has enough outputs
264
+ if (i >= result.length) {
265
+ throw new Error(
266
+ `Move call result doesn't have output at index ${i} for call "${Buffer.from(outputID).toString('hex')}"`
267
+ )
268
+ }
269
+ const resultID = Buffer.from(outputID).toString('hex')
270
+ if (resolutionIDs.has(resultID)) {
271
+ throw new Error(`Move call result already exists for call "${resultID}"`)
272
+ }
273
+ resolutionIDs.set(resultID, result[i] as unknown as TransactionResult)
274
+ }
275
+ }
276
+ } else {
277
+ tx.moveCall(moveCallParam)
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Decode move calls from a simulation result
283
+ * @param viewResult - The simulation result containing move calls
284
+ * @returns Array of decoded move calls
285
+ * @throws Error if the result type doesn't match expected format
286
+ * @private
287
+ */
288
+ #decodeMoveCalls(viewResult: SimulateResult): MoveCall[] {
289
+ const { value, type } = viewResult
290
+ const vectorCallType =
291
+ `vector<${normalizeIotaPackageId(this.packageId, true, true)}::${MOVE_CALL_MODULE_NAME}::MoveCall>`.toLowerCase()
292
+ if (type.toLowerCase() !== vectorCallType) {
293
+ throw new Error(`not match the type: ${type.toLowerCase()} - expected ${vectorCallType}`)
294
+ }
295
+ return this.#decodeMoveCallsBytes(value)
296
+ }
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
+
303
+ /**
304
+ * Decode move calls from raw bytes
305
+ * @param bytes - The raw bytes containing encoded move calls
306
+ * @returns Array of decoded move calls
307
+ * @private
308
+ */
309
+ #decodeMoveCallsBytes(bytes: Uint8Array): MoveCall[] {
310
+ const moveCalls = VectorMoveCallBCS.parse(bytes)
311
+ return moveCalls.map((moveCall) => ({
312
+ function: {
313
+ package: moveCall.function.package,
314
+ module_name: moveCall.function.module_name,
315
+ name: moveCall.function.name,
316
+ },
317
+ arguments: moveCall.arguments.map((arg) => {
318
+ if (arg.ID !== undefined) {
319
+ return { ID: arg.ID }
320
+ } else if (arg.Object !== undefined) {
321
+ return { Object: arg.Object }
322
+ } else if (arg.Pure !== undefined) {
323
+ return { Pure: new Uint8Array(arg.Pure) }
324
+ } else {
325
+ // Must be NestedResult since we've handled other cases
326
+ return {
327
+ NestedResult: [arg.NestedResult.call_index, arg.NestedResult.result_index] as [number, number],
328
+ }
329
+ }
330
+ }),
331
+ type_arguments: moveCall.type_arguments,
332
+ result_ids: moveCall.result_ids.map((id) => Buffer.from(id)),
333
+ is_builder_call: moveCall.is_builder_call,
334
+ })) as MoveCall[]
335
+ }
336
+
337
+ /**
338
+ * Calculate the offset for nested result indices accounting for builder expansions
339
+ * @param index - The original index to calculate offset for
340
+ * @param baseOffset - The base offset to add
341
+ * @param placeholderInfos - Information about placeholder expansions
342
+ * @returns The calculated offset index
343
+ * @private
344
+ */
345
+ #calculateOffset(index: number, baseOffset: number, placeholderInfos: BuilderPlaceholderInfo[]): number {
346
+ let placeholderCount = 0
347
+ let placeholderMoveCallCount = 0
348
+ for (const placeholder of placeholderInfos) {
349
+ // builder move_call will not return any nested result, so only check index > placeholder.index
350
+ if (index > placeholder.index) {
351
+ placeholderMoveCallCount += placeholder.moveCallCount
352
+ placeholderCount++
353
+ }
354
+ }
355
+ return index - placeholderCount + placeholderMoveCallCount + baseOffset
356
+ }
357
+ }
@@ -0,0 +1,53 @@
1
+ import { IotaClient } from '@iota/iota-sdk/client'
2
+ import { Transaction, TransactionResult } from '@iota/iota-sdk/transactions'
3
+
4
+ import { ModuleManager } from '../../module-manager'
5
+ import { ObjectOptions } from '../../types'
6
+
7
+ const MODULE_NAME = 'simple_msglib_ptb_builder'
8
+
9
+ export class SimpleMessageLibPtbBuilder {
10
+ public packageId: string
11
+ public readonly client: IotaClient
12
+ private readonly objects: ObjectOptions
13
+
14
+ constructor(
15
+ packageId: string,
16
+ client: IotaClient,
17
+ objects: ObjectOptions,
18
+ private readonly moduleManager: ModuleManager
19
+ ) {
20
+ this.packageId = packageId
21
+ this.client = client
22
+ this.objects = objects
23
+ }
24
+
25
+ // === View Functions ===
26
+
27
+ /**
28
+ * Creates a transaction to get PTB builder info
29
+ * @param tx - The transaction to add the move call to
30
+ * @returns Transaction result containing PTB builder information
31
+ */
32
+ getPtbBuilderInfoMoveCall(tx: Transaction): TransactionResult {
33
+ return tx.moveCall({
34
+ target: this.#target('get_ptb_builder_info'),
35
+ arguments: [
36
+ tx.object(this.objects.simpleMessageLibPtbBuilder),
37
+ tx.object(this.objects.endpointV2),
38
+ tx.object(this.objects.simpleMessageLib),
39
+ ],
40
+ })
41
+ }
42
+
43
+ /**
44
+ * Generate the full target path for move calls
45
+ * @param name - The function name to call
46
+ * @param module_name - The module name (defaults to MODULE_NAME)
47
+ * @returns The full module path for the move call
48
+ * @private
49
+ */
50
+ #target(name: string, module_name = MODULE_NAME): string {
51
+ return `${this.packageId}::${module_name}::${name}`
52
+ }
53
+ }