@ocap/tx-protocols 1.29.26 → 1.30.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 (78) hide show
  1. package/esm/_virtual/rolldown_runtime.mjs +32 -0
  2. package/esm/node_modules/bn.js/lib/bn.mjs +2551 -0
  3. package/esm/node_modules/valibot/dist/index.mjs +663 -0
  4. package/esm/protocols/account/delegate.mjs +42 -36
  5. package/esm/protocols/account/migrate.mjs +7 -10
  6. package/esm/protocols/account/revoke-delegate.mjs +11 -11
  7. package/esm/protocols/asset/acquire-v2.mjs +19 -13
  8. package/esm/protocols/asset/acquire-v3.mjs +17 -14
  9. package/esm/protocols/asset/consume.mjs +9 -9
  10. package/esm/protocols/asset/create.mjs +2 -1
  11. package/esm/protocols/asset/mint.mjs +19 -13
  12. package/esm/protocols/asset/update.mjs +11 -11
  13. package/esm/protocols/governance/claim-stake.mjs +10 -10
  14. package/esm/protocols/governance/return-stake.mjs +11 -11
  15. package/esm/protocols/governance/revoke-stake.mjs +10 -10
  16. package/esm/protocols/governance/slash-stake.mjs +11 -11
  17. package/esm/protocols/governance/stake.mjs +16 -16
  18. package/esm/protocols/rollup/claim-reward.mjs +21 -18
  19. package/esm/protocols/rollup/close.mjs +16 -13
  20. package/esm/protocols/rollup/create-block.mjs +25 -22
  21. package/esm/protocols/rollup/join.mjs +14 -12
  22. package/esm/protocols/rollup/leave.mjs +12 -11
  23. package/esm/protocols/rollup/migrate.mjs +15 -12
  24. package/esm/protocols/rollup/pause.mjs +9 -9
  25. package/esm/protocols/rollup/resume.mjs +9 -9
  26. package/esm/protocols/rollup/update.mjs +31 -28
  27. package/esm/protocols/token/create.mjs +25 -22
  28. package/esm/protocols/token/deposit-v2.mjs +20 -14
  29. package/esm/protocols/token/withdraw-v2.mjs +20 -14
  30. package/esm/protocols/token-factory/burn.mjs +12 -12
  31. package/esm/protocols/token-factory/create.mjs +45 -37
  32. package/esm/protocols/token-factory/mint.mjs +13 -12
  33. package/esm/protocols/token-factory/update.mjs +21 -21
  34. package/esm/protocols/trade/exchange-v2.mjs +15 -15
  35. package/esm/protocols/trade/transfer-v2.mjs +12 -12
  36. package/esm/protocols/trade/transfer-v3.mjs +7 -10
  37. package/esm/util.d.mts +3 -1
  38. package/esm/util.mjs +16 -1
  39. package/lib/_virtual/rolldown_runtime.cjs +2 -0
  40. package/lib/node_modules/bn.js/lib/bn.cjs +2554 -0
  41. package/lib/node_modules/valibot/dist/index.cjs +683 -0
  42. package/lib/protocols/account/delegate.cjs +41 -35
  43. package/lib/protocols/account/migrate.cjs +6 -9
  44. package/lib/protocols/account/revoke-delegate.cjs +10 -10
  45. package/lib/protocols/asset/acquire-v2.cjs +18 -12
  46. package/lib/protocols/asset/acquire-v3.cjs +16 -13
  47. package/lib/protocols/asset/consume.cjs +8 -8
  48. package/lib/protocols/asset/create.cjs +2 -1
  49. package/lib/protocols/asset/mint.cjs +18 -12
  50. package/lib/protocols/asset/update.cjs +10 -10
  51. package/lib/protocols/governance/claim-stake.cjs +9 -9
  52. package/lib/protocols/governance/return-stake.cjs +10 -10
  53. package/lib/protocols/governance/revoke-stake.cjs +9 -9
  54. package/lib/protocols/governance/slash-stake.cjs +10 -10
  55. package/lib/protocols/governance/stake.cjs +15 -15
  56. package/lib/protocols/rollup/claim-reward.cjs +20 -17
  57. package/lib/protocols/rollup/close.cjs +15 -12
  58. package/lib/protocols/rollup/create-block.cjs +24 -21
  59. package/lib/protocols/rollup/join.cjs +13 -11
  60. package/lib/protocols/rollup/leave.cjs +11 -10
  61. package/lib/protocols/rollup/migrate.cjs +14 -11
  62. package/lib/protocols/rollup/pause.cjs +8 -8
  63. package/lib/protocols/rollup/resume.cjs +8 -8
  64. package/lib/protocols/rollup/update.cjs +29 -27
  65. package/lib/protocols/token/create.cjs +23 -20
  66. package/lib/protocols/token/deposit-v2.cjs +19 -13
  67. package/lib/protocols/token/withdraw-v2.cjs +19 -13
  68. package/lib/protocols/token-factory/burn.cjs +11 -11
  69. package/lib/protocols/token-factory/create.cjs +43 -35
  70. package/lib/protocols/token-factory/mint.cjs +12 -11
  71. package/lib/protocols/token-factory/update.cjs +19 -19
  72. package/lib/protocols/trade/exchange-v2.cjs +14 -14
  73. package/lib/protocols/trade/transfer-v2.cjs +11 -11
  74. package/lib/protocols/trade/transfer-v3.cjs +6 -9
  75. package/lib/util.cjs +17 -0
  76. package/lib/util.d.cts +3 -1
  77. package/package.json +16 -18
  78. package/tools/fixtures.ts +2 -1
