@keep-network/tbtc-v2 0.1.1-dev.85 → 0.1.1-dev.86

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.
Files changed (58) hide show
  1. package/artifacts/Bank.json +3 -3
  2. package/artifacts/Bridge.json +5 -5
  3. package/artifacts/Deposit.json +2 -2
  4. package/artifacts/DepositSweep.json +2 -2
  5. package/artifacts/EcdsaDkgValidator.json +1 -1
  6. package/artifacts/EcdsaInactivity.json +1 -1
  7. package/artifacts/EcdsaSortitionPool.json +2 -2
  8. package/artifacts/Fraud.json +2 -2
  9. package/artifacts/KeepRegistry.json +1 -1
  10. package/artifacts/KeepStake.json +2 -2
  11. package/artifacts/KeepToken.json +2 -2
  12. package/artifacts/KeepTokenStaking.json +1 -1
  13. package/artifacts/MovingFunds.json +2 -2
  14. package/artifacts/NuCypherStakingEscrow.json +1 -1
  15. package/artifacts/NuCypherToken.json +2 -2
  16. package/artifacts/RandomBeaconStub.json +1 -1
  17. package/artifacts/Redemption.json +2 -2
  18. package/artifacts/ReimbursementPool.json +2 -2
  19. package/artifacts/Relay.json +2 -2
  20. package/artifacts/T.json +2 -2
  21. package/artifacts/TBTC.json +3 -3
  22. package/artifacts/TBTCToken.json +3 -3
  23. package/artifacts/TBTCVault.json +140 -13
  24. package/artifacts/TokenStaking.json +1 -1
  25. package/artifacts/TokenholderGovernor.json +9 -9
  26. package/artifacts/TokenholderTimelock.json +8 -8
  27. package/artifacts/VendingMachine.json +3 -3
  28. package/artifacts/VendingMachineKeep.json +1 -1
  29. package/artifacts/VendingMachineNuCypher.json +1 -1
  30. package/artifacts/WalletRegistry.json +5 -5
  31. package/artifacts/WalletRegistryGovernance.json +2 -2
  32. package/artifacts/Wallets.json +2 -2
  33. package/artifacts/solcInputs/{0f79d51f4c2e0d6bf7d919933c677b91.json → 6371edede0c121e15ead18cf51551442.json} +7 -7
  34. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  35. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  36. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +1 -1
  37. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  38. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  39. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  40. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  41. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +1 -1
  42. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  43. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  44. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +1 -1
  45. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  46. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  47. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
  48. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
  49. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  50. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  51. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  52. package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +1 -1
  53. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  54. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  55. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +93 -2
  56. package/contracts/vault/TBTCVault.sol +58 -1
  57. package/export.json +91 -0
  58. package/package.json +1 -1
@@ -20,6 +20,7 @@ import "@keep-network/random-beacon/contracts/Governable.sol";
20
20
  import "./IVault.sol";
21
21
  import "../bank/Bank.sol";
22
22
  import "../token/TBTC.sol";
23
+ import "../GovernanceUtils.sol";
23
24
 
24
25
  /// @title TBTC application vault
25
26
  /// @notice TBTC is a fully Bitcoin-backed ERC-20 token pegged to the price of
@@ -30,18 +31,43 @@ import "../token/TBTC.sol";
30
31
  /// @dev TBTC Vault is the owner of TBTC token contract and is the only contract
31
32
  /// minting the token.
