@keep-network/tbtc-v2 0.1.1-dev.5 → 0.1.1-dev.52

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 (95) hide show
  1. package/README.adoc +12 -0
  2. package/artifacts/Bank.json +752 -0
  3. package/artifacts/Bridge.json +3307 -0
  4. package/artifacts/Deposit.json +117 -0
  5. package/artifacts/EcdsaDkgValidator.json +532 -0
  6. package/artifacts/EcdsaInactivity.json +156 -0
  7. package/artifacts/Fraud.json +154 -0
  8. package/artifacts/KeepRegistry.json +99 -0
  9. package/artifacts/KeepStake.json +286 -0
  10. package/artifacts/KeepToken.json +711 -0
  11. package/artifacts/KeepTokenStaking.json +483 -0
  12. package/artifacts/MovingFunds.json +160 -0
  13. package/artifacts/NuCypherStakingEscrow.json +256 -0
  14. package/artifacts/NuCypherToken.json +711 -0
  15. package/artifacts/RandomBeaconStub.json +141 -0
  16. package/artifacts/Redemption.json +161 -0
  17. package/artifacts/ReimbursementPool.json +509 -0
  18. package/artifacts/Relay.json +123 -0
  19. package/artifacts/SortitionPool.json +944 -0
  20. package/artifacts/Sweep.json +76 -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/TokenStaking.json +2288 -0
  25. package/artifacts/TokenholderGovernor.json +1795 -0
  26. package/artifacts/TokenholderTimelock.json +1058 -0
  27. package/artifacts/VendingMachine.json +30 -29
  28. package/artifacts/VendingMachineKeep.json +400 -0
  29. package/artifacts/VendingMachineNuCypher.json +400 -0
  30. package/artifacts/WalletRegistry.json +2709 -0
  31. package/artifacts/WalletRegistryGovernance.json +2364 -0
  32. package/artifacts/Wallets.json +186 -0
  33. package/artifacts/solcInputs/dcf2fc19e497270603c798faeb0a9ba9.json +218 -0
  34. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  35. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
  36. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  37. package/build/contracts/bank/Bank.sol/Bank.json +20 -2
  38. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +4 -0
  39. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +10 -0
  40. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  41. package/build/contracts/bridge/Bridge.sol/Bridge.json +2114 -77
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  43. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +172 -0
  44. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
  45. package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
  46. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
  47. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
  48. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
  49. package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
  50. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
  51. package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
  52. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
  53. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +81 -0
  54. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
  55. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
  56. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
  57. package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
  58. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +4 -0
  59. package/build/contracts/bridge/Sweep.sol/Sweep.json +30 -0
  60. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  61. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
  62. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
  63. package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
  64. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  65. package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
  66. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  67. package/build/contracts/vault/IVault.sol/IVault.json +19 -1
  68. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  69. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +36 -18
  70. package/contracts/GovernanceUtils.sol +1 -1
  71. package/contracts/bank/Bank.sol +34 -18
  72. package/contracts/bridge/BitcoinTx.sol +234 -0
  73. package/contracts/bridge/Bridge.sol +1298 -126
  74. package/contracts/bridge/BridgeState.sol +553 -0
  75. package/contracts/bridge/Deposit.sol +266 -0
  76. package/contracts/bridge/EcdsaLib.sol +45 -0
  77. package/contracts/bridge/Fraud.sol +504 -0
  78. package/contracts/bridge/IRelay.sol +28 -0
  79. package/contracts/bridge/MovingFunds.sol +511 -0
  80. package/contracts/bridge/Redemption.sol +846 -0
  81. package/contracts/bridge/Sweep.sol +514 -0
  82. package/contracts/bridge/VendingMachine.sol +1 -1
  83. package/contracts/bridge/Wallets.sol +552 -0
  84. package/contracts/token/TBTC.sol +1 -1
  85. package/contracts/vault/IVault.sol +32 -10
  86. package/contracts/vault/TBTCVault.sol +20 -2
  87. package/deploy/00_resolve_relay.ts +28 -0
  88. package/deploy/04_deploy_bank.ts +27 -0
  89. package/deploy/05_deploy_bridge.ts +64 -0
  90. package/deploy/06_bank_update_bridge.ts +19 -0
  91. package/deploy/07_transfer_ownership.ts +15 -0
  92. package/deploy/08_transfer_governance.ts +20 -0
  93. package/export.json +15194 -472
  94. package/package.json +27 -23
  95. package/artifacts/solcInputs/d71966212a658480bad5748ad85b1396.json +0 -116
