@ocap/tx-protocols 1.28.9 → 1.29.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 (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,53 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import { Blacklist } from "@ocap/state";
3
+ import { IAccountState, IGasContext } from "@ocap/types";
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 };
@@ -0,0 +1,225 @@
1
+ import ensure_cost_default from "./pipes/ensure-cost.mjs";
2
+ import ensure_gas_default from "./pipes/ensure-gas.mjs";
3
+ import { Runner, pipes } from "@ocap/tx-pipeline";
4
+ import { CustomError } from "@ocap/util/lib/error";
5
+ import camelCase from "lodash/camelCase.js";
6
+ import get from "lodash/get.js";
7
+ import merge from "lodash/merge.js";
8
+ import pick from "lodash/pick.js";
9
+
10
+ //#region src/execute.ts
11
+ const ensureTxGas = ensure_gas_default(() => ({
12
+ create: 0,
13
+ update: 2
14
+ }));
15
+ const ensureTxCost = ensure_cost_default({
16
+ attachSenderChanges: true,
17
+ gasOnly: true
18
+ });
19
+ const getTxName = (typeUrl) => camelCase(typeUrl.split(":").pop() ?? "");
20
+ /** Get states helper with type guard - throws if states is not initialized */
21
+ const getStates = (context) => {
22
+ if (!context.states) throw new CustomError("INTERNAL", "States helper is not initialized in context");
23
+ return context.states;
24
+ };
25
+ const flushEvents = (context, extra = {}) => {
26
+ (context.events || []).forEach((e) => {
27
+ const table = context.statedb[e.table];
28
+ if (table?.emit) table.emit(e.name, e.data, {
29
+ ...e.ctx,
30
+ ...extra
31
+ });
32
+ });
33
+ context.events = [];
34
+ };
35
+ const shouldPersistTx = (err) => !err || Boolean(get(err, "props.persist"));
36
+ const createExecute = ({ filter, runAsLambda }) => {
37
+ const pre = new Runner("pre-execute");
38
+ pre.use(pipes.DecodeTx);
39
+ pre.use(pipes.VerifyBlocked({
40
+ filter,
41
+ stateKeys: ["tx.from"]
42
+ }));
43
+ pre.use(pipes.DecodeItx);
44
+ pre.use(pipes.VerifyTx);
45
+ pre.use(pipes.VerifyServiceFee);
46
+ pre.use(async (context, next) => {
47
+ if (filter.has(context.txHash)) {
48
+ if (await context.statedb.tx.get(context.txHash, context)) return next(new CustomError("DUPLICATE_TX", "Can not execute duplicate transaction"));
49
+ }
50
+ filter.add(context.txHash);
51
+ return next();
52
+ });
53
+ pre.use(pipes.VerifyTxSize);
54
+ pre.use(pipes.VerifySignature);
55
+ const ensureGasFeePaid = (context) => {
56
+ const gasRunner = new Runner("ensure-gas-fee-paid");
57
+ gasRunner.use(ensureTxGas);
58
+ gasRunner.use(ensureTxCost);
59
+ gasRunner.use(async (ctx, next) => {
60
+ const { tx, statedb, senderUpdates, updateVaults } = ctx;
61
+ if (ctx.senderState && ctx.states && tx) {
62
+ const senderState = ctx.stateSnapshot?.[ctx.senderState.address] || ctx.senderState;
63
+ const updates = ctx.states.account.update(senderState, {
64
+ nonce: tx.nonce,
65
+ pk: tx.pk,
66
+ ...senderUpdates
67
+ }, ctx);
68
+ await statedb.account.update(senderState.address, updates, ctx);
69
+ if (updateVaults) await updateVaults();
70
+ }
71
+ return next();
72
+ });
73
+ return new Promise((resolve, reject) => {
74
+ gasRunner.run(context, (err) => {
75
+ if (err) {
76
+ context.logger?.error("Failed to charge gas fee for errored tx", {
77
+ error: err,
78
+ tx: context.tx,
79
+ txBase64: context.txBase64,
80
+ txHash: context.txHash
81
+ });
82
+ reject(err);
83
+ return;
84
+ }
85
+ resolve();
86
+ });
87
+ });
88
+ };
89
+ const execute = async (context, protocols, isRetrySupported = false) => new Promise((resolve, reject) => {
90
+ pre.run(context, (err) => {
91
+ if (err) {
92
+ context.logger?.error("Failed to prepare transaction", {
93
+ error: err,
94
+ txHash: context.txHash,
95
+ request: context.extra?.request
96
+ });
97
+ return reject(err);
98
+ }
99
+ const protocol = protocols[getTxName(context.txType)];
100
+ if (!protocol) return reject(new CustomError("UNSUPPORTED_TX", `Unsupported tx type ${context.txType}`));
101
+ protocol.run(context, async (error) => {
102
+ if (isRetrySupported) {
103
+ if (error) return reject(error);
104
+ return resolve(context);
105
+ }
106
+ const txStatus = error ? error.code || "INTERNAL" : "OK";
107
+ const states = getStates(context);
108
+ let txState = states.tx.create(context, txStatus);
109
+ if (shouldPersistTx(error)) try {
110
+ if (error) {
111
+ await ensureGasFeePaid(context);
112
+ txState = states.tx.create(context, txStatus);
113
+ }
114
+ await context.statedb.tx.create(txState.hash, txState, context);
115
+ flushEvents(context, { txState });
116
+ } catch (e) {
117
+ context.logger?.error("Failed to save transaction to statedb", {
118
+ error: e,
119
+ txError: error,
120
+ txHash: context.txHash,
121
+ txState
122
+ });
123
+ return reject(error);
124
+ }
125
+ context.logger?.info("Tx finalized", {
126
+ txHash: context.txHash,
127
+ txStatus,
128
+ txState,
129
+ error
130
+ });
131
+ if (error) return reject(error);
132
+ return resolve(context);
133
+ });
134
+ });
135
+ });
136
+ if (typeof runAsLambda === "function") return async (context, protocols) => {
137
+ let ctx = context;
138
+ const startTime = Date.now();
139
+ try {
140
+ const txState = await runAsLambda(async (txn) => {
141
+ ctx = pick(context, [
142
+ "txBase64",
143
+ "statedb",
144
+ "indexdb",
145
+ "config",
146
+ "states",
147
+ "filter",
148
+ "extra",
149
+ "logger"
150
+ ]);
151
+ ctx.txn = txn;
152
+ await execute(ctx, protocols, true);
153
+ const state = getStates(context).tx.create(ctx, "OK");
154
+ await context.statedb.tx.create(state.hash, state, ctx);
155
+ return state;
156
+ }, {
157
+ cleanWorkingSet: true,
158
+ verifyHash: true,
159
+ context: ctx
160
+ });
161
+ flushEvents(ctx, { txState });
162
+ ctx.logger?.info("Tx finalized", {
163
+ txHash: ctx.txHash,
164
+ txState,
165
+ txStatus: "OK",
166
+ duration: Date.now() - startTime
167
+ });
168
+ } catch (error) {
169
+ const err = error;
170
+ const txStatus = err.code || "INTERNAL";
171
+ let txState = ctx.tx ? getStates(context).tx.create(ctx, txStatus, false) : null;
172
+ ctx.logger?.error("Failed to execute transaction", {
173
+ error,
174
+ txHash: ctx.txHash,
175
+ txState,
176
+ request: context.extra?.request
177
+ });
178
+ if (txState && shouldPersistTx(err)) {
179
+ ctx.events = [];
180
+ try {
181
+ txState = await runAsLambda(async (txn) => {
182
+ ctx = Object.assign({}, ctx, {
183
+ txn,
184
+ cacheStates: null
185
+ });
186
+ await ensureGasFeePaid(ctx);
187
+ const state = getStates(context).tx.create(ctx, txStatus);
188
+ await ctx.statedb.tx.create(state.hash, state, ctx);
189
+ return state;
190
+ }, {
191
+ cleanWorkingSet: true,
192
+ verifyHash: true,
193
+ context: ctx
194
+ });
195
+ flushEvents(ctx, { txState });
196
+ ctx.logger?.info("Tx finalized", {
197
+ txHash: ctx.txHash,
198
+ txState,
199
+ txStatus,
200
+ error,
201
+ duration: Date.now() - startTime
202
+ });
203
+ } catch (innerErr) {
204
+ ctx.logger?.error("Failed to save invalid transaction to statedb", {
205
+ error: innerErr,
206
+ txError: error,
207
+ txHash: ctx.txHash,
208
+ txState,
209
+ request: context.extra?.request
210
+ });
211
+ throw error;
212
+ }
213
+ }
214
+ throw error;
215
+ } finally {
216
+ merge(context, ctx);
217
+ }
218
+ return ctx;
219
+ };
220
+ return execute;
221
+ };
222
+ var execute_default = createExecute;
223
+
224
+ //#endregion
225
+ export { execute_default as default };
@@ -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 };
package/esm/index.mjs ADDED
@@ -0,0 +1,100 @@
1
+ import execute_default from "./execute.mjs";
2
+ import delegate_default from "./protocols/account/delegate.mjs";
3
+ import migrate_default from "./protocols/account/migrate.mjs";
4
+ import revoke_delegate_default from "./protocols/account/revoke-delegate.mjs";
5
+ import acquire_v2_default from "./protocols/asset/acquire-v2.mjs";
6
+ import acquire_v3_default from "./protocols/asset/acquire-v3.mjs";
7
+ import consume_default from "./protocols/asset/consume.mjs";
8
+ import create_default from "./protocols/asset/create.mjs";
9
+ import mint_default from "./protocols/asset/mint.mjs";
10
+ import update_default from "./protocols/asset/update.mjs";
11
+ import create_default$1 from "./protocols/factory/create.mjs";
12
+ import claim_stake_default from "./protocols/governance/claim-stake.mjs";
13
+ import return_stake_default from "./protocols/governance/return-stake.mjs";
14
+ import revoke_stake_default from "./protocols/governance/revoke-stake.mjs";
15
+ import slash_stake_default from "./protocols/governance/slash-stake.mjs";
16
+ import stake_default from "./protocols/governance/stake.mjs";
17
+ import claim_reward_default from "./protocols/rollup/claim-reward.mjs";
18
+ import close_default from "./protocols/rollup/close.mjs";
19
+ import create_default$2 from "./protocols/rollup/create.mjs";
20
+ import create_block_default from "./protocols/rollup/create-block.mjs";
21
+ import join_default from "./protocols/rollup/join.mjs";
22
+ import leave_default from "./protocols/rollup/leave.mjs";
23
+ import migrate_default$1 from "./protocols/rollup/migrate.mjs";
24
+ import pause_default from "./protocols/rollup/pause.mjs";
25
+ import resume_default from "./protocols/rollup/resume.mjs";
26
+ import update_default$1 from "./protocols/rollup/update.mjs";
27
+ import burn_default from "./protocols/token-factory/burn.mjs";
28
+ import create_default$3 from "./protocols/token-factory/create.mjs";
29
+ import mint_default$1 from "./protocols/token-factory/mint.mjs";
30
+ import update_default$2 from "./protocols/token-factory/update.mjs";
31
+ import create_default$4 from "./protocols/token/create.mjs";
32
+ import deposit_v2_default from "./protocols/token/deposit-v2.mjs";
33
+ import withdraw_v2_default from "./protocols/token/withdraw-v2.mjs";
34
+ import exchange_v2_default from "./protocols/trade/exchange-v2.mjs";
35
+ import transfer_v2_default from "./protocols/trade/transfer-v2.mjs";
36
+ import transfer_v3_default from "./protocols/trade/transfer-v3.mjs";
37
+ import * as states from "@ocap/state";
38
+
39
+ //#region src/index.ts
40
+ const createExecutor = ({ filter, runAsLambda }) => {
41
+ const protocols = {
42
+ transfer: transfer_v2_default,
43
+ transferV2: transfer_v2_default,
44
+ transferV3: transfer_v3_default,
45
+ exchangeV2: exchange_v2_default,
46
+ accountMigrate: migrate_default,
47
+ delegate: delegate_default,
48
+ revokeDelegate: revoke_delegate_default,
49
+ createAsset: create_default,
50
+ updateAsset: update_default,
51
+ consumeAsset: consume_default,
52
+ acquireAssetV2: acquire_v2_default,
53
+ acquireAssetV3: acquire_v3_default,
54
+ mintAsset: mint_default,
55
+ createFactory: create_default$1,
56
+ createToken: create_default$4,
57
+ depositTokenV2: deposit_v2_default,
58
+ withdrawTokenV2: withdraw_v2_default,
59
+ createTokenFactory: create_default$3,
60
+ updateTokenFactory: update_default$2,
61
+ mintToken: mint_default$1,
62
+ burnToken: burn_default,
63
+ stake: stake_default,
64
+ revokeStake: revoke_stake_default,
65
+ claimStake: claim_stake_default,
66
+ slashStake: slash_stake_default,
67
+ returnStake: return_stake_default,
68
+ createRollup: create_default$2,
69
+ updateRollup: update_default$1,
70
+ joinRollup: join_default,
71
+ leaveRollup: leave_default,
72
+ pauseRollup: pause_default,
73
+ closeRollup: close_default,
74
+ resumeRollup: resume_default,
75
+ createRollupBlock: create_block_default,
76
+ claimBlockReward: claim_reward_default,
77
+ migrateRollup: migrate_default$1
78
+ };
79
+ const execute$1 = execute_default({
80
+ filter,
81
+ runAsLambda
82
+ });
83
+ return {
84
+ ...protocols,
85
+ execute: (context, done) => {
86
+ Object.defineProperty(context, "states", { value: states });
87
+ if (typeof done === "function") return execute$1(context, protocols).then((res) => done(null, res)).catch((err) => done(err));
88
+ return execute$1(context, protocols);
89
+ }
90
+ };
91
+ };
92
+ const defaultExecutor = createExecutor({
93
+ filter: new states.Blacklist(),
94
+ runAsLambda: void 0
95
+ });
96
+ const { execute } = defaultExecutor;
97
+ var src_default = defaultExecutor;
98
+
99
+ //#endregion
100
+ export { createExecutor, src_default as default, execute };
@@ -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 };
@@ -0,0 +1,136 @@
1
+ import { applyTokenUpdates, isGasStakeValid } from "../util.mjs";
2
+ import { CustomError } from "@ocap/util/lib/error";
3
+ import { toAddress } from "@arcblock/did";
4
+ import { toStakeAddress } from "@arcblock/did-util";
5
+ import * as JWT from "@arcblock/jwt";
6
+ import { account } from "@ocap/state";
7
+ import { BN, fromTokenToUnit, fromUnitToToken, hexToNumber } from "@ocap/util";
8
+ import noop from "lodash/noop.js";
9
+ import Debug from "debug";
10
+
11
+ //#region src/pipes/ensure-cost.ts
12
+ const debug = Debug("@ocap/tx-protocols:pipes:ensure-cost");
13
+ const ZERO = new BN(0);
14
+ /** Context for ensure cost pipe */ function CreateEnsureTxCostPipe({ attachSenderChanges = true, throwOnInsufficientFund = true, gasOnly = false } = {}) {
15
+ return async function EnsureTxCost(context, next) {
16
+ const { statedb, txType, senderState, gasEstimate, totalGas } = context;
17
+ const { config } = context;
18
+ const { tx: tx$1, extra = {}, txHash = "" } = context;
19
+ const { token: token$1, pk } = extra.gasStakeHeaders || {};
20
+ const gasStake = {};
21
+ if (token$1 && pk && await JWT.verify(token$1, pk, {
22
+ enforceTimestamp: true,
23
+ tolerance: 5
24
+ })) {
25
+ const decoded = JWT.decode(token$1);
26
+ if ((decoded.txHash || "").split(",").map((x) => x.trim()).filter(Boolean).includes(txHash)) {
27
+ gasStake.owner = toAddress(decoded.iss);
28
+ gasStake.stakeId = toStakeAddress(gasStake.owner, gasStake.owner);
29
+ } else console.warn(`Invalid gas payer header for: ${txHash}`);
30
+ }
31
+ if (!gasStake.owner && tx$1?.from) {
32
+ const owner = tx$1.from;
33
+ gasStake.owner = owner;
34
+ gasStake.stakeId = toStakeAddress(owner, owner);
35
+ }
36
+ gasStake.state = await statedb.stake.get(gasStake.stakeId, context);
37
+ gasStake.valid = isGasStakeValid(gasStake.state, config);
38
+ context.gasStake = gasStake;
39
+ debug("gasStake", gasStake, context.extra);
40
+ const changes = {};
41
+ let txCost = new BN(0);
42
+ const txFeeMap = config.transaction.txFee;
43
+ const txFee = txType ? txFeeMap[txType] : void 0;
44
+ if (!gasOnly && txFee) {
45
+ const totalFee = fromTokenToUnit(txFee, config.token.decimal);
46
+ txCost = txCost.add(totalFee);
47
+ changes.fee = {
48
+ address: config.token.address,
49
+ value: totalFee.toString(10)
50
+ };
51
+ context.feeVaultChange = changes.fee;
52
+ }
53
+ const totalGasBN = totalGas ?? ZERO;
54
+ if (!gasStake.valid && totalGasBN.gt(ZERO)) {
55
+ txCost = txCost.add(totalGasBN);
56
+ changes.gas = {
57
+ address: config.token.address,
58
+ value: totalGasBN.toString(10)
59
+ };
60
+ context.gasVaultChange = changes.gas;
61
+ }
62
+ if (changes.fee) if (config.vaults.txFees?.length) {
63
+ const feeIndex = hexToNumber(txHash.slice(-8)) % config.vaults.txFees.length;
64
+ context.feeVault = config.vaults.txFees[feeIndex];
65
+ } else context.feeVault = config.vaults.txFee;
66
+ let isCostCharged = false;
67
+ if (txCost.gt(ZERO)) {
68
+ const expected = new BN(gasEstimate?.payment || 0).add(txCost);
69
+ const actual = new BN(senderState?.tokens?.[config.token.address] || 0);
70
+ if (senderState && actual.gte(expected)) {
71
+ isCostCharged = true;
72
+ context.senderUpdates = applyTokenUpdates([{
73
+ address: config.token.address,
74
+ value: txCost.toString(10)
75
+ }], senderState, "sub");
76
+ context.senderChange = {
77
+ address: senderState.address,
78
+ token: config.token.address,
79
+ delta: `-${txCost.toString(10)}`
80
+ };
81
+ debug({
82
+ changes,
83
+ senderUpdates: context.senderUpdates
84
+ });
85
+ context.updateVaults = async function updateVaults() {
86
+ 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]);
87
+ const [newFeeVaultState, newGasVaultState] = await Promise.all([changes.fee && feeVaultState ? statedb.account.update(feeVaultState.address, account.update(feeVaultState, applyTokenUpdates([changes.fee], feeVaultState, "add"), context), context) : null, changes.gas && gasVaultState ? statedb.account.update(gasVaultState.address, account.update(gasVaultState, applyTokenUpdates([changes.gas], gasVaultState, "add"), context), context) : null]);
88
+ if (newFeeVaultState) context.feeVaultState = newFeeVaultState;
89
+ if (newGasVaultState) context.gasVaultState = newGasVaultState;
90
+ context.updatedAccounts = context.updatedAccounts || [];
91
+ if (changes.fee && feeVaultState) {
92
+ context.updatedAccounts.push({
93
+ address: feeVaultState.address,
94
+ token: config.token.address,
95
+ delta: changes.fee.value,
96
+ action: "fee"
97
+ });
98
+ if (attachSenderChanges) context.updatedAccounts.push({
99
+ address: senderState.address,
100
+ token: config.token.address,
101
+ delta: `-${changes.fee.value}`,
102
+ action: "fee"
103
+ });
104
+ }
105
+ if (changes.gas && gasVaultState) {
106
+ context.updatedAccounts.push({
107
+ address: gasVaultState.address,
108
+ token: config.token.address,
109
+ delta: changes.gas.value,
110
+ action: "gas"
111
+ });
112
+ if (attachSenderChanges) context.updatedAccounts.push({
113
+ address: senderState.address,
114
+ token: config.token.address,
115
+ delta: `-${changes.gas.value}`,
116
+ action: "gas"
117
+ });
118
+ }
119
+ context.gasPaid = true;
120
+ };
121
+ } else if (!senderState) return next(new CustomError("INVALID_GAS_PAYER", `Gas payer ${tx$1.from} does not exist on chain`));
122
+ else if (throwOnInsufficientFund) return next(new CustomError("INSUFFICIENT_FUND", `Insufficient fund to pay for tx cost from ${senderState.address || tx$1.from}, expected ${fromUnitToToken(expected, config.token.decimal)} ${config.token.symbol}, got ${fromUnitToToken(actual, config.token.decimal)} ${config.token.symbol}`));
123
+ }
124
+ if (!isCostCharged) {
125
+ context.senderUpdates = {};
126
+ context.senderChange = null;
127
+ context.updateVaults = noop;
128
+ context.updatedAccounts = [];
129
+ }
130
+ return next();
131
+ };
132
+ }
133
+ var ensure_cost_default = CreateEnsureTxCostPipe;
134
+
135
+ //#endregion
136
+ export { ensure_cost_default as default };
@@ -0,0 +1,14 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+
3
+ //#region src/pipes/ensure-gas.d.ts
4
+ /** Gas estimate result */
5
+ interface IGasEstimate {
6
+ create: number;
7
+ update: number;
8
+ payment?: number;
9
+ }
10
+ /** Gas estimator function type - uses any for flexible context access */
11
+ type GasEstimatorFn = (context: any) => IGasEstimate;
12
+ declare function CreateGasEnsureFn(estimateTxGas: GasEstimatorFn): PipeFunction<any>;
13
+ //#endregion
14
+ export { CreateGasEnsureFn as default };
@@ -0,0 +1,38 @@
1
+ import { BN, hexToNumber } from "@ocap/util";
2
+ import Debug from "debug";
3
+
4
+ //#region src/pipes/ensure-gas.ts
5
+ const debug = Debug("@ocap/tx-protocols:pipes:ensure-gas");
6
+ function CreateGasEnsureFn(estimateTxGas) {
7
+ return function EnsureTxGas(context, next) {
8
+ const { txHash = "", config } = context;
9
+ const { txGas } = config.transaction;
10
+ const basePrice = new BN(txGas.price);
11
+ const estimate = estimateTxGas(context);
12
+ let totalGas = new BN(0);
13
+ if (context.txBaseGas) {
14
+ totalGas = basePrice.mul(new BN(txGas.dataStorage)).mul(new BN(context.txSize));
15
+ totalGas = totalGas.add(basePrice.mul(new BN(txGas.createState)).mul(new BN(estimate.create + 1)));
16
+ totalGas = totalGas.add(basePrice.mul(new BN(txGas.updateState)).mul(new BN(estimate.update)));
17
+ }
18
+ const { txGas: gasVaults = [] } = config.vaults;
19
+ const gasVault = gasVaults[gasVaults.length > 0 ? hexToNumber(txHash.slice(-8)) % gasVaults.length : 0];
20
+ context.gasVault = gasVault;
21
+ debug({
22
+ txType: context.txType,
23
+ txHash: context.txHash,
24
+ txSize: context.txSize,
25
+ txBaseGas: context.txBaseGas,
26
+ totalGas: totalGas.toString(10),
27
+ gasVault,
28
+ estimate
29
+ });
30
+ context.totalGas = totalGas;
31
+ context.gasEstimate = estimate;
32
+ return next();
33
+ };
34
+ }
35
+ var ensure_gas_default = CreateGasEnsureFn;
36
+
37
+ //#endregion
38
+ export { ensure_gas_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/account/delegate.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };