@keep-network/tbtc-v2 0.1.1-dev.34 → 0.1.1-dev.37

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 (36) hide show
  1. package/artifacts/TBTC.json +3 -3
  2. package/artifacts/TBTCToken.json +3 -3
  3. package/artifacts/VendingMachine.json +10 -10
  4. package/artifacts/solcInputs/{a67a2c11233ce411fb55a9f369ced323.json → e22260bedca047fea8676977de0ef137.json} +15 -6
  5. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  6. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  7. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  8. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  9. package/build/contracts/bridge/Bridge.sol/Bridge.json +196 -204
  10. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  11. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +2 -2
  12. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  13. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  14. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  15. package/build/contracts/bridge/Frauds.sol/Frauds.dbg.json +1 -1
  16. package/build/contracts/bridge/Frauds.sol/Frauds.json +2 -2
  17. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
  18. package/build/contracts/bridge/{Bridge.sol → IRelay.sol}/IRelay.json +1 -1
  19. package/build/contracts/bridge/Redeem.sol/OutboundTx.dbg.json +4 -0
  20. package/build/contracts/bridge/Redeem.sol/OutboundTx.json +10 -0
  21. package/build/contracts/bridge/Redeem.sol/Redeem.dbg.json +4 -0
  22. package/build/contracts/bridge/Redeem.sol/Redeem.json +126 -0
  23. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +4 -0
  24. package/build/contracts/bridge/Sweep.sol/Sweep.json +48 -0
  25. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  26. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  27. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  28. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  29. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  30. package/contracts/bridge/Bridge.sol +165 -1130
  31. package/contracts/bridge/BridgeState.sol +110 -0
  32. package/contracts/bridge/IRelay.sol +28 -0
  33. package/contracts/bridge/Redeem.sol +849 -0
  34. package/contracts/bridge/Sweep.sol +510 -0
  35. package/package.json +1 -1
  36. package/build/contracts/bridge/Bridge.sol/IRelay.dbg.json +0 -4
@@ -15,10 +15,29 @@
15
15
 
16
16
  pragma solidity ^0.8.9;
17
17
 
18
+ import "./IRelay.sol";
18
19
  import "./Deposit.sol";
20
+ import "./Redeem.sol";
21
+
22
+ import "../bank/Bank.sol";
19
23
 
