@needmoretruth/nmts-cli 0.50.0 → 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.
- package/CHANGELOG.md +28 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/api.js +3 -0
- package/dist/artifact-about.d.ts +1 -1
- package/dist/client-id.d.ts +11 -0
- package/dist/client-id.js +30 -0
- package/dist/commands/mcp.js +3 -0
- package/dist/commands/wallet-activity.d.ts +10 -6
- package/dist/commands/wallet-activity.js +17 -6
- package/dist/env-vars.d.ts +1 -1
- package/dist/env-vars.js +1 -1
- package/dist/extend-chain.d.ts +4 -6
- package/dist/extend-chain.js +30 -28
- package/dist/net-retry.js +14 -0
- package/dist/portable.d.ts +2 -0
- package/dist/portable.js +2 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/reach.d.ts +1 -1
- package/dist/shared/lib/storage-control/chain.d.ts +30 -29
- package/dist/shared/lib/storage-control/chain.js +14 -20
- package/dist/shared/lib/wallet/activity.d.ts +42 -48
- package/dist/shared/lib/wallet/activity.js +51 -30
- package/dist/shared/lib/wallet/address-history.d.ts +42 -0
- package/dist/shared/lib/wallet/address-history.js +247 -0
- package/dist/shared/lib/wallet/chain-calls.d.ts +44 -0
- package/dist/shared/lib/wallet/chain-calls.js +59 -0
- package/dist/storage-control-chain.js +5 -4
- package/dist/sui-execute.d.ts +54 -0
- package/dist/sui-execute.js +43 -0
- package/dist/sui-rpc.d.ts +16 -9
- package/dist/sui-rpc.js +53 -19
- package/dist/upload-wallet-chain.d.ts +8 -3
- package/dist/upload-wallet-chain.js +33 -29
- package/dist/upload-wallet-plan.d.ts +1 -1
- package/dist/upload-wallet-put.js +1 -1
- package/dist/wallet-activity-chain.d.ts +2 -2
- package/dist/wallet-activity-chain.js +12 -27
- package/dist/wallet-chain.js +19 -13
- package/dist/wallet-list-chain.d.ts +1 -1
- package/dist/wallet-list-chain.js +13 -14
- package/dist/wallet-send-chain.js +4 -3
- package/dist/wallet-sign-external.d.ts +18 -25
- package/dist/wallet-sign-external.js +16 -19
- package/dist/wallet-sign.js +22 -70
- package/dist/wallet-storage-chain.js +2 -3
- package/dist/wallet-swap-chain.d.ts +3 -6
- package/dist/wallet-swap-chain.js +16 -16
- package/dist/wallet-swap-quote.js +16 -17
- package/dist/walrus-fresh.d.ts +8 -0
- package/dist/walrus-fresh.js +15 -0
- package/dist/walrus-write.js +6 -16
- package/dist/walrus.d.ts +13 -13
- package/dist/walrus.js +15 -15
- package/package.json +7 -4
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +11 -11
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +11 -11
package/dist/wallet-chain.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
// address holds, and whether a coin type exists. A balance is public data — anybody can ask the
|
|
11
11
|
// same question about the same address — so nothing about this run leaves that was not already
|
|
12
12
|
// published by the chain itself.
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { RpcError } from "@mysten/sui/grpc";
|
|
14
|
+
import { suiClient } from "./sui-rpc.js";
|
|
15
15
|
/**
|
|
16
16
|
* How long one balance question gets.
|
|
17
17
|
*
|
|
@@ -31,25 +31,31 @@ export const BALANCE_TIMEOUT_MS = 20_000;
|
|
|
31
31
|
export function chainReader(network, address) {
|
|
32
32
|
// The network name reaches the SDK as well as the URL, which is what keeps a mirror pointed at
|
|
33
33
|
// the wrong chain from being discovered later, as an answer that quietly made no sense.
|
|
34
|
-
const client =
|
|
34
|
+
const client = suiClient(network);
|
|
35
35
|
return {
|
|
36
36
|
async totalOf(coinType) {
|
|
37
|
-
const {
|
|
37
|
+
const { balance } = await client.core.getBalance({
|
|
38
38
|
owner: address,
|
|
39
39
|
coinType,
|
|
40
40
|
signal: AbortSignal.timeout(BALANCE_TIMEOUT_MS),
|
|
41
41
|
});
|
|
42
|
-
return baseUnitsOf(
|
|
42
|
+
return baseUnitsOf(balance.balance);
|
|
43
43
|
},
|
|
44
44
|
async knowsCoinType(coinType) {
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
// ⛔ ASKED RAW, NOT THROUGH `client.core.getCoinMetadata`: that helper answers `null` for ANY
|
|
46
|
+
// failure, a timeout included, and then "the node did not answer" would print as "this
|
|
47
|
+
// chain does not know the coin". The node's own answer for a type that does not exist is the
|
|
48
|
+
// status NOT_FOUND (measured on both networks' four hosts, 2026-10-21); every other failure
|
|
49
|
+
// is thrown, which the caller reports as "could not be confirmed".
|
|
50
|
+
try {
|
|
51
|
+
const { response } = await client.stateService.getCoinInfo({ coinType }, { abort: AbortSignal.timeout(BALANCE_TIMEOUT_MS) });
|
|
52
|
+
return response.metadata !== undefined;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof RpcError && error.code === "NOT_FOUND")
|
|
56
|
+
return false;
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
53
59
|
},
|
|
54
60
|
};
|
|
55
61
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Network } from "./network.ts";
|
|
2
|
-
/** How long the
|
|
2
|
+
/** How long the question gets. A read that stalls is a read that failed. */
|
|
3
3
|
export declare const HISTORY_TIMEOUT_MS = 20000;
|
|
4
4
|
export declare function hasHistory(network: Network, address: string): Promise<boolean>;
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
// The live read behind `nmts wallet list`'s walk: has this address ever been in a transaction?
|
|
2
2
|
//
|
|
3
|
-
// ⛔ READ ONLY, and
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// ⛔ READ ONLY, and ONE question since 2026-10-21. The retired JSON-RPC filter had no OR, so "from"
|
|
4
|
+
// and "to" were asked separately; the gRPC ledger index answers "every transaction that moved this
|
|
5
|
+
// address" in one (`shared/lib/wallet/address-history.ts`, the browser's copy). A wallet that only
|
|
6
|
+
// ever RECEIVED is in use too, and a walk that asked about balances alone would report a wallet
|
|
7
|
+
// somebody emptied as one that does not exist.
|
|
6
8
|
//
|
|
7
9
|
// ⚠ ONE transaction is enough to answer, so one is what is asked for. This runs once per wallet
|
|
8
|
-
// the walk looks at, which is why it asks for as little as the chain will sell.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// the walk looks at, which is why it asks for as little as the chain will sell. A scan the node
|
|
11
|
+
// stopped short of the end throws instead of answering "no" — the walk then says it could not read.
|
|
12
|
+
// ⛔ A node keeps only weeks of history, so "nothing lately" is followed by one question to Sui's
|
|
13
|
+
// GraphQL service before it may become "never used" (`deeperHistory`).
|
|
14
|
+
import { hasAddressHistory } from "./shared/lib/wallet/address-history.js";
|
|
15
|
+
import { deeperHistory, suiClient } from "./sui-rpc.js";
|
|
16
|
+
/** How long the question gets. A read that stalls is a read that failed. */
|
|
12
17
|
export const HISTORY_TIMEOUT_MS = 20_000;
|
|
13
18
|
export async function hasHistory(network, address) {
|
|
14
|
-
|
|
15
|
-
const signal = AbortSignal.timeout(HISTORY_TIMEOUT_MS);
|
|
16
|
-
const sent = await client.queryTransactionBlocks({ filter: { FromAddress: address }, limit: 1, signal });
|
|
17
|
-
if (sent.data.length > 0)
|
|
18
|
-
return true;
|
|
19
|
-
const received = await client.queryTransactionBlocks({ filter: { ToAddress: address }, limit: 1, signal });
|
|
20
|
-
return received.data.length > 0;
|
|
19
|
+
return hasAddressHistory(suiClient(network), address, AbortSignal.timeout(HISTORY_TIMEOUT_MS), deeperHistory(network));
|
|
21
20
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// same two things.
|
|
11
11
|
import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
|
|
12
12
|
import { walrusClient, netGasFee } from "./extend-chain.js";
|
|
13
|
+
import { dryRun } from "./shared/lib/wallet/chain-calls.js";
|
|
13
14
|
import { readBalances, walCoinType } from "./wallet.js";
|
|
14
15
|
import { chainReader } from "./wallet-chain.js";
|
|
15
16
|
export function transferTransaction(input) {
|
|
@@ -36,10 +37,10 @@ export function sendReads(network) {
|
|
|
36
37
|
async estimateFee(shape, sender) {
|
|
37
38
|
try {
|
|
38
39
|
const bytes = await transferTransaction({ ...shape, sender }).build({ client });
|
|
39
|
-
const {
|
|
40
|
-
if (
|
|
40
|
+
const { status, gasUsed } = await dryRun(client, bytes);
|
|
41
|
+
if (!status.success)
|
|
41
42
|
return null;
|
|
42
|
-
return netGasFee(
|
|
43
|
+
return netGasFee(gasUsed);
|
|
43
44
|
}
|
|
44
45
|
catch {
|
|
45
46
|
return null;
|
|
@@ -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
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 {
|
|
@@ -36,21 +36,14 @@ import { Transaction, TransactionDataBuilder } from "@mysten/sui/transactions";
|
|
|
36
36
|
import { fromBase64 } from "@mysten/sui/utils";
|
|
37
37
|
import { NmtsError } from "./errors.js";
|
|
38
38
|
import { walrusClient } from "./extend-chain.js";
|
|
39
|
-
import {
|
|
39
|
+
import { freshWalrus } from "./walrus-fresh.js";
|
|
40
|
+
import { EXECUTE_INCLUDE, readAnswer } from "./sui-execute.js";
|
|
40
41
|
import { isTransient, keepTrying } from "./net-retry.js";
|
|
41
42
|
import { storageOpTransaction } from "./storage-control-chain.js";
|
|
42
43
|
import { certifyTransaction, createdBlob, payingClient, registerTransaction } from "./upload-wallet-chain.js";
|
|
43
44
|
function why(error) {
|
|
44
45
|
return error instanceof Error ? error.message : String(error);
|
|
45
46
|
}
|
|
46
|
-
/** What a refused execution said, or null when the effects say it went through. */
|
|
47
|
-
function refusedBecause(result) {
|
|
48
|
-
const status = isRecord(result.effects) ? result.effects["status"] : undefined;
|
|
49
|
-
if (!isRecord(status) || status["status"] !== "failure")
|
|
50
|
-
return null;
|
|
51
|
-
const reason = status["error"];
|
|
52
|
-
return typeof reason === "string" ? reason : "no reason was given";
|
|
53
|
-
}
|
|
54
47
|
/** `sui:mainnet` or `sui:testnet` — what a wallet is told the transaction is for. */
|
|
55
48
|
function chainOf(network) {
|
|
56
49
|
return `sui:${network === "mainnet" ? "mainnet" : "testnet"}`;
|
|
@@ -76,28 +69,31 @@ export async function signAndSubmit(client, payer, input) {
|
|
|
76
69
|
}
|
|
77
70
|
const signed = typeof answered.bytes === "string" ? fromBase64(answered.bytes) : answered.bytes;
|
|
78
71
|
const digest = TransactionDataBuilder.getDigestFromBytes(signed);
|
|
79
|
-
const options = { showEffects: true, showObjectChanges: true };
|
|
80
72
|
let sent = false;
|
|
81
|
-
const
|
|
73
|
+
const answer = await keepTrying(async () => {
|
|
82
74
|
if (sent) {
|
|
83
75
|
// The attempt before this one may have reached the chain and lost only its reply. An
|
|
84
76
|
// unknown digest and a node that did not answer look the same here, and both mean "send
|
|
85
77
|
// the same bytes again" — which is safe precisely because they are the same bytes.
|
|
86
|
-
const seen = await client.
|
|
78
|
+
const seen = await client.core.getTransaction({ digest, include: EXECUTE_INCLUDE }).catch(() => null);
|
|
87
79
|
if (seen !== null)
|
|
88
80
|
return seen;
|
|
89
81
|
}
|
|
90
82
|
sent = true;
|
|
91
|
-
return client.
|
|
83
|
+
return client.core.executeTransaction({
|
|
84
|
+
transaction: signed,
|
|
85
|
+
signatures: [answered.signature],
|
|
86
|
+
include: EXECUTE_INCLUDE,
|
|
87
|
+
});
|
|
92
88
|
}, { ...input.retry, retryable: isTransient });
|
|
89
|
+
const result = readAnswer(answer);
|
|
93
90
|
// ⛔ SUCCESS IS ALREADY DECIDED BY THE EFFECTS BELOW. This wait is for what happens NEXT — the
|
|
94
91
|
// relay being told the digest, the blob object being read back — because a node that has not
|
|
95
92
|
// indexed the transaction yet answers those as if nothing had happened. A wait that times out
|
|
96
93
|
// changes nothing about what was signed, so it is not a failure of this transaction.
|
|
97
|
-
await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
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}.`, {
|
|
101
97
|
exitCode: 1,
|
|
102
98
|
nextStep: input.refusals.refused.nextStep,
|
|
103
99
|
});
|
|
@@ -132,7 +128,7 @@ export function externalBlobSigners(payer) {
|
|
|
132
128
|
},
|
|
133
129
|
});
|
|
134
130
|
// The blob object is found by its type in what the transaction created, not by position.
|
|
135
|
-
return { digest: result.digest, ...(await createdBlob(client, result.
|
|
131
|
+
return { digest: result.digest, ...(await createdBlob(client, result.created)) };
|
|
136
132
|
},
|
|
137
133
|
certify: async ({ network, relayUrl, blobId, blobObjectId, certificate }) => {
|
|
138
134
|
const client = payingClient(network, relayUrl);
|
|
@@ -176,8 +172,9 @@ export function externalExtendSigner(payer) {
|
|
|
176
172
|
const tx = new Transaction();
|
|
177
173
|
// The sender goes first: the fragments below pick this address's WAL when they resolve.
|
|
178
174
|
tx.setSender(payer.address);
|
|
175
|
+
const fresh = freshWalrus(client);
|
|
179
176
|
for (const blobObjectId of unique)
|
|
180
|
-
tx.add(
|
|
177
|
+
tx.add(fresh.extendBlob({ blobObjectId, epochs }));
|
|
181
178
|
const result = await signAndSubmit(client, payer, {
|
|
182
179
|
network,
|
|
183
180
|
bytes: await tx.build({ client }),
|
package/dist/wallet-sign.js
CHANGED
|
@@ -35,10 +35,11 @@ import { assertUsableCode } from "./account.js";
|
|
|
35
35
|
import { DERIVED, loadCrypto } from "./crypto.js";
|
|
36
36
|
import { NmtsError } from "./errors.js";
|
|
37
37
|
import { walrusClient } from "./extend-chain.js";
|
|
38
|
+
import { freshWalrus } from "./walrus-fresh.js";
|
|
38
39
|
import { transferTransaction } from "./wallet-send-chain.js";
|
|
39
40
|
import { storageOpTransaction } from "./storage-control-chain.js";
|
|
40
41
|
import { swapTransaction } from "./wallet-swap-chain.js";
|
|
41
|
-
import {
|
|
42
|
+
import { signAndRun } from "./sui-execute.js";
|
|
42
43
|
import { certifyTransaction, createdBlob, payingClient, registerTransaction, } from "./upload-wallet-chain.js";
|
|
43
44
|
import { BUILT_IN_WALLET_INDEX } from "./wallet.js";
|
|
44
45
|
/**
|
|
@@ -120,35 +121,23 @@ export const signExtension = async ({ network, code, wallet, objectIds, epochs }
|
|
|
120
121
|
// The sender must be set before the fragments resolve: paying with the SDK's default coin
|
|
121
122
|
// selection picks the WAL coins from the sender's own address.
|
|
122
123
|
tx.setSender(keypair.toSuiAddress());
|
|
124
|
+
const fresh = freshWalrus(client);
|
|
123
125
|
for (const blobObjectId of unique) {
|
|
124
|
-
tx.add(
|
|
126
|
+
tx.add(fresh.extendBlob({ blobObjectId, epochs }));
|
|
125
127
|
}
|
|
126
|
-
const result = await client
|
|
127
|
-
transaction: tx,
|
|
128
|
-
signer: keypair,
|
|
129
|
-
options: { showEffects: true },
|
|
130
|
-
});
|
|
128
|
+
const result = await signAndRun(client, tx, keypair);
|
|
131
129
|
// ⛔ A DIGEST IS NOT A SUCCESS. A transaction that was executed and FAILED still has one, and the
|
|
132
130
|
// gas for it is still gone; recording it as an extension would move the drive's expiry date
|
|
133
|
-
// over storage nobody bought.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const outcome = isRecord(status) ? status["status"] : undefined;
|
|
137
|
-
if (outcome === "failure") {
|
|
138
|
-
const why = isRecord(status) ? status["error"] : undefined;
|
|
139
|
-
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}.`, {
|
|
140
134
|
exitCode: 1,
|
|
141
135
|
nextStep: `The storage was NOT extended and the file still ends when it did. The transaction fee ` +
|
|
142
136
|
`was spent. The usual causes are too little WAL or SUI in this account's wallet — ` +
|
|
143
137
|
`\`nmts wallet\` shows both — or a length the network will no longer sell.`,
|
|
144
138
|
});
|
|
145
139
|
}
|
|
146
|
-
//
|
|
147
|
-
// the server is told the digest, `nmts wallet` is run, the browser's activity list opens —
|
|
148
|
-
// and a full node that has not indexed the transaction yet answers those as if nothing
|
|
149
|
-
// happened. Waiting until it is readable is what the browser's signers do. A wait that times
|
|
150
|
-
// out changes nothing about what was signed, so it is not an error of this extension.
|
|
151
|
-
await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
|
|
140
|
+
// The wait until a node can read it back already happened inside `signAndRun`.
|
|
152
141
|
return result.digest;
|
|
153
142
|
};
|
|
154
143
|
/**
|
|
@@ -164,23 +153,14 @@ export const signTransfer = async ({ network, code, wallet, shape }) => {
|
|
|
164
153
|
const client = walrusClient(network);
|
|
165
154
|
const keypair = await keypairFor(code, wallet);
|
|
166
155
|
const tx = transferTransaction({ ...shape, sender: keypair.toSuiAddress() });
|
|
167
|
-
const result = await client
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
options: { showEffects: true },
|
|
171
|
-
});
|
|
172
|
-
const effects = result.effects;
|
|
173
|
-
const status = isRecord(effects) ? effects["status"] : undefined;
|
|
174
|
-
const outcome = isRecord(status) ? status["status"] : undefined;
|
|
175
|
-
if (outcome === "failure") {
|
|
176
|
-
const why = isRecord(status) ? status["error"] : undefined;
|
|
177
|
-
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}.`, {
|
|
178
159
|
exitCode: 1,
|
|
179
160
|
nextStep: `Nothing was sent. The transaction fee was spent. The usual cause is a balance that moved ` +
|
|
180
161
|
`between reading it and signing — \`nmts wallet\` shows both balances now.`,
|
|
181
162
|
});
|
|
182
163
|
}
|
|
183
|
-
await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
|
|
184
164
|
return result.digest;
|
|
185
165
|
};
|
|
186
166
|
/**
|
|
@@ -213,12 +193,8 @@ export const signSwap = async ({ network, code, wallet, shape }) => {
|
|
|
213
193
|
const client = walrusClient(network);
|
|
214
194
|
const keypair = await keypairFor(code, wallet);
|
|
215
195
|
const tx = swapTransaction({ ...shape, network, sender: keypair.toSuiAddress() });
|
|
216
|
-
const result = await client
|
|
217
|
-
|
|
218
|
-
signer: keypair,
|
|
219
|
-
options: { showEffects: true },
|
|
220
|
-
});
|
|
221
|
-
const refused = refusedBecause(result);
|
|
196
|
+
const result = await signAndRun(client, tx, keypair);
|
|
197
|
+
const refused = result.refused;
|
|
222
198
|
if (refused !== null) {
|
|
223
199
|
throw new NmtsError(`The chain refused the swap: ${refused}.`, {
|
|
224
200
|
exitCode: 1,
|
|
@@ -227,18 +203,8 @@ export const signSwap = async ({ network, code, wallet, shape }) => {
|
|
|
227
203
|
`or a balance that moved. \`nmts wallet\` shows both balances now.`,
|
|
228
204
|
});
|
|
229
205
|
}
|
|
230
|
-
await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
|
|
231
206
|
return result.digest;
|
|
232
207
|
};
|
|
233
|
-
/** What a refused execution said, or null when the effects say it went through. */
|
|
234
|
-
function refusedBecause(result) {
|
|
235
|
-
const effects = isRecord(result) ? result["effects"] : undefined;
|
|
236
|
-
const status = isRecord(effects) ? effects["status"] : undefined;
|
|
237
|
-
if (!isRecord(status) || status["status"] !== "failure")
|
|
238
|
-
return null;
|
|
239
|
-
const why = status["error"];
|
|
240
|
-
return typeof why === "string" ? why : "no reason was given";
|
|
241
|
-
}
|
|
242
208
|
/**
|
|
243
209
|
* Register ONE part's blob, signed by the account's own wallet: the relay's tip, then the storage
|
|
244
210
|
* — bought for `epochs`, or a resource the wallet already holds, cut to fit first if asked.
|
|
@@ -255,12 +221,8 @@ export const signBlobRegister = async ({ network, code, wallet, relayUrl, ...sha
|
|
|
255
221
|
const client = payingClient(network, relayUrl);
|
|
256
222
|
const keypair = await keypairFor(code, wallet);
|
|
257
223
|
const tx = await registerTransaction(client, network, { ...shape, sender: keypair.toSuiAddress() });
|
|
258
|
-
const result = await client
|
|
259
|
-
|
|
260
|
-
signer: keypair,
|
|
261
|
-
options: { showEffects: true, showObjectChanges: true },
|
|
262
|
-
});
|
|
263
|
-
const refused = refusedBecause(result);
|
|
224
|
+
const result = await signAndRun(client, tx, keypair);
|
|
225
|
+
const refused = result.refused;
|
|
264
226
|
if (refused !== null) {
|
|
265
227
|
throw new NmtsError(`The storage network refused the registration: ${refused}.`, {
|
|
266
228
|
exitCode: 1,
|
|
@@ -269,8 +231,7 @@ export const signBlobRegister = async ({ network, code, wallet, relayUrl, ...sha
|
|
|
269
231
|
`resource too small for the part once encoded.`,
|
|
270
232
|
});
|
|
271
233
|
}
|
|
272
|
-
await client
|
|
273
|
-
const blob = await createdBlob(client, result.objectChanges);
|
|
234
|
+
const blob = await createdBlob(client, result.created);
|
|
274
235
|
return { digest: result.digest, ...blob };
|
|
275
236
|
};
|
|
276
237
|
/** Certify ONE registered part from the relay's certificate. Gas only; nothing else leaves the wallet. */
|
|
@@ -279,12 +240,8 @@ export const signBlobCertify = async ({ network, code, wallet, relayUrl, ...shap
|
|
|
279
240
|
const keypair = await keypairFor(code, wallet);
|
|
280
241
|
const tx = certifyTransaction(client, shape);
|
|
281
242
|
tx.setSender(keypair.toSuiAddress());
|
|
282
|
-
const result = await client
|
|
283
|
-
|
|
284
|
-
signer: keypair,
|
|
285
|
-
options: { showEffects: true },
|
|
286
|
-
});
|
|
287
|
-
const refused = refusedBecause(result);
|
|
243
|
+
const result = await signAndRun(client, tx, keypair);
|
|
244
|
+
const refused = result.refused;
|
|
288
245
|
if (refused !== null) {
|
|
289
246
|
throw new NmtsError(`The storage network refused the certification: ${refused}.`, {
|
|
290
247
|
exitCode: 1,
|
|
@@ -292,7 +249,6 @@ export const signBlobCertify = async ({ network, code, wallet, relayUrl, ...shap
|
|
|
292
249
|
`its fee was spent. Running the same command again certifies again and buys nothing.`,
|
|
293
250
|
});
|
|
294
251
|
}
|
|
295
|
-
await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
|
|
296
252
|
return result.digest;
|
|
297
253
|
};
|
|
298
254
|
/**
|
|
@@ -308,16 +264,12 @@ export const signStorageOp = async ({ network, code, wallet, shape, walrusPackag
|
|
|
308
264
|
// that can reshape or hand it over.
|
|
309
265
|
const keypair = await keypairFor(code, wallet);
|
|
310
266
|
const tx = storageOpTransaction(shape, { walrusPackageId, sender: keypair.toSuiAddress() });
|
|
311
|
-
const result = await client
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (isRecord(status) && status["status"] === "failure") {
|
|
315
|
-
const why = status["error"];
|
|
316
|
-
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}.`, {
|
|
317
270
|
exitCode: 1,
|
|
318
271
|
nextStep: "Nothing changed on the resource. The transaction fee was spent.",
|
|
319
272
|
});
|
|
320
273
|
}
|
|
321
|
-
await client.waitForTransaction({ digest: result.digest }).catch(() => undefined);
|
|
322
274
|
return result.digest;
|
|
323
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 {
|
|
9
|
+
import { suiClient } from "./sui-rpc.js";
|
|
11
10
|
export async function readWalletStorage(network, address) {
|
|
12
|
-
const client =
|
|
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
|
|
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
|
-
|
|
64
|
-
|
|
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
|
-
/**
|
|
129
|
-
function fieldOf(
|
|
130
|
-
|
|
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`
|
|
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.
|
|
140
|
-
return
|
|
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
|
|
191
|
-
const type =
|
|
192
|
-
if (
|
|
193
|
-
throw new Error(`Object ${objectId} is not a wal_exchange Exchange (type ${type
|
|
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(
|
|
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 {
|
|
210
|
-
if (
|
|
209
|
+
const { status, gasUsed } = await dryRun(client, bytes);
|
|
210
|
+
if (!status.success)
|
|
211
211
|
return null;
|
|
212
|
-
return netGasFee(
|
|
212
|
+
return netGasFee(gasUsed);
|
|
213
213
|
}
|
|
214
214
|
catch {
|
|
215
215
|
return null;
|