@@ -12,26 +12,29 @@ import { BN } from "@ocap/util";
12
12
  import Debug from "debug";
13
13
  import cloneDeep from "lodash/cloneDeep.js";
14
14
  import groupBy from "lodash/groupBy.js";
15
- import { Joi, patterns } from "@arcblock/validator";
15
+ import { patterns, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
16
16
  import uniqBy from "lodash/uniqBy.js";
17
17
 
18
18
  //#region src/protocols/rollup/claim-reward.ts
19
19
  const debug = Debug("@ocap/tx-protocols:claim-block-reward");
20
20
  const runner = new Runner("claim_block_reward");
21
- const schema = Joi.object({
22
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
23
- blockHeight: Joi.number().integer().greater(0).required(),
24
- blockHash: Joi.string().regex(patterns.txHash).required(),
25
- evidence: Joi.object({ hash: Joi.string().regex(patterns.txHash).required() }).required(),
26
- publisher: Joi.DID().prefix().wallet("ethereum").required(),
27
- data: Joi.any().optional().allow(null)
28
- }).options({
29
- stripUnknown: true,
30
- noDefaults: false
31
- });
21
+ const schema = v.pipe(v.object({
22
+ rollup: vDID({
23
+ prefix: true,
24
+ role: "ROLE_ROLLUP"
25
+ }),
26
+ blockHeight: v.pipe(v.number(), v.integer(), v.check((n) => n > 0, "Must be > 0")),
27
+ blockHash: v.pipe(v.string(), v.regex(patterns.txHash)),
28
+ evidence: v.object({ hash: v.pipe(v.string(), v.regex(patterns.txHash)) }),
29
+ publisher: vDID({
30
+ prefix: true,
31
+ wallet: "ethereum"
32
+ }),
33
+ data: v.optional(v.nullable(v.any()))
34
+ }), vStripUnknown());
32
35
  runner.use((context, next) => {
33
36
  const { tx: tx$1, itx } = context;
34
- const { error } = schema.validate(itx);
37
+ const { error } = vValidate(schema, itx);
35
38
  if (error) return next(new CustomError("INVALID_TX", error.message));
36
39
  if (tx$1.from !== itx.publisher) return next(new CustomError("INVALID_TX", "itx.publisher must be same with tx.from"));
37
40
  context.lockerAddress = getRewardLocker(itx.rollup);
@@ -186,8 +189,8 @@ runner.use((context, next) => {
186
189
  const blockSignatures = blockState.signatures;
187
190
  const validators = txSignatures.map((s) => s.signer).concat(blockSignatures.map((s) => s.signer));
188
191
  const validatorShare = validator.div(new BN(validators.length));
189
- validators.forEach((v) => changes.account.push({
190
- address: v,
192
+ validators.forEach((v$1) => changes.account.push({
193
+ address: v$1,
191
194
  delta: validatorShare.toString(10),
192
195
  action: "fee"
193
196
  }));
@@ -206,9 +209,9 @@ runner.use((context, next) => {
206
209
  }, {}),
207
210
  rateBase: new BN(validators.length)
208
211
  });
209
- Object.keys(validatorShares).forEach((v) => changes.account.push({
210
- address: v,
211
- delta: validatorShares[v],
212
+ Object.keys(validatorShares).forEach((v$1) => changes.account.push({
213
+ address: v$1,
214
+ delta: validatorShares[v$1],
212
215
  action: "fee"
213
216
  }));
214
217
  }
@@ -7,24 +7,27 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
7
7
  import { CustomError } from "@ocap/util/lib/error";
8
8
  import { toStakeAddress } from "@arcblock/did-util";
9
9
  import { account, rollup, stake } from "@ocap/state";
10
- import { Joi } from "@arcblock/validator";
10
+ import { v, vBN, vBNPositive, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
11
11
 
12
12
  //#region src/protocols/rollup/close.ts
13
13
  const runner = new Runner("close_rollup");
14
- const schema = Joi.object({
15
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
16
- message: Joi.string().trim().min(1).max(512).required(),
17
- token: Joi.object({
18
- address: Joi.DID().prefix().wallet("ethereum").required(),
19
- value: Joi.BN().positive().required()
14
+ const schema = v.pipe(v.object({
15
+ rollup: vDID({
16
+ prefix: true,
17
+ role: "ROLE_ROLLUP"
20
18
  }),
21
- data: Joi.any().optional().allow(null)
22
- }).options({
23
- stripUnknown: true,
24
- noDefaults: false
25
- });
19
+ message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(512)),
20
+ token: v.optional(v.object({
21
+ address: vDID({
22
+ prefix: true,
23
+ wallet: "ethereum"
24
+ }),
25
+ value: vBN(vBNPositive())
26
+ })),
27
+ data: v.optional(v.nullable(v.any()))
28
+ }), vStripUnknown());
26
29
  runner.use(({ itx }, next) => {
27
- const { error } = schema.validate(itx);
30
+ const { error } = vValidate(schema, itx);
28
31
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
29
32
  });
30
33
  runner.use(pipes.ExtractState({
@@ -14,37 +14,40 @@ import Debug from "debug";
14
14
  import { formatMessage } from "@ocap/message";
15
15
  import { getListField } from "@ocap/util/lib/get-list-field";
16
16
  import cloneDeep from "lodash/cloneDeep.js";
17
- import { Joi, patterns, schemas } from "@arcblock/validator";
17
+ import { patterns, schemas, v, vBN, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
18
18
  import MerkleTree from "@ocap/merkle-tree";
19
19
 
20
20
  //#region src/protocols/rollup/create-block.ts
21
21
  const debug = Debug("@ocap/tx-protocols:create-rollup-block");
22
22
  const runner = new Runner("create_rollup_block");
23
- const schema = Joi.object({
24
- hash: Joi.string().regex(patterns.txHash).required(),
25
- height: Joi.number().integer().greater(0).required(),
26
- merkleRoot: Joi.string().regex(patterns.txHash).required(),
27
- previousHash: Joi.string().when("height", {
28
- is: 1,
29
- then: Joi.string().optional().allow(null).allow(""),
30
- otherwise: Joi.string().regex(patterns.txHash).required()
23
+ const txHashString = v.pipe(v.string(), v.regex(patterns.txHash));
24
+ const schema = v.pipe(v.object({
25
+ hash: txHashString,
26
+ height: v.pipe(v.number(), v.integer(), v.check((n) => n > 0, "Must be greater than 0")),
27
+ merkleRoot: txHashString,
28
+ previousHash: v.optional(v.nullable(v.string())),
29
+ txsHash: txHashString,
30
+ txsList: v.pipe(v.array(txHashString), v.minLength(1)),
31
+ proposer: vDID({
32
+ prefix: true,
33
+ wallet: "ethereum"
31
34
  }),
32
- txsHash: Joi.string().regex(patterns.txHash).required(),
33
- txsList: Joi.array().items(Joi.string().regex(patterns.txHash).required()).min(1).unique().required(),
34
- proposer: Joi.DID().prefix().wallet("ethereum").required(),
35
- signaturesList: schemas.multiSig.min(1).required(),
36
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
37
- minReward: Joi.BN().min(0).required(),
38
- governance: Joi.boolean().default(false),
39
- data: Joi.any().optional().allow(null)
40
- }).options({
41
- stripUnknown: true,
42
- noDefaults: false
43
- });
35
+ signaturesList: v.pipe(schemas.multiSig, v.minLength(1)),
36
+ rollup: vDID({
37
+ prefix: true,
38
+ role: "ROLE_ROLLUP"
39
+ }),
40
+ minReward: vBN(vBNMin(0)),
41
+ governance: v.optional(v.boolean(), false),
42
+ data: v.optional(v.nullable(v.any()))
43
+ }), v.forward(v.check((input) => {
44
+ if (input.height === 1) return true;
45
+ return typeof input.previousHash === "string" && patterns.txHash.test(input.previousHash);
46
+ }, "previousHash must match txHash pattern when height > 1"), ["previousHash"]), vStripUnknown());
44
47
  runner.use((context, next) => {
45
48
  const { tx: tx$1, itx } = context;
46
49
  context.formattedItx = formatMessage("CreateRollupBlockTx", itx);
47
- const { error } = schema.validate(itx);
50
+ const { error } = vValidate(schema, itx);
48
51
  if (error) return next(new CustomError("INVALID_TX", error.message));
49
52
  if (tx$1.from !== itx.proposer) return next(new CustomError("INVALID_TX", "itx.proposer must be same with tx.from"));
50
53
  if (getListField(tx$1, "signatures").some((x) => x.signer === itx.proposer) === false) return next(new CustomError("INVALID_TX", "itx.proposer must exist in signatures"));
@@ -1,8 +1,10 @@
1
+ import { isHttpUrl } from "../../util.mjs";
1
2
  import ensure_cost_default from "../../pipes/ensure-cost.mjs";
2
3
  import ensure_gas_default from "../../pipes/ensure-gas.mjs";
3
4
  import verify_signers_default from "./pipes/verify-signers.mjs";
4
5
  import verify_status_default from "./pipes/verify-status.mjs";
5
6
  import verify_evidence_default from "./pipes/verify-evidence.mjs";
7
+ import { any, check, minLength, nullable, object, optional, pipe, regex, string } from "../../node_modules/valibot/dist/index.mjs";
6
8
  import { Runner, pipes } from "@ocap/tx-pipeline";
7
9
  import { CustomError } from "@ocap/util/lib/error";
8
10
  import { isEthereumDid } from "@arcblock/did";
@@ -10,25 +12,25 @@ import { toStakeAddress } from "@arcblock/did-util";
10
12
  import { account, evidence, rollup, stake } from "@ocap/state";
11
13
  import { BN, toHex } from "@ocap/util";
12
14
  import Debug from "debug";
13
- import { Joi, patterns, schemas } from "@arcblock/validator";
15
+ import { patterns, schemas, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
14
16
  import MerkleTree from "@ocap/merkle-tree";
15
17
  import joinUrl from "url-join";
16
18
 
17
19
  //#region src/protocols/rollup/join.ts
18
20
  const debug = Debug("@ocap/tx-protocols:join-rollup");
19
21
  const runner = new Runner("join_rollup");
20
- const schema = Joi.object({
21
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
22
- endpoint: Joi.string().uri({ scheme: [/https?/] }).required(),
23
- evidence: Joi.object({ hash: Joi.string().regex(patterns.txHash).required() }).required(),
24
- signaturesList: schemas.multiSig.min(1).required(),
25
- data: Joi.any().optional().allow(null)
26
- }).options({
27
- stripUnknown: true,
28
- noDefaults: false
29
- });
22
+ const schema = pipe(object({
23
+ rollup: vDID({
24
+ prefix: true,
25
+ role: "ROLE_ROLLUP"
26
+ }),
27
+ endpoint: pipe(string(), check(isHttpUrl, "Must be a valid HTTP/HTTPS URL")),
28
+ evidence: object({ hash: pipe(string(), regex(patterns.txHash)) }),
29
+ signaturesList: pipe(schemas.multiSig, minLength(1)),
30
+ data: optional(nullable(any()))
31
+ }), vStripUnknown());
30
32
  runner.use(({ itx }, next) => {
31
- const { error } = schema.validate(itx);
33
+ const { error } = vValidate(schema, itx);
32
34
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
33
35
  });
34
36
  runner.use(pipes.ExtractState({
@@ -4,28 +4,29 @@ import ensure_validator_default from "./pipes/ensure-validator.mjs";
4
4
  import verify_signers_default from "./pipes/verify-signers.mjs";
5
5
  import verify_status_default from "./pipes/verify-status.mjs";
6
6
  import verify_evidence_default from "./pipes/verify-evidence.mjs";
7
+ import { any, minLength, nullable, object, optional, pipe, regex, string } from "../../node_modules/valibot/dist/index.mjs";
7
8
  import { Runner, pipes } from "@ocap/tx-pipeline";
8
9
  import { CustomError } from "@ocap/util/lib/error";
9
10
  import { toStakeAddress } from "@arcblock/did-util";
10
11
  import { account, evidence, rollup, stake } from "@ocap/state";
11
12
  import Debug from "debug";
12
- import { Joi, patterns, schemas } from "@arcblock/validator";
13
+ import { patterns, schemas, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
13
14
  import MerkleTree from "@ocap/merkle-tree";
14
15
 
15
16
  //#region src/protocols/rollup/leave.ts
16
17
  const debug = Debug("@ocap/tx-protocols:leave-rollup");
17
18
  const runner = new Runner("leave_rollup");
18
- const schema = Joi.object({
19
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
20
- evidence: Joi.object({ hash: Joi.string().regex(patterns.txHash).required() }).required(),
21
- signaturesList: schemas.multiSig.min(1).required(),
22
- data: Joi.any().optional().allow(null)
23
- }).options({
24
- stripUnknown: true,
25
- noDefaults: false
26
- });
19
+ const schema = pipe(object({
20
+ rollup: vDID({
21
+ prefix: true,
22
+ role: "ROLE_ROLLUP"
23
+ }),
24
+ evidence: object({ hash: pipe(string(), regex(patterns.txHash)) }),
25
+ signaturesList: pipe(schemas.multiSig, minLength(1)),
26
+ data: optional(nullable(any()))
27
+ }), vStripUnknown());
27
28
  runner.use(({ itx }, next) => {
28
- const { error } = schema.validate(itx);
29
+ const { error } = vValidate(schema, itx);
29
30
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
30
31
  });
31
32
  runner.use(pipes.ExtractState({
@@ -6,22 +6,25 @@ import verify_status_default from "./pipes/verify-status.mjs";
6
6
  import { Runner, pipes } from "@ocap/tx-pipeline";
7
7
  import { CustomError } from "@ocap/util/lib/error";
8
8
  import { account, rollup } from "@ocap/state";
9
- import { Joi } from "@arcblock/validator";
9
+ import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
10
 
11
11
  //#region src/protocols/rollup/migrate.ts
12
12
  const runner = new Runner("migrate_rollup");
13
- const schema = Joi.object({
14
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
15
- to: Joi.DID().prefix().wallet("ethereum").required(),
16
- type: Joi.string().trim().valid("vault", "contract").required(),
17
- message: Joi.string().trim().min(1).max(512).required(),
18
- data: Joi.any().optional().allow(null)
19
- }).options({
20
- stripUnknown: true,
21
- noDefaults: false
22
- });
13
+ const schema = v.pipe(v.object({
14
+ rollup: vDID({
15
+ prefix: true,
16
+ role: "ROLE_ROLLUP"
17
+ }),
18
+ to: vDID({
19
+ prefix: true,
20
+ wallet: "ethereum"
21
+ }),
22
+ type: v.pipe(v.string(), v.trim(), v.check((s) => s === "vault" || s === "contract", "Must be vault or contract")),
23
+ message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(512)),
24
+ data: v.optional(v.nullable(v.any()))
25
+ }), vStripUnknown());
23
26
  runner.use(({ itx }, next) => {
24
- const { error } = schema.validate(itx);
27
+ const { error } = vValidate(schema, itx);
25
28
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
26
29
  });
27
30
  runner.use(pipes.ExtractState({
@@ -6,19 +6,19 @@ import verify_status_default from "./pipes/verify-status.mjs";
6
6
  import { Runner, pipes } from "@ocap/tx-pipeline";
7
7
  import { CustomError } from "@ocap/util/lib/error";
8
8
  import { account, rollup } from "@ocap/state";
9
- import { Joi } from "@arcblock/validator";
9
+ import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
10
 
11
11
  //#region src/protocols/rollup/pause.ts
12
12
  const runner = new Runner("pause_rollup");
13
- const schema = Joi.object({
14
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
15
- data: Joi.any().optional().allow(null)
16
- }).options({
17
- stripUnknown: true,
18
- noDefaults: false
19
- });
13
+ const schema = v.pipe(v.object({
14
+ rollup: vDID({
15
+ prefix: true,
16
+ role: "ROLE_ROLLUP"
17
+ }),
18
+ data: v.optional(v.nullable(v.any()))
19
+ }), vStripUnknown());
20
20
  runner.use(({ itx }, next) => {
21
- const { error } = schema.validate(itx);
21
+ const { error } = vValidate(schema, itx);
22
22
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
23
23
  });
24
24
  runner.use(pipes.ExtractState({
@@ -6,19 +6,19 @@ import verify_status_default from "./pipes/verify-status.mjs";
6
6
  import { Runner, pipes } from "@ocap/tx-pipeline";
7
7
  import { CustomError } from "@ocap/util/lib/error";
8
8
  import { account, rollup } from "@ocap/state";
9
- import { Joi } from "@arcblock/validator";
9
+ import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
10
 
11
11
  //#region src/protocols/rollup/resume.ts
12
12
  const runner = new Runner("resume_rollup");
13
- const schema = Joi.object({
14
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
15
- data: Joi.any().optional().allow(null)
16
- }).options({
17
- stripUnknown: true,
18
- noDefaults: false
19
- });
13
+ const schema = v.pipe(v.object({
14
+ rollup: vDID({
15
+ prefix: true,
16
+ role: "ROLE_ROLLUP"
17
+ }),
18
+ data: v.optional(v.nullable(v.any()))
19
+ }), vStripUnknown());
20
20
  runner.use(({ itx }, next) => {
21
- const { error } = schema.validate(itx);
21
+ const { error } = vValidate(schema, itx);
22
22
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
23
23
  });
24
24
  runner.use(pipes.ExtractState({
@@ -1,46 +1,49 @@
1
+ import { __toESM } from "../../_virtual/rolldown_runtime.mjs";
1
2
  import { decodeAnySafe } from "../../util.mjs";
2
3
  import ensure_cost_default from "../../pipes/ensure-cost.mjs";
3
4
  import ensure_gas_default from "../../pipes/ensure-gas.mjs";
4
5
  import ensure_validator_default from "./pipes/ensure-validator.mjs";
5
6
  import verify_signers_default from "./pipes/verify-signers.mjs";
6
7
  import verify_status_default from "./pipes/verify-status.mjs";
8
+ import { require_bn } from "../../node_modules/bn.js/lib/bn.mjs";
7
9
  import { Runner, pipes } from "@ocap/tx-pipeline";
8
10
  import { CustomError } from "@ocap/util/lib/error";
9
11
  import { account, rollup } from "@ocap/state";
10
12
  import Debug from "debug";
11
- import { Joi } from "@arcblock/validator";
13
+ import { v, vBN, vBNGreater, vBNPositive, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
12
14
 
13
15
  //#region src/protocols/rollup/update.ts
16
+ var import_bn = /* @__PURE__ */ __toESM(require_bn(), 1);
14
17
  const debug = Debug("@ocap/tx-protocols:update-rollup");
15
18
  const runner = new Runner("update_rollup");
16
- const schema = Joi.object({
17
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
18
- minStakeAmount: Joi.BN().greater(0).required(),
19
- maxStakeAmount: Joi.BN().greater(Joi.ref("minStakeAmount")).required(),
20
- minSignerCount: Joi.number().integer().required(),
21
- maxSignerCount: Joi.number().integer().min(1).max(8).greater(Joi.ref("minSignerCount")).required(),
22
- minBlockSize: Joi.number().integer().min(1).required(),
23
- maxBlockSize: Joi.number().integer().min(1).max(10).greater(Joi.ref("minBlockSize")).required(),
24
- minBlockInterval: Joi.number().integer().min(1).max(3600).required(),
25
- minBlockConfirmation: Joi.number().integer().min(1).max(100).required(),
26
- minDepositAmount: Joi.BN().positive().required(),
27
- maxDepositAmount: Joi.BN().greater(Joi.ref("minDepositAmount")).required(),
28
- minWithdrawAmount: Joi.BN().positive().required(),
29
- maxWithdrawAmount: Joi.BN().greater(Joi.ref("minWithdrawAmount")).required(),
30
- depositFeeRate: Joi.number().integer().min(1).max(1e4).required(),
31
- withdrawFeeRate: Joi.number().integer().min(1).max(1e4).required(),
32
- publisherFeeShare: Joi.number().integer().min(1).max(1e4).required(),
33
- minDepositFee: Joi.BN().positive().required(),
34
- maxDepositFee: Joi.BN().greater(Joi.ref("minDepositFee")).required(),
35
- minWithdrawFee: Joi.BN().positive().required(),
36
- maxWithdrawFee: Joi.BN().greater(Joi.ref("minWithdrawFee")).required(),
37
- data: Joi.any().optional().allow(null)
38
- }).options({
39
- stripUnknown: true,
40
- noDefaults: false
41
- });
19
+ const schema = v.pipe(v.object({
20
+ rollup: vDID({
21
+ prefix: true,
22
+ role: "ROLE_ROLLUP"
23
+ }),
24
+ minStakeAmount: vBN(vBNGreater(0)),
25
+ maxStakeAmount: vBN(vBNGreater(0)),
26
+ minSignerCount: v.pipe(v.number(), v.integer()),
27
+ maxSignerCount: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(8)),
28
+ minBlockSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
29
+ maxBlockSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(10)),
30
+ minBlockInterval: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(3600)),
31
+ minBlockConfirmation: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100)),
32
+ minDepositAmount: vBN(vBNPositive()),
33
+ maxDepositAmount: vBN(vBNPositive()),
34
+ minWithdrawAmount: vBN(vBNPositive()),
35
+ maxWithdrawAmount: vBN(vBNPositive()),
36
+ depositFeeRate: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
37
+ withdrawFeeRate: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
38
+ publisherFeeShare: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
39
+ minDepositFee: vBN(vBNPositive()),
40
+ maxDepositFee: vBN(vBNPositive()),
41
+ minWithdrawFee: vBN(vBNPositive()),
42
+ maxWithdrawFee: vBN(vBNPositive()),
43
+ data: v.optional(v.nullable(v.any()))
44
+ }), v.forward(v.check((input) => new import_bn.default(input.maxStakeAmount).gt(new import_bn.default(input.minStakeAmount)), "maxStakeAmount must be > minStakeAmount"), ["maxStakeAmount"]), v.forward(v.check((input) => input.maxSignerCount > input.minSignerCount, "maxSignerCount must be > minSignerCount"), ["maxSignerCount"]), v.forward(v.check((input) => input.maxBlockSize > input.minBlockSize, "maxBlockSize must be > minBlockSize"), ["maxBlockSize"]), v.forward(v.check((input) => new import_bn.default(input.maxDepositAmount).gt(new import_bn.default(input.minDepositAmount)), "maxDepositAmount must be > minDepositAmount"), ["maxDepositAmount"]), v.forward(v.check((input) => new import_bn.default(input.maxWithdrawAmount).gt(new import_bn.default(input.minWithdrawAmount)), "maxWithdrawAmount must be > minWithdrawAmount"), ["maxWithdrawAmount"]), v.forward(v.check((input) => new import_bn.default(input.maxDepositFee).gt(new import_bn.default(input.minDepositFee)), "maxDepositFee must be > minDepositFee"), ["maxDepositFee"]), v.forward(v.check((input) => new import_bn.default(input.maxWithdrawFee).gt(new import_bn.default(input.minWithdrawFee)), "maxWithdrawFee must be > minWithdrawFee"), ["maxWithdrawFee"]), vStripUnknown());
42
45
  runner.use(({ itx }, next) => {
43
- const { error } = schema.validate(itx);
46
+ const { error } = vValidate(schema, itx);
44
47
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
45
48
  });
46
49
  runner.use(pipes.VerifyInfo([{
@@ -5,10 +5,10 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
5
5
  import { CustomError } from "@ocap/util/lib/error";
6
6
  import { toTokenAddress } from "@arcblock/did-util";
7
7
  import { account, delegation, token } from "@ocap/state";
8
- import { fromTokenToUnit } from "@ocap/util";
8
+ import { BN, fromTokenToUnit } from "@ocap/util";
9
9
  import Debug from "debug";
10
10
  import cloneDeep from "lodash/cloneDeep.js";
11
- import { Joi, schemas } from "@arcblock/validator";
11
+ import { schemas, v, vBN, vBNGreater, vBNMax, vDID, vForbidden, vStripUnknown, vValidate } from "@arcblock/validator";
12
12
  import uniq from "lodash/uniq.js";
13
13
  import isEmpty from "lodash/isEmpty.js";
14
14
 
@@ -17,27 +17,30 @@ const debug = Debug("@ocap/tx-protocols:create-token");
17
17
  const MAX_TOTAL_SUPPLY = fromTokenToUnit(1e4 * 1e8, 18);
18
18
  const runner = new Runner("create_token");
19
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
- });
20
+ const schema = v.pipe(v.object({
21
+ address: vDID({
22
+ prefix: true,
23
+ role: "ROLE_TOKEN"
24
+ }),
25
+ name: v.pipe(v.string(), v.minLength(1), v.maxLength(32)),
26
+ description: v.pipe(v.string(), v.minLength(16), v.maxLength(128)),
27
+ symbol: v.pipe(v.string(), v.minLength(2), v.maxLength(6), v.toUpperCase()),
28
+ unit: v.pipe(v.string(), v.minLength(1), v.maxLength(6), v.toLowerCase()),
29
+ decimal: v.pipe(v.number(), v.minValue(2), v.maxValue(18)),
30
+ icon: v.optional(v.nullable(v.literal(""))),
31
+ totalSupply: vBN(vBNGreater(0), vBNMax(MAX_TOTAL_SUPPLY)),
32
+ initialSupply: vBN(vBNGreater(0)),
33
+ maxTotalSupply: v.optional(v.nullable(v.union([vBN(vBNGreater(0)), v.literal("")]))),
34
+ foreignToken: v.optional(v.nullable(schemas.foreignToken)),
35
+ spendersList: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(30)))),
36
+ tokenFactoryAddress: v.optional(vForbidden("tokenFactoryAddress is forbidden")),
37
+ data: v.optional(v.nullable(v.any()))
38
+ }), v.forward(v.check((input) => new BN(input.initialSupply).lte(new BN(input.totalSupply)), "initialSupply must be <= totalSupply"), ["initialSupply"]), v.forward(v.check((input) => {
39
+ if (!input.maxTotalSupply || input.maxTotalSupply === "") return true;
40
+ return new BN(input.maxTotalSupply).lte(new BN(input.totalSupply));
41
+ }, "maxTotalSupply must be <= totalSupply"), ["maxTotalSupply"]), vStripUnknown());
39
42
  runner.use(({ itx }, next) => {
40
- const { error, value } = schema.validate(itx);
43
+ const { error, value } = vValidate(schema, itx);
41
44
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
42
45
  const spendersList = value.spendersList;
43
46
  itx.spenders = spendersList?.length ? uniq(spendersList) : null;
@@ -10,25 +10,31 @@ import { account, evidence, stake } from "@ocap/state";
10
10
  import { BN, fromUnitToToken } from "@ocap/util";
11
11
  import Debug from "debug";
12
12
  import { getListField } from "@ocap/util/lib/get-list-field";
13
- import { Joi, patterns, schemas } from "@arcblock/validator";
13
+ import { patterns, schemas, v, vBN, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
14
14
 
15
15
  //#region src/protocols/token/deposit-v2.ts
16
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
- });
17
+ const schema = v.pipe(v.object({
18
+ token: schemas.tokenInput,
19
+ to: vDID({
20
+ prefix: true,
21
+ wallet: "ethereum"
22
+ }),
23
+ proposer: vDID({
24
+ prefix: true,
25
+ wallet: "ethereum"
26
+ }),
27
+ evidence: v.object({ hash: v.pipe(v.string(), v.regex(patterns.txHash)) }),
28
+ rollup: vDID({
29
+ prefix: true,
30
+ role: "ROLE_ROLLUP"
31
+ }),
32
+ actualFee: vBN(vBNMin(0)),
33
+ data: v.optional(v.nullable(v.any()))
34
+ }), vStripUnknown());
29
35
  const runner = new Runner("deposit_token_v2");
30
36
  runner.use(({ tx: tx$1, itx }, next) => {
31
- const { error } = schema.validate(itx);
37
+ const { error } = vValidate(schema, itx);
32
38
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
33
39
  if (itx.to !== tx$1.from) return next(new CustomError("INVALID_TX", "You can only deposit to tx sender account"));
34
40
  const signatures = getListField(tx$1, "signatures");
@@ -9,26 +9,32 @@ import { account, stake } from "@ocap/state";
9
9
  import { BN, fromUnitToToken } from "@ocap/util";
10
10
  import Debug from "debug";
11
11
  import { getListField } from "@ocap/util/lib/get-list-field";
12
- import { Joi, schemas } from "@arcblock/validator";
12
+ import { schemas, v, vBN, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
13
13
 
14
14
  //#region src/protocols/token/withdraw-v2.ts
15
15
  const debug = Debug("@ocap/tx-protocols:withdraw-token");
16
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
- });
17
+ const schema = v.pipe(v.object({
18
+ token: schemas.tokenInput,
19
+ to: vDID({
20
+ prefix: true,
21
+ wallet: "ethereum"
22
+ }),
23
+ rollup: vDID({
24
+ prefix: true,
25
+ role: "ROLE_ROLLUP"
26
+ }),
27
+ proposer: v.optional(v.nullable(v.union([v.literal(""), vDID({
28
+ prefix: true,
29
+ wallet: "ethereum"
30
+ })])), ""),
31
+ actualFee: vBN(vBNMin(0)),
32
+ maxFee: vBN(vBNMin(0)),
33
+ data: v.optional(v.nullable(v.any()))
34
+ }), vStripUnknown());
29
35
  const runner = new Runner("withdraw_token_v2");
30
36
  runner.use(({ tx: tx$1, itx }, next) => {
31
- const { error } = schema.validate(itx);
37
+ const { error } = vValidate(schema, itx);
32
38
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
33
39
  if (itx.to !== tx$1.from) return next(new CustomError("INVALID_TX", "You can only withdraw to tx sender account"));
34
40
  return next();