@integraledger/profile-facilitator 0.5.0 → 0.6.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 (55) hide show
  1. package/CHANGELOG.md +556 -0
  2. package/README.md +754 -111
  3. package/dist/core.d.ts +1 -1
  4. package/dist/core.js +683 -66
  5. package/dist/http.d.ts +19 -4
  6. package/dist/http.js +16 -6
  7. package/dist/module.d.ts +111 -24
  8. package/dist/module.js +39 -0
  9. package/dist/modules/algorand/index.js +1 -1
  10. package/dist/modules/aptos/index.js +1 -1
  11. package/dist/modules/cardano/index.js +1 -1
  12. package/dist/modules/casper/index.js +15 -3
  13. package/dist/modules/concordium/index.js +1 -1
  14. package/dist/modules/erc7710/index.d.ts +8 -5
  15. package/dist/modules/erc7710/index.js +1111 -34
  16. package/dist/modules/evm/escrow.d.ts +125 -0
  17. package/dist/modules/evm/escrow.js +619 -0
  18. package/dist/modules/evm/forms.d.ts +39 -11
  19. package/dist/modules/evm/forms.js +191 -25
  20. package/dist/modules/evm/index.d.ts +41 -6
  21. package/dist/modules/evm/index.js +1135 -20
  22. package/dist/modules/evm/node.d.ts +16 -1
  23. package/dist/modules/evm/node.js +181 -26
  24. package/dist/modules/evm/nonce-proof.d.ts +186 -0
  25. package/dist/modules/evm/nonce-proof.js +779 -0
  26. package/dist/modules/hedera/executor.js +1 -1
  27. package/dist/modules/hedera/index.js +1 -1
  28. package/dist/modules/lnbtc/index.js +3 -2
  29. package/dist/modules/near/index.js +1 -1
  30. package/dist/modules/polkadot/index.js +1 -1
  31. package/dist/modules/solana/index.d.ts +3 -0
  32. package/dist/modules/solana/index.js +119 -10
  33. package/dist/modules/solana/reader.d.ts +2 -1
  34. package/dist/modules/solana/reader.js +42 -4
  35. package/dist/modules/solana/upto-claim.d.ts +58 -0
  36. package/dist/modules/solana/upto-claim.js +269 -0
  37. package/dist/modules/starknet/index.js +9 -2
  38. package/dist/modules/stellar/index.d.ts +5 -0
  39. package/dist/modules/stellar/index.js +18 -8
  40. package/dist/modules/stellar/node.d.ts +7 -1
  41. package/dist/modules/stellar/node.js +51 -7
  42. package/dist/modules/sui/index.js +66 -20
  43. package/dist/modules/sui/node.d.ts +13 -0
  44. package/dist/modules/sui/node.js +60 -0
  45. package/dist/modules/ton/index.js +6 -2
  46. package/dist/modules/tron/index.js +1 -1
  47. package/dist/modules/xrpl/index.js +61 -12
  48. package/dist/modules/xrpl/node.d.ts +31 -2
  49. package/dist/modules/xrpl/node.js +88 -17
  50. package/dist/modules/xrpl/upto.js +106 -20
  51. package/dist/record.d.ts +52 -8
  52. package/dist/record.js +39 -5
  53. package/dist/wrapper.d.ts +7 -5
  54. package/dist/wrapper.js +7 -5
  55. package/package.json +4 -3
@@ -4,17 +4,28 @@
4
4
  * x402 specifies the method and leaves the `permissionContext` opaque, and no published facilitator class settles it,
5
5
  * so the module is the settler's own: it simulates the redemption the payment names, and then sends it, calling
6
6
  * `redeemDelegations` on the delegation manager the payload names with one single-call execution that transfers the
