@ocap/state 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 (39) hide show
  1. package/esm/_virtual/rolldown_runtime.mjs +28 -1
  2. package/esm/node_modules/bn.js/lib/bn.mjs +2551 -0
  3. package/esm/states/account.d.mts +18 -2
  4. package/esm/states/account.mjs +16 -16
  5. package/esm/states/asset.d.mts +2 -5
  6. package/esm/states/asset.mjs +9 -13
  7. package/esm/states/evidence.d.mts +11 -2
  8. package/esm/states/evidence.mjs +6 -9
  9. package/esm/states/factory.mjs +15 -11
  10. package/esm/states/rollup-block.d.mts +36 -2
  11. package/esm/states/rollup-block.mjs +27 -25
  12. package/esm/states/rollup.d.mts +62 -2
  13. package/esm/states/rollup.mjs +73 -49
  14. package/esm/states/stake.d.mts +22 -2
  15. package/esm/states/stake.mjs +32 -20
  16. package/esm/states/token-factory.d.mts +15 -4
  17. package/esm/states/token-factory.mjs +47 -31
  18. package/esm/states/token.d.mts +44 -3
  19. package/esm/states/token.mjs +55 -43
  20. package/lib/_virtual/rolldown_runtime.cjs +2 -0
  21. package/lib/node_modules/bn.js/lib/bn.cjs +2554 -0
  22. package/lib/states/account.cjs +15 -15
  23. package/lib/states/account.d.cts +18 -2
  24. package/lib/states/asset.cjs +7 -13
  25. package/lib/states/asset.d.cts +2 -5
  26. package/lib/states/evidence.cjs +5 -8
  27. package/lib/states/evidence.d.cts +11 -2
  28. package/lib/states/factory.cjs +14 -10
  29. package/lib/states/rollup-block.cjs +26 -24
  30. package/lib/states/rollup-block.d.cts +36 -2
  31. package/lib/states/rollup.cjs +71 -47
  32. package/lib/states/rollup.d.cts +62 -2
  33. package/lib/states/stake.cjs +31 -19
  34. package/lib/states/stake.d.cts +22 -2
  35. package/lib/states/token-factory.cjs +46 -30
  36. package/lib/states/token-factory.d.cts +15 -4
  37. package/lib/states/token.cjs +54 -42
  38. package/lib/states/token.d.cts +44 -3
  39. package/package.json +9 -9
@@ -13,25 +13,37 @@ var stake_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
13
13
  update: () => update,
14
14
  validate: () => validate
15
15
  });
16
- const schema = _arcblock_validator.Joi.object({
17
- address: _arcblock_validator.Joi.DID().prefix().role("ROLE_STAKE").trim().required(),
18
- sender: _arcblock_validator.Joi.DID().prefix().trim().required(),
19
- receiver: _arcblock_validator.Joi.DID().prefix().trim().required(),
20
- tokens: _arcblock_validator.Joi.object({}).pattern(_arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN"), _arcblock_validator.Joi.BN().min(0)).default({}),
21
- assets: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET")).default([]),
22
- slashers: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).default([]),
23
- revocable: _arcblock_validator.Joi.boolean().default(true),
24
- message: _arcblock_validator.Joi.string().trim().min(1).max(256).required(),
25
- revokeWaitingPeriod: _arcblock_validator.Joi.number().integer().min(0).default(0),
26
- revokedTokens: _arcblock_validator.Joi.object({}).pattern(_arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN"), _arcblock_validator.Joi.BN().min(0)).default({}),
27
- revokedAssets: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().role("ROLE_ASSET")).default([]),
16
+ const schema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
17
+ address: (0, _arcblock_validator.vDID)({
18
+ prefix: true,
19
+ role: "ROLE_STAKE"
20
+ }),
21
+ sender: (0, _arcblock_validator.vDID)({ prefix: true }),
22
+ receiver: (0, _arcblock_validator.vDID)({ prefix: true }),
23
+ tokens: _arcblock_validator.v.optional((0, _arcblock_validator.vFilteredRecord)((0, _arcblock_validator.vDID)({
24
+ prefix: true,
25
+ role: "ROLE_TOKEN"
26
+ }), (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0))), {}),
27
+ assets: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({
28
+ prefix: true,
29
+ role: "ROLE_ASSET"
30
+ })), []),
31
+ slashers: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({ prefix: true })), []),
32
+ revocable: _arcblock_validator.v.optional(_arcblock_validator.v.boolean(), true),
33
+ message: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.trim(), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(256)),
34
+ revokeWaitingPeriod: _arcblock_validator.v.optional(_arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.integer(), _arcblock_validator.v.minValue(0)), 0),
35
+ revokedTokens: _arcblock_validator.v.optional((0, _arcblock_validator.vFilteredRecord)((0, _arcblock_validator.vDID)({
36
+ prefix: true,
37
+ role: "ROLE_TOKEN"
38
+ }), (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0))), {}),
39
+ revokedAssets: _arcblock_validator.v.optional(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({
40
+ prefix: true,
41
+ role: "ROLE_ASSET"
42
+ })), []),
28
43
  context: _arcblock_validator.schemas.context,