32
33
  contract TBTCVault is IVault, Governable {
34
+ /// @notice The time delay that needs to pass between initializing and
35
+ /// finalizing upgrade to a new vault. The time delay forces the
36
+ /// upgrading party to reflect on the vault address it is upgrading
37
+ /// to and lets all TBTC holders notice the planned
38
+ /// upgrade.
39
+ uint256 public constant UPGRADE_GOVERNANCE_DELAY = 24 hours;
40
+
33
41
  Bank public bank;
34
42
  TBTC public tbtcToken;
35
43
 
36
- event Minted(address indexed to, uint256 amount);
44
+ /// @notice The address of a new TBTC vault. Set only when the upgrade
45
+ /// process is pending. Once the upgrade gets finalized, the new
46
+ /// TBTC vault will become an owner of TBTC token.
47
+ address public newVault;
48
+ /// @notice The timestamp at which an upgrade to a new TBTC vault was
49
+ /// initiated. Set only when the upgrade process is pending.
50
+ uint256 public upgradeInitiatedTimestamp;
37
51
 
52
+ event Minted(address indexed to, uint256 amount);
38
53
  event Unminted(address indexed from, uint256 amount);
39
54
 
55
+ event UpgradeInitiated(address newVault, uint256 timestamp);
56
+ event UpgradeFinalized(address newVault);
57
+
40
58
  modifier onlyBank() {
41
59
  require(msg.sender == address(bank), "Caller is not the Bank");
42
60
  _;
43
61
  }
44
62
 
63
+ modifier onlyAfterUpgradeGovernanceDelay() {
64
+ GovernanceUtils.onlyAfterGovernanceDelay(
65
+ upgradeInitiatedTimestamp,
66
+ UPGRADE_GOVERNANCE_DELAY
67
+ );
68
+ _;
69
+ }
70
+
45
71
  constructor(Bank _bank, TBTC _tbtcToken) {
46
72
  require(
47
73
  address(_bank) != address(0),
@@ -192,6 +218,37 @@ contract TBTCVault is IVault, Governable {
192
218
  }
193
219
  }
194
220
 
221
+ /// @notice Initiates vault upgrade process. The upgrade process needs to be
222
+ /// finalized with a call to `finalizeUpgrade` function after the
223
+ /// `UPGRADE_GOVERNANCE_DELAY` passes. Only the governance can
224
+ /// initiate the upgrade.
225
+ /// @param _newVault The new vault address.
226
+ function initiateUpgrade(address _newVault) external onlyGovernance {
227
+ require(_newVault != address(0), "New vault address cannot be zero");
228
+ /* solhint-disable-next-line not-rely-on-time */
229
+ emit UpgradeInitiated(_newVault, block.timestamp);
230
+ /* solhint-disable-next-line not-rely-on-time */
231
+ upgradeInitiatedTimestamp = block.timestamp;
232
+ newVault = _newVault;
233
+ }
234
+
235
+ /// @notice Allows the governance to finalize vault upgrade process. The
236
+ /// upgrade process needs to be first initiated with a call to
237
+ /// `initiateUpgrade` and the `UPGRADE_GOVERNANCE_DELAY` needs to
238
+ /// pass. Once the upgrade is finalized, the new vault will become
239
+ /// an owner of TBTC token.
240
+ function finalizeUpgrade()
241
+ external
242
+ onlyGovernance
243
+ onlyAfterUpgradeGovernanceDelay
244
+ {
245
+ emit UpgradeFinalized(newVault);
246
+ // slither-disable-next-line reentrancy-no-eth
247
+ tbtcToken.transferOwnership(newVault);
248
+ newVault = address(0);
249
+ upgradeInitiatedTimestamp = 0;
250
+ }
251
+
195
252
  // slither-disable-next-line calls-loop
196
253
  function _mint(address minter, uint256 amount) internal {
197
254
  emit Minted(minter, amount);
package/export.json CHANGED
@@ -16883,6 +16883,51 @@
16883
16883
  "name": "Unminted",
16884
16884
  "type": "event"
16885
16885
  },
16886
+ {
16887
+ "anonymous": false,
16888
+ "inputs": [
16889
+ {
16890
+ "indexed": false,
16891
+ "internalType": "address",
16892
+ "name": "newVault",
16893
+ "type": "address"
16894
+ }
16895
+ ],
16896
+ "name": "UpgradeFinalized",
16897
+ "type": "event"
16898
+ },
16899
+ {
16900
+ "anonymous": false,
16901
+ "inputs": [
16902
+ {
16903
+ "indexed": false,
16904
+ "internalType": "address",
16905
+ "name": "newVault",
16906
+ "type": "address"
16907
+ },
16908
+ {
16909
+ "indexed": false,
16910
+ "internalType": "uint256",
16911
+ "name": "timestamp",
16912
+ "type": "uint256"
16913
+ }
16914
+ ],
16915
+ "name": "UpgradeInitiated",
16916
+ "type": "event"
16917
+ },
16918
+ {
16919
+ "inputs": [],
16920
+ "name": "UPGRADE_GOVERNANCE_DELAY",
16921
+ "outputs": [
16922
+ {
16923
+ "internalType": "uint256",
16924
+ "name": "",
16925
+ "type": "uint256"
16926
+ }
16927
+ ],
16928
+ "stateMutability": "view",
16929
+ "type": "function"
16930
+ },
16886
16931
  {
16887
16932
  "inputs": [],
16888
16933
  "name": "bank",
@@ -16896,6 +16941,13 @@
16896
16941
  "stateMutability": "view",
16897
16942
  "type": "function"
16898
16943
  },
16944
+ {
16945
+ "inputs": [],
16946
+ "name": "finalizeUpgrade",
16947
+ "outputs": [],
16948
+ "stateMutability": "nonpayable",
16949
+ "type": "function"
16950
+ },
16899
16951
  {
16900
16952
  "inputs": [],
16901
16953
  "name": "governance",
@@ -16909,6 +16961,19 @@
16909
16961
  "stateMutability": "view",
16910
16962
  "type": "function"
16911
16963
  },
16964
+ {
16965
+ "inputs": [
16966
+ {
16967
+ "internalType": "address",
16968
+ "name": "_newVault",
16969
+ "type": "address"
16970
+ }
16971
+ ],
16972
+ "name": "initiateUpgrade",
16973
+ "outputs": [],
16974
+ "stateMutability": "nonpayable",
16975
+ "type": "function"
16976
+ },
16912
16977
  {
16913
16978
  "inputs": [
16914
16979
  {
@@ -16922,6 +16987,19 @@
16922
16987
  "stateMutability": "nonpayable",
16923
16988
  "type": "function"
16924
16989
  },
16990
+ {
16991
+ "inputs": [],
16992
+ "name": "newVault",
16993
+ "outputs": [
16994
+ {
16995
+ "internalType": "address",
16996
+ "name": "",
16997
+ "type": "address"
16998
+ }
16999
+ ],
17000
+ "stateMutability": "view",
17001
+ "type": "function"
17002
+ },
16925
17003
  {
16926
17004
  "inputs": [
16927
17005
  {
@@ -17098,6 +17176,19 @@
17098
17176
  "outputs": [],
17099
17177
  "stateMutability": "nonpayable",
17100
17178
  "type": "function"
17179
+ },
17180
+ {
17181
+ "inputs": [],
17182
+ "name": "upgradeInitiatedTimestamp",
17183
+ "outputs": [
17184
+ {
17185
+ "internalType": "uint256",
17186
+ "name": "",
17187
+ "type": "uint256"
17188
+ }
17189
+ ],
17190
+ "stateMutability": "view",
17191
+ "type": "function"
17101
17192
  }
17102
17193
  ]
17103
17194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keep-network/tbtc-v2",
3
- "version": "0.1.1-dev.85+main.fb30690e353afd45b08ebfb46ab76800eb78912b",
3
+ "version": "0.1.1-dev.86+main.a2af959fe52dd8730a212f386b63242faac7d844",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "artifacts/",