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