@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,902 @@
|
|
|
1
|
+
import { CoinStruct, IotaClient } from '@iota/iota-sdk/client'
|
|
2
|
+
import { Transaction, TransactionArgument, TransactionResult } from '@iota/iota-sdk/transactions'
|
|
3
|
+
|
|
4
|
+
import { asAddress, asBool, asBytes, asBytes32, asObject, asU128, asU16, asU256, asU32, asU64, asU8 } from '../utils'
|
|
5
|
+
|
|
6
|
+
const BYTES32_MODULE_NAME = 'bytes32'
|
|
7
|
+
const BUFFER_READER_MODULE_NAME = 'buffer_reader'
|
|
8
|
+
const BUFFER_WRITER_MODULE_NAME = 'buffer_writer'
|
|
9
|
+
const PACKAGE_MODULE_NAME = 'package'
|
|
10
|
+
|
|
11
|
+
export const UtilsErrorCode = {
|
|
12
|
+
// Utils related errors (with Utils_ prefix)
|
|
13
|
+
Utils_EInvalidLength: 1,
|
|
14
|
+
} as const
|
|
15
|
+
|
|
16
|
+
export class Utils {
|
|
17
|
+
public packageId: string
|
|
18
|
+
public readonly client: IotaClient
|
|
19
|
+
|
|
20
|
+
constructor(packageId: string, client: IotaClient) {
|
|
21
|
+
this.packageId = packageId
|
|
22
|
+
this.client = client
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// === bytes32 Functions ===
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a bytes32 from a byte array
|
|
29
|
+
* @param tx - The transaction to add the move call to
|
|
30
|
+
* @param peer - The byte array to convert to bytes32 or transaction argument
|
|
31
|
+
* @returns Transaction result containing the bytes32 value
|
|
32
|
+
*/
|
|
33
|
+
fromBytesMoveCall(tx: Transaction, peer: Uint8Array | TransactionArgument): TransactionResult {
|
|
34
|
+
return tx.moveCall({
|
|
35
|
+
target: this.#target('from_bytes'),
|
|
36
|
+
arguments: [asBytes(tx, peer)],
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create a bytes32 from a byte array with left padding
|
|
42
|
+
* @param tx - The transaction to add the move call to
|
|
43
|
+
* @param bytes - The byte array to convert with left padding or transaction argument
|
|
44
|
+
* @returns Transaction result containing the left-padded bytes32 value
|
|
45
|
+
*/
|
|
46
|
+
fromBytesLeftPaddedMoveCall(tx: Transaction, bytes: Uint8Array | TransactionArgument): TransactionResult {
|
|
47
|
+
return tx.moveCall({
|
|
48
|
+
target: this.#target('from_bytes_left_padded'),
|
|
49
|
+
arguments: [asBytes(tx, bytes)],
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create a bytes32 from a byte array with right padding
|
|
55
|
+
* @param tx - The transaction to add the move call to
|
|
56
|
+
* @param bytes - The byte array to convert with right padding or transaction argument
|
|
57
|
+
* @returns Transaction result containing the right-padded bytes32 value
|
|
58
|
+
*/
|
|
59
|
+
fromBytesRightPaddedMoveCall(tx: Transaction, bytes: Uint8Array | TransactionArgument): TransactionResult {
|
|
60
|
+
return tx.moveCall({
|
|
61
|
+
target: this.#target('from_bytes_right_padded'),
|
|
62
|
+
arguments: [asBytes(tx, bytes)],
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create a bytes32 from an address
|
|
68
|
+
* @param tx - The transaction to add the move call to
|
|
69
|
+
* @param address - The address to convert to bytes32 or transaction argument
|
|
70
|
+
* @returns Transaction result containing the bytes32 representation of the address
|
|
71
|
+
*/
|
|
72
|
+
fromAddressMoveCall(tx: Transaction, address: string | TransactionArgument): TransactionResult {
|
|
73
|
+
return tx.moveCall({
|
|
74
|
+
target: this.#target('from_address'),
|
|
75
|
+
arguments: [asAddress(tx, address)],
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create a bytes32 from an object ID
|
|
81
|
+
* @param tx - The transaction to add the move call to
|
|
82
|
+
* @param id - The object ID to convert to bytes32 or transaction argument
|
|
83
|
+
* @returns Transaction result containing the bytes32 representation of the ID
|
|
84
|
+
*/
|
|
85
|
+
fromIdMoveCall(tx: Transaction, id: string | TransactionArgument): TransactionResult {
|
|
86
|
+
return tx.moveCall({
|
|
87
|
+
target: this.#target('from_id'),
|
|
88
|
+
arguments: [asObject(tx, id)],
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create a zero bytes32 value (all zeros)
|
|
94
|
+
* @param tx - The transaction to add the move call to
|
|
95
|
+
* @returns Transaction result containing a zero bytes32
|
|
96
|
+
*/
|
|
97
|
+
zeroBytes32MoveCall(tx: Transaction): TransactionResult {
|
|
98
|
+
return tx.moveCall({
|
|
99
|
+
target: this.#target('zero_bytes32'),
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Create a bytes32 with all bits set to 1 (0xff...)
|
|
105
|
+
* @param tx - The transaction to add the move call to
|
|
106
|
+
* @returns Transaction result containing a bytes32 with all bits set
|
|
107
|
+
*/
|
|
108
|
+
ffBytes32MoveCall(tx: Transaction): TransactionResult {
|
|
109
|
+
return tx.moveCall({
|
|
110
|
+
target: this.#target('ff_bytes32'),
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Check if a bytes32 value is zero (all zeros)
|
|
116
|
+
* @param tx - The transaction to add the move call to
|
|
117
|
+
* @param bytes32 - The bytes32 value to check or transaction argument
|
|
118
|
+
* @returns Transaction result containing a boolean indicating if the value is zero
|
|
119
|
+
*/
|
|
120
|
+
isZeroMoveCall(tx: Transaction, bytes32: TransactionArgument): TransactionResult {
|
|
121
|
+
return tx.moveCall({
|
|
122
|
+
target: this.#target('is_zero'),
|
|
123
|
+
arguments: [bytes32],
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Check if a bytes32 value has all bits set to 1
|
|
129
|
+
* @param tx - The transaction to add the move call to
|
|
130
|
+
* @param bytes32 - The bytes32 value to check or transaction argument
|
|
131
|
+
* @returns Transaction result containing a boolean indicating if all bits are set
|
|
132
|
+
*/
|
|
133
|
+
isFfMoveCall(tx: Transaction, bytes32: TransactionArgument): TransactionResult {
|
|
134
|
+
return tx.moveCall({
|
|
135
|
+
target: this.#target('is_ff'),
|
|
136
|
+
arguments: [bytes32],
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Convert a bytes32 to a byte array
|
|
142
|
+
* @param tx - The transaction to add the move call to
|
|
143
|
+
* @param bytes32 - The bytes32 value to convert or transaction argument
|
|
144
|
+
* @returns Transaction result containing the byte array representation
|
|
145
|
+
*/
|
|
146
|
+
toBytesMoveCall(tx: Transaction, bytes32: TransactionArgument): TransactionResult {
|
|
147
|
+
return tx.moveCall({
|
|
148
|
+
target: this.#target('to_bytes'),
|
|
149
|
+
arguments: [bytes32],
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Convert a bytes32 to an address
|
|
155
|
+
* @param tx - The transaction to add the move call to
|
|
156
|
+
* @param bytes32 - The bytes32 value to convert or transaction argument
|
|
157
|
+
* @returns Transaction result containing the address representation
|
|
158
|
+
*/
|
|
159
|
+
toAddressMoveCall(tx: Transaction, bytes32: TransactionArgument): TransactionResult {
|
|
160
|
+
return tx.moveCall({
|
|
161
|
+
target: this.#target('to_address'),
|
|
162
|
+
arguments: [bytes32],
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Convert a bytes32 to an object ID
|
|
168
|
+
* @param tx - The transaction to add the move call to
|
|
169
|
+
* @param bytes32 - The bytes32 value to convert or transaction argument
|
|
170
|
+
* @returns Transaction result containing the object ID representation
|
|
171
|
+
*/
|
|
172
|
+
toIdMoveCall(tx: Transaction, bytes32: TransactionArgument): TransactionResult {
|
|
173
|
+
return tx.moveCall({
|
|
174
|
+
target: this.#target('to_id'),
|
|
175
|
+
arguments: [bytes32],
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// === Reader Buffer Functions ===
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Create a new buffer reader from a byte array
|
|
183
|
+
* @param tx - The transaction to add the move call to
|
|
184
|
+
* @param buffer - The byte array to create the reader from or transaction argument
|
|
185
|
+
* @returns Transaction result containing the buffer reader
|
|
186
|
+
*/
|
|
187
|
+
newReaderMoveCall(tx: Transaction, buffer: Uint8Array | TransactionArgument): TransactionResult {
|
|
188
|
+
return tx.moveCall({
|
|
189
|
+
target: this.#target('create', BUFFER_READER_MODULE_NAME),
|
|
190
|
+
arguments: [asBytes(tx, buffer)],
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Get the current position of the buffer reader
|
|
196
|
+
* @param tx - The transaction to add the move call to
|
|
197
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
198
|
+
* @returns Transaction result containing the current position
|
|
199
|
+
*/
|
|
200
|
+
positionMoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
201
|
+
return tx.moveCall({
|
|
202
|
+
target: this.#target('position', BUFFER_READER_MODULE_NAME),
|
|
203
|
+
arguments: [reader],
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Get the remaining length of data in the buffer reader
|
|
209
|
+
* @param tx - The transaction to add the move call to
|
|
210
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
211
|
+
* @returns Transaction result containing the remaining length
|
|
212
|
+
*/
|
|
213
|
+
remainingLengthMoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
214
|
+
return tx.moveCall({
|
|
215
|
+
target: this.#target('remaining_length', BUFFER_READER_MODULE_NAME),
|
|
216
|
+
arguments: [reader],
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Skip a specified number of bytes in the buffer reader
|
|
222
|
+
* @param tx - The transaction to add the move call to
|
|
223
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
224
|
+
* @param len - The number of bytes to skip or transaction argument
|
|
225
|
+
* @returns Transaction result containing the updated reader
|
|
226
|
+
*/
|
|
227
|
+
skipMoveCall(tx: Transaction, reader: TransactionArgument, len: number | TransactionArgument): TransactionResult {
|
|
228
|
+
return tx.moveCall({
|
|
229
|
+
target: this.#target('skip', BUFFER_READER_MODULE_NAME),
|
|
230
|
+
arguments: [reader, asU64(tx, len)],
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Set the position of the buffer reader
|
|
236
|
+
* @param tx - The transaction to add the move call to
|
|
237
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
238
|
+
* @param position - The position to set or transaction argument
|
|
239
|
+
* @returns Transaction result containing the updated reader
|
|
240
|
+
*/
|
|
241
|
+
setPositionMoveCall(
|
|
242
|
+
tx: Transaction,
|
|
243
|
+
reader: TransactionArgument,
|
|
244
|
+
position: number | TransactionArgument
|
|
245
|
+
): TransactionResult {
|
|
246
|
+
return tx.moveCall({
|
|
247
|
+
target: this.#target('set_position', BUFFER_READER_MODULE_NAME),
|
|
248
|
+
arguments: [reader, asU64(tx, position)],
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Rewind the buffer reader by a specified number of bytes
|
|
254
|
+
* @param tx - The transaction to add the move call to
|
|
255
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
256
|
+
* @param len - The number of bytes to rewind or transaction argument
|
|
257
|
+
* @returns Transaction result containing the updated reader
|
|
258
|
+
*/
|
|
259
|
+
rewindMoveCall(tx: Transaction, reader: TransactionArgument, len: number | TransactionArgument): TransactionResult {
|
|
260
|
+
return tx.moveCall({
|
|
261
|
+
target: this.#target('rewind', BUFFER_READER_MODULE_NAME),
|
|
262
|
+
arguments: [reader, asU64(tx, len)],
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Read a boolean value from the buffer reader
|
|
268
|
+
* @param tx - The transaction to add the move call to
|
|
269
|
+
* @param reader - The buffer reader instance
|
|
270
|
+
* @returns Transaction result containing the boolean value
|
|
271
|
+
*/
|
|
272
|
+
readBoolMoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
273
|
+
return tx.moveCall({
|
|
274
|
+
target: this.#target('read_bool', BUFFER_READER_MODULE_NAME),
|
|
275
|
+
arguments: [reader],
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Read a u8 value from the buffer reader
|
|
281
|
+
* @param tx - The transaction to add the move call to
|
|
282
|
+
* @param reader - The buffer reader instance
|
|
283
|
+
* @returns Transaction result containing the u8 value
|
|
284
|
+
*/
|
|
285
|
+
readU8MoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
286
|
+
return tx.moveCall({
|
|
287
|
+
target: this.#target('read_u8', BUFFER_READER_MODULE_NAME),
|
|
288
|
+
arguments: [reader],
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Read a u16 value from the buffer reader
|
|
294
|
+
* @param tx - The transaction to add the move call to
|
|
295
|
+
* @param reader - The buffer reader instance
|
|
296
|
+
* @returns Transaction result containing the u16 value
|
|
297
|
+
*/
|
|
298
|
+
readU16MoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
299
|
+
return tx.moveCall({
|
|
300
|
+
target: this.#target('read_u16', BUFFER_READER_MODULE_NAME),
|
|
301
|
+
arguments: [reader],
|
|
302
|
+
})
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Read a u32 value from the buffer reader
|
|
307
|
+
* @param tx - The transaction to add the move call to
|
|
308
|
+
* @param reader - The buffer reader instance
|
|
309
|
+
* @returns Transaction result containing the u32 value
|
|
310
|
+
*/
|
|
311
|
+
readU32MoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
312
|
+
return tx.moveCall({
|
|
313
|
+
target: this.#target('read_u32', BUFFER_READER_MODULE_NAME),
|
|
314
|
+
arguments: [reader],
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Read a u64 value from the buffer reader
|
|
320
|
+
* @param tx - The transaction to add the move call to
|
|
321
|
+
* @param reader - The buffer reader instance
|
|
322
|
+
* @returns Transaction result containing the u64 value
|
|
323
|
+
*/
|
|
324
|
+
readU64MoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
325
|
+
return tx.moveCall({
|
|
326
|
+
target: this.#target('read_u64', BUFFER_READER_MODULE_NAME),
|
|
327
|
+
arguments: [reader],
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Read a u128 value from the buffer reader
|
|
333
|
+
* @param tx - The transaction to add the move call to
|
|
334
|
+
* @param reader - The buffer reader instance
|
|
335
|
+
* @returns Transaction result containing the u128 value
|
|
336
|
+
*/
|
|
337
|
+
readU128MoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
338
|
+
return tx.moveCall({
|
|
339
|
+
target: this.#target('read_u128', BUFFER_READER_MODULE_NAME),
|
|
340
|
+
arguments: [reader],
|
|
341
|
+
})
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Read a u256 value from the buffer reader
|
|
346
|
+
* @param tx - The transaction to add the move call to
|
|
347
|
+
* @param reader - The buffer reader instance
|
|
348
|
+
* @returns Transaction result containing the u256 value
|
|
349
|
+
*/
|
|
350
|
+
readU256MoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
351
|
+
return tx.moveCall({
|
|
352
|
+
target: this.#target('read_u256', BUFFER_READER_MODULE_NAME),
|
|
353
|
+
arguments: [reader],
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Read a bytes32 value from the buffer reader
|
|
359
|
+
* @param tx - The transaction to add the move call to
|
|
360
|
+
* @param reader - The buffer reader instance
|
|
361
|
+
* @returns Transaction result containing the bytes32 value
|
|
362
|
+
*/
|
|
363
|
+
readBytes32MoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
364
|
+
return tx.moveCall({
|
|
365
|
+
target: this.#target('read_bytes32', BUFFER_READER_MODULE_NAME),
|
|
366
|
+
arguments: [reader],
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Read an address value from the buffer reader
|
|
372
|
+
* @param tx - The transaction to add the move call to
|
|
373
|
+
* @param reader - The buffer reader instance
|
|
374
|
+
* @returns Transaction result containing the address value
|
|
375
|
+
*/
|
|
376
|
+
readAddressMoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
377
|
+
return tx.moveCall({
|
|
378
|
+
target: this.#target('read_address', BUFFER_READER_MODULE_NAME),
|
|
379
|
+
arguments: [reader],
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Read a fixed-length byte array from the buffer reader
|
|
385
|
+
* @param tx - The transaction to add the move call to
|
|
386
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
387
|
+
* @param len - The length of bytes to read or transaction argument
|
|
388
|
+
* @returns Transaction result containing the byte array
|
|
389
|
+
*/
|
|
390
|
+
readFixedLenBytesMoveCall(
|
|
391
|
+
tx: Transaction,
|
|
392
|
+
reader: TransactionArgument,
|
|
393
|
+
len: number | TransactionArgument
|
|
394
|
+
): TransactionResult {
|
|
395
|
+
return tx.moveCall({
|
|
396
|
+
target: this.#target('read_fixed_len_bytes', BUFFER_READER_MODULE_NAME),
|
|
397
|
+
arguments: [reader, asU64(tx, len)],
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Read all remaining bytes from the buffer reader until the end
|
|
403
|
+
* @param tx - The transaction to add the move call to
|
|
404
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
405
|
+
* @returns Transaction result containing the remaining bytes
|
|
406
|
+
*/
|
|
407
|
+
readBytesUntilEndMoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
408
|
+
return tx.moveCall({
|
|
409
|
+
target: this.#target('read_bytes_until_end', BUFFER_READER_MODULE_NAME),
|
|
410
|
+
arguments: [reader],
|
|
411
|
+
})
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Get the total buffer length of the reader
|
|
416
|
+
* @param tx - The transaction to add the move call to
|
|
417
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
418
|
+
* @returns Transaction result containing the total buffer length
|
|
419
|
+
*/
|
|
420
|
+
readerBufferLengthMoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
421
|
+
return tx.moveCall({
|
|
422
|
+
target: this.#target('length', BUFFER_READER_MODULE_NAME),
|
|
423
|
+
arguments: [reader],
|
|
424
|
+
})
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Convert the buffer reader to a byte array
|
|
429
|
+
* @param tx - The transaction to add the move call to
|
|
430
|
+
* @param reader - The buffer reader instance or transaction argument
|
|
431
|
+
* @returns Transaction result containing the byte array representation
|
|
432
|
+
*/
|
|
433
|
+
readerToBytesMoveCall(tx: Transaction, reader: TransactionArgument): TransactionResult {
|
|
434
|
+
return tx.moveCall({
|
|
435
|
+
target: this.#target('to_bytes', BUFFER_READER_MODULE_NAME),
|
|
436
|
+
arguments: [reader],
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Writer functions
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Create a new empty buffer writer
|
|
444
|
+
* @param tx - The transaction to add the move call to
|
|
445
|
+
* @returns Transaction result containing the buffer writer
|
|
446
|
+
*/
|
|
447
|
+
newWriterMoveCall(tx: Transaction): TransactionResult {
|
|
448
|
+
return tx.moveCall({
|
|
449
|
+
target: this.#target('new', BUFFER_WRITER_MODULE_NAME),
|
|
450
|
+
})
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Create a buffer writer with initial data
|
|
455
|
+
* @param tx - The transaction to add the move call to
|
|
456
|
+
* @param buffer - The initial byte array data for the writer or transaction argument
|
|
457
|
+
* @returns Transaction result containing the buffer writer
|
|
458
|
+
*/
|
|
459
|
+
createWriterMoveCall(tx: Transaction, buffer: Uint8Array | TransactionArgument): TransactionResult {
|
|
460
|
+
return tx.moveCall({
|
|
461
|
+
target: this.#target('create', BUFFER_WRITER_MODULE_NAME),
|
|
462
|
+
arguments: [asBytes(tx, buffer)],
|
|
463
|
+
})
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Get the total buffer length of the writer
|
|
468
|
+
* @param tx - The transaction to add the move call to
|
|
469
|
+
* @param writer - The buffer writer instance
|
|
470
|
+
* @returns Transaction result containing the total buffer length
|
|
471
|
+
*/
|
|
472
|
+
writerBufferLengthMoveCall(tx: Transaction, writer: TransactionArgument): TransactionResult {
|
|
473
|
+
return tx.moveCall({
|
|
474
|
+
target: this.#target('length', BUFFER_WRITER_MODULE_NAME),
|
|
475
|
+
arguments: [writer],
|
|
476
|
+
})
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Convert the buffer writer to a byte array
|
|
481
|
+
* @param tx - The transaction to add the move call to
|
|
482
|
+
* @param writer - The buffer writer instance
|
|
483
|
+
* @returns Transaction result containing the byte array representation
|
|
484
|
+
*/
|
|
485
|
+
writerToBytesMoveCall(tx: Transaction, writer: TransactionArgument): TransactionResult {
|
|
486
|
+
return tx.moveCall({
|
|
487
|
+
target: this.#target('to_bytes', BUFFER_WRITER_MODULE_NAME),
|
|
488
|
+
arguments: [writer],
|
|
489
|
+
})
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Write a boolean value to the buffer writer
|
|
494
|
+
* @param tx - The transaction to add the move call to
|
|
495
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
496
|
+
* @param value - The boolean value to write or transaction argument
|
|
497
|
+
* @returns Transaction result containing the updated writer
|
|
498
|
+
*/
|
|
499
|
+
writeBoolMoveCall(
|
|
500
|
+
tx: Transaction,
|
|
501
|
+
writer: TransactionArgument,
|
|
502
|
+
value: boolean | TransactionArgument
|
|
503
|
+
): TransactionResult {
|
|
504
|
+
return tx.moveCall({
|
|
505
|
+
target: this.#target('write_bool', BUFFER_WRITER_MODULE_NAME),
|
|
506
|
+
arguments: [writer, asBool(tx, value)],
|
|
507
|
+
})
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Write a u8 value to the buffer writer
|
|
512
|
+
* @param tx - The transaction to add the move call to
|
|
513
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
514
|
+
* @param value - The u8 value to write or transaction argument
|
|
515
|
+
* @returns Transaction result containing the updated writer
|
|
516
|
+
*/
|
|
517
|
+
writeU8MoveCall(
|
|
518
|
+
tx: Transaction,
|
|
519
|
+
writer: TransactionArgument,
|
|
520
|
+
value: number | TransactionArgument
|
|
521
|
+
): TransactionResult {
|
|
522
|
+
return tx.moveCall({
|
|
523
|
+
target: this.#target('write_u8', BUFFER_WRITER_MODULE_NAME),
|
|
524
|
+
arguments: [writer, asU8(tx, value)],
|
|
525
|
+
})
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Write a u16 value to the buffer writer
|
|
530
|
+
* @param tx - The transaction to add the move call to
|
|
531
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
532
|
+
* @param value - The u16 value to write or transaction argument
|
|
533
|
+
* @returns Transaction result containing the updated writer
|
|
534
|
+
*/
|
|
535
|
+
writeU16MoveCall(
|
|
536
|
+
tx: Transaction,
|
|
537
|
+
writer: TransactionArgument,
|
|
538
|
+
value: number | TransactionArgument
|
|
539
|
+
): TransactionResult {
|
|
540
|
+
return tx.moveCall({
|
|
541
|
+
target: this.#target('write_u16', BUFFER_WRITER_MODULE_NAME),
|
|
542
|
+
arguments: [writer, asU16(tx, value)],
|
|
543
|
+
})
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Write a u32 value to the buffer writer
|
|
548
|
+
* @param tx - The transaction to add the move call to
|
|
549
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
550
|
+
* @param value - The u32 value to write or transaction argument
|
|
551
|
+
* @returns Transaction result containing the updated writer
|
|
552
|
+
*/
|
|
553
|
+
writeU32MoveCall(
|
|
554
|
+
tx: Transaction,
|
|
555
|
+
writer: TransactionArgument,
|
|
556
|
+
value: number | TransactionArgument
|
|
557
|
+
): TransactionResult {
|
|
558
|
+
return tx.moveCall({
|
|
559
|
+
target: this.#target('write_u32', BUFFER_WRITER_MODULE_NAME),
|
|
560
|
+
arguments: [writer, asU32(tx, value)],
|
|
561
|
+
})
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Write a u64 value to the buffer writer
|
|
566
|
+
* @param tx - The transaction to add the move call to
|
|
567
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
568
|
+
* @param value - The u64 value to write or transaction argument
|
|
569
|
+
* @returns Transaction result containing the updated writer
|
|
570
|
+
*/
|
|
571
|
+
writeU64MoveCall(
|
|
572
|
+
tx: Transaction,
|
|
573
|
+
writer: TransactionArgument,
|
|
574
|
+
value: bigint | number | string | TransactionArgument
|
|
575
|
+
): TransactionResult {
|
|
576
|
+
return tx.moveCall({
|
|
577
|
+
target: this.#target('write_u64', BUFFER_WRITER_MODULE_NAME),
|
|
578
|
+
arguments: [writer, asU64(tx, value)],
|
|
579
|
+
})
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Write a u128 value to the buffer writer
|
|
584
|
+
* @param tx - The transaction to add the move call to
|
|
585
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
586
|
+
* @param value - The u128 value to write or transaction argument
|
|
587
|
+
* @returns Transaction result containing the updated writer
|
|
588
|
+
*/
|
|
589
|
+
writeU128MoveCall(
|
|
590
|
+
tx: Transaction,
|
|
591
|
+
writer: TransactionArgument,
|
|
592
|
+
value: bigint | number | string | TransactionArgument
|
|
593
|
+
): TransactionResult {
|
|
594
|
+
return tx.moveCall({
|
|
595
|
+
target: this.#target('write_u128', BUFFER_WRITER_MODULE_NAME),
|
|
596
|
+
arguments: [writer, asU128(tx, value)],
|
|
597
|
+
})
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Write a u256 value to the buffer writer
|
|
602
|
+
* @param tx - The transaction to add the move call to
|
|
603
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
604
|
+
* @param value - The u256 value to write or transaction argument
|
|
605
|
+
* @returns Transaction result containing the updated writer
|
|
606
|
+
*/
|
|
607
|
+
writeU256MoveCall(
|
|
608
|
+
tx: Transaction,
|
|
609
|
+
writer: TransactionArgument,
|
|
610
|
+
value: bigint | number | string | TransactionArgument
|
|
611
|
+
): TransactionResult {
|
|
612
|
+
return tx.moveCall({
|
|
613
|
+
target: this.#target('write_u256', BUFFER_WRITER_MODULE_NAME),
|
|
614
|
+
arguments: [writer, asU256(tx, value)],
|
|
615
|
+
})
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Write a byte array to the buffer writer
|
|
620
|
+
* @param tx - The transaction to add the move call to
|
|
621
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
622
|
+
* @param bytes - The byte array to write or transaction argument
|
|
623
|
+
* @returns Transaction result containing the updated writer
|
|
624
|
+
*/
|
|
625
|
+
writeBytesMoveCall(
|
|
626
|
+
tx: Transaction,
|
|
627
|
+
writer: TransactionArgument,
|
|
628
|
+
bytes: Uint8Array | TransactionArgument
|
|
629
|
+
): TransactionResult {
|
|
630
|
+
return tx.moveCall({
|
|
631
|
+
target: this.#target('write_bytes', BUFFER_WRITER_MODULE_NAME),
|
|
632
|
+
arguments: [writer, asBytes(tx, bytes)],
|
|
633
|
+
})
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Write an address to the buffer writer
|
|
638
|
+
* @param tx - The transaction to add the move call to
|
|
639
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
640
|
+
* @param address - The address to write or transaction argument
|
|
641
|
+
* @returns Transaction result containing the updated writer
|
|
642
|
+
*/
|
|
643
|
+
writeAddressMoveCall(
|
|
644
|
+
tx: Transaction,
|
|
645
|
+
writer: TransactionArgument,
|
|
646
|
+
address: string | TransactionArgument
|
|
647
|
+
): TransactionResult {
|
|
648
|
+
return tx.moveCall({
|
|
649
|
+
target: this.#target('write_address', BUFFER_WRITER_MODULE_NAME),
|
|
650
|
+
arguments: [writer, asAddress(tx, address)],
|
|
651
|
+
})
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Write a bytes32 value to the buffer writer
|
|
656
|
+
* @param tx - The transaction to add the move call to
|
|
657
|
+
* @param writer - The buffer writer instance or transaction argument
|
|
658
|
+
* @param bytes32 - The bytes32 value to write (as Uint8Array) or transaction argument
|
|
659
|
+
* @returns Transaction result containing the updated writer
|
|
660
|
+
*/
|
|
661
|
+
writeBytes32MoveCall(
|
|
662
|
+
tx: Transaction,
|
|
663
|
+
writer: TransactionArgument,
|
|
664
|
+
bytes32: Uint8Array | TransactionArgument
|
|
665
|
+
): TransactionResult {
|
|
666
|
+
return tx.moveCall({
|
|
667
|
+
target: this.#target('write_bytes32', BUFFER_WRITER_MODULE_NAME),
|
|
668
|
+
arguments: [writer, asBytes32(tx, bytes32, this)],
|
|
669
|
+
})
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// === Package Functions ===
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Get the original package address where a type was first defined
|
|
676
|
+
* @param tx - The transaction to add the move call to
|
|
677
|
+
* @param typeArgument - The type to get the original package address for
|
|
678
|
+
* @returns Transaction result containing the original package address
|
|
679
|
+
*/
|
|
680
|
+
originalPackageOfTypeMoveCall(tx: Transaction, typeArgument: string): TransactionResult {
|
|
681
|
+
return tx.moveCall({
|
|
682
|
+
target: this.#target('original_package_of_type', PACKAGE_MODULE_NAME),
|
|
683
|
+
typeArguments: [typeArgument],
|
|
684
|
+
})
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Get the current package address where a type is defined
|
|
689
|
+
* @param tx - The transaction to add the move call to
|
|
690
|
+
* @param typeArgument - The type to get the current package address for
|
|
691
|
+
* @returns Transaction result containing the current package address
|
|
692
|
+
*/
|
|
693
|
+
packageOfTypeMoveCall(tx: Transaction, typeArgument: string): TransactionResult {
|
|
694
|
+
return tx.moveCall({
|
|
695
|
+
target: this.#target('package_of_type', PACKAGE_MODULE_NAME),
|
|
696
|
+
typeArguments: [typeArgument],
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// === Other Package Utils Functions ===
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Create an Option<Coin<IOTA>> from a value
|
|
704
|
+
* @param tx - The transaction to add the move call to
|
|
705
|
+
* @param value - The amount of IOTA to wrap in the option
|
|
706
|
+
* @returns Transaction result containing option::none for zero values, option::some otherwise
|
|
707
|
+
* @note TransactionArguments always create option::some (runtime values cannot be evaluated)
|
|
708
|
+
*/
|
|
709
|
+
createOptionIotaL1Call(
|
|
710
|
+
tx: Transaction,
|
|
711
|
+
value: bigint | number | string | TransactionArgument
|
|
712
|
+
): TransactionResult {
|
|
713
|
+
if (this.isZeroValue(value)) {
|
|
714
|
+
return this._createOptionNone(tx)
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
return this._createOptionSome(tx, value)
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Check if a static value (non-TransactionArgument) is zero
|
|
722
|
+
*/
|
|
723
|
+
private isZeroValue(value: bigint | number | string | TransactionArgument): boolean {
|
|
724
|
+
if (typeof value === 'bigint' || typeof value === 'number' || typeof value === 'string') {
|
|
725
|
+
return this._isZeroValue(value)
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
return false
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Check if a primitive value equals zero
|
|
733
|
+
*/
|
|
734
|
+
private _isZeroValue(value: bigint | number | string): boolean {
|
|
735
|
+
switch (typeof value) {
|
|
736
|
+
case 'bigint':
|
|
737
|
+
return value === 0n
|
|
738
|
+
case 'number':
|
|
739
|
+
return value === 0
|
|
740
|
+
case 'string':
|
|
741
|
+
return value === '0' || Number(value) === 0
|
|
742
|
+
default:
|
|
743
|
+
return false
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Create option::none for Coin<IOTA>
|
|
749
|
+
*/
|
|
750
|
+
private _createOptionNone(tx: Transaction): TransactionResult {
|
|
751
|
+
return tx.moveCall({
|
|
752
|
+
target: '0x1::option::none',
|
|
753
|
+
typeArguments: ['0x2::coin::Coin<0x2::iota::IOTA>'],
|
|
754
|
+
arguments: [],
|
|
755
|
+
})
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Create option::some for Coin<IOTA>
|
|
760
|
+
*/
|
|
761
|
+
private _createOptionSome(
|
|
762
|
+
tx: Transaction,
|
|
763
|
+
value: bigint | number | string | TransactionArgument
|
|
764
|
+
): TransactionResult {
|
|
765
|
+
const coin = tx.splitCoins(tx.gas, [asU64(tx, value)])
|
|
766
|
+
return tx.moveCall({
|
|
767
|
+
target: '0x1::option::some',
|
|
768
|
+
typeArguments: ['0x2::coin::Coin<0x2::iota::IOTA>'],
|
|
769
|
+
arguments: [coin],
|
|
770
|
+
})
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Splits specified amount of coins from user's wallet
|
|
775
|
+
* @param tx - The transaction to add the move call to
|
|
776
|
+
* @param coinType - The type of coin to split
|
|
777
|
+
* @param owner - Address of the user whose coins to split
|
|
778
|
+
* @param amount - Amount of coins to split (in smallest units)
|
|
779
|
+
* @param limit - Maximum total number of coins to collect across all pages (default: 200)
|
|
780
|
+
* @param pageSize - Maximum number of coins to fetch per page (default: 50)
|
|
781
|
+
* @returns Promise resolving to split coin as TransactionResult
|
|
782
|
+
* @throws Error if insufficient coins balance or no coins found
|
|
783
|
+
*/
|
|
784
|
+
async splitCoinMoveCall(
|
|
785
|
+
tx: Transaction,
|
|
786
|
+
coinType: string,
|
|
787
|
+
owner: string,
|
|
788
|
+
amount: bigint,
|
|
789
|
+
limit = 200,
|
|
790
|
+
pageSize = 50
|
|
791
|
+
): Promise<TransactionResult> {
|
|
792
|
+
const sufficientCoins = await this.#fetchSufficientCoins(owner, coinType, amount, limit, pageSize)
|
|
793
|
+
const totalBalance = sufficientCoins.reduce((sum, coin) => sum + BigInt(coin.balance), 0n)
|
|
794
|
+
|
|
795
|
+
// Use single coin if available, otherwise merge multiple coins
|
|
796
|
+
const primaryCoin = sufficientCoins.find((coin) => BigInt(coin.balance) >= amount) ?? sufficientCoins[0]
|
|
797
|
+
const primaryCoinObj = tx.object(primaryCoin.coinObjectId)
|
|
798
|
+
|
|
799
|
+
// Merge additional coins if needed
|
|
800
|
+
if (primaryCoin === sufficientCoins[0] && sufficientCoins.length > 1) {
|
|
801
|
+
tx.mergeCoins(
|
|
802
|
+
primaryCoinObj,
|
|
803
|
+
sufficientCoins.slice(1).map((coin) => tx.object(coin.coinObjectId))
|
|
804
|
+
)
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// Split the required amount
|
|
808
|
+
const splitCoin = tx.splitCoins(primaryCoinObj, [asU64(tx, amount)])
|
|
809
|
+
|
|
810
|
+
// Destroy zero-value remainder if total balance equals requested amount
|
|
811
|
+
if (totalBalance === amount) {
|
|
812
|
+
this.#destroyZeroCoin(tx, primaryCoinObj, coinType)
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
return splitCoin
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// === Internal Functions ===
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Generate the full target path for move calls
|
|
822
|
+
* @param name - The function name to call
|
|
823
|
+
* @param module_name - The module name (defaults to BYTES32_MODULE_NAME)
|
|
824
|
+
* @returns The full module path for the move call
|
|
825
|
+
* @private
|
|
826
|
+
*/
|
|
827
|
+
#target(name: string, module_name = BYTES32_MODULE_NAME): string {
|
|
828
|
+
return `${this.packageId}::${module_name}::${name}`
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Destroy a zero-value coin to clean up wallet state
|
|
833
|
+
* @param tx - The transaction to add the move call to
|
|
834
|
+
* @param coinObj - The coin object to destroy
|
|
835
|
+
* @param coinType - The coin type
|
|
836
|
+
* @private
|
|
837
|
+
*/
|
|
838
|
+
#destroyZeroCoin(tx: Transaction, coinObj: TransactionArgument, coinType: string): void {
|
|
839
|
+
tx.moveCall({
|
|
840
|
+
target: '0x2::coin::destroy_zero',
|
|
841
|
+
arguments: [coinObj],
|
|
842
|
+
typeArguments: [coinType],
|
|
843
|
+
})
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Fetches coins incrementally until sufficient balance is reached
|
|
848
|
+
* This method paginates through the user's ZRO coins to collect enough balance
|
|
849
|
+
* @param owner - Address of the user whose ZRO coins to fetch
|
|
850
|
+
* @param coinType - ZRO coin type string
|
|
851
|
+
* @param amount - Required amount to reach
|
|
852
|
+
* @param limit - Maximum total number of coins to collect across all pages
|
|
853
|
+
* @param pageSize - Maximum coins to fetch per page
|
|
854
|
+
* @returns Promise resolving to array of coin objects with sufficient total balance
|
|
855
|
+
*/
|
|
856
|
+
async #fetchSufficientCoins(
|
|
857
|
+
owner: string,
|
|
858
|
+
coinType: string,
|
|
859
|
+
amount: bigint,
|
|
860
|
+
limit: number,
|
|
861
|
+
pageSize: number
|
|
862
|
+
): Promise<CoinStruct[]> {
|
|
863
|
+
const coins: CoinStruct[] = []
|
|
864
|
+
let accumulatedBalance = 0n
|
|
865
|
+
let cursor: string | null = null
|
|
866
|
+
|
|
867
|
+
do {
|
|
868
|
+
const coinsResponse = await this.client.getCoins({ owner, coinType, cursor, limit: pageSize })
|
|
869
|
+
if (coinsResponse.data.length === 0) {
|
|
870
|
+
break
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
for (const coin of coinsResponse.data) {
|
|
874
|
+
coins.push(coin)
|
|
875
|
+
accumulatedBalance += BigInt(coin.balance)
|
|
876
|
+
|
|
877
|
+
// Stop if we have enough balance
|
|
878
|
+
if (accumulatedBalance >= amount) {
|
|
879
|
+
return coins
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// Throw error if we have reached the maximum coin limit
|
|
883
|
+
if (coins.length >= limit) {
|
|
884
|
+
throw new Error(
|
|
885
|
+
`Insufficient ${coinType} balance: reached maximum coin limit (${limit}) but still need ${amount - accumulatedBalance} more`
|
|
886
|
+
)
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
cursor = coinsResponse.hasNextPage ? coinsResponse.nextCursor ?? null : null
|
|
891
|
+
} while (cursor != null)
|
|
892
|
+
|
|
893
|
+
// If we've exhausted all coins but still don't have sufficient balance
|
|
894
|
+
if (accumulatedBalance < amount) {
|
|
895
|
+
throw new Error(
|
|
896
|
+
`Insufficient ${coinType} balance: only found ${accumulatedBalance} but need ${amount} (shortfall: ${amount - accumulatedBalance})`
|
|
897
|
+
)
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
return coins
|
|
901
|
+
}
|
|
902
|
+
}
|