@bananapus/nana-sdk-core 3.5.1 → 4.0.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/bin/wallet-check.mjs +489 -0
- package/dist/cjs/actions/suckerPairs.d.ts +5 -3
- package/dist/cjs/actions/suckerPairs.d.ts.map +1 -1
- package/dist/cjs/actions/suckerPairs.js +6 -26
- package/dist/cjs/actions/suckerPairs.js.map +1 -1
- package/dist/cjs/pause.d.ts +2 -0
- package/dist/cjs/pause.d.ts.map +1 -1
- package/dist/cjs/pause.js +17 -0
- package/dist/cjs/pause.js.map +1 -1
- package/dist/cjs/review/confirm.d.ts +52 -0
- package/dist/cjs/review/confirm.d.ts.map +1 -0
- package/dist/cjs/review/confirm.js +88 -0
- package/dist/cjs/review/confirm.js.map +1 -0
- package/dist/cjs/review/contractWrite.d.ts +5 -3
- package/dist/cjs/review/contractWrite.d.ts.map +1 -1
- package/dist/cjs/review/contractWrite.js +8 -7
- package/dist/cjs/review/contractWrite.js.map +1 -1
- package/dist/cjs/review/decode.d.ts +19 -1
- package/dist/cjs/review/decode.d.ts.map +1 -1
- package/dist/cjs/review/decode.js +30 -11
- package/dist/cjs/review/decode.js.map +1 -1
- package/dist/cjs/review/decodeCall.d.ts +21 -0
- package/dist/cjs/review/decodeCall.d.ts.map +1 -0
- package/dist/cjs/review/decodeCall.js +183 -0
- package/dist/cjs/review/decodeCall.js.map +1 -0
- package/dist/cjs/review/heldWrite.d.ts.map +1 -1
- package/dist/cjs/review/heldWrite.js +5 -4
- package/dist/cjs/review/heldWrite.js.map +1 -1
- package/dist/cjs/review/index.d.ts +11 -0
- package/dist/cjs/review/index.d.ts.map +1 -1
- package/dist/cjs/review/index.js +24 -0
- package/dist/cjs/review/index.js.map +1 -1
- package/dist/cjs/review/intents.d.ts +10 -0
- package/dist/cjs/review/intents.d.ts.map +1 -1
- package/dist/cjs/review/intents.js +13 -0
- package/dist/cjs/review/intents.js.map +1 -1
- package/dist/cjs/review/lineError.d.ts +34 -0
- package/dist/cjs/review/lineError.d.ts.map +1 -0
- package/dist/cjs/review/lineError.js +42 -0
- package/dist/cjs/review/lineError.js.map +1 -0
- package/dist/cjs/review/messages.d.ts +15 -3
- package/dist/cjs/review/messages.d.ts.map +1 -1
- package/dist/cjs/review/messages.js +16 -4
- package/dist/cjs/review/messages.js.map +1 -1
- package/dist/cjs/review/model.d.ts +149 -0
- package/dist/cjs/review/model.d.ts.map +1 -0
- package/dist/cjs/review/model.js +750 -0
- package/dist/cjs/review/model.js.map +1 -0
- package/dist/cjs/review/plan.d.ts +63 -0
- package/dist/cjs/review/plan.d.ts.map +1 -0
- package/dist/cjs/review/plan.js +149 -0
- package/dist/cjs/review/plan.js.map +1 -0
- package/dist/cjs/review/react/index.d.ts +1 -0
- package/dist/cjs/review/react/index.d.ts.map +1 -1
- package/dist/cjs/review/react/index.js +1 -0
- package/dist/cjs/review/react/index.js.map +1 -1
- package/dist/cjs/review/react/useReviewedRun.d.ts +96 -0
- package/dist/cjs/review/react/useReviewedRun.d.ts.map +1 -0
- package/dist/cjs/review/react/useReviewedRun.js +261 -0
- package/dist/cjs/review/react/useReviewedRun.js.map +1 -0
- package/dist/cjs/review/receipt.d.ts +4 -1
- package/dist/cjs/review/receipt.d.ts.map +1 -1
- package/dist/cjs/review/receipt.js +7 -3
- package/dist/cjs/review/receipt.js.map +1 -1
- package/dist/cjs/review/relayr.d.ts +13 -4
- package/dist/cjs/review/relayr.d.ts.map +1 -1
- package/dist/cjs/review/relayr.js +51 -8
- package/dist/cjs/review/relayr.js.map +1 -1
- package/dist/cjs/review/relayrSend.d.ts +135 -0
- package/dist/cjs/review/relayrSend.d.ts.map +1 -0
- package/dist/cjs/review/relayrSend.js +943 -0
- package/dist/cjs/review/relayrSend.js.map +1 -0
- package/dist/cjs/review/reviewQueue.d.ts +10 -9
- package/dist/cjs/review/reviewQueue.d.ts.map +1 -1
- package/dist/cjs/review/reviewQueue.js +19 -29
- package/dist/cjs/review/reviewQueue.js.map +1 -1
- package/dist/cjs/review/reviewRequests.d.ts +86 -0
- package/dist/cjs/review/reviewRequests.d.ts.map +1 -0
- package/dist/cjs/review/reviewRequests.js +266 -0
- package/dist/cjs/review/reviewRequests.js.map +1 -0
- package/dist/cjs/review/safeRelayr.d.ts +3 -1
- package/dist/cjs/review/safeRelayr.d.ts.map +1 -1
- package/dist/cjs/review/safeRelayr.js +5 -1
- package/dist/cjs/review/safeRelayr.js.map +1 -1
- package/dist/cjs/review/safeSend.d.ts +69 -0
- package/dist/cjs/review/safeSend.d.ts.map +1 -0
- package/dist/cjs/review/safeSend.js +308 -0
- package/dist/cjs/review/safeSend.js.map +1 -0
- package/dist/cjs/review/send.d.ts +241 -0
- package/dist/cjs/review/send.d.ts.map +1 -0
- package/dist/cjs/review/send.js +1017 -0
- package/dist/cjs/review/send.js.map +1 -0
- package/dist/cjs/review/sequence.d.ts +77 -0
- package/dist/cjs/review/sequence.d.ts.map +1 -0
- package/dist/cjs/review/sequence.js +232 -0
- package/dist/cjs/review/sequence.js.map +1 -0
- package/dist/cjs/review/sign.d.ts +109 -0
- package/dist/cjs/review/sign.d.ts.map +1 -0
- package/dist/cjs/review/sign.js +374 -0
- package/dist/cjs/review/sign.js.map +1 -0
- package/dist/cjs/review/simulation.d.ts +41 -2
- package/dist/cjs/review/simulation.d.ts.map +1 -1
- package/dist/cjs/review/simulation.js +99 -29
- package/dist/cjs/review/simulation.js.map +1 -1
- package/dist/cjs/review/transaction-message.d.ts +13 -0
- package/dist/cjs/review/transaction-message.d.ts.map +1 -1
- package/dist/cjs/review/transaction-message.js +25 -0
- package/dist/cjs/review/transaction-message.js.map +1 -1
- package/dist/cjs/review/transactionReview.d.ts +27 -19
- package/dist/cjs/review/transactionReview.d.ts.map +1 -1
- package/dist/cjs/review/transactionReview.js +22 -63
- package/dist/cjs/review/transactionReview.js.map +1 -1
- package/dist/cjs/review/wallet.d.ts +82 -0
- package/dist/cjs/review/wallet.d.ts.map +1 -0
- package/dist/cjs/review/wallet.js +157 -0
- package/dist/cjs/review/wallet.js.map +1 -0
- package/dist/cjs/review/writeHold.d.ts +100 -12
- package/dist/cjs/review/writeHold.d.ts.map +1 -1
- package/dist/cjs/review/writeHold.js +61 -13
- package/dist/cjs/review/writeHold.js.map +1 -1
- package/dist/cjs/review/writeRecovery.d.ts +6 -1
- package/dist/cjs/review/writeRecovery.d.ts.map +1 -1
- package/dist/cjs/review/writeRecovery.js +108 -40
- package/dist/cjs/review/writeRecovery.js.map +1 -1
- package/dist/cjs/safeService.d.ts +27 -4
- package/dist/cjs/safeService.d.ts.map +1 -1
- package/dist/cjs/safeService.js +120 -3
- package/dist/cjs/safeService.js.map +1 -1
- package/dist/cjs/testing.d.ts +24 -0
- package/dist/cjs/testing.d.ts.map +1 -1
- package/dist/cjs/testing.js +26 -1
- package/dist/cjs/testing.js.map +1 -1
- package/dist/cjs/v6/defifa.d.ts.map +1 -1
- package/dist/cjs/v6/defifa.js +24 -23
- package/dist/cjs/v6/defifa.js.map +1 -1
- package/dist/cjs/v6/executionErrors.d.ts.map +1 -1
- package/dist/cjs/v6/executionErrors.js +3 -2
- package/dist/cjs/v6/executionErrors.js.map +1 -1
- package/dist/cjs/v6/pay.d.ts +25 -7
- package/dist/cjs/v6/pay.d.ts.map +1 -1
- package/dist/cjs/v6/pay.js +168 -40
- package/dist/cjs/v6/pay.js.map +1 -1
- package/dist/cjs/v6/suckers.d.ts +30 -0
- package/dist/cjs/v6/suckers.d.ts.map +1 -1
- package/dist/cjs/v6/suckers.js +69 -5
- package/dist/cjs/v6/suckers.js.map +1 -1
- package/dist/esm/actions/suckerPairs.d.ts +5 -3
- package/dist/esm/actions/suckerPairs.d.ts.map +1 -1
- package/dist/esm/actions/suckerPairs.js +7 -27
- package/dist/esm/actions/suckerPairs.js.map +1 -1
- package/dist/esm/pause.d.ts +2 -0
- package/dist/esm/pause.d.ts.map +1 -1
- package/dist/esm/pause.js +16 -0
- package/dist/esm/pause.js.map +1 -1
- package/dist/esm/review/confirm.d.ts +52 -0
- package/dist/esm/review/confirm.d.ts.map +1 -0
- package/dist/esm/review/confirm.js +83 -0
- package/dist/esm/review/confirm.js.map +1 -0
- package/dist/esm/review/contractWrite.d.ts +5 -3
- package/dist/esm/review/contractWrite.d.ts.map +1 -1
- package/dist/esm/review/contractWrite.js +8 -7
- package/dist/esm/review/contractWrite.js.map +1 -1
- package/dist/esm/review/decode.d.ts +19 -1
- package/dist/esm/review/decode.d.ts.map +1 -1
- package/dist/esm/review/decode.js +29 -14
- package/dist/esm/review/decode.js.map +1 -1
- package/dist/esm/review/decodeCall.d.ts +21 -0
- package/dist/esm/review/decodeCall.d.ts.map +1 -0
- package/dist/esm/review/decodeCall.js +180 -0
- package/dist/esm/review/decodeCall.js.map +1 -0
- package/dist/esm/review/heldWrite.d.ts.map +1 -1
- package/dist/esm/review/heldWrite.js +5 -4
- package/dist/esm/review/heldWrite.js.map +1 -1
- package/dist/esm/review/index.d.ts +11 -0
- package/dist/esm/review/index.d.ts.map +1 -1
- package/dist/esm/review/index.js +11 -0
- package/dist/esm/review/index.js.map +1 -1
- package/dist/esm/review/intents.d.ts +10 -0
- package/dist/esm/review/intents.d.ts.map +1 -1
- package/dist/esm/review/intents.js +12 -0
- package/dist/esm/review/intents.js.map +1 -1
- package/dist/esm/review/lineError.d.ts +34 -0
- package/dist/esm/review/lineError.d.ts.map +1 -0
- package/dist/esm/review/lineError.js +36 -0
- package/dist/esm/review/lineError.js.map +1 -0
- package/dist/esm/review/messages.d.ts +15 -3
- package/dist/esm/review/messages.d.ts.map +1 -1
- package/dist/esm/review/messages.js +15 -3
- package/dist/esm/review/messages.js.map +1 -1
- package/dist/esm/review/model.d.ts +149 -0
- package/dist/esm/review/model.d.ts.map +1 -0
- package/dist/esm/review/model.js +746 -0
- package/dist/esm/review/model.js.map +1 -0
- package/dist/esm/review/plan.d.ts +63 -0
- package/dist/esm/review/plan.d.ts.map +1 -0
- package/dist/esm/review/plan.js +141 -0
- package/dist/esm/review/plan.js.map +1 -0
- package/dist/esm/review/react/index.d.ts +1 -0
- package/dist/esm/review/react/index.d.ts.map +1 -1
- package/dist/esm/review/react/index.js +1 -0
- package/dist/esm/review/react/index.js.map +1 -1
- package/dist/esm/review/react/useReviewedRun.d.ts +96 -0
- package/dist/esm/review/react/useReviewedRun.d.ts.map +1 -0
- package/dist/esm/review/react/useReviewedRun.js +257 -0
- package/dist/esm/review/react/useReviewedRun.js.map +1 -0
- package/dist/esm/review/receipt.d.ts +4 -1
- package/dist/esm/review/receipt.d.ts.map +1 -1
- package/dist/esm/review/receipt.js +6 -2
- package/dist/esm/review/receipt.js.map +1 -1
- package/dist/esm/review/relayr.d.ts +13 -4
- package/dist/esm/review/relayr.d.ts.map +1 -1
- package/dist/esm/review/relayr.js +50 -8
- package/dist/esm/review/relayr.js.map +1 -1
- package/dist/esm/review/relayrSend.d.ts +135 -0
- package/dist/esm/review/relayrSend.d.ts.map +1 -0
- package/dist/esm/review/relayrSend.js +934 -0
- package/dist/esm/review/relayrSend.js.map +1 -0
- package/dist/esm/review/reviewQueue.d.ts +10 -9
- package/dist/esm/review/reviewQueue.d.ts.map +1 -1
- package/dist/esm/review/reviewQueue.js +17 -26
- package/dist/esm/review/reviewQueue.js.map +1 -1
- package/dist/esm/review/reviewRequests.d.ts +86 -0
- package/dist/esm/review/reviewRequests.d.ts.map +1 -0
- package/dist/esm/review/reviewRequests.js +263 -0
- package/dist/esm/review/reviewRequests.js.map +1 -0
- package/dist/esm/review/safeRelayr.d.ts +3 -1
- package/dist/esm/review/safeRelayr.d.ts.map +1 -1
- package/dist/esm/review/safeRelayr.js +5 -1
- package/dist/esm/review/safeRelayr.js.map +1 -1
- package/dist/esm/review/safeSend.d.ts +69 -0
- package/dist/esm/review/safeSend.d.ts.map +1 -0
- package/dist/esm/review/safeSend.js +303 -0
- package/dist/esm/review/safeSend.js.map +1 -0
- package/dist/esm/review/send.d.ts +241 -0
- package/dist/esm/review/send.d.ts.map +1 -0
- package/dist/esm/review/send.js +1011 -0
- package/dist/esm/review/send.js.map +1 -0
- package/dist/esm/review/sequence.d.ts +77 -0
- package/dist/esm/review/sequence.d.ts.map +1 -0
- package/dist/esm/review/sequence.js +223 -0
- package/dist/esm/review/sequence.js.map +1 -0
- package/dist/esm/review/sign.d.ts +109 -0
- package/dist/esm/review/sign.d.ts.map +1 -0
- package/dist/esm/review/sign.js +368 -0
- package/dist/esm/review/sign.js.map +1 -0
- package/dist/esm/review/simulation.d.ts +41 -2
- package/dist/esm/review/simulation.d.ts.map +1 -1
- package/dist/esm/review/simulation.js +95 -29
- package/dist/esm/review/simulation.js.map +1 -1
- package/dist/esm/review/transaction-message.d.ts +13 -0
- package/dist/esm/review/transaction-message.d.ts.map +1 -1
- package/dist/esm/review/transaction-message.js +23 -0
- package/dist/esm/review/transaction-message.js.map +1 -1
- package/dist/esm/review/transactionReview.d.ts +27 -19
- package/dist/esm/review/transactionReview.d.ts.map +1 -1
- package/dist/esm/review/transactionReview.js +19 -56
- package/dist/esm/review/transactionReview.js.map +1 -1
- package/dist/esm/review/wallet.d.ts +82 -0
- package/dist/esm/review/wallet.d.ts.map +1 -0
- package/dist/esm/review/wallet.js +150 -0
- package/dist/esm/review/wallet.js.map +1 -0
- package/dist/esm/review/writeHold.d.ts +100 -12
- package/dist/esm/review/writeHold.d.ts.map +1 -1
- package/dist/esm/review/writeHold.js +59 -13
- package/dist/esm/review/writeHold.js.map +1 -1
- package/dist/esm/review/writeRecovery.d.ts +6 -1
- package/dist/esm/review/writeRecovery.d.ts.map +1 -1
- package/dist/esm/review/writeRecovery.js +111 -43
- package/dist/esm/review/writeRecovery.js.map +1 -1
- package/dist/esm/safeService.d.ts +27 -4
- package/dist/esm/safeService.d.ts.map +1 -1
- package/dist/esm/safeService.js +119 -4
- package/dist/esm/safeService.js.map +1 -1
- package/dist/esm/testing.d.ts +24 -0
- package/dist/esm/testing.d.ts.map +1 -1
- package/dist/esm/testing.js +23 -1
- package/dist/esm/testing.js.map +1 -1
- package/dist/esm/v6/defifa.d.ts.map +1 -1
- package/dist/esm/v6/defifa.js +24 -23
- package/dist/esm/v6/defifa.js.map +1 -1
- package/dist/esm/v6/executionErrors.d.ts.map +1 -1
- package/dist/esm/v6/executionErrors.js +3 -2
- package/dist/esm/v6/executionErrors.js.map +1 -1
- package/dist/esm/v6/pay.d.ts +25 -7
- package/dist/esm/v6/pay.d.ts.map +1 -1
- package/dist/esm/v6/pay.js +166 -39
- package/dist/esm/v6/pay.js.map +1 -1
- package/dist/esm/v6/suckers.d.ts +30 -0
- package/dist/esm/v6/suckers.d.ts.map +1 -1
- package/dist/esm/v6/suckers.js +67 -5
- package/dist/esm/v6/suckers.js.map +1 -1
- package/package.json +11 -2
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
import { ReviewedCallRevertedError, ReviewLineError } from "./lineError.js";
|
|
2
|
+
import { encodeFunctionData, formatEther, } from "viem";
|
|
3
|
+
import { promptReview } from "./confirm.js";
|
|
4
|
+
import { isDefiniteWalletRejection, SubmittedContractWriteError, submitReviewedContractWrite, } from "./contractWrite.js";
|
|
5
|
+
import { JB_CHAINS } from "../constants.js";
|
|
6
|
+
import { gasWithHeadroom } from "./gas.js";
|
|
7
|
+
import { findPendingSafeAppProposal, hasSafeService, isSafeExecTransaction, } from "../safeService.js";
|
|
8
|
+
import { REVIEWED_ACCOUNT_CHANGED_LINE, WRITE_HOLD_CALL_FAILED_LINE, WRITE_HOLD_SAFE_UNCONFIRMED_LINE, } from "./messages.js";
|
|
9
|
+
import { buildReviewModel, enrichReviewModel, } from "./model.js";
|
|
10
|
+
import { mintPlan, relayrStandInSender, REVIEWED_PLAN_REFUSED_LINE, spendPlan, } from "./plan.js";
|
|
11
|
+
import { waitForTrackedReceipt } from "./receipt.js";
|
|
12
|
+
import { relayrPaymentChains } from "./relayr.js";
|
|
13
|
+
import { relayrFeeCap } from "./relayrSend.js";
|
|
14
|
+
import { assertSavableCalls, readReviewedSequence, removeReviewedSequence, REVIEWED_SEQUENCE_MOVED_LINE, REVIEWED_SEQUENCE_UNCERTAIN_LINE, REVIEWED_SEQUENCE_UNFINISHED_LINE, saveReviewedSequence, } from "./sequence.js";
|
|
15
|
+
import { plannedCallsOf, prepareSignature, signPrepared, } from "./sign.js";
|
|
16
|
+
import { isRevert, REVERT_UNKNOWN_LINE, revertDetail, revertReason, simulateCallSequence, simulateStateChangingTransaction, simulationFailure, } from "./simulation.js";
|
|
17
|
+
import { unsupportedWalletRequest, walletReady, } from "./wallet.js";
|
|
18
|
+
import { openStepHold, safeBatchCall, WriteHeldError, WriteHoldStaleReviewError, } from "./writeHold.js";
|
|
19
|
+
import { createHeldWriteStorage, } from "./writeRecovery.js";
|
|
20
|
+
const CHANGED = "Transaction data changed after review. Nothing was sent; review it again.";
|
|
21
|
+
const MISMATCHED = "This call's data does not match its arguments. Nothing was sent.";
|
|
22
|
+
const BAD_GAS = "This call's gas limit is not valid. Nothing was sent.";
|
|
23
|
+
const BAD_ADOPT = "This call's adoption rule is not valid. Nothing was sent.";
|
|
24
|
+
const ACCOUNT_CHANGED = REVIEWED_ACCOUNT_CHANGED_LINE;
|
|
25
|
+
const NOT_SAVED = "This action's progress could not be saved. Nothing was sent; review it again.";
|
|
26
|
+
export const SAFE_BATCH_UNSUPPORTED_LINE = "This Safe connection can't propose these calls as one transaction. Nothing was sent.";
|
|
27
|
+
export const SAFE_BATCH_UNFOLLOWABLE_LINE = "Your Safe took this batch, but it can't be followed from here. Check your Safe before sending again.";
|
|
28
|
+
const SIMULATION_UNAVAILABLE = "Simulation unavailable. This could not be checked before you confirm; it is checked again before your wallet opens.";
|
|
29
|
+
/**
|
|
30
|
+
* `call` as it encodes now, each field read once, so a getter cannot show one
|
|
31
|
+
* value and send another. Refuses `data` that is not its arguments' encoding.
|
|
32
|
+
*/
|
|
33
|
+
function exact(call) {
|
|
34
|
+
const { chainId, to, data, value, gas, abi, functionName, args } = call;
|
|
35
|
+
const { label, contractName } = call;
|
|
36
|
+
const ignoring = call.adoptIgnoringArgs;
|
|
37
|
+
if (gas !== undefined && (typeof gas !== "bigint" || gas <= 0n)) {
|
|
38
|
+
throw new ReviewLineError(BAD_GAS);
|
|
39
|
+
}
|
|
40
|
+
if (ignoring !== undefined && !Array.isArray(ignoring)) {
|
|
41
|
+
throw new ReviewLineError(BAD_ADOPT);
|
|
42
|
+
}
|
|
43
|
+
const adoptIgnoringArgs = ignoring && Object.freeze([...ignoring]);
|
|
44
|
+
if (adoptIgnoringArgs &&
|
|
45
|
+
(!abi ||
|
|
46
|
+
!functionName ||
|
|
47
|
+
new Set(adoptIgnoringArgs).size !== adoptIgnoringArgs.length ||
|
|
48
|
+
adoptIgnoringArgs.some((index) => !Number.isInteger(index) || index < 0 || index >= (args?.length ?? 0)))) {
|
|
49
|
+
throw new ReviewLineError(BAD_ADOPT);
|
|
50
|
+
}
|
|
51
|
+
if (abi && functionName) {
|
|
52
|
+
const encoded = encodeFunctionData({
|
|
53
|
+
abi,
|
|
54
|
+
functionName,
|
|
55
|
+
args: args ?? [],
|
|
56
|
+
});
|
|
57
|
+
if (encoded.toLowerCase() !== data.toLowerCase()) {
|
|
58
|
+
throw new ReviewLineError(MISMATCHED);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
sent: Object.freeze({
|
|
63
|
+
chainId,
|
|
64
|
+
to,
|
|
65
|
+
data,
|
|
66
|
+
value: value ?? 0n,
|
|
67
|
+
...(gas === undefined ? {} : { gas }),
|
|
68
|
+
}),
|
|
69
|
+
shown: {
|
|
70
|
+
abi,
|
|
71
|
+
functionName,
|
|
72
|
+
args,
|
|
73
|
+
label,
|
|
74
|
+
contractName,
|
|
75
|
+
...(adoptIgnoringArgs ? { adoptIgnoringArgs } : {}),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** What a Safe app may adopt a queued proposal by, as reviewed. */
|
|
80
|
+
function adopting({ abi, adoptIgnoringArgs, }) {
|
|
81
|
+
return abi && adoptIgnoringArgs
|
|
82
|
+
? { abi, ignoring: adoptIgnoringArgs }
|
|
83
|
+
: undefined;
|
|
84
|
+
}
|
|
85
|
+
function sameCall(a, b) {
|
|
86
|
+
return (a.chainId === b.chainId &&
|
|
87
|
+
a.to.toLowerCase() === b.to.toLowerCase() &&
|
|
88
|
+
a.data.toLowerCase() === b.data.toLowerCase() &&
|
|
89
|
+
a.value === b.value &&
|
|
90
|
+
a.gas === b.gas);
|
|
91
|
+
}
|
|
92
|
+
/** The chain's name in a line the person reads, never only its id when core knows it. */
|
|
93
|
+
function chainNameOf(client, chainId) {
|
|
94
|
+
return (client.chain?.name ??
|
|
95
|
+
JB_CHAINS[chainId]?.name ??
|
|
96
|
+
`chain ${chainId}`);
|
|
97
|
+
}
|
|
98
|
+
/** A call as the review shows it, from `from` (none: Relayr's own account runs it). */
|
|
99
|
+
function shownCall({ sent: { gas, ...sent }, shown }, from, safe) {
|
|
100
|
+
return {
|
|
101
|
+
...sent,
|
|
102
|
+
...(from ? { from } : {}),
|
|
103
|
+
// A Safe app signs safeTxGas 0, never the app's gas.
|
|
104
|
+
...(safe ? { safeTxGas: 0n } : gas === undefined ? {} : { gas }),
|
|
105
|
+
...(shown.abi ? { abi: shown.abi } : {}),
|
|
106
|
+
...(shown.functionName ? { functionName: shown.functionName } : {}),
|
|
107
|
+
...(shown.args ? { args: shown.args } : {}),
|
|
108
|
+
...(shown.label
|
|
109
|
+
? { label: shown.label }
|
|
110
|
+
: from
|
|
111
|
+
? {}
|
|
112
|
+
: { label: "Sent by Relayr" }),
|
|
113
|
+
...(shown.contractName ? { contractName: shown.contractName } : {}),
|
|
114
|
+
...(shown.adoptIgnoringArgs
|
|
115
|
+
? { adoptIgnoringArgs: shown.adoptIgnoringArgs }
|
|
116
|
+
: {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function labelOf(call, index) {
|
|
120
|
+
return call.label ?? call.functionName ?? `Step ${index + 1}`;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The latest block, or `minimum` while the node has not reached it: never
|
|
124
|
+
* state from before a prerequisite took effect, never stale state after it.
|
|
125
|
+
*/
|
|
126
|
+
async function notBefore(client, minimum) {
|
|
127
|
+
const head = await client.getBlockNumber();
|
|
128
|
+
return head > minimum ? head : minimum;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The review-time simulation of every call, per chain: a sequence through
|
|
132
|
+
* {@link simulateCallSequence}, a lone call through
|
|
133
|
+
* {@link simulateStateChangingTransaction}. A lone call that needs a step on
|
|
134
|
+
* another chain is left to the simulation before its send. It never rejects:
|
|
135
|
+
* a revert is `failed`, anything else `unavailable`.
|
|
136
|
+
*/
|
|
137
|
+
async function reviewSimulation(fromOf, calls, sent, blocks, clientFor,
|
|
138
|
+
/** Steps whose value someone else pays: the sender's balance is topped up by it. */
|
|
139
|
+
funded) {
|
|
140
|
+
const chains = [...new Set(sent.map((call) => call.chainId))];
|
|
141
|
+
const perChain = chains.map(async (chainId) => {
|
|
142
|
+
const steps = sent.flatMap((call, index) => call.chainId === chainId ? [index] : []);
|
|
143
|
+
const paid = steps.reduce((sum, index) => sum + (funded?.(index) ? (sent[index].value ?? 0n) : 0n), 0n);
|
|
144
|
+
let chainName = `chain ${chainId}`;
|
|
145
|
+
try {
|
|
146
|
+
const client = clientFor(chainId);
|
|
147
|
+
chainName = chainNameOf(client, chainId);
|
|
148
|
+
const from = fromOf(steps[0]);
|
|
149
|
+
const balance = paid
|
|
150
|
+
? { balance: (await client.getBalance({ address: from })) + paid }
|
|
151
|
+
: {};
|
|
152
|
+
if (steps.length > 1) {
|
|
153
|
+
// A sequence runs from one sender; mixed senders are checked before each send.
|
|
154
|
+
if (steps.some((index) => fromOf(index) !== from))
|
|
155
|
+
return { status: "unavailable", message: SIMULATION_UNAVAILABLE };
|
|
156
|
+
await simulateCallSequence(client, {
|
|
157
|
+
from,
|
|
158
|
+
chainName,
|
|
159
|
+
calls: steps.map((index) => ({
|
|
160
|
+
to: sent[index].to,
|
|
161
|
+
data: sent[index].data,
|
|
162
|
+
value: sent[index].value,
|
|
163
|
+
gas: sent[index].gas,
|
|
164
|
+
label: labelOf(calls[index], index),
|
|
165
|
+
dependsOnPrior: calls[index].dependsOnPrior,
|
|
166
|
+
funded: funded?.(index) === true,
|
|
167
|
+
})),
|
|
168
|
+
...balance,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else if (!(calls[steps[0]].dependsOnPrior && steps[0] > 0)) {
|
|
172
|
+
const minimum = blocks[steps[0]];
|
|
173
|
+
await simulateStateChangingTransaction(client, {
|
|
174
|
+
from,
|
|
175
|
+
to: sent[steps[0]].to,
|
|
176
|
+
data: sent[steps[0]].data,
|
|
177
|
+
value: sent[steps[0]].value,
|
|
178
|
+
gas: sent[steps[0]].gas,
|
|
179
|
+
...balance,
|
|
180
|
+
...(minimum === undefined
|
|
181
|
+
? {}
|
|
182
|
+
: { blockNumber: await notBefore(client, minimum) }),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return { status: "passed" };
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (!isRevert(error))
|
|
189
|
+
return { status: "unavailable", message: SIMULATION_UNAVAILABLE };
|
|
190
|
+
const reason = revertReason(error);
|
|
191
|
+
return {
|
|
192
|
+
status: "failed",
|
|
193
|
+
// A sequence's failure is the SDK's line naming its call.
|
|
194
|
+
message: error instanceof ReviewLineError
|
|
195
|
+
? error.message
|
|
196
|
+
: `${labelOf(calls[steps[0]], steps[0])} cannot run on ${chainName}: ${reason ?? REVERT_UNKNOWN_LINE}`,
|
|
197
|
+
explained: reason !== null,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
// A revert on one chain is reported at once, whatever the others still wait on.
|
|
202
|
+
const failed = new Promise((resolve) => {
|
|
203
|
+
for (const result of perChain) {
|
|
204
|
+
void result.then((settled) => {
|
|
205
|
+
if (settled.status === "failed")
|
|
206
|
+
resolve(settled);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
const all = Promise.all(perChain).then((results) => results.find((result) => result.status === "unavailable") ?? {
|
|
211
|
+
status: "passed",
|
|
212
|
+
});
|
|
213
|
+
return Promise.race([failed, all]);
|
|
214
|
+
}
|
|
215
|
+
function simulationWarning(simulation) {
|
|
216
|
+
if (simulation.status === "failed") {
|
|
217
|
+
return { code: "simulation-failed", text: simulation.message };
|
|
218
|
+
}
|
|
219
|
+
if (simulation.status === "unavailable") {
|
|
220
|
+
return { code: "simulation-unavailable", text: SIMULATION_UNAVAILABLE };
|
|
221
|
+
}
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
/** One prompt over `model`, with the review-time simulation of `run` as its warning. */
|
|
225
|
+
async function promptSimulated(model, fromOf, calls, run, blocks, clientFor, signal, funded) {
|
|
226
|
+
const simulation = reviewSimulation(fromOf, calls, run, blocks, clientFor, funded);
|
|
227
|
+
const enriched = Promise.all([
|
|
228
|
+
enrichReviewModel(model, clientFor).catch(() => model),
|
|
229
|
+
simulation,
|
|
230
|
+
]).then(([read, simulated]) => {
|
|
231
|
+
const warning = simulationWarning(simulated);
|
|
232
|
+
return warning ? { ...read, warnings: [...read.warnings, warning] } : read;
|
|
233
|
+
});
|
|
234
|
+
await promptReview(model, simulation, enriched, signal);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* One review of calls an app then sends one by one, across chains and
|
|
238
|
+
* paths: core's prompt over exactly `action.calls`, simulated as their
|
|
239
|
+
* senders, and nothing else. The plan it returns lets {@link sendReviewed},
|
|
240
|
+
* `signReviewed`, `proposeReviewedSafeTransaction`, `payRelayrReviewed` and
|
|
241
|
+
* `runRelayrReviewed` skip their prompt for a call identical to one of its
|
|
242
|
+
* calls (account, chain, sender, target, data, value and gas: a call's
|
|
243
|
+
* exact gas limit, or a forward request's signed gas, is set before the
|
|
244
|
+
* review), each spent once, for {@link REVIEWED_PLAN_TTL_MS} after confirm.
|
|
245
|
+
* Anything else is refused.
|
|
246
|
+
*/
|
|
247
|
+
export async function reviewPlan(action, deps) {
|
|
248
|
+
const { account } = action;
|
|
249
|
+
const calls = [...action.calls];
|
|
250
|
+
if (!calls.length)
|
|
251
|
+
throw new ReviewLineError("There is no transaction to review.");
|
|
252
|
+
const froms = calls.map(({ from }) => from ?? account);
|
|
253
|
+
const snapshots = calls.map(exact);
|
|
254
|
+
const roundOf = calls.map(({ relayrRound }) => relayrRound);
|
|
255
|
+
const fees = new Map();
|
|
256
|
+
for (const round of new Set(roundOf)) {
|
|
257
|
+
if (round === undefined)
|
|
258
|
+
continue;
|
|
259
|
+
const members = snapshots.flatMap(({ sent }, index) => roundOf[index] === round
|
|
260
|
+
? [{ ...sent, raw: froms[index] === "relayr" }]
|
|
261
|
+
: []);
|
|
262
|
+
if (members.some(({ raw, gas }) => !raw && gas === undefined))
|
|
263
|
+
throw new ReviewLineError("A relayed call needs the gas limit its request signs.");
|
|
264
|
+
const chainId = action.relayrRounds?.[round]?.paymentChainId ?? members[0].chainId;
|
|
265
|
+
if (!relayrPaymentChains(members.map((member) => member.chainId)).includes(chainId))
|
|
266
|
+
throw new ReviewLineError("Choose a Relayr funding chain in the same network family as these destinations.");
|
|
267
|
+
fees.set(round, {
|
|
268
|
+
chainId,
|
|
269
|
+
cap: await relayrFeeCap(members.map(({ chainId, to, data, value, gas, raw }) => ({
|
|
270
|
+
chainId,
|
|
271
|
+
target: to,
|
|
272
|
+
data,
|
|
273
|
+
value,
|
|
274
|
+
gas: gas ?? 0n,
|
|
275
|
+
raw,
|
|
276
|
+
})), account, chainId, deps.clientFor),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
const feeRows = [...fees.values()].map(({ chainId, cap }, index) => ({
|
|
280
|
+
label: fees.size > 1 ? `Network fee ${index + 1}` : "Network fee",
|
|
281
|
+
value: `Up to ${formatEther(cap)} ETH on ${chainNameOf(deps.clientFor(chainId), chainId)}`,
|
|
282
|
+
strong: true,
|
|
283
|
+
}));
|
|
284
|
+
const context = [...(action.context ?? []), ...feeRows];
|
|
285
|
+
const model = buildReviewModel({
|
|
286
|
+
calls: snapshots.map((snapshot, index) => shownCall(snapshot, froms[index] === "relayr" ? undefined : froms[index], false)),
|
|
287
|
+
...(action.title ? { title: action.title } : {}),
|
|
288
|
+
...(action.description ? { description: action.description } : {}),
|
|
289
|
+
...(action.confirmLabel ? { confirmLabel: action.confirmLabel } : {}),
|
|
290
|
+
...(context.length ? { context } : {}),
|
|
291
|
+
});
|
|
292
|
+
const relayr = relayrStandInSender();
|
|
293
|
+
await promptSimulated(model, (index) => (froms[index] === "relayr" ? relayr : froms[index]), calls, snapshots.map(({ sent }) => sent), calls.map((call) => call.simulationBlockNumber), deps.clientFor, action.signal,
|
|
294
|
+
// Relayr pays a relayed call's value: its signer needs none of its own.
|
|
295
|
+
(index) => roundOf[index] !== undefined && froms[index] !== "relayr");
|
|
296
|
+
return mintPlan(account, snapshots.map(({ sent: { chainId, to, data, value, gas } }, index) => ({
|
|
297
|
+
chainId,
|
|
298
|
+
from: froms[index],
|
|
299
|
+
to,
|
|
300
|
+
data,
|
|
301
|
+
value,
|
|
302
|
+
// Relayr's own call: its gas bounds only the fee.
|
|
303
|
+
...(gas === undefined || froms[index] === "relayr" ? {} : { gas }),
|
|
304
|
+
...(roundOf[index] === undefined ? {} : { relayrRound: roundOf[index] }),
|
|
305
|
+
})), fees);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Sends one reviewed action: one call, or a sequence (approve then pay, say),
|
|
309
|
+
* reviewed once and sent without asking again.
|
|
310
|
+
*
|
|
311
|
+
* Core builds one model over every call and asks the registered review
|
|
312
|
+
* handler once ({@link registerReviewHandler}); nothing is sent unless the
|
|
313
|
+
* handler returns the confirmation core minted for that model. The
|
|
314
|
+
* review-time simulation runs while the review is open, and confirm never
|
|
315
|
+
* waits on it. Then, for each call in order: `reverify`, a check that the call
|
|
316
|
+
* still encodes to exactly the reviewed bytes, a simulation (at the previous
|
|
317
|
+
* step's receipt block when `dependsOnPrior`), and the send of those bytes
|
|
318
|
+
* through the adapter under the call's write hold, by
|
|
319
|
+
* `submitReviewedContractWrite`. The connected account must stay
|
|
320
|
+
* `action.account`, and the wallet on the call's chain. Each step waits for
|
|
321
|
+
* its receipt; a revert stops the sequence. A Safe-connected wallet's first
|
|
322
|
+
* step becomes a proposal, and the sequence stops there.
|
|
323
|
+
*
|
|
324
|
+
* The action's `signatures` show in the same model and prompt, and are
|
|
325
|
+
* signed after confirm and before the first send, as `signReviewed` signs.
|
|
326
|
+
*
|
|
327
|
+
* Only an explicit wallet rejection (EIP-1193 4001) releases a step's hold;
|
|
328
|
+
* any other failure once the wallet opened keeps it held.
|
|
329
|
+
*
|
|
330
|
+
* A self-reviewing adapter (Signa) is never prompted: `onPreview` gets the
|
|
331
|
+
* model, and the adapter gets the raw calls to review on its own page. An
|
|
332
|
+
* action with `signatures` is refused for it with EIP-1193 4200.
|
|
333
|
+
*/
|
|
334
|
+
export async function sendReviewed(action, deps) {
|
|
335
|
+
action.guard?.();
|
|
336
|
+
await walletReady(deps.adapter);
|
|
337
|
+
return send(action, deps);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Finish a sequence {@link sendReviewed} saved under `record.scope`: the step
|
|
341
|
+
* whose wallet call opened is decided by its write hold first (still held is
|
|
342
|
+
* refused; a settled success counts as completed, its receipt's hash
|
|
343
|
+
* recorded), then every remaining step, and only those, is reviewed once
|
|
344
|
+
* more as one fresh model and sent as `sendReviewed` sends. `reverify` gets
|
|
345
|
+
* each step's original index in the action. Only `record.account` can resume
|
|
346
|
+
* it. The result's `hashes` are every completed step's, `receipts` this
|
|
347
|
+
* run's.
|
|
348
|
+
*/
|
|
349
|
+
export async function resumeReviewed(record, action, deps) {
|
|
350
|
+
action.guard?.();
|
|
351
|
+
await walletReady(deps.adapter);
|
|
352
|
+
const storage = deps.storage ?? createHeldWriteStorage();
|
|
353
|
+
const { raw, record: saved } = readReviewedSequence(record.scope, record.account, storage);
|
|
354
|
+
if (!saved || saved.id !== record.id)
|
|
355
|
+
throw new ReviewLineError(REVIEWED_SEQUENCE_MOVED_LINE);
|
|
356
|
+
let expected = raw;
|
|
357
|
+
const connected = deps.adapter.account();
|
|
358
|
+
if (!connected)
|
|
359
|
+
throw new ReviewLineError("Connect a wallet first.");
|
|
360
|
+
if (connected.toLowerCase() !== saved.account.toLowerCase())
|
|
361
|
+
throw new ReviewLineError(ACCOUNT_CHANGED);
|
|
362
|
+
if (saved.sending) {
|
|
363
|
+
const { step, reservation } = saved.sending;
|
|
364
|
+
const call = saved.calls[step];
|
|
365
|
+
const handle = openStepHold(deps.hold, saved.account, deps.adapter.isSafe(), call);
|
|
366
|
+
const state = await handle.state(deps.clientFor(call.chainId));
|
|
367
|
+
if (state.status !== "clear")
|
|
368
|
+
throw new WriteHeldError(state);
|
|
369
|
+
// Only the step's own reservation's outcome decides it: a later one of
|
|
370
|
+
// the same call or intent hides it.
|
|
371
|
+
if (state.reservation !== reservation)
|
|
372
|
+
throw new ReviewLineError(REVIEWED_SEQUENCE_UNCERTAIN_LINE);
|
|
373
|
+
// Clear with no settlement: a settlement that could not be saved, which
|
|
374
|
+
// may have run, unless the user released it by its exit ("I checked my
|
|
375
|
+
// wallet") or nothing was sent: then the step is reviewed and sent again.
|
|
376
|
+
if (!state.settled && !handle.released(reservation))
|
|
377
|
+
throw new ReviewLineError(REVIEWED_SEQUENCE_UNCERTAIN_LINE);
|
|
378
|
+
delete saved.sending;
|
|
379
|
+
delete saved.proposed;
|
|
380
|
+
const { settled } = state;
|
|
381
|
+
if (settled?.result === "success") {
|
|
382
|
+
// This sequence's own step: it is recorded, never offered again.
|
|
383
|
+
await handle.acknowledge(settled);
|
|
384
|
+
saved.completed.push(settled.hash);
|
|
385
|
+
}
|
|
386
|
+
/** Tells the site of the step that went through while away, once saved and when its receipt reads. */
|
|
387
|
+
const told = async () => {
|
|
388
|
+
if (settled?.result !== "success" || !action.onConfirmed)
|
|
389
|
+
return;
|
|
390
|
+
try {
|
|
391
|
+
const receipt = await deps
|
|
392
|
+
.clientFor(call.chainId)
|
|
393
|
+
.getTransactionReceipt({ hash: settled.hash });
|
|
394
|
+
if (receipt.status === "success")
|
|
395
|
+
await action.onConfirmed(call, step, receipt);
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
/* The step went through whatever the read or the site's callback does. */
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
if (saved.completed.length === saved.calls.length) {
|
|
402
|
+
await removeReviewedSequence(saved, storage, expected);
|
|
403
|
+
await told();
|
|
404
|
+
const total = saved.calls.length;
|
|
405
|
+
deps.onProgress?.({ step: total - 1, total, phase: "done" });
|
|
406
|
+
return { status: "done", hashes: saved.completed, receipts: [] };
|
|
407
|
+
}
|
|
408
|
+
expected = await saveReviewedSequence(saved, storage, expected);
|
|
409
|
+
await told();
|
|
410
|
+
}
|
|
411
|
+
return send({
|
|
412
|
+
...action,
|
|
413
|
+
account: saved.account,
|
|
414
|
+
calls: saved.calls.slice(saved.completed.length),
|
|
415
|
+
scope: saved.scope,
|
|
416
|
+
}, deps, { record: saved, storage, raw: expected });
|
|
417
|
+
}
|
|
418
|
+
async function send(action, deps, resuming) {
|
|
419
|
+
const { adapter, clientFor, hold, onProgress } = deps;
|
|
420
|
+
action.guard?.();
|
|
421
|
+
const { account } = action;
|
|
422
|
+
const calls = [...action.calls];
|
|
423
|
+
if (!calls.length)
|
|
424
|
+
throw new ReviewLineError("There is no transaction to review.");
|
|
425
|
+
const snapshots = calls.map(exact);
|
|
426
|
+
const sent = snapshots.map(({ sent }) => sent);
|
|
427
|
+
/** Each step's simulation block, read once; a resumed run's prerequisites are long confirmed. */
|
|
428
|
+
const blocks = calls.map((call) => resuming ? undefined : call.simulationBlockNumber);
|
|
429
|
+
/** A site's release callback never stops core's own release. */
|
|
430
|
+
const tellUnsent = async (call, step) => {
|
|
431
|
+
try {
|
|
432
|
+
await action.onUnsent?.(call, step);
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
/* The step is released whatever the site's callback does. */
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
const connected = adapter.account();
|
|
439
|
+
if (!connected)
|
|
440
|
+
throw new ReviewLineError("Connect a wallet first.");
|
|
441
|
+
if (connected.toLowerCase() !== account.toLowerCase()) {
|
|
442
|
+
throw new ReviewLineError(ACCOUNT_CHANGED);
|
|
443
|
+
}
|
|
444
|
+
// A resumed sequence signs none: its signatures went with its first run.
|
|
445
|
+
const prepared = (resuming ? [] : [...(action.signatures ?? [])]).map((signature) => prepareSignature(signature, account));
|
|
446
|
+
// Signa has no reviewed-signature path yet.
|
|
447
|
+
if (prepared.length && adapter.kind === "self-reviewing") {
|
|
448
|
+
throw unsupportedWalletRequest();
|
|
449
|
+
}
|
|
450
|
+
const request = (safe) => ({
|
|
451
|
+
calls: snapshots.map((snapshot) => shownCall(snapshot, account, safe)),
|
|
452
|
+
...(prepared.length
|
|
453
|
+
? { signatures: prepared.map(({ review }) => review) }
|
|
454
|
+
: {}),
|
|
455
|
+
...(action.title ? { title: action.title } : {}),
|
|
456
|
+
...(action.description ? { description: action.description } : {}),
|
|
457
|
+
...(action.confirmLabel ? { confirmLabel: action.confirmLabel } : {}),
|
|
458
|
+
...(action.context ? { context: action.context } : {}),
|
|
459
|
+
});
|
|
460
|
+
if (adapter.kind === "self-reviewing") {
|
|
461
|
+
if (!adapter.submitToReviewer) {
|
|
462
|
+
throw new ReviewLineError("This wallet cannot review this transaction.");
|
|
463
|
+
}
|
|
464
|
+
deps.onPreview?.(buildReviewModel(request(false)));
|
|
465
|
+
/** The steps whose beforeWrite began, and whether the wallet was handed the calls. */
|
|
466
|
+
let began = 0;
|
|
467
|
+
let submitting = false;
|
|
468
|
+
let hash;
|
|
469
|
+
try {
|
|
470
|
+
for (const [step, call] of calls.entries()) {
|
|
471
|
+
began += 1;
|
|
472
|
+
await action.beforeWallet?.(call, step);
|
|
473
|
+
}
|
|
474
|
+
// The site's hooks may have awaited: the gates once more, right before the wallet.
|
|
475
|
+
action.guard?.();
|
|
476
|
+
action.assertWriteState?.();
|
|
477
|
+
if (adapter.account()?.toLowerCase() !== account.toLowerCase())
|
|
478
|
+
throw new ReviewLineError(ACCOUNT_CHANGED);
|
|
479
|
+
submitting = true;
|
|
480
|
+
hash = await adapter.submitToReviewer({
|
|
481
|
+
account,
|
|
482
|
+
calls: sent.map((call) => ({ ...call })),
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
// Only the site's own refusal or an explicit rejection proves nothing was sent.
|
|
487
|
+
if (!submitting || isDefiniteWalletRejection(error))
|
|
488
|
+
for (const [step, call] of calls.slice(0, began).entries())
|
|
489
|
+
await tellUnsent(call, step);
|
|
490
|
+
throw error;
|
|
491
|
+
}
|
|
492
|
+
// Every step is told; a site's failure to record it never reads as unsent.
|
|
493
|
+
const failures = [];
|
|
494
|
+
for (const [step, call] of calls.entries())
|
|
495
|
+
try {
|
|
496
|
+
await action.onSubmitted?.(call, step, hash, {
|
|
497
|
+
safe: false,
|
|
498
|
+
adopted: false,
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
failures.push(error);
|
|
503
|
+
}
|
|
504
|
+
if (failures.length)
|
|
505
|
+
throw new SubmittedContractWriteError(hash, failures[0]);
|
|
506
|
+
return { status: "done", hashes: [hash], receipts: [] };
|
|
507
|
+
}
|
|
508
|
+
const { scope } = action;
|
|
509
|
+
const storage = scope === undefined
|
|
510
|
+
? undefined
|
|
511
|
+
: (resuming?.storage ?? deps.storage ?? createHeldWriteStorage());
|
|
512
|
+
/** The journal's saved value as this run last read or wrote it. */
|
|
513
|
+
let expected = resuming?.raw ?? null;
|
|
514
|
+
if (storage && !resuming) {
|
|
515
|
+
const saved = readReviewedSequence(scope, account, storage);
|
|
516
|
+
// A fresh run refuses while an earlier run of the same action is unfinished.
|
|
517
|
+
if (saved.record)
|
|
518
|
+
throw new ReviewLineError(REVIEWED_SEQUENCE_UNFINISHED_LINE);
|
|
519
|
+
assertSavableCalls(calls);
|
|
520
|
+
expected = saved.raw;
|
|
521
|
+
}
|
|
522
|
+
/** Where the remaining steps start in the whole action. */
|
|
523
|
+
const offset = resuming?.record.completed.length ?? 0;
|
|
524
|
+
const safe = adapter.isSafe();
|
|
525
|
+
/** Through a Safe app, the one MultiSend call every step goes as. */
|
|
526
|
+
const batched =
|
|
527
|
+
// A resumed sequence is journaled step by step: never folded into one proposal.
|
|
528
|
+
action.batch && safe && calls.length > 1 && !resuming
|
|
529
|
+
? safeBatchCall(account, calls.map((call, step) => ({ ...call, ...sent[step] })))
|
|
530
|
+
: undefined;
|
|
531
|
+
if (batched &&
|
|
532
|
+
(!adapter.sendCalls ||
|
|
533
|
+
sent.some((call) => call.chainId !== batched.chainId)))
|
|
534
|
+
throw new ReviewLineError(SAFE_BATCH_UNSUPPORTED_LINE);
|
|
535
|
+
const handles = (batched ? [batched] : calls).map((call, step) => openStepHold(hold, account, safe, {
|
|
536
|
+
intent: call.intent,
|
|
537
|
+
legacy: call.legacy,
|
|
538
|
+
...(batched ?? sent[step]),
|
|
539
|
+
}));
|
|
540
|
+
// A step its hold already holds is refused before the review opens.
|
|
541
|
+
for (const handle of handles) {
|
|
542
|
+
const state = handle.peek();
|
|
543
|
+
if (state.status !== "clear")
|
|
544
|
+
throw new WriteHeldError(state);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Each step's latest reservation as the review opened. Another prompt of
|
|
548
|
+
* the same action that reserved meanwhile, whether or not it has settled,
|
|
549
|
+
* makes this review stale.
|
|
550
|
+
*/
|
|
551
|
+
const generation = (handle) => handle.peek().reservation ?? null;
|
|
552
|
+
const reviewedGenerations = handles.map(generation);
|
|
553
|
+
const model = buildReviewModel(request(safe));
|
|
554
|
+
/** What each step runs as: a Safe app's call is proposed with safeTxGas 0, not the app's gas. */
|
|
555
|
+
const run = safe
|
|
556
|
+
? sent.map(({ gas: _gas, ...call }) => call)
|
|
557
|
+
: sent;
|
|
558
|
+
if (action.plan) {
|
|
559
|
+
// A plan binds bytes, never an adoption rule; a Safe app's unbatched
|
|
560
|
+
// sequence stops at its first proposal, so its other calls would be spent unsent.
|
|
561
|
+
if (snapshots.some(({ shown }) => shown.adoptIgnoringArgs) ||
|
|
562
|
+
(safe && !batched && calls.length > 1))
|
|
563
|
+
throw new ReviewLineError(REVIEWED_PLAN_REFUSED_LINE);
|
|
564
|
+
spendPlan(action.plan, account, [
|
|
565
|
+
...sent.map(({ chainId, to, data, value, gas }) => ({
|
|
566
|
+
chainId,
|
|
567
|
+
from: account,
|
|
568
|
+
to,
|
|
569
|
+
data,
|
|
570
|
+
value,
|
|
571
|
+
...(gas === undefined ? {} : { gas }),
|
|
572
|
+
})),
|
|
573
|
+
...prepared.flatMap(plannedCallsOf),
|
|
574
|
+
]);
|
|
575
|
+
}
|
|
576
|
+
else
|
|
577
|
+
await promptSimulated(model, () => account, calls, run, blocks, clientFor, action.signal);
|
|
578
|
+
let signed = {};
|
|
579
|
+
if (prepared.length) {
|
|
580
|
+
// The action's own gates, last before the wallet opens for each signature.
|
|
581
|
+
const stillReviewed = () => {
|
|
582
|
+
action.guard?.();
|
|
583
|
+
action.assertWriteState?.();
|
|
584
|
+
calls.forEach((call, step) => {
|
|
585
|
+
let now;
|
|
586
|
+
try {
|
|
587
|
+
now = exact(call).sent;
|
|
588
|
+
}
|
|
589
|
+
catch {
|
|
590
|
+
throw new ReviewLineError(CHANGED);
|
|
591
|
+
}
|
|
592
|
+
if (!sameCall(now, sent[step]))
|
|
593
|
+
throw new ReviewLineError(CHANGED);
|
|
594
|
+
});
|
|
595
|
+
handles.forEach((handle, step) => {
|
|
596
|
+
if (generation(handle) !== reviewedGenerations[step]) {
|
|
597
|
+
throw new WriteHoldStaleReviewError();
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
};
|
|
601
|
+
signed = {
|
|
602
|
+
signatures: await signPrepared(prepared, account, adapter, stillReviewed),
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
if (batched) {
|
|
606
|
+
const client = clientFor(batched.chainId);
|
|
607
|
+
const unchanged = () => calls.forEach((call, step) => {
|
|
608
|
+
let now;
|
|
609
|
+
try {
|
|
610
|
+
now = exact(call).sent;
|
|
611
|
+
}
|
|
612
|
+
catch {
|
|
613
|
+
throw new ReviewLineError(CHANGED);
|
|
614
|
+
}
|
|
615
|
+
if (!sameCall(now, sent[step]))
|
|
616
|
+
throw new ReviewLineError(CHANGED);
|
|
617
|
+
});
|
|
618
|
+
const progress = (phase, hash) => onProgress?.({
|
|
619
|
+
step: 0,
|
|
620
|
+
total: calls.length,
|
|
621
|
+
phase,
|
|
622
|
+
...(hash ? { hash } : {}),
|
|
623
|
+
});
|
|
624
|
+
/** The steps whose `beforeWallet` began. */
|
|
625
|
+
let began = 0;
|
|
626
|
+
const hash = await handles[0].send(client, (gate) => {
|
|
627
|
+
if (generation(handles[0]) !== reviewedGenerations[0]) {
|
|
628
|
+
throw new WriteHoldStaleReviewError();
|
|
629
|
+
}
|
|
630
|
+
const released = async () => {
|
|
631
|
+
gate.onRejected();
|
|
632
|
+
for (const [step, call] of calls.slice(0, began).entries())
|
|
633
|
+
await tellUnsent(call, step);
|
|
634
|
+
};
|
|
635
|
+
return submitReviewedContractWrite({
|
|
636
|
+
request: batched,
|
|
637
|
+
expectedAccount: account,
|
|
638
|
+
review: () => Promise.resolve(),
|
|
639
|
+
switchChain: async (chainId) => {
|
|
640
|
+
if (adapter.chainId() !== chainId)
|
|
641
|
+
await adapter.switchChain(chainId);
|
|
642
|
+
},
|
|
643
|
+
currentAccount: () => adapter.account(),
|
|
644
|
+
reverify: async () => {
|
|
645
|
+
for (const [step, call] of calls.entries())
|
|
646
|
+
await action.reverify?.(call, step, undefined);
|
|
647
|
+
unchanged();
|
|
648
|
+
},
|
|
649
|
+
simulate: async (sending) => {
|
|
650
|
+
await simulateCallSequence(client, {
|
|
651
|
+
from: account,
|
|
652
|
+
chainName: chainNameOf(client, batched.chainId),
|
|
653
|
+
calls: run.map((call, step) => ({
|
|
654
|
+
...call,
|
|
655
|
+
label: labelOf(calls[step], step),
|
|
656
|
+
dependsOnPrior: calls[step].dependsOnPrior,
|
|
657
|
+
})),
|
|
658
|
+
});
|
|
659
|
+
return sending;
|
|
660
|
+
},
|
|
661
|
+
beforeWrite: async () => {
|
|
662
|
+
await gate.beforeSend();
|
|
663
|
+
try {
|
|
664
|
+
for (const [step, call] of calls.entries()) {
|
|
665
|
+
began = step + 1;
|
|
666
|
+
await action.beforeWallet?.(call, step);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
await released();
|
|
671
|
+
throw error;
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
beforeSend: () => {
|
|
675
|
+
action.assertWriteState?.();
|
|
676
|
+
unchanged();
|
|
677
|
+
if (!adapter.isSafe())
|
|
678
|
+
throw new ReviewLineError("Wallet connection changed. Review the transaction again.");
|
|
679
|
+
if (adapter.chainId() !== batched.chainId)
|
|
680
|
+
throw new ReviewLineError("Your wallet changed networks. Review the transaction again.");
|
|
681
|
+
if (adapter.account()?.toLowerCase() !== account.toLowerCase())
|
|
682
|
+
throw new ReviewLineError(ACCOUNT_CHANGED);
|
|
683
|
+
},
|
|
684
|
+
onBeforeWriteAborted: released,
|
|
685
|
+
onWriteRejected: released,
|
|
686
|
+
onWriteSubmitted: async (submitted) => {
|
|
687
|
+
gate.afterSubmit(submitted);
|
|
688
|
+
// Every step went: each is told, whatever an earlier callback does.
|
|
689
|
+
const failures = [];
|
|
690
|
+
for (const [step, call] of calls.entries())
|
|
691
|
+
try {
|
|
692
|
+
await action.onSubmitted?.(call, step, submitted, {
|
|
693
|
+
safe: true,
|
|
694
|
+
adopted: false,
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
catch (error) {
|
|
698
|
+
failures.push(error);
|
|
699
|
+
}
|
|
700
|
+
if (failures.length)
|
|
701
|
+
throw failures[0];
|
|
702
|
+
},
|
|
703
|
+
write: async () => {
|
|
704
|
+
const id = await adapter.sendCalls(batched.chainId, sent.map(({ to, data, value }) => ({ to, data, value })));
|
|
705
|
+
// A Safe app answers with the proposal's safeTxHash; anything else can't be followed.
|
|
706
|
+
if (typeof id !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(id))
|
|
707
|
+
throw new ReviewLineError(SAFE_BATCH_UNFOLLOWABLE_LINE);
|
|
708
|
+
return id;
|
|
709
|
+
},
|
|
710
|
+
onPhase: (phase) => progress(phase),
|
|
711
|
+
guard: action.guard,
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
progress("proposed", hash);
|
|
715
|
+
return { status: "proposed", step: 0, safeTxHash: hash, ...signed };
|
|
716
|
+
}
|
|
717
|
+
// Saved before the first wallet call, once the review is confirmed.
|
|
718
|
+
let journal;
|
|
719
|
+
if (storage) {
|
|
720
|
+
if (resuming)
|
|
721
|
+
journal = { ...resuming.record, modelId: model.id };
|
|
722
|
+
else
|
|
723
|
+
journal = {
|
|
724
|
+
version: 1,
|
|
725
|
+
id: globalThis.crypto.randomUUID(),
|
|
726
|
+
account,
|
|
727
|
+
scope: scope,
|
|
728
|
+
modelId: model.id,
|
|
729
|
+
// What was reviewed, read once above.
|
|
730
|
+
calls: calls.map((call, step) => ({
|
|
731
|
+
...call,
|
|
732
|
+
...snapshots[step].shown,
|
|
733
|
+
...snapshots[step].sent,
|
|
734
|
+
})),
|
|
735
|
+
completed: [],
|
|
736
|
+
};
|
|
737
|
+
// Refused when another window changed it meanwhile.
|
|
738
|
+
expected = await saveReviewedSequence(journal, storage, expected);
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Progress after a send is saved as it can be: the step's saved
|
|
742
|
+
* `sending` mark already lets its hold decide it on resume.
|
|
743
|
+
*/
|
|
744
|
+
const keep = async () => {
|
|
745
|
+
try {
|
|
746
|
+
if (journal.completed.length === journal.calls.length)
|
|
747
|
+
await removeReviewedSequence(journal, storage, expected);
|
|
748
|
+
else
|
|
749
|
+
expected = await saveReviewedSequence(journal, storage, expected);
|
|
750
|
+
}
|
|
751
|
+
catch {
|
|
752
|
+
/* Another window owns the sequence now; the hold still holds the step. */
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
const hashes = [];
|
|
756
|
+
const receipts = [];
|
|
757
|
+
const total = offset + calls.length;
|
|
758
|
+
for (const [step, call] of calls.entries()) {
|
|
759
|
+
const reviewed = sent[step];
|
|
760
|
+
/** This step's index in the whole action. */
|
|
761
|
+
const at = offset + step;
|
|
762
|
+
const progress = (phase, hash) => onProgress?.({ step: at, total, phase, ...(hash ? { hash } : {}) });
|
|
763
|
+
const unchanged = () => {
|
|
764
|
+
let now;
|
|
765
|
+
try {
|
|
766
|
+
now = exact(call);
|
|
767
|
+
}
|
|
768
|
+
catch {
|
|
769
|
+
throw new ReviewLineError(CHANGED);
|
|
770
|
+
}
|
|
771
|
+
if (!sameCall(now.sent, reviewed) ||
|
|
772
|
+
String(now.shown.adoptIgnoringArgs) !==
|
|
773
|
+
String(snapshots[step].shown.adoptIgnoringArgs))
|
|
774
|
+
throw new ReviewLineError(CHANGED);
|
|
775
|
+
};
|
|
776
|
+
const client = clientFor(reviewed.chainId);
|
|
777
|
+
const prior = receipts[step - 1];
|
|
778
|
+
/** Where the step before this one confirmed: this run's receipt, or a resumed run's last completed step. */
|
|
779
|
+
const confirmedBefore = async () => {
|
|
780
|
+
if (prior)
|
|
781
|
+
return {
|
|
782
|
+
chainId: sent[step - 1].chainId,
|
|
783
|
+
blockNumber: prior.blockNumber,
|
|
784
|
+
blockHash: prior.blockHash,
|
|
785
|
+
};
|
|
786
|
+
const done = resuming?.record;
|
|
787
|
+
if (step > 0 || !done?.completed.length)
|
|
788
|
+
return undefined;
|
|
789
|
+
const { chainId } = done.calls[done.completed.length - 1];
|
|
790
|
+
// One read: a receipt that can't be read now (a repriced original) is no block.
|
|
791
|
+
const receipt = await clientFor(chainId)
|
|
792
|
+
.getTransactionReceipt({
|
|
793
|
+
hash: done.completed[done.completed.length - 1],
|
|
794
|
+
})
|
|
795
|
+
.catch(() => undefined);
|
|
796
|
+
return receipt
|
|
797
|
+
? {
|
|
798
|
+
chainId,
|
|
799
|
+
blockNumber: receipt.blockNumber,
|
|
800
|
+
blockHash: receipt.blockHash,
|
|
801
|
+
}
|
|
802
|
+
: undefined;
|
|
803
|
+
};
|
|
804
|
+
const priorBlock = call.dependsOnPrior &&
|
|
805
|
+
prior &&
|
|
806
|
+
sent[step - 1].chainId === reviewed.chainId
|
|
807
|
+
? prior.blockNumber
|
|
808
|
+
: undefined;
|
|
809
|
+
/** The reservation this step's send took. */
|
|
810
|
+
let reserved;
|
|
811
|
+
/** A proposal of exactly this call its Safe already queued, sent in its place. */
|
|
812
|
+
let queued;
|
|
813
|
+
const hash = await handles[step].send(client, (gate) => {
|
|
814
|
+
// Under the hold's own check of the call, before anything reserves.
|
|
815
|
+
if (generation(handles[step]) !== reviewedGenerations[step]) {
|
|
816
|
+
throw new WriteHoldStaleReviewError();
|
|
817
|
+
}
|
|
818
|
+
/** Nothing was sent: the hold lets go, and the step is no longer in flight. */
|
|
819
|
+
const released = async () => {
|
|
820
|
+
gate.onRejected();
|
|
821
|
+
if (journal) {
|
|
822
|
+
delete journal.sending;
|
|
823
|
+
await keep();
|
|
824
|
+
}
|
|
825
|
+
await tellUnsent(call, at);
|
|
826
|
+
};
|
|
827
|
+
return submitReviewedContractWrite({
|
|
828
|
+
request: reviewed,
|
|
829
|
+
expectedAccount: account,
|
|
830
|
+
// Confirmed once, above, for every step.
|
|
831
|
+
review: () => Promise.resolve(),
|
|
832
|
+
switchChain: async (chainId) => {
|
|
833
|
+
if (adapter.chainId() !== chainId)
|
|
834
|
+
await adapter.switchChain(chainId);
|
|
835
|
+
},
|
|
836
|
+
currentAccount: () => adapter.account(),
|
|
837
|
+
reverify: async () => {
|
|
838
|
+
if (action.reverify)
|
|
839
|
+
await action.reverify(call, at, await confirmedBefore());
|
|
840
|
+
unchanged();
|
|
841
|
+
},
|
|
842
|
+
simulate: async (sending) => {
|
|
843
|
+
const blockNumber = priorBlock ??
|
|
844
|
+
(blocks[step] === undefined
|
|
845
|
+
? undefined
|
|
846
|
+
: await notBefore(client, blocks[step]));
|
|
847
|
+
const tx = {
|
|
848
|
+
to: sending.to,
|
|
849
|
+
data: sending.data,
|
|
850
|
+
value: sending.value,
|
|
851
|
+
...(blockNumber === undefined ? {} : { blockNumber }),
|
|
852
|
+
};
|
|
853
|
+
const { gas } = run[step];
|
|
854
|
+
const [, estimate, found] = await Promise.all([
|
|
855
|
+
simulateStateChangingTransaction(client, {
|
|
856
|
+
from: account,
|
|
857
|
+
...tx,
|
|
858
|
+
gas,
|
|
859
|
+
}).catch((error) => {
|
|
860
|
+
throw simulationFailure(`${labelOf(call, at)} cannot run on ${chainNameOf(client, sending.chainId)}: ${revertDetail(error)}`, error);
|
|
861
|
+
}),
|
|
862
|
+
// A Safe app signs the sent gas as safeTxGas; 0 makes a failed call revert.
|
|
863
|
+
safe || gas !== undefined
|
|
864
|
+
? undefined
|
|
865
|
+
: client.estimateGas({ account, ...tx }),
|
|
866
|
+
// A Safe app never proposes again a call its Safe already queued exactly.
|
|
867
|
+
safe && hasSafeService(sending.chainId)
|
|
868
|
+
? findPendingSafeAppProposal(client, sending.chainId, account, sending, hold.safeService, true, adopting(snapshots[step].shown))
|
|
869
|
+
: null,
|
|
870
|
+
]);
|
|
871
|
+
queued = found;
|
|
872
|
+
return {
|
|
873
|
+
...sending,
|
|
874
|
+
gas: safe ? 0n : (gas ?? gasWithHeadroom(estimate)),
|
|
875
|
+
};
|
|
876
|
+
},
|
|
877
|
+
beforeWrite: async () => {
|
|
878
|
+
// An adopted proposal is held as the call it runs.
|
|
879
|
+
await gate.beforeSend(queued?.call);
|
|
880
|
+
reserved = handles[step].peek().reservation;
|
|
881
|
+
if (journal)
|
|
882
|
+
try {
|
|
883
|
+
const { reservation } = handles[step].peek();
|
|
884
|
+
if (reservation === undefined)
|
|
885
|
+
throw new ReviewLineError(NOT_SAVED);
|
|
886
|
+
journal.sending = { step: at, reservation };
|
|
887
|
+
expected = await saveReviewedSequence(journal, storage, expected);
|
|
888
|
+
}
|
|
889
|
+
catch (error) {
|
|
890
|
+
// Reserved, and the wallet never opened.
|
|
891
|
+
delete journal.sending;
|
|
892
|
+
gate.onRejected();
|
|
893
|
+
throw error;
|
|
894
|
+
}
|
|
895
|
+
try {
|
|
896
|
+
await action.beforeWallet?.(call, at);
|
|
897
|
+
}
|
|
898
|
+
catch (error) {
|
|
899
|
+
await released();
|
|
900
|
+
throw error;
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
beforeSend: () => {
|
|
904
|
+
action.assertWriteState?.();
|
|
905
|
+
unchanged();
|
|
906
|
+
if (adapter.isSafe() !== safe) {
|
|
907
|
+
throw new ReviewLineError("Wallet connection changed. Review the transaction again.");
|
|
908
|
+
}
|
|
909
|
+
if (adapter.chainId() !== reviewed.chainId) {
|
|
910
|
+
throw new ReviewLineError("Your wallet changed networks. Review the transaction again.");
|
|
911
|
+
}
|
|
912
|
+
// Last, after every callback and getter above could have run.
|
|
913
|
+
if (adapter.account()?.toLowerCase() !== account.toLowerCase()) {
|
|
914
|
+
throw new ReviewLineError(ACCOUNT_CHANGED);
|
|
915
|
+
}
|
|
916
|
+
},
|
|
917
|
+
onBeforeWriteAborted: released,
|
|
918
|
+
onWriteRejected: released,
|
|
919
|
+
// An adopted proposal's nonce lets the hold prove its execution onchain.
|
|
920
|
+
onWriteSubmitted: async (submitted) => {
|
|
921
|
+
gate.afterSubmit(submitted, queued?.tx);
|
|
922
|
+
await action.onSubmitted?.(call, at, submitted, {
|
|
923
|
+
safe,
|
|
924
|
+
adopted: !!queued,
|
|
925
|
+
});
|
|
926
|
+
},
|
|
927
|
+
write: async ({ chainId, to, data, value, gas }) => queued?.proposalHash ??
|
|
928
|
+
adapter.sendTransaction({ chainId, to, data, value, gas }),
|
|
929
|
+
onPhase: (phase) => progress(phase),
|
|
930
|
+
guard: action.guard,
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
hashes.push(hash);
|
|
934
|
+
// A later step held under this step's key (the same call, or the same
|
|
935
|
+
// intent) was reserved by this send, not by another prompt.
|
|
936
|
+
for (const [later, handle] of handles.entries()) {
|
|
937
|
+
const sameKey = call.intent
|
|
938
|
+
? calls[later].intent === call.intent &&
|
|
939
|
+
sent[later].chainId === reviewed.chainId
|
|
940
|
+
: !calls[later].intent && sameCall(sent[later], reviewed);
|
|
941
|
+
if (later > step && sameKey) {
|
|
942
|
+
reviewedGenerations[later] = generation(handle);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
if (safe) {
|
|
946
|
+
if (journal) {
|
|
947
|
+
journal.proposed = { step: at, safeTxHash: hash };
|
|
948
|
+
await keep();
|
|
949
|
+
}
|
|
950
|
+
progress("proposed", hash);
|
|
951
|
+
return { status: "proposed", step: at, safeTxHash: hash, ...signed };
|
|
952
|
+
}
|
|
953
|
+
progress("receipt", hash);
|
|
954
|
+
const receipt = await waitForTrackedReceipt(client, hash);
|
|
955
|
+
// The hold checks the receipt itself and settles, so the same call (or
|
|
956
|
+
// intent) can be reviewed and sent again without waiting on a view.
|
|
957
|
+
// Only this send's own reservation's settlement speaks for it: a later
|
|
958
|
+
// send of the same call or intent may have settled since.
|
|
959
|
+
const settled = await handles[step]
|
|
960
|
+
.state(client)
|
|
961
|
+
.then((state) => state.status === "clear" &&
|
|
962
|
+
reserved !== undefined &&
|
|
963
|
+
state.reservation === reserved
|
|
964
|
+
? state.settled
|
|
965
|
+
: undefined)
|
|
966
|
+
.catch(() => undefined);
|
|
967
|
+
if (receipt.status === "success" && settled?.result === "failed") {
|
|
968
|
+
// It ran, and the hold proved it failed: a Safe's call that failed.
|
|
969
|
+
if (journal) {
|
|
970
|
+
delete journal.sending;
|
|
971
|
+
await keep();
|
|
972
|
+
}
|
|
973
|
+
throw new ReviewLineError(WRITE_HOLD_CALL_FAILED_LINE);
|
|
974
|
+
}
|
|
975
|
+
// A Safe's execTransaction is done only once its hold proved the Safe's
|
|
976
|
+
// own success; until then the step stays in flight, held and journaled.
|
|
977
|
+
if (receipt.status === "success" &&
|
|
978
|
+
isSafeExecTransaction(reviewed.data) &&
|
|
979
|
+
settled?.result !== "success") {
|
|
980
|
+
throw new ReviewLineError(WRITE_HOLD_SAFE_UNCONFIRMED_LINE);
|
|
981
|
+
}
|
|
982
|
+
if (receipt.status !== "success") {
|
|
983
|
+
// It ran and reverted: nothing of it to resume.
|
|
984
|
+
if (journal) {
|
|
985
|
+
delete journal.sending;
|
|
986
|
+
await keep();
|
|
987
|
+
}
|
|
988
|
+
throw new ReviewedCallRevertedError(at, hash, receipt);
|
|
989
|
+
}
|
|
990
|
+
receipts.push(receipt);
|
|
991
|
+
if (journal) {
|
|
992
|
+
delete journal.sending;
|
|
993
|
+
journal.completed.push(hash);
|
|
994
|
+
await keep();
|
|
995
|
+
}
|
|
996
|
+
try {
|
|
997
|
+
await action.onConfirmed?.(call, at, receipt);
|
|
998
|
+
}
|
|
999
|
+
catch {
|
|
1000
|
+
/* The step went through whatever the site's callback does. */
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
onProgress?.({ step: total - 1, total, phase: "done" });
|
|
1004
|
+
return {
|
|
1005
|
+
status: "done",
|
|
1006
|
+
hashes: journal ? [...journal.completed] : hashes,
|
|
1007
|
+
receipts,
|
|
1008
|
+
...signed,
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
//# sourceMappingURL=send.js.map
|