@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,178 @@
1
+ import { applyTokenUpdates } 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 { Runner, pipes } from "@ocap/tx-pipeline";
5
+ import { CustomError } from "@ocap/util/lib/error";
6
+ import { account, stake } from "@ocap/state";
7
+ import { BN } from "@ocap/util";
8
+ import Debug from "debug";
9
+ import { getListField } from "@ocap/util/lib/get-list-field";
10
+ import { Joi, schemas } from "@arcblock/validator";
11
+ import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
12
+ import isEmpty from "lodash/isEmpty.js";
13
+
14
+ //#region src/protocols/governance/revoke-stake.ts
15
+ const debug = Debug("@ocap/tx-protocols:revoke-stake");
16
+ const runner = new Runner("revoke_stake");
17
+ runner.use(pipes.VerifyMultiSig(0));
18
+ const schema = Joi.object({
19
+ address: Joi.DID().prefix().role("ROLE_STAKE").required(),
20
+ outputsList: schemas.multiInput.min(1).required(),
21
+ data: Joi.any().optional().allow(null)
22
+ }).options({
23
+ stripUnknown: true,
24
+ noDefaults: false
25
+ });
26
+ runner.use(({ itx }, next) => {
27
+ const { error } = schema.validate(itx);
28
+ return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
29
+ });
30
+ runner.use(pipes.VerifyTxInput({
31
+ fieldKey: "itx.outputs",
32
+ inputsKey: "outputs",
33
+ sendersKey: "receivers",
34
+ tokensKey: "tokens",
35
+ assetsKey: "assets"
36
+ }));
37
+ runner.use(pipes.VerifyInfo([{
38
+ error: "INSUFFICIENT_DATA",
39
+ message: "Can not revoke stake without any output",
40
+ fn: (ctx) => {
41
+ const context = ctx;
42
+ return !(isEmpty(context.tokens) && isEmpty(context.assets));
43
+ }
44
+ }]));
45
+ runner.use(pipes.VerifyListSize({ listKey: [
46
+ "outputs",
47
+ "receivers",
48
+ "tokens",
49
+ "assets"
50
+ ] }));
51
+ runner.use(pipes.ExtractState({
52
+ from: "tx.from",
53
+ to: "senderState",
54
+ status: "INVALID_SENDER_STATE",
55
+ table: "account"
56
+ }));
57
+ runner.use(pipes.ExtractState({
58
+ from: "receivers",
59
+ to: "receiverStates",
60
+ status: "INVALID_RECEIVER_STATE",
61
+ table: "account"
62
+ }));
63
+ runner.use(pipes.VerifyBlocked({ stateKeys: ["receiverStates"] }));
64
+ runner.use(pipes.VerifyAccountMigration({
65
+ stateKey: "senderState",
66
+ addressKey: "tx.from"
67
+ }));
68
+ runner.use(pipes.ExtractState({
69
+ from: "itx.address",
70
+ to: "stakeState",
71
+ status: "INVALID_STAKE_STATE",
72
+ table: "stake"
73
+ }));
74
+ runner.use(pipes.VerifyInfo([
75
+ {
76
+ error: "SENDER_NOT_MATCH",
77
+ message: "You are not allowed to revoke stake from this address",
78
+ fn: (ctx) => {
79
+ const context = ctx;
80
+ return getRelatedAddresses(context.senderState).includes(context.stakeState.sender);
81
+ }
82
+ },
83
+ {
84
+ error: "STAKE_NOT_REVOCABLE",
85
+ message: "This stake address is not revocable",
86
+ fn: (ctx) => {
87
+ return ctx.stakeState.revocable;
88
+ }
89
+ },
90
+ {
91
+ error: "INVALID_TX",
92
+ message: "Can not revoke assets that are not locked in the stake",
93
+ fn: (ctx) => {
94
+ const context = ctx;
95
+ return (context.assets || []).every((x) => (context.stakeState.assets || []).includes(x));
96
+ }
97
+ }
98
+ ]));
99
+ runner.use(pipes.ExtractState({
100
+ from: "tokens",
101
+ to: "tokenStates",
102
+ status: "INVALID_TOKEN",
103
+ table: "token"
104
+ }));
105
+ runner.use((context, next) => {
106
+ const { outputs = [], stakeState } = context;
107
+ const tokens = {};
108
+ outputs.forEach((output) => {
109
+ getListField(output, "tokens").forEach(({ address, value }) => {
110
+ if (typeof tokens[address] === "undefined") tokens[address] = new BN(0);
111
+ tokens[address] = tokens[address].add(new BN(value));
112
+ });
113
+ });
114
+ context.tokenCondition = {
115
+ owner: stakeState.address,
116
+ tokens: Object.keys(tokens).map((address) => ({
117
+ address,
118
+ value: tokens[address]
119
+ }))
120
+ };
121
+ next();
122
+ });
123
+ runner.use(pipes.VerifyTokenBalance({
124
+ ownerKey: "stakeState",
125
+ conditionKey: "tokenCondition"
126
+ }));
127
+ runner.use(pipes.ExtractState({
128
+ from: "assets",
129
+ to: "assetStates",
130
+ status: "OK",
131
+ table: "asset"
132
+ }));
133
+ runner.use(pipes.VerifyTransferrable({ assets: "assetStates" }));
134
+ runner.use(pipes.VerifyUpdater({
135
+ assetKey: "assetStates",
136
+ ownerKey: "stakeState"
137
+ }));
138
+ runner.use(ensure_gas_default(() => ({
139
+ create: 0,
140
+ update: 2,
141
+ payment: 0
142
+ })));
143
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
144
+ runner.use(pipes.TakeStateSnapshot());
145
+ runner.use(async (context, next) => {
146
+ const { tx: tx$1, itx, outputs = [], statedb, senderState, senderUpdates, stakeState, updateVaults } = context;
147
+ const stakeUpdates = {
148
+ tokens: stakeState.tokens || {},
149
+ assets: stakeState.assets || [],
150
+ revokedTokens: stakeState.revokedTokens || {},
151
+ revokedAssets: stakeState.revokedAssets || []
152
+ };
153
+ outputs.forEach((x) => {
154
+ const tokensList = getListField(x, "tokens");
155
+ const assetsList = getListField(x, "assets");
156
+ stakeUpdates.tokens = applyTokenUpdates(tokensList, { tokens: stakeUpdates.tokens }, "sub").tokens;
157
+ stakeUpdates.assets = stakeUpdates.assets.filter((a) => assetsList.includes(a) === false);
158
+ stakeUpdates.revokedTokens = applyTokenUpdates(tokensList, { tokens: stakeUpdates.revokedTokens }, "add").tokens;
159
+ stakeUpdates.revokedAssets = stakeUpdates.revokedAssets.concat(...assetsList);
160
+ });
161
+ const [newSenderState, newStakeState] = await Promise.all([statedb.account.update(senderState.address, account.update(senderState, {
162
+ nonce: tx$1.nonce,
163
+ ...senderUpdates
164
+ }, context), context), statedb.stake.update(stakeState.address, stake.update(stakeState, stakeUpdates, context), context)]);
165
+ if (updateVaults) await updateVaults();
166
+ context.senderState = newSenderState;
167
+ context.stakeState = newStakeState;
168
+ debug("revoke-stake", {
169
+ address: itx.address,
170
+ stakeUpdates
171
+ });
172
+ next();
173
+ }, { persistError: true });
174
+ runner.use(pipes.VerifyStateDiff());
175
+ var revoke_stake_default = runner;
176
+
177
+ //#endregion
178
+ export { revoke_stake_default as default };
@@ -0,0 +1,17 @@
1
+ //#region src/protocols/governance/slash-stake.d.ts
2
+ /** Token input type */
3
+ interface TokenInput {
4
+ address: string;
5
+ value: string;
6
+ }
7
+ /** Multi-output type */
8
+ interface MultiOutput {
9
+ owner: string;
10
+ tokensList?: TokenInput[];
11
+ tokens?: TokenInput[];
12
+ assetsList?: string[];
13
+ assets?: string[];
14
+ }
15
+ declare const runner: any;
16
+ //#endregion
17
+ export { MultiOutput, TokenInput, runner as default };
@@ -0,0 +1,213 @@
1
+ import { applyTokenChange, applyTokenUpdates } 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 { Runner, pipes } from "@ocap/tx-pipeline";
5
+ import { CustomError } from "@ocap/util/lib/error";
6
+ import { account, asset, stake } from "@ocap/state";
7
+ import { BN } from "@ocap/util";
8
+ import Debug from "debug";
9
+ import { getListField } from "@ocap/util/lib/get-list-field";
10
+ import { Joi, schemas } from "@arcblock/validator";
11
+ import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
12
+ import isEmpty from "lodash/isEmpty.js";
13
+
14
+ //#region src/protocols/governance/slash-stake.ts
15
+ const debug = Debug("@ocap/tx-protocols:slash-stake");
16
+ const runner = new Runner("slash_stake");
17
+ runner.use(pipes.VerifyMultiSig(0));
18
+ const schema = Joi.object({
19
+ address: Joi.DID().prefix().role("ROLE_STAKE").required(),
20
+ message: Joi.string().trim().min(1).max(256).required(),
21
+ outputsList: schemas.multiInput.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.VerifyTxInput({
32
+ fieldKey: "itx.outputs",
33
+ inputsKey: "outputs",
34
+ sendersKey: "receivers",
35
+ tokensKey: "tokens",
36
+ assetsKey: "assets"
37
+ }));
38
+ runner.use(pipes.VerifyInfo([{
39
+ error: "INSUFFICIENT_DATA",
40
+ message: "Can not slash stake without any output",
41
+ fn: (ctx) => {
42
+ const context = ctx;
43
+ return !(isEmpty(context.tokens || []) && isEmpty(context.assets || []));
44
+ }
45
+ }]));
46
+ runner.use(pipes.VerifyListSize({ listKey: [
47
+ "outputs",
48
+ "receivers",
49
+ "tokens",
50
+ "assets"
51
+ ] }));
52
+ runner.use(pipes.ExtractState({
53
+ from: "tx.from",
54
+ to: "senderState",
55
+ status: "INVALID_SENDER_STATE",
56
+ table: "account"
57
+ }));
58
+ runner.use(pipes.ExtractState({
59
+ from: "receivers",
60
+ to: "receiverStates",
61
+ status: "INVALID_RECEIVER_STATE",
62
+ table: "account"
63
+ }));
64
+ runner.use(pipes.VerifyBlocked({ stateKeys: ["receiverStates"] }));
65
+ runner.use(pipes.VerifyAccountMigration({
66
+ stateKey: "senderState",
67
+ addressKey: "tx.from"
68
+ }));
69
+ runner.use(pipes.ExtractState({
70
+ from: "itx.address",
71
+ to: "stakeState",
72
+ status: "INVALID_STAKE_STATE",
73
+ table: "stake"
74
+ }));
75
+ runner.use(pipes.ExtractState({
76
+ from: "stakeState.slashers",
77
+ to: "slasherStates",
78
+ status: "INVALID_SLASH_STATE",
79
+ table: "account"
80
+ }));
81
+ runner.use(pipes.VerifyInfo([{
82
+ error: "INVALID_TX",
83
+ message: "You are not allowed to slash from this stake",
84
+ fn: (ctx) => {
85
+ const context = ctx;
86
+ const slasherStates = context.slasherStates || [];
87
+ return (isEmpty(slasherStates) ? [context.stakeState.receiver] : slasherStates.map((x) => x.address)).includes(context.senderState.address);
88
+ }
89
+ }, {
90
+ error: "INVALID_TX",
91
+ message: "Can only send slashed token/assets to vault or specified slasher",
92
+ fn: (ctx) => {
93
+ const context = ctx;
94
+ const slasherStates = context.slasherStates || [];
95
+ return (context.receivers || []).every((x) => x === context.config.vaults.slashedStake || slasherStates.some((s) => s.address === x));
96
+ }
97
+ }]));
98
+ runner.use(pipes.ExtractState({
99
+ from: "tokens",
100
+ to: "tokenStates",
101
+ status: "INVALID_TOKEN",
102
+ table: "token"
103
+ }));
104
+ runner.use((context, next) => {
105
+ const { outputs = [], stakeState } = context;
106
+ const tokens = {};
107
+ outputs.forEach((output) => {
108
+ getListField(output, "tokens").forEach(({ address, value }) => {
109
+ if (typeof tokens[address] === "undefined") tokens[address] = new BN(0);
110
+ tokens[address] = tokens[address].add(new BN(value));
111
+ });
112
+ });
113
+ const lockedState = {
114
+ address: stakeState.address,
115
+ tokens: { ...stakeState.tokens },
116
+ assets: [...stakeState.assets || [], ...stakeState.revokedAssets || []]
117
+ };
118
+ Object.keys(stakeState.revokedTokens || {}).forEach((address) => {
119
+ lockedState.tokens[address] = new BN(stakeState.revokedTokens[address] || "0").add(new BN(stakeState.tokens[address] || "0")).toString(10);
120
+ });
121
+ context.lockedState = lockedState;
122
+ context.tokenCondition = {
123
+ owner: stakeState.address,
124
+ tokens: Object.keys(tokens).map((address) => ({
125
+ address,
126
+ value: tokens[address]
127
+ }))
128
+ };
129
+ next();
130
+ });
131
+ runner.use(pipes.VerifyTokenBalance({
132
+ ownerKey: "lockedState",
133
+ conditionKey: "tokenCondition"
134
+ }));
135
+ runner.use(pipes.VerifyInfo([{
136
+ error: "INVALID_TX",
137
+ message: "Can not slash assets that are not locked in the stake",
138
+ fn: (ctx) => {
139
+ const context = ctx;
140
+ return (context.assets || []).every((x) => (context.lockedState?.assets || []).includes(x));
141
+ }
142
+ }]));
143
+ runner.use(pipes.ExtractState({
144
+ from: "assets",
145
+ to: "assetStates",
146
+ status: "INVALID_ASSET_STATE",
147
+ table: "asset"
148
+ }));
149
+ runner.use(pipes.VerifyTransferrable({ assets: "assetStates" }));
150
+ runner.use(pipes.VerifyUpdater({
151
+ assetKey: "assetStates",
152
+ ownerKey: "stakeState"
153
+ }));
154
+ runner.use(ensure_gas_default((context) => {
155
+ const result = {
156
+ create: 0,
157
+ update: 2,
158
+ payment: 0
159
+ };
160
+ if (context.receiverStates) result.update += context.receiverStates.length;
161
+ if (context.assetStates) result.update += context.assetStates.length;
162
+ return result;
163
+ }));
164
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
165
+ runner.use(pipes.TakeStateSnapshot());
166
+ runner.use(async (context, next) => {
167
+ const { tx: tx$1, itx, outputs = [], statedb, senderState, receiverStates = [], assetStates = [], stakeState, updateVaults, senderChange } = context;
168
+ const receiverUpdates = {};
169
+ const assetUpdates = {};
170
+ const stakeUpdates = {
171
+ tokens: stakeState.tokens || {},
172
+ assets: stakeState.assets || [],
173
+ revokedTokens: stakeState.revokedTokens || {},
174
+ revokedAssets: stakeState.revokedAssets || []
175
+ };
176
+ outputs.forEach((x) => {
177
+ const { owner } = x;
178
+ const tokensList = getListField(x, "tokens");
179
+ const assetsList = getListField(x, "assets");
180
+ stakeUpdates.assets = stakeUpdates.assets.filter((a) => assetsList.includes(a) === false);
181
+ stakeUpdates.revokedAssets = stakeUpdates.revokedAssets.filter((a) => assetsList.includes(a) === false);
182
+ const [newTokens, newRevoked] = applyTokenUpdates(tokensList, [{ tokens: stakeUpdates.tokens }, { tokens: stakeUpdates.revokedTokens }], "sub");
183
+ stakeUpdates.tokens = newTokens.tokens;
184
+ stakeUpdates.revokedTokens = newRevoked.tokens;
185
+ const ownerState = receiverStates.find((s) => getRelatedAddresses(s).includes(owner));
186
+ receiverUpdates[ownerState.address] = applyTokenUpdates(tokensList, ownerState, "add");
187
+ if (senderChange && ownerState.address === senderChange.address) receiverUpdates[ownerState.address] = applyTokenChange(receiverUpdates[ownerState.address], senderChange);
188
+ assetsList.forEach((a) => {
189
+ assetUpdates[a] = { owner: ownerState.address };
190
+ });
191
+ });
192
+ const [newSenderState, newReceiverStates, newStakeState, newAssetStates] = await Promise.all([
193
+ statedb.account.update(senderState.address, account.update(senderState, Object.assign({ nonce: tx$1.nonce }, receiverUpdates[senderState.address] || (senderChange ? applyTokenChange(senderState, senderChange) : {})), context), context),
194
+ Promise.all(receiverStates.filter((x) => x.address !== senderState.address).map((x) => statedb.account.update(x.address, account.update(x, receiverUpdates[x.address], context), context))),
195
+ statedb.stake.update(stakeState.address, stake.update(stakeState, stakeUpdates, context), context),
196
+ Promise.all(assetStates.map((x) => statedb.asset.update(x.address, asset.update(x, assetUpdates[x.address], context), context)))
197
+ ]);
198
+ if (updateVaults) await updateVaults();
199
+ context.senderState = newSenderState;
200
+ context.receiverStates = newReceiverStates;
201
+ context.stakeState = newStakeState;
202
+ context.assetStates = newAssetStates;
203
+ debug("slash-stake", {
204
+ address: itx.address,
205
+ stakeUpdates
206
+ });
207
+ next();
208
+ }, { persistError: true });
209
+ runner.use(pipes.VerifyStateDiff());
210
+ var slash_stake_default = runner;
211
+
212
+ //#endregion
213
+ export { slash_stake_default as default };
@@ -0,0 +1,15 @@
1
+ //#region src/protocols/governance/stake.d.ts
2
+ /** Token input type */
3
+ interface TokenInput {
4
+ address: string;
5
+ value: string;
6
+ }
7
+ /** Multi-input type - uses List suffix in proto but runtime has both */
8
+ interface MultiInput {
9
+ owner: string;
10
+ tokensList?: TokenInput[];
11
+ assetsList?: string[];
12
+ }
13
+ declare const runner: any;
14
+ //#endregion
15
+ export { MultiInput, TokenInput, runner as default };
@@ -0,0 +1,270 @@
1
+ import { applyTokenChange, applyTokenUpdates, isGasStakeAddress, isGasStakeInput } 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 { Runner, pipes } from "@ocap/tx-pipeline";
5
+ import { CustomError } from "@ocap/util/lib/error";
6
+ import pick from "lodash/pick.js";
7
+ import { toStakeAddress } from "@arcblock/did-util";
8
+ import { account, asset, stake } from "@ocap/state";
9
+ import { BN, fromTokenToUnit } from "@ocap/util";
10
+ import Debug from "debug";
11
+ import { getListField } from "@ocap/util/lib/get-list-field";
12
+ import { Joi, schemas } from "@arcblock/validator";
13
+ import { promisify } from "node:util";
14
+ import isEmpty from "lodash/isEmpty.js";
15
+
16
+ //#region src/protocols/governance/stake.ts
17
+ const debug = Debug("@ocap/tx-protocols:stake");
18
+ const verifyAssetOwner = promisify(pipes.VerifyUpdater({
19
+ assetKey: "assets",
20
+ ownerKey: "owner"
21
+ }));
22
+ const runner = new Runner("stake");
23
+ const schema = Joi.object({
24
+ address: Joi.DID().prefix().role("ROLE_STAKE").required(),
25
+ receiver: Joi.DID().prefix().required(),
26
+ slashersList: Joi.array().items(Joi.DID().prefix()).default([]),
27
+ locked: Joi.boolean().default(false),
28
+ inputsList: schemas.multiInput.min(1).required(),
29
+ message: Joi.string().trim().min(1).max(256).required(),
30
+ revokeWaitingPeriod: Joi.number().integer().min(0).default(0),
31
+ data: Joi.any().optional().allow(null),
32
+ nonce: Joi.string().trim().min(1).max(256).allow("").optional().allow(null)
33
+ }).options({
34
+ stripUnknown: true,
35
+ noDefaults: false
36
+ });
37
+ runner.use(({ itx }, next) => {
38
+ const { error } = schema.validate(itx);
39
+ return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
40
+ });
41
+ runner.use(pipes.VerifyTxInput({
42
+ fieldKey: "itx.inputs",
43
+ inputsKey: "inputs",
44
+ sendersKey: "senders",
45
+ tokensKey: "tokens",
46
+ assetsKey: "assets"
47
+ }));
48
+ runner.use(pipes.VerifyInfo([
49
+ {
50
+ error: "INVALID_TX",
51
+ message: "Invalid staking address",
52
+ fn: (ctx) => {
53
+ const context = ctx;
54
+ return toStakeAddress(context.tx.from, context.itx.receiver, context.itx.nonce) === context.itx.address;
55
+ }
56
+ },
57
+ {
58
+ error: "INVALID_TX",
59
+ message: "Tx sender can not be slasher",
60
+ fn: (ctx) => {
61
+ const context = ctx;
62
+ const slashers = getListField(context.itx, "slashers");
63
+ return slashers.length === 0 || slashers.includes(context.tx.from) === false;
64
+ }
65
+ },
66
+ {
67
+ error: "INSUFFICIENT_DATA",
68
+ message: "Can not stake without any token or asset",
69
+ fn: (ctx) => {
70
+ const context = ctx;
71
+ return !(isEmpty(context.tokens) && isEmpty(context.assets));
72
+ }
73
+ }
74
+ ]));
75
+ runner.use(pipes.VerifyListSize({ listKey: [
76
+ "inputs",
77
+ "senders",
78
+ "tokens",
79
+ "assets"
80
+ ] }));
81
+ runner.use(pipes.VerifyMultiSigV2({ signersKey: "senders" }));
82
+ runner.use(pipes.ExtractState({
83
+ from: "itx.address",
84
+ to: "stakeState",
85
+ status: "OK",
86
+ table: "stake"
87
+ }));
88
+ runner.use(pipes.ExtractState({
89
+ from: "tx.from",
90
+ to: "senderState",
91
+ status: "OK",
92
+ table: "account"
93
+ }));
94
+ runner.use(pipes.ExtractState({
95
+ from: "senders",
96
+ to: "signerStates",
97
+ status: "INVALID_SIGNER_STATE",
98
+ table: "account"
99
+ }));
100
+ runner.use(pipes.VerifyAccountMigration({
101
+ signerKey: "signerStates",
102
+ stateKey: "senderState",
103
+ addressKey: "tx.from"
104
+ }));
105
+ runner.use(pipes.ExtractState({
106
+ from: "itx.receiver",
107
+ to: "receiverState",
108
+ status: "INVALID_RECEIVER_STATE"
109
+ }));
110
+ runner.use(pipes.VerifyBlocked({ stateKeys: ["signerStates", "receiverState"] }));
111
+ runner.use(pipes.VerifyAccountMigration({
112
+ stateKey: "receiverState",
113
+ addressKey: "itx.receiver"
114
+ }));
115
+ runner.use(pipes.ExtractState({
116
+ from: "tokens",
117
+ to: "tokenStates",
118
+ status: "INVALID_TOKEN",
119
+ table: "token"
120
+ }));
121
+ runner.use(pipes.VerifyTokenBalance({
122
+ ownerKey: "signerStates",
123
+ conditionKey: "inputs"
124
+ }));
125
+ runner.use(pipes.verifyTokenAccess({
126
+ statesKey: "tokenStates",
127
+ listFieldKey: "spenders",
128
+ accountKeys: ["senderState"],
129
+ errorMessage: "Account {address} is not allowed to stake token {tokenAddress}"
130
+ }));
131
+ runner.use(pipes.ExtractState({
132
+ from: "assets",
133
+ to: "assetStates",
134
+ status: "OK",
135
+ table: "asset"
136
+ }));
137
+ runner.use(pipes.VerifyTransferrable({ assets: "assetStates" }));
138
+ runner.use(async (context, next) => {
139
+ const { inputs = [], assetStates = [], signerStates = [] } = context;
140
+ for (const input of inputs) {
141
+ const { owner } = input;
142
+ const assetsList = getListField(input, "assets");
143
+ const states = assetStates.filter((x) => assetsList.includes(x.address));
144
+ const signer = signerStates.find((x) => x.address === owner);
145
+ try {
146
+ await verifyAssetOwner({
147
+ assets: states,
148
+ owner: signer
149
+ });
150
+ } catch (err) {
151
+ return next(err);
152
+ }
153
+ }
154
+ return next();
155
+ });
156
+ runner.use(pipes.ExtractState({
157
+ from: "itx.slashersList",
158
+ to: "slasherStates",
159
+ status: "INVALID_SLASHER_STATE",
160
+ table: "account"
161
+ }));
162
+ runner.use(pipes.VerifyAccountMigration({
163
+ stateKey: "slasherStates",
164
+ addressKey: "itx.slashersList"
165
+ }));
166
+ runner.use((context, next) => {
167
+ const { tx: tx$1, itx, inputs = [] } = context;
168
+ const { config } = context;
169
+ const { token: token$1, transaction } = config;
170
+ const { minStake, maxStake } = transaction.txGas;
171
+ context.isGasStake = isGasStakeAddress(tx$1.from, itx.address) && isGasStakeInput(inputs, token$1.address);
172
+ if (context.isGasStake) {
173
+ const [tokenInput] = getListField(inputs[0], "tokens");
174
+ const actualStake = new BN(tokenInput.value);
175
+ const expectedMinStake = fromTokenToUnit(minStake, token$1.decimal);
176
+ const expectedMaxStake = fromTokenToUnit(maxStake, token$1.decimal);
177
+ if (actualStake.lt(expectedMinStake)) return next(new CustomError("INVALID_TX", `Stake for gas should be greater than: ${minStake}`));
178
+ if (actualStake.gt(expectedMaxStake)) return next(new CustomError("INVALID_TX", `Stake for gas should be less than: ${maxStake}`));
179
+ }
180
+ if (context.isGasStake) {
181
+ context.revokeWaitingPeriod = transaction.txGas.stakeLockPeriod;
182
+ context.slashers = [config.moderator.address];
183
+ } else {
184
+ context.revokeWaitingPeriod = itx.revokeWaitingPeriod;
185
+ context.slashers = getListField(itx, "slashers");
186
+ }
187
+ return next();
188
+ });
189
+ runner.use(ensure_gas_default((context) => {
190
+ const result = {
191
+ create: 0,
192
+ update: 0,
193
+ payment: 0
194
+ };
195
+ if ((context.senderState ? context.senderState.address : context.tx.from) === (context.receiverState ? context.receiverState.address : context.itx.receiver)) {
196
+ Object.defineProperty(context, "txBaseGas", { value: false });
197
+ return result;
198
+ }
199
+ if (context.senderState) result.update += 1;
200
+ else result.create += 1;
201
+ if (context.stakeState) result.update += 1;
202
+ else result.create += 1;
203
+ if (context.signerStates) result.update += context.signerStates.length;
204
+ if (context.assetStates) result.update += context.assetStates.length;
205
+ return result;
206
+ }));
207
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
208
+ runner.use(pipes.TakeStateSnapshot());
209
+ runner.use(async (context, next) => {
210
+ const { tx: tx$1, itx, inputs = [], statedb, senderState, senderChange, stakeState, signerStates = [], updateVaults, assetStates = [] } = context;
211
+ const signerUpdates = {};
212
+ const stakeUpdates = stakeState ? {
213
+ tokens: stakeState.tokens,
214
+ assets: stakeState.assets || [],
215
+ data: itx.data
216
+ } : {
217
+ tokens: {},
218
+ assets: [],
219
+ data: itx.data
220
+ };
221
+ inputs.forEach((x) => {
222
+ const { owner } = x;
223
+ const tokensList = getListField(x, "tokens");
224
+ const assetsList = getListField(x, "assets");
225
+ signerUpdates[owner] = applyTokenUpdates(tokensList, signerStates.find((s) => s.address === owner), "sub");
226
+ if (senderChange && owner === senderChange.address) signerUpdates[owner] = applyTokenChange(signerUpdates[owner], senderChange);
227
+ Object.assign(stakeUpdates, applyTokenUpdates(tokensList, stakeUpdates, "add"));
228
+ stakeUpdates.assets.push(...assetsList);
229
+ });
230
+ const isAlsoSigner = !!signerUpdates[tx$1.from];
231
+ const [newSenderState, newSignerStates, newStakeState, newAssetStates] = await Promise.all([
232
+ statedb.account.updateOrCreate(senderState ?? null, account.updateOrCreate(senderState ?? null, Object.assign({
233
+ address: tx$1.from,
234
+ nonce: tx$1.nonce,
235
+ pk: tx$1.pk
236
+ }, signerUpdates[tx$1.from] || (senderChange ? applyTokenChange(senderState ?? {}, senderChange) : {})), context), context),
237
+ Promise.all(signerStates.filter((x) => x.address !== tx$1.from).map((x) => statedb.account.update(x.address, account.update(x, signerUpdates[x.address], context), context))),
238
+ stakeState ? statedb.stake.update(stakeState.address, stake.update(stakeState, stakeUpdates, context), context) : statedb.stake.create(itx.address, stake.create({
239
+ sender: tx$1.from,
240
+ revocable: !itx.locked,
241
+ slashers: context.slashers,
242
+ revokeWaitingPeriod: context.revokeWaitingPeriod,
243
+ ...pick(itx, [
244
+ "address",
245
+ "receiver",
246
+ "message",
247
+ "data",
248
+ "nonce"
249
+ ]),
250
+ ...stakeUpdates
251
+ }, context), context),
252
+ Promise.all(assetStates.map((x) => statedb.asset.update(x.address, asset.update(x, { owner: itx.address }, context), context)))
253
+ ]);
254
+ if (updateVaults) await updateVaults();
255
+ context.senderState = newSenderState;
256
+ context.signerStates = isAlsoSigner ? newSignerStates.concat(newSenderState) : newSignerStates;
257
+ context.stakeState = newStakeState;
258
+ context.assetStates = newAssetStates;
259
+ debug("stake", {
260
+ address: itx.address,
261
+ stakeUpdates,
262
+ signerUpdates
263
+ });
264
+ next();
265
+ }, { persistError: true });
266
+ runner.use(pipes.VerifyStateDiff());
267
+ var stake_default = runner;
268
+
269
+ //#endregion
270
+ export { stake_default as default };