@ocap/tx-protocols 1.28.9 → 1.29.1

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 (284) hide show
  1. package/esm/execute.d.mts +53 -0
  2. package/esm/execute.mjs +225 -0
  3. package/esm/index.d.mts +95 -0
  4. package/esm/index.mjs +100 -0
  5. package/esm/pipes/ensure-cost.d.mts +18 -0
  6. package/esm/pipes/ensure-cost.mjs +136 -0
  7. package/esm/pipes/ensure-gas.d.mts +14 -0
  8. package/esm/pipes/ensure-gas.mjs +38 -0
  9. package/esm/protocols/account/delegate.d.mts +4 -0
  10. package/esm/protocols/account/delegate.mjs +195 -0
  11. package/esm/protocols/account/migrate.d.mts +4 -0
  12. package/esm/protocols/account/migrate.mjs +130 -0
  13. package/esm/protocols/account/revoke-delegate.d.mts +4 -0
  14. package/esm/protocols/account/revoke-delegate.mjs +102 -0
  15. package/esm/protocols/asset/acquire-v2.d.mts +9 -0
  16. package/esm/protocols/asset/acquire-v2.mjs +213 -0
  17. package/esm/protocols/asset/acquire-v3.d.mts +17 -0
  18. package/esm/protocols/asset/acquire-v3.mjs +265 -0
  19. package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
  20. package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
  21. package/esm/protocols/asset/calls/transfer.d.mts +4 -0
  22. package/esm/protocols/asset/calls/transfer.mjs +32 -0
  23. package/esm/protocols/asset/consume.d.mts +4 -0
  24. package/esm/protocols/asset/consume.mjs +92 -0
  25. package/esm/protocols/asset/create.d.mts +4 -0
  26. package/esm/protocols/asset/create.mjs +136 -0
  27. package/esm/protocols/asset/mint.d.mts +4 -0
  28. package/esm/protocols/asset/mint.mjs +156 -0
  29. package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
  30. package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
  31. package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
  32. package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
  33. package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
  34. package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
  35. package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
  36. package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
  37. package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
  38. package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
  39. package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
  40. package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
  41. package/esm/protocols/asset/update.d.mts +4 -0
  42. package/esm/protocols/asset/update.mjs +111 -0
  43. package/esm/protocols/factory/create.d.mts +29 -0
  44. package/esm/protocols/factory/create.mjs +155 -0
  45. package/esm/protocols/governance/claim-stake.d.mts +27 -0
  46. package/esm/protocols/governance/claim-stake.mjs +220 -0
  47. package/esm/protocols/governance/return-stake.d.mts +27 -0
  48. package/esm/protocols/governance/return-stake.mjs +211 -0
  49. package/esm/protocols/governance/revoke-stake.d.mts +27 -0
  50. package/esm/protocols/governance/revoke-stake.mjs +178 -0
  51. package/esm/protocols/governance/slash-stake.d.mts +17 -0
  52. package/esm/protocols/governance/slash-stake.mjs +213 -0
  53. package/esm/protocols/governance/stake.d.mts +15 -0
  54. package/esm/protocols/governance/stake.mjs +270 -0
  55. package/esm/protocols/rollup/claim-reward.d.mts +11 -0
  56. package/esm/protocols/rollup/claim-reward.mjs +322 -0
  57. package/esm/protocols/rollup/close.d.mts +4 -0
  58. package/esm/protocols/rollup/close.mjs +105 -0
  59. package/esm/protocols/rollup/create-block.d.mts +11 -0
  60. package/esm/protocols/rollup/create-block.mjs +303 -0
  61. package/esm/protocols/rollup/create.d.mts +4 -0
  62. package/esm/protocols/rollup/create.mjs +164 -0
  63. package/esm/protocols/rollup/join.d.mts +4 -0
  64. package/esm/protocols/rollup/join.mjs +152 -0
  65. package/esm/protocols/rollup/leave.d.mts +4 -0
  66. package/esm/protocols/rollup/leave.mjs +137 -0
  67. package/esm/protocols/rollup/migrate.d.mts +4 -0
  68. package/esm/protocols/rollup/migrate.mjs +85 -0
  69. package/esm/protocols/rollup/pause.d.mts +4 -0
  70. package/esm/protocols/rollup/pause.mjs +76 -0
  71. package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
  72. package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
  73. package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
  74. package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
  75. package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
  76. package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
  77. package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
  78. package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
  79. package/esm/protocols/rollup/resume.d.mts +4 -0
  80. package/esm/protocols/rollup/resume.mjs +79 -0
  81. package/esm/protocols/rollup/update.d.mts +4 -0
  82. package/esm/protocols/rollup/update.mjs +111 -0
  83. package/esm/protocols/token/create.d.mts +4 -0
  84. package/esm/protocols/token/create.mjs +150 -0
  85. package/esm/protocols/token/deposit-v2.d.mts +11 -0
  86. package/esm/protocols/token/deposit-v2.mjs +216 -0
  87. package/esm/protocols/token/withdraw-v2.d.mts +9 -0
  88. package/esm/protocols/token/withdraw-v2.mjs +222 -0
  89. package/esm/protocols/token-factory/burn.d.mts +15 -0
  90. package/esm/protocols/token-factory/burn.mjs +233 -0
  91. package/esm/protocols/token-factory/create.d.mts +4 -0
  92. package/esm/protocols/token-factory/create.mjs +254 -0
  93. package/esm/protocols/token-factory/mint.d.mts +15 -0
  94. package/esm/protocols/token-factory/mint.mjs +234 -0
  95. package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
  96. package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
  97. package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
  98. package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
  99. package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
  100. package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
  101. package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
  102. package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
  103. package/esm/protocols/token-factory/update.d.mts +10 -0
  104. package/esm/protocols/token-factory/update.mjs +152 -0
  105. package/esm/protocols/trade/exchange-v2.d.mts +9 -0
  106. package/esm/protocols/trade/exchange-v2.mjs +239 -0
  107. package/esm/protocols/trade/transfer-v2.d.mts +9 -0
  108. package/esm/protocols/trade/transfer-v2.mjs +226 -0
  109. package/esm/protocols/trade/transfer-v3.d.mts +17 -0
  110. package/esm/protocols/trade/transfer-v3.mjs +270 -0
  111. package/esm/util.d.mts +141 -0
  112. package/esm/util.mjs +278 -0
  113. package/lib/_virtual/rolldown_runtime.cjs +29 -0
  114. package/lib/execute.cjs +231 -0
  115. package/lib/execute.d.cts +53 -0
  116. package/lib/index.cjs +105 -0
  117. package/lib/index.d.cts +95 -0
  118. package/lib/pipes/ensure-cost.cjs +141 -0
  119. package/lib/pipes/ensure-cost.d.cts +18 -0
  120. package/lib/pipes/ensure-gas.cjs +41 -0
  121. package/lib/pipes/ensure-gas.d.cts +14 -0
  122. package/lib/protocols/account/delegate.cjs +201 -0
  123. package/lib/protocols/account/delegate.d.cts +4 -0
  124. package/lib/protocols/account/migrate.cjs +135 -0
  125. package/lib/protocols/account/migrate.d.cts +4 -0
  126. package/lib/protocols/account/revoke-delegate.cjs +107 -0
  127. package/lib/protocols/account/revoke-delegate.d.cts +4 -0
  128. package/lib/protocols/asset/acquire-v2.cjs +216 -0
  129. package/lib/protocols/asset/acquire-v2.d.cts +9 -0
  130. package/lib/protocols/asset/acquire-v3.cjs +269 -0
  131. package/lib/protocols/asset/acquire-v3.d.cts +17 -0
  132. package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
  133. package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
  134. package/lib/protocols/asset/calls/transfer.cjs +35 -0
  135. package/lib/protocols/asset/calls/transfer.d.cts +4 -0
  136. package/lib/protocols/asset/consume.cjs +95 -0
  137. package/lib/protocols/asset/consume.d.cts +4 -0
  138. package/lib/protocols/asset/create.cjs +140 -0
  139. package/lib/protocols/asset/create.d.cts +4 -0
  140. package/lib/protocols/asset/mint.cjs +159 -0
  141. package/lib/protocols/asset/mint.d.cts +4 -0
  142. package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
  143. package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
  144. package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
  145. package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
  146. package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
  147. package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
  148. package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
  149. package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
  150. package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
  151. package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
  152. package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
  153. package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
  154. package/lib/protocols/asset/update.cjs +114 -0
  155. package/lib/protocols/asset/update.d.cts +4 -0
  156. package/lib/protocols/factory/create.cjs +161 -0
  157. package/lib/protocols/factory/create.d.cts +29 -0
  158. package/lib/protocols/governance/claim-stake.cjs +223 -0
  159. package/lib/protocols/governance/claim-stake.d.cts +27 -0
  160. package/lib/protocols/governance/return-stake.cjs +215 -0
  161. package/lib/protocols/governance/return-stake.d.cts +27 -0
  162. package/lib/protocols/governance/revoke-stake.cjs +182 -0
  163. package/lib/protocols/governance/revoke-stake.d.cts +27 -0
  164. package/lib/protocols/governance/slash-stake.cjs +217 -0
  165. package/lib/protocols/governance/slash-stake.d.cts +17 -0
  166. package/lib/protocols/governance/stake.cjs +275 -0
  167. package/lib/protocols/governance/stake.d.cts +15 -0
  168. package/lib/protocols/rollup/claim-reward.cjs +328 -0
  169. package/lib/protocols/rollup/claim-reward.d.cts +11 -0
  170. package/lib/protocols/rollup/close.cjs +107 -0
  171. package/lib/protocols/rollup/close.d.cts +4 -0
  172. package/lib/protocols/rollup/create-block.cjs +309 -0
  173. package/lib/protocols/rollup/create-block.d.cts +11 -0
  174. package/lib/protocols/rollup/create.cjs +169 -0
  175. package/lib/protocols/rollup/create.d.cts +4 -0
  176. package/lib/protocols/rollup/join.cjs +157 -0
  177. package/lib/protocols/rollup/join.d.cts +4 -0
  178. package/lib/protocols/rollup/leave.cjs +141 -0
  179. package/lib/protocols/rollup/leave.d.cts +4 -0
  180. package/lib/protocols/rollup/migrate.cjs +87 -0
  181. package/lib/protocols/rollup/migrate.d.cts +4 -0
  182. package/lib/protocols/rollup/pause.cjs +78 -0
  183. package/lib/protocols/rollup/pause.d.cts +4 -0
  184. package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
  185. package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
  186. package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
  187. package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
  188. package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
  189. package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
  190. package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
  191. package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
  192. package/lib/protocols/rollup/resume.cjs +81 -0
  193. package/lib/protocols/rollup/resume.d.cts +4 -0
  194. package/lib/protocols/rollup/update.cjs +114 -0
  195. package/lib/protocols/rollup/update.d.cts +4 -0
  196. package/lib/protocols/token/create.cjs +156 -0
  197. package/lib/protocols/token/create.d.cts +4 -0
  198. package/lib/protocols/token/deposit-v2.cjs +219 -0
  199. package/lib/protocols/token/deposit-v2.d.cts +11 -0
  200. package/lib/protocols/token/withdraw-v2.cjs +225 -0
  201. package/lib/protocols/token/withdraw-v2.d.cts +9 -0
  202. package/lib/protocols/token-factory/burn.cjs +236 -0
  203. package/lib/protocols/token-factory/burn.d.cts +15 -0
  204. package/lib/protocols/token-factory/create.cjs +260 -0
  205. package/lib/protocols/token-factory/create.d.cts +4 -0
  206. package/lib/protocols/token-factory/mint.cjs +237 -0
  207. package/lib/protocols/token-factory/mint.d.cts +15 -0
  208. package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
  209. package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
  210. package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
  211. package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
  212. package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
  213. package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
  214. package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
  215. package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
  216. package/lib/protocols/token-factory/update.cjs +155 -0
  217. package/lib/protocols/token-factory/update.d.cts +10 -0
  218. package/lib/protocols/trade/exchange-v2.cjs +243 -0
  219. package/lib/protocols/trade/exchange-v2.d.cts +9 -0
  220. package/lib/protocols/trade/transfer-v2.cjs +229 -0
  221. package/lib/protocols/trade/transfer-v2.d.cts +9 -0
  222. package/lib/protocols/trade/transfer-v3.cjs +274 -0
  223. package/lib/protocols/trade/transfer-v3.d.cts +17 -0
  224. package/lib/util.cjs +296 -0
  225. package/lib/util.d.cts +141 -0
  226. package/package.json +49 -22
  227. package/tools/fixtures.ts +564 -0
  228. package/lib/execute.js +0 -254
  229. package/lib/index.js +0 -117
  230. package/lib/pipes/ensure-cost.js +0 -193
  231. package/lib/pipes/ensure-gas.js +0 -48
  232. package/lib/protocols/account/delegate.js +0 -223
  233. package/lib/protocols/account/migrate.js +0 -153
  234. package/lib/protocols/account/revoke-delegate.js +0 -110
  235. package/lib/protocols/asset/acquire-v2.js +0 -262
  236. package/lib/protocols/asset/acquire-v3.js +0 -330
  237. package/lib/protocols/asset/calls/README.md +0 -5
  238. package/lib/protocols/asset/calls/transfer-token.js +0 -36
  239. package/lib/protocols/asset/calls/transfer.js +0 -28
  240. package/lib/protocols/asset/consume.js +0 -105
  241. package/lib/protocols/asset/create.js +0 -151
  242. package/lib/protocols/asset/mint.js +0 -199
  243. package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
  244. package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
  245. package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
  246. package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
  247. package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
  248. package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
  249. package/lib/protocols/asset/update.js +0 -131
  250. package/lib/protocols/factory/create.js +0 -191
  251. package/lib/protocols/governance/claim-stake.js +0 -266
  252. package/lib/protocols/governance/return-stake.js +0 -248
  253. package/lib/protocols/governance/revoke-stake.js +0 -172
  254. package/lib/protocols/governance/slash-stake.js +0 -271
  255. package/lib/protocols/governance/stake.js +0 -303
  256. package/lib/protocols/rollup/claim-reward.js +0 -342
  257. package/lib/protocols/rollup/close.js +0 -104
  258. package/lib/protocols/rollup/create-block.js +0 -413
  259. package/lib/protocols/rollup/create.js +0 -197
  260. package/lib/protocols/rollup/join.js +0 -182
  261. package/lib/protocols/rollup/leave.js +0 -145
  262. package/lib/protocols/rollup/migrate.js +0 -85
  263. package/lib/protocols/rollup/pause.js +0 -75
  264. package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
  265. package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
  266. package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
  267. package/lib/protocols/rollup/pipes/verify-status.js +0 -30
  268. package/lib/protocols/rollup/resume.js +0 -75
  269. package/lib/protocols/rollup/update.js +0 -122
  270. package/lib/protocols/token/create.js +0 -199
  271. package/lib/protocols/token/deposit-v2.js +0 -290
  272. package/lib/protocols/token/withdraw-v2.js +0 -305
  273. package/lib/protocols/token-factory/burn.js +0 -371
  274. package/lib/protocols/token-factory/create.js +0 -342
  275. package/lib/protocols/token-factory/mint.js +0 -385
  276. package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
  277. package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
  278. package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
  279. package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
  280. package/lib/protocols/token-factory/update.js +0 -208
  281. package/lib/protocols/trade/exchange-v2.js +0 -239
  282. package/lib/protocols/trade/transfer-v2.js +0 -233
  283. package/lib/protocols/trade/transfer-v3.js +0 -333
  284. package/lib/util.js +0 -442
