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

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 +3271 -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 +153 -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/b0c3ed0992bd570aaaee717425c37538.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 +2093 -77
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  43. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +166 -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 +1274 -126
  74. package/contracts/bridge/BridgeState.sol +538 -0
  75. package/contracts/bridge/Deposit.sol +266 -0
  76. package/contracts/bridge/EcdsaLib.sol +45 -0
  77. package/contracts/bridge/Fraud.sol +488 -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 +551 -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 +15173 -472
  94. package/package.json +27 -23
  95. package/artifacts/solcInputs/d71966212a658480bad5748ad85b1396.json +0 -116
@@ -0,0 +1,538 @@
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
+ uint256 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 or closing.
179
+ uint64 walletMinBtcBalance;
180
+ // The maximum BTC threshold in satoshi that is used to decide about
181
+ // wallet creation.
182
+ uint64 walletMaxBtcBalance;
183
+ // The maximum age of a wallet in seconds, after which the wallet
184
+ // moving funds process can be requested.
185
+ uint32 walletMaxAge;
186
+ // 20-byte wallet public key hash being reference to the currently
187
+ // active wallet. Can be unset to the zero value under certain
188
+ // circumstances.
189
+ bytes20 activeWalletPubKeyHash;
190
+ // The current number of wallets in the Live state.
191
+ uint32 liveWalletsCount;
192
+ // The maximum BTC amount in satoshi than can be transferred to a single
193
+ // target wallet during the moving funds process.
194
+ uint64 walletMaxBtcTransfer;
195
+ // Determines the length of the wallet closing period, i.e. the period
196
+ // when the wallet remains in the Closing state and can be subject
197
+ // of deposit fraud challenges. This value is in seconds and should be
198
+ // greater than the deposit refund time plus some time margin.
199
+ uint32 walletClosingPeriod;
200
+ // Maps the 20-byte wallet public key hash (computed using Bitcoin
201
+ // HASH160 over the compressed ECDSA public key) to the basic wallet
202
+ // information like state and pending redemptions value.
203
+ mapping(bytes20 => Wallets.Wallet) registeredWallets;
204
+ }
205
+
206
+ event DepositParametersUpdated(
207
+ uint64 depositDustThreshold,
208
+ uint64 depositTreasuryFeeDivisor,
209
+ uint64 depositTxMaxFee
210
+ );
211
+
212
+ event RedemptionParametersUpdated(
213
+ uint64 redemptionDustThreshold,
214
+ uint64 redemptionTreasuryFeeDivisor,
215
+ uint64 redemptionTxMaxFee,
216
+ uint256 redemptionTimeout
217
+ );
218
+
219
+ event MovingFundsParametersUpdated(
220
+ uint64 movingFundsTxMaxTotalFee,
221
+ uint32 movingFundsTimeout,
222
+ uint64 movingFundsDustThreshold
223
+ );
224
+
225
+ event WalletParametersUpdated(
226
+ uint32 walletCreationPeriod,
227
+ uint64 walletMinBtcBalance,
228
+ uint64 walletMaxBtcBalance,
229
+ uint32 walletMaxAge,
230
+ uint64 walletMaxBtcTransfer,
231
+ uint32 walletClosingPeriod
232
+ );
233
+
234
+ event FraudParametersUpdated(
235
+ uint256 fraudSlashingAmount,
236
+ uint256 fraudNotifierRewardMultiplier,
237
+ uint256 fraudChallengeDefeatTimeout,
238
+ uint256 fraudChallengeDepositAmount
239
+ );
240
+
241
+ /// @notice Updates parameters of deposits.
242
+ /// @param _depositDustThreshold New value of the deposit dust threshold in
243
+ /// satoshis. It is the minimal amount that can be requested to
244
+ //// deposit. Value of this parameter must take into account the value
245
+ /// of `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters
246
+ /// in order to make requests that can incur the treasury and
247
+ /// transaction fee and still satisfy the depositor
248
+ /// @param _depositTreasuryFeeDivisor New value of the treasury fee divisor.
249
+ /// It is the divisor used to compute the treasury fee taken from
250
+ /// each deposit and transferred to the treasury upon sweep proof
251
+ /// submission. That fee is computed as follows:
252
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
253
+ /// For example, if the treasury fee needs to be 2% of each deposit,
254
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
255
+ /// because `1/50 = 0.02 = 2%`
256
+ /// @param _depositTxMaxFee New value of the deposit tx max fee in satoshis.
257
+ /// It is the maximum amount of BTC transaction fee that can
258
+ /// be incurred by each swept deposit being part of the given sweep
259
+ /// transaction. If the maximum BTC transaction fee is exceeded,
260
+ /// such transaction is considered a fraud
261
+ /// @dev Requirements:
262
+ /// - Deposit dust threshold must be greater than zero
263
+ /// - Deposit treasury fee divisor must be greater than zero
264
+ /// - Deposit transaction max fee must be greater than zero
265
+ function updateDepositParameters(
266
+ Storage storage self,
267
+ uint64 _depositDustThreshold,
268
+ uint64 _depositTreasuryFeeDivisor,
269
+ uint64 _depositTxMaxFee
270
+ ) internal {
271
+ require(
272
+ _depositDustThreshold > 0,
273
+ "Deposit dust threshold must be greater than zero"
274
+ );
275
+
276
+ require(
277
+ _depositTreasuryFeeDivisor > 0,
278
+ "Deposit treasury fee divisor must be greater than zero"
279
+ );
280
+
281
+ require(
282
+ _depositTxMaxFee > 0,
283
+ "Deposit transaction max fee must be greater than zero"
284
+ );
285
+
286
+ self.depositDustThreshold = _depositDustThreshold;
287
+ self.depositTreasuryFeeDivisor = _depositTreasuryFeeDivisor;
288
+ self.depositTxMaxFee = _depositTxMaxFee;
289
+
290
+ emit DepositParametersUpdated(
291
+ _depositDustThreshold,
292
+ _depositTreasuryFeeDivisor,
293
+ _depositTxMaxFee
294
+ );
295
+ }
296
+
297
+ /// @notice Updates parameters of redemptions.
298
+ /// @param _redemptionDustThreshold New value of the redemption dust
299
+ /// threshold in satoshis. It is the minimal amount that can be
300
+ /// requested for redemption. Value of this parameter must take into
301
+ /// account the value of `redemptionTreasuryFeeDivisor` and
302
+ /// `redemptionTxMaxFee` parameters in order to make requests that
303
+ /// can incur the treasury and transaction fee and still satisfy the
304
+ /// redeemer.
305
+ /// @param _redemptionTreasuryFeeDivisor New value of the redemption
306
+ /// treasury fee divisor. It is the divisor used to compute the
307
+ /// treasury fee taken from each redemption request and transferred
308
+ /// to the treasury upon successful request finalization. That fee is
309
+ /// computed as follows:
310
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
311
+ /// For example, if the treasury fee needs to be 2% of each
312
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
313
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
314
+ /// @param _redemptionTxMaxFee New value of the redemption transaction max
315
+ /// fee in satoshis. It is the maximum amount of BTC transaction fee
316
+ /// that can be incurred by each redemption request being part of the
317
+ /// given redemption transaction. If the maximum BTC transaction fee
318
+ /// is exceeded, such transaction is considered a fraud.
319
+ /// This is a per-redemption output max fee for the redemption
320
+ /// transaction.
321
+ /// @param _redemptionTimeout New value of the redemption timeout in seconds.
322
+ /// It is the time after which the redemption request can be reported
323
+ /// as timed out. It is counted from the moment when the redemption
324
+ /// request was created via `requestRedemption` call. Reported timed
325
+ /// out requests are cancelled and locked TBTC is returned to the
326
+ /// redeemer in full amount.
327
+ /// @dev Requirements:
328
+ /// - Redemption dust threshold must be greater than zero
329
+ /// - Redemption treasury fee divisor must be greater than zero
330
+ /// - Redemption transaction max fee must be greater than zero
331
+ /// - Redemption timeout must be greater than zero
332
+ function updateRedemptionParameters(
333
+ Storage storage self,
334
+ uint64 _redemptionDustThreshold,
335
+ uint64 _redemptionTreasuryFeeDivisor,
336
+ uint64 _redemptionTxMaxFee,
337
+ uint256 _redemptionTimeout
338
+ ) internal {
339
+ require(
340
+ _redemptionDustThreshold > 0,
341
+ "Redemption dust threshold must be greater than zero"
342
+ );
343
+
344
+ require(
345
+ _redemptionTreasuryFeeDivisor > 0,
346
+ "Redemption treasury fee divisor must be greater than zero"
347
+ );
348
+
349
+ require(
350
+ _redemptionTxMaxFee > 0,
351
+ "Redemption transaction max fee must be greater than zero"
352
+ );
353
+
354
+ require(
355
+ _redemptionTimeout > 0,
356
+ "Redemption timeout must be greater than zero"
357
+ );
358
+
359
+ self.redemptionDustThreshold = _redemptionDustThreshold;
360
+ self.redemptionTreasuryFeeDivisor = _redemptionTreasuryFeeDivisor;
361
+ self.redemptionTxMaxFee = _redemptionTxMaxFee;
362
+ self.redemptionTimeout = _redemptionTimeout;
363
+
364
+ emit RedemptionParametersUpdated(
365
+ _redemptionDustThreshold,
366
+ _redemptionTreasuryFeeDivisor,
367
+ _redemptionTxMaxFee,
368
+ _redemptionTimeout
369
+ );
370
+ }
371
+
372
+ /// @notice Updates parameters of moving funds.
373
+ /// @param _movingFundsTxMaxTotalFee New value of the moving funds transaction
374
+ /// max total fee in satoshis. It is the maximum amount of the total
375
+ /// BTC transaction fee that is acceptable in a single moving funds
376
+ /// transaction. This is a _total_ max fee for the entire moving
377
+ /// funds transaction.
378
+ /// @param _movingFundsTimeout New value of the moving funds timeout in
379
+ /// seconds. It is the time after which the moving funds process can
380
+ /// be reported as timed out. It is counted from the moment when the
381
+ /// wallet was requested to move their funds and switched to the
382
+ /// MovingFunds state.
383
+ /// @param _movingFundsDustThreshold New value of the moving funds dust
384
+ /// threshold. It is the minimal satoshi amount that makes sense to
385
+ // be transferred during the moving funds process. Moving funds
386
+ // wallets having their BTC balance below that value can begin
387
+ // closing immediately as transferring such a low value may not be
388
+ // possible due to BTC network fees.
389
+ /// @dev Requirements:
390
+ /// - Moving funds transaction max total fee must be greater than zero
391
+ /// - Moving funds timeout must be greater than zero
392
+ /// - Moving funds dust threshold must be greater than zero
393
+ function updateMovingFundsParameters(
394
+ Storage storage self,
395
+ uint64 _movingFundsTxMaxTotalFee,
396
+ uint32 _movingFundsTimeout,
397
+ uint64 _movingFundsDustThreshold
398
+ ) internal {
399
+ require(
400
+ _movingFundsTxMaxTotalFee > 0,
401
+ "Moving funds transaction max total fee must be greater than zero"
402
+ );
403
+
404
+ require(
405
+ _movingFundsTimeout > 0,
406
+ "Moving funds timeout must be greater than zero"
407
+ );
408
+
409
+ require(
410
+ _movingFundsDustThreshold > 0,
411
+ "Moving funds dust threshold must be greater than zero"
412
+ );
413
+
414
+ self.movingFundsTxMaxTotalFee = _movingFundsTxMaxTotalFee;
415
+ self.movingFundsTimeout = _movingFundsTimeout;
416
+ self.movingFundsDustThreshold = _movingFundsDustThreshold;
417
+
418
+ emit MovingFundsParametersUpdated(
419
+ _movingFundsTxMaxTotalFee,
420
+ _movingFundsTimeout,
421
+ _movingFundsDustThreshold
422
+ );
423
+ }
424
+
425
+ /// @notice Updates parameters of wallets.
426
+ /// @param _walletCreationPeriod New value of the wallet creation period in
427
+ /// seconds, determines how frequently a new wallet creation can be
428
+ /// requested
429
+ /// @param _walletMinBtcBalance New value of the wallet minimum BTC balance
430
+ /// in satoshi, used to decide about wallet creation or closing
431
+ /// @param _walletMaxBtcBalance New value of the wallet maximum BTC balance
432
+ /// in satoshi, used to decide about wallet creation
433
+ /// @param _walletMaxAge New value of the wallet maximum age in seconds,
434
+ /// indicates the maximum age of a wallet in seconds, after which
435
+ /// the wallet moving funds process can be requested
436
+ /// @param _walletMaxBtcTransfer New value of the wallet maximum BTC transfer
437
+ /// in satoshi, determines the maximum amount that can be transferred
438
+ /// to a single target wallet during the moving funds process
439
+ /// @param _walletClosingPeriod New value of the wallet closing period in
440
+ /// seconds, determines the length of the wallet closing period,
441
+ // i.e. the period when the wallet remains in the Closing state
442
+ // and can be subject of deposit fraud challenges
443
+ /// @dev Requirements:
444
+ /// - Wallet minimum BTC balance must be greater than zero
445
+ /// - Wallet maximum BTC balance must be greater than the wallet
446
+ /// minimum BTC balance
447
+ /// - Wallet maximum BTC transfer must be greater than zero
448
+ /// - Wallet closing period must be greater than zero
449
+ function updateWalletParameters(
450
+ Storage storage self,
451
+ uint32 _walletCreationPeriod,
452
+ uint64 _walletMinBtcBalance,
453
+ uint64 _walletMaxBtcBalance,
454
+ uint32 _walletMaxAge,
455
+ uint64 _walletMaxBtcTransfer,
456
+ uint32 _walletClosingPeriod
457
+ ) internal {
458
+ require(
459
+ _walletMinBtcBalance > 0,
460
+ "Wallet minimum BTC balance must be greater than zero"
461
+ );
462
+ require(
463
+ _walletMaxBtcBalance > _walletMinBtcBalance,
464
+ "Wallet maximum BTC balance must be greater than the minimum"
465
+ );
466
+ require(
467
+ _walletMaxBtcTransfer > 0,
468
+ "Wallet maximum BTC transfer must be greater than zero"
469
+ );
470
+ require(
471
+ _walletClosingPeriod > 0,
472
+ "Wallet closing period must be greater than zero"
473
+ );
474
+
475
+ self.walletCreationPeriod = _walletCreationPeriod;
476
+ self.walletMinBtcBalance = _walletMinBtcBalance;
477
+ self.walletMaxBtcBalance = _walletMaxBtcBalance;
478
+ self.walletMaxAge = _walletMaxAge;
479
+ self.walletMaxBtcTransfer = _walletMaxBtcTransfer;
480
+ self.walletClosingPeriod = _walletClosingPeriod;
481
+
482
+ emit WalletParametersUpdated(
483
+ _walletCreationPeriod,
484
+ _walletMinBtcBalance,
485
+ _walletMaxBtcBalance,
486
+ _walletMaxAge,
487
+ _walletMaxBtcTransfer,
488
+ _walletClosingPeriod
489
+ );
490
+ }
491
+
492
+ /// @notice Updates parameters related to frauds.
493
+ /// @param _fraudSlashingAmount New value of the fraud slashing amount in T,
494
+ /// it is the amount slashed from each wallet member for committing
495
+ /// a fraud
496
+ /// @param _fraudNotifierRewardMultiplier New value of the fraud notifier
497
+ /// reward multiplier as percentage, it determines the percentage of
498
+ /// the notifier reward from the staking contact the notifier of
499
+ /// a fraud receives. The value must be in the range [0, 100]
500
+ /// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
501
+ /// timeout in seconds, it is the amount of time the wallet has to
502
+ /// defeat a fraud challenge. The value must be greater than zero
503
+ /// @param _fraudChallengeDepositAmount New value of the fraud challenge
504
+ /// deposit amount in wei, it is the amount of ETH the party
505
+ /// challenging the wallet for fraud needs to deposit
506
+ /// @dev Requirements:
507
+ /// - Fraud notifier reward multiplier must be in the range [0, 100]
508
+ /// - Fraud challenge defeat timeout must be greater than 0
509
+ function updateFraudParameters(
510
+ Storage storage self,
511
+ uint256 _fraudSlashingAmount,
512
+ uint256 _fraudNotifierRewardMultiplier,
513
+ uint256 _fraudChallengeDefeatTimeout,
514
+ uint256 _fraudChallengeDepositAmount
515
+ ) internal {
516
+ require(
517
+ _fraudNotifierRewardMultiplier <= 100,
518
+ "Fraud notifier reward multiplier must be in the range [0, 100]"
519
+ );
520
+
521
+ require(
522
+ _fraudChallengeDefeatTimeout > 0,
523
+ "Fraud challenge defeat timeout must be greater than zero"
524
+ );
525
+
526
+ self.fraudSlashingAmount = _fraudSlashingAmount;
527
+ self.fraudNotifierRewardMultiplier = _fraudNotifierRewardMultiplier;
528
+ self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
529
+ self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
530
+
531
+ emit FraudParametersUpdated(
532
+ _fraudSlashingAmount,
533
+ _fraudNotifierRewardMultiplier,
534
+ _fraudChallengeDefeatTimeout,
535
+ _fraudChallengeDepositAmount
536
+ );
537
+ }
538
+ }