29
- data: _arcblock_validator.Joi.any().optional().allow(null),
30
- nonce: _arcblock_validator.Joi.string().trim().min(1).max(256).allow("").allow(null).optional()
31
- }).options({
32
- stripUnknown: true,
33
- noDefaults: false
34
- });
44
+ data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any())),
45
+ nonce: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.trim(), _arcblock_validator.v.check((s) => s === "" || s.length >= 1 && s.length <= 256, "Must be 1-256 chars or empty"))))
46
+ }), (0, _arcblock_validator.vStripUnknown)());
35
47
  const create = (attrs, context) => {
36
48
  const stake = {
37
49
  tokens: {},
@@ -80,7 +92,7 @@ const update = (state, attrs, context) => {
80
92
  });
81
93
  };
82
94
  const validate = (state) => {
83
- const { value, error } = schema.validate(state);
95
+ const { value, error } = (0, _arcblock_validator.vValidate)(schema, state);
84
96
  if (error) throw new _ocap_util_lib_error.CustomError("INVALID_STAKE", `Invalid stake state: ${error.details.map((x) => x.message).join(", ")}`);
85
97
  if (!value.data) value.data = null;
86
98
  return value;
@@ -1,12 +1,32 @@
1
1
  import { StateContextInput } from "../contexts/state.cjs";
2
2
  import { IStakeState } from "@ocap/types";
3
- import * as joi2 from "joi";
3
+ import { v } from "@arcblock/validator";
4
4
 
5
5
  //#region src/states/stake.d.ts
6
6
  declare namespace stake_d_exports {
7
7
  export { create, schema, update, validate };
8
8
  }
9
- declare const schema: joi2.ObjectSchema<any>;
9
+ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
+ readonly address: any;
11
+ readonly sender: any;
12
+ readonly receiver: any;
13
+ readonly tokens: v.OptionalSchema<any, {}>;
14
+ readonly assets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
15
+ readonly slashers: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
16
+ readonly revocable: v.OptionalSchema<v.BooleanSchema<undefined>, true>;
17
+ readonly message: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 256, undefined>]>;
18
+ readonly revokeWaitingPeriod: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, 0>;
19
+ readonly revokedTokens: v.OptionalSchema<any, {}>;
20
+ readonly revokedAssets: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
21
+ readonly context: v.ObjectSchema<{
22
+ readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
23
+ readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
24
+ readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
25
+ readonly renaissanceTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
26
+ }, undefined>;
27
+ readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
28
+ readonly nonce: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.CheckAction<string, "Must be 1-256 chars or empty">]>, undefined>, undefined>;
29
+ }, undefined>, any]>;
10
30
  declare const create: (attrs: Partial<IStakeState>, context: StateContextInput) => IStakeState;
