@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.
- package/CHANGELOG.md +32 -0
- package/README.md +19 -0
- package/deployments/iotal1-mainnet/blocked_message_lib.json +58 -0
- package/deployments/iotal1-mainnet/blocked_msglib_ptb_builder.json +58 -0
- package/deployments/iotal1-mainnet/call.json +46 -0
- package/deployments/iotal1-mainnet/counter.json +85 -0
- package/deployments/iotal1-mainnet/dvn.json +49 -0
- package/deployments/iotal1-mainnet/dvn_call_type.json +45 -0
- package/deployments/iotal1-mainnet/dvn_fee_lib.json +59 -0
- package/deployments/iotal1-mainnet/dvn_layerzero.json +56 -0
- package/deployments/iotal1-mainnet/dvn_ptb_builder.json +45 -0
- package/deployments/iotal1-mainnet/endpoint_ptb_builder.json +70 -0
- package/deployments/iotal1-mainnet/endpoint_v2.json +86 -0
- package/deployments/iotal1-mainnet/executor.json +49 -0
- package/deployments/iotal1-mainnet/executor_call_type.json +45 -0
- package/deployments/iotal1-mainnet/executor_fee_lib.json +60 -0
- package/deployments/iotal1-mainnet/executor_layerzero.json +56 -0
- package/deployments/iotal1-mainnet/executor_ptb_builder.json +45 -0
- package/deployments/iotal1-mainnet/layerzero_views.json +46 -0
- package/deployments/iotal1-mainnet/message_lib_common.json +47 -0
- package/deployments/iotal1-mainnet/msglib_ptb_builder_call_types.json +45 -0
- package/deployments/iotal1-mainnet/multi_call.json +45 -0
- package/deployments/iotal1-mainnet/oapp.json +50 -0
- package/deployments/iotal1-mainnet/object-BlockedMessageLib.json +9 -0
- package/deployments/iotal1-mainnet/object-BlockedMsglibPtbBuilder.json +9 -0
- package/deployments/iotal1-mainnet/object-Counter.json +9 -0
- package/deployments/iotal1-mainnet/object-CounterAdminCap.json +9 -0
- package/deployments/iotal1-mainnet/object-CounterOApp.json +9 -0
- package/deployments/iotal1-mainnet/object-DVN.json +5 -0
- package/deployments/iotal1-mainnet/object-DVNCap.json +9 -0
- package/deployments/iotal1-mainnet/object-DVNFeeLib.json +9 -0
- package/deployments/iotal1-mainnet/object-EndpointPtbBuilder.json +9 -0
- package/deployments/iotal1-mainnet/object-EndpointPtbBuilderAdminCap.json +9 -0
- package/deployments/iotal1-mainnet/object-EndpointV2.json +9 -0
- package/deployments/iotal1-mainnet/object-EndpointV2AdminCap.json +9 -0
- package/deployments/iotal1-mainnet/object-Executor.json +5 -0
- package/deployments/iotal1-mainnet/object-ExecutorCap.json +9 -0
- package/deployments/iotal1-mainnet/object-ExecutorFeeLib.json +9 -0
- package/deployments/iotal1-mainnet/object-ExecutorOwnerCap.json +5 -0
- package/deployments/iotal1-mainnet/object-OFTComposerManager.json +9 -0
- package/deployments/iotal1-mainnet/object-PackageWhitelistValidator.json +9 -0
- package/deployments/iotal1-mainnet/object-PriceFeed.json +9 -0
- package/deployments/iotal1-mainnet/object-PriceFeedOwnerCap.json +9 -0
- package/deployments/iotal1-mainnet/object-SimpleMessageLib.json +9 -0
- package/deployments/iotal1-mainnet/object-SimpleMessageLibAdminCap.json +9 -0
- package/deployments/iotal1-mainnet/object-SmlPtbBuilder.json +9 -0
- package/deployments/iotal1-mainnet/object-Treasury.json +9 -0
- package/deployments/iotal1-mainnet/object-TreasuryAdminCap.json +9 -0
- package/deployments/iotal1-mainnet/object-ULN302.json +9 -0
- package/deployments/iotal1-mainnet/object-ULN302AdminCap.json +9 -0
- package/deployments/iotal1-mainnet/object-Uln302PtbBuilder.json +9 -0
- package/deployments/iotal1-mainnet/object-Uln302Verification.json +9 -0
- package/deployments/iotal1-mainnet/object-WorkerRegistry.json +9 -0
- package/deployments/iotal1-mainnet/object-ZroCoinMetadata.json +9 -0
- package/deployments/iotal1-mainnet/object-ZroTreasuryCap.json +9 -0
- package/deployments/iotal1-mainnet/oft_common.json +61 -0
- package/deployments/iotal1-mainnet/package_whitelist_validator.json +113 -0
- package/deployments/iotal1-mainnet/price_feed.json +70 -0
- package/deployments/iotal1-mainnet/price_feed_call_types.json +45 -0
- package/deployments/iotal1-mainnet/ptb_move_call.json +48 -0
- package/deployments/iotal1-mainnet/simple_message_lib.json +69 -0
- package/deployments/iotal1-mainnet/simple_msglib_ptb_builder.json +58 -0
- package/deployments/iotal1-mainnet/treasury.json +69 -0
- package/deployments/iotal1-mainnet/uln_302.json +87 -0
- package/deployments/iotal1-mainnet/uln_302_ptb_builder.json +58 -0
- package/deployments/iotal1-mainnet/uln_common.json +49 -0
- package/deployments/iotal1-mainnet/utils.json +57 -0
- package/deployments/iotal1-mainnet/worker_common.json +46 -0
- package/deployments/iotal1-mainnet/worker_registry.json +58 -0
- package/deployments/iotal1-mainnet/zro.json +67 -0
- package/deployments/iotal1-sandbox-local/blocked_message_lib.json +58 -0
- package/deployments/iotal1-sandbox-local/blocked_msglib_ptb_builder.json +58 -0
- package/deployments/iotal1-sandbox-local/call.json +46 -0
- package/deployments/iotal1-sandbox-local/counter.json +148 -0
- package/deployments/iotal1-sandbox-local/dvn.json +49 -0
- package/deployments/iotal1-sandbox-local/dvn_call_type.json +73 -0
- package/deployments/iotal1-sandbox-local/dvn_fee_lib.json +59 -0
- package/deployments/iotal1-sandbox-local/dvn_layerzero.json +56 -0
- package/deployments/iotal1-sandbox-local/dvn_ptb_builder.json +45 -0
- package/deployments/iotal1-sandbox-local/endpoint_ptb_builder.json +70 -0
- package/deployments/iotal1-sandbox-local/endpoint_v2.json +86 -0
- package/deployments/iotal1-sandbox-local/executor.json +49 -0
- package/deployments/iotal1-sandbox-local/executor_call_type.json +73 -0
- package/deployments/iotal1-sandbox-local/executor_fee_lib.json +60 -0
- package/deployments/iotal1-sandbox-local/executor_layerzero.json +56 -0
- package/deployments/iotal1-sandbox-local/executor_ptb_builder.json +45 -0
- package/deployments/iotal1-sandbox-local/layerzero_views.json +46 -0
- package/deployments/iotal1-sandbox-local/message_lib_common.json +47 -0
- package/deployments/iotal1-sandbox-local/msglib_ptb_builder_call_types.json +45 -0
- package/deployments/iotal1-sandbox-local/multi_call.json +45 -0
- package/deployments/iotal1-sandbox-local/oapp.json +50 -0
- package/deployments/iotal1-sandbox-local/object-BlockedMessageLib.json +9 -0
- package/deployments/iotal1-sandbox-local/object-BlockedMsglibPtbBuilder.json +9 -0
- package/deployments/iotal1-sandbox-local/object-Counter.json +9 -0
- package/deployments/iotal1-sandbox-local/object-CounterAdminCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-CounterOApp.json +9 -0
- package/deployments/iotal1-sandbox-local/object-DVN.json +5 -0
- package/deployments/iotal1-sandbox-local/object-DVNCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-DVNFeeLib.json +9 -0
- package/deployments/iotal1-sandbox-local/object-EndpointPtbBuilder.json +9 -0
- package/deployments/iotal1-sandbox-local/object-EndpointPtbBuilderAdminCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-EndpointV2.json +9 -0
- package/deployments/iotal1-sandbox-local/object-EndpointV2AdminCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-Executor.json +5 -0
- package/deployments/iotal1-sandbox-local/object-ExecutorCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-ExecutorFeeLib.json +9 -0
- package/deployments/iotal1-sandbox-local/object-ExecutorOwnerCap.json +5 -0
- package/deployments/iotal1-sandbox-local/object-PackageWhitelistValidator.json +9 -0
- package/deployments/iotal1-sandbox-local/object-PriceFeed.json +9 -0
- package/deployments/iotal1-sandbox-local/object-PriceFeedOwnerCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-SimpleMessageLib.json +9 -0
- package/deployments/iotal1-sandbox-local/object-SimpleMessageLibAdminCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-SmlPtbBuilder.json +9 -0
- package/deployments/iotal1-sandbox-local/object-Treasury.json +9 -0
- package/deployments/iotal1-sandbox-local/object-TreasuryAdminCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-ULN302.json +9 -0
- package/deployments/iotal1-sandbox-local/object-ULN302AdminCap.json +9 -0
- package/deployments/iotal1-sandbox-local/object-Uln302PtbBuilder.json +9 -0
- package/deployments/iotal1-sandbox-local/object-Uln302Verification.json +9 -0
- package/deployments/iotal1-sandbox-local/object-WorkerRegistry.json +9 -0
- package/deployments/iotal1-sandbox-local/object-ZroCoinMetadata.json +9 -0
- package/deployments/iotal1-sandbox-local/object-ZroTreasuryCap.json +9 -0
- package/deployments/iotal1-sandbox-local/package_whitelist_validator.json +113 -0
- package/deployments/iotal1-sandbox-local/price_feed.json +98 -0
- package/deployments/iotal1-sandbox-local/price_feed_call_types.json +45 -0
- package/deployments/iotal1-sandbox-local/ptb_move_call.json +48 -0
- package/deployments/iotal1-sandbox-local/simple_message_lib.json +69 -0
- package/deployments/iotal1-sandbox-local/simple_msglib_ptb_builder.json +58 -0
- package/deployments/iotal1-sandbox-local/treasury.json +97 -0
- package/deployments/iotal1-sandbox-local/uln_302.json +87 -0
- package/deployments/iotal1-sandbox-local/uln_302_ptb_builder.json +58 -0
- package/deployments/iotal1-sandbox-local/uln_common.json +49 -0
- package/deployments/iotal1-sandbox-local/utils.json +78 -0
- package/deployments/iotal1-sandbox-local/worker_common.json +46 -0
- package/deployments/iotal1-sandbox-local/worker_registry.json +58 -0
- package/deployments/iotal1-sandbox-local/zro.json +67 -0
- package/deployments/iotal1-testnet/blocked_message_lib.json +58 -0
- package/deployments/iotal1-testnet/blocked_msglib_ptb_builder.json +58 -0
- package/deployments/iotal1-testnet/call.json +46 -0
- package/deployments/iotal1-testnet/counter.json +85 -0
- package/deployments/iotal1-testnet/dvn.json +49 -0
- package/deployments/iotal1-testnet/dvn_call_type.json +45 -0
- package/deployments/iotal1-testnet/dvn_fee_lib.json +59 -0
- package/deployments/iotal1-testnet/dvn_layerzero.json +56 -0
- package/deployments/iotal1-testnet/dvn_ptb_builder.json +45 -0
- package/deployments/iotal1-testnet/endpoint_ptb_builder.json +70 -0
- package/deployments/iotal1-testnet/endpoint_v2.json +86 -0
- package/deployments/iotal1-testnet/executor.json +49 -0
- package/deployments/iotal1-testnet/executor_call_type.json +45 -0
- package/deployments/iotal1-testnet/executor_fee_lib.json +60 -0
- package/deployments/iotal1-testnet/executor_layerzero.json +56 -0
- package/deployments/iotal1-testnet/executor_ptb_builder.json +45 -0
- package/deployments/iotal1-testnet/layerzero_views.json +46 -0
- package/deployments/iotal1-testnet/message_lib_common.json +47 -0
- package/deployments/iotal1-testnet/msglib_ptb_builder_call_types.json +45 -0
- package/deployments/iotal1-testnet/multi_call.json +45 -0
- package/deployments/iotal1-testnet/oapp.json +50 -0
- package/deployments/iotal1-testnet/object-BlockedMessageLib.json +9 -0
- package/deployments/iotal1-testnet/object-BlockedMsglibPtbBuilder.json +9 -0
- package/deployments/iotal1-testnet/object-Counter.json +9 -0
- package/deployments/iotal1-testnet/object-CounterAdminCap.json +9 -0
- package/deployments/iotal1-testnet/object-CounterOApp.json +9 -0
- package/deployments/iotal1-testnet/object-DVN.json +5 -0
- package/deployments/iotal1-testnet/object-DVNCap.json +9 -0
- package/deployments/iotal1-testnet/object-DVNFeeLib.json +9 -0
- package/deployments/iotal1-testnet/object-EndpointPtbBuilder.json +9 -0
- package/deployments/iotal1-testnet/object-EndpointPtbBuilderAdminCap.json +9 -0
- package/deployments/iotal1-testnet/object-EndpointV2.json +9 -0
- package/deployments/iotal1-testnet/object-EndpointV2AdminCap.json +9 -0
- package/deployments/iotal1-testnet/object-Executor.json +5 -0
- package/deployments/iotal1-testnet/object-ExecutorCap.json +9 -0
- package/deployments/iotal1-testnet/object-ExecutorFeeLib.json +9 -0
- package/deployments/iotal1-testnet/object-ExecutorOwnerCap.json +5 -0
- package/deployments/iotal1-testnet/object-PackageWhitelistValidator.json +9 -0
- package/deployments/iotal1-testnet/object-PriceFeed.json +9 -0
- package/deployments/iotal1-testnet/object-PriceFeedOwnerCap.json +9 -0
- package/deployments/iotal1-testnet/object-SimpleMessageLib.json +9 -0
- package/deployments/iotal1-testnet/object-SimpleMessageLibAdminCap.json +9 -0
- package/deployments/iotal1-testnet/object-SmlPtbBuilder.json +9 -0
- package/deployments/iotal1-testnet/object-Treasury.json +9 -0
- package/deployments/iotal1-testnet/object-TreasuryAdminCap.json +9 -0
- package/deployments/iotal1-testnet/object-ULN302.json +9 -0
- package/deployments/iotal1-testnet/object-ULN302AdminCap.json +9 -0
- package/deployments/iotal1-testnet/object-Uln302PtbBuilder.json +9 -0
- package/deployments/iotal1-testnet/object-Uln302Verification.json +9 -0
- package/deployments/iotal1-testnet/object-WorkerRegistry.json +9 -0
- package/deployments/iotal1-testnet/object-ZroCoinMetadata.json +9 -0
- package/deployments/iotal1-testnet/object-ZroTreasuryCap.json +9 -0
- package/deployments/iotal1-testnet/package_whitelist_validator.json +113 -0
- package/deployments/iotal1-testnet/price_feed.json +70 -0
- package/deployments/iotal1-testnet/price_feed_call_types.json +45 -0
- package/deployments/iotal1-testnet/ptb_move_call.json +48 -0
- package/deployments/iotal1-testnet/simple_message_lib.json +69 -0
- package/deployments/iotal1-testnet/simple_msglib_ptb_builder.json +58 -0
- package/deployments/iotal1-testnet/treasury.json +69 -0
- package/deployments/iotal1-testnet/uln_302.json +87 -0
- package/deployments/iotal1-testnet/uln_302_ptb_builder.json +58 -0
- package/deployments/iotal1-testnet/uln_common.json +49 -0
- package/deployments/iotal1-testnet/utils.json +57 -0
- package/deployments/iotal1-testnet/worker_common.json +46 -0
- package/deployments/iotal1-testnet/worker_registry.json +58 -0
- package/deployments/iotal1-testnet/zro.json +67 -0
- package/dist/index.cjs +11279 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +5824 -0
- package/dist/index.d.ts +5824 -0
- package/dist/index.mjs +11107 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -0
- package/src/bcs/dvn.ts +7 -0
- package/src/bcs/endpoint.ts +7 -0
- package/src/bcs/executor.ts +27 -0
- package/src/bcs/index.ts +8 -0
- package/src/bcs/messaging-fee.ts +6 -0
- package/src/bcs/move-call.ts +28 -0
- package/src/bcs/oapp.ts +14 -0
- package/src/bcs/price-feed.ts +21 -0
- package/src/bcs/uln.ts +15 -0
- package/src/generated/addresses.ts +344 -0
- package/src/index.ts +5 -0
- package/src/module-manager.ts +360 -0
- package/src/modules/call.ts +245 -0
- package/src/modules/endpoint.ts +2417 -0
- package/src/modules/index.ts +10 -0
- package/src/modules/layerzero-views.ts +205 -0
- package/src/modules/message-libs/blocked-message-lib.ts +112 -0
- package/src/modules/message-libs/index.ts +4 -0
- package/src/modules/message-libs/simple-message-lib.ts +270 -0
- package/src/modules/message-libs/uln302.ts +827 -0
- package/src/modules/oapps/counter.ts +458 -0
- package/src/modules/oapps/index.ts +3 -0
- package/src/modules/oapps/oapp.ts +744 -0
- package/src/modules/ptb-builders/blocked-message-lib-ptb-builder.ts +49 -0
- package/src/modules/ptb-builders/dvn-ptb-builder.ts +58 -0
- package/src/modules/ptb-builders/endpoint-ptb-builder.ts +520 -0
- package/src/modules/ptb-builders/executor-ptb-builder.ts +58 -0
- package/src/modules/ptb-builders/index.ts +9 -0
- package/src/modules/ptb-builders/package-whitelist-validator.ts +142 -0
- package/src/modules/ptb-builders/ptb-builder.ts +357 -0
- package/src/modules/ptb-builders/simple-message-lib-ptb-builder.ts +53 -0
- package/src/modules/ptb-builders/uln302-ptb-builder.ts +222 -0
- package/src/modules/utils.ts +902 -0
- package/src/modules/workers/dvn-fee-lib.ts +89 -0
- package/src/modules/workers/dvn-layerzero.ts +85 -0
- package/src/modules/workers/dvn.ts +1727 -0
- package/src/modules/workers/executor-fee-lib.ts +94 -0
- package/src/modules/workers/executor-layerzero.ts +79 -0
- package/src/modules/workers/executor.ts +1170 -0
- package/src/modules/workers/index.ts +10 -0
- package/src/modules/workers/price-feed.ts +575 -0
- package/src/modules/workers/treasury.ts +295 -0
- package/src/modules/workers/worker-registry.ts +110 -0
- package/src/modules/zro.ts +94 -0
- package/src/resource.ts +104 -0
- package/src/sdk.ts +183 -0
- package/src/types/dvn.ts +20 -0
- package/src/types/endpoint.ts +16 -0
- package/src/types/errors.ts +10 -0
- package/src/types/executor.ts +23 -0
- package/src/types/index.ts +13 -0
- package/src/types/layerzero-views.ts +59 -0
- package/src/types/message-lib.ts +38 -0
- package/src/types/modules.ts +36 -0
- package/src/types/move-types.ts +24 -0
- package/src/types/oapp.ts +6 -0
- package/src/types/options.ts +333 -0
- package/src/types/price-feed.ts +21 -0
- package/src/types/ptb-builder.ts +29 -0
- package/src/types/simulation.ts +8 -0
- package/src/utils/argument.ts +198 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/move-call-object-fetcher.ts +105 -0
- package/src/utils/non-sender-object-validator.ts +102 -0
- package/src/utils/package-allowlist-validator.ts +134 -0
- package/src/utils/ptb-validator.ts +14 -0
- package/src/utils/share-object-validator.ts +37 -0
- package/src/utils/transaction.ts +157 -0
- package/src/utils/type-name.ts +99 -0
- 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
|
+
}
|