@ninsei-labs/sdk 0.56.1 → 0.58.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 (73) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE-POLICY.md +9 -2
  3. package/README.md +78 -28
  4. package/THIRD_PARTY_NOTICES.md +176 -2
  5. package/assets/vendors/MANIFEST.json +1 -13
  6. package/assets/vendors/sdk/sdk-browser.js +5 -4
  7. package/engine/atomic/dleq2.js +116 -15
  8. package/engine/atomic/order.js +21 -3
  9. package/engine/core/config.js +20 -46
  10. package/engine/core/deployments.generated.js +103 -0
  11. package/engine/core/rfqSource.js +6 -133
  12. package/engine/core/swap.js +8 -8
  13. package/engine/evm/asyncRoute.js +1 -1
  14. package/engine/evm/claimGas.js +2 -1
  15. package/engine/evm/escrow.js +13 -8
  16. package/engine/evm/factory.js +11 -6
  17. package/engine/evm/funding.js +8 -3
  18. package/engine/evm/index.js +5 -6
  19. package/engine/evm/session.js +48 -279
  20. package/engine/monero/address.js +15 -33
  21. package/engine/monero/keys.js +124 -0
  22. package/engine/monero/mnemonic.js +104 -0
  23. package/engine/monero/scan.js +121 -28
  24. package/engine/monero/wallet.js +31 -68
  25. package/engine/monero/wordlist.en.js +210 -0
  26. package/engine/recovery/restore.js +9 -9
  27. package/engine/sdk/bridge.js +9 -187
  28. package/engine/ui/walletModal.js +7 -27
  29. package/index.d.ts +234 -262
  30. package/package.json +7 -6
  31. package/src/actions.mjs +8 -5
  32. package/src/codes.mjs +17 -0
  33. package/src/config.mjs +17 -54
  34. package/src/engine.mjs +9 -6
  35. package/src/feeEstimate.mjs +11 -4
  36. package/src/http.mjs +4 -1
  37. package/src/index.mjs +24 -45
  38. package/src/legs/kyber.mjs +23 -0
  39. package/src/lock.mjs +1 -0
  40. package/src/order.mjs +110 -22
  41. package/src/primitives.mjs +4 -5
  42. package/src/probes.mjs +9 -3
  43. package/src/public/networks.d.ts +45 -0
  44. package/src/public/networks.mjs +10 -1
  45. package/src/public/recovery.d.ts +17 -1
  46. package/src/public/recovery.mjs +1 -0
  47. package/src/public/xmr.mjs +1 -1
  48. package/src/quotePolicy.mjs +25 -0
  49. package/src/quotes.mjs +109 -765
  50. package/src/readyWindow.mjs +76 -0
  51. package/src/recovery-key.mjs +71 -16
  52. package/src/recovery.mjs +11 -28
  53. package/src/relayClaim.mjs +132 -0
  54. package/src/relayFeatures.mjs +25 -13
  55. package/src/relayFirmClient.mjs +36 -7
  56. package/src/relayQuote.mjs +92 -11
  57. package/src/relayView.mjs +3 -3
  58. package/src/swap-flow.mjs +146 -60
  59. package/src/swaps.mjs +521 -357
  60. package/src/sweep-action.mjs +73 -0
  61. package/src/sweep-restore.mjs +8 -4
  62. package/src/sweep.mjs +12 -2
  63. package/src/version.mjs +1 -1
  64. package/src/xmr-arrival.mjs +328 -29
  65. package/src/xmrAmountPolicy.mjs +35 -0
  66. package/assets/vendors/atomic/atomic-browser.js +0 -24
  67. package/assets/vendors/monero/monero-js-browser.js +0 -58
  68. package/assets/vendors/monero-js/LICENSE +0 -9
  69. package/assets/vendors/walletconnect/wc-browser.js +0 -6202
  70. package/engine/atomic/order-client.js +0 -56
  71. package/engine/atomic/order-worker.js +0 -156
  72. package/engine/evm/asyncExec.js +0 -577
  73. package/engine/evm/asyncLegs.js +0 -308