@@ -0,0 +1,553 @@
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
+
26
+ import "../bank/Bank.sol";
27
+
28
+ library BridgeState {
29
+ // TODO: Make parameters governable
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
+ // Time after which the moving funds process can be reported as
87
+ // timed out. It is counted from the moment when the wallet
88
+ // was requested to move their funds and switched to the MovingFunds
89
+ // state. Value in seconds.
90
+ uint32 movingFundsTimeout;
91
+ // The minimal satoshi amount that makes sense to be transferred during
92
+ // the moving funds process. Moving funds wallets having their BTC
93
+ // balance below that value can begin closing immediately as
94
+ // transferring such a low value may not be possible due to
95
+ // BTC network fees.
96
+ uint64 movingFundsDustThreshold;
97
+ // The minimal amount that can be requested for redemption.
98
+ // Value of this parameter must take into account the value of
99
+ // `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
100
+ // parameters in order to make requests that can incur the
101
+ // treasury and transaction fee and still satisfy the redeemer.
102
+ uint64 redemptionDustThreshold;
103
+ // Divisor used to compute the treasury fee taken from each
104
+ // redemption request and transferred to the treasury upon
105
+ // successful request finalization. That fee is computed as follows:
106
+ // `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
107
+ // For example, if the treasury fee needs to be 2% of each
108
+ // redemption request, the `redemptionTreasuryFeeDivisor` should
109
+ // be set to `50` because `1/50 = 0.02 = 2%`.
110
+ uint64 redemptionTreasuryFeeDivisor;
111
+ // Maximum amount of BTC transaction fee that can be incurred by
112
+ // each redemption request being part of the given redemption
113
+ // transaction. If the maximum BTC transaction fee is exceeded, such
114
+ // transaction is considered a fraud.
115
+ //
116
+ // This is a per-redemption output max fee for the redemption
117
+ // transaction.
118
+ uint64 redemptionTxMaxFee;
119
+ // Time after which the redemption request can be reported as
120
+ // timed out. It is counted from the moment when the redemption
121
+ // request was created via `requestRedemption` call. Reported
122
+ // timed out requests are cancelled and locked TBTC is returned
123
+ // to the redeemer in full amount.
124
+ uint256 redemptionTimeout;
125
+ // Collection of all pending redemption requests indexed by
126
+ // redemption key built as
127
+ // `keccak256(walletPubKeyHash | redeemerOutputScript)`.
128
+ // The `walletPubKeyHash` is the 20-byte wallet's public key hash
129
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
130
+ // public key) and `redeemerOutputScript` is a Bitcoin script
131
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
132
+ // redeemed BTC as requested by the redeemer. Requests are added
133
+ // to this mapping by the `requestRedemption` method (duplicates
134
+ // not allowed) and are removed by one of the following methods:
135
+ // - `submitRedemptionProof` in case the request was handled
136
+ // successfully
137
+ // - `notifyRedemptionTimeout` in case the request was reported
138
+ // to be timed out
139
+ mapping(uint256 => Redemption.RedemptionRequest) pendingRedemptions;
140
+ // Collection of all timed out redemptions requests indexed by
141
+ // redemption key built as
142
+ // `keccak256(walletPubKeyHash | redeemerOutputScript)`. The
143
+ // `walletPubKeyHash` is the 20-byte wallet's public key hash
144
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
145
+ // public key) and `redeemerOutputScript` is the Bitcoin script
146
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
147
+ // out request. Timed out requests are stored in this mapping to
148
+ // avoid slashing the wallets multiple times for the same timeout.
149
+ // Only one method can add to this mapping:
150
+ // - `notifyRedemptionTimeout` which puts the redemption key to this
151
+ // mapping basing on a timed out request stored previously in
152
+ // `pendingRedemptions` mapping.
153
+ mapping(uint256 => Redemption.RedemptionRequest) timedOutRedemptions;
154
+ // The amount of stake slashed from each member of a wallet for a fraud.
155
+ uint96 fraudSlashingAmount;
156
+ // The percentage of the notifier reward from the staking contract
157
+ // the notifier of a fraud receives. The value is in the range [0, 100].
158
+ uint256 fraudNotifierRewardMultiplier;
159
+ // The amount of time the wallet has to defeat a fraud challenge.
160
+ uint256 fraudChallengeDefeatTimeout;
161
+ // The amount of ETH in wei the party challenging the wallet for fraud
162
+ // needs to deposit.
163
+ uint256 fraudChallengeDepositAmount;
164
+ // Collection of all submitted fraud challenges indexed by challenge
165
+ // key built as `keccak256(walletPublicKey|sighash)`.
166
+ mapping(uint256 => Fraud.FraudChallenge) fraudChallenges;
167
+ // Collection of main UTXOs that are honestly spent indexed by
168
+ // `keccak256(fundingTxHash | fundingOutputIndex)`. The `fundingTxHash`
169
+ // is `bytes32` (ordered as in Bitcoin internally) and
170
+ // `fundingOutputIndex` an `uint32`. A main UTXO is considered honestly
171
+ // spent if it was used as an input of a transaction that have been
172
+ // proven in the Bridge.
173
+ mapping(uint256 => bool) spentMainUTXOs;
174
+ // Determines how frequently a new wallet creation can be requested.
175
+ // Value in seconds.
176
+ uint32 walletCreationPeriod;
177
+ // The minimum BTC threshold in satoshi that is used to decide about
178
+ // wallet creation. Specifically, we allow for the creation of a new
179
+ // wallet if the active wallet is old enough and their amount of BTC
180
+ // is greater than or equal this threshold.
181
+ uint64 walletCreationMinBtcBalance;
182
+ // The maximum BTC threshold in satoshi that is used to decide about
183
+ // wallet creation. Specifically, we allow for the creation of a new
184
+ // wallet if the active wallet's amount of BTC is greater than or equal
185
+ // this threshold, regardless of the active wallet's age.
186
+ uint64 walletCreationMaxBtcBalance;
187
+ // The minimum BTC threshold in satoshi that is used to decide about
188
+ // wallet closing. Specifically, we allow for the closure of the given
189
+ // wallet if their amount of BTC is lesser than this threshold,
190
+ // regardless of the wallet's age.
191
+ uint64 walletClosureMinBtcBalance;
192
+ // The maximum age of a wallet in seconds, after which the wallet
193
+ // moving funds process can be requested.
194
+ uint32 walletMaxAge;
195
+ // 20-byte wallet public key hash being reference to the currently
196
+ // active wallet. Can be unset to the zero value under certain
197
+ // circumstances.
198
+ bytes20 activeWalletPubKeyHash;
199
+ // The current number of wallets in the Live state.
200
+ uint32 liveWalletsCount;
201
+ // The maximum BTC amount in satoshi than can be transferred to a single
202
+ // target wallet during the moving funds process.
203
+ uint64 walletMaxBtcTransfer;
204
+ // Determines the length of the wallet closing period, i.e. the period
205
+ // when the wallet remains in the Closing state and can be subject
206
+ // of deposit fraud challenges. This value is in seconds and should be
207
+ // greater than the deposit refund time plus some time margin.
208
+ uint32 walletClosingPeriod;
209
+ // Maps the 20-byte wallet public key hash (computed using Bitcoin
210
+ // HASH160 over the compressed ECDSA public key) to the basic wallet
211
+ // information like state and pending redemptions value.
212
+ mapping(bytes20 => Wallets.Wallet) registeredWallets;
213
+ }
214
+
215
+ event DepositParametersUpdated(
216
+ uint64 depositDustThreshold,
217
+ uint64 depositTreasuryFeeDivisor,
218
+ uint64 depositTxMaxFee
219
+ );
220
+
221
+ event RedemptionParametersUpdated(
222
+ uint64 redemptionDustThreshold,
223
+ uint64 redemptionTreasuryFeeDivisor,
224
+ uint64 redemptionTxMaxFee,
225
+ uint256 redemptionTimeout
226
+ );
227
+
228
+ event MovingFundsParametersUpdated(
229
+ uint64 movingFundsTxMaxTotalFee,
230
+ uint32 movingFundsTimeout,
231
+ uint64 movingFundsDustThreshold
232
+ );
233
+
234
+ event WalletParametersUpdated(
235
+ uint32 walletCreationPeriod,
236
+ uint64 walletCreationMinBtcBalance,
237
+ uint64 walletCreationMaxBtcBalance,
238
+ uint64 walletClosureMinBtcBalance,
239
+ uint32 walletMaxAge,
240
+ uint64 walletMaxBtcTransfer,
241
+ uint32 walletClosingPeriod
242
+ );
243
+
244
+ event FraudParametersUpdated(
245
+ uint96 fraudSlashingAmount,
246
+ uint256 fraudNotifierRewardMultiplier,
247
+ uint256 fraudChallengeDefeatTimeout,
248
+ uint256 fraudChallengeDepositAmount
249
+ );
250
+
251
+ /// @notice Updates parameters of deposits.
252
+ /// @param _depositDustThreshold New value of the deposit dust threshold in
253
+ /// satoshis. It is the minimal amount that can be requested to
254
+ //// deposit. Value of this parameter must take into account the value
255
+ /// of `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters
256
+ /// in order to make requests that can incur the treasury and
257
+ /// transaction fee and still satisfy the depositor
258
+ /// @param _depositTreasuryFeeDivisor New value of the treasury fee divisor.
259
+ /// It is the divisor used to compute the treasury fee taken from
260
+ /// each deposit and transferred to the treasury upon sweep proof
261
+ /// submission. That fee is computed as follows:
262
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
263
+ /// For example, if the treasury fee needs to be 2% of each deposit,
264
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
265
+ /// because `1/50 = 0.02 = 2%`
266
+ /// @param _depositTxMaxFee New value of the deposit tx max fee in satoshis.
267
+ /// It is the maximum amount of BTC transaction fee that can
268
+ /// be incurred by each swept deposit being part of the given sweep
269
+ /// transaction. If the maximum BTC transaction fee is exceeded,
270
+ /// such transaction is considered a fraud
271
+ /// @dev Requirements:
272
+ /// - Deposit dust threshold must be greater than zero
273
+ /// - Deposit treasury fee divisor must be greater than zero
274
+ /// - Deposit transaction max fee must be greater than zero
275
+ function updateDepositParameters(
276
+ Storage storage self,
277
+ uint64 _depositDustThreshold,
278
+ uint64 _depositTreasuryFeeDivisor,
279
+ uint64 _depositTxMaxFee
280
+ ) internal {
281
+ require(
282
+ _depositDustThreshold > 0,
283
+ "Deposit dust threshold must be greater than zero"
284
+ );
285
+
286
+ require(
287
+ _depositTreasuryFeeDivisor > 0,
288
+ "Deposit treasury fee divisor must be greater than zero"
289
+ );
290
+
291
+ require(
292
+ _depositTxMaxFee > 0,
293
+ "Deposit transaction max fee must be greater than zero"
294
+ );
295
+
296
+ self.depositDustThreshold = _depositDustThreshold;
297
+ self.depositTreasuryFeeDivisor = _depositTreasuryFeeDivisor;
298
+ self.depositTxMaxFee = _depositTxMaxFee;
299
+
300
+ emit DepositParametersUpdated(
301
+ _depositDustThreshold,
302
+ _depositTreasuryFeeDivisor,
303
+ _depositTxMaxFee
304
+ );
305
+ }
306
+
307
+ /// @notice Updates parameters of redemptions.
308
+ /// @param _redemptionDustThreshold New value of the redemption dust
309
+ /// threshold in satoshis. It is the minimal amount that can be
310
+ /// requested for redemption. Value of this parameter must take into
311
+ /// account the value of `redemptionTreasuryFeeDivisor` and
312
+ /// `redemptionTxMaxFee` parameters in order to make requests that
313
+ /// can incur the treasury and transaction fee and still satisfy the
314
+ /// redeemer.
315
+ /// @param _redemptionTreasuryFeeDivisor New value of the redemption
316
+ /// treasury fee divisor. It is the divisor used to compute the
317
+ /// treasury fee taken from each redemption request and transferred
318
+ /// to the treasury upon successful request finalization. That fee is
319
+ /// computed as follows:
320
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
321
+ /// For example, if the treasury fee needs to be 2% of each
322
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
323
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
324
+ /// @param _redemptionTxMaxFee New value of the redemption transaction max
325
+ /// fee in satoshis. It is the maximum amount of BTC transaction fee
326
+ /// that can be incurred by each redemption request being part of the
327
+ /// given redemption transaction. If the maximum BTC transaction fee
328
+ /// is exceeded, such transaction is considered a fraud.
329
+ /// This is a per-redemption output max fee for the redemption
330
+ /// transaction.
331
+ /// @param _redemptionTimeout New value of the redemption timeout in seconds.
332
+ /// It is the time after which the redemption request can be reported
333
+ /// as timed out. It is counted from the moment when the redemption
334
+ /// request was created via `requestRedemption` call. Reported timed
335
+ /// out requests are cancelled and locked TBTC is returned to the
336
+ /// redeemer in full amount.
337
+ /// @dev Requirements:
338
+ /// - Redemption dust threshold must be greater than zero
339
+ /// - Redemption treasury fee divisor must be greater than zero
340
+ /// - Redemption transaction max fee must be greater than zero
341
+ /// - Redemption timeout must be greater than zero
342
+ function updateRedemptionParameters(
343
+ Storage storage self,
344
+ uint64 _redemptionDustThreshold,
345
+ uint64 _redemptionTreasuryFeeDivisor,
346
+ uint64 _redemptionTxMaxFee,
347
+ uint256 _redemptionTimeout
348
+ ) internal {
349
+ require(
350
+ _redemptionDustThreshold > 0,
351
+ "Redemption dust threshold must be greater than zero"
352
+ );
353
+
354
+ require(
355
+ _redemptionTreasuryFeeDivisor > 0,
356
+ "Redemption treasury fee divisor must be greater than zero"
357
+ );
358
+
359
+ require(
360
+ _redemptionTxMaxFee > 0,
361
+ "Redemption transaction max fee must be greater than zero"
362
+ );
363
+
364
+ require(
365
+ _redemptionTimeout > 0,
366
+ "Redemption timeout must be greater than zero"
367
+ );
368
+
369
+ self.redemptionDustThreshold = _redemptionDustThreshold;
370
+ self.redemptionTreasuryFeeDivisor = _redemptionTreasuryFeeDivisor;
371
+ self.redemptionTxMaxFee = _redemptionTxMaxFee;
372
+ self.redemptionTimeout = _redemptionTimeout;
373
+
374
+ emit RedemptionParametersUpdated(
375
+ _redemptionDustThreshold,
376
+ _redemptionTreasuryFeeDivisor,
377
+ _redemptionTxMaxFee,
378
+ _redemptionTimeout
379
+ );
380
+ }
381
+
382
+ /// @notice Updates parameters of moving funds.
383
+ /// @param _movingFundsTxMaxTotalFee New value of the moving funds transaction
384
+ /// max total fee in satoshis. It is the maximum amount of the total
385
+ /// BTC transaction fee that is acceptable in a single moving funds
386
+ /// transaction. This is a _total_ max fee for the entire moving
387
+ /// funds transaction.
388
+ /// @param _movingFundsTimeout New value of the moving funds timeout in
389
+ /// seconds. It is the time after which the moving funds process can
390
+ /// be reported as timed out. It is counted from the moment when the
391
+ /// wallet was requested to move their funds and switched to the
392
+ /// MovingFunds state.
393
+ /// @param _movingFundsDustThreshold New value of the moving funds dust
394
+ /// threshold. It is the minimal satoshi amount that makes sense to
395
+ // be transferred during the moving funds process. Moving funds
396
+ // wallets having their BTC balance below that value can begin
397
+ // closing immediately as transferring such a low value may not be
398
+ // possible due to BTC network fees.
399
+ /// @dev Requirements:
400
+ /// - Moving funds transaction max total fee must be greater than zero
401
+ /// - Moving funds timeout must be greater than zero
402
+ /// - Moving funds dust threshold must be greater than zero
403
+ function updateMovingFundsParameters(
404
+ Storage storage self,
405
+ uint64 _movingFundsTxMaxTotalFee,
406
+ uint32 _movingFundsTimeout,
407
+ uint64 _movingFundsDustThreshold
408
+ ) internal {
409
+ require(
410
+ _movingFundsTxMaxTotalFee > 0,
411
+ "Moving funds transaction max total fee must be greater than zero"
412
+ );
413
+
414
+ require(
415
+ _movingFundsTimeout > 0,
416
+ "Moving funds timeout must be greater than zero"
417
+ );
418
+
419
+ require(
420
+ _movingFundsDustThreshold > 0,
421
+ "Moving funds dust threshold must be greater than zero"
422
+ );
423
+
424
+ self.movingFundsTxMaxTotalFee = _movingFundsTxMaxTotalFee;
425
+ self.movingFundsTimeout = _movingFundsTimeout;
426
+ self.movingFundsDustThreshold = _movingFundsDustThreshold;
427
+
428
+ emit MovingFundsParametersUpdated(
429
+ _movingFundsTxMaxTotalFee,
430
+ _movingFundsTimeout,
431
+ _movingFundsDustThreshold
432
+ );
433
+ }
434
+
435
+ /// @notice Updates parameters of wallets.
436
+ /// @param _walletCreationPeriod New value of the wallet creation period in
437
+ /// seconds, determines how frequently a new wallet creation can be
438
+ /// requested
439
+ /// @param _walletCreationMinBtcBalance New value of the wallet minimum BTC
440
+ /// balance in satoshi, used to decide about wallet creation
441
+ /// @param _walletCreationMaxBtcBalance New value of the wallet maximum BTC
442
+ /// balance in satoshi, used to decide about wallet creation
443
+ /// @param _walletClosureMinBtcBalance New value of the wallet minimum BTC
444
+ /// balance in satoshi, used to decide about wallet closure
445
+ /// @param _walletMaxAge New value of the wallet maximum age in seconds,
446
+ /// indicates the maximum age of a wallet in seconds, after which
447
+ /// the wallet moving funds process can be requested
448
+ /// @param _walletMaxBtcTransfer New value of the wallet maximum BTC transfer
449
+ /// in satoshi, determines the maximum amount that can be transferred
450
+ /// to a single target wallet during the moving funds process
451
+ /// @param _walletClosingPeriod New value of the wallet closing period in
452
+ /// seconds, determines the length of the wallet closing period,
453
+ // i.e. the period when the wallet remains in the Closing state
454
+ // and can be subject of deposit fraud challenges
455
+ /// @dev Requirements:
456
+ /// - Wallet minimum BTC balance must be greater than zero
457
+ /// - Wallet maximum BTC balance must be greater than the wallet
458
+ /// minimum BTC balance
459
+ /// - Wallet maximum BTC transfer must be greater than zero
460
+ /// - Wallet closing period must be greater than zero
461
+ function updateWalletParameters(
462
+ Storage storage self,
463
+ uint32 _walletCreationPeriod,
464
+ uint64 _walletCreationMinBtcBalance,
465
+ uint64 _walletCreationMaxBtcBalance,
466
+ uint64 _walletClosureMinBtcBalance,
467
+ uint32 _walletMaxAge,
468
+ uint64 _walletMaxBtcTransfer,
469
+ uint32 _walletClosingPeriod
470
+ ) internal {
471
+ require(
472
+ _walletCreationMaxBtcBalance > _walletCreationMinBtcBalance,
473
+ "Wallet creation maximum BTC balance must be greater than the creation minimum BTC balance"
474
+ );
475
+ require(
476
+ _walletClosureMinBtcBalance > 0,
477
+ "Wallet closure minimum BTC balance must be greater than zero"
478
+ );
479
+ require(
480
+ _walletMaxBtcTransfer > 0,
481
+ "Wallet maximum BTC transfer must be greater than zero"
482
+ );
483
+ require(
484
+ _walletClosingPeriod > 0,
485
+ "Wallet closing period must be greater than zero"
486
+ );
487
+
488
+ self.walletCreationPeriod = _walletCreationPeriod;
489
+ self.walletCreationMinBtcBalance = _walletCreationMinBtcBalance;
490
+ self.walletCreationMaxBtcBalance = _walletCreationMaxBtcBalance;
491
+ self.walletClosureMinBtcBalance = _walletClosureMinBtcBalance;
492
+ self.walletMaxAge = _walletMaxAge;
493
+ self.walletMaxBtcTransfer = _walletMaxBtcTransfer;
494
+ self.walletClosingPeriod = _walletClosingPeriod;
495
+
496
+ emit WalletParametersUpdated(
497
+ _walletCreationPeriod,
498
+ _walletCreationMinBtcBalance,
499
+ _walletCreationMaxBtcBalance,
500
+ _walletClosureMinBtcBalance,
501
+ _walletMaxAge,
502
+ _walletMaxBtcTransfer,
503
+ _walletClosingPeriod
504
+ );
505
+ }
506
+
507
+ /// @notice Updates parameters related to frauds.
508
+ /// @param _fraudSlashingAmount New value of the fraud slashing amount in T,
509
+ /// it is the amount slashed from each wallet member for committing
510
+ /// a fraud
511
+ /// @param _fraudNotifierRewardMultiplier New value of the fraud notifier
512
+ /// reward multiplier as percentage, it determines the percentage of
513
+ /// the notifier reward from the staking contact the notifier of
514
+ /// a fraud receives. The value must be in the range [0, 100]
515
+ /// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
516
+ /// timeout in seconds, it is the amount of time the wallet has to
517
+ /// defeat a fraud challenge. The value must be greater than zero
518
+ /// @param _fraudChallengeDepositAmount New value of the fraud challenge
519
+ /// deposit amount in wei, it is the amount of ETH the party
520
+ /// challenging the wallet for fraud needs to deposit
521
+ /// @dev Requirements:
522
+ /// - Fraud notifier reward multiplier must be in the range [0, 100]
523
+ /// - Fraud challenge defeat timeout must be greater than 0
524
+ function updateFraudParameters(
525
+ Storage storage self,
526
+ uint96 _fraudSlashingAmount,
527
+ uint256 _fraudNotifierRewardMultiplier,
528
+ uint256 _fraudChallengeDefeatTimeout,
529
+ uint256 _fraudChallengeDepositAmount
530
+ ) internal {
531
+ require(
532
+ _fraudNotifierRewardMultiplier <= 100,
533
+ "Fraud notifier reward multiplier must be in the range [0, 100]"
534
+ );
535
+
536
+ require(
537
+ _fraudChallengeDefeatTimeout > 0,
538
+ "Fraud challenge defeat timeout must be greater than zero"
539
+ );
540
+
541
+ self.fraudSlashingAmount = _fraudSlashingAmount;
542
+ self.fraudNotifierRewardMultiplier = _fraudNotifierRewardMultiplier;
543
+ self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
544
+ self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
545
+
546
+ emit FraudParametersUpdated(
547
+ _fraudSlashingAmount,
548
+ _fraudNotifierRewardMultiplier,
549
+ _fraudChallengeDefeatTimeout,
550
+ _fraudChallengeDepositAmount
551
+ );
552
+ }
553
+ }