@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.
- package/CHANGELOG.md +27 -0
- package/dist/client/core-resolver.d.mts.map +1 -1
- package/dist/client/core-resolver.mjs +2 -5
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/cryptography/signature.d.mts +14 -14
- package/dist/grpc/client.d.mts +1 -1
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +3 -5
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +10 -10
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/index.d.mts +4 -3
- package/dist/grpc/index.mjs +4 -2
- package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
- package/dist/grpc/transport.d.mts +18 -0
- package/dist/grpc/transport.d.mts.map +1 -0
- package/dist/grpc/transport.mjs +97 -0
- package/dist/grpc/transport.mjs.map +1 -0
- package/dist/transactions/Transaction.d.mts +7 -10
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/data/internal.d.mts +127 -127
- package/dist/transactions/data/v1.d.mts +239 -239
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/transactions/data/v2.d.mts.map +1 -1
- package/dist/transactions/intents/CoinWithBalance.mjs +4 -2
- package/dist/transactions/intents/CoinWithBalance.mjs.map +1 -1
- package/dist/transactions/resolution-utils.mjs +13 -0
- package/dist/transactions/resolution-utils.mjs.map +1 -0
- package/dist/transactions/resolve.d.mts +8 -0
- package/dist/transactions/resolve.d.mts.map +1 -1
- package/dist/transactions/resolve.mjs +6 -2
- package/dist/transactions/resolve.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/docs/clients/grpc.md +31 -7
- package/docs/migrations/sui-2.0/json-rpc-migration.md +50 -1
- package/docs/transactions/basics.md +19 -14
- package/docs/transactions/offline.md +137 -88
- package/package.json +2 -2
- package/src/client/core-resolver.ts +2 -7
- package/src/grpc/client.ts +12 -4
- package/src/grpc/core.ts +18 -14
- package/src/grpc/index.ts +7 -3
- package/src/grpc/transport.ts +160 -0
- package/src/transactions/Transaction.ts +1 -4
- package/src/transactions/intents/CoinWithBalance.ts +32 -25
- package/src/transactions/resolution-utils.ts +18 -0
- package/src/transactions/resolve.ts +29 -2
- 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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
|
50
|
+
if (!data.gasData.price || !data.gasData.budget) {
|
|
42
51
|
return true;
|
|
43
52
|
}
|
|
44
53
|
|
|
45
|
-
if (data.gasData.payment
|
|
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