@ocap/state 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 (83) hide show
  1. package/esm/_virtual/rolldown_runtime.mjs +18 -0
  2. package/esm/contexts/state.d.mts +15 -0
  3. package/esm/contexts/state.mjs +17 -0
  4. package/esm/index.d.mts +20 -0
  5. package/esm/index.mjs +47 -0
  6. package/esm/states/account.d.mts +18 -0
  7. package/esm/states/account.mjs +91 -0
  8. package/esm/states/asset.d.mts +14 -0
  9. package/esm/states/asset.mjs +80 -0
  10. package/esm/states/blacklist.d.mts +36 -0
  11. package/esm/states/blacklist.mjs +71 -0
  12. package/esm/states/chain.d.mts +30 -0
  13. package/esm/states/chain.mjs +52 -0
  14. package/esm/states/delegation.d.mts +11 -0
  15. package/esm/states/delegation.mjs +42 -0
  16. package/esm/states/evidence.d.mts +12 -0
  17. package/esm/states/evidence.mjs +35 -0
  18. package/esm/states/factory.d.mts +12 -0
  19. package/esm/states/factory.mjs +76 -0
  20. package/esm/states/rollup-block.d.mts +13 -0
  21. package/esm/states/rollup-block.mjs +75 -0
  22. package/esm/states/rollup.d.mts +18 -0
  23. package/esm/states/rollup.mjs +215 -0
  24. package/esm/states/stake.d.mts +13 -0
  25. package/esm/states/stake.mjs +89 -0
  26. package/esm/states/token-factory.d.mts +13 -0
  27. package/esm/states/token-factory.mjs +76 -0
  28. package/esm/states/token.d.mts +14 -0
  29. package/esm/states/token.mjs +109 -0
  30. package/esm/states/tx.d.mts +233 -0
  31. package/esm/states/tx.mjs +867 -0
  32. package/esm/util.d.mts +6 -0
  33. package/esm/util.mjs +18 -0
  34. package/lib/_virtual/rolldown_runtime.cjs +43 -0
  35. package/lib/contexts/state.cjs +19 -0
  36. package/lib/contexts/state.d.cts +15 -0
  37. package/lib/index.cjs +121 -0
  38. package/lib/index.d.cts +20 -0
  39. package/lib/states/account.cjs +106 -0
  40. package/lib/states/account.d.cts +18 -0
  41. package/lib/states/asset.cjs +91 -0
  42. package/lib/states/asset.d.cts +14 -0
  43. package/lib/states/blacklist.cjs +74 -0
  44. package/lib/states/blacklist.d.cts +36 -0
  45. package/lib/states/chain.cjs +62 -0
  46. package/lib/states/chain.d.cts +30 -0
  47. package/lib/states/delegation.cjs +50 -0
  48. package/lib/states/delegation.d.cts +11 -0
  49. package/lib/states/evidence.cjs +44 -0
  50. package/lib/states/evidence.d.cts +12 -0
  51. package/lib/states/factory.cjs +85 -0
  52. package/lib/states/factory.d.cts +12 -0
  53. package/lib/states/rollup-block.cjs +85 -0
  54. package/lib/states/rollup-block.d.cts +13 -0
  55. package/lib/states/rollup.cjs +230 -0
  56. package/lib/states/rollup.d.cts +18 -0
  57. package/lib/states/stake.cjs +99 -0
  58. package/lib/states/stake.d.cts +13 -0
  59. package/lib/states/token-factory.cjs +86 -0
  60. package/lib/states/token-factory.d.cts +13 -0
  61. package/lib/states/token.cjs +121 -0
  62. package/lib/states/token.d.cts +14 -0
  63. package/lib/states/tx.cjs +889 -0
  64. package/lib/states/tx.d.cts +233 -0
  65. package/lib/util.cjs +19 -0
  66. package/lib/util.d.cts +6 -0
  67. package/package.json +46 -14
  68. package/lib/contexts/state.js +0 -19
  69. package/lib/index.js +0 -63
  70. package/lib/states/account.js +0 -95
  71. package/lib/states/asset.js +0 -91
  72. package/lib/states/blacklist.js +0 -103
  73. package/lib/states/chain.js +0 -49
  74. package/lib/states/delegation.js +0 -46
  75. package/lib/states/evidence.js +0 -35
  76. package/lib/states/factory.js +0 -92
  77. package/lib/states/rollup-block.js +0 -84
  78. package/lib/states/rollup.js +0 -297
  79. package/lib/states/stake.js +0 -83
  80. package/lib/states/token-factory.js +0 -74
  81. package/lib/states/token.js +0 -124
  82. package/lib/states/tx.js +0 -896
  83. package/lib/util.js +0 -28
