@needmoretruth/nmts-cli 0.50.1 → 0.52.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 (56) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.ko.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/api.js +3 -0
  5. package/dist/artifact-about.d.ts +1 -1
  6. package/dist/client-id.d.ts +11 -0
  7. package/dist/client-id.js +30 -0
  8. package/dist/commands/mcp.js +3 -0
  9. package/dist/commands/wallet-activity.d.ts +10 -6
  10. package/dist/commands/wallet-activity.js +17 -6
  11. package/dist/env-vars.d.ts +1 -1
  12. package/dist/env-vars.js +1 -1
  13. package/dist/extend-chain.d.ts +4 -6
  14. package/dist/extend-chain.js +25 -26
  15. package/dist/net-retry.js +14 -0
  16. package/dist/portable.d.ts +2 -0
  17. package/dist/portable.js +2 -0
  18. package/dist/product.d.ts +1 -1
  19. package/dist/product.js +1 -1
  20. package/dist/reach.d.ts +1 -1
  21. package/dist/shared/lib/storage-control/chain.d.ts +30 -29
  22. package/dist/shared/lib/storage-control/chain.js +14 -20
  23. package/dist/shared/lib/wallet/activity.d.ts +42 -48
  24. package/dist/shared/lib/wallet/activity.js +51 -30
  25. package/dist/shared/lib/wallet/address-history.d.ts +42 -0
  26. package/dist/shared/lib/wallet/address-history.js +247 -0
  27. package/dist/shared/lib/wallet/chain-calls.d.ts +44 -0
  28. package/dist/shared/lib/wallet/chain-calls.js +59 -0
  29. package/dist/storage-control-chain.js +5 -4
  30. package/dist/sui-execute.d.ts +54 -0
  31. package/dist/sui-execute.js +43 -0
  32. package/dist/sui-rpc.d.ts +16 -9
  33. package/dist/sui-rpc.js +53 -19
  34. package/dist/upload-wallet-chain.d.ts +3 -3
  35. package/dist/upload-wallet-chain.js +14 -22
  36. package/dist/wallet-activity-chain.d.ts +2 -2
  37. package/dist/wallet-activity-chain.js +12 -27
  38. package/dist/wallet-chain.js +19 -13
  39. package/dist/wallet-list-chain.d.ts +1 -1
  40. package/dist/wallet-list-chain.js +13 -14
  41. package/dist/wallet-send-chain.js +4 -3
  42. package/dist/wallet-sign-external.d.ts +18 -25
  43. package/dist/wallet-sign-external.js +13 -18
  44. package/dist/wallet-sign.js +19 -69
  45. package/dist/wallet-storage-chain.js +2 -3
  46. package/dist/wallet-swap-chain.d.ts +3 -6
  47. package/dist/wallet-swap-chain.js +16 -16
  48. package/dist/wallet-swap-quote.js +16 -17
  49. package/dist/walrus-write.js +6 -16
  50. package/dist/walrus.d.ts +13 -13
  51. package/dist/walrus.js +15 -15
  52. package/package.json +7 -4
  53. package/server.json +2 -2
  54. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +11 -11
  55. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  56. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +11 -11
@@ -1,4 +1,5 @@
1
1
  import type { SignExtension } from "./extend-plan.ts";
2
+ import { EXECUTE_INCLUDE, type ChainAnswer, type Executed } from "./sui-execute.ts";
2
3
  import { type KeepTryingOptions } from "./net-retry.ts";
3
4
  import type { SignBlobCertify, SignBlobRegister, SignStorageOp } from "./wallet-sign-seams.ts";
4
5
  /** What a wallet answers once it has signed: the bytes it signed, and the signature over them. */
@@ -25,38 +26,30 @@ export interface ExternalPayer {
25
26
  chain: string;
26
27
  }): Promise<SignedTransaction>;
27
28
  }
28
- /** What the chain says about one submitted transaction. */
29
- export interface SubmittedTransaction {
30
- digest: string;
31
- effects?: unknown;
32
- objectChanges?: unknown;
33
- }
29
+ /** What the chain says about one submitted transaction (`sui-execute.ts` reads it). */
30
+ export type SubmittedTransaction = Executed;
34
31
  /**
35
- * Just the three calls a submitted transaction needs.
32
+ * Just the three calls a submitted transaction needs, in the SDK's core API.
36
33
  *
37
34
  * ⚠ NARROW ON PURPOSE: a test hands in a client that answers from a table, and every real client
38
35
  * fits it. Asking the node the plain question is also why the wallet is only ever asked to SIGN —
39
36
  * a wallet's own "sign and execute" would answer a digest and leave the judging to nobody.
40
37
  */