11
31
  declare const update: (state: IStakeState, attrs: Partial<IStakeState>, context: StateContextInput) => IStakeState;
12
32
  declare const validate: (state: IStakeState) => IStakeState;
@@ -7,38 +7,54 @@ let _arcblock_validator = require("@arcblock/validator");
7
7
  //#region src/states/token-factory.ts
8
8
  var token_factory_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
9
9
  create: () => create,
10
- curveSchema: () => curveSchema,
11
10
  update: () => update,
11
+ vCurveSchema: () => vCurveSchema,
12
12
  validate: () => validate
13
13
  });
14
- const curveSchema = _arcblock_validator.Joi.alternatives().try(_arcblock_validator.Joi.object({
15
- type: _arcblock_validator.Joi.string().valid("linear").required(),
16
- basePrice: _arcblock_validator.Joi.BN().greater(0).required(),
17
- slope: _arcblock_validator.Joi.BN().greater(0).required()
18
- }), _arcblock_validator.Joi.object({
19
- type: _arcblock_validator.Joi.string().valid("constant").required(),
20
- fixedPrice: _arcblock_validator.Joi.BN().min(1).required()
21
- }), _arcblock_validator.Joi.object({
22
- type: _arcblock_validator.Joi.string().valid("quadratic").required(),
23
- basePrice: _arcblock_validator.Joi.BN().greater(0).required(),
24
- constant: _arcblock_validator.Joi.number().greater(0).required()
25
- }));
26
- const stateSchema = _arcblock_validator.Joi.object({
27
- address: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").required(),
28
- owner: _arcblock_validator.Joi.alternatives().try(_arcblock_validator.Joi.DID().prefix().role("ROLE_ACCOUNT"), _arcblock_validator.Joi.DID().prefix().role("ROLE_APPLICATION")).required(),
29
- tokenAddress: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN").required(),
30
- reserveAddress: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN").required(),
31
- currentSupply: _arcblock_validator.Joi.BN().min(0).required(),
32
- reserveBalance: _arcblock_validator.Joi.BN().min(0).required(),
33
- status: _arcblock_validator.Joi.string().valid("ACTIVE", "PAUSED").required(),
34
- feeRate: _arcblock_validator.Joi.number().min(0).max(2e3).required(),
35
- curve: curveSchema.optional().allow(null),
14
+ const vCurveSchema = _arcblock_validator.v.variant("type", [
15
+ _arcblock_validator.v.object({
16
+ type: _arcblock_validator.v.literal("linear"),
17
+ basePrice: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0)),
18
+ slope: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0))
19
+ }),
20
+ _arcblock_validator.v.object({
21
+ type: _arcblock_validator.v.literal("constant"),
22
+ fixedPrice: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(1))
23
+ }),
24
+ _arcblock_validator.v.object({
25
+ type: _arcblock_validator.v.literal("quadratic"),
26
+ basePrice: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0)),
27
+ constant: _arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.check((n) => n > 0, "Must be greater than 0"))
28
+ })
29
+ ]);
30
+ const stateSchema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
31
+ address: (0, _arcblock_validator.vDID)({
32
+ prefix: true,
33
+ role: "ROLE_TOKEN_FACTORY"
34
+ }),
35
+ owner: _arcblock_validator.v.union([(0, _arcblock_validator.vDID)({
36
+ prefix: true,
37
+ role: "ROLE_ACCOUNT"
38
+ }), (0, _arcblock_validator.vDID)({
39
+ prefix: true,
40
+ role: "ROLE_APPLICATION"
41
+ })]),
42
+ tokenAddress: (0, _arcblock_validator.vDID)({
43
+ prefix: true,
44
+ role: "ROLE_TOKEN"
45
+ }),
46
+ reserveAddress: (0, _arcblock_validator.vDID)({
47
+ prefix: true,
48
+ role: "ROLE_TOKEN"
49
+ }),
50
+ currentSupply: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0)),
51
+ reserveBalance: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0)),
52
+ status: _arcblock_validator.v.picklist(["ACTIVE", "PAUSED"]),
53
+ feeRate: _arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.minValue(0), _arcblock_validator.v.maxValue(2e3)),
54
+ curve: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(vCurveSchema)),
36
55
  context: _arcblock_validator.schemas.context,
