@bananapus/nana-sdk-core 2.35.0 → 2.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/review/relayr.d.ts +22 -5
- package/dist/cjs/review/relayr.d.ts.map +1 -1
- package/dist/cjs/review/relayr.js +56 -29
- package/dist/cjs/review/relayr.js.map +1 -1
- package/dist/cjs/review/safeRelayr.d.ts +31 -2
- package/dist/cjs/review/safeRelayr.d.ts.map +1 -1
- package/dist/cjs/review/safeRelayr.js +388 -99
- package/dist/cjs/review/safeRelayr.js.map +1 -1
- package/dist/cjs/review/tabState.d.ts +23 -0
- package/dist/cjs/review/tabState.d.ts.map +1 -0
- package/dist/cjs/review/tabState.js +30 -0
- package/dist/cjs/review/tabState.js.map +1 -0
- package/dist/cjs/review/writeHold.d.ts +31 -5
- package/dist/cjs/review/writeHold.d.ts.map +1 -1
- package/dist/cjs/review/writeHold.js +260 -42
- package/dist/cjs/review/writeHold.js.map +1 -1
- package/dist/cjs/review/writeRecovery.d.ts +42 -3
- package/dist/cjs/review/writeRecovery.d.ts.map +1 -1
- package/dist/cjs/review/writeRecovery.js +168 -14
- package/dist/cjs/review/writeRecovery.js.map +1 -1
- package/dist/cjs/testing.d.ts +7 -0
- package/dist/cjs/testing.d.ts.map +1 -0
- package/dist/cjs/testing.js +30 -0
- package/dist/cjs/testing.js.map +1 -0
- package/dist/esm/review/relayr.d.ts +22 -5
- package/dist/esm/review/relayr.d.ts.map +1 -1
- package/dist/esm/review/relayr.js +55 -29
- package/dist/esm/review/relayr.js.map +1 -1
- package/dist/esm/review/safeRelayr.d.ts +31 -2
- package/dist/esm/review/safeRelayr.d.ts.map +1 -1
- package/dist/esm/review/safeRelayr.js +388 -99
- package/dist/esm/review/safeRelayr.js.map +1 -1
- package/dist/esm/review/tabState.d.ts +23 -0
- package/dist/esm/review/tabState.d.ts.map +1 -0
- package/dist/esm/review/tabState.js +26 -0
- package/dist/esm/review/tabState.js.map +1 -0
- package/dist/esm/review/writeHold.d.ts +31 -5
- package/dist/esm/review/writeHold.d.ts.map +1 -1
- package/dist/esm/review/writeHold.js +261 -43
- package/dist/esm/review/writeHold.js.map +1 -1
- package/dist/esm/review/writeRecovery.d.ts +42 -3
- package/dist/esm/review/writeRecovery.d.ts.map +1 -1
- package/dist/esm/review/writeRecovery.js +167 -16
- package/dist/esm/review/writeRecovery.js.map +1 -1
- package/dist/esm/testing.d.ts +7 -0
- package/dist/esm/testing.d.ts.map +1 -0
- package/dist/esm/testing.js +25 -0
- package/dist/esm/testing.js.map +1 -0
- package/package.json +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safeRelayr.d.ts","sourceRoot":"","sources":["../../../src/review/safeRelayr.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAEd,OAAO,EAKL,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,
|
|
1
|
+
{"version":3,"file":"safeRelayr.d.ts","sourceRoot":"","sources":["../../../src/review/safeRelayr.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAEd,OAAO,EAKL,KAAK,sBAAsB,EAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EA6BL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC/B,MAAM,aAAa,CAAC;AAGrB,0FAA0F;AAC1F,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,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,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;KAC7B,KAAG,OAAO,CAAC,gBAAgB,CAAC;8EAmP1B;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,KAAG,OAAO,CAAC,gBAAgB,CAAC;4CA8D1B;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,KAAG,OAAO,CAAC,gBAAgB,CAAC;EAqB9B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SafeRelayrRecoveryError = void 0;
|
|
3
|
+
exports.SafeRelayrRecoveryError = exports.SAFE_RELAYR_UNCONFIRMED_LINE = exports.SAFE_RELAYR_FUNDING_EXIT_LINE = exports.SAFE_RELAYR_QUOTE_CLOSING_LINE = exports.SAFE_RELAYR_STATUS_UNKNOWN_LINE = void 0;
|
|
4
4
|
exports.canReplaceSafeRelayrQuote = canReplaceSafeRelayrQuote;
|
|
5
5
|
exports.safeRelayrReservationKey = safeRelayrReservationKey;
|
|
6
6
|
exports.sameSafeRelayrIntents = sameSafeRelayrIntents;
|
|
@@ -12,6 +12,7 @@ const viem_1 = require("viem");
|
|
|
12
12
|
const safe_js_1 = require("../safe.js");
|
|
13
13
|
const safeService_js_1 = require("../safeService.js");
|
|
14
14
|
const relayr_js_1 = require("./relayr.js");
|
|
15
|
+
const tabState_js_1 = require("./tabState.js");
|
|
15
16
|
function hasFundingRecords(records) {
|
|
16
17
|
if (records === undefined)
|
|
17
18
|
return false;
|
|
@@ -71,6 +72,28 @@ function canReplaceSafeRelayrQuote(session) {
|
|
|
71
72
|
return false;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
75
|
+
/** The line a Safe action shows when its payment's status couldn't be read. */
|
|
76
|
+
exports.SAFE_RELAYR_STATUS_UNKNOWN_LINE = "Couldn't check this payment's status. Try again in a moment.";
|
|
77
|
+
/** The line a Safe action shows when its quote can no longer be paid but hasn't expired onchain. */
|
|
78
|
+
exports.SAFE_RELAYR_QUOTE_CLOSING_LINE = "This quote's payment window has closed. Try again in a few minutes for a new quote.";
|
|
79
|
+
/** The line a Safe action shows with its warned exit while Relayr's funding report is unresolved. */
|
|
80
|
+
exports.SAFE_RELAYR_FUNDING_EXIT_LINE = "Relayr reported a payment for this quote. Check your wallet and Relayr before paying again.";
|
|
81
|
+
/** How long after funding was last reported its warned exit waits: an hour. */
|
|
82
|
+
const FUNDING_EXIT_MS = 60 * 60_000;
|
|
83
|
+
/** The line a Safe action shows with its warned exit (see {@link SafeRelayrRecovery.exit}). */
|
|
84
|
+
exports.SAFE_RELAYR_UNCONFIRMED_LINE = "We couldn't confirm this payment's status. If your wallet shows no payment, get a new quote.";
|
|
85
|
+
/** A status read's failure that says nothing: no refusal Relayr gave. */
|
|
86
|
+
function statusUnknown(error) {
|
|
87
|
+
return (!(error instanceof relayr_js_1.RelayrPaymentRetryError) || error.reason === "unknown");
|
|
88
|
+
}
|
|
89
|
+
/** A refusal saying Relayr reports the bundle paid, or a call running or run. */
|
|
90
|
+
function fundingReported(error) {
|
|
91
|
+
return (error instanceof relayr_js_1.RelayrPaymentRetryError &&
|
|
92
|
+
(error.reason === "paid" || error.reason === "running"));
|
|
93
|
+
}
|
|
94
|
+
/** Reads of a bundle's payment status before an unknown answer is reported. */
|
|
95
|
+
const STATUS_READS = 3;
|
|
96
|
+
const STATUS_RETRY_MS = 250;
|
|
74
97
|
class SafeRelayrRecoveryError extends Error {
|
|
75
98
|
constructor(session, message = "This Safe action already has a payment in progress. Check it before paying again.", recovery) {
|
|
76
99
|
super(message);
|
|
@@ -83,7 +106,9 @@ exports.SafeRelayrRecoveryError = SafeRelayrRecoveryError;
|
|
|
83
106
|
// Review is a page-lifetime capability, never a local-storage claim. Multiple
|
|
84
107
|
// hook instances can share it; reloading, changing exact bytes, or eviction
|
|
85
108
|
// requires explicit review again. Eviction only adds a review, never a write.
|
|
86
|
-
const reviewedIntents = new Set();
|
|
109
|
+
const reviewedIntents = (0, tabState_js_1.tabShared)(tabState_js_1.TAB.reviews, () => new Set());
|
|
110
|
+
/** The stop of every running watch, for the test-only reset. */
|
|
111
|
+
const watching = (0, tabState_js_1.tabShared)(tabState_js_1.TAB.watches, () => new Set());
|
|
87
112
|
function reviewKey(session) {
|
|
88
113
|
return (0, viem_1.keccak256)((0, viem_1.toHex)(JSON.stringify([
|
|
89
114
|
session.account.toLowerCase(),
|
|
@@ -274,7 +299,31 @@ function requireSessionQuote(session) {
|
|
|
274
299
|
}
|
|
275
300
|
/** Shared Safe Relayr state machine. It never signs Safe proposals or submits on prepare/check. */
|
|
276
301
|
function createSafeRelayrController(options) {
|
|
277
|
-
|
|
302
|
+
/**
|
|
303
|
+
* The app's store, with funding evidence sticky in its one save path: a
|
|
304
|
+
* save from an older snapshot never drops `fundingObserved` or an older
|
|
305
|
+
* `fundingObservedAt` another flow saved. Nothing ever clears them; an
|
|
306
|
+
* exit keeps them for reconciliation.
|
|
307
|
+
*/
|
|
308
|
+
const store = {
|
|
309
|
+
get scope() {
|
|
310
|
+
return options.store.scope;
|
|
311
|
+
},
|
|
312
|
+
list: (account) => options.store.list(account),
|
|
313
|
+
withLock: (account, run) => options.store.withLock(account, run),
|
|
314
|
+
async save(next) {
|
|
315
|
+
const saved = (await options.store.list(next.account)).find((session) => session.id === next.id);
|
|
316
|
+
const at = [saved?.fundingObservedAt, next.fundingObservedAt].filter((value) => typeof value === "number");
|
|
317
|
+
// Once seen, funding stays, and its clock only moves forward.
|
|
318
|
+
return options.store.save(saved?.fundingObserved || next.fundingObserved
|
|
319
|
+
? {
|
|
320
|
+
...next,
|
|
321
|
+
fundingObserved: true,
|
|
322
|
+
...(at.length ? { fundingObservedAt: Math.max(...at) } : {}),
|
|
323
|
+
}
|
|
324
|
+
: next);
|
|
325
|
+
},
|
|
326
|
+
};
|
|
278
327
|
const fetchRelayr = options.fetch ?? globalThis.fetch;
|
|
279
328
|
const displayedExecutions = new Map();
|
|
280
329
|
const notify = (progress, rechecking = false) => {
|
|
@@ -462,18 +511,14 @@ function createSafeRelayrController(options) {
|
|
|
462
511
|
checks,
|
|
463
512
|
});
|
|
464
513
|
if (session.bundleUuid) {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
catch {
|
|
514
|
+
const [status, read] = await bundleUnpaid(session);
|
|
515
|
+
session = read;
|
|
516
|
+
if (status !== "unpaid")
|
|
471
517
|
return pending({
|
|
472
518
|
reason: "funding-unresolved",
|
|
473
519
|
message: "Every saved Safe nonce has been used, but the existing Relayr bundle has not been proven unpaid with all calls pending. Keep its payment evidence and inspect the original bundle before replacing this selection.",
|
|
474
520
|
checks,
|
|
475
521
|
});
|
|
476
|
-
}
|
|
477
522
|
}
|
|
478
523
|
session = {
|
|
479
524
|
...session,
|
|
@@ -498,6 +543,192 @@ function createSafeRelayrController(options) {
|
|
|
498
543
|
checks,
|
|
499
544
|
});
|
|
500
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* `read` of the bundle's status, tried up to {@link STATUS_READS} times
|
|
548
|
+
* while its failure is unknown. Every status read goes through it.
|
|
549
|
+
*/
|
|
550
|
+
async function statusRead(read) {
|
|
551
|
+
for (let attempt = 1;; attempt += 1) {
|
|
552
|
+
try {
|
|
553
|
+
return await read();
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
if (!statusUnknown(error) || attempt >= STATUS_READS)
|
|
557
|
+
throw error;
|
|
558
|
+
await new Promise((resolve) => setTimeout(resolve, STATUS_RETRY_MS));
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
/** `session`, saved with the funding Relayr reported. */
|
|
563
|
+
async function observed(session) {
|
|
564
|
+
session = {
|
|
565
|
+
...session,
|
|
566
|
+
fundingObserved: true,
|
|
567
|
+
fundingObservedAt: Date.now(),
|
|
568
|
+
};
|
|
569
|
+
await store.save(session);
|
|
570
|
+
return session;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* The bundle's payment status, three-valued: proven unpaid, funded (Relayr
|
|
574
|
+
* reports it paid or running, saved as observed funding), or unknown when
|
|
575
|
+
* it couldn't be read. Unknown is never paid, and never free to pay again.
|
|
576
|
+
*/
|
|
577
|
+
async function bundleUnpaid(session) {
|
|
578
|
+
try {
|
|
579
|
+
await statusRead(() => (0, relayr_js_1.requireRelayrBundleUnpaid)(session.bundleUuid, { fetch: fetchRelayr }));
|
|
580
|
+
return ["unpaid", session];
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
if (!fundingReported(error))
|
|
584
|
+
return ["unknown", session];
|
|
585
|
+
return ["funded", await observed(session)];
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* What a quote whose payments didn't fund it allows
|
|
590
|
+
* ({@link revertedRelayrQuote}), read after {@link bundleUnpaid} proved it
|
|
591
|
+
* unpaid; its own reads are confirmations. Funding they report is saved.
|
|
592
|
+
* Null while unproven, or with `rethrow`, its reason thrown.
|
|
593
|
+
*/
|
|
594
|
+
async function disposed(session, quote, chains, rethrow = false) {
|
|
595
|
+
let state;
|
|
596
|
+
/** The last read before release failed after its retries: unknown. */
|
|
597
|
+
let unconfirmed = false;
|
|
598
|
+
try {
|
|
599
|
+
({ state } = await (0, relayr_js_1.revertedRelayrQuote)(options.clientFor, {
|
|
600
|
+
bundleUuid: quote.bundle_uuid,
|
|
601
|
+
payments: session.payments,
|
|
602
|
+
options: quote.payment_info,
|
|
603
|
+
destinationChainIds: chains,
|
|
604
|
+
account: session.account,
|
|
605
|
+
}, {
|
|
606
|
+
fetch: fetchRelayr,
|
|
607
|
+
// Every read of its bundle, through the same retries.
|
|
608
|
+
statusRead: (read) => statusRead(read).catch((error) => {
|
|
609
|
+
unconfirmed = statusUnknown(error);
|
|
610
|
+
throw error;
|
|
611
|
+
}),
|
|
612
|
+
}));
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
if (unconfirmed)
|
|
616
|
+
return { state: "unknown", session };
|
|
617
|
+
if (rethrow)
|
|
618
|
+
throw error;
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
state,
|
|
623
|
+
session: state === "funded" ? await observed(session) : session,
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Held while reported funding is unresolved: never a release or a retry.
|
|
628
|
+
* Once every deadline is final and an hour has passed since funding was
|
|
629
|
+
* last reported, the user may leave it, strongly warned: a spurious
|
|
630
|
+
* report is no dead end.
|
|
631
|
+
*/
|
|
632
|
+
async function fundingUnresolved(session) {
|
|
633
|
+
const exit = await fundingExitDue(session, session.quote);
|
|
634
|
+
return {
|
|
635
|
+
...result("pending", session),
|
|
636
|
+
recovery: exit
|
|
637
|
+
? {
|
|
638
|
+
reason: "funding-unresolved",
|
|
639
|
+
message: exports.SAFE_RELAYR_FUNDING_EXIT_LINE,
|
|
640
|
+
exit: true,
|
|
641
|
+
}
|
|
642
|
+
: {
|
|
643
|
+
reason: "funding-unresolved",
|
|
644
|
+
message: "This saved selection has reported funding or execution activity. Check the existing bundle and its funding transactions before submitting another payment.",
|
|
645
|
+
},
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
/** Reported funding's warned exit is due: an hour since it was last reported, and every deadline final. */
|
|
649
|
+
async function fundingExitDue(session, quote) {
|
|
650
|
+
return (Date.now() - Number(session.fundingObservedAt) >= FUNDING_EXIT_MS &&
|
|
651
|
+
(await deadlinesFinal(session, quote)));
|
|
652
|
+
}
|
|
653
|
+
/** Every deadline of the quote's options and payments passed at a canonical finalized block. */
|
|
654
|
+
async function deadlinesFinal(session, quote) {
|
|
655
|
+
const deadlines = [
|
|
656
|
+
...(0, relayr_js_1.relayrQuotedOptions)(quote, session.executions.map(({ entry }) => entry.chain)).map(({ details }) => details),
|
|
657
|
+
...session.payments,
|
|
658
|
+
];
|
|
659
|
+
for (const { chainId, deadline } of deadlines) {
|
|
660
|
+
const client = options.clientFor(chainId);
|
|
661
|
+
if (!client || (await (0, relayr_js_1.relayrDeadlinePassed)(client, deadline)) !== true)
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* A held result that says why: in progress, unknown, or closing. Unknown
|
|
668
|
+
* offers the warned exit once nothing shown can fund the quote.
|
|
669
|
+
*/
|
|
670
|
+
async function held(why, session) {
|
|
671
|
+
if (why === "funded")
|
|
672
|
+
return result("pending", session);
|
|
673
|
+
if (why === "closing")
|
|
674
|
+
return {
|
|
675
|
+
...result("pending", session),
|
|
676
|
+
recovery: {
|
|
677
|
+
reason: "quote-closing",
|
|
678
|
+
message: exports.SAFE_RELAYR_QUOTE_CLOSING_LINE,
|
|
679
|
+
retryable: true,
|
|
680
|
+
},
|
|
681
|
+
};
|
|
682
|
+
const quote = session.quote;
|
|
683
|
+
// With funding reported and unresolved, the exit also waits for the
|
|
684
|
+
// funding exit's rule (see fundingUnresolved), with its stronger warning.
|
|
685
|
+
const funded = hasObservedFunding(session);
|
|
686
|
+
const spent = !!quote &&
|
|
687
|
+
(!funded || (await fundingExitDue(session, quote))) &&
|
|
688
|
+
(await (0, relayr_js_1.relayrQuoteUnfundable)(options.clientFor, {
|
|
689
|
+
bundleUuid: quote.bundle_uuid,
|
|
690
|
+
payments: session.payments,
|
|
691
|
+
options: quote.payment_info,
|
|
692
|
+
destinationChainIds: session.executions.map(({ entry }) => entry.chain),
|
|
693
|
+
account: session.account,
|
|
694
|
+
}, { unseen: true }).catch(() => null)) === true;
|
|
695
|
+
return {
|
|
696
|
+
...result("pending", session),
|
|
697
|
+
recovery: spent
|
|
698
|
+
? {
|
|
699
|
+
reason: "status-unknown",
|
|
700
|
+
message: funded
|
|
701
|
+
? exports.SAFE_RELAYR_FUNDING_EXIT_LINE
|
|
702
|
+
: exports.SAFE_RELAYR_UNCONFIRMED_LINE,
|
|
703
|
+
retryable: true,
|
|
704
|
+
exit: true,
|
|
705
|
+
}
|
|
706
|
+
: {
|
|
707
|
+
reason: "status-unknown",
|
|
708
|
+
message: exports.SAFE_RELAYR_STATUS_UNKNOWN_LINE,
|
|
709
|
+
retryable: true,
|
|
710
|
+
},
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
/** The status-unknown refusal, for a status read outside an inspection. */
|
|
714
|
+
const unknownStatus = (session) => new SafeRelayrRecoveryError(session, exports.SAFE_RELAYR_STATUS_UNKNOWN_LINE, {
|
|
715
|
+
reason: "status-unknown",
|
|
716
|
+
message: exports.SAFE_RELAYR_STATUS_UNKNOWN_LINE,
|
|
717
|
+
retryable: true,
|
|
718
|
+
});
|
|
719
|
+
/**
|
|
720
|
+
* Why an overlapping quote is kept, or null when it may be replaced: it is
|
|
721
|
+
* unused (see {@link canReplaceSafeRelayrQuote}) and, once quoted, a status
|
|
722
|
+
* read now proves it unpaid. Funding it reports is saved; unknown keeps it.
|
|
723
|
+
*/
|
|
724
|
+
async function unreplaceable(saved) {
|
|
725
|
+
if (!canReplaceSafeRelayrQuote(saved))
|
|
726
|
+
return result("pending", saved);
|
|
727
|
+
if (!saved.bundleUuid)
|
|
728
|
+
return null;
|
|
729
|
+
const [status, read] = await bundleUnpaid(saved);
|
|
730
|
+
return status === "unpaid" ? null : held(status, read);
|
|
731
|
+
}
|
|
501
732
|
async function inspect(session, signal) {
|
|
502
733
|
const report = (progress, rechecking = false) => {
|
|
503
734
|
if (!signal?.aborted)
|
|
@@ -509,23 +740,28 @@ function createSafeRelayrController(options) {
|
|
|
509
740
|
return result("released", session);
|
|
510
741
|
if (session.state === "complete")
|
|
511
742
|
return result("complete", session);
|
|
512
|
-
if (hasObservedFunding(session) &&
|
|
513
|
-
session
|
|
743
|
+
if (hasObservedFunding(session) &&
|
|
744
|
+
(session.fundingObserved !== true ||
|
|
745
|
+
session.fundingObservedAt === undefined)) {
|
|
746
|
+
// A record saved before the clock existed starts it now.
|
|
747
|
+
session = {
|
|
748
|
+
...session,
|
|
749
|
+
fundingObserved: true,
|
|
750
|
+
fundingObservedAt: session.fundingObservedAt ?? Date.now(),
|
|
751
|
+
};
|
|
514
752
|
await store.save(session);
|
|
515
753
|
}
|
|
516
754
|
if (!session.bundleUuid || !session.quote)
|
|
517
755
|
return inspectMissingQuote(session);
|
|
518
756
|
const quote = requireSessionQuote(session);
|
|
519
757
|
const chains = session.executions.map(({ entry }) => entry.chain);
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
hasFundingRecords(bundle.transactions))
|
|
526
|
-
session =
|
|
527
|
-
await store.save(session);
|
|
528
|
-
}
|
|
758
|
+
const bundleUuid = session.bundleUuid;
|
|
759
|
+
const bundle = await statusRead(() => (0, relayr_js_1.readRelayrBundle)(bundleUuid, { fetch: fetchRelayr })).catch(() => null);
|
|
760
|
+
if (!bundle)
|
|
761
|
+
return held("unknown", session);
|
|
762
|
+
if (bundle.payment_received === true ||
|
|
763
|
+
hasFundingRecords(bundle.transactions))
|
|
764
|
+
session = await observed(session);
|
|
529
765
|
if (!Array.isArray(bundle.transactions))
|
|
530
766
|
throw new SafeRelayrRecoveryError(session, "Relayr has not returned this bundle's transactions. Check the existing bundle again.");
|
|
531
767
|
const records = bundle.transactions;
|
|
@@ -691,18 +927,28 @@ function createSafeRelayrController(options) {
|
|
|
691
927
|
everyReverted = false;
|
|
692
928
|
}
|
|
693
929
|
}
|
|
930
|
+
// Funding reported once stays unresolved until the chain proves a
|
|
931
|
+
// payment funded it (above) or the calls ran: a later unpaid read,
|
|
932
|
+
// or this session's own payments reverting, can't exclude another
|
|
933
|
+
// payment. No release, no retry.
|
|
934
|
+
if (hasObservedFunding(session))
|
|
935
|
+
return await fundingUnresolved(session);
|
|
694
936
|
if (!everyReverted) {
|
|
695
937
|
// A payment through a wallet contract that reverted is no
|
|
696
938
|
// RelayrPaymentRevertedError. Once nothing can fund the quote, it
|
|
697
|
-
// is released like an expired one.
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
939
|
+
// is released like an expired one. A payment that can't be shown
|
|
940
|
+
// reverted (dropped, or unreadable) is unknown: never released on
|
|
941
|
+
// its own, since no node can prove a transaction doesn't exist;
|
|
942
|
+
// the warned exit is offered once the chain says it has none.
|
|
943
|
+
const [status, read] = await bundleUnpaid(session);
|
|
944
|
+
session = read;
|
|
945
|
+
if (status === "funded")
|
|
946
|
+
return held("funded", session);
|
|
947
|
+
const disposition = status === "unpaid" ? await disposed(session, quote, chains) : null;
|
|
948
|
+
if (!disposition || disposition.state === "unknown")
|
|
949
|
+
return held("unknown", session);
|
|
950
|
+
session = disposition.session;
|
|
951
|
+
if (disposition.state !== "released")
|
|
706
952
|
return result("pending", session);
|
|
707
953
|
session = {
|
|
708
954
|
...session,
|
|
@@ -715,13 +961,15 @@ function createSafeRelayrController(options) {
|
|
|
715
961
|
}
|
|
716
962
|
session = { ...session, paymentStatus: "reverted" };
|
|
717
963
|
await store.save(session);
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
964
|
+
const [status, read] = await bundleUnpaid(session);
|
|
965
|
+
session = read;
|
|
966
|
+
if (status !== "unpaid")
|
|
967
|
+
return held(status, session);
|
|
968
|
+
// Unpaid, its release may still be unproven: it says why.
|
|
969
|
+
const disposition = (await disposed(session, quote, chains, true));
|
|
970
|
+
session = disposition.session;
|
|
971
|
+
if (disposition.state === "unknown")
|
|
972
|
+
return held("unknown", session);
|
|
725
973
|
if (disposition.state === "funded")
|
|
726
974
|
return result("pending", session);
|
|
727
975
|
if (disposition.state === "released") {
|
|
@@ -739,13 +987,7 @@ function createSafeRelayrController(options) {
|
|
|
739
987
|
session.fundingObserved) {
|
|
740
988
|
// A wallet invocation without a known hash may still have broadcast.
|
|
741
989
|
return session.fundingObserved && !known.length
|
|
742
|
-
?
|
|
743
|
-
...result("pending", session),
|
|
744
|
-
recovery: {
|
|
745
|
-
reason: "funding-unresolved",
|
|
746
|
-
message: "This saved selection has reported funding or execution activity. Check the existing bundle and its funding transactions before submitting another payment.",
|
|
747
|
-
},
|
|
748
|
-
}
|
|
990
|
+
? await fundingUnresolved(session)
|
|
749
991
|
: result("pending", session);
|
|
750
992
|
}
|
|
751
993
|
const quoted = (0, relayr_js_1.relayrQuotedOptions)(quote, chains);
|
|
@@ -756,18 +998,15 @@ function createSafeRelayrController(options) {
|
|
|
756
998
|
? [false]
|
|
757
999
|
: await Promise.all(quoted.map(async ({ details }) => {
|
|
758
1000
|
const client = options.clientFor(details.chainId);
|
|
759
|
-
return
|
|
760
|
-
|
|
1001
|
+
return client
|
|
1002
|
+
? (0, relayr_js_1.relayrDeadlinePassed)(client, details.deadline)
|
|
1003
|
+
: false;
|
|
761
1004
|
}));
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
}
|
|
768
|
-
catch {
|
|
769
|
-
return result("pending", session);
|
|
770
|
-
}
|
|
1005
|
+
const [unpaid, read] = await bundleUnpaid(session);
|
|
1006
|
+
session = read;
|
|
1007
|
+
if (unpaid !== "unpaid")
|
|
1008
|
+
return held(unpaid, session);
|
|
1009
|
+
if (expired.every((passed) => passed === true)) {
|
|
771
1010
|
session = {
|
|
772
1011
|
...session,
|
|
773
1012
|
state: "released",
|
|
@@ -777,15 +1016,11 @@ function createSafeRelayrController(options) {
|
|
|
777
1016
|
await store.save(session);
|
|
778
1017
|
return result("released", session);
|
|
779
1018
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
catch {
|
|
786
|
-
return result("pending", session);
|
|
787
|
-
}
|
|
788
|
-
const allowed = session.payments.length && payments.length
|
|
1019
|
+
// No option the browser's clock still allows, though the chain hasn't
|
|
1020
|
+
// shown the quote expired: closing, or unknown if the chain couldn't say.
|
|
1021
|
+
if (!payments.length)
|
|
1022
|
+
return held(expired.some((passed) => passed === null) ? "unknown" : "closing", session);
|
|
1023
|
+
const allowed = session.payments.length
|
|
789
1024
|
? [(0, relayr_js_1.relayrRetryOption)(session.payments, payments)]
|
|
790
1025
|
: payments;
|
|
791
1026
|
return allowed.length
|
|
@@ -804,9 +1039,12 @@ function createSafeRelayrController(options) {
|
|
|
804
1039
|
return store.withLock(account, async () => {
|
|
805
1040
|
checkAccount(account, signal);
|
|
806
1041
|
const reservations = (await store.list(account)).filter((session) => reserves(session, executions));
|
|
807
|
-
for (const
|
|
808
|
-
|
|
1042
|
+
for (const found of reservations) {
|
|
1043
|
+
const kept = await unreplaceable(found);
|
|
1044
|
+
if (!kept)
|
|
809
1045
|
continue;
|
|
1046
|
+
// What its status read saved, a funding report included.
|
|
1047
|
+
const saved = kept.session;
|
|
810
1048
|
let checked;
|
|
811
1049
|
try {
|
|
812
1050
|
checked = await inspect(saved, signal);
|
|
@@ -842,8 +1080,9 @@ function createSafeRelayrController(options) {
|
|
|
842
1080
|
for (const saved of await store.list(account)) {
|
|
843
1081
|
if (!reserves(saved, executions))
|
|
844
1082
|
continue;
|
|
845
|
-
|
|
846
|
-
|
|
1083
|
+
const kept = await unreplaceable(saved);
|
|
1084
|
+
if (kept)
|
|
1085
|
+
throw new SafeRelayrRecoveryError(kept.session, kept.recovery?.message, kept.recovery);
|
|
847
1086
|
await store.save({
|
|
848
1087
|
...saved,
|
|
849
1088
|
state: "released",
|
|
@@ -938,17 +1177,21 @@ function createSafeRelayrController(options) {
|
|
|
938
1177
|
phase("payment-checking", session, signal);
|
|
939
1178
|
await revalidate(session.executions, account, onStatus, true, signal);
|
|
940
1179
|
await assertUnreserved(account, session.executions, session.id);
|
|
941
|
-
|
|
942
|
-
|
|
1180
|
+
await statusRead(() => session.payments.length
|
|
1181
|
+
? (0, relayr_js_1.requireRelayrRetry)(options.clientFor, {
|
|
943
1182
|
payments: session.payments,
|
|
944
1183
|
from: account,
|
|
945
1184
|
bundleUuid: session.bundleUuid,
|
|
946
|
-
}, { fetch: fetchRelayr })
|
|
947
|
-
|
|
948
|
-
else
|
|
949
|
-
await (0, relayr_js_1.requireRelayrBundleUnpaid)(session.bundleUuid, {
|
|
1185
|
+
}, { fetch: fetchRelayr })
|
|
1186
|
+
: (0, relayr_js_1.requireRelayrBundleUnpaid)(session.bundleUuid, {
|
|
950
1187
|
fetch: fetchRelayr,
|
|
951
|
-
})
|
|
1188
|
+
})).catch(async (error) => {
|
|
1189
|
+
if (statusUnknown(error))
|
|
1190
|
+
throw unknownStatus(session);
|
|
1191
|
+
if (fundingReported(error))
|
|
1192
|
+
session = await observed(session);
|
|
1193
|
+
throw error;
|
|
1194
|
+
});
|
|
952
1195
|
checkAccount(account, signal);
|
|
953
1196
|
requireOpenPayment();
|
|
954
1197
|
verified = true;
|
|
@@ -957,6 +1200,17 @@ function createSafeRelayrController(options) {
|
|
|
957
1200
|
checkAccount(account, signal);
|
|
958
1201
|
if (!verified || sending)
|
|
959
1202
|
throw new Error("Recheck the Safe execution before funding it.");
|
|
1203
|
+
// The saved record, read again just before the wallet opens: funding
|
|
1204
|
+
// another flow reported, or any change to its payment, refuses.
|
|
1205
|
+
const stored = await load(account, session.id);
|
|
1206
|
+
if (hasObservedFunding(stored) ||
|
|
1207
|
+
stored.state !== session.state ||
|
|
1208
|
+
stored.paymentStatus !== session.paymentStatus ||
|
|
1209
|
+
stored.bundleUuid !== session.bundleUuid ||
|
|
1210
|
+
JSON.stringify(stored.payments) !== JSON.stringify(session.payments))
|
|
1211
|
+
throw new SafeRelayrRecoveryError(stored, hasObservedFunding(stored)
|
|
1212
|
+
? exports.SAFE_RELAYR_FUNDING_EXIT_LINE
|
|
1213
|
+
: "This saved selection changed while it was being paid. Check it again before paying.");
|
|
960
1214
|
session = { ...session, paymentStatus: "sending" };
|
|
961
1215
|
await store.save(session);
|
|
962
1216
|
try {
|
|
@@ -1074,31 +1328,66 @@ function createSafeRelayrController(options) {
|
|
|
1074
1328
|
!Number.isFinite(timeoutMs) ||
|
|
1075
1329
|
timeoutMs < 0)
|
|
1076
1330
|
throw new Error("Safe Relayr polling needs a positive interval and a finite timeout.");
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
};
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
aborted()
|
|
1099
|
-
|
|
1331
|
+
// The caller's signal, or a test reset, stops it.
|
|
1332
|
+
const halt = new AbortController();
|
|
1333
|
+
const stop = () => halt.abort(signal?.aborted
|
|
1334
|
+
? signal.reason
|
|
1335
|
+
: new DOMException("Aborted", "AbortError"));
|
|
1336
|
+
watching.add(stop);
|
|
1337
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
1338
|
+
if (signal?.aborted)
|
|
1339
|
+
stop();
|
|
1340
|
+
const halted = halt.signal;
|
|
1341
|
+
try {
|
|
1342
|
+
const started = Date.now();
|
|
1343
|
+
while (true) {
|
|
1344
|
+
halted.throwIfAborted();
|
|
1345
|
+
const next = await check({ account, sessionId, signal: halted });
|
|
1346
|
+
halted.throwIfAborted();
|
|
1347
|
+
await onUpdate?.(next);
|
|
1348
|
+
const remaining = timeoutMs - (Date.now() - started);
|
|
1349
|
+
if (next.state !== "pending" || remaining <= 0)
|
|
1350
|
+
return next;
|
|
1351
|
+
await new Promise((resolve, reject) => {
|
|
1352
|
+
const aborted = () => {
|
|
1353
|
+
clearTimeout(timer);
|
|
1354
|
+
reject(halted.reason);
|
|
1355
|
+
};
|
|
1356
|
+
const timer = setTimeout(() => {
|
|
1357
|
+
halted.removeEventListener("abort", aborted);
|
|
1358
|
+
resolve();
|
|
1359
|
+
}, Math.min(intervalMs, remaining));
|
|
1360
|
+
halted.addEventListener("abort", aborted, { once: true });
|
|
1361
|
+
if (halted.aborted)
|
|
1362
|
+
aborted();
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
finally {
|
|
1367
|
+
watching.delete(stop);
|
|
1368
|
+
signal?.removeEventListener("abort", stop);
|
|
1100
1369
|
}
|
|
1101
1370
|
}
|
|
1102
|
-
|
|
1371
|
+
/**
|
|
1372
|
+
* The user's warned exit from a quote whose status stays unknown (see
|
|
1373
|
+
* {@link SafeRelayrRecovery.exit}): rechecked now, then released, its
|
|
1374
|
+
* record kept for reconciliation, so a new quote can follow.
|
|
1375
|
+
*/
|
|
1376
|
+
async function exit({ account, sessionId, signal, }) {
|
|
1377
|
+
return store.withLock(account, async () => {
|
|
1378
|
+
checkAccount(account, signal);
|
|
1379
|
+
const checked = await inspect(await load(account, sessionId), signal);
|
|
1380
|
+
if (!checked.recovery?.exit)
|
|
1381
|
+
throw new SafeRelayrRecoveryError(checked.session, checked.recovery?.message, checked.recovery);
|
|
1382
|
+
const session = {
|
|
1383
|
+
...checked.session,
|
|
1384
|
+
state: "released",
|
|
1385
|
+
releaseReason: "payment-unconfirmed",
|
|
1386
|
+
};
|
|
1387
|
+
await store.save(session);
|
|
1388
|
+
return result("released", session);
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
return { prepare, check, fund, watch, exit };
|
|
1103
1392
|
}
|
|
1104
1393
|
//# sourceMappingURL=safeRelayr.js.map
|