@mysten/sui 2.28.0 → 2.30.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/client/core-resolver.d.mts.map +1 -1
  3. package/dist/client/core-resolver.mjs +2 -5
  4. package/dist/client/core-resolver.mjs.map +1 -1
  5. package/dist/cryptography/signature.d.mts +14 -14
  6. package/dist/grpc/client.d.mts +1 -1
  7. package/dist/grpc/client.d.mts.map +1 -1
  8. package/dist/grpc/client.mjs +3 -5
  9. package/dist/grpc/client.mjs.map +1 -1
  10. package/dist/grpc/core.d.mts.map +1 -1
  11. package/dist/grpc/core.mjs +10 -10
  12. package/dist/grpc/core.mjs.map +1 -1
  13. package/dist/grpc/index.d.mts +4 -3
  14. package/dist/grpc/index.mjs +4 -2
  15. package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
  16. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  17. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  18. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  19. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  20. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  21. package/dist/grpc/transport.d.mts +18 -0
  22. package/dist/grpc/transport.d.mts.map +1 -0
  23. package/dist/grpc/transport.mjs +97 -0
  24. package/dist/grpc/transport.mjs.map +1 -0
  25. package/dist/transactions/Transaction.d.mts +7 -10
  26. package/dist/transactions/Transaction.d.mts.map +1 -1
  27. package/dist/transactions/Transaction.mjs.map +1 -1
  28. package/dist/transactions/data/internal.d.mts +127 -127
  29. package/dist/transactions/data/v1.d.mts +239 -239
  30. package/dist/transactions/data/v1.d.mts.map +1 -1
  31. package/dist/transactions/data/v2.d.mts +16 -16
  32. package/dist/transactions/data/v2.d.mts.map +1 -1
  33. package/dist/transactions/intents/CoinWithBalance.mjs +4 -2
  34. package/dist/transactions/intents/CoinWithBalance.mjs.map +1 -1
  35. package/dist/transactions/resolution-utils.mjs +13 -0
  36. package/dist/transactions/resolution-utils.mjs.map +1 -0
  37. package/dist/transactions/resolve.d.mts +8 -0
  38. package/dist/transactions/resolve.d.mts.map +1 -1
  39. package/dist/transactions/resolve.mjs +6 -2
  40. package/dist/transactions/resolve.mjs.map +1 -1
  41. package/dist/version.mjs +1 -1
  42. package/dist/version.mjs.map +1 -1
  43. package/dist/zklogin/bcs.d.mts +14 -14
  44. package/docs/clients/grpc.md +31 -7
  45. package/docs/migrations/sui-2.0/json-rpc-migration.md +50 -1
  46. package/docs/transactions/basics.md +19 -14
  47. package/docs/transactions/offline.md +137 -88
  48. package/package.json +2 -2
  49. package/src/client/core-resolver.ts +2 -7
  50. package/src/grpc/client.ts +12 -4
  51. package/src/grpc/core.ts +18 -14
  52. package/src/grpc/index.ts +7 -3
  53. package/src/grpc/transport.ts +160 -0
  54. package/src/transactions/Transaction.ts +1 -4
  55. package/src/transactions/intents/CoinWithBalance.ts +32 -25
  56. package/src/transactions/resolution-utils.ts +18 -0
  57. package/src/transactions/resolve.ts +29 -2
  58. package/src/version.ts +1 -1
