@ocap/config 1.28.8 → 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/default.d.mts +6 -0
- package/esm/default.mjs +159 -0
- package/esm/index.d.mts +8 -0
- package/esm/index.mjs +65 -0
- package/esm/schema.d.mts +4 -0
- package/esm/schema.mjs +77 -0
- package/esm/types.d.mts +2 -0
- package/esm/types.mjs +1 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/default.cjs +161 -0
- package/lib/default.d.cts +6 -0
- package/lib/index.cjs +71 -0
- package/lib/index.d.cts +8 -0
- package/lib/schema.cjs +79 -0
- package/lib/schema.d.cts +4 -0
- package/lib/types.cjs +0 -0
- package/lib/types.d.cts +2 -0
- package/package.json +32 -8
- package/lib/default.js +0 -156
- package/lib/index.js +0 -83
- package/lib/schema.js +0 -87
package/esm/default.mjs
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
//#region src/default.ts
|
|
2
|
+
const defaultConfig = {
|
|
3
|
+
transaction: {
|
|
4
|
+
maxAssetSize: 65536,
|
|
5
|
+
maxListSize: 8,
|
|
6
|
+
maxMultisig: 8,
|
|
7
|
+
maxTxSize: {
|
|
8
|
+
default: 65535,
|
|
9
|
+
"fg:t:account_migrate": 1691,
|
|
10
|
+
"fg:t:create_asset": 65881,
|
|
11
|
+
"fg:t:create_factory": 65881,
|
|
12
|
+
"fg:t:exchange_v2": 1691,
|
|
13
|
+
"fg:t:transfer": 664,
|
|
14
|
+
"fg:t:transfer_v2": 664,
|
|
15
|
+
"fg:t:transfer_v3": 4096,
|
|
16
|
+
"fg:t:update_asset": 65881,
|
|
17
|
+
"fg:t:consume_asset": 1691,
|
|
18
|
+
"fg:t:acquire_asset_v2": 4096,
|
|
19
|
+
"fg:t:acquire_asset_v3": 4096,
|
|
20
|
+
"fg:t:mint_asset": 4096,
|
|
21
|
+
"fg:t:create_token": 664,
|
|
22
|
+
"fg:t:deposit_token_v2": 1691,
|
|
23
|
+
"fg:t:withdraw_token_v2": 1691,
|
|
24
|
+
"fg:t:stake": 4096,
|
|
25
|
+
"fg:t:revoke_stake": 4096,
|
|
26
|
+
"fg:t:claim_stake": 664,
|
|
27
|
+
"fg:t:slash_stake": 4096,
|
|
28
|
+
"fg:t:return_stake": 4096,
|
|
29
|
+
"fg:t:create_rollup": 1691,
|
|
30
|
+
"fg:t:update_rollup": 1691,
|
|
31
|
+
"fg:t:pause_rollup": 1691,
|
|
32
|
+
"fg:t:resume_rollup": 1691,
|
|
33
|
+
"fg:t:close_rollup": 1691,
|
|
34
|
+
"fg:t:join_rollup": 1691,
|
|
35
|
+
"fg:t:leave_rollup": 1691,
|
|
36
|
+
"fg:t:migrate_rollup": 1691,
|
|
37
|
+
"fg:t:create_rollup_block": 4096,
|
|
38
|
+
"fg:t:claim_block_reward": 1691,
|
|
39
|
+
"fg:t:mint_token": 4096,
|
|
40
|
+
"fg:t:burn_token": 4096,
|
|
41
|
+
"fg:t:create_token_factory": Math.floor(20480),
|
|
42
|
+
"fg:t:update_token_factory": Math.floor(18075)
|
|
43
|
+
},
|
|
44
|
+
txFee: {
|
|
45
|
+
default: 0,
|
|
46
|
+
"fg:t:create_asset": 1,
|
|
47
|
+
"fg:t:mint_asset": 1,
|
|
48
|
+
"fg:t:update_token_factory": 100,
|
|
49
|
+
"fg:t:create_factory": 100,
|
|
50
|
+
"fg:t:create_token": 1e3,
|
|
51
|
+
"fg:t:create_rollup": 1e4
|
|
52
|
+
},
|
|
53
|
+
txGas: {
|
|
54
|
+
price: 1e8,
|
|
55
|
+
createState: 1e6,
|
|
56
|
+
updateState: 1e4,
|
|
57
|
+
dataStorage: 100,
|
|
58
|
+
minStake: 1,
|
|
59
|
+
maxStake: 1e4,
|
|
60
|
+
stakeLockPeriod: 365 * 24 * 60 * 60
|
|
61
|
+
},
|
|
62
|
+
txStake: {
|
|
63
|
+
createToken: 100,
|
|
64
|
+
createCreditToken: 100,
|
|
65
|
+
createTokenLockPeriod: 1440 * 60
|
|
66
|
+
},
|
|
67
|
+
delegate: {
|
|
68
|
+
deltaInterval: 18e3,
|
|
69
|
+
typeUrls: [
|
|
70
|
+
"fg:t:transfer",
|
|
71
|
+
"fg:t:transfer_v2",
|
|
72
|
+
"fg:t:exchange_v2",
|
|
73
|
+
"fg:t:acquire_asset_v2",
|
|
74
|
+
"fg:t:create_asset",
|
|
75
|
+
"fg:t:create_factory",
|
|
76
|
+
"fg:t:create_token",
|
|
77
|
+
"fg:t:create_rollup",
|
|
78
|
+
"fg:t:create_token_factory",
|
|
79
|
+
"fg:t:update_token_factory"
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
supportedTxs: [
|
|
83
|
+
"fg:t:transfer",
|
|
84
|
+
"fg:t:transfer_v2",
|
|
85
|
+
"fg:t:transfer_v3",
|
|
86
|
+
"fg:t:exchange_v2",
|
|
87
|
+
"fg:t:account_migrate",
|
|
88
|
+
"fg:t:delegate",
|
|
89
|
+
"fg:t:revoke_delegate",
|
|
90
|
+
"fg:t:create_asset",
|
|
91
|
+
"fg:t:update_asset",
|
|
92
|
+
"fg:t:consume_asset",
|
|
93
|
+
"fg:t:create_factory",
|
|
94
|
+
"fg:t:acquire_asset_v2",
|
|
95
|
+
"fg:t:acquire_asset_v3",
|
|
96
|
+
"fg:t:mint_asset",
|
|
97
|
+
"fg:t:create_token",
|
|
98
|
+
"fg:t:deposit_token_v2",
|
|
99
|
+
"fg:t:withdraw_token_v2",
|
|
100
|
+
"fg:t:stake",
|
|
101
|
+
"fg:t:revoke_stake",
|
|
102
|
+
"fg:t:claim_stake",
|
|
103
|
+
"fg:t:slash_stake",
|
|
104
|
+
"fg:t:return_stake",
|
|
105
|
+
"fg:t:create_rollup",
|
|
106
|
+
"fg:t:update_rollup",
|
|
107
|
+
"fg:t:pause_rollup",
|
|
108
|
+
"fg:t:close_rollup",
|
|
109
|
+
"fg:t:resume_rollup",
|
|
110
|
+
"fg:t:join_rollup",
|
|
111
|
+
"fg:t:leave_rollup",
|
|
112
|
+
"fg:t:create_rollup_block",
|
|
113
|
+
"fg:t:migrate_rollup",
|
|
114
|
+
"fg:t:claim_block_reward",
|
|
115
|
+
"fg:t:create_token_factory",
|
|
116
|
+
"fg:t:update_token_factory",
|
|
117
|
+
"fg:t:mint_token",
|
|
118
|
+
"fg:t:burn_token"
|
|
119
|
+
],
|
|
120
|
+
multiSignV2Txs: [
|
|
121
|
+
"fg:t:transfer_v3",
|
|
122
|
+
"fg:t:acquire_asset_v3",
|
|
123
|
+
"fg:t:stake",
|
|
124
|
+
"fg:t:join_rollup",
|
|
125
|
+
"fg:t:leave_rollup",
|
|
126
|
+
"fg:t:update_rollup",
|
|
127
|
+
"fg:t:pause_rollup",
|
|
128
|
+
"fg:t:resume_rollup",
|
|
129
|
+
"fg:t:close_rollup",
|
|
130
|
+
"fg:t:deposit_token_v2",
|
|
131
|
+
"fg:t:withdraw_token_v2",
|
|
132
|
+
"fg:t:create_rollup_block",
|
|
133
|
+
"fg:t:migrate_rollup",
|
|
134
|
+
"fg:t:claim_block_reward",
|
|
135
|
+
"fg:t:create_asset",
|
|
136
|
+
"fg:t:consume_asset",
|
|
137
|
+
"fg:t:mint_token",
|
|
138
|
+
"fg:t:burn_token"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
vaults: {},
|
|
142
|
+
accounts: [],
|
|
143
|
+
reservedSymbols: ["TBA"],
|
|
144
|
+
token: {
|
|
145
|
+
name: "TestChainToken",
|
|
146
|
+
decimal: 18,
|
|
147
|
+
symbol: "TBA",
|
|
148
|
+
unit: "arc",
|
|
149
|
+
description: "Token on ArcBlock Test Chain",
|
|
150
|
+
icon: "",
|
|
151
|
+
initialSupply: 1e9,
|
|
152
|
+
totalSupply: 1e9,
|
|
153
|
+
inflationRate: 0
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var default_default = defaultConfig;
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
export { default_default as default };
|
package/esm/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAccountConfig, IChainConfig, IChainConfigInput, IDefaultConfig, ITokenConfig, ITokenItx, ITransactionConfig, ITxGasConfig, ITxStakeConfig, IVaultsConfig, TDelegateConfig, TForeignToken, TxTypeMap, TxTypeUrl } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const validate: (config: Partial<IChainConfig>) => IChainConfig;
|
|
5
|
+
declare const create: (props: IChainConfigInput) => IChainConfig;
|
|
6
|
+
declare const genTokenItx: (config: IChainConfig) => ITokenItx;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { IAccountConfig, IChainConfig, IChainConfigInput, IDefaultConfig, ITokenConfig, ITokenItx, ITransactionConfig, ITxGasConfig, ITxStakeConfig, IVaultsConfig, TDelegateConfig, TForeignToken, TxTypeMap, TxTypeUrl, create, genTokenItx, validate };
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import default_default from "./default.mjs";
|
|
2
|
+
import schema_default from "./schema.mjs";
|
|
3
|
+
import { isValid, toTypeInfoStr } from "@arcblock/did";
|
|
4
|
+
import { toTokenAddress } from "@arcblock/did-util";
|
|
5
|
+
import { fromTokenToUnit } from "@ocap/util";
|
|
6
|
+
import flatten from "lodash/flatten.js";
|
|
7
|
+
import merge from "lodash/merge.js";
|
|
8
|
+
import pick from "lodash/pick.js";
|
|
9
|
+
|
|
10
|
+
//#region src/index.ts
|
|
11
|
+
const validate = (config) => {
|
|
12
|
+
const { value, error } = schema_default.validate(config);
|
|
13
|
+
if (error) throw new Error(`Invalid config: ${error.details.map((x) => x.message).join(", ")}`);
|
|
14
|
+
const { vaults, transaction, accounts } = value;
|
|
15
|
+
if (flatten(Object.values(vaults)).some((a) => !accounts.find((x) => x.address === a))) throw new Error("Invalid config: vault address does not exist in accounts");
|
|
16
|
+
if (transaction.txGas.price > 0 && (!vaults.txGas || !vaults.txGas.length)) throw new Error("Invalid config: vaults.txGas can not be empty when gas enabled");
|
|
17
|
+
if (Object.keys(transaction.txFee).some((x) => transaction.txFee[x] > 0) && !vaults.txFee) throw new Error("Invalid config: vaults.txFee can not be empty when there are paid transactions");
|
|
18
|
+
if (vaults.txFee && vaults.txGas && vaults.txGas.includes(vaults.txFee)) throw new Error("Invalid config: vaults.txFee can not contain same address with vaults.txGas");
|
|
19
|
+
if (!vaults.slashedStake) throw new Error("Invalid config: vaults.slashedStake must be a valid DID");
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
const create = (props) => {
|
|
23
|
+
return validate(merge({}, default_default, props));
|
|
24
|
+
};
|
|
25
|
+
const genTokenItx = (config) => {
|
|
26
|
+
const { token, moderator } = config;
|
|
27
|
+
const itx = {
|
|
28
|
+
name: token.name,
|
|
29
|
+
description: token.description,
|
|
30
|
+
symbol: token.symbol,
|
|
31
|
+
unit: token.unit,
|
|
32
|
+
decimal: token.decimal,
|
|
33
|
+
icon: token.icon,
|
|
34
|
+
totalSupply: fromTokenToUnit(token.totalSupply, token.decimal).toString(),
|
|
35
|
+
initialSupply: fromTokenToUnit(token.initialSupply || token.totalSupply, token.decimal).toString(),
|
|
36
|
+
issuer: moderator.address,
|
|
37
|
+
address: "",
|
|
38
|
+
foreignToken: token.foreignToken,
|
|
39
|
+
metadata: token.metadata,
|
|
40
|
+
website: token.website
|
|
41
|
+
};
|
|
42
|
+
const legacyAddr = process.env.CHAIN_TOKEN_ADDRESS;
|
|
43
|
+
if (legacyAddr && isValid(legacyAddr) && toTypeInfoStr(legacyAddr).role === "ROLE_TOKEN") itx.address = legacyAddr;
|
|
44
|
+
else {
|
|
45
|
+
const { foreignToken, ...rest } = pick(itx, [
|
|
46
|
+
"name",
|
|
47
|
+
"description",
|
|
48
|
+
"symbol",
|
|
49
|
+
"unit",
|
|
50
|
+
"decimal",
|
|
51
|
+
"totalSupply",
|
|
52
|
+
"initialSupply",
|
|
53
|
+
"issuer",
|
|
54
|
+
"foreignToken"
|
|
55
|
+
]);
|
|
56
|
+
itx.address = toTokenAddress({
|
|
57
|
+
...rest,
|
|
58
|
+
foreignToken: foreignToken ?? void 0
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return itx;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { create, genTokenItx, validate };
|
package/esm/schema.d.mts
ADDED
package/esm/schema.mjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import default_default from "./default.mjs";
|
|
2
|
+
import { Joi } from "@arcblock/validator";
|
|
3
|
+
|
|
4
|
+
//#region src/schema.ts
|
|
5
|
+
const accountSchema = {
|
|
6
|
+
address: Joi.DID().prefix().required(),
|
|
7
|
+
pk: Joi.string().allow("").required(),
|
|
8
|
+
balance: Joi.number().optional().default(0),
|
|
9
|
+
moniker: Joi.string().optional().allow("")
|
|
10
|
+
};
|
|
11
|
+
const configSchema = Joi.object({
|
|
12
|
+
chainId: Joi.string().min(1).required(),
|
|
13
|
+
version: Joi.string().min(1).required(),
|
|
14
|
+
transaction: Joi.object({
|
|
15
|
+
maxAssetSize: Joi.number().positive().required(),
|
|
16
|
+
maxListSize: Joi.number().positive().required(),
|
|
17
|
+
maxMultisig: Joi.number().positive().required(),
|
|
18
|
+
maxTxSize: Joi.object().pattern(Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), Joi.number().integer().greater(0)).required(),
|
|
19
|
+
delegate: Joi.object({
|
|
20
|
+
deltaInterval: Joi.number().positive(),
|
|
21
|
+
typeUrls: Joi.array().items(Joi.string())
|
|
22
|
+
}).required(),
|
|
23
|
+
supportedTxs: Joi.array().items(Joi.string()).min(1).required(),
|
|
24
|
+
multiSignV2Txs: Joi.array().items(Joi.string()).min(1).required(),
|
|
25
|
+
txFee: Joi.object().pattern(Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), Joi.number().precision(6).min(0)).required(),
|
|
26
|
+
txGas: Joi.object({
|
|
27
|
+
price: Joi.number().integer().min(0).required(),
|
|
28
|
+
createState: Joi.number().integer().min(1).required(),
|
|
29
|
+
updateState: Joi.number().integer().min(1).required(),
|
|
30
|
+
dataStorage: Joi.number().integer().min(1).required(),
|
|
31
|
+
minStake: Joi.number().integer().min(1).required(),
|
|
32
|
+
maxStake: Joi.number().integer().min(1).required(),
|
|
33
|
+
stakeLockPeriod: Joi.number().integer().min(1).required()
|
|
34
|
+
}).optional(),
|
|
35
|
+
txStake: Joi.object({
|
|
36
|
+
createToken: Joi.number().integer().min(1).required(),
|
|
37
|
+
createCreditToken: Joi.number().integer().min(0).required(),
|
|
38
|
+
createTokenLockPeriod: Joi.number().integer().min(1).required()
|
|
39
|
+
}).optional()
|
|
40
|
+
}).optional().default(default_default.transaction),
|
|
41
|
+
moderator: Joi.object(accountSchema).required(),
|
|
42
|
+
accounts: Joi.array().items(accountSchema).required(),
|
|
43
|
+
vaults: Joi.object({
|
|
44
|
+
slashedStake: Joi.DID().prefix().required(),
|
|
45
|
+
txFee: Joi.DID().prefix(),
|
|
46
|
+
txFees: Joi.array().items(Joi.DID().prefix()),
|
|
47
|
+
txGas: Joi.array().items(Joi.DID().prefix())
|
|
48
|
+
}).default({}),
|
|
49
|
+
token: Joi.object({
|
|
50
|
+
name: Joi.string().required(),
|
|
51
|
+
description: Joi.string().required(),
|
|
52
|
+
symbol: Joi.string().required(),
|
|
53
|
+
unit: Joi.string().required(),
|
|
54
|
+
decimal: Joi.number().positive().required(),
|
|
55
|
+
icon: Joi.string().required().allow(""),
|
|
56
|
+
initialSupply: Joi.number().positive().required(),
|
|
57
|
+
totalSupply: Joi.number().positive().required(),
|
|
58
|
+
inflationRate: Joi.number().required(),
|
|
59
|
+
website: Joi.string().uri({
|
|
60
|
+
scheme: ["https"],
|
|
61
|
+
allowRelative: false
|
|
62
|
+
}).max(256).optional().allow(null, ""),
|
|
63
|
+
metadata: Joi.any().optional().allow(null),
|
|
64
|
+
foreignToken: Joi.object({
|
|
65
|
+
type: Joi.string().min(1).max(32).required(),
|
|
66
|
+
contractAddress: Joi.string().required(),
|
|
67
|
+
chainType: Joi.string().min(1).max(32).required(),
|
|
68
|
+
chainName: Joi.string().min(1).max(32).required(),
|
|
69
|
+
chainId: Joi.number().positive().required()
|
|
70
|
+
}).optional().allow(null)
|
|
71
|
+
}).optional().default(default_default.token),
|
|
72
|
+
reservedSymbols: Joi.array().items(Joi.string()).optional()
|
|
73
|
+
}).options({ stripUnknown: true });
|
|
74
|
+
var schema_default = configSchema;
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { schema_default as default };
|
package/esm/types.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { IAccountConfig, IChainConfig, IChainConfigInput, IDefaultConfig, ITokenConfig, ITokenItx, ITransactionConfig, ITxGasConfig, ITxStakeConfig, IVaultsConfig, TDelegateConfig, TForeignToken, TxTypeMap, TxTypeUrl } from "@ocap/types";
|
|
2
|
+
export { type IAccountConfig, type IChainConfig, type IChainConfigInput, type IDefaultConfig, type ITokenConfig, type ITokenItx, type ITransactionConfig, type ITxGasConfig, type ITxStakeConfig, type IVaultsConfig, type TDelegateConfig, type TForeignToken, type TxTypeMap, type TxTypeUrl };
|
package/esm/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/lib/default.cjs
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
//#region src/default.ts
|
|
4
|
+
const defaultConfig = {
|
|
5
|
+
transaction: {
|
|
6
|
+
maxAssetSize: 65536,
|
|
7
|
+
maxListSize: 8,
|
|
8
|
+
maxMultisig: 8,
|
|
9
|
+
maxTxSize: {
|
|
10
|
+
default: 65535,
|
|
11
|
+
"fg:t:account_migrate": 1691,
|
|
12
|
+
"fg:t:create_asset": 65881,
|
|
13
|
+
"fg:t:create_factory": 65881,
|
|
14
|
+
"fg:t:exchange_v2": 1691,
|
|
15
|
+
"fg:t:transfer": 664,
|
|
16
|
+
"fg:t:transfer_v2": 664,
|
|
17
|
+
"fg:t:transfer_v3": 4096,
|
|
18
|
+
"fg:t:update_asset": 65881,
|
|
19
|
+
"fg:t:consume_asset": 1691,
|
|
20
|
+
"fg:t:acquire_asset_v2": 4096,
|
|
21
|
+
"fg:t:acquire_asset_v3": 4096,
|
|
22
|
+
"fg:t:mint_asset": 4096,
|
|
23
|
+
"fg:t:create_token": 664,
|
|
24
|
+
"fg:t:deposit_token_v2": 1691,
|
|
25
|
+
"fg:t:withdraw_token_v2": 1691,
|
|
26
|
+
"fg:t:stake": 4096,
|
|
27
|
+
"fg:t:revoke_stake": 4096,
|
|
28
|
+
"fg:t:claim_stake": 664,
|
|
29
|
+
"fg:t:slash_stake": 4096,
|
|
30
|
+
"fg:t:return_stake": 4096,
|
|
31
|
+
"fg:t:create_rollup": 1691,
|
|
32
|
+
"fg:t:update_rollup": 1691,
|
|
33
|
+
"fg:t:pause_rollup": 1691,
|
|
34
|
+
"fg:t:resume_rollup": 1691,
|
|
35
|
+
"fg:t:close_rollup": 1691,
|
|
36
|
+
"fg:t:join_rollup": 1691,
|
|
37
|
+
"fg:t:leave_rollup": 1691,
|
|
38
|
+
"fg:t:migrate_rollup": 1691,
|
|
39
|
+
"fg:t:create_rollup_block": 4096,
|
|
40
|
+
"fg:t:claim_block_reward": 1691,
|
|
41
|
+
"fg:t:mint_token": 4096,
|
|
42
|
+
"fg:t:burn_token": 4096,
|
|
43
|
+
"fg:t:create_token_factory": Math.floor(20480),
|
|
44
|
+
"fg:t:update_token_factory": Math.floor(18075)
|
|
45
|
+
},
|
|
46
|
+
txFee: {
|
|
47
|
+
default: 0,
|
|
48
|
+
"fg:t:create_asset": 1,
|
|
49
|
+
"fg:t:mint_asset": 1,
|
|
50
|
+
"fg:t:update_token_factory": 100,
|
|
51
|
+
"fg:t:create_factory": 100,
|
|
52
|
+
"fg:t:create_token": 1e3,
|
|
53
|
+
"fg:t:create_rollup": 1e4
|
|
54
|
+
},
|
|
55
|
+
txGas: {
|
|
56
|
+
price: 1e8,
|
|
57
|
+
createState: 1e6,
|
|
58
|
+
updateState: 1e4,
|
|
59
|
+
dataStorage: 100,
|
|
60
|
+
minStake: 1,
|
|
61
|
+
maxStake: 1e4,
|
|
62
|
+
stakeLockPeriod: 365 * 24 * 60 * 60
|
|
63
|
+
},
|
|
64
|
+
txStake: {
|
|
65
|
+
createToken: 100,
|
|
66
|
+
createCreditToken: 100,
|
|
67
|
+
createTokenLockPeriod: 1440 * 60
|
|
68
|
+
},
|
|
69
|
+
delegate: {
|
|
70
|
+
deltaInterval: 18e3,
|
|
71
|
+
typeUrls: [
|
|
72
|
+
"fg:t:transfer",
|
|
73
|
+
"fg:t:transfer_v2",
|
|
74
|
+
"fg:t:exchange_v2",
|
|
75
|
+
"fg:t:acquire_asset_v2",
|
|
76
|
+
"fg:t:create_asset",
|
|
77
|
+
"fg:t:create_factory",
|
|
78
|
+
"fg:t:create_token",
|
|
79
|
+
"fg:t:create_rollup",
|
|
80
|
+
"fg:t:create_token_factory",
|
|
81
|
+
"fg:t:update_token_factory"
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
supportedTxs: [
|
|
85
|
+
"fg:t:transfer",
|
|
86
|
+
"fg:t:transfer_v2",
|
|
87
|
+
"fg:t:transfer_v3",
|
|
88
|
+
"fg:t:exchange_v2",
|
|
89
|
+
"fg:t:account_migrate",
|
|
90
|
+
"fg:t:delegate",
|
|
91
|
+
"fg:t:revoke_delegate",
|
|
92
|
+
"fg:t:create_asset",
|
|
93
|
+
"fg:t:update_asset",
|
|
94
|
+
"fg:t:consume_asset",
|
|
95
|
+
"fg:t:create_factory",
|
|
96
|
+
"fg:t:acquire_asset_v2",
|
|
97
|
+
"fg:t:acquire_asset_v3",
|
|
98
|
+
"fg:t:mint_asset",
|
|
99
|
+
"fg:t:create_token",
|
|
100
|
+
"fg:t:deposit_token_v2",
|
|
101
|
+
"fg:t:withdraw_token_v2",
|
|
102
|
+
"fg:t:stake",
|
|
103
|
+
"fg:t:revoke_stake",
|
|
104
|
+
"fg:t:claim_stake",
|
|
105
|
+
"fg:t:slash_stake",
|
|
106
|
+
"fg:t:return_stake",
|
|
107
|
+
"fg:t:create_rollup",
|
|
108
|
+
"fg:t:update_rollup",
|
|
109
|
+
"fg:t:pause_rollup",
|
|
110
|
+
"fg:t:close_rollup",
|
|
111
|
+
"fg:t:resume_rollup",
|
|
112
|
+
"fg:t:join_rollup",
|
|
113
|
+
"fg:t:leave_rollup",
|
|
114
|
+
"fg:t:create_rollup_block",
|
|
115
|
+
"fg:t:migrate_rollup",
|
|
116
|
+
"fg:t:claim_block_reward",
|
|
117
|
+
"fg:t:create_token_factory",
|
|
118
|
+
"fg:t:update_token_factory",
|
|
119
|
+
"fg:t:mint_token",
|
|
120
|
+
"fg:t:burn_token"
|
|
121
|
+
],
|
|
122
|
+
multiSignV2Txs: [
|
|
123
|
+
"fg:t:transfer_v3",
|
|
124
|
+
"fg:t:acquire_asset_v3",
|
|
125
|
+
"fg:t:stake",
|
|
126
|
+
"fg:t:join_rollup",
|
|
127
|
+
"fg:t:leave_rollup",
|
|
128
|
+
"fg:t:update_rollup",
|
|
129
|
+
"fg:t:pause_rollup",
|
|
130
|
+
"fg:t:resume_rollup",
|
|
131
|
+
"fg:t:close_rollup",
|
|
132
|
+
"fg:t:deposit_token_v2",
|
|
133
|
+
"fg:t:withdraw_token_v2",
|
|
134
|
+
"fg:t:create_rollup_block",
|
|
135
|
+
"fg:t:migrate_rollup",
|
|
136
|
+
"fg:t:claim_block_reward",
|
|
137
|
+
"fg:t:create_asset",
|
|
138
|
+
"fg:t:consume_asset",
|
|
139
|
+
"fg:t:mint_token",
|
|
140
|
+
"fg:t:burn_token"
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
vaults: {},
|
|
144
|
+
accounts: [],
|
|
145
|
+
reservedSymbols: ["TBA"],
|
|
146
|
+
token: {
|
|
147
|
+
name: "TestChainToken",
|
|
148
|
+
decimal: 18,
|
|
149
|
+
symbol: "TBA",
|
|
150
|
+
unit: "arc",
|
|
151
|
+
description: "Token on ArcBlock Test Chain",
|
|
152
|
+
icon: "",
|
|
153
|
+
initialSupply: 1e9,
|
|
154
|
+
totalSupply: 1e9,
|
|
155
|
+
inflationRate: 0
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var default_default = defaultConfig;
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
exports.default = default_default;
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_default = require('./default.cjs');
|
|
3
|
+
const require_schema = require('./schema.cjs');
|
|
4
|
+
let _arcblock_did = require("@arcblock/did");
|
|
5
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
6
|
+
let _ocap_util = require("@ocap/util");
|
|
7
|
+
let lodash_flatten = require("lodash/flatten");
|
|
8
|
+
lodash_flatten = require_rolldown_runtime.__toESM(lodash_flatten);
|
|
9
|
+
let lodash_merge = require("lodash/merge");
|
|
10
|
+
lodash_merge = require_rolldown_runtime.__toESM(lodash_merge);
|
|
11
|
+
let lodash_pick = require("lodash/pick");
|
|
12
|
+
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
13
|
+
|
|
14
|
+
//#region src/index.ts
|
|
15
|
+
const validate = (config) => {
|
|
16
|
+
const { value, error } = require_schema.default.validate(config);
|
|
17
|
+
if (error) throw new Error(`Invalid config: ${error.details.map((x) => x.message).join(", ")}`);
|
|
18
|
+
const { vaults, transaction, accounts } = value;
|
|
19
|
+
if ((0, lodash_flatten.default)(Object.values(vaults)).some((a) => !accounts.find((x) => x.address === a))) throw new Error("Invalid config: vault address does not exist in accounts");
|
|
20
|
+
if (transaction.txGas.price > 0 && (!vaults.txGas || !vaults.txGas.length)) throw new Error("Invalid config: vaults.txGas can not be empty when gas enabled");
|
|
21
|
+
if (Object.keys(transaction.txFee).some((x) => transaction.txFee[x] > 0) && !vaults.txFee) throw new Error("Invalid config: vaults.txFee can not be empty when there are paid transactions");
|
|
22
|
+
if (vaults.txFee && vaults.txGas && vaults.txGas.includes(vaults.txFee)) throw new Error("Invalid config: vaults.txFee can not contain same address with vaults.txGas");
|
|
23
|
+
if (!vaults.slashedStake) throw new Error("Invalid config: vaults.slashedStake must be a valid DID");
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
const create = (props) => {
|
|
27
|
+
return validate((0, lodash_merge.default)({}, require_default.default, props));
|
|
28
|
+
};
|
|
29
|
+
const genTokenItx = (config) => {
|
|
30
|
+
const { token, moderator } = config;
|
|
31
|
+
const itx = {
|
|
32
|
+
name: token.name,
|
|
33
|
+
description: token.description,
|
|
34
|
+
symbol: token.symbol,
|
|
35
|
+
unit: token.unit,
|
|
36
|
+
decimal: token.decimal,
|
|
37
|
+
icon: token.icon,
|
|
38
|
+
totalSupply: (0, _ocap_util.fromTokenToUnit)(token.totalSupply, token.decimal).toString(),
|
|
39
|
+
initialSupply: (0, _ocap_util.fromTokenToUnit)(token.initialSupply || token.totalSupply, token.decimal).toString(),
|
|
40
|
+
issuer: moderator.address,
|
|
41
|
+
address: "",
|
|
42
|
+
foreignToken: token.foreignToken,
|
|
43
|
+
metadata: token.metadata,
|
|
44
|
+
website: token.website
|
|
45
|
+
};
|
|
46
|
+
const legacyAddr = process.env.CHAIN_TOKEN_ADDRESS;
|
|
47
|
+
if (legacyAddr && (0, _arcblock_did.isValid)(legacyAddr) && (0, _arcblock_did.toTypeInfoStr)(legacyAddr).role === "ROLE_TOKEN") itx.address = legacyAddr;
|
|
48
|
+
else {
|
|
49
|
+
const { foreignToken, ...rest } = (0, lodash_pick.default)(itx, [
|
|
50
|
+
"name",
|
|
51
|
+
"description",
|
|
52
|
+
"symbol",
|
|
53
|
+
"unit",
|
|
54
|
+
"decimal",
|
|
55
|
+
"totalSupply",
|
|
56
|
+
"initialSupply",
|
|
57
|
+
"issuer",
|
|
58
|
+
"foreignToken"
|
|
59
|
+
]);
|
|
60
|
+
itx.address = (0, _arcblock_did_util.toTokenAddress)({
|
|
61
|
+
...rest,
|
|
62
|
+
foreignToken: foreignToken ?? void 0
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return itx;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.create = create;
|
|
70
|
+
exports.genTokenItx = genTokenItx;
|
|
71
|
+
exports.validate = validate;
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAccountConfig, IChainConfig, IChainConfigInput, IDefaultConfig, ITokenConfig, ITokenItx, ITransactionConfig, ITxGasConfig, ITxStakeConfig, IVaultsConfig, TDelegateConfig, TForeignToken, TxTypeMap, TxTypeUrl } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const validate: (config: Partial<IChainConfig>) => IChainConfig;
|
|
5
|
+
declare const create: (props: IChainConfigInput) => IChainConfig;
|
|
6
|
+
declare const genTokenItx: (config: IChainConfig) => ITokenItx;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { IAccountConfig, IChainConfig, IChainConfigInput, IDefaultConfig, ITokenConfig, ITokenItx, ITransactionConfig, ITxGasConfig, ITxStakeConfig, IVaultsConfig, TDelegateConfig, TForeignToken, TxTypeMap, TxTypeUrl, create, genTokenItx, validate };
|
package/lib/schema.cjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_default = require('./default.cjs');
|
|
4
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
5
|
+
|
|
6
|
+
//#region src/schema.ts
|
|
7
|
+
const accountSchema = {
|
|
8
|
+
address: _arcblock_validator.Joi.DID().prefix().required(),
|
|
9
|
+
pk: _arcblock_validator.Joi.string().allow("").required(),
|
|
10
|
+
balance: _arcblock_validator.Joi.number().optional().default(0),
|
|
11
|
+
moniker: _arcblock_validator.Joi.string().optional().allow("")
|
|
12
|
+
};
|
|
13
|
+
const configSchema = _arcblock_validator.Joi.object({
|
|
14
|
+
chainId: _arcblock_validator.Joi.string().min(1).required(),
|
|
15
|
+
version: _arcblock_validator.Joi.string().min(1).required(),
|
|
16
|
+
transaction: _arcblock_validator.Joi.object({
|
|
17
|
+
maxAssetSize: _arcblock_validator.Joi.number().positive().required(),
|
|
18
|
+
maxListSize: _arcblock_validator.Joi.number().positive().required(),
|
|
19
|
+
maxMultisig: _arcblock_validator.Joi.number().positive().required(),
|
|
20
|
+
maxTxSize: _arcblock_validator.Joi.object().pattern(_arcblock_validator.Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), _arcblock_validator.Joi.number().integer().greater(0)).required(),
|
|
21
|
+
delegate: _arcblock_validator.Joi.object({
|
|
22
|
+
deltaInterval: _arcblock_validator.Joi.number().positive(),
|
|
23
|
+
typeUrls: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.string())
|
|
24
|
+
}).required(),
|
|
25
|
+
supportedTxs: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.string()).min(1).required(),
|
|
26
|
+
multiSignV2Txs: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.string()).min(1).required(),
|
|
27
|
+
txFee: _arcblock_validator.Joi.object().pattern(_arcblock_validator.Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), _arcblock_validator.Joi.number().precision(6).min(0)).required(),
|
|
28
|
+
txGas: _arcblock_validator.Joi.object({
|
|
29
|
+
price: _arcblock_validator.Joi.number().integer().min(0).required(),
|
|
30
|
+
createState: _arcblock_validator.Joi.number().integer().min(1).required(),
|
|
31
|
+
updateState: _arcblock_validator.Joi.number().integer().min(1).required(),
|
|
32
|
+
dataStorage: _arcblock_validator.Joi.number().integer().min(1).required(),
|
|
33
|
+
minStake: _arcblock_validator.Joi.number().integer().min(1).required(),
|
|
34
|
+
maxStake: _arcblock_validator.Joi.number().integer().min(1).required(),
|
|
35
|
+
stakeLockPeriod: _arcblock_validator.Joi.number().integer().min(1).required()
|
|
36
|
+
}).optional(),
|
|
37
|
+
txStake: _arcblock_validator.Joi.object({
|
|
38
|
+
createToken: _arcblock_validator.Joi.number().integer().min(1).required(),
|
|
39
|
+
createCreditToken: _arcblock_validator.Joi.number().integer().min(0).required(),
|
|
40
|
+
createTokenLockPeriod: _arcblock_validator.Joi.number().integer().min(1).required()
|
|
41
|
+
}).optional()
|
|
42
|
+
}).optional().default(require_default.default.transaction),
|
|
43
|
+
moderator: _arcblock_validator.Joi.object(accountSchema).required(),
|
|
44
|
+
accounts: _arcblock_validator.Joi.array().items(accountSchema).required(),
|
|
45
|
+
vaults: _arcblock_validator.Joi.object({
|
|
46
|
+
slashedStake: _arcblock_validator.Joi.DID().prefix().required(),
|
|
47
|
+
txFee: _arcblock_validator.Joi.DID().prefix(),
|
|
48
|
+
txFees: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix()),
|
|
49
|
+
txGas: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.DID().prefix())
|
|
50
|
+
}).default({}),
|
|
51
|
+
token: _arcblock_validator.Joi.object({
|
|
52
|
+
name: _arcblock_validator.Joi.string().required(),
|
|
53
|
+
description: _arcblock_validator.Joi.string().required(),
|
|
54
|
+
symbol: _arcblock_validator.Joi.string().required(),
|
|
55
|
+
unit: _arcblock_validator.Joi.string().required(),
|
|
56
|
+
decimal: _arcblock_validator.Joi.number().positive().required(),
|
|
57
|
+
icon: _arcblock_validator.Joi.string().required().allow(""),
|
|
58
|
+
initialSupply: _arcblock_validator.Joi.number().positive().required(),
|
|
59
|
+
totalSupply: _arcblock_validator.Joi.number().positive().required(),
|
|
60
|
+
inflationRate: _arcblock_validator.Joi.number().required(),
|
|
61
|
+
website: _arcblock_validator.Joi.string().uri({
|
|
62
|
+
scheme: ["https"],
|
|
63
|
+
allowRelative: false
|
|
64
|
+
}).max(256).optional().allow(null, ""),
|
|
65
|
+
metadata: _arcblock_validator.Joi.any().optional().allow(null),
|
|
66
|
+
foreignToken: _arcblock_validator.Joi.object({
|
|
67
|
+
type: _arcblock_validator.Joi.string().min(1).max(32).required(),
|
|
68
|
+
contractAddress: _arcblock_validator.Joi.string().required(),
|
|
69
|
+
chainType: _arcblock_validator.Joi.string().min(1).max(32).required(),
|
|
70
|
+
chainName: _arcblock_validator.Joi.string().min(1).max(32).required(),
|
|
71
|
+
chainId: _arcblock_validator.Joi.number().positive().required()
|
|
72
|
+
}).optional().allow(null)
|
|
73
|
+
}).optional().default(require_default.default.token),
|
|
74
|
+
reservedSymbols: _arcblock_validator.Joi.array().items(_arcblock_validator.Joi.string()).optional()
|
|
75
|
+
}).options({ stripUnknown: true });
|
|
76
|
+
var schema_default = configSchema;
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
exports.default = schema_default;
|
package/lib/schema.d.cts
ADDED
package/lib/types.cjs
ADDED
|
File without changes
|
package/lib/types.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { IAccountConfig, IChainConfig, IChainConfigInput, IDefaultConfig, ITokenConfig, ITokenItx, ITransactionConfig, ITxGasConfig, ITxStakeConfig, IVaultsConfig, TDelegateConfig, TForeignToken, TxTypeMap, TxTypeUrl } from "@ocap/types";
|
|
2
|
+
export { type IAccountConfig, type IChainConfig, type IChainConfigInput, type IDefaultConfig, type ITokenConfig, type ITokenItx, type ITransactionConfig, type ITxGasConfig, type ITxStakeConfig, type IVaultsConfig, type TDelegateConfig, type TForeignToken, type TxTypeMap, type TxTypeUrl };
|
package/package.json
CHANGED
|
@@ -3,13 +3,36 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.29.0",
|
|
7
7
|
"description": "OCAP config parsing/validation and default",
|
|
8
|
-
"
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./lib/index.cjs",
|
|
10
|
+
"module": "./esm/index.mjs",
|
|
11
|
+
"types": "./esm/index.d.mts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./esm/index.d.mts",
|
|
15
|
+
"import": "./esm/index.mjs",
|
|
16
|
+
"default": "./lib/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./lib/*.js": {
|
|
19
|
+
"types": "./esm/*.d.mts",
|
|
20
|
+
"import": "./esm/*.mjs",
|
|
21
|
+
"default": "./lib/*.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./lib/*": {
|
|
24
|
+
"types": "./esm/*.d.mts",
|
|
25
|
+
"import": "./esm/*.mjs",
|
|
26
|
+
"default": "./lib/*.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
9
29
|
"files": [
|
|
10
|
-
"lib"
|
|
30
|
+
"lib",
|
|
31
|
+
"esm"
|
|
11
32
|
],
|
|
12
33
|
"scripts": {
|
|
34
|
+
"build": "tsdown",
|
|
35
|
+
"prebuild": "rm -rf lib esm",
|
|
13
36
|
"lint": "biome check",
|
|
14
37
|
"lint:fix": "biome check --write",
|
|
15
38
|
"test": "bun test",
|
|
@@ -23,10 +46,11 @@
|
|
|
23
46
|
"license": "MIT",
|
|
24
47
|
"devDependencies": {},
|
|
25
48
|
"dependencies": {
|
|
26
|
-
"@arcblock/did": "1.
|
|
27
|
-
"@arcblock/did-util": "1.
|
|
28
|
-
"@arcblock/validator": "1.
|
|
29
|
-
"@ocap/
|
|
30
|
-
"
|
|
49
|
+
"@arcblock/did": "1.29.0",
|
|
50
|
+
"@arcblock/did-util": "1.29.0",
|
|
51
|
+
"@arcblock/validator": "1.29.0",
|
|
52
|
+
"@ocap/types": "1.29.0",
|
|
53
|
+
"@ocap/util": "1.29.0",
|
|
54
|
+
"lodash": "^4.17.23"
|
|
31
55
|
}
|
|
32
56
|
}
|
package/lib/default.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
transaction: {
|
|
3
|
-
maxAssetSize: 65536,
|
|
4
|
-
maxListSize: 8,
|
|
5
|
-
maxMultisig: 8,
|
|
6
|
-
maxTxSize: {
|
|
7
|
-
default: 65535,
|
|
8
|
-
'fg:t:account_migrate': 1691,
|
|
9
|
-
'fg:t:create_asset': 65881,
|
|
10
|
-
'fg:t:create_factory': 65881,
|
|
11
|
-
'fg:t:exchange_v2': 1691,
|
|
12
|
-
'fg:t:transfer': 664,
|
|
13
|
-
'fg:t:transfer_v2': 664,
|
|
14
|
-
'fg:t:transfer_v3': 4096,
|
|
15
|
-
'fg:t:update_asset': 65881,
|
|
16
|
-
'fg:t:consume_asset': 1691,
|
|
17
|
-
'fg:t:acquire_asset_v2': 4096,
|
|
18
|
-
'fg:t:acquire_asset_v3': 4096,
|
|
19
|
-
'fg:t:mint_asset': 4096,
|
|
20
|
-
'fg:t:create_token': 664,
|
|
21
|
-
'fg:t:deposit_token_v2': 1691,
|
|
22
|
-
'fg:t:withdraw_token_v2': 1691,
|
|
23
|
-
'fg:t:stake': 4096,
|
|
24
|
-
'fg:t:revoke_stake': 4096,
|
|
25
|
-
'fg:t:claim_stake': 664,
|
|
26
|
-
'fg:t:slash_stake': 4096,
|
|
27
|
-
'fg:t:return_stake': 4096,
|
|
28
|
-
'fg:t:create_rollup': 1691,
|
|
29
|
-
'fg:t:update_rollup': 1691,
|
|
30
|
-
'fg:t:pause_rollup': 1691,
|
|
31
|
-
'fg:t:resume_rollup': 1691,
|
|
32
|
-
'fg:t:close_rollup': 1691,
|
|
33
|
-
'fg:t:join_rollup': 1691,
|
|
34
|
-
'fg:t:leave_rollup': 1691,
|
|
35
|
-
'fg:t:migrate_rollup': 1691,
|
|
36
|
-
'fg:t:create_rollup_block': 4096,
|
|
37
|
-
'fg:t:claim_block_reward': 1691,
|
|
38
|
-
'fg:t:mint_token': 4096,
|
|
39
|
-
'fg:t:burn_token': 4096,
|
|
40
|
-
'fg:t:create_token_factory': Math.floor(16 * 1024 + 4096), // icon size limit is 16KB
|
|
41
|
-
'fg:t:update_token_factory': Math.floor(16 * 1024 + 1691), // icon size limit is 16KB
|
|
42
|
-
},
|
|
43
|
-
txFee: {
|
|
44
|
-
default: 0, // in ABT
|
|
45
|
-
'fg:t:create_asset': 1,
|
|
46
|
-
'fg:t:mint_asset': 1,
|
|
47
|
-
'fg:t:update_token_factory': 100,
|
|
48
|
-
'fg:t:create_factory': 100,
|
|
49
|
-
'fg:t:create_token': 1000,
|
|
50
|
-
'fg:t:create_rollup': 10000,
|
|
51
|
-
},
|
|
52
|
-
txGas: {
|
|
53
|
-
price: 100000000, // in ARC
|
|
54
|
-
createState: 1000000, // per op
|
|
55
|
-
updateState: 10000, // per op
|
|
56
|
-
dataStorage: 100, // per bytes
|
|
57
|
-
minStake: 1, // in ABT
|
|
58
|
-
maxStake: 10000, // in ABT
|
|
59
|
-
stakeLockPeriod: 365 * 24 * 60 * 60, // 1 year
|
|
60
|
-
},
|
|
61
|
-
txStake: {
|
|
62
|
-
createToken: 100, // in ABT
|
|
63
|
-
createCreditToken: 100, // in ABT
|
|
64
|
-
createTokenLockPeriod: 24 * 60 * 60, // 1 day
|
|
65
|
-
},
|
|
66
|
-
delegate: {
|
|
67
|
-
deltaInterval: 18000,
|
|
68
|
-
// list transaction protocols that can work with delegation
|
|
69
|
-
// the transaction protocol must enable VerifyDelegation pipe before added here
|
|
70
|
-
typeUrls: [
|
|
71
|
-
'fg:t:transfer',
|
|
72
|
-
'fg:t:transfer_v2',
|
|
73
|
-
'fg:t:exchange_v2',
|
|
74
|
-
'fg:t:acquire_asset_v2',
|
|
75
|
-
'fg:t:create_asset',
|
|
76
|
-
'fg:t:create_factory',
|
|
77
|
-
'fg:t:create_token',
|
|
78
|
-
'fg:t:create_rollup',
|
|
79
|
-
'fg:t:create_token_factory',
|
|
80
|
-
'fg:t:update_token_factory',
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
supportedTxs: [
|
|
84
|
-
'fg:t:transfer',
|
|
85
|
-
'fg:t:transfer_v2',
|
|
86
|
-
'fg:t:transfer_v3',
|
|
87
|
-
'fg:t:exchange_v2',
|
|
88
|
-
'fg:t:account_migrate',
|
|
89
|
-
'fg:t:delegate',
|
|
90
|
-
'fg:t:revoke_delegate',
|
|
91
|
-
'fg:t:create_asset',
|
|
92
|
-
'fg:t:update_asset',
|
|
93
|
-
'fg:t:consume_asset',
|
|
94
|
-
'fg:t:create_factory',
|
|
95
|
-
'fg:t:acquire_asset_v2',
|
|
96
|
-
'fg:t:acquire_asset_v3',
|
|
97
|
-
'fg:t:mint_asset',
|
|
98
|
-
'fg:t:create_token',
|
|
99
|
-
'fg:t:deposit_token_v2',
|
|
100
|
-
'fg:t:withdraw_token_v2',
|
|
101
|
-
'fg:t:stake',
|
|
102
|
-
'fg:t:revoke_stake',
|
|
103
|
-
'fg:t:claim_stake',
|
|
104
|
-
'fg:t:slash_stake',
|
|
105
|
-
'fg:t:return_stake',
|
|
106
|
-
'fg:t:create_rollup',
|
|
107
|
-
'fg:t:update_rollup',
|
|
108
|
-
'fg:t:pause_rollup',
|
|
109
|
-
'fg:t:close_rollup',
|
|
110
|
-
'fg:t:resume_rollup',
|
|
111
|
-
'fg:t:join_rollup',
|
|
112
|
-
'fg:t:leave_rollup',
|
|
113
|
-
'fg:t:create_rollup_block',
|
|
114
|
-
'fg:t:migrate_rollup',
|
|
115
|
-
'fg:t:claim_block_reward',
|
|
116
|
-
'fg:t:create_token_factory',
|
|
117
|
-
'fg:t:update_token_factory',
|
|
118
|
-
'fg:t:mint_token',
|
|
119
|
-
'fg:t:burn_token',
|
|
120
|
-
],
|
|
121
|
-
multiSignV2Txs: [
|
|
122
|
-
'fg:t:transfer_v3',
|
|
123
|
-
'fg:t:acquire_asset_v3',
|
|
124
|
-
'fg:t:stake',
|
|
125
|
-
'fg:t:join_rollup',
|
|
126
|
-
'fg:t:leave_rollup',
|
|
127
|
-
'fg:t:update_rollup',
|
|
128
|
-
'fg:t:pause_rollup',
|
|
129
|
-
'fg:t:resume_rollup',
|
|
130
|
-
'fg:t:close_rollup',
|
|
131
|
-
'fg:t:deposit_token_v2',
|
|
132
|
-
'fg:t:withdraw_token_v2',
|
|
133
|
-
'fg:t:create_rollup_block',
|
|
134
|
-
'fg:t:migrate_rollup',
|
|
135
|
-
'fg:t:claim_block_reward',
|
|
136
|
-
'fg:t:create_asset',
|
|
137
|
-
'fg:t:consume_asset',
|
|
138
|
-
'fg:t:mint_token',
|
|
139
|
-
'fg:t:burn_token',
|
|
140
|
-
],
|
|
141
|
-
},
|
|
142
|
-
vaults: {},
|
|
143
|
-
accounts: [],
|
|
144
|
-
reservedSymbols: ['TBA'],
|
|
145
|
-
token: {
|
|
146
|
-
name: 'TestChainToken',
|
|
147
|
-
decimal: 18,
|
|
148
|
-
symbol: 'TBA',
|
|
149
|
-
unit: 'arc',
|
|
150
|
-
description: 'Token on ArcBlock Test Chain',
|
|
151
|
-
icon: '',
|
|
152
|
-
initialSupply: 1000000000, // 1 billion
|
|
153
|
-
totalSupply: 1000000000, // 1 billion
|
|
154
|
-
inflationRate: 0,
|
|
155
|
-
},
|
|
156
|
-
};
|
package/lib/index.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const merge = require('lodash/merge');
|
|
2
|
-
const pick = require('lodash/pick');
|
|
3
|
-
const flatten = require('lodash/flatten');
|
|
4
|
-
const { fromTokenToUnit } = require('@ocap/util');
|
|
5
|
-
const { isValid, toTypeInfoStr } = require('@arcblock/did');
|
|
6
|
-
const { toTokenAddress } = require('@arcblock/did-util');
|
|
7
|
-
|
|
8
|
-
const defaultConfig = require('./default');
|
|
9
|
-
const schema = require('./schema');
|
|
10
|
-
|
|
11
|
-
const validate = (config) => {
|
|
12
|
-
const { value, error } = schema.validate(config);
|
|
13
|
-
if (error) {
|
|
14
|
-
throw new Error(`Invalid config: ${error.details.map((x) => x.message).join(', ')}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const { vaults, transaction, accounts } = value;
|
|
18
|
-
if (flatten(Object.values(vaults)).some((a) => !accounts.find((x) => x.address === a))) {
|
|
19
|
-
throw new Error('Invalid config: vault address does not exist in accounts');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (transaction.txGas.price > 0 && (!vaults.txGas || !vaults.txGas.length)) {
|
|
23
|
-
throw new Error('Invalid config: vaults.txGas can not be empty when gas enabled');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const hasPaidTx = Object.keys(transaction.txFee).some((x) => transaction.txFee[x] > 0);
|
|
27
|
-
if (hasPaidTx && !vaults.txFee) {
|
|
28
|
-
throw new Error('Invalid config: vaults.txFee can not be empty when there are paid transactions');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (vaults.txFee && vaults.txGas && vaults.txGas.includes(vaults.txFee)) {
|
|
32
|
-
throw new Error('Invalid config: vaults.txFee can not contain same address with vaults.txGas');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!vaults.slashedStake) {
|
|
36
|
-
throw new Error('Invalid config: vaults.slashedStake must be a valid DID');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return value;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const create = (props) => {
|
|
43
|
-
const config = merge({}, defaultConfig, props);
|
|
44
|
-
return validate(config);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Generate token state if token exist in config
|
|
48
|
-
const genTokenItx = (config) => {
|
|
49
|
-
const itx = pick(config.token, [
|
|
50
|
-
'name',
|
|
51
|
-
'description',
|
|
52
|
-
'symbol',
|
|
53
|
-
'unit',
|
|
54
|
-
'decimal',
|
|
55
|
-
'totalSupply',
|
|
56
|
-
'initialSupply',
|
|
57
|
-
'foreignToken',
|
|
58
|
-
]);
|
|
59
|
-
|
|
60
|
-
itx.totalSupply = fromTokenToUnit(itx.totalSupply, itx.decimal).toString();
|
|
61
|
-
itx.initialSupply = fromTokenToUnit(itx.initialSupply || itx.totalSupply, itx.decimal).toString();
|
|
62
|
-
itx.issuer = config.moderator.address;
|
|
63
|
-
|
|
64
|
-
const legacyAddr = process.env.CHAIN_TOKEN_ADDRESS;
|
|
65
|
-
if (legacyAddr && isValid(legacyAddr) && toTypeInfoStr(legacyAddr).role === 'ROLE_TOKEN') {
|
|
66
|
-
itx.address = legacyAddr;
|
|
67
|
-
} else {
|
|
68
|
-
itx.address = toTokenAddress(itx);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// These properties are mutable, so they cannot included in toTokenAddress calculation
|
|
72
|
-
itx.metadata = config.token.metadata;
|
|
73
|
-
itx.website = config.token.website;
|
|
74
|
-
itx.icon = config.token.icon;
|
|
75
|
-
|
|
76
|
-
return itx;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
module.exports = {
|
|
80
|
-
validate,
|
|
81
|
-
create,
|
|
82
|
-
genTokenItx,
|
|
83
|
-
};
|
package/lib/schema.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
const { Joi } = require('@arcblock/validator');
|
|
2
|
-
|
|
3
|
-
const defaultConfig = require('./default');
|
|
4
|
-
|
|
5
|
-
const accountSchema = {
|
|
6
|
-
address: Joi.DID().prefix().required(),
|
|
7
|
-
pk: Joi.string().allow('').required(),
|
|
8
|
-
balance: Joi.number().optional().default(0),
|
|
9
|
-
moniker: Joi.string().optional().allow(''),
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const configSchema = Joi.object({
|
|
13
|
-
chainId: Joi.string().min(1).required(),
|
|
14
|
-
version: Joi.string().min(1).required(),
|
|
15
|
-
transaction: Joi.object({
|
|
16
|
-
maxAssetSize: Joi.number().positive().required(),
|
|
17
|
-
maxListSize: Joi.number().positive().required(),
|
|
18
|
-
maxMultisig: Joi.number().positive().required(),
|
|
19
|
-
maxTxSize: Joi.object()
|
|
20
|
-
.pattern(Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), Joi.number().integer().greater(0))
|
|
21
|
-
.required(),
|
|
22
|
-
delegate: Joi.object({
|
|
23
|
-
deltaInterval: Joi.number().positive(),
|
|
24
|
-
typeUrls: Joi.array().items(Joi.string()),
|
|
25
|
-
}).required(),
|
|
26
|
-
supportedTxs: Joi.array().items(Joi.string()).min(1).required(),
|
|
27
|
-
multiSignV2Txs: Joi.array().items(Joi.string()).min(1).required(),
|
|
28
|
-
txFee: Joi.object()
|
|
29
|
-
.pattern(Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), Joi.number().precision(6).min(0))
|
|
30
|
-
.required(),
|
|
31
|
-
txGas: Joi.object({
|
|
32
|
-
price: Joi.number().integer().min(0).required(),
|
|
33
|
-
createState: Joi.number().integer().min(1).required(),
|
|
34
|
-
updateState: Joi.number().integer().min(1).required(),
|
|
35
|
-
dataStorage: Joi.number().integer().min(1).required(),
|
|
36
|
-
minStake: Joi.number().integer().min(1).required(),
|
|
37
|
-
maxStake: Joi.number().integer().min(1).required(),
|
|
38
|
-
stakeLockPeriod: Joi.number().integer().min(1).required(),
|
|
39
|
-
}).optional(),
|
|
40
|
-
txStake: Joi.object({
|
|
41
|
-
createToken: Joi.number().integer().min(1).required(),
|
|
42
|
-
createCreditToken: Joi.number().integer().min(0).required(),
|
|
43
|
-
createTokenLockPeriod: Joi.number().integer().min(1).required(),
|
|
44
|
-
}).optional(),
|
|
45
|
-
})
|
|
46
|
-
.optional()
|
|
47
|
-
.default(defaultConfig.transaction),
|
|
48
|
-
moderator: Joi.object(accountSchema).required(),
|
|
49
|
-
accounts: Joi.array().items(accountSchema).required(),
|
|
50
|
-
vaults: Joi.object({
|
|
51
|
-
slashedStake: Joi.DID().prefix().required(),
|
|
52
|
-
txFee: Joi.DID().prefix(),
|
|
53
|
-
txFees: Joi.array().items(Joi.DID().prefix()),
|
|
54
|
-
txGas: Joi.array().items(Joi.DID().prefix()),
|
|
55
|
-
}).default({}),
|
|
56
|
-
token: Joi.object({
|
|
57
|
-
name: Joi.string().required(),
|
|
58
|
-
description: Joi.string().required(),
|
|
59
|
-
symbol: Joi.string().required(),
|
|
60
|
-
unit: Joi.string().required(),
|
|
61
|
-
decimal: Joi.number().positive().required(),
|
|
62
|
-
icon: Joi.string().required().allow(''),
|
|
63
|
-
initialSupply: Joi.number().positive().required(),
|
|
64
|
-
totalSupply: Joi.number().positive().required(),
|
|
65
|
-
inflationRate: Joi.number().required(),
|
|
66
|
-
website: Joi.string()
|
|
67
|
-
.uri({ scheme: ['https'], allowRelative: false })
|
|
68
|
-
.max(256)
|
|
69
|
-
.optional()
|
|
70
|
-
.allow(null, ''),
|
|
71
|
-
metadata: Joi.any().optional().allow(null),
|
|
72
|
-
foreignToken: Joi.object({
|
|
73
|
-
type: Joi.string().min(1).max(32).required(),
|
|
74
|
-
contractAddress: Joi.string().required(),
|
|
75
|
-
chainType: Joi.string().min(1).max(32).required(),
|
|
76
|
-
chainName: Joi.string().min(1).max(32).required(),
|
|
77
|
-
chainId: Joi.number().positive().required(),
|
|
78
|
-
})
|
|
79
|
-
.optional()
|
|
80
|
-
.allow(null),
|
|
81
|
-
})
|
|
82
|
-
.optional()
|
|
83
|
-
.default(defaultConfig.token),
|
|
84
|
-
reservedSymbols: Joi.array().items(Joi.string()).optional(),
|
|
85
|
-
}).options({ stripUnknown: true });
|
|
86
|
-
|
|
87
|
-
module.exports = configSchema;
|