37
- data: _arcblock_validator.Joi.any().optional().allow(null)
38
- }).options({
39
- stripUnknown: true,
40
- noDefaults: false
41
- });
56
+ data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
57
+ }), (0, _arcblock_validator.vStripUnknown)());
42
58
  const create = (attrs, context) => {
43
59
  const tokenFactory = {
44
60
  context: require_contexts_state.create(context),
@@ -68,14 +84,13 @@ const update = (state, attrs, context) => validate({
68
84
  context: require_contexts_state.update(state.context, context)
69
85
  });
70
86
  const validate = (state) => {
71
- const { value, error } = stateSchema.validate(state);
87
+ const { value, error } = (0, _arcblock_validator.vValidate)(stateSchema, state);
72
88
  if (error) throw new Error(`Invalid token factory: ${error.details.map((x) => x.message).join(", ")}`);
73
89
  return value;
74
90
  };
75
91
 
76
92
  //#endregion
77
93
  exports.create = create;
78
- exports.curveSchema = curveSchema;
79
94
  Object.defineProperty(exports, 'token_factory_exports', {
80
95
  enumerable: true,
81
96
  get: function () {
@@ -83,4 +98,5 @@ Object.defineProperty(exports, 'token_factory_exports', {
83
98
  }
84
99
  });
85
100
  exports.update = update;
101
+ exports.vCurveSchema = vCurveSchema;
86
102
  exports.validate = validate;
@@ -1,14 +1,25 @@
1
1
  import { StateContextInput } from "../contexts/state.cjs";
2
2
  import { ITokenFactoryState } from "@ocap/types";
3
- import * as joi4 from "joi";
3
+ import { v } from "@arcblock/validator";
4
4
 
5
5
  //#region src/states/token-factory.d.ts
6
6
  declare namespace token_factory_d_exports {
7
- export { create, curveSchema, update, validate };
7
+ export { create, update, vCurveSchema, validate };
8
8
  }
9
- declare const curveSchema: joi4.AlternativesSchema<any>;
9
+ declare const vCurveSchema: v.VariantSchema<"type", [v.ObjectSchema<{
10
+ readonly type: v.LiteralSchema<"linear", undefined>;
11
+ readonly basePrice: any;
12
+ readonly slope: any;
13
+ }, undefined>, v.ObjectSchema<{
14
+ readonly type: v.LiteralSchema<"constant", undefined>;
15
+ readonly fixedPrice: any;
16
+ }, undefined>, v.ObjectSchema<{
17
+ readonly type: v.LiteralSchema<"quadratic", undefined>;
18
+ readonly basePrice: any;
19
+ readonly constant: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, "Must be greater than 0">]>;
20
+ }, undefined>], undefined>;
10
21
  declare const create: (attrs: Partial<ITokenFactoryState>, context: StateContextInput) => ITokenFactoryState;
11
22
  declare const update: (state: ITokenFactoryState, attrs: Partial<ITokenFactoryState>, context: StateContextInput) => ITokenFactoryState;
12
23
  declare const validate: (state: ITokenFactoryState) => ITokenFactoryState;
13
24
  //#endregion
14
- export { create, curveSchema, token_factory_d_exports, update, validate };
25
+ export { create, token_factory_d_exports, update, vCurveSchema, validate };
@@ -17,47 +17,60 @@ var token_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
17
17
  validate: () => validate
18
18
  });
19
19
  const isTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI;
20
- const metadataSchema = _arcblock_validator.Joi.object({
21
- communityUrl: _arcblock_validator.Joi.string().uri({
22
- scheme: ["https"],
23
- allowRelative: false
24
- }).max(256).optional().allow(null, ""),
25
- issuer: _arcblock_validator.Joi.string().max(64).required()
26
- }).options({
27
- stripUnknown: true,
28
- noDefaults: false
29
- });
30
- const stateSchema = _arcblock_validator.Joi.object({
31
- address: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN").required(),
32
- name: _arcblock_validator.Joi.string().min(1).max(32).required(),
33
- description: _arcblock_validator.Joi.string().min(16).max(128).required(),
34
- symbol: _arcblock_validator.Joi.string().min(2).max(6).uppercase().required(),
35
- unit: _arcblock_validator.Joi.string().min(1).max(6).lowercase().required(),
36
- decimal: _arcblock_validator.Joi.number().min(2).max(18).required(),
37
- icon: _arcblock_validator.Joi.string().optional().allow(null, ""),
38
- totalSupply: _arcblock_validator.Joi.BN().min(0).required(),
39
- initialSupply: _arcblock_validator.Joi.BN().min(0).required(),
40
- maxTotalSupply: _arcblock_validator.Joi.alternatives().try(_arcblock_validator.Joi.BN().greater(0), _arcblock_validator.Joi.string().valid("")).optional().allow(null),
41
- foreignToken: _arcblock_validator.schemas.foreignToken.optional().allow(null),
42
- issuer: _arcblock_validator.Joi.DID().prefix().optional().allow(null, ""),
43
- website: _arcblock_validator.Joi.string().uri({
44
- scheme: isTest ? ["http", "https"] : ["https"],
45
- allowRelative: false
46
- }).max(256).optional().allow(null, ""),
47
- metadata: _arcblock_validator.Joi.object({
48
- type: _arcblock_validator.Joi.string().valid("json").required(),
49
- value: metadataSchema.optional()
50
- }).optional().allow(null),
51
- tokenFactoryAddress: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN_FACTORY").optional().allow(null, ""),
52
- spenders: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).max(30).optional().allow(null),
53
- minters: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()).max(30).optional().allow(null),
54
- type: _arcblock_validator.Joi.string().valid("Token", "CreditToken", "BondingCurveToken").optional().allow(null, ""),
20
+ const isValidWebsiteUrl = (s) => {
21
+ try {
22
+ const url = new URL(s);
23
+ return isTest ? ["http:", "https:"].includes(url.protocol) : url.protocol === "https:";
24
+ } catch {
25
+ return false;
26
+ }
27
+ };
28
+ const isHttpsUrl = (s) => {
29
+ try {
30
+ return new URL(s).protocol === "https:";
31
+ } catch {
32
+ return false;
33
+ }
34
+ };
35
+ const metadataSchema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
36
+ communityUrl: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.maxLength(256), _arcblock_validator.v.check(isHttpsUrl, "Must be HTTPS URL"))]))),
37
+ issuer: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.maxLength(64))
38
+ }), (0, _arcblock_validator.vStripUnknown)());
39
+ const stateSchema = _arcblock_validator.v.pipe(_arcblock_validator.v.object({
40
+ address: (0, _arcblock_validator.vDID)({
41
+ prefix: true,
42
+ role: "ROLE_TOKEN"
43
+ }),
44
+ name: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(32)),
45
+ description: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(16), _arcblock_validator.v.maxLength(128)),
46
+ symbol: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(2), _arcblock_validator.v.maxLength(6), _arcblock_validator.v.transform((s) => s.toUpperCase())),
47
+ unit: _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.minLength(1), _arcblock_validator.v.maxLength(6), _arcblock_validator.v.transform((s) => s.toLowerCase())),
48
+ decimal: _arcblock_validator.v.pipe(_arcblock_validator.v.number(), _arcblock_validator.v.minValue(2), _arcblock_validator.v.maxValue(18)),
49
+ icon: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.string())),
50
+ totalSupply: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0)),
51
+ initialSupply: (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNMin)(0)),
52
+ maxTotalSupply: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), (0, _arcblock_validator.vBN)((0, _arcblock_validator.vBNGreater)(0))]))),
53
+ foreignToken: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.schemas.foreignToken)),
54
+ issuer: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), (0, _arcblock_validator.vDID)({ prefix: true })]))),
55
+ website: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), _arcblock_validator.v.pipe(_arcblock_validator.v.string(), _arcblock_validator.v.maxLength(256), _arcblock_validator.v.check(isValidWebsiteUrl, "Must be valid URL"))]))),
56
+ metadata: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.object({
57
+ type: _arcblock_validator.v.picklist(["json"]),
58
+ value: _arcblock_validator.v.optional(metadataSchema)
59
+ }))),
60
+ tokenFactoryAddress: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), (0, _arcblock_validator.vDID)({
61
+ prefix: true,
62
+ role: "ROLE_TOKEN_FACTORY"
63
+ })]))),
64
+ spenders: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.pipe(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({ prefix: true })), _arcblock_validator.v.maxLength(30)))),
65
+ minters: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.pipe(_arcblock_validator.v.array((0, _arcblock_validator.vDID)({ prefix: true })), _arcblock_validator.v.maxLength(30)))),
66
+ type: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.union([_arcblock_validator.v.literal(""), _arcblock_validator.v.picklist([
67
+ "Token",
68
+ "CreditToken",
69
+ "BondingCurveToken"
70
+ ])]))),
55
71
  context: _arcblock_validator.schemas.context,
