@sig-net/midnight-contract-deploy 0.21.0-rc.8 → 0.21.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.
@@ -1,16 +1,8 @@
1
- // Account funding primitives for the root-funds-children model. Fees are paid
2
- // in DUST, which only generates on NIGHT registered for dust generation, so a
3
- // wallet is fee-ready only once it holds NIGHT that is registered and has
4
- // generated spendable dust. One ROOT wallet (the local genesis mint, or a
5
- // faucet-funded seed on a deployed network) holds the funds and pays out to
6
- // the role wallets (deployer, invoker, mpc responder); the roles themselves
7
- // are generated per environment and topped up from root.
8
- //
9
- // These are mechanical primitives (read a balance, assert root is funded,
10
- // fund one child). The pipeline that resolves/persists seeds, decides the
11
- // per-child amount, and prints addresses lives in the integration-tests setup.
1
+ import { formatDust } from "./format-dust.js";
12
2
  import { isLocalStandaloneNetwork } from "./network-id.js";
13
- import { deriveAccountKeys, deriveAddresses, registerNightForDustGeneration, transferNight, waitForSpendableDust, withSyncedWalletFacade, } from "./wallet.js";
3
+ import { deriveAccountKeys, deriveAddresses, registerNightForDustGeneration, transferNight, waitForSpendableDust, } from "./wallet.js";
4
+ /** The registry's root wallet label, shared by every primitive that logs it. */
5
+ const ROOT_LABEL = "root";
14
6
  /**
15
7
  * Sum a wallet's unshielded NIGHT across its UTXOs, in base units.
16
8
  *
@@ -32,29 +24,32 @@ export function deriveWalletAddresses(seed, config) {
32
24
  return deriveAddresses(deriveAccountKeys(seed, config.networkId), config.networkId);
33
25
  }
34
26
  /**
35
- * Sync a wallet and read its funding snapshot (addresses + NIGHT + DUST).
27
+ * Read a wallet's funding snapshot (addresses + NIGHT + DUST) from its synced
28
+ * state, syncing it first if the registry has not opened it yet.
36
29
  *
37
- * @param config - The stack the wallet connects to.
30
+ * @param wallets - The registry holding the wallet.
38
31
  * @param seed - The wallet seed (hex or mnemonic).
32
+ * @param label - The wallet's role name, for the sync log.
39
33
  * @returns The synced {@link AccountFunding}.
40
34
  */