7
- * option's amount of its asset to `payTo`. Its key is the seller's gas key, which must be the delegate the leaf
8
- * delegation names (or the reference implementation's wildcard delegate); it sends the transaction and pays its gas.
7
+ * option's amount of its asset to `payTo`. The redemption is signed first: the module keeps the signed bytes, and the
8
+ * record holds their hash before they are sent, so a repeat can send exactly those bytes again, replace them at the same
9
+ * nonce with a higher fee where the node holds them unmined below the base fee, or, where one finalized block shows that a
10
+ * different transaction took their nonce (`nonceProof`), retire the hash. A redemption is one sale's for good: the sale
11
+ * it was signed for is kept by its hash after it is mined, until a finalized block shows its nonce taken, and nothing
12
+ * signed below that nonce is sent again. Its key is the seller's gas key, which must be the delegate the leaf delegation
13
+ * names (or the reference implementation's wildcard delegate); it sends the transaction and pays its gas.
9
14
  * It registers nothing of its own: it is offered to the `exact` registration the `evm` module makes on each of its
10
15
  * networks, which hands it every payment whose option names `erc7710`, and the settler does not start where the `evm`
11
16
  * module does not register `exact` on such a network.
12
17
  */
13
18
  import { decodePermissionContext } from "@integraledger/lcp/evm";
14
- import { isRefusal } from "@integraledger/lcp";
15
- import { encodeFunctionData, encodePacked, getAddress, isAddress, isHex } from "viem";
16
- import { admit, ERC7710_PAIRINGS, instrumentOf, readOf } from "../evm/forms.js";
17
- import { chargedFrom, evmReader } from "../evm/node.js";
19
+ import { digestJson, isRefusal } from "@integraledger/lcp";
20
+ import { exactErc7710 } from "@integraledger/lcp/x402";
21
+ import { encodeFunctionData, encodePacked, getAddress, isAddress, isHex, keccak256, parseTransaction, recoverTransactionAddress } from "viem";
22
+ import { outcomeOf } from "../../module.js";
23
+ import { admit, delegationOf, ERC7710_PAIRINGS, instrumentOf, readOf } from "../evm/forms.js";
24
+ import { chargedFrom, evmReader, rpcCall } from "../evm/node.js";
25
+ import { anchorsIn, finalizedReceipt, nonceProof, passedAtFinalized, registerAnchors } from "../evm/nonce-proof.js";
26
+ import { NODE_TIMEOUT_MS, sleep } from "../../http.js";
27
+ import { unexpectedSettle } from "../../unexpected.js";
28
+ import { ownReceipt } from "../evm/index.js";
18
29
  /** The reference implementation's wildcard delegate, which any redeemer may redeem as. */
19
30
  const ANY_DELEGATE = "0x0000000000000000000000000000000000000a11";
20
31
  /** keccak256("Transfer(address,address,uint256)"). */
@@ -85,9 +96,693 @@ function transfers(logs, r) {
85
96
  l.data.length === 66 &&
86
97
  BigInt(l.data) === r.amount);
87
98
  }
88
- /** The module's own facilitator for x402's `erc7710` method. */
89
- function facilitatorOf(c) {
99
+ /**
100
+ * Where the module keeps the signed bytes of a redemption it named, by their hash. Kept after the redemption is mined,
101
+ * until the finalized chain shows its own receipt (`prune`).
102
+ */
103
+ function keptAt(transaction) {
104
+ return `signed:${transaction.toLowerCase()}`;
105
+ }
106
+ /**
107
+ * Where the module keeps the sale a signed redemption was named for, by its hash: one transaction, one sale. Kept
108
+ * after the redemption is mined, until the floor of the key that signed it is above its nonce (`Owned`) and the
109
+ * finalized chain was read to show what took that nonce, or was read `UNREAD_TRIES` times without showing it (`prune`).
110
+ */
111
+ function ownerAt(transaction) {
112
+ return `sale:${transaction.toLowerCase()}`;
113
+ }
114
+ /**
115
+ * Where the module keeps, by the hash of each redemption signed at one nonce, every hash signed at it (`Signed`). Kept
116
+ * as long as that redemption's signed bytes are.
117
+ */
118
+ function nonceAt(transaction) {
119
+ return `nonce:${transaction.toLowerCase()}`;
120
+ }
121
+ /**
122
+ * Where the module keeps, for one key on one network, the redemptions signed with it whose owner record stands, and
123
+ * the nonce below which it sends nothing signed with that key (`Owned`).
124
+ */
125
+ function ownedAt(network, key) {
126
+ return `owned:${network}:${key.toLowerCase()}`;
127
+ }
128
+ /**
129
+ * Where the module keeps, for one network, the keys whose owner records are listed (`ownedAt`), each an address in
130
+ * lower case: every key a redemption was listed under, so that the records of a key the settler no longer signs with
131
+ * are removed as its own are (`prune`). A key stays named.
132
+ */
133
+ function keysAt(network) {
134
+ return `keys:${network}`;
135
+ }
136
+ /** How long a settle waits for the removal of the records the finalized chain has passed, in milliseconds; it goes on after. */
137
+ const PRUNE_WAIT_MS = 250;
138
+ /**
139
+ * How many times the fate of a listed redemption below the floor is read and not shown (`prune`) before its owner
140
+ * record goes as that of one whose nonce another transaction took: its signed bytes stay.
141
+ */
142
+ const UNREAD_TRIES = 8;
143
+ function isOwned(v) {
144
+ return (typeof v === "object" &&
145
+ v !== null &&
146
+ typeof v.floor === "string" &&
147
+ /^[0-9]+$/.test(v.floor) &&
148
+ Array.isArray(v.signed) &&
149
+ v.signed.every((e) => Array.isArray(e) &&
150
+ (e.length === 2 || (e.length === 3 && typeof e[2] === "string" && /^[0-9]+$/.test(e[2]))) &&
151
+ typeof e[0] === "string" &&
152
+ /^[0-9]+$/.test(e[0]) &&
153
+ typeof e[1] === "string"));
154
+ }
155
+ /** How often a write that lost to another writer of the same record is made again from what the store then holds. */
156
+ const SWAP_TRIES = 64;
157
+ function isSigned(v) {
158
+ return typeof v === "object" && v !== null && Array.isArray(v.hashes) && v.hashes.every((h) => typeof h === "string");
159
+ }
160
+ /** The fee a replacement at the same nonce must at least raise by, as nodes take one: an eighth, above their tenth. */
161
+ function raised(fee) {
162
+ return fee + fee / 8n + 1n;
163
+ }
164
+ /** Where the module marks the one redemption it has in flight under a mark key (`markOf`). */
165
+ function flightAt(mark) {
166
+ return `flight:${mark}`;
167
+ }
168
+ /**
169
+ * What a redemption in flight is marked under, so that one redemption under it is in flight at a time: the root
170
+ * delegator, the payload's `delegator`, whose funds the transfer moves, on the network. Every redemption that draws on
171
+ * what that delegator signed or holds shares it: two leaves under one root delegation whose caveats allow one more call,
172
+ * and two delegations of one delegator whose balance holds one more price. The one place the mark's key is chosen.
173
+ */
174
+ function markOf(delegation, network) {
175
+ return { network, delegator: delegation["delegator"] };
176
+ }
177
+ function isKeys(v) {
178
+ return Array.isArray(v) && v.every((k) => typeof k === "string");
179
+ }
180
+ function isFlight(v) {
181
+ return typeof v === "object" && v !== null && typeof v.sale === "string" && typeof v.since === "number";
182
+ }
183
+ /** How often a settle waiting on another sale's redemption under its mark looks again, in milliseconds. */
184
+ const FLIGHT_POLL_MS = 200;
185
+ /** A transaction count or a nonce as the node answers it. */
186
+ function quantity(v, what) {
187
+ if (typeof v !== "string" || !/^0x[0-9a-fA-F]+$/.test(v))
188
+ throw new TypeError(`the node's ${what} is not a quantity`);
189
+ return BigInt(v);
190
+ }
191
+ function isObject(v) {
192
+ return typeof v === "object" && v !== null && !Array.isArray(v);
193
+ }
194
+ async function fateOf(rpc, signed, at, deadline) {
195
+ const transaction = keccak256(signed);
196
+ const t = await rpcCall(rpc, "eth_getTransactionByHash", [transaction], deadline);
197
+ if (isObject(t)) {
198
+ const cap = t["maxFeePerGas"] ?? t["gasPrice"];
199
+ return { held: { mined: t["blockNumber"] !== null && t["blockNumber"] !== undefined, feeCap: typeof cap === "string" ? quantity(cap, "fee cap") : undefined } };
200
+ }
201
+ const nonce = BigInt(parseTransaction(signed).nonce ?? 0);
202
+ const from = await recoverTransactionAddress({ serializedTransaction: signed });
203
+ const since = at.since === undefined ? undefined : BigInt(at.since);
204
+ const proof = await nonceProof(rpc, from, nonce, [...at.hashes, transaction], { deadline, ...(since === undefined ? {} : { from: since }) });
205
+ if (proof.answer === "taken-by-another")
206
+ return "gone";
207
+ if (proof.answer === "ours")
208
+ return proof.transaction === transaction.toLowerCase() ? "landed" : "gone";
209
+ if (proof.reason !== "not-finalized")
210
+ return "unknown";
211
+ // A node can answer a `pending` count below its own `latest` count for a moment after a block: the nonce is the key's
212
+ // next only where neither count has passed it.
213
+ const pending = quantity(await rpcCall(rpc, "eth_getTransactionCount", [from, "pending"], deadline), "pending transaction count");
214
+ const latest = quantity(await rpcCall(rpc, "eth_getTransactionCount", [from, "latest"], deadline), "transaction count");
215
+ return { open: { next: pending <= nonce && latest <= nonce } };
216
+ }
217
+ /**
218
+ * The module's own facilitator for x402's `erc7710` method, and the record's resend of a redemption it named: `naming`
219
+ * keeps a transaction in the record before it is sent, and `state` keeps its signed bytes, the sale each hash was named
220
+ * for, and the one redemption in flight under each mark (`markOf`).
221
+ */
222
+ function facilitatorOf(c, core) {
90
223
  const signer = c.signer;
224
+ /** The digests of the mark an admitted payment's redemption is held under and of its sale (the record's key); else undefined. */
225
+ async function keysOf(payload, requirements) {
226
+ const p = { payload, requirements };
227
+ const a = await admit("erc7710", p, ERC7710_PAIRINGS);
228
+ if ("refused" in a)
229
+ return undefined;
230
+ const d = delegationOf(p, a);
231
+ const h = a.ref?.["h"];
232
+ const mark = await digestJson(markOf(d, requirements.network));
233
+ const sale = await digestJson({ ...d, h: typeof h === "string" ? h.toLowerCase() : "" });
234
+ return isRefusal(mark) || isRefusal(sale) ? undefined : { mark: mark, sale: sale };
235
+ }
236
+ /**
237
+ * Every redemption signed at the nonce of the one `transaction` names, as the record under the first of them holds
238
+ * them (`Signed`); that one alone where none is kept.
239
+ */
240
+ async function signedAt(transaction) {
241
+ const kept = await core.state.get(nonceAt(transaction));
242
+ if (!isSigned(kept))
243
+ return { hashes: [transaction.toLowerCase()] };
244
+ const first = kept.hashes[0];
245
+ if (first === undefined || first.toLowerCase() === transaction.toLowerCase())
246
+ return kept;
247
+ const whole = await core.state.get(nonceAt(first));
248
+ return isSigned(whole) && whole.hashes.some((h) => h.toLowerCase() === transaction.toLowerCase()) ? whole : kept;
249
+ }
250
+ /**
251
+ * Writes what `change` makes of the redemptions signed at the nonce of `at`'s first, as the store holds them when it
252
+ * is written (`at` where it holds none), under each of their hashes; two writers never lose one another's. A store
253
+ * call that fails rejects.
254
+ */
255
+ async function revise(at, change) {
256
+ const first = at.hashes[0];
257
+ if (first === undefined)
258
+ return at;
259
+ for (let i = 0; i < SWAP_TRIES; i++) {
260
+ const stored = await core.state.get(nonceAt(first));
261
+ const next = change(isSigned(stored) ? stored : at);
262
+ if (!(await core.state.swap(nonceAt(first), stored, next)))
263
+ continue;
264
+ for (const h of next.hashes.slice(1))
265
+ await core.state.set(nonceAt(h), next);
266
+ return next;
267
+ }
268
+ throw new Error("the redemptions signed at a nonce could not be written");
269
+ }
270
+ /**
271
+ * Whether the redemptions signed at the nonce of `transaction` are still those `judged`, which a proof was made
272
+ * against: another sale's settle lists a replacement there before it sends it (`moveOn`), so a proof that met one
273
+ * listed since it was read took it for another payment's transaction, and retires nothing. A store call that fails
274
+ * rejects.
275
+ */
276
+ async function stillAsJudged(transaction, judged) {
277
+ const now = await signedAt(transaction);
278
+ return (now.unnamed ?? []).length === 0 && now.hashes.length === judged.hashes.length && now.hashes.every((h, i) => h.toLowerCase() === judged.hashes[i]?.toLowerCase());
279
+ }
280
+ /** The address the gas key signs from, lowercase; undefined where it gives none. */
281
+ function ownKey() {
282
+ return signer.getAddresses()[0]?.toLowerCase();
283
+ }
284
+ /** The owner records of `key` on the network (`Owned`); none, and a floor of 0, where none is kept. */
285
+ async function ownedOf(key) {
286
+ const stored = await core.state.get(ownedAt(c.network, key));
287
+ return isOwned(stored) ? stored : { floor: "0", signed: [] };
288
+ }
289
+ /**
290
+ * Lists `transaction`, signed by `key` at `nonce`, among the key's owner records, before its owner record is written,
291
+ * so that every owner record is listed and is removed once the floor passes its nonce (`prune`). A store call that
292
+ * fails rejects.
293
+ */
294
+ async function listOwned(key, nonce, transaction) {
295
+ const hash = transaction.toLowerCase();
296
+ // The key is named among the network's keys before its list is written, and stays named.
297
+ const named = async () => {
298
+ for (let i = 0; i < SWAP_TRIES; i++) {
299
+ const stored = await core.state.get(keysAt(c.network));
300
+ const keys = isKeys(stored) ? stored : [];
301
+ if (keys.includes(key.toLowerCase()))
302
+ return;
303
+ if (await core.state.swap(keysAt(c.network), stored, [...keys, key.toLowerCase()]))
304
+ return;
305
+ }
306
+ throw new Error("the keys of the network could not be written");
307
+ };
308
+ await named();
309
+ for (let i = 0; i < SWAP_TRIES; i++) {
310
+ const stored = await core.state.get(ownedAt(c.network, key));
311
+ const current = isOwned(stored) ? stored : { floor: "0", signed: [] };
312
+ if (current.signed.some(([, h]) => h === hash))
313
+ return;
314
+ if (await core.state.swap(ownedAt(c.network, key), stored, { floor: current.floor, signed: [...current.signed, [nonce.toString(), hash]] }))
315
+ return;
316
+ }
317
+ throw new Error("the owner records of the key could not be written");
318
+ }
319
+ /**
320
+ * Removes the owner records that can no longer matter, of the gas key and of each earlier key the network's keys
321
+ * name (`keysAt`), so that they do not grow with the sales. For each key (`pruneOf`) it
322
+ * reads the key's transaction count at the block the node names `finalized`, by that block's hash; raises the floor
323
+ * to it, in the store, first; and only then removes each owner record whose nonce is below the stored floor, and
324
+ * takes it off the list. A node behind answers a lower count, which raises nothing and removes nothing. Where the
325
+ * node serves no state at that block, the count there is shown by a receipt instead: a listed redemption's own
326
+ * receipt that the finalized chain shows (`finalizedReceipt`), mined or reverted, shows its nonce, and every one
327
+ * below it, taken at a finalized block, so the count there is above its nonce; the highest such nonce counts, and
328
+ * none shown raises nothing. What is left is one record for each redemption signed at a nonce the finalized chain
329
+ * has not passed, and one for each below it whose fate could not be read. With an owner record go the signed bytes
330
+ * and the nonce record of its redemption, where the finalized chain shows that redemption's own receipt: a receipt
331
+ * at the head does not remove them, since the chain can drop its block. Where one finalized block shows that another
332
+ * transaction took its nonce (`nonceProof`), the owner record goes and the bytes and the nonce record stay, so that
333
+ * a repeat reads its fate and retires it (`resend`); they are not removed after it. Where neither is shown (a read
334
+ * failed or ran out of time, the node does not hold the block), nothing of it is removed and it stays listed, for
335
+ * the next call; after `UNREAD_TRIES` reads that showed neither, its owner record goes as that of one whose nonce
336
+ * was taken, its bytes staying. A failure goes to the log, and the records stay.
337
+ */
338
+ async function prune(network) {
339
+ let keys = [];
340
+ try {
341
+ const stored = await core.state.get(keysAt(c.network));
342
+ if (isKeys(stored))
343
+ keys = stored;
344
+ }
345
+ catch (e) {
346
+ core.log({ event: "owner-records-not-pruned", network }, e);
347
+ }
348
+ const own = ownKey();
349
+ // A key stays named: one whose list is empty costs one read, and another settler may be writing its list.
350
+ for (const key of new Set([...(own === undefined ? [] : [own]), ...keys]))
351
+ await pruneOf(network, key);
352
+ }
353
+ /** `prune` for the owner records of one key, the one the settler signs with or an earlier one. */
354
+ async function pruneOf(network, key) {
355
+ try {
356
+ if ((await ownedOf(key)).signed.length === 0)
357
+ return;
358
+ const deadline = performance.now() + NODE_TIMEOUT_MS;
359
+ const finalized = await rpcCall(c.rpc, "eth_getBlockByNumber", ["finalized", false], deadline);
360
+ if (!isObject(finalized) || typeof finalized["hash"] !== "string" || !isHex(finalized["hash"]))
361
+ return;
362
+ let count;
363
+ try {
364
+ count = quantity(await rpcCall(c.rpc, "eth_getTransactionCount", [key, { blockHash: finalized["hash"], requireCanonical: true }], deadline), "transaction count");
365
+ }
366
+ catch (e) {
367
+ // Those at or above the stored floor only: one below it left unread shows no receipt, and is no part of the
368
+ // prefix the search halves. Nothing shown raises nothing, and those below the floor are still read.
369
+ const owned = await ownedOf(key);
370
+ count = await countShown(owned.signed.filter(([n]) => BigInt(n) >= BigInt(owned.floor)), deadline);
371
+ if (count === 0n && !owned.signed.some(([n]) => BigInt(n) < BigInt(owned.floor)))
372
+ throw e;
373
+ }
374
+ for (let i = 0; i < SWAP_TRIES; i++) {
375
+ // A pass that lost its write to another settle's is made again only while there is time to read in.
376
+ if (i > 0 && performance.now() >= deadline)
377
+ return;
378
+ const stored = await core.state.get(ownedAt(c.network, key));
379
+ if (!isOwned(stored))
380
+ return;
381
+ const floor = BigInt(stored.floor) > count ? BigInt(stored.floor) : count;
382
+ const below = stored.signed.filter(([n]) => BigInt(n) < floor);
383
+ if (below.length === 0 && floor === BigInt(stored.floor))
384
+ return;
385
+ // The floor first: an owner record goes only once the store holds a floor above its nonce.
386
+ if (floor !== BigInt(stored.floor)) {
387
+ await core.state.swap(ownedAt(c.network, key), stored, { floor: floor.toString(), signed: stored.signed });
388
+ continue;
389
+ }
390
+ // Those below the floor whose fate the finalized chain did not show as read stay listed, with all of theirs, each
391
+ // with the number of reads that showed nothing; a read not begun for want of time is not counted.
392
+ const unread = new Map();
393
+ const done = async (h, landed) => {
394
+ // What was signed goes with the owner record only where the finalized chain shows that redemption itself: one
395
+ // whose nonce another transaction took keeps its bytes, so that a repeat reads its fate.
396
+ if (landed) {
397
+ await core.state.delete(keptAt(h));
398
+ await core.state.delete(nonceAt(h));
399
+ }
400
+ await core.state.delete(ownerAt(h));
401
+ };
402
+ // The receipts first, a few reads each, so that those that landed go whatever the proofs of the others take.
403
+ const left = [];
404
+ for (const e of below) {
405
+ if (!isHex(e[1]) || (await finalizedReceipt(c.rpc, e[1], deadline)) !== undefined)
406
+ await done(e[1], true);
407
+ else
408
+ left.push(e);
409
+ }
410
+ // Those read least often first, so that one whose proof takes all the time is the last read; and a read is
411
+ // counted where it began with time left, so that the one that took the time is the one it is counted against.
412
+ const triesOf = (e) => Number(e[2] ?? "0");
413
+ for (const e of [...left].sort((x, y) => triesOf(x) - triesOf(y))) {
414
+ const [n, h] = e;
415
+ const began = performance.now() < deadline;
416
+ const shown = began ? await shownFinal(key, BigInt(n), h, deadline) : "unread";
417
+ if (shown !== "unread")
418
+ await done(h, shown === "landed");
419
+ else if (!began)
420
+ unread.set(h, triesOf(e));
421
+ else if (triesOf(e) + 1 >= UNREAD_TRIES)
422
+ await done(h, false);
423
+ else
424
+ unread.set(h, triesOf(e) + 1);
425
+ }
426
+ const kept = stored.signed.flatMap((e) => {
427
+ if (BigInt(e[0]) >= floor)
428
+ return [e];
429
+ const tries = unread.get(e[1]);
430
+ return tries === undefined ? [] : [tries === 0 ? [e[0], e[1]] : [e[0], e[1], tries.toString()]];
431
+ });
432
+ if (await core.state.swap(ownedAt(c.network, key), stored, { floor: stored.floor, signed: kept }))
433
+ return;
434
+ }
435
+ }
436
+ catch (e) {
437
+ core.log({ event: "owner-records-not-pruned", network }, e);
438
+ }
439
+ }
440
+ /**
441
+ * What one finalized block shows of the nonce `nonce` of `key`, which the key's count at a finalized block has
442
+ * passed, for the redemption `transaction` signed at it, whose own receipt the finalized chain was not read to show
443
+ * (`nonceProof`): `landed`, where that redemption took the nonce; `taken`, where another transaction did; `unread`,
444
+ * where it shows neither as read, a failed read and one past `deadline` among them. A store call that fails rejects.
445
+ */
446
+ async function shownFinal(key, nonce, transaction, deadline) {
447
+ const at = await signedAt(transaction);
448
+ const since = at.since === undefined ? undefined : BigInt(at.since);
449
+ const proof = await nonceProof(c.rpc, key, nonce, [...at.hashes, transaction], { deadline, ...(since === undefined ? {} : { from: since }) });
450
+ if (proof.answer === "ours")
451
+ return proof.transaction === transaction.toLowerCase() ? "landed" : "taken";
452
+ return proof.answer === "taken-by-another" ? "taken" : "unread";
453
+ }
454
+ /**
455
+ * The key's count at a finalized block as the owner records `signed` show it with no state: one more than a nonce at
456
+ * which a listed redemption's own receipt is on the finalized chain (`finalizedReceipt`); 0 where none is found. The
457
+ * listed nonces are searched by halves, since the newest are the ones not yet final: a few reads find a nonce near
458
+ * the highest so shown within the deadline. Any nonce found is so shown, whichever it is.
459
+ */
460
+ async function countShown(signed, deadline) {
461
+ const nonces = [...new Set(signed.map(([n]) => n))].map((n) => BigInt(n)).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
462
+ const shown = async (n) => {
463
+ for (const [m, h] of signed) {
464
+ if (BigInt(m) === n && isHex(h) && (await finalizedReceipt(c.rpc, h, deadline)) !== undefined)
465
+ return true;
466
+ }
467
+ return false;
468
+ };
469
+ let count = 0n;
470
+ for (let lo = 0, hi = nonces.length - 1; lo <= hi;) {
471
+ const mid = (lo + hi) >> 1;
472
+ if (await shown(nonces[mid])) {
473
+ count = nonces[mid] + 1n;
474
+ lo = mid + 1;
475
+ }
476
+ else
477
+ hi = mid - 1;
478
+ }
479
+ return count;
480
+ }
481
+ /**
482
+ * What the node shows of `transaction` by its hash: whether it is mined, and its fee cap; undefined where it shows
483
+ * none, which is no fact about it. A failed lookup rejects.
484
+ */
485
+ async function shownBy(transaction, deadline) {
486
+ const t = await rpcCall(c.rpc, "eth_getTransactionByHash", [transaction], deadline);
487
+ if (!isObject(t))
488
+ return undefined;
489
+ const cap = t["maxFeePerGas"] ?? t["gasPrice"];
490
+ return { mined: t["blockNumber"] !== null && t["blockNumber"] !== undefined, feeCap: typeof cap === "string" ? quantity(cap, "fee cap") : undefined };
491
+ }
492
+ /**
493
+ * Whether `key`'s count at the node's latest block has passed `nonce`: a transaction of that key at that nonce is
494
+ * mined, whichever it is, so nothing else at it can land, and what a redemption at it spent shows in the next
495
+ * simulation. A read that fails rejects.
496
+ */
497
+ async function minedAt(key, nonce, deadline) {
498
+ return quantity(await rpcCall(c.rpc, "eth_getTransactionCount", [key, "latest"], deadline), "transaction count") > nonce;
499
+ }
500
+ /**
501
+ * Whether the node's `pending` count for `key`, or its count at the latest block, is above `nonce`: the node holds a
502
+ * transaction of that key at that nonce, mined or in its pool, whichever scheme sent it. Both are read, since a node
503
+ * can answer a `pending` count below its own `latest` count for a moment after a block. Only where both are at or
504
+ * below `nonce` is none shown held there; a read that fails rejects.
505
+ */
506
+ async function heldAt(key, nonce, deadline) {
507
+ if (quantity(await rpcCall(c.rpc, "eth_getTransactionCount", [key, "pending"], deadline), "pending transaction count") > nonce)
508
+ return true;
509
+ return minedAt(key, nonce, deadline);
510
+ }
511
+ /**
512
+ * Whether `key`'s nonce `nonce` is taken for good: for the gas key, its count at the latest block has passed it
513
+ * (`minedAt`); for a key the settler no longer signs with, its count at the finalized block, read by that block's
514
+ * hash, has passed it (`passedAtFinalized`).
515
+ */
516
+ async function takenAt(key, nonce, deadline) {
517
+ return key === ownKey() ? minedAt(key, nonce, deadline) : passedAtFinalized(c.rpc, key, nonce, deadline);
518
+ }
519
+ /**
520
+ * Whether another sale's mark still stands. It ends only on a fact the node shows, never on its age or on a lookup
521
+ * that finds nothing:
522
+ * - its settle named no transaction and the hold has passed: nothing was sent under it, and that settle sends nothing
523
+ * once the mark has moved, since it names its transaction by swapping the mark it holds (`send`);
524
+ * - the redemption it names, or another signed at its nonce, is mined, by a receipt or by the node's answer for its
525
+ * hash; the gas key signed it and the key's count at the node's latest block has passed its nonce (`minedAt`); or
526
+ * its signed bytes are no
527
+ * longer kept, which follows only its receipt on the finalized chain (`prune`). A mined redemption, reverted or not, has taken its
528
+ * nonce, so what it spent shows in the next simulation;
529
+ * - one finalized block shows that it took its nonce or that another transaction did (`fateOf`), or the key's count
530
+ * at the finalized block, read by its hash, has passed its nonce: nothing at that nonce can land any more;
531
+ * - the gas key signed it, and the node's `pending` count shows no transaction of the key at its nonce, which is
532
+ * still the key's next (`fateOf` `open`): the mark passes on, naming that nonce and key, at which alone the sale
533
+ * taking it signs, so that of the two only one can land. A mark that lapsed naming a nonce passes on again only
534
+ * while the `pending` count still shows nothing held at it, and ends once that nonce is taken (`takenAt`).
535
+ * Anything else leaves it standing, however old: where the node holds a transaction of the key at that nonce and finds
536
+ * none by this hash, the redemption may still land, and a transaction another scheme sent at that nonce is not to be
537
+ * replaced. A redemption signed by a key the settler no longer signs with ends only on a receipt, the node's answer
538
+ * naming its block, or a finalized fact about that key's nonce.
539
+ */
540
+ async function stands(f, deadline) {
541
+ if (f.transaction === undefined) {
542
+ if (Date.now() - f.since < core.settleWaitMs)
543
+ return "stands";
544
+ if (f.at === undefined)
545
+ return "ended";
546
+ // A nonce named, nothing sent at it under this mark: ended once that nonce is taken (`takenAt`); passed on only
547
+ // while the node's pending count shows nothing of the key held at it.
548
+ const nonce = BigInt(f.at.nonce);
549
+ if (await takenAt(f.at.key, nonce, deadline))
550
+ return "ended";
551
+ if (f.at.key !== ownKey() || (await heldAt(f.at.key, nonce, deadline)))
552
+ return "stands";
553
+ return { at: nonce, key: f.at.key };
554
+ }
555
+ // Mined, it or another signed at its nonce (one it replaced, or its replacement): the nonce is taken.
556
+ const all = await signedAt(f.transaction);
557
+ for (const h of new Set([f.transaction.toLowerCase(), ...all.hashes.map((x) => x.toLowerCase())])) {
558
+ if ((await rpcCall(c.rpc, "eth_getTransactionReceipt", [h], deadline)) !== null)
559
+ return "ended";
560
+ }
561
+ const signed = await core.state.get(keptAt(f.transaction));
562
+ if (typeof signed !== "string" || !isHex(signed))
563
+ return "ended";
564
+ const nonce = BigInt(parseTransaction(signed).nonce ?? 0);
565
+ // The key that signed it, which may be one the settler no longer signs with.
566
+ const from = (await recoverTransactionAddress({ serializedTransaction: signed })).toLowerCase();
567
+ const own = from === ownKey();
568
+ if (own && (await minedAt(from, nonce, deadline)))
569
+ return "ended";
570
+ const fate = await fateOf(c.rpc, signed, all, deadline);
571
+ if (fate === "gone" || fate === "landed")
572
+ return "ended";
573
+ if (fate === "unknown")
574
+ return (await passedAtFinalized(c.rpc, from, nonce, deadline)) ? "ended" : "stands";
575
+ if ("held" in fate)
576
+ return fate.held.mined ? "ended" : "stands";
577
+ return own && fate.open.next ? { at: nonce, key: from } : "stands";
578
+ }
579
+ /**
580
+ * Takes the mark for this sale, waiting while another sale's stands, until `until` (a
581
+ * `performance.now()` time). The mark taken, or undefined where another sale's still stands then. A read or store
582
+ * call that fails rejects.
583
+ */
584
+ async function take(keys, until) {
585
+ const at = flightAt(keys.mark);
586
+ for (;;) {
587
+ const current = await core.state.get(at);
588
+ const standing = !isFlight(current) || current.sale === keys.sale ? "ended" : await stands(current, performance.now() + NODE_TIMEOUT_MS);
589
+ if (standing !== "stands") {
590
+ // The nonce the mark passes on with, or this sale's own mark's.
591
+ let named = typeof standing === "object" ? { nonce: standing.at.toString(), key: standing.key } : isFlight(current) && current.sale === keys.sale ? current.at : undefined;
592
+ // This sale's own mark names a nonce since taken: it binds no more.
593
+ if (typeof standing !== "object" && named !== undefined && (await takenAt(named.key, BigInt(named.nonce), performance.now() + NODE_TIMEOUT_MS)))
594
+ named = undefined;
595
+ const mine = { sale: keys.sale, since: Date.now(), ...(named === undefined ? {} : { at: named }) };
596
+ if (await core.state.swap(at, current, mine))
597
+ return mine;
598
+ continue;
599
+ }
600
+ if (performance.now() + FLIGHT_POLL_MS > until)
601
+ return undefined;
602
+ await sleep(FLIGHT_POLL_MS);
603
+ }
604
+ }
605
+ /**
606
+ * Gives the mark back where it is still `mine`; a failure goes to the log, and the mark then ends as `stands` shows.
607
+ * Where it names a nonce and nothing was sent under it (`unsent`), it stays, lapsed, naming that nonce, so that the
608
+ * next sale taking it signs at that nonce too: the redemption it passed on from may still land there.
609
+ */
610
+ async function free(keys, mine, network, unsent = false) {
611
+ try {
612
+ await core.state.swap(flightAt(keys.mark), mine, unsent && mine.at !== undefined ? { sale: mine.sale, since: 0, at: mine.at } : null);
613
+ }
614
+ catch (e) {
615
+ core.log({ event: "store-call-failed", network, call: "state" }, e);
616
+ }
617
+ }
618
+ /**
619
+ * Sends again, for the sale that owns them, the bytes this sale's signing gave where they are another sale's
620
+ * redemption (the level that signs no H gives two sales of one price the same call, and one nonce and one fee then the
621
+ * same transaction): a redemption that never reached the node, whose buyer does not ask again, would otherwise hold
622
+ * back every sale that signs those bytes. Only the very bytes kept, only where their sale's row was seen to name them
623
+ * (`Signed.named`), and only as that sale's own repeat sends them (`resend`): their nonce still the key's next, the
624
+ * finalized chain not past it, the node holding nothing there. The mark, which this sale holds, passes to the sale
625
+ * whose redemption it is, naming it, before the send. Nothing is named for this sale, which is answered as having
626
+ * sent nothing; its repeat signs its own redemption once the node shows that nonce taken. A failure goes to the log.
627
+ */
628
+ async function sendForOwner(network, signed, keys, mine) {
629
+ const transaction = keccak256(signed);
630
+ try {
631
+ const owner = await core.state.get(ownerAt(transaction));
632
+ const kept = await core.state.get(keptAt(transaction));
633
+ if (typeof owner !== "string" || owner === keys.sale || typeof kept !== "string" || kept.toLowerCase() !== signed.toLowerCase())
634
+ return;
635
+ const all = await signedAt(transaction);
636
+ if (all.named !== true)
637
+ return;
638
+ const fate = await fateOf(c.rpc, signed, all, performance.now() + NODE_TIMEOUT_MS);
639
+ if (typeof fate !== "object" || !("open" in fate) || !fate.open.next)
640
+ return;
641
+ if (!(await core.state.swap(flightAt(keys.mark), mine, { sale: owner, transaction, since: Date.now() })))
642
+ return;
643
+ core.log({ event: "sent-for-its-sale", network, transaction });
644
+ try {
645
+ await signer.sendRawTransaction({ serializedTransaction: signed });
646
+ }
647
+ catch (e) {
648
+ core.log({ event: "send-failed", network, transaction, named: "kept" }, e);
649
+ }
650
+ }
651
+ catch (e) {
652
+ core.log({ event: "read-failed", network, transaction }, e);
653
+ }
654
+ }
655
+ /**
656
+ * Sends the redemption, signed first, for the sale `keys` names, which holds the mark `mine`. The hash
657
+ * is taken for this sale alone: where another sale's redemption signed the same bytes (the level that signs no H
658
+ * gives two sales of one price the same call, and one nonce then the same transaction), nothing is sent, so that no
659
+ * transaction is ever two sales' payment; where those bytes are a redemption their own sale's row names and the node
660
+ * does not hold, they are sent for that sale (`sendForOwner`), and nothing is named for this one. Nothing is sent
661
+ * either where they are signed at a nonce below the floor of the key (`Owned`), which a finalized block showed
662
+ * taken: a signer answered by a node behind signs there. Its signed bytes are kept in the module's state, the mark names it, then
663
+ * its hash goes in the claim's record, and only then is it sent: where any of these cannot be kept, nothing is sent. A
664
+ * send that fails may still have reached the node (its answer lost, or a gateway that forwarded it and then answered
665
+ * an error), so it is read on by the hash, and a repeat sends the same bytes again; the hash is taken back only where
666
+ * the node shows the bytes can never land (`fateOf`). The transaction and the mark naming it; undefined where
667
+ * nothing was sent, which a repeat may settle: the signer failed to sign it (it reads the gas, the fees and the nonce
668
+ * from the node), the hash is another sale's, it is signed below the floor, the mark was lost, a call to the
669
+ * module's state failed, or the node shows the bytes can never land right after a send that failed.
670
+ */
671
+ async function send(r, network, keys, mine) {
672
+ const data = encodeFunctionData({ abi: REDEEM_ABI, functionName: "redeemDelegations", args: redeemCall(r) });
673
+ let signed;
674
+ let since;
675
+ try {
676
+ // The head before signing: the nonce the signer takes is not yet taken at or below it.
677
+ since = quantity(await rpcCall(c.rpc, "eth_blockNumber", [], performance.now() + NODE_TIMEOUT_MS), "block number");
678
+ }
679
+ catch (e) {
680
+ core.log({ event: "read-failed", network }, e);
681
+ }
682
+ if (mine.at !== undefined) {
683
+ // A nonce named: signed only by the key it is a nonce of, and only where the node's pending count, read now,
684
+ // shows no transaction of the key held at it, whichever scheme sent one, so that none is replaced.
685
+ if (mine.at.key !== ownKey()) {
686
+ core.log({ event: "nonce-of-another-key", network, nonce: mine.at.nonce });
687
+ return undefined;
688
+ }
689
+ let held;
690
+ try {
691
+ held = await heldAt(mine.at.key, BigInt(mine.at.nonce), performance.now() + NODE_TIMEOUT_MS);
692
+ }
693
+ catch (e) {
694
+ core.log({ event: "read-failed", network }, e);
695
+ return undefined;
696
+ }
697
+ if (held) {
698
+ core.log({ event: "nonce-held", network, nonce: mine.at.nonce });
699
+ return undefined;
700
+ }
701
+ }
702
+ try {
703
+ signed = await signer.signTransaction({ to: r.manager, data, ...(mine.at === undefined ? {} : { nonce: Number(mine.at.nonce) }) });
704
+ }
705
+ catch (e) {
706
+ core.log({ event: "sign-failed", network }, e);
707
+ return undefined;
708
+ }
709
+ // The mark passed on naming a nonce: signed at any other, it could land beside the redemption at that one.
710
+ if (mine.at !== undefined && BigInt(parseTransaction(signed).nonce ?? 0) !== BigInt(mine.at.nonce)) {
711
+ core.log({ event: "redemption-not-signed-at-nonce", network, nonce: mine.at.nonce });
712
+ return undefined;
713
+ }
714
+ const transaction = keccak256(signed);
715
+ const flight = { ...mine, transaction };
716
+ const nonce = BigInt(parseTransaction(signed).nonce ?? 0);
717
+ // The owner record is kept where nothing is sent, and after the redemption is mined: another settle of the same sale
718
+ // may have written it (it is found by reading as well as by writing) and named the same bytes, and a signer answered
719
+ // by a node behind signs at a nonce already taken, which for another sale of the same price is the same bytes. It
720
+ // goes only once the floor is above its nonce (`prune`), and nothing signed below the floor is sent.
721
+ try {
722
+ const by = (await recoverTransactionAddress({ serializedTransaction: signed })).toLowerCase();
723
+ await listOwned(by, nonce, transaction);
724
+ const fresh = await core.state.swap(ownerAt(transaction), undefined, keys.sale);
725
+ const owned = fresh || (await core.state.get(ownerAt(transaction))) === keys.sale;
726
+ if (!owned) {
727
+ core.log({ event: "transaction-of-another-sale", network, transaction });
728
+ await sendForOwner(network, signed, keys, mine);
729
+ return undefined;
730
+ }
731
+ // Read after the owner record is written: the record of a hash goes only after the floor passed its nonce.
732
+ if (nonce < BigInt((await ownedOf(by)).floor)) {
733
+ core.log({ event: "signed-below-finalized-nonce", network, transaction, nonce: nonce.toString() });
734
+ if (fresh)
735
+ await core.state.delete(ownerAt(transaction));
736
+ return undefined;
737
+ }
738
+ await core.state.set(keptAt(transaction), signed);
739
+ // Kept as first written where these bytes were signed before: the redemptions signed at their nonce since stay listed.
740
+ await core.state.swap(nonceAt(transaction), undefined, { hashes: [transaction], ...(since === undefined ? {} : { since: since.toString() }), last: Date.now(), mark: keys.mark });
741
+ if (!(await core.state.swap(flightAt(keys.mark), mine, flight))) {
742
+ core.log({ event: "mark-lost", network, transaction });
743
+ return undefined;
744
+ }
745
+ }
746
+ catch (e) {
747
+ core.log({ event: "store-call-failed", network, transaction, call: "state" }, e);
748
+ return undefined;
749
+ }
750
+ let withdraw;
751
+ try {
752
+ withdraw = await core.naming(transaction);
753
+ }
754
+ catch (e) {
755
+ // The hash stays this sale's: a write that lands after its call failed leaves the row naming it.
756
+ await free(keys, flight, network, true);
757
+ throw e;
758
+ }
759
+ // The row names it: only such a redemption does another sale's settle send again or replace for its sale.
760
+ await revise(await signedAt(transaction), (current) => ({ ...current, named: true })).catch((e) => core.log({ event: "store-call-failed", network, transaction, call: "state" }, e));
761
+ try {
762
+ await signer.sendRawTransaction({ serializedTransaction: signed });
763
+ }
764
+ catch (e) {
765
+ let fate;
766
+ try {
767
+ const judged = await signedAt(transaction);
768
+ fate = await fateOf(c.rpc, signed, judged, performance.now() + NODE_TIMEOUT_MS);
769
+ if (fate === "gone" && !(await stillAsJudged(transaction, judged)))
770
+ fate = "unknown";
771
+ }
772
+ catch (f) {
773
+ core.log({ event: "read-failed", network, transaction }, f);
774
+ }
775
+ if (fate === "gone") {
776
+ core.log({ event: "send-failed", network, transaction, named: "withdrawn" }, e);
777
+ await withdraw();
778
+ await core.state.delete(ownerAt(transaction)).catch(() => { });
779
+ await free(keys, flight, network);
780
+ return undefined;
781
+ }
782
+ core.log({ event: "send-failed", network, transaction, named: "kept" }, e);
783
+ }
784
+ return { transaction, flight };
785
+ }
91
786
  /** lcp's checks, the leaf's delegate, the manager's code and the simulation, in that order; nothing is sent. */
92
787
  async function check(payload, requirements) {
93
788
  const a = await admit("erc7710", { payload, requirements }, ERC7710_PAIRINGS);
@@ -98,8 +793,8 @@ function facilitatorOf(c) {
98
793
  return { isValid: false, invalidReason: "invalid_payload" };
99
794
  const payer = r.delegator;
100
795
  // A context the reference manager's encoding reads names its leaf's delegate, which alone may redeem it; another
101
- // manager's context is opaque, and its simulation shows whether the module's key may redeem it. The key sends from
102
- // its first address, `writeContract` taking no account, so that is the delegate the leaf must name, and the account
796
+ // manager's context is opaque, and its simulation shows whether the module's key may redeem it. The key signs from
797
+ // its first address (`EvmSender.signTransaction`), so that is the delegate the leaf must name, and the account
103
798
  // the simulation runs from.
104
799
  const delegations = decodePermissionContext(r.context);
105
800
  const from = signer.getAddresses()[0];
@@ -124,7 +819,306 @@ function facilitatorOf(c) {
124
819
  }
125
820
  return { redemption: r, from };
126
821
  }
127
- return {
822
+ /**
823
+ * Takes the mark for a repeat's send of a redemption the row names, naming `transaction`: undefined where another
824
+ * sale's mark stands or the mark was lost, and nothing may then be sent.
825
+ */
826
+ async function markFor(p, transaction, deadline) {
827
+ const keys = await keysOf(p.payload, p.requirements);
828
+ return keys === undefined ? undefined : markOfSale(keys, p.requirements.network, transaction, deadline);
829
+ }
830
+ /** `markFor`, for the sale and mark `keys` names. */
831
+ async function markOfSale(keys, network, transaction, deadline) {
832
+ const current = await core.state.get(flightAt(keys.mark));
833
+ if (isFlight(current) && current.sale !== keys.sale) {
834
+ const standing = await stands(current, deadline);
835
+ // A mark passed on naming a nonce is taken only to send at that nonce of that key. A mark that lapsed naming a
836
+ // nonce (past the hold, its settle having sent nothing) is taken for kept bytes at exactly that nonce of that key,
837
+ // whatever else stands: they are what it names,
838
+ // and the repeat sends them only where the node holds nothing at that nonce (`resend`), or replaces them only
839
+ // where the node holds them (`replace`).
840
+ const kept = typeof standing === "object" || current.at !== undefined ? await core.state.get(keptAt(transaction)) : undefined;
841
+ const at = typeof kept === "string" && isHex(kept) ? BigInt(parseTransaction(kept).nonce ?? 0) : undefined;
842
+ const by = typeof kept === "string" && isHex(kept) ? (await recoverTransactionAddress({ serializedTransaction: kept })).toLowerCase() : undefined;
843
+ const lapsedAt = current.transaction === undefined && current.at !== undefined && Date.now() - current.since >= core.settleWaitMs && at === BigInt(current.at.nonce) && by === current.at.key;
844
+ if (!lapsedAt && (standing === "stands" || (typeof standing === "object" && (standing.at !== at || standing.key !== by)))) {
845
+ core.log({ event: "delegation-in-flight", network, transaction, named: "kept" });
846
+ return undefined;
847
+ }
848
+ }
849
+ const flight = { sale: keys.sale, transaction, since: Date.now() };
850
+ if (!(await core.state.swap(flightAt(keys.mark), current, flight))) {
851
+ core.log({ event: "mark-lost", network, transaction, named: "kept" });
852
+ return undefined;
853
+ }
854
+ return { keys, flight };
855
+ }
856
+ /**
857
+ * Replaces a redemption the node holds unmined and underpriced by the same call signed at the same nonce: its fee cap
858
+ * below the base fee of the node's latest block, or its tip below the tip the node suggests
859
+ * (`eth_maxPriorityFeePerGas`) a whole settle wait after the last redemption at its nonce was signed. One priced by
860
+ * `gasPrice` alone tips its price less the base fee, and offers its whole price as its tip. The replacement's tip is
861
+ * the larger of the tip the held one offers raised by an eighth and the node's suggestion, and its fee cap the
862
+ * larger of the held one's raised by an eighth and twice the base fee and the tip, so that a replacement is made again
863
+ * only where the base fee passes its cap or the node's suggested tip rises past its own: the fees follow what the
864
+ * node asks, and repeats alone never raise them. Named in the row first (`Core.naming`), kept with every redemption
865
+ * signed at the nonce, and sent under the mark of the sale `keys` names. Where `inRow` is false the caller is another
866
+ * sale's settle (`moveOn`), which cannot write that sale's row: the replacement is then listed among those signed at
867
+ * the nonce as one the row does not name yet, before it is sent, and never named in the caller's row. Both can be the
868
+ * one that lands, and the nonce lets one only. Nothing
869
+ * is sent where the signer does not sign at that nonce with those fees, where the held one was signed by a key the
870
+ * settler no longer signs with, or below the floor of the key (`Owned`). Where its send fails and the node does not
871
+ * show it by its hash, the row names the held one again, which a later repeat replaces again: with the
872
+ * same fees while the node asks the same. Where the node shows it later, the sale's next repeat names it in the row
873
+ * (`resend`).
874
+ */
875
+ async function replace(keys, network, transaction, signed, at, feeCap, deadline, inRow) {
876
+ const latest = await rpcCall(c.rpc, "eth_getBlockByNumber", ["latest", false], deadline);
877
+ if (!isObject(latest) || typeof latest["baseFeePerGas"] !== "string")
878
+ return;
879
+ const base = quantity(latest["baseFeePerGas"], "base fee");
880
+ const held = parseTransaction(signed);
881
+ // A transaction priced by `gasPrice` alone tips what its price leaves above the base fee, and offers its whole price
882
+ // as its tip (EIP-1559): its replacement's tip is raised from that price, so that it pays no less at any base fee.
883
+ const price = held.gasPrice ?? 0n;
884
+ const heldTip = held.maxPriorityFeePerGas ?? (price > base ? price - base : 0n);
885
+ const offered = held.maxPriorityFeePerGas ?? price;
886
+ let suggested = 0n;
887
+ try {
888
+ suggested = quantity(await rpcCall(c.rpc, "eth_maxPriorityFeePerGas", [], deadline), "suggested tip");
889
+ }
890
+ catch (e) {
891
+ core.log({ event: "read-failed", network, transaction }, e);
892
+ }
893
+ const waited = at.last === undefined || Date.now() - at.last >= core.settleWaitMs;
894
+ if (feeCap >= base && !(waited && heldTip < suggested))
895
+ return;
896
+ const old = held;
897
+ if (old.to === undefined || old.to === null || old.nonce === undefined)
898
+ return;
899
+ // Only the key that signed the held one signs at its nonce, and never below the floor (`Owned`): a transaction of
900
+ // another key at that nonce could land beside it, and one below the floor can never land.
901
+ const by = (await recoverTransactionAddress({ serializedTransaction: signed })).toLowerCase();
902
+ if (by !== ownKey() || BigInt(old.nonce) < BigInt((await ownedOf(by)).floor))
903
+ return;
904
+ const larger = (a, b) => (a > b ? a : b);
905
+ const tip = larger(raised(offered), suggested);
906
+ const cap = larger(raised(old.maxFeePerGas ?? old.gasPrice ?? 0n), 2n * base + tip);
907
+ const request = { to: old.to, data: old.data ?? "0x", ...(old.gas === undefined ? {} : { gas: old.gas }), nonce: old.nonce, maxFeePerGas: cap, maxPriorityFeePerGas: tip };
908
+ let next;
909
+ try {
910
+ next = await signer.signTransaction(request);
911
+ }
912
+ catch (e) {
913
+ core.log({ event: "sign-failed", network, transaction }, e);
914
+ return;
915
+ }
916
+ const n = parseTransaction(next);
917
+ if (n.nonce !== old.nonce || n.maxFeePerGas !== cap || n.maxPriorityFeePerGas !== tip || n.to?.toLowerCase() !== old.to.toLowerCase() || n.data !== old.data) {
918
+ core.log({ event: "replacement-not-signed", network, transaction });
919
+ return;
920
+ }
921
+ const replacement = keccak256(next);
922
+ if ((await recoverTransactionAddress({ serializedTransaction: next })).toLowerCase() !== by) {
923
+ core.log({ event: "replacement-not-signed", network, transaction });
924
+ return;
925
+ }
926
+ await listOwned(by, BigInt(old.nonce), replacement);
927
+ if (!((await core.state.swap(ownerAt(replacement), undefined, keys.sale)) || (await core.state.get(ownerAt(replacement))) === keys.sale)) {
928
+ core.log({ event: "transaction-of-another-sale", network, transaction: replacement });
929
+ return;
930
+ }
931
+ await core.state.set(keptAt(replacement), next);
932
+ const mark = await markOfSale(keys, network, replacement, deadline);
933
+ if (mark === undefined)
934
+ return;
935
+ if (inRow) {
936
+ try {
937
+ await core.naming(replacement);
938
+ }
939
+ catch (e) {
940
+ core.log({ event: "store-call-failed", network, transaction: replacement, call: "naming" }, e);
941
+ return;
942
+ }
943
+ }
944
+ // Named, or listed as one its sale's row does not name yet: kept with every redemption signed at the nonce before
945
+ // it is sent, so that its sale's next repeat names it before it judges any of them (`resend`).
946
+ await revise(at, (current) => ({
947
+ ...current,
948
+ hashes: [...current.hashes.filter((h) => h !== replacement), replacement],
949
+ last: Date.now(),
950
+ ...(inRow ? {} : { unnamed: [...(current.unnamed ?? []).filter((h) => h !== replacement), replacement] }),
951
+ }));
952
+ try {
953
+ await signer.sendRawTransaction({ serializedTransaction: next });
954
+ core.log({ event: "replaced", network, transaction, replacement });
955
+ }
956
+ catch (e) {
957
+ core.log({ event: "send-failed", network, transaction: replacement, named: "kept" }, e);
958
+ // A replacement the node does not hold is judged only once the node shows it: the row names again the redemption it
959
+ // holds, which a later repeat replaces again.
960
+ let shown;
961
+ try {
962
+ shown = await rpcCall(c.rpc, "eth_getTransactionByHash", [replacement], deadline);
963
+ }
964
+ catch (f) {
965
+ core.log({ event: "read-failed", network, transaction: replacement }, f);
966
+ return;
967
+ }
968
+ if (isObject(shown) || !inRow)
969
+ return;
970
+ try {
971
+ await core.naming(transaction);
972
+ }
973
+ catch (f) {
974
+ core.log({ event: "store-call-failed", network, transaction, call: "naming" }, f);
975
+ }
976
+ }
977
+ }
978
+ /**
979
+ * Whether the node shows, by its hash, any redemption signed at the nonce after `transaction` (`at` lists them first to
980
+ * last): such a one is judged on its own, and `transaction` is then not replaced. A failed lookup rejects.
981
+ */
982
+ async function shownAfter(at, transaction, deadline) {
983
+ const i = at.hashes.findIndex((h) => h.toLowerCase() === transaction.toLowerCase());
984
+ for (const h of i < 0 ? [] : at.hashes.slice(i + 1)) {
985
+ if (isObject(await rpcCall(c.rpc, "eth_getTransactionByHash", [h], deadline)))
986
+ return true;
987
+ }
988
+ return false;
989
+ }
990
+ /**
991
+ * Replaces, for the sale that owns it, another sale's redemption that holds back this one, `hash` being one of those
992
+ * signed at its nonce: the last of them the node shows by its hash, where it shows it unmined and underpriced,
993
+ * exactly as that sale's own repeat replaces it (`replace`): the same call at the same nonce, signed by the same
994
+ * key, under the same rule for its fees, under that sale's mark. Only where that sale's row was seen to name the
995
+ * first signed at the nonce (`Signed.named`). The replacement is this settle's to send and not this sale's: this
996
+ * sale's row never names it. It is kept, owned by its sale and listed among those signed at the nonce as one that
997
+ * sale's row does not name yet, before it is sent, and that sale's next repeat names it in its row before it judges
998
+ * any of them (`resend`). A failure goes to the log, and nothing is sent.
999
+ */
1000
+ async function moveOn(network, hash, deadline) {
1001
+ try {
1002
+ const all = await signedAt(hash);
1003
+ if (all.named !== true || all.mark === undefined)
1004
+ return;
1005
+ for (const h of [...all.hashes].reverse()) {
1006
+ const held = await shownBy(h, deadline);
1007
+ if (held === undefined)
1008
+ continue;
1009
+ if (held.mined || held.feeCap === undefined)
1010
+ return;
1011
+ const signed = await core.state.get(keptAt(h));
1012
+ const owner = await core.state.get(ownerAt(h));
1013
+ if (typeof signed !== "string" || !isHex(signed) || typeof owner !== "string")
1014
+ return;
1015
+ await replace({ mark: all.mark, sale: owner }, network, h, signed, all, held.feeCap, deadline, false);
1016
+ return;
1017
+ }
1018
+ }
1019
+ catch (e) {
1020
+ core.log({ event: "read-failed", network, transaction: hash }, e);
1021
+ }
1022
+ }
1023
+ /**
1024
+ * Where `signed`, a redemption of the gas key the node holds unmined, waits behind a lower nonce of the key (the
1025
+ * key's count at the node's latest block is below its nonce), moves on the redemption the module signed at that
1026
+ * lowest unmined nonce (`moveOn`). A transaction there that is not the module's, another scheme's, is left alone. A
1027
+ * failure goes to the log.
1028
+ */
1029
+ async function unblock(network, signed, deadline) {
1030
+ try {
1031
+ const key = ownKey();
1032
+ if (key === undefined || (await recoverTransactionAddress({ serializedTransaction: signed })).toLowerCase() !== key)
1033
+ return;
1034
+ const lowest = quantity(await rpcCall(c.rpc, "eth_getTransactionCount", [key, "latest"], deadline), "transaction count");
1035
+ if (lowest >= BigInt(parseTransaction(signed).nonce ?? 0))
1036
+ return;
1037
+ const there = (await ownedOf(key)).signed.filter(([n]) => BigInt(n) === lowest).at(-1);
1038
+ if (there !== undefined)
1039
+ await moveOn(network, there[1], deadline);
1040
+ }
1041
+ catch (e) {
1042
+ core.log({ event: "read-failed", network }, e);
1043
+ }
1044
+ }
1045
+ /**
1046
+ * A redemption named before it was sent, on a repeat. Its kept bytes are sent again where their nonce is still the
1047
+ * key's next and the finalized chain has not passed it; where the node holds them unmined below the base fee they are
1048
+ * replaced at the same nonce (`replace`); `gone` only where one finalized block shows a different transaction took
1049
+ * their nonce (`fateOf`). Where the chain as read shows none of these, nothing is sent and the hash stays named.
1050
+ * Where several were signed at the nonce and the chain shows this one mined, the row names it, so that the record's
1051
+ * read is of the one that landed and not of a replacement that can no longer land. A replacement another sale's
1052
+ * settle sent for this sale is named in the row first of all. Where this one is held unmined behind a lower nonce
1053
+ * of the gas key, the module's redemption at that nonce is moved on (`unblock`). A
1054
+ * send is a redemption in flight like any other, so it is made only under the mark, taken for its sale and naming
1055
+ * its hash: while another sale's mark stands, nothing is sent, so that no redemption under the same root delegator is
1056
+ * simulated and sent beside it.
1057
+ */
1058
+ async function resend(p, transaction, at) {
1059
+ const network = p.requirements.network;
1060
+ const signed = await core.state.get(keptAt(transaction));
1061
+ if (typeof signed !== "string" || !isHex(signed))
1062
+ return "kept";
1063
+ let all = await signedAt(transaction);
1064
+ // A replacement another sale's settle signed and sent for this sale (`moveOn`): named in the row before any
1065
+ // redemption at the nonce is judged, so that none is taken out of the row while one the row does not name can land.
1066
+ const unnamed = all.unnamed ?? [];
1067
+ if (unnamed.length > 0) {
1068
+ for (const u of unnamed)
1069
+ await core.naming(u);
1070
+ all = await revise(all, (current) => {
1071
+ const { unnamed: listed, ...rest } = current;
1072
+ const left = (listed ?? []).filter((h) => !unnamed.includes(h));
1073
+ return left.length === 0 ? rest : { ...rest, unnamed: left };
1074
+ });
1075
+ }
1076
+ const fate = await fateOf(c.rpc, signed, all, at.deadline);
1077
+ // Retired only where the proof was made against every redemption signed at the nonce: one listed since stays for
1078
+ // the next repeat, which names it first.
1079
+ if (fate === "gone")
1080
+ return (await stillAsJudged(transaction, all)) ? "gone" : "kept";
1081
+ if (fate === "unknown")
1082
+ return "kept";
1083
+ // Of several signed at the nonce, the one the chain shows mined is the one the row names: the record's read is of
1084
+ // the transaction the row names, and the row may name a replacement of it that can no longer land.
1085
+ const mined = fate === "landed" || ("held" in fate && fate.held.mined);
1086
+ if (mined && all.hashes.length > 1)
1087
+ await core.naming(transaction);
1088
+ if (fate === "landed")
1089
+ return "kept";
1090
+ if ("held" in fate) {
1091
+ // Replaced where the node shows it unmined and shows none signed after it at the nonce, which is judged on its
1092
+ // own: a replacement the node never took is judged only once the node shows it.
1093
+ if (!fate.held.mined && fate.held.feeCap !== undefined && !(await shownAfter(all, transaction, at.deadline))) {
1094
+ // The one the node holds is the one the row names (a replacement whose send failed and that reached the node
1095
+ // later, or the redemption it would have replaced).
1096
+ await core.naming(transaction);
1097
+ const keys = await keysOf(p.payload, p.requirements);
1098
+ if (keys !== undefined)
1099
+ await replace(keys, network, transaction, signed, all, fate.held.feeCap, at.deadline, true);
1100
+ }
1101
+ // Held unmined behind a lower nonce of the gas key: the redemption there is moved on, where it is the module's.
1102
+ if (!fate.held.mined)
1103
+ await unblock(network, signed, at.deadline);
1104
+ return "kept";
1105
+ }
1106
+ if (!fate.open.next)
1107
+ return "kept";
1108
+ if ((await markFor(p, transaction, at.deadline)) === undefined)
1109
+ return "kept";
1110
+ // Named again under this repeat's hold before it is sent, as any send of the claim is: the core then counts it
1111
+ // against the fee budget, and nothing is sent where the claim was taken since.
1112
+ await core.naming(transaction);
1113
+ try {
1114
+ await signer.sendRawTransaction({ serializedTransaction: signed });
1115
+ }
1116
+ catch (e) {
1117
+ core.log({ event: "send-failed", network, transaction, named: "kept" }, e);
1118
+ }
1119
+ return "kept";
1120
+ }
1121
+ const facilitator = {
128
1122
  scheme: "exact",
129
1123
  caipFamily: "eip155:*",
130
1124
  getExtra: () => undefined,
@@ -135,61 +1129,139 @@ function facilitatorOf(c) {
135
1129
  },
136
1130
  async settle(payload, requirements) {
137
1131
  const network = requirements.network;
138
- const checked = await check(payload, requirements);
139
- if (!("redemption" in checked)) {
140
- return { success: false, errorReason: checked.invalidReason ?? "invalid_payload", transaction: "", network, ...(checked.payer === undefined ? {} : { payer: checked.payer }) };
1132
+ const until = performance.now() + core.settleWaitMs / 2;
1133
+ const refusal = (v) => ({
1134
+ success: false,
1135
+ errorReason: v.invalidReason ?? "invalid_payload",
1136
+ transaction: "",
1137
+ network,
1138
+ ...(v.payer === undefined ? {} : { payer: v.payer }),
1139
+ });
1140
+ const keys = await keysOf(payload, requirements);
1141
+ if (keys === undefined) {
1142
+ const checked = await check(payload, requirements);
1143
+ return "redemption" in checked ? refusal({ isValid: false, invalidReason: "invalid_payload" }) : refusal(checked);
141
1144
  }
142
- const r = checked.redemption;
143
- const payer = r.delegator;
144
- let transaction;
1145
+ // One redemption under the mark in flight at a time: another sale's, not yet mined, is waited for, so that the
1146
+ // simulation below sees what it spent of the caveats or the balance, and nothing is sent that they then refuse.
1147
+ let mine;
145
1148
  try {
146
- transaction = (await signer.writeContract({
147
- address: r.manager,
148
- abi: REDEEM_ABI,
149
- functionName: "redeemDelegations",
150
- args: redeemCall(r),
151
- }));
1149
+ mine = await take(keys, until);
152
1150
  }
153
- catch {
154
- return { success: false, errorReason: "invalid_transaction", transaction: "", network, payer };
1151
+ catch (e) {
1152
+ return unexpectedSettle(core.log, { event: "store-call-failed", network, call: "state" }, e);
155
1153
  }
1154
+ // Another sale's redemption under the mark still in flight when the wait ends: nothing sent, and a repeat
1155
+ // settles this sale.
1156
+ if (mine === undefined) {
1157
+ // The redemption that holds this sale back is moved on where the node holds it unmined and underpriced
1158
+ // (`moveOn`): its own buyer may never ask again.
1159
+ try {
1160
+ const standing = await core.state.get(flightAt(keys.mark));
1161
+ if (isFlight(standing) && standing.sale !== keys.sale && standing.transaction !== undefined)
1162
+ await moveOn(network, standing.transaction, performance.now() + NODE_TIMEOUT_MS);
1163
+ }
1164
+ catch (e) {
1165
+ core.log({ event: "store-call-failed", network, call: "state" }, e);
1166
+ }
1167
+ return unexpectedSettle(core.log, { event: "delegation-in-flight", network });
1168
+ }
1169
+ let sent;
1170
+ let r;
1171
+ try {
1172
+ const checked = await check(payload, requirements);
1173
+ if (!("redemption" in checked))
1174
+ return refusal(checked);
1175
+ r = checked.redemption;
1176
+ sent = await send(r, network, keys, mine);
1177
+ // Nothing sent, and a repeat may send it: the sale's own refusal is its simulation's, above.
1178
+ if (sent === undefined)
1179
+ return { ...unexpectedSettle(core.log, { event: "redemption-not-sent", network }), payer: r.delegator };
1180
+ }
1181
+ finally {
1182
+ if (sent === undefined)
1183
+ await free(keys, mine, network, true);
1184
+ }
1185
+ const payer = r.delegator;
1186
+ const transaction = sent.transaction;
1187
+ // The removal is waited for a moment only, and goes on beside the receipt wait: it reads the node for each record,
1188
+ // and a slow read there is no part of this sale's answer.
1189
+ let waited;
1190
+ await Promise.race([prune(network), new Promise((done) => (waited = setTimeout(done, PRUNE_WAIT_MS)))]);
1191
+ clearTimeout(waited);
156
1192
  let receipt;
157
1193
  try {
158
- receipt = await signer.waitForTransactionReceipt({ hash: transaction });
1194
+ // Its own receipt only (`ownReceipt`): another transaction at its nonce is no fact about this sale, and what it
1195
+ // signed is kept, so that a repeat reads its fate.
1196
+ receipt = ownReceipt(transaction, await signer.waitForTransactionReceipt({ hash: transaction }));
159
1197
  }
160
1198
  catch {
161
1199
  return { success: false, errorReason: "settlement_pending", transaction, network, payer };
162
1200
  }
163
- if (receipt.status !== "success" || !transfers(receipt.logs, r)) {
1201
+ // Mined at the head: the next sale under the mark may simulate. What it signed is kept, since the chain can drop
1202
+ // the receipt's block and a repeat then reads its fate by the bytes (`resend`); it goes once the finalized chain
1203
+ // shows the redemption (`prune`). Its owner record stays too: a receipt does not stop a signer answered by a
1204
+ // node behind from signing the same bytes for another sale. It goes once the floor is above its nonce (`prune`).
1205
+ await free(keys, sent.flight, network);
1206
+ // Mined and reverted: the claim's failure, naming it, once the record's read shows it at the finalized block.
1207
+ if (receipt.status !== "success")
1208
+ return { success: false, errorReason: "invalid_transaction_state", transaction, network, payer };
1209
+ if (!transfers(receipt.logs, r))
164
1210
  return { success: false, errorReason: "invalid_transaction", transaction, network, payer };
165
- }
166
1211
  return { success: true, transaction, network, payer };
167
1212
  },
168
1213
  };
1214
+ return { facilitator, resend };
169
1215
  }
170
1216
  /**
171
1217
  * The `erc7710` module on one network, as the hand-off the `exact` registration there takes: every payment whose option
172
1218
  * names the `erc7710` method, by the option's own member, before x402's `exact` class sees it.
173
1219
  */
174
- export function erc7710Handoff(c) {
1220
+ export function erc7710Handoff(c, core) {
175
1221
  const network = c.network;
1222
+ // The blocks a proof showed on the finalized chain, kept so that a later proof walks on from them.
1223
+ registerAnchors(c.rpc, anchorsIn(core.state, `finalized-anchors:${c.network}`));
1224
+ const own = facilitatorOf(c, core);
176
1225
  const record = {
1226
+ // The module's settle answers a success on the redemption's first receipt, at the head.
1227
+ successAtHead: true,
177
1228
  async instrument(p) {
178
1229
  const a = await admit("erc7710", p, ERC7710_PAIRINGS);
179
1230
  return "refused" in a ? a : instrumentOf(network, p, a);
180
1231
  },
181
1232
  // The level that signs no H is found only by the transaction the record holds, the one this module's settle named.
1233
+ // lcp reads a named redemption that mined and reverted as pending (its profile, rule 8), and on that level nothing
1234
+ // else can show the sale paid: the module reads that receipt itself, and one reverted at or below the finalized
1235
+ // block is the claim's failure, naming it, as nothing was paid by it and nothing named will be sent again. On the
1236
+ // salt level lcp's search for H, which is never read whole, can still meet another redemption carrying H, so its
1237
+ // answer stands.
182
1238
  async read(p, at) {
183
1239
  const a = await admit("erc7710", p, ERC7710_PAIRINGS);
184
1240
  if ("refused" in a)
185
1241
  return { outcome: "live", answer: { state: "unreadable", reason: "unparseable", foreign: [] } };
186
- return readOf(evmReader(c.network, c.rpc, at.deadline), a, at);
1242
+ const reader = evmReader(c.network, c.rpc, at.deadline);
1243
+ const read = await readOf(reader, a, at);
1244
+ if (a.pairing !== exactErc7710.id || read.outcome !== "live" || read.answer.state !== "pending" || at.transaction === undefined)
1245
+ return read;
1246
+ const transaction = at.transaction.toLowerCase();
1247
+ try {
1248
+ // Final only on the finalized chain: the receipt's block, by its hash, shown below the finalized block's own hash.
1249
+ const receipt = await finalizedReceipt(c.rpc, transaction, at.deadline);
1250
+ if (receipt === undefined || receipt.status !== 0)
1251
+ return read;
1252
+ }
1253
+ catch (e) {
1254
+ core.log({ event: "read-failed", network, transaction }, e);
1255
+ return read;
1256
+ }
1257
+ return outcomeOf({ state: "failed", reason: "transaction-failed", transaction, finality: "finalized", foreign: [] });
187
1258
  },
1259
+ resend: own.resend,
188
1260
  };
189
1261
  const module = {
190
- descriptor: { name: "erc7710", key: "relayer", pairings: ERC7710_PAIRINGS, acceptsZero: false },
1262
+ descriptor: { name: "erc7710", key: "relayer", pairings: ERC7710_PAIRINGS, acceptsZero: [] },
191
1263
  network,
192
- facilitator: facilitatorOf(c),
1264
+ facilitator: own.facilitator,
193
1265
  record,
194
1266
  fees: {
195
1267
  paysFee: () => true,
@@ -211,10 +1283,15 @@ export function erc7710Handoff(c) {
211
1283
  */
212
1284
  export const starter = {
213
1285
  name: "erc7710",
214
- async start(networks) {
1286
+ async start(networks, core) {
1287
+ for (const c of networks) {
1288
+ if (typeof c.signer.signTransaction !== "function" || typeof c.signer.sendRawTransaction !== "function") {
1289
+ throw new TypeError(`erc7710 on ${c.network}: the signer must give signTransaction and sendRawTransaction`);
1290
+ }
1291
+ }
215
1292
  return {
216
1293
  registrations: [],
217
- handoffs: networks.map((c) => ({ scheme: "exact", network: c.network, handoff: erc7710Handoff(c) })),
1294
+ handoffs: networks.map((c) => ({ scheme: "exact", network: c.network, handoff: erc7710Handoff(c, core) })),
218
1295
  };
219
1296
  },
220
1297
  };