@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,137 @@
1
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
+ import verify_signers_default from "./pipes/verify-signers.mjs";
5
+ import verify_status_default from "./pipes/verify-status.mjs";
6
+ import verify_evidence_default from "./pipes/verify-evidence.mjs";
7
+ import { Runner, pipes } from "@ocap/tx-pipeline";
8
+ import { CustomError } from "@ocap/util/lib/error";
9
+ import { toStakeAddress } from "@arcblock/did-util";
10
+ import { account, evidence, rollup, stake } from "@ocap/state";
11
+ import Debug from "debug";
12
+ import { Joi, patterns, schemas } from "@arcblock/validator";
13
+ import MerkleTree from "@ocap/merkle-tree";
14
+
15
+ //#region src/protocols/rollup/leave.ts
16
+ const debug = Debug("@ocap/tx-protocols:leave-rollup");
17
+ const runner = new Runner("leave_rollup");
18
+ const schema = Joi.object({
19
+ rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
20
+ evidence: Joi.object({ hash: Joi.string().regex(patterns.txHash).required() }).required(),
21
+ signaturesList: schemas.multiSig.min(1).required(),
22
+ data: Joi.any().optional().allow(null)
23
+ }).options({
24
+ stripUnknown: true,
25
+ noDefaults: false
26
+ });
27
+ runner.use(({ itx }, next) => {
28
+ const { error } = schema.validate(itx);
29
+ return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
30
+ });
31
+ runner.use(pipes.ExtractState({
32
+ from: "itx.rollup",
33
+ to: "rollupState",
34
+ status: "INVALID_ROLLUP",
35
+ table: "rollup"
36
+ }));
37
+ runner.use(ensure_validator_default(false));
38
+ runner.use(verify_status_default({ paused: false }));
39
+ runner.use((context, next) => {
40
+ context.validatorsHash = MerkleTree.getListHash([context.tx.from]);
41
+ return next();
42
+ });
43
+ runner.use(verify_signers_default({
44
+ signersKey: "itx.signaturesList",
45
+ allowSender: false,
46
+ allowShrink: true
47
+ }));
48
+ runner.use(verify_evidence_default({
49
+ evidenceKey: "validatorsHash",
50
+ signaturesKey: "itx.signaturesList",
51
+ verifyMethod: "ethVerify"
52
+ }));
53
+ runner.use(pipes.ExtractState({
54
+ from: "itx.evidence.hash",
55
+ to: "evidenceState",
56
+ status: "OK",
57
+ table: "evidence"
58
+ }));
59
+ runner.use((context, next) => {
60
+ if (context.evidenceState) return next(new CustomError("INVALID_TX", "Leave evidence already seen on this chain"));
61
+ return next();
62
+ });
63
+ runner.use(verify_signers_default({
64
+ signersKey: "tx.signaturesList",
65
+ allowSender: false,
66
+ allowShrink: true
67
+ }));
68
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
69
+ runner.use((context, next) => {
70
+ const { tx: tx$1, rollupState } = context;
71
+ if (rollupState?.seedValidators.some((x) => x.address === tx$1.from)) return next(new CustomError("INVALID_TX", `Address ${tx$1.from} can not leave since it's seed validator`));
72
+ if (rollupState?.validators.some((x) => x.address === tx$1.from) === false) return next(new CustomError("INVALID_TX", `Address ${tx$1.from} not exist in validator whitelist`));
73
+ return next();
74
+ });
75
+ runner.use((context, next) => {
76
+ const { tx: tx$1, itx } = context;
77
+ context.stakeAddress = toStakeAddress(tx$1.from, itx.rollup);
78
+ return next();
79
+ });
80
+ runner.use(pipes.ExtractState({
81
+ from: "stakeAddress",
82
+ to: "stakeState",
83
+ status: "INVALID_STAKE_STATE",
84
+ table: "stake"
85
+ }));
86
+ runner.use(pipes.ExtractState({
87
+ from: "tx.from",
88
+ to: "senderState",
89
+ status: "INVALID_SENDER_STATE",
90
+ table: "account"
91
+ }));
92
+ runner.use(pipes.ExtractState({
93
+ from: "signers",
94
+ to: "signerStates",
95
+ status: "INVALID_SIGNER_STATE",
96
+ table: "account"
97
+ }));
98
+ runner.use(pipes.VerifyAccountMigration({
99
+ signerKey: "signerStates",
100
+ stateKey: "senderState",
101
+ addressKey: "tx.from"
102
+ }));
103
+ runner.use(ensure_gas_default(() => ({
104
+ create: 1,
105
+ update: 3,
106
+ payment: 0
107
+ })));
108
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
109
+ runner.use(pipes.TakeStateSnapshot());
110
+ runner.use(async (context, next) => {
111
+ const { tx: tx$1, itx, rollupState, statedb, senderState, stakeState, stakeAddress, senderUpdates, updateVaults } = context;
112
+ const newValidators = rollupState.validators.filter((x) => x.address !== tx$1.from);
113
+ const [newSenderState, newRollupState, newStakeState, newEvidenceState] = await Promise.all([
114
+ statedb.account.update(senderState.address, account.update(senderState, {
115
+ nonce: tx$1.nonce,
116
+ ...senderUpdates
117
+ }, context), context),
118
+ statedb.rollup.update(rollupState.address, rollup.update(rollupState, { validators: newValidators }, context), context),
119
+ statedb.stake.update(stakeAddress, stake.update(stakeState, { revocable: true }, context), context),
120
+ statedb.evidence.create(itx.evidence.hash, evidence.create({
121
+ hash: itx.evidence.hash,
122
+ data: "rollup-leave"
123
+ }, context), context)
124
+ ]);
125
+ if (updateVaults) await updateVaults();
126
+ context.senderState = newSenderState;
127
+ context.rollupState = newRollupState;
128
+ context.stakeState = newStakeState;
129
+ context.evidenceState = newEvidenceState;
130
+ debug("leave-rollup", newValidators);
131
+ next();
132
+ }, { persistError: true });
133
+ runner.use(pipes.VerifyStateDiff());
134
+ var leave_default = runner;
135
+
136
+ //#endregion
137
+ export { leave_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/rollup/migrate.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,85 @@
1
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
+ import verify_signers_default from "./pipes/verify-signers.mjs";
5
+ import verify_status_default from "./pipes/verify-status.mjs";
6
+ import { Runner, pipes } from "@ocap/tx-pipeline";
7
+ import { CustomError } from "@ocap/util/lib/error";
8
+ import { account, rollup } from "@ocap/state";
9
+ import { Joi } from "@arcblock/validator";
10
+
11
+ //#region src/protocols/rollup/migrate.ts
12
+ const runner = new Runner("migrate_rollup");
13
+ const schema = Joi.object({
14
+ rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
15
+ to: Joi.DID().prefix().wallet("ethereum").required(),
16
+ type: Joi.string().trim().valid("vault", "contract").required(),
17
+ message: Joi.string().trim().min(1).max(512).required(),
18
+ data: Joi.any().optional().allow(null)
19
+ }).options({
20
+ stripUnknown: true,
21
+ noDefaults: false
22
+ });
23
+ runner.use(({ itx }, next) => {
24
+ const { error } = schema.validate(itx);
25
+ return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
26
+ });
27
+ runner.use(pipes.ExtractState({
28
+ from: "itx.rollup",
29
+ to: "rollupState",
30
+ status: "INVALID_ROLLUP",
31
+ table: "rollup"
32
+ }));
33
+ runner.use(ensure_validator_default(true));
34
+ runner.use(verify_status_default({
35
+ paused: true,
36
+ closed: false
37
+ }));
38
+ runner.use(verify_signers_default({
39
+ signersKey: "tx.signaturesList",
40
+ allowSender: true
41
+ }));
42
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
43
+ runner.use(pipes.ExtractState({
44
+ from: "tx.from",
45
+ to: "senderState",
46
+ status: "INVALID_SENDER_STATE",
47
+ table: "account"
48
+ }));
49
+ runner.use(pipes.ExtractState({
50
+ from: "signers",
51
+ to: "signerStates",
52
+ status: "INVALID_SIGNER_STATE",
53
+ table: "account"
54
+ }));
55
+ runner.use(pipes.VerifyAccountMigration({
56
+ signerKey: "signerStates",
57
+ stateKey: "senderState",
58
+ addressKey: "tx.from"
59
+ }));
60
+ runner.use(ensure_gas_default(() => ({
61
+ create: 0,
62
+ update: 2,
63
+ payment: 0
64
+ })));
65
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
66
+ runner.use(pipes.TakeStateSnapshot());
67
+ runner.use(async (context, next) => {
68
+ const { tx: tx$1, itx, statedb, rollupState, senderState, senderUpdates, updateVaults } = context;
69
+ let updates = {};
70
+ if (itx.type === "vault") updates = rollup.migrateVault(rollupState, itx.to, context);
71
+ if (itx.type === "contract") updates = rollup.migrateContract(rollupState, itx.to, context);
72
+ const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
73
+ nonce: tx$1.nonce,
74
+ ...senderUpdates
75
+ }, context), context), statedb.rollup.update(itx.rollup, updates, context)]);
76
+ if (updateVaults) await updateVaults();
77
+ context.senderState = newSenderState;
78
+ context.rollupState = newRollupState;
79
+ next();
80
+ }, { persistError: true });
81
+ runner.use(pipes.VerifyStateDiff());
82
+ var migrate_default = runner;
83
+
84
+ //#endregion
85
+ export { migrate_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/rollup/pause.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,76 @@
1
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
+ import verify_signers_default from "./pipes/verify-signers.mjs";
5
+ import verify_status_default from "./pipes/verify-status.mjs";
6
+ import { Runner, pipes } from "@ocap/tx-pipeline";
7
+ import { CustomError } from "@ocap/util/lib/error";
8
+ import { account, rollup } from "@ocap/state";
9
+ import { Joi } from "@arcblock/validator";
10
+
11
+ //#region src/protocols/rollup/pause.ts
12
+ const runner = new Runner("pause_rollup");
13
+ const schema = Joi.object({
14
+ rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
15
+ data: Joi.any().optional().allow(null)
16
+ }).options({
17
+ stripUnknown: true,
18
+ noDefaults: false
19
+ });
20
+ runner.use(({ itx }, next) => {
21
+ const { error } = schema.validate(itx);
22
+ return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
23
+ });
24
+ runner.use(pipes.ExtractState({
25
+ from: "itx.rollup",
26
+ to: "rollupState",
27
+ status: "INVALID_ROLLUP",
28
+ table: "rollup"
29
+ }));
30
+ runner.use(ensure_validator_default(true));
31
+ runner.use(verify_status_default({ paused: false }));
32
+ runner.use(verify_signers_default({
33
+ signersKey: "tx.signaturesList",
34
+ allowSender: true
35
+ }));
36
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
37
+ runner.use(pipes.ExtractState({
38
+ from: "tx.from",
39
+ to: "senderState",
40
+ status: "INVALID_SENDER_STATE",
41
+ table: "account"
42
+ }));
43
+ runner.use(pipes.ExtractState({
44
+ from: "signers",
45
+ to: "signerStates",
46
+ status: "INVALID_SIGNER_STATE",
47
+ table: "account"
48
+ }));
49
+ runner.use(pipes.VerifyAccountMigration({
50
+ signerKey: "signerStates",
51
+ stateKey: "senderState",
52
+ addressKey: "tx.from"
53
+ }));
54
+ runner.use(ensure_gas_default(() => ({
55
+ create: 0,
56
+ update: 2,
57
+ payment: 0
58
+ })));
59
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
60
+ runner.use(pipes.TakeStateSnapshot());
61
+ runner.use(async (context, next) => {
62
+ const { tx: tx$1, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
63
+ const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
64
+ nonce: tx$1.nonce,
65
+ ...senderUpdates
66
+ }, context), context), statedb.rollup.update(itx.rollup, rollup.pause(rollupState, context), context)]);
67
+ if (updateVaults) await updateVaults();
68
+ context.senderState = newSenderState;
69
+ context.rollupState = newRollupState;
70
+ next();
71
+ }, { persistError: true });
72
+ runner.use(pipes.VerifyStateDiff());
73
+ var pause_default = runner;
74
+
75
+ //#endregion
76
+ export { pause_default as default };
@@ -0,0 +1,6 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+
3
+ //#region src/protocols/rollup/pipes/ensure-validator.d.ts
4
+ declare const ensure_validator: (isSeed: boolean) => PipeFunction<any>;
5
+ //#endregion
6
+ export { ensure_validator as default };
@@ -0,0 +1,12 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+
3
+ //#region src/protocols/rollup/pipes/ensure-validator.ts
4
+ const ensure_validator = (isSeed) => (context, next) => {
5
+ const { rollupState, tx } = context;
6
+ if ((isSeed ? rollupState.seedValidators : rollupState.validators).some((x) => x.address === tx?.from) === false) return next(new CustomError("INVALID_TX", "Tx sender is not an expected validator"));
7
+ return next();
8
+ };
9
+ var ensure_validator_default = ensure_validator;
10
+
11
+ //#endregion
12
+ export { ensure_validator_default as default };
@@ -0,0 +1,15 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+
3
+ //#region src/protocols/rollup/pipes/verify-evidence.d.ts
4
+ interface IVerifyEvidenceOptions {
5
+ evidenceKey: string;
6
+ signaturesKey: string;
7
+ verifyMethod?: 'verify' | 'ethVerify';
8
+ }
9
+ declare function CreateVerifyEvidencePipe({
10
+ evidenceKey,
11
+ signaturesKey,
12
+ verifyMethod
13
+ }: IVerifyEvidenceOptions): PipeFunction<any>;
14
+ //#endregion
15
+ export { CreateVerifyEvidencePipe as default };
@@ -0,0 +1,29 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import get from "lodash/get.js";
3
+ import { toTypeInfo } from "@arcblock/did";
4
+ import { toHex } from "@ocap/util";
5
+ import { fromPublicKey as fromPublicKey$1 } from "@ocap/wallet";
6
+
7
+ //#region src/protocols/rollup/pipes/verify-evidence.ts
8
+ function CreateVerifyEvidencePipe({ evidenceKey, signaturesKey, verifyMethod = "verify" }) {
9
+ if (["verify", "ethVerify"].includes(verifyMethod) === false) throw new CustomError("INVALID_ARGUMENT", `Invalid verify method: ${verifyMethod}, supported methods are: verify, ethVerify`);
10
+ return async (context, next) => {
11
+ const evidence = get(context, evidenceKey);
12
+ const signatures = get(context, signaturesKey);
13
+ for (const sig of signatures) {
14
+ const { signer, pk, delegator, signature } = sig;
15
+ const address = delegator || signer;
16
+ const wallet = fromPublicKey$1(pk, toTypeInfo(address));
17
+ try {
18
+ if (await wallet[verifyMethod](toHex(evidence), toHex(signature)) === false) return next(new CustomError("INVALID_SIGNATURE", `Signature for evidence from ${address} is not valid`));
19
+ } catch (err) {
20
+ return next(new CustomError("INVALID_SIGNATURE", `Signature for evidence from ${address} verify failed: ${err.message}`));
21
+ }
22
+ }
23
+ return next();
24
+ };
25
+ }
26
+ var verify_evidence_default = CreateVerifyEvidencePipe;
27
+
28
+ //#endregion
29
+ export { verify_evidence_default as default };
@@ -0,0 +1,15 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+
3
+ //#region src/protocols/rollup/pipes/verify-signers.d.ts
4
+ interface IVerifySignersOptions {
5
+ signersKey: string;
6
+ allowSender?: boolean;
7
+ allowShrink?: boolean;
8
+ }
9
+ declare function CreateVerifySignersPipe({
10
+ signersKey,
11
+ allowSender,
12
+ allowShrink
13
+ }: IVerifySignersOptions): PipeFunction<any>;
14
+ //#endregion
15
+ export { CreateVerifySignersPipe as default };
@@ -0,0 +1,36 @@
1
+ import { CustomError } from "@ocap/util/lib/error";
2
+ import get from "lodash/get.js";
3
+
4
+ //#region src/protocols/rollup/pipes/verify-signers.ts
5
+ function CreateVerifySignersPipe({ signersKey, allowSender = true, allowShrink = false }) {
6
+ return (context, next) => {
7
+ const { tx, rollupState } = context;
8
+ const rollup = rollupState;
9
+ const { minSignerCount, maxSignerCount } = rollup;
10
+ const signatures = get(context, signersKey);
11
+ const signerCount = signatures.length;
12
+ const seedValidators = rollup.seedValidators.map((x) => x.address);
13
+ const validators = rollup.validators.map((x) => x.address);
14
+ if (!allowSender && signatures.some((x) => x.signer === tx.from)) return next(new CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, sender not allowed to sign`));
15
+ if (validators.length > minSignerCount) {
16
+ if (signerCount < minSignerCount) return next(new CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, expect at least ${minSignerCount} signatures, got ${signerCount}`));
17
+ if (signerCount > maxSignerCount) return next(new CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, Expect at most ${maxSignerCount} signatures, got ${signerCount}`));
18
+ } else {
19
+ let actualValidatorCount = validators.length;
20
+ if (!allowSender && allowShrink) actualValidatorCount -= 1;
21
+ const expectedSignerCount = Math.min(actualValidatorCount, minSignerCount);
22
+ if (signerCount < expectedSignerCount) return next(new CustomError("INVALID_SIGNATURE", `Invalid ${signersKey}, all validators are expected to sign because we have less than ${expectedSignerCount} validators`));
23
+ }
24
+ const signers = signatures.map((x) => x.signer);
25
+ const missingSigner = seedValidators.find((x) => signers.includes(x) === false);
26
+ if (missingSigner) return next(new CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, missing signature from seed validator: ${missingSigner}`));
27
+ const invalidSigner = signers.find((x) => validators.includes(x) === false);
28
+ if (invalidSigner) return next(new CustomError("INVALID_SIGNATURE", `Invalid: ${signersKey}, signer ${invalidSigner} does not exist in validator whitelist`));
29
+ context.signers = signers;
30
+ return next();
31
+ };
32
+ }
33
+ var verify_signers_default = CreateVerifySignersPipe;
34
+
35
+ //#endregion
36
+ export { verify_signers_default as default };
@@ -0,0 +1,13 @@
1
+ import { PipeFunction } from "@ocap/tx-pipeline";
2
+
3
+ //#region src/protocols/rollup/pipes/verify-status.d.ts
4
+ interface IVerifyStatusOptions {
5
+ paused?: boolean;
6
+ closed?: boolean;
7
+ }
8
+ declare const verify_status: ({
9
+ paused,
10
+ closed
11
+ }?: IVerifyStatusOptions) => PipeFunction<any>;
12
+ //#endregion
13
+ export { verify_status as default };
@@ -0,0 +1,26 @@
1
+ import { pipes } from "@ocap/tx-pipeline";
2
+
3
+ //#region src/protocols/rollup/pipes/verify-status.ts
4
+ const verify_status = ({ paused, closed } = {}) => {
5
+ const fns = [];
6
+ if (paused === false) fns.push({
7
+ error: "INVALID_TX",
8
+ message: "The rollup is paused",
9
+ fn: (context) => !context.rollupState.paused
10
+ });
11
+ if (paused === true) fns.push({
12
+ error: "INVALID_TX",
13
+ message: "The rollup is not paused",
14
+ fn: (context) => context.rollupState.paused
15
+ });
16
+ if (closed === false) fns.push({
17
+ error: "INVALID_TX",
18
+ message: "The rollup is closed",
19
+ fn: (context) => !context.rollupState.closed
20
+ });
21
+ return pipes.VerifyInfo(fns);
22
+ };
23
+ var verify_status_default = verify_status;
24
+
25
+ //#endregion
26
+ export { verify_status_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/rollup/resume.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,79 @@
1
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
+ import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
+ import verify_signers_default from "./pipes/verify-signers.mjs";
5
+ import verify_status_default from "./pipes/verify-status.mjs";
6
+ import { Runner, pipes } from "@ocap/tx-pipeline";
7
+ import { CustomError } from "@ocap/util/lib/error";
8
+ import { account, rollup } from "@ocap/state";
9
+ import { Joi } from "@arcblock/validator";
10
+
11
+ //#region src/protocols/rollup/resume.ts
12
+ const runner = new Runner("resume_rollup");
13
+ const schema = Joi.object({
14
+ rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
15
+ data: Joi.any().optional().allow(null)
16
+ }).options({
17
+ stripUnknown: true,
18
+ noDefaults: false
19
+ });
20
+ runner.use(({ itx }, next) => {
21
+ const { error } = schema.validate(itx);
22
+ return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
23
+ });
24
+ runner.use(pipes.ExtractState({
25
+ from: "itx.rollup",
26
+ to: "rollupState",
27
+ status: "INVALID_ROLLUP",
28
+ table: "rollup"
29
+ }));
30
+ runner.use(ensure_validator_default(true));
31
+ runner.use(verify_status_default({
32
+ paused: true,
33
+ closed: false
34
+ }));
35
+ runner.use(verify_signers_default({
36
+ signersKey: "tx.signaturesList",
37
+ allowSender: true
38
+ }));
39
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
40
+ runner.use(pipes.ExtractState({
41
+ from: "tx.from",
42
+ to: "senderState",
43
+ status: "INVALID_SENDER_STATE",
44
+ table: "account"
45
+ }));
46
+ runner.use(pipes.ExtractState({
47
+ from: "signers",
48
+ to: "signerStates",
49
+ status: "INVALID_SIGNER_STATE",
50
+ table: "account"
51
+ }));
52
+ runner.use(pipes.VerifyAccountMigration({
53
+ signerKey: "signerStates",
54
+ stateKey: "senderState",
55
+ addressKey: "tx.from"
56
+ }));
57
+ runner.use(ensure_gas_default(() => ({
58
+ create: 0,
59
+ update: 2,
60
+ payment: 0
61
+ })));
62
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
63
+ runner.use(pipes.TakeStateSnapshot());
64
+ runner.use(async (context, next) => {
65
+ const { tx: tx$1, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
66
+ const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
67
+ nonce: tx$1.nonce,
68
+ ...senderUpdates
69
+ }, context), context), statedb.rollup.update(itx.rollup, rollup.resume(rollupState, context), context)]);
70
+ if (updateVaults) await updateVaults();
71
+ context.senderState = newSenderState;
72
+ context.rollupState = newRollupState;
73
+ next();
74
+ }, { persistError: true });
75
+ runner.use(pipes.VerifyStateDiff());
76
+ var resume_default = runner;
77
+
78
+ //#endregion
79
+ export { resume_default as default };
@@ -0,0 +1,4 @@
1
+ //#region src/protocols/rollup/update.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,111 @@
1
+ import { decodeAnySafe } from "../../util.mjs";
2
+ import ensure_cost_default from "../../pipes/ensure-cost.mjs";
3
+ import ensure_gas_default from "../../pipes/ensure-gas.mjs";
4
+ import ensure_validator_default from "./pipes/ensure-validator.mjs";
5
+ import verify_signers_default from "./pipes/verify-signers.mjs";
6
+ import verify_status_default from "./pipes/verify-status.mjs";
7
+ import { Runner, pipes } from "@ocap/tx-pipeline";
8
+ import { CustomError } from "@ocap/util/lib/error";
9
+ import { account, rollup } from "@ocap/state";
10
+ import Debug from "debug";
11
+ import { Joi } from "@arcblock/validator";
12
+
13
+ //#region src/protocols/rollup/update.ts
14
+ const debug = Debug("@ocap/tx-protocols:update-rollup");
15
+ const runner = new Runner("update_rollup");
16
+ const schema = Joi.object({
17
+ rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
18
+ minStakeAmount: Joi.BN().greater(0).required(),
19
+ maxStakeAmount: Joi.BN().greater(Joi.ref("minStakeAmount")).required(),
20
+ minSignerCount: Joi.number().integer().required(),
21
+ maxSignerCount: Joi.number().integer().min(1).max(8).greater(Joi.ref("minSignerCount")).required(),
22
+ minBlockSize: Joi.number().integer().min(1).required(),
23
+ maxBlockSize: Joi.number().integer().min(1).max(10).greater(Joi.ref("minBlockSize")).required(),
24
+ minBlockInterval: Joi.number().integer().min(1).max(3600).required(),
25
+ minBlockConfirmation: Joi.number().integer().min(1).max(100).required(),
26
+ minDepositAmount: Joi.BN().positive().required(),
27
+ maxDepositAmount: Joi.BN().greater(Joi.ref("minDepositAmount")).required(),
28
+ minWithdrawAmount: Joi.BN().positive().required(),
29
+ maxWithdrawAmount: Joi.BN().greater(Joi.ref("minWithdrawAmount")).required(),
30
+ depositFeeRate: Joi.number().integer().min(1).max(1e4).required(),
31
+ withdrawFeeRate: Joi.number().integer().min(1).max(1e4).required(),
32
+ publisherFeeShare: Joi.number().integer().min(1).max(1e4).required(),
33
+ minDepositFee: Joi.BN().positive().required(),
34
+ maxDepositFee: Joi.BN().greater(Joi.ref("minDepositFee")).required(),
35
+ minWithdrawFee: Joi.BN().positive().required(),
36
+ maxWithdrawFee: Joi.BN().greater(Joi.ref("minWithdrawFee")).required(),
37
+ data: Joi.any().optional().allow(null)
38
+ }).options({
39
+ stripUnknown: true,
40
+ noDefaults: false
41
+ });
42
+ runner.use(({ itx }, next) => {
43
+ const { error } = schema.validate(itx);
44
+ return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
45
+ });
46
+ runner.use(pipes.VerifyInfo([{
47
+ error: "INVALID_TX",
48
+ message: "Sum of itx.proposerFeeShare and itx.publisherFeeShare must be less than 10000",
49
+ fn: (ctx) => {
50
+ const context = ctx;
51
+ return context.itx.proposerFeeShare + context.itx.publisherFeeShare < 1e4;
52
+ }
53
+ }]));
54
+ runner.use(pipes.ExtractState({
55
+ from: "itx.rollup",
56
+ to: "rollupState",
57
+ status: "INVALID_ROLLUP",
58
+ table: "rollup"
59
+ }));
60
+ runner.use(ensure_validator_default(true));
61
+ runner.use(verify_status_default({ paused: false }));
62
+ runner.use(verify_signers_default({
63
+ signersKey: "tx.signaturesList",
64
+ allowSender: true
65
+ }));
66
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "signers" }));
67
+ runner.use(pipes.ExtractState({
68
+ from: "tx.from",
69
+ to: "senderState",
70
+ status: "INVALID_SENDER_STATE",
71
+ table: "account"
72
+ }));
73
+ runner.use(pipes.ExtractState({
74
+ from: "signers",
75
+ to: "signerStates",
76
+ status: "INVALID_SIGNER_STATE",
77
+ table: "account"
78
+ }));
79
+ runner.use(pipes.VerifyAccountMigration({
80
+ signerKey: "signerStates",
81
+ stateKey: "senderState",
82
+ addressKey: "tx.from"
83
+ }));
84
+ runner.use(ensure_gas_default(() => ({
85
+ create: 0,
86
+ update: 2,
87
+ payment: 0
88
+ })));
89
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
90
+ runner.use(pipes.TakeStateSnapshot());
91
+ runner.use(async (context, next) => {
92
+ const { tx: tx$1, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
93
+ const data = decodeAnySafe(itx.data ?? null);
94
+ const [newSenderState, newRollupState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
95
+ nonce: tx$1.nonce,
96
+ ...senderUpdates
97
+ }, context), context), statedb.rollup.update(itx.rollup, rollup.update(rollupState, {
98
+ ...itx,
99
+ data
100
+ }, context), context)]);
101
+ if (updateVaults) await updateVaults();
102
+ context.senderState = newSenderState;
103
+ context.rollupState = newRollupState;
104
+ debug("update-rollup", newRollupState);
105
+ next();
106
+ }, { persistError: true });
107
+ runner.use(pipes.VerifyStateDiff());
108
+ var update_default = runner;
109
+
110
+ //#endregion
111
+ export { update_default as default };