@@ -1,20 +1,10 @@
1
- // GENERATED FILE - a byte-for-byte copy of the engine module www/js/core/rfqSource.js for the SDK package.
2
- // Edit the source under www/js and regenerate the mirror; a drift guard reddens on any difference.
3
- // Everything below this header is identical to the source.
1
+ // THE ORDER-QUOTE MIRROR OF www/js/core/rfqSource.js. The SDK copy drops the indicative quote book that the page
2
+ // still uses: the bridge helpers it called are gone. Keep the order-quote path in sync with the source.
4
3
 
5
- // LIVE INDICATIVE QUOTES FROM OUR PROVIDER - THROUGH THE SDK CORE.
6
- // WHY THROUGH THE CORE, NOT OUR OWN REQUEST. The read rules (zero = "no direction", staleness by the quote own
7
- // stamp, a self-contradicting row) used to live here and, separately, in the core, and two editions of one rule
8
- // diverge silently. So the book now comes from the CORE: watch - quotes.watch, snapshot - quotes.snapshot, and
9
- // the shape is translated by the bridge. NO selection rule is left here: the core decides. Core silence or
10
- // refusal gives an EMPTY book.
11
- // THE SNAPSHOT SHAPE, in short: no STEPS (one RANGE, one price); one quote KIND - quoteKind is gone, the only
12
- // firm quote is the order one; rate: 0 means "direction disabled" with a why, and zero is NEVER a price; the
13
- // network is part of the market identity and is checked against ours; seq and at travel with the quote for
14
- // freshness; the SIZE is in units of the ASSET (the first pair element).
15
- //
16
- //
17
- import { API, DEFAULT_CHAIN } from "./config.js";
4
+ // THE ORDER QUOTE FOR THE EXECUTOR FALLBACK. This module no longer carries the indicative quote book: the SDK has
5
+ // no book path, and the bridge helpers it called (`sdkBook`, `sdkBookSnapshot`) are gone. What remains is the
6
+ // order quote the executor asks for when it has to fall back to the provider, and its shape check.
7
+ import { API } from "./config.js";
18
8
 
19
9
  // QUOTE FOR A SPECIFIC ORDER (orderQuote). The request goes THROUGH OUR BACKEND, not straight to the provider
20
10
  // node: a direct request would require CORS headers, i.e. a node exposed to the internet. Our backend routes
@@ -56,120 +46,3 @@ export function checkOrderQuoteShape(quote) {
56
46
 
57
47
  let baseOverride = null;
58
48
  const apiBase = () => baseOverride || API.base;
59
-
60
- // WHAT WE ASK THE CORE. The side and SIZE are in units of the ASSET; the network and token let the core pick ITS
61
- // instance. No numbers appear here: the size comes from the screen, aligned to the provider grid.
62
- let query = { size: 1, side: "buy", chain: DEFAULT_CHAIN, token: null };
63
- export function setRfqQuery(next) {
64
- if (!next) return;
65
- if (next.side === "buy" || next.side === "sell") query.side = next.side;
66
- // NO QUOTE KIND IN THE REQUEST anymore: the second kind does not exist.
67
- if (next.size !== null && next.size !== undefined && Number(next.size) > 0) query.size = Number(next.size);
68
- else query.size = 1; // no amount entered - ask for one ASSET unit, not "nothing"
69
- if (typeof next.chain === "string" && next.chain) query.chain = next.chain;
70
- if (typeof next.token === "string" && next.token) query.token = next.token;
71
- }
72
-
73
- // The current request: the screen needs to know the side and size asked for, else it cannot tell "the provider is
74
- // silent" from "the provider does not take this size".
75
- export function rfqQuery() {
76
- return { ...query };
77
- }
78
-
79
- // THE SNAPSHOT THE SCREENS READ: { ok, error, data, at }. In data - references and best, while offers and
80
- // refusals come from rfqOffers(). If the core was never polled or refused, there is no data, shown by ok.
81
- // Old numbers are not pasted as "live".
82
- const snapshot = { ok: false, error: null, data: null, at: 0, fetching: false };
83
- export function rfqSnapshot() {
84
- return snapshot;
85
- }
86
-
87
- // The pair the user SEES: buying XMR means the pairs XMR/<asset>; selling means the reverse.
88
- export function pairFacingUser(side = query.side, asset = "ETH") {
89
- return side === "sell" ? asset.toUpperCase() + "/XMR" : "XMR/" + asset.toUpperCase();
90
- }
91
-
92
- // PAIR SIDES ARE READ BY POSITION: the first element is the ASSET (the size is measured in it), the second is
93
- // the CURRENCY (what is paid). Separate functions, because this is a convention.
94
- export function pairAsset(pair) {
95
- return String(pair || "").split("/")[0].toUpperCase();
96
- }
97
- export function pairCurrency(pair) {
98
- return String(pair || "").split("/")[1] ? String(pair).split("/")[1].toUpperCase() : "";
99
- }
100
-
101
- // OFFERS AND REFUSALS - FROM THE CORE SNAPSHOT, NO SECOND SELECTION. The core already split the rows into
102
- // offers and refusals and named the best. Here they are only transferred: no own filtering, sorting or
103
- // thresholds. An empty snapshot is an empty book.
104
- export function rfqOffers() {
105
- const data = snapshot.ok && snapshot.data ? snapshot.data : null;
106
- if (!data) return { offers: [], refused: [], seq: null, at: null };
107
- return {
108
- offers: data.offers || [],
109
- refused: data.refused || [],
110
- seq: data.seq === undefined ? null : data.seq,
111
- at: data.at === undefined ? null : data.at,
112
- };
113
- }
114
-
115
- // CHECKING THE QUOTE NETWORK AGAINST OURS. The network is part of the market identity: arbitrum and
116
- // arbitrum-sepolia are ONE WORD FOR DIFFERENT MONEY, and a wallet does not move coins between them. The side
117
- // holding XMR must speak Monero, the other the EVM registry language (its id). We return a verdict, not a
118
- // throw: one quote refusal does not close the market.
119
- export function quoteNetworksFit(quote, { monero, evm }) {
120
- const xmrOnAsset = quote.asset === "XMR";
121
- const xmrOnCurrency = quote.currency === "XMR";
122
- if (!xmrOnAsset && !xmrOnCurrency) return { ok: false, stated: quote.networkStated, why: "pair " + quote.pair + " has no XMR on either side" };
123
- const moneroNet = xmrOnAsset ? quote.assetNetwork : quote.currencyNetwork;
124
- const evmNet = xmrOnAsset ? quote.currencyNetwork : quote.assetNetwork;
125
- const moneroSide = xmrOnAsset ? "assetNetwork" : "currencyNetwork";
126
- const evmSide = xmrOnAsset ? "currencyNetwork" : "assetNetwork";
127
- if (moneroNet && moneroNet !== monero) {
128
- return { ok: false, stated: true, why: quote.pair + ": " + moneroSide + " is " + moneroNet + ", but this page pays XMR on " + monero };
129
- }
130
- if (evmNet && evmNet !== evm) {
131
- return { ok: false, stated: true, why: quote.pair + ": " + evmSide + " is " + evmNet + ", but this page settles on " + evm };
132
- }
133
- // NOT NAMED - DOES NOT MEAN "OURS". There is nothing to compare, and that is logged, but we do not close the
134
- // market for it: the rule catches a network NAMED WRONG, not a missing field.
135
- return { ok: true, stated: quote.networkStated, moneroNet: moneroNet || null, evmNet: evmNet || null, why: null };
136
- }
137
-
138
- // POLLING GOES THROUGH THE CORE. The bridge hands the core what it needs (network, size, direction) and returns
139
- // the TRANSLATED snapshot. The core is loaded DYNAMICALLY: this module is also read without a browser, and then
140
- // the book is simply not requested. A load failure IS a failure, not a reason to take the book elsewhere.
141
- export async function refreshRfq() {
142
- if (snapshot.fetching) return snapshot;
143
- snapshot.fetching = true;
144
- try {
145
- const bridge = await import("../sdk/bridge.js");
146
- await bridge.sdkBook({ chain: query.chain, direction: query.side, token: query.token, size: query.size });
147
- const next = bridge.sdkBookSnapshot();
148
- snapshot.ok = next.ok;
149
- snapshot.error = next.error;
150
- snapshot.data = next.data;
151
- snapshot.at = next.at || Date.now();
152
- } catch (error) {
153
- // A REFUSAL IS NOT REPLACED BY OLD NUMBERS: showing a stale price as live is worse than saying there is no
154
- // connection. No data is left at all.
155
- snapshot.ok = false;
156
- snapshot.error = String((error && error.message) || error);
157
- snapshot.data = null;
158
- snapshot.at = Date.now();
159
- } finally {
160
- snapshot.fetching = false;
161
- }
162
- return snapshot;
163
- }
164
-
165
- let timer = null;
166
-
167
- // ALWAYS POLL. The poll is not to "catch a new price": it confirms the provider is there. The core holds the
168
- // poll for the subscription; this tick keeps the book updating with the screen. Node silence shows as a missing
169
- // fresh stamp, not as "the price is the same".
170
- export function startRfqPolling(chain = null, ms = API.pollMs) {
171
- if (typeof chain === "string" && chain) query.chain = chain;
172
- if (timer) return;
173
- refreshRfq();
174
- timer = setInterval(() => refreshRfq(), ms);
175
- }
@@ -132,7 +132,7 @@ export function createSwap(input, store = null) {
132
132
  //
133
133
  // WHAT THE REVERSE DEAL DOES DIFFERENTLY. On the buy flow the PAGE funds the escrow, and the counterparty's half
134
134
  // is only learned after settlement. On the sell flow the PROVIDER funds the escrow, the page merely requests the
135
- // order, and it computes ITS OWN halves (atomic/order-worker.js, newMakerMaterial). So fields are named by side:
135
+ // order, and it computes ITS OWN halves (atomic/order.js, newMakerMaterial). So fields are named by side:
136
136
  // our half is `half`, and the DEPOSITOR's (provider's) point and view half are counterSpendPoint/counterView*.
137
137
  // The page does not know the depositor's SPEND half and must not: the contract publishes it on settlement, and
138
138
  // only then does the sweep of our own XMR open up (see refundHalfRevealed).
@@ -219,7 +219,7 @@ export function halvesWalletOf(swap) {
219
219
  if (!e.half || !e.viewHalf || !e.counterViewHalf || !e.moneroAddress) return null;
220
220
  return {
221
221
  source: "halves",
222
- library: "monero-js",
222
+ library: "ninsei-monero-keys",
223
223
  network: e.moneroNetwork || MONERO.networkType,
224
224
  address: e.moneroAddress,
225
225
  subaddress: null,
@@ -519,17 +519,17 @@ export function derive(swap, now = nowReal()) {
519
519
  }
520
520
  } else if (live && readyAt === null && chainReadyByMs !== null && nowReal() >= chainReadyByMs
521
521
  && (chainT1Ms === null || nowReal() < chainT1Ms)) {
522
- // THE DEAD ZONE IS REAL, AND THE CONTRACT DOES NOT OPEN THE REFUND IN IT. `refund()` rejects a call before
523
- // `t1` when `block.timestamp >= readyBy` and `ready` is false; the same rule keeps the claim closed without the
524
- // mark. Nothing can be signed between `readyBy` and `t1`, so the screen must not offer a refund that reverts.
522
+ // THE DEAD ZONE IS ABOUT THE REFUND, NOT THE CLAIM. `refund()` rejects a call before `t1` when
523
+ // `block.timestamp >= readyBy` and `ready` is false; the claim is open at `readyBy` even without the mark. The
524
+ // screen must not offer a refund that reverts.
525
525
  phase = "dead_zone";
526
526
  phaseLabel = "Ready deadline passed - the refund opens at T1";
527
527
  can.ready = false;
528
528
  can.refund = false;
529
529
  can.refundByAnyone = false;
530
- note = "The ready() deadline has passed without your confirmation, so the maker cannot claim - and the " +
531
- "escrow refuses a refund before T1 while the mark is absent. Nothing can be signed now; the refund opens " +
532
- "at T1 and returns your ETH and publishes your half. " +
530
+ note = "The ready() deadline has passed without your confirmation. The maker can claim now, and the escrow " +
531
+ "refuses a refund before T1 while the mark is absent. The refund opens at T1 and returns your ETH and " +
532
+ "publishes your half. " +
533
533
  (chainT1Ms !== null ? "T1: " + new Date(chainT1Ms).toISOString() + "." : "");
534
534
  } else if (live && readyAt === null) {
535
535
  // Live mode: Monero-leg states come from the backend. The simulated EVM-leg timeouts (T0/T1, watchtower)
@@ -18,7 +18,7 @@
18
18
  // refuses native as an order asset). So a wrapped provider is NEVER chosen as the sole provider for a native need:
19
19
  // it is a LIQUIDITY leg, and the route to native is a COMPOSITION of two orders - the liquidity leg (token -> WETH)
20
20
  // and a native leg on a native-capable provider (WETH -> native coin, CoW). The choice returns a route record or a
21
- // composition; the composition is EXECUTED in evm/asyncExec.js, which pays the second leg's own fee out of the
21
+ // composition; the composition is EXECUTED by the package provider layer, which pays the second leg's own fee out of the
22
22
  // reserve so the person is not sent into a composition that leaves them short of the deposit.
23
23
  //
24
24
  // IT MIRRORS THE PACKAGE'S PROVIDER LAYER ON PURPOSE. The move to async lives in the SDK package
@@ -12,7 +12,8 @@
12
12
  // cost plus an EXPLICIT margin for base-fee growth between ticket and claim.
13
13
 
14
14
  // THE CLAIM GAS LIMIT IS ONE NUMBER ON BOTH SIDES. MEASURED: an honest claim costs 120 721 gas on a live chain,
15
- // more than the old 120 000, which cut off legitimate claims. The limit has a margin: 200 000.
15
+ // more than the old 120 000, which cut off legitimate claims. The limit has a margin: 200 000. The Arbitrum L1
16
+ // share of a tipped claim was not part of that measurement.
16
17
  export const CLAIM_GAS_LIMIT = 200_000n;
17
18
 
18
19
  // THE TIP FLOOR IS NETWORK POLICY, NOT A CONSTANT IN THE SENDING CODE. A fixed 1 gwei minimum inflated
@@ -142,26 +142,31 @@ export function encodeRead(name) {
142
142
  return sel;
143
143
  }
144
144
 
145
+ const strictWord = (returnedHex, what, words) => {
146
+ if (typeof returnedHex !== "string" || !/^0x[0-9a-fA-F]*$/.test(returnedHex)) {
147
+ throw new Error("invalid " + what + ": " + returnedHex);
148
+ }
149
+ const hex = returnedHex.slice(2);
150
+ if (hex.length !== words * 64) throw new Error("short answer " + what + ": " + returnedHex);
151
+ return hex.toLowerCase();
152
+ };
153
+
145
154
  // Parse a bytes32 answer: one word.
146
155
  export function decodeBytes32(returnedHex, what = "value") {
147
- const hex = String(returnedHex || "").replace(/^0x/, "");
148
- if (hex.length < 64) throw new Error("short answer " + what + ": " + returnedHex);
149
- return "0x" + hex.slice(0, 64).toLowerCase();
156
+ return "0x" + strictWord(returnedHex, what, 1);
150
157
  }
151
158
 
152
159
  // Parse the t1() answer: one word, uint64 inside uint256.
153
160
  export function decodeUint64(returnedHex, what = "value") {
154
- const hex = String(returnedHex || "").replace(/^0x/, "");
155
- if (hex.length < 64) throw new Error("short answer " + what + ": " + returnedHex);
156
- const v = BigInt("0x" + hex.slice(0, 64));
161
+ const hex = strictWord(returnedHex, what, 1);
162
+ const v = BigInt("0x" + hex);
157
163
  if (v > 18446744073709551615n) throw new Error("answer " + what + " does not fit in uint64: " + v);
158
164
  return Number(v);
159
165
  }
160
166
 
161
167
  // Parse the status() answer: four 32-byte words - three flags and the balance.
162
168
  export function decodeStatus(returnedHex) {
163
- const hex = String(returnedHex || "").replace(/^0x/, "");
164
- if (hex.length < 256) throw new Error("short status() answer: " + returnedHex);
169
+ const hex = strictWord(returnedHex, "status()", 4);
165
170
  const word = (i) => hex.slice(i * 64, (i + 1) * 64);
166
171
  return {
167
172
  isFunded: BigInt("0x" + word(0)) !== 0n,
@@ -129,11 +129,18 @@ export function encodeCreateOrderAndFund(quote) {
129
129
  return FACTORY_METHODS.createOrderAndFund + quoteCallArgs(quote);
130
130
  }
131
131
 
132
+ const strictWord = (returnedHex, what, words = 1) => {
133
+ if (typeof returnedHex !== "string" || !/^0x[0-9a-fA-F]*$/.test(returnedHex)) {
134
+ throw new Error("invalid " + what + ": " + returnedHex);
135
+ }
136
+ const hex = returnedHex.slice(2);
137
+ if (hex.length !== words * 64) throw new Error("short answer: " + returnedHex);
138
+ return hex.toLowerCase();
139
+ };
140
+
132
141
  // predict() answer - one address in a 32-byte word.
133
142
  export function decodeAddress(returnedHex) {
134
- const hex = String(returnedHex || "").replace(/^0x/, "");
135
- if (hex.length < 64) throw new Error("short answer: " + returnedHex);
136
- return "0x" + hex.slice(24, 64);
143
+ return "0x" + strictWord(returnedHex, "predict()").slice(24, 64);
137
144
  }
138
145
 
139
146
 
@@ -167,9 +174,7 @@ export function decodeImplementation(returnedHex) {
167
174
 
168
175
  // implementationCodeHash() - one bytes32 word.
169
176
  export function decodeImplementationCodeHash(returnedHex) {
170
- const hex = String(returnedHex || "").replace(/^0x/, "");
171
- if (hex.length < 64) throw new Error("short answer from implementationCodeHash(): " + returnedHex);
172
- return "0x" + hex.slice(0, 64).toLowerCase();
177
+ return "0x" + strictWord(returnedHex, "implementationCodeHash()");
173
178
  }
174
179
 
175
180
  // VERDICT ON THE IMPLEMENTATION - the same three conditions the factory checks:
@@ -213,7 +213,7 @@ async function waitReceipt(receiptReader, hash, { tries = 12, delayMs = 1500 } =
213
213
 
214
214
  // The full funding path. Steps are returned outward so the interface can show each one: predict is a free call,
215
215
  // createOrder and lock are transactions in the user's wallet.
216
- export async function fundOrder({ factory, locker, claimer, commitHalfLocker, commitHalfClaimer, edPointLocker, edPointClaimer, edViewPointLocker, salt: providedSalt, amountWei, amountLabel, claimWindowSeconds, readyWindowSeconds, readyBy, t1, quote, call, send, receipt, onStep }) {
216
+ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, commitHalfClaimer, edPointLocker, edPointClaimer, edViewPointLocker, salt: providedSalt, amountWei, amountLabel, claimWindowSeconds, readyWindowSeconds, readyBy, t1, quote, call, send, receipt, onStep, onPredicted }) {
217
217
  if (!factory) throw new Error("no escrow factory address set for this network");
218
218
  if (!locker) throw new Error("no EVM wallet connected: there is nobody to deposit");
219
219
  if (!claimer) throw new Error("the order recipient (claimer) is not set");
@@ -245,7 +245,9 @@ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, co
245
245
  // code. Here that is guaranteed because both predict and createOrderAndFund are built from THE SAME terms: they
246
246
  // can diverge only if one of the two places is edited alone. They already did once (the preimage was missing from
247
247
  // the prediction); the cure is a shared source of fields, not care.
248
- // THE DEPOSITOR'S FIELDS GO AS SEPARATE FACTORY ARGUMENTS (they are not in the signed set).
248
+ // THE DEPOSITOR'S FIELDS GO AS SEPARATE FACTORY ARGUMENTS, BUT THEY ARE IN THE SIGNED SET. Since quote protocol v10
249
+ // the factory signs them; the overwrite below must reproduce the signed values, or the digest check rejects the
250
+ // creation.
249
251
  const quoteEnc = { ...quote, commitHalfLocker: terms.commitHalfLocker, edPointLocker: terms.edPointLocker, edViewPointLocker: terms.edViewPointLocker };
250
252
  // QUOTE AND TERMS ARE ABOUT ONE THING: a divergence moves the escrow address and signs the wrong order.
251
253
  // THE COUNTERPARTY'S SPEND HALF IS PART OF THAT ONE THING. The proof is checked against the counterparty side,
@@ -284,7 +286,6 @@ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, co
284
286
  }
285
287
  const escrowState = escrowStateVerdict({ status: stateRead.status, error: stateRead.error, address: escrow });
286
288
  if (escrowState.blocks) throw new Error("signature not started: " + escrowState.reason);
287
-
288
289
  // 2) ONE TRANSACTION: creating the order TOGETHER with the deposit.
289
290
  //
290
291
  // It used to be two steps (createOrder, then lock) with two defects, both seen live: the wallet estimated the
@@ -312,6 +313,10 @@ export async function fundOrder({ factory, locker, claimer, commitHalfLocker, co
312
313
  // WHICH FACTORY DOOR THE DEPOSIT GOES THROUGH. There is ONE path: createOrderAndFund, where the wallet that
313
314
  // sends the transaction becomes the locker. The sender may not change the order terms - the quote signature
314
315
  // covers THE SAME digest the escrow checks.
316
+ // THE PREDICTED ADDRESS IS WRITTEN TO THE CALLER'S RECORD BEFORE THE TRANSACTION. A receipt can take longer than
317
+ // the process that sent it; a record saved only after the wait leaves nothing to resume from, and the retry asks
318
+ // for a second deposit. The callback runs after every refusal and immediately before the send.
319
+ if (typeof onPredicted === "function") await onPredicted({ escrow, salt, terms });
315
320
  const createData = encodeCreateOrderAndFund(quoteEnc);
316
321
  const createHash = await send({
317
322
  to: factory,
@@ -3,7 +3,8 @@
3
3
  // Everything below this header is identical to the source.
4
4
 
5
5
  // The wallet used by the demo interface.
6
- // One implementation: WalletConnect (www/js/evm/walletconnect.js) - the user's real wallet, real balances.
6
+ // One implementation: the injected EIP-1193 browser wallet (www/js/evm/session.js) - the user's real wallet,
7
+ // real balances. Mobile connectors are loaded by the host page and passed in as the same provider.
7
8
  // The built-in demo wallet and its mode switch were removed: we are heading to a real product, not a mockup.
8
9
  // Still NO transfers: there is no escrow contract yet and the address is mocked (mock/chain.js), so funding
9
10
  // is a simulation (simulateEscrowFunding below); provider.sendTransaction will replace it.
@@ -38,10 +39,8 @@ export * from "./permit.js";
38
39
  // THE ASYNCHRONOUS ROUTE, EXECUTED - through the same engine seam as the decision that chooses it. The page reaches
39
40
  // it through the bridge; the SDK carries the same module in its engine mirror (tools/build-sdk-engine.mjs).
40
41
  export * from "./asyncRoute.js";
41
- export * from "./asyncExec.js";
42
- // THE LIQUIDITY LEG OF A COMPOSED ROUTE (KyberSwap Limit Order) - through the same engine seam as the CoW leg,
43
- // so the page and the SDK carry one implementation each.
44
- export * from "./asyncLegs.js";
42
+ // THE EXECUTOR IS THE PACKAGE'S PROVIDER LAYER (src/legs/cow.mjs and its siblings). The generated mirror that
43
+ // used to execute the route here carried a second submit/status path; it was removed with the order worker.
45
44
 
46
45
  // currentProvider - the wallet provider goes OUT to the SDK core (evm-wallet.mjs) so signing uses the same
47
46
  // key as the page. Screens do not need it; they read status()/isConnected().
@@ -53,7 +52,7 @@ import { sendTransaction, readContract, readReceipt, readCode } from "./session.
53
52
  export { sendTransaction, readContract, readReceipt, readCode };
54
53
 
55
54
  // The browser wallets available here (EIP-6963, falling back to window.ethereum). An empty list is normal:
56
- // no extension, so WalletConnect remains.
55
+ // no extension is installed; the host can still bring its own connector and pass its provider to the SDK.
57
56
  export function wallets() {
58
57
  return discoverWallets();
59
58
  }