@keep-network/tbtc-v2 0.1.1-dev.8 → 0.1.1-dev.80

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 (112) hide show
  1. package/README.adoc +12 -0
  2. package/artifacts/Bank.json +757 -0
  3. package/artifacts/Bridge.json +2644 -0
  4. package/artifacts/Deposit.json +117 -0
  5. package/artifacts/DepositSweep.json +77 -0
  6. package/artifacts/EcdsaDkgValidator.json +532 -0
  7. package/artifacts/EcdsaInactivity.json +156 -0
  8. package/artifacts/EcdsaSortitionPool.json +1004 -0
  9. package/artifacts/Fraud.json +164 -0
  10. package/artifacts/KeepRegistry.json +99 -0
  11. package/artifacts/KeepStake.json +286 -0
  12. package/artifacts/KeepToken.json +711 -0
  13. package/artifacts/KeepTokenStaking.json +483 -0
  14. package/artifacts/MovingFunds.json +249 -0
  15. package/artifacts/NuCypherStakingEscrow.json +256 -0
  16. package/artifacts/NuCypherToken.json +711 -0
  17. package/artifacts/RandomBeaconStub.json +141 -0
  18. package/artifacts/Redemption.json +162 -0
  19. package/artifacts/ReimbursementPool.json +509 -0
  20. package/artifacts/Relay.json +123 -0
  21. package/artifacts/T.json +1148 -0
  22. package/artifacts/TBTC.json +27 -26
  23. package/artifacts/TBTCToken.json +27 -26
  24. package/artifacts/TBTCVault.json +462 -0
  25. package/artifacts/TokenStaking.json +2288 -0
  26. package/artifacts/TokenholderGovernor.json +1795 -0
  27. package/artifacts/TokenholderTimelock.json +1058 -0
  28. package/artifacts/VendingMachine.json +30 -29
  29. package/artifacts/VendingMachineKeep.json +400 -0
  30. package/artifacts/VendingMachineNuCypher.json +400 -0
  31. package/artifacts/WalletRegistry.json +1843 -0
  32. package/artifacts/WalletRegistryGovernance.json +2754 -0
  33. package/artifacts/Wallets.json +186 -0
  34. package/artifacts/solcInputs/4f6d4f5cd1e3d835e20ed55926a445cd.json +311 -0
  35. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  36. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
  37. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  38. package/build/contracts/bank/Bank.sol/Bank.json +25 -2
  39. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +4 -0
  40. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.json +34 -0
  41. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  42. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  43. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  44. package/build/contracts/bridge/Bridge.sol/Bridge.json +2516 -196
  45. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  46. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +226 -0
  47. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
  48. package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
  49. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
  50. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +30 -0
  51. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
  52. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
  53. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
  54. package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
  55. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +4 -0
  56. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.json +10 -0
  57. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
  58. package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
  59. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
  60. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +138 -0
  61. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
  62. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
  63. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
  64. package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
  65. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  66. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
  67. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
  68. package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
  69. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  70. package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
  71. package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +4 -0
  72. package/build/contracts/vault/DonationVault.sol/DonationVault.json +108 -0
  73. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  74. package/build/contracts/vault/IVault.sol/IVault.json +24 -1
  75. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  76. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +126 -7
  77. package/contracts/GovernanceUtils.sol +4 -4
  78. package/contracts/bank/Bank.sol +45 -20
  79. package/contracts/bank/IReceiveBalanceApproval.sol +45 -0
  80. package/contracts/bridge/BitcoinTx.sol +232 -10
  81. package/contracts/bridge/Bridge.sol +1601 -244
  82. package/contracts/bridge/BridgeState.sol +739 -0
  83. package/contracts/bridge/Deposit.sol +269 -0
  84. package/contracts/bridge/DepositSweep.sol +571 -0
  85. package/contracts/bridge/EcdsaLib.sol +45 -0
  86. package/contracts/bridge/Fraud.sol +604 -0
  87. package/contracts/bridge/Heartbeat.sol +112 -0
  88. package/contracts/bridge/IRelay.sol +28 -0
  89. package/contracts/bridge/MovingFunds.sol +1089 -0
  90. package/contracts/bridge/Redemption.sol +867 -0
  91. package/contracts/bridge/VendingMachine.sol +1 -1
  92. package/contracts/bridge/Wallets.sol +553 -0
  93. package/contracts/hardhat-dependency-compiler/.hardhat-dependency-compiler +1 -0
  94. package/contracts/hardhat-dependency-compiler/@keep-network/ecdsa/contracts/WalletRegistry.sol +3 -0
  95. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol +3 -0
  96. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +3 -0
  97. package/contracts/token/TBTC.sol +1 -1
  98. package/contracts/vault/DonationVault.sol +125 -0
  99. package/contracts/vault/IVault.sol +19 -13
  100. package/contracts/vault/TBTCVault.sol +58 -8
  101. package/deploy/00_resolve_relay.ts +28 -0
  102. package/deploy/04_deploy_bank.ts +27 -0
  103. package/deploy/05_deploy_bridge.ts +80 -0
  104. package/deploy/06_deploy_tbtc_vault.ts +30 -0
  105. package/deploy/07_bank_update_bridge.ts +19 -0
  106. package/deploy/08_transfer_ownership.ts +15 -0
  107. package/deploy/09_transfer_governance.ts +20 -0
  108. package/deploy/10_transfer_proxy_admin_ownership.ts +30 -0
  109. package/deploy/11_deploy_proxy_admin_with_deputy.ts +33 -0
  110. package/export.json +15993 -475
  111. package/package.json +32 -25
  112. package/artifacts/solcInputs/4cf328e09411ac69d75a3c381680bc2c.json +0 -128