@@ -0,0 +1,29 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -0,0 +1,231 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const require_pipes_ensure_cost = require('./pipes/ensure-cost.cjs');
4
+ const require_pipes_ensure_gas = require('./pipes/ensure-gas.cjs');
5
+ let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
6
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
7
+ let lodash_camelCase = require("lodash/camelCase");
8
+ lodash_camelCase = require_rolldown_runtime.__toESM(lodash_camelCase);
9
+ let lodash_get = require("lodash/get");
10
+ lodash_get = require_rolldown_runtime.__toESM(lodash_get);
11
+ let lodash_merge = require("lodash/merge");
12
+ lodash_merge = require_rolldown_runtime.__toESM(lodash_merge);
13
+ let lodash_pick = require("lodash/pick");
14
+ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
15
+
16
+ //#region src/execute.ts
17
+ const ensureTxGas = require_pipes_ensure_gas.default(() => ({
18
+ create: 0,
19
+ update: 2
20
+ }));
21
+ const ensureTxCost = require_pipes_ensure_cost.default({
22
+ attachSenderChanges: true,
23
+ gasOnly: true
24
+ });
25
+ const getTxName = (typeUrl) => (0, lodash_camelCase.default)(typeUrl.split(":").pop() ?? "");
26
+ /** Get states helper with type guard - throws if states is not initialized */
27
+ const getStates = (context) => {
28
+ if (!context.states) throw new _ocap_util_lib_error.CustomError("INTERNAL", "States helper is not initialized in context");
29
+ return context.states;
30
+ };
31
+ const flushEvents = (context, extra = {}) => {
32
+ (context.events || []).forEach((e) => {
33
+ const table = context.statedb[e.table];
34
+ if (table?.emit) table.emit(e.name, e.data, {
35
+ ...e.ctx,
36
+ ...extra
37
+ });
38
+ });
39
+ context.events = [];
40
+ };
41
+ const shouldPersistTx = (err) => !err || Boolean((0, lodash_get.default)(err, "props.persist"));
42
+ const createExecute = ({ filter, runAsLambda }) => {
43
+ const pre = new _ocap_tx_pipeline.Runner("pre-execute");
44
+ pre.use(_ocap_tx_pipeline.pipes.DecodeTx);
45
+ pre.use(_ocap_tx_pipeline.pipes.VerifyBlocked({
46
+ filter,
47
+ stateKeys: ["tx.from"]
48
+ }));
49
+ pre.use(_ocap_tx_pipeline.pipes.DecodeItx);
50
+ pre.use(_ocap_tx_pipeline.pipes.VerifyTx);
51
+ pre.use(_ocap_tx_pipeline.pipes.VerifyServiceFee);
52
+ pre.use(async (context, next) => {
53
+ if (filter.has(context.txHash)) {
54
+ if (await context.statedb.tx.get(context.txHash, context)) return next(new _ocap_util_lib_error.CustomError("DUPLICATE_TX", "Can not execute duplicate transaction"));
55
+ }
56
+ filter.add(context.txHash);
57
+ return next();
58
+ });
59
+ pre.use(_ocap_tx_pipeline.pipes.VerifyTxSize);
60
+ pre.use(_ocap_tx_pipeline.pipes.VerifySignature);
61
+ const ensureGasFeePaid = (context) => {
62
+ const gasRunner = new _ocap_tx_pipeline.Runner("ensure-gas-fee-paid");
63
+ gasRunner.use(ensureTxGas);
64
+ gasRunner.use(ensureTxCost);
65
+ gasRunner.use(async (ctx, next) => {
66
+ const { tx, statedb, senderUpdates, updateVaults } = ctx;
67
+ if (ctx.senderState && ctx.states && tx) {
68
+ const senderState = ctx.stateSnapshot?.[ctx.senderState.address] || ctx.senderState;
69
+ const updates = ctx.states.account.update(senderState, {
70
+ nonce: tx.nonce,
71
+ pk: tx.pk,
72
+ ...senderUpdates
73
+ }, ctx);
74
+ await statedb.account.update(senderState.address, updates, ctx);
75
+ if (updateVaults) await updateVaults();
76
+ }
77
+ return next();
78
+ });
79
+ return new Promise((resolve, reject) => {
80
+ gasRunner.run(context, (err) => {
81
+ if (err) {
82
+ context.logger?.error("Failed to charge gas fee for errored tx", {
83
+ error: err,
84
+ tx: context.tx,
85
+ txBase64: context.txBase64,
86
+ txHash: context.txHash
87
+ });
88
+ reject(err);
89
+ return;
90
+ }
91
+ resolve();
92
+ });
93
+ });
94
+ };
95
+ const execute = async (context, protocols, isRetrySupported = false) => new Promise((resolve, reject) => {
96
+ pre.run(context, (err) => {
97
+ if (err) {
98
+ context.logger?.error("Failed to prepare transaction", {
99
+ error: err,
100
+ txHash: context.txHash,
101
+ request: context.extra?.request
102
+ });
103
+ return reject(err);
104
+ }
105
+ const protocol = protocols[getTxName(context.txType)];
106
+ if (!protocol) return reject(new _ocap_util_lib_error.CustomError("UNSUPPORTED_TX", `Unsupported tx type ${context.txType}`));
107
+ protocol.run(context, async (error) => {
108
+ if (isRetrySupported) {
109
+ if (error) return reject(error);
110
+ return resolve(context);
111
+ }
112
+ const txStatus = error ? error.code || "INTERNAL" : "OK";
113
+ const states = getStates(context);
114
+ let txState = states.tx.create(context, txStatus);
115
+ if (shouldPersistTx(error)) try {
116
+ if (error) {
117
+ await ensureGasFeePaid(context);
118
+ txState = states.tx.create(context, txStatus);
119
+ }
120
+ await context.statedb.tx.create(txState.hash, txState, context);
121
+ flushEvents(context, { txState });
122
+ } catch (e) {
123
+ context.logger?.error("Failed to save transaction to statedb", {
124
+ error: e,
125
+ txError: error,
126
+ txHash: context.txHash,
127
+ txState
128
+ });
129
+ return reject(error);
130
+ }
131
+ context.logger?.info("Tx finalized", {
132
+ txHash: context.txHash,
133
+ txStatus,
134
+ txState,
135
+ error
136
+ });
137
+ if (error) return reject(error);
138
+ return resolve(context);
139
+ });
140
+ });
141
+ });
142
+ if (typeof runAsLambda === "function") return async (context, protocols) => {
143
+ let ctx = context;
144
+ const startTime = Date.now();
145
+ try {
146
+ const txState = await runAsLambda(async (txn) => {
147
+ ctx = (0, lodash_pick.default)(context, [
148
+ "txBase64",
149
+ "statedb",
150
+ "indexdb",
151
+ "config",
152
+ "states",
153
+ "filter",
154
+ "extra",
155
+ "logger"
156
+ ]);
157
+ ctx.txn = txn;
158
+ await execute(ctx, protocols, true);
159
+ const state = getStates(context).tx.create(ctx, "OK");
160
+ await context.statedb.tx.create(state.hash, state, ctx);
161
+ return state;
162
+ }, {
163
+ cleanWorkingSet: true,
164
+ verifyHash: true,
165
+ context: ctx
166
+ });
167
+ flushEvents(ctx, { txState });
168
+ ctx.logger?.info("Tx finalized", {
169
+ txHash: ctx.txHash,
170
+ txState,
171
+ txStatus: "OK",
172
+ duration: Date.now() - startTime
173
+ });
174
+ } catch (error) {
175
+ const err = error;
176
+ const txStatus = err.code || "INTERNAL";
177
+ let txState = ctx.tx ? getStates(context).tx.create(ctx, txStatus, false) : null;
178
+ ctx.logger?.error("Failed to execute transaction", {
179
+ error,
180
+ txHash: ctx.txHash,
181
+ txState,
182
+ request: context.extra?.request
183
+ });
184
+ if (txState && shouldPersistTx(err)) {
185
+ ctx.events = [];
186
+ try {
187
+ txState = await runAsLambda(async (txn) => {
188
+ ctx = Object.assign({}, ctx, {
189
+ txn,
190
+ cacheStates: null
191
+ });
192
+ await ensureGasFeePaid(ctx);
193
+ const state = getStates(context).tx.create(ctx, txStatus);
194
+ await ctx.statedb.tx.create(state.hash, state, ctx);
195
+ return state;
196
+ }, {
197
+ cleanWorkingSet: true,
198
+ verifyHash: true,
199
+ context: ctx
200
+ });
201
+ flushEvents(ctx, { txState });
202
+ ctx.logger?.info("Tx finalized", {
203
+ txHash: ctx.txHash,
204
+ txState,
205
+ txStatus,
206
+ error,
207
+ duration: Date.now() - startTime
208
+ });
209
+ } catch (innerErr) {
210
+ ctx.logger?.error("Failed to save invalid transaction to statedb", {
211
+ error: innerErr,
212
+ txError: error,
213
+ txHash: ctx.txHash,
214
+ txState,
215
+ request: context.extra?.request
216
+ });
217
+ throw error;
218
+ }
219
+ }
220
+ throw error;
221
+ } finally {
222
+ (0, lodash_merge.default)(context, ctx);
223
+ }
224
+ return ctx;
225
+ };
226
+ return execute;
227
+ };
228
+ var execute_default = createExecute;
229
+
230
+ //#endregion
231
+ exports.default = execute_default;
@@ -0,0 +1,53 @@
1
+ import { IAccountState, IGasContext } from "@ocap/types";
2
+ import { CustomError } from "@ocap/util/lib/error";
3
+ import { Blacklist } from "@ocap/state";
4
+
5
+ //#region src/execute.d.ts
6
+ /** State helpers interface */
7
+ interface IStateHelpers {
8
+ tx: {
9
+ create: (ctx: IExecutionContext, status: string, persist?: boolean) => {
10
+ hash: string;
11
+ };
12
+ };
13
+ account: {
14
+ update: (state: unknown, updates: unknown, ctx: unknown) => unknown;
15
+ };
16
+ }
17
+ /** Extended context with tx-protocols specific fields */
18
+ interface IExecutionContext extends IGasContext {
19
+ events?: Array<{
20
+ table: string;
21
+ name: string;
22
+ data: unknown;
23
+ ctx: Record<string, unknown>;
24
+ }>;
25
+ states?: IStateHelpers;
26
+ stateSnapshot?: Record<string, unknown>;
27
+ txn?: unknown;
28
+ cacheStates?: unknown;
29
+ senderState?: IAccountState;
30
+ }
31
+ /** Protocol runner interface */
32
+ interface IProtocolRunner {
33
+ run: (context: IExecutionContext, callback: (error?: CustomError | null) => void) => void;
34
+ }
35
+ /** Protocols map */
36
+ type ProtocolsMap = Record<string, IProtocolRunner>;
37
+ /** Execute options */
38
+ interface IExecuteOptions {
39
+ filter: InstanceType<typeof Blacklist>;
40
+ runAsLambda?: <T>(fn: (txn: unknown) => Promise<T>, opts: {
41
+ cleanWorkingSet: boolean;
42
+ verifyHash: boolean;
43
+ context: IExecutionContext;
44
+ }) => Promise<T>;
45
+ }
46
+ /** Execute function type */
47
+ type ExecuteFn = (context: IExecutionContext, protocols: ProtocolsMap, isRetrySupported?: boolean) => Promise<IExecutionContext>;
48
+ declare const createExecute: ({
49
+ filter,
50
+ runAsLambda
51
+ }: IExecuteOptions) => ExecuteFn;
52
+ //#endregion
53
+ export { createExecute as default };
package/lib/index.cjs ADDED
@@ -0,0 +1,105 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
+ const require_execute = require('./execute.cjs');
4
+ const require_protocols_account_delegate = require('./protocols/account/delegate.cjs');
5
+ const require_protocols_account_migrate = require('./protocols/account/migrate.cjs');
6
+ const require_protocols_account_revoke_delegate = require('./protocols/account/revoke-delegate.cjs');
7
+ const require_protocols_asset_acquire_v2 = require('./protocols/asset/acquire-v2.cjs');
8
+ const require_protocols_asset_acquire_v3 = require('./protocols/asset/acquire-v3.cjs');
9
+ const require_protocols_asset_consume = require('./protocols/asset/consume.cjs');
10
+ const require_protocols_asset_create = require('./protocols/asset/create.cjs');
11
+ const require_protocols_asset_mint = require('./protocols/asset/mint.cjs');
12
+ const require_protocols_asset_update = require('./protocols/asset/update.cjs');
13
+ const require_protocols_factory_create = require('./protocols/factory/create.cjs');
14
+ const require_protocols_governance_claim_stake = require('./protocols/governance/claim-stake.cjs');
15
+ const require_protocols_governance_return_stake = require('./protocols/governance/return-stake.cjs');
16
+ const require_protocols_governance_revoke_stake = require('./protocols/governance/revoke-stake.cjs');
17
+ const require_protocols_governance_slash_stake = require('./protocols/governance/slash-stake.cjs');
18
+ const require_protocols_governance_stake = require('./protocols/governance/stake.cjs');
19
+ const require_protocols_rollup_claim_reward = require('./protocols/rollup/claim-reward.cjs');
20
+ const require_protocols_rollup_close = require('./protocols/rollup/close.cjs');
21
+ const require_protocols_rollup_create = require('./protocols/rollup/create.cjs');
22
+ const require_protocols_rollup_create_block = require('./protocols/rollup/create-block.cjs');
23
+ const require_protocols_rollup_join = require('./protocols/rollup/join.cjs');
24
+ const require_protocols_rollup_leave = require('./protocols/rollup/leave.cjs');
25
+ const require_protocols_rollup_migrate = require('./protocols/rollup/migrate.cjs');
26
+ const require_protocols_rollup_pause = require('./protocols/rollup/pause.cjs');
27
+ const require_protocols_rollup_resume = require('./protocols/rollup/resume.cjs');
28
+ const require_protocols_rollup_update = require('./protocols/rollup/update.cjs');
29
+ const require_protocols_token_factory_burn = require('./protocols/token-factory/burn.cjs');
30
+ const require_protocols_token_factory_create = require('./protocols/token-factory/create.cjs');
31
+ const require_protocols_token_factory_mint = require('./protocols/token-factory/mint.cjs');
32
+ const require_protocols_token_factory_update = require('./protocols/token-factory/update.cjs');
33
+ const require_protocols_token_create = require('./protocols/token/create.cjs');
34
+ const require_protocols_token_deposit_v2 = require('./protocols/token/deposit-v2.cjs');
35
+ const require_protocols_token_withdraw_v2 = require('./protocols/token/withdraw-v2.cjs');
36
+ const require_protocols_trade_exchange_v2 = require('./protocols/trade/exchange-v2.cjs');
37
+ const require_protocols_trade_transfer_v2 = require('./protocols/trade/transfer-v2.cjs');
38
+ const require_protocols_trade_transfer_v3 = require('./protocols/trade/transfer-v3.cjs');
39
+ let _ocap_state = require("@ocap/state");
40
+ _ocap_state = require_rolldown_runtime.__toESM(_ocap_state);
41
+
42
+ //#region src/index.ts
43
+ const createExecutor = ({ filter, runAsLambda }) => {
44
+ const protocols = {
45
+ transfer: require_protocols_trade_transfer_v2.default,
46
+ transferV2: require_protocols_trade_transfer_v2.default,
47
+ transferV3: require_protocols_trade_transfer_v3.default,
48
+ exchangeV2: require_protocols_trade_exchange_v2.default,
49
+ accountMigrate: require_protocols_account_migrate.default,
50
+ delegate: require_protocols_account_delegate.default,
51
+ revokeDelegate: require_protocols_account_revoke_delegate.default,
52
+ createAsset: require_protocols_asset_create.default,
53
+ updateAsset: require_protocols_asset_update.default,
54
+ consumeAsset: require_protocols_asset_consume.default,
55
+ acquireAssetV2: require_protocols_asset_acquire_v2.default,
56
+ acquireAssetV3: require_protocols_asset_acquire_v3.default,
57
+ mintAsset: require_protocols_asset_mint.default,
58
+ createFactory: require_protocols_factory_create.default,
59
+ createToken: require_protocols_token_create.default,
60
+ depositTokenV2: require_protocols_token_deposit_v2.default,
61
+ withdrawTokenV2: require_protocols_token_withdraw_v2.default,
62
+ createTokenFactory: require_protocols_token_factory_create.default,
63
+ updateTokenFactory: require_protocols_token_factory_update.default,
64
+ mintToken: require_protocols_token_factory_mint.default,
65
+ burnToken: require_protocols_token_factory_burn.default,
66
+ stake: require_protocols_governance_stake.default,
67
+ revokeStake: require_protocols_governance_revoke_stake.default,
68
+ claimStake: require_protocols_governance_claim_stake.default,
69
+ slashStake: require_protocols_governance_slash_stake.default,
70
+ returnStake: require_protocols_governance_return_stake.default,
71
+ createRollup: require_protocols_rollup_create.default,
72
+ updateRollup: require_protocols_rollup_update.default,
73
+ joinRollup: require_protocols_rollup_join.default,
74
+ leaveRollup: require_protocols_rollup_leave.default,
75
+ pauseRollup: require_protocols_rollup_pause.default,
76
+ closeRollup: require_protocols_rollup_close.default,
77
+ resumeRollup: require_protocols_rollup_resume.default,
78
+ createRollupBlock: require_protocols_rollup_create_block.default,
79
+ claimBlockReward: require_protocols_rollup_claim_reward.default,
80
+ migrateRollup: require_protocols_rollup_migrate.default
81
+ };
82
+ const execute$1 = require_execute.default({
83
+ filter,
84
+ runAsLambda
85
+ });
86
+ return {
87
+ ...protocols,
88
+ execute: (context, done) => {
89
+ Object.defineProperty(context, "states", { value: _ocap_state });
90
+ if (typeof done === "function") return execute$1(context, protocols).then((res) => done(null, res)).catch((err) => done(err));
91
+ return execute$1(context, protocols);
92
+ }
93
+ };
94
+ };
95
+ const defaultExecutor = createExecutor({
96
+ filter: new _ocap_state.Blacklist(),
97
+ runAsLambda: void 0
98
+ });
99
+ const { execute } = defaultExecutor;
100
+ var src_default = defaultExecutor;
101
+
102
+ //#endregion
103
+ exports.createExecutor = createExecutor;
104
+ exports.default = src_default;
105
+ exports.execute = execute;
@@ -0,0 +1,95 @@
1
+ import * as states from "@ocap/state";
2
+
3
+ //#region src/index.d.ts
4
+ interface ICreateExecutorOptions {
5
+ filter: InstanceType<typeof states.Blacklist>;
6
+ runAsLambda?: <T>(fn: (txn: unknown) => Promise<T>, opts: {
7
+ cleanWorkingSet: boolean;
8
+ verifyHash: boolean;
9
+ context: unknown;
10
+ }) => Promise<T>;
11
+ }
12
+ declare const createExecutor: ({
13
+ filter,
14
+ runAsLambda
15
+ }: ICreateExecutorOptions) => {
16
+ execute: (context: unknown, done?: (err: Error | null, res?: unknown) => void) => any;
17
+ transfer: any;
18
+ transferV2: any;
19
+ transferV3: any;
20
+ exchangeV2: any;
21
+ accountMigrate: any;
22
+ delegate: any;
23
+ revokeDelegate: any;
24
+ createAsset: any;
25
+ updateAsset: any;
26
+ consumeAsset: any;
27
+ acquireAssetV2: any;
28
+ acquireAssetV3: any;
29
+ mintAsset: any;
30
+ createFactory: any;
31
+ createToken: any;
32
+ depositTokenV2: any;
33
+ withdrawTokenV2: any;
34
+ createTokenFactory: any;
35
+ updateTokenFactory: any;
36
+ mintToken: any;
37
+ burnToken: any;
38
+ stake: any;
39
+ revokeStake: any;
40
+ claimStake: any;
41
+ slashStake: any;
42
+ returnStake: any;
43
+ createRollup: any;
44
+ updateRollup: any;
45
+ joinRollup: any;
46
+ leaveRollup: any;
47
+ pauseRollup: any;
48
+ closeRollup: any;
49
+ resumeRollup: any;
50
+ createRollupBlock: any;
51
+ claimBlockReward: any;
52
+ migrateRollup: any;
53
+ };
54
+ declare const defaultExecutor: {
55
+ execute: (context: unknown, done?: (err: Error | null, res?: unknown) => void) => any;
56
+ transfer: any;
57
+ transferV2: any;
58
+ transferV3: any;
59
+ exchangeV2: any;
60
+ accountMigrate: any;
61
+ delegate: any;
62
+ revokeDelegate: any;
63
+ createAsset: any;
64
+ updateAsset: any;
65
+ consumeAsset: any;
66
+ acquireAssetV2: any;
67
+ acquireAssetV3: any;
68
+ mintAsset: any;
69
+ createFactory: any;
70
+ createToken: any;
71
+ depositTokenV2: any;
72
+ withdrawTokenV2: any;
73
+ createTokenFactory: any;
74
+ updateTokenFactory: any;
75
+ mintToken: any;
76
+ burnToken: any;
77
+ stake: any;
78
+ revokeStake: any;
79
+ claimStake: any;
80
+ slashStake: any;
81
+ returnStake: any;
82
+ createRollup: any;
83
+ updateRollup: any;
84
+ joinRollup: any;
85
+ leaveRollup: any;
86
+ pauseRollup: any;
87
+ closeRollup: any;
88
+ resumeRollup: any;
89
+ createRollupBlock: any;
90
+ claimBlockReward: any;
91
+ migrateRollup: any;
92
+ };
93
+ declare const execute: (context: unknown, done?: (err: Error | null, res?: unknown) => void) => any;
94
+ //#endregion
95
+ export { createExecutor, defaultExecutor as default, execute };
@@ -0,0 +1,141 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
+ const require_util = require('../util.cjs');
4
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
+ let _arcblock_did = require("@arcblock/did");
6
+ let _arcblock_did_util = require("@arcblock/did-util");
7
+ let _arcblock_jwt = require("@arcblock/jwt");
8
+ _arcblock_jwt = require_rolldown_runtime.__toESM(_arcblock_jwt);
9
+ let _ocap_state = require("@ocap/state");
10
+ let _ocap_util = require("@ocap/util");
11
+ let lodash_noop = require("lodash/noop");
12
+ lodash_noop = require_rolldown_runtime.__toESM(lodash_noop);
13
+ let debug = require("debug");
14
+ debug = require_rolldown_runtime.__toESM(debug);
15
+
16
+ //#region src/pipes/ensure-cost.ts
17
+ const debug$1 = (0, debug.default)("@ocap/tx-protocols:pipes:ensure-cost");
18
+ const ZERO = new _ocap_util.BN(0);
19
+ /** Context for ensure cost pipe */ function CreateEnsureTxCostPipe({ attachSenderChanges = true, throwOnInsufficientFund = true, gasOnly = false } = {}) {
20
+ return async function EnsureTxCost(context, next) {
21
+ const { statedb, txType, senderState, gasEstimate, totalGas } = context;
22
+ const { config } = context;
23
+ const { tx, extra = {}, txHash = "" } = context;
24
+ const { token, pk } = extra.gasStakeHeaders || {};
25
+ const gasStake = {};
26
+ if (token && pk && await _arcblock_jwt.verify(token, pk, {
27
+ enforceTimestamp: true,
28
+ tolerance: 5
29
+ })) {
30
+ const decoded = _arcblock_jwt.decode(token);
31
+ if ((decoded.txHash || "").split(",").map((x) => x.trim()).filter(Boolean).includes(txHash)) {
32
+ gasStake.owner = (0, _arcblock_did.toAddress)(decoded.iss);
33
+ gasStake.stakeId = (0, _arcblock_did_util.toStakeAddress)(gasStake.owner, gasStake.owner);
34
+ } else console.warn(`Invalid gas payer header for: ${txHash}`);
35
+ }
36
+ if (!gasStake.owner && tx?.from) {
37
+ const owner = tx.from;
38
+ gasStake.owner = owner;
39
+ gasStake.stakeId = (0, _arcblock_did_util.toStakeAddress)(owner, owner);
40
+ }
41
+ gasStake.state = await statedb.stake.get(gasStake.stakeId, context);
42
+ gasStake.valid = require_util.isGasStakeValid(gasStake.state, config);
43
+ context.gasStake = gasStake;
44
+ debug$1("gasStake", gasStake, context.extra);
45
+ const changes = {};
46
+ let txCost = new _ocap_util.BN(0);
47
+ const txFeeMap = config.transaction.txFee;
48
+ const txFee = txType ? txFeeMap[txType] : void 0;
49
+ if (!gasOnly && txFee) {
50
+ const totalFee = (0, _ocap_util.fromTokenToUnit)(txFee, config.token.decimal);
51
+ txCost = txCost.add(totalFee);
52
+ changes.fee = {
53
+ address: config.token.address,
54
+ value: totalFee.toString(10)
55
+ };
56
+ context.feeVaultChange = changes.fee;
57
+ }
58
+ const totalGasBN = totalGas ?? ZERO;
59
+ if (!gasStake.valid && totalGasBN.gt(ZERO)) {
60
+ txCost = txCost.add(totalGasBN);
61
+ changes.gas = {
62
+ address: config.token.address,
63
+ value: totalGasBN.toString(10)
64
+ };
65
+ context.gasVaultChange = changes.gas;
66
+ }
67
+ if (changes.fee) if (config.vaults.txFees?.length) {
68
+ const feeIndex = (0, _ocap_util.hexToNumber)(txHash.slice(-8)) % config.vaults.txFees.length;
69
+ context.feeVault = config.vaults.txFees[feeIndex];
70
+ } else context.feeVault = config.vaults.txFee;
71
+ let isCostCharged = false;
72
+ if (txCost.gt(ZERO)) {
73
+ const expected = new _ocap_util.BN(gasEstimate?.payment || 0).add(txCost);
74
+ const actual = new _ocap_util.BN(senderState?.tokens?.[config.token.address] || 0);
75
+ if (senderState && actual.gte(expected)) {
76
+ isCostCharged = true;
77
+ context.senderUpdates = require_util.applyTokenUpdates([{
78
+ address: config.token.address,
79
+ value: txCost.toString(10)
80
+ }], senderState, "sub");
81
+ context.senderChange = {
82
+ address: senderState.address,
83
+ token: config.token.address,
84
+ delta: `-${txCost.toString(10)}`
85
+ };
86
+ debug$1({
87
+ changes,
88
+ senderUpdates: context.senderUpdates
89
+ });
90
+ context.updateVaults = async function updateVaults() {
91
+ const [feeVaultState, gasVaultState] = await Promise.all([changes.fee && context.feeVault ? statedb.account.get(context.feeVault, context) : null, changes.gas && context.gasVault ? statedb.account.get(context.gasVault, context) : null]);
92
+ const [newFeeVaultState, newGasVaultState] = await Promise.all([changes.fee && feeVaultState ? statedb.account.update(feeVaultState.address, _ocap_state.account.update(feeVaultState, require_util.applyTokenUpdates([changes.fee], feeVaultState, "add"), context), context) : null, changes.gas && gasVaultState ? statedb.account.update(gasVaultState.address, _ocap_state.account.update(gasVaultState, require_util.applyTokenUpdates([changes.gas], gasVaultState, "add"), context), context) : null]);
93
+ if (newFeeVaultState) context.feeVaultState = newFeeVaultState;
94
+ if (newGasVaultState) context.gasVaultState = newGasVaultState;
95
+ context.updatedAccounts = context.updatedAccounts || [];
96
+ if (changes.fee && feeVaultState) {
97
+ context.updatedAccounts.push({
98
+ address: feeVaultState.address,
99
+ token: config.token.address,
100
+ delta: changes.fee.value,
101
+ action: "fee"
102
+ });
103
+ if (attachSenderChanges) context.updatedAccounts.push({
104
+ address: senderState.address,
105
+ token: config.token.address,
106
+ delta: `-${changes.fee.value}`,
107
+ action: "fee"
108
+ });
109
+ }
110
+ if (changes.gas && gasVaultState) {
111
+ context.updatedAccounts.push({
112
+ address: gasVaultState.address,
113
+ token: config.token.address,
114
+ delta: changes.gas.value,
115
+ action: "gas"
116
+ });
117
+ if (attachSenderChanges) context.updatedAccounts.push({
118
+ address: senderState.address,
119
+ token: config.token.address,
120
+ delta: `-${changes.gas.value}`,
121
+ action: "gas"
122
+ });
123
+ }
124
+ context.gasPaid = true;
125
+ };
126
+ } else if (!senderState) return next(new _ocap_util_lib_error.CustomError("INVALID_GAS_PAYER", `Gas payer ${tx.from} does not exist on chain`));
127
+ else if (throwOnInsufficientFund) return next(new _ocap_util_lib_error.CustomError("INSUFFICIENT_FUND", `Insufficient fund to pay for tx cost from ${senderState.address || tx.from}, expected ${(0, _ocap_util.fromUnitToToken)(expected, config.token.decimal)} ${config.token.symbol}, got ${(0, _ocap_util.fromUnitToToken)(actual, config.token.decimal)} ${config.token.symbol}`));
128
+ }
129
+ if (!isCostCharged) {
130
+ context.senderUpdates = {};
131
+ context.senderChange = null;
132
+ context.updateVaults = lodash_noop.default;
133
+ context.updatedAccounts = [];
134
+ }
135
+ return next();
136
+ };
137
+ }
138
+ var ensure_cost_default = CreateEnsureTxCostPipe;
139
+
140
+ //#endregion
141
+ exports.default = ensure_cost_default;
@@ -0,0 +1,18 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+
3
+ //#region src/pipes/ensure-cost.d.ts
4
+ /** Options for CreateEnsureTxCostPipe */
5
+ interface IEnsureTxCostOptions {
6
+ attachSenderChanges?: boolean;
7
+ throwOnInsufficientFund?: boolean;
8
+ gasOnly?: boolean;
9
+ }
10
+ /** Context for ensure cost pipe */
11
+ declare function CreateEnsureTxCostPipe({
12
+ attachSenderChanges,
13
+ throwOnInsufficientFund,
14
+ // In some cases, we can tolerance insufficient fund, such as account migration
15
+ gasOnly
16
+ }?: IEnsureTxCostOptions): PipeFunction<any>;
17
+ //#endregion
18
+ export { CreateEnsureTxCostPipe as default };