@ocap/config 1.6.5 → 1.6.10

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/lib/default.js CHANGED
@@ -2,60 +2,119 @@ module.exports = {
2
2
  transaction: {
3
3
  maxAssetSize: 65536,
4
4
  maxListSize: 8,
5
- maxMultisig: 4,
5
+ maxMultisig: 8,
6
6
  maxTxSize: {
7
7
  default: 65535,
8
8
  'fg:t:account_migrate': 348,
9
9
  'fg:t:create_asset': 65881,
10
+ 'fg:t:create_factory': 65881,
10
11
  'fg:t:declare': 664,
11
- 'fg:t:exchange': 1691,
12
+ 'fg:t:exchange_v2': 1691,
12
13
  'fg:t:transfer': 664,
14
+ 'fg:t:transfer_v2': 664,
15
+ 'fg:t:transfer_v3': 4096,
13
16
  'fg:t:update_asset': 65881,
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': 664,
25
+ 'fg:t:claim_stake': 664,
26
+ 'fg:t:create_rollup': 1691,
27
+ 'fg:t:update_rollup': 1691,
28
+ 'fg:t:pause_rollup': 1691,
29
+ 'fg:t:resume_rollup': 1691,
30
+ 'fg:t:join_rollup': 1691,
31
+ 'fg:t:leave_rollup': 1691,
32
+ 'fg:t:migrate_rollup_contract': 1691,
33
+ 'fg:t:migrate_rollup_token': 1691,
34
+ 'fg:t:create_rollup_block': 4096,
35
+ 'fg:t:claim_block_reward': 1691,
36
+ },
37
+ txFee: {
38
+ default: 0, // in ABT
39
+ 'fg:t:create_asset': 1,
40
+ 'fg:t:create_factory': 100,
41
+ 'fg:t:create_token': 1000,
42
+ 'fg:t:create_rollup': 10000,
14
43
  },
15
44
  delegate: {
16
45
  deltaInterval: 18000,
17
46
  // list transaction protocols that can work with delegation
18
47
  // the transaction protocol must enable VerifyDelegation pipe before added here
19
- typeUrls: ['fg:t:transfer', 'fg:t:exchange'],
20
- },
21
- declare: {
22
- cost: 0,
23
- hierarchy: 5,
24
- restricted: false,
25
- },
26
- poke: {
27
- amount: 25,
28
- dailyLimit: 100000, // TODO: not implemented yet
29
- enabled: true,
48
+ typeUrls: [
49
+ 'fg:t:transfer',
50
+ 'fg:t:transfer_v2',
51
+ 'fg:t:exchange_v2',
52
+ 'fg:t:acquire_asset_v2',
53
+ 'fg:t:create_asset',
54
+ 'fg:t:create_factory',
55
+ 'fg:t:create_token',
56
+ 'fg:t:create_rollup',
57
+ ],
30
58
  },
31
59
  supportedTxs: [
32
- 'fg:t:poke',
33
60
  'fg:t:transfer',
34
- 'fg:t:exchange',
61
+ 'fg:t:transfer_v2',
62
+ 'fg:t:transfer_v3',
63
+ 'fg:t:exchange_v2',
35
64
  'fg:t:declare',
36
65
  'fg:t:account_migrate',
37
66
  'fg:t:delegate',
38
67
  'fg:t:revoke_delegate',
39
68
  'fg:t:create_asset',
40
69
  'fg:t:update_asset',
70
+ 'fg:t:create_factory',
71
+ 'fg:t:acquire_asset_v2',
72
+ 'fg:t:acquire_asset_v3',
73
+ 'fg:t:mint_asset',
74
+ 'fg:t:create_token',
75
+ 'fg:t:deposit_token_v2',
76
+ 'fg:t:withdraw_token_v2',
77
+ 'fg:t:stake',
78
+ 'fg:t:revoke_stake',
79
+ 'fg:t:claim_stake',
80
+ 'fg:t:create_rollup',
81
+ 'fg:t:update_rollup',
82
+ 'fg:t:pause_rollup',
83
+ 'fg:t:resume_rollup',
84
+ 'fg:t:join_rollup',
85
+ 'fg:t:leave_rollup',
86
+ 'fg:t:create_rollup_block',
87
+ 'fg:t:migrate_rollup_contract',
88
+ 'fg:t:migrate_rollup_token',
89
+ 'fg:t:claim_block_reward',
90
+ ],
91
+ multiSignV2Txs: [
92
+ 'fg:t:transfer_v3',
93
+ 'fg:t:acquire_asset_v3',
94
+ 'fg:t:stake',
95
+ 'fg:t:join_rollup',
96
+ 'fg:t:leave_rollup',
97
+ 'fg:t:update_rollup',
98
+ 'fg:t:pause_rollup',
99
+ 'fg:t:resume_rollup',
100
+ 'fg:t:deposit_token_v2',
101
+ 'fg:t:withdraw_token_v2',
102
+ 'fg:t:create_rollup_block',
103
+ 'fg:t:migrate_rollup_contract',
104
+ 'fg:t:migrate_rollup_token',
105
+ 'fg:t:claim_block_reward',
106
+ 'fg:t:create_asset',
41
107
  ],
42
108
  },
43
- accounts: [
44
- {
45
- // This account does not have pk and sk, so no one can change account balance
46
- // Used by poke transaction
47
- address: 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
48
- pk: '',
49
- balance: 100000000, // 0.1 billion
50
- },
51
- ],
109
+ vaults: {},
110
+ accounts: [],
52
111
  token: {
53
112
  name: 'TestChainToken',
54
113
  decimal: 18,
55
114
  symbol: 'TBA',
56
115
  unit: 'arc',
57
116
  description: 'Token on ArcBlock Test Chain',
58
- icon: null,
117
+ icon: '',
59
118
  initialSupply: 1000000000, // 1 billion
60
119
  totalSupply: 1000000000, // 1 billion
61
120
  inflationRate: 0,
package/lib/index.js CHANGED
@@ -1,14 +1,27 @@
1
1
  const merge = require('lodash/merge');
2
+ const pick = require('lodash/pick');
3
+ const { fromTokenToUnit } = require('@ocap/util');
4
+ const { isValid, toTypeInfo } = require('@arcblock/did');
5
+ const { toTokenAddress } = require('@arcblock/did-util');
2
6
 
3
- const constants = require('constants');
4
7
  const defaultConfig = require('./default');
5
8
  const schema = require('./schema');
6
9
 
7
10
  const validate = (config) => {
8
11
  const { value, error } = schema.validate(config);
9
12
  if (error) {
10
- console.error('Invalid ocap config', error.details.map((x) => x.message).join(', '));
11
- throw new Error(`Invalid ocap config: ${error.details.map((x) => x.message).join(', ')}`);
13
+ console.error('Invalid config', error.details.map((x) => x.message).join(', '));
14
+ throw new Error(`Invalid config: ${error.details.map((x) => x.message).join(', ')}`);
15
+ }
16
+
17
+ const { vaults, transaction, accounts } = value;
18
+ if (Object.keys(vaults).some((v) => !accounts.find((x) => x.address === vaults[v]))) {
19
+ throw new Error('Invalid config: vault address does not exist in accounts');
20
+ }
21
+
22
+ const hasPaidTx = Object.keys(transaction.txFee).some((x) => transaction.txFee[x] > 0);
23
+ if (hasPaidTx && !vaults.txFee) {
24
+ throw new Error('Invalid config: vaults.txFee can not be empty when there are paid transactions');
12
25
  }
13
26
 
14
27
  return value;
@@ -16,15 +29,39 @@ const validate = (config) => {
16
29
 
17
30
  const create = (props) => {
18
31
  const config = merge({}, defaultConfig, props);
19
- const pokeAccount = config.accounts.find((x) => !x.pk);
20
- if (!pokeAccount) {
21
- config.accounts = config.accounts.concat(defaultConfig.accounts);
22
- }
23
32
  return validate(config);
24
33
  };
25
34
 
35
+ // Generate token state if token exist in config
36
+ const genTokenItx = (config) => {
37
+ const itx = pick(config.token, [
38
+ 'name',
39
+ 'description',
40
+ 'symbol',
41
+ 'unit',
42
+ 'decimal',
43
+ 'icon',
44
+ 'totalSupply',
45
+ 'initialSupply',
46
+ 'foreignToken',
47
+ ]);
48
+
49
+ itx.totalSupply = fromTokenToUnit(itx.totalSupply, itx.decimal).toString();
50
+ itx.initialSupply = fromTokenToUnit(itx.initialSupply || itx.totalSupply, itx.decimal).toString();
51
+ itx.issuer = config.moderator.address;
52
+
53
+ const legacyAddr = process.env.CHAIN_TOKEN_ADDRESS;
54
+ if (legacyAddr && isValid(legacyAddr) && toTypeInfo(legacyAddr, true).role === 'ROLE_TOKEN') {
55
+ itx.address = legacyAddr;
56
+ } else {
57
+ itx.address = toTokenAddress(itx);
58
+ }
59
+
60
+ return itx;
61
+ };
62
+
26
63
  module.exports = {
27
- ...constants,
28
64
  validate,
29
65
  create,
66
+ genTokenItx,
30
67
  };
package/lib/schema.js CHANGED
@@ -1,9 +1,9 @@
1
- const Joi = require('joi');
1
+ const Joi = require('@arcblock/validator');
2
2
 
3
3
  const defaultConfig = require('./default');
4
4
 
5
5
  const accountSchema = {
6
- address: Joi.string().required(),
6
+ address: Joi.DID().required(),
7
7
  pk: Joi.string().allow('').required(),
8
8
  balance: Joi.number().optional().default(0),
9
9
  };
@@ -15,37 +15,43 @@ const configSchema = Joi.object({
15
15
  maxAssetSize: Joi.number().positive().required(),
16
16
  maxListSize: Joi.number().positive().required(),
17
17
  maxMultisig: Joi.number().positive().required(),
18
- maxTxSize: Joi.any(),
18
+ maxTxSize: Joi.object()
19
+ .pattern(Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), Joi.number().integer().greater(0))
20
+ .required(),
19
21
  delegate: Joi.object({
20
22
  deltaInterval: Joi.number().positive(),
21
23
  typeUrls: Joi.array().items(Joi.string()),
22
24
  }).required(),
23
- poke: Joi.object({
24
- amount: Joi.number().positive().allow(0),
25
- dailyLimit: Joi.number().positive().allow(0),
26
- enabled: Joi.boolean(),
27
- }).required(),
28
- declare: Joi.object({
29
- cost: Joi.number().positive().allow(0),
30
- hierarchy: Joi.number().positive(),
31
- restricted: Joi.boolean(),
32
- }).required(),
33
25
  supportedTxs: Joi.array().items(Joi.string()).min(1).required(),
26
+ multiSignV2Txs: Joi.array().items(Joi.string()).min(1).required(),
27
+ txFee: Joi.object()
28
+ .pattern(Joi.string().pattern(/^(default|fg:t:[_a-z0-9]+)$/), Joi.number().precision(6).min(0))
29
+ .required(),
34
30
  })
35
31
  .optional()
36
32
  .default(defaultConfig.transaction),
37
33
  moderator: Joi.object(accountSchema).required(),
38
34
  accounts: Joi.array().items(accountSchema).required(),
35
+ vaults: Joi.object().pattern(Joi.string().allow('quotaSlash', 'txFee'), Joi.DID()).default({}),
39
36
  token: Joi.object({
40
37
  name: Joi.string().required(),
41
38
  description: Joi.string().required(),
42
39
  symbol: Joi.string().required(),
43
40
  unit: Joi.string().required(),
44
41
  decimal: Joi.number().positive().required(),
45
- icon: Joi.string().allow(null).required(),
42
+ icon: Joi.string().required().allow(''),
46
43
  initialSupply: Joi.number().positive().required(),
47
44
  totalSupply: Joi.number().positive().required(),
48
45
  inflationRate: Joi.number().required(),
46
+ foreignToken: Joi.object({
47
+ type: Joi.string().min(1).max(32).required(),
48
+ contractAddress: Joi.string().required(),
49
+ chainType: Joi.string().min(1).max(32).required(),
50
+ chainName: Joi.string().min(1).max(32).required(),
51
+ chainId: Joi.number().positive().required(),
52
+ })
53
+ .optional()
54
+ .allow(null),
49
55
  })
50
56
  .optional()
51
57
  .default(defaultConfig.token),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.5",
6
+ "version": "1.6.10",
7
7
  "description": "OCAP config parsing/validation and default",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -12,18 +12,24 @@
12
12
  "scripts": {
13
13
  "lint": "eslint tests lib",
14
14
  "lint:fix": "eslint --fix tests lib",
15
- "test": "node tools/jest.js",
15
+ "test": "jest --forceExit --detectOpenHandles",
16
16
  "coverage": "npm run test -- --coverage"
17
17
  },
18
18
  "keywords": [],
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
+ "contributors": [
21
+ "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
22
+ ],
20
23
  "license": "MIT",
21
24
  "devDependencies": {
22
- "jest": "^26.6.3"
25
+ "jest": "^27.3.1"
23
26
  },
24
27
  "dependencies": {
25
- "joi": "^17.3.0",
28
+ "@arcblock/did": "1.6.10",
29
+ "@arcblock/did-util": "1.6.10",
30
+ "@arcblock/validator": "1.6.10",
31
+ "@ocap/util": "1.6.10",
26
32
  "lodash": "^4.17.21"
27
33
  },
28
- "gitHead": "5779448f13824de38978df3c84c9da0c1e1ad989"
34
+ "gitHead": "ab272e8db3a15c6571cc7fae7cc3d3e0fdd4bdb1"
29
35
  }
package/lib/const.js DELETED
@@ -1,103 +0,0 @@
1
- const SUPPORTED_TXS = [
2
- 'fg:t:poke',
3
- 'fg:t:declare',
4
- 'fg:t:account_migrate',
5
- 'fg:t:revoke_delegate',
6
- 'fg:t:create_asset',
7
-
8
- 'fg:t:delegate',
9
- 'fg:t:update_asset',
10
- // 'fg:t:consume_asset',
11
- // 'fg:t:deposit_token',
12
- // 'fg:t:acquire_asset',
13
-
14
- 'fg:t:transfer',
15
- 'fg:t:exchange',
16
-
17
- // 'fg:t:update_consensus_params',
18
- // 'fg:t:upgrade_node',
19
- // 'fg:t:update_validator',
20
-
21
- // 'fg:t:setup_swap',
22
- // 'fg:t:revoke_swap',
23
- // 'fg:t:retrieve_swap',
24
-
25
- // 'fg:t:approve_withdraw',
26
- // 'fg:t:revoke_withdraw',
27
- // 'fg:t:withdraw_token',
28
- ];
29
-
30
- const STATUS_CODE = [
31
- 'ACCOUNT_MIGRATED',
32
- 'BANNED_UNSTAKE',
33
- 'CONSENSUS_RPC_ERROR',
34
- 'CONSUMED_ASSET',
35
- 'EXCEED_DEPOSIT_CAP',
36
- 'EXPIRED_ASSET',
37
- 'EXPIRED_TX',
38
- 'EXPIRED_WALLET_TOKEN',
39
- 'FORBIDDEN',
40
- 'INSUFFICIENT_DATA',
41
- 'INSUFFICIENT_DELEGATION',
42
- 'INSUFFICIENT_FUND',
43
- 'INSUFFICIENT_GAS',
44
- 'INSUFFICIENT_STAKE',
45
- 'INTERNAL',
46
- 'INVALID_ASSET',
47
- 'INVALID_CANDIDATE_STATE',
48
- 'INVALID_CHAIN_ID',
49
- 'INVALID_CHAIN_TYPE',
50
- 'INVALID_CUSTODIAN',
51
- 'INVALID_DEACTIVATION',
52
- 'INVALID_DELEGATION',
53
- 'INVALID_DELEGATION_RULE',
54
- 'INVALID_DELEGATION_TYPE_URL',
55
- 'INVALID_DEPOSIT',
56
- 'INVALID_DEPOSIT_TARGET',
57
- 'INVALID_DEPOSIT_VALUE',
58
- 'INVALID_DEPOSITOR',
59
- 'INVALID_DID_TYPE',
60
- 'INVALID_EXPIRY_DATE',
61
- 'INVALID_FORGE_STATE',
62
- 'INVALID_HASHKEY',
63
- 'INVALID_LOCK_STATUS',
64
- 'INVALID_MONIKER',
65
- 'INVALID_MULTISIG',
66
- 'INVALID_NONCE',
67
- 'INVALID_OWNER',
68
- 'INVALID_PASSPHRASE',
69
- 'INVALID_RECEIVER_STATE',
70
- 'INVALID_REQUEST',
71
- 'INVALID_SENDER_STATE',
72
- 'INVALID_SIGNATURE',
73
- 'INVALID_SIGNER_STATE',
74
- 'INVALID_STAKE_STATE',
75
- 'INVALID_SUBSCRIBE',
76
- 'INVALID_SWAP',
77
- 'INVALID_TIME',
78
- 'INVALID_TX',
79
- 'INVALID_TX_SIZE',
80
- 'INVALID_WALLET',
81
- 'INVALID_WITHDRAW_TX',
82
- 'INVALID_WITHDRAWER',
83
- 'NOENT',
84
- 'OK',
85
- 'PROTOCOL_NOT_ACTIVATED',
86
- 'PROTOCOL_NOT_PAUSED',
87
- 'PROTOCOL_NOT_RUNNING',
88
- 'READONLY_ASSET',
89
- 'RPC_CONNECTION_ERROR',
90
- 'SENDER_NOT_AUTHORIZED',
91
- 'SENDER_WITHDRAW_ITEMS_FULL',
92
- 'STORAGE_RPC_ERROR',
93
- 'TIMEOUT',
94
- 'TOO_MANY_TXS',
95
- 'UNSUPPORTED_STAKE',
96
- 'UNSUPPORTED_TX',
97
- 'UNTRANSFERRABLE_ASSET',
98
- 'VALIDATOR_NOT_CHANGED',
99
- 'VALIDATOR_NOT_FOUND',
100
- 'WITHDRAW_ITEM_MISSING',
101
- ];
102
-
103
- module.exports = { SUPPORTED_TXS, STATUS_CODE };