@@ -0,0 +1,30 @@
1
+ import { StateContext } from "../contexts/state.cjs";
2
+
3
+ //#region src/states/chain.d.ts
4
+ declare namespace chain_d_exports {
5
+ export { ChainState, create, update };
6
+ }
7
+ interface ChainState {
8
+ address?: string;
9
+ chainId?: string;
10
+ version?: string;
11
+ transaction?: unknown;
12
+ moderator?: unknown;
13
+ accounts?: unknown;
14
+ token?: {
15
+ symbol?: string;
16
+ decimal?: number;
17
+ name?: string;
18
+ description?: string;
19
+ unit?: string;
20
+ totalSupply?: string;
21
+ initialSupply?: string;
22
+ foreignToken?: unknown;
23
+ };
24
+ vaults?: unknown;
25
+ context: StateContext;
26
+ }
27
+ declare const create: (attrs: Partial<ChainState>) => ChainState;
28
+ declare const update: (state: ChainState, updates: Partial<ChainState>) => ChainState;
29
+ //#endregion
30
+ export { ChainState, chain_d_exports, create, update };
@@ -0,0 +1,50 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_contexts_state = require('../contexts/state.cjs');
3
+ const require_util = require('../util.cjs');
4
+ let _ocap_util = require("@ocap/util");
5
+ let lodash_pick = require("lodash/pick");
6
+ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
7
+
8
+ //#region src/states/delegation.ts
9
+ var delegation_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
10
+ create: () => create,
11
+ update: () => update
12
+ });
13
+ const create = (attrs, context) => {
14
+ const delegation = {
15
+ context: require_contexts_state.create(context),
16
+ ...(0, lodash_pick.default)(attrs, [
17
+ "address",
18
+ "to",
19
+ "from",
20
+ "ops",
21
+ "data"
22
+ ])
23
+ };
24
+ if (!delegation.data) delegation.data = null;
25
+ delegation.address = (0, _ocap_util.toAddress)(delegation.address);
26
+ delegation.ops = require_util.nullify(delegation.ops);
27
+ return delegation;
28
+ };
29
+ const update = (state, attrs, context) => {
30
+ const delegation = {
31
+ ...state,
32
+ ...(0, lodash_pick.default)(attrs, ["ops", "data"]),
33
+ context: require_contexts_state.update(state.context, context)
34
+ };
35
+ if (!delegation.data) delegation.data = null;
36
+ if (!state.to && attrs.to) delegation.to = (0, _ocap_util.toAddress)(attrs.to);
37
+ if (!state.from && attrs.from) delegation.from = (0, _ocap_util.toAddress)(attrs.from);
38
+ delegation.ops = require_util.nullify(delegation.ops);
39
+ return delegation;
40
+ };
41
+
42
+ //#endregion
43
+ exports.create = create;
44
+ Object.defineProperty(exports, 'delegation_exports', {
45
+ enumerable: true,
46
+ get: function () {
47
+ return delegation_exports;
48
+ }
49
+ });
50
+ exports.update = update;
@@ -0,0 +1,11 @@
1
+ import { StateContextInput } from "../contexts/state.cjs";
2
+ import { IDelegateState } from "@ocap/types";
3
+
4
+ //#region src/states/delegation.d.ts
5
+ declare namespace delegation_d_exports {
6
+ export { create, update };
7
+ }
8
+ declare const create: (attrs: Partial<IDelegateState>, context: StateContextInput) => IDelegateState;
9
+ declare const update: (state: IDelegateState, attrs: Partial<IDelegateState>, context: StateContextInput) => IDelegateState;
10
+ //#endregion
11
+ export { create, delegation_d_exports, update };
@@ -0,0 +1,44 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_contexts_state = require('../contexts/state.cjs');
3
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
4
+ let lodash_pick = require("lodash/pick");
5
+ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
6
+ let _arcblock_validator = require("@arcblock/validator");
7
+
8
+ //#region src/states/evidence.ts
9
+ var evidence_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
10
+ create: () => create,
11
+ schema: () => schema,
12
+ validate: () => validate
13
+ });
14
+ const schema = _arcblock_validator.Joi.object({
15
+ hash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
16
+ context: _arcblock_validator.schemas.context,
17
+ data: _arcblock_validator.Joi.any().optional().allow(null)
18
+ }).options({
19
+ stripUnknown: true,
20
+ noDefaults: false
21
+ });
22
+ const create = (attrs, context) => {
23
+ return validate({
24
+ context: require_contexts_state.create(context),
25
+ ...(0, lodash_pick.default)(attrs, ["hash", "data"])
26
+ });
27
+ };
28
+ const validate = (state) => {
29
+ const { value, error } = schema.validate(state);
30
+ if (error) throw new _ocap_util_lib_error.CustomError("INVALID_EVIDENCE", `Invalid evidence state: ${error.details.map((x) => x.message).join(", ")}`);
31
+ if (!value.data) value.data = null;
32
+ return value;
33
+ };
34
+
35
+ //#endregion
36
+ exports.create = create;
37
+ Object.defineProperty(exports, 'evidence_exports', {
38
+ enumerable: true,
39
+ get: function () {
40
+ return evidence_exports;
41
+ }
42
+ });
43
+ exports.schema = schema;
44
+ exports.validate = validate;
@@ -0,0 +1,12 @@
1
+ import { StateContextInput } from "../contexts/state.cjs";
2
+ import { IEvidenceState } from "@ocap/types";
3
+
4
+ //#region src/states/evidence.d.ts
5
+ declare namespace evidence_d_exports {
6
+ export { create, schema, validate };
7
+ }
8
+ declare const schema: any;
9
+ declare const create: (attrs: Partial<IEvidenceState>, context: StateContextInput) => IEvidenceState;
10
+ declare const validate: (state: IEvidenceState) => IEvidenceState;
11
+ //#endregion
12
+ export { create, evidence_d_exports, schema, validate };
@@ -0,0 +1,85 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_contexts_state = require('../contexts/state.cjs');
3
+ let _ocap_util = require("@ocap/util");
4
+ let lodash_pick = require("lodash/pick");
5
+ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
6
+ let _arcblock_validator = require("@arcblock/validator");
7
+ let _ocap_contract = require("@ocap/contract");
8
+
9
+ //#region src/states/factory.ts
10
+ var factory_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
11
+ create: () => create,
12
+ update: () => update,
13
+ validate: () => validate
14
+ });
15
+ const stateSchema = _arcblock_validator.Joi.object({
16
+ ..._arcblock_validator.schemas.factoryProps,
17
+ owner: _arcblock_validator.Joi.DID().prefix().required(),
18
+ numMinted: _arcblock_validator.Joi.number().min(0).default(0),
19
+ lastSettlement: _arcblock_validator.Joi.date().iso().raw().allow(""),
20
+ tokens: _arcblock_validator.Joi.object().pattern(_arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN"), _arcblock_validator.Joi.BN().min(0)).default({}),
21
+ context: _arcblock_validator.schemas.context
22
+ }).options({
23
+ stripUnknown: true,
24
+ noDefaults: false
25
+ });
26
+ const compileHook = (hook) => {
27
+ if (hook.type === "contract") hook.compiled = (0, _ocap_contract.merge)((0, _ocap_contract.compile)(hook.hook));
28
+ return hook;
29
+ };
30
+ const create = (attrs, context) => {
31
+ const factory = {
32
+ numMinted: 0,
33
+ lastSettlement: "",
34
+ tokens: {},
35
+ context: require_contexts_state.create(context),
36
+ ...(0, lodash_pick.default)(attrs, [
37
+ "address",
38
+ "owner",
39
+ "name",
40
+ "description",
41
+ "settlement",
42
+ "limit",
43
+ "tokens",
44
+ "trustedIssuers",
45
+ "input",
46
+ "output",
47
+ "display",
48
+ "hooks",
49
+ "data"
50
+ ])
51
+ };
52
+ if (!factory.data) factory.data = null;
53
+ (0, _ocap_contract.getQuota)(factory.input);
54
+ factory.hooks = (factory.hooks || []).map((x) => compileHook(x));
55
+ factory.address = (0, _ocap_util.toAddress)(factory.address);
56
+ return validate(factory);
57
+ };
58
+ const update = (state, attrs, context) => {
59
+ const factory = {
60
+ ...state,
61
+ ...(0, lodash_pick.default)(attrs, ["numMinted", "tokens"]),
62
+ context: require_contexts_state.update(state.context, context)
63
+ };
64
+ if (factory.output?.tags === null) factory.output.tags = [];
65
+ return validate(factory);
66
+ };
67
+ const validate = (state) => {
68
+ const { value, error } = stateSchema.validate(state);
69
+ if (error) throw new Error(`Invalid factory: ${error.details.map((x) => x.message).join(", ")}`);
70
+ ["display"].forEach((key) => {
71
+ if (!value[key]) delete value[key];
72
+ });
73
+ return value;
74
+ };
75
+
76
+ //#endregion
77
+ exports.create = create;
78
+ Object.defineProperty(exports, 'factory_exports', {
79
+ enumerable: true,
80
+ get: function () {
81
+ return factory_exports;
82
+ }
83
+ });
84
+ exports.update = update;
85
+ exports.validate = validate;
@@ -0,0 +1,12 @@
1
+ import { StateContextInput } from "../contexts/state.cjs";
2
+ import { IAssetFactoryState } from "@ocap/types";
3
+
4
+ //#region src/states/factory.d.ts
5
+ declare namespace factory_d_exports {
6
+ export { create, update, validate };
7
+ }
8
+ declare const create: (attrs: Partial<IAssetFactoryState>, context: StateContextInput) => IAssetFactoryState;
9
+ declare const update: (state: IAssetFactoryState, attrs: Partial<IAssetFactoryState>, context: StateContextInput) => IAssetFactoryState;
10
+ declare const validate: (state: IAssetFactoryState) => IAssetFactoryState;
11
+ //#endregion
12
+ export { create, factory_d_exports, update, validate };
@@ -0,0 +1,85 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_contexts_state = require('../contexts/state.cjs');
3
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
4
+ let lodash_pick = require("lodash/pick");
5
+ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
6
+ let _arcblock_validator = require("@arcblock/validator");
7
+
8
+ //#region src/states/rollup-block.ts
9
+ var rollup_block_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
10
+ create: () => create,
11
+ schema: () => schema,
12
+ update: () => update,
13
+ validate: () => validate
14
+ });
15
+ const schema = _arcblock_validator.Joi.object({
16
+ hash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
17
+ height: _arcblock_validator.Joi.number().integer().greater(0).required(),
18
+ merkleRoot: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
19
+ previousHash: _arcblock_validator.Joi.string().when("height", {
20
+ is: 1,
21
+ then: _arcblock_validator.Joi.string().optional().allow(null).allow(""),
22
+ otherwise: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required()
23
+ }),
24
+ txsHash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required(),
25
+ txs: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).required()).min(1).unique().required(),
26
+ proposer: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").required(),
27
+ signatures: _arcblock_validator.schemas.multiSig.min(1).required(),
28
+ rollup: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
29
+ mintedAmount: _arcblock_validator.Joi.BN().min(0).optional().allow(null).default("0"),
30
+ burnedAmount: _arcblock_validator.Joi.BN().min(0).optional().allow(null).default("0"),
31
+ rewardAmount: _arcblock_validator.Joi.BN().min(0).optional().allow(null).default("0"),
32
+ minReward: _arcblock_validator.Joi.BN().min(0).required(),
33
+ governance: _arcblock_validator.Joi.boolean().default(false),
34
+ context: _arcblock_validator.schemas.context,
35
+ data: _arcblock_validator.Joi.any().optional().allow(null)
36
+ }).options({
37
+ stripUnknown: true,
38
+ noDefaults: false
39
+ });
40
+ const create = (attrs, context) => {
41
+ return validate({
42
+ context: require_contexts_state.create(context),
43
+ ...(0, lodash_pick.default)(attrs, [
44
+ "hash",
45
+ "height",
46
+ "merkleRoot",
47
+ "previousHash",
48
+ "txsHash",
49
+ "txs",
50
+ "proposer",
51
+ "signatures",
52
+ "rollup",
53
+ "mintedAmount",
54
+ "burnedAmount",
55
+ "rewardAmount",
56
+ "minReward",
57
+ "governance",
58
+ "data"
59
+ ])
60
+ });
61
+ };
62
+ const update = (state, context) => {
63
+ return validate({
64
+ ...state,
65
+ context: require_contexts_state.update(state.context, context)
66
+ });
67
+ };
68
+ const validate = (state) => {
69
+ const { value, error } = schema.validate(state);
70
+ if (error) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_BLOCK", `Invalid rollup block: ${error.details.map((x) => x.message).join(", ")}`);
71
+ if (!value.data) value.data = null;
72
+ return value;
73
+ };
74
+
75
+ //#endregion
76
+ exports.create = create;
77
+ Object.defineProperty(exports, 'rollup_block_exports', {
78
+ enumerable: true,
79
+ get: function () {
80
+ return rollup_block_exports;
81
+ }
82
+ });
83
+ exports.schema = schema;
84
+ exports.update = update;
85
+ exports.validate = validate;
@@ -0,0 +1,13 @@
1
+ import { StateContextInput } from "../contexts/state.cjs";
2
+ import { IRollupBlock } from "@ocap/types";
3
+
4
+ //#region src/states/rollup-block.d.ts
5
+ declare namespace rollup_block_d_exports {
6
+ export { create, schema, update, validate };
7
+ }
8
+ declare const schema: any;
9
+ declare const create: (attrs: Partial<IRollupBlock>, context: StateContextInput) => IRollupBlock;
10
+ declare const update: (state: IRollupBlock, context: StateContextInput) => IRollupBlock;
11
+ declare const validate: (state: IRollupBlock) => IRollupBlock;
12
+ //#endregion
13
+ export { create, rollup_block_d_exports, schema, update, validate };
@@ -0,0 +1,230 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_contexts_state = require('../contexts/state.cjs');
3
+ let _ocap_util = require("@ocap/util");
4
+ let _ocap_util_lib_error = require("@ocap/util/lib/error");
5
+ let lodash_pick = require("lodash/pick");
6
+ lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
7
+ let _arcblock_validator = require("@arcblock/validator");
8
+
9
+ //#region src/states/rollup.ts
10
+ var rollup_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
11
+ close: () => close,
12
+ create: () => create,
13
+ migrateContract: () => migrateContract,
14
+ migrateVault: () => migrateVault,
15
+ pause: () => pause,
16
+ resume: () => resume,
17
+ schema: () => schema,
18
+ update: () => update,
19
+ validate: () => validate
20
+ });
21
+ const validator = _arcblock_validator.Joi.object({
22
+ pk: _arcblock_validator.Joi.string().required(),
23
+ address: _arcblock_validator.Joi.DID().prefix().required(),
24
+ endpoint: _arcblock_validator.Joi.string().uri({ scheme: [/https?/] }).required()
25
+ });
26
+ const schema = _arcblock_validator.Joi.object({
27
+ address: _arcblock_validator.Joi.DID().prefix().role("ROLE_ROLLUP").required(),
28
+ tokenAddress: _arcblock_validator.Joi.DID().prefix().role("ROLE_TOKEN").required(),
29
+ contractAddress: _arcblock_validator.Joi.DID().prefix().wallet("ethereum").required(),
30
+ vaultAddress: _arcblock_validator.Joi.DID().wallet("ethereum").optional().allow(null).allow(""),
31
+ migrateHistory: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().wallet("ethereum")).default([]),
32
+ vaultHistory: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix().wallet("ethereum")).default([]),
33
+ paused: _arcblock_validator.Joi.boolean().default(false),
34
+ closed: _arcblock_validator.Joi.boolean().default(false),
35
+ seedValidators: _arcblock_validator.Joi.array().items(validator).min(1).required(),
36
+ validators: _arcblock_validator.Joi.array().items(validator).max(24).default([]),
37
+ minStakeAmount: _arcblock_validator.Joi.BN().positive().required(),
38
+ maxStakeAmount: _arcblock_validator.Joi.BN().min(_arcblock_validator.Joi.ref("minStakeAmount")).required(),
39
+ minSignerCount: _arcblock_validator.Joi.number().integer().min(_arcblock_validator.Joi.ref("seedValidators", { adjust: (v) => v.length })).required(),
40
+ maxSignerCount: _arcblock_validator.Joi.number().integer().min(1).max(8).min(_arcblock_validator.Joi.ref("minSignerCount")).required(),
41
+ minBlockSize: _arcblock_validator.Joi.number().integer().min(1).required(),
42
+ maxBlockSize: _arcblock_validator.Joi.number().integer().min(1).max(15).min(_arcblock_validator.Joi.ref("minBlockSize")).required(),
43
+ minBlockInterval: _arcblock_validator.Joi.number().integer().min(1).max(3600).required(),
44
+ minBlockConfirmation: _arcblock_validator.Joi.number().integer().min(1).max(100).required(),
45
+ minDepositAmount: _arcblock_validator.Joi.BN().positive().less(_arcblock_validator.Joi.ref("minStakeAmount")).required(),
46
+ maxDepositAmount: _arcblock_validator.Joi.BN().greater(_arcblock_validator.Joi.ref("minDepositAmount")).less(_arcblock_validator.Joi.ref("minStakeAmount")).required(),
47
+ minWithdrawAmount: _arcblock_validator.Joi.BN().positive().required(),
48
+ maxWithdrawAmount: _arcblock_validator.Joi.BN().greater(_arcblock_validator.Joi.ref("minWithdrawAmount")).required(),
49
+ depositFeeRate: _arcblock_validator.Joi.number().integer().min(0).max(1e4).required(),
50
+ withdrawFeeRate: _arcblock_validator.Joi.number().integer().min(0).max(1e4).required(),
51
+ proposerFeeShare: _arcblock_validator.Joi.number().integer().min(1).max(1e4).required(),
52
+ publisherFeeShare: _arcblock_validator.Joi.number().integer().min(1).max(1e4).required(),
53
+ minDepositFee: _arcblock_validator.Joi.BN().positive().required(),
54
+ maxDepositFee: _arcblock_validator.Joi.BN().min(_arcblock_validator.Joi.ref("minDepositFee")).required(),
55
+ minWithdrawFee: _arcblock_validator.Joi.BN().positive().required(),
56
+ maxWithdrawFee: _arcblock_validator.Joi.BN().min(_arcblock_validator.Joi.ref("minWithdrawFee")).required(),
57
+ blockHeight: _arcblock_validator.Joi.number().integer().min(0).required(),
58
+ blockHash: _arcblock_validator.Joi.string().regex(_arcblock_validator.patterns.txHash).optional().allow(null).allow(""),
59
+ issuer: _arcblock_validator.Joi.DID().prefix().optional().allow(null),
60
+ leaveWaitingPeriod: _arcblock_validator.Joi.number().integer().min(_arcblock_validator.Joi.ref("minBlockInterval")).default(0),
61
+ publishWaitingPeriod: _arcblock_validator.Joi.number().integer().min(_arcblock_validator.Joi.ref("minBlockInterval")).default(0),
62
+ publishSlashRate: _arcblock_validator.Joi.number().integer().min(1).max(1e4).required(),
63
+ context: _arcblock_validator.schemas.context,
64
+ data: _arcblock_validator.Joi.any().optional().allow(null)
65
+ }).options({
66
+ stripUnknown: true,
67
+ noDefaults: false
68
+ });
69
+ const create = (attrs, context) => {
70
+ const rollup = {
71
+ context: require_contexts_state.create(context),
72
+ paused: false,
73
+ closed: false,
74
+ migrateHistory: [],
75
+ vaultHistory: [],
76
+ blockHeight: 0,
77
+ blockHash: "",
78
+ ...(0, lodash_pick.default)(attrs, [
79
+ "address",
80
+ "tokenAddress",
81
+ "vaultAddress",
82
+ "contractAddress",
83
+ "seedValidators",
84
+ "validators",
85
+ "minStakeAmount",
86
+ "maxStakeAmount",
87
+ "minSignerCount",
88
+ "maxSignerCount",
89
+ "minBlockSize",
90
+ "maxBlockSize",
91
+ "minBlockInterval",
92
+ "minBlockConfirmation",
93
+ "minDepositAmount",
94
+ "maxDepositAmount",
95
+ "minWithdrawAmount",
96
+ "maxWithdrawAmount",
97
+ "depositFeeRate",
98
+ "withdrawFeeRate",
99
+ "proposerFeeShare",
100
+ "publisherFeeShare",
101
+ "minDepositFee",
102
+ "maxDepositFee",
103
+ "minWithdrawFee",
104
+ "maxWithdrawFee",
105
+ "leaveWaitingPeriod",
106
+ "publishWaitingPeriod",
107
+ "publishSlashRate",
108
+ "issuer",
109
+ "data"
110
+ ])
111
+ };
112
+ rollup.address = (0, _ocap_util.toAddress)(rollup.address);
113
+ return validate(rollup);
114
+ };
115
+ const update = (state, updates, context) => {
116
+ if (updates.blockHeight && !updates.blockHash) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHash must be updated together with blockHeight");
117
+ if (updates.blockHash && !updates.blockHeight) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHeight must be updated together with blockHash");
118
+ if (updates.blockHeight && updates.blockHash) {
119
+ if (updates.blockHeight !== state.blockHeight + 1) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHeight must be incremented");
120
+ if (updates.blockHash === state.blockHash) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHash can not remain unchanged between blocks");
121
+ }
122
+ if (typeof updates.blockHeight !== "undefined" && !updates.blockHeight) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHeight can not be unset");
123
+ if (typeof updates.blockHash !== "undefined" && !updates.blockHash) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_UPDATE", "blockHash can not be unset");
124
+ return validate({
125
+ ...state,
126
+ ...(0, lodash_pick.default)(updates, [
127
+ "validators",
128
+ "minStakeAmount",
129
+ "maxStakeAmount",
130
+ "minSignerCount",
131
+ "maxSignerCount",
132
+ "minBlockSize",
133
+ "maxBlockSize",
134
+ "minBlockInterval",
135
+ "minBlockConfirmation",
136
+ "minDepositAmount",
137
+ "maxDepositAmount",
138
+ "minWithdrawAmount",
139
+ "maxWithdrawAmount",
140
+ "depositFeeRate",
141
+ "withdrawFeeRate",
142
+ "publisherFeeShare",
143
+ "minDepositFee",
144
+ "maxDepositFee",
145
+ "minWithdrawFee",
146
+ "maxWithdrawFee",
147
+ "blockHeight",
148
+ "blockHash",
149
+ "leaveWaitingPeriod",
150
+ "publishWaitingPeriod",
151
+ "publishSlashRate",
152
+ "data"
153
+ ]),
154
+ context: require_contexts_state.update(state.context, context)
155
+ });
156
+ };
157
+ const pause = (state, context) => {
158
+ if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_PAUSE_ATTEMPT", "rollup already closed");
159
+ if (state.paused) throw new _ocap_util_lib_error.CustomError("INVALID_PAUSE_ATTEMPT", "rollup already paused");
160
+ return validate({
161
+ ...state,
162
+ paused: true,
163
+ context: require_contexts_state.update(state.context, context)
164
+ });
165
+ };
166
+ const close = (state, context) => {
167
+ if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_CLOSE_ATTEMPT", "rollup already closed");
168
+ if (!state.paused) throw new _ocap_util_lib_error.CustomError("INVALID_CLOSE_ATTEMPT", "rollup must be paused");
169
+ return validate({
170
+ ...state,
171
+ closed: true,
172
+ context: require_contexts_state.update(state.context, context)
173
+ });
174
+ };
175
+ const resume = (state, context) => {
176
+ if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_RESUME_ATTEMPT", "rollup is closed");
177
+ if (state.paused === false) throw new _ocap_util_lib_error.CustomError("INVALID_RESUME_ATTEMPT", "rollup not paused");
178
+ return validate({
179
+ ...state,
180
+ paused: false,
181
+ context: require_contexts_state.update(state.context, context)
182
+ });
183
+ };
184
+ const migrateContract = (state, to, context) => {
185
+ if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup is closed");
186
+ if (state.paused === false) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup not paused");
187
+ if (state.contractAddress === to) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate contract to self");
188
+ if (state.migrateHistory.includes(to)) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate contract to history contracts");
189
+ return validate({
190
+ ...state,
191
+ contractAddress: to,
192
+ migrateHistory: [...state.migrateHistory, state.contractAddress],
193
+ context: require_contexts_state.update(state.context, context)
194
+ });
195
+ };
196
+ const migrateVault = (state, to, context) => {
197
+ if (state.closed) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup is closed");
198
+ if (state.paused === false) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "rollup not paused");
199
+ if (state.vaultAddress === to) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate vault to self");
200
+ if (state.vaultHistory.includes(to)) throw new _ocap_util_lib_error.CustomError("INVALID_MIGRATE_ATTEMPT", "can not migrate vault to history vaults");
201
+ return validate({
202
+ ...state,
203
+ vaultAddress: to,
204
+ vaultHistory: [...state.vaultHistory, state.vaultAddress],
205
+ context: require_contexts_state.update(state.context, context)
206
+ });
207
+ };
208
+ const validate = (state) => {
209
+ const { value, error } = schema.validate(state);
210
+ if (error) throw new _ocap_util_lib_error.CustomError("INVALID_ROLLUP_PROPS", error.details.map((x) => x.message).join(", "));
211
+ if (!value.data) value.data = null;
212
+ return value;
213
+ };
214
+
215
+ //#endregion
216
+ exports.close = close;
217
+ exports.create = create;
218
+ exports.migrateContract = migrateContract;
219
+ exports.migrateVault = migrateVault;
220
+ exports.pause = pause;
221
+ exports.resume = resume;
222
+ Object.defineProperty(exports, 'rollup_exports', {
223
+ enumerable: true,
224
+ get: function () {
225
+ return rollup_exports;
226
+ }
227
+ });
228
+ exports.schema = schema;
229
+ exports.update = update;
230
+ exports.validate = validate;
@@ -0,0 +1,18 @@
1
+ import { StateContextInput } from "../contexts/state.cjs";
2
+ import { IRollupState } from "@ocap/types";
3
+
4
+ //#region src/states/rollup.d.ts
5
+ declare namespace rollup_d_exports {
6
+ export { close, create, migrateContract, migrateVault, pause, resume, schema, update, validate };
7
+ }
8
+ declare const schema: any;
9
+ declare const create: (attrs: Partial<IRollupState>, context: StateContextInput) => IRollupState;
10
+ declare const update: (state: IRollupState, updates: Partial<IRollupState>, context: StateContextInput) => IRollupState;
11
+ declare const pause: (state: IRollupState, context: StateContextInput) => IRollupState;
12
+ declare const close: (state: IRollupState, context: StateContextInput) => IRollupState;
13
+ declare const resume: (state: IRollupState, context: StateContextInput) => IRollupState;
14
+ declare const migrateContract: (state: IRollupState, to: string, context: StateContextInput) => IRollupState;
15
+ declare const migrateVault: (state: IRollupState, to: string, context: StateContextInput) => IRollupState;
16
+ declare const validate: (state: IRollupState) => IRollupState;
17
+ //#endregion
18
+ export { close, create, migrateContract, migrateVault, pause, resume, rollup_d_exports, schema, update, validate };