@keep-network/tbtc-v2 0.1.1-dev.1 → 0.1.1-dev.101

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 (125) hide show
  1. package/README.adoc +12 -0
  2. package/artifacts/Bank.json +807 -0
  3. package/artifacts/Bridge.json +2300 -0
  4. package/artifacts/BridgeGovernance.json +2931 -0
  5. package/artifacts/BridgeGovernanceParameters.json +1445 -0
  6. package/artifacts/Deposit.json +117 -0
  7. package/artifacts/DepositSweep.json +77 -0
  8. package/artifacts/EcdsaDkgValidator.json +532 -0
  9. package/artifacts/EcdsaInactivity.json +156 -0
  10. package/artifacts/EcdsaSortitionPool.json +1004 -0
  11. package/artifacts/Fraud.json +164 -0
  12. package/artifacts/KeepRegistry.json +99 -0
  13. package/artifacts/KeepStake.json +286 -0
  14. package/artifacts/KeepToken.json +711 -0
  15. package/artifacts/KeepTokenStaking.json +483 -0
  16. package/artifacts/MovingFunds.json +249 -0
  17. package/artifacts/NuCypherStakingEscrow.json +256 -0
  18. package/artifacts/NuCypherToken.json +711 -0
  19. package/artifacts/RandomBeaconStub.json +141 -0
  20. package/artifacts/Redemption.json +174 -0
  21. package/artifacts/ReimbursementPool.json +509 -0
  22. package/artifacts/Relay.json +123 -0
  23. package/artifacts/T.json +1148 -0
  24. package/artifacts/TBTC.json +27 -26
  25. package/artifacts/TBTCToken.json +27 -26
  26. package/artifacts/TBTCVault.json +691 -0
  27. package/artifacts/TokenStaking.json +2288 -0
  28. package/artifacts/TokenholderGovernor.json +1795 -0
  29. package/artifacts/TokenholderTimelock.json +1058 -0
  30. package/artifacts/VendingMachine.json +31 -30
  31. package/artifacts/VendingMachineKeep.json +400 -0
  32. package/artifacts/VendingMachineNuCypher.json +400 -0
  33. package/artifacts/WalletRegistry.json +1843 -0
  34. package/artifacts/WalletRegistryGovernance.json +2754 -0
  35. package/artifacts/Wallets.json +186 -0
  36. package/artifacts/solcInputs/af641e0b3597cdfa29d6ad42d1cd8742.json +320 -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 +4 -0
  40. package/build/contracts/bank/Bank.sol/Bank.json +542 -0
  41. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +4 -0
  42. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.json +34 -0
  43. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +4 -0
  44. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +10 -0
  45. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +4 -0
  46. package/build/contracts/bridge/Bridge.sol/Bridge.json +2686 -0
  47. package/build/contracts/bridge/BridgeGovernance.sol/BridgeGovernance.dbg.json +4 -0
  48. package/build/contracts/bridge/BridgeGovernance.sol/BridgeGovernance.json +2246 -0
  49. package/build/contracts/bridge/BridgeGovernanceParameters.sol/BridgeGovernanceParameters.dbg.json +4 -0
  50. package/build/contracts/bridge/BridgeGovernanceParameters.sol/BridgeGovernanceParameters.json +971 -0
  51. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  52. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +226 -0
  53. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
  54. package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
  55. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
  56. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +30 -0
  57. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
  58. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
  59. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
  60. package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
  61. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +4 -0
  62. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.json +10 -0
  63. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
  64. package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
  65. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
  66. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +138 -0
  67. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
  68. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
  69. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
  70. package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
  71. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  72. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
  73. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
  74. package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
  75. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  76. package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
  77. package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +4 -0
  78. package/build/contracts/vault/DonationVault.sol/DonationVault.json +108 -0
  79. package/build/contracts/vault/IVault.sol/IVault.dbg.json +4 -0
  80. package/build/contracts/vault/IVault.sol/IVault.json +52 -0
  81. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +4 -0
  82. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +449 -0
  83. package/contracts/GovernanceUtils.sol +4 -4
  84. package/contracts/bank/Bank.sol +436 -0
  85. package/contracts/bank/IReceiveBalanceApproval.sol +45 -0
  86. package/contracts/bridge/BitcoinTx.sol +361 -0
  87. package/contracts/bridge/Bridge.sol +1799 -0
  88. package/contracts/bridge/BridgeGovernance.sol +1533 -0
  89. package/contracts/bridge/BridgeGovernanceParameters.sol +1695 -0
  90. package/contracts/bridge/BridgeState.sol +768 -0
  91. package/contracts/bridge/Deposit.sol +269 -0
  92. package/contracts/bridge/DepositSweep.sol +574 -0
  93. package/contracts/bridge/EcdsaLib.sol +45 -0
  94. package/contracts/bridge/Fraud.sol +579 -0
  95. package/contracts/bridge/Heartbeat.sol +112 -0
  96. package/contracts/bridge/IRelay.sol +28 -0
  97. package/contracts/bridge/MovingFunds.sol +1077 -0
  98. package/contracts/bridge/Redemption.sol +1058 -0
  99. package/contracts/bridge/VendingMachine.sol +2 -2
  100. package/contracts/bridge/Wallets.sol +719 -0
  101. package/contracts/hardhat-dependency-compiler/.hardhat-dependency-compiler +1 -0
  102. package/contracts/hardhat-dependency-compiler/@keep-network/ecdsa/contracts/WalletRegistry.sol +3 -0
  103. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol +3 -0
  104. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +3 -0
  105. package/contracts/token/TBTC.sol +1 -1
  106. package/contracts/vault/DonationVault.sol +125 -0
  107. package/contracts/vault/IVault.sol +44 -0
  108. package/contracts/vault/TBTCVault.sol +305 -0
  109. package/deploy/00_resolve_relay.ts +28 -0
  110. package/deploy/{03_transfer_roles.ts → 03_transfer_vending_machine_roles.ts} +1 -1
  111. package/deploy/04_deploy_bank.ts +27 -0
  112. package/deploy/05_deploy_bridge.ts +80 -0
  113. package/deploy/06_deploy_tbtc_vault.ts +30 -0
  114. package/deploy/07_deploy_bridge_governance.ts +40 -0
  115. package/deploy/08_bank_update_bridge.ts +19 -0
  116. package/deploy/09_transfer_bank_ownership.ts +15 -0
  117. package/deploy/10_transfer_tbtc_vault_ownership.ts +15 -0
  118. package/deploy/11_transfer_bridge_governance_ownership.ts +19 -0
  119. package/deploy/12_transfer_bridge_governance.ts +22 -0
  120. package/deploy/13_initialize_wallet_owner.ts +18 -0
  121. package/deploy/14_deploy_proxy_admin_with_deputy.ts +33 -0
  122. package/deploy/15_transfer_proxy_admin_ownership.ts +30 -0
  123. package/export.json +18510 -475
  124. package/package.json +35 -26
  125. package/artifacts/solcInputs/0c46d22cee2363c42c8bb0664dc1be66.json +0 -104
