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