@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,4 @@
1
+ //#region src/protocols/token/create.d.ts
2
+ declare const runner: any;
3
+ //#endregion
4
+ export { runner as default };
@@ -0,0 +1,150 @@
1
+ import { decodeAnySafe, getDelegationRequirements } 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 { toTokenAddress } from "@arcblock/did-util";
7
+ import { account, delegation, token } from "@ocap/state";
8
+ import { fromTokenToUnit } from "@ocap/util";
9
+ import Debug from "debug";
10
+ import cloneDeep from "lodash/cloneDeep.js";
11
+ import { Joi, schemas } from "@arcblock/validator";
12
+ import uniq from "lodash/uniq.js";
13
+ import isEmpty from "lodash/isEmpty.js";
14
+
15
+ //#region src/protocols/token/create.ts
16
+ const debug = Debug("@ocap/tx-protocols:create-token");
17
+ const MAX_TOTAL_SUPPLY = fromTokenToUnit(1e4 * 1e8, 18);
18
+ const runner = new Runner("create_token");
19
+ runner.use(pipes.VerifyMultiSig(0));
20
+ const schema = Joi.object({
21
+ address: Joi.DID().prefix().role("ROLE_TOKEN").required(),
22
+ name: Joi.string().min(1).max(32).required(),
23
+ description: Joi.string().min(16).max(128).required(),
24
+ symbol: Joi.string().min(2).max(6).uppercase().required(),
25
+ unit: Joi.string().min(1).max(6).lowercase().required(),
26
+ decimal: Joi.number().min(2).max(18).required(),
27
+ icon: Joi.string().optional().allow(null).valid(""),
28
+ totalSupply: Joi.BN().greater(0).max(MAX_TOTAL_SUPPLY).required(),
29
+ initialSupply: Joi.BN().greater(0).max(Joi.ref("totalSupply")).required(),
30
+ maxTotalSupply: Joi.alternatives().try(Joi.BN().greater(0).max(Joi.ref("totalSupply")), Joi.string().valid("")).optional().allow(null),
31
+ foreignToken: schemas.foreignToken.optional().allow(null).default(null),
32
+ spendersList: Joi.array().items(Joi.DID().prefix()).max(30).optional().allow(null).default(null),
33
+ tokenFactoryAddress: Joi.forbidden(),
34
+ data: Joi.any().optional().allow(null)
35
+ }).options({
36
+ stripUnknown: true,
37
+ noDefaults: false
38
+ });
39
+ runner.use(({ itx }, next) => {
40
+ const { error, value } = schema.validate(itx);
41
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
42
+ const spendersList = value.spendersList;
43
+ itx.spenders = spendersList?.length ? uniq(spendersList) : null;
44
+ delete itx.spendersList;
45
+ return next();
46
+ });
47
+ runner.use(pipes.VerifyInfo([{
48
+ error: "INVALID_TOKEN",
49
+ message: "Token address is not valid",
50
+ fn: (ctx) => {
51
+ const context = ctx;
52
+ const itx = cloneDeep(context.itx);
53
+ itx.data = decodeAnySafe(itx.data ?? null);
54
+ itx.address = "";
55
+ return toTokenAddress(itx) === context.itx.address;
56
+ }
57
+ }]));
58
+ runner.use(pipes.ExtractState({
59
+ from: "tx.from",
60
+ to: "senderState",
61
+ status: "INVALID_SENDER_STATE",
62
+ table: "account"
63
+ }));
64
+ runner.use(pipes.VerifyAccountMigration({
65
+ stateKey: "senderState",
66
+ addressKey: "tx.from"
67
+ }));
68
+ runner.use(pipes.ExtractState({
69
+ from: "tx.delegator",
70
+ to: "delegatorState",
71
+ status: "OK",
72
+ table: "account"
73
+ }));
74
+ runner.use(pipes.VerifyAccountMigration({
75
+ stateKey: "delegatorState",
76
+ addressKey: "tx.delegator"
77
+ }));
78
+ runner.use(pipes.VerifyDelegation({
79
+ type: "signature",
80
+ signerKey: "senderState",
81
+ delegatorKey: "delegatorState",
82
+ getRequirements: getDelegationRequirements
83
+ }));
84
+ runner.use(pipes.ExtractState({
85
+ from: "itx.address",
86
+ to: "tokenState",
87
+ table: "token",
88
+ status: "OK"
89
+ }));
90
+ runner.use(pipes.VerifyInfo([{
91
+ error: "DUPLICATE_TOKEN",
92
+ message: "Token address already exists on chain",
93
+ fn: (ctx) => isEmpty(ctx.tokenState)
94
+ }]));
95
+ runner.use(async function EnsureTokenSymbol(context, next) {
96
+ const { symbol } = context.config.token;
97
+ if (symbol.toLowerCase() === context.itx.symbol.toLowerCase()) return next(new CustomError("DUPLICATE_SYMBOL", `Token symbol can not be ${symbol}`));
98
+ if (await context.statedb.token.existBySymbol(context.itx.symbol, context)) return next(new CustomError("DUPLICATE_SYMBOL", "Token symbol already exists"));
99
+ return next();
100
+ }, { persistError: true });
101
+ runner.use(ensure_gas_default((context) => {
102
+ const result = {
103
+ create: 1,
104
+ update: 2,
105
+ payment: 0
106
+ };
107
+ if (context.delegatorState) result.update += 1;
108
+ return result;
109
+ }));
110
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
111
+ runner.use(pipes.TakeStateSnapshot());
112
+ runner.use(async (context, next) => {
113
+ const { tx: tx$1, itx, statedb, senderState, delegatorState, delegationState, senderUpdates, updateVaults } = context;
114
+ const data = decodeAnySafe(itx.data ?? null);
115
+ const owner = delegatorState ? delegatorState.address : senderState.address;
116
+ const delegatorUpdates = {};
117
+ const updates = senderUpdates;
118
+ updates.tokens = updates.tokens || senderState.tokens || {};
119
+ if (delegatorState) {
120
+ delegatorUpdates.tokens = delegatorState.tokens || {};
121
+ delegatorUpdates.tokens[itx.address] = itx.initialSupply;
122
+ } else updates.tokens[itx.address] = itx.initialSupply;
123
+ const [newSenderState, tokenState, newDelegatorState, newDelegationState] = await Promise.all([
124
+ statedb.account.update(senderState.address, account.update(senderState, {
125
+ nonce: tx$1.nonce,
126
+ pk: tx$1.pk,
127
+ ...senderUpdates
128
+ }, context), context),
129
+ statedb.token.create(itx.address, token.create({
130
+ ...cloneDeep(itx),
131
+ data,
132
+ issuer: owner,
133
+ type: "Token"
134
+ }, context), context),
135
+ delegatorState ? statedb.account.update(delegatorState.address, account.update(delegatorState, delegatorUpdates, context), context) : null,
136
+ context.isDelegationChanged ? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context) : delegationState
137
+ ]);
138
+ if (updateVaults) await updateVaults();
139
+ context.senderState = newSenderState;
140
+ context.tokenState = tokenState;
141
+ context.delegatorState = newDelegatorState ?? void 0;
142
+ context.delegationState = newDelegationState ?? void 0;
143
+ debug("create token v2", tokenState);
144
+ next();
145
+ }, { persistError: true });
146
+ runner.use(pipes.VerifyStateDiff());
147
+ var create_default = runner;
148
+
149
+ //#endregion
150
+ export { create_default as default };
@@ -0,0 +1,11 @@
1
+ //#region src/protocols/token/deposit-v2.d.ts
2
+ /** Token change for updates */
3
+ interface TokenChange {
4
+ address: string;
5
+ token: string;
6
+ delta: string;
7
+ action: string;
8
+ }
9
+ declare const runner: any;
10
+ //#endregion
11
+ export { TokenChange, runner as default };
@@ -0,0 +1,216 @@
1
+ import { applyTokenChange, applyTokenUpdates, getBNSum, getRewardLocker, getTxFee } 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 verify_signers_default from "../rollup/pipes/verify-signers.mjs";
5
+ import verify_status_default from "../rollup/pipes/verify-status.mjs";
6
+ import { Runner, pipes } from "@ocap/tx-pipeline";
7
+ import { CustomError } from "@ocap/util/lib/error";
8
+ import { toStakeAddress } from "@arcblock/did-util";
9
+ import { account, evidence, stake } from "@ocap/state";
10
+ import { BN, fromUnitToToken } from "@ocap/util";
11
+ import Debug from "debug";
12
+ import { getListField } from "@ocap/util/lib/get-list-field";
13
+ import { Joi, patterns, schemas } from "@arcblock/validator";
14
+
15
+ //#region src/protocols/token/deposit-v2.ts
16
+ const debug = Debug("@ocap/tx-protocols:deposit-token");
17
+ const schema = Joi.object({
18
+ token: schemas.tokenInput.required(),
19
+ to: Joi.DID().prefix().wallet("ethereum").required(),
20
+ proposer: Joi.DID().prefix().wallet("ethereum").required(),
21
+ evidence: Joi.object({ hash: Joi.string().regex(patterns.txHash).required() }).required(),
22
+ rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
23
+ actualFee: Joi.BN().min(0).required(),
24
+ data: Joi.any().optional().allow(null)
25
+ }).options({
26
+ stripUnknown: true,
27
+ noDefaults: false
28
+ });
29
+ const runner = new Runner("deposit_token_v2");
30
+ runner.use(({ tx: tx$1, itx }, next) => {
31
+ const { error } = schema.validate(itx);
32
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
33
+ if (itx.to !== tx$1.from) return next(new CustomError("INVALID_TX", "You can only deposit to tx sender account"));
34
+ const signatures = getListField(tx$1, "signatures");
35
+ if (signatures.some((x) => x.signer === itx.proposer) === false) return next(new CustomError("INVALID_TX", "itx.proposer must exist in signatures"));
36
+ if (signatures.some((x) => x.signer === tx$1.from)) return next(new CustomError("INVALID_TX", "tx.from should not exist in signatures"));
37
+ return next();
38
+ });
39
+ runner.use(pipes.ExtractState({
40
+ from: "itx.rollup",
41
+ to: "rollupState",
42
+ status: "INVALID_ROLLUP",
43
+ table: "rollup"
44
+ }));
45
+ runner.use(verify_status_default({ paused: false }));
46
+ runner.use((context, next) => {
47
+ const { itx, rollupState } = context;
48
+ if (rollupState.tokenAddress !== itx.token.address) return next(new CustomError("INVALID_TX", "Deposit token address does not match with rollup state"));
49
+ if (rollupState.validators.some((x) => x.address === itx.proposer) === false) return next(new CustomError("INVALID_TX", "itx.proposer does not exist in validators"));
50
+ return next();
51
+ });
52
+ runner.use(pipes.ExtractState({
53
+ from: "itx.evidence.hash",
54
+ to: "evidenceState",
55
+ status: "OK",
56
+ table: "evidence"
57
+ }));
58
+ runner.use(({ evidenceState }, next) => {
59
+ if (evidenceState) return next(new CustomError("INVALID_TX", "Deposit evidence already seen on this chain"));
60
+ return next();
61
+ });
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: "itx.token.address",
69
+ to: "tokenState",
70
+ status: "INVALID_TOKEN",
71
+ table: "token"
72
+ }));
73
+ runner.use((context, next) => {
74
+ const { itx } = context;
75
+ context.stakeAddress = toStakeAddress(itx.proposer, itx.rollup);
76
+ context.lockerAddress = getRewardLocker(itx.rollup);
77
+ return next();
78
+ });
79
+ runner.use(pipes.ExtractState({
80
+ from: "lockerAddress",
81
+ to: "lockerState",
82
+ status: "OK",
83
+ table: "stake"
84
+ }));
85
+ runner.use(pipes.ExtractState({
86
+ from: "stakeAddress",
87
+ to: "stakeState",
88
+ status: "INVALID_STAKE_STATE",
89
+ table: "stake"
90
+ }));
91
+ runner.use((context, next) => {
92
+ const { itx, stakeState, tokenState, rollupState } = context;
93
+ if (stakeState.revocable === true) return next(new CustomError("INVALID_STAKE_STATE", `Staking not locked for deposit: ${stakeState.address}`));
94
+ const depositAmount = new BN(itx.token.value).add(new BN(itx.actualFee));
95
+ const minDepositAmount = new BN(rollupState.minDepositAmount);
96
+ const maxDepositAmount = new BN(rollupState.maxDepositAmount);
97
+ if (depositAmount.lt(minDepositAmount)) return next(new CustomError("INVALID_TX", `Deposit amount must be greater than minDepositAmount: ${fromUnitToToken(minDepositAmount, tokenState.decimal)}`));
98
+ if (depositAmount.gt(maxDepositAmount)) return next(new CustomError("INVALID_TX", `Deposit amount must be less than maxDepositAmount: ${fromUnitToToken(maxDepositAmount, tokenState.decimal)}`));
99
+ const stakedAmount = new BN(stakeState.tokens[rollupState.tokenAddress] || 0);
100
+ if (depositAmount.gt(stakedAmount)) return next(new CustomError("INSUFFICIENT_STAKE", `Deposit amount must be less than available stake: ${fromUnitToToken(stakedAmount, tokenState.decimal)}`));
101
+ return next();
102
+ });
103
+ runner.use((context, next) => {
104
+ const { itx, rollupState, tokenState } = context;
105
+ const { depositFeeRate, maxDepositFee, minDepositFee } = rollupState;
106
+ const { reward } = getTxFee({
107
+ amount: itx.token.value,
108
+ feeRate: depositFeeRate,
109
+ maxFee: maxDepositFee,
110
+ minFee: minDepositFee
111
+ });
112
+ if (new BN(itx.actualFee).lt(new BN(reward))) return next(new CustomError("INVALID_TX", `itx.actualFee too low, expect at least ${fromUnitToToken(reward, tokenState.decimal)}, got ${fromUnitToToken(itx.actualFee, tokenState.decimal)}`));
113
+ return next();
114
+ });
115
+ runner.use(pipes.ExtractState({
116
+ from: "tx.from",
117
+ to: "senderState",
118
+ status: "OK",
119
+ table: "account"
120
+ }));
121
+ runner.use(pipes.ExtractState({
122
+ from: "signers",
123
+ to: "signerStates",
124
+ status: "INVALID_SIGNER_STATE",
125
+ table: "account"
126
+ }));
127
+ runner.use(pipes.VerifyAccountMigration({
128
+ signerKey: "signerStates",
129
+ stateKey: "senderState",
130
+ addressKey: "tx.from"
131
+ }));
132
+ runner.use(ensure_gas_default((context) => {
133
+ const result = {
134
+ create: 1,
135
+ update: 1,
136
+ payment: 0
137
+ };
138
+ if (context.senderState) result.update += 1;
139
+ else result.create += 1;
140
+ if (context.lockerState) result.update += 1;
141
+ else result.create += 1;
142
+ return result;
143
+ }));
144
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
145
+ runner.use(pipes.TakeStateSnapshot());
146
+ runner.use(async (context, next) => {
147
+ const { tx: tx$1, itx, statedb, senderState, stakeState, stakeAddress, lockerState, lockerAddress, senderChange, updateVaults } = context;
148
+ const user = itx.token.value;
149
+ const fee = itx.actualFee;
150
+ const total = getBNSum(user, fee);
151
+ const stakeUpdates = applyTokenUpdates([{
152
+ address: itx.token.address,
153
+ value: total
154
+ }], stakeState, "sub");
155
+ let senderUpdates = applyTokenUpdates([{
156
+ address: itx.token.address,
157
+ value: user
158
+ }], senderState || {}, "add");
159
+ const lockerUpdates = applyTokenUpdates([{
160
+ address: itx.token.address,
161
+ value: fee
162
+ }], lockerState || { tokens: {} }, "add");
163
+ if (senderChange && senderState) senderUpdates = applyTokenChange(senderUpdates, senderChange);
164
+ const sender = senderState ? senderState.address : tx$1.from;
165
+ const [newSenderState, newStakeState, newLockerState, evidenceState] = await Promise.all([
166
+ statedb.account.updateOrCreate(senderState ?? null, account.updateOrCreate(senderState ?? null, {
167
+ address: sender,
168
+ nonce: tx$1.nonce,
169
+ pk: tx$1.pk,
170
+ ...senderUpdates
171
+ }, context), context),
172
+ statedb.stake.update(stakeAddress, stake.update(stakeState, stakeUpdates, context), context),
173
+ lockerState ? statedb.stake.update(lockerState.address, stake.update(lockerState, lockerUpdates, context), context) : statedb.stake.create(lockerAddress, stake.create({
174
+ address: lockerAddress,
175
+ sender: itx.rollup,
176
+ receiver: itx.rollup,
177
+ revocable: false,
178
+ message: "pending-block-reward",
179
+ revokeWaitingPeriod: 0,
180
+ ...lockerUpdates
181
+ }, context), context),
182
+ statedb.evidence.create(itx.evidence.hash, evidence.create({
183
+ hash: itx.evidence.hash,
184
+ data: "rollup-deposit"
185
+ }, context), context)
186
+ ]);
187
+ if (updateVaults) await updateVaults();
188
+ context.senderState = newSenderState;
189
+ context.stakeState = newStakeState;
190
+ context.evidenceState = evidenceState;
191
+ context.stakeStates = [newStakeState, newLockerState];
192
+ context.updatedAccounts = context.updatedAccounts || [];
193
+ context.updatedAccounts.push({
194
+ address: stakeAddress,
195
+ token: itx.token.address,
196
+ delta: `-${total}`,
197
+ action: "unlock"
198
+ }, {
199
+ address: sender,
200
+ token: itx.token.address,
201
+ delta: user,
202
+ action: "unlock"
203
+ }, {
204
+ address: lockerAddress,
205
+ token: itx.token.address,
206
+ delta: fee,
207
+ action: "pending"
208
+ });
209
+ debug("deposit-token-v2", itx);
210
+ next();
211
+ }, { persistError: true });
212
+ runner.use(pipes.VerifyStateDiff());
213
+ var deposit_v2_default = runner;
214
+
215
+ //#endregion
216
+ export { deposit_v2_default as default };
@@ -0,0 +1,9 @@
1
+ //#region src/protocols/token/withdraw-v2.d.ts
2
+ /** Token input */
3
+ interface TokenInput {
4
+ address: string;
5
+ value: string;
6
+ }
7
+ declare const runner: any;
8
+ //#endregion
9
+ export { TokenInput, runner as default };
@@ -0,0 +1,222 @@
1
+ import { applyTokenChange, applyTokenUpdates, getBNSum, getRewardLocker, getTxFee } 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 verify_status_default from "../rollup/pipes/verify-status.mjs";
5
+ import { Runner, pipes } from "@ocap/tx-pipeline";
6
+ import { CustomError } from "@ocap/util/lib/error";
7
+ import { toStakeAddress } from "@arcblock/did-util";
8
+ import { account, stake } from "@ocap/state";
9
+ import { BN, fromUnitToToken } 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
+
14
+ //#region src/protocols/token/withdraw-v2.ts
15
+ const debug = Debug("@ocap/tx-protocols:withdraw-token");
16
+ const verifyMultiSigV2 = pipes.VerifyMultiSigV2({ signersKey: "signers" });
17
+ const schema = Joi.object({
18
+ token: schemas.tokenInput.required(),
19
+ to: Joi.DID().prefix().wallet("ethereum").required(),
20
+ rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
21
+ proposer: Joi.DID().prefix().wallet("ethereum").optional().allow(null).allow("").default(""),
22
+ actualFee: Joi.BN().min(0).required(),
23
+ maxFee: Joi.BN().min(0).required(),
24
+ data: Joi.any().optional().allow(null)
25
+ }).options({
26
+ stripUnknown: true,
27
+ noDefaults: false
28
+ });
29
+ const runner = new Runner("withdraw_token_v2");
30
+ runner.use(({ tx: tx$1, itx }, next) => {
31
+ const { error } = schema.validate(itx);
32
+ if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
33
+ if (itx.to !== tx$1.from) return next(new CustomError("INVALID_TX", "You can only withdraw to tx sender account"));
34
+ return next();
35
+ });
36
+ runner.use(pipes.ExtractState({
37
+ from: "itx.rollup",
38
+ to: "rollupState",
39
+ status: "INVALID_ROLLUP",
40
+ table: "rollup"
41
+ }));
42
+ runner.use(verify_status_default({ paused: false }));
43
+ runner.use((context, next) => {
44
+ const { itx, rollupState } = context;
45
+ if (rollupState.tokenAddress !== itx.token.address) return next(new CustomError("INVALID_TX", "Withdraw token address does not match with rollup"));
46
+ return next();
47
+ });
48
+ runner.use(pipes.ExtractState({
49
+ from: "itx.token.address",
50
+ to: "tokenState",
51
+ status: "INVALID_TOKEN",
52
+ table: "token"
53
+ }));
54
+ runner.use(pipes.ExtractState({
55
+ from: "tx.from",
56
+ to: "senderState",
57
+ status: "INVALID_SENDER_STATE",
58
+ table: "account"
59
+ }));
60
+ runner.use((context, next) => {
61
+ const { tx: tx$1, itx, tokenState, rollupState } = context;
62
+ const withdrawAmount = new BN(itx.token.value);
63
+ const minWithdrawAmount = new BN(rollupState.minWithdrawAmount);
64
+ const maxWithdrawAmount = new BN(rollupState.maxWithdrawAmount);
65
+ if (withdrawAmount.lt(minWithdrawAmount)) return next(new CustomError("INVALID_TX", `Withdraw amount must be greater than: ${fromUnitToToken(minWithdrawAmount, tokenState.decimal)}`));
66
+ if (withdrawAmount.gt(maxWithdrawAmount)) return next(new CustomError("INVALID_TX", `Withdraw amount must be less than maxWithdrawAmount: ${fromUnitToToken(maxWithdrawAmount, tokenState.decimal)}`));
67
+ const maxAmount = getBNSum(itx.token.value, itx.actualFee, itx.maxFee);
68
+ context.tokenConditions = {
69
+ owner: tx$1.from,
70
+ tokens: [{
71
+ address: itx.token.address,
72
+ value: maxAmount
73
+ }]
74
+ };
75
+ return next();
76
+ });
77
+ runner.use(pipes.VerifyTokenBalance({
78
+ ownerKey: "senderState",
79
+ conditionKey: "tokenConditions"
80
+ }));
81
+ runner.use((context, next) => {
82
+ const { itx, rollupState, tokenState } = context;
83
+ const { withdrawFeeRate, maxWithdrawFee, minWithdrawFee } = rollupState;
84
+ if (new BN(itx.maxFee).isZero()) {
85
+ const { reward } = getTxFee({
86
+ amount: itx.token.value,
87
+ feeRate: withdrawFeeRate,
88
+ maxFee: maxWithdrawFee,
89
+ minFee: minWithdrawFee
90
+ });
91
+ if (new BN(itx.actualFee).lt(new BN(reward))) return next(new CustomError("INVALID_TX", `itx.actualFee too low, expect at least ${fromUnitToToken(reward, tokenState.decimal)}, got ${fromUnitToToken(itx.actualFee, tokenState.decimal)}`));
92
+ }
93
+ return next();
94
+ });
95
+ runner.use((context, next) => {
96
+ const { tx: tx$1, itx } = context;
97
+ if (new BN(itx.maxFee).isZero()) return next();
98
+ const signatures = getListField(tx$1, "signatures");
99
+ if (signatures.length !== 1) return next(new CustomError("INVALID_TX", "Withdraw with maxFee should have one multi-sig"));
100
+ if (signatures.some((x) => x.signer === itx.proposer) === false) return next(new CustomError("INVALID_TX", "itx.proposer must exist in tx.signatures"));
101
+ context.signers = signatures.map((x) => x.signer);
102
+ verifyMultiSigV2(context, next);
103
+ });
104
+ runner.use(pipes.ExtractState({
105
+ from: "signers",
106
+ to: "signerStates",
107
+ status: "INVALID_SIGNER_STATE",
108
+ table: "account"
109
+ }));
110
+ runner.use(pipes.VerifyAccountMigration({
111
+ signerKey: "signerStates",
112
+ stateKey: "senderState",
113
+ addressKey: "tx.from"
114
+ }));
115
+ runner.use((context, next) => {
116
+ const { itx, senderState } = context;
117
+ context.stakeAddress = toStakeAddress(senderState.address, itx.rollup);
118
+ context.lockerAddress = getRewardLocker(itx.rollup);
119
+ return next();
120
+ });
121
+ runner.use(pipes.ExtractState({
122
+ from: "lockerAddress",
123
+ to: "lockerState",
124
+ status: "OK",
125
+ table: "stake"
126
+ }));
127
+ runner.use(pipes.ExtractState({
128
+ from: "stakeAddress",
129
+ to: "stakeState",
130
+ status: "OK",
131
+ table: "stake"
132
+ }));
133
+ runner.use((context, next) => {
134
+ const { stakeState } = context;
135
+ if (stakeState && stakeState.revocable === true) return next(new CustomError("INVALID_STAKE_STATE", `Staking not locked for withdraw: ${stakeState.address}`));
136
+ return next();
137
+ });
138
+ runner.use(ensure_gas_default((context) => {
139
+ const result = {
140
+ create: 0,
141
+ update: 1,
142
+ payment: 0
143
+ };
144
+ if (context.stakeState) result.update += 1;
145
+ else result.create += 1;
146
+ if (context.lockerState) result.update += 1;
147
+ else result.create += 1;
148
+ return result;
149
+ }));
150
+ runner.use(ensure_cost_default({ attachSenderChanges: true }));
151
+ runner.use(pipes.TakeStateSnapshot());
152
+ runner.use(async (context, next) => {
153
+ const { tx: tx$1, itx, statedb, stakeState, senderState, lockerState, lockerAddress, stakeAddress, senderChange, updateVaults } = context;
154
+ const total = getBNSum(itx.token.value, itx.actualFee, itx.maxFee);
155
+ const fee = getBNSum(itx.actualFee, itx.maxFee);
156
+ let senderUpdates = applyTokenUpdates([{
157
+ address: itx.token.address,
158
+ value: total
159
+ }], senderState, "sub");
160
+ if (senderChange) senderUpdates = applyTokenChange(senderUpdates, senderChange);
161
+ const stakeUpdates = applyTokenUpdates([{
162
+ address: itx.token.address,
163
+ value: itx.token.value
164
+ }], stakeState || {}, "add");
165
+ const lockerUpdates = applyTokenUpdates([{
166
+ address: itx.token.address,
167
+ value: fee
168
+ }], lockerState || { tokens: {} }, "add");
169
+ const [newSenderState, newStakeState, newLockerState] = await Promise.all([
170
+ statedb.account.update(senderState.address, account.update(senderState, {
171
+ nonce: tx$1.nonce,
172
+ ...senderUpdates
173
+ }, context), context),
174
+ stakeState ? statedb.stake.update(stakeAddress, stake.update(stakeState, stakeUpdates, context), context) : statedb.stake.create(stakeAddress, stake.create({
175
+ address: stakeAddress,
176
+ sender: senderState.address,
177
+ receiver: itx.rollup,
178
+ revocable: false,
179
+ tokens: stakeUpdates.tokens,
180
+ message: "withdraw-locker",
181
+ assets: []
182
+ }, context), context),
183
+ lockerState ? statedb.stake.update(lockerState.address, stake.update(lockerState, lockerUpdates, context), context) : statedb.stake.create(lockerAddress, stake.create({
184
+ address: lockerAddress,
185
+ sender: itx.rollup,
186
+ receiver: itx.rollup,
187
+ revocable: false,
188
+ message: "pending-block-reward",
189
+ revokeWaitingPeriod: 0,
190
+ ...lockerUpdates
191
+ }, context), context)
192
+ ]);
193
+ if (updateVaults) await updateVaults();
194
+ context.senderState = newSenderState;
195
+ context.stakeState = newStakeState;
196
+ context.lockerState = newLockerState;
197
+ context.stakeStates = [newStakeState, newLockerState];
198
+ context.updatedAccounts = context.updatedAccounts || [];
199
+ context.updatedAccounts.push({
200
+ address: senderState.address,
201
+ token: itx.token.address,
202
+ delta: `-${total}`,
203
+ action: "lock"
204
+ }, {
205
+ address: stakeAddress,
206
+ token: itx.token.address,
207
+ delta: itx.token.value,
208
+ action: "lock"
209
+ }, {
210
+ address: lockerAddress,
211
+ token: itx.token.address,
212
+ delta: fee,
213
+ action: "pending"
214
+ });
215
+ debug("withdraw-token-v2", itx);
216
+ next();
217
+ }, { persistError: true });
218
+ runner.use(pipes.VerifyStateDiff());
219
+ var withdraw_v2_default = runner;
220
+
221
+ //#endregion
222
+ export { withdraw_v2_default as default };
@@ -0,0 +1,15 @@
1
+ //#region src/protocols/token-factory/burn.d.ts
2
+ /** Token input type */
3
+ interface TokenInput {
4
+ address: string;
5
+ value: string;
6
+ }
7
+ /** Multi-input type */
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 };