@@ -0,0 +1,1799 @@
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 "@keep-network/random-beacon/contracts/Governable.sol";
19
+ import {IWalletOwner as EcdsaWalletOwner} from "@keep-network/ecdsa/contracts/api/IWalletOwner.sol";
20
+
21
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
22
+ import "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";
23
+
24
+ import "./IRelay.sol";
25
+ import "./BridgeState.sol";
26
+ import "./Deposit.sol";
27
+ import "./DepositSweep.sol";
28
+ import "./Redemption.sol";
29
+ import "./BitcoinTx.sol";
30
+ import "./EcdsaLib.sol";
31
+ import "./Wallets.sol";
32
+ import "./Fraud.sol";
33
+ import "./MovingFunds.sol";
34
+
35
+ import "../bank/IReceiveBalanceApproval.sol";
36
+ import "../bank/Bank.sol";
37
+
38
+ /// @title Bitcoin Bridge
39
+ /// @notice Bridge manages BTC deposit and redemption flow and is increasing and
40
+ /// decreasing balances in the Bank as a result of BTC deposit and
41
+ /// redemption operations performed by depositors and redeemers.
42
+ ///
43
+ /// Depositors send BTC funds to the most recently created off-chain
44
+ /// ECDSA wallet of the bridge using pay-to-script-hash (P2SH) or
45
+ /// pay-to-witness-script-hash (P2WSH) containing hashed information
46
+ /// about the depositor’s Ethereum address. Then, the depositor reveals
47
+ /// their Ethereum address along with their deposit blinding factor,
48
+ /// refund public key hash and refund locktime to the Bridge on Ethereum
49
+ /// chain. The off-chain ECDSA wallet listens for these sorts of
50
+ /// messages and when it gets one, it checks the Bitcoin network to make
51
+ /// sure the deposit lines up. If it does, the off-chain ECDSA wallet
52
+ /// may decide to pick the deposit transaction for sweeping, and when
53
+ /// the sweep operation is confirmed on the Bitcoin network, the ECDSA
54
+ /// wallet informs the Bridge about the sweep increasing appropriate
55
+ /// balances in the Bank.
56
+ /// @dev Bridge is an upgradeable component of the Bank. The order of
57
+ /// functionalities in this contract is: deposit, sweep, redemption,
58
+ /// moving funds, wallet lifecycle, frauds, parameters.
59
+ contract Bridge is
60
+ Governable,
61
+ EcdsaWalletOwner,
62
+ Initializable,
63
+ IReceiveBalanceApproval
64
+ {
65
+ using BridgeState for BridgeState.Storage;
66
+ using Deposit for BridgeState.Storage;
67
+ using DepositSweep for BridgeState.Storage;
68
+ using Redemption for BridgeState.Storage;
69
+ using MovingFunds for BridgeState.Storage;
70
+ using Wallets for BridgeState.Storage;
71
+ using Fraud for BridgeState.Storage;
72
+
73
+ BridgeState.Storage internal self;
74
+
75
+ event DepositRevealed(
76
+ bytes32 fundingTxHash,
77
+ uint32 fundingOutputIndex,
78
+ address indexed depositor,
79
+ uint64 amount,
80
+ bytes8 blindingFactor,
81
+ bytes20 indexed walletPubKeyHash,
82
+ bytes20 refundPubKeyHash,
83
+ bytes4 refundLocktime,
84
+ address vault
85
+ );
86
+
87
+ event DepositsSwept(bytes20 walletPubKeyHash, bytes32 sweepTxHash);
88
+
89
+ event RedemptionRequested(
90
+ bytes20 indexed walletPubKeyHash,
91
+ bytes redeemerOutputScript,
92
+ address indexed redeemer,
93
+ uint64 requestedAmount,
94
+ uint64 treasuryFee,
95
+ uint64 txMaxFee
96
+ );
97
+
98
+ event RedemptionsCompleted(
99
+ bytes20 indexed walletPubKeyHash,
100
+ bytes32 redemptionTxHash
101
+ );
102
+
103
+ event RedemptionTimedOut(
104
+ bytes20 indexed walletPubKeyHash,
105
+ bytes redeemerOutputScript
106
+ );
107
+
108
+ event WalletMovingFunds(
109
+ bytes32 indexed ecdsaWalletID,
110
+ bytes20 indexed walletPubKeyHash
111
+ );
112
+
113
+ event MovingFundsCommitmentSubmitted(
114
+ bytes20 indexed walletPubKeyHash,
115
+ bytes20[] targetWallets,
116
+ address submitter
117
+ );
118
+
119
+ event MovingFundsTimeoutReset(bytes20 indexed walletPubKeyHash);
120
+
121
+ event MovingFundsCompleted(
122
+ bytes20 indexed walletPubKeyHash,
123
+ bytes32 movingFundsTxHash
124
+ );
125
+
126
+ event MovingFundsTimedOut(bytes20 indexed walletPubKeyHash);
127
+
128
+ event MovingFundsBelowDustReported(bytes20 indexed walletPubKeyHash);
129
+
130
+ event MovedFundsSwept(
131
+ bytes20 indexed walletPubKeyHash,
132
+ bytes32 sweepTxHash
133
+ );
134
+
135
+ event MovedFundsSweepTimedOut(
136
+ bytes20 indexed walletPubKeyHash,
137
+ bytes32 movingFundsTxHash,
138
+ uint32 movingFundsTxOutputIndex
139
+ );
140
+
141
+ event NewWalletRequested();
142
+
143
+ event NewWalletRegistered(
144
+ bytes32 indexed ecdsaWalletID,
145
+ bytes20 indexed walletPubKeyHash
146
+ );
147
+
148
+ event WalletClosing(
149
+ bytes32 indexed ecdsaWalletID,
150
+ bytes20 indexed walletPubKeyHash
151
+ );
152
+
153
+ event WalletClosed(
154
+ bytes32 indexed ecdsaWalletID,
155
+ bytes20 indexed walletPubKeyHash
156
+ );
157
+
158
+ event WalletTerminated(
159
+ bytes32 indexed ecdsaWalletID,
160
+ bytes20 indexed walletPubKeyHash
161
+ );
162
+
163
+ event FraudChallengeSubmitted(
164
+ bytes20 indexed walletPubKeyHash,
165
+ bytes32 sighash,
166
+ uint8 v,
167
+ bytes32 r,
168
+ bytes32 s
169
+ );
170
+
171
+ event FraudChallengeDefeated(
172
+ bytes20 indexed walletPubKeyHash,
173
+ bytes32 sighash
174
+ );
175
+
176
+ event FraudChallengeDefeatTimedOut(
177
+ bytes20 indexed walletPubKeyHash,
178
+ bytes32 sighash
179
+ );
180
+
181
+ event VaultStatusUpdated(address indexed vault, bool isTrusted);
182
+
183
+ event DepositParametersUpdated(
184
+ uint64 depositDustThreshold,
185
+ uint64 depositTreasuryFeeDivisor,
186
+ uint64 depositTxMaxFee
187
+ );
188
+
189
+ event RedemptionParametersUpdated(
190
+ uint64 redemptionDustThreshold,
191
+ uint64 redemptionTreasuryFeeDivisor,
192
+ uint64 redemptionTxMaxFee,
193
+ uint32 redemptionTimeout,
194
+ uint96 redemptionTimeoutSlashingAmount,
195
+ uint32 redemptionTimeoutNotifierRewardMultiplier
196
+ );
197
+
198
+ event MovingFundsParametersUpdated(
199
+ uint64 movingFundsTxMaxTotalFee,
200
+ uint64 movingFundsDustThreshold,
201
+ uint32 movingFundsTimeoutResetDelay,
202
+ uint32 movingFundsTimeout,
203
+ uint96 movingFundsTimeoutSlashingAmount,
204
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
205
+ uint64 movedFundsSweepTxMaxTotalFee,
206
+ uint32 movedFundsSweepTimeout,
207
+ uint96 movedFundsSweepTimeoutSlashingAmount,
208
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
209
+ );
210
+
211
+ event WalletParametersUpdated(
212
+ uint32 walletCreationPeriod,
213
+ uint64 walletCreationMinBtcBalance,
214
+ uint64 walletCreationMaxBtcBalance,
215
+ uint64 walletClosureMinBtcBalance,
216
+ uint32 walletMaxAge,
217
+ uint64 walletMaxBtcTransfer,
218
+ uint32 walletClosingPeriod
219
+ );
220
+
221
+ event FraudParametersUpdated(
222
+ uint96 fraudChallengeDepositAmount,
223
+ uint32 fraudChallengeDefeatTimeout,
224
+ uint96 fraudSlashingAmount,
225
+ uint32 fraudNotifierRewardMultiplier
226
+ );
227
+
228
+ /// @dev Initializes upgradable contract on deployment.
229
+ /// @param _bank Address of the Bank the Bridge belongs to.
230
+ /// @param _relay Address of the Bitcoin relay providing the current Bitcoin
231
+ /// network difficulty.
232
+ /// @param _treasury Address where the deposit and redemption treasury fees
233
+ /// will be sent to.
234
+ /// @param _ecdsaWalletRegistry Address of the ECDSA Wallet Registry contract.
235
+ /// @param _txProofDifficultyFactor The number of confirmations on the Bitcoin
236
+ /// chain required to successfully evaluate an SPV proof.
237
+ function initialize(
238
+ address _bank,
239
+ address _relay,
240
+ address _treasury,
241
+ address _ecdsaWalletRegistry,
242
+ uint96 _txProofDifficultyFactor
243
+ ) external initializer {
244
+ require(_bank != address(0), "Bank address cannot be zero");
245
+ self.bank = Bank(_bank);
246
+
247
+ require(_relay != address(0), "Relay address cannot be zero");
248
+ self.relay = IRelay(_relay);
249
+
250
+ require(
251
+ _ecdsaWalletRegistry != address(0),
252
+ "ECDSA Wallet Registry address cannot be zero"
253
+ );
254
+ self.ecdsaWalletRegistry = EcdsaWalletRegistry(_ecdsaWalletRegistry);
255
+
256
+ require(_treasury != address(0), "Treasury address cannot be zero");
257
+ self.treasury = _treasury;
258
+
259
+ self.txProofDifficultyFactor = _txProofDifficultyFactor;
260
+
261
+ //
262
+ // All parameters set in the constructor are initial ones, used at the
263
+ // moment contracts were deployed for the first time. Parameters are
264
+ // governable and values assigned in the constructor do not need to
265
+ // reflect the current ones. Keep in mind the initial parameters are
266
+ // pretty forgiving and valid only for the early stage of the network.
267
+ //
268
+
269
+ self.depositDustThreshold = 1000000; // 1000000 satoshi = 0.01 BTC
270
+ self.depositTxMaxFee = 100000; // 100000 satoshi = 0.001 BTC
271
+ self.depositTreasuryFeeDivisor = 2000; // 1/2000 == 5bps == 0.05% == 0.0005
272
+ self.redemptionDustThreshold = 1000000; // 1000000 satoshi = 0.01 BTC
273
+ self.redemptionTreasuryFeeDivisor = 2000; // 1/2000 == 5bps == 0.05% == 0.0005
274
+ self.redemptionTxMaxFee = 100000; // 100000 satoshi = 0.001 BTC
275
+ self.redemptionTimeout = 5 days;
276
+ self.redemptionTimeoutSlashingAmount = 100 * 1e18; // 100 T
277
+ self.redemptionTimeoutNotifierRewardMultiplier = 100; // 100%
278
+ self.movingFundsTxMaxTotalFee = 100000; // 100000 satoshi = 0.001 BTC
279
+ self.movingFundsDustThreshold = 200000; // 200000 satoshi = 0.002 BTC
280
+ self.movingFundsTimeoutResetDelay = 6 days;
281
+ self.movingFundsTimeout = 7 days;
282
+ self.movingFundsTimeoutSlashingAmount = 100 * 1e18; // 100 T
283
+ self.movingFundsTimeoutNotifierRewardMultiplier = 100; //100%
284
+ self.movedFundsSweepTxMaxTotalFee = 100000; // 100000 satoshi = 0.001 BTC
285
+ self.movedFundsSweepTimeout = 7 days;
286
+ self.movedFundsSweepTimeoutSlashingAmount = 100 * 1e18; // 100 T
287
+ self.movedFundsSweepTimeoutNotifierRewardMultiplier = 100; //100%
288
+ self.fraudChallengeDepositAmount = 5 ether;
289
+ self.fraudChallengeDefeatTimeout = 7 days;
290
+ self.fraudSlashingAmount = 100 * 1e18; // 100 T
291
+ self.fraudNotifierRewardMultiplier = 100; // 100%
292
+ self.walletCreationPeriod = 1 weeks;
293
+ self.walletCreationMinBtcBalance = 1e8; // 1 BTC
294
+ self.walletCreationMaxBtcBalance = 100e8; // 100 BTC
295
+ self.walletClosureMinBtcBalance = 5 * 1e7; // 0.5 BTC
296
+ self.walletMaxAge = 26 weeks; // ~6 months
297
+ self.walletMaxBtcTransfer = 10e8; // 10 BTC
298
+ self.walletClosingPeriod = 40 days;
299
+
300
+ _transferGovernance(msg.sender);
301
+ }
302
+
303
+ /// @notice Used by the depositor to reveal information about their P2(W)SH
304
+ /// Bitcoin deposit to the Bridge on Ethereum chain. The off-chain
305
+ /// wallet listens for revealed deposit events and may decide to
306
+ /// include the revealed deposit in the next executed sweep.
307
+ /// Information about the Bitcoin deposit can be revealed before or
308
+ /// after the Bitcoin transaction with P2(W)SH deposit is mined on
309
+ /// the Bitcoin chain. Worth noting, the gas cost of this function
310
+ /// scales with the number of P2(W)SH transaction inputs and
311
+ /// outputs. The deposit may be routed to one of the trusted vaults.
312
+ /// When a deposit is routed to a vault, vault gets notified when
313
+ /// the deposit gets swept and it may execute the appropriate action.
314
+ /// @param fundingTx Bitcoin funding transaction data, see `BitcoinTx.Info`.
315
+ /// @param reveal Deposit reveal data, see `RevealInfo struct.
316
+ /// @dev Requirements:
317
+ /// - `reveal.walletPubKeyHash` must identify a `Live` wallet,
318
+ /// - `reveal.vault` must be 0x0 or point to a trusted vault,
319
+ /// - `reveal.fundingOutputIndex` must point to the actual P2(W)SH
320
+ /// output of the BTC deposit transaction,
321
+ /// - `reveal.depositor` must be the Ethereum address used in the
322
+ /// P2(W)SH BTC deposit transaction,
323
+ /// - `reveal.blindingFactor` must be the blinding factor used in the
324
+ /// P2(W)SH BTC deposit transaction,
325
+ /// - `reveal.walletPubKeyHash` must be the wallet pub key hash used in
326
+ /// the P2(W)SH BTC deposit transaction,
327
+ /// - `reveal.refundPubKeyHash` must be the refund pub key hash used in
328
+ /// the P2(W)SH BTC deposit transaction,
329
+ /// - `reveal.refundLocktime` must be the refund locktime used in the
330
+ /// P2(W)SH BTC deposit transaction,
331
+ /// - BTC deposit for the given `fundingTxHash`, `fundingOutputIndex`
332
+ /// can be revealed only one time.
333
+ ///
334
+ /// If any of these requirements is not met, the wallet _must_ refuse
335
+ /// to sweep the deposit and the depositor has to wait until the
336
+ /// deposit script unlocks to receive their BTC back.
337
+ function revealDeposit(
338
+ BitcoinTx.Info calldata fundingTx,
339
+ Deposit.DepositRevealInfo calldata reveal
340
+ ) external {
341
+ self.revealDeposit(fundingTx, reveal);
342
+ }
343
+
344
+ /// @notice Used by the wallet to prove the BTC deposit sweep transaction
345
+ /// and to update Bank balances accordingly. Sweep is only accepted
346
+ /// if it satisfies SPV proof.
347
+ ///
348
+ /// The function is performing Bank balance updates by first
349
+ /// computing the Bitcoin fee for the sweep transaction. The fee is
350
+ /// divided evenly between all swept deposits. Each depositor
351
+ /// receives a balance in the bank equal to the amount inferred
352
+ /// during the reveal transaction, minus their fee share.
353
+ ///
354
+ /// It is possible to prove the given sweep only one time.
355
+ /// @param sweepTx Bitcoin sweep transaction data.
356
+ /// @param sweepProof Bitcoin sweep proof data.
357
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
358
+ /// the Ethereum chain. If no main UTXO exists for the given wallet,
359
+ /// this parameter is ignored.
360
+ /// @param vault Optional address of the vault where all swept deposits
361
+ /// should be routed to. All deposits swept as part of the transaction
362
+ /// must have their `vault` parameters set to the same address.
363
+ /// If this parameter is set to an address of a trusted vault, swept
364
+ /// deposits are routed to that vault.
365
+ /// If this parameter is set to the zero address or to an address
366
+ /// of a non-trusted vault, swept deposits are not routed to a
367
+ /// vault but depositors' balances are increased in the Bank
368
+ /// individually.
369
+ /// @dev Requirements:
370
+ /// - `sweepTx` components must match the expected structure. See
371
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
372
+ /// correspond to appropriate Bitcoin transaction fields to produce
373
+ /// a provable transaction hash,
374
+ /// - The `sweepTx` should represent a Bitcoin transaction with 1..n
375
+ /// inputs. If the wallet has no main UTXO, all n inputs should
376
+ /// correspond to P2(W)SH revealed deposits UTXOs. If the wallet has
377
+ /// an existing main UTXO, one of the n inputs must point to that
378
+ /// main UTXO and remaining n-1 inputs should correspond to P2(W)SH
379
+ /// revealed deposits UTXOs. That transaction must have only
380
+ /// one P2(W)PKH output locking funds on the 20-byte wallet public
381
+ /// key hash,
382
+ /// - All revealed deposits that are swept by `sweepTx` must have
383
+ /// their `vault` parameters set to the same address as the address
384
+ /// passed in the `vault` function parameter,
385
+ /// - `sweepProof` components must match the expected structure. See
386
+ /// `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
387
+ /// field must contain a valid number of block headers, not less
388
+ /// than the `txProofDifficultyFactor` contract constant,
389
+ /// - `mainUtxo` components must point to the recent main UTXO
390
+ /// of the given wallet, as currently known on the Ethereum chain.
391
+ /// If there is no main UTXO, this parameter is ignored.
392
+ function submitDepositSweepProof(
393
+ BitcoinTx.Info calldata sweepTx,
394
+ BitcoinTx.Proof calldata sweepProof,
395
+ BitcoinTx.UTXO calldata mainUtxo,
396
+ address vault
397
+ ) external {
398
+ self.submitDepositSweepProof(sweepTx, sweepProof, mainUtxo, vault);
399
+ }
400
+
401
+ /// @notice Requests redemption of the given amount from the specified
402
+ /// wallet to the redeemer Bitcoin output script. Handles the
403
+ /// simplest case in which the redeemer's balance is decreased in
404
+ /// the Bank.
405
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
406
+ /// using Bitcoin HASH160 over the compressed ECDSA public key).
407
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
408
+ /// the Ethereum chain.
409
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
410
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
411
+ /// redeemed BTC.
412
+ /// @param amount Requested amount in satoshi. This is also the Bank balance
413
+ /// that is taken from the `balanceOwner` upon request.
414
+ /// Once the request is handled, the actual amount of BTC locked
415
+ /// on the redeemer output script will be always lower than this value
416
+ /// since the treasury and Bitcoin transaction fees must be incurred.
417
+ /// The minimal amount satisfying the request can be computed as:
418
+ /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
419
+ /// Fees values are taken at the moment of request creation.
420
+ /// @dev Requirements:
421
+ /// - Wallet behind `walletPubKeyHash` must be live,
422
+ /// - `mainUtxo` components must point to the recent main UTXO
423
+ /// of the given wallet, as currently known on the Ethereum chain,
424
+ /// - `redeemerOutputScript` must be a proper Bitcoin script,
425
+ /// - `redeemerOutputScript` cannot have wallet PKH as payload,
426
+ /// - `amount` must be above or equal the `redemptionDustThreshold`,
427
+ /// - Given `walletPubKeyHash` and `redeemerOutputScript` pair can be
428
+ /// used for only one pending request at the same time,
429
+ /// - Wallet must have enough Bitcoin balance to process the request,
430
+ /// - Redeemer must make an allowance in the Bank that the Bridge
431
+ /// contract can spend the given `amount`.
432
+ function requestRedemption(
433
+ bytes20 walletPubKeyHash,
434
+ BitcoinTx.UTXO calldata mainUtxo,
435
+ bytes calldata redeemerOutputScript,
436
+ uint64 amount
437
+ ) external {
438
+ self.requestRedemption(
439
+ walletPubKeyHash,
440
+ mainUtxo,
441
+ msg.sender,
442
+ redeemerOutputScript,
443
+ amount
444
+ );
445
+ }
446
+
447
+ /// @notice Requests redemption of the given amount from the specified
448
+ /// wallet to the redeemer Bitcoin output script. Used by
449
+ /// `Bank.approveBalanceAndCall`. Can handle more complex cases
450
+ /// where balance owner may be someone else than the redeemer.
451
+ /// For example, vault redeeming its balance for some depositor.
452
+ /// @param balanceOwner The address of the Bank balance owner whose balance
453
+ /// is getting redeemed.
454
+ /// @param amount Requested amount in satoshi. This is also the Bank balance
455
+ /// that is taken from the `balanceOwner` upon request.
456
+ /// Once the request is handled, the actual amount of BTC locked
457
+ /// on the redeemer output script will be always lower than this value
458
+ /// since the treasury and Bitcoin transaction fees must be incurred.
459
+ /// The minimal amount satisfying the request can be computed as:
460
+ /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
461
+ /// Fees values are taken at the moment of request creation.
462
+ /// @param redemptionData ABI-encoded redemption data:
463
+ /// [
464
+ /// address redeemer,
465
+ /// bytes20 walletPubKeyHash,
466
+ /// bytes32 mainUtxoTxHash,
467
+ /// uint32 mainUtxoTxOutputIndex,
468
+ /// uint64 mainUtxoTxOutputValue,
469
+ /// bytes redeemerOutputScript
470
+ /// ]
471
+ ///
472
+ /// - redeemer: The Ethereum address of the redeemer who will be able
473
+ /// to claim Bank balance if anything goes wrong during the redemption.
474
+ /// In the most basic case, when someone redeems their balance
475
+ /// from the Bank, `balanceOwner` is the same as `redemeer`.
476
+ /// However, when a Vault is redeeming part of its balance for some
477
+ /// redeemer address (for example, someone who has earlier deposited
478
+ /// into that Vault), `balanceOwner` is the Vault, and `redemeer` is
479
+ /// the address for which the vault is redeeming its balance to,
480
+ /// - walletPubKeyHash: The 20-byte wallet public key hash (computed
481
+ /// using Bitcoin HASH160 over the compressed ECDSA public key),
482
+ /// - mainUtxoTxHash: Data of the wallet's main UTXO TX hash, as
483
+ /// currently known on the Ethereum chain,
484
+ /// - mainUtxoTxOutputIndex: Data of the wallet's main UTXO output
485
+ /// index, as currently known on Ethereum chain,
486
+ /// - mainUtxoTxOutputValue: Data of the wallet's main UTXO output
487
+ /// value, as currently known on Ethereum chain,
488
+ /// - redeemerOutputScript The redeemer's length-prefixed output
489
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
490
+ /// redeemed BTC.
491
+ /// @dev Requirements:
492
+ /// - The caller must be the Bank,
493
+ /// - Wallet behind `walletPubKeyHash` must be live,
494
+ /// - `mainUtxo` components must point to the recent main UTXO
495
+ /// of the given wallet, as currently known on the Ethereum chain,
496
+ /// - `redeemerOutputScript` must be a proper Bitcoin script,
497
+ /// - `redeemerOutputScript` cannot have wallet PKH as payload,
498
+ /// - `amount` must be above or equal the `redemptionDustThreshold`,
499
+ /// - Given `walletPubKeyHash` and `redeemerOutputScript` pair can be
500
+ /// used for only one pending request at the same time,
501
+ /// - Wallet must have enough Bitcoin balance to process the request.
502
+ ///
503
+ /// Note on upgradeability:
504
+ /// Bridge is an upgradeable contract deployed behind
505
+ /// a TransparentUpgradeableProxy. Accepting redemption data as bytes
506
+ /// provides great flexibility. The Bridge is just like any other
507
+ /// contract with a balance approved in the Bank and can be upgraded
508
+ /// to another version without being bound to a particular interface
509
+ /// forever. This flexibility comes with the cost - developers
510
+ /// integrating their vaults and dApps with `Bridge` using
511
+ /// `approveBalanceAndCall` need to pay extra attention to
512
+ /// `redemptionData` and adjust the code in case the expected structure
513
+ /// of `redemptionData` changes.
514
+ function receiveBalanceApproval(
515
+ address balanceOwner,
516
+ uint256 amount,
517
+ bytes calldata redemptionData
518
+ ) external override {
519
+ require(msg.sender == address(self.bank), "Caller is not the bank");
520
+
521
+ self.requestRedemption(
522
+ balanceOwner,
523
+ SafeCastUpgradeable.toUint64(amount),
524
+ redemptionData
525
+ );
526
+ }
527
+
528
+ /// @notice Used by the wallet to prove the BTC redemption transaction
529
+ /// and to make the necessary bookkeeping. Redemption is only
530
+ /// accepted if it satisfies SPV proof.
531
+ ///
532
+ /// The function is performing Bank balance updates by burning
533
+ /// the total redeemed Bitcoin amount from Bridge balance and
534
+ /// transferring the treasury fee sum to the treasury address.
535
+ ///
536
+ /// It is possible to prove the given redemption only one time.
537
+ /// @param redemptionTx Bitcoin redemption transaction data.
538
+ /// @param redemptionProof Bitcoin redemption proof data.
539
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
540
+ /// the Ethereum chain.
541
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
542
+ /// HASH160 over the compressed ECDSA public key) of the wallet which
543
+ /// performed the redemption transaction.
544
+ /// @dev Requirements:
545
+ /// - `redemptionTx` components must match the expected structure. See
546
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
547
+ /// correspond to appropriate Bitcoin transaction fields to produce
548
+ /// a provable transaction hash,
549
+ /// - The `redemptionTx` should represent a Bitcoin transaction with
550
+ /// exactly 1 input that refers to the wallet's main UTXO. That
551
+ /// transaction should have 1..n outputs handling existing pending
552
+ /// redemption requests or pointing to reported timed out requests.
553
+ /// There can be also 1 optional output representing the
554
+ /// change and pointing back to the 20-byte wallet public key hash.
555
+ /// The change should be always present if the redeemed value sum
556
+ /// is lower than the total wallet's BTC balance,
557
+ /// - `redemptionProof` components must match the expected structure.
558
+ /// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
559
+ /// field must contain a valid number of block headers, not less
560
+ /// than the `txProofDifficultyFactor` contract constant,
561
+ /// - `mainUtxo` components must point to the recent main UTXO
562
+ /// of the given wallet, as currently known on the Ethereum chain.
563
+ /// Additionally, the recent main UTXO on Ethereum must be set,
564
+ /// - `walletPubKeyHash` must be connected with the main UTXO used
565
+ /// as transaction single input.
566
+ /// Other remarks:
567
+ /// - Putting the change output as the first transaction output can
568
+ /// save some gas because the output processing loop begins each
569
+ /// iteration by checking whether the given output is the change
570
+ /// thus uses some gas for making the comparison. Once the change
571
+ /// is identified, that check is omitted in further iterations.
572
+ function submitRedemptionProof(
573
+ BitcoinTx.Info calldata redemptionTx,
574
+ BitcoinTx.Proof calldata redemptionProof,
575
+ BitcoinTx.UTXO calldata mainUtxo,
576
+ bytes20 walletPubKeyHash
577
+ ) external {
578
+ self.submitRedemptionProof(
579
+ redemptionTx,
580
+ redemptionProof,
581
+ mainUtxo,
582
+ walletPubKeyHash
583
+ );
584
+ }
585
+
586
+ /// @notice Notifies that there is a pending redemption request associated
587
+ /// with the given wallet, that has timed out. The redemption
588
+ /// request is identified by the key built as
589
+ /// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
590
+ /// The results of calling this function:
591
+ /// - The pending redemptions value for the wallet will be decreased
592
+ /// by the requested amount (minus treasury fee),
593
+ /// - The tokens taken from the redeemer on redemption request will
594
+ /// be returned to the redeemer,
595
+ /// - The request will be moved from pending redemptions to
596
+ /// timed-out redemptions,
597
+ /// - If the state of the wallet is `Live` or `MovingFunds`, the
598
+ /// wallet operators will be slashed and the notifier will be
599
+ /// rewarded,
600
+ /// - If the state of wallet is `Live`, the wallet will be closed or
601
+ /// marked as `MovingFunds` (depending on the presence or absence
602
+ /// of the wallet's main UTXO) and the wallet will no longer be
603
+ /// marked as the active wallet (if it was marked as such).
604
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet.
605
+ /// @param walletMembersIDs Identifiers of the wallet signing group members.
606
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
607
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH).
608
+ /// @dev Requirements:
609
+ /// - The wallet must be in the Live or MovingFunds or Terminated state,
610
+ /// - The redemption request identified by `walletPubKeyHash` and
611
+ /// `redeemerOutputScript` must exist,
612
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
613
+ /// be exactly the same as the hash stored under `membersIdsHash`
614
+ /// for the given `walletID`. Those IDs are not directly stored
615
+ /// in the contract for gas efficiency purposes but they can be
616
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
617
+ /// events of the `WalletRegistry` contract,
618
+ /// - The amount of time defined by `redemptionTimeout` must have
619
+ /// passed since the redemption was requested (the request must be
620
+ /// timed-out).
621
+ function notifyRedemptionTimeout(
622
+ bytes20 walletPubKeyHash,
623
+ uint32[] calldata walletMembersIDs,
624
+ bytes calldata redeemerOutputScript
625
+ ) external {
626
+ self.notifyRedemptionTimeout(
627
+ walletPubKeyHash,
628
+ walletMembersIDs,
629
+ redeemerOutputScript
630
+ );
631
+ }
632
+
633
+ /// @notice Submits the moving funds target wallets commitment.
634
+ /// Once all requirements are met, that function registers the
635
+ /// target wallets commitment and opens the way for moving funds
636
+ /// proof submission.
637
+ /// @param walletPubKeyHash 20-byte public key hash of the source wallet.
638
+ /// @param walletMainUtxo Data of the source wallet's main UTXO, as
639
+ /// currently known on the Ethereum chain.
640
+ /// @param walletMembersIDs Identifiers of the source wallet signing group
641
+ /// members.
642
+ /// @param walletMemberIndex Position of the caller in the source wallet
643
+ /// signing group members list.
644
+ /// @param targetWallets List of 20-byte public key hashes of the target
645
+ /// wallets that the source wallet commits to move the funds to.
646
+ /// @dev Requirements:
647
+ /// - The source wallet must be in the MovingFunds state,
648
+ /// - The source wallet must not have pending redemption requests,
649
+ /// - The source wallet must not have pending moved funds sweep requests,
650
+ /// - The source wallet must not have submitted its commitment already,
651
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
652
+ /// be exactly the same as the hash stored under `membersIdsHash`
653
+ /// for the given source wallet in the ECDSA registry. Those IDs are
654
+ /// not directly stored in the contract for gas efficiency purposes
655
+ /// but they can be read from appropriate `DkgResultSubmitted`
656
+ /// and `DkgResultApproved` events,
657
+ /// - The `walletMemberIndex` must be in range [1, walletMembersIDs.length],
658
+ /// - The caller must be the member of the source wallet signing group
659
+ /// at the position indicated by `walletMemberIndex` parameter,
660
+ /// - The `walletMainUtxo` components must point to the recent main
661
+ /// UTXO of the source wallet, as currently known on the Ethereum
662
+ /// chain,
663
+ /// - Source wallet BTC balance must be greater than zero,
664
+ /// - At least one Live wallet must exist in the system,
665
+ /// - Submitted target wallets count must match the expected count
666
+ /// `N = min(liveWalletsCount, ceil(walletBtcBalance / walletMaxBtcTransfer))`
667
+ /// where `N > 0`,
668
+ /// - Each target wallet must be not equal to the source wallet,
669
+ /// - Each target wallet must follow the expected order i.e. all
670
+ /// target wallets 20-byte public key hashes represented as numbers
671
+ /// must form a strictly increasing sequence without duplicates,
672
+ /// - Each target wallet must be in Live state.
673
+ function submitMovingFundsCommitment(
674
+ bytes20 walletPubKeyHash,
675
+ BitcoinTx.UTXO calldata walletMainUtxo,
676
+ uint32[] calldata walletMembersIDs,
677
+ uint256 walletMemberIndex,
678
+ bytes20[] calldata targetWallets
679
+ ) external {
680
+ self.submitMovingFundsCommitment(
681
+ walletPubKeyHash,
682
+ walletMainUtxo,
683
+ walletMembersIDs,
684
+ walletMemberIndex,
685
+ targetWallets
686
+ );
687
+ }
688
+
689
+ /// @notice Resets the moving funds timeout for the given wallet if the
690
+ /// target wallet commitment cannot be submitted due to a lack
691
+ /// of live wallets in the system.
692
+ /// @param walletPubKeyHash 20-byte public key hash of the moving funds wallet.
693
+ /// @dev Requirements:
694
+ /// - The wallet must be in the MovingFunds state,
695
+ /// - The target wallets commitment must not be already submitted for
696
+ /// the given moving funds wallet,
697
+ /// - Live wallets count must be zero,
698
+ /// - The moving funds timeout reset delay must be elapsed.
699
+ function resetMovingFundsTimeout(bytes20 walletPubKeyHash) external {
700
+ self.resetMovingFundsTimeout(walletPubKeyHash);
701
+ }
702
+
703
+ /// @notice Used by the wallet to prove the BTC moving funds transaction
704
+ /// and to make the necessary state changes. Moving funds is only
705
+ /// accepted if it satisfies SPV proof.
706
+ ///
707
+ /// The function validates the moving funds transaction structure
708
+ /// by checking if it actually spends the main UTXO of the declared
709
+ /// wallet and locks the value on the pre-committed target wallets
710
+ /// using a reasonable transaction fee. If all preconditions are
711
+ /// met, this functions closes the source wallet.
712
+ ///
713
+ /// It is possible to prove the given moving funds transaction only
714
+ /// one time.
715
+ /// @param movingFundsTx Bitcoin moving funds transaction data.
716
+ /// @param movingFundsProof Bitcoin moving funds proof data.
717
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
718
+ /// the Ethereum chain.
719
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
720
+ /// HASH160 over the compressed ECDSA public key) of the wallet
721
+ /// which performed the moving funds transaction.
722
+ /// @dev Requirements:
723
+ /// - `movingFundsTx` components must match the expected structure. See
724
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
725
+ /// correspond to appropriate Bitcoin transaction fields to produce
726
+ /// a provable transaction hash,
727
+ /// - The `movingFundsTx` should represent a Bitcoin transaction with
728
+ /// exactly 1 input that refers to the wallet's main UTXO. That
729
+ /// transaction should have 1..n outputs corresponding to the
730
+ /// pre-committed target wallets. Outputs must be ordered in the
731
+ /// same way as their corresponding target wallets are ordered
732
+ /// within the target wallets commitment,
733
+ /// - `movingFundsProof` components must match the expected structure.
734
+ /// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
735
+ /// field must contain a valid number of block headers, not less
736
+ /// than the `txProofDifficultyFactor` contract constant,
737
+ /// - `mainUtxo` components must point to the recent main UTXO
738
+ /// of the given wallet, as currently known on the Ethereum chain.
739
+ /// Additionally, the recent main UTXO on Ethereum must be set,
740
+ /// - `walletPubKeyHash` must be connected with the main UTXO used
741
+ /// as transaction single input,
742
+ /// - The wallet that `walletPubKeyHash` points to must be in the
743
+ /// MovingFunds state,
744
+ /// - The target wallets commitment must be submitted by the wallet
745
+ /// that `walletPubKeyHash` points to,
746
+ /// - The total Bitcoin transaction fee must be lesser or equal
747
+ /// to `movingFundsTxMaxTotalFee` governable parameter.
748
+ function submitMovingFundsProof(
749
+ BitcoinTx.Info calldata movingFundsTx,
750
+ BitcoinTx.Proof calldata movingFundsProof,
751
+ BitcoinTx.UTXO calldata mainUtxo,
752
+ bytes20 walletPubKeyHash
753
+ ) external {
754
+ self.submitMovingFundsProof(
755
+ movingFundsTx,
756
+ movingFundsProof,
757
+ mainUtxo,
758
+ walletPubKeyHash
759
+ );
760
+ }
761
+
762
+ /// @notice Notifies about a timed out moving funds process. Terminates
763
+ /// the wallet and slashes signing group members as a result.
764
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet.
765
+ /// @param walletMembersIDs Identifiers of the wallet signing group members.
766
+ /// @dev Requirements:
767
+ /// - The wallet must be in the MovingFunds state,
768
+ /// - The moving funds timeout must be actually exceeded,
769
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
770
+ /// be exactly the same as the hash stored under `membersIdsHash`
771
+ /// for the given `walletID`. Those IDs are not directly stored
772
+ /// in the contract for gas efficiency purposes but they can be
773
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
774
+ /// events of the `WalletRegistry` contract.
775
+ function notifyMovingFundsTimeout(
776
+ bytes20 walletPubKeyHash,
777
+ uint32[] calldata walletMembersIDs
778
+ ) external {
779
+ self.notifyMovingFundsTimeout(walletPubKeyHash, walletMembersIDs);
780
+ }
781
+
782
+ /// @notice Notifies about a moving funds wallet whose BTC balance is
783
+ /// below the moving funds dust threshold. Ends the moving funds
784
+ /// process and begins wallet closing immediately.
785
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
786
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known
787
+ /// on the Ethereum chain.
788
+ /// @dev Requirements:
789
+ /// - The wallet must be in the MovingFunds state,
790
+ /// - The `mainUtxo` components must point to the recent main UTXO
791
+ /// of the given wallet, as currently known on the Ethereum chain.
792
+ /// If the wallet has no main UTXO, this parameter can be empty as it
793
+ /// is ignored,
794
+ /// - The wallet BTC balance must be below the moving funds threshold.
795
+ function notifyMovingFundsBelowDust(
796
+ bytes20 walletPubKeyHash,
797
+ BitcoinTx.UTXO calldata mainUtxo
798
+ ) external {
799
+ self.notifyMovingFundsBelowDust(walletPubKeyHash, mainUtxo);
800
+ }
801
+
802
+ /// @notice Used by the wallet to prove the BTC moved funds sweep
803
+ /// transaction and to make the necessary state changes. Moved
804
+ /// funds sweep is only accepted if it satisfies SPV proof.
805
+ ///
806
+ /// The function validates the sweep transaction structure by
807
+ /// checking if it actually spends the moved funds UTXO and the
808
+ /// sweeping wallet's main UTXO (optionally), and if it locks the
809
+ /// value on the sweeping wallet's 20-byte public key hash using a
810
+ /// reasonable transaction fee. If all preconditions are
811
+ /// met, this function updates the sweeping wallet main UTXO, thus
812
+ /// their BTC balance.
813
+ ///
814
+ /// It is possible to prove the given sweep transaction only
815
+ /// one time.
816
+ /// @param sweepTx Bitcoin sweep funds transaction data.
817
+ /// @param sweepProof Bitcoin sweep funds proof data.
818
+ /// @param mainUtxo Data of the sweeping wallet's main UTXO, as currently
819
+ /// known on the Ethereum chain.
820
+ /// @dev Requirements:
821
+ /// - `sweepTx` components must match the expected structure. See
822
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
823
+ /// correspond to appropriate Bitcoin transaction fields to produce
824
+ /// a provable transaction hash,
825
+ /// - The `sweepTx` should represent a Bitcoin transaction with
826
+ /// the first input pointing to a moved funds sweep request targeted
827
+ /// to the wallet, and optionally, the second input pointing to the
828
+ /// wallet's main UTXO, if the sweeping wallet has a main UTXO set.
829
+ /// There should be only one output locking funds on the sweeping
830
+ /// wallet 20-byte public key hash,
831
+ /// - `sweepProof` components must match the expected structure.
832
+ /// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
833
+ /// field must contain a valid number of block headers, not less
834
+ /// than the `txProofDifficultyFactor` contract constant,
835
+ /// - `mainUtxo` components must point to the recent main UTXO
836
+ /// of the sweeping wallet, as currently known on the Ethereum chain.
837
+ /// If there is no main UTXO, this parameter is ignored,
838
+ /// - The sweeping wallet must be in the Live or MovingFunds state,
839
+ /// - The total Bitcoin transaction fee must be lesser or equal
840
+ /// to `movedFundsSweepTxMaxTotalFee` governable parameter.
841
+ function submitMovedFundsSweepProof(
842
+ BitcoinTx.Info calldata sweepTx,
843
+ BitcoinTx.Proof calldata sweepProof,
844
+ BitcoinTx.UTXO calldata mainUtxo
845
+ ) external {
846
+ self.submitMovedFundsSweepProof(sweepTx, sweepProof, mainUtxo);
847
+ }
848
+
849
+ /// @notice Notifies about a timed out moved funds sweep process. If the
850
+ /// wallet is not terminated yet, that function terminates
851
+ /// the wallet and slashes signing group members as a result.
852
+ /// Marks the given sweep request as TimedOut.
853
+ /// @param movingFundsTxHash 32-byte hash of the moving funds transaction
854
+ /// that caused the sweep request to be created.
855
+ /// @param movingFundsTxOutputIndex Index of the moving funds transaction
856
+ /// output that is subject of the sweep request.
857
+ /// @param walletMembersIDs Identifiers of the wallet signing group members.
858
+ /// @dev Requirements:
859
+ /// - The moved funds sweep request must be in the Pending state,
860
+ /// - The moved funds sweep timeout must be actually exceeded,
861
+ /// - The wallet must be either in the Live or MovingFunds or
862
+ /// Terminated state,
863
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
864
+ /// be exactly the same as the hash stored under `membersIdsHash`
865
+ /// for the given `walletID`. Those IDs are not directly stored
866
+ /// in the contract for gas efficiency purposes but they can be
867
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
868
+ /// events of the `WalletRegistry` contract.
869
+ function notifyMovedFundsSweepTimeout(
870
+ bytes32 movingFundsTxHash,
871
+ uint32 movingFundsTxOutputIndex,
872
+ uint32[] calldata walletMembersIDs
873
+ ) external {
874
+ self.notifyMovedFundsSweepTimeout(
875
+ movingFundsTxHash,
876
+ movingFundsTxOutputIndex,
877
+ walletMembersIDs
878
+ );
879
+ }
880
+
881
+ /// @notice Requests creation of a new wallet. This function just
882
+ /// forms a request and the creation process is performed
883
+ /// asynchronously. Once a wallet is created, the ECDSA Wallet
884
+ /// Registry will notify this contract by calling the
885
+ /// `__ecdsaWalletCreatedCallback` function.
886
+ /// @param activeWalletMainUtxo Data of the active wallet's main UTXO, as
887
+ /// currently known on the Ethereum chain.
888
+ /// @dev Requirements:
889
+ /// - `activeWalletMainUtxo` components must point to the recent main
890
+ /// UTXO of the given active wallet, as currently known on the
891
+ /// Ethereum chain. If there is no active wallet at the moment, or
892
+ /// the active wallet has no main UTXO, this parameter can be
893
+ /// empty as it is ignored,
894
+ /// - Wallet creation must not be in progress,
895
+ /// - If the active wallet is set, one of the following
896
+ /// conditions must be true:
897
+ /// - The active wallet BTC balance is above the minimum threshold
898
+ /// and the active wallet is old enough, i.e. the creation period
899
+ /// was elapsed since its creation time,
900
+ /// - The active wallet BTC balance is above the maximum threshold.
901
+ function requestNewWallet(BitcoinTx.UTXO calldata activeWalletMainUtxo)
902
+ external
903
+ {
904
+ self.requestNewWallet(activeWalletMainUtxo);
905
+ }
906
+
907
+ /// @notice A callback function that is called by the ECDSA Wallet Registry
908
+ /// once a new ECDSA wallet is created.
909
+ /// @param ecdsaWalletID Wallet's unique identifier.
910
+ /// @param publicKeyX Wallet's public key's X coordinate.
911
+ /// @param publicKeyY Wallet's public key's Y coordinate.
912
+ /// @dev Requirements:
913
+ /// - The only caller authorized to call this function is `registry`,
914
+ /// - Given wallet data must not belong to an already registered wallet.
915
+ function __ecdsaWalletCreatedCallback(
916
+ bytes32 ecdsaWalletID,
917
+ bytes32 publicKeyX,
918
+ bytes32 publicKeyY
919
+ ) external override {
920
+ self.registerNewWallet(ecdsaWalletID, publicKeyX, publicKeyY);
921
+ }
922
+
923
+ /// @notice A callback function that is called by the ECDSA Wallet Registry
924
+ /// once a wallet heartbeat failure is detected.
925
+ /// @param publicKeyX Wallet's public key's X coordinate.
926
+ /// @param publicKeyY Wallet's public key's Y coordinate.
927
+ /// @dev Requirements:
928
+ /// - The only caller authorized to call this function is `registry`,
929
+ /// - Wallet must be in Live state.
930
+ function __ecdsaWalletHeartbeatFailedCallback(
931
+ bytes32,
932
+ bytes32 publicKeyX,
933
+ bytes32 publicKeyY
934
+ ) external override {
935
+ self.notifyWalletHeartbeatFailed(publicKeyX, publicKeyY);
936
+ }
937
+
938
+ /// @notice Notifies that the wallet is either old enough or has too few
939
+ /// satoshi left and qualifies to be closed.
940
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet.
941
+ /// @param walletMainUtxo Data of the wallet's main UTXO, as currently
942
+ /// known on the Ethereum chain.
943
+ /// @dev Requirements:
944
+ /// - Wallet must not be set as the current active wallet,
945
+ /// - Wallet must exceed the wallet maximum age OR the wallet BTC
946
+ /// balance must be lesser than the minimum threshold. If the latter
947
+ /// case is true, the `walletMainUtxo` components must point to the
948
+ /// recent main UTXO of the given wallet, as currently known on the
949
+ /// Ethereum chain. If the wallet has no main UTXO, this parameter
950
+ /// can be empty as it is ignored since the wallet balance is
951
+ /// assumed to be zero,
952
+ /// - Wallet must be in Live state.
953
+ function notifyWalletCloseable(
954
+ bytes20 walletPubKeyHash,
955
+ BitcoinTx.UTXO calldata walletMainUtxo
956
+ ) external {
957
+ self.notifyWalletCloseable(walletPubKeyHash, walletMainUtxo);
958
+ }
959
+
960
+ /// @notice Notifies about the end of the closing period for the given wallet.
961
+ /// Closes the wallet ultimately and notifies the ECDSA registry
962
+ /// about this fact.
963
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet.
964
+ /// @dev Requirements:
965
+ /// - The wallet must be in the Closing state,
966
+ /// - The wallet closing period must have elapsed.
967
+ function notifyWalletClosingPeriodElapsed(bytes20 walletPubKeyHash)
968
+ external
969
+ {
970
+ self.notifyWalletClosingPeriodElapsed(walletPubKeyHash);
971
+ }
972
+
973
+ /// @notice Submits a fraud challenge indicating that a UTXO being under
974
+ /// wallet control was unlocked by the wallet but was not used
975
+ /// according to the protocol rules. That means the wallet signed
976
+ /// a transaction input pointing to that UTXO and there is a unique
977
+ /// sighash and signature pair associated with that input. This
978
+ /// function uses those parameters to create a fraud accusation that
979
+ /// proves a given transaction input unlocking the given UTXO was
980
+ /// actually signed by the wallet. This function cannot determine
981
+ /// whether the transaction was actually broadcast and the input was
982
+ /// consumed in a fraudulent way so it just opens a challenge period
983
+ /// during which the wallet can defeat the challenge by submitting
984
+ /// proof of a transaction that consumes the given input according
985
+ /// to protocol rules. To prevent spurious allegations, the caller
986
+ /// must deposit ETH that is returned back upon justified fraud
987
+ /// challenge or confiscated otherwise.
988
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
989
+ /// and unprefixed format (64 bytes).
990
+ /// @param preimageSha256 The hash that was generated by applying SHA-256
991
+ /// one time over the preimage used during input signing. The preimage
992
+ /// is a serialized subset of the transaction and its structure
993
+ /// depends on the transaction input (see BIP-143 for reference).
994
+ /// Notice that applying SHA-256 over the `preimageSha256` results
995
+ /// in `sighash`. The path from `preimage` to `sighash` looks like
996
+ /// this:
997
+ /// preimage -> (SHA-256) -> preimageSha256 -> (SHA-256) -> sighash.
998
+ /// @param signature Bitcoin signature in the R/S/V format.
999
+ /// @dev Requirements:
1000
+ /// - Wallet behind `walletPublicKey` must be in Live or MovingFunds
1001
+ /// or Closing state,
1002
+ /// - The challenger must send appropriate amount of ETH used as
1003
+ /// fraud challenge deposit,
1004
+ /// - The signature (represented by r, s and v) must be generated by
1005
+ /// the wallet behind `walletPubKey` during signing of `sighash`
1006
+ /// which was calculated from `preimageSha256`,
1007
+ /// - Wallet can be challenged for the given signature only once.
1008
+ function submitFraudChallenge(
1009
+ bytes calldata walletPublicKey,
1010
+ bytes memory preimageSha256,
1011
+ BitcoinTx.RSVSignature calldata signature
1012
+ ) external payable {
1013
+ self.submitFraudChallenge(walletPublicKey, preimageSha256, signature);
1014
+ }
1015
+
1016
+ /// @notice Allows to defeat a pending fraud challenge against a wallet if
1017
+ /// the transaction that spends the UTXO follows the protocol rules.
1018
+ /// In order to defeat the challenge the same `walletPublicKey` and
1019
+ /// signature (represented by `r`, `s` and `v`) must be provided as
1020
+ /// were used to calculate the sighash during input signing.
1021
+ /// The fraud challenge defeat attempt will only succeed if the
1022
+ /// inputs in the preimage are considered honestly spent by the
1023
+ /// wallet. Therefore the transaction spending the UTXO must be
1024
+ /// proven in the Bridge before a challenge defeat is called.
1025
+ /// If successfully defeated, the fraud challenge is marked as
1026
+ /// resolved and the amount of ether deposited by the challenger is
1027
+ /// sent to the treasury.
1028
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
1029
+ /// and unprefixed format (64 bytes).
1030
+ /// @param preimage The preimage which produces sighash used to generate the
1031
+ /// ECDSA signature that is the subject of the fraud claim. It is a
1032
+ /// serialized subset of the transaction. The exact subset used as
1033
+ /// the preimage depends on the transaction input the signature is
1034
+ /// produced for. See BIP-143 for reference.
1035
+ /// @param witness Flag indicating whether the preimage was produced for a
1036
+ /// witness input. True for witness, false for non-witness input.
1037
+ /// @dev Requirements:
1038
+ /// - `walletPublicKey` and `sighash` calculated as `hash256(preimage)`
1039
+ /// must identify an open fraud challenge,
1040
+ /// - the preimage must be a valid preimage of a transaction generated
1041
+ /// according to the protocol rules and already proved in the Bridge,
1042
+ /// - before a defeat attempt is made the transaction that spends the
1043
+ /// given UTXO must be proven in the Bridge.
1044
+ function defeatFraudChallenge(
1045
+ bytes calldata walletPublicKey,
1046
+ bytes calldata preimage,
1047
+ bool witness
1048
+ ) external {
1049
+ self.defeatFraudChallenge(walletPublicKey, preimage, witness);
1050
+ }
1051
+
1052
+ /// @notice Allows to defeat a pending fraud challenge against a wallet by
1053
+ /// proving the sighash and signature were produced for an off-chain
1054
+ /// wallet heartbeat message following a strict format.
1055
+ /// In order to defeat the challenge the same `walletPublicKey` and
1056
+ /// signature (represented by `r`, `s` and `v`) must be provided as
1057
+ /// were used to calculate the sighash during heartbeat message
1058
+ /// signing. The fraud challenge defeat attempt will only succeed if
1059
+ /// the signed message follows a strict format required for
1060
+ /// heartbeat messages. If successfully defeated, the fraud
1061
+ /// challenge is marked as resolved and the amount of ether
1062
+ /// deposited by the challenger is sent to the treasury.
1063
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
1064
+ /// and unprefixed format (64 bytes).
1065
+ /// @param heartbeatMessage Off-chain heartbeat message meeting the heartbeat
1066
+ /// message format requirements which produces sighash used to
1067
+ /// generate the ECDSA signature that is the subject of the fraud
1068
+ /// claim.
1069
+ /// @dev Requirements:
1070
+ /// - `walletPublicKey` and `sighash` calculated as
1071
+ /// `hash256(heartbeatMessage)` must identify an open fraud challenge,
1072
+ /// - `heartbeatMessage` must follow a strict format of heartbeat
1073
+ /// messages.
1074
+ function defeatFraudChallengeWithHeartbeat(
1075
+ bytes calldata walletPublicKey,
1076
+ bytes calldata heartbeatMessage
1077
+ ) external {
1078
+ self.defeatFraudChallengeWithHeartbeat(
1079
+ walletPublicKey,
1080
+ heartbeatMessage
1081
+ );
1082
+ }
1083
+
1084
+ /// @notice Notifies about defeat timeout for the given fraud challenge.
1085
+ /// Can be called only if there was a fraud challenge identified by
1086
+ /// the provided `walletPublicKey` and `sighash` and it was not
1087
+ /// defeated on time. The amount of time that needs to pass after
1088
+ /// a fraud challenge is reported is indicated by the
1089
+ /// `challengeDefeatTimeout`. After a successful fraud challenge
1090
+ /// defeat timeout notification the fraud challenge is marked as
1091
+ /// resolved, the stake of each operator is slashed, the ether
1092
+ /// deposited is returned to the challenger and the challenger is
1093
+ /// rewarded.
1094
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
1095
+ /// and unprefixed format (64 bytes).
1096
+ /// @param walletMembersIDs Identifiers of the wallet signing group members.
1097
+ /// @param preimageSha256 The hash that was generated by applying SHA-256
1098
+ /// one time over the preimage used during input signing. The preimage
1099
+ /// is a serialized subset of the transaction and its structure
1100
+ /// depends on the transaction input (see BIP-143 for reference).
1101
+ /// Notice that applying SHA-256 over the `preimageSha256` results
1102
+ /// in `sighash`. The path from `preimage` to `sighash` looks like
1103
+ /// this:
1104
+ /// preimage -> (SHA-256) -> preimageSha256 -> (SHA-256) -> sighash.
1105
+ /// @dev Requirements:
1106
+ /// - The wallet must be in the Live or MovingFunds or Closing or
1107
+ /// Terminated state,
1108
+ /// - The `walletPublicKey` and `sighash` calculated from
1109
+ /// `preimageSha256` must identify an open fraud challenge,
1110
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
1111
+ /// be exactly the same as the hash stored under `membersIdsHash`
1112
+ /// for the given `walletID`. Those IDs are not directly stored
1113
+ /// in the contract for gas efficiency purposes but they can be
1114
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
1115
+ /// events of the `WalletRegistry` contract,
1116
+ /// - The amount of time indicated by `challengeDefeatTimeout` must pass
1117
+ /// after the challenge was reported.
1118
+ function notifyFraudChallengeDefeatTimeout(
1119
+ bytes calldata walletPublicKey,
1120
+ uint32[] calldata walletMembersIDs,
1121
+ bytes memory preimageSha256
1122
+ ) external {
1123
+ self.notifyFraudChallengeDefeatTimeout(
1124
+ walletPublicKey,
1125
+ walletMembersIDs,
1126
+ preimageSha256
1127
+ );
1128
+ }
1129
+
1130
+ /// @notice Allows the Governance to mark the given vault address as trusted
1131
+ /// or no longer trusted. Vaults are not trusted by default.
1132
+ /// Trusted vault must meet the following criteria:
1133
+ /// - `IVault.receiveBalanceIncrease` must have a known, low gas
1134
+ /// cost,
1135
+ /// - `IVault.receiveBalanceIncrease` must never revert.
1136
+ /// @dev Without restricting reveal only to trusted vaults, malicious
1137
+ /// vaults not meeting the criteria would be able to nuke sweep proof
1138
+ /// transactions executed by ECDSA wallet with deposits routed to
1139
+ /// them.
1140
+ /// @param vault The address of the vault.
1141
+ /// @param isTrusted flag indicating whether the vault is trusted or not.
1142
+ /// @dev Can only be called by the Governance.
1143
+ function setVaultStatus(address vault, bool isTrusted)
1144
+ external
1145
+ onlyGovernance
1146
+ {
1147
+ self.isVaultTrusted[vault] = isTrusted;
1148
+ emit VaultStatusUpdated(vault, isTrusted);
1149
+ }
1150
+
1151
+ /// @notice Updates parameters of deposits.
1152
+ /// @param depositDustThreshold New value of the deposit dust threshold in
1153
+ /// satoshis. It is the minimal amount that can be requested to
1154
+ //// deposit. Value of this parameter must take into account the value
1155
+ /// of `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters
1156
+ /// in order to make requests that can incur the treasury and
1157
+ /// transaction fee and still satisfy the depositor.
1158
+ /// @param depositTreasuryFeeDivisor New value of the treasury fee divisor.
1159
+ /// It is the divisor used to compute the treasury fee taken from
1160
+ /// each deposit and transferred to the treasury upon sweep proof
1161
+ /// submission. That fee is computed as follows:
1162
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
1163
+ /// For example, if the treasury fee needs to be 2% of each deposit,
1164
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
1165
+ /// because `1/50 = 0.02 = 2%`.
1166
+ /// @param depositTxMaxFee New value of the deposit tx max fee in satoshis.
1167
+ /// It is the maximum amount of BTC transaction fee that can
1168
+ /// be incurred by each swept deposit being part of the given sweep
1169
+ /// transaction. If the maximum BTC transaction fee is exceeded,
1170
+ /// such transaction is considered a fraud.
1171
+ /// @dev Requirements:
1172
+ /// - Deposit dust threshold must be greater than zero,
1173
+ /// - Deposit treasury fee divisor must be greater than zero,
1174
+ /// - Deposit transaction max fee must be greater than zero.
1175
+ function updateDepositParameters(
1176
+ uint64 depositDustThreshold,
1177
+ uint64 depositTreasuryFeeDivisor,
1178
+ uint64 depositTxMaxFee
1179
+ ) external onlyGovernance {
1180
+ self.updateDepositParameters(
1181
+ depositDustThreshold,
1182
+ depositTreasuryFeeDivisor,
1183
+ depositTxMaxFee
1184
+ );
1185
+ }
1186
+
1187
+ /// @notice Updates parameters of redemptions.
1188
+ /// @param redemptionDustThreshold New value of the redemption dust
1189
+ /// threshold in satoshis. It is the minimal amount that can be
1190
+ /// requested for redemption. Value of this parameter must take into
1191
+ /// account the value of `redemptionTreasuryFeeDivisor` and
1192
+ /// `redemptionTxMaxFee` parameters in order to make requests that
1193
+ /// can incur the treasury and transaction fee and still satisfy the
1194
+ /// redeemer.
1195
+ /// @param redemptionTreasuryFeeDivisor New value of the redemption
1196
+ /// treasury fee divisor. It is the divisor used to compute the
1197
+ /// treasury fee taken from each redemption request and transferred
1198
+ /// to the treasury upon successful request finalization. That fee is
1199
+ /// computed as follows:
1200
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
1201
+ /// For example, if the treasury fee needs to be 2% of each
1202
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
1203
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
1204
+ /// @param redemptionTxMaxFee New value of the redemption transaction max
1205
+ /// fee in satoshis. It is the maximum amount of BTC transaction fee
1206
+ /// that can be incurred by each redemption request being part of the
1207
+ /// given redemption transaction. If the maximum BTC transaction fee
1208
+ /// is exceeded, such transaction is considered a fraud.
1209
+ /// This is a per-redemption output max fee for the redemption
1210
+ /// transaction.
1211
+ /// @param redemptionTimeout New value of the redemption timeout in seconds.
1212
+ /// It is the time after which the redemption request can be reported
1213
+ /// as timed out. It is counted from the moment when the redemption
1214
+ /// request was created via `requestRedemption` call. Reported timed
1215
+ /// out requests are cancelled and locked balance is returned to the
1216
+ /// redeemer in full amount.
1217
+ /// @param redemptionTimeoutSlashingAmount New value of the redemption
1218
+ /// timeout slashing amount in T, it is the amount slashed from each
1219
+ /// wallet member for redemption timeout.
1220
+ /// @param redemptionTimeoutNotifierRewardMultiplier New value of the
1221
+ /// redemption timeout notifier reward multiplier as percentage,
1222
+ /// it determines the percentage of the notifier reward from the
1223
+ /// staking contact the notifier of a redemption timeout receives.
1224
+ /// The value must be in the range [0, 100].
1225
+ /// @dev Requirements:
1226
+ /// - Redemption dust threshold must be greater than moving funds dust
1227
+ /// threshold,
1228
+ /// - Redemption treasury fee divisor must be greater than zero,
1229
+ /// - Redemption transaction max fee must be greater than zero,
1230
+ /// - Redemption timeout must be greater than zero,
1231
+ /// - Redemption timeout notifier reward multiplier must be in the
1232
+ /// range [0, 100].
1233
+ function updateRedemptionParameters(
1234
+ uint64 redemptionDustThreshold,
1235
+ uint64 redemptionTreasuryFeeDivisor,
1236
+ uint64 redemptionTxMaxFee,
1237
+ uint32 redemptionTimeout,
1238
+ uint96 redemptionTimeoutSlashingAmount,
1239
+ uint32 redemptionTimeoutNotifierRewardMultiplier
1240
+ ) external onlyGovernance {
1241
+ self.updateRedemptionParameters(
1242
+ redemptionDustThreshold,
1243
+ redemptionTreasuryFeeDivisor,
1244
+ redemptionTxMaxFee,
1245
+ redemptionTimeout,
1246
+ redemptionTimeoutSlashingAmount,
1247
+ redemptionTimeoutNotifierRewardMultiplier
1248
+ );
1249
+ }
1250
+
1251
+ /// @notice Updates parameters of moving funds.
1252
+ /// @param movingFundsTxMaxTotalFee New value of the moving funds transaction
1253
+ /// max total fee in satoshis. It is the maximum amount of the total
1254
+ /// BTC transaction fee that is acceptable in a single moving funds
1255
+ /// transaction. This is a _total_ max fee for the entire moving
1256
+ /// funds transaction.
1257
+ /// @param movingFundsDustThreshold New value of the moving funds dust
1258
+ /// threshold. It is the minimal satoshi amount that makes sense to
1259
+ /// be transferred during the moving funds process. Moving funds
1260
+ /// wallets having their BTC balance below that value can begin
1261
+ /// closing immediately as transferring such a low value may not be
1262
+ /// possible due to BTC network fees.
1263
+ /// @param movingFundsTimeoutResetDelay New value of the moving funds
1264
+ /// timeout reset delay in seconds. It is the time after which the
1265
+ /// moving funds timeout can be reset in case the target wallet
1266
+ /// commitment cannot be submitted due to a lack of live wallets
1267
+ /// in the system. It is counted from the moment when the wallet
1268
+ /// was requested to move their funds and switched to the MovingFunds
1269
+ /// state or from the moment the timeout was reset the last time.
1270
+ /// @param movingFundsTimeout New value of the moving funds timeout in
1271
+ /// seconds. It is the time after which the moving funds process can
1272
+ /// be reported as timed out. It is counted from the moment when the
1273
+ /// wallet was requested to move their funds and switched to the
1274
+ /// MovingFunds state.
1275
+ /// @param movingFundsTimeoutSlashingAmount New value of the moving funds
1276
+ /// timeout slashing amount in T, it is the amount slashed from each
1277
+ /// wallet member for moving funds timeout.
1278
+ /// @param movingFundsTimeoutNotifierRewardMultiplier New value of the
1279
+ /// moving funds timeout notifier reward multiplier as percentage,
1280
+ /// it determines the percentage of the notifier reward from the
1281
+ /// staking contact the notifier of a moving funds timeout receives.
1282
+ /// The value must be in the range [0, 100].
1283
+ /// @param movedFundsSweepTxMaxTotalFee New value of the moved funds sweep
1284
+ /// transaction max total fee in satoshis. It is the maximum amount
1285
+ /// of the total BTC transaction fee that is acceptable in a single
1286
+ /// moved funds sweep transaction. This is a _total_ max fee for the
1287
+ /// entire moved funds sweep transaction.
1288
+ /// @param movedFundsSweepTimeout New value of the moved funds sweep
1289
+ /// timeout in seconds. It is the time after which the moved funds
1290
+ /// sweep process can be reported as timed out. It is counted from
1291
+ /// the moment when the wallet was requested to sweep the received
1292
+ /// funds.
1293
+ /// @param movedFundsSweepTimeoutSlashingAmount New value of the moved
1294
+ /// funds sweep timeout slashing amount in T, it is the amount
1295
+ /// slashed from each wallet member for moved funds sweep timeout.
1296
+ /// @param movedFundsSweepTimeoutNotifierRewardMultiplier New value of
1297
+ /// the moved funds sweep timeout notifier reward multiplier as
1298
+ /// percentage, it determines the percentage of the notifier reward
1299
+ /// from the staking contact the notifier of a moved funds sweep
1300
+ /// timeout receives. The value must be in the range [0, 100].
1301
+ /// @dev Requirements:
1302
+ /// - Moving funds transaction max total fee must be greater than zero,
1303
+ /// - Moving funds dust threshold must be greater than zero and lower
1304
+ /// than the redemption dust threshold,
1305
+ /// - Moving funds timeout reset delay must be greater than zero,
1306
+ /// - Moving funds timeout must be greater than the moving funds
1307
+ /// timeout reset delay,
1308
+ /// - Moving funds timeout notifier reward multiplier must be in the
1309
+ /// range [0, 100],
1310
+ /// - Moved funds sweep transaction max total fee must be greater than zero,
1311
+ /// - Moved funds sweep timeout must be greater than zero,
1312
+ /// - Moved funds sweep timeout notifier reward multiplier must be in the
1313
+ /// range [0, 100].
1314
+ function updateMovingFundsParameters(
1315
+ uint64 movingFundsTxMaxTotalFee,
1316
+ uint64 movingFundsDustThreshold,
1317
+ uint32 movingFundsTimeoutResetDelay,
1318
+ uint32 movingFundsTimeout,
1319
+ uint96 movingFundsTimeoutSlashingAmount,
1320
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
1321
+ uint64 movedFundsSweepTxMaxTotalFee,
1322
+ uint32 movedFundsSweepTimeout,
1323
+ uint96 movedFundsSweepTimeoutSlashingAmount,
1324
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
1325
+ ) external onlyGovernance {
1326
+ self.updateMovingFundsParameters(
1327
+ movingFundsTxMaxTotalFee,
1328
+ movingFundsDustThreshold,
1329
+ movingFundsTimeoutResetDelay,
1330
+ movingFundsTimeout,
1331
+ movingFundsTimeoutSlashingAmount,
1332
+ movingFundsTimeoutNotifierRewardMultiplier,
1333
+ movedFundsSweepTxMaxTotalFee,
1334
+ movedFundsSweepTimeout,
1335
+ movedFundsSweepTimeoutSlashingAmount,
1336
+ movedFundsSweepTimeoutNotifierRewardMultiplier
1337
+ );
1338
+ }
1339
+
1340
+ /// @notice Updates parameters of wallets.
1341
+ /// @param walletCreationPeriod New value of the wallet creation period in
1342
+ /// seconds, determines how frequently a new wallet creation can be
1343
+ /// requested.
1344
+ /// @param walletCreationMinBtcBalance New value of the wallet minimum BTC
1345
+ /// balance in satoshi, used to decide about wallet creation.
1346
+ /// @param walletCreationMaxBtcBalance New value of the wallet maximum BTC
1347
+ /// balance in satoshi, used to decide about wallet creation.
1348
+ /// @param walletClosureMinBtcBalance New value of the wallet minimum BTC
1349
+ /// balance in satoshi, used to decide about wallet closure.
1350
+ /// @param walletMaxAge New value of the wallet maximum age in seconds,
1351
+ /// indicates the maximum age of a wallet in seconds, after which
1352
+ /// the wallet moving funds process can be requested.
1353
+ /// @param walletMaxBtcTransfer New value of the wallet maximum BTC transfer
1354
+ /// in satoshi, determines the maximum amount that can be transferred
1355
+ // to a single target wallet during the moving funds process.
1356
+ /// @param walletClosingPeriod New value of the wallet closing period in
1357
+ /// seconds, determines the length of the wallet closing period,
1358
+ // i.e. the period when the wallet remains in the Closing state
1359
+ // and can be subject of deposit fraud challenges.
1360
+ /// @dev Requirements:
1361
+ /// - Wallet minimum BTC balance must be greater than zero,
1362
+ /// - Wallet maximum BTC balance must be greater than the wallet
1363
+ /// minimum BTC balance,
1364
+ /// - Wallet maximum BTC transfer must be greater than zero,
1365
+ /// - Wallet closing period must be greater than zero.
1366
+ function updateWalletParameters(
1367
+ uint32 walletCreationPeriod,
1368
+ uint64 walletCreationMinBtcBalance,
1369
+ uint64 walletCreationMaxBtcBalance,
1370
+ uint64 walletClosureMinBtcBalance,
1371
+ uint32 walletMaxAge,
1372
+ uint64 walletMaxBtcTransfer,
1373
+ uint32 walletClosingPeriod
1374
+ ) external onlyGovernance {
1375
+ self.updateWalletParameters(
1376
+ walletCreationPeriod,
1377
+ walletCreationMinBtcBalance,
1378
+ walletCreationMaxBtcBalance,
1379
+ walletClosureMinBtcBalance,
1380
+ walletMaxAge,
1381
+ walletMaxBtcTransfer,
1382
+ walletClosingPeriod
1383
+ );
1384
+ }
1385
+
1386
+ /// @notice Updates parameters related to frauds.
1387
+ /// @param fraudChallengeDepositAmount New value of the fraud challenge
1388
+ /// deposit amount in wei, it is the amount of ETH the party
1389
+ /// challenging the wallet for fraud needs to deposit.
1390
+ /// @param fraudChallengeDefeatTimeout New value of the challenge defeat
1391
+ /// timeout in seconds, it is the amount of time the wallet has to
1392
+ /// defeat a fraud challenge. The value must be greater than zero.
1393
+ /// @param fraudSlashingAmount New value of the fraud slashing amount in T,
1394
+ /// it is the amount slashed from each wallet member for committing
1395
+ /// a fraud.
1396
+ /// @param fraudNotifierRewardMultiplier New value of the fraud notifier
1397
+ /// reward multiplier as percentage, it determines the percentage of
1398
+ /// the notifier reward from the staking contact the notifier of
1399
+ /// a fraud receives. The value must be in the range [0, 100].
1400
+ /// @dev Requirements:
1401
+ /// - Fraud challenge defeat timeout must be greater than 0,
1402
+ /// - Fraud notifier reward multiplier must be in the range [0, 100].
1403
+ function updateFraudParameters(
1404
+ uint96 fraudChallengeDepositAmount,
1405
+ uint32 fraudChallengeDefeatTimeout,
1406
+ uint96 fraudSlashingAmount,
1407
+ uint32 fraudNotifierRewardMultiplier
1408
+ ) external onlyGovernance {
1409
+ self.updateFraudParameters(
1410
+ fraudChallengeDepositAmount,
1411
+ fraudChallengeDefeatTimeout,
1412
+ fraudSlashingAmount,
1413
+ fraudNotifierRewardMultiplier
1414
+ );
1415
+ }
1416
+
1417
+ /// @notice Collection of all revealed deposits indexed by
1418
+ /// keccak256(fundingTxHash | fundingOutputIndex).
1419
+ /// The fundingTxHash is bytes32 (ordered as in Bitcoin internally)
1420
+ /// and fundingOutputIndex an uint32. This mapping may contain valid
1421
+ /// and invalid deposits and the wallet is responsible for
1422
+ /// validating them before attempting to execute a sweep.
1423
+ function deposits(uint256 depositKey)
1424
+ external
1425
+ view
1426
+ returns (Deposit.DepositRequest memory)
1427
+ {
1428
+ return self.deposits[depositKey];
1429
+ }
1430
+
1431
+ /// @notice Collection of all pending redemption requests indexed by
1432
+ /// redemption key built as
1433
+ /// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
1434
+ /// The walletPubKeyHash is the 20-byte wallet's public key hash
1435
+ /// (computed using Bitcoin HASH160 over the compressed ECDSA
1436
+ /// public key) and `redeemerOutputScript` is a Bitcoin script
1437
+ /// (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
1438
+ /// redeemed BTC as requested by the redeemer. Requests are added
1439
+ /// to this mapping by the `requestRedemption` method (duplicates
1440
+ /// not allowed) and are removed by one of the following methods:
1441
+ /// - `submitRedemptionProof` in case the request was handled
1442
+ /// successfully,
1443
+ /// - `notifyRedemptionTimeout` in case the request was reported
1444
+ /// to be timed out.
1445
+ function pendingRedemptions(uint256 redemptionKey)
1446
+ external
1447
+ view
1448
+ returns (Redemption.RedemptionRequest memory)
1449
+ {
1450
+ return self.pendingRedemptions[redemptionKey];
1451
+ }
1452
+
1453
+ /// @notice Collection of all timed out redemptions requests indexed by
1454
+ /// redemption key built as
1455
+ /// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
1456
+ /// The walletPubKeyHash is the 20-byte wallet's public key hash
1457
+ /// (computed using Bitcoin HASH160 over the compressed ECDSA
1458
+ /// public key) and `redeemerOutputScript` is the Bitcoin script
1459
+ /// (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
1460
+ /// out request. Timed out requests are stored in this mapping to
1461
+ /// avoid slashing the wallets multiple times for the same timeout.
1462
+ /// Only one method can add to this mapping:
1463
+ /// - `notifyRedemptionTimeout` which puts the redemption key
1464
+ /// to this mapping basing on a timed out request stored
1465
+ /// previously in `pendingRedemptions` mapping.
1466
+ function timedOutRedemptions(uint256 redemptionKey)
1467
+ external
1468
+ view
1469
+ returns (Redemption.RedemptionRequest memory)
1470
+ {
1471
+ return self.timedOutRedemptions[redemptionKey];
1472
+ }
1473
+
1474
+ /// @notice Collection of main UTXOs that are honestly spent indexed by
1475
+ /// keccak256(fundingTxHash | fundingOutputIndex). The fundingTxHash
1476
+ /// is bytes32 (ordered as in Bitcoin internally) and
1477
+ /// fundingOutputIndex an uint32. A main UTXO is considered honestly
1478
+ /// spent if it was used as an input of a transaction that have been
1479
+ /// proven in the Bridge.
1480
+ function spentMainUTXOs(uint256 utxoKey) external view returns (bool) {
1481
+ return self.spentMainUTXOs[utxoKey];
1482
+ }
1483
+
1484
+ /// @notice Gets details about a registered wallet.
1485
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
1486
+ /// using Bitcoin HASH160 over the compressed ECDSA public key).
1487
+ /// @return Wallet details.
1488
+ function wallets(bytes20 walletPubKeyHash)
1489
+ external
1490
+ view
1491
+ returns (Wallets.Wallet memory)
1492
+ {
1493
+ return self.registeredWallets[walletPubKeyHash];
1494
+ }
1495
+
1496
+ /// @notice Gets the public key hash of the active wallet.
1497
+ /// @return The 20-byte public key hash (computed using Bitcoin HASH160
1498
+ /// over the compressed ECDSA public key) of the active wallet.
1499
+ /// Returns bytes20(0) if there is no active wallet at the moment.
1500
+ function activeWalletPubKeyHash() external view returns (bytes20) {
1501
+ return self.activeWalletPubKeyHash;
1502
+ }
1503
+
1504
+ /// @notice Gets the live wallets count.
1505
+ /// @return The current count of wallets being in the Live state.
1506
+ function liveWalletsCount() external view returns (uint32) {
1507
+ return self.liveWalletsCount;
1508
+ }
1509
+
1510
+ /// @notice Returns the fraud challenge identified by the given key built
1511
+ /// as keccak256(walletPublicKey|sighash).
1512
+ function fraudChallenges(uint256 challengeKey)
1513
+ external
1514
+ view
1515
+ returns (Fraud.FraudChallenge memory)
1516
+ {
1517
+ return self.fraudChallenges[challengeKey];
1518
+ }
1519
+
1520
+ /// @notice Collection of all moved funds sweep requests indexed by
1521
+ /// `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
1522
+ /// The `movingFundsTxHash` is `bytes32` (ordered as in Bitcoin
1523
+ /// internally) and `movingFundsOutputIndex` an `uint32`. Each entry
1524
+ /// is actually an UTXO representing the moved funds and is supposed
1525
+ /// to be swept with the current main UTXO of the recipient wallet.
1526
+ /// @param requestKey Request key built as
1527
+ /// `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
1528
+ /// @return Details of the moved funds sweep request.
1529
+ function movedFundsSweepRequests(uint256 requestKey)
1530
+ external
1531
+ view
1532
+ returns (MovingFunds.MovedFundsSweepRequest memory)
1533
+ {
1534
+ return self.movedFundsSweepRequests[requestKey];
1535
+ }
1536
+
1537
+ /// @notice Indicates if the vault with the given address is trusted or not.
1538
+ /// Depositors can route their revealed deposits only to trusted
1539
+ /// vaults and have trusted vaults notified about new deposits as
1540
+ /// soon as these deposits get swept. Vaults not trusted by the
1541
+ /// Bridge can still be used by Bank balance owners on their own
1542
+ /// responsibility - anyone can approve their Bank balance to any
1543
+ /// address.
1544
+ function isVaultTrusted(address vault) external view returns (bool) {
1545
+ return self.isVaultTrusted[vault];
1546
+ }
1547
+
1548
+ /// @notice Returns the current values of Bridge deposit parameters.
1549
+ /// @return depositDustThreshold The minimal amount that can be requested
1550
+ /// to deposit. Value of this parameter must take into account the
1551
+ /// value of `depositTreasuryFeeDivisor` and `depositTxMaxFee`
1552
+ /// parameters in order to make requests that can incur the
1553
+ /// treasury and transaction fee and still satisfy the depositor.
1554
+ /// @return depositTreasuryFeeDivisor Divisor used to compute the treasury
1555
+ /// fee taken from each deposit and transferred to the treasury upon
1556
+ /// sweep proof submission. That fee is computed as follows:
1557
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
1558
+ /// For example, if the treasury fee needs to be 2% of each deposit,
1559
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
1560
+ /// because `1/50 = 0.02 = 2%`.
1561
+ /// @return depositTxMaxFee Maximum amount of BTC transaction fee that can
1562
+ /// be incurred by each swept deposit being part of the given sweep
1563
+ /// transaction. If the maximum BTC transaction fee is exceeded,
1564
+ /// such transaction is considered a fraud.
1565
+ function depositParameters()
1566
+ external
1567
+ view
1568
+ returns (
1569
+ uint64 depositDustThreshold,
1570
+ uint64 depositTreasuryFeeDivisor,
1571
+ uint64 depositTxMaxFee
1572
+ )
1573
+ {
1574
+ depositDustThreshold = self.depositDustThreshold;
1575
+ depositTreasuryFeeDivisor = self.depositTreasuryFeeDivisor;
1576
+ depositTxMaxFee = self.depositTxMaxFee;
1577
+ }
1578
+
1579
+ /// @notice Returns the current values of Bridge redemption parameters.
1580
+ /// @return redemptionDustThreshold The minimal amount that can be requested
1581
+ /// for redemption. Value of this parameter must take into account
1582
+ /// the value of `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
1583
+ /// parameters in order to make requests that can incur the
1584
+ /// treasury and transaction fee and still satisfy the redeemer.
1585
+ /// @return redemptionTreasuryFeeDivisor Divisor used to compute the treasury
1586
+ /// fee taken from each redemption request and transferred to the
1587
+ /// treasury upon successful request finalization. That fee is
1588
+ /// computed as follows:
1589
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
1590
+ /// For example, if the treasury fee needs to be 2% of each
1591
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
1592
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
1593
+ /// @return redemptionTxMaxFee Maximum amount of BTC transaction fee that
1594
+ /// can be incurred by each redemption request being part of the
1595
+ /// given redemption transaction. If the maximum BTC transaction
1596
+ /// fee is exceeded, such transaction is considered a fraud.
1597
+ /// This is a per-redemption output max fee for the redemption
1598
+ /// transaction.
1599
+ /// @return redemptionTimeout Time after which the redemption request can be
1600
+ /// reported as timed out. It is counted from the moment when the
1601
+ /// redemption request was created via `requestRedemption` call.
1602
+ /// Reported timed out requests are cancelled and locked balance is
1603
+ /// returned to the redeemer in full amount.
1604
+ /// @return redemptionTimeoutSlashingAmount The amount of stake slashed
1605
+ /// from each member of a wallet for a redemption timeout.
1606
+ /// @return redemptionTimeoutNotifierRewardMultiplier The percentage of the
1607
+ /// notifier reward from the staking contract the notifier of a
1608
+ /// redemption timeout receives. The value is in the range [0, 100].
1609
+ function redemptionParameters()
1610
+ external
1611
+ view
1612
+ returns (
1613
+ uint64 redemptionDustThreshold,
1614
+ uint64 redemptionTreasuryFeeDivisor,
1615
+ uint64 redemptionTxMaxFee,
1616
+ uint32 redemptionTimeout,
1617
+ uint96 redemptionTimeoutSlashingAmount,
1618
+ uint32 redemptionTimeoutNotifierRewardMultiplier
1619
+ )
1620
+ {
1621
+ redemptionDustThreshold = self.redemptionDustThreshold;
1622
+ redemptionTreasuryFeeDivisor = self.redemptionTreasuryFeeDivisor;
1623
+ redemptionTxMaxFee = self.redemptionTxMaxFee;
1624
+ redemptionTimeout = self.redemptionTimeout;
1625
+ redemptionTimeoutSlashingAmount = self.redemptionTimeoutSlashingAmount;
1626
+ redemptionTimeoutNotifierRewardMultiplier = self
1627
+ .redemptionTimeoutNotifierRewardMultiplier;
1628
+ }
1629
+
1630
+ /// @notice Returns the current values of Bridge moving funds between
1631
+ /// wallets parameters.
1632
+ /// @return movingFundsTxMaxTotalFee Maximum amount of the total BTC
1633
+ /// transaction fee that is acceptable in a single moving funds
1634
+ /// transaction. This is a _total_ max fee for the entire moving
1635
+ /// funds transaction.
1636
+ /// @return movingFundsDustThreshold The minimal satoshi amount that makes
1637
+ /// sense to be transferred during the moving funds process. Moving
1638
+ /// funds wallets having their BTC balance below that value can
1639
+ /// begin closing immediately as transferring such a low value may
1640
+ /// not be possible due to BTC network fees.
1641
+ /// @return movingFundsTimeoutResetDelay Time after which the moving funds
1642
+ /// timeout can be reset in case the target wallet commitment
1643
+ /// cannot be submitted due to a lack of live wallets in the system.
1644
+ /// It is counted from the moment when the wallet was requested to
1645
+ /// move their funds and switched to the MovingFunds state or from
1646
+ /// the moment the timeout was reset the last time. Value in seconds
1647
+ /// This value should be lower than the value of the
1648
+ /// `movingFundsTimeout`.
1649
+ /// @return movingFundsTimeout Time after which the moving funds process
1650
+ /// can be reported as timed out. It is counted from the moment
1651
+ /// when the wallet was requested to move their funds and switched
1652
+ /// to the MovingFunds state. Value in seconds.
1653
+ /// @return movingFundsTimeoutSlashingAmount The amount of stake slashed
1654
+ /// from each member of a wallet for a moving funds timeout.
1655
+ /// @return movingFundsTimeoutNotifierRewardMultiplier The percentage of the
1656
+ /// notifier reward from the staking contract the notifier of a
1657
+ /// moving funds timeout receives. The value is in the range [0, 100].
1658
+ /// @return movedFundsSweepTxMaxTotalFee Maximum amount of the total BTC
1659
+ /// transaction fee that is acceptable in a single moved funds
1660
+ /// sweep transaction. This is a _total_ max fee for the entire
1661
+ /// moved funds sweep transaction.
1662
+ /// @return movedFundsSweepTimeout Time after which the moved funds sweep
1663
+ /// process can be reported as timed out. It is counted from the
1664
+ /// moment when the wallet was requested to sweep the received funds.
1665
+ /// Value in seconds.
1666
+ /// @return movedFundsSweepTimeoutSlashingAmount The amount of stake slashed
1667
+ /// from each member of a wallet for a moved funds sweep timeout.
1668
+ /// @return movedFundsSweepTimeoutNotifierRewardMultiplier The percentage
1669
+ /// of the notifier reward from the staking contract the notifier
1670
+ /// of a moved funds sweep timeout receives. The value is in the
1671
+ /// range [0, 100].
1672
+ function movingFundsParameters()
1673
+ external
1674
+ view
1675
+ returns (
1676
+ uint64 movingFundsTxMaxTotalFee,
1677
+ uint64 movingFundsDustThreshold,
1678
+ uint32 movingFundsTimeoutResetDelay,
1679
+ uint32 movingFundsTimeout,
1680
+ uint96 movingFundsTimeoutSlashingAmount,
1681
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
1682
+ uint64 movedFundsSweepTxMaxTotalFee,
1683
+ uint32 movedFundsSweepTimeout,
1684
+ uint96 movedFundsSweepTimeoutSlashingAmount,
1685
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
1686
+ )
1687
+ {
1688
+ movingFundsTxMaxTotalFee = self.movingFundsTxMaxTotalFee;
1689
+ movingFundsDustThreshold = self.movingFundsDustThreshold;
1690
+ movingFundsTimeoutResetDelay = self.movingFundsTimeoutResetDelay;
1691
+ movingFundsTimeout = self.movingFundsTimeout;
1692
+ movingFundsTimeoutSlashingAmount = self
1693
+ .movingFundsTimeoutSlashingAmount;
1694
+ movingFundsTimeoutNotifierRewardMultiplier = self
1695
+ .movingFundsTimeoutNotifierRewardMultiplier;
1696
+ movedFundsSweepTxMaxTotalFee = self.movedFundsSweepTxMaxTotalFee;
1697
+ movedFundsSweepTimeout = self.movedFundsSweepTimeout;
1698
+ movedFundsSweepTimeoutSlashingAmount = self
1699
+ .movedFundsSweepTimeoutSlashingAmount;
1700
+ movedFundsSweepTimeoutNotifierRewardMultiplier = self
1701
+ .movedFundsSweepTimeoutNotifierRewardMultiplier;
1702
+ }
1703
+
1704
+ /// @return walletCreationPeriod Determines how frequently a new wallet
1705
+ /// creation can be requested. Value in seconds.
1706
+ /// @return walletCreationMinBtcBalance The minimum BTC threshold in satoshi
1707
+ /// that is used to decide about wallet creation.
1708
+ /// @return walletCreationMaxBtcBalance The maximum BTC threshold in satoshi
1709
+ /// that is used to decide about wallet creation.
1710
+ /// @return walletClosureMinBtcBalance The minimum BTC threshold in satoshi
1711
+ /// that is used to decide about wallet closure.
1712
+ /// @return walletMaxAge The maximum age of a wallet in seconds, after which
1713
+ /// the wallet moving funds process can be requested.
1714
+ /// @return walletMaxBtcTransfer The maximum BTC amount in satoshi than
1715
+ /// can be transferred to a single target wallet during the moving
1716
+ /// funds process.
1717
+ /// @return walletClosingPeriod Determines the length of the wallet closing
1718
+ /// period, i.e. the period when the wallet remains in the Closing
1719
+ /// state and can be subject of deposit fraud challenges. Value
1720
+ /// in seconds.
1721
+ function walletParameters()
1722
+ external
1723
+ view
1724
+ returns (
1725
+ uint32 walletCreationPeriod,
1726
+ uint64 walletCreationMinBtcBalance,
1727
+ uint64 walletCreationMaxBtcBalance,
1728
+ uint64 walletClosureMinBtcBalance,
1729
+ uint32 walletMaxAge,
1730
+ uint64 walletMaxBtcTransfer,
1731
+ uint32 walletClosingPeriod
1732
+ )
1733
+ {
1734
+ walletCreationPeriod = self.walletCreationPeriod;
1735
+ walletCreationMinBtcBalance = self.walletCreationMinBtcBalance;
1736
+ walletCreationMaxBtcBalance = self.walletCreationMaxBtcBalance;
1737
+ walletClosureMinBtcBalance = self.walletClosureMinBtcBalance;
1738
+ walletMaxAge = self.walletMaxAge;
1739
+ walletMaxBtcTransfer = self.walletMaxBtcTransfer;
1740
+ walletClosingPeriod = self.walletClosingPeriod;
1741
+ }
1742
+
1743
+ /// @notice Returns the current values of Bridge fraud parameters.
1744
+ /// @return fraudChallengeDepositAmount The amount of ETH in wei the party
1745
+ /// challenging the wallet for fraud needs to deposit.
1746
+ /// @return fraudChallengeDefeatTimeout The amount of time the wallet has to
1747
+ /// defeat a fraud challenge.
1748
+ /// @return fraudSlashingAmount The amount slashed from each wallet member
1749
+ /// for committing a fraud.
1750
+ /// @return fraudNotifierRewardMultiplier The percentage of the notifier
1751
+ /// reward from the staking contract the notifier of a fraud
1752
+ /// receives. The value is in the range [0, 100].
1753
+ function fraudParameters()
1754
+ external
1755
+ view
1756
+ returns (
1757
+ uint96 fraudChallengeDepositAmount,
1758
+ uint32 fraudChallengeDefeatTimeout,
1759
+ uint96 fraudSlashingAmount,
1760
+ uint32 fraudNotifierRewardMultiplier
1761
+ )
1762
+ {
1763
+ fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
1764
+ fraudChallengeDefeatTimeout = self.fraudChallengeDefeatTimeout;
1765
+ fraudSlashingAmount = self.fraudSlashingAmount;
1766
+ fraudNotifierRewardMultiplier = self.fraudNotifierRewardMultiplier;
1767
+ }
1768
+
1769
+ /// @notice Returns the addresses of contracts Bridge is interacting with.
1770
+ /// @return bank Address of the Bank the Bridge belongs to.
1771
+ /// @return relay Address of the Bitcoin relay providing the current Bitcoin
1772
+ /// network difficulty.
1773
+ /// @return ecdsaWalletRegistry Address of the ECDSA Wallet Registry.
1774
+ function contractReferences()
1775
+ external
1776
+ view
1777
+ returns (
1778
+ Bank bank,
1779
+ IRelay relay,
1780
+ EcdsaWalletRegistry ecdsaWalletRegistry
1781
+ )
1782
+ {
1783
+ bank = self.bank;
1784
+ relay = self.relay;
1785
+ ecdsaWalletRegistry = self.ecdsaWalletRegistry;
1786
+ }
1787
+
1788
+ /// @notice Address where the deposit treasury fees will be sent to.
1789
+ /// Treasury takes part in the operators rewarding process.
1790
+ function treasury() external view returns (address) {
1791
+ return self.treasury;
1792
+ }
1793
+
1794
+ /// @notice The number of confirmations on the Bitcoin chain required to
1795
+ /// successfully evaluate an SPV proof.
1796
+ function txProofDifficultyFactor() external view returns (uint256) {
1797
+ return self.txProofDifficultyFactor;
1798
+ }
1799
+ }