41
38
  export interface SubmitClient {
42
- executeTransactionBlock(input: {
43
- transactionBlock: Uint8Array;
44
- signature: string | string[];
45
- options: {
46
- showEffects: true;
47
- showObjectChanges: true;
48
- };
49
- }): Promise<SubmittedTransaction>;
50
- getTransactionBlock(input: {
51
- digest: string;
52
- options: {
53
- showEffects: true;
54
- showObjectChanges: true;
55
- };
56
- }): Promise<SubmittedTransaction>;
57
- waitForTransaction(input: {
58
- digest: string;
59
- }): Promise<unknown>;
39
+ core: {
40
+ executeTransaction(input: {
41
+ transaction: Uint8Array;
42
+ signatures: string[];
43
+ include: typeof EXECUTE_INCLUDE;
44
+ }): Promise<ChainAnswer>;
45
+ getTransaction(input: {
46
+ digest: string;
47
+ include: typeof EXECUTE_INCLUDE;
48
+ }): Promise<ChainAnswer>;
49
+ waitForTransaction(input: {
50
+ digest: string;
51
+ }): Promise<unknown>;
52
+ };
60
53
  }
61
54
  /** What a caller is told when one of these transactions does not go through. */
62
55
  export interface ExternalRefusals {
@@ -37,21 +37,13 @@ import { fromBase64 } from "@mysten/sui/utils";
37
37
  import { NmtsError } from "./errors.js";
38
38
  import { walrusClient } from "./extend-chain.js";
39
39
  import { freshWalrus } from "./walrus-fresh.js";
40
- import { isRecord } from "./guards.js";
40
+ import { EXECUTE_INCLUDE, readAnswer } from "./sui-execute.js";
41
41
  import { isTransient, keepTrying } from "./net-retry.js";
42
42
  import { storageOpTransaction } from "./storage-control-chain.js";
43
43
  import { certifyTransaction, createdBlob, payingClient, registerTransaction } from "./upload-wallet-chain.js";
44
44
  function why(error) {
45
45
  return error instanceof Error ? error.message : String(error);
46
46
  }
47
- /** What a refused execution said, or null when the effects say it went through. */
48
- function refusedBecause(result) {
49
- const status = isRecord(result.effects) ? result.effects["status"] : undefined;
50
- if (!isRecord(status) || status["status"] !== "failure")
51
- return null;
52
- const reason = status["error"];
53
- return typeof reason === "string" ? reason : "no reason was given";
54
- }
55
47
  /** `sui:mainnet` or `sui:testnet` — what a wallet is told the transaction is for. */
56
48
  function chainOf(network) {
57
49
  return `sui:${network === "mainnet" ? "mainnet" : "testnet"}`;
@@ -77,28 +69,31 @@ export async function signAndSubmit(client, payer, input) {
77
69
  }
78
70
  const signed = typeof answered.bytes === "string" ? fromBase64(answered.bytes) : answered.bytes;
79
71
  const digest = TransactionDataBuilder.getDigestFromBytes(signed);
80
- const options = { showEffects: true, showObjectChanges: true };
81
72
  let sent = false;
82
- const result = await keepTrying(async () => {
73
+ const answer = await keepTrying(async () => {
83
74
  if (sent) {
84
75
  // The attempt before this one may have reached the chain and lost only its reply. An
85
76
  // unknown digest and a node that did not answer look the same here, and both mean "send
86
77
  // the same bytes again" — which is safe precisely because they are the same bytes.
87
- const seen = await client.getTransactionBlock({ digest, options }).catch(() => null);
78
+ const seen = await client.core.getTransaction({ digest, include: EXECUTE_INCLUDE }).catch(() => null);
88
79
  if (seen !== null)
89
80
  return seen;
90
81
  }
91
82
  sent = true;
92
- return client.executeTransactionBlock({ transactionBlock: signed, signature: answered.signature, options });
83
+ return client.core.executeTransaction({
84
+ transaction: signed,
85
+ signatures: [answered.signature],
86
+ include: EXECUTE_INCLUDE,
87
+ });
93
88
  }, { ...input.retry, retryable: isTransient });
89
+ const result = readAnswer(answer);
94
90
  // ⛔ SUCCESS IS ALREADY DECIDED BY THE EFFECTS BELOW. This wait is for what happens NEXT — the
95
91
  // relay being told the digest, the blob object being read back — because a node that has not
96
92
  // indexed the transaction yet answers those as if nothing had happened. A wait that times out
97
93
  // changes nothing about what was signed, so it is not a failure of this transaction.
98
- await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
99
- const refused = refusedBecause(result);
100
- if (refused !== null) {
101
- throw new NmtsError(`${input.refusals.refused.what}: ${refused}.`, {
94
+ await client.core.waitForTransaction({ digest: result.digest }).catch(() => undefined);
95
+ if (result.refused !== null) {
96
+ throw new NmtsError(`${input.refusals.refused.what}: ${result.refused}.`, {
102
97
  exitCode: 1,
103
98
  nextStep: input.refusals.refused.nextStep,
104
99
  });
@@ -133,7 +128,7 @@ export function externalBlobSigners(payer) {
133
128
  },
134
129
  });
135
130
  // The blob object is found by its type in what the transaction created, not by position.
136
- return { digest: result.digest, ...(await createdBlob(client, result.objectChanges)) };
131
+ return { digest: result.digest, ...(await createdBlob(client, result.created)) };
137
132
  },
138
133
  certify: async ({ network, relayUrl, blobId, blobObjectId, certificate }) => {
139
134
  const client = payingClient(network, relayUrl);
@@ -39,7 +39,7 @@ import { freshWalrus } from "./walrus-fresh.js";
39
39
  import { transferTransaction } from "./wallet-send-chain.js";
40
40
  import { storageOpTransaction } from "./storage-control-chain.js";
41
41
  import { swapTransaction } from "./wallet-swap-chain.js";
42
- import { isRecord } from "./guards.js";
42
+ import { signAndRun } from "./sui-execute.js";
43
43
  import { certifyTransaction, createdBlob, payingClient, registerTransaction, } from "./upload-wallet-chain.js";
44
44
  import { BUILT_IN_WALLET_INDEX } from "./wallet.js";
45
45
  /**
@@ -125,32 +125,19 @@ export const signExtension = async ({ network, code, wallet, objectIds, epochs }
125
125
  for (const blobObjectId of unique) {
126
126
  tx.add(fresh.extendBlob({ blobObjectId, epochs }));
127
127
  }
128
- const result = await client.signAndExecuteTransaction({
129
- transaction: tx,
130
- signer: keypair,
131
- options: { showEffects: true },
132
- });
128
+ const result = await signAndRun(client, tx, keypair);
133
129
  // ⛔ A DIGEST IS NOT A SUCCESS. A transaction that was executed and FAILED still has one, and the
134
130
  // gas for it is still gone; recording it as an extension would move the drive's expiry date
135
- // over storage nobody bought. The status is asked for above and read here.
136
- const effects = result.effects;
137
- const status = isRecord(effects) ? effects["status"] : undefined;
138
- const outcome = isRecord(status) ? status["status"] : undefined;
139
- if (outcome === "failure") {
140
- const why = isRecord(status) ? status["error"] : undefined;
141
- throw new NmtsError(`The storage network refused the extension: ${typeof why === "string" ? why : "no reason was given"}.`, {
131
+ // over storage nobody bought. `signAndRun` reads the status; a refusal is said here.
132
+ if (result.refused !== null) {
133
+ throw new NmtsError(`The storage network refused the extension: ${result.refused}.`, {
142
134
  exitCode: 1,
143
135
  nextStep: `The storage was NOT extended and the file still ends when it did. The transaction fee ` +
144
136
  `was spent. The usual causes are too little WAL or SUI in this account's wallet — ` +
145
137
  `\`nmts wallet\` shows both — or a length the network will no longer sell.`,
146
138
  });
147
139
  }
148
- // ⛔ SUCCESS IS ALREADY KNOWN — the effects above said so. This wait is for what happens NEXT:
149
- // the server is told the digest, `nmts wallet` is run, the browser's activity list opens —
150
- // and a full node that has not indexed the transaction yet answers those as if nothing
151
- // happened. Waiting until it is readable is what the browser's signers do. A wait that times
152
- // out changes nothing about what was signed, so it is not an error of this extension.
153
- await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
140
+ // The wait until a node can read it back already happened inside `signAndRun`.
154
141
  return result.digest;
155
142
  };
156
143
  /**
@@ -166,23 +153,14 @@ export const signTransfer = async ({ network, code, wallet, shape }) => {
166
153
  const client = walrusClient(network);
167
154
  const keypair = await keypairFor(code, wallet);
168
155
  const tx = transferTransaction({ ...shape, sender: keypair.toSuiAddress() });
169
- const result = await client.signAndExecuteTransaction({
170
- transaction: tx,
171
- signer: keypair,
172
- options: { showEffects: true },
173
- });
174
- const effects = result.effects;
175
- const status = isRecord(effects) ? effects["status"] : undefined;
176
- const outcome = isRecord(status) ? status["status"] : undefined;
177
- if (outcome === "failure") {
178
- const why = isRecord(status) ? status["error"] : undefined;
179
- throw new NmtsError(`The chain refused the transfer: ${typeof why === "string" ? why : "no reason was given"}.`, {
156
+ const result = await signAndRun(client, tx, keypair);
157
+ if (result.refused !== null) {
158
+ throw new NmtsError(`The chain refused the transfer: ${result.refused}.`, {
180
159
  exitCode: 1,
181
160
  nextStep: `Nothing was sent. The transaction fee was spent. The usual cause is a balance that moved ` +
182
161
  `between reading it and signing — \`nmts wallet\` shows both balances now.`,
183
162
  });
184
163
  }
185
- await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
186
164
  return result.digest;
187
165
  };
188
166
  /**
@@ -215,12 +193,8 @@ export const signSwap = async ({ network, code, wallet, shape }) => {
215
193
  const client = walrusClient(network);
216
194
  const keypair = await keypairFor(code, wallet);
217
195
  const tx = swapTransaction({ ...shape, network, sender: keypair.toSuiAddress() });
218
- const result = await client.signAndExecuteTransaction({
219
- transaction: tx,
220
- signer: keypair,
221
- options: { showEffects: true },
222
- });
223
- const refused = refusedBecause(result);
196
+ const result = await signAndRun(client, tx, keypair);
197
+ const refused = result.refused;
224
198
  if (refused !== null) {
225
199
  throw new NmtsError(`The chain refused the swap: ${refused}.`, {
226
200
  exitCode: 1,
@@ -229,18 +203,8 @@ export const signSwap = async ({ network, code, wallet, shape }) => {
229
203
  `or a balance that moved. \`nmts wallet\` shows both balances now.`,
230
204
  });
231
205
  }
232
- await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
233
206
  return result.digest;
234
207
  };
235
- /** What a refused execution said, or null when the effects say it went through. */
236
- function refusedBecause(result) {
237
- const effects = isRecord(result) ? result["effects"] : undefined;
238
- const status = isRecord(effects) ? effects["status"] : undefined;
239
- if (!isRecord(status) || status["status"] !== "failure")
240
- return null;
241
- const why = status["error"];
242
- return typeof why === "string" ? why : "no reason was given";
243
- }
244
208
  /**
245
209
  * Register ONE part's blob, signed by the account's own wallet: the relay's tip, then the storage
246
210
  * — bought for `epochs`, or a resource the wallet already holds, cut to fit first if asked.
@@ -257,12 +221,8 @@ export const signBlobRegister = async ({ network, code, wallet, relayUrl, ...sha
257
221
  const client = payingClient(network, relayUrl);
258
222
  const keypair = await keypairFor(code, wallet);
259
223
  const tx = await registerTransaction(client, network, { ...shape, sender: keypair.toSuiAddress() });
260
- const result = await client.signAndExecuteTransaction({
261
- transaction: tx,
262
- signer: keypair,
263
- options: { showEffects: true, showObjectChanges: true },
264
- });
265
- const refused = refusedBecause(result);
224
+ const result = await signAndRun(client, tx, keypair);
225
+ const refused = result.refused;
266
226
  if (refused !== null) {
267
227
  throw new NmtsError(`The storage network refused the registration: ${refused}.`, {
268
228
  exitCode: 1,
@@ -271,8 +231,7 @@ export const signBlobRegister = async ({ network, code, wallet, relayUrl, ...sha
271
231
  `resource too small for the part once encoded.`,
272
232
  });
273
233
  }
274
- await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
275
- const blob = await createdBlob(client, result.objectChanges);
234
+ const blob = await createdBlob(client, result.created);
276
235
  return { digest: result.digest, ...blob };
277
236
  };
278
237
  /** Certify ONE registered part from the relay's certificate. Gas only; nothing else leaves the wallet. */
@@ -281,12 +240,8 @@ export const signBlobCertify = async ({ network, code, wallet, relayUrl, ...shap
281
240
  const keypair = await keypairFor(code, wallet);
282
241
  const tx = certifyTransaction(client, shape);
283
242
  tx.setSender(keypair.toSuiAddress());
284
- const result = await client.signAndExecuteTransaction({
285
- transaction: tx,
286
- signer: keypair,
287
- options: { showEffects: true },
288
- });
289
- const refused = refusedBecause(result);
243
+ const result = await signAndRun(client, tx, keypair);
244
+ const refused = result.refused;
290
245
  if (refused !== null) {
291
246
  throw new NmtsError(`The storage network refused the certification: ${refused}.`, {
292
247
  exitCode: 1,
@@ -294,7 +249,6 @@ export const signBlobCertify = async ({ network, code, wallet, relayUrl, ...shap
294
249
  `its fee was spent. Running the same command again certifies again and buys nothing.`,
295
250
  });
296
251
  }
297
- await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
298
252
  return result.digest;
299
253
  };
300
254
  /**
@@ -310,16 +264,12 @@ export const signStorageOp = async ({ network, code, wallet, shape, walrusPackag
310
264
  // that can reshape or hand it over.
311
265
  const keypair = await keypairFor(code, wallet);
312
266
  const tx = storageOpTransaction(shape, { walrusPackageId, sender: keypair.toSuiAddress() });
313
- const result = await client.signAndExecuteTransaction({ transaction: tx, signer: keypair, options: { showEffects: true } });
314
- const effects = result.effects;
315
- const status = isRecord(effects) ? effects["status"] : undefined;
316
- if (isRecord(status) && status["status"] === "failure") {
317
- const why = status["error"];
318
- throw new NmtsError(`The chain refused it: ${typeof why === "string" ? why : "no reason was given"}.`, {
267
+ const result = await signAndRun(client, tx, keypair);
268
+ if (result.refused !== null) {
269
+ throw new NmtsError(`The chain refused it: ${result.refused}.`, {
319
270
  exitCode: 1,
320
271
  nextStep: "Nothing changed on the resource. The transaction fee was spent.",
321
272
  });
322
273
  }
323
- await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
324
274
  return result.digest;
325
275
  };
@@ -3,13 +3,12 @@
3
3
  // ⛔ READ ONLY, and the reader is the browser's (`shared/lib/storage-control/chain.ts`). The epoch
4
4
  // comes from the same window read `nmts extend` prices with; when that read fails the list is
5
5
  // still printed, without the "usable now" judgement, rather than not at all.
6
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
7
6
  import { MAINNET_WALRUS_PACKAGE_CONFIG, TESTNET_WALRUS_PACKAGE_CONFIG } from "@mysten/walrus";
8
7
  import { extendReads } from "./extend-chain.js";
9
8
  import { readOwnedStorage, readStorageType } from "./shared/lib/storage-control/chain.js";
10
- import { suiRpcTransport } from "./sui-rpc.js";
9
+ import { suiClient } from "./sui-rpc.js";
11
10
  export async function readWalletStorage(network, address) {
12
- const client = new SuiJsonRpcClient({ network, transport: suiRpcTransport(network) });
11
+ const client = suiClient(network);
13
12
  const walrus = network === "mainnet" ? MAINNET_WALRUS_PACKAGE_CONFIG : TESTNET_WALRUS_PACKAGE_CONFIG;
14
13
  const [type, window] = await Promise.all([
15
14
  readStorageType(client, walrus.systemObjectId),
@@ -57,14 +57,11 @@ export interface SwapReads {
57
57
  /** The fee in MIST measured by dry-running this exact swap, or null when it could not be. */
58
58
  estimateFee(shape: SwapShape, sender: string): Promise<bigint | null>;
59
59
  }
60
- /** All this path uses of an RPC: one devInspect and its `error`. Narrow on purpose — the type itself
60
+ /** All this path uses of a node: one simulation and its `error`. Narrow on purpose — the type itself
61
61
  * has no place for a chain-supplied ADDRESS to enter, and a test can hand it a fake. */
62
62
  export interface BluefinVersionRpc {
63
- devInspectTransactionBlock(input: {
64
- sender: string;
65
- transactionBlock: Transaction;
66
- }): Promise<{
67
- error?: string | null;
63
+ inspect(transaction: Transaction, sender: string): Promise<{
64
+ error: string | null;
68
65
  }>;
69
66
  }
70
67
  /** The pinned addresses, returned only once the chain confirms the pinned package still verifies.
@@ -24,6 +24,7 @@ import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
24
24
  import { TESTNET_WALRUS_PACKAGE_CONFIG } from "@mysten/walrus";
25
25
  import { walrusClient, netGasFee } from "./extend-chain.js";
26
26
  import { isRecord } from "./guards.js";
27
+ import { dryRun, inspect } from "./shared/lib/wallet/chain-calls.js";
27
28
  import { hopFor, routeHops } from "./shared/lib/wallet/swap-routes.js";
28
29
  import { directionCoins } from "./shared/lib/wallet/swap-rules.js";
29
30
  import { BLUEFIN_GLOBAL_CONFIG_IDS, BLUEFIN_MAX_SQRT_PRICE, BLUEFIN_MIN_SQRT_PRICE, BLUEFIN_PACKAGE_IDS, BLUEFIN_SUI_USDC_POOLS, BLUEFIN_WAL_SUI_POOLS, BLUEFIN_WAL_USDC_POOLS, DEEP_COIN_TYPES, DEEPBOOK_PACKAGE_IDS, } from "./shared/lib/wallet/venue-ids.js";
@@ -125,19 +126,18 @@ export function swapTransaction(input) {
125
126
  tx.setGasBudget(input.gasBudgetMist);
126
127
  return tx;
127
128
  }
128
- /** `fields.<name>` of a Move object's content, as a string, or null when the shape differs. */
129
- function fieldOf(content, name) {
130
- const fields = isRecord(content) ? content["fields"] : undefined;
131
- return isRecord(fields) ? fields[name] : undefined;
129
+ /** `<name>` of a Move object's JSON rendering (nested structs are plain objects), or undefined. */
130
+ function fieldOf(json, name) {
131
+ return isRecord(json) ? json[name] : undefined;
132
132
  }
133
- /** Does the chain still accept this package? `config::verify_version` under devInspect: no signature,
133
+ /** Does the chain still accept this package? `config::verify_version` in a simulation: no signature,
134
134
  * no gas. False when the chain refuses AND when the RPC cannot answer — both mean "no Bluefin". */
135
135
  async function versionPasses(rpc, packageId, globalConfigId) {
136
136
  try {
137
137
  const tx = new Transaction();
138
138
  tx.moveCall({ target: `${packageId}::config::verify_version`, arguments: [tx.object(globalConfigId)] });
139
- const res = await rpc.devInspectTransactionBlock({ sender: QUOTE_SENDER, transactionBlock: tx });
140
- return !res.error;
139
+ const res = await rpc.inspect(tx, QUOTE_SENDER);
140
+ return res.error === null;
141
141
  }
142
142
  catch {
143
143
  return false;
@@ -172,7 +172,7 @@ export function swapReads(network) {
172
172
  if (packageId === null || globalConfigId === null || BLUEFIN_WAL_SUI_POOLS[network] === null) {
173
173
  throw new Error(`This tool knows no Bluefin WAL/SUI pool on ${network}.`);
174
174
  }
175
- return checkedBluefinBinding({ packageId, globalConfigId, pools: bluefinPools(network) }, client);
175
+ return checkedBluefinBinding({ packageId, globalConfigId, pools: bluefinPools(network) }, { inspect: (transaction, sender) => inspect(client, transaction, sender) });
176
176
  })();
177
177
  bluefin = pending;
178
178
  pending.catch(() => {
@@ -187,12 +187,12 @@ export function swapReads(network) {
187
187
  const objectId = TESTNET_WALRUS_PACKAGE_CONFIG.exchangeIds[0];
188
188
  if (objectId === undefined)
189
189
  throw new Error("This build names no testnet exchange object.");
190
- const obj = await client.getObject({ id: objectId, options: { showContent: true, showType: true } });
191
- const type = obj.data?.type;
192
- if (typeof type !== "string" || !type.includes("::wal_exchange::Exchange")) {
193
- throw new Error(`Object ${objectId} is not a wal_exchange Exchange (type ${type ?? "unknown"}).`);
190
+ const { object } = await client.core.getObject({ objectId, include: { json: true } });
191
+ const type = object.type;
192
+ if (!type.includes("::wal_exchange::Exchange")) {
193
+ throw new Error(`Object ${objectId} is not a wal_exchange Exchange (type ${type}).`);
194
194
  }
195
- const rate = fieldOf(obj.data?.content, "rate");
195
+ const rate = fieldOf(object.json, "rate");
196
196
  const wal = fieldOf(rate, "wal");
197
197
  const sui = fieldOf(rate, "sui");
198
198
  if (typeof wal !== "string" || typeof sui !== "string" || !/^\d+$/.test(wal) || !/^\d+$/.test(sui) || BigInt(sui) === 0n) {
@@ -206,10 +206,10 @@ export function swapReads(network) {
206
206
  async estimateFee(shape, sender) {
207
207
  try {
208
208
  const bytes = await swapTransaction({ ...shape, network, sender }).build({ client });
209
- const { effects } = await client.dryRunTransactionBlock({ transactionBlock: bytes });
210
- if (effects.status.status !== "success")
209
+ const { status, gasUsed } = await dryRun(client, bytes);
210
+ if (!status.success)
211
211
  return null;
212
- return netGasFee(effects.gasUsed);
212
+ return netGasFee(gasUsed);
213
213
  }
214
214
  catch {
215
215
  return null;
@@ -1,6 +1,7 @@
1
1
  // A venue's answer, read from the chain: how much comes out now, what stays unused, and the fee the
2
- // quote's own numbers say the venue charges. ⛔ EVERYTHING HERE IS A READ — `devInspect`, no gas,
3
- // no key, no signature, and a zero address as the nominal sender so a quote needs no funded wallet.
2
+ // quote's own numbers say the venue charges. ⛔ EVERYTHING HERE IS A READ — a simulation with checks
3
+ // off (what JSON-RPC called a devInspect), no gas, no key, no signature, and a zero address as the
4
+ // nominal sender so a quote needs no funded wallet.
4
5
  //
5
6
  // ⛔ THE ARITHMETIC IS THE BROWSER'S, copied byte-for-byte (`shared/lib/wallet/swap-rules.ts`); this
6
7
  // file only asks the chain and hands the answers to it. DeepBook's fee has no constant: it is
@@ -18,6 +19,7 @@
18
19
  // answer, not a failure: the amount is below one lot, or the book is empty.
19
20
  import { bcs } from "@mysten/sui/bcs";
20
21
  import { Transaction } from "@mysten/sui/transactions";
22
+ import { inspect, u64FromLe } from "./shared/lib/wallet/chain-calls.js";
21
23
  import { hopFor, PAIR_COINS, pickRoute, routeHops, venueRoutes, } from "./shared/lib/wallet/swap-routes.js";
22
24
  import { combineFeeBps, deepbookRowFrom, directionCoins, feeRateBpsOf, measureDeepbookFeeBps, } from "./shared/lib/wallet/swap-rules.js";
23
25
  import { BLUEFIN_MAX_SQRT_PRICE, BLUEFIN_MIN_SQRT_PRICE, DEEPBOOK_PACKAGE_IDS, DEEPBOOK_SUI_USDC_POOLS, DEEPBOOK_WAL_SUI_POOLS, DEEPBOOK_WAL_USDC_POOLS, USDC_COIN_TYPES, } from "./shared/lib/wallet/venue-ids.js";
@@ -56,9 +58,6 @@ export function routesWithPools(venue, direction, pools) {
56
58
  return hops !== null && hops.every((hop) => pools[hop.pair] !== null);
57
59
  });
58
60
  }
59
- function readU64(value) {
60
- return BigInt(bcs.U64.parse(Uint8Array.from(value[0])));
61
- }
62
61
  /**
63
62
  * The FRONT of Bluefin's `SwapResult`, in the order its `pool.move` declares them. BCS reads from
64
63
  * the front, so the fields behind these need not be known. The first three are checked against the
@@ -90,14 +89,13 @@ async function quoteBluefin(client, network, direction, amountInUnits, binding)
90
89
  tx.pure.u128(a2b ? BLUEFIN_MIN_SQRT_PRICE : BLUEFIN_MAX_SQRT_PRICE),
91
90
  ],
92
91
  });
93
- const res = await client.devInspectTransactionBlock({ sender: QUOTE_SENDER, transactionBlock: tx });
94
- if (res.error)
92
+ const res = await inspect(client, tx, QUOTE_SENDER);
93
+ if (res.error !== null)
95
94
  throw new Error(`the Bluefin quote was refused on chain: ${res.error}`);
96
- const returned = res.results?.[0]?.returnValues;
97
- const first = returned?.[0];
95
+ const first = res.results[0]?.returnValues[0];
98
96
  if (first === undefined)
99
97
  throw new Error("the Bluefin quote came back with no value");
100
- const result = BluefinSwapResultPrefix.parse(Uint8Array.from(first[0]));
98
+ const result = BluefinSwapResultPrefix.parse(first);
101
99
  if (result.a2b !== a2b || result.by_amount_in !== true || BigInt(result.amount_specified) !== amountInUnits) {
102
100
  throw new Error("the Bluefin quote did not echo the question it was asked");
103
101
  }
@@ -135,21 +133,22 @@ async function quoteDeepbookHop(client, network, hop, amountInUnits) {
135
133
  };
136
134
  // Both modes in ONE inspection so they see the same book. If the DEEP-mode call is refused, the
137
135
  // quote is asked again alone: what comes out matters more than what the fee was.
138
- let res = await client.devInspectTransactionBlock({ sender: QUOTE_SENDER, transactionBlock: build(true) });
136
+ let res = await inspect(client, build(true), QUOTE_SENDER);
139
137
  let deepModeAnswered = true;
140
- if (res.error) {
138
+ if (res.error !== null) {
141
139
  deepModeAnswered = false;
142
- res = await client.devInspectTransactionBlock({ sender: QUOTE_SENDER, transactionBlock: build(false) });
140
+ res = await inspect(client, build(false), QUOTE_SENDER);
143
141
  }
144
- if (res.error)
142
+ if (res.error !== null)
145
143
  throw new Error(`the DeepBook quote was refused on chain: ${res.error}`);
144
+ // A u64 is exactly eight bytes; any other length is a shape this tool does not read (`u64FromLe` throws).
146
145
  const rowOf = (values) => values !== undefined && values.length >= 3 && values[0] !== undefined && values[1] !== undefined
147
- ? deepbookRowFrom(hop.sellsFirst, readU64(values[0]), readU64(values[1]))
146
+ ? deepbookRowFrom(hop.sellsFirst, u64FromLe(values[0]), u64FromLe(values[1]))
148
147
  : null;
149
- const inputMode = rowOf(res.results?.[0]?.returnValues);
148
+ const inputMode = rowOf(res.results[0]?.returnValues);
150
149
  if (inputMode === null)
151
150
  throw new Error("the DeepBook quote came back in a shape this tool does not read");
152
- const deepMode = deepModeAnswered ? rowOf(res.results?.[1]?.returnValues) : null;
151
+ const deepMode = deepModeAnswered ? rowOf(res.results[1]?.returnValues) : null;
153
152
  return {
154
153
  outUnits: inputMode.outUnits,
155
154
  leftoverInUnits: inputMode.leftoverInUnits,
@@ -8,7 +8,6 @@
8
8
  // registers the blob and pays the relay's tip out of the treasury; this tool computes the id
9
9
  // locally and hands over the bytes. The one thing it must get right is telling the relay WHICH
10
10
  // transaction paid — see the note on `sendTip` below, which is not what its name suggests.
11
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
12
11
  import { walrus } from "@mysten/walrus";
13
12
  import { toBase64Url } from "./bytes.js";
14
13
  import { epochClock } from "./expiry.js";
@@ -19,7 +18,7 @@ import { NmtsError } from "./errors.js";
19
18
  import { countingFetch } from "./progress.js";
20
19
  import { reachFetch } from "./reach.js";
21
20
  import { relayHost, storageNodesThrough } from "./walrus.js";
22
- import { suiRpcTransport } from "./sui-rpc.js";
21
+ import { suiClient } from "./sui-rpc.js";
23
22
  /**
24
23
  * How long the relay gets for one blob PUT, sized to the body.
25
24
  *
@@ -44,12 +43,9 @@ export function relayTimeoutMs(bodyBytes) {
44
43
  */
45
44
  const TIP_CEILING_UNUSED_MIST = 1;
46
45
  function extend(network, relayUrl, bodyBytes, onSent) {
47
- const base = new SuiJsonRpcClient({
48
- // ⛔ The network name reaches the SDK as well as the URL. A mirror pointed at the wrong chain
49
- // would otherwise be discovered as a blob the storage nodes refuse, after the money moved.
50
- network: network === "mainnet" ? "mainnet" : "testnet",
51
- transport: suiRpcTransport(network),
52
- });
46
+ // ⛔ The network name reaches the SDK as well as the URL. A node pointed at the wrong chain
47
+ // would otherwise be discovered as a blob the storage nodes refuse, after the money moved.
48
+ const base = suiClient(network === "mainnet" ? "mainnet" : "testnet");
53
49
  return base.$extend(walrus({
54
50
  ...storageNodesThrough(),
55
51
  uploadRelay: {
@@ -133,10 +129,7 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
133
129
  */
134
130
  export async function readCurrentEpoch(network) {
135
131
  try {
136
- const base = new SuiJsonRpcClient({
137
- network: network === "mainnet" ? "mainnet" : "testnet",
138
- transport: suiRpcTransport(network),
139
- }).$extend(walrus(storageNodesThrough()));
132
+ const base = suiClient(network === "mainnet" ? "mainnet" : "testnet").$extend(walrus(storageNodesThrough()));
140
133
  // The epoch lives on the COMMITTEE, not beside it: the system state describes capacity and
141
134
  // the deny lists as well, and only the committee is stamped with which epoch it serves.
142
135
  const state = await base.walrus.systemState();
@@ -164,10 +157,7 @@ export async function readCurrentEpoch(network) {
164
157
  */
165
158
  export async function readEpochWindow(network) {
166
159
  try {
167
- const base = new SuiJsonRpcClient({
168
- network: network === "mainnet" ? "mainnet" : "testnet",
169
- transport: suiRpcTransport(network),
170
- }).$extend(walrus(storageNodesThrough()));
160
+ const base = suiClient(network === "mainnet" ? "mainnet" : "testnet").$extend(walrus(storageNodesThrough()));
171
161
  const [system, staking] = await Promise.all([base.walrus.systemState(), base.walrus.stakingState()]);
172
162
  // Both numbers can arrive as strings — Sui reports 64-bit values that way — so they are
173
163
  // converted here and the constructor below refuses whatever did not survive it.
package/dist/walrus.d.ts CHANGED
@@ -18,20 +18,20 @@ export declare const AGGREGATOR_HOSTS: Readonly<Record<string, readonly string[]
18
18
  */
19
19
  export declare const RELAY_HOSTS: Readonly<Record<string, readonly string[]>>;
20
20
  /**
21
- * Sui JSON-RPC endpoints per network — public mirrors, because the official full nodes retired
22
- * JSON-RPC on both networks (browser measurements 2026-07-29 testnet, 2026-08-03 mainnet).
21
+ * Sui node endpoints per network, spoken to over gRPC-web (`sui-rpc.ts`), first-that-answers.
23
22
  *
24
- * ⛔ READ-ONLY, AND NOT TRUSTED WITH ANYTHING. This tool asks one question here: how many shards
25
- * the storage network currently has, which the erasure coding needs. A wrong answer produces a
26
- * blob id the storage network refuses, so it fails loudly at the relay rather than quietly
27
- * storing something unreadable. No key is ever sent to one of these, and nothing is signed.
23
+ * ⛔ READ-MOSTLY, AND NOT TRUSTED WITH ANYTHING SECRET. Most commands ask one question here — how
24
+ * many shards the storage network has, which the erasure coding needs; the wallet commands also
25
+ * read balances and submit transactions the person signed on this machine. No key is ever sent to
26
+ * one of these. A wrong shard count produces a blob id the storage network refuses, so it fails
27
+ * loudly at the relay rather than quietly storing something unreadable.
28
28
  *
29
- * ⭐ 2026-09-01 — a LIST per network, two operators, first-that-answers. It used to be one host,
30
- * and the testnet one was measured dead that morning: `rpc-testnet.suiscan.xyz` completes the
31
- * TCP handshake in 31 ms and then sends nothing for 12 seconds, three times running. It had
32
- * been that way for eleven days, so every `nmts` command that needed the shard count on testnet
33
- * simply stopped. Each host below answered `sui_getChainIdentifier` with the right value the
34
- * same morning, 8/8 on a burst.
29
+ * ⭐ 2026-10-21 — THE SAME LIST AS THE BROWSER'S, AND A NEW ONE. Sui removed JSON-RPC from its node
30
+ * software in October 2026; the JSON-RPC mirrors this table held were dead (testnet) or about to be
31
+ * (mainnet). Every host below answered chain id, a balance, an object and the gas price over
32
+ * gRPC-web that morning. Two operators per network — Suiscan and Mysten Labs — in the browser's
33
+ * order (`web/src/lib/walrus/network-hosts.ts` says why mainnet keeps Suiscan first). A test
34
+ * and `deploy/check-walrus-hosts.mjs` hold this table to the browser's.
35
35
  */
36
36
  export declare const SUI_RPC_HOSTS: Readonly<Record<string, readonly string[]>>;
37
37
  /** How long one host gets before the next is tried. A read that stalls is a read that failed. */
@@ -47,7 +47,7 @@ export { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.t
47
47
  */
48
48
  export declare function relayHost(network: string): string;
49
49
  /**
50
- * Every Sui JSON-RPC node this run may ask, in order: the caller's list if it named one, then the
50
+ * Every Sui node this run may ask (it must answer gRPC-web), in order: the caller's list if it named one, then the
51
51
  * environment's, then the network's.
52
52
  *
53
53
  * ⛔ Naming nodes REPLACES the list rather than adding to it — the same rule the aggregator