56
- data: _arcblock_validator.Joi.any().optional().allow(null)
57
- }).options({
58
- stripUnknown: true,
59
- noDefaults: false
60
- });
72
+ data: _arcblock_validator.v.optional(_arcblock_validator.v.nullable(_arcblock_validator.v.any()))
73
+ }), (0, _arcblock_validator.vStripUnknown)());
61
74
  const create = (attrs, context) => {
62
75
  const token = {
63
76
  context: require_contexts_state.create(context),
@@ -101,8 +114,7 @@ const update = (state, attrs) => validate({
101
114
  });
102
115
  const validate = (state) => {
103
116
  if (state.maxTotalSupply && new _ocap_util.BN(state.maxTotalSupply).lt(new _ocap_util.BN(state.totalSupply))) throw new Error("maxTotalSupply must be greater than or equal to totalSupply");
104
- const data = (0, lodash_cloneDeep.default)(state);
105
- const { value, error } = stateSchema.validate(data);
117
+ const { value, error } = (0, _arcblock_validator.vValidate)(stateSchema, (0, lodash_cloneDeep.default)(state));
106
118
  if (error) throw new Error(`Invalid token state: ${error.message}`);
107
119
  return value;
108
120
  };
@@ -1,13 +1,54 @@
1
1
  import { StateContextInput } from "../contexts/state.cjs";
2
2
  import { ITokenState } from "@ocap/types";
3
- import * as joi5 from "joi";
3
+ import { v } from "@arcblock/validator";
4
4
 
5
5
  //#region src/states/token.d.ts
6
6
  declare namespace token_d_exports {
7
7
  export { create, metadataSchema, stateSchema, update, validate };
8
8
  }
9
- declare const metadataSchema: joi5.ObjectSchema<any>;
10
- declare const stateSchema: joi5.ObjectSchema<any>;
9
+ declare const metadataSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
+ readonly communityUrl: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>, v.CheckAction<string, "Must be HTTPS URL">]>], undefined>, undefined>, undefined>;
11
+ readonly issuer: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 64, undefined>]>;
12
+ }, undefined>, any]>;
13
+ declare const stateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
14
+ readonly address: any;
15
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
16
+ readonly description: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 16, undefined>, v.MaxLengthAction<string, 128, undefined>]>;
17
+ readonly symbol: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 2, undefined>, v.MaxLengthAction<string, 6, undefined>, v.TransformAction<string, string>]>;
18
+ readonly unit: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 6, undefined>, v.TransformAction<string, string>]>;
19
+ readonly decimal: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 2, undefined>, v.MaxValueAction<number, 18, undefined>]>;
20
+ readonly icon: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
21
+ readonly totalSupply: any;
22
+ readonly initialSupply: any;
23
+ readonly maxTotalSupply: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>, undefined>;
24
+ readonly foreignToken: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
25
+ readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
26
+ readonly contractAddress: any;
27
+ readonly chainType: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
28
+ readonly chainName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 32, undefined>]>;
29
+ readonly chainId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.CheckAction<number, "Must be positive">]>;
30
+ }, undefined>, undefined>, undefined>;
31
+ readonly issuer: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>, undefined>;
32
+ readonly website: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>, v.CheckAction<string, "Must be valid URL">]>], undefined>, undefined>, undefined>;
33
+ readonly metadata: v.OptionalSchema<v.NullableSchema<v.ObjectSchema<{
34
+ readonly type: v.PicklistSchema<["json"], undefined>;
35
+ readonly value: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
36
+ readonly communityUrl: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>, v.CheckAction<string, "Must be HTTPS URL">]>], undefined>, undefined>, undefined>;
37
+ readonly issuer: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 64, undefined>]>;
38
+ }, undefined>, any]>, undefined>;
39
+ }, undefined>, undefined>, undefined>;
40
+ readonly tokenFactoryAddress: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>, undefined>;
41
+ readonly spenders: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.ArraySchema<any, undefined>, v.MaxLengthAction<any[], 30, undefined>]>, undefined>, undefined>;
42
+ readonly minters: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.ArraySchema<any, undefined>, v.MaxLengthAction<any[], 30, undefined>]>, undefined>, undefined>;
43
+ readonly type: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, v.PicklistSchema<["Token", "CreditToken", "BondingCurveToken"], undefined>], undefined>, undefined>, undefined>;
44
+ readonly context: v.ObjectSchema<{
45
+ readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
46
+ readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
47
+ readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
48
+ readonly renaissanceTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
49
+ }, undefined>;
50
+ readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
51
+ }, undefined>, any]>;
11
52
  declare const create: (attrs: Partial<ITokenState>, context: StateContextInput) => ITokenState;
