Skip to content

Commit f912390

Browse files
committed
add reusable predicate function
1 parent 947a815 commit f912390

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ const defaults = {
203203
const toBytes32 = key => w3utils.rightPad(w3utils.asciiToHex(key), 64);
204204
const fromBytes32 = key => w3utils.hexToAscii(key);
205205

206+
const allowZeroOrUpdateIfNonZero = param => input => param === '0' || input !== '0';
207+
206208
const getFolderNameForNetwork = ({ network, useOvm = false }) => {
207209
if (network.includes('ovm')) {
208210
return network;
@@ -635,6 +637,7 @@ const wrap = ({ network, deploymentPath, fs, path, useOvm = false }) =>
635637
}, {});
636638

637639
module.exports = {
640+
allowZeroOrUpdateIfNonZero,
638641
chainIdMapping,
639642
constants,
640643
decode,

publish/src/commands/deploy/configure-loans.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const { gray } = require('chalk');
4-
const { toBytes32 } = require('../../../..');
4+
const { toBytes32, allowZeroOrUpdateIfNonZero } = require('../../../..');
55

66
module.exports = async ({
77
addressOf,
@@ -85,7 +85,7 @@ module.exports = async ({
8585
contract: 'CollateralEth',
8686
target: CollateralEth,
8787
read: 'issueFeeRate',
88-
expected: input => issueFeeRate === '0' || input !== '0',
88+
expected: allowZeroOrUpdateIfNonZero(issueFeeRate),
8989
write: 'setIssueFeeRate',
9090
writeArg: [issueFeeRate],
9191
comment: 'Ensure the CollateralEth contract has its issue fee rate set',
@@ -127,7 +127,7 @@ module.exports = async ({
127127
contract: 'CollateralErc20',
128128
target: CollateralErc20,
129129
read: 'issueFeeRate',
130-
expected: input => issueFeeRate === '0' || input !== '0',
130+
expected: allowZeroOrUpdateIfNonZero(issueFeeRate),
131131
write: 'setIssueFeeRate',
132132
writeArg: [issueFeeRate],
133133
comment: 'Ensure the CollateralErc20 contract has its issue fee rate set',
@@ -169,7 +169,7 @@ module.exports = async ({
169169
contract: 'CollateralShort',
170170
target: CollateralShort,
171171
read: 'issueFeeRate',
172-
expected: input => issueFeeRate === '0' || input !== '0',
172+
expected: allowZeroOrUpdateIfNonZero(issueFeeRate),
173173
write: 'setIssueFeeRate',
174174
writeArg: [issueFeeRate],
175175
comment: 'Ensure the CollateralShort contract has its issue fee rate set',
@@ -181,7 +181,7 @@ module.exports = async ({
181181
contract: 'CollateralShort',
182182
target: CollateralShort,
183183
read: 'interactionDelay',
184-
expected: input => interactionDelay === '0' || input !== '0',
184+
expected: allowZeroOrUpdateIfNonZero(interactionDelay),
185185
write: 'setInteractionDelay',
186186
writeArg: [interactionDelay],
187187
comment:
@@ -195,7 +195,7 @@ module.exports = async ({
195195
contract: 'CollateralManager',
196196
target: CollateralManager,
197197
read: 'maxDebt',
198-
expected: input => maxDebt === '0' || input !== '0',
198+
expected: allowZeroOrUpdateIfNonZero(maxDebt),
199199
write: 'setMaxDebt',
200200
writeArg: [maxDebt],
201201
comment: 'Set the max amount of debt in the CollateralManager',
@@ -207,7 +207,7 @@ module.exports = async ({
207207
contract: 'CollateralManager',
208208
target: CollateralManager,
209209
read: 'maxSkewRate',
210-
expected: input => maxSkewRate === '0' || input !== '0',
210+
expected: allowZeroOrUpdateIfNonZero(maxSkewRate),
211211
write: 'setMaxSkewRate',
212212
writeArg: [maxSkewRate],
213213
comment: 'Set the max skew rate in the CollateralManager',
@@ -219,7 +219,7 @@ module.exports = async ({
219219
contract: 'CollateralManager',
220220
target: CollateralManager,
221221
read: 'baseBorrowRate',
222-
expected: input => baseBorrowRate === '0' || input !== '0',
222+
expected: allowZeroOrUpdateIfNonZero(baseBorrowRate),
223223
write: 'setBaseBorrowRate',
224224
writeArg: [baseBorrowRate],
225225
comment: 'Set the base borrow rate in the CollateralManager',
@@ -230,7 +230,7 @@ module.exports = async ({
230230
contract: 'CollateralManager',
231231
target: CollateralManager,
232232
read: 'baseShortRate',
233-
expected: input => baseShortRate === '0' || input !== '0',
233+
expected: allowZeroOrUpdateIfNonZero(baseShortRate),
234234
write: 'setBaseShortRate',
235235
writeArg: [baseShortRate],
236236
comment: 'Set the base short rate in the CollateralManager',

publish/src/commands/deploy/configure-system-settings.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
} = require('ethers');
77
const {
88
toBytes32,
9+
allowZeroOrUpdateIfNonZero,
910
constants: { ZERO_ADDRESS },
1011
} = require('../../../..');
1112

@@ -107,7 +108,7 @@ module.exports = async ({
107108
target: SystemSettings,
108109
read: 'waitingPeriodSecs',
109110
readTarget: previousSystemSettings,
110-
expected: input => waitingPeriodSecs === '0' || input !== '0', // only change if setting to non-zero from zero
111+
expected: allowZeroOrUpdateIfNonZero(waitingPeriodSecs),
111112
write: 'setWaitingPeriodSecs',
112113
writeArg: waitingPeriodSecs,
113114
comment: 'Set the fee reclamation (SIP-37) waiting period',
@@ -121,7 +122,7 @@ module.exports = async ({
121122
target: SystemSettings,
122123
read: 'priceDeviationThresholdFactor',
123124
readTarget: previousSystemSettings,
124-
expected: input => priceDeviationThresholdFactor === '0' || input !== '0',
125+
expected: allowZeroOrUpdateIfNonZero(priceDeviationThresholdFactor),
125126
write: 'setPriceDeviationThresholdFactor',
126127
writeArg: priceDeviationThresholdFactor,
127128
comment: 'Set the threshold for the circuit breaker (SIP-65)',
@@ -145,7 +146,7 @@ module.exports = async ({
145146
target: SystemSettings,
146147
read: 'issuanceRatio',
147148
readTarget: previousSystemSettings,
148-
expected: input => issuanceRatio === '0' || input !== '0',
149+
expected: allowZeroOrUpdateIfNonZero(issuanceRatio),
149150
write: 'setIssuanceRatio',
150151
writeArg: issuanceRatio,
151152
comment: 'Set the issuance ratio - the c-ratio stored as an inverted decimal',
@@ -157,7 +158,7 @@ module.exports = async ({
157158
target: SystemSettings,
158159
read: 'feePeriodDuration',
159160
readTarget: previousSystemSettings,
160-
expected: input => feePeriodDuration === '0' || input !== '0',
161+
expected: allowZeroOrUpdateIfNonZero(feePeriodDuration),
161162
write: 'setFeePeriodDuration',
162163
writeArg: feePeriodDuration,
163164
comment: 'Set the fee period duration',
@@ -169,7 +170,7 @@ module.exports = async ({
169170
target: SystemSettings,
170171
read: 'targetThreshold',
171172
readTarget: previousSystemSettings,
172-
expected: input => targetThreshold === '0' || input !== '0',
173+
expected: allowZeroOrUpdateIfNonZero(targetThreshold),
173174
write: 'setTargetThreshold',
174175
writeArg: targetThreshold,
175176
comment:
@@ -182,7 +183,7 @@ module.exports = async ({
182183
target: SystemSettings,
183184
read: 'liquidationDelay',
184185
readTarget: previousSystemSettings,
185-
expected: input => liquidationDelay === '0' || input !== '0',
186+
expected: allowZeroOrUpdateIfNonZero(liquidationDelay),
186187
write: 'setLiquidationDelay',
187188
writeArg: liquidationDelay,
188189
comment: 'Set the delay from when an account is flagged till when it can be liquidated',
@@ -194,7 +195,7 @@ module.exports = async ({
194195
target: SystemSettings,
195196
read: 'liquidationRatio',
196197
readTarget: previousSystemSettings,
197-
expected: input => liquidationRatio === '0' || input !== '0',
198+
expected: allowZeroOrUpdateIfNonZero(liquidationRatio),
198199
write: 'setLiquidationRatio',
199200
writeArg: liquidationRatio,
200201
comment: 'Set the ratio below which an account can be flagged for liquidation',
@@ -206,7 +207,7 @@ module.exports = async ({
206207
target: SystemSettings,
207208
read: 'liquidationPenalty',
208209
readTarget: previousSystemSettings,
209-
expected: input => liquidationPenalty === '0' || input !== '0',
210+
expected: allowZeroOrUpdateIfNonZero(liquidationPenalty),
210211
write: 'setLiquidationPenalty',
211212
writeArg: liquidationPenalty,
212213
comment: 'Set the penalty amount a liquidator receives from a liquidated account',
@@ -218,7 +219,7 @@ module.exports = async ({
218219
target: SystemSettings,
219220
read: 'rateStalePeriod',
220221
readTarget: previousSystemSettings,
221-
expected: input => rateStalePeriod === '0' || input !== '0',
222+
expected: allowZeroOrUpdateIfNonZero(rateStalePeriod),
222223
write: 'setRateStalePeriod',
223224
writeArg: rateStalePeriod,
224225
comment: 'Set the maximum amount of time (in secs) that a rate can be used for',
@@ -230,7 +231,7 @@ module.exports = async ({
230231
target: SystemSettings,
231232
read: 'minimumStakeTime',
232233
readTarget: previousSystemSettings,
233-
expected: input => minimumStakeTime === '0' || input !== '0',
234+
expected: allowZeroOrUpdateIfNonZero(minimumStakeTime),
234235
write: 'setMinimumStakeTime',
235236
writeArg: minimumStakeTime,
236237
comment: 'Set the minimum amount of time SNX can be issued before any is burned (SIP-40)',
@@ -242,7 +243,7 @@ module.exports = async ({
242243
target: SystemSettings,
243244
read: 'debtSnapshotStaleTime',
244245
readTarget: previousSystemSettings,
245-
expected: input => debtSnapshotStaleTime === '0' || input !== '0',
246+
expected: allowZeroOrUpdateIfNonZero(debtSnapshotStaleTime),
246247
write: 'setDebtSnapshotStaleTime',
247248
writeArg: debtSnapshotStaleTime,
248249
comment: 'Set the length of time after which the DebtCache snapshot becomes stale (SIP-91)',
@@ -255,7 +256,7 @@ module.exports = async ({
255256
read: 'crossDomainMessageGasLimit',
256257
readArg: 0,
257258
readTarget: previousSystemSettings,
258-
expected: input => crossDomainDepositGasLimit === '0' || input !== '0',
259+
expected: allowZeroOrUpdateIfNonZero(crossDomainDepositGasLimit),
259260
write: 'setCrossDomainMessageGasLimit',
260261
writeArg: [0, crossDomainDepositGasLimit],
261262
comment: 'Set the gas limit for depositing onto L2',
@@ -268,7 +269,7 @@ module.exports = async ({
268269
read: 'crossDomainMessageGasLimit',
269270
readArg: 1,
270271
readTarget: previousSystemSettings,
271-
expected: input => crossDomainEscrowGasLimit === '0' || input !== '0',
272+
expected: allowZeroOrUpdateIfNonZero(crossDomainEscrowGasLimit),
272273
write: 'setCrossDomainMessageGasLimit',
273274
writeArg: [1, crossDomainEscrowGasLimit],
274275
comment: 'Set the gas limit for migrating escrowed SNX to L2',
@@ -281,7 +282,7 @@ module.exports = async ({
281282
read: 'crossDomainMessageGasLimit',
282283
readArg: 2,
283284
readTarget: previousSystemSettings,
284-
expected: input => crossDomainRewardGasLimit === '0' || input !== '0',
285+
expected: allowZeroOrUpdateIfNonZero(crossDomainRewardGasLimit),
285286
write: 'setCrossDomainMessageGasLimit',
286287
writeArg: [2, crossDomainRewardGasLimit],
287288
comment: 'Set the gas limit for depositing rewards to L2',
@@ -296,7 +297,7 @@ module.exports = async ({
296297
read: 'crossDomainMessageGasLimit',
297298
readArg: 3,
298299
readTarget: previousSystemSettings,
299-
expected: input => crossDomainWithdrawalGasLimit === '0' || input !== '0',
300+
expected: allowZeroOrUpdateIfNonZero(crossDomainWithdrawalGasLimit),
300301
write: 'setCrossDomainMessageGasLimit',
301302
writeArg: [3, crossDomainWithdrawalGasLimit],
302303
comment: 'Set the gas limit for withdrawing from L2',
@@ -309,7 +310,7 @@ module.exports = async ({
309310
read: 'crossDomainMessageGasLimit',
310311
readArg: 4,
311312
readTarget: previousSystemSettings,
312-
expected: input => crossDomainRelayGasLimit === '0' || input !== '0',
313+
expected: allowZeroOrUpdateIfNonZero(crossDomainRelayGasLimit),
313314
write: 'setCrossDomainMessageGasLimit',
314315
writeArg: [4, crossDomainRelayGasLimit],
315316
comment: 'Set the gas limit for relaying owner actions to L2',
@@ -336,7 +337,7 @@ module.exports = async ({
336337
target: SystemSettings,
337338
read: 'etherWrapperMaxETH',
338339
readTarget: previousSystemSettings,
339-
expected: input => etherWrapperMaxETH === '0' || input !== '0',
340+
expected: allowZeroOrUpdateIfNonZero(etherWrapperMaxETH),
340341
write: 'setEtherWrapperMaxETH',
341342
writeArg: etherWrapperMaxETH,
342343
comment: 'Set the max amount of Ether allowed in the EtherWrapper (SIP-112)',
@@ -348,7 +349,7 @@ module.exports = async ({
348349
target: SystemSettings,
349350
read: 'etherWrapperMintFeeRate',
350351
readTarget: previousSystemSettings,
351-
expected: input => etherWrapperMintFeeRate === '0' || input !== '0',
352+
expected: allowZeroOrUpdateIfNonZero(etherWrapperMintFeeRate),
352353
write: 'setEtherWrapperMintFeeRate',
353354
writeArg: etherWrapperMintFeeRate,
354355
comment: 'Set the fee rate for minting sETH from ETH in the EtherWrapper (SIP-112)',
@@ -361,7 +362,7 @@ module.exports = async ({
361362
target: SystemSettings,
362363
read: 'etherWrapperBurnFeeRate',
363364
readTarget: previousSystemSettings,
364-
expected: input => etherWrapperBurnFeeRate === '0' || input !== '0', // only change if the value to set is above zero and the value onchain is 0
365+
expected: allowZeroOrUpdateIfNonZero(etherWrapperBurnFeeRate),
365366
write: 'setEtherWrapperBurnFeeRate',
366367
writeArg: etherWrapperBurnFeeRate,
367368
comment: 'Set the fee rate for burning sETH for ETH in the EtherWrapper (SIP-112)',
@@ -376,7 +377,7 @@ module.exports = async ({
376377
target: SystemSettings,
377378
read: 'atomicMaxVolumePerBlock',
378379
readTarget: previousSystemSettings,
379-
expected: input => atomicMaxVolumePerBlock === '0' || input !== '0', // only change if setting to non-zero from zero
380+
expected: allowZeroOrUpdateIfNonZero(atomicMaxVolumePerBlock),
380381
write: 'setAtomicMaxVolumePerBlock',
381382
writeArg: atomicMaxVolumePerBlock,
382383
comment: 'SIP-120 Set max atomic volume per block (in USD amounts)',
@@ -390,7 +391,7 @@ module.exports = async ({
390391
target: SystemSettings,
391392
read: 'atomicTwapWindow',
392393
readTarget: previousSystemSettings,
393-
expected: input => atomicTwapWindow === '0' || input !== '0',
394+
expected: allowZeroOrUpdateIfNonZero(atomicTwapWindow),
394395
write: 'setAtomicTwapWindow',
395396
writeArg: atomicTwapWindow,
396397
comment: 'SIP-120 Set the TWAP window for atomic swaps',
@@ -513,7 +514,7 @@ module.exports = async ({
513514
read: 'interactionDelay',
514515
readArg: addressOf(CollateralShort),
515516
readTarget: previousSystemSettings,
516-
expected: input => interactionDelay === '0' || input !== '0',
517+
expected: allowZeroOrUpdateIfNonZero(interactionDelay),
517518
write: 'setInteractionDelay',
518519
writeArg: [CollateralShort.address, interactionDelay],
519520
comment: 'Ensure the CollateralShort contract has an interaction delay of zero on the OVM',
@@ -528,7 +529,7 @@ module.exports = async ({
528529
read: 'collapseFeeRate',
529530
readArg: addressOf(CollateralShort),
530531
readTarget: previousSystemSettings,
531-
expected: input => collapseFeeRate === '0' || input !== '0',
532+
expected: allowZeroOrUpdateIfNonZero(collapseFeeRate),
532533
write: 'setCollapseFeeRate',
533534
writeArg: [CollateralShort.address, collapseFeeRate],
534535
comment:

0 commit comments

Comments
 (0)