Skip to content

Commit cb38d15

Browse files
committed
Allows to override deploy parameters
1 parent da2be56 commit cb38d15

File tree

9 files changed

+68
-30
lines changed

9 files changed

+68
-30
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const constants = {
5454
AST_FOLDER: 'ast',
5555

5656
CONFIG_FILENAME: 'config.json',
57+
PARAMS_FILENAME: 'params.json',
5758
SYNTHS_FILENAME: 'synths.json',
5859
STAKING_REWARDS_FILENAME: 'rewards.json',
5960
OWNER_ACTIONS_FILENAME: 'owner-actions.json',

publish/deployed/kovan/params.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

publish/deployed/local/params.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

publish/deployed/mainnet/params.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

publish/deployed/rinkeby/params.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

publish/deployed/ropsten/params.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

publish/src/commands/deploy.js

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,7 @@ const {
3030
ZERO_ADDRESS,
3131
inflationStartTimestampInSecs,
3232
},
33-
defaults: {
34-
WAITING_PERIOD_SECS,
35-
PRICE_DEVIATION_THRESHOLD_FACTOR,
36-
TRADING_REWARDS_ENABLED,
37-
ISSUANCE_RATIO,
38-
FEE_PERIOD_DURATION,
39-
TARGET_THRESHOLD,
40-
LIQUIDATION_DELAY,
41-
LIQUIDATION_RATIO,
42-
LIQUIDATION_PENALTY,
43-
RATE_STALE_PERIOD,
44-
EXCHANGE_FEE_RATES,
45-
MINIMUM_STAKE_TIME,
46-
AGGREGATOR_WARNING_FLAGS,
47-
},
33+
defaults,
4834
} = require('../../../.');
4935

