@haneullabs/haneul 2.5.2 → 2.13.0
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 +129 -0
- package/README.md +36 -36
- package/dist/bcs/bcs.d.mts +6 -7
- package/dist/bcs/bcs.d.mts.map +1 -1
- package/dist/bcs/bcs.mjs.map +1 -1
- package/dist/bcs/effects.mjs.map +1 -1
- package/dist/bcs/index.d.mts +2 -2
- package/dist/bcs/index.d.mts.map +1 -1
- package/dist/bcs/index.mjs +2 -2
- package/dist/bcs/index.mjs.map +1 -1
- package/dist/bcs/pure.d.mts.map +1 -1
- package/dist/bcs/type-tag-serializer.d.mts.map +1 -1
- package/dist/bcs/types.d.mts +0 -1
- package/dist/bcs/types.d.mts.map +1 -1
- package/dist/client/cache.d.mts.map +1 -1
- package/dist/client/client.d.mts.map +1 -1
- package/dist/client/core-resolver.d.mts.map +1 -1
- package/dist/client/core-resolver.mjs +87 -68
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts +9 -8
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +29 -10
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/errors.d.mts.map +1 -1
- package/dist/client/mvr.d.mts +0 -1
- package/dist/client/mvr.d.mts.map +1 -1
- package/dist/client/types.d.mts +110 -24
- package/dist/client/types.d.mts.map +1 -1
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/client/utils.mjs +7 -7
- package/dist/client/utils.mjs.map +1 -1
- package/dist/cryptography/index.d.mts +2 -2
- package/dist/cryptography/index.mjs +2 -2
- package/dist/cryptography/intent.d.mts +2 -2
- package/dist/cryptography/intent.d.mts.map +1 -1
- package/dist/cryptography/intent.mjs +2 -2
- package/dist/cryptography/intent.mjs.map +1 -1
- package/dist/cryptography/keypair.d.mts +3 -3
- package/dist/cryptography/keypair.d.mts.map +1 -1
- package/dist/cryptography/keypair.mjs +3 -3
- package/dist/cryptography/keypair.mjs.map +1 -1
- package/dist/cryptography/mnemonics.d.mts +5 -5
- package/dist/cryptography/mnemonics.d.mts.map +1 -1
- package/dist/cryptography/mnemonics.mjs +7 -7
- package/dist/cryptography/mnemonics.mjs.map +1 -1
- package/dist/cryptography/publickey.d.mts +1 -2
- package/dist/cryptography/publickey.d.mts.map +1 -1
- package/dist/cryptography/publickey.mjs +7 -7
- package/dist/cryptography/publickey.mjs.map +1 -1
- package/dist/cryptography/signature-scheme.d.mts.map +1 -1
- package/dist/cryptography/signature.d.mts +10 -13
- package/dist/cryptography/signature.d.mts.map +1 -1
- package/dist/cryptography/signature.mjs +2 -2
- package/dist/cryptography/signature.mjs.map +1 -1
- package/dist/faucet/faucet.d.mts +2 -2
- package/dist/faucet/faucet.d.mts.map +1 -1
- package/dist/faucet/faucet.mjs +2 -2
- package/dist/faucet/faucet.mjs.map +1 -1
- package/dist/faucet/index.d.mts +2 -2
- package/dist/faucet/index.mjs +2 -2
- package/dist/graphql/client.d.mts +20 -5
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +55 -7
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +6 -5
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +43 -47
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/generated/queries.d.mts +0 -1
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +46 -10
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +706 -98
- package/dist/graphql/generated/tada-env.d.mts.map +1 -1
- package/dist/graphql/index.d.mts +2 -2
- package/dist/graphql/index.mjs +2 -2
- package/dist/graphql/schema/index.d.mts +0 -1
- package/dist/graphql/schema/index.d.mts.map +1 -1
- package/dist/graphql/types.d.mts.map +1 -1
- package/dist/grpc/client.d.mts +20 -5
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +47 -7
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +6 -5
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +35 -34
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/index.d.mts +2 -2
- package/dist/grpc/index.mjs +2 -2
- package/dist/grpc/proto/google/protobuf/any.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/any.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/duration.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/duration.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/field_mask.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/field_mask.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/struct.d.mts +1 -2
- package/dist/grpc/proto/google/protobuf/struct.d.mts.map +1 -1
- package/dist/grpc/proto/google/protobuf/timestamp.d.mts +0 -1
- package/dist/grpc/proto/google/protobuf/timestamp.d.mts.map +1 -1
- package/dist/grpc/proto/google/rpc/status.d.mts +0 -1
- package/dist/grpc/proto/google/rpc/status.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/argument.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/argument.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/balance_change.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/balance_change.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/bcs.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/bcs.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/bcs.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_contents.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_contents.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_summary.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/checkpoint_summary.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/effects.d.mts +5 -6
- package/dist/grpc/proto/haneul/rpc/v2/effects.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/epoch.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/epoch.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/error_reason.d.mts +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/error_reason.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/event.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/event.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/executed_transaction.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/executed_transaction.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.d.mts +8 -9
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.mjs +4 -4
- package/dist/grpc/proto/haneul/rpc/v2/execution_status.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/gas_cost_summary.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/gas_cost_summary.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/input.d.mts +3 -4
- package/dist/grpc/proto/haneul/rpc/v2/input.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/jwk.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/jwk.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/ledger_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package.d.mts +5 -6
- package/dist/grpc/proto/haneul/rpc/v2/move_package.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/move_package_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/name_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/name_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/name_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/name_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/object.d.mts +38 -2
- package/dist/grpc/proto/haneul/rpc/v2/object.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/object.mjs +26 -1
- package/dist/grpc/proto/haneul/rpc/v2/object.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/object_reference.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/object_reference.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/owner.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/owner.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/protocol_config.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/protocol_config.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature.d.mts +1 -2
- package/dist/grpc/proto/haneul/rpc/v2/signature.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.d.mts +2 -2
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.mjs +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_scheme.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.client.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/signature_verification_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/state_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/state_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/state_service.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/state_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.client.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/subscription_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/system_state.d.mts +3 -4
- package/dist/grpc/proto/haneul/rpc/v2/system_state.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/system_state.mjs.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction.d.mts +4 -5
- package/dist/grpc/proto/haneul/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.client.d.mts +0 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.d.mts +9 -2
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.mjs +23 -12
- package/dist/grpc/proto/haneul/rpc/v2/transaction_execution_service.mjs.map +1 -1
- package/dist/grpc/proto/types.d.mts +2 -2
- package/dist/grpc/proto/types.d.mts.map +1 -1
- package/dist/grpc/proto/types.mjs +2 -1
- package/dist/jsonRpc/client.d.mts +4 -7
- package/dist/jsonRpc/client.d.mts.map +1 -1
- package/dist/jsonRpc/client.mjs +4 -33
- package/dist/jsonRpc/client.mjs.map +1 -1
- package/dist/jsonRpc/core.d.mts +8 -15
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/core.mjs +81 -34
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/jsonRpc/errors.d.mts.map +1 -1
- package/dist/jsonRpc/http-transport.d.mts +1 -17
- package/dist/jsonRpc/http-transport.d.mts.map +1 -1
- package/dist/jsonRpc/http-transport.mjs +0 -23
- package/dist/jsonRpc/http-transport.mjs.map +1 -1
- package/dist/jsonRpc/index.d.mts +3 -3
- package/dist/jsonRpc/network.d.mts.map +1 -1
- package/dist/jsonRpc/types/chain.d.mts.map +1 -1
- package/dist/jsonRpc/types/changes.d.mts.map +1 -1
- package/dist/jsonRpc/types/coins.d.mts.map +1 -1
- package/dist/jsonRpc/types/common.d.mts +1 -2
- package/dist/jsonRpc/types/common.d.mts.map +1 -1
- package/dist/jsonRpc/types/generated.d.mts +101 -129
- package/dist/jsonRpc/types/generated.d.mts.map +1 -1
- package/dist/jsonRpc/types/index.d.mts +1 -1
- package/dist/jsonRpc/types/params.d.mts +9 -14
- package/dist/jsonRpc/types/params.d.mts.map +1 -1
- package/dist/keypairs/ed25519/keypair.d.mts +8 -6
- package/dist/keypairs/ed25519/keypair.d.mts.map +1 -1
- package/dist/keypairs/ed25519/keypair.mjs +13 -9
- package/dist/keypairs/ed25519/keypair.mjs.map +1 -1
- package/dist/keypairs/ed25519/publickey.d.mts +0 -1
- package/dist/keypairs/ed25519/publickey.d.mts.map +1 -1
- package/dist/keypairs/passkey/keypair.d.mts +12 -5
- package/dist/keypairs/passkey/keypair.d.mts.map +1 -1
- package/dist/keypairs/passkey/keypair.mjs +20 -7
- package/dist/keypairs/passkey/keypair.mjs.map +1 -1
- package/dist/keypairs/passkey/publickey.d.mts +0 -1
- package/dist/keypairs/passkey/publickey.d.mts.map +1 -1
- package/dist/keypairs/passkey/types.d.mts.map +1 -1
- package/dist/keypairs/secp256k1/keypair.d.mts +3 -3
- package/dist/keypairs/secp256k1/keypair.d.mts.map +1 -1
- package/dist/keypairs/secp256k1/keypair.mjs +6 -6
- package/dist/keypairs/secp256k1/keypair.mjs.map +1 -1
- package/dist/keypairs/secp256k1/publickey.d.mts +0 -1
- package/dist/keypairs/secp256k1/publickey.d.mts.map +1 -1
- package/dist/keypairs/secp256r1/keypair.d.mts +3 -3
- package/dist/keypairs/secp256r1/keypair.d.mts.map +1 -1
- package/dist/keypairs/secp256r1/keypair.mjs +6 -6
- package/dist/keypairs/secp256r1/keypair.mjs.map +1 -1
- package/dist/keypairs/secp256r1/publickey.d.mts +0 -1
- package/dist/keypairs/secp256r1/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.d.mts +1 -0
- package/dist/multisig/publickey.d.mts.map +1 -1
- package/dist/multisig/publickey.mjs +7 -7
- package/dist/multisig/publickey.mjs.map +1 -1
- package/dist/multisig/signer.d.mts.map +1 -1
- package/dist/transactions/Arguments.d.mts.map +1 -1
- package/dist/transactions/Commands.d.mts +1 -1
- package/dist/transactions/Commands.d.mts.map +1 -1
- package/dist/transactions/Commands.mjs.map +1 -1
- package/dist/transactions/Inputs.d.mts.map +1 -1
- package/dist/transactions/ObjectCache.d.mts +3 -3
- package/dist/transactions/ObjectCache.d.mts.map +1 -1
- package/dist/transactions/Transaction.d.mts +26 -0
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +23 -1
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/TransactionData.d.mts.map +1 -1
- package/dist/transactions/TransactionData.mjs +8 -8
- package/dist/transactions/TransactionData.mjs.map +1 -1
- package/dist/transactions/data/internal.d.mts +109 -109
- package/dist/transactions/data/internal.d.mts.map +1 -1
- package/dist/transactions/data/internal.mjs.map +1 -1
- package/dist/transactions/data/v1.d.mts +220 -221
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts.map +1 -1
- package/dist/transactions/data/v2.mjs.map +1 -1
- package/dist/transactions/executor/caching.mjs +2 -2
- package/dist/transactions/executor/caching.mjs.map +1 -1
- package/dist/transactions/executor/parallel.d.mts +1 -1
- package/dist/transactions/executor/parallel.d.mts.map +1 -1
- package/dist/transactions/executor/parallel.mjs +1 -1
- package/dist/transactions/executor/parallel.mjs.map +1 -1
- package/dist/transactions/executor/serial.d.mts +3 -3
- package/dist/transactions/executor/serial.d.mts.map +1 -1
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/transactions/intents/CoinWithBalance.d.mts.map +1 -1
- package/dist/transactions/intents/CoinWithBalance.mjs +174 -97
- package/dist/transactions/intents/CoinWithBalance.mjs.map +1 -1
- package/dist/transactions/object.d.mts.map +1 -1
- package/dist/transactions/pure.d.mts.map +1 -1
- package/dist/transactions/pure.mjs +12 -12
- package/dist/transactions/pure.mjs.map +1 -1
- package/dist/transactions/resolve.d.mts.map +1 -1
- package/dist/transactions/resolve.mjs +3 -3
- package/dist/transactions/resolve.mjs.map +1 -1
- package/dist/transactions/serializer.d.mts.map +1 -1
- package/dist/transactions/serializer.mjs +15 -15
- package/dist/transactions/serializer.mjs.map +1 -1
- package/dist/transactions/utils.d.mts +0 -1
- package/dist/transactions/utils.d.mts.map +1 -1
- package/dist/utils/coin-reservation.mjs +67 -0
- package/dist/utils/coin-reservation.mjs.map +1 -0
- package/dist/utils/constants.d.mts +2 -1
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +2 -1
- package/dist/utils/constants.mjs.map +1 -1
- package/dist/utils/derived-objects.d.mts +0 -1
- package/dist/utils/derived-objects.d.mts.map +1 -1
- package/dist/utils/dynamic-fields.d.mts.map +1 -1
- package/dist/utils/dynamic-fields.mjs +4 -4
- package/dist/utils/dynamic-fields.mjs.map +1 -1
- package/dist/utils/format.d.mts.map +1 -1
- package/dist/utils/haneul-types.d.mts.map +1 -1
- package/dist/utils/haneul-types.mjs +8 -0
- package/dist/utils/haneul-types.mjs.map +1 -1
- package/dist/utils/haneulns.d.mts.map +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +2 -2
- package/dist/utils/move-registry.d.mts.map +1 -1
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/address.d.mts.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/dist/zklogin/bcs.d.mts.map +1 -1
- package/dist/zklogin/jwt-decode.d.mts +0 -1
- package/dist/zklogin/jwt-decode.d.mts.map +1 -1
- package/dist/zklogin/jwt-utils.d.mts +0 -1
- package/dist/zklogin/jwt-utils.d.mts.map +1 -1
- package/dist/zklogin/nonce.d.mts.map +1 -1
- package/dist/zklogin/poseidon.d.mts.map +1 -1
- package/dist/zklogin/publickey.d.mts +0 -1
- package/dist/zklogin/publickey.d.mts.map +1 -1
- package/dist/zklogin/signature.d.mts.map +1 -1
- package/dist/zklogin/utils.d.mts.map +1 -1
- package/dist/zklogin/utils.mjs +1 -1
- package/dist/zklogin/utils.mjs.map +1 -1
- package/docs/bcs.md +132 -0
- package/docs/clients/core.md +616 -0
- package/docs/clients/graphql.md +99 -0
- package/docs/clients/grpc.md +152 -0
- package/docs/clients/index.md +93 -0
- package/docs/clients/json-rpc.md +235 -0
- package/docs/cryptography/keypairs.md +259 -0
- package/docs/cryptography/multisig.md +192 -0
- package/docs/cryptography/passkey.md +111 -0
- package/docs/cryptography/webcrypto-signer.md +81 -0
- package/docs/executors.md +148 -0
- package/docs/faucet.md +26 -0
- package/docs/hello-haneul.md +115 -0
- package/docs/index.md +56 -0
- package/docs/install.md +61 -0
- package/docs/llm-docs.md +32 -0
- package/docs/llms-index.md +66 -0
- package/docs/migrations/0.38.md +57 -0
- package/docs/migrations/haneul-1.0.md +454 -0
- package/docs/migrations/haneul-2.0/agent-prompt.md +42 -0
- package/docs/migrations/haneul-2.0/dapp-kit.md +350 -0
- package/docs/migrations/haneul-2.0/deepbook-v3.md +33 -0
- package/docs/migrations/haneul-2.0/haneul.md +341 -0
- package/docs/migrations/haneul-2.0/haneulns.md +42 -0
- package/docs/migrations/haneul-2.0/index.md +161 -0
- package/docs/migrations/haneul-2.0/json-rpc-migration.md +399 -0
- package/docs/migrations/haneul-2.0/kiosk.md +120 -0
- package/docs/migrations/haneul-2.0/sdk-maintainers.md +91 -0
- package/docs/migrations/haneul-2.0/seal.md +14 -0
- package/docs/migrations/haneul-2.0/wallet-builders.md +66 -0
- package/docs/migrations/haneul-2.0/walrus.md +41 -0
- package/docs/migrations/haneul-2.0/zksend.md +94 -0
- package/docs/plugins.md +255 -0
- package/docs/sdk-building.md +341 -0
- package/docs/transaction-building/basics.md +297 -0
- package/docs/transaction-building/gas.md +62 -0
- package/docs/transaction-building/intents.md +61 -0
- package/docs/transaction-building/offline.md +71 -0
- package/docs/transaction-building/sponsored-transactions.md +22 -0
- package/docs/utils/derived_objects.md +80 -0
- package/docs/utils/index.md +53 -0
- package/docs/zklogin.md +78 -0
- package/package.json +199 -199
- package/src/bcs/bcs.ts +13 -13
- package/src/bcs/effects.ts +20 -20
- package/src/bcs/index.ts +2 -2
- package/src/client/core-resolver.ts +150 -100
- package/src/client/core.ts +62 -22
- package/src/client/types.ts +109 -24
- package/src/cryptography/index.ts +2 -2
- package/src/cryptography/keypair.ts +2 -2
- package/src/cryptography/mnemonics.ts +7 -7
- package/src/cryptography/publickey.ts +5 -5
- package/src/faucet/faucet.ts +1 -1
- package/src/faucet/index.ts +1 -1
- package/src/graphql/client.ts +100 -8
- package/src/graphql/core.ts +73 -80
- package/src/graphql/generated/queries.ts +301 -51
- package/src/graphql/generated/schema.graphql +407 -104
- package/src/graphql/generated/tada-env.ts +779 -58
- package/src/graphql/index.ts +1 -1
- package/src/graphql/queries/getAllBalances.graphql +1 -1
- package/src/graphql/queries/getBalance.graphql +1 -1
- package/src/graphql/queries/getCoins.graphql +2 -2
- package/src/graphql/queries/getDynamicFields.graphql +9 -1
- package/src/graphql/queries/getMoveFunction.graphql +1 -1
- package/src/graphql/queries/getProtocolConfig.graphql +18 -0
- package/src/graphql/queries/nameService.graphql +1 -1
- package/src/graphql/queries/objects.graphql +11 -1
- package/src/graphql/queries/transactions.graphql +1 -3
- package/src/graphql/queries/verifyZkLoginSignature.graphql +1 -2
- package/src/grpc/client.ts +66 -8
- package/src/grpc/core.ts +74 -35
- package/src/grpc/index.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/bcs.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/execution_status.ts +4 -4
- package/src/grpc/proto/haneul/rpc/v2/object.ts +44 -0
- package/src/grpc/proto/haneul/rpc/v2/signature.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/signature_scheme.ts +1 -1
- package/src/grpc/proto/haneul/rpc/v2/system_state.ts +4 -4
- package/src/grpc/proto/haneul/rpc/v2/transaction_execution_service.ts +16 -0
- package/src/jsonRpc/client.ts +5 -23
- package/src/jsonRpc/core.ts +114 -41
- package/src/jsonRpc/http-transport.ts +0 -52
- package/src/jsonRpc/index.ts +0 -1
- package/src/jsonRpc/types/common.ts +0 -1
- package/src/jsonRpc/types/generated.ts +2 -2
- package/src/jsonRpc/types/params.ts +6 -6
- package/src/keypairs/ed25519/keypair.ts +14 -10
- package/src/keypairs/passkey/keypair.ts +22 -8
- package/src/keypairs/secp256k1/keypair.ts +6 -6
- package/src/keypairs/secp256r1/keypair.ts +6 -6
- package/src/transactions/Commands.ts +1 -1
- package/src/transactions/Transaction.ts +38 -1
- package/src/transactions/TransactionData.ts +3 -3
- package/src/transactions/__tests__/bcs.test.ts +3 -3
- package/src/transactions/data/internal.ts +12 -12
- package/src/transactions/data/v2.ts +6 -6
- package/src/transactions/executor/caching.ts +2 -2
- package/src/transactions/executor/parallel.ts +1 -2
- package/src/transactions/executor/serial.ts +1 -1
- package/src/transactions/intents/CoinWithBalance.ts +247 -121
- package/src/utils/coin-reservation.ts +84 -0
- package/src/utils/constants.ts +2 -0
- package/src/utils/haneul-types.ts +16 -1
- package/src/utils/index.ts +1 -0
- package/src/version.ts +1 -1
- package/src/zklogin/utils.ts +1 -1
- package/dist/jsonRpc/rpc-websocket-client.d.mts +0 -26
- package/dist/jsonRpc/rpc-websocket-client.d.mts.map +0 -1
- package/dist/jsonRpc/rpc-websocket-client.mjs +0 -135
- package/dist/jsonRpc/rpc-websocket-client.mjs.map +0 -1
- package/src/jsonRpc/rpc-websocket-client.ts +0 -241
|
@@ -37,7 +37,7 @@ declare class ParallelTransactionExecutor {
|
|
|
37
37
|
constructor(options: ParallelTransactionExecutorOptions);
|
|
38
38
|
resetCache(): Promise<void>;
|
|
39
39
|
waitForLastTransaction(): Promise<void>;
|
|
40
|
-
executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(transaction: Transaction, include?: Include, additionalSignatures?: string[]): Promise<HaneulClientTypes.TransactionResult<Include & {
|
|
40
|
+
executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(transaction: Transaction, include?: Include & HaneulClientTypes.TransactionInclude, additionalSignatures?: string[]): Promise<HaneulClientTypes.TransactionResult<Include & {
|
|
41
41
|
effects: true;
|
|
42
42
|
}>>;
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.d.mts","names":[],"sources":["../../../src/transactions/executor/parallel.ts"],"
|
|
1
|
+
{"version":3,"file":"parallel.d.mts","names":[],"sources":["../../../src/transactions/executor/parallel.ts"],"mappings":";;;;;;;;UAwBU,sCAAA,SAA+C,IAAA,CAAK,kBAAA;EAC7D,MAAA,EAAQ,iBAAA;EACR,MAAA,EAAQ,MAAA;EAFC;EAIT,gBAAA;;EAEA,WAAA;AAAA;AAAA,UAGgB,sCAAA,SAA+C,sCAAA;EATP;EAWxD,OAAA;EAX4D;EAa5D,aAAA;EAb6D;EAe7D,kBAAA;EAdQ;EAgBR,kBAAA;EAfQ;EAiBR,WAAA;AAAA;AAAA,UAGgB,gDAAA,SAAyD,sCAAA;EAhB9D;EAkBX,OAAA;AAAA;;KAIW,kCAAA,GACT,sCAAA,GACA,gDAAA;AAAA,cAQU,2BAAA;EAAA;cA0BA,OAAA,EAAS,kCAAA;EA+BrB,UAAA,CAAA,GAAU,OAAA;EAKJ,sBAAA,CAAA,GAAsB,OAAA;EAItB,kBAAA,iBAAmC,iBAAA,CAAkB,kBAAA,MAAA,CAC1D,WAAA,EAAa,WAAA,EACb,OAAA,GAAU,OAAA,GAAU,iBAAA,CAAkB,kBAAA,EACtC,oBAAA,cACE,OAAA,CAAQ,iBAAA,CAAkB,iBAAA,CAAkB,OAAA;IAAY,OAAA;EAAA;AAAA"}
|
|
@@ -140,7 +140,7 @@ var ParallelTransactionExecutor = class {
|
|
|
140
140
|
if (gasCoin && gasUsed && gasObject) {
|
|
141
141
|
const coin = gasCoin;
|
|
142
142
|
if ((gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner) === this.#signer.toHaneulAddress()) {
|
|
143
|
-
const totalUsed = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost)
|
|
143
|
+
const totalUsed = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
|
|
144
144
|
const remainingBalance = coin.balance - totalUsed;
|
|
145
145
|
let usesGasCoin = false;
|
|
146
146
|
new TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.mjs","names":["#signer","#client","#gasMode","#coinBatchSize","#initialCoinBalance","#minimumCoinBalance","#sourceCoins","#defaultGasBudget","#maxPoolSize","#cache","#executeQueue","#epochInfo","#updateCache","#waitForLastDigest","#getUsedObjects","#execute","#objectIdQueues","#buildQueue","#getGasPrice","#pendingTransactions","#getValidDuringExpiration","#getGasCoin","#coinPool","#lastDigest","#cacheLock","#refillCoinPool","#ensureEpochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { promiseWithResolvers } from '@haneullabs/utils';\nimport type { HaneulObjectRef } from '../../bcs/types.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { TransactionDataBuilder } from '../TransactionData.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n} satisfies Partial<ParallelTransactionExecutorCoinOptions>;\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface ParallelTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\t/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */\n\tdefaultGasBudget?: bigint;\n\t/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */\n\tmaxPoolSize?: number;\n}\n\nexport interface ParallelTransactionExecutorCoinOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use owned coins for gas payments (default) */\n\tgasMode?: 'coins';\n\t/** The number of coins to create in a batch when refilling the gas pool */\n\tcoinBatchSize?: number;\n\t/** The initial balance of each coin created for the gas pool */\n\tinitialCoinBalance?: bigint;\n\t/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */\n\tminimumCoinBalance?: bigint;\n\t/** An initial list of coins used to fund the gas pool, uses all owned HANEUL coins by default */\n\tsourceCoins?: string[];\n}\n\nexport interface ParallelTransactionExecutorAddressBalanceOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use address balance for gas payments instead of owned coins */\n\tgasMode: 'addressBalance';\n}\n\n/** Options for ParallelTransactionExecutor - discriminated union based on gasMode */\nexport type ParallelTransactionExecutorOptions =\n\t| ParallelTransactionExecutorCoinOptions\n\t| ParallelTransactionExecutorAddressBalanceOptions;\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#defaultGasBudget: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, HaneulObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\t#lastDigest: string | null = null;\n\t#cacheLock: Promise<void> | null = null;\n\t#pendingTransactions = 0;\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\tprice: bigint;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\n\t\tif (this.#gasMode === 'coins') {\n\t\t\tconst coinOptions = options as ParallelTransactionExecutorCoinOptions;\n\t\t\tthis.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\t\tthis.#initialCoinBalance =\n\t\t\t\tcoinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\t\tthis.#minimumCoinBalance =\n\t\t\t\tcoinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = coinOptions.sourceCoins\n\t\t\t\t? new Map(coinOptions.sourceCoins.map((id) => [id, null]))\n\t\t\t\t: null;\n\t\t} else {\n\t\t\tthis.#coinBatchSize = 0;\n\t\t\tthis.#initialCoinBalance = 0n;\n\t\t\tthis.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = null;\n\t\t}\n\n\t\tthis.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t}\n\n\tresetCache() {\n\t\tthis.#epochInfo = null;\n\t\treturn this.#updateCache(() => this.#cache.reset());\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tawait this.#updateCache(() => this.#waitForLastDigest());\n\t}\n\n\tasync executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tconst { promise, resolve, reject } =\n\t\t\tpromiseWithResolvers<HaneulClientTypes.TransactionResult<Include & { effects: true }>>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects, include, additionalSignatures);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tusedObjects: Set<string>,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tlet gasCoin: CoinWithBalance | null = null;\n\t\ttry {\n\t\t\ttransaction.setSenderIfNotSet(this.#signer.toHaneulAddress());\n\n\t\t\tawait this.#buildQueue.runTask(async () => {\n\t\t\t\tconst data = transaction.getData();\n\n\t\t\t\tif (!data.gasData.price) {\n\t\t\t\t\ttransaction.setGasPrice(await this.#getGasPrice());\n\t\t\t\t}\n\n\t\t\t\ttransaction.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\n\t\t\t\tawait this.#updateCache();\n\t\t\t\tthis.#pendingTransactions++;\n\n\t\t\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\t\t\t// Address balance mode: use empty gas payment with ValidDuring expiration\n\t\t\t\t\ttransaction.setGasPayment([]);\n\t\t\t\t\ttransaction.setExpiration(await this.#getValidDuringExpiration());\n\t\t\t\t} else {\n\t\t\t\t\t// Coin mode: use gas coin from pool\n\t\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t\t},\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\t// Resolve cached references\n\t\t\t\tawait this.#cache.buildTransaction({ transaction, onlyTransactionKind: true });\n\t\t\t});\n\n\t\t\tconst bytes = await transaction.build({ client: this.#client });\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\tinclude,\n\t\t\t});\n\n\t\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\t\tconst effects = tx.effects!;\n\t\t\tconst gasObject = effects.gasObject;\n\t\t\tconst gasUsed = effects.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasObject) {\n\t\t\t\tconst coin = gasCoin as CoinWithBalance;\n\t\t\t\tconst gasOwner = gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner;\n\n\t\t\t\tif (gasOwner === this.#signer.toHaneulAddress()) {\n\t\t\t\t\tconst totalUsed =\n\t\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\t\t\t\t\tconst remainingBalance = coin.balance - totalUsed;\n\n\t\t\t\t\tlet usesGasCoin = false;\n\t\t\t\t\tnew TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {\n\t\t\t\t\t\tif (arg.$kind === 'GasCoin') {\n\t\t\t\t\t\t\tusesGasCoin = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn arg;\n\t\t\t\t\t});\n\n\t\t\t\t\tconst gasRef = {\n\t\t\t\t\t\tobjectId: gasObject.objectId,\n\t\t\t\t\t\tversion: gasObject.outputVersion!,\n\t\t\t\t\t\tdigest: gasObject.outputDigest!,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) {\n\t\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\t\tid: gasRef.objectId,\n\t\t\t\t\t\t\tversion: gasRef.version,\n\t\t\t\t\t\t\tdigest: gasRef.digest,\n\t\t\t\t\t\t\tbalance: remainingBalance,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#sourceCoins.set(gasRef.objectId, gasRef);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.#lastDigest = tx.digest;\n\n\t\t\treturn results as HaneulClientTypes.TransactionResult<Include & { effects: true }>;\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set((gasCoin as CoinWithBalance).id, null);\n\t\t\t}\n\n\t\t\tawait this.#updateCache(async () => {\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tthis.#cache.cache.deleteObjects([...usedObjects]),\n\t\t\t\t\tthis.#waitForLastDigest(),\n\t\t\t\t]);\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.#pendingTransactions--;\n\t\t}\n\t}\n\n\t/** Helper for synchronizing cache updates, by ensuring only one update happens at a time. This can also be used to wait for any pending cache updates */\n\tasync #updateCache(fn?: () => Promise<void>) {\n\t\tif (this.#cacheLock) {\n\t\t\tawait this.#cacheLock;\n\t\t}\n\n\t\tthis.#cacheLock =\n\t\t\tfn?.().then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#cacheLock = null;\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t) ?? null;\n\t}\n\n\tasync #waitForLastDigest() {\n\t\tconst digest = this.#lastDigest;\n\t\tif (digest) {\n\t\t\tthis.#lastDigest = null;\n\t\t\tawait this.#client.core.waitForTransaction({ digest });\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #getGasPrice(): Promise<bigint> {\n\t\tawait this.#ensureEpochInfo();\n\t\treturn this.#epochInfo!.price;\n\t}\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\tprice: BigInt(systemState.referenceGasPrice),\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toHaneulAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst { objects } = await this.#client.core.getObjects({\n\t\t\t\t\tobjectIds: ids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...objects\n\t\t\t\t\t\t.filter((obj): obj is HaneulClientTypes.Object => !(obj instanceof Error))\n\t\t\t\t\t\t.map((obj) => ({\n\t\t\t\t\t\t\tobjectId: obj.objectId,\n\t\t\t\t\t\t\tversion: obj.version,\n\t\t\t\t\t\t\tdigest: obj.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst splitResults = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(splitResults[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tawait this.waitForLastTransaction();\n\n\t\ttxb.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\tconst bytes = await txb.build({ client: this.#client });\n\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\tconst result = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude: { effects: true },\n\t\t});\n\n\t\tconst tx = result.$kind === 'Transaction' ? result.Transaction : result.FailedTransaction;\n\t\tconst effects = tx.effects!;\n\n\t\teffects.changedObjects.forEach((changedObj) => {\n\t\t\tif (\n\t\t\t\tchangedObj.objectId === effects.gasObject?.objectId ||\n\t\t\t\tchangedObj.outputState !== 'ObjectWrite'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid: changedObj.objectId,\n\t\t\t\tversion: changedObj.outputVersion!,\n\t\t\t\tdigest: changedObj.outputDigest!,\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = effects.gasObject!;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, {\n\t\t\tobjectId: gasObject.objectId,\n\t\t\tversion: gasObject.outputVersion!,\n\t\t\tdigest: gasObject.outputDigest!,\n\t\t});\n\n\t\tawait this.#client.core.waitForTransaction({ digest: tx.digest });\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BAA6B;CAClC,eAAe;CACf,oBAAoB;CACpB,oBAAoB;CACpB,aAAa;CACb;AAED,MAAM,wBAAwB;AAwC9B,IAAa,8BAAb,MAAyC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,YAA+B,EAAE;CACjC;CACA,kCAAkB,IAAI,KAA6B;CACnD,cAAc,IAAI,aAAa;CAC/B;CACA,cAA6B;CAC7B,aAAmC;CACnC,uBAAuB;CACvB,aAKI;CACJ,oBAA0C;CAE1C,YAAY,SAA6C;AACxD,QAAKA,SAAU,QAAQ;AACvB,QAAKC,SAAU,QAAQ;AACvB,QAAKC,UAAW,QAAQ,WAAW;AAEnC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AAS,UAAU;GACnB,QAAQ,UAAU;GAClB,CAAC;AAEF,QAAM,MAAKL,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,GAAG,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"parallel.mjs","names":["#signer","#client","#gasMode","#coinBatchSize","#initialCoinBalance","#minimumCoinBalance","#sourceCoins","#defaultGasBudget","#maxPoolSize","#cache","#executeQueue","#epochInfo","#updateCache","#waitForLastDigest","#getUsedObjects","#execute","#objectIdQueues","#buildQueue","#getGasPrice","#pendingTransactions","#getValidDuringExpiration","#getGasCoin","#coinPool","#lastDigest","#cacheLock","#refillCoinPool","#ensureEpochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { promiseWithResolvers } from '@haneullabs/utils';\nimport type { HaneulObjectRef } from '../../bcs/types.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { TransactionDataBuilder } from '../TransactionData.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n} satisfies Partial<ParallelTransactionExecutorCoinOptions>;\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface ParallelTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\t/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */\n\tdefaultGasBudget?: bigint;\n\t/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */\n\tmaxPoolSize?: number;\n}\n\nexport interface ParallelTransactionExecutorCoinOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use owned coins for gas payments (default) */\n\tgasMode?: 'coins';\n\t/** The number of coins to create in a batch when refilling the gas pool */\n\tcoinBatchSize?: number;\n\t/** The initial balance of each coin created for the gas pool */\n\tinitialCoinBalance?: bigint;\n\t/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */\n\tminimumCoinBalance?: bigint;\n\t/** An initial list of coins used to fund the gas pool, uses all owned HANEUL coins by default */\n\tsourceCoins?: string[];\n}\n\nexport interface ParallelTransactionExecutorAddressBalanceOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use address balance for gas payments instead of owned coins */\n\tgasMode: 'addressBalance';\n}\n\n/** Options for ParallelTransactionExecutor - discriminated union based on gasMode */\nexport type ParallelTransactionExecutorOptions =\n\t| ParallelTransactionExecutorCoinOptions\n\t| ParallelTransactionExecutorAddressBalanceOptions;\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#defaultGasBudget: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, HaneulObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\t#lastDigest: string | null = null;\n\t#cacheLock: Promise<void> | null = null;\n\t#pendingTransactions = 0;\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\tprice: bigint;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\n\t\tif (this.#gasMode === 'coins') {\n\t\t\tconst coinOptions = options as ParallelTransactionExecutorCoinOptions;\n\t\t\tthis.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\t\tthis.#initialCoinBalance =\n\t\t\t\tcoinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\t\tthis.#minimumCoinBalance =\n\t\t\t\tcoinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = coinOptions.sourceCoins\n\t\t\t\t? new Map(coinOptions.sourceCoins.map((id) => [id, null]))\n\t\t\t\t: null;\n\t\t} else {\n\t\t\tthis.#coinBatchSize = 0;\n\t\t\tthis.#initialCoinBalance = 0n;\n\t\t\tthis.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = null;\n\t\t}\n\n\t\tthis.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t}\n\n\tresetCache() {\n\t\tthis.#epochInfo = null;\n\t\treturn this.#updateCache(() => this.#cache.reset());\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tawait this.#updateCache(() => this.#waitForLastDigest());\n\t}\n\n\tasync executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tinclude?: Include & HaneulClientTypes.TransactionInclude,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tconst { promise, resolve, reject } =\n\t\t\tpromiseWithResolvers<HaneulClientTypes.TransactionResult<Include & { effects: true }>>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects, include, additionalSignatures);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tusedObjects: Set<string>,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tlet gasCoin: CoinWithBalance | null = null;\n\t\ttry {\n\t\t\ttransaction.setSenderIfNotSet(this.#signer.toHaneulAddress());\n\n\t\t\tawait this.#buildQueue.runTask(async () => {\n\t\t\t\tconst data = transaction.getData();\n\n\t\t\t\tif (!data.gasData.price) {\n\t\t\t\t\ttransaction.setGasPrice(await this.#getGasPrice());\n\t\t\t\t}\n\n\t\t\t\ttransaction.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\n\t\t\t\tawait this.#updateCache();\n\t\t\t\tthis.#pendingTransactions++;\n\n\t\t\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\t\t\t// Address balance mode: use empty gas payment with ValidDuring expiration\n\t\t\t\t\ttransaction.setGasPayment([]);\n\t\t\t\t\ttransaction.setExpiration(await this.#getValidDuringExpiration());\n\t\t\t\t} else {\n\t\t\t\t\t// Coin mode: use gas coin from pool\n\t\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t\t},\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\t// Resolve cached references\n\t\t\t\tawait this.#cache.buildTransaction({ transaction, onlyTransactionKind: true });\n\t\t\t});\n\n\t\t\tconst bytes = await transaction.build({ client: this.#client });\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\tinclude,\n\t\t\t});\n\n\t\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\t\tconst effects = tx.effects!;\n\t\t\tconst gasObject = effects.gasObject;\n\t\t\tconst gasUsed = effects.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasObject) {\n\t\t\t\tconst coin = gasCoin as CoinWithBalance;\n\t\t\t\tconst gasOwner = gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner;\n\n\t\t\t\tif (gasOwner === this.#signer.toHaneulAddress()) {\n\t\t\t\t\tconst totalUsed =\n\t\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\t\t\t\t\tconst remainingBalance = coin.balance - totalUsed;\n\n\t\t\t\t\tlet usesGasCoin = false;\n\t\t\t\t\tnew TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {\n\t\t\t\t\t\tif (arg.$kind === 'GasCoin') {\n\t\t\t\t\t\t\tusesGasCoin = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn arg;\n\t\t\t\t\t});\n\n\t\t\t\t\tconst gasRef = {\n\t\t\t\t\t\tobjectId: gasObject.objectId,\n\t\t\t\t\t\tversion: gasObject.outputVersion!,\n\t\t\t\t\t\tdigest: gasObject.outputDigest!,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) {\n\t\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\t\tid: gasRef.objectId,\n\t\t\t\t\t\t\tversion: gasRef.version,\n\t\t\t\t\t\t\tdigest: gasRef.digest,\n\t\t\t\t\t\t\tbalance: remainingBalance,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#sourceCoins.set(gasRef.objectId, gasRef);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.#lastDigest = tx.digest;\n\n\t\t\treturn results as HaneulClientTypes.TransactionResult<Include & { effects: true }>;\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set((gasCoin as CoinWithBalance).id, null);\n\t\t\t}\n\n\t\t\tawait this.#updateCache(async () => {\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tthis.#cache.cache.deleteObjects([...usedObjects]),\n\t\t\t\t\tthis.#waitForLastDigest(),\n\t\t\t\t]);\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.#pendingTransactions--;\n\t\t}\n\t}\n\n\t/** Helper for synchronizing cache updates, by ensuring only one update happens at a time. This can also be used to wait for any pending cache updates */\n\tasync #updateCache(fn?: () => Promise<void>) {\n\t\tif (this.#cacheLock) {\n\t\t\tawait this.#cacheLock;\n\t\t}\n\n\t\tthis.#cacheLock =\n\t\t\tfn?.().then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#cacheLock = null;\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t) ?? null;\n\t}\n\n\tasync #waitForLastDigest() {\n\t\tconst digest = this.#lastDigest;\n\t\tif (digest) {\n\t\t\tthis.#lastDigest = null;\n\t\t\tawait this.#client.core.waitForTransaction({ digest });\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #getGasPrice(): Promise<bigint> {\n\t\tawait this.#ensureEpochInfo();\n\t\treturn this.#epochInfo!.price;\n\t}\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\tprice: BigInt(systemState.referenceGasPrice),\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toHaneulAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst { objects } = await this.#client.core.getObjects({\n\t\t\t\t\tobjectIds: ids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...objects\n\t\t\t\t\t\t.filter((obj): obj is HaneulClientTypes.Object => !(obj instanceof Error))\n\t\t\t\t\t\t.map((obj) => ({\n\t\t\t\t\t\t\tobjectId: obj.objectId,\n\t\t\t\t\t\t\tversion: obj.version,\n\t\t\t\t\t\t\tdigest: obj.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst splitResults = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(splitResults[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tawait this.waitForLastTransaction();\n\n\t\ttxb.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\tconst bytes = await txb.build({ client: this.#client });\n\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\tconst result = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude: { effects: true },\n\t\t});\n\n\t\tconst tx = result.$kind === 'Transaction' ? result.Transaction : result.FailedTransaction;\n\t\tconst effects = tx.effects!;\n\n\t\teffects.changedObjects.forEach((changedObj) => {\n\t\t\tif (\n\t\t\t\tchangedObj.objectId === effects.gasObject?.objectId ||\n\t\t\t\tchangedObj.outputState !== 'ObjectWrite'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid: changedObj.objectId,\n\t\t\t\tversion: changedObj.outputVersion!,\n\t\t\t\tdigest: changedObj.outputDigest!,\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = effects.gasObject!;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, {\n\t\t\tobjectId: gasObject.objectId,\n\t\t\tversion: gasObject.outputVersion!,\n\t\t\tdigest: gasObject.outputDigest!,\n\t\t});\n\n\t\tawait this.#client.core.waitForTransaction({ digest: tx.digest });\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BAA6B;CAClC,eAAe;CACf,oBAAoB;CACpB,oBAAoB;CACpB,aAAa;CACb;AAED,MAAM,wBAAwB;AAwC9B,IAAa,8BAAb,MAAyC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;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AW;IACf,SAAS,WAAW;IACpB,QAAQ,WAAW;IACnB,SAAS,OAAO,MAAKlB,mBAAoB;IACzC,CAAC;IACD;AAEF,MAAI,CAAC,MAAKE,YACT,OAAKA,8BAAe,IAAI,KAAK;EAG9B,MAAM,YAAY,QAAQ;AAC1B,QAAKA,YAAc,IAAI,UAAU,UAAU;GAC1C,UAAU,UAAU;GACpB,SAAS,UAAU;GACnB,QAAQ,UAAU;GAClB,CAAC;AAEF,QAAM,MAAKL,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,GAAG,QAAQ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bcs as
|
|
1
|
+
import { bcs as haneulBcs } from "../../bcs/index.mjs";
|
|
2
2
|
import { HaneulClientTypes } from "../../client/types.mjs";
|
|
3
3
|
import { Transaction } from "../Transaction.mjs";
|
|
4
4
|
import { Signer } from "../../cryptography/keypair.mjs";
|
|
@@ -21,11 +21,11 @@ type SerialTransactionExecutorOptions = SerialTransactionExecutorCoinOptions | S
|
|
|
21
21
|
declare class SerialTransactionExecutor {
|
|
22
22
|
#private;
|
|
23
23
|
constructor(options: SerialTransactionExecutorOptions);
|
|
24
|
-
applyEffects(effects: typeof
|
|
24
|
+
applyEffects(effects: typeof haneulBcs.TransactionEffects.$inferType): Promise<void>;
|
|
25
25
|
buildTransaction(transaction: Transaction): Promise<Uint8Array<ArrayBuffer>>;
|
|
26
26
|
resetCache(): Promise<void>;
|
|
27
27
|
waitForLastTransaction(): Promise<void>;
|
|
28
|
-
executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(transaction: Transaction | Uint8Array, include?: Include, additionalSignatures?: string[]): Promise<HaneulClientTypes.TransactionResult<Include & {
|
|
28
|
+
executeTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(transaction: Transaction | Uint8Array, include?: Include & HaneulClientTypes.TransactionInclude, additionalSignatures?: string[]): Promise<HaneulClientTypes.TransactionResult<Include & {
|
|
29
29
|
effects: true;
|
|
30
30
|
}>>;
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serial.d.mts","names":[],"sources":["../../../src/transactions/executor/serial.ts"],"
|
|
1
|
+
{"version":3,"file":"serial.d.mts","names":[],"sources":["../../../src/transactions/executor/serial.ts"],"mappings":";;;;;;;;UAcU,oCAAA,SAA6C,IAAA,CAAK,kBAAA;EAC3D,MAAA,EAAQ,iBAAA;EACR,MAAA,EAAQ,MAAA;EACR,gBAAA;AAAA;AAAA,UAGgB,oCAAA,SAA6C,oCAAA;EAC7D,OAAA;AAAA;AAAA,UAGgB,8CAAA,SAAuD,oCAAA;EACvE,OAAA;AAAA;AAAA,KAGW,gCAAA,GACT,oCAAA,GACA,8CAAA;AAAA,cAEU,yBAAA;EAAA;cAcA,OAAA,EAAS,gCAAA;EAaf,YAAA,CAAa,OAAA,SAAgB,SAAA,CAAI,kBAAA,CAAmB,UAAA,GAAU,OAAA;EAiB9D,gBAAA,CAAiB,WAAA,EAAa,WAAA,GAAW,OAAA,CAAA,UAAA,CAAA,WAAA;EAgF/C,UAAA,CAAA,GAAU,OAAA;EAIV,sBAAA,CAAA,GAAsB,OAAA;EAItB,kBAAA,iBAAmC,iBAAA,CAAkB,kBAAA,MAAA,CACpD,WAAA,EAAa,WAAA,GAAc,UAAA,EAC3B,OAAA,GAAU,OAAA,GAAU,iBAAA,CAAkB,kBAAA,EACtC,oBAAA,cACE,OAAA,CAAQ,iBAAA,CAAkB,iBAAA,CAAkB,OAAA;IAAY,OAAA;EAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serial.mjs","names":["#signer","#client","#defaultGasBudget","#gasMode","#cache","#cacheGasCoin","#queue","#buildTransaction","#getValidDuringExpiration","#ensureEpochInfo","#epochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/serial.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { isTransaction, Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { SerialQueue } from './queue.js';\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface SerialTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\tdefaultGasBudget?: bigint;\n}\n\nexport interface SerialTransactionExecutorCoinOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode?: 'coins';\n}\n\nexport interface SerialTransactionExecutorAddressBalanceOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode: 'addressBalance';\n}\n\nexport type SerialTransactionExecutorOptions =\n\t| SerialTransactionExecutorCoinOptions\n\t| SerialTransactionExecutorAddressBalanceOptions;\n\nexport class SerialTransactionExecutor {\n\t#queue = new SerialQueue();\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#cache: CachingTransactionExecutor;\n\t#defaultGasBudget: bigint;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: SerialTransactionExecutorOptions) {\n\t\tconst { signer, defaultGasBudget = 50_000_000n, client, cache } = options;\n\t\tthis.#signer = signer;\n\t\tthis.#client = client;\n\t\tthis.#defaultGasBudget = defaultGasBudget;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient,\n\t\t\tcache,\n\t\t\tonEffects: (effects) => this.#cacheGasCoin(effects),\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\treturn this.#cache.applyEffects(effects);\n\t}\n\n\t#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {\n\t\tif (this.#gasMode === 'addressBalance' || !effects.V2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst gasCoin = getGasCoinFromEffects(effects).ref;\n\t\tif (gasCoin) {\n\t\t\tthis.#cache.cache.setCustom('gasCoin', gasCoin);\n\t\t} else {\n\t\t\tthis.#cache.cache.deleteCustom('gasCoin');\n\t\t}\n\t};\n\n\tasync buildTransaction(transaction: Transaction) {\n\t\treturn this.#queue.runTask(() => this.#buildTransaction(transaction));\n\t}\n\n\t#buildTransaction = async (transaction: Transaction) => {\n\t\tawait transaction.prepareForSerialization({\n\t\t\tclient: this.#client,\n\t\t\tsupportedIntents: ['CoinWithBalance'],\n\t\t});\n\t\tconst copy = Transaction.from(transaction);\n\n\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\tcopy.setGasPayment([]);\n\t\t\tcopy.setExpiration(await this.#getValidDuringExpiration());\n\t\t} else {\n\t\t\t// Coin mode: use cached gas coin if available\n\t\t\tconst gasCoin = await this.#cache.cache.getCustom<{\n\t\t\t\tobjectId: string;\n\t\t\t\tversion: string;\n\t\t\t\tdigest: string;\n\t\t\t}>('gasCoin');\n\n\t\t\tif (gasCoin) {\n\t\t\t\tcopy.setGasPayment([gasCoin]);\n\t\t\t}\n\t\t}\n\n\t\tcopy.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\t\tcopy.setSenderIfNotSet(this.#signer.toHaneulAddress());\n\n\t\treturn this.#cache.buildTransaction({ transaction: copy });\n\t};\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tresetCache() {\n\t\treturn this.#cache.reset();\n\t}\n\n\twaitForLastTransaction() {\n\t\treturn this.#cache.waitForLastTransaction();\n\t}\n\n\texecuteTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction | Uint8Array,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\treturn this.#queue.runTask(async () => {\n\t\t\tconst bytes = isTransaction(transaction)\n\t\t\t\t? await this.#buildTransaction(transaction)\n\t\t\t\t: transaction;\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\t\t\treturn this.#cache\n\t\t\t\t.executeTransaction({\n\t\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\t\ttransaction: bytes,\n\t\t\t\t\tinclude,\n\t\t\t\t})\n\t\t\t\t.catch(async (error) => {\n\t\t\t\t\tawait this.resetCache();\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t});\n\t}\n}\n\nexport function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\tif (!effects.V2) {\n\t\tthrow new Error('Unexpected effects version');\n\t}\n\n\tconst gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex!];\n\n\tif (!gasObjectChange) {\n\t\tthrow new Error('Gas object not found in effects');\n\t}\n\n\tconst [objectId, { outputState }] = gasObjectChange;\n\n\tif (!outputState.ObjectWrite) {\n\t\tthrow new Error('Unexpected gas object state');\n\t}\n\n\tconst [digest, owner] = outputState.ObjectWrite;\n\n\treturn {\n\t\tref: {\n\t\t\tobjectId,\n\t\t\tdigest,\n\t\t\tversion: effects.V2.lamportVersion,\n\t\t},\n\t\towner: owner.AddressOwner || owner.ObjectOwner!,\n\t};\n}\n"],"mappings":";;;;;AAYA,MAAM,wBAAwB;AAoB9B,IAAa,4BAAb,MAAuC;CACtC,SAAS,IAAI,aAAa;CAC1B;CACA;CACA;CACA;CACA;CACA,aAII;CACJ,oBAA0C;CAE1C,YAAY,SAA2C;EACtD,MAAM,EAAE,QAAQ,mBAAmB,WAAa,QAAQ,UAAU;AAClE,QAAKA,SAAU;AACf,QAAKC,SAAU;AACf,QAAKC,mBAAoB;AACzB,QAAKC,UAAW,QAAQ,WAAW;AACnC,QAAKC,QAAS,IAAI,2BAA2B;GAC5C;GACA;GACA,YAAY,YAAY,MAAKC,aAAc,QAAQ;GACnD,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,SAAO,MAAKD,MAAO,aAAa,QAAQ;;CAGzC,gBAAgB,OAAO,YAAsD;AAC5E,MAAI,MAAKD,YAAa,oBAAoB,CAAC,QAAQ,GAClD;EAGD,MAAM,UAAU,sBAAsB,QAAQ,CAAC;AAC/C,MAAI,QACH,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#gasMode","#cache","#cacheGasCoin","#queue","#buildTransaction","#getValidDuringExpiration","#ensureEpochInfo","#epochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/serial.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport type { HaneulClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { isTransaction, Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { SerialQueue } from './queue.js';\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface SerialTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\tdefaultGasBudget?: bigint;\n}\n\nexport interface SerialTransactionExecutorCoinOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode?: 'coins';\n}\n\nexport interface SerialTransactionExecutorAddressBalanceOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode: 'addressBalance';\n}\n\nexport type SerialTransactionExecutorOptions =\n\t| SerialTransactionExecutorCoinOptions\n\t| SerialTransactionExecutorAddressBalanceOptions;\n\nexport class SerialTransactionExecutor {\n\t#queue = new SerialQueue();\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#cache: CachingTransactionExecutor;\n\t#defaultGasBudget: bigint;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: SerialTransactionExecutorOptions) {\n\t\tconst { signer, defaultGasBudget = 50_000_000n, client, cache } = options;\n\t\tthis.#signer = signer;\n\t\tthis.#client = client;\n\t\tthis.#defaultGasBudget = defaultGasBudget;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient,\n\t\t\tcache,\n\t\t\tonEffects: (effects) => this.#cacheGasCoin(effects),\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\treturn this.#cache.applyEffects(effects);\n\t}\n\n\t#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {\n\t\tif (this.#gasMode === 'addressBalance' || !effects.V2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst gasCoin = getGasCoinFromEffects(effects).ref;\n\t\tif (gasCoin) {\n\t\t\tthis.#cache.cache.setCustom('gasCoin', gasCoin);\n\t\t} else {\n\t\t\tthis.#cache.cache.deleteCustom('gasCoin');\n\t\t}\n\t};\n\n\tasync buildTransaction(transaction: Transaction) {\n\t\treturn this.#queue.runTask(() => this.#buildTransaction(transaction));\n\t}\n\n\t#buildTransaction = async (transaction: Transaction) => {\n\t\tawait transaction.prepareForSerialization({\n\t\t\tclient: this.#client,\n\t\t\tsupportedIntents: ['CoinWithBalance'],\n\t\t});\n\t\tconst copy = Transaction.from(transaction);\n\n\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\tcopy.setGasPayment([]);\n\t\t\tcopy.setExpiration(await this.#getValidDuringExpiration());\n\t\t} else {\n\t\t\t// Coin mode: use cached gas coin if available\n\t\t\tconst gasCoin = await this.#cache.cache.getCustom<{\n\t\t\t\tobjectId: string;\n\t\t\t\tversion: string;\n\t\t\t\tdigest: string;\n\t\t\t}>('gasCoin');\n\n\t\t\tif (gasCoin) {\n\t\t\t\tcopy.setGasPayment([gasCoin]);\n\t\t\t}\n\t\t}\n\n\t\tcopy.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\t\tcopy.setSenderIfNotSet(this.#signer.toHaneulAddress());\n\n\t\treturn this.#cache.buildTransaction({ transaction: copy });\n\t};\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tresetCache() {\n\t\treturn this.#cache.reset();\n\t}\n\n\twaitForLastTransaction() {\n\t\treturn this.#cache.waitForLastTransaction();\n\t}\n\n\texecuteTransaction<Include extends HaneulClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction | Uint8Array,\n\t\tinclude?: Include & HaneulClientTypes.TransactionInclude,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<HaneulClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\treturn this.#queue.runTask(async () => {\n\t\t\tconst bytes = isTransaction(transaction)\n\t\t\t\t? await this.#buildTransaction(transaction)\n\t\t\t\t: transaction;\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\t\t\treturn this.#cache\n\t\t\t\t.executeTransaction({\n\t\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\t\ttransaction: bytes,\n\t\t\t\t\tinclude,\n\t\t\t\t})\n\t\t\t\t.catch(async (error) => {\n\t\t\t\t\tawait this.resetCache();\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t});\n\t}\n}\n\nexport function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\tif (!effects.V2) {\n\t\tthrow new Error('Unexpected effects version');\n\t}\n\n\tconst gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex!];\n\n\tif (!gasObjectChange) {\n\t\tthrow new Error('Gas object not found in effects');\n\t}\n\n\tconst [objectId, { outputState }] = gasObjectChange;\n\n\tif (!outputState.ObjectWrite) {\n\t\tthrow new Error('Unexpected gas object state');\n\t}\n\n\tconst [digest, owner] = outputState.ObjectWrite;\n\n\treturn {\n\t\tref: {\n\t\t\tobjectId,\n\t\t\tdigest,\n\t\t\tversion: effects.V2.lamportVersion,\n\t\t},\n\t\towner: owner.AddressOwner || owner.ObjectOwner!,\n\t};\n}\n"],"mappings":";;;;;AAYA,MAAM,wBAAwB;AAoB9B,IAAa,4BAAb,MAAuC;CACtC,SAAS,IAAI,aAAa;CAC1B;CACA;CACA;CACA;CACA;CACA,aAII;CACJ,oBAA0C;CAE1C,YAAY,SAA2C;EACtD,MAAM,EAAE,QAAQ,mBAAmB,WAAa,QAAQ,UAAU;AAClE,QAAKA,SAAU;AACf,QAAKC,SAAU;AACf,QAAKC,mBAAoB;AACzB,QAAKC,UAAW,QAAQ,WAAW;AACnC,QAAKC,QAAS,IAAI,2BAA2B;GAC5C;GACA;GACA,YAAY,YAAY,MAAKC,aAAc,QAAQ;GACnD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MAAM,8BAA8B;CAG/C,MAAM,CAAC,QAAQ,SAAS,YAAY;AAEpC,QAAO;EACN,KAAK;GACJ;GACA;GACA,SAAS,QAAQ,GAAG;GACpB;EACD,OAAO,MAAM,gBAAgB,MAAM;EACnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoinWithBalance.d.mts","names":[],"sources":["../../../src/transactions/intents/CoinWithBalance.ts"],"
|
|
1
|
+
{"version":3,"file":"CoinWithBalance.d.mts","names":[],"sources":["../../../src/transactions/intents/CoinWithBalance.ts"],"mappings":";;;;;iBAmBgB,eAAA,CAAA;EACf,IAAA;EACA,OAAA;EACA;AAAA;EAEA,OAAA;EACA,IAAA;EACA,UAAA;AAAA,KACI,EAAA,EAAI,WAAA,KAAgB,iBAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { normalizeStructTag } from "../../utils/haneul-types.mjs";
|
|
2
|
-
import { bcs as
|
|
2
|
+
import { bcs as haneulBcs } from "../../bcs/index.mjs";
|
|
3
3
|
import { TransactionCommands } from "../Commands.mjs";
|
|
4
4
|
import { Inputs } from "../Inputs.mjs";
|
|
5
|
-
import { bigint, object, parse, string } from "valibot";
|
|
5
|
+
import { bigint, object, optional, parse, picklist, string } from "valibot";
|
|
6
6
|
|
|
7
7
|
//#region src/transactions/intents/CoinWithBalance.ts
|
|
8
8
|
const COIN_WITH_BALANCE = "CoinWithBalance";
|
|
9
|
-
const
|
|
10
|
-
function coinWithBalance({ type =
|
|
9
|
+
const HANEUL_TYPE = normalizeStructTag("0x2::haneul::HANEUL");
|
|
10
|
+
function coinWithBalance({ type = HANEUL_TYPE, balance, useGasCoin = true }) {
|
|
11
11
|
let coinResult = null;
|
|
12
12
|
return (tx) => {
|
|
13
13
|
if (coinResult) return coinResult;
|
|
@@ -17,25 +17,60 @@ function coinWithBalance({ type = SUI_TYPE, balance, useGasCoin = true }) {
|
|
|
17
17
|
name: COIN_WITH_BALANCE,
|
|
18
18
|
inputs: {},
|
|
19
19
|
data: {
|
|
20
|
-
type: coinType ===
|
|
21
|
-
balance: BigInt(balance)
|
|
20
|
+
type: coinType === HANEUL_TYPE && useGasCoin ? "gas" : coinType,
|
|
21
|
+
balance: BigInt(balance),
|
|
22
|
+
outputKind: "coin"
|
|
22
23
|
}
|
|
23
24
|
}));
|
|
24
25
|
return coinResult;
|
|
25
26
|
};
|
|
26
27
|
}
|
|
28
|
+
function createBalance({ type = HANEUL_TYPE, balance, useGasCoin = true }) {
|
|
29
|
+
let balanceResult = null;
|
|
30
|
+
return (tx) => {
|
|
31
|
+
if (balanceResult) return balanceResult;
|
|
32
|
+
tx.addIntentResolver(COIN_WITH_BALANCE, resolveCoinBalance);
|
|
33
|
+
const coinType = type === "gas" ? type : normalizeStructTag(type);
|
|
34
|
+
balanceResult = tx.add(TransactionCommands.Intent({
|
|
35
|
+
name: COIN_WITH_BALANCE,
|
|
36
|
+
inputs: {},
|
|
37
|
+
data: {
|
|
38
|
+
type: coinType === HANEUL_TYPE && useGasCoin ? "gas" : coinType,
|
|
39
|
+
balance: BigInt(balance),
|
|
40
|
+
outputKind: "balance"
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
return balanceResult;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
27
46
|
const CoinWithBalanceData = object({
|
|
28
47
|
type: string(),
|
|
29
|
-
balance: bigint()
|
|
48
|
+
balance: bigint(),
|
|
49
|
+
outputKind: optional(picklist(["coin", "balance"]))
|
|
30
50
|
});
|
|
31
51
|
async function resolveCoinBalance(transactionData, buildOptions, next) {
|
|
32
52
|
const coinTypes = /* @__PURE__ */ new Set();
|
|
33
53
|
const totalByType = /* @__PURE__ */ new Map();
|
|
54
|
+
const intentsByType = /* @__PURE__ */ new Map();
|
|
34
55
|
if (!transactionData.sender) throw new Error("Sender must be set to resolve CoinWithBalance");
|
|
35
|
-
for (const command of transactionData.commands
|
|
36
|
-
|
|
37
|
-
|
|
56
|
+
for (const [i, command] of transactionData.commands.entries()) {
|
|
57
|
+
if (command.$kind !== "$Intent" || command.$Intent.name !== COIN_WITH_BALANCE) continue;
|
|
58
|
+
const { type, balance, outputKind } = parse(CoinWithBalanceData, command.$Intent.data);
|
|
59
|
+
if (balance === 0n) {
|
|
60
|
+
const coinType = type === "gas" ? HANEUL_TYPE : type;
|
|
61
|
+
transactionData.replaceCommand(i, TransactionCommands.MoveCall({
|
|
62
|
+
target: (outputKind ?? "coin") === "balance" ? "0x2::balance::zero" : "0x2::coin::zero",
|
|
63
|
+
typeArguments: [coinType]
|
|
64
|
+
}));
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (type !== "gas") coinTypes.add(type);
|
|
38
68
|
totalByType.set(type, (totalByType.get(type) ?? 0n) + balance);
|
|
69
|
+
if (!intentsByType.has(type)) intentsByType.set(type, []);
|
|
70
|
+
intentsByType.get(type).push({
|
|
71
|
+
balance,
|
|
72
|
+
outputKind: outputKind ?? "coin"
|
|
73
|
+
});
|
|
39
74
|
}
|
|
40
75
|
const usedIds = /* @__PURE__ */ new Set();
|
|
41
76
|
for (const input of transactionData.inputs) {
|
|
@@ -58,94 +93,140 @@ async function resolveCoinBalance(transactionData, buildOptions, next) {
|
|
|
58
93
|
addressBalanceByType.set(coinType, addressBalance);
|
|
59
94
|
}), totalByType.has("gas") ? await client.core.getBalance({
|
|
60
95
|
owner: transactionData.sender,
|
|
61
|
-
coinType:
|
|
96
|
+
coinType: HANEUL_TYPE
|
|
62
97
|
}).then(({ balance }) => {
|
|
63
98
|
addressBalanceByType.set("gas", BigInt(balance.addressBalance));
|
|
64
99
|
}) : null]);
|
|
65
100
|
const mergedCoins = /* @__PURE__ */ new Map();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}));
|
|
101
|
+
const exactBalanceByType = /* @__PURE__ */ new Map();
|
|
102
|
+
const typeState = /* @__PURE__ */ new Map();
|
|
103
|
+
let index = 0;
|
|
104
|
+
while (index < transactionData.commands.length) {
|
|
105
|
+
const transaction = transactionData.commands[index];
|
|
106
|
+
if (transaction.$kind !== "$Intent" || transaction.$Intent.name !== COIN_WITH_BALANCE) {
|
|
107
|
+
index++;
|
|
74
108
|
continue;
|
|
75
109
|
}
|
|
110
|
+
const { type, balance } = transaction.$Intent.data;
|
|
111
|
+
const coinType = type === "gas" ? HANEUL_TYPE : type;
|
|
112
|
+
const totalRequired = totalByType.get(type);
|
|
113
|
+
const addressBalance = addressBalanceByType.get(type) ?? 0n;
|
|
76
114
|
const commands = [];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
115
|
+
let intentResult;
|
|
116
|
+
const intentsForType = intentsByType.get(type) ?? [];
|
|
117
|
+
if (intentsForType.every((i) => i.outputKind === "balance") && addressBalance >= totalRequired) {
|
|
118
|
+
commands.push(TransactionCommands.MoveCall({
|
|
119
|
+
target: "0x2::balance::redeem_funds",
|
|
120
|
+
typeArguments: [coinType],
|
|
121
|
+
arguments: [transactionData.addInput("withdrawal", Inputs.FundsWithdrawal({
|
|
122
|
+
reservation: {
|
|
123
|
+
$kind: "MaxAmountU64",
|
|
124
|
+
MaxAmountU64: String(balance)
|
|
125
|
+
},
|
|
126
|
+
typeArg: {
|
|
127
|
+
$kind: "Balance",
|
|
128
|
+
Balance: coinType
|
|
129
|
+
},
|
|
130
|
+
withdrawFrom: {
|
|
131
|
+
$kind: "Sender",
|
|
132
|
+
Sender: true
|
|
133
|
+
}
|
|
134
|
+
}))]
|
|
135
|
+
}));
|
|
136
|
+
intentResult = {
|
|
137
|
+
$kind: "NestedResult",
|
|
138
|
+
NestedResult: [index + commands.length - 1, 0]
|
|
139
|
+
};
|
|
140
|
+
} else {
|
|
141
|
+
if (!typeState.has(type)) {
|
|
142
|
+
const intents = intentsForType;
|
|
143
|
+
const sources = [];
|
|
144
|
+
if (type === "gas") sources.push({
|
|
145
|
+
$kind: "GasCoin",
|
|
146
|
+
GasCoin: true
|
|
147
|
+
});
|
|
148
|
+
else {
|
|
149
|
+
const coins = coinsByType.get(type);
|
|
150
|
+
const loadedCoinBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
151
|
+
const abNeeded = totalRequired > loadedCoinBalance ? totalRequired - loadedCoinBalance : 0n;
|
|
152
|
+
exactBalanceByType.set(type, loadedCoinBalance + abNeeded === totalRequired);
|
|
153
|
+
for (const coin of coins) sources.push(transactionData.addInput("object", Inputs.ObjectRef({
|
|
154
|
+
objectId: coin.objectId,
|
|
155
|
+
digest: coin.digest,
|
|
156
|
+
version: coin.version
|
|
157
|
+
})));
|
|
158
|
+
if (abNeeded > 0n) {
|
|
159
|
+
commands.push(TransactionCommands.MoveCall({
|
|
160
|
+
target: "0x2::coin::redeem_funds",
|
|
161
|
+
typeArguments: [coinType],
|
|
162
|
+
arguments: [transactionData.addInput("withdrawal", Inputs.FundsWithdrawal({
|
|
163
|
+
reservation: {
|
|
164
|
+
$kind: "MaxAmountU64",
|
|
165
|
+
MaxAmountU64: String(abNeeded)
|
|
166
|
+
},
|
|
167
|
+
typeArg: {
|
|
168
|
+
$kind: "Balance",
|
|
169
|
+
Balance: coinType
|
|
170
|
+
},
|
|
171
|
+
withdrawFrom: {
|
|
172
|
+
$kind: "Sender",
|
|
173
|
+
Sender: true
|
|
174
|
+
}
|
|
175
|
+
}))]
|
|
176
|
+
}));
|
|
177
|
+
sources.push({
|
|
178
|
+
$kind: "Result",
|
|
179
|
+
Result: index + commands.length - 1
|
|
180
|
+
});
|
|
181
|
+
}
|
|
92
182
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!mergedCoins.has(type)) {
|
|
97
|
-
const addressBalance = addressBalanceByType.get(type) ?? 0n;
|
|
98
|
-
const coinType = type === "gas" ? SUI_TYPE : type;
|
|
99
|
-
let baseCoin;
|
|
100
|
-
let restCoins;
|
|
101
|
-
if (type === "gas") {
|
|
102
|
-
baseCoin = {
|
|
103
|
-
$kind: "GasCoin",
|
|
104
|
-
GasCoin: true
|
|
105
|
-
};
|
|
106
|
-
restCoins = [];
|
|
107
|
-
} else [baseCoin, ...restCoins] = coinsByType.get(type).map((coin) => transactionData.addInput("object", Inputs.ObjectRef({
|
|
108
|
-
objectId: coin.objectId,
|
|
109
|
-
digest: coin.digest,
|
|
110
|
-
version: coin.version
|
|
111
|
-
})));
|
|
112
|
-
if (addressBalance > 0n) {
|
|
113
|
-
commands.push(TransactionCommands.MoveCall({
|
|
114
|
-
target: "0x2::coin::redeem_funds",
|
|
115
|
-
typeArguments: [coinType],
|
|
116
|
-
arguments: [transactionData.addInput("withdrawal", Inputs.FundsWithdrawal({
|
|
117
|
-
reservation: {
|
|
118
|
-
$kind: "MaxAmountU64",
|
|
119
|
-
MaxAmountU64: String(addressBalance)
|
|
120
|
-
},
|
|
121
|
-
typeArg: {
|
|
122
|
-
$kind: "Balance",
|
|
123
|
-
Balance: coinType
|
|
124
|
-
},
|
|
125
|
-
withdrawFrom: {
|
|
126
|
-
$kind: "Sender",
|
|
127
|
-
Sender: true
|
|
128
|
-
}
|
|
129
|
-
}))]
|
|
130
|
-
}));
|
|
131
|
-
commands.push(TransactionCommands.MergeCoins(baseCoin, [{
|
|
132
|
-
$kind: "Result",
|
|
133
|
-
Result: index + commands.length - 1
|
|
134
|
-
}, ...restCoins]));
|
|
135
|
-
} else if (restCoins.length > 0) commands.push(TransactionCommands.MergeCoins(baseCoin, restCoins));
|
|
183
|
+
const baseCoin = sources[0];
|
|
184
|
+
const rest = sources.slice(1);
|
|
185
|
+
for (let i = 0; i < rest.length; i += 500) commands.push(TransactionCommands.MergeCoins(baseCoin, rest.slice(i, i + 500)));
|
|
136
186
|
mergedCoins.set(type, baseCoin);
|
|
187
|
+
const splitCmdIndex = index + commands.length;
|
|
188
|
+
commands.push(TransactionCommands.SplitCoins(baseCoin, intents.map((i) => transactionData.addInput("pure", Inputs.Pure(haneulBcs.u64().serialize(i.balance))))));
|
|
189
|
+
const results = [];
|
|
190
|
+
for (let i = 0; i < intents.length; i++) {
|
|
191
|
+
const splitResult = {
|
|
192
|
+
$kind: "NestedResult",
|
|
193
|
+
NestedResult: [splitCmdIndex, i]
|
|
194
|
+
};
|
|
195
|
+
if (intents[i].outputKind === "balance") {
|
|
196
|
+
commands.push(TransactionCommands.MoveCall({
|
|
197
|
+
target: "0x2::coin::into_balance",
|
|
198
|
+
typeArguments: [coinType],
|
|
199
|
+
arguments: [splitResult]
|
|
200
|
+
}));
|
|
201
|
+
results.push({
|
|
202
|
+
$kind: "NestedResult",
|
|
203
|
+
NestedResult: [index + commands.length - 1, 0]
|
|
204
|
+
});
|
|
205
|
+
} else results.push(splitResult);
|
|
206
|
+
}
|
|
207
|
+
typeState.set(type, {
|
|
208
|
+
results,
|
|
209
|
+
nextIntent: 0
|
|
210
|
+
});
|
|
137
211
|
}
|
|
138
|
-
|
|
212
|
+
const state = typeState.get(type);
|
|
213
|
+
intentResult = state.results[state.nextIntent++];
|
|
139
214
|
}
|
|
140
|
-
transactionData.replaceCommand(index, commands);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
215
|
+
transactionData.replaceCommand(index, commands, intentResult);
|
|
216
|
+
index += commands.length;
|
|
217
|
+
}
|
|
218
|
+
for (const [type, mergedCoin] of mergedCoins) {
|
|
219
|
+
if (type === "gas") continue;
|
|
220
|
+
if (intentsByType.get(type)?.some((i) => i.outputKind === "balance")) transactionData.commands.push(TransactionCommands.MoveCall({
|
|
221
|
+
target: "0x2::coin::send_funds",
|
|
222
|
+
typeArguments: [type],
|
|
223
|
+
arguments: [mergedCoin, transactionData.addInput("pure", Inputs.Pure(haneulBcs.Address.serialize(transactionData.sender)))]
|
|
224
|
+
}));
|
|
225
|
+
else if (exactBalanceByType.get(type)) transactionData.commands.push(TransactionCommands.MoveCall({
|
|
226
|
+
target: "0x2::coin::destroy_zero",
|
|
227
|
+
typeArguments: [type],
|
|
228
|
+
arguments: [mergedCoin]
|
|
229
|
+
}));
|
|
149
230
|
}
|
|
150
231
|
return next();
|
|
151
232
|
}
|
|
@@ -174,20 +255,16 @@ async function getCoinsAndBalanceOfType({ coinType, balance, client, owner, used
|
|
|
174
255
|
cursor
|
|
175
256
|
});
|
|
176
257
|
await balanceRequest;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
coins.push(coin);
|
|
182
|
-
remainingBalance -= coinBalance;
|
|
183
|
-
if (remainingBalance <= 0) break;
|
|
184
|
-
}
|
|
185
|
-
if (hasNextPage) return loadMoreCoins(nextCursor);
|
|
258
|
+
for (const coin of objects) {
|
|
259
|
+
if (usedIds.has(coin.objectId)) continue;
|
|
260
|
+
coins.push(coin);
|
|
261
|
+
remainingBalance -= BigInt(coin.balance);
|
|
186
262
|
}
|
|
263
|
+
if (remainingBalance > 0n && hasNextPage) return loadMoreCoins(nextCursor);
|
|
187
264
|
return coins;
|
|
188
265
|
}
|
|
189
266
|
}
|
|
190
267
|
|
|
191
268
|
//#endregion
|
|
192
|
-
export { COIN_WITH_BALANCE, coinWithBalance, resolveCoinBalance };
|
|
269
|
+
export { COIN_WITH_BALANCE, coinWithBalance, createBalance, resolveCoinBalance };
|
|
193
270
|
//# sourceMappingURL=CoinWithBalance.mjs.map
|