@@ -9,18 +9,23 @@ import {IBTCETHPriceFeed} from "../interfaces/IBTCETHPriceFeed.sol";
99import {DepositLog} from "../DepositLog.sol " ;
1010
1111import "openzeppelin-solidity/contracts/ownership/Ownable.sol " ;
12+ import "openzeppelin-solidity/contracts/math/SafeMath.sol " ;
1213
1314contract TBTCSystem is Ownable , ITBTCSystem , DepositLog {
1415
15- event LogLotSizesUpdated (uint256 [] _lotSizes );
16- event LogAllowNewDepositsUpdated (bool _allowNewDeposits );
17- event LogSignerFeeDivisorUpdated (uint256 _signerFeeDivisor );
18- event LogCollateralizationThresholdsUpdated (
16+ using SafeMath for uint256 ;
17+
18+ event LotSizesUpdated (uint256 [] _lotSizes );
19+ event AllowNewDepositsUpdated (bool _allowNewDeposits );
20+ event SignerFeeDivisorUpdated (uint256 _signerFeeDivisor );
21+ event CollateralizationThresholdsUpdated (
1922 uint256 _undercollateralizedThresholdPercent ,
2023 uint256 _severelyUndercollateralizedThresholdPercent
2124 );
2225
2326 bool _initialized = false ;
27+ uint256 pausedTimestamp;
28+ uint256 pausedDuration = 10 days ;
2429
2530 uint256 currentDifficulty = 1 ;
2631 uint256 previousDifficulty = 1 ;
@@ -29,7 +34,7 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
2934 address public priceFeed;
3035
3136 // Parameters governed by the TBTCSystem owner
32- bool private allowNewDeposits = true ;
37+ bool private allowNewDeposits = false ;
3338 uint256 private signerFeeDivisor = 200 ; // 1/200 == 50bps == 0.5% == 0.005
3439 uint128 private undercollateralizedThresholdPercent = 140 ; // percent
3540 uint128 private severelyUndercollateralizedThresholdPercent = 120 ; // percent
@@ -46,19 +51,34 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
4651
4752 keepRegistry = _keepRegistry;
4853 _initialized = true ;
54+ allowNewDeposits = true ;
4955 }
5056
51- /// @notice Enables/disables new deposits from being created.
52- /// @param _allowNewDeposits Whether to allow new deposits.
53- function setAllowNewDeposits (bool _allowNewDeposits )
54- external onlyOwner
55- {
56- allowNewDeposits = _allowNewDeposits;
57- emit LogAllowNewDepositsUpdated (_allowNewDeposits);
57+ /// @notice gets whether new deposits are allowed
58+ function getAllowNewDeposits () external view returns (bool ) { return allowNewDeposits; }
59+
60+ /// @notice One-time-use emergency function to disallow future deposit creation for 10 days.
61+ function emergencyPauseNewDeposits () external onlyOwner returns (bool ) {
62+ require (pausedTimestamp == 0 , "emergencyPauseNewDeposits can only be called once " );
63+ pausedTimestamp = block .timestamp ;
64+ allowNewDeposits = false ;
65+ emit AllowNewDepositsUpdated (false );
5866 }
5967
60- /// @notice Gets whether new deposits are allowed.
61- function getAllowNewDeposits () external view returns (bool ) { return allowNewDeposits; }
68+ /// @notice Anyone can reactivate deposit creations after the pause duration is over.
69+ function resumeNewDeposits () public {
70+ require (allowNewDeposits == false , "New deposits are currently allowed " );
71+ require (block .timestamp .sub (pausedTimestamp) >= pausedDuration, "Deposits are still paused " );
72+ allowNewDeposits = true ;
73+ emit AllowNewDepositsUpdated (true );
74+ }
75+
76+ function getRemainingPauseTerm () public view returns (uint256 ) {
77+ require (allowNewDeposits == false , "New deposits are currently allowed " );
78+ return (block .timestamp .sub (pausedTimestamp) >= pausedDuration)?
79+ 0 :
80+ pausedDuration.sub (block .timestamp .sub (pausedTimestamp));
81+ }
6282
6383 /// @notice Set the system signer fee divisor.
6484 /// @param _signerFeeDivisor The signer fee divisor.
@@ -67,7 +87,7 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
6787 {
6888 require (_signerFeeDivisor > 1 , "Signer fee must be lower than 100% " );
6989 signerFeeDivisor = _signerFeeDivisor;
70- emit LogSignerFeeDivisorUpdated (_signerFeeDivisor);
90+ emit SignerFeeDivisorUpdated (_signerFeeDivisor);
7191 }
7292
7393 /// @notice Gets the system signer fee divisor.
@@ -78,8 +98,14 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
7898 /// @dev Lot sizes should be
7999 /// @param _lotSizes Array of allowed lot sizes.
80100 function setLotSizes (uint256 [] calldata _lotSizes ) external onlyOwner {
81- lotSizesSatoshis = _lotSizes;
82- emit LogLotSizesUpdated (_lotSizes);
101+ for ( uint i = 0 ; i < _lotSizes.length ; i++ ){
102+ if (_lotSizes[i] == 10 ** 8 ){
103+ lotSizesSatoshis = _lotSizes;
104+ emit LotSizesUpdated (_lotSizes);
105+ return ;
106+ }
107+ }
108+ revert ("Lot size array must always contain 1BTC " );
83109 }
84110
85111 /// @notice Gets the allowed lot sizes
@@ -113,7 +139,7 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
113139 );
114140 undercollateralizedThresholdPercent = _undercollateralizedThresholdPercent;
115141 severelyUndercollateralizedThresholdPercent = _severelyUndercollateralizedThresholdPercent;
116- emit LogCollateralizationThresholdsUpdated (
142+ emit CollateralizationThresholdsUpdated (
117143 _undercollateralizedThresholdPercent,
118144 _severelyUndercollateralizedThresholdPercent
119145 );
0 commit comments