@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,2417 @@
|
|
|
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 { MessagingFeeBcs, TimeoutBcs } from '../bcs'
|
|
6
|
+
import { ModuleManager } from '../module-manager'
|
|
7
|
+
import {
|
|
8
|
+
CallTypeName,
|
|
9
|
+
DEFAULT_SIMULATION_TIMES,
|
|
10
|
+
LzTypeName,
|
|
11
|
+
MessageLibType,
|
|
12
|
+
MessagingFee,
|
|
13
|
+
MoveCall,
|
|
14
|
+
ObjectOptions,
|
|
15
|
+
Timeout,
|
|
16
|
+
} from '../types'
|
|
17
|
+
import {
|
|
18
|
+
asAddress,
|
|
19
|
+
asArgWithTx,
|
|
20
|
+
asBytes,
|
|
21
|
+
asBytes32,
|
|
22
|
+
asObject,
|
|
23
|
+
asString,
|
|
24
|
+
asU16,
|
|
25
|
+
asU32,
|
|
26
|
+
asU64,
|
|
27
|
+
executeSimulate,
|
|
28
|
+
simulateTransaction,
|
|
29
|
+
} from '../utils'
|
|
30
|
+
import { PackageAllowlistValidator } from '../utils/package-allowlist-validator'
|
|
31
|
+
import { IPTBValidator } from '../utils/ptb-validator'
|
|
32
|
+
import { ShareObjectValidator } from '../utils/share-object-validator'
|
|
33
|
+
import { callId, getTypeName } from '../utils/type-name'
|
|
34
|
+
import { validateWithDetails } from '../utils/validate-with-details'
|
|
35
|
+
|
|
36
|
+
const MODULE_NAME = 'endpoint_v2'
|
|
37
|
+
|
|
38
|
+
export const EndpointErrorCode = {
|
|
39
|
+
// MessageLibManager related errors (with MessageLibManager_ prefix)
|
|
40
|
+
MessageLibManager_EAlreadyRegistered: 1,
|
|
41
|
+
MessageLibManager_EDefaultReceiveLibUnavailable: 2,
|
|
42
|
+
MessageLibManager_EDefaultSendLibUnavailable: 3,
|
|
43
|
+
MessageLibManager_EInvalidAddress: 4,
|
|
44
|
+
MessageLibManager_EInvalidBounds: 5,
|
|
45
|
+
MessageLibManager_EInvalidExpiry: 6,
|
|
46
|
+
MessageLibManager_EInvalidReceiveLib: 7,
|
|
47
|
+
MessageLibManager_EOnlyNonDefaultLib: 8,
|
|
48
|
+
MessageLibManager_EOnlyReceiveLib: 9,
|
|
49
|
+
MessageLibManager_EOnlyRegisteredLib: 10,
|
|
50
|
+
MessageLibManager_EOnlySendLib: 11,
|
|
51
|
+
MessageLibManager_ESameValue: 12,
|
|
52
|
+
|
|
53
|
+
MessagingChannel_EAlreadyInitialized: 1,
|
|
54
|
+
MessagingChannel_EInsufficientNativeFee: 2,
|
|
55
|
+
MessagingChannel_EInsufficientZroFee: 3,
|
|
56
|
+
MessagingChannel_EInvalidNonce: 4,
|
|
57
|
+
MessagingChannel_EInvalidOApp: 5,
|
|
58
|
+
MessagingChannel_EInvalidPayloadHash: 6,
|
|
59
|
+
MessagingChannel_ENotSending: 7,
|
|
60
|
+
MessagingChannel_EPathNotVerifiable: 8,
|
|
61
|
+
MessagingChannel_EPayloadHashNotFound: 9,
|
|
62
|
+
MessagingChannel_ESendReentrancy: 10,
|
|
63
|
+
MessagingChannel_EUninitializedChannel: 11,
|
|
64
|
+
|
|
65
|
+
// MessagingComposer related errors (with MessagingComposer_ prefix)
|
|
66
|
+
MessagingComposer_EComposeExists: 1,
|
|
67
|
+
MessagingComposer_EComposeMessageMismatch: 2,
|
|
68
|
+
MessagingComposer_EComposeNotFound: 3,
|
|
69
|
+
MessagingComposer_EComposerNotRegistered: 4,
|
|
70
|
+
MessagingComposer_EComposerRegistered: 5,
|
|
71
|
+
// OAppRegistry related errors (with OAppRegistry_ prefix)
|
|
72
|
+
OAppRegistry_EOAppNotRegistered: 1,
|
|
73
|
+
OAppRegistry_EOAppRegistered: 2,
|
|
74
|
+
|
|
75
|
+
// Endpoint related errors (with Endpoint_ prefix)
|
|
76
|
+
Endpoint_EAlreadyInitialized: 1,
|
|
77
|
+
Endpoint_EInvalidEid: 2,
|
|
78
|
+
Endpoint_ENotInitialized: 3,
|
|
79
|
+
Endpoint_ERefundAddressNotFound: 4,
|
|
80
|
+
Endpoint_EUnauthorizedOApp: 5,
|
|
81
|
+
Endpoint_EUnauthorizedSendLibrary: 6,
|
|
82
|
+
} as const
|
|
83
|
+
|
|
84
|
+
export class Endpoint {
|
|
85
|
+
public packageId: string
|
|
86
|
+
public readonly client: IotaClient
|
|
87
|
+
private readonly objects: ObjectOptions
|
|
88
|
+
|
|
89
|
+
constructor(
|
|
90
|
+
packageId: string,
|
|
91
|
+
client: IotaClient,
|
|
92
|
+
objects: ObjectOptions,
|
|
93
|
+
private readonly moduleManager: ModuleManager
|
|
94
|
+
) {
|
|
95
|
+
this.packageId = packageId
|
|
96
|
+
this.client = client
|
|
97
|
+
this.objects = objects
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// === Set Functions ===
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Initialize the endpoint with an Endpoint ID (EID)
|
|
104
|
+
* @param tx - The transaction to add the move call to
|
|
105
|
+
* @param eid - The endpoint ID to initialize or transaction argument
|
|
106
|
+
*/
|
|
107
|
+
initEidMoveCall(tx: Transaction, eid: number | TransactionArgument): void {
|
|
108
|
+
tx.moveCall({
|
|
109
|
+
target: this.#target('init_eid'),
|
|
110
|
+
arguments: [tx.object(this.objects.endpointV2), tx.object(this.objects.endpointAdminCap), asU32(tx, eid)],
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ===== OApp Messaging Functions =====
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Register an OApp with the endpoint
|
|
118
|
+
* @param tx - The transaction to add the move call to
|
|
119
|
+
* @param oappCap - The OApp capability object ID or transaction argument
|
|
120
|
+
* @param oappInfo - OApp information including lz_receive execution information
|
|
121
|
+
* @returns Transaction result containing the messaging channel address
|
|
122
|
+
*/
|
|
123
|
+
registerOAppMoveCall(
|
|
124
|
+
tx: Transaction,
|
|
125
|
+
oappCap: string | TransactionArgument,
|
|
126
|
+
oappInfo: Uint8Array | TransactionArgument
|
|
127
|
+
): TransactionResult {
|
|
128
|
+
return tx.moveCall({
|
|
129
|
+
target: this.#target('register_oapp'),
|
|
130
|
+
arguments: [tx.object(this.objects.endpointV2), asObject(tx, oappCap), asBytes(tx, oappInfo)],
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Set a delegate for an OApp
|
|
136
|
+
* @param tx - The transaction to add the move call to
|
|
137
|
+
* @param oappCap - The OApp capability object ID or transaction argument
|
|
138
|
+
* @param newDelegate - The new delegate address or transaction argument
|
|
139
|
+
*/
|
|
140
|
+
setDelegateMoveCall(
|
|
141
|
+
tx: Transaction,
|
|
142
|
+
oappCap: string | TransactionArgument,
|
|
143
|
+
newDelegate: string | TransactionArgument
|
|
144
|
+
): void {
|
|
145
|
+
tx.moveCall({
|
|
146
|
+
target: this.#target('set_delegate'),
|
|
147
|
+
arguments: [tx.object(this.objects.endpointV2), asObject(tx, oappCap), asAddress(tx, newDelegate)],
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Set OApp information for an OApp
|
|
153
|
+
* @param tx - The transaction to add the move call to
|
|
154
|
+
* @param callerCap - The caller capability object ID or transaction argument
|
|
155
|
+
* @param oapp - The OApp address or transaction argument
|
|
156
|
+
* @param oappInfo - The OApp information including lz_receive execution information as bytes or transaction argument
|
|
157
|
+
*/
|
|
158
|
+
setOappInfoMoveCall(
|
|
159
|
+
tx: Transaction,
|
|
160
|
+
callerCap: string | TransactionArgument,
|
|
161
|
+
oapp: string | TransactionArgument,
|
|
162
|
+
oappInfo: Uint8Array | TransactionArgument
|
|
163
|
+
): void {
|
|
164
|
+
tx.moveCall({
|
|
165
|
+
target: this.#target('set_oapp_info'),
|
|
166
|
+
arguments: [
|
|
167
|
+
tx.object(this.objects.endpointV2),
|
|
168
|
+
asObject(tx, callerCap),
|
|
169
|
+
asAddress(tx, oapp),
|
|
170
|
+
asBytes(tx, oappInfo),
|
|
171
|
+
],
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Initialize a messaging channel between local and remote OApps
|
|
177
|
+
* @param tx - The transaction to add the move call to
|
|
178
|
+
* @param callerCap - The caller capability object ID or transaction argument
|
|
179
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
180
|
+
* @param remoteEid - The remote endpoint ID or transaction argument
|
|
181
|
+
* @param remoteOapp - The remote OApp address as bytes or transaction argument
|
|
182
|
+
*/
|
|
183
|
+
initChannelMoveCall(
|
|
184
|
+
tx: Transaction,
|
|
185
|
+
callerCap: string | TransactionArgument,
|
|
186
|
+
messagingChannel: string | TransactionArgument,
|
|
187
|
+
remoteEid: number | TransactionArgument,
|
|
188
|
+
remoteOapp: Uint8Array | TransactionArgument
|
|
189
|
+
): void {
|
|
190
|
+
tx.moveCall({
|
|
191
|
+
target: this.#target('init_channel'),
|
|
192
|
+
arguments: [
|
|
193
|
+
tx.object(this.objects.endpointV2),
|
|
194
|
+
asObject(tx, callerCap),
|
|
195
|
+
asObject(tx, messagingChannel),
|
|
196
|
+
asU32(tx, remoteEid),
|
|
197
|
+
asBytes32(tx, remoteOapp, this.moduleManager.getUtils()),
|
|
198
|
+
],
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Quote the messaging fee for sending a message
|
|
204
|
+
* @param tx - The transaction to add the move call to
|
|
205
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
206
|
+
* @param call - The call transaction result
|
|
207
|
+
* @returns Transaction result containing the quote
|
|
208
|
+
*/
|
|
209
|
+
quoteMoveCall(
|
|
210
|
+
tx: Transaction,
|
|
211
|
+
messagingChannel: string | TransactionArgument,
|
|
212
|
+
call: TransactionArgument
|
|
213
|
+
): TransactionResult {
|
|
214
|
+
return tx.moveCall({
|
|
215
|
+
target: this.#target('quote'),
|
|
216
|
+
arguments: [tx.object(this.objects.endpointV2), asObject(tx, messagingChannel), call],
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Confirm quote operation with message library
|
|
222
|
+
* @param tx - The transaction to add the move call to
|
|
223
|
+
* @param endpointCall - The endpoint call transaction result or transaction argument
|
|
224
|
+
* @param messageLibCall - The message library call transaction result or transaction argument
|
|
225
|
+
*/
|
|
226
|
+
confirmQuoteMoveCall(
|
|
227
|
+
tx: Transaction,
|
|
228
|
+
endpointCall: TransactionArgument,
|
|
229
|
+
messageLibCall: TransactionArgument
|
|
230
|
+
): void {
|
|
231
|
+
tx.moveCall({
|
|
232
|
+
target: this.#target('confirm_quote'),
|
|
233
|
+
arguments: [tx.object(this.objects.endpointV2), endpointCall, messageLibCall],
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Send a message through the messaging channel
|
|
239
|
+
* @param tx - The transaction to add the move call to
|
|
240
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
241
|
+
* @param call - The call transaction result
|
|
242
|
+
* @returns Transaction result containing the send operation
|
|
243
|
+
*/
|
|
244
|
+
sendMoveCall(
|
|
245
|
+
tx: Transaction,
|
|
246
|
+
messagingChannel: string | TransactionArgument,
|
|
247
|
+
call: TransactionArgument
|
|
248
|
+
): TransactionResult {
|
|
249
|
+
return tx.moveCall({
|
|
250
|
+
target: this.#target('send'),
|
|
251
|
+
arguments: [tx.object(this.objects.endpointV2), asObject(tx, messagingChannel), call],
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Confirm send operation with send library
|
|
257
|
+
* @param tx - The transaction to add the move call to
|
|
258
|
+
* @param sendLibrary - The send library object ID or transaction argument
|
|
259
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
260
|
+
* @param endpointCall - The endpoint call transaction result
|
|
261
|
+
* @param sendLibraryCall - The send library call transaction result
|
|
262
|
+
* @returns Transaction result containing the confirmed send operation
|
|
263
|
+
*/
|
|
264
|
+
confirmSendMoveCall(
|
|
265
|
+
tx: Transaction,
|
|
266
|
+
sendLibrary: string | TransactionArgument,
|
|
267
|
+
messagingChannel: string | TransactionArgument,
|
|
268
|
+
endpointCall: TransactionArgument,
|
|
269
|
+
sendLibraryCall: TransactionArgument
|
|
270
|
+
): TransactionResult {
|
|
271
|
+
return tx.moveCall({
|
|
272
|
+
target: this.#target('confirm_send'),
|
|
273
|
+
arguments: [
|
|
274
|
+
tx.object(this.objects.endpointV2),
|
|
275
|
+
asObject(tx, sendLibrary),
|
|
276
|
+
asObject(tx, messagingChannel),
|
|
277
|
+
endpointCall,
|
|
278
|
+
sendLibraryCall,
|
|
279
|
+
],
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Refund fees from a send operation
|
|
285
|
+
* @param tx - The transaction to add the move call to
|
|
286
|
+
* @param sendCall - The send call transaction result or transaction argument
|
|
287
|
+
* @returns Transaction result containing the refund operation
|
|
288
|
+
*/
|
|
289
|
+
refundMoveCall(tx: Transaction, sendCall: TransactionArgument): void {
|
|
290
|
+
tx.moveCall({
|
|
291
|
+
target: this.#target('refund'),
|
|
292
|
+
arguments: [tx.object(this.objects.endpointV2), sendCall],
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Verify a message from another chain
|
|
298
|
+
* @param tx - The transaction to add the move call to
|
|
299
|
+
* @param receiveLibrary - The receive library object ID or transaction argument
|
|
300
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
301
|
+
* @param srcEid - The source endpoint ID or transaction argument
|
|
302
|
+
* @param sender - The sender address as bytes or transaction argument
|
|
303
|
+
* @param nonce - The message nonce or transaction argument
|
|
304
|
+
* @param payloadHash - The payload hash as bytes or transaction argument
|
|
305
|
+
*/
|
|
306
|
+
verifyMoveCall(
|
|
307
|
+
tx: Transaction,
|
|
308
|
+
receiveLibrary: string | TransactionArgument,
|
|
309
|
+
messagingChannel: string | TransactionArgument,
|
|
310
|
+
srcEid: number | TransactionArgument,
|
|
311
|
+
sender: Uint8Array | TransactionArgument,
|
|
312
|
+
nonce: bigint | number | string | TransactionArgument,
|
|
313
|
+
payloadHash: Uint8Array | TransactionArgument
|
|
314
|
+
): void {
|
|
315
|
+
tx.moveCall({
|
|
316
|
+
target: this.#target('verify'),
|
|
317
|
+
arguments: [
|
|
318
|
+
tx.object(this.objects.endpointV2),
|
|
319
|
+
asObject(tx, receiveLibrary),
|
|
320
|
+
asObject(tx, messagingChannel),
|
|
321
|
+
asU32(tx, srcEid),
|
|
322
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
323
|
+
asU64(tx, nonce),
|
|
324
|
+
asBytes32(tx, payloadHash, this.moduleManager.getUtils()),
|
|
325
|
+
tx.object.clock(),
|
|
326
|
+
],
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Clear a verified message by executing it
|
|
332
|
+
* @param tx - The transaction to add the move call to
|
|
333
|
+
* @param caller - The caller object ID or transaction argument
|
|
334
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
335
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
336
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
337
|
+
* @param nonce - Message nonce or transaction argument
|
|
338
|
+
* @param guid - Globally unique identifier as bytes or transaction argument
|
|
339
|
+
* @param message - Message payload as bytes or transaction argument
|
|
340
|
+
*/
|
|
341
|
+
clearMoveCall(
|
|
342
|
+
tx: Transaction,
|
|
343
|
+
caller: string | TransactionArgument,
|
|
344
|
+
messagingChannel: string | TransactionArgument,
|
|
345
|
+
srcEid: number | TransactionArgument,
|
|
346
|
+
sender: Uint8Array | TransactionArgument,
|
|
347
|
+
nonce: bigint | number | string | TransactionArgument,
|
|
348
|
+
guid: Uint8Array | TransactionArgument,
|
|
349
|
+
message: Uint8Array | TransactionArgument
|
|
350
|
+
): void {
|
|
351
|
+
tx.moveCall({
|
|
352
|
+
target: this.#target('clear'),
|
|
353
|
+
arguments: [
|
|
354
|
+
tx.object(this.objects.endpointV2),
|
|
355
|
+
asObject(tx, caller),
|
|
356
|
+
asObject(tx, messagingChannel),
|
|
357
|
+
asU32(tx, srcEid),
|
|
358
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
359
|
+
asU64(tx, nonce),
|
|
360
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
361
|
+
asBytes(tx, message),
|
|
362
|
+
],
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Skip a message (mark as processed without execution)
|
|
368
|
+
* @param tx - The transaction to add the move call to
|
|
369
|
+
* @param caller - The caller object ID or transaction argument
|
|
370
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
371
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
372
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
373
|
+
* @param nonce - Message nonce or transaction argument
|
|
374
|
+
*/
|
|
375
|
+
skipMoveCall(
|
|
376
|
+
tx: Transaction,
|
|
377
|
+
caller: string | TransactionArgument,
|
|
378
|
+
messagingChannel: string | TransactionArgument,
|
|
379
|
+
srcEid: number | TransactionArgument,
|
|
380
|
+
sender: Uint8Array | TransactionArgument,
|
|
381
|
+
nonce: bigint | number | string | TransactionArgument
|
|
382
|
+
): void {
|
|
383
|
+
tx.moveCall({
|
|
384
|
+
target: this.#target('skip'),
|
|
385
|
+
arguments: [
|
|
386
|
+
tx.object(this.objects.endpointV2),
|
|
387
|
+
asObject(tx, caller),
|
|
388
|
+
asObject(tx, messagingChannel),
|
|
389
|
+
asU32(tx, srcEid),
|
|
390
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
391
|
+
asU64(tx, nonce),
|
|
392
|
+
],
|
|
393
|
+
})
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Nilify a message (clear without execution)
|
|
398
|
+
* @param tx - The transaction to add the move call to
|
|
399
|
+
* @param caller - The caller object ID or transaction argument
|
|
400
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
401
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
402
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
403
|
+
* @param nonce - Message nonce or transaction argument
|
|
404
|
+
* @param payloadHash - Message payload hash as bytes or transaction argument
|
|
405
|
+
*/
|
|
406
|
+
nilifyMoveCall(
|
|
407
|
+
tx: Transaction,
|
|
408
|
+
caller: string | TransactionArgument,
|
|
409
|
+
messagingChannel: string | TransactionArgument,
|
|
410
|
+
srcEid: number | TransactionArgument,
|
|
411
|
+
sender: Uint8Array | TransactionArgument,
|
|
412
|
+
nonce: bigint | number | string | TransactionArgument,
|
|
413
|
+
payloadHash: Uint8Array | TransactionArgument
|
|
414
|
+
): void {
|
|
415
|
+
tx.moveCall({
|
|
416
|
+
target: this.#target('nilify'),
|
|
417
|
+
arguments: [
|
|
418
|
+
tx.object(this.objects.endpointV2),
|
|
419
|
+
asObject(tx, caller),
|
|
420
|
+
asObject(tx, messagingChannel),
|
|
421
|
+
asU32(tx, srcEid),
|
|
422
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
423
|
+
asU64(tx, nonce),
|
|
424
|
+
asBytes32(tx, payloadHash, this.moduleManager.getUtils()),
|
|
425
|
+
],
|
|
426
|
+
})
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Burn a message (permanently remove)
|
|
431
|
+
* @param tx - The transaction to add the move call to
|
|
432
|
+
* @param caller - The caller object ID or transaction argument
|
|
433
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
434
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
435
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
436
|
+
* @param nonce - Message nonce or transaction argument
|
|
437
|
+
* @param payloadHash - Message payload hash as bytes or transaction argument
|
|
438
|
+
*/
|
|
439
|
+
burnMoveCall(
|
|
440
|
+
tx: Transaction,
|
|
441
|
+
caller: string | TransactionArgument,
|
|
442
|
+
messagingChannel: string | TransactionArgument,
|
|
443
|
+
srcEid: number | TransactionArgument,
|
|
444
|
+
sender: Uint8Array | TransactionArgument,
|
|
445
|
+
nonce: bigint | number | string | TransactionArgument,
|
|
446
|
+
payloadHash: Uint8Array | TransactionArgument
|
|
447
|
+
): void {
|
|
448
|
+
tx.moveCall({
|
|
449
|
+
target: this.#target('burn'),
|
|
450
|
+
arguments: [
|
|
451
|
+
tx.object(this.objects.endpointV2),
|
|
452
|
+
asObject(tx, caller),
|
|
453
|
+
asObject(tx, messagingChannel),
|
|
454
|
+
asU32(tx, srcEid),
|
|
455
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
456
|
+
asU64(tx, nonce),
|
|
457
|
+
asBytes32(tx, payloadHash, this.moduleManager.getUtils()),
|
|
458
|
+
],
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Execute a LayerZero receive operation
|
|
464
|
+
* @param tx - The transaction to add the move call to
|
|
465
|
+
* @param executorCallCap - The executor call capability
|
|
466
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
467
|
+
* @param srcEid - The source endpoint ID or transaction argument
|
|
468
|
+
* @param sender - The sender address as bytes or transaction argument
|
|
469
|
+
* @param nonce - The message nonce or transaction argument
|
|
470
|
+
* @param guid - The globally unique identifier as bytes or transaction argument
|
|
471
|
+
* @param message - The message payload as bytes or transaction argument
|
|
472
|
+
* @param extraData - Additional data as bytes or transaction argument (optional)
|
|
473
|
+
* @param value - The native token value to transfer or transaction argument
|
|
474
|
+
* @returns Transaction result containing the receive operation
|
|
475
|
+
*/
|
|
476
|
+
lzReceiveMoveCall(
|
|
477
|
+
tx: Transaction,
|
|
478
|
+
executorCallCap: TransactionArgument,
|
|
479
|
+
messagingChannel: string | TransactionArgument,
|
|
480
|
+
srcEid: number | TransactionArgument,
|
|
481
|
+
sender: Uint8Array | TransactionArgument,
|
|
482
|
+
nonce: bigint | number | string | TransactionArgument,
|
|
483
|
+
guid: Uint8Array | TransactionArgument,
|
|
484
|
+
message: Uint8Array | TransactionArgument,
|
|
485
|
+
extraData: Uint8Array | TransactionArgument = new Uint8Array(),
|
|
486
|
+
value: bigint | number | string | TransactionArgument
|
|
487
|
+
): TransactionResult {
|
|
488
|
+
return tx.moveCall({
|
|
489
|
+
target: this.#target('lz_receive'),
|
|
490
|
+
arguments: [
|
|
491
|
+
tx.object(this.objects.endpointV2),
|
|
492
|
+
executorCallCap,
|
|
493
|
+
asObject(tx, messagingChannel),
|
|
494
|
+
asU32(tx, srcEid),
|
|
495
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
496
|
+
asU64(tx, nonce),
|
|
497
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
498
|
+
asBytes(tx, message),
|
|
499
|
+
asBytes(tx, extraData),
|
|
500
|
+
asArgWithTx(tx, value, (tx, val) => this.moduleManager.getUtils().createOptionIotaL1Call(tx, val)),
|
|
501
|
+
],
|
|
502
|
+
})
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Send alert for failed LayerZero receive operation
|
|
507
|
+
* @param tx - The transaction to add the move call to
|
|
508
|
+
* @param executor - The executor object ID or transaction argument
|
|
509
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
510
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
511
|
+
* @param nonce - Message nonce or transaction argument
|
|
512
|
+
* @param receiver - Receiver address or transaction argument
|
|
513
|
+
* @param guid - Globally unique identifier as bytes or transaction argument
|
|
514
|
+
* @param gas - Gas amount for execution or transaction argument
|
|
515
|
+
* @param value - Native token value or transaction argument
|
|
516
|
+
* @param message - Message payload as bytes or transaction argument
|
|
517
|
+
* @param extraData - Additional execution data as bytes or transaction argument
|
|
518
|
+
* @param reason - Failure reason or transaction argument
|
|
519
|
+
*/
|
|
520
|
+
lzReceiveAlertMoveCall(
|
|
521
|
+
tx: Transaction,
|
|
522
|
+
executor: string | TransactionArgument,
|
|
523
|
+
srcEid: number | TransactionArgument,
|
|
524
|
+
sender: Uint8Array | TransactionArgument,
|
|
525
|
+
nonce: bigint | number | string | TransactionArgument,
|
|
526
|
+
receiver: string | TransactionArgument,
|
|
527
|
+
guid: Uint8Array | TransactionArgument,
|
|
528
|
+
gas: bigint | number | string | TransactionArgument,
|
|
529
|
+
value: bigint | number | string | TransactionArgument,
|
|
530
|
+
message: Uint8Array | TransactionArgument,
|
|
531
|
+
extraData: Uint8Array | TransactionArgument,
|
|
532
|
+
reason: string | TransactionArgument
|
|
533
|
+
): void {
|
|
534
|
+
tx.moveCall({
|
|
535
|
+
target: this.#target('lz_receive_alert'),
|
|
536
|
+
arguments: [
|
|
537
|
+
asObject(tx, executor),
|
|
538
|
+
asU32(tx, srcEid),
|
|
539
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
540
|
+
asU64(tx, nonce),
|
|
541
|
+
asAddress(tx, receiver),
|
|
542
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
543
|
+
asU64(tx, gas),
|
|
544
|
+
asU64(tx, value),
|
|
545
|
+
asBytes(tx, message),
|
|
546
|
+
asBytes(tx, extraData),
|
|
547
|
+
asString(tx, reason),
|
|
548
|
+
],
|
|
549
|
+
})
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Register a composer with the endpoint
|
|
554
|
+
* @param tx - The transaction to add the move call to
|
|
555
|
+
* @param composerCap - The composer capability object ID or transaction argument
|
|
556
|
+
* @param composerInfo - Composer information including lz_compose execution information as bytes
|
|
557
|
+
* @returns Transaction result containing the compose queue address
|
|
558
|
+
*/
|
|
559
|
+
registerComposerMoveCall(
|
|
560
|
+
tx: Transaction,
|
|
561
|
+
composerCap: string | TransactionArgument,
|
|
562
|
+
composerInfo: Uint8Array | TransactionArgument
|
|
563
|
+
): TransactionResult {
|
|
564
|
+
return tx.moveCall({
|
|
565
|
+
target: this.#target('register_composer'),
|
|
566
|
+
arguments: [tx.object(this.objects.endpointV2), asObject(tx, composerCap), asBytes(tx, composerInfo)],
|
|
567
|
+
})
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Set composer information for a composer
|
|
572
|
+
* @param tx - The transaction to add the move call to
|
|
573
|
+
* @param composerCap - The composer capability object ID or transaction argument
|
|
574
|
+
* @param composerInfo - Composer information including lz_compose execution information as bytes or transaction argument
|
|
575
|
+
*/
|
|
576
|
+
setComposerInfoMoveCall(
|
|
577
|
+
tx: Transaction,
|
|
578
|
+
composerCap: string | TransactionArgument,
|
|
579
|
+
composerInfo: Uint8Array | TransactionArgument
|
|
580
|
+
): void {
|
|
581
|
+
tx.moveCall({
|
|
582
|
+
target: this.#target('set_composer_info'),
|
|
583
|
+
arguments: [tx.object(this.objects.endpointV2), asObject(tx, composerCap), asBytes(tx, composerInfo)],
|
|
584
|
+
})
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Send compose message to queue
|
|
589
|
+
* @param tx - The transaction to add the move call to
|
|
590
|
+
* @param from - The sender object ID or transaction argument
|
|
591
|
+
* @param composeQueue - The compose queue object ID or transaction argument
|
|
592
|
+
* @param guid - Globally unique identifier as bytes or transaction argument
|
|
593
|
+
* @param index - Compose message index or transaction argument
|
|
594
|
+
* @param message - Message payload as bytes or transaction argument
|
|
595
|
+
*/
|
|
596
|
+
sendComposeMoveCall(
|
|
597
|
+
tx: Transaction,
|
|
598
|
+
from: string | TransactionArgument,
|
|
599
|
+
composeQueue: string | TransactionArgument,
|
|
600
|
+
guid: Uint8Array | TransactionArgument,
|
|
601
|
+
index: number | TransactionArgument,
|
|
602
|
+
message: Uint8Array | TransactionArgument
|
|
603
|
+
): void {
|
|
604
|
+
tx.moveCall({
|
|
605
|
+
target: this.#target('send_compose'),
|
|
606
|
+
arguments: [
|
|
607
|
+
asObject(tx, from),
|
|
608
|
+
asObject(tx, composeQueue),
|
|
609
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
610
|
+
asU16(tx, index),
|
|
611
|
+
asBytes(tx, message),
|
|
612
|
+
],
|
|
613
|
+
})
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Execute LayerZero compose operation
|
|
618
|
+
* @param tx - The transaction to add the move call to
|
|
619
|
+
* @param executorCallCap - The executor call capability
|
|
620
|
+
* @param composeQueue - The compose queue object ID or transaction argument
|
|
621
|
+
* @param from - Source address or transaction argument
|
|
622
|
+
* @param guid - Globally unique identifier as bytes or transaction argument
|
|
623
|
+
* @param index - Compose message index or transaction argument
|
|
624
|
+
* @param message - Message payload as bytes or transaction argument
|
|
625
|
+
* @param extraData - Additional execution data as bytes or transaction argument (optional)
|
|
626
|
+
* @param value - Native token value to transfer or transaction argument
|
|
627
|
+
* @returns Transaction result containing the compose operation
|
|
628
|
+
*/
|
|
629
|
+
lzComposeMoveCall(
|
|
630
|
+
tx: Transaction,
|
|
631
|
+
executorCallCap: TransactionArgument,
|
|
632
|
+
composeQueue: string | TransactionArgument,
|
|
633
|
+
from: string | TransactionArgument,
|
|
634
|
+
guid: Uint8Array | TransactionArgument,
|
|
635
|
+
index: number | TransactionArgument,
|
|
636
|
+
message: Uint8Array | TransactionArgument,
|
|
637
|
+
extraData: Uint8Array | TransactionArgument = new Uint8Array(),
|
|
638
|
+
value: bigint | number | string | TransactionArgument
|
|
639
|
+
): TransactionResult {
|
|
640
|
+
return tx.moveCall({
|
|
641
|
+
target: this.#target('lz_compose'),
|
|
642
|
+
arguments: [
|
|
643
|
+
tx.object(this.objects.endpointV2),
|
|
644
|
+
executorCallCap,
|
|
645
|
+
asObject(tx, composeQueue),
|
|
646
|
+
asAddress(tx, from),
|
|
647
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
648
|
+
asU16(tx, index),
|
|
649
|
+
asBytes(tx, message),
|
|
650
|
+
asBytes(tx, extraData),
|
|
651
|
+
asArgWithTx(tx, value, (tx, val) => this.moduleManager.getUtils().createOptionIotaL1Call(tx, val)),
|
|
652
|
+
],
|
|
653
|
+
})
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Send alert for failed LayerZero compose operation
|
|
658
|
+
* @param tx - The transaction to add the move call to
|
|
659
|
+
* @param executor - The executor object ID or transaction argument
|
|
660
|
+
* @param from - Source address or transaction argument
|
|
661
|
+
* @param to - Destination address or transaction argument
|
|
662
|
+
* @param guid - Globally unique identifier as bytes or transaction argument
|
|
663
|
+
* @param index - Compose message index or transaction argument
|
|
664
|
+
* @param gas - Gas amount for execution or transaction argument
|
|
665
|
+
* @param value - Native token value or transaction argument
|
|
666
|
+
* @param message - Message payload as bytes or transaction argument
|
|
667
|
+
* @param extraData - Additional execution data as bytes or transaction argument
|
|
668
|
+
* @param reason - Failure reason or transaction argument
|
|
669
|
+
*/
|
|
670
|
+
lzComposeAlertMoveCall(
|
|
671
|
+
tx: Transaction,
|
|
672
|
+
executor: string | TransactionArgument,
|
|
673
|
+
from: string | TransactionArgument,
|
|
674
|
+
to: string | TransactionArgument,
|
|
675
|
+
guid: Uint8Array | TransactionArgument,
|
|
676
|
+
index: number | TransactionArgument,
|
|
677
|
+
gas: bigint | number | string | TransactionArgument,
|
|
678
|
+
value: bigint | number | string | TransactionArgument,
|
|
679
|
+
message: Uint8Array | TransactionArgument,
|
|
680
|
+
extraData: Uint8Array | TransactionArgument,
|
|
681
|
+
reason: string | TransactionArgument
|
|
682
|
+
): void {
|
|
683
|
+
tx.moveCall({
|
|
684
|
+
target: this.#target('lz_compose_alert'),
|
|
685
|
+
arguments: [
|
|
686
|
+
asObject(tx, executor),
|
|
687
|
+
asAddress(tx, from),
|
|
688
|
+
asAddress(tx, to),
|
|
689
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
690
|
+
asU16(tx, index),
|
|
691
|
+
asU64(tx, gas),
|
|
692
|
+
asU64(tx, value),
|
|
693
|
+
asBytes(tx, message),
|
|
694
|
+
asBytes(tx, extraData),
|
|
695
|
+
asString(tx, reason),
|
|
696
|
+
],
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// ===== OApp Library Configuration Functions =====
|
|
701
|
+
/**
|
|
702
|
+
* Set the send library for an OApp to a specific destination
|
|
703
|
+
* @param tx - The transaction to add the move call to
|
|
704
|
+
* @param caller - The caller capability object ID or transaction argument
|
|
705
|
+
* @param sender - The sender OApp address or transaction argument
|
|
706
|
+
* @param dstEid - The destination endpoint ID or transaction argument
|
|
707
|
+
* @param newLib - The new send library address or transaction argument
|
|
708
|
+
*/
|
|
709
|
+
setSendLibraryMoveCall(
|
|
710
|
+
tx: Transaction,
|
|
711
|
+
caller: string | TransactionArgument,
|
|
712
|
+
sender: string | TransactionArgument,
|
|
713
|
+
dstEid: number | TransactionArgument,
|
|
714
|
+
newLib: string | TransactionArgument
|
|
715
|
+
): void {
|
|
716
|
+
tx.moveCall({
|
|
717
|
+
target: this.#target('set_send_library'),
|
|
718
|
+
arguments: [
|
|
719
|
+
tx.object(this.objects.endpointV2),
|
|
720
|
+
asObject(tx, caller),
|
|
721
|
+
asAddress(tx, sender),
|
|
722
|
+
asU32(tx, dstEid),
|
|
723
|
+
asAddress(tx, newLib),
|
|
724
|
+
],
|
|
725
|
+
})
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Set the receive library for an OApp from a specific source
|
|
730
|
+
* @param tx - The transaction to add the move call to
|
|
731
|
+
* @param caller - The caller capability object ID or transaction argument
|
|
732
|
+
* @param receiver - The receiver OApp address or transaction argument
|
|
733
|
+
* @param srcEid - The source endpoint ID or transaction argument
|
|
734
|
+
* @param newLib - The new receive library address or transaction argument
|
|
735
|
+
* @param gracePeriod - The grace period in seconds or transaction argument
|
|
736
|
+
*/
|
|
737
|
+
setReceiveLibraryMoveCall(
|
|
738
|
+
tx: Transaction,
|
|
739
|
+
caller: string | TransactionArgument,
|
|
740
|
+
receiver: string | TransactionArgument,
|
|
741
|
+
srcEid: number | TransactionArgument,
|
|
742
|
+
newLib: string | TransactionArgument,
|
|
743
|
+
gracePeriod: number | string | bigint | TransactionArgument
|
|
744
|
+
): void {
|
|
745
|
+
tx.moveCall({
|
|
746
|
+
target: this.#target('set_receive_library'),
|
|
747
|
+
arguments: [
|
|
748
|
+
tx.object(this.objects.endpointV2),
|
|
749
|
+
asObject(tx, caller),
|
|
750
|
+
asAddress(tx, receiver),
|
|
751
|
+
asU32(tx, srcEid),
|
|
752
|
+
asAddress(tx, newLib),
|
|
753
|
+
asU64(tx, gracePeriod),
|
|
754
|
+
tx.object.clock(),
|
|
755
|
+
],
|
|
756
|
+
})
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Set timeout for receive library transition
|
|
761
|
+
* @param tx - The transaction to add the move call to
|
|
762
|
+
* @param caller - The caller capability object ID or transaction argument
|
|
763
|
+
* @param receiver - The receiver OApp address or transaction argument
|
|
764
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
765
|
+
* @param lib - The library address or transaction argument
|
|
766
|
+
* @param expiry - Timeout expiry timestamp or transaction argument
|
|
767
|
+
*/
|
|
768
|
+
setReceiveLibraryTimeoutMoveCall(
|
|
769
|
+
tx: Transaction,
|
|
770
|
+
caller: string | TransactionArgument,
|
|
771
|
+
receiver: string | TransactionArgument,
|
|
772
|
+
srcEid: number | TransactionArgument,
|
|
773
|
+
lib: string | TransactionArgument,
|
|
774
|
+
expiry: number | string | bigint | TransactionArgument
|
|
775
|
+
): void {
|
|
776
|
+
tx.moveCall({
|
|
777
|
+
target: this.#target('set_receive_library_timeout'),
|
|
778
|
+
arguments: [
|
|
779
|
+
tx.object(this.objects.endpointV2),
|
|
780
|
+
asObject(tx, caller),
|
|
781
|
+
asAddress(tx, receiver),
|
|
782
|
+
asU32(tx, srcEid),
|
|
783
|
+
asAddress(tx, lib),
|
|
784
|
+
asU64(tx, expiry),
|
|
785
|
+
tx.object.clock(),
|
|
786
|
+
],
|
|
787
|
+
})
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Set configuration for an OApp's message library
|
|
792
|
+
* @param tx - The transaction to add the move call to
|
|
793
|
+
* @param caller - The caller object ID or transaction argument
|
|
794
|
+
* @param oapp - The OApp address or transaction argument
|
|
795
|
+
* @param lib - The message library address or transaction argument
|
|
796
|
+
* @param eid - Endpoint ID or transaction argument
|
|
797
|
+
* @param config_type - Configuration type identifier or transaction argument
|
|
798
|
+
* @param config - Configuration data as bytes or transaction argument
|
|
799
|
+
* @returns Transaction result containing the configuration operation
|
|
800
|
+
*/
|
|
801
|
+
setConfigMoveCall(
|
|
802
|
+
tx: Transaction,
|
|
803
|
+
caller: string | TransactionArgument,
|
|
804
|
+
oapp: string | TransactionArgument,
|
|
805
|
+
lib: string | TransactionArgument,
|
|
806
|
+
eid: number | TransactionArgument,
|
|
807
|
+
config_type: number | TransactionArgument,
|
|
808
|
+
config: Uint8Array | TransactionArgument
|
|
809
|
+
): TransactionResult {
|
|
810
|
+
return tx.moveCall({
|
|
811
|
+
target: this.#target('set_config'),
|
|
812
|
+
arguments: [
|
|
813
|
+
tx.object(this.objects.endpointV2),
|
|
814
|
+
asObject(tx, caller),
|
|
815
|
+
asAddress(tx, oapp),
|
|
816
|
+
asAddress(tx, lib),
|
|
817
|
+
asU32(tx, eid),
|
|
818
|
+
asU32(tx, config_type),
|
|
819
|
+
asBytes(tx, config),
|
|
820
|
+
],
|
|
821
|
+
})
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Register a message library with the endpoint (admin only)
|
|
826
|
+
* @param tx - The transaction to add the move call to
|
|
827
|
+
* @param messageLibCap - The message library capability address or transaction argument
|
|
828
|
+
* @param messageLibType - The type of message library (Send, Receive, or SendAndReceive)
|
|
829
|
+
*/
|
|
830
|
+
registerLibraryMoveCall(
|
|
831
|
+
tx: Transaction,
|
|
832
|
+
messageLibCap: string | TransactionArgument,
|
|
833
|
+
messageLibType: MessageLibType
|
|
834
|
+
): void {
|
|
835
|
+
const libType = this.messageLibTypeMoveCall(tx, messageLibType)
|
|
836
|
+
tx.moveCall({
|
|
837
|
+
target: this.#target('register_library'),
|
|
838
|
+
arguments: [
|
|
839
|
+
tx.object(this.objects.endpointV2),
|
|
840
|
+
tx.object(this.objects.endpointAdminCap),
|
|
841
|
+
asAddress(tx, messageLibCap),
|
|
842
|
+
libType,
|
|
843
|
+
],
|
|
844
|
+
})
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Set default send library for a destination EID (admin only)
|
|
849
|
+
* @param tx - The transaction to add the move call to
|
|
850
|
+
* @param dstEid - Destination endpoint ID
|
|
851
|
+
* @param newLib - The new default send library address
|
|
852
|
+
*/
|
|
853
|
+
setDefaultSendLibraryMoveCall(
|
|
854
|
+
tx: Transaction,
|
|
855
|
+
dstEid: number | TransactionArgument,
|
|
856
|
+
newLib: string | TransactionArgument
|
|
857
|
+
): void {
|
|
858
|
+
tx.moveCall({
|
|
859
|
+
target: this.#target('set_default_send_library'),
|
|
860
|
+
arguments: [
|
|
861
|
+
tx.object(this.objects.endpointV2),
|
|
862
|
+
tx.object(this.objects.endpointAdminCap),
|
|
863
|
+
asU32(tx, dstEid),
|
|
864
|
+
asAddress(tx, newLib),
|
|
865
|
+
],
|
|
866
|
+
})
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Set default receive library for a source EID (admin only)
|
|
871
|
+
* @param tx - The transaction to add the move call to
|
|
872
|
+
* @param srcEid - Source endpoint ID
|
|
873
|
+
* @param newLib - The new default receive library address
|
|
874
|
+
* @param gracePeriod - Grace period in seconds for library transition
|
|
875
|
+
*/
|
|
876
|
+
setDefaultReceiveLibraryMoveCall(
|
|
877
|
+
tx: Transaction,
|
|
878
|
+
srcEid: number | TransactionArgument,
|
|
879
|
+
newLib: string | TransactionArgument,
|
|
880
|
+
gracePeriod: number | string | bigint | TransactionArgument
|
|
881
|
+
): void {
|
|
882
|
+
tx.moveCall({
|
|
883
|
+
target: this.#target('set_default_receive_library'),
|
|
884
|
+
arguments: [
|
|
885
|
+
tx.object(this.objects.endpointV2),
|
|
886
|
+
tx.object(this.objects.endpointAdminCap),
|
|
887
|
+
asU32(tx, srcEid),
|
|
888
|
+
asAddress(tx, newLib),
|
|
889
|
+
asU64(tx, gracePeriod),
|
|
890
|
+
tx.object.clock(),
|
|
891
|
+
],
|
|
892
|
+
})
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Set timeout for default receive library transition (admin only)
|
|
897
|
+
* @param tx - The transaction to add the move call to
|
|
898
|
+
* @param srcEid - Source endpoint ID
|
|
899
|
+
* @param lib - The library address
|
|
900
|
+
* @param expiry - Timeout expiry timestamp
|
|
901
|
+
*/
|
|
902
|
+
setDefaultReceiveLibraryTimeoutMoveCall(
|
|
903
|
+
tx: Transaction,
|
|
904
|
+
srcEid: number | TransactionArgument,
|
|
905
|
+
lib: string | TransactionArgument,
|
|
906
|
+
expiry: number | string | bigint | TransactionArgument
|
|
907
|
+
): void {
|
|
908
|
+
tx.moveCall({
|
|
909
|
+
target: this.#target('set_default_receive_library_timeout'),
|
|
910
|
+
arguments: [
|
|
911
|
+
tx.object(this.objects.endpointV2),
|
|
912
|
+
tx.object(this.objects.endpointAdminCap),
|
|
913
|
+
asU32(tx, srcEid),
|
|
914
|
+
asAddress(tx, lib),
|
|
915
|
+
asU64(tx, expiry),
|
|
916
|
+
tx.object.clock(),
|
|
917
|
+
],
|
|
918
|
+
})
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* Create message library type move call
|
|
923
|
+
* @param tx - The transaction to add the move call to
|
|
924
|
+
* @param messageLibType - The message library type enum value
|
|
925
|
+
* @returns Transaction result containing the library type
|
|
926
|
+
*/
|
|
927
|
+
messageLibTypeMoveCall(tx: Transaction, messageLibType: MessageLibType): TransactionResult {
|
|
928
|
+
switch (messageLibType) {
|
|
929
|
+
case MessageLibType.Send:
|
|
930
|
+
return tx.moveCall({
|
|
931
|
+
target: this.#target('send', 'message_lib_type'),
|
|
932
|
+
arguments: [],
|
|
933
|
+
})
|
|
934
|
+
case MessageLibType.Receive:
|
|
935
|
+
return tx.moveCall({
|
|
936
|
+
target: this.#target('receive', 'message_lib_type'),
|
|
937
|
+
arguments: [],
|
|
938
|
+
})
|
|
939
|
+
case MessageLibType.SendAndReceive:
|
|
940
|
+
return tx.moveCall({
|
|
941
|
+
target: this.#target('send_and_receive', 'message_lib_type'),
|
|
942
|
+
arguments: [],
|
|
943
|
+
})
|
|
944
|
+
default:
|
|
945
|
+
throw new Error(`Invalid message lib type: ${JSON.stringify(messageLibType)}`)
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// === View Functions ===
|
|
950
|
+
|
|
951
|
+
// Basic endpoint info
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* Get the Endpoint ID (EID) of the current chain
|
|
955
|
+
* @param tx - The transaction to add the move call to
|
|
956
|
+
* @returns Transaction result containing the EID
|
|
957
|
+
*/
|
|
958
|
+
eidMoveCall(tx: Transaction): TransactionResult {
|
|
959
|
+
return tx.moveCall({
|
|
960
|
+
target: this.#target('eid'),
|
|
961
|
+
arguments: [tx.object(this.objects.endpointV2)],
|
|
962
|
+
})
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Get the Endpoint ID (EID) of the current chain
|
|
967
|
+
* @returns The endpoint ID, or 0 if not initialized
|
|
968
|
+
*/
|
|
969
|
+
async eid(): Promise<number> {
|
|
970
|
+
return executeSimulate(
|
|
971
|
+
this.client,
|
|
972
|
+
(tx) => {
|
|
973
|
+
this.eidMoveCall(tx)
|
|
974
|
+
},
|
|
975
|
+
(result) => bcs.U32.parse(result[0].value)
|
|
976
|
+
)
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Check if an OApp is registered with the endpoint
|
|
981
|
+
* @param tx - The transaction to add the move call to
|
|
982
|
+
* @param oapp - The OApp address to check or transaction argument
|
|
983
|
+
* @returns Transaction result containing the registration status
|
|
984
|
+
*/
|
|
985
|
+
isOappRegisteredMoveCall(tx: Transaction, oapp: string | TransactionArgument): TransactionResult {
|
|
986
|
+
return tx.moveCall({
|
|
987
|
+
target: this.#target('is_oapp_registered'),
|
|
988
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, oapp)],
|
|
989
|
+
})
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Check if an OApp is registered with the endpoint
|
|
994
|
+
* @param oapp - The OApp address to check
|
|
995
|
+
* @returns True if the OApp is registered, false otherwise
|
|
996
|
+
*/
|
|
997
|
+
async isOappRegistered(oapp: string): Promise<boolean> {
|
|
998
|
+
return executeSimulate(
|
|
999
|
+
this.client,
|
|
1000
|
+
(tx) => this.isOappRegisteredMoveCall(tx, oapp),
|
|
1001
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1002
|
+
)
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Get messaging channel for an OApp
|
|
1007
|
+
* @param tx - The transaction to add the move call to
|
|
1008
|
+
* @param oapp - The OApp address or transaction argument
|
|
1009
|
+
* @returns Transaction result containing the messaging channel address
|
|
1010
|
+
*/
|
|
1011
|
+
getMessagingChannelMoveCall(tx: Transaction, oapp: string | TransactionArgument): TransactionResult {
|
|
1012
|
+
return tx.moveCall({
|
|
1013
|
+
target: this.#target('get_messaging_channel'),
|
|
1014
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, oapp)],
|
|
1015
|
+
})
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Get the messaging channel for an OApp
|
|
1020
|
+
* @param oapp - The OApp address
|
|
1021
|
+
* @returns The messaging channel address
|
|
1022
|
+
*/
|
|
1023
|
+
async getMessagingChannel(oapp: string): Promise<string> {
|
|
1024
|
+
return executeSimulate(
|
|
1025
|
+
this.client,
|
|
1026
|
+
(tx) => {
|
|
1027
|
+
this.getMessagingChannelMoveCall(tx, oapp)
|
|
1028
|
+
},
|
|
1029
|
+
(result) => bcs.Address.parse(result[0].value)
|
|
1030
|
+
)
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Get OApp information for an OApp
|
|
1035
|
+
* @param tx - The transaction to add the move call to
|
|
1036
|
+
* @param oapp - The OApp address or transaction argument
|
|
1037
|
+
* @returns Transaction result containing the OApp information including lz_receive execution information
|
|
1038
|
+
*/
|
|
1039
|
+
getOappInfoMoveCall(tx: Transaction, oapp: string | TransactionArgument): TransactionResult {
|
|
1040
|
+
return tx.moveCall({
|
|
1041
|
+
target: this.#target('get_oapp_info'),
|
|
1042
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, oapp)],
|
|
1043
|
+
})
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Get OApp information for an OApp
|
|
1048
|
+
* @param oapp - The OApp address
|
|
1049
|
+
* @returns Promise<Uint8Array> - The OApp information including lz_receive execution information as bytes
|
|
1050
|
+
*/
|
|
1051
|
+
async getOappInfo(oapp: string): Promise<Uint8Array> {
|
|
1052
|
+
return executeSimulate(
|
|
1053
|
+
this.client,
|
|
1054
|
+
(tx) => {
|
|
1055
|
+
return this.getOappInfoMoveCall(tx, oapp)
|
|
1056
|
+
},
|
|
1057
|
+
(result) => {
|
|
1058
|
+
const parsed = bcs.vector(bcs.u8()).parse(result[0].value)
|
|
1059
|
+
return new Uint8Array(parsed)
|
|
1060
|
+
}
|
|
1061
|
+
)
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Get delegate address for an OApp
|
|
1066
|
+
* @param tx - The transaction to add the move call to
|
|
1067
|
+
* @param oapp - The OApp address or transaction argument
|
|
1068
|
+
* @returns Transaction result containing the delegate address
|
|
1069
|
+
*/
|
|
1070
|
+
getDelegateMoveCall(tx: Transaction, oapp: string | TransactionArgument): TransactionResult {
|
|
1071
|
+
return tx.moveCall({
|
|
1072
|
+
target: this.#target('get_delegate'),
|
|
1073
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, oapp)],
|
|
1074
|
+
})
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Get delegate address for an OApp
|
|
1079
|
+
* @param oapp - The OApp address
|
|
1080
|
+
* @returns Promise<string> - The delegate address
|
|
1081
|
+
*/
|
|
1082
|
+
async getDelegate(oapp: string): Promise<string> {
|
|
1083
|
+
return executeSimulate(
|
|
1084
|
+
this.client,
|
|
1085
|
+
(tx) => {
|
|
1086
|
+
this.getDelegateMoveCall(tx, oapp)
|
|
1087
|
+
},
|
|
1088
|
+
(result) => bcs.Address.parse(result[0].value)
|
|
1089
|
+
)
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Check if a composer is registered with the endpoint
|
|
1094
|
+
* @param tx - The transaction to add the move call to
|
|
1095
|
+
* @param composer - The composer address or transaction argument
|
|
1096
|
+
* @returns Transaction result containing the registration status
|
|
1097
|
+
*/
|
|
1098
|
+
isComposerRegisteredMoveCall(tx: Transaction, composer: string | TransactionArgument): TransactionResult {
|
|
1099
|
+
return tx.moveCall({
|
|
1100
|
+
target: this.#target('is_composer_registered'),
|
|
1101
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, composer)],
|
|
1102
|
+
})
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Check if a composer is registered with the endpoint
|
|
1107
|
+
* @param composer - The composer address
|
|
1108
|
+
* @returns Promise<boolean> - True if the composer is registered
|
|
1109
|
+
*/
|
|
1110
|
+
async isComposerRegistered(composer: string): Promise<boolean> {
|
|
1111
|
+
return executeSimulate(
|
|
1112
|
+
this.client,
|
|
1113
|
+
(tx) => {
|
|
1114
|
+
this.isComposerRegisteredMoveCall(tx, composer)
|
|
1115
|
+
},
|
|
1116
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1117
|
+
)
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* Get compose queue address for a composer
|
|
1122
|
+
* @param tx - The transaction to add the move call to
|
|
1123
|
+
* @param composer - The composer address or transaction argument
|
|
1124
|
+
* @returns Transaction result containing the compose queue address
|
|
1125
|
+
*/
|
|
1126
|
+
getComposeQueueMoveCall(tx: Transaction, composer: string | TransactionArgument): TransactionResult {
|
|
1127
|
+
return tx.moveCall({
|
|
1128
|
+
target: this.#target('get_compose_queue'),
|
|
1129
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, composer)],
|
|
1130
|
+
})
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Get compose queue address for a composer
|
|
1135
|
+
* @param composer - The composer address
|
|
1136
|
+
* @returns Promise<string> - The compose queue address
|
|
1137
|
+
*/
|
|
1138
|
+
async getComposeQueue(composer: string): Promise<string> {
|
|
1139
|
+
return executeSimulate(
|
|
1140
|
+
this.client,
|
|
1141
|
+
(tx) => {
|
|
1142
|
+
this.getComposeQueueMoveCall(tx, composer)
|
|
1143
|
+
},
|
|
1144
|
+
(result) => bcs.Address.parse(result[0].value)
|
|
1145
|
+
)
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* Get composer information for a registered composer
|
|
1150
|
+
* @param tx - The transaction to add the move call to
|
|
1151
|
+
* @param composer - The composer address or transaction argument
|
|
1152
|
+
* @returns Transaction result containing the composer information
|
|
1153
|
+
*/
|
|
1154
|
+
getComposerInfoMoveCall(tx: Transaction, composer: string | TransactionArgument): TransactionResult {
|
|
1155
|
+
return tx.moveCall({
|
|
1156
|
+
target: this.#target('get_composer_info'),
|
|
1157
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, composer)],
|
|
1158
|
+
})
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* Get composer information for a registered composer
|
|
1163
|
+
* @param composer - The composer address
|
|
1164
|
+
* @returns Promise<Uint8Array> - The composer information as bytes
|
|
1165
|
+
*/
|
|
1166
|
+
async getComposerInfo(composer: string): Promise<Uint8Array> {
|
|
1167
|
+
return executeSimulate(
|
|
1168
|
+
this.client,
|
|
1169
|
+
(tx) => {
|
|
1170
|
+
this.getComposerInfoMoveCall(tx, composer)
|
|
1171
|
+
},
|
|
1172
|
+
(result) => {
|
|
1173
|
+
const parsed = bcs.vector(bcs.u8()).parse(result[0].value)
|
|
1174
|
+
return new Uint8Array(parsed)
|
|
1175
|
+
}
|
|
1176
|
+
)
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// Compose Queue View Functions
|
|
1180
|
+
/**
|
|
1181
|
+
* Get composer address from compose queue
|
|
1182
|
+
* @param tx - The transaction to add the move call to
|
|
1183
|
+
* @param composeQueue - The compose queue object ID or transaction argument
|
|
1184
|
+
* @returns Transaction result containing the composer address
|
|
1185
|
+
*/
|
|
1186
|
+
getComposerMoveCall(tx: Transaction, composeQueue: string | TransactionArgument): TransactionResult {
|
|
1187
|
+
return tx.moveCall({
|
|
1188
|
+
target: this.#target('get_composer'),
|
|
1189
|
+
arguments: [asObject(tx, composeQueue)],
|
|
1190
|
+
})
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Get composer address from compose queue
|
|
1195
|
+
* @param composeQueue - The compose queue object ID
|
|
1196
|
+
* @returns Promise<string> - The composer address
|
|
1197
|
+
*/
|
|
1198
|
+
async getComposer(composeQueue: string): Promise<string> {
|
|
1199
|
+
return executeSimulate(
|
|
1200
|
+
this.client,
|
|
1201
|
+
(tx) => this.getComposerMoveCall(tx, composeQueue),
|
|
1202
|
+
(result) => bcs.Address.parse(result[0].value)
|
|
1203
|
+
)
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* Check if compose message hash exists
|
|
1208
|
+
* @param tx - The transaction to add the move call to
|
|
1209
|
+
* @param composeQueue - The compose queue object ID
|
|
1210
|
+
* @param from - Sender address
|
|
1211
|
+
* @param guid - Globally unique identifier as bytes
|
|
1212
|
+
* @param index - Compose message index
|
|
1213
|
+
* @returns Transaction result containing the message hash existence status
|
|
1214
|
+
*/
|
|
1215
|
+
hasComposeMessageHashMoveCall(
|
|
1216
|
+
tx: Transaction,
|
|
1217
|
+
composeQueue: string | TransactionArgument,
|
|
1218
|
+
from: string | TransactionArgument,
|
|
1219
|
+
guid: Uint8Array | TransactionArgument,
|
|
1220
|
+
index: number | TransactionArgument
|
|
1221
|
+
): TransactionResult {
|
|
1222
|
+
return tx.moveCall({
|
|
1223
|
+
target: this.#target('has_compose_message_hash'),
|
|
1224
|
+
arguments: [
|
|
1225
|
+
asObject(tx, composeQueue),
|
|
1226
|
+
asAddress(tx, from),
|
|
1227
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
1228
|
+
asU16(tx, index),
|
|
1229
|
+
],
|
|
1230
|
+
})
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Check if compose message hash exists
|
|
1235
|
+
* @param composeQueue - The compose queue object ID
|
|
1236
|
+
* @param from - Sender address
|
|
1237
|
+
* @param guid - Globally unique identifier as bytes
|
|
1238
|
+
* @param index - Compose message index
|
|
1239
|
+
* @returns Promise<boolean> - True if message hash exists
|
|
1240
|
+
*/
|
|
1241
|
+
async hasComposeMessageHash(composeQueue: string, from: string, guid: Uint8Array, index: number): Promise<boolean> {
|
|
1242
|
+
return executeSimulate(
|
|
1243
|
+
this.client,
|
|
1244
|
+
(tx) => this.hasComposeMessageHashMoveCall(tx, composeQueue, from, guid, index),
|
|
1245
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1246
|
+
)
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* Get compose message hash
|
|
1251
|
+
* @param tx - The transaction to add the move call to
|
|
1252
|
+
* @param composeQueue - The compose queue object ID
|
|
1253
|
+
* @param from - Sender address
|
|
1254
|
+
* @param guid - Globally unique identifier as bytes
|
|
1255
|
+
* @param index - Compose message index
|
|
1256
|
+
* @returns Transaction result containing the message hash
|
|
1257
|
+
*/
|
|
1258
|
+
getComposeMessageHashMoveCall(
|
|
1259
|
+
tx: Transaction,
|
|
1260
|
+
composeQueue: string | TransactionArgument,
|
|
1261
|
+
from: string | TransactionArgument,
|
|
1262
|
+
guid: Uint8Array | TransactionArgument,
|
|
1263
|
+
index: number | TransactionArgument
|
|
1264
|
+
): TransactionResult {
|
|
1265
|
+
return tx.moveCall({
|
|
1266
|
+
target: this.#target('get_compose_message_hash'),
|
|
1267
|
+
arguments: [
|
|
1268
|
+
asObject(tx, composeQueue),
|
|
1269
|
+
asAddress(tx, from),
|
|
1270
|
+
asBytes32(tx, guid, this.moduleManager.getUtils()),
|
|
1271
|
+
asU16(tx, index),
|
|
1272
|
+
],
|
|
1273
|
+
})
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* Get compose message hash
|
|
1278
|
+
* @param composeQueue - The compose queue object ID
|
|
1279
|
+
* @param from - Sender address
|
|
1280
|
+
* @param guid - Globally unique identifier as bytes
|
|
1281
|
+
* @param index - Compose message index
|
|
1282
|
+
* @returns Promise<Uint8Array> - The message hash as bytes
|
|
1283
|
+
*/
|
|
1284
|
+
async getComposeMessageHash(
|
|
1285
|
+
composeQueue: string,
|
|
1286
|
+
from: string,
|
|
1287
|
+
guid: Uint8Array,
|
|
1288
|
+
index: number
|
|
1289
|
+
): Promise<Uint8Array> {
|
|
1290
|
+
return executeSimulate(
|
|
1291
|
+
this.client,
|
|
1292
|
+
(tx) => {
|
|
1293
|
+
this.getComposeMessageHashMoveCall(tx, composeQueue, from, guid, index)
|
|
1294
|
+
},
|
|
1295
|
+
(result) => {
|
|
1296
|
+
const parsed = bcs.vector(bcs.u8()).parse(result[0].value)
|
|
1297
|
+
return new Uint8Array(parsed)
|
|
1298
|
+
}
|
|
1299
|
+
)
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// Message Library View Functions
|
|
1303
|
+
/**
|
|
1304
|
+
* Get count of registered message libraries
|
|
1305
|
+
* @param tx - The transaction to add the move call to
|
|
1306
|
+
* @returns Transaction result containing the count of registered libraries
|
|
1307
|
+
*/
|
|
1308
|
+
registeredLibrariesCountMoveCall(tx: Transaction): TransactionResult {
|
|
1309
|
+
return tx.moveCall({
|
|
1310
|
+
target: this.#target('registered_libraries_count'),
|
|
1311
|
+
arguments: [tx.object(this.objects.endpointV2)],
|
|
1312
|
+
})
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/**
|
|
1316
|
+
* Get count of registered message libraries
|
|
1317
|
+
* @returns Promise<bigint> - The number of registered libraries
|
|
1318
|
+
*/
|
|
1319
|
+
async registeredLibrariesCount(): Promise<bigint> {
|
|
1320
|
+
return executeSimulate(
|
|
1321
|
+
this.client,
|
|
1322
|
+
(tx) => {
|
|
1323
|
+
this.registeredLibrariesCountMoveCall(tx)
|
|
1324
|
+
},
|
|
1325
|
+
(result) => BigInt(bcs.U64.parse(result[0].value))
|
|
1326
|
+
)
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
/**
|
|
1330
|
+
* Get list of registered message libraries with pagination
|
|
1331
|
+
* @param tx - The transaction to add the move call to
|
|
1332
|
+
* @param start - Start index for pagination or transaction argument
|
|
1333
|
+
* @param maxCount - Maximum count to return or transaction argument
|
|
1334
|
+
* @returns Transaction result containing array of library addresses
|
|
1335
|
+
*/
|
|
1336
|
+
registeredLibrariesMoveCall(
|
|
1337
|
+
tx: Transaction,
|
|
1338
|
+
start: bigint | TransactionArgument,
|
|
1339
|
+
maxCount: bigint | TransactionArgument
|
|
1340
|
+
): TransactionResult {
|
|
1341
|
+
return tx.moveCall({
|
|
1342
|
+
target: this.#target('registered_libraries'),
|
|
1343
|
+
arguments: [tx.object(this.objects.endpointV2), asU64(tx, start), asU64(tx, maxCount)],
|
|
1344
|
+
})
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
/**
|
|
1348
|
+
* Get list of registered message libraries with pagination
|
|
1349
|
+
* @param start - Start index for pagination
|
|
1350
|
+
* @param maxCount - Maximum count to return
|
|
1351
|
+
* @returns Promise<string[]> - Array of registered library addresses
|
|
1352
|
+
*/
|
|
1353
|
+
async registeredLibraries(start: bigint, maxCount: bigint): Promise<string[]> {
|
|
1354
|
+
return executeSimulate(
|
|
1355
|
+
this.client,
|
|
1356
|
+
(tx) => {
|
|
1357
|
+
this.registeredLibrariesMoveCall(tx, start, maxCount)
|
|
1358
|
+
},
|
|
1359
|
+
(result) => bcs.vector(bcs.Address).parse(result[0].value)
|
|
1360
|
+
)
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* Check if a message library is registered
|
|
1365
|
+
* @param tx - The transaction to add the move call to
|
|
1366
|
+
* @param messageLib - The message library address or transaction argument
|
|
1367
|
+
* @returns Transaction result containing the registration status
|
|
1368
|
+
*/
|
|
1369
|
+
isLibraryRegisteredMoveCall(tx: Transaction, messageLib: string | TransactionArgument): TransactionResult {
|
|
1370
|
+
return tx.moveCall({
|
|
1371
|
+
target: this.#target('is_registered_library'),
|
|
1372
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, messageLib)],
|
|
1373
|
+
})
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
/**
|
|
1377
|
+
* Check if a message library is registered
|
|
1378
|
+
* @param lib - The message library address
|
|
1379
|
+
* @returns Promise<boolean> - True if the library is registered
|
|
1380
|
+
*/
|
|
1381
|
+
async isRegisteredLibrary(lib: string): Promise<boolean> {
|
|
1382
|
+
return executeSimulate(
|
|
1383
|
+
this.client,
|
|
1384
|
+
(tx) => {
|
|
1385
|
+
this.isLibraryRegisteredMoveCall(tx, lib)
|
|
1386
|
+
},
|
|
1387
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1388
|
+
)
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Get message library type
|
|
1393
|
+
* @param tx - The transaction to add the move call to
|
|
1394
|
+
* @param lib - The message library address or transaction argument
|
|
1395
|
+
* @returns Transaction result containing the library type
|
|
1396
|
+
*/
|
|
1397
|
+
getLibraryTypeMoveCall(tx: Transaction, lib: string | TransactionArgument): TransactionResult {
|
|
1398
|
+
return tx.moveCall({
|
|
1399
|
+
target: this.#target('get_library_type'),
|
|
1400
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, lib)],
|
|
1401
|
+
})
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
/**
|
|
1405
|
+
* Get message library type
|
|
1406
|
+
* @param lib - The message library address
|
|
1407
|
+
* @returns Promise<MessageLibType> - The library type (Send, Receive, or SendAndReceive)
|
|
1408
|
+
*/
|
|
1409
|
+
async getLibraryType(lib: string): Promise<MessageLibType> {
|
|
1410
|
+
return executeSimulate(
|
|
1411
|
+
this.client,
|
|
1412
|
+
(tx) => {
|
|
1413
|
+
this.getLibraryTypeMoveCall(tx, lib)
|
|
1414
|
+
},
|
|
1415
|
+
(result) => {
|
|
1416
|
+
const value = bcs.U8.parse(result[0].value)
|
|
1417
|
+
return value as MessageLibType
|
|
1418
|
+
}
|
|
1419
|
+
)
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* Get default send library for a destination EID
|
|
1424
|
+
* @param tx - The transaction to add the move call to
|
|
1425
|
+
* @param dstEid - Destination endpoint ID or transaction argument
|
|
1426
|
+
* @returns Transaction result containing the default send library address
|
|
1427
|
+
*/
|
|
1428
|
+
getDefaultSendLibraryMoveCall(tx: Transaction, dstEid: number | TransactionArgument): TransactionResult {
|
|
1429
|
+
return tx.moveCall({
|
|
1430
|
+
target: this.#target('get_default_send_library'),
|
|
1431
|
+
arguments: [tx.object(this.objects.endpointV2), asU32(tx, dstEid)],
|
|
1432
|
+
})
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
/**
|
|
1436
|
+
* Get default send library for a destination EID
|
|
1437
|
+
* @param dstEid - Destination endpoint ID
|
|
1438
|
+
* @returns Promise<string> - The default send library address, empty string if unavailable
|
|
1439
|
+
*/
|
|
1440
|
+
async getDefaultSendLibrary(dstEid: number): Promise<string> {
|
|
1441
|
+
return executeSimulate(
|
|
1442
|
+
this.client,
|
|
1443
|
+
(tx) => {
|
|
1444
|
+
this.getDefaultSendLibraryMoveCall(tx, dstEid)
|
|
1445
|
+
},
|
|
1446
|
+
(result) => bcs.Address.parse(result[0].value)
|
|
1447
|
+
)
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* Get default receive library for a source EID
|
|
1452
|
+
* @param tx - The transaction to add the move call to
|
|
1453
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1454
|
+
* @returns Transaction result containing the default receive library address
|
|
1455
|
+
*/
|
|
1456
|
+
getDefaultReceiveLibraryMoveCall(tx: Transaction, srcEid: number | TransactionArgument): TransactionResult {
|
|
1457
|
+
return tx.moveCall({
|
|
1458
|
+
target: this.#target('get_default_receive_library'),
|
|
1459
|
+
arguments: [tx.object(this.objects.endpointV2), asU32(tx, srcEid)],
|
|
1460
|
+
})
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* Get default receive library for a source EID
|
|
1465
|
+
* @param srcEid - Source endpoint ID
|
|
1466
|
+
* @returns Promise<string> - The default receive library address, empty string if unavailable
|
|
1467
|
+
*/
|
|
1468
|
+
async getDefaultReceiveLibrary(srcEid: number): Promise<string> {
|
|
1469
|
+
return executeSimulate(
|
|
1470
|
+
this.client,
|
|
1471
|
+
(tx) => {
|
|
1472
|
+
this.getDefaultReceiveLibraryMoveCall(tx, srcEid)
|
|
1473
|
+
},
|
|
1474
|
+
(result) => bcs.Address.parse(result[0].value)
|
|
1475
|
+
)
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
/**
|
|
1479
|
+
* Get timeout for default receive library transition
|
|
1480
|
+
* @param tx - The transaction to add the move call to
|
|
1481
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1482
|
+
* @returns Transaction result containing the timeout information
|
|
1483
|
+
*/
|
|
1484
|
+
getDefaultReceiveLibraryTimeoutMoveCall(tx: Transaction, srcEid: number | TransactionArgument): TransactionResult {
|
|
1485
|
+
return tx.moveCall({
|
|
1486
|
+
target: this.#target('get_default_receive_library_timeout'),
|
|
1487
|
+
arguments: [tx.object(this.objects.endpointV2), asU32(tx, srcEid)],
|
|
1488
|
+
})
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* Get timeout for default receive library transition
|
|
1493
|
+
* @param srcEid - Source endpoint ID
|
|
1494
|
+
* @returns Promise<Timeout | null> - The timeout information or null if not set
|
|
1495
|
+
*/
|
|
1496
|
+
async getDefaultReceiveLibraryTimeout(srcEid: number): Promise<Timeout | null> {
|
|
1497
|
+
return executeSimulate(
|
|
1498
|
+
this.client,
|
|
1499
|
+
(tx) => {
|
|
1500
|
+
this.getDefaultReceiveLibraryTimeoutMoveCall(tx, srcEid)
|
|
1501
|
+
},
|
|
1502
|
+
(result) => {
|
|
1503
|
+
const optionBytes = result[0].value
|
|
1504
|
+
const optionValue = bcs.option(TimeoutBcs).parse(optionBytes)
|
|
1505
|
+
if (optionValue) {
|
|
1506
|
+
return {
|
|
1507
|
+
expiry: BigInt(optionValue.expiry),
|
|
1508
|
+
fallbackLib: optionValue.fallback_lib,
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
return null
|
|
1512
|
+
}
|
|
1513
|
+
)
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* Check if an endpoint ID is supported
|
|
1518
|
+
* @param tx - The transaction to add the move call to
|
|
1519
|
+
* @param eid - Endpoint ID to check or transaction argument
|
|
1520
|
+
* @returns Transaction result containing the support status
|
|
1521
|
+
*/
|
|
1522
|
+
isSupportedEidMoveCall(tx: Transaction, eid: number | TransactionArgument): TransactionResult {
|
|
1523
|
+
return tx.moveCall({
|
|
1524
|
+
target: this.#target('is_supported_eid'),
|
|
1525
|
+
arguments: [tx.object(this.objects.endpointV2), asU32(tx, eid)],
|
|
1526
|
+
})
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
/**
|
|
1530
|
+
* Check if an endpoint ID is supported
|
|
1531
|
+
* @param eid - Endpoint ID to check
|
|
1532
|
+
* @returns Promise<boolean> - True if the endpoint ID is supported
|
|
1533
|
+
*/
|
|
1534
|
+
async isSupportedEid(eid: number): Promise<boolean> {
|
|
1535
|
+
return executeSimulate(
|
|
1536
|
+
this.client,
|
|
1537
|
+
(tx) => this.isSupportedEidMoveCall(tx, eid),
|
|
1538
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1539
|
+
)
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
/**
|
|
1543
|
+
* Get send library for an OApp and destination EID
|
|
1544
|
+
* @param tx - The transaction to add the move call to
|
|
1545
|
+
* @param sender - The sender OApp address or transaction argument
|
|
1546
|
+
* @param dstEid - Destination endpoint ID or transaction argument
|
|
1547
|
+
* @returns Transaction result containing the send library info
|
|
1548
|
+
*/
|
|
1549
|
+
getSendLibraryMoveCall(
|
|
1550
|
+
tx: Transaction,
|
|
1551
|
+
sender: string | TransactionArgument,
|
|
1552
|
+
dstEid: number | TransactionArgument
|
|
1553
|
+
): TransactionResult {
|
|
1554
|
+
return tx.moveCall({
|
|
1555
|
+
target: this.#target('get_send_library'),
|
|
1556
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, sender), asU32(tx, dstEid)],
|
|
1557
|
+
})
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* Get send library for an OApp and destination EID
|
|
1562
|
+
* @param sender - The sender OApp address
|
|
1563
|
+
* @param dstEid - Destination endpoint ID
|
|
1564
|
+
* @returns Promise<[string, boolean]> - Tuple of [library address, is default]
|
|
1565
|
+
*/
|
|
1566
|
+
async getSendLibrary(sender: string, dstEid: number): Promise<[string, boolean]> {
|
|
1567
|
+
return executeSimulate(
|
|
1568
|
+
this.client,
|
|
1569
|
+
(tx) => this.getSendLibraryMoveCall(tx, sender, dstEid),
|
|
1570
|
+
(result) => {
|
|
1571
|
+
const lib = bcs.Address.parse(result[0].value)
|
|
1572
|
+
const isDefault = bcs.Bool.parse(result[1].value)
|
|
1573
|
+
return [lib, isDefault]
|
|
1574
|
+
}
|
|
1575
|
+
)
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* Get receive library for an OApp and source EID
|
|
1580
|
+
* @param tx - The transaction to add the move call to
|
|
1581
|
+
* @param receiver - The receiver OApp address or transaction argument
|
|
1582
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1583
|
+
* @returns Transaction result containing the receive library info
|
|
1584
|
+
*/
|
|
1585
|
+
getReceiveLibraryMoveCall(
|
|
1586
|
+
tx: Transaction,
|
|
1587
|
+
receiver: string | TransactionArgument,
|
|
1588
|
+
srcEid: number | TransactionArgument
|
|
1589
|
+
): TransactionResult {
|
|
1590
|
+
return tx.moveCall({
|
|
1591
|
+
target: this.#target('get_receive_library'),
|
|
1592
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, receiver), asU32(tx, srcEid)],
|
|
1593
|
+
})
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* Get receive library for an OApp and source EID
|
|
1598
|
+
* @param receiver - The receiver OApp address
|
|
1599
|
+
* @param srcEid - Source endpoint ID
|
|
1600
|
+
* @returns Promise<[string, boolean]> - Tuple of [library address, is default]
|
|
1601
|
+
*/
|
|
1602
|
+
async getReceiveLibrary(receiver: string, srcEid: number): Promise<[string, boolean]> {
|
|
1603
|
+
return executeSimulate(
|
|
1604
|
+
this.client,
|
|
1605
|
+
(tx) => this.getReceiveLibraryMoveCall(tx, receiver, srcEid),
|
|
1606
|
+
(result) => {
|
|
1607
|
+
const lib = bcs.Address.parse(result[0].value)
|
|
1608
|
+
const isDefault = bcs.Bool.parse(result[1].value)
|
|
1609
|
+
return [lib, isDefault]
|
|
1610
|
+
}
|
|
1611
|
+
)
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
/**
|
|
1615
|
+
* Get receive library timeout for an OApp and source EID
|
|
1616
|
+
* @param tx - The transaction to add the move call to
|
|
1617
|
+
* @param receiver - The receiver OApp address or transaction argument
|
|
1618
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1619
|
+
* @returns Transaction result containing the timeout information
|
|
1620
|
+
*/
|
|
1621
|
+
getReceiveLibraryTimeoutMoveCall(
|
|
1622
|
+
tx: Transaction,
|
|
1623
|
+
receiver: string | TransactionArgument,
|
|
1624
|
+
srcEid: number | TransactionArgument
|
|
1625
|
+
): TransactionResult {
|
|
1626
|
+
return tx.moveCall({
|
|
1627
|
+
target: this.#target('get_receive_library_timeout'),
|
|
1628
|
+
arguments: [tx.object(this.objects.endpointV2), asAddress(tx, receiver), asU32(tx, srcEid)],
|
|
1629
|
+
})
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Get receive library timeout for an OApp and source EID
|
|
1634
|
+
* @param receiver - The receiver OApp address
|
|
1635
|
+
* @param srcEid - Source endpoint ID
|
|
1636
|
+
* @returns Promise<Timeout | null> - The timeout information or null if not set
|
|
1637
|
+
*/
|
|
1638
|
+
async getReceiveLibraryTimeout(receiver: string, srcEid: number): Promise<Timeout | null> {
|
|
1639
|
+
return executeSimulate(
|
|
1640
|
+
this.client,
|
|
1641
|
+
(tx) => this.getReceiveLibraryTimeoutMoveCall(tx, receiver, srcEid),
|
|
1642
|
+
(result) => {
|
|
1643
|
+
const optionBytes = result[0].value
|
|
1644
|
+
const optionValue = bcs.option(TimeoutBcs).parse(optionBytes)
|
|
1645
|
+
if (optionValue) {
|
|
1646
|
+
return {
|
|
1647
|
+
expiry: BigInt(optionValue.expiry),
|
|
1648
|
+
fallbackLib: optionValue.fallback_lib,
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
return null
|
|
1652
|
+
}
|
|
1653
|
+
)
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
/**
|
|
1657
|
+
* Check if a receive library is valid for current time
|
|
1658
|
+
* @param tx - The transaction to add the move call to
|
|
1659
|
+
* @param receiver - The receiver OApp address or transaction argument
|
|
1660
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1661
|
+
* @param actualReceiveLib - The actual receive library address to validate or transaction argument
|
|
1662
|
+
* @returns Transaction result containing the validity status
|
|
1663
|
+
*/
|
|
1664
|
+
isValidReceiveLibraryMoveCall(
|
|
1665
|
+
tx: Transaction,
|
|
1666
|
+
receiver: string | TransactionArgument,
|
|
1667
|
+
srcEid: number | TransactionArgument,
|
|
1668
|
+
actualReceiveLib: string | TransactionArgument
|
|
1669
|
+
): TransactionResult {
|
|
1670
|
+
return tx.moveCall({
|
|
1671
|
+
target: this.#target('is_valid_receive_library'),
|
|
1672
|
+
arguments: [
|
|
1673
|
+
tx.object(this.objects.endpointV2),
|
|
1674
|
+
asAddress(tx, receiver),
|
|
1675
|
+
asU32(tx, srcEid),
|
|
1676
|
+
asAddress(tx, actualReceiveLib),
|
|
1677
|
+
tx.object.clock(),
|
|
1678
|
+
],
|
|
1679
|
+
})
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* Check if a receive library is valid for current time
|
|
1684
|
+
* @param receiver - The receiver OApp address
|
|
1685
|
+
* @param srcEid - Source endpoint ID
|
|
1686
|
+
* @param actualReceiveLib - The actual receive library address to validate
|
|
1687
|
+
* @returns Promise<boolean> - True if the receive library is valid
|
|
1688
|
+
*/
|
|
1689
|
+
async isValidReceiveLibrary(receiver: string, srcEid: number, actualReceiveLib: string): Promise<boolean> {
|
|
1690
|
+
return executeSimulate(
|
|
1691
|
+
this.client,
|
|
1692
|
+
(tx) => this.isValidReceiveLibraryMoveCall(tx, receiver, srcEid, actualReceiveLib),
|
|
1693
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1694
|
+
)
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// Messaging Channel View Functions
|
|
1698
|
+
|
|
1699
|
+
/**
|
|
1700
|
+
* Check if channel is initialized for remote OApp
|
|
1701
|
+
* @param tx - The transaction to add the move call to
|
|
1702
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1703
|
+
* @param remoteEid - Remote endpoint ID or transaction argument
|
|
1704
|
+
* @param remoteOapp - Remote OApp address as bytes or transaction argument
|
|
1705
|
+
* @returns Transaction result containing the initialization status
|
|
1706
|
+
*/
|
|
1707
|
+
isChannelInitedMoveCall(
|
|
1708
|
+
tx: Transaction,
|
|
1709
|
+
messagingChannel: string | TransactionArgument,
|
|
1710
|
+
remoteEid: number | TransactionArgument,
|
|
1711
|
+
remoteOapp: Uint8Array | TransactionArgument
|
|
1712
|
+
): TransactionResult {
|
|
1713
|
+
return tx.moveCall({
|
|
1714
|
+
target: this.#target('is_channel_inited'),
|
|
1715
|
+
arguments: [
|
|
1716
|
+
asObject(tx, messagingChannel),
|
|
1717
|
+
asU32(tx, remoteEid),
|
|
1718
|
+
asBytes32(tx, remoteOapp, this.moduleManager.getUtils()),
|
|
1719
|
+
],
|
|
1720
|
+
})
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* Check if channel is initialized for remote OApp
|
|
1725
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1726
|
+
* @param remoteEid - Remote endpoint ID
|
|
1727
|
+
* @param remoteOapp - Remote OApp address as bytes
|
|
1728
|
+
* @returns Promise<boolean> - True if channel is initialized
|
|
1729
|
+
*/
|
|
1730
|
+
async isChannelInited(messagingChannel: string, remoteEid: number, remoteOapp: Uint8Array): Promise<boolean> {
|
|
1731
|
+
return executeSimulate(
|
|
1732
|
+
this.client,
|
|
1733
|
+
(tx) => this.isChannelInitedMoveCall(tx, messagingChannel, remoteEid, remoteOapp),
|
|
1734
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1735
|
+
)
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
/**
|
|
1739
|
+
* Check if message path is initializable
|
|
1740
|
+
* @param tx - The transaction to add the move call to
|
|
1741
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1742
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1743
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
1744
|
+
* @returns Transaction result containing the initialization status
|
|
1745
|
+
*/
|
|
1746
|
+
initializableMoveCall(
|
|
1747
|
+
tx: Transaction,
|
|
1748
|
+
messagingChannel: string | TransactionArgument,
|
|
1749
|
+
srcEid: number | TransactionArgument,
|
|
1750
|
+
sender: Uint8Array | TransactionArgument
|
|
1751
|
+
): TransactionResult {
|
|
1752
|
+
return tx.moveCall({
|
|
1753
|
+
target: this.#target('initializable'),
|
|
1754
|
+
arguments: [
|
|
1755
|
+
asObject(tx, messagingChannel),
|
|
1756
|
+
asU32(tx, srcEid),
|
|
1757
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
1758
|
+
],
|
|
1759
|
+
})
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* Check if message path is initializable
|
|
1764
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1765
|
+
* @param srcEid - Source endpoint ID
|
|
1766
|
+
* @param sender - Sender address as bytes
|
|
1767
|
+
* @returns Promise<boolean> - True if path is initializable
|
|
1768
|
+
*/
|
|
1769
|
+
async initializable(messagingChannel: string, srcEid: number, sender: Uint8Array): Promise<boolean> {
|
|
1770
|
+
return executeSimulate(
|
|
1771
|
+
this.client,
|
|
1772
|
+
(tx) => this.initializableMoveCall(tx, messagingChannel, srcEid, sender),
|
|
1773
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1774
|
+
)
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Get OApp address from messaging channel
|
|
1779
|
+
* @param tx - The transaction to add the move call to
|
|
1780
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1781
|
+
* @returns Transaction result containing the OApp address
|
|
1782
|
+
*/
|
|
1783
|
+
getOappMoveCall(tx: Transaction, messagingChannel: string | TransactionArgument): TransactionResult {
|
|
1784
|
+
return tx.moveCall({
|
|
1785
|
+
target: this.#target('get_oapp'),
|
|
1786
|
+
arguments: [asObject(tx, messagingChannel)],
|
|
1787
|
+
})
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
/**
|
|
1791
|
+
* Get OApp address from messaging channel
|
|
1792
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1793
|
+
* @returns Promise<string> - The OApp address
|
|
1794
|
+
*/
|
|
1795
|
+
async getOapp(messagingChannel: string): Promise<string> {
|
|
1796
|
+
return executeSimulate(
|
|
1797
|
+
this.client,
|
|
1798
|
+
(tx) => this.getOappMoveCall(tx, messagingChannel),
|
|
1799
|
+
(result) => bcs.Address.parse(result[0].value)
|
|
1800
|
+
)
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
/**
|
|
1804
|
+
* Check if messaging channel is currently sending
|
|
1805
|
+
* @param tx - The transaction to add the move call to
|
|
1806
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1807
|
+
* @returns Transaction result containing the sending status
|
|
1808
|
+
*/
|
|
1809
|
+
isSendingMoveCall(tx: Transaction, messagingChannel: string | TransactionArgument): TransactionResult {
|
|
1810
|
+
return tx.moveCall({
|
|
1811
|
+
target: this.#target('is_sending'),
|
|
1812
|
+
arguments: [asObject(tx, messagingChannel)],
|
|
1813
|
+
})
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
/**
|
|
1817
|
+
* Check if messaging channel is currently sending
|
|
1818
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1819
|
+
* @returns Promise<boolean> - True if the channel is currently sending
|
|
1820
|
+
*/
|
|
1821
|
+
async isSending(messagingChannel: string): Promise<boolean> {
|
|
1822
|
+
return executeSimulate(
|
|
1823
|
+
this.client,
|
|
1824
|
+
(tx) => this.isSendingMoveCall(tx, messagingChannel),
|
|
1825
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
1826
|
+
)
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
/**
|
|
1830
|
+
* Get next GUID for outbound message
|
|
1831
|
+
* @param tx - The transaction to add the move call to
|
|
1832
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1833
|
+
* @param dstEid - Destination endpoint ID or transaction argument
|
|
1834
|
+
* @param receiver - Receiver address as bytes or transaction argument
|
|
1835
|
+
* @returns Transaction result containing the next GUID
|
|
1836
|
+
*/
|
|
1837
|
+
getNextGuidMoveCall(
|
|
1838
|
+
tx: Transaction,
|
|
1839
|
+
messagingChannel: string | TransactionArgument,
|
|
1840
|
+
dstEid: number | TransactionArgument,
|
|
1841
|
+
receiver: Uint8Array | TransactionArgument
|
|
1842
|
+
): TransactionResult {
|
|
1843
|
+
return tx.moveCall({
|
|
1844
|
+
target: this.#target('get_next_guid'),
|
|
1845
|
+
arguments: [
|
|
1846
|
+
tx.object(this.objects.endpointV2),
|
|
1847
|
+
asObject(tx, messagingChannel),
|
|
1848
|
+
asU32(tx, dstEid),
|
|
1849
|
+
asBytes32(tx, receiver, this.moduleManager.getUtils()),
|
|
1850
|
+
],
|
|
1851
|
+
})
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
/**
|
|
1855
|
+
* Get next GUID for outbound message
|
|
1856
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1857
|
+
* @param dstEid - Destination endpoint ID
|
|
1858
|
+
* @param receiver - Receiver address as bytes
|
|
1859
|
+
* @returns Promise<Uint8Array> - The next GUID as bytes
|
|
1860
|
+
*/
|
|
1861
|
+
async getNextGuid(messagingChannel: string, dstEid: number, receiver: Uint8Array): Promise<Uint8Array> {
|
|
1862
|
+
return executeSimulate(
|
|
1863
|
+
this.client,
|
|
1864
|
+
(tx) => this.getNextGuidMoveCall(tx, messagingChannel, dstEid, receiver),
|
|
1865
|
+
(result) => {
|
|
1866
|
+
const parsed = bcs.vector(bcs.u8()).parse(result[0].value)
|
|
1867
|
+
return new Uint8Array(parsed)
|
|
1868
|
+
}
|
|
1869
|
+
)
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
/**
|
|
1873
|
+
* Get outbound nonce for destination
|
|
1874
|
+
* @param tx - The transaction to add the move call to
|
|
1875
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1876
|
+
* @param dstEid - Destination endpoint ID or transaction argument
|
|
1877
|
+
* @param receiver - Receiver address as bytes or transaction argument
|
|
1878
|
+
* @returns Transaction result containing the outbound nonce
|
|
1879
|
+
*/
|
|
1880
|
+
getOutboundNonceMoveCall(
|
|
1881
|
+
tx: Transaction,
|
|
1882
|
+
messagingChannel: string | TransactionArgument,
|
|
1883
|
+
dstEid: number | TransactionArgument,
|
|
1884
|
+
receiver: Uint8Array | TransactionArgument
|
|
1885
|
+
): TransactionResult {
|
|
1886
|
+
return tx.moveCall({
|
|
1887
|
+
target: this.#target('get_outbound_nonce'),
|
|
1888
|
+
arguments: [
|
|
1889
|
+
asObject(tx, messagingChannel),
|
|
1890
|
+
asU32(tx, dstEid),
|
|
1891
|
+
asBytes32(tx, receiver, this.moduleManager.getUtils()),
|
|
1892
|
+
],
|
|
1893
|
+
})
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* Get outbound nonce for destination
|
|
1898
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1899
|
+
* @param dstEid - Destination endpoint ID
|
|
1900
|
+
* @param receiver - Receiver address as bytes
|
|
1901
|
+
* @returns Promise<bigint> - The outbound nonce value
|
|
1902
|
+
*/
|
|
1903
|
+
async getOutboundNonce(messagingChannel: string, dstEid: number, receiver: Uint8Array): Promise<bigint> {
|
|
1904
|
+
return executeSimulate(
|
|
1905
|
+
this.client,
|
|
1906
|
+
(tx) => this.getOutboundNonceMoveCall(tx, messagingChannel, dstEid, receiver),
|
|
1907
|
+
(result) => BigInt(bcs.U64.parse(result[0].value))
|
|
1908
|
+
)
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
/**
|
|
1912
|
+
* Get lazy inbound nonce from source
|
|
1913
|
+
* @param tx - The transaction to add the move call to
|
|
1914
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1915
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1916
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
1917
|
+
* @returns Transaction result containing the lazy inbound nonce
|
|
1918
|
+
*/
|
|
1919
|
+
getLazyInboundNonceMoveCall(
|
|
1920
|
+
tx: Transaction,
|
|
1921
|
+
messagingChannel: string | TransactionArgument,
|
|
1922
|
+
srcEid: number | TransactionArgument,
|
|
1923
|
+
sender: Uint8Array | TransactionArgument
|
|
1924
|
+
): TransactionResult {
|
|
1925
|
+
return tx.moveCall({
|
|
1926
|
+
target: this.#target('get_lazy_inbound_nonce'),
|
|
1927
|
+
arguments: [
|
|
1928
|
+
asObject(tx, messagingChannel),
|
|
1929
|
+
asU32(tx, srcEid),
|
|
1930
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
1931
|
+
],
|
|
1932
|
+
})
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
/**
|
|
1936
|
+
* Get lazy inbound nonce from source
|
|
1937
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1938
|
+
* @param srcEid - Source endpoint ID
|
|
1939
|
+
* @param sender - Sender address as bytes
|
|
1940
|
+
* @returns Promise<bigint> - The lazy inbound nonce value
|
|
1941
|
+
*/
|
|
1942
|
+
async getLazyInboundNonce(messagingChannel: string, srcEid: number, sender: Uint8Array): Promise<bigint> {
|
|
1943
|
+
return executeSimulate(
|
|
1944
|
+
this.client,
|
|
1945
|
+
(tx) => this.getLazyInboundNonceMoveCall(tx, messagingChannel, srcEid, sender),
|
|
1946
|
+
(result) => BigInt(bcs.U64.parse(result[0].value))
|
|
1947
|
+
)
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
/**
|
|
1951
|
+
* Get inbound nonce from source
|
|
1952
|
+
* @param tx - The transaction to add the move call to
|
|
1953
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1954
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1955
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
1956
|
+
* @returns Transaction result containing the inbound nonce
|
|
1957
|
+
*/
|
|
1958
|
+
getInboundNonceMoveCall(
|
|
1959
|
+
tx: Transaction,
|
|
1960
|
+
messagingChannel: string | TransactionArgument,
|
|
1961
|
+
srcEid: number | TransactionArgument,
|
|
1962
|
+
sender: Uint8Array | TransactionArgument
|
|
1963
|
+
): TransactionResult {
|
|
1964
|
+
return tx.moveCall({
|
|
1965
|
+
target: this.#target('get_inbound_nonce'),
|
|
1966
|
+
arguments: [
|
|
1967
|
+
asObject(tx, messagingChannel),
|
|
1968
|
+
asU32(tx, srcEid),
|
|
1969
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
1970
|
+
],
|
|
1971
|
+
})
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
/**
|
|
1975
|
+
* Get inbound nonce from source
|
|
1976
|
+
* @param messagingChannel - The messaging channel object ID
|
|
1977
|
+
* @param srcEid - Source endpoint ID
|
|
1978
|
+
* @param sender - Sender address as bytes
|
|
1979
|
+
* @returns Promise<bigint> - The inbound nonce value
|
|
1980
|
+
*/
|
|
1981
|
+
async getInboundNonce(messagingChannel: string, srcEid: number, sender: Uint8Array): Promise<bigint> {
|
|
1982
|
+
return executeSimulate(
|
|
1983
|
+
this.client,
|
|
1984
|
+
(tx) => this.getInboundNonceMoveCall(tx, messagingChannel, srcEid, sender),
|
|
1985
|
+
(result) => BigInt(bcs.U64.parse(result[0].value))
|
|
1986
|
+
)
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
/**
|
|
1990
|
+
* Check if inbound payload hash exists
|
|
1991
|
+
* @param tx - The transaction to add the move call to
|
|
1992
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
1993
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
1994
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
1995
|
+
* @param nonce - Message nonce or transaction argument
|
|
1996
|
+
* @returns Transaction result containing the payload hash existence status
|
|
1997
|
+
*/
|
|
1998
|
+
hasInboundPayloadHashMoveCall(
|
|
1999
|
+
tx: Transaction,
|
|
2000
|
+
messagingChannel: string | TransactionArgument,
|
|
2001
|
+
srcEid: number | TransactionArgument,
|
|
2002
|
+
sender: Uint8Array | TransactionArgument,
|
|
2003
|
+
nonce: bigint | number | string | TransactionArgument
|
|
2004
|
+
): TransactionResult {
|
|
2005
|
+
return tx.moveCall({
|
|
2006
|
+
target: this.#target('has_inbound_payload_hash'),
|
|
2007
|
+
arguments: [
|
|
2008
|
+
asObject(tx, messagingChannel),
|
|
2009
|
+
asU32(tx, srcEid),
|
|
2010
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
2011
|
+
asU64(tx, nonce),
|
|
2012
|
+
],
|
|
2013
|
+
})
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
/**
|
|
2017
|
+
* Check if inbound payload hash exists
|
|
2018
|
+
* @param messagingChannel - The messaging channel object ID
|
|
2019
|
+
* @param srcEid - Source endpoint ID
|
|
2020
|
+
* @param sender - Sender address as bytes
|
|
2021
|
+
* @param nonce - Message nonce
|
|
2022
|
+
* @returns Promise<boolean> - True if payload hash exists
|
|
2023
|
+
*/
|
|
2024
|
+
async hasInboundPayloadHash(
|
|
2025
|
+
messagingChannel: string,
|
|
2026
|
+
srcEid: number,
|
|
2027
|
+
sender: Uint8Array,
|
|
2028
|
+
nonce: bigint
|
|
2029
|
+
): Promise<boolean> {
|
|
2030
|
+
return executeSimulate(
|
|
2031
|
+
this.client,
|
|
2032
|
+
(tx) => this.hasInboundPayloadHashMoveCall(tx, messagingChannel, srcEid, sender, nonce),
|
|
2033
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
2034
|
+
)
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
/**
|
|
2038
|
+
* Get inbound payload hash
|
|
2039
|
+
* @param tx - The transaction to add the move call to
|
|
2040
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
2041
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
2042
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
2043
|
+
* @param nonce - Message nonce or transaction argument
|
|
2044
|
+
* @returns Transaction result containing the payload hash
|
|
2045
|
+
*/
|
|
2046
|
+
getInboundPayloadHashMoveCall(
|
|
2047
|
+
tx: Transaction,
|
|
2048
|
+
messagingChannel: string | TransactionArgument,
|
|
2049
|
+
srcEid: number | TransactionArgument,
|
|
2050
|
+
sender: Uint8Array | TransactionArgument,
|
|
2051
|
+
nonce: bigint | number | string | TransactionArgument
|
|
2052
|
+
): TransactionResult {
|
|
2053
|
+
return tx.moveCall({
|
|
2054
|
+
target: this.#target('get_inbound_payload_hash'),
|
|
2055
|
+
arguments: [
|
|
2056
|
+
asObject(tx, messagingChannel),
|
|
2057
|
+
asU32(tx, srcEid),
|
|
2058
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
2059
|
+
asU64(tx, nonce),
|
|
2060
|
+
],
|
|
2061
|
+
})
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
/**
|
|
2065
|
+
* Get inbound payload hash
|
|
2066
|
+
* @param messagingChannel - The messaging channel object ID
|
|
2067
|
+
* @param srcEid - Source endpoint ID
|
|
2068
|
+
* @param sender - Sender address as bytes
|
|
2069
|
+
* @param nonce - Message nonce
|
|
2070
|
+
* @returns Promise<Uint8Array | null> - The payload hash as bytes or null if not found
|
|
2071
|
+
*/
|
|
2072
|
+
async getInboundPayloadHash(
|
|
2073
|
+
messagingChannel: string,
|
|
2074
|
+
srcEid: number,
|
|
2075
|
+
sender: Uint8Array,
|
|
2076
|
+
nonce: bigint
|
|
2077
|
+
): Promise<Uint8Array | null> {
|
|
2078
|
+
return executeSimulate(
|
|
2079
|
+
this.client,
|
|
2080
|
+
(tx) => this.getInboundPayloadHashMoveCall(tx, messagingChannel, srcEid, sender, nonce),
|
|
2081
|
+
(result) => {
|
|
2082
|
+
const parsed = bcs.vector(bcs.u8()).parse(result[0].value)
|
|
2083
|
+
return new Uint8Array(parsed)
|
|
2084
|
+
}
|
|
2085
|
+
)
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
/**
|
|
2089
|
+
* Check if message is verifiable
|
|
2090
|
+
* @param tx - The transaction to add the move call to
|
|
2091
|
+
* @param messagingChannel - The messaging channel object ID or transaction argument
|
|
2092
|
+
* @param srcEid - Source endpoint ID or transaction argument
|
|
2093
|
+
* @param sender - Sender address as bytes or transaction argument
|
|
2094
|
+
* @param nonce - Message nonce or transaction argument
|
|
2095
|
+
* @returns Transaction result containing the verifiable status
|
|
2096
|
+
*/
|
|
2097
|
+
verifiableMoveCall(
|
|
2098
|
+
tx: Transaction,
|
|
2099
|
+
messagingChannel: string | TransactionArgument,
|
|
2100
|
+
srcEid: number | TransactionArgument,
|
|
2101
|
+
sender: Uint8Array | TransactionArgument,
|
|
2102
|
+
nonce: bigint | number | string | TransactionArgument
|
|
2103
|
+
): TransactionResult {
|
|
2104
|
+
return tx.moveCall({
|
|
2105
|
+
target: this.#target('verifiable'),
|
|
2106
|
+
arguments: [
|
|
2107
|
+
asObject(tx, messagingChannel),
|
|
2108
|
+
asU32(tx, srcEid),
|
|
2109
|
+
asBytes32(tx, sender, this.moduleManager.getUtils()),
|
|
2110
|
+
asU64(tx, nonce),
|
|
2111
|
+
],
|
|
2112
|
+
})
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
/**
|
|
2116
|
+
* Check if message is verifiable
|
|
2117
|
+
* @param messagingChannel - The messaging channel object ID
|
|
2118
|
+
* @param srcEid - Source endpoint ID
|
|
2119
|
+
* @param sender - Sender address as bytes
|
|
2120
|
+
* @param nonce - Message nonce
|
|
2121
|
+
* @returns Promise<boolean> - True if message is verifiable
|
|
2122
|
+
*/
|
|
2123
|
+
async verifiable(messagingChannel: string, srcEid: number, sender: Uint8Array, nonce: bigint): Promise<boolean> {
|
|
2124
|
+
return executeSimulate(
|
|
2125
|
+
this.client,
|
|
2126
|
+
(tx) => this.verifiableMoveCall(tx, messagingChannel, srcEid, sender, nonce),
|
|
2127
|
+
(result) => bcs.Bool.parse(result[0].value)
|
|
2128
|
+
)
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
// === Quote and Send Functions ===
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
* Quote the messaging fee for sending a message
|
|
2135
|
+
*
|
|
2136
|
+
* This method simulates the transaction to calculate the exact fees required
|
|
2137
|
+
* for sending a cross-chain message, including native and ZRO token fees.
|
|
2138
|
+
*
|
|
2139
|
+
* @param tx - The transaction containing the quote call
|
|
2140
|
+
* @param quoteCall - The quote call transaction result
|
|
2141
|
+
* @param sender - Optional sender address for simulation context
|
|
2142
|
+
* @param maxSimulationTimes - Maximum number of simulation iterations allowed
|
|
2143
|
+
* @returns Promise resolving to MessagingFee with nativeFee and zroFee
|
|
2144
|
+
* @throws Error if simulation fails or validation errors occur
|
|
2145
|
+
*/
|
|
2146
|
+
async quote(
|
|
2147
|
+
tx: Transaction,
|
|
2148
|
+
quoteCall: TransactionResult,
|
|
2149
|
+
sender: string | undefined = undefined,
|
|
2150
|
+
validators: IPTBValidator[] = [],
|
|
2151
|
+
maxSimulationTimes = DEFAULT_SIMULATION_TIMES
|
|
2152
|
+
): Promise<MessagingFee> {
|
|
2153
|
+
await this.populateQuoteTransaction(tx, quoteCall, sender, validators, maxSimulationTimes)
|
|
2154
|
+
|
|
2155
|
+
// apply get fee result move-call
|
|
2156
|
+
const quoteResult = this.moduleManager
|
|
2157
|
+
.getCall()
|
|
2158
|
+
.resultMoveCall(
|
|
2159
|
+
tx,
|
|
2160
|
+
getTypeName(this.moduleManager, LzTypeName.EndpointQuoteParam),
|
|
2161
|
+
getTypeName(this.moduleManager, LzTypeName.MessagingFee),
|
|
2162
|
+
quoteCall
|
|
2163
|
+
)
|
|
2164
|
+
tx.moveCall({
|
|
2165
|
+
target: '0x1::option::borrow',
|
|
2166
|
+
typeArguments: [getTypeName(this.moduleManager, LzTypeName.MessagingFee)],
|
|
2167
|
+
arguments: [quoteResult],
|
|
2168
|
+
})
|
|
2169
|
+
|
|
2170
|
+
const result = await simulateTransaction(this.client, tx)
|
|
2171
|
+
const messageFee = MessagingFeeBcs.parse(result[0].value)
|
|
2172
|
+
return {
|
|
2173
|
+
nativeFee: BigInt(messageFee.native_fee),
|
|
2174
|
+
zroFee: BigInt(messageFee.zro_fee),
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/**
|
|
2179
|
+
* Populate a transaction with all necessary move calls for quoting a message
|
|
2180
|
+
* @param tx - The transaction to populate with move calls
|
|
2181
|
+
* @param quoteCall - The quote call transaction result
|
|
2182
|
+
* @param sender - Optional sender address for simulation context
|
|
2183
|
+
* @param maxSimulationTimes - Maximum number of simulation iterations allowed
|
|
2184
|
+
* @param validators - validators for simulation context (ShareObjectValidator + PackageWhitelistValidator are always ensured, additional validators can be provided)
|
|
2185
|
+
* @throws Error if simulation fails or validation errors occur
|
|
2186
|
+
* @returns Promise<MoveCall[]> - The final move calls that are built
|
|
2187
|
+
*/
|
|
2188
|
+
async populateQuoteTransaction(
|
|
2189
|
+
tx: Transaction,
|
|
2190
|
+
quoteCall: TransactionResult,
|
|
2191
|
+
sender: string | undefined = undefined,
|
|
2192
|
+
validators: IPTBValidator[] = [],
|
|
2193
|
+
maxSimulationTimes = DEFAULT_SIMULATION_TIMES
|
|
2194
|
+
): Promise<MoveCall[]> {
|
|
2195
|
+
const simulateTx = Transaction.from(tx)
|
|
2196
|
+
this.moduleManager.getEndpointPtbBuilder(this.client).buildQuotePtbByCallMoveCall(simulateTx, quoteCall)
|
|
2197
|
+
|
|
2198
|
+
const moveCalls = await this.moduleManager.getPtbBuilder().simulatePtb(simulateTx)
|
|
2199
|
+
|
|
2200
|
+
const [_, finalMoveCalls] = await this.moduleManager
|
|
2201
|
+
.getPtbBuilder()
|
|
2202
|
+
.buildPtb(
|
|
2203
|
+
tx,
|
|
2204
|
+
moveCalls,
|
|
2205
|
+
new Map([[callId(this.moduleManager, CallTypeName.EndpointQuoteCall), quoteCall]]),
|
|
2206
|
+
sender,
|
|
2207
|
+
maxSimulationTimes
|
|
2208
|
+
)
|
|
2209
|
+
|
|
2210
|
+
// Always validate for quote operations (compulsory) - AFTER building with complete moveCalls
|
|
2211
|
+
const allValidators = this.#addRequiredValidators(validators)
|
|
2212
|
+
await validateWithDetails(this.client, finalMoveCalls, allValidators)
|
|
2213
|
+
return finalMoveCalls
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
/**
|
|
2217
|
+
* Populate a transaction with all necessary move calls for sending a message
|
|
2218
|
+
*
|
|
2219
|
+
* This method builds the complete transaction by simulating and resolving all
|
|
2220
|
+
* required move calls, including worker assignments and fee calculations.
|
|
2221
|
+
* It validates all input objects to ensure PTB compatibility.
|
|
2222
|
+
*
|
|
2223
|
+
* @param tx - The transaction to populate with move calls
|
|
2224
|
+
* @param sendCall - The send call transaction result
|
|
2225
|
+
* @param sender - Optional sender address for simulation context
|
|
2226
|
+
* @param validators - validators for simulation context (ShareObjectValidator + PackageWhitelistValidator are always ensured, additional validators can be provided)
|
|
2227
|
+
* @param maxSimulationTimes - Maximum number of simulation iterations allowed
|
|
2228
|
+
* @throws Error if simulation fails, validation errors occur, or objects are not PTB-compatible
|
|
2229
|
+
* @returns Promise<MoveCall[]> - The final move calls that are built
|
|
2230
|
+
*/
|
|
2231
|
+
async populateSendTransaction(
|
|
2232
|
+
tx: Transaction,
|
|
2233
|
+
sendCall: TransactionResult,
|
|
2234
|
+
sender: string | undefined = undefined,
|
|
2235
|
+
validators: IPTBValidator[] = [],
|
|
2236
|
+
maxSimulationTimes = DEFAULT_SIMULATION_TIMES
|
|
2237
|
+
): Promise<MoveCall[]> {
|
|
2238
|
+
const simulateTx = Transaction.from(tx)
|
|
2239
|
+
this.moduleManager.getEndpointPtbBuilder(this.client).buildSendPtbByCallMoveCall(simulateTx, sendCall)
|
|
2240
|
+
|
|
2241
|
+
const moveCalls = await this.moduleManager.getPtbBuilder().simulatePtb(simulateTx)
|
|
2242
|
+
|
|
2243
|
+
const [_, finalMoveCalls] = await this.moduleManager
|
|
2244
|
+
.getPtbBuilder()
|
|
2245
|
+
.buildPtb(
|
|
2246
|
+
tx,
|
|
2247
|
+
moveCalls,
|
|
2248
|
+
new Map([[callId(this.moduleManager, CallTypeName.EndpointSendCall), sendCall]]),
|
|
2249
|
+
sender,
|
|
2250
|
+
maxSimulationTimes
|
|
2251
|
+
)
|
|
2252
|
+
|
|
2253
|
+
// Always validate for send operations (compulsory) - AFTER building with complete moveCalls
|
|
2254
|
+
const allValidators = this.#addRequiredValidators(validators)
|
|
2255
|
+
await validateWithDetails(this.client, finalMoveCalls, allValidators)
|
|
2256
|
+
return finalMoveCalls
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
/**
|
|
2260
|
+
* Populate a transaction with all necessary move calls for setting configuration
|
|
2261
|
+
*
|
|
2262
|
+
* This method builds the complete transaction for updating message library configuration
|
|
2263
|
+
* by simulating and resolving all required move calls.
|
|
2264
|
+
*
|
|
2265
|
+
* @param tx - The transaction to populate with move calls
|
|
2266
|
+
* @param setConfigCall - The set config call transaction result
|
|
2267
|
+
* @param sender - Optional sender address for simulation context
|
|
2268
|
+
* @param validators - validators for simulation context (ShareObjectValidator + PackageWhitelistValidator are always ensured, additional validators can be provided)
|
|
2269
|
+
* @param maxSimulationTimes - Maximum number of simulation iterations allowed
|
|
2270
|
+
* @throws Error if simulation fails or validation errors occur
|
|
2271
|
+
* @returns Promise<MoveCall[]> - The final move calls that are built
|
|
2272
|
+
*/
|
|
2273
|
+
async populateSetConfigTransaction(
|
|
2274
|
+
tx: Transaction,
|
|
2275
|
+
setConfigCall: TransactionResult,
|
|
2276
|
+
sender: string | undefined = undefined,
|
|
2277
|
+
validators: IPTBValidator[] = [],
|
|
2278
|
+
maxSimulationTimes = DEFAULT_SIMULATION_TIMES
|
|
2279
|
+
): Promise<MoveCall[]> {
|
|
2280
|
+
const simulateTx = Transaction.from(tx)
|
|
2281
|
+
this.moduleManager.getEndpointPtbBuilder(this.client).buildSetConfigPtbByCallMoveCall(simulateTx, setConfigCall)
|
|
2282
|
+
|
|
2283
|
+
const moveCalls = await this.moduleManager.getPtbBuilder().simulatePtb(simulateTx)
|
|
2284
|
+
|
|
2285
|
+
const [_, finalMoveCalls] = await this.moduleManager
|
|
2286
|
+
.getPtbBuilder()
|
|
2287
|
+
.buildPtb(
|
|
2288
|
+
tx,
|
|
2289
|
+
moveCalls,
|
|
2290
|
+
new Map([[callId(this.moduleManager, CallTypeName.MessageLibSetConfigCall), setConfigCall]]),
|
|
2291
|
+
sender,
|
|
2292
|
+
maxSimulationTimes
|
|
2293
|
+
)
|
|
2294
|
+
|
|
2295
|
+
// Always validate for set config operations (compulsory) - AFTER building with complete moveCalls
|
|
2296
|
+
const allValidators = this.#addRequiredValidators(validators)
|
|
2297
|
+
await validateWithDetails(this.client, finalMoveCalls, allValidators)
|
|
2298
|
+
|
|
2299
|
+
return finalMoveCalls
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* Populate a transaction with all necessary move calls for receiving a LayerZero message
|
|
2304
|
+
*
|
|
2305
|
+
* This method builds the complete transaction for processing an incoming cross-chain
|
|
2306
|
+
* message, including all required validations and state updates.
|
|
2307
|
+
*
|
|
2308
|
+
* @param tx - The transaction to populate with move calls
|
|
2309
|
+
* @param lzReceiveCall - The LayerZero receive call transaction result
|
|
2310
|
+
* @param oapp - The receiver OApp address
|
|
2311
|
+
* @param sender - Optional sender address for simulation context
|
|
2312
|
+
* @param maxSimulationTimes - Maximum number of simulation iterations allowed
|
|
2313
|
+
* @throws Error if simulation fails or validation errors occur
|
|
2314
|
+
* @returns Promise<MoveCall[]> - The final move calls that are built
|
|
2315
|
+
*/
|
|
2316
|
+
async populateLzReceiveTransaction(
|
|
2317
|
+
tx: Transaction,
|
|
2318
|
+
lzReceiveCall: TransactionResult,
|
|
2319
|
+
oapp: string | TransactionArgument, // receiver oapp
|
|
2320
|
+
sender: string | undefined = undefined,
|
|
2321
|
+
validators: IPTBValidator[] = [],
|
|
2322
|
+
maxSimulationTimes = DEFAULT_SIMULATION_TIMES
|
|
2323
|
+
): Promise<MoveCall[]> {
|
|
2324
|
+
const simulateTx = Transaction.from(tx)
|
|
2325
|
+
this.getOappInfoMoveCall(simulateTx, oapp)
|
|
2326
|
+
const moveCalls = await this.moduleManager.getPtbBuilder().simulateLzReceivePtb(simulateTx, sender)
|
|
2327
|
+
|
|
2328
|
+
const [_, finalMoveCalls] = await this.moduleManager
|
|
2329
|
+
.getPtbBuilder()
|
|
2330
|
+
.buildPtb(
|
|
2331
|
+
tx,
|
|
2332
|
+
moveCalls,
|
|
2333
|
+
new Map([[callId(this.moduleManager, CallTypeName.EndpointLzReceiveCall), lzReceiveCall]]),
|
|
2334
|
+
sender,
|
|
2335
|
+
maxSimulationTimes
|
|
2336
|
+
)
|
|
2337
|
+
|
|
2338
|
+
await validateWithDetails(this.client, finalMoveCalls, validators)
|
|
2339
|
+
|
|
2340
|
+
return finalMoveCalls
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
* Populate a transaction with all necessary move calls for LayerZero compose
|
|
2345
|
+
*
|
|
2346
|
+
* This method builds the complete transaction for processing a LayerZero compose
|
|
2347
|
+
* operation, including all required validations and state updates.
|
|
2348
|
+
*
|
|
2349
|
+
* @param tx - The transaction to populate with move calls
|
|
2350
|
+
* @param endpointLzComposeCall - The LayerZero compose call transaction result
|
|
2351
|
+
* @param composer - The composer address
|
|
2352
|
+
* @param sender - Optional sender address for simulation context
|
|
2353
|
+
* @param maxSimulationTimes - Maximum number of simulation iterations allowed
|
|
2354
|
+
* @throws Error if simulation fails or validation errors occur
|
|
2355
|
+
* @returns Promise<MoveCall[]> - The final move calls that are built
|
|
2356
|
+
*/
|
|
2357
|
+
async populateLzComposeTransaction(
|
|
2358
|
+
tx: Transaction,
|
|
2359
|
+
endpointLzComposeCall: TransactionResult,
|
|
2360
|
+
composer: string | TransactionArgument,
|
|
2361
|
+
sender: string | undefined = undefined,
|
|
2362
|
+
validators: IPTBValidator[] = [],
|
|
2363
|
+
maxSimulationTimes = DEFAULT_SIMULATION_TIMES
|
|
2364
|
+
): Promise<MoveCall[]> {
|
|
2365
|
+
const simulateTx = Transaction.from(tx)
|
|
2366
|
+
this.getComposerInfoMoveCall(simulateTx, composer)
|
|
2367
|
+
const moveCalls = await this.moduleManager.getPtbBuilder().simulateLzComposePtb(simulateTx, sender)
|
|
2368
|
+
|
|
2369
|
+
const [_, finalMoveCalls] = await this.moduleManager
|
|
2370
|
+
.getPtbBuilder()
|
|
2371
|
+
.buildPtb(
|
|
2372
|
+
tx,
|
|
2373
|
+
moveCalls,
|
|
2374
|
+
new Map([[callId(this.moduleManager, CallTypeName.EndpointLzComposeCall), endpointLzComposeCall]]),
|
|
2375
|
+
sender,
|
|
2376
|
+
maxSimulationTimes
|
|
2377
|
+
)
|
|
2378
|
+
|
|
2379
|
+
await validateWithDetails(this.client, finalMoveCalls, validators)
|
|
2380
|
+
|
|
2381
|
+
return finalMoveCalls
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
// === Private Functions ===
|
|
2385
|
+
|
|
2386
|
+
/**
|
|
2387
|
+
* Add required validators if missing, then combine with user validators
|
|
2388
|
+
* @param validators - User-provided validators
|
|
2389
|
+
* @returns Combined array with required validators first, then user validators
|
|
2390
|
+
* @private
|
|
2391
|
+
*/
|
|
2392
|
+
#addRequiredValidators(validators: IPTBValidator[]): IPTBValidator[] {
|
|
2393
|
+
const hasShareValidator = validators.some((v) => v instanceof ShareObjectValidator)
|
|
2394
|
+
const hasPackageValidator = validators.some((v) => v instanceof PackageAllowlistValidator)
|
|
2395
|
+
|
|
2396
|
+
const required: IPTBValidator[] = []
|
|
2397
|
+
if (!hasShareValidator) required.push(new ShareObjectValidator())
|
|
2398
|
+
if (!hasPackageValidator) {
|
|
2399
|
+
// Use SDK to get the correct PackageWhitelistValidator with proper package address
|
|
2400
|
+
const packageWhitelistContract = this.moduleManager.getPackageWhitelistValidator(this.client)
|
|
2401
|
+
required.push(new PackageAllowlistValidator([], packageWhitelistContract))
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
return [...required, ...validators]
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
/**
|
|
2408
|
+
* Generate the full target path for move calls
|
|
2409
|
+
* @param functionName - The function name to call
|
|
2410
|
+
* @param moduleName - The module name (defaults to MODULE_NAME)
|
|
2411
|
+
* @returns The full module path for the move call
|
|
2412
|
+
* @private
|
|
2413
|
+
*/
|
|
2414
|
+
#target(functionName: string, moduleName: string = MODULE_NAME): string {
|
|
2415
|
+
return `${this.packageId}::${moduleName}::${functionName}`
|
|
2416
|
+
}
|
|
2417
|
+
}
|