12
53
  declare const update: (state: ITokenState, attrs: Partial<ITokenState>) => ITokenState;
13
54
  declare const validate: (state: ITokenState) => ITokenState;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.29.26",
6
+ "version": "1.30.0",
7
7
  "description": "State management utilities for OCAP blockchain",
8
8
  "type": "module",
9
9
  "main": "./lib/index.cjs",
@@ -40,14 +40,14 @@
40
40
  "clean": "rm -rf lib esm"
41
41
  },
42
42
  "dependencies": {
43
- "@arcblock/did": "1.29.26",
44
- "@arcblock/validator": "1.29.26",
45
- "@ocap/contract": "1.29.26",
46
- "@ocap/mcrypto": "1.29.26",
47
- "@ocap/message": "1.29.26",
48
- "@ocap/types": "1.29.26",
49
- "@ocap/util": "1.29.26",
50
- "@ocap/wallet": "1.29.26",
43
+ "@arcblock/did": "1.30.0",
44
+ "@arcblock/validator": "1.30.0",
45
+ "@ocap/contract": "1.30.0",
46
+ "@ocap/mcrypto": "1.30.0",
47
+ "@ocap/message": "1.30.0",
48
+ "@ocap/types": "1.30.0",
49
+ "@ocap/util": "1.30.0",
50
+ "@ocap/wallet": "1.30.0",
51
51
  "bloom-filters": "^1.3.9",
52
52
  "lodash": "^4.17.23"
53
53
  },