41
- export async function readAccountFunding(config, seed) {
42
- const keys = deriveAccountKeys(seed, config.networkId);
43
- const addresses = deriveAddresses(keys, config.networkId);
44
- return withSyncedWalletFacade(keys, config, (_facade, state) => Promise.resolve({
45
- addresses,
35
+ export async function readAccountFunding(wallets, seed, label) {
36
+ const { facade, keys } = await wallets.wallet(seed, label);
37
+ const state = await facade.waitForSyncedState();
38
+ return {
39
+ addresses: deriveAddresses(keys, wallets.config.networkId),
46
40
  night: totalNight(state),
47
41
  dust: state.dust.balance(new Date()),
48
- }));
42
+ };
49
43
  }
50
44
  /**
51
- * A wallet is fee-ready when it holds NIGHT and that NIGHT has generated spendable dust.
45
+ * A wallet is fee-ready when its spendable DUST covers `minimumDust`.
52
46
  *
53
47
  * @param funding - The wallet's measured funding.
48
+ * @param minimumDust - The spendable DUST that counts as ready, in base units, 1 (any dust at all) by default.
54
49
  * @returns Whether the wallet can pay fees right now.
55
50
  */
56
- export function isFeeReady(funding) {
57
- return funding.night > 0n && funding.dust > 0n;
51
+ export function isFeeReady(funding, minimumDust = 1n) {
52
+ return funding.dust >= minimumDust;
58
53
  }
59
54
  /**
60
55
  * A wallet holds no NIGHT and no DUST, so it cannot pay fees until its NIGHT
@@ -86,10 +81,14 @@ export class WalletUnfundedError extends Error {
86
81
  * generation, so every unregistered NIGHT UTXO the wallet holds is registered
87
82
  * here first, whatever its current dust: a faucet top-up or transfer change
88
83
  * arrives unregistered, and leaving it so while older dust lasts would let
89
- * the wallet's dust generation shrink with every spend. Then a wallet with
90
- * spendable dust returns it, and one without waits until its first dust
91
- * appears (a few blocks). The facade must be started and synced, and `state`
92
- * must be its synced state (see `withSyncedWalletFacade` in wallet.ts).
84
+ * the wallet's dust generation shrink with every spend. Then a wallet holding
85
+ * at least `minimumDust` of spendable dust returns it, and one without waits
86
+ * until it does: a few blocks for a fresh registration, longer for a
87
+ * multi-transaction budget. A flow about to submit several transactions
88
+ * passes their total fee as `minimumDust`, so a wallet that cannot cover
89
+ * them stops here with the shortfall named and nothing submitted. The facade
90
+ * must be started and synced, and `state` must be its synced state (see
91
+ * `withSyncedWalletFacade` in wallet.ts).
93
92
  *
94
93
  * @param facade - A started wallet facade for `keys`, which submits the registration.
95
94
  * @param keys - The key material of the same wallet. Its keystore signs the registration.
@@ -97,15 +96,17 @@ export class WalletUnfundedError extends Error {
97
96
  * @param networkId - The network the wallet lives on, which prefixes the
98
97
  * NIGHT receive address the no-NIGHT error prints for faucet funding.
99
98
  * @param faucetUrl - The network's faucet for the no-NIGHT hint, when one is known.
100
- * @returns The wallet's spendable DUST balance, always positive.
101
- * @throws {WalletUnfundedError} If the wallet holds neither NIGHT nor DUST.
102
- * @throws {Error} If no dust appears in time after registration (see
99
+ * @param minimumDust - The spendable DUST to require, in base units, 1 (any dust at all) by default.
100
+ * @param timeoutMs - Spendable DUST wait deadline in milliseconds, after registration.
101
+ * @returns The wallet's spendable DUST balance, at least `minimumDust`.
102
+ * @throws {WalletUnfundedError} If the wallet holds no NIGHT and less than `minimumDust` of DUST.
103
+ * @throws {Error} If the dust stays below `minimumDust` for the wait's timeout (see
103
104
  * {@link waitForSpendableDust}).
104
105
  */
105
- export async function ensureFeeReady(facade, keys, state, networkId, faucetUrl) {
106
+ export async function ensureFeeReady(facade, keys, state, networkId, faucetUrl, minimumDust = 1n, timeoutMs) {
106
107
  const dust = state.dust.balance(new Date());
107
108
  if (totalNight(state) === 0n) {
108
- if (dust > 0n)
109
+ if (dust >= minimumDust)
109
110
  return dust;
110
111
  throw new WalletUnfundedError(deriveAddresses(keys, networkId).unshielded, faucetUrl);
111
112
  }
@@ -113,10 +114,10 @@ export async function ensureFeeReady(facade, keys, state, networkId, faucetUrl)
113
114
  if (registered > 0) {
114
115
  console.log(`registered ${String(registered)} NIGHT UTXO(s) for dust generation`);
115
116
  }
116
- if (dust > 0n)
117
+ if (dust >= minimumDust)
117
118
  return dust;
118
- console.log("waiting for spendable DUST...");
119
- return waitForSpendableDust(facade);
119
+ console.log(`waiting for spendable DUST (have ${formatDust(dust)}, need at least ${formatDust(minimumDust)})...`);
120
+ return waitForSpendableDust(facade, minimumDust, timeoutMs);
120
121
  }
121
122
  // A freshly composed local stack has a window where the indexer reports a
122
123
  // synced (empty) state before it has indexed the genesis block that funds the
@@ -135,7 +136,7 @@ const GENESIS_INDEX_TIMEOUT_MS = 120_000;
135
136
  * {@link ensureFeeReady}: a faucet-funded root needs its NIGHT registered for
136
137
  * dust generation before it holds any spendable DUST.
137
138
  *
138
- * @param config - The stack the root wallet connects to.
139
+ * @param wallets - The registry holding the root wallet.
139
140
  * @param rootSeed - The root wallet seed.
140
141
  * @param faucetUrl - The network's faucet URL for the underfunded message.
141
142
  * @returns The root's fee-ready funding snapshot.
@@ -144,62 +145,65 @@ const GENESIS_INDEX_TIMEOUT_MS = 120_000;
144
145
  * {@link waitForSpendableDust}): root is funded but not yet fee-ready, so
145
146
  * this is a plain error, not a funding stop.
146
147
  */
147
- export async function assertRootFunded(config, rootSeed, faucetUrl) {
148
- const keys = deriveAccountKeys(rootSeed, config.networkId);
149
- const addresses = deriveAddresses(keys, config.networkId);
150
- return withSyncedWalletFacade(keys, config, async (facade, state) => {
151
- let night = totalNight(state);
152
- if (night === 0n && isLocalStandaloneNetwork(config.networkId)) {
153
- const deadline = Date.now() + GENESIS_INDEX_TIMEOUT_MS;
154
- while (night === 0n && Date.now() < deadline) {
155
- await new Promise((resolve) => setTimeout(resolve, GENESIS_INDEX_POLL_INTERVAL_MS));
156
- state = await facade.waitForSyncedState();
157
- night = totalNight(state);
158
- }
159
- }
160
- if (night === 0n) {
161
- throw new WalletUnfundedError(addresses.unshielded, faucetUrl);
148
+ export async function assertRootFunded(wallets, rootSeed, faucetUrl) {
149
+ const { networkId } = wallets.config;
150
+ const { facade, keys } = await wallets.wallet(rootSeed, ROOT_LABEL);
151
+ const addresses = deriveAddresses(keys, networkId);
152
+ let state = await facade.waitForSyncedState();
153
+ let night = totalNight(state);
154
+ if (night === 0n && isLocalStandaloneNetwork(networkId)) {
155
+ const deadline = Date.now() + GENESIS_INDEX_TIMEOUT_MS;
156
+ while (night === 0n && Date.now() < deadline) {
157
+ await new Promise((resolve) => setTimeout(resolve, GENESIS_INDEX_POLL_INTERVAL_MS));
158
+ state = await facade.waitForSyncedState();
159
+ night = totalNight(state);
162
160
  }
163
- const dust = await ensureFeeReady(facade, keys, state, config.networkId, faucetUrl);
164
- return { addresses, night, dust };
165
- });
161
+ }
162
+ if (night === 0n) {
163
+ throw new WalletUnfundedError(addresses.unshielded, faucetUrl);
164
+ }
165
+ const dust = await ensureFeeReady(facade, keys, state, networkId, faucetUrl);
166
+ return { addresses, night, dust };
166
167
  }
167
168
  /**
168
169
  * Bring one child wallet to fee-ready by topping it up from root: if it holds
169
170
  * no NIGHT, transfer `amount` from root and wait for the child to see it, then
170
171
  * finish through {@link ensureFeeReady}. A child that already holds NIGHT but
171
- * no dust yet is only registered and waited on (no transfer). Call only for a
172
- * child that is not already fee-ready.
172
+ * no dust yet is registered and waited on. A sufficient DUST balance returns immediately.
173
173
  *
174
- * @param config - The stack both wallets connect to.
174
+ * @param wallets - The registry holding both wallets.
175
175
  * @param rootSeed - The funding wallet's seed.
176
176
  * @param childSeed - The child wallet's seed.
177
+ * @param childLabel - The child's role name, for the sync log.
177
178
  * @param amount - NIGHT to transfer when the child holds none, in base units.
179
+ * @param minimumDust - Required spendable DUST in SPECKs.
178
180
  * @returns The child's post-funding snapshot.
179
181
  * @throws {Error} If root cannot cover the transfer, or dust never appears in time.
180
182
  */
181
- export async function fundChildFromRoot(config, rootSeed, childSeed, amount) {
182
- const rootKeys = deriveAccountKeys(rootSeed, config.networkId);
183
- const childKeys = deriveAccountKeys(childSeed, config.networkId);
184
- const childAddresses = deriveAddresses(childKeys, config.networkId);
185
- const before = await withSyncedWalletFacade(childKeys, config, (_f, s) => Promise.resolve(totalNight(s)));
186
- if (before === 0n) {
187
- await withSyncedWalletFacade(rootKeys, config, async (rootFacade, rootState) => {
188
- await transferNight(rootFacade, rootKeys, rootState, childAddresses.unshielded, config.networkId, amount);
189
- });
183
+ export async function fundChildFromRoot(wallets, rootSeed, childSeed, childLabel, amount, minimumDust = 1n) {
184
+ const { networkId } = wallets.config;
185
+ const child = await wallets.wallet(childSeed, childLabel);
186
+ const childAddresses = deriveAddresses(child.keys, networkId);
187
+ let state = await child.facade.waitForSyncedState();
188
+ const available = state.dust.balance(new Date());
189
+ if (available >= minimumDust) {
190
+ console.log(`${childLabel}: available ${formatDust(available)} DUST, required ${formatDust(minimumDust)} DUST, funding skipped`);
191
+ return { addresses: childAddresses, night: totalNight(state), dust: available };
190
192
  }
191
- return withSyncedWalletFacade(childKeys, config, async (childFacade, childState) => {
192
- // Wait for the transferred NIGHT UTXO to land in the child's synced view.
193
- let state = childState;
194
- for (let i = 0; i < 40 && totalNight(state) === 0n; i++) {
195
- await new Promise((resolve) => setTimeout(resolve, 3_000));
196
- state = await childFacade.waitForSyncedState();
197
- }
198
- if (totalNight(state) === 0n) {
199
- throw new Error(`child wallet ${childAddresses.unshielded} shows no NIGHT after funding from root`);
200
- }
201
- const dust = await ensureFeeReady(childFacade, childKeys, state, config.networkId);
202
- return { addresses: childAddresses, night: totalNight(state), dust };
203
- });
193
+ if (totalNight(state) === 0n) {
194
+ const root = await wallets.wallet(rootSeed, ROOT_LABEL);
195
+ const rootState = await root.facade.waitForSyncedState();
196
+ await transferNight(root.facade, root.keys, rootState, childAddresses.unshielded, networkId, amount);
197
+ }
198
+ // Wait for the transferred NIGHT UTXO to land in the child's synced view.
199
+ for (let i = 0; i < 40 && totalNight(state) === 0n; i++) {
200
+ await new Promise((resolve) => setTimeout(resolve, 3_000));
201
+ state = await child.facade.waitForSyncedState();
202
+ }
203
+ if (totalNight(state) === 0n) {
204
+ throw new Error(`child wallet ${childAddresses.unshielded} shows no NIGHT after funding from root`);
205
+ }
206
+ const dust = await ensureFeeReady(child.facade, child.keys, state, networkId, undefined, minimumDust);
207
+ return { addresses: childAddresses, night: totalNight(state), dust };
204
208
  }
205
209
  //# sourceMapping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GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACxD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QACzD,MAAM,aAAa,CACjB,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,IAAI,EACT,SAAS,EACT,cAAc,CAAC,UAAU,EACzB,SAAS,EACT,MAAM,CACP,CAAC;IACJ,CAAC;IAED,0EAA0E;IAC1E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QACxD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QAC3D,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;IAClD,CAAC;IACD,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,gBAAgB,cAAc,CAAC,UAAU,yCAAyC,CACnF,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,cAAc,CAC/B,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,IAAI,EACV,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,CACZ,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;AACvE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { NetworkId as MidnightSDKNetworkId } from "@midnight-ntwrk/midnight-js/network-id";
2
- import { MidnightNetwork } from "@sig-net/midnight";
2
+ import { type DeployedNetwork, MidnightNetwork } from "@sig-net/midnight";
3
3
  export { MidnightNetwork };
4
4
  /** A Midnight network id: the SDK's bare-string type plus the named networks. */
5
5
  export type NetworkId = MidnightSDKNetworkId | MidnightNetwork;
@@ -17,4 +17,13 @@ export declare const NETWORK_IDS: readonly NetworkId[];
17
17
  * @returns Whether the genesis mint wallet holds spendable funds here.
18
18
  */
19
19
  export declare function isLocalStandaloneNetwork(networkId: NetworkId): boolean;
20
+ /** Every deployed network, the ones the SDK may publish counterparty values for. */
21
+ export declare const DEPLOYED_NETWORKS: readonly DeployedNetwork[];
22
+ /**
23
+ * Narrow a network id to a deployed network.
24
+ *
25
+ * @param networkId - The network to classify.
26
+ * @returns The same id as a {@link DeployedNetwork}, or undefined for the local standalone stack.
27
+ */
28
+ export declare function deployedNetwork(networkId: NetworkId): DeployedNetwork | undefined;
20
29
  //# sourceMappingURL=network-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"network-id.d.ts","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,IAAI,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,oBAAoB,GAAG,eAAe,CAAC;AAG/D,oEAAoE;AACpE,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAAmC,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAGtE"}
1
+ {"version":3,"file":"network-id.d.ts","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,IAAI,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAChG,OAAO,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,oBAAoB,GAAG,eAAe,CAAC;AAG/D,oEAAoE;AACpE,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAAmC,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAGtE;AAED,oFAAoF;AACpF,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAKvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,eAAe,GAAG,SAAS,CAMjF"}
@@ -18,4 +18,24 @@ export function isLocalStandaloneNetwork(networkId) {
18
18
  const undeployed = MidnightNetwork.Undeployed;
19
19
  return networkId === undeployed;
20
20
  }
21
+ /** Every deployed network, the ones the SDK may publish counterparty values for. */
22
+ export const DEPLOYED_NETWORKS = [
23
+ MidnightNetwork.Stagenet,
24
+ MidnightNetwork.Preview,
25
+ MidnightNetwork.Preprod,
26
+ MidnightNetwork.Mainnet,
27
+ ];
28
+ /**
29
+ * Narrow a network id to a deployed network.
30
+ *
31
+ * @param networkId - The network to classify.
32
+ * @returns The same id as a {@link DeployedNetwork}, or undefined for the local standalone stack.
33
+ */
34
+ export function deployedNetwork(networkId) {
35
+ const id = networkId;
36
+ return DEPLOYED_NETWORKS.find((network) => {
37
+ const candidate = network;
38
+ return candidate === id;
39
+ });
40
+ }
21
41
  //# sourceMappingURL=network-id.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"network-id.js","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,CAAC;AAK3B,+DAA+D;AAC/D,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAyB,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAoB;IAC3D,MAAM,UAAU,GAAc,eAAe,CAAC,UAAU,CAAC;IACzD,OAAO,SAAS,KAAK,UAAU,CAAC;AAClC,CAAC"}
1
+ {"version":3,"file":"network-id.js","sourceRoot":"","sources":["../../src/plumbing/network-id.ts"],"names":[],"mappings":"AAOA,OAAO,EAAwB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,CAAC;AAK3B,+DAA+D;AAC/D,oEAAoE;AACpE,MAAM,CAAC,MAAM,WAAW,GAAyB,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAoB;IAC3D,MAAM,UAAU,GAAc,eAAe,CAAC,UAAU,CAAC;IACzD,OAAO,SAAS,KAAK,UAAU,CAAC;AAClC,CAAC;AAED,oFAAoF;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAA+B;IAC3D,eAAe,CAAC,QAAQ;IACxB,eAAe,CAAC,OAAO;IACvB,eAAe,CAAC,OAAO;IACvB,eAAe,CAAC,OAAO;CACxB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,SAAoB;IAClD,MAAM,EAAE,GAAW,SAAS,CAAC;IAC7B,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACxC,MAAM,SAAS,GAAW,OAAO,CAAC;QAClC,OAAO,SAAS,KAAK,EAAE,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -2,7 +2,7 @@ import * as ledger from "@midnightntwrk/ledger-v9";
2
2
  import { type FacadeState, type TransactionIdentifier, WalletFacade } from "@midnightntwrk/wallet-sdk-facade";
3
3
  import { type UnshieldedKeystore } from "@midnightntwrk/wallet-sdk-unshielded-wallet";
4
4
  import type { MidnightNodeConfig } from "./midnight-node-config.ts";
5
- import type { NetworkId } from "./network-id.ts";
5
+ import { type NetworkId } from "./network-id.ts";
6
6
  export type { FacadeState, TransactionIdentifier, WalletFacade, } from "@midnightntwrk/wallet-sdk-facade";
7
7
  export type { EncPublicKey } from "@midnightntwrk/ledger-v9";
8
8
  /** The live key material for one account. Reused for signing / balancing. */
@@ -18,35 +18,42 @@ export interface WalletAddresses {
18
18
  dust: string;
19
19
  }
20
20
  /**
21
- * Default `additionalFeeOverhead` the facade balances transactions with: it
22
- * burns `feesWithMargin(params, feeBlocksMargin) + additionalFeeOverhead`
23
- * per transaction, so the overhead is burned as dust on EVERY submitted
24
- * transaction.
21
+ * The `additionalFeeOverhead` a facade balances with when its
22
+ * {@link WalletFacadeOptions} name none: 5e13 on the local standalone chain,
23
+ * whose dust is free, and 0 on every deployed network, whose dust is scarce.
25
24
  *
26
- * The overhead compensates for the wallet sdk pricing a PROOF-ERASED
27
- * transaction while the node prices the real proof bytes. The node's fee
28
- * consequently exceeds the wallet's estimate by an amount that grows with
29
- * proof size, and the node rejects the spend with
30
- * Malformed(BalanceCheckOverspend) when the wallet under-provides. 5e13
31
- * covers the gap this repo's circuits produce, with headroom, and the excess
32
- * is simply burned dust. The default is tuned for local fakenet chains where
33
- * dust is free: real-network deploys may want a lower value (see
34
- * {@link WalletFacadeOptions}).
25
+ * @param networkId - The network the facade connects to.
26
+ * @returns The overhead burned as dust on top of every transaction's estimated fee.
35
27
  */
36
- export declare const DEFAULT_ADDITIONAL_FEE_OVERHEAD = 50000000000000n;
28
+ export declare function defaultAdditionalFeeOverhead(networkId: NetworkId): bigint;
37
29
  /**
38
30
  * Optional tuning knobs for {@link initialiseWalletFacade} (and
39
- * {@link withSyncedWalletFacade}, which passes them through).
31
+ * {@link withSyncedWalletFacade} and {@link WalletRegistry}, which pass them
32
+ * through).
40
33
  */
41
34
  export interface WalletFacadeOptions {
42
35
  /**
43
36
  * Flat fee overhead added on top of the estimated fee of every submitted
44
37
  * transaction, burned as dust each time. Defaults to
45
- * {@link DEFAULT_ADDITIONAL_FEE_OVERHEAD} (5e13), which is tuned for local
46
- * fakenet chains: real-network deploys may want it lower.
38
+ * {@link defaultAdditionalFeeOverhead} for the facade's network.
47
39
  */
48
40
  additionalFeeOverhead?: bigint;
49
41
  }
42
+ /** The DUST a facade refusal reports holding and needing, in base units. */
43
+ export interface DustShortfall {
44
+ /** The DUST the facade found available to the refused call. */
45
+ readonly have: bigint;
46
+ /** The DUST the refused call needs. */
47
+ readonly need: bigint;
48
+ }
49
+ /**
50
+ * The amounts a facade refusal names when it refuses for lack of DUST.
51
+ *
52
+ * @param error - What a facade call threw.
53
+ * @returns The named shortfall, or undefined for a refusal that names no
54
+ * amount and for any other error.
55
+ */
56
+ export declare function dustShortfall(error: unknown): DustShortfall | undefined;
50
57
  /**
51
58
  * Parse a seed and derive the three role keys (Zswap / NightExternal / Dust).
52
59
  * Pure crypto — no network. This is the step that exercises the ledger WASM.
@@ -75,6 +82,31 @@ export declare function deriveAddresses(keys: AccountKeys, networkId: NetworkId)
75
82
  * @returns The constructed facade, not yet syncing.
76
83
  */
77
84
  export declare function initialiseWalletFacade(keys: AccountKeys, config: MidnightNodeConfig, options?: WalletFacadeOptions): Promise<WalletFacade>;
85
+ /**
86
+ * Wait until the wallet's spendable DUST (fee) balance reaches `minimumDust`,
87
+ * polling the synced facade state and logging each reading. Pair with
88
+ * {@link registerNightForDustGeneration}: a wallet whose NIGHT was just
89
+ * registered has no dust for a few blocks.
90
+ *
91
+ * @param facade - A started wallet facade.
92
+ * @param minimumDust - The spendable DUST to wait for, in base units (1 = any dust at all).
93
+ * @param timeoutMs - Give-up deadline in milliseconds.
94
+ * @returns The first spendable dust balance at or above `minimumDust`.
95
+ * @throws {Error} If the balance stays below `minimumDust` for `timeoutMs`.
96
+ */
97
+ export declare function waitForSpendableDust(facade: WalletFacade, minimumDust: bigint, timeoutMs?: number): Promise<bigint>;
98
+ /**
99
+ * The fee the facade prices a serialized unproven transaction at: the
100
+ * ledger's fee with the facade's block margin plus the network's overhead
101
+ * (see {@link defaultAdditionalFeeOverhead}). The balancing inputs the
102
+ * facade adds at submission carry a further small fee, so this is the floor
103
+ * of what submitting the transaction burns.
104
+ *
105
+ * @param facade - A started facade, whose network sets the overhead.
106
+ * @param serializedTransaction - The unproven transaction bytes.
107
+ * @returns The transaction's fee in DUST base units.
108
+ */
109
+ export declare function estimateUnprovenTransactionFee(facade: WalletFacade, serializedTransaction: Uint8Array): Promise<bigint>;
78
110
  /**
79
111
  * Balance, sign, prove and submit a serialized unproven transaction (e.g. a
80
112
  * contract deploy built by `buildDeployTransaction` in deploy.ts). Proving
@@ -111,26 +143,20 @@ export declare function transferNight(facade: WalletFacade, keys: AccountKeys, s
111
143
  * wallet can pay transaction fees (fees are paid in DUST, which only
112
144
  * generates on registered NIGHT). Registers ONLY unregistered UTXOs — the
113
145
  * node rejects a re-registration of an already-registered one — and submits
114
- * nothing when there is nothing new to register.
146
+ * nothing when there is nothing new to register. A first-time registration
147
+ * pays its own fee out of the dust its NIGHT UTXOs have generated since they
148
+ * landed, and a UTXO that landed moments ago has not yet generated it: the
149
+ * facade refuses naming the shortfall (see {@link dustShortfall}), and this
150
+ * waits for exactly that amount to generate before registering again.
115
151
  *
116
152
  * @param facade - A started wallet facade for `keys` (builds, proves and submits the registration).
117
153
  * @param keys - The key material of the same wallet; its unshielded keystore signs the registration.
118
154
  * @param state - The synced facade state to read the NIGHT UTXOs from.
119
155
  * @returns How many NIGHT UTXOs this call registered (0 = nothing unregistered, including no NIGHT at all).
120
- * @throws {Error} If the node rejects the registration transaction.
156
+ * @throws {Error} If the fee does not generate within {@link GENERATED_DUST_TIMEOUT_MS}, or
157
+ * the node rejects the registration transaction.
121
158
  */
122
159
  export declare function registerNightForDustGeneration(facade: WalletFacade, keys: AccountKeys, state: FacadeState): Promise<number>;
123
- /**
124
- * Wait until the wallet's spendable DUST (fee) balance is positive, polling
125
- * the synced facade state. Pair with {@link registerNightForDustGeneration}:
126
- * a wallet whose NIGHT was just registered has no dust for a few blocks.
127
- *
128
- * @param facade - A started wallet facade.
129
- * @param timeoutMs - Give-up deadline in milliseconds.
130
- * @returns The first positive dust balance observed.
131
- * @throws {Error} If no dust appears within `timeoutMs`.
132
- */
133
- export declare function waitForSpendableDust(facade: WalletFacade, timeoutMs?: number): Promise<bigint>;
134
160
  /**
135
161
  * Run `fn` against a started-and-synced {@link WalletFacade}, then stop the
136
162
  * facade — even when `fn` throws. The one place the start / wait-for-sync /
@@ -144,4 +170,57 @@ export declare function waitForSpendableDust(facade: WalletFacade, timeoutMs?: n
144
170
  * @throws {Error} Whatever {@link initialiseWalletFacade}, the facade start/sync, or `fn` throws.
145
171
  */
146
172
  export declare function withSyncedWalletFacade<T>(keys: AccountKeys, config: MidnightNodeConfig, fn: (facade: WalletFacade, state: FacadeState) => Promise<T>, options?: WalletFacadeOptions): Promise<T>;
173
+ /** A wallet a {@link WalletRegistry} holds started and synced. */
174
+ export interface RegisteredWallet {
175
+ /** The wallet's role name, as logged. */
176
+ readonly label: string;
177
+ /** The wallet's key material, for balancing and signing. */
178
+ readonly keys: AccountKeys;
179
+ /** The started facade. Later `waitForSyncedState()` calls catch it up incrementally. */
180
+ readonly facade: WalletFacade;
181
+ }
182
+ /**
183
+ * The dedup key a {@link WalletRegistry} files a seed under: its normalised
184
+ * hex, so two spellings of one seed (0x-prefixed, upper case, a mnemonic and
185
+ * its derived hex) share a facade.
186
+ *
187
+ * @param seed - The wallet seed, as hex or a BIP-39 mnemonic.
188
+ * @returns The seed's normalised hex.
189
+ * @throws {ParseError} If the seed parses as neither form.
190
+ */
191
+ export declare function walletRegistryKey(seed: string): string;
192
+ /**
193
+ * One started, synced facade per wallet for the life of a pipeline: the
194
+ * first request for a seed builds, starts and fully syncs its facade (the
195
+ * expensive step on a deployed network, where a fresh facade scans the chain
196
+ * from nothing), every later request returns the same running facade, whose
197
+ * `waitForSyncedState()` only catches up incrementally. {@link close} stops
198
+ * every facade once, at the end.
199
+ */
200
+ export declare class WalletRegistry {
201
+ readonly config: MidnightNodeConfig;
202
+ private readonly options;
203
+ private readonly wallets;
204
+ /**
205
+ * @param config - The stack every facade in the registry connects to.
206
+ * @param options - Facade tuning passed to every facade built here.
207
+ */
208
+ constructor(config: MidnightNodeConfig, options?: WalletFacadeOptions);
209
+ /**
210
+ * The started, synced wallet for `seed`, built on first request.
211
+ *
212
+ * @param seed - The wallet seed, as hex or a BIP-39 mnemonic.
213
+ * @param label - The wallet's role name, used in the sync log lines.
214
+ * @returns The registered wallet.
215
+ * @throws {Error} Whatever building, starting or syncing the facade throws. The
216
+ * failed entry is dropped, so a later request retries.
217
+ */
218
+ wallet(seed: string, label: string): Promise<RegisteredWallet>;
219
+ private open;
220
+ /**
221
+ * Stop every facade the registry opened. Safe to call more than once and
222
+ * with nothing opened.
223
+ */
224
+ close(): Promise<void>;
225
+ }
147
226
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/plumbing/wallet.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AAWnD,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,qBAAqB,EAE1B,YAAY,EACb,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,6CAA6C,CAAC;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKjD,YAAY,EACV,WAAW,EACX,qBAAqB,EACrB,YAAY,GACb,MAAM,kCAAkC,CAAC;AAI1C,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,kBAAkB,EAAE,MAAM,CAAC,eAAe,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC;IACpC,kBAAkB,EAAE,kBAAkB,CAAC;CACxC;AAED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