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

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