@ocap/state 1.29.27 → 1.30.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.
- package/esm/_virtual/rolldown_runtime.mjs +28 -1
- package/esm/node_modules/bn.js/lib/bn.mjs +2551 -0
- package/esm/states/account.d.mts +18 -2
- package/esm/states/account.mjs +16 -16
- package/esm/states/asset.d.mts +2 -5
- package/esm/states/asset.mjs +9 -13
- package/esm/states/evidence.d.mts +11 -2
- package/esm/states/evidence.mjs +6 -9
- package/esm/states/factory.mjs +15 -11
- package/esm/states/rollup-block.d.mts +36 -2
- package/esm/states/rollup-block.mjs +27 -25
- package/esm/states/rollup.d.mts +62 -2
- package/esm/states/rollup.mjs +73 -49
- package/esm/states/stake.d.mts +22 -2
- package/esm/states/stake.mjs +32 -20
- package/esm/states/token-factory.d.mts +15 -4
- package/esm/states/token-factory.mjs +47 -31
- package/esm/states/token.d.mts +44 -3
- package/esm/states/token.mjs +55 -43
- package/lib/_virtual/rolldown_runtime.cjs +2 -0
- package/lib/node_modules/bn.js/lib/bn.cjs +2554 -0
- package/lib/states/account.cjs +15 -15
- package/lib/states/account.d.cts +18 -2
- package/lib/states/asset.cjs +7 -13
- package/lib/states/asset.d.cts +2 -5
- package/lib/states/evidence.cjs +5 -8
- package/lib/states/evidence.d.cts +11 -2
- package/lib/states/factory.cjs +14 -10
- package/lib/states/rollup-block.cjs +26 -24
- package/lib/states/rollup-block.d.cts +36 -2
- package/lib/states/rollup.cjs +71 -47
- package/lib/states/rollup.d.cts +62 -2
- package/lib/states/stake.cjs +31 -19
- package/lib/states/stake.d.cts +22 -2
- package/lib/states/token-factory.cjs +46 -30
- package/lib/states/token-factory.d.cts +15 -4
- package/lib/states/token.cjs +54 -42
- package/lib/states/token.d.cts +44 -3
- package/package.json +9 -9
package/esm/states/stake.d.mts
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { StateContextInput } from "../contexts/state.mjs";
|
|
2
|
+
import { v } from "@arcblock/validator";
|
|
2
3
|
import { IStakeState } from "@ocap/types";
|
|
3
|
-
import * as joi5 from "joi";
|
|
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:
|
|
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;
|
package/esm/states/stake.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { create as create$1, update as update$1 } from "../contexts/state.mjs";
|
|
|
3
3
|
import { toAddress } from "@ocap/util";
|
|
4
4
|
import { CustomError } from "@ocap/util/lib/error";
|
|
5
5
|
import pick from "lodash/pick.js";
|
|
6
|
-
import {
|
|
6
|
+
import { schemas, v, vBN, vBNMin, vDID, vFilteredRecord, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
7
7
|
|
|
8
8
|
//#region src/states/stake.ts
|
|
9
9
|
var stake_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -12,25 +12,37 @@ var stake_exports = /* @__PURE__ */ __exportAll({
|
|
|
12
12
|
update: () => update,
|
|
13
13
|
validate: () => validate
|
|
14
14
|
});
|
|
15
|
-
const schema =
|
|
16
|
-
address:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const schema = v.pipe(v.object({
|
|
16
|
+
address: vDID({
|
|
17
|
+
prefix: true,
|
|
18
|
+
role: "ROLE_STAKE"
|
|
19
|
+
}),
|
|
20
|
+
sender: vDID({ prefix: true }),
|
|
21
|
+
receiver: vDID({ prefix: true }),
|
|
22
|
+
tokens: v.optional(vFilteredRecord(vDID({
|
|
23
|
+
prefix: true,
|
|
24
|
+
role: "ROLE_TOKEN"
|
|
25
|
+
}), vBN(vBNMin(0))), {}),
|
|
26
|
+
assets: v.optional(v.array(vDID({
|
|
27
|
+
prefix: true,
|
|
28
|
+
role: "ROLE_ASSET"
|
|
29
|
+
})), []),
|
|
30
|
+
slashers: v.optional(v.array(vDID({ prefix: true })), []),
|
|
31
|
+
revocable: v.optional(v.boolean(), true),
|
|
32
|
+
message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
|
|
33
|
+
revokeWaitingPeriod: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 0),
|
|
34
|
+
revokedTokens: v.optional(vFilteredRecord(vDID({
|
|
35
|
+
prefix: true,
|
|
36
|
+
role: "ROLE_TOKEN"
|
|
37
|
+
}), vBN(vBNMin(0))), {}),
|
|
38
|
+
revokedAssets: v.optional(v.array(vDID({
|
|
39
|
+
prefix: true,
|
|
40
|
+
role: "ROLE_ASSET"
|
|
41
|
+
})), []),
|
|
27
42
|
context: schemas.context,
|
|
28
|
-
data:
|
|
29
|
-
nonce:
|
|
30
|
-
})
|
|
31
|
-
stripUnknown: true,
|
|
32
|
-
noDefaults: false
|
|
33
|
-
});
|
|
43
|
+
data: v.optional(v.nullable(v.any())),
|
|
44
|
+
nonce: v.optional(v.nullable(v.pipe(v.string(), v.trim(), v.check((s) => s === "" || s.length >= 1 && s.length <= 256, "Must be 1-256 chars or empty"))))
|
|
45
|
+
}), vStripUnknown());
|
|
34
46
|
const create = (attrs, context) => {
|
|
35
47
|
const stake = {
|
|
36
48
|
tokens: {},
|
|
@@ -79,7 +91,7 @@ const update = (state, attrs, context) => {
|
|
|
79
91
|
});
|
|
80
92
|
};
|
|
81
93
|
const validate = (state) => {
|
|
82
|
-
const { value, error } = schema
|
|
94
|
+
const { value, error } = vValidate(schema, state);
|
|
83
95
|
if (error) throw new CustomError("INVALID_STAKE", `Invalid stake state: ${error.details.map((x) => x.message).join(", ")}`);
|
|
84
96
|
if (!value.data) value.data = null;
|
|
85
97
|
return value;
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { StateContextInput } from "../contexts/state.mjs";
|
|
2
|
+
import { v } from "@arcblock/validator";
|
|
2
3
|
import { ITokenFactoryState } from "@ocap/types";
|
|
3
|
-
import * as joi3 from "joi";
|
|
4
4
|
|
|
5
5
|
//#region src/states/token-factory.d.ts
|
|
6
6
|
declare namespace token_factory_d_exports {
|
|
7
|
-
export { create,
|
|
7
|
+
export { create, update, vCurveSchema, validate };
|
|
8
8
|
}
|
|
9
|
-
declare const
|
|
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,
|
|
25
|
+
export { create, token_factory_d_exports, update, vCurveSchema, validate };
|
|
@@ -1,43 +1,59 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
|
|
2
2
|
import { create as create$1, update as update$1 } from "../contexts/state.mjs";
|
|
3
3
|
import pick from "lodash/pick.js";
|
|
4
|
-
import {
|
|
4
|
+
import { schemas, v, vBN, vBNGreater, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
5
5
|
|
|
6
6
|
//#region src/states/token-factory.ts
|
|
7
7
|
var token_factory_exports = /* @__PURE__ */ __exportAll({
|
|
8
8
|
create: () => create,
|
|
9
|
-
curveSchema: () => curveSchema,
|
|
10
9
|
update: () => update,
|
|
10
|
+
vCurveSchema: () => vCurveSchema,
|
|
11
11
|
validate: () => validate
|
|
12
12
|
});
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
const vCurveSchema = v.variant("type", [
|
|
14
|
+
v.object({
|
|
15
|
+
type: v.literal("linear"),
|
|
16
|
+
basePrice: vBN(vBNGreater(0)),
|
|
17
|
+
slope: vBN(vBNGreater(0))
|
|
18
|
+
}),
|
|
19
|
+
v.object({
|
|
20
|
+
type: v.literal("constant"),
|
|
21
|
+
fixedPrice: vBN(vBNMin(1))
|
|
22
|
+
}),
|
|
23
|
+
v.object({
|
|
24
|
+
type: v.literal("quadratic"),
|
|
25
|
+
basePrice: vBN(vBNGreater(0)),
|
|
26
|
+
constant: v.pipe(v.number(), v.check((n) => n > 0, "Must be greater than 0"))
|
|
27
|
+
})
|
|
28
|
+
]);
|
|
29
|
+
const stateSchema = v.pipe(v.object({
|
|
30
|
+
address: vDID({
|
|
31
|
+
prefix: true,
|
|
32
|
+
role: "ROLE_TOKEN_FACTORY"
|
|
33
|
+
}),
|
|
34
|
+
owner: v.union([vDID({
|
|
35
|
+
prefix: true,
|
|
36
|
+
role: "ROLE_ACCOUNT"
|
|
37
|
+
}), vDID({
|
|
38
|
+
prefix: true,
|
|
39
|
+
role: "ROLE_APPLICATION"
|
|
40
|
+
})]),
|
|
41
|
+
tokenAddress: vDID({
|
|
42
|
+
prefix: true,
|
|
43
|
+
role: "ROLE_TOKEN"
|
|
44
|
+
}),
|
|
45
|
+
reserveAddress: vDID({
|
|
46
|
+
prefix: true,
|
|
47
|
+
role: "ROLE_TOKEN"
|
|
48
|
+
}),
|
|
49
|
+
currentSupply: vBN(vBNMin(0)),
|
|
50
|
+
reserveBalance: vBN(vBNMin(0)),
|
|
51
|
+
status: v.picklist(["ACTIVE", "PAUSED"]),
|
|
52
|
+
feeRate: v.pipe(v.number(), v.minValue(0), v.maxValue(2e3)),
|
|
53
|
+
curve: v.optional(v.nullable(vCurveSchema)),
|
|
35
54
|
context: schemas.context,
|
|
36
|
-
data:
|
|
37
|
-
})
|
|
38
|
-
stripUnknown: true,
|
|
39
|
-
noDefaults: false
|
|
40
|
-
});
|
|
55
|
+
data: v.optional(v.nullable(v.any()))
|
|
56
|
+
}), vStripUnknown());
|
|
41
57
|
const create = (attrs, context) => {
|
|
42
58
|
const tokenFactory = {
|
|
43
59
|
context: create$1(context),
|
|
@@ -67,10 +83,10 @@ const update = (state, attrs, context) => validate({
|
|
|
67
83
|
context: update$1(state.context, context)
|
|
68
84
|
});
|
|
69
85
|
const validate = (state) => {
|
|
70
|
-
const { value, error } = stateSchema
|
|
86
|
+
const { value, error } = vValidate(stateSchema, state);
|
|
71
87
|
if (error) throw new Error(`Invalid token factory: ${error.details.map((x) => x.message).join(", ")}`);
|
|
72
88
|
return value;
|
|
73
89
|
};
|
|
74
90
|
|
|
75
91
|
//#endregion
|
|
76
|
-
export { create,
|
|
92
|
+
export { create, token_factory_exports, update, vCurveSchema, validate };
|
package/esm/states/token.d.mts
CHANGED
|
@@ -1,13 +1,54 @@
|
|
|
1
1
|
import { StateContextInput } from "../contexts/state.mjs";
|
|
2
|
+
import { v } from "@arcblock/validator";
|
|
2
3
|
import { ITokenState } from "@ocap/types";
|
|
3
|
-
import * as joi6 from "joi";
|
|
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:
|
|
10
|
-
|
|
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/esm/states/token.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { create as create$1 } from "../contexts/state.mjs";
|
|
|
3
3
|
import { toChecksumAddress } from "@arcblock/did/lib/type";
|
|
4
4
|
import { BN, toAddress } from "@ocap/util";
|
|
5
5
|
import pick from "lodash/pick.js";
|
|
6
|
-
import {
|
|
6
|
+
import { schemas, v, vBN, vBNGreater, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
|
|
7
7
|
import cloneDeep from "lodash/cloneDeep.js";
|
|
8
8
|
|
|
9
9
|
//#region src/states/token.ts
|
|
@@ -15,47 +15,60 @@ var token_exports = /* @__PURE__ */ __exportAll({
|
|
|
15
15
|
validate: () => validate
|
|
16
16
|
});
|
|
17
17
|
const isTest = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" || process.env.CI;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
18
|
+
const isValidWebsiteUrl = (s) => {
|
|
19
|
+
try {
|
|
20
|
+
const url = new URL(s);
|
|
21
|
+
return isTest ? ["http:", "https:"].includes(url.protocol) : url.protocol === "https:";
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const isHttpsUrl = (s) => {
|
|
27
|
+
try {
|
|
28
|
+
return new URL(s).protocol === "https:";
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const metadataSchema = v.pipe(v.object({
|
|
34
|
+
communityUrl: v.optional(v.nullable(v.union([v.literal(""), v.pipe(v.string(), v.maxLength(256), v.check(isHttpsUrl, "Must be HTTPS URL"))]))),
|
|
35
|
+
issuer: v.pipe(v.string(), v.maxLength(64))
|
|
36
|
+
}), vStripUnknown());
|
|
37
|
+
const stateSchema = v.pipe(v.object({
|
|
38
|
+
address: vDID({
|
|
39
|
+
prefix: true,
|
|
40
|
+
role: "ROLE_TOKEN"
|
|
41
|
+
}),
|
|
42
|
+
name: v.pipe(v.string(), v.minLength(1), v.maxLength(32)),
|
|
43
|
+
description: v.pipe(v.string(), v.minLength(16), v.maxLength(128)),
|
|
44
|
+
symbol: v.pipe(v.string(), v.minLength(2), v.maxLength(6), v.transform((s) => s.toUpperCase())),
|
|
45
|
+
unit: v.pipe(v.string(), v.minLength(1), v.maxLength(6), v.transform((s) => s.toLowerCase())),
|
|
46
|
+
decimal: v.pipe(v.number(), v.minValue(2), v.maxValue(18)),
|
|
47
|
+
icon: v.optional(v.nullable(v.string())),
|
|
48
|
+
totalSupply: vBN(vBNMin(0)),
|
|
49
|
+
initialSupply: vBN(vBNMin(0)),
|
|
50
|
+
maxTotalSupply: v.optional(v.nullable(v.union([v.literal(""), vBN(vBNGreater(0))]))),
|
|
51
|
+
foreignToken: v.optional(v.nullable(schemas.foreignToken)),
|
|
52
|
+
issuer: v.optional(v.nullable(v.union([v.literal(""), vDID({ prefix: true })]))),
|
|
53
|
+
website: v.optional(v.nullable(v.union([v.literal(""), v.pipe(v.string(), v.maxLength(256), v.check(isValidWebsiteUrl, "Must be valid URL"))]))),
|
|
54
|
+
metadata: v.optional(v.nullable(v.object({
|
|
55
|
+
type: v.picklist(["json"]),
|
|
56
|
+
value: v.optional(metadataSchema)
|
|
57
|
+
}))),
|
|
58
|
+
tokenFactoryAddress: v.optional(v.nullable(v.union([v.literal(""), vDID({
|
|
59
|
+
prefix: true,
|
|
60
|
+
role: "ROLE_TOKEN_FACTORY"
|
|
61
|
+
})]))),
|
|
62
|
+
spenders: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(30)))),
|
|
63
|
+
minters: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(30)))),
|
|
64
|
+
type: v.optional(v.nullable(v.union([v.literal(""), v.picklist([
|
|
65
|
+
"Token",
|
|
66
|
+
"CreditToken",
|
|
67
|
+
"BondingCurveToken"
|
|
68
|
+
])]))),
|
|
53
69
|
context: schemas.context,
|
|
54
|
-
data:
|
|
55
|
-
})
|
|
56
|
-
stripUnknown: true,
|
|
57
|
-
noDefaults: false
|
|
58
|
-
});
|
|
70
|
+
data: v.optional(v.nullable(v.any()))
|
|
71
|
+
}), vStripUnknown());
|
|
59
72
|
const create = (attrs, context) => {
|
|
60
73
|
const token = {
|
|
61
74
|
context: create$1(context),
|
|
@@ -99,8 +112,7 @@ const update = (state, attrs) => validate({
|
|
|
99
112
|
});
|
|
100
113
|
const validate = (state) => {
|
|
101
114
|
if (state.maxTotalSupply && new BN(state.maxTotalSupply).lt(new BN(state.totalSupply))) throw new Error("maxTotalSupply must be greater than or equal to totalSupply");
|
|
102
|
-
const
|
|
103
|
-
const { value, error } = stateSchema.validate(data);
|
|
115
|
+
const { value, error } = vValidate(stateSchema, cloneDeep(state));
|
|
104
116
|
if (error) throw new Error(`Invalid token state: ${error.message}`);
|
|
105
117
|
return value;
|
|
106
118
|
};
|
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
8
9
|
var __exportAll = (all, symbols) => {
|
|
9
10
|
let target = {};
|
|
10
11
|
for (var name in all) {
|
|
@@ -39,5 +40,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
40
|
|
|
40
41
|
//#endregion
|
|
41
42
|
|
|
43
|
+
exports.__commonJSMin = __commonJSMin;
|
|
42
44
|
exports.__exportAll = __exportAll;
|
|
43
45
|
exports.__toESM = __toESM;
|