@@ -0,0 +1,739 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ // ██████████████ ▐████▌ ██████████████
4
+ // ██████████████ ▐████▌ ██████████████
5
+ // ▐████▌ ▐████▌
6
+ // ▐████▌ ▐████▌
7
+ // ██████████████ ▐████▌ ██████████████
8
+ // ██████████████ ▐████▌ ██████████████
9
+ // ▐████▌ ▐████▌
10
+ // ▐████▌ ▐████▌
11
+ // ▐████▌ ▐████▌
12
+ // ▐████▌ ▐████▌
13
+ // ▐████▌ ▐████▌
14
+ // ▐████▌ ▐████▌
15
+
16
+ pragma solidity ^0.8.9;
17
+
18
+ import {IWalletRegistry as EcdsaWalletRegistry} from "@keep-network/ecdsa/contracts/api/IWalletRegistry.sol";
19
+
20
+ import "./IRelay.sol";
21
+ import "./Deposit.sol";
22
+ import "./Redemption.sol";
23
+ import "./Fraud.sol";
24
+ import "./Wallets.sol";
25
+ import "./MovingFunds.sol";
26
+
27
+ import "../bank/Bank.sol";
28
+
29
+ library BridgeState {
30
+ struct Storage {
31
+ // Address of the Bank the Bridge belongs to.
32
+ Bank bank;
33
+ // Bitcoin relay providing the current Bitcoin network difficulty.
34
+ IRelay relay;
35
+ // ECDSA Wallet Registry contract handle.
36
+ EcdsaWalletRegistry ecdsaWalletRegistry;
37
+ // The number of confirmations on the Bitcoin chain required to
38
+ // successfully evaluate an SPV proof.
39
+ uint256 txProofDifficultyFactor;
40
+ // Address where the deposit and redemption treasury fees will be sent
41
+ // to. Treasury takes part in the operators rewarding process.
42
+ address treasury;
43
+ // The minimal amount that can be requested to deposit.
44
+ // Value of this parameter must take into account the value of
45
+ // `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters in order
46
+ // to make requests that can incur the treasury and transaction fee and
47
+ // still satisfy the depositor.
48
+ uint64 depositDustThreshold;
49
+ // Divisor used to compute the treasury fee taken from each deposit and
50
+ // transferred to the treasury upon sweep proof submission. That fee is
51
+ // computed as follows:
52
+ // `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
53
+ // For example, if the treasury fee needs to be 2% of each deposit,
54
+ // the `depositTreasuryFeeDivisor` should be set to `50` because
55
+ // `1/50 = 0.02 = 2%`.
56
+ uint64 depositTreasuryFeeDivisor;
57
+ // Maximum amount of BTC transaction fee that can be incurred by each
58
+ // swept deposit being part of the given sweep transaction. If the
59
+ // maximum BTC transaction fee is exceeded, such transaction is
60
+ // considered a fraud.
61
+ //
62
+ // This is a per-deposit input max fee for the sweep transaction.
63
+ uint64 depositTxMaxFee;
64
+ // Collection of all revealed deposits indexed by
65
+ // `keccak256(fundingTxHash | fundingOutputIndex)`.
66
+ // The `fundingTxHash` is `bytes32` (ordered as in Bitcoin internally)
67
+ // and `fundingOutputIndex` an `uint32`. This mapping may contain valid
68
+ // and invalid deposits and the wallet is responsible for validating
69
+ // them before attempting to execute a sweep.
70
+ mapping(uint256 => Deposit.DepositRequest) deposits;
71
+ // Indicates if the vault with the given address is trusted or not.
72
+ // Depositors can route their revealed deposits only to trusted vaults
73
+ // and have trusted vaults notified about new deposits as soon as these
74
+ // deposits get swept. Vaults not trusted by the Bridge can still be
75
+ // used by Bank balance owners on their own responsibility - anyone can
76
+ // approve their Bank balance to any address.
77
+ mapping(address => bool) isVaultTrusted;
78
+ // Maximum amount of the total BTC transaction fee that is acceptable in
79
+ // a single moving funds transaction.
80
+ //
81
+ // This is a TOTAL max fee for the moving funds transaction. Note
82
+ // that `depositTxMaxFee` is per single deposit and `redemptionTxMaxFee`
83
+ // if per single redemption. `movingFundsTxMaxTotalFee` is a total
84
+ // fee for the entire transaction.
85
+ uint64 movingFundsTxMaxTotalFee;
86
+ // The minimal satoshi amount that makes sense to be transferred during
87
+ // the moving funds process. Moving funds wallets having their BTC
88
+ // balance below that value can begin closing immediately as
89
+ // transferring such a low value may not be possible due to
90
+ // BTC network fees. The value of this parameter must always be lower
91
+ // than `redemptionDustThreshold` in order to prevent redemption requests
92
+ // with values lower or equal to `movingFundsDustThreshold`.
93
+ uint64 movingFundsDustThreshold;
94
+ // Time after which the moving funds timeout can be reset in case the
95
+ // target wallet commitment cannot be submitted due to a lack of live
96
+ // wallets in the system. It is counted from the moment when the wallet
97
+ // was requested to move their funds and switched to the MovingFunds
98
+ // state or from the moment the timeout was reset the last time.
99
+ // Value in seconds. This value should be lower than the value
100
+ // of the `movingFundsTimeout`.
101
+ uint32 movingFundsTimeoutResetDelay;
102
+ // Time after which the moving funds process can be reported as
103
+ // timed out. It is counted from the moment when the wallet
104
+ // was requested to move their funds and switched to the MovingFunds
105
+ // state. Value in seconds.
106
+ uint32 movingFundsTimeout;
107
+ // The amount of stake slashed from each member of a wallet for a moving
108
+ // funds timeout.
109
+ uint96 movingFundsTimeoutSlashingAmount;
110
+ // The percentage of the notifier reward from the staking contract
111
+ // the notifier of a moving funds timeout receives. The value is in the
112
+ // range [0, 100].
113
+ uint256 movingFundsTimeoutNotifierRewardMultiplier;
114
+ // Maximum amount of the total BTC transaction fee that is acceptable in
115
+ // a single moved funds sweep transaction.
116
+ //
117
+ // This is a TOTAL max fee for the moved funds sweep transaction. Note
118
+ // that `depositTxMaxFee` is per single deposit and `redemptionTxMaxFee`
119
+ // if per single redemption. `movedFundsSweepTxMaxTotalFee` is a total
120
+ // fee for the entire transaction.
121
+ uint64 movedFundsSweepTxMaxTotalFee;
122
+ // Time after which the moved funds sweep process can be reported as
123
+ // timed out. It is counted from the moment when the recipient wallet
124
+ // was requested to sweep the received funds. Value in seconds.
125
+ uint32 movedFundsSweepTimeout;
126
+ // The amount of stake slashed from each member of a wallet for a moved
127
+ // funds sweep timeout.
128
+ uint96 movedFundsSweepTimeoutSlashingAmount;
129
+ // The percentage of the notifier reward from the staking contract
130
+ // the notifier of a moved funds sweep timeout receives. The value is
131
+ // in the range [0, 100].
132
+ uint256 movedFundsSweepTimeoutNotifierRewardMultiplier;
133
+ // Collection of all moved funds sweep requests indexed by
134
+ // `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
135
+ // The `movingFundsTxHash` is `bytes32` (ordered as in Bitcoin
136
+ // internally) and `movingFundsOutputIndex` an `uint32`. Each entry
137
+ // is actually an UTXO representing the moved funds and is supposed
138
+ // to be swept with the current main UTXO of the recipient wallet.
139
+ mapping(uint256 => MovingFunds.MovedFundsSweepRequest) movedFundsSweepRequests;
140
+ // The minimal amount that can be requested for redemption.
141
+ // Value of this parameter must take into account the value of
142
+ // `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
143
+ // parameters in order to make requests that can incur the
144
+ // treasury and transaction fee and still satisfy the redeemer.
145
+ // Additionally, the value of this parameter must always be greater
146
+ // than `movingFundsDustThreshold` in order to prevent redemption
147
+ // requests with values lower or equal to `movingFundsDustThreshold`.
148
+ uint64 redemptionDustThreshold;
149
+ // Divisor used to compute the treasury fee taken from each
150
+ // redemption request and transferred to the treasury upon
151
+ // successful request finalization. That fee is computed as follows:
152
+ // `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
153
+ // For example, if the treasury fee needs to be 2% of each
154
+ // redemption request, the `redemptionTreasuryFeeDivisor` should
155
+ // be set to `50` because `1/50 = 0.02 = 2%`.
156
+ uint64 redemptionTreasuryFeeDivisor;
157
+ // Maximum amount of BTC transaction fee that can be incurred by
158
+ // each redemption request being part of the given redemption
159
+ // transaction. If the maximum BTC transaction fee is exceeded, such
160
+ // transaction is considered a fraud.
161
+ //
162
+ // This is a per-redemption output max fee for the redemption
163
+ // transaction.
164
+ uint64 redemptionTxMaxFee;
165
+ // Time after which the redemption request can be reported as
166
+ // timed out. It is counted from the moment when the redemption
167
+ // request was created via `requestRedemption` call. Reported
168
+ // timed out requests are cancelled and locked TBTC is returned
169
+ // to the redeemer in full amount.
170
+ uint256 redemptionTimeout;
171
+ // The amount of stake slashed from each member of a wallet for a
172
+ // redemption timeout.
173
+ uint96 redemptionTimeoutSlashingAmount;
174
+ // The percentage of the notifier reward from the staking contract
175
+ // the notifier of a redemption timeout receives. The value is in the
176
+ // range [0, 100].
177
+ uint256 redemptionTimeoutNotifierRewardMultiplier;
178
+ // Collection of all pending redemption requests indexed by
179
+ // redemption key built as
180
+ // `keccak256(walletPubKeyHash | redeemerOutputScript)`.
181
+ // The `walletPubKeyHash` is the 20-byte wallet's public key hash
182
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
183
+ // public key) and `redeemerOutputScript` is a Bitcoin script
184
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
185
+ // redeemed BTC as requested by the redeemer. Requests are added
186
+ // to this mapping by the `requestRedemption` method (duplicates
187
+ // not allowed) and are removed by one of the following methods:
188
+ // - `submitRedemptionProof` in case the request was handled
189
+ // successfully,
190
+ // - `notifyRedemptionTimeout` in case the request was reported
191
+ // to be timed out.
192
+ mapping(uint256 => Redemption.RedemptionRequest) pendingRedemptions;
193
+ // Collection of all timed out redemptions requests indexed by
194
+ // redemption key built as
195
+ // `keccak256(walletPubKeyHash | redeemerOutputScript)`. The
196
+ // `walletPubKeyHash` is the 20-byte wallet's public key hash
197
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
198
+ // public key) and `redeemerOutputScript` is the Bitcoin script
199
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
200
+ // out request. Timed out requests are stored in this mapping to
201
+ // avoid slashing the wallets multiple times for the same timeout.
202
+ // Only one method can add to this mapping:
203
+ // - `notifyRedemptionTimeout` which puts the redemption key to this
204
+ // mapping basing on a timed out request stored previously in
205
+ // `pendingRedemptions` mapping.
206
+ mapping(uint256 => Redemption.RedemptionRequest) timedOutRedemptions;
207
+ // The amount of ETH in wei the party challenging the wallet for fraud
208
+ // needs to deposit.
209
+ uint256 fraudChallengeDepositAmount;
210
+ // The amount of time the wallet has to defeat a fraud challenge.
211
+ uint256 fraudChallengeDefeatTimeout;
212
+ // The amount of stake slashed from each member of a wallet for a fraud.
213
+ uint96 fraudSlashingAmount;
214
+ // The percentage of the notifier reward from the staking contract
215
+ // the notifier of a fraud receives. The value is in the range [0, 100].
216
+ uint256 fraudNotifierRewardMultiplier;
217
+ // Collection of all submitted fraud challenges indexed by challenge
218
+ // key built as `keccak256(walletPublicKey|sighash)`.
219
+ mapping(uint256 => Fraud.FraudChallenge) fraudChallenges;
220
+ // Collection of main UTXOs that are honestly spent indexed by
221
+ // `keccak256(fundingTxHash | fundingOutputIndex)`. The `fundingTxHash`
222
+ // is `bytes32` (ordered as in Bitcoin internally) and
223
+ // `fundingOutputIndex` an `uint32`. A main UTXO is considered honestly
224
+ // spent if it was used as an input of a transaction that have been
225
+ // proven in the Bridge.
226
+ mapping(uint256 => bool) spentMainUTXOs;
227
+ // Determines how frequently a new wallet creation can be requested.
228
+ // Value in seconds.
229
+ uint32 walletCreationPeriod;
230
+ // The minimum BTC threshold in satoshi that is used to decide about
231
+ // wallet creation. Specifically, we allow for the creation of a new
232
+ // wallet if the active wallet is old enough and their amount of BTC
233
+ // is greater than or equal this threshold.
234
+ uint64 walletCreationMinBtcBalance;
235
+ // The maximum BTC threshold in satoshi that is used to decide about
236
+ // wallet creation. Specifically, we allow for the creation of a new
237
+ // wallet if the active wallet's amount of BTC is greater than or equal
238
+ // this threshold, regardless of the active wallet's age.
239
+ uint64 walletCreationMaxBtcBalance;
240
+ // The minimum BTC threshold in satoshi that is used to decide about
241
+ // wallet closing. Specifically, we allow for the closure of the given
242
+ // wallet if their amount of BTC is lesser than this threshold,
243
+ // regardless of the wallet's age.
244
+ uint64 walletClosureMinBtcBalance;
245
+ // The maximum age of a wallet in seconds, after which the wallet
246
+ // moving funds process can be requested.
247
+ uint32 walletMaxAge;
248
+ // 20-byte wallet public key hash being reference to the currently
249
+ // active wallet. Can be unset to the zero value under certain
250
+ // circumstances.
251
+ bytes20 activeWalletPubKeyHash;
252
+ // The current number of wallets in the Live state.
253
+ uint32 liveWalletsCount;
254
+ // The maximum BTC amount in satoshi than can be transferred to a single
255
+ // target wallet during the moving funds process.
256
+ uint64 walletMaxBtcTransfer;
257
+ // Determines the length of the wallet closing period, i.e. the period
258
+ // when the wallet remains in the Closing state and can be subject
259
+ // of deposit fraud challenges. This value is in seconds and should be
260
+ // greater than the deposit refund time plus some time margin.
261
+ uint32 walletClosingPeriod;
262
+ // Maps the 20-byte wallet public key hash (computed using Bitcoin
263
+ // HASH160 over the compressed ECDSA public key) to the basic wallet
264
+ // information like state and pending redemptions value.
265
+ mapping(bytes20 => Wallets.Wallet) registeredWallets;
266
+ // Reserved storage space in case we need to add more variables.
267
+ // The convention from OpenZeppelin suggests the storage space should
268
+ // add up to 50 slots. Here we want to have more slots as there are
269
+ // planned upgrades of the Bridge contract. If more entires are added to
270
+ // the struct in the upcoming versions we need to reduce the array size.
271
+ // See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
272
+ // slither-disable-next-line unused-state
273
+ uint256[50] __gap;
274
+ }
275
+
276
+ event DepositParametersUpdated(
277
+ uint64 depositDustThreshold,
278
+ uint64 depositTreasuryFeeDivisor,
279
+ uint64 depositTxMaxFee
280
+ );
281
+
282
+ event RedemptionParametersUpdated(
283
+ uint64 redemptionDustThreshold,
284
+ uint64 redemptionTreasuryFeeDivisor,
285
+ uint64 redemptionTxMaxFee,
286
+ uint256 redemptionTimeout,
287
+ uint96 redemptionTimeoutSlashingAmount,
288
+ uint256 redemptionTimeoutNotifierRewardMultiplier
289
+ );
290
+
291
+ event MovingFundsParametersUpdated(
292
+ uint64 movingFundsTxMaxTotalFee,
293
+ uint64 movingFundsDustThreshold,
294
+ uint32 movingFundsTimeoutResetDelay,
295
+ uint32 movingFundsTimeout,
296
+ uint96 movingFundsTimeoutSlashingAmount,
297
+ uint256 movingFundsTimeoutNotifierRewardMultiplier,
298
+ uint64 movedFundsSweepTxMaxTotalFee,
299
+ uint32 movedFundsSweepTimeout,
300
+ uint96 movedFundsSweepTimeoutSlashingAmount,
301
+ uint256 movedFundsSweepTimeoutNotifierRewardMultiplier
302
+ );
303
+
304
+ event WalletParametersUpdated(
305
+ uint32 walletCreationPeriod,
306
+ uint64 walletCreationMinBtcBalance,
307
+ uint64 walletCreationMaxBtcBalance,
308
+ uint64 walletClosureMinBtcBalance,
309
+ uint32 walletMaxAge,
310
+ uint64 walletMaxBtcTransfer,
311
+ uint32 walletClosingPeriod
312
+ );
313
+
314
+ event FraudParametersUpdated(
315
+ uint256 fraudChallengeDepositAmount,
316
+ uint256 fraudChallengeDefeatTimeout,
317
+ uint96 fraudSlashingAmount,
318
+ uint256 fraudNotifierRewardMultiplier
319
+ );
320
+
321
+ /// @notice Updates parameters of deposits.
322
+ /// @param _depositDustThreshold New value of the deposit dust threshold in
323
+ /// satoshis. It is the minimal amount that can be requested to
324
+ //// deposit. Value of this parameter must take into account the value
325
+ /// of `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters
326
+ /// in order to make requests that can incur the treasury and
327
+ /// transaction fee and still satisfy the depositor.
328
+ /// @param _depositTreasuryFeeDivisor New value of the treasury fee divisor.
329
+ /// It is the divisor used to compute the treasury fee taken from
330
+ /// each deposit and transferred to the treasury upon sweep proof
331
+ /// submission. That fee is computed as follows:
332
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
333
+ /// For example, if the treasury fee needs to be 2% of each deposit,
334
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
335
+ /// because `1/50 = 0.02 = 2%`.
336
+ /// @param _depositTxMaxFee New value of the deposit tx max fee in satoshis.
337
+ /// It is the maximum amount of BTC transaction fee that can
338
+ /// be incurred by each swept deposit being part of the given sweep
339
+ /// transaction. If the maximum BTC transaction fee is exceeded,
340
+ /// such transaction is considered a fraud.
341
+ /// @dev Requirements:
342
+ /// - Deposit dust threshold must be greater than zero,
343
+ /// - Deposit treasury fee divisor must be greater than zero,
344
+ /// - Deposit transaction max fee must be greater than zero.
345
+ function updateDepositParameters(
346
+ Storage storage self,
347
+ uint64 _depositDustThreshold,
348
+ uint64 _depositTreasuryFeeDivisor,
349
+ uint64 _depositTxMaxFee
350
+ ) internal {
351
+ require(
352
+ _depositDustThreshold > 0,
353
+ "Deposit dust threshold must be greater than zero"
354
+ );
355
+
356
+ require(
357
+ _depositTreasuryFeeDivisor > 0,
358
+ "Deposit treasury fee divisor must be greater than zero"
359
+ );
360
+
361
+ require(
362
+ _depositTxMaxFee > 0,
363
+ "Deposit transaction max fee must be greater than zero"
364
+ );
365
+
366
+ self.depositDustThreshold = _depositDustThreshold;
367
+ self.depositTreasuryFeeDivisor = _depositTreasuryFeeDivisor;
368
+ self.depositTxMaxFee = _depositTxMaxFee;
369
+
370
+ emit DepositParametersUpdated(
371
+ _depositDustThreshold,
372
+ _depositTreasuryFeeDivisor,
373
+ _depositTxMaxFee
374
+ );
375
+ }
376
+
377
+ /// @notice Updates parameters of redemptions.
378
+ /// @param _redemptionDustThreshold New value of the redemption dust
379
+ /// threshold in satoshis. It is the minimal amount that can be
380
+ /// requested for redemption. Value of this parameter must take into
381
+ /// account the value of `redemptionTreasuryFeeDivisor` and
382
+ /// `redemptionTxMaxFee` parameters in order to make requests that
383
+ /// can incur the treasury and transaction fee and still satisfy the
384
+ /// redeemer.
385
+ /// @param _redemptionTreasuryFeeDivisor New value of the redemption
386
+ /// treasury fee divisor. It is the divisor used to compute the
387
+ /// treasury fee taken from each redemption request and transferred
388
+ /// to the treasury upon successful request finalization. That fee is
389
+ /// computed as follows:
390
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
391
+ /// For example, if the treasury fee needs to be 2% of each
392
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
393
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
394
+ /// @param _redemptionTxMaxFee New value of the redemption transaction max
395
+ /// fee in satoshis. It is the maximum amount of BTC transaction fee
396
+ /// that can be incurred by each redemption request being part of the
397
+ /// given redemption transaction. If the maximum BTC transaction fee
398
+ /// is exceeded, such transaction is considered a fraud.
399
+ /// This is a per-redemption output max fee for the redemption
400
+ /// transaction.
401
+ /// @param _redemptionTimeout New value of the redemption timeout in seconds.
402
+ /// It is the time after which the redemption request can be reported
403
+ /// as timed out. It is counted from the moment when the redemption
404
+ /// request was created via `requestRedemption` call. Reported timed
405
+ /// out requests are cancelled and locked TBTC is returned to the
406
+ /// redeemer in full amount.
407
+ /// @param _redemptionTimeoutSlashingAmount New value of the redemption
408
+ /// timeout slashing amount in T, it is the amount slashed from each
409
+ /// wallet member for redemption timeout.
410
+ /// @param _redemptionTimeoutNotifierRewardMultiplier New value of the
411
+ /// redemption timeout notifier reward multiplier as percentage,
412
+ /// it determines the percentage of the notifier reward from the
413
+ /// staking contact the notifier of a redemption timeout receives.
414
+ /// The value must be in the range [0, 100].
415
+ /// @dev Requirements:
416
+ /// - Redemption dust threshold must be greater than moving funds dust
417
+ /// threshold,
418
+ /// - Redemption treasury fee divisor must be greater than zero,
419
+ /// - Redemption transaction max fee must be greater than zero,
420
+ /// - Redemption timeout must be greater than zero,
421
+ /// - Redemption timeout notifier reward multiplier must be in the
422
+ /// range [0, 100].
423
+ function updateRedemptionParameters(
424
+ Storage storage self,
425
+ uint64 _redemptionDustThreshold,
426
+ uint64 _redemptionTreasuryFeeDivisor,
427
+ uint64 _redemptionTxMaxFee,
428
+ uint256 _redemptionTimeout,
429
+ uint96 _redemptionTimeoutSlashingAmount,
430
+ uint256 _redemptionTimeoutNotifierRewardMultiplier
431
+ ) internal {
432
+ require(
433
+ _redemptionDustThreshold > self.movingFundsDustThreshold,
434
+ "Redemption dust threshold must be greater than moving funds dust threshold"
435
+ );
436
+
437
+ require(
438
+ _redemptionTreasuryFeeDivisor > 0,
439
+ "Redemption treasury fee divisor must be greater than zero"
440
+ );
441
+
442
+ require(
443
+ _redemptionTxMaxFee > 0,
444
+ "Redemption transaction max fee must be greater than zero"
445
+ );
446
+
447
+ require(
448
+ _redemptionTimeout > 0,
449
+ "Redemption timeout must be greater than zero"
450
+ );
451
+
452
+ require(
453
+ _redemptionTimeoutNotifierRewardMultiplier <= 100,
454
+ "Redemption timeout notifier reward multiplier must be in the range [0, 100]"
455
+ );
456
+
457
+ self.redemptionDustThreshold = _redemptionDustThreshold;
458
+ self.redemptionTreasuryFeeDivisor = _redemptionTreasuryFeeDivisor;
459
+ self.redemptionTxMaxFee = _redemptionTxMaxFee;
460
+ self.redemptionTimeout = _redemptionTimeout;
461
+ self.redemptionTimeoutSlashingAmount = _redemptionTimeoutSlashingAmount;
462
+ self
463
+ .redemptionTimeoutNotifierRewardMultiplier = _redemptionTimeoutNotifierRewardMultiplier;
464
+
465
+ emit RedemptionParametersUpdated(
466
+ _redemptionDustThreshold,
467
+ _redemptionTreasuryFeeDivisor,
468
+ _redemptionTxMaxFee,
469
+ _redemptionTimeout,
470
+ _redemptionTimeoutSlashingAmount,
471
+ _redemptionTimeoutNotifierRewardMultiplier
472
+ );
473
+ }
474
+
475
+ /// @notice Updates parameters of moving funds.
476
+ /// @param _movingFundsTxMaxTotalFee New value of the moving funds transaction
477
+ /// max total fee in satoshis. It is the maximum amount of the total
478
+ /// BTC transaction fee that is acceptable in a single moving funds
479
+ /// transaction. This is a _total_ max fee for the entire moving
480
+ /// funds transaction.
481
+ /// @param _movingFundsDustThreshold New value of the moving funds dust
482
+ /// threshold. It is the minimal satoshi amount that makes sense to
483
+ /// be transferred during the moving funds process. Moving funds
484
+ /// wallets having their BTC balance below that value can begin
485
+ /// closing immediately as transferring such a low value may not be
486
+ /// possible due to BTC network fees.
487
+ /// @param _movingFundsTimeoutResetDelay New value of the moving funds
488
+ /// timeout reset delay in seconds. It is the time after which the
489
+ /// moving funds timeout can be reset in case the target wallet
490
+ /// commitment cannot be submitted due to a lack of live wallets
491
+ /// in the system. It is counted from the moment when the wallet
492
+ /// was requested to move their funds and switched to the MovingFunds
493
+ /// state or from the moment the timeout was reset the last time.
494
+ /// @param _movingFundsTimeout New value of the moving funds timeout in
495
+ /// seconds. It is the time after which the moving funds process can
496
+ /// be reported as timed out. It is counted from the moment when the
497
+ /// wallet was requested to move their funds and switched to the
498
+ /// MovingFunds state.
499
+ /// @param _movingFundsTimeoutSlashingAmount New value of the moving funds
500
+ /// timeout slashing amount in T, it is the amount slashed from each
501
+ /// wallet member for moving funds timeout.
502
+ /// @param _movingFundsTimeoutNotifierRewardMultiplier New value of the
503
+ /// moving funds timeout notifier reward multiplier as percentage,
504
+ /// it determines the percentage of the notifier reward from the
505
+ /// staking contact the notifier of a moving funds timeout receives.
506
+ /// The value must be in the range [0, 100].
507
+ /// @param _movedFundsSweepTxMaxTotalFee New value of the moved funds sweep
508
+ /// transaction max total fee in satoshis. It is the maximum amount
509
+ /// of the total BTC transaction fee that is acceptable in a single
510
+ /// moved funds sweep transaction. This is a _total_ max fee for the
511
+ /// entire moved funds sweep transaction.
512
+ /// @param _movedFundsSweepTimeout New value of the moved funds sweep
513
+ /// timeout in seconds. It is the time after which the moved funds
514
+ /// sweep process can be reported as timed out. It is counted from
515
+ /// the moment when the wallet was requested to sweep the received
516
+ /// funds.
517
+ /// @param _movedFundsSweepTimeoutSlashingAmount New value of the moved
518
+ /// funds sweep timeout slashing amount in T, it is the amount
519
+ /// slashed from each wallet member for moved funds sweep timeout.
520
+ /// @param _movedFundsSweepTimeoutNotifierRewardMultiplier New value of
521
+ /// the moved funds sweep timeout notifier reward multiplier as
522
+ /// percentage, it determines the percentage of the notifier reward
523
+ /// from the staking contact the notifier of a moved funds sweep
524
+ /// timeout receives. The value must be in the range [0, 100].
525
+ /// @dev Requirements:
526
+ /// - Moving funds transaction max total fee must be greater than zero,
527
+ /// - Moving funds dust threshold must be greater than zero and lower
528
+ /// than the redemption dust threshold,
529
+ /// - Moving funds timeout reset delay must be greater than zero,
530
+ /// - Moving funds timeout must be greater than the moving funds
531
+ /// timeout reset delay,
532
+ /// - Moving funds timeout notifier reward multiplier must be in the
533
+ /// range [0, 100],
534
+ /// - Moved funds sweep transaction max total fee must be greater than zero,
535
+ /// - Moved funds sweep timeout must be greater than zero,
536
+ /// - Moved funds sweep timeout notifier reward multiplier must be in the
537
+ /// range [0, 100].
538
+ function updateMovingFundsParameters(
539
+ Storage storage self,
540
+ uint64 _movingFundsTxMaxTotalFee,
541
+ uint64 _movingFundsDustThreshold,
542
+ uint32 _movingFundsTimeoutResetDelay,
543
+ uint32 _movingFundsTimeout,
544
+ uint96 _movingFundsTimeoutSlashingAmount,
545
+ uint256 _movingFundsTimeoutNotifierRewardMultiplier,
546
+ uint64 _movedFundsSweepTxMaxTotalFee,
547
+ uint32 _movedFundsSweepTimeout,
548
+ uint96 _movedFundsSweepTimeoutSlashingAmount,
549
+ uint256 _movedFundsSweepTimeoutNotifierRewardMultiplier
550
+ ) internal {
551
+ require(
552
+ _movingFundsTxMaxTotalFee > 0,
553
+ "Moving funds transaction max total fee must be greater than zero"
554
+ );
555
+
556
+ require(
557
+ _movingFundsDustThreshold > 0 &&
558
+ _movingFundsDustThreshold < self.redemptionDustThreshold,
559
+ "Moving funds dust threshold must be greater than zero and lower than redemption dust threshold"
560
+ );
561
+
562
+ require(
563
+ _movingFundsTimeoutResetDelay > 0,
564
+ "Moving funds timeout reset delay must be greater than zero"
565
+ );
566
+
567
+ require(
568
+ _movingFundsTimeout > _movingFundsTimeoutResetDelay,
569
+ "Moving funds timeout must be greater than its reset delay"
570
+ );
571
+
572
+ require(
573
+ _movingFundsTimeoutNotifierRewardMultiplier <= 100,
574
+ "Moving funds timeout notifier reward multiplier must be in the range [0, 100]"
575
+ );
576
+
577
+ require(
578
+ _movedFundsSweepTxMaxTotalFee > 0,
579
+ "Moved funds sweep transaction max total fee must be greater than zero"
580
+ );
581
+
582
+ require(
583
+ _movedFundsSweepTimeout > 0,
584
+ "Moved funds sweep timeout must be greater than zero"
585
+ );
586
+
587
+ require(
588
+ _movedFundsSweepTimeoutNotifierRewardMultiplier <= 100,
589
+ "Moved funds sweep timeout notifier reward multiplier must be in the range [0, 100]"
590
+ );
591
+
592
+ self.movingFundsTxMaxTotalFee = _movingFundsTxMaxTotalFee;
593
+ self.movingFundsDustThreshold = _movingFundsDustThreshold;
594
+ self.movingFundsTimeoutResetDelay = _movingFundsTimeoutResetDelay;
595
+ self.movingFundsTimeout = _movingFundsTimeout;
596
+ self
597
+ .movingFundsTimeoutSlashingAmount = _movingFundsTimeoutSlashingAmount;
598
+ self
599
+ .movingFundsTimeoutNotifierRewardMultiplier = _movingFundsTimeoutNotifierRewardMultiplier;
600
+ self.movedFundsSweepTxMaxTotalFee = _movedFundsSweepTxMaxTotalFee;
601
+ self.movedFundsSweepTimeout = _movedFundsSweepTimeout;
602
+ self
603
+ .movedFundsSweepTimeoutSlashingAmount = _movedFundsSweepTimeoutSlashingAmount;
604
+ self
605
+ .movedFundsSweepTimeoutNotifierRewardMultiplier = _movedFundsSweepTimeoutNotifierRewardMultiplier;
606
+
607
+ emit MovingFundsParametersUpdated(
608
+ _movingFundsTxMaxTotalFee,
609
+ _movingFundsDustThreshold,
610
+ _movingFundsTimeoutResetDelay,
611
+ _movingFundsTimeout,
612
+ _movingFundsTimeoutSlashingAmount,
613
+ _movingFundsTimeoutNotifierRewardMultiplier,
614
+ _movedFundsSweepTxMaxTotalFee,
615
+ _movedFundsSweepTimeout,
616
+ _movedFundsSweepTimeoutSlashingAmount,
617
+ _movedFundsSweepTimeoutNotifierRewardMultiplier
618
+ );
619
+ }
620
+
621
+ /// @notice Updates parameters of wallets.
622
+ /// @param _walletCreationPeriod New value of the wallet creation period in
623
+ /// seconds, determines how frequently a new wallet creation can be
624
+ /// requested.
625
+ /// @param _walletCreationMinBtcBalance New value of the wallet minimum BTC
626
+ /// balance in satoshi, used to decide about wallet creation.
627
+ /// @param _walletCreationMaxBtcBalance New value of the wallet maximum BTC
628
+ /// balance in satoshi, used to decide about wallet creation.
629
+ /// @param _walletClosureMinBtcBalance New value of the wallet minimum BTC
630
+ /// balance in satoshi, used to decide about wallet closure.
631
+ /// @param _walletMaxAge New value of the wallet maximum age in seconds,
632
+ /// indicates the maximum age of a wallet in seconds, after which
633
+ /// the wallet moving funds process can be requested.
634
+ /// @param _walletMaxBtcTransfer New value of the wallet maximum BTC transfer
635
+ /// in satoshi, determines the maximum amount that can be transferred
636
+ /// to a single target wallet during the moving funds process.
637
+ /// @param _walletClosingPeriod New value of the wallet closing period in
638
+ /// seconds, determines the length of the wallet closing period,
639
+ // i.e. the period when the wallet remains in the Closing state
640
+ // and can be subject of deposit fraud challenges.
641
+ /// @dev Requirements:
642
+ /// - Wallet minimum BTC balance must be greater than zero,
643
+ /// - Wallet maximum BTC balance must be greater than the wallet
644
+ /// minimum BTC balance,
645
+ /// - Wallet maximum BTC transfer must be greater than zero,
646
+ /// - Wallet closing period must be greater than zero.
647
+ function updateWalletParameters(
648
+ Storage storage self,
649
+ uint32 _walletCreationPeriod,
650
+ uint64 _walletCreationMinBtcBalance,
651
+ uint64 _walletCreationMaxBtcBalance,
652
+ uint64 _walletClosureMinBtcBalance,
653
+ uint32 _walletMaxAge,
654
+ uint64 _walletMaxBtcTransfer,
655
+ uint32 _walletClosingPeriod
656
+ ) internal {
657
+ require(
658
+ _walletCreationMaxBtcBalance > _walletCreationMinBtcBalance,
659
+ "Wallet creation maximum BTC balance must be greater than the creation minimum BTC balance"
660
+ );
661
+ require(
662
+ _walletClosureMinBtcBalance > 0,
663
+ "Wallet closure minimum BTC balance must be greater than zero"
664
+ );
665
+ require(
666
+ _walletMaxBtcTransfer > 0,
667
+ "Wallet maximum BTC transfer must be greater than zero"
668
+ );
669
+ require(
670
+ _walletClosingPeriod > 0,
671
+ "Wallet closing period must be greater than zero"
672
+ );
673
+
674
+ self.walletCreationPeriod = _walletCreationPeriod;
675
+ self.walletCreationMinBtcBalance = _walletCreationMinBtcBalance;
676
+ self.walletCreationMaxBtcBalance = _walletCreationMaxBtcBalance;
677
+ self.walletClosureMinBtcBalance = _walletClosureMinBtcBalance;
678
+ self.walletMaxAge = _walletMaxAge;
679
+ self.walletMaxBtcTransfer = _walletMaxBtcTransfer;
680
+ self.walletClosingPeriod = _walletClosingPeriod;
681
+
682
+ emit WalletParametersUpdated(
683
+ _walletCreationPeriod,
684
+ _walletCreationMinBtcBalance,
685
+ _walletCreationMaxBtcBalance,
686
+ _walletClosureMinBtcBalance,
687
+ _walletMaxAge,
688
+ _walletMaxBtcTransfer,
689
+ _walletClosingPeriod
690
+ );
691
+ }
692
+
693
+ /// @notice Updates parameters related to frauds.
694
+ /// @param _fraudChallengeDepositAmount New value of the fraud challenge
695
+ /// deposit amount in wei, it is the amount of ETH the party
696
+ /// challenging the wallet for fraud needs to deposit.
697
+ /// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
698
+ /// timeout in seconds, it is the amount of time the wallet has to
699
+ /// defeat a fraud challenge. The value must be greater than zero.
700
+ /// @param _fraudSlashingAmount New value of the fraud slashing amount in T,
701
+ /// it is the amount slashed from each wallet member for committing
702
+ /// a fraud.
703
+ /// @param _fraudNotifierRewardMultiplier New value of the fraud notifier
704
+ /// reward multiplier as percentage, it determines the percentage of
705
+ /// the notifier reward from the staking contact the notifier of
706
+ /// a fraud receives. The value must be in the range [0, 100].
707
+ /// @dev Requirements:
708
+ /// - Fraud challenge defeat timeout must be greater than 0,
709
+ /// - Fraud notifier reward multiplier must be in the range [0, 100].
710
+ function updateFraudParameters(
711
+ Storage storage self,
712
+ uint256 _fraudChallengeDepositAmount,
713
+ uint256 _fraudChallengeDefeatTimeout,
714
+ uint96 _fraudSlashingAmount,
715
+ uint256 _fraudNotifierRewardMultiplier
716
+ ) internal {
717
+ require(
718
+ _fraudChallengeDefeatTimeout > 0,
719
+ "Fraud challenge defeat timeout must be greater than zero"
720
+ );
721
+
722
+ require(
723
+ _fraudNotifierRewardMultiplier <= 100,
724
+ "Fraud notifier reward multiplier must be in the range [0, 100]"
725
+ );
726
+
727
+ self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
728
+ self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
729
+ self.fraudSlashingAmount = _fraudSlashingAmount;
730
+ self.fraudNotifierRewardMultiplier = _fraudNotifierRewardMultiplier;
731
+
732
+ emit FraudParametersUpdated(
733
+ _fraudChallengeDepositAmount,
734
+ _fraudChallengeDefeatTimeout,
735
+ _fraudSlashingAmount,
736
+ _fraudNotifierRewardMultiplier
737
+ );
738
+ }
739
+ }