@mysten/sui 2.12.1 → 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 +18 -0
- package/dist/bcs/bcs.d.mts +0 -1
- package/dist/bcs/bcs.d.mts.map +1 -1
- package/dist/bcs/index.d.mts +20 -20
- package/dist/bcs/index.d.mts.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 -76
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts.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.map +1 -1
- package/dist/client/utils.d.mts.map +1 -1
- package/dist/cryptography/intent.d.mts.map +1 -1
- package/dist/cryptography/keypair.d.mts.map +1 -1
- package/dist/cryptography/mnemonics.d.mts.map +1 -1
- package/dist/cryptography/publickey.d.mts +0 -1
- package/dist/cryptography/publickey.d.mts.map +1 -1
- package/dist/cryptography/signature-scheme.d.mts.map +1 -1
- package/dist/cryptography/signature.d.mts +2 -5
- package/dist/cryptography/signature.d.mts.map +1 -1
- package/dist/faucet/faucet.d.mts.map +1 -1
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/core.d.mts.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/tada-env.d.mts.map +1 -1
- 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.map +1 -1
- package/dist/grpc/core.d.mts.map +1 -1
- 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/sui/rpc/v2/argument.d.mts +1 -2
- package/dist/grpc/proto/sui/rpc/v2/argument.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/balance_change.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/balance_change.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/bcs.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/bcs.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/checkpoint.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/checkpoint.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/checkpoint_contents.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/checkpoint_contents.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/checkpoint_summary.d.mts +1 -2
- package/dist/grpc/proto/sui/rpc/v2/checkpoint_summary.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/effects.d.mts +5 -6
- package/dist/grpc/proto/sui/rpc/v2/effects.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/epoch.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/epoch.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts +1 -1
- package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/event.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/event.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/executed_transaction.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/executed_transaction.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/execution_status.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/execution_status.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/gas_cost_summary.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/gas_cost_summary.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/input.d.mts +3 -4
- package/dist/grpc/proto/sui/rpc/v2/input.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/jwk.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/jwk.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package.d.mts +5 -6
- package/dist/grpc/proto/sui/rpc/v2/move_package.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/name_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/object.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/object.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/object_reference.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/object_reference.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/owner.d.mts +1 -2
- package/dist/grpc/proto/sui/rpc/v2/owner.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/protocol_config.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/protocol_config.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/signature.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/state_service.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/state_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/system_state.d.mts +0 -1
- package/dist/grpc/proto/sui/rpc/v2/system_state.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -5
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +1 -2
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/types.d.mts.map +1 -1
- package/dist/jsonRpc/client.d.mts +2 -5
- package/dist/jsonRpc/client.d.mts.map +1 -1
- package/dist/jsonRpc/client.mjs +1 -30
- package/dist/jsonRpc/client.mjs.map +1 -1
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/errors.d.mts.map +1 -1
- package/dist/jsonRpc/http-transport.d.mts.map +1 -1
- 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.map +1 -1
- package/dist/jsonRpc/types/generated.d.mts +99 -127
- package/dist/jsonRpc/types/generated.d.mts.map +1 -1
- package/dist/jsonRpc/types/params.d.mts +4 -9
- package/dist/jsonRpc/types/params.d.mts.map +1 -1
- package/dist/keypairs/ed25519/keypair.d.mts.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.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.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.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/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/Inputs.d.mts.map +1 -1
- package/dist/transactions/ObjectCache.d.mts.map +1 -1
- package/dist/transactions/Transaction.d.mts +29 -3
- 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/data/internal.d.mts.map +1 -1
- package/dist/transactions/data/v1.d.mts +0 -1
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts.map +1 -1
- package/dist/transactions/executor/parallel.d.mts.map +1 -1
- package/dist/transactions/executor/serial.d.mts.map +1 -1
- package/dist/transactions/intents/CoinWithBalance.d.mts.map +1 -1
- package/dist/transactions/intents/CoinWithBalance.mjs +169 -92
- 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/resolve.d.mts.map +1 -1
- package/dist/transactions/serializer.d.mts.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.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/format.d.mts.map +1 -1
- package/dist/utils/move-registry.d.mts.map +1 -1
- package/dist/utils/sui-types.d.mts.map +1 -1
- package/dist/utils/suins.d.mts.map +1 -1
- package/dist/verify/verify.d.mts.map +1 -1
- package/dist/version.mjs +2 -2
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/address.d.mts.map +1 -1
- 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/package.json +1 -1
- package/src/client/core-resolver.ts +149 -115
- package/src/jsonRpc/client.ts +1 -19
- package/src/transactions/Transaction.ts +38 -1
- package/src/transactions/intents/CoinWithBalance.ts +243 -117
- package/src/utils/coin-reservation.ts +84 -0
- package/src/version.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-utils.d.mts","names":[],"sources":["../../src/zklogin/jwt-utils.ts"],"
|
|
1
|
+
{"version":3,"file":"jwt-utils.d.mts","names":[],"sources":["../../src/zklogin/jwt-utils.ts"],"mappings":";;;iBAsHgB,SAAA,CAAU,GAAA,WAAc,IAAA,CAAK,UAAA;EAC5C,GAAA;EACA,GAAA;EACA,GAAA;EACA,MAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nonce.d.mts","names":[],"sources":["../../src/zklogin/nonce.ts"],"
|
|
1
|
+
{"version":3,"file":"nonce.d.mts","names":[],"sources":["../../src/zklogin/nonce.ts"],"mappings":";;;iBAqBgB,kBAAA,CAAA;AAAA,iBAKA,aAAA,CAAc,SAAA,EAAW,SAAA,EAAW,QAAA,UAAkB,UAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poseidon.d.mts","names":[],"sources":["../../src/zklogin/poseidon.ts"],"
|
|
1
|
+
{"version":3,"file":"poseidon.d.mts","names":[],"sources":["../../src/zklogin/poseidon.ts"],"mappings":";iBA4CgB,YAAA,CAAa,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/zklogin/publickey.ts"],"
|
|
1
|
+
{"version":3,"file":"publickey.d.mts","names":[],"sources":["../../src/zklogin/publickey.ts"],"mappings":";;;;;;AAoBA;;cAAa,uBAAA,SAAgC,SAAA;EAAA;EASJ;;;;cAA5B,KAAA,EAAO,iBAAA;IAAqB;EAAA;IAAY,MAAA,GAAS,iBAAA;EAAA;EAAA,OAmBtD,SAAA,CACN,KAAA,EAAO,UAAA;IAEN,MAAA;IACA,OAAA;IACA;EAAA;IACI,MAAA,GAAS,iBAAA;IAAmB,OAAA;IAAkB,aAAA;EAAA,IAA8B,uBAAA;EAAA,OAmC3E,SAAA,CAAU,OAAA,UAAiB,KAAA,EAAO,sBAAA,GAAsB,uBAAA;EAiExC;;;EAvCd,MAAA,CAAO,SAAA,EAAW,uBAAA;EAIlB,YAAA,CAAA;EA0CmE;;;EArB5E,UAAA,CAAA,GAAc,UAAA,CAAW,WAAA;EAxHmB;;;EA+H5C,IAAA,CAAA;;;;EAOM,MAAA,CAAO,QAAA,EAAU,UAAA,EAAY,UAAA,EAAY,UAAA,YAAsB,OAAA;EA7H7B;;;EAoIxC,qBAAA,CAAsB,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EAjHrE;;;EAiIP,iBAAA,CAAkB,WAAA,EAAa,UAAA,EAAY,SAAA,EAAW,UAAA,YAAsB,OAAA;EA9H1E;;;EA6IO,aAAA,CAAc,OAAA;AAAA;AAAA,iBAMR,yBAAA,CACf,WAAA,UACA,GAAA,UACA,OAAA;EAAW,MAAA,GAAS,iBAAA;EAAmB,aAAA;AAAA,IACrC,uBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.d.mts","names":[],"sources":["../../src/zklogin/signature.ts"],"
|
|
1
|
+
{"version":3,"file":"signature.d.mts","names":[],"sources":["../../src/zklogin/signature.ts"],"mappings":";;;UASU,wBAAA,SAAiC,IAAA,CAAK,gBAAA;EAC/C,aAAA,WAAwB,gBAAA;AAAA;AAAA,iBAiBT,mBAAA,CAAA;EAAsB,MAAA;EAAQ,QAAA;EAAU;AAAA,GAAiB,wBAAA;AAAA,iBAQzD,qBAAA,CAAsB,SAAA,WAAoB,UAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/zklogin/utils.ts"],"
|
|
1
|
+
{"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/zklogin/utils.ts"],"mappings":";;;iBAwBgB,sBAAA,CAAuB,GAAA,UAAa,KAAA,WAAgB,UAAA;AAAA,iBAMpD,gBAAA,CAAiB,GAAA,UAAa,KAAA,WAAgB,UAAA;AAAA,iBAY9C,6BAAA,CAA8B,SAAA,EAAW,SAAA;AAAA,iBA8BzC,mBAAA,CAAoB,GAAA,UAAa,OAAA;AAAA,iBAiBjC,cAAA,CACf,IAAA,mBACA,IAAA,UACA,KAAA,UACA,GAAA,UACA,eAAA,WACA,gBAAA,WACA,cAAA"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
normalizeSuiAddress,
|
|
6
|
+
normalizeSuiObjectId,
|
|
7
|
+
normalizeStructTag,
|
|
8
|
+
SUI_TYPE_ARG,
|
|
9
|
+
} from '../utils/index.js';
|
|
10
|
+
import { createCoinReservationRef } from '../utils/coin-reservation.js';
|
|
7
11
|
import type { ClientWithCoreApi } from './core.js';
|
|
8
|
-
import { ObjectRefSchema } from '../transactions/data/internal.js';
|
|
9
12
|
import type { CallArg, Command } from '../transactions/data/internal.js';
|
|
10
13
|
import type { SuiClientTypes } from './types.js';
|
|
11
14
|
import { SimulationError } from './errors.js';
|
|
@@ -38,36 +41,89 @@ export async function coreClientResolveTransactionPlugin(
|
|
|
38
41
|
) {
|
|
39
42
|
const client = getClient(options);
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
const needsGasPrice = !options.onlyTransactionKind && !transactionData.gasData.price;
|
|
45
|
+
const needsPayment = !options.onlyTransactionKind && !transactionData.gasData.payment;
|
|
46
|
+
const gasPayer = transactionData.gasData.owner ?? transactionData.sender;
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
let usesGasCoin = false;
|
|
49
|
+
let withdrawals = 0n;
|
|
50
|
+
|
|
51
|
+
transactionData.mapArguments((arg) => {
|
|
52
|
+
if (arg.$kind === 'GasCoin') usesGasCoin = true;
|
|
53
|
+
return arg;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const normalizedGasPayer = gasPayer ? normalizeSuiAddress(gasPayer) : null;
|
|
57
|
+
for (const input of transactionData.inputs) {
|
|
58
|
+
if (input.$kind !== 'FundsWithdrawal' || !normalizedGasPayer) continue;
|
|
59
|
+
if (normalizeStructTag(input.FundsWithdrawal.typeArg.Balance) !== SUI_TYPE_ARG) continue;
|
|
60
|
+
|
|
61
|
+
const withdrawalOwner = input.FundsWithdrawal.withdrawFrom.Sender
|
|
62
|
+
? transactionData.sender
|
|
63
|
+
: gasPayer;
|
|
64
|
+
if (
|
|
65
|
+
withdrawalOwner &&
|
|
66
|
+
normalizeSuiAddress(withdrawalOwner) === normalizedGasPayer &&
|
|
67
|
+
input.FundsWithdrawal.reservation.$kind === 'MaxAmountU64'
|
|
68
|
+
) {
|
|
69
|
+
withdrawals += BigInt(input.FundsWithdrawal.reservation.MaxAmountU64);
|
|
70
|
+
}
|
|
46
71
|
}
|
|
47
72
|
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
const needsSystemState = needsGasPrice || (needsPayment && usesGasCoin);
|
|
74
|
+
const [, systemStateResult, balanceResult, coinsResult, protocolConfigResult, chainIdResult] =
|
|
75
|
+
await Promise.all([
|
|
76
|
+
normalizeInputs(transactionData, client),
|
|
77
|
+
needsSystemState ? client.core.getCurrentSystemState() : null,
|
|
78
|
+
needsPayment && gasPayer ? client.core.getBalance({ owner: gasPayer }) : null,
|
|
79
|
+
needsPayment && gasPayer
|
|
80
|
+
? client.core.listCoins({ owner: gasPayer, coinType: SUI_TYPE_ARG })
|
|
81
|
+
: null,
|
|
82
|
+
needsPayment && usesGasCoin ? client.core.getProtocolConfig() : null,
|
|
83
|
+
needsPayment && usesGasCoin ? client.core.getChainIdentifier() : null,
|
|
84
|
+
]);
|
|
50
85
|
|
|
51
|
-
|
|
52
|
-
epoch: string;
|
|
53
|
-
referenceGasPrice: string;
|
|
54
|
-
}
|
|
86
|
+
await resolveObjectReferences(transactionData, client);
|
|
55
87
|
|
|
56
|
-
|
|
57
|
-
|
|
88
|
+
if (!options.onlyTransactionKind) {
|
|
89
|
+
const systemState = systemStateResult?.systemState ?? null;
|
|
58
90
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
transactionData.gasData.price = systemState.referenceGasPrice;
|
|
63
|
-
}
|
|
91
|
+
if (systemState && !transactionData.gasData.price) {
|
|
92
|
+
transactionData.gasData.price = systemState.referenceGasPrice;
|
|
93
|
+
}
|
|
64
94
|
|
|
65
|
-
|
|
66
|
-
|
|
95
|
+
await setGasBudget(transactionData, client);
|
|
96
|
+
|
|
97
|
+
if (needsPayment) {
|
|
98
|
+
if (!balanceResult || !coinsResult) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
'Could not resolve gas payment: a gas owner or sender must be set to fetch balance and coins.',
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
setGasPayment({
|
|
104
|
+
transactionData,
|
|
105
|
+
balance: balanceResult,
|
|
106
|
+
coins: coinsResult,
|
|
107
|
+
usesGasCoin,
|
|
108
|
+
withdrawals,
|
|
109
|
+
protocolConfig: protocolConfigResult?.protocolConfig,
|
|
110
|
+
gasPayer: gasPayer!,
|
|
111
|
+
chainIdentifier: chainIdResult?.chainIdentifier ?? null,
|
|
112
|
+
epoch: systemState?.epoch ?? null,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
67
115
|
|
|
68
|
-
|
|
69
|
-
|
|
116
|
+
if (!transactionData.expiration && transactionData.gasData.payment?.length === 0) {
|
|
117
|
+
await setExpiration(
|
|
118
|
+
transactionData,
|
|
119
|
+
client,
|
|
120
|
+
systemState,
|
|
121
|
+
chainIdResult?.chainIdentifier ?? null,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
70
124
|
}
|
|
125
|
+
|
|
126
|
+
return await next();
|
|
71
127
|
}
|
|
72
128
|
|
|
73
129
|
async function setGasBudget(transactionData: TransactionDataBuilder, client: ClientWithCoreApi) {
|
|
@@ -109,100 +165,89 @@ async function setGasBudget(transactionData: TransactionDataBuilder, client: Cli
|
|
|
109
165
|
);
|
|
110
166
|
}
|
|
111
167
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
168
|
+
function setGasPayment({
|
|
169
|
+
transactionData,
|
|
170
|
+
balance,
|
|
171
|
+
coins,
|
|
172
|
+
usesGasCoin,
|
|
173
|
+
withdrawals,
|
|
174
|
+
protocolConfig,
|
|
175
|
+
gasPayer,
|
|
176
|
+
chainIdentifier,
|
|
177
|
+
epoch,
|
|
178
|
+
}: {
|
|
179
|
+
transactionData: TransactionDataBuilder;
|
|
180
|
+
balance: SuiClientTypes.GetBalanceResponse;
|
|
181
|
+
coins: SuiClientTypes.ListCoinsResponse;
|
|
182
|
+
usesGasCoin: boolean;
|
|
183
|
+
withdrawals: bigint;
|
|
184
|
+
protocolConfig: SuiClientTypes.ProtocolConfig | undefined;
|
|
185
|
+
gasPayer: string;
|
|
186
|
+
chainIdentifier: string | null;
|
|
187
|
+
epoch: string | null;
|
|
188
|
+
}) {
|
|
189
|
+
const budget = BigInt(transactionData.gasData.budget!);
|
|
190
|
+
const addressBalance = BigInt(balance.balance.addressBalance);
|
|
191
|
+
|
|
192
|
+
if (budget === 0n || (!usesGasCoin && addressBalance >= budget + withdrawals)) {
|
|
193
|
+
transactionData.gasData.payment = [];
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
119
196
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
transactionData.mapArguments((arg) => {
|
|
125
|
-
if (arg.$kind === 'GasCoin') {
|
|
126
|
-
usesGasCoin = true;
|
|
127
|
-
} else if (arg.$kind === 'Input') {
|
|
128
|
-
const input = transactionData.inputs[arg.Input];
|
|
129
|
-
|
|
130
|
-
if (input.$kind === 'FundsWithdrawal') {
|
|
131
|
-
const withdrawalOwner = input.FundsWithdrawal.withdrawFrom.Sender
|
|
132
|
-
? transactionData.sender
|
|
133
|
-
: gasPayer;
|
|
134
|
-
|
|
135
|
-
if (withdrawalOwner && normalizeSuiAddress(withdrawalOwner) === normalizedGasPayer) {
|
|
136
|
-
if (input.FundsWithdrawal.reservation.$kind === 'MaxAmountU64') {
|
|
137
|
-
withdrawals += BigInt(input.FundsWithdrawal.reservation.MaxAmountU64);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
197
|
+
const filteredCoins = coins.objects.filter((coin) => {
|
|
198
|
+
const matchingInput = transactionData.inputs.find((input) => {
|
|
199
|
+
if (input.Object?.ImmOrOwnedObject) {
|
|
200
|
+
return coin.objectId === input.Object.ImmOrOwnedObject.objectId;
|
|
141
201
|
}
|
|
142
202
|
|
|
143
|
-
return
|
|
203
|
+
return false;
|
|
144
204
|
});
|
|
145
205
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
client.core.listCoins({
|
|
149
|
-
owner: gasPayer,
|
|
150
|
-
coinType: SUI_TYPE_ARG,
|
|
151
|
-
}),
|
|
152
|
-
]);
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
suiBalance?.balance.addressBalance &&
|
|
156
|
-
BigInt(suiBalance.balance.addressBalance) >=
|
|
157
|
-
BigInt(transactionData.gasData.budget || '0') + withdrawals
|
|
158
|
-
) {
|
|
159
|
-
transactionData.gasData.payment = [];
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const paymentCoins = coins.objects
|
|
164
|
-
// Filter out coins that are also used as input:
|
|
165
|
-
.filter((coin) => {
|
|
166
|
-
const matchingInput = transactionData.inputs.find((input) => {
|
|
167
|
-
if (input.Object?.ImmOrOwnedObject) {
|
|
168
|
-
return coin.objectId === input.Object.ImmOrOwnedObject.objectId;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return false;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return !matchingInput;
|
|
175
|
-
})
|
|
176
|
-
.map((coin) =>
|
|
177
|
-
parse(ObjectRefSchema, {
|
|
178
|
-
objectId: coin.objectId,
|
|
179
|
-
digest: coin.digest,
|
|
180
|
-
version: coin.version,
|
|
181
|
-
}),
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
if (!paymentCoins.length) {
|
|
185
|
-
throw new Error('No valid gas coins found for the transaction.');
|
|
186
|
-
}
|
|
206
|
+
return !matchingInput;
|
|
207
|
+
});
|
|
187
208
|
|
|
209
|
+
const paymentCoins = filteredCoins.map((coin) => ({
|
|
210
|
+
objectId: coin.objectId,
|
|
211
|
+
digest: coin.digest,
|
|
212
|
+
version: coin.version,
|
|
213
|
+
}));
|
|
214
|
+
|
|
215
|
+
const reservationAmount = addressBalance - withdrawals;
|
|
216
|
+
|
|
217
|
+
if (
|
|
218
|
+
usesGasCoin &&
|
|
219
|
+
reservationAmount > 0n &&
|
|
220
|
+
protocolConfig?.featureFlags?.['enable_coin_reservation_obj_refs'] &&
|
|
221
|
+
chainIdentifier &&
|
|
222
|
+
epoch
|
|
223
|
+
) {
|
|
224
|
+
transactionData.gasData.payment = [
|
|
225
|
+
createCoinReservationRef(reservationAmount, gasPayer, chainIdentifier, epoch),
|
|
226
|
+
...paymentCoins,
|
|
227
|
+
];
|
|
228
|
+
} else if (!filteredCoins.length) {
|
|
229
|
+
throw new Error('No valid gas coins found for the transaction.');
|
|
230
|
+
} else {
|
|
188
231
|
transactionData.gasData.payment = paymentCoins;
|
|
189
232
|
}
|
|
190
233
|
}
|
|
191
234
|
|
|
235
|
+
interface SystemStateData {
|
|
236
|
+
epoch: string;
|
|
237
|
+
referenceGasPrice: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
192
240
|
async function setExpiration(
|
|
193
241
|
transactionData: TransactionDataBuilder,
|
|
194
242
|
client: ClientWithCoreApi,
|
|
195
|
-
|
|
243
|
+
systemState: SystemStateData | null,
|
|
244
|
+
existingChainIdentifier: string | null = null,
|
|
196
245
|
) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const [systemState, { chainIdentifier }] = await Promise.all([
|
|
202
|
-
existingSystemState ?? client.core.getCurrentSystemState().then((r) => r.systemState),
|
|
203
|
-
client.core.getChainIdentifier(),
|
|
246
|
+
const [chainIdentifier, resolvedSystemState] = await Promise.all([
|
|
247
|
+
existingChainIdentifier ?? client.core.getChainIdentifier().then((r) => r.chainIdentifier),
|
|
248
|
+
systemState ?? client.core.getCurrentSystemState().then((r) => r.systemState),
|
|
204
249
|
]);
|
|
205
|
-
const currentEpoch = BigInt(
|
|
250
|
+
const currentEpoch = BigInt(resolvedSystemState.epoch);
|
|
206
251
|
|
|
207
252
|
transactionData.expiration = {
|
|
208
253
|
$kind: 'ValidDuring',
|
|
@@ -217,17 +262,6 @@ async function setExpiration(
|
|
|
217
262
|
};
|
|
218
263
|
}
|
|
219
264
|
|
|
220
|
-
function hasVersionedInputs(transactionData: TransactionDataBuilder): boolean {
|
|
221
|
-
if (transactionData.gasData.payment?.length) {
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return transactionData.inputs.some(
|
|
226
|
-
(input) =>
|
|
227
|
-
input.Object?.ImmOrOwnedObject || (input.UnresolvedObject && input.UnresolvedObject.version),
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
265
|
async function resolveObjectReferences(
|
|
232
266
|
transactionData: TransactionDataBuilder,
|
|
233
267
|
client: ClientWithCoreApi,
|
package/src/jsonRpc/client.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { fromBase58, toBase64, toHex } from '@mysten/bcs';
|
|
|
5
5
|
import type { Signer } from '../cryptography/index.js';
|
|
6
6
|
import { BaseClient } from '../client/client.js';
|
|
7
7
|
import type { SuiClientTypes } from '../client/types.js';
|
|
8
|
+
import { isCoinReservationDigest } from '../utils/coin-reservation.js';
|
|
8
9
|
import type { Transaction } from '../transactions/Transaction.js';
|
|
9
10
|
import { isTransaction } from '../transactions/Transaction.js';
|
|
10
11
|
import {
|
|
@@ -128,25 +129,6 @@ type NetworkOrTransport =
|
|
|
128
129
|
|
|
129
130
|
const SUI_CLIENT_BRAND = Symbol.for('@mysten/SuiJsonRpcClient') as never;
|
|
130
131
|
|
|
131
|
-
// Magic number used to identify fake address balance coins (last 20 bytes of the digest)
|
|
132
|
-
// See: sui/crates/sui-types/src/coin_reservation.rs
|
|
133
|
-
const COIN_RESERVATION_MAGIC = new Uint8Array([
|
|
134
|
-
0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac, 0xac,
|
|
135
|
-
0xac, 0xac, 0xac, 0xac,
|
|
136
|
-
]);
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Checks if a digest indicates a fake address balance coin.
|
|
140
|
-
* These "coins" are created by the JSON RPC to represent address balances
|
|
141
|
-
* and should be filtered out from coin listings.
|
|
142
|
-
*/
|
|
143
|
-
function isCoinReservationDigest(digestBase58: string): boolean {
|
|
144
|
-
const digestBytes = fromBase58(digestBase58);
|
|
145
|
-
// Check if the last 20 bytes match the magic number
|
|
146
|
-
const last20Bytes = digestBytes.slice(12, 32);
|
|
147
|
-
return last20Bytes.every((byte, i) => byte === COIN_RESERVATION_MAGIC[i]);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
132
|
export function isSuiJsonRpcClient(client: unknown): client is SuiJsonRpcClient {
|
|
151
133
|
return (
|
|
152
134
|
typeof client === 'object' && client !== null && (client as any)[SUI_CLIENT_BRAND] === true
|
|
@@ -31,7 +31,12 @@ import { createPure } from './pure.js';
|
|
|
31
31
|
import { TransactionDataBuilder } from './TransactionData.js';
|
|
32
32
|
import { getIdFromCallArg } from './utils.js';
|
|
33
33
|
import { namedPackagesPlugin } from './plugins/NamedPackagesPlugin.js';
|
|
34
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
COIN_WITH_BALANCE,
|
|
36
|
+
resolveCoinBalance,
|
|
37
|
+
coinWithBalance,
|
|
38
|
+
createBalance,
|
|
39
|
+
} from './intents/CoinWithBalance.js';
|
|
35
40
|
import type { ClientWithCoreApi } from '../client/core.js';
|
|
36
41
|
|
|
37
42
|
export type TransactionObjectArgument =
|
|
@@ -307,6 +312,38 @@ export class Transaction {
|
|
|
307
312
|
return { $kind: 'GasCoin' as const, GasCoin: true as const };
|
|
308
313
|
}
|
|
309
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Creates a coin of the specified type and balance.
|
|
317
|
+
* Sourced from address balance when available, falling back to owned coins.
|
|
318
|
+
*/
|
|
319
|
+
coin({
|
|
320
|
+
type,
|
|
321
|
+
balance,
|
|
322
|
+
useGasCoin,
|
|
323
|
+
}: {
|
|
324
|
+
balance: bigint | number;
|
|
325
|
+
type?: string;
|
|
326
|
+
useGasCoin?: boolean;
|
|
327
|
+
}): TransactionResult {
|
|
328
|
+
return this.add(coinWithBalance({ type, balance, useGasCoin }));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Creates a Balance object of the specified type and balance.
|
|
333
|
+
* Sourced from address balance when available, falling back to owned coins.
|
|
334
|
+
*/
|
|
335
|
+
balance({
|
|
336
|
+
type,
|
|
337
|
+
balance,
|
|
338
|
+
useGasCoin,
|
|
339
|
+
}: {
|
|
340
|
+
balance: bigint | number;
|
|
341
|
+
type?: string;
|
|
342
|
+
useGasCoin?: boolean;
|
|
343
|
+
}): TransactionResult {
|
|
344
|
+
return this.add(createBalance({ type, balance, useGasCoin }));
|
|
345
|
+
}
|
|
346
|
+
|
|
310
347
|
/**
|
|
311
348
|
* Add a new object input to the transaction.
|
|
312
349
|
*/
|