@@ -178,37 +178,44 @@ export async function resolveCoinBalance(
178
178
  const coinsByType = new Map<string, SuiClientTypes.Coin[]>();
179
179
  const addressBalanceByType = new Map<string, bigint>();
180
180
  const client = buildOptions.client;
181
+ const assumeSufficientAddressBalances = buildOptions.assumeSufficientAddressBalances;
181
182
 
182
- if (!client) {
183
+ if (!client && !assumeSufficientAddressBalances) {
183
184
  throw new Error(
184
185
  'Client must be provided to build or serialize transactions with CoinWithBalance intents',
185
186
  );
186
187
  }
187
188
 
188
- await Promise.all([
189
- ...[...coinTypes].map(async (coinType) => {
190
- const { coins, addressBalance } = await getCoinsAndBalanceOfType({
191
- coinType,
192
- balance: totalByType.get(coinType)!,
193
- client,
194
- owner: transactionData.sender!,
195
- usedIds,
196
- });
197
-
198
- coinsByType.set(coinType, coins);
199
- addressBalanceByType.set(coinType, addressBalance);
200
- }),
201
- totalByType.has('gas')
202
- ? await client.core
203
- .getBalance({
204
- owner: transactionData.sender!,
205
- coinType: SUI_TYPE,
206
- })
207
- .then(({ balance }) => {
208
- addressBalanceByType.set('gas', BigInt(balance.addressBalance));
209
- })
210
- : null,
211
- ]);
189
+ if (assumeSufficientAddressBalances) {
190
+ for (const [coinType, balance] of totalByType) {
191
+ addressBalanceByType.set(coinType, balance);
192
+ }
193
+ } else {
194
+ await Promise.all([
195
+ ...[...coinTypes].map(async (coinType) => {
196
+ const { coins, addressBalance } = await getCoinsAndBalanceOfType({
197
+ coinType,
198
+ balance: totalByType.get(coinType)!,
199
+ client: client!,
200
+ owner: transactionData.sender!,
201
+ usedIds,
202
+ });
203
+
204
+ coinsByType.set(coinType, coins);
205
+ addressBalanceByType.set(coinType, addressBalance);
206
+ }),
207
+ totalByType.has('gas')
208
+ ? await client!.core
209
+ .getBalance({
210
+ owner: transactionData.sender!,
211
+ coinType: SUI_TYPE,
212
+ })
213
+ .then(({ balance }) => {
214
+ addressBalanceByType.set('gas', BigInt(balance.addressBalance));
215
+ })
216
+ : null,
217
+ ]);
218
+ }
212
219
 
213
220
  const exactBalanceByType = new Map<string, boolean>();
214
221
  const usedAddressBalance = new Set<string>();
@@ -0,0 +1,18 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { TransactionDataBuilder } from './TransactionData.js';
5
+
6
+ export function transactionUsesGasCoin(transactionData: TransactionDataBuilder) {
7
+ let usesGasCoin = false;
8
+
9
+ transactionData.mapArguments((arg) => {
10
+ if (arg.$kind === 'GasCoin') {
11
+ usesGasCoin = true;
12
+ }
13
+
14
+ return arg;
15
+ });
16
+
17
+ return usesGasCoin;
18
+ }
@@ -9,10 +9,19 @@ import type { BcsType } from '@mysten/bcs';
9
9
  import { Inputs } from './Inputs.js';
10
10
  import { bcs } from '../bcs/index.js';
11
11
  import { coreClientResolveTransactionPlugin } from '../client/core-resolver.js';
12
+ import { transactionUsesGasCoin } from './resolution-utils.js';
12
13
 
13
14
  export interface BuildTransactionOptions {
14
15
  client?: ClientWithCoreApi;
15
16
  onlyTransactionKind?: boolean;
17
+ /**
18
+ * Resolve `CoinWithBalance` intents from address balance without looking up balances or coins.
19
+ *
20
+ * If nothing else needs resolution, the transaction doesn't use `GasCoin`, and it already has a
21
+ * `ValidDuring` or `Validity` expiration, an unset gas payment is also set to `[]` (pay gas from
22
+ * address balance). Execution fails if the balances aren't there.
23
+ */
24
+ assumeSufficientAddressBalances?: boolean;
16
25
  }
17
26
 
18
27
  export interface SerializeTransactionOptions extends BuildTransactionOptions {
@@ -38,11 +47,23 @@ export function needsTransactionResolution(
38
47
  }
39
48
 
40
49
  if (!options.onlyTransactionKind) {
41
- if (!data.gasData.price || !data.gasData.budget || !data.gasData.payment) {
50
+ if (!data.gasData.price || !data.gasData.budget) {
42
51
  return true;
43
52
  }
44
53
 
45
- if (data.gasData.payment.length === 0 && !data.expiration) {
54
+ if (!data.gasData.payment) {
55
+ const assumesAddressBalanceGas =
56
+ options.assumeSufficientAddressBalances && !transactionUsesGasCoin(data);
57
+
58
+ // Address balance gas has no object version to protect against replay, so an offline build
59
+ // needs a ValidDuring expiration. Epoch expiration doesn't count.
60
+ if (
61
+ !assumesAddressBalanceGas ||
62
+ (data.expiration?.$kind !== 'ValidDuring' && data.expiration?.$kind !== 'Validity')
63
+ ) {
64
+ return true;
65
+ }
66
+ } else if (data.gasData.payment.length === 0 && !data.expiration) {
46
67
  return true;
47
68
  }
48
69
  }
@@ -56,7 +77,13 @@ export async function resolveTransactionPlugin(
56
77
  next: () => Promise<void>,
57
78
  ) {
58
79
  normalizeRawArguments(transactionData);
80
+
59
81
  if (!needsTransactionResolution(transactionData, options)) {
82
+ // Payment can only be unset here when assumeSufficientAddressBalances applies
83
+ if (!options.onlyTransactionKind && !transactionData.gasData.payment) {
84
+ transactionData.gasData.payment = [];
85
+ }
86
+
60
87
  await validate(transactionData);
61
88
  return next();
62
89
  }
package/src/version.ts CHANGED
@@ -3,4 +3,4 @@
3
3
 
4
4
  // This file is generated by genversion.mjs. Do not edit it directly.
5
5
 
6
- export const PACKAGE_VERSION = '2.28.0';
6
+ export const PACKAGE_VERSION = '2.30.0';