@keep-network/tbtc-v2 0.1.1-dev.6 → 0.1.1-dev.62

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