@keep-network/tbtc-v2 0.1.1-dev.7 → 0.1.1-dev.72

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