5036
const DEFAULTS = {
@@ -76,6 +62,7 @@ const deploy = async ({
7662

7763
const {
7864
config,
65+
params,
7966
configFile,
8067
synths,
8168
deployment,
@@ -90,6 +77,43 @@ const deploy = async ({
9077

9178
const standaloneFeeds = Object.values(feeds).filter(({ standalone }) => standalone);
9279

80+
const getDeployParameter = async name => {
81+
const defaultParam = defaults[name];
82+
let effectiveValue = defaultParam;
83+
84+
if (params) {
85+
const param = params.find(p => p.name == name);
86+
87+
if (param) {
88+
if (!yes) {
89+
try {
90+
await confirmAction(
91+
yellow(
92+
`⚠⚠⚠ WARNING: Found an entry for ${param.name} in params.json. Specified value is ${param.value} and default is ${defaultParam}.` +
93+
'\nDo you want to use the specified value (default otherwise)? (y/n) '
94+
)
95+
);
96+
97+
effectiveValue = param.value;
98+
} catch (err) {}
99+
} else {
100+
// yes = true
101+
effectiveValue = param.value;
102+
}
103+
}
104+
}
105+
106+
if (effectiveValue !== defaultParam) {
107+
console.log(
108+
yellow(
109+
`PARAMETER OVERRIDE: Overriding default ${name} with ${effectiveValue}, specified in params.json.`
110+
)
111+
);
112+
}
113+
114+
return effectiveValue;
115+
};
116+
93117
console.log(
94118
gray('Checking all contracts not flagged for deployment have addresses in this network...')
95119
);
@@ -1296,12 +1320,13 @@ const deploy = async ({
12961320
synths.map(({ name }) => systemSettings.methods.exchangeFeeRate(toBytes32(name)).call())
12971321
);
12981322

1323+
const exchangeFeeRates = await getDeployParameter('EXCHANGE_FEE_RATES');
12991324
const synthsRatesToUpdate = synths
13001325
.map((synth, i) =>
13011326
Object.assign(
13021327
{
13031328
currentRate: w3utils.fromWei(synthRates[i] || '0'),
1304-
targetRate: EXCHANGE_FEE_RATES[synth.category],
1329+
targetRate: exchangeFeeRates[synth.category],
13051330
},
13061331
synth
13071332
)
@@ -1342,7 +1367,7 @@ const deploy = async ({
13421367
read: 'waitingPeriodSecs',
13431368
expected: input => input !== '0',
13441369
write: 'setWaitingPeriodSecs',
1345-
writeArg: WAITING_PERIOD_SECS,
1370+
writeArg: await getDeployParameter('WAITING_PERIOD_SECS'),
13461371
});
13471372

13481373
await runStep({
@@ -1351,16 +1376,17 @@ const deploy = async ({
13511376
read: 'priceDeviationThresholdFactor',
13521377
expected: input => input !== '0', // only change if non-zero
13531378
write: 'setPriceDeviationThresholdFactor',
1354-
writeArg: PRICE_DEVIATION_THRESHOLD_FACTOR,
1379+
writeArg: await getDeployParameter('PRICE_DEVIATION_THRESHOLD_FACTOR'),
13551380
});
13561381

1382+
const tradingRewardsEnabled = await getDeployParameter('TRADING_REWARDS_ENABLED');
13571383
await runStep({
13581384
contract: 'SystemSettings',
13591385
target: systemSettings,
13601386
read: 'tradingRewardsEnabled',
1361-
expected: input => input === TRADING_REWARDS_ENABLED, // only change if non-default
1387+
expected: input => input === tradingRewardsEnabled, // only change if non-default
13621388
write: 'setTradingRewardsEnabled',
1363-
writeArg: TRADING_REWARDS_ENABLED,
1389+
writeArg: tradingRewardsEnabled,
13641390
});
13651391

13661392
await runStep({
@@ -1369,7 +1395,7 @@ const deploy = async ({
13691395
read: 'issuanceRatio',
13701396
expected: input => input !== '0', // only change if non-zero
13711397
write: 'setIssuanceRatio',
1372-
writeArg: ISSUANCE_RATIO,
1398+
writeArg: await getDeployParameter('ISSUANCE_RATIO'),
13731399
});
13741400

13751401
await runStep({
@@ -1378,7 +1404,7 @@ const deploy = async ({
13781404
read: 'feePeriodDuration',
13791405
expected: input => input !== '0', // only change if non-zero
13801406
write: 'setFeePeriodDuration',
1381-
writeArg: FEE_PERIOD_DURATION,
1407+
writeArg: await getDeployParameter('FEE_PERIOD_DURATION'),
13821408
});
13831409

13841410
await runStep({
@@ -1387,7 +1413,7 @@ const deploy = async ({
13871413
read: 'targetThreshold',
13881414
expected: input => input !== '0', // only change if non-zero
13891415
write: 'setTargetThreshold',
1390-
writeArg: TARGET_THRESHOLD,
1416+
writeArg: await getDeployParameter('TARGET_THRESHOLD'),
13911417
});
13921418

13931419
await runStep({
@@ -1396,7 +1422,7 @@ const deploy = async ({
13961422
read: 'liquidationDelay',
13971423
expected: input => input !== '0', // only change if non-zero
13981424
write: 'setLiquidationDelay',
1399-
writeArg: LIQUIDATION_DELAY,
1425+
writeArg: await getDeployParameter('LIQUIDATION_DELAY'),
14001426
});
14011427

14021428
await runStep({
@@ -1405,7 +1431,7 @@ const deploy = async ({
14051431
read: 'liquidationRatio',
14061432
expected: input => input !== '0', // only change if non-zero
14071433
write: 'setLiquidationRatio',
1408-
writeArg: LIQUIDATION_RATIO,
1434+
writeArg: await getDeployParameter('LIQUIDATION_RATIO'),
14091435
});
14101436

14111437
await runStep({
@@ -1414,7 +1440,7 @@ const deploy = async ({
14141440
read: 'liquidationPenalty',
14151441
expected: input => input !== '0', // only change if non-zero
14161442
write: 'setLiquidationPenalty',
1417-
writeArg: LIQUIDATION_PENALTY,
1443+
writeArg: await getDeployParameter('LIQUIDATION_PENALTY'),
14181444
});
14191445

14201446
await runStep({
@@ -1423,7 +1449,7 @@ const deploy = async ({
14231449
read: 'rateStalePeriod',
14241450
expected: input => input !== '0', // only change if non-zero
14251451
write: 'setRateStalePeriod',
1426-
writeArg: RATE_STALE_PERIOD,
1452+
writeArg: await getDeployParameter('RATE_STALE_PERIOD'),
14271453
});
14281454

14291455
await runStep({
@@ -1432,11 +1458,10 @@ const deploy = async ({
14321458
read: 'minimumStakeTime',
14331459
expected: input => input !== '0', // only change if non-zero
14341460
write: 'setMinimumStakeTime',
1435-
writeArg: MINIMUM_STAKE_TIME,
1461+
writeArg: await getDeployParameter('MINIMUM_STAKE_TIME'),
14361462
});
14371463

1438-
const aggregatorWarningFlags = AGGREGATOR_WARNING_FLAGS[network];
1439-
1464+
const aggregatorWarningFlags = (await getDeployParameter('AGGREGATOR_WARNING_FLAGS'))[network];
14401465
if (aggregatorWarningFlags) {
14411466
await runStep({
14421467
contract: 'SystemSettings',

publish/src/util.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const w3utils = require('web3-utils');
99
const {
1010
constants: {
1111
CONFIG_FILENAME,
12+
PARAMS_FILENAME,
1213
DEPLOYMENT_FILENAME,
1314
OWNER_ACTIONS_FILENAME,
1415
SYNTHS_FILENAME,
@@ -62,6 +63,10 @@ const loadAndCheckRequiredSources = ({ deploymentPath, network }) => {
6263
const configFile = path.join(deploymentPath, CONFIG_FILENAME);
6364
const config = JSON.parse(fs.readFileSync(configFile));
6465

66+
console.log(gray(`Loading the list of deployment parameters on ${network.toUpperCase()}...`));
67+
const paramsFile = path.join(deploymentPath, PARAMS_FILENAME);
68+
const params = JSON.parse(fs.readFileSync(paramsFile));
69+
6570
const versionsFile = path.join(deploymentPath, VERSIONS_FILENAME);
6671
const versions = network !== 'local' ? getVersions({ network, deploymentPath }) : {};
6772

@@ -85,6 +90,7 @@ const loadAndCheckRequiredSources = ({ deploymentPath, network }) => {
8590

8691
return {
8792
config,
93+
params,
8894
configFile,
8995
synths,
9096
synthsFile,

0 commit comments

Comments
 (0)