20
24
  library BridgeState {
21
25
  struct Storage {
26
+ /// @notice The number of confirmations on the Bitcoin chain required to
27
+ /// successfully evaluate an SPV proof.
28
+ uint256 txProofDifficultyFactor;
29
+ /// TODO: Revisit whether it should be governable or not.
30
+ /// @notice Address of the Bank this Bridge belongs to.
31
+ Bank bank;
32
+ /// TODO: Make it governable.
33
+ /// @notice Bitcoin relay providing the current Bitcoin network
34
+ /// difficulty.
35
+ IRelay relay;
36
+ /// TODO: Revisit whether it should be governable or not.
37
+ /// @notice Address where the deposit and redemption treasury fees will
38
+ /// be sent to. Treasury takes part in the operators rewarding
39
+ /// process.
40
+ address treasury;
22
41
  /// TODO: Make it governable.
23
42
  /// @notice The minimal amount that can be requested to deposit.
24
43
  /// Value of this parameter must take into account the value of
@@ -35,6 +54,13 @@ library BridgeState {
35
54
  /// the `depositTreasuryFeeDivisor` should be set to `50`
36
55
  /// because `1/50 = 0.02 = 2%`.
37
56
  uint64 depositTreasuryFeeDivisor;
57
+ /// TODO: Make it governable.
58
+ /// @notice Maximum amount of BTC transaction fee that can be incurred by
59
+ /// each swept deposit being part of the given sweep
60
+ /// transaction. If the maximum BTC transaction fee is exceeded,
61
+ /// such transaction is considered a fraud.
62
+ /// @dev This is a per-deposit input max fee for the sweep transaction.
63
+ uint64 depositTxMaxFee;
38
64
  /// @notice Collection of all revealed deposits indexed by
39
65
  /// keccak256(fundingTxHash | fundingOutputIndex).
40
66
  /// The fundingTxHash is bytes32 (ordered as in Bitcoin internally)
@@ -50,5 +76,89 @@ library BridgeState {
50
76
  /// responsibility - anyone can approve their Bank balance to any
51
77
  /// address.
52
78
  mapping(address => bool) isVaultTrusted;
79
+ /// TODO: Make it governable.
80
+ /// @notice The minimal amount that can be requested for redemption.
81
+ /// Value of this parameter must take into account the value of
82
+ /// `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
83
+ /// parameters in order to make requests that can incur the
84
+ /// treasury and transaction fee and still satisfy the redeemer.
85
+ uint64 redemptionDustThreshold;
86
+ /// TODO: Make it governable.
87
+ /// @notice Divisor used to compute the treasury fee taken from each
88
+ /// redemption request and transferred to the treasury upon
89
+ /// successful request finalization. That fee is computed as follows:
90
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
91
+ /// For example, if the treasury fee needs to be 2% of each
92
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
93
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
94
+ uint64 redemptionTreasuryFeeDivisor;
95
+ /// TODO: Make it governable.
96
+ /// @notice Maximum amount of BTC transaction fee that can be incurred by
97
+ /// each redemption request being part of the given redemption
98
+ /// transaction. If the maximum BTC transaction fee is exceeded, such
99
+ /// transaction is considered a fraud.
100
+ /// @dev This is a per-redemption output max fee for the redemption transaction.
101
+ uint64 redemptionTxMaxFee;
102
+ /// TODO: Make it governable.
103
+ /// @notice Time after which the redemption request can be reported as
104
+ /// timed out. It is counted from the moment when the redemption
105
+ /// request was created via `requestRedemption` call. Reported
106
+ /// timed out requests are cancelled and locked TBTC is returned
107
+ /// to the redeemer in full amount.
108
+ uint256 redemptionTimeout;
109
+ /// @notice Collection of all pending redemption requests indexed by
110
+ /// redemption key built as
111
+ /// keccak256(walletPubKeyHash | redeemerOutputScript). The
112
+ /// walletPubKeyHash is the 20-byte wallet's public key hash
113
+ /// (computed using Bitcoin HASH160 over the compressed ECDSA
114
+ /// public key) and redeemerOutputScript is a Bitcoin script
115
+ /// (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
116
+ /// redeemed BTC as requested by the redeemer. Requests are added
117
+ /// to this mapping by the `requestRedemption` method (duplicates
118
+ /// not allowed) and are removed by one of the following methods:
119
+ /// - `submitRedemptionProof` in case the request was handled
120
+ /// successfully
121
+ /// - `notifyRedemptionTimeout` in case the request was reported
122
+ /// to be timed out
123
+ mapping(uint256 => Redeem.RedemptionRequest) pendingRedemptions;
124
+ /// @notice Collection of all timed out redemptions requests indexed by
125
+ /// redemption key built as
126
+ /// keccak256(walletPubKeyHash | redeemerOutputScript). The
127
+ /// walletPubKeyHash is the 20-byte wallet's public key hash
128
+ /// (computed using Bitcoin HASH160 over the compressed ECDSA
129
+ /// public key) and redeemerOutputScript is the Bitcoin script
130
+ /// (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
131
+ /// out request. Timed out requests are stored in this mapping to
132
+ /// avoid slashing the wallets multiple times for the same timeout.
133
+ /// Only one method can add to this mapping:
134
+ /// - `notifyRedemptionTimeout` which puts the redemption key
135
+ /// to this mapping basing on a timed out request stored
136
+ /// previously in `pendingRedemptions` mapping.
137
+ mapping(uint256 => Redeem.RedemptionRequest) timedOutRedemptions;
138
+ /// @notice Collection of main UTXOs that are honestly spent indexed by
139
+ /// keccak256(fundingTxHash | fundingOutputIndex). The fundingTxHash
140
+ /// is bytes32 (ordered as in Bitcoin internally) and
141
+ /// fundingOutputIndex an uint32. A main UTXO is considered honestly
142
+ /// spent if it was used as an input of a transaction that have been
143
+ /// proven in the Bridge.
144
+ mapping(uint256 => bool) spentMainUTXOs;
145
+ }
146
+
147
+ // TODO: Is it the right place for this function? Should we move it to Bridge?
148
+ /// @notice Determines the current Bitcoin SPV proof difficulty context.
149
+ /// @return proofDifficulty Bitcoin proof difficulty context.
150
+ function proofDifficultyContext(Storage storage self)
151
+ internal
152
+ view
153
+ returns (BitcoinTx.ProofDifficulty memory proofDifficulty)
154
+ {
155
+ IRelay relay = self.relay;
156
+ proofDifficulty.currentEpochDifficulty = relay
157
+ .getCurrentEpochDifficulty();
158
+ proofDifficulty.previousEpochDifficulty = relay
159
+ .getPrevEpochDifficulty();
160
+ proofDifficulty.difficultyFactor = self.txProofDifficultyFactor;
161
+
162
+ return proofDifficulty;
53
163
  }
54
164
  }
@@ -0,0 +1,28 @@
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
+ /// @title Interface for the Bitcoin relay
19
+ /// @notice Contains only the methods needed by tBTC v2. The Bitcoin relay
20
+ /// provides the difficulty of the previous and current epoch. One
21
+ /// difficulty epoch spans 2016 blocks.
22
+ interface IRelay {
23
+ /// @notice Returns the difficulty of the current epoch.
24
+ function getCurrentEpochDifficulty() external view returns (uint256);
25
+
26
+ /// @notice Returns the difficulty of the previous epoch.
27
+ function getPrevEpochDifficulty() external view returns (uint256);
28
+ }