@ocap/tx-protocols 1.28.9 → 1.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/esm/execute.d.mts +53 -0
  2. package/esm/execute.mjs +225 -0
  3. package/esm/index.d.mts +95 -0
  4. package/esm/index.mjs +100 -0
  5. package/esm/pipes/ensure-cost.d.mts +18 -0
  6. package/esm/pipes/ensure-cost.mjs +136 -0
  7. package/esm/pipes/ensure-gas.d.mts +14 -0
  8. package/esm/pipes/ensure-gas.mjs +38 -0
  9. package/esm/protocols/account/delegate.d.mts +4 -0
  10. package/esm/protocols/account/delegate.mjs +195 -0
  11. package/esm/protocols/account/migrate.d.mts +4 -0
  12. package/esm/protocols/account/migrate.mjs +130 -0
  13. package/esm/protocols/account/revoke-delegate.d.mts +4 -0
  14. package/esm/protocols/account/revoke-delegate.mjs +102 -0
  15. package/esm/protocols/asset/acquire-v2.d.mts +9 -0
  16. package/esm/protocols/asset/acquire-v2.mjs +213 -0
  17. package/esm/protocols/asset/acquire-v3.d.mts +17 -0
  18. package/esm/protocols/asset/acquire-v3.mjs +265 -0
  19. package/esm/protocols/asset/calls/transfer-token.d.mts +4 -0
  20. package/esm/protocols/asset/calls/transfer-token.mjs +36 -0
  21. package/esm/protocols/asset/calls/transfer.d.mts +4 -0
  22. package/esm/protocols/asset/calls/transfer.mjs +32 -0
  23. package/esm/protocols/asset/consume.d.mts +4 -0
  24. package/esm/protocols/asset/consume.mjs +92 -0
  25. package/esm/protocols/asset/create.d.mts +4 -0
  26. package/esm/protocols/asset/create.mjs +136 -0
  27. package/esm/protocols/asset/mint.d.mts +4 -0
  28. package/esm/protocols/asset/mint.mjs +156 -0
  29. package/esm/protocols/asset/pipes/exec-mint-hook.d.mts +24 -0
  30. package/esm/protocols/asset/pipes/exec-mint-hook.mjs +54 -0
  31. package/esm/protocols/asset/pipes/extract-factory-tokens.d.mts +21 -0
  32. package/esm/protocols/asset/pipes/extract-factory-tokens.mjs +22 -0
  33. package/esm/protocols/asset/pipes/verify-itx-address.d.mts +32 -0
  34. package/esm/protocols/asset/pipes/verify-itx-address.mjs +56 -0
  35. package/esm/protocols/asset/pipes/verify-itx-assets.d.mts +18 -0
  36. package/esm/protocols/asset/pipes/verify-itx-assets.mjs +27 -0
  37. package/esm/protocols/asset/pipes/verify-itx-variables.d.mts +17 -0
  38. package/esm/protocols/asset/pipes/verify-itx-variables.mjs +20 -0
  39. package/esm/protocols/asset/pipes/verify-mint-limit.d.mts +15 -0
  40. package/esm/protocols/asset/pipes/verify-mint-limit.mjs +14 -0
  41. package/esm/protocols/asset/update.d.mts +4 -0
  42. package/esm/protocols/asset/update.mjs +111 -0
  43. package/esm/protocols/factory/create.d.mts +29 -0
  44. package/esm/protocols/factory/create.mjs +155 -0
  45. package/esm/protocols/governance/claim-stake.d.mts +27 -0
  46. package/esm/protocols/governance/claim-stake.mjs +220 -0
  47. package/esm/protocols/governance/return-stake.d.mts +27 -0
  48. package/esm/protocols/governance/return-stake.mjs +211 -0
  49. package/esm/protocols/governance/revoke-stake.d.mts +27 -0
  50. package/esm/protocols/governance/revoke-stake.mjs +178 -0
  51. package/esm/protocols/governance/slash-stake.d.mts +17 -0
  52. package/esm/protocols/governance/slash-stake.mjs +213 -0
  53. package/esm/protocols/governance/stake.d.mts +15 -0
  54. package/esm/protocols/governance/stake.mjs +270 -0
  55. package/esm/protocols/rollup/claim-reward.d.mts +11 -0
  56. package/esm/protocols/rollup/claim-reward.mjs +322 -0
  57. package/esm/protocols/rollup/close.d.mts +4 -0
  58. package/esm/protocols/rollup/close.mjs +105 -0
  59. package/esm/protocols/rollup/create-block.d.mts +11 -0
  60. package/esm/protocols/rollup/create-block.mjs +303 -0
  61. package/esm/protocols/rollup/create.d.mts +4 -0
  62. package/esm/protocols/rollup/create.mjs +164 -0
  63. package/esm/protocols/rollup/join.d.mts +4 -0
  64. package/esm/protocols/rollup/join.mjs +152 -0
  65. package/esm/protocols/rollup/leave.d.mts +4 -0
  66. package/esm/protocols/rollup/leave.mjs +137 -0
  67. package/esm/protocols/rollup/migrate.d.mts +4 -0
  68. package/esm/protocols/rollup/migrate.mjs +85 -0
  69. package/esm/protocols/rollup/pause.d.mts +4 -0
  70. package/esm/protocols/rollup/pause.mjs +76 -0
  71. package/esm/protocols/rollup/pipes/ensure-validator.d.mts +6 -0
  72. package/esm/protocols/rollup/pipes/ensure-validator.mjs +12 -0
  73. package/esm/protocols/rollup/pipes/verify-evidence.d.mts +15 -0
  74. package/esm/protocols/rollup/pipes/verify-evidence.mjs +29 -0
  75. package/esm/protocols/rollup/pipes/verify-signers.d.mts +15 -0
  76. package/esm/protocols/rollup/pipes/verify-signers.mjs +36 -0
  77. package/esm/protocols/rollup/pipes/verify-status.d.mts +13 -0
  78. package/esm/protocols/rollup/pipes/verify-status.mjs +26 -0
  79. package/esm/protocols/rollup/resume.d.mts +4 -0
  80. package/esm/protocols/rollup/resume.mjs +79 -0
  81. package/esm/protocols/rollup/update.d.mts +4 -0
  82. package/esm/protocols/rollup/update.mjs +111 -0
  83. package/esm/protocols/token/create.d.mts +4 -0
  84. package/esm/protocols/token/create.mjs +150 -0
  85. package/esm/protocols/token/deposit-v2.d.mts +11 -0
  86. package/esm/protocols/token/deposit-v2.mjs +216 -0
  87. package/esm/protocols/token/withdraw-v2.d.mts +9 -0
  88. package/esm/protocols/token/withdraw-v2.mjs +222 -0
  89. package/esm/protocols/token-factory/burn.d.mts +15 -0
  90. package/esm/protocols/token-factory/burn.mjs +233 -0
  91. package/esm/protocols/token-factory/create.d.mts +4 -0
  92. package/esm/protocols/token-factory/create.mjs +254 -0
  93. package/esm/protocols/token-factory/mint.d.mts +15 -0
  94. package/esm/protocols/token-factory/mint.mjs +234 -0
  95. package/esm/protocols/token-factory/pipes/calc-reserve.d.mts +21 -0
  96. package/esm/protocols/token-factory/pipes/calc-reserve.mjs +34 -0
  97. package/esm/protocols/token-factory/pipes/verify-icon.d.mts +14 -0
  98. package/esm/protocols/token-factory/pipes/verify-icon.mjs +18 -0
  99. package/esm/protocols/token-factory/pipes/verify-ownership.d.mts +12 -0
  100. package/esm/protocols/token-factory/pipes/verify-ownership.mjs +63 -0
  101. package/esm/protocols/token-factory/pipes/verify-url.d.mts +12 -0
  102. package/esm/protocols/token-factory/pipes/verify-url.mjs +26 -0
  103. package/esm/protocols/token-factory/update.d.mts +10 -0
  104. package/esm/protocols/token-factory/update.mjs +152 -0
  105. package/esm/protocols/trade/exchange-v2.d.mts +9 -0
  106. package/esm/protocols/trade/exchange-v2.mjs +239 -0
  107. package/esm/protocols/trade/transfer-v2.d.mts +9 -0
  108. package/esm/protocols/trade/transfer-v2.mjs +226 -0
  109. package/esm/protocols/trade/transfer-v3.d.mts +17 -0
  110. package/esm/protocols/trade/transfer-v3.mjs +270 -0
  111. package/esm/util.d.mts +141 -0
  112. package/esm/util.mjs +278 -0
  113. package/lib/_virtual/rolldown_runtime.cjs +29 -0
  114. package/lib/execute.cjs +231 -0
  115. package/lib/execute.d.cts +53 -0
  116. package/lib/index.cjs +105 -0
  117. package/lib/index.d.cts +95 -0
  118. package/lib/pipes/ensure-cost.cjs +141 -0
  119. package/lib/pipes/ensure-cost.d.cts +18 -0
  120. package/lib/pipes/ensure-gas.cjs +41 -0
  121. package/lib/pipes/ensure-gas.d.cts +14 -0
  122. package/lib/protocols/account/delegate.cjs +201 -0
  123. package/lib/protocols/account/delegate.d.cts +4 -0
  124. package/lib/protocols/account/migrate.cjs +135 -0
  125. package/lib/protocols/account/migrate.d.cts +4 -0
  126. package/lib/protocols/account/revoke-delegate.cjs +107 -0
  127. package/lib/protocols/account/revoke-delegate.d.cts +4 -0
  128. package/lib/protocols/asset/acquire-v2.cjs +216 -0
  129. package/lib/protocols/asset/acquire-v2.d.cts +9 -0
  130. package/lib/protocols/asset/acquire-v3.cjs +269 -0
  131. package/lib/protocols/asset/acquire-v3.d.cts +17 -0
  132. package/lib/protocols/asset/calls/transfer-token.cjs +40 -0
  133. package/lib/protocols/asset/calls/transfer-token.d.cts +4 -0
  134. package/lib/protocols/asset/calls/transfer.cjs +35 -0
  135. package/lib/protocols/asset/calls/transfer.d.cts +4 -0
  136. package/lib/protocols/asset/consume.cjs +95 -0
  137. package/lib/protocols/asset/consume.d.cts +4 -0
  138. package/lib/protocols/asset/create.cjs +140 -0
  139. package/lib/protocols/asset/create.d.cts +4 -0
  140. package/lib/protocols/asset/mint.cjs +159 -0
  141. package/lib/protocols/asset/mint.d.cts +4 -0
  142. package/lib/protocols/asset/pipes/exec-mint-hook.cjs +57 -0
  143. package/lib/protocols/asset/pipes/exec-mint-hook.d.cts +24 -0
  144. package/lib/protocols/asset/pipes/extract-factory-tokens.cjs +25 -0
  145. package/lib/protocols/asset/pipes/extract-factory-tokens.d.cts +21 -0
  146. package/lib/protocols/asset/pipes/verify-itx-address.cjs +59 -0
  147. package/lib/protocols/asset/pipes/verify-itx-address.d.cts +32 -0
  148. package/lib/protocols/asset/pipes/verify-itx-assets.cjs +29 -0
  149. package/lib/protocols/asset/pipes/verify-itx-assets.d.cts +18 -0
  150. package/lib/protocols/asset/pipes/verify-itx-variables.cjs +22 -0
  151. package/lib/protocols/asset/pipes/verify-itx-variables.d.cts +17 -0
  152. package/lib/protocols/asset/pipes/verify-mint-limit.cjs +16 -0
  153. package/lib/protocols/asset/pipes/verify-mint-limit.d.cts +15 -0
  154. package/lib/protocols/asset/update.cjs +114 -0
  155. package/lib/protocols/asset/update.d.cts +4 -0
  156. package/lib/protocols/factory/create.cjs +161 -0
  157. package/lib/protocols/factory/create.d.cts +29 -0
  158. package/lib/protocols/governance/claim-stake.cjs +223 -0
  159. package/lib/protocols/governance/claim-stake.d.cts +27 -0
  160. package/lib/protocols/governance/return-stake.cjs +215 -0
  161. package/lib/protocols/governance/return-stake.d.cts +27 -0
  162. package/lib/protocols/governance/revoke-stake.cjs +182 -0
  163. package/lib/protocols/governance/revoke-stake.d.cts +27 -0
  164. package/lib/protocols/governance/slash-stake.cjs +217 -0
  165. package/lib/protocols/governance/slash-stake.d.cts +17 -0
  166. package/lib/protocols/governance/stake.cjs +275 -0
  167. package/lib/protocols/governance/stake.d.cts +15 -0
  168. package/lib/protocols/rollup/claim-reward.cjs +328 -0
  169. package/lib/protocols/rollup/claim-reward.d.cts +11 -0
  170. package/lib/protocols/rollup/close.cjs +107 -0
  171. package/lib/protocols/rollup/close.d.cts +4 -0
  172. package/lib/protocols/rollup/create-block.cjs +309 -0
  173. package/lib/protocols/rollup/create-block.d.cts +11 -0
  174. package/lib/protocols/rollup/create.cjs +169 -0
  175. package/lib/protocols/rollup/create.d.cts +4 -0
  176. package/lib/protocols/rollup/join.cjs +157 -0
  177. package/lib/protocols/rollup/join.d.cts +4 -0
  178. package/lib/protocols/rollup/leave.cjs +141 -0
  179. package/lib/protocols/rollup/leave.d.cts +4 -0
  180. package/lib/protocols/rollup/migrate.cjs +87 -0
  181. package/lib/protocols/rollup/migrate.d.cts +4 -0
  182. package/lib/protocols/rollup/pause.cjs +78 -0
  183. package/lib/protocols/rollup/pause.d.cts +4 -0
  184. package/lib/protocols/rollup/pipes/ensure-validator.cjs +14 -0
  185. package/lib/protocols/rollup/pipes/ensure-validator.d.cts +6 -0
  186. package/lib/protocols/rollup/pipes/verify-evidence.cjs +32 -0
  187. package/lib/protocols/rollup/pipes/verify-evidence.d.cts +15 -0
  188. package/lib/protocols/rollup/pipes/verify-signers.cjs +39 -0
  189. package/lib/protocols/rollup/pipes/verify-signers.d.cts +15 -0
  190. package/lib/protocols/rollup/pipes/verify-status.cjs +28 -0
  191. package/lib/protocols/rollup/pipes/verify-status.d.cts +13 -0
  192. package/lib/protocols/rollup/resume.cjs +81 -0
  193. package/lib/protocols/rollup/resume.d.cts +4 -0
  194. package/lib/protocols/rollup/update.cjs +114 -0
  195. package/lib/protocols/rollup/update.d.cts +4 -0
  196. package/lib/protocols/token/create.cjs +156 -0
  197. package/lib/protocols/token/create.d.cts +4 -0
  198. package/lib/protocols/token/deposit-v2.cjs +219 -0
  199. package/lib/protocols/token/deposit-v2.d.cts +11 -0
  200. package/lib/protocols/token/withdraw-v2.cjs +225 -0
  201. package/lib/protocols/token/withdraw-v2.d.cts +9 -0
  202. package/lib/protocols/token-factory/burn.cjs +236 -0
  203. package/lib/protocols/token-factory/burn.d.cts +15 -0
  204. package/lib/protocols/token-factory/create.cjs +260 -0
  205. package/lib/protocols/token-factory/create.d.cts +4 -0
  206. package/lib/protocols/token-factory/mint.cjs +237 -0
  207. package/lib/protocols/token-factory/mint.d.cts +15 -0
  208. package/lib/protocols/token-factory/pipes/calc-reserve.cjs +38 -0
  209. package/lib/protocols/token-factory/pipes/calc-reserve.d.cts +21 -0
  210. package/lib/protocols/token-factory/pipes/verify-icon.cjs +22 -0
  211. package/lib/protocols/token-factory/pipes/verify-icon.d.cts +14 -0
  212. package/lib/protocols/token-factory/pipes/verify-ownership.cjs +66 -0
  213. package/lib/protocols/token-factory/pipes/verify-ownership.d.cts +12 -0
  214. package/lib/protocols/token-factory/pipes/verify-url.cjs +29 -0
  215. package/lib/protocols/token-factory/pipes/verify-url.d.cts +12 -0
  216. package/lib/protocols/token-factory/update.cjs +155 -0
  217. package/lib/protocols/token-factory/update.d.cts +10 -0
  218. package/lib/protocols/trade/exchange-v2.cjs +243 -0
  219. package/lib/protocols/trade/exchange-v2.d.cts +9 -0
  220. package/lib/protocols/trade/transfer-v2.cjs +229 -0
  221. package/lib/protocols/trade/transfer-v2.d.cts +9 -0
  222. package/lib/protocols/trade/transfer-v3.cjs +274 -0
  223. package/lib/protocols/trade/transfer-v3.d.cts +17 -0
  224. package/lib/util.cjs +296 -0
  225. package/lib/util.d.cts +141 -0
  226. package/package.json +49 -22
  227. package/tools/fixtures.ts +564 -0
  228. package/lib/execute.js +0 -254
  229. package/lib/index.js +0 -117
  230. package/lib/pipes/ensure-cost.js +0 -193
  231. package/lib/pipes/ensure-gas.js +0 -48
  232. package/lib/protocols/account/delegate.js +0 -223
  233. package/lib/protocols/account/migrate.js +0 -153
  234. package/lib/protocols/account/revoke-delegate.js +0 -110
  235. package/lib/protocols/asset/acquire-v2.js +0 -262
  236. package/lib/protocols/asset/acquire-v3.js +0 -330
  237. package/lib/protocols/asset/calls/README.md +0 -5
  238. package/lib/protocols/asset/calls/transfer-token.js +0 -36
  239. package/lib/protocols/asset/calls/transfer.js +0 -28
  240. package/lib/protocols/asset/consume.js +0 -105
  241. package/lib/protocols/asset/create.js +0 -151
  242. package/lib/protocols/asset/mint.js +0 -199
  243. package/lib/protocols/asset/pipes/exec-mint-hook.js +0 -62
  244. package/lib/protocols/asset/pipes/extract-factory-tokens.js +0 -18
  245. package/lib/protocols/asset/pipes/verify-itx-address.js +0 -54
  246. package/lib/protocols/asset/pipes/verify-itx-assets.js +0 -51
  247. package/lib/protocols/asset/pipes/verify-itx-variables.js +0 -26
  248. package/lib/protocols/asset/pipes/verify-mint-limit.js +0 -13
  249. package/lib/protocols/asset/update.js +0 -131
  250. package/lib/protocols/factory/create.js +0 -191
  251. package/lib/protocols/governance/claim-stake.js +0 -266
  252. package/lib/protocols/governance/return-stake.js +0 -248
  253. package/lib/protocols/governance/revoke-stake.js +0 -172
  254. package/lib/protocols/governance/slash-stake.js +0 -271
  255. package/lib/protocols/governance/stake.js +0 -303
  256. package/lib/protocols/rollup/claim-reward.js +0 -342
  257. package/lib/protocols/rollup/close.js +0 -104
  258. package/lib/protocols/rollup/create-block.js +0 -413
  259. package/lib/protocols/rollup/create.js +0 -197
  260. package/lib/protocols/rollup/join.js +0 -182
  261. package/lib/protocols/rollup/leave.js +0 -145
  262. package/lib/protocols/rollup/migrate.js +0 -85
  263. package/lib/protocols/rollup/pause.js +0 -75
  264. package/lib/protocols/rollup/pipes/ensure-validator.js +0 -12
  265. package/lib/protocols/rollup/pipes/verify-evidence.js +0 -37
  266. package/lib/protocols/rollup/pipes/verify-signers.js +0 -87
  267. package/lib/protocols/rollup/pipes/verify-status.js +0 -30
  268. package/lib/protocols/rollup/resume.js +0 -75
  269. package/lib/protocols/rollup/update.js +0 -122
  270. package/lib/protocols/token/create.js +0 -199
  271. package/lib/protocols/token/deposit-v2.js +0 -290
  272. package/lib/protocols/token/withdraw-v2.js +0 -305
  273. package/lib/protocols/token-factory/burn.js +0 -371
  274. package/lib/protocols/token-factory/create.js +0 -342
  275. package/lib/protocols/token-factory/mint.js +0 -385
  276. package/lib/protocols/token-factory/pipes/calc-reserve.js +0 -37
  277. package/lib/protocols/token-factory/pipes/verify-icon.js +0 -27
  278. package/lib/protocols/token-factory/pipes/verify-ownership.js +0 -93
  279. package/lib/protocols/token-factory/pipes/verify-url.js +0 -32
  280. package/lib/protocols/token-factory/update.js +0 -208
  281. package/lib/protocols/trade/exchange-v2.js +0 -239
  282. package/lib/protocols/trade/transfer-v2.js +0 -233
  283. package/lib/protocols/trade/transfer-v3.js +0 -333
  284. package/lib/util.js +0 -442
@@ -1,37 +0,0 @@
1
- const get = require('lodash/get');
2
- const { CustomError: Error } = require('@ocap/util/lib/error');
3
- const { toHex } = require('@ocap/util');
4
- const { toTypeInfo } = require('@arcblock/did');
5
- const { fromPublicKey } = require('@ocap/wallet');
6
-
7
- module.exports = function CreateVerifyEvidencePipe({ evidenceKey, signaturesKey, verifyMethod = 'verify' }) {
8
- if (['verify', 'ethVerify'].includes(verifyMethod) === false) {
9
- throw new Error(`Invalid verify method: ${verifyMethod}, supported methods are: verify, ethVerify`);
10
- }
11
-
12
- return async (context, next) => {
13
- const evidence = get(context, evidenceKey);
14
- const signatures = get(context, signaturesKey);
15
-
16
- for (const sig of signatures) {
17
- const { signer, pk, delegator, signature } = sig;
18
-
19
- // if delegator is empty, pk and signer shall be a pair
20
- // if delegator is not empty, pk and delegator shall be a pair
21
- const address = delegator || signer;
22
- const wallet = fromPublicKey(pk, toTypeInfo(address));
23
-
24
- try {
25
- if ((await wallet[verifyMethod](toHex(evidence), toHex(signature))) === false) {
26
- return next(new Error('INVALID_SIGNATURE', `Signature for evidence from ${address} is not valid`));
27
- }
28
- } catch (err) {
29
- return next(
30
- new Error('INVALID_SIGNATURE', `Signature for evidence from ${address} verify failed: ${err.message}`)
31
- );
32
- }
33
- }
34
-
35
- return next();
36
- };
37
- };
@@ -1,87 +0,0 @@
1
- const get = require('lodash/get');
2
- const { CustomError: Error } = require('@ocap/util/lib/error');
3
-
4
- module.exports = function CreateVerifySignersPipe({ signersKey, allowSender = true, allowShrink = false }) {
5
- return (context, next) => {
6
- const { tx, rollupState } = context;
7
- const { minSignerCount, maxSignerCount } = rollupState;
8
-
9
- const signatures = get(context, signersKey);
10
- const signerCount = signatures.length;
11
-
12
- const seedValidators = rollupState.seedValidators.map((x) => x.address);
13
- const validators = rollupState.validators.map((x) => x.address);
14
-
15
- // ensure singer blacklist
16
- if (!allowSender && signatures.some((x) => x.signer === tx.from)) {
17
- return next(new Error('INVALID_SIGNATURE', `Invalid: ${signersKey}, sender not allowed to sign`));
18
- }
19
-
20
- // ensure signer count
21
- // If we have a large validators pool, we expect at least minSignerCount signers
22
- if (validators.length > minSignerCount) {
23
- if (signerCount < minSignerCount) {
24
- return next(
25
- new Error(
26
- 'INVALID_SIGNATURE',
27
- `Invalid: ${signersKey}, expect at least ${minSignerCount} signatures, got ${signerCount}`
28
- )
29
- );
30
- }
31
- if (signerCount > maxSignerCount) {
32
- return next(
33
- new Error(
34
- 'INVALID_SIGNATURE',
35
- `Invalid: ${signersKey}, Expect at most ${maxSignerCount} signatures, got ${signerCount}`
36
- )
37
- );
38
- }
39
- } else {
40
- // If we have a small validators pool, eg, the minSignerCount is 3, and we have only 2 validator,
41
- // We expect all validators to sign before we have enough validators
42
- // But on some occasions, we need to shrink the signer requirement, such as a validator want to leave a small validator pool.
43
- let actualValidatorCount = validators.length;
44
- if (!allowSender && allowShrink) {
45
- actualValidatorCount -= 1;
46
- }
47
-
48
- const expectedSignerCount = Math.min(actualValidatorCount, minSignerCount);
49
-
50
- if (signerCount < expectedSignerCount) {
51
- return next(
52
- new Error(
53
- 'INVALID_SIGNATURE',
54
- `Invalid ${signersKey}, all validators are expected to sign because we have less than ${expectedSignerCount} validators`
55
- )
56
- );
57
- }
58
- }
59
-
60
- // ensure seed validators exist
61
- const signers = signatures.map((x) => x.signer);
62
- const missingSigner = seedValidators.find((x) => signers.includes(x) === false);
63
- if (missingSigner) {
64
- return next(
65
- new Error(
66
- 'INVALID_SIGNATURE',
67
- `Invalid: ${signersKey}, missing signature from seed validator: ${missingSigner}`
68
- )
69
- );
70
- }
71
-
72
- // ensure signers exist in validators
73
- const invalidSigner = signers.find((x) => validators.includes(x) === false);
74
- if (invalidSigner) {
75
- return next(
76
- new Error(
77
- 'INVALID_SIGNATURE',
78
- `Invalid: ${signersKey}, signer ${invalidSigner} does not exist in validator whitelist`
79
- )
80
- );
81
- }
82
-
83
- context.signers = signers;
84
-
85
- return next();
86
- };
87
- };
@@ -1,30 +0,0 @@
1
- const { pipes } = require('@ocap/tx-pipeline');
2
-
3
- module.exports = ({ paused, closed } = {}) => {
4
- const fns = [];
5
- if (paused === false) {
6
- fns.push({
7
- error: 'INVALID_TX',
8
- message: 'The rollup is paused',
9
- fn: (context) => !context.rollupState.paused,
10
- });
11
- }
12
-
13
- if (paused === true) {
14
- fns.push({
15
- error: 'INVALID_TX',
16
- message: 'The rollup is not paused',
17
- fn: (context) => context.rollupState.paused,
18
- });
19
- }
20
-
21
- if (closed === false) {
22
- fns.push({
23
- error: 'INVALID_TX',
24
- message: 'The rollup is closed',
25
- fn: (context) => !context.rollupState.closed,
26
- });
27
- }
28
-
29
- return pipes.VerifyInfo(fns);
30
- };
@@ -1,75 +0,0 @@
1
- const { CustomError: Error } = require('@ocap/util/lib/error');
2
- const { Joi } = require('@arcblock/validator');
3
- const { Runner, pipes } = require('@ocap/tx-pipeline');
4
- const { account, rollup } = require('@ocap/state');
5
-
6
- const VerifySigners = require('./pipes/verify-signers');
7
- const VerifyStatus = require('./pipes/verify-status');
8
- const EnsureValidator = require('./pipes/ensure-validator');
9
- const EnsureTxGas = require('../../pipes/ensure-gas');
10
- const EnsureTxCost = require('../../pipes/ensure-cost');
11
-
12
- const runner = new Runner();
13
-
14
- // 1. verify itx
15
- const schema = Joi.object({
16
- rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
17
- data: Joi.any().optional().allow(null),
18
- }).options({ stripUnknown: true, noDefaults: false });
19
- runner.use(({ itx }, next) => {
20
- const { error } = schema.validate(itx);
21
- return next(error ? new Error('INVALID_TX', `Invalid itx: ${error.message}`) : null);
22
- });
23
-
24
- // 2. verify rollup
25
- runner.use(pipes.ExtractState({ from: 'itx.rollup', to: 'rollupState', status: 'INVALID_ROLLUP', table: 'rollup' }));
26
- runner.use(EnsureValidator(true));
27
- runner.use(VerifyStatus({ paused: true, closed: false }));
28
-
29
- // 3. verify tx signers and signatures
30
- runner.use(VerifySigners({ signersKey: 'tx.signaturesList', allowSender: true }));
31
- runner.use(pipes.VerifyMultiSigV2({ signersKey: 'signers' }));
32
-
33
- // 4. verify sender and signer states
34
- runner.use(
35
- pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
36
- );
37
- runner.use(
38
- pipes.ExtractState({ from: 'signers', to: 'signerStates', status: 'INVALID_SIGNER_STATE', table: 'account' })
39
- );
40
- runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', stateKey: 'senderState', addressKey: 'tx.from' }));
41
-
42
- // Ensure tx fee and gas
43
- runner.use(EnsureTxGas(() => ({ create: 0, update: 2, payment: 0 })));
44
- runner.use(EnsureTxCost({ attachSenderChanges: true }));
45
-
46
- // Save context snapshot before updating states
47
- runner.use(pipes.TakeStateSnapshot());
48
-
49
- // 5. update rollup state
50
- runner.use(
51
- async (context, next) => {
52
- const { tx, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
53
-
54
- const [newSenderState, newRollupState] = await Promise.all([
55
- statedb.account.update(
56
- senderState.address,
57
- account.update(senderState, { nonce: tx.nonce, ...senderUpdates }, context),
58
- context
59
- ),
60
- statedb.rollup.update(itx.rollup, rollup.resume(rollupState, context), context),
61
- ]);
62
-
63
- await updateVaults();
64
-
65
- context.senderState = newSenderState;
66
- context.rollupState = newRollupState;
67
-
68
- next();
69
- },
70
- { persistError: true }
71
- );
72
-
73
- runner.use(pipes.VerifyStateDiff());
74
-
75
- module.exports = runner;
@@ -1,122 +0,0 @@
1
- const { CustomError: Error } = require('@ocap/util/lib/error');
2
- const { Joi } = require('@arcblock/validator');
3
- const { Runner, pipes } = require('@ocap/tx-pipeline');
4
- const { account, rollup } = require('@ocap/state');
5
-
6
- const debug = require('debug')(`${require('../../../package.json').name}:update-rollup`);
7
-
8
- const VerifySigners = require('./pipes/verify-signers');
9
- const VerifyStatus = require('./pipes/verify-status');
10
- const EnsureValidator = require('./pipes/ensure-validator');
11
- const EnsureTxGas = require('../../pipes/ensure-gas');
12
- const EnsureTxCost = require('../../pipes/ensure-cost');
13
-
14
- const { decodeAnySafe } = require('../../util');
15
-
16
- const runner = new Runner();
17
-
18
- // 1. verify itx: client must use previous rollup state to construct this itx
19
- const schema = Joi.object({
20
- rollup: Joi.DID().prefix().role('ROLE_ROLLUP').required(),
21
-
22
- minStakeAmount: Joi.BN().greater(0).required(),
23
- maxStakeAmount: Joi.BN().greater(Joi.ref('minStakeAmount')).required(),
24
-
25
- minSignerCount: Joi.number().integer().required(),
26
- maxSignerCount: Joi.number().integer().min(1).max(8).greater(Joi.ref('minSignerCount')).required(),
27
-
28
- minBlockSize: Joi.number().integer().min(1).required(),
29
- maxBlockSize: Joi.number().integer().min(1).max(10).greater(Joi.ref('minBlockSize')).required(),
30
-
31
- minBlockInterval: Joi.number()
32
- .integer()
33
- .min(1)
34
- .max(60 * 60)
35
- .required(),
36
- minBlockConfirmation: Joi.number().integer().min(1).max(100).required(),
37
-
38
- minDepositAmount: Joi.BN().positive().required(),
39
- maxDepositAmount: Joi.BN().greater(Joi.ref('minDepositAmount')).required(),
40
- minWithdrawAmount: Joi.BN().positive().required(),
41
- maxWithdrawAmount: Joi.BN().greater(Joi.ref('minWithdrawAmount')).required(),
42
-
43
- depositFeeRate: Joi.number().integer().min(1).max(10000).required(),
44
- withdrawFeeRate: Joi.number().integer().min(1).max(10000).required(),
45
- publisherFeeShare: Joi.number().integer().min(1).max(10000).required(),
46
- minDepositFee: Joi.BN().positive().required(),
47
- maxDepositFee: Joi.BN().greater(Joi.ref('minDepositFee')).required(),
48
- minWithdrawFee: Joi.BN().positive().required(),
49
- maxWithdrawFee: Joi.BN().greater(Joi.ref('minWithdrawFee')).required(),
50
-
51
- data: Joi.any().optional().allow(null),
52
- }).options({ stripUnknown: true, noDefaults: false });
53
- runner.use(({ itx }, next) => {
54
- const { error } = schema.validate(itx);
55
- return next(error ? new Error('INVALID_TX', `Invalid itx: ${error.message}`) : null);
56
- });
57
-
58
- runner.use(
59
- pipes.VerifyInfo([
60
- {
61
- error: 'INVALID_TX',
62
- message: 'Sum of itx.proposerFeeShare and itx.publisherFeeShare must be less than 10000',
63
- fn: ({ itx }) => itx.proposerFeeShare + itx.publisherFeeShare < 10000,
64
- },
65
- ])
66
- );
67
-
68
- // 2. verify rollup
69
- runner.use(pipes.ExtractState({ from: 'itx.rollup', to: 'rollupState', status: 'INVALID_ROLLUP', table: 'rollup' }));
70
- runner.use(EnsureValidator(true));
71
- runner.use(VerifyStatus({ paused: false }));
72
-
73
- // 3. verify tx signers and signatures
74
- runner.use(VerifySigners({ signersKey: 'tx.signaturesList', allowSender: true }));
75
- runner.use(pipes.VerifyMultiSigV2({ signersKey: 'signers' }));
76
-
77
- // 4. verify sender and signer states
78
- runner.use(
79
- pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
80
- );
81
- runner.use(
82
- pipes.ExtractState({ from: 'signers', to: 'signerStates', status: 'INVALID_SIGNER_STATE', table: 'account' })
83
- );
84
- runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', stateKey: 'senderState', addressKey: 'tx.from' }));
85
-
86
- // Ensure tx fee and gas
87
- runner.use(EnsureTxGas(() => ({ create: 0, update: 2, payment: 0 })));
88
- runner.use(EnsureTxCost({ attachSenderChanges: true }));
89
-
90
- // Save context snapshot before updating states
91
- runner.use(pipes.TakeStateSnapshot());
92
-
93
- // 5. update rollup state
94
- runner.use(
95
- async (context, next) => {
96
- const { tx, itx, rollupState, statedb, senderState, senderUpdates, updateVaults } = context;
97
- const data = decodeAnySafe(itx.data);
98
-
99
- const [newSenderState, newRollupState] = await Promise.all([
100
- statedb.account.update(
101
- senderState.address,
102
- account.update(senderState, { nonce: tx.nonce, ...senderUpdates }, context),
103
- context
104
- ),
105
- statedb.rollup.update(itx.rollup, rollup.update(rollupState, { ...itx, data }, context), context),
106
- ]);
107
-
108
- await updateVaults();
109
-
110
- context.senderState = newSenderState;
111
- context.rollupState = newRollupState;
112
-
113
- debug('update-rollup', newRollupState);
114
-
115
- next();
116
- },
117
- { persistError: true }
118
- );
119
-
120
- runner.use(pipes.VerifyStateDiff());
121
-
122
- module.exports = runner;
@@ -1,199 +0,0 @@
1
- const isEmpty = require('empty-value');
2
- const cloneDeep = require('lodash/cloneDeep');
3
- const uniq = require('lodash/uniq');
4
- const { Joi, schemas } = require('@arcblock/validator');
5
- const { CustomError: Error } = require('@ocap/util/lib/error');
6
- const { Runner, pipes } = require('@ocap/tx-pipeline');
7
- const { account, token, delegation } = require('@ocap/state');
8
- const { toTokenAddress } = require('@arcblock/did-util');
9
- const { fromTokenToUnit } = require('@ocap/util');
10
-
11
- const debug = require('debug')(`${require('../../../package.json').name}:create-token`);
12
- const { decodeAnySafe, getDelegationRequirements } = require('../../util');
13
-
14
- const EnsureTxGas = require('../../pipes/ensure-gas');
15
- const EnsureTxCost = require('../../pipes/ensure-cost');
16
-
17
- const MAX_TOTAL_SUPPLY = fromTokenToUnit(10000 * 100000000, 18); // 32
18
-
19
- const runner = new Runner();
20
-
21
- runner.use(pipes.VerifyMultiSig(0));
22
-
23
- const schema = Joi.object({
24
- address: Joi.DID().prefix().role('ROLE_TOKEN').required(),
25
- name: Joi.string().min(1).max(32).required(),
26
- description: Joi.string().min(16).max(128).required(),
27
- symbol: Joi.string().min(2).max(6).uppercase().required(),
28
- unit: Joi.string().min(1).max(6).lowercase().required(),
29
- decimal: Joi.number().min(2).max(18).required(),
30
- icon: Joi.string().optional().allow(null).valid(''),
31
- totalSupply: Joi.BN().greater(0).max(MAX_TOTAL_SUPPLY).required(),
32
- initialSupply: Joi.BN().greater(0).max(Joi.ref('totalSupply')).required(),
33
- maxTotalSupply: Joi.alternatives()
34
- .try(Joi.BN().greater(0).max(Joi.ref('totalSupply')), Joi.string().valid(''))
35
- .optional()
36
- .allow(null),
37
- foreignToken: schemas.foreignToken.optional().allow(null).default(null),
38
- spendersList: Joi.array().items(Joi.DID().prefix()).max(30).optional().allow(null).default(null),
39
- tokenFactoryAddress: Joi.forbidden(),
40
- data: Joi.any().optional().allow(null),
41
- }).options({ stripUnknown: true, noDefaults: false });
42
-
43
- // 1. verify itx
44
- runner.use(({ itx }, next) => {
45
- const { error, value } = schema.validate(itx);
46
- if (error) {
47
- return next(new Error('INVALID_TX', `Invalid itx: ${error.message}`));
48
- }
49
-
50
- // convert spendersList to spenders
51
- itx.spenders = value.spendersList?.length ? uniq(value.spendersList) : null;
52
- delete itx.spendersList;
53
-
54
- return next();
55
- });
56
-
57
- runner.use(
58
- pipes.VerifyInfo([
59
- {
60
- error: 'INVALID_TOKEN',
61
- message: 'Token address is not valid',
62
- fn: (context) => {
63
- const itx = cloneDeep(context.itx);
64
- itx.data = decodeAnySafe(itx.data);
65
- itx.address = '';
66
-
67
- return toTokenAddress(itx) === context.itx.address;
68
- },
69
- },
70
- ])
71
- );
72
-
73
- // Ensure sender exist
74
- runner.use(
75
- pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })
76
- );
77
- runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
78
-
79
- // Ensure delegation
80
- runner.use(pipes.ExtractState({ from: 'tx.delegator', to: 'delegatorState', status: 'OK', table: 'account' }));
81
- runner.use(pipes.VerifyAccountMigration({ stateKey: 'delegatorState', addressKey: 'tx.delegator' }));
82
- runner.use(
83
- pipes.VerifyDelegation({
84
- type: 'signature',
85
- signerKey: 'senderState',
86
- delegatorKey: 'delegatorState',
87
- getRequirements: getDelegationRequirements,
88
- })
89
- );
90
-
91
- // Ensure token not exist
92
- runner.use(pipes.ExtractState({ from: 'itx.address', to: 'tokenState', table: 'token', status: 'OK' }));
93
- runner.use(
94
- pipes.VerifyInfo([
95
- {
96
- error: 'DUPLICATE_TOKEN',
97
- message: 'Token address already exists on chain',
98
- fn: (context) => isEmpty(context.tokenState),
99
- },
100
- ])
101
- );
102
-
103
- // Ensure uniqueness of token symbol
104
- runner.use(
105
- async function EnsureTokenSymbol(context, next) {
106
- const { symbol } = context.config.token;
107
- if (symbol.toLowerCase() === context.itx.symbol.toLowerCase()) {
108
- return next(new Error('DUPLICATE_SYMBOL', `Token symbol can not be ${symbol}`));
109
- }
110
-
111
- const exist = await context.statedb.token.existBySymbol(context.itx.symbol, context);
112
- if (exist) {
113
- return next(new Error('DUPLICATE_SYMBOL', 'Token symbol already exists'));
114
- }
115
-
116
- return next();
117
- },
118
- { persistError: true }
119
- );
120
-
121
- // Ensure tx fee and gas
122
- runner.use(
123
- EnsureTxGas((context) => {
124
- const result = { create: 1, update: 2, payment: 0 };
125
- if (context.delegatorState) {
126
- result.update += 1;
127
- }
128
-
129
- return result;
130
- })
131
- );
132
- runner.use(EnsureTxCost({ attachSenderChanges: true }));
133
-
134
- // Save context snapshot before updating states
135
- runner.use(pipes.TakeStateSnapshot());
136
-
137
- // Update sender state, token state
138
- runner.use(
139
- async (context, next) => {
140
- const { tx, itx, statedb, senderState, delegatorState, delegationState, senderUpdates, updateVaults } = context;
141
- const data = decodeAnySafe(itx.data);
142
- const owner = delegatorState ? delegatorState.address : senderState.address;
143
-
144
- const delegatorUpdates = {};
145
- senderUpdates.tokens = senderUpdates.tokens || senderState.tokens;
146
-
147
- // We are definitely creating a different token, so it is safe to set tokens to initial supply
148
- // For delegated create-token, the delegator is the actual token-holder
149
- if (delegatorState) {
150
- delegatorUpdates.tokens = delegatorState.tokens || {};
151
- delegatorUpdates.tokens[itx.address] = itx.initialSupply;
152
- } else {
153
- senderUpdates.tokens[itx.address] = itx.initialSupply;
154
- }
155
-
156
- const [newSenderState, tokenState, newDelegatorState, newDelegationState] = await Promise.all([
157
- statedb.account.update(
158
- senderState.address,
159
- account.update(senderState, { nonce: tx.nonce, pk: tx.pk, ...senderUpdates }, context),
160
- context
161
- ),
162
-
163
- statedb.token.create(
164
- itx.address,
165
- token.create({ ...cloneDeep(itx), data, issuer: owner, type: 'Token' }, context),
166
- context
167
- ),
168
-
169
- delegatorState
170
- ? statedb.account.update(
171
- delegatorState.address,
172
- account.update(delegatorState, delegatorUpdates, context),
173
- context
174
- )
175
- : null,
176
-
177
- // Update delegation state
178
- context.isDelegationChanged
179
- ? statedb.delegation.update(delegationState.address, delegation.update(delegationState, {}, context), context)
180
- : delegationState,
181
- ]);
182
-
183
- await updateVaults();
184
-
185
- context.senderState = newSenderState;
186
- context.tokenState = tokenState;
187
- context.delegatorState = newDelegatorState;
188
- context.delegationState = newDelegationState;
189
-
190
- debug('create token v2', tokenState);
191
-
192
- next();
193
- },
194
- { persistError: true }
195
- );
196
-
197
- runner.use(pipes.VerifyStateDiff());
198
-
199
- module.exports = runner;