@keep-network/tbtc-v2 0.1.1-dev.8 → 0.1.1-dev.80
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.
- package/README.adoc +12 -0
- package/artifacts/Bank.json +757 -0
- package/artifacts/Bridge.json +2644 -0
- package/artifacts/Deposit.json +117 -0
- package/artifacts/DepositSweep.json +77 -0
- package/artifacts/EcdsaDkgValidator.json +532 -0
- package/artifacts/EcdsaInactivity.json +156 -0
- package/artifacts/EcdsaSortitionPool.json +1004 -0
- package/artifacts/Fraud.json +164 -0
- package/artifacts/KeepRegistry.json +99 -0
- package/artifacts/KeepStake.json +286 -0
- package/artifacts/KeepToken.json +711 -0
- package/artifacts/KeepTokenStaking.json +483 -0
- package/artifacts/MovingFunds.json +249 -0
- package/artifacts/NuCypherStakingEscrow.json +256 -0
- package/artifacts/NuCypherToken.json +711 -0
- package/artifacts/RandomBeaconStub.json +141 -0
- package/artifacts/Redemption.json +162 -0
- package/artifacts/ReimbursementPool.json +509 -0
- package/artifacts/Relay.json +123 -0
- package/artifacts/T.json +1148 -0
- package/artifacts/TBTC.json +27 -26
- package/artifacts/TBTCToken.json +27 -26
- package/artifacts/TBTCVault.json +462 -0
- package/artifacts/TokenStaking.json +2288 -0
- package/artifacts/TokenholderGovernor.json +1795 -0
- package/artifacts/TokenholderTimelock.json +1058 -0
- package/artifacts/VendingMachine.json +30 -29
- package/artifacts/VendingMachineKeep.json +400 -0
- package/artifacts/VendingMachineNuCypher.json +400 -0
- package/artifacts/WalletRegistry.json +1843 -0
- package/artifacts/WalletRegistryGovernance.json +2754 -0
- package/artifacts/Wallets.json +186 -0
- package/artifacts/solcInputs/4f6d4f5cd1e3d835e20ed55926a445cd.json +311 -0
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
- package/build/contracts/bank/Bank.sol/Bank.json +25 -2
- package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +4 -0
- package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.json +34 -0
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.json +2516 -196
- package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
- package/build/contracts/bridge/BridgeState.sol/BridgeState.json +226 -0
- package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
- package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
- package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
- package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +30 -0
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
- package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
- package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
- package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +4 -0
- package/build/contracts/bridge/Heartbeat.sol/Heartbeat.json +10 -0
- package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
- package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +138 -0
- package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
- package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
- package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
- package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
- package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
- package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
- package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +4 -0
- package/build/contracts/vault/DonationVault.sol/DonationVault.json +108 -0
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
- package/build/contracts/vault/IVault.sol/IVault.json +24 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +126 -7
- package/contracts/GovernanceUtils.sol +4 -4
- package/contracts/bank/Bank.sol +45 -20
- package/contracts/bank/IReceiveBalanceApproval.sol +45 -0
- package/contracts/bridge/BitcoinTx.sol +232 -10
- package/contracts/bridge/Bridge.sol +1601 -244
- package/contracts/bridge/BridgeState.sol +739 -0
- package/contracts/bridge/Deposit.sol +269 -0
- package/contracts/bridge/DepositSweep.sol +571 -0
- package/contracts/bridge/EcdsaLib.sol +45 -0
- package/contracts/bridge/Fraud.sol +604 -0
- package/contracts/bridge/Heartbeat.sol +112 -0
- package/contracts/bridge/IRelay.sol +28 -0
- package/contracts/bridge/MovingFunds.sol +1089 -0
- package/contracts/bridge/Redemption.sol +867 -0
- package/contracts/bridge/VendingMachine.sol +1 -1
- package/contracts/bridge/Wallets.sol +553 -0
- package/contracts/hardhat-dependency-compiler/.hardhat-dependency-compiler +1 -0
- package/contracts/hardhat-dependency-compiler/@keep-network/ecdsa/contracts/WalletRegistry.sol +3 -0
- package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol +3 -0
- package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +3 -0
- package/contracts/token/TBTC.sol +1 -1
- package/contracts/vault/DonationVault.sol +125 -0
- package/contracts/vault/IVault.sol +19 -13
- package/contracts/vault/TBTCVault.sol +58 -8
- package/deploy/00_resolve_relay.ts +28 -0
- package/deploy/04_deploy_bank.ts +27 -0
- package/deploy/05_deploy_bridge.ts +80 -0
- package/deploy/06_deploy_tbtc_vault.ts +30 -0
- package/deploy/07_bank_update_bridge.ts +19 -0
- package/deploy/08_transfer_ownership.ts +15 -0
- package/deploy/09_transfer_governance.ts +20 -0
- package/deploy/10_transfer_proxy_admin_ownership.ts +30 -0
- package/deploy/11_deploy_proxy_admin_with_deputy.ts +33 -0
- package/export.json +15993 -475
- package/package.json +32 -25
- package/artifacts/solcInputs/4cf328e09411ac69d75a3c381680bc2c.json +0 -128
|
@@ -0,0 +1,125 @@
|
|
|
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 "./IVault.sol";
|
|
19
|
+
import "../bank/Bank.sol";
|
|
20
|
+
|
|
21
|
+
/// @title BTC donation vault
|
|
22
|
+
/// @notice Vault that allows making BTC donations to the system. Upon deposit,
|
|
23
|
+
/// this vault does not increase depositors' balances and always
|
|
24
|
+
/// decreases its own balance in the same transaction. The vault also
|
|
25
|
+
/// allows making donations using existing Bank balances.
|
|
26
|
+
///
|
|
27
|
+
/// BEWARE: ALL BTC DEPOSITS TARGETING THIS VAULT ARE NOT REDEEMABLE
|
|
28
|
+
/// AND THERE IS NO WAY TO RESTORE THE DONATED BALANCE.
|
|
29
|
+
/// USE THIS VAULT ONLY WHEN YOU REALLY KNOW WHAT YOU ARE DOING!
|
|
30
|
+
contract DonationVault is IVault {
|
|
31
|
+
Bank public bank;
|
|
32
|
+
|
|
33
|
+
event DonationReceived(address donor, uint256 donatedAmount);
|
|
34
|
+
|
|
35
|
+
modifier onlyBank() {
|
|
36
|
+
require(msg.sender == address(bank), "Caller is not the Bank");
|
|
37
|
+
_;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
constructor(Bank _bank) {
|
|
41
|
+
require(
|
|
42
|
+
address(_bank) != address(0),
|
|
43
|
+
"Bank can not be the zero address"
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
bank = _bank;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// @notice Transfers the given `amount` of the Bank balance from the
|
|
50
|
+
/// caller to the Donation Vault and immediately decreases the
|
|
51
|
+
/// vault's balance in the Bank by the transferred `amount`.
|
|
52
|
+
/// @param amount Amount of the Bank balance to donate.
|
|
53
|
+
/// @dev Requirements:
|
|
54
|
+
/// - The caller's balance in the Bank must be greater than or equal
|
|
55
|
+
/// to the `amount`,
|
|
56
|
+
/// - Donation Vault must have an allowance for caller's balance in
|
|
57
|
+
/// the Bank for at least `amount`.
|
|
58
|
+
function donate(uint256 amount) external {
|
|
59
|
+
address donor = msg.sender;
|
|
60
|
+
|
|
61
|
+
require(
|
|
62
|
+
bank.balanceOf(donor) >= amount,
|
|
63
|
+
"Amount exceeds balance in the bank"
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
emit DonationReceived(donor, amount);
|
|
67
|
+
|
|
68
|
+
bank.transferBalanceFrom(donor, address(this), amount);
|
|
69
|
+
bank.decreaseBalance(amount);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// @notice Transfers the given `amount` of the Bank balance from the
|
|
73
|
+
/// `owner` to the Donation Vault and immediately decreases the
|
|
74
|
+
/// vault's balance in the Bank by the transferred `amount`.
|
|
75
|
+
/// @param owner Address of the Bank balance owner who approved their
|
|
76
|
+
/// balance to be used by the vault.
|
|
77
|
+
/// @param amount The amount of the Bank balance approved by the owner
|
|
78
|
+
/// to be used by the vault.
|
|
79
|
+
/// @dev Requirements:
|
|
80
|
+
/// - Can only be called by the Bank via `approveBalanceAndCall`,
|
|
81
|
+
/// - The `owner` balance in the Bank must be greater than or equal
|
|
82
|
+
/// to the `amount`.
|
|
83
|
+
function receiveBalanceApproval(
|
|
84
|
+
address owner,
|
|
85
|
+
uint256 amount,
|
|
86
|
+
bytes memory
|
|
87
|
+
) external override onlyBank {
|
|
88
|
+
require(
|
|
89
|
+
bank.balanceOf(owner) >= amount,
|
|
90
|
+
"Amount exceeds balance in the bank"
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
emit DonationReceived(owner, amount);
|
|
94
|
+
|
|
95
|
+
bank.transferBalanceFrom(owner, address(this), amount);
|
|
96
|
+
bank.decreaseBalance(amount);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// @notice Ignores the deposited amounts and does not increase depositors'
|
|
100
|
+
/// individual balances. The vault decreases its own tBTC balance
|
|
101
|
+
/// in the Bank by the total deposited amount.
|
|
102
|
+
/// @param depositors Addresses of depositors whose deposits have been swept.
|
|
103
|
+
/// @param depositedAmounts Amounts deposited by individual depositors and
|
|
104
|
+
/// swept.
|
|
105
|
+
/// @dev Requirements:
|
|
106
|
+
/// - Can only be called by the Bank after the Bridge swept deposits
|
|
107
|
+
/// and Bank increased balance for the vault,
|
|
108
|
+
/// - The `depositors` array must not be empty,
|
|
109
|
+
/// - The `depositors` array length must be equal to the
|
|
110
|
+
/// `depositedAmounts` array length.
|
|
111
|
+
function receiveBalanceIncrease(
|
|
112
|
+
address[] calldata depositors,
|
|
113
|
+
uint256[] calldata depositedAmounts
|
|
114
|
+
) external override onlyBank {
|
|
115
|
+
require(depositors.length != 0, "No depositors specified");
|
|
116
|
+
|
|
117
|
+
uint256 totalAmount = 0;
|
|
118
|
+
for (uint256 i = 0; i < depositors.length; i++) {
|
|
119
|
+
totalAmount += depositedAmounts[i];
|
|
120
|
+
emit DonationReceived(depositors[i], depositedAmounts[i]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
bank.decreaseBalance(totalAmount);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -13,25 +13,31 @@
|
|
|
13
13
|
// ▐████▌ ▐████▌
|
|
14
14
|
// ▐████▌ ▐████▌
|
|
15
15
|
|
|
16
|
-
pragma solidity 0.8.
|
|
16
|
+
pragma solidity ^0.8.9;
|
|
17
|
+
|
|
18
|
+
import "../bank/IReceiveBalanceApproval.sol";
|
|
17
19
|
|
|
18
20
|
/// @title Bank Vault interface
|
|
19
21
|
/// @notice `IVault` is an interface for a smart contract consuming Bank
|
|
20
|
-
/// balances
|
|
21
|
-
|
|
22
|
-
/// depositor to route their deposit revealed to the Bridge to the
|
|
23
|
-
/// particular smart contract in the same transaction the deposit is
|
|
24
|
-
/// revealed. This way, the depositor does not have to execute
|
|
25
|
-
/// additional transaction after the deposit gets swept by the Bridge.
|
|
26
|
-
interface IVault {
|
|
22
|
+
/// balances of other contracts or externally owned accounts (EOA).
|
|
23
|
+
interface IVault is IReceiveBalanceApproval {
|
|
27
24
|
/// @notice Called by the Bank in `increaseBalanceAndCall` function after
|
|
28
|
-
/// increasing the balance in the Bank for the vault.
|
|
29
|
-
///
|
|
25
|
+
/// increasing the balance in the Bank for the vault. It happens in
|
|
26
|
+
/// the same transaction in which deposits were swept by the Bridge.
|
|
27
|
+
/// This allows the depositor to route their deposit revealed to the
|
|
28
|
+
/// Bridge to the particular smart contract (vault) in the same
|
|
29
|
+
/// transaction in which the deposit is revealed. This way, the
|
|
30
|
+
/// depositor does not have to execute additional transaction after
|
|
31
|
+
/// the deposit gets swept by the Bridge to approve and transfer
|
|
32
|
+
/// their balance to the vault.
|
|
33
|
+
/// @param depositors Addresses of depositors whose deposits have been swept.
|
|
30
34
|
/// @param depositedAmounts Amounts deposited by individual depositors and
|
|
31
|
-
/// swept
|
|
35
|
+
/// swept.
|
|
32
36
|
/// @dev The implementation must ensure this function can only be called
|
|
33
|
-
/// by the Bank.
|
|
34
|
-
function
|
|
37
|
+
/// by the Bank. The Bank guarantees that the vault's balance was
|
|
38
|
+
/// increased by the sum of all deposited amounts before this function
|
|
39
|
+
/// is called, in the same transaction.
|
|
40
|
+
function receiveBalanceIncrease(
|
|
35
41
|
address[] calldata depositors,
|
|
36
42
|
uint256[] calldata depositedAmounts
|
|
37
43
|
) external;
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
// ▐████▌ ▐████▌
|
|
14
14
|
// ▐████▌ ▐████▌
|
|
15
15
|
|
|
16
|
-
pragma solidity 0.8.
|
|
16
|
+
pragma solidity ^0.8.9;
|
|
17
|
+
|
|
18
|
+
import "@keep-network/random-beacon/contracts/Governable.sol";
|
|
17
19
|
|
|
18
20
|
import "./IVault.sol";
|
|
19
21
|
import "../bank/Bank.sol";
|
|
@@ -27,7 +29,7 @@ import "../token/TBTC.sol";
|
|
|
27
29
|
/// Bank.
|
|
28
30
|
/// @dev TBTC Vault is the owner of TBTC token contract and is the only contract
|
|
29
31
|
/// minting the token.
|
|
30
|
-
contract TBTCVault is IVault {
|
|
32
|
+
contract TBTCVault is IVault, Governable {
|
|
31
33
|
Bank public bank;
|
|
32
34
|
TBTC public tbtcToken;
|
|
33
35
|
|
|
@@ -53,13 +55,43 @@ contract TBTCVault is IVault {
|
|
|
53
55
|
|
|
54
56
|
bank = _bank;
|
|
55
57
|
tbtcToken = _tbtcToken;
|
|
58
|
+
|
|
59
|
+
_transferGovernance(msg.sender);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// @notice Allows the governance of the TBTCVault to recover any ERC20
|
|
63
|
+
/// token sent mistakenly to the TBTC token contract address.
|
|
64
|
+
/// @param token Address of the recovered ERC20 token contract.
|
|
65
|
+
/// @param recipient Address the recovered token should be sent to.
|
|
66
|
+
/// @param amount Recovered amount.
|
|
67
|
+
function recoverERC20(
|
|
68
|
+
IERC20 token,
|
|
69
|
+
address recipient,
|
|
70
|
+
uint256 amount
|
|
71
|
+
) external onlyGovernance {
|
|
72
|
+
tbtcToken.recoverERC20(token, recipient, amount);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// @notice Allows the governance of the TBTCVault to recover any ERC721
|
|
76
|
+
/// token sent mistakenly to the TBTC token contract address.
|
|
77
|
+
/// @param token Address of the recovered ERC721 token contract.
|
|
78
|
+
/// @param recipient Address the recovered token should be sent to.
|
|
79
|
+
/// @param tokenId Identifier of the recovered token.
|
|
80
|
+
/// @param data Additional data.
|
|
81
|
+
function recoverERC721(
|
|
82
|
+
IERC721 token,
|
|
83
|
+
address recipient,
|
|
84
|
+
uint256 tokenId,
|
|
85
|
+
bytes calldata data
|
|
86
|
+
) external onlyGovernance {
|
|
87
|
+
tbtcToken.recoverERC721(token, recipient, tokenId, data);
|
|
56
88
|
}
|
|
57
89
|
|
|
58
90
|
/// @notice Transfers the given `amount` of the Bank balance from caller
|
|
59
91
|
/// to TBTC Vault, and mints `amount` of TBTC to the caller.
|
|
60
92
|
/// @dev TBTC Vault must have an allowance for caller's balance in the Bank
|
|
61
93
|
/// for at least `amount`.
|
|
62
|
-
/// @param amount Amount of TBTC to mint
|
|
94
|
+
/// @param amount Amount of TBTC to mint.
|
|
63
95
|
function mint(uint256 amount) external {
|
|
64
96
|
address minter = msg.sender;
|
|
65
97
|
require(
|
|
@@ -70,13 +102,31 @@ contract TBTCVault is IVault {
|
|
|
70
102
|
bank.transferBalanceFrom(minter, address(this), amount);
|
|
71
103
|
}
|
|
72
104
|
|
|
105
|
+
/// @notice Transfers the given `amount` of the Bank balance from the caller
|
|
106
|
+
/// to TBTC Vault and mints `amount` of TBTC to the caller.
|
|
107
|
+
/// @dev Can only be called by the Bank via `approveBalanceAndCall`.
|
|
108
|
+
/// @param owner The owner who approved their Bank balance.
|
|
109
|
+
/// @param amount Amount of TBTC to mint.
|
|
110
|
+
function receiveBalanceApproval(
|
|
111
|
+
address owner,
|
|
112
|
+
uint256 amount,
|
|
113
|
+
bytes memory
|
|
114
|
+
) external override onlyBank {
|
|
115
|
+
require(
|
|
116
|
+
bank.balanceOf(owner) >= amount,
|
|
117
|
+
"Amount exceeds balance in the bank"
|
|
118
|
+
);
|
|
119
|
+
_mint(owner, amount);
|
|
120
|
+
bank.transferBalanceFrom(owner, address(this), amount);
|
|
121
|
+
}
|
|
122
|
+
|
|
73
123
|
/// @notice Mints the same amount of TBTC as the deposited amount for each
|
|
74
124
|
/// depositor in the array. Can only be called by the Bank after the
|
|
75
125
|
/// Bridge swept deposits and Bank increased balance for the
|
|
76
126
|
/// vault.
|
|
77
127
|
/// @dev Fails if `depositors` array is empty. Expects the length of
|
|
78
128
|
/// `depositors` and `depositedAmounts` is the same.
|
|
79
|
-
function
|
|
129
|
+
function receiveBalanceIncrease(
|
|
80
130
|
address[] calldata depositors,
|
|
81
131
|
uint256[] calldata depositedAmounts
|
|
82
132
|
) external override onlyBank {
|
|
@@ -90,7 +140,7 @@ contract TBTCVault is IVault {
|
|
|
90
140
|
/// `amount` back to the caller's balance in the Bank.
|
|
91
141
|
/// @dev Caller must have at least `amount` of TBTC approved to
|
|
92
142
|
/// TBTC Vault.
|
|
93
|
-
/// @param amount Amount of TBTC to redeem
|
|
143
|
+
/// @param amount Amount of TBTC to redeem.
|
|
94
144
|
function redeem(uint256 amount) external {
|
|
95
145
|
_redeem(msg.sender, amount);
|
|
96
146
|
}
|
|
@@ -100,9 +150,9 @@ contract TBTCVault is IVault {
|
|
|
100
150
|
/// @dev This function is doing the same as `redeem` but it allows to
|
|
101
151
|
/// execute redemption without an additional approval transaction.
|
|
102
152
|
/// The function can be called only via `approveAndCall` of TBTC token.
|
|
103
|
-
/// @param from TBTC token holder executing redemption
|
|
104
|
-
/// @param amount Amount of TBTC to redeem
|
|
105
|
-
/// @param token TBTC token address
|
|
153
|
+
/// @param from TBTC token holder executing redemption.
|
|
154
|
+
/// @param amount Amount of TBTC to redeem.
|
|
155
|
+
/// @param token TBTC token address.
|
|
106
156
|
function receiveApproval(
|
|
107
157
|
address from,
|
|
108
158
|
uint256 amount,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
5
|
+
const { getNamedAccounts, deployments, helpers } = hre
|
|
6
|
+
const { log } = deployments
|
|
7
|
+
const { deployer } = await getNamedAccounts()
|
|
8
|
+
|
|
9
|
+
const Relay = await deployments.getOrNull("Relay")
|
|
10
|
+
|
|
11
|
+
if (Relay && helpers.address.isValid(Relay.address)) {
|
|
12
|
+
log(`using external Relay at ${Relay.address}`)
|
|
13
|
+
} else if (hre.network.name !== "hardhat") {
|
|
14
|
+
throw new Error("deployed Relay contract not found")
|
|
15
|
+
} else {
|
|
16
|
+
log("deploying Relay stub")
|
|
17
|
+
|
|
18
|
+
await deployments.deploy("Relay", {
|
|
19
|
+
contract: "TestRelay",
|
|
20
|
+
from: deployer,
|
|
21
|
+
log: true,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default func
|
|
27
|
+
|
|
28
|
+
func.tags = ["Relay"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
5
|
+
const { deployments, getNamedAccounts } = hre
|
|
6
|
+
const { deploy } = deployments
|
|
7
|
+
const { deployer } = await getNamedAccounts()
|
|
8
|
+
|
|
9
|
+
const Bank = await deploy("Bank", {
|
|
10
|
+
contract:
|
|
11
|
+
deployments.getNetworkName() === "hardhat" ? "BankStub" : undefined,
|
|
12
|
+
from: deployer,
|
|
13
|
+
args: [],
|
|
14
|
+
log: true,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
if (hre.network.tags.tenderly) {
|
|
18
|
+
await hre.tenderly.verify({
|
|
19
|
+
name: "Bank",
|
|
20
|
+
address: Bank.address,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default func
|
|
26
|
+
|
|
27
|
+
func.tags = ["Bank"]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
5
|
+
const { ethers, helpers, deployments, getNamedAccounts } = hre
|
|
6
|
+
const { deploy } = deployments
|
|
7
|
+
const { deployer, treasury } = await getNamedAccounts()
|
|
8
|
+
|
|
9
|
+
const Bank = await deployments.get("Bank")
|
|
10
|
+
const Relay = await deployments.get("Relay")
|
|
11
|
+
|
|
12
|
+
// TODO: Test for mainnet deployment that when `WalletRegistry` is provided
|
|
13
|
+
// in `external/mainnet/` directory it gets resolved correctly, and the deployment
|
|
14
|
+
// script from `@keep-network/ecdsa` is not invoked once again.
|
|
15
|
+
const WalletRegistry = await deployments.get("WalletRegistry")
|
|
16
|
+
|
|
17
|
+
// For local tests use `1`.
|
|
18
|
+
const txProofDifficultyFactor =
|
|
19
|
+
deployments.getNetworkName() === "hardhat" ? 1 : 6
|
|
20
|
+
|
|
21
|
+
const Deposit = await deploy("Deposit", { from: deployer, log: true })
|
|
22
|
+
const DepositSweep = await deploy("DepositSweep", {
|
|
23
|
+
from: deployer,
|
|
24
|
+
log: true,
|
|
25
|
+
})
|
|
26
|
+
const Redemption = await deploy("Redemption", { from: deployer, log: true })
|
|
27
|
+
const Wallets = await deploy("Wallets", {
|
|
28
|
+
contract: "contracts/bridge/Wallets.sol:Wallets",
|
|
29
|
+
from: deployer,
|
|
30
|
+
log: true,
|
|
31
|
+
})
|
|
32
|
+
const Fraud = await deploy("Fraud", { from: deployer, log: true })
|
|
33
|
+
const MovingFunds = await deploy("MovingFunds", {
|
|
34
|
+
from: deployer,
|
|
35
|
+
log: true,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const bridge = await helpers.upgrades.deployProxy("Bridge", {
|
|
39
|
+
contractName:
|
|
40
|
+
deployments.getNetworkName() === "hardhat" ? "BridgeStub" : undefined,
|
|
41
|
+
initializerArgs: [
|
|
42
|
+
Bank.address,
|
|
43
|
+
Relay.address,
|
|
44
|
+
treasury,
|
|
45
|
+
WalletRegistry.address,
|
|
46
|
+
txProofDifficultyFactor,
|
|
47
|
+
],
|
|
48
|
+
factoryOpts: {
|
|
49
|
+
signer: await ethers.getSigner(deployer),
|
|
50
|
+
libraries: {
|
|
51
|
+
Deposit: Deposit.address,
|
|
52
|
+
DepositSweep: DepositSweep.address,
|
|
53
|
+
Redemption: Redemption.address,
|
|
54
|
+
Wallets: Wallets.address,
|
|
55
|
+
Fraud: Fraud.address,
|
|
56
|
+
MovingFunds: MovingFunds.address,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
proxyOpts: {
|
|
60
|
+
kind: "transparent",
|
|
61
|
+
// Allow external libraries linking. We need to ensure manually that the
|
|
62
|
+
// external libraries we link are upgrade safe, as the OpenZeppelin plugin
|
|
63
|
+
// doesn't perform such a validation yet.
|
|
64
|
+
// See: https://docs.openzeppelin.com/upgrades-plugins/1.x/faq#why-cant-i-use-external-libraries
|
|
65
|
+
unsafeAllow: ["external-library-linking"],
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
if (hre.network.tags.tenderly) {
|
|
70
|
+
await hre.tenderly.verify({
|
|
71
|
+
name: "Bridge",
|
|
72
|
+
address: bridge.address,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default func
|
|
78
|
+
|
|
79
|
+
func.tags = ["Bridge"]
|
|
80
|
+
func.dependencies = ["Bank", "Relay", "Treasury", "WalletRegistry"]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
5
|
+
const { deployments, getNamedAccounts } = hre
|
|
6
|
+
const { deploy } = deployments
|
|
7
|
+
const { deployer } = await getNamedAccounts()
|
|
8
|
+
|
|
9
|
+
const Bank = await deployments.get("Bank")
|
|
10
|
+
const TBTC = await deployments.get("TBTC")
|
|
11
|
+
|
|
12
|
+
const TBTCVault = await deploy("TBTCVault", {
|
|
13
|
+
contract: "TBTCVault",
|
|
14
|
+
from: deployer,
|
|
15
|
+
args: [Bank.address, TBTC.address],
|
|
16
|
+
log: true,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
if (hre.network.tags.tenderly) {
|
|
20
|
+
await hre.tenderly.verify({
|
|
21
|
+
name: "TBTCVault",
|
|
22
|
+
address: TBTCVault.address,
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default func
|
|
28
|
+
|
|
29
|
+
func.tags = ["TBTCVault"]
|
|
30
|
+
func.dependencies = ["Bank", "TBTC"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
5
|
+
const { getNamedAccounts, deployments } = hre
|
|
6
|
+
const { execute, log } = deployments
|
|
7
|
+
const { deployer } = await getNamedAccounts()
|
|
8
|
+
|
|
9
|
+
const Bridge = await deployments.get("Bridge")
|
|
10
|
+
|
|
11
|
+
log("updating Bridge in Bank")
|
|
12
|
+
|
|
13
|
+
await execute("Bank", { from: deployer }, "updateBridge", Bridge.address)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default func
|
|
17
|
+
|
|
18
|
+
func.tags = ["BankUpdateBridge"]
|
|
19
|
+
func.dependencies = ["Bank", "Bridge"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
5
|
+
const { getNamedAccounts, helpers } = hre
|
|
6
|
+
const { deployer, governance } = await getNamedAccounts()
|
|
7
|
+
|
|
8
|
+
await helpers.ownable.transferOwnership("Bank", governance, deployer)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default func
|
|
12
|
+
|
|
13
|
+
func.tags = ["TransferOwnership"]
|
|
14
|
+
func.dependencies = ["Bank"]
|
|
15
|
+
func.runAtTheEnd = true
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
5
|
+
const { getNamedAccounts, deployments } = hre
|
|
6
|
+
const { deployer, governance } = await getNamedAccounts()
|
|
7
|
+
|
|
8
|
+
await deployments.execute(
|
|
9
|
+
"Bridge",
|
|
10
|
+
{ from: deployer },
|
|
11
|
+
"transferGovernance",
|
|
12
|
+
governance
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default func
|
|
17
|
+
|
|
18
|
+
func.tags = ["TransferGovernance"]
|
|
19
|
+
func.dependencies = ["Bridge"]
|
|
20
|
+
func.runAtTheEnd = true
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import type { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
|
|
5
|
+
const { helpers, upgrades, deployments } = hre
|
|
6
|
+
const { esdm, deployer } = await helpers.signers.getNamedSigners()
|
|
7
|
+
const { log } = deployments
|
|
8
|
+
|
|
9
|
+
// TODO: Once a DAO is established we want to switch to ProxyAdminWithDeputy and
|
|
10
|
+
// use the DAO as the proxy admin owner and ESDM as the deputy. Until then we
|
|
11
|
+
// use ESDM as the owner of ProxyAdmin contract.
|
|
12
|
+
const newProxyAdminOwner = esdm.address
|
|
13
|
+
|
|
14
|
+
const proxyAdmin = await upgrades.admin.getInstance()
|
|
15
|
+
|
|
16
|
+
const currentOwner = await proxyAdmin.owner()
|
|
17
|
+
|
|
18
|
+
// The `@openzeppelin/hardhat-upgrades` plugin deploys a single ProxyAdmin
|
|
19
|
+
// per network. We don't want to transfer the ownership if the owner is already
|
|
20
|
+
// set to the desired address.
|
|
21
|
+
if (!helpers.address.equal(currentOwner, newProxyAdminOwner)) {
|
|
22
|
+
log(`transferring ownership of ProxyAdmin to ${newProxyAdminOwner}`)
|
|
23
|
+
await proxyAdmin.connect(deployer).transferOwnership(newProxyAdminOwner)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default func
|
|
28
|
+
|
|
29
|
+
func.tags = ["TransferProxyAdminOwnership"]
|
|
30
|
+
func.dependencies = ["Bridge"]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { HardhatRuntimeEnvironment } from "hardhat/types"
|
|
2
|
+
import type { DeployFunction } from "hardhat-deploy/types"
|
|
3
|
+
|
|
4
|
+
const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
|
|
5
|
+
const { ethers, getNamedAccounts, upgrades, deployments } = hre
|
|
6
|
+
const { deployer, dao, esdm } = await getNamedAccounts()
|
|
7
|
+
|
|
8
|
+
const BridgeProxyAdminWithDeputy = await deployments.deploy(
|
|
9
|
+
"BridgeProxyAdminWithDeputy",
|
|
10
|
+
{
|
|
11
|
+
contract: "ProxyAdminWithDeputy",
|
|
12
|
+
from: deployer,
|
|
13
|
+
args: [dao, esdm],
|
|
14
|
+
log: true,
|
|
15
|
+
}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const Bridge = await deployments.get("Bridge")
|
|
19
|
+
|
|
20
|
+
const proxyAdmin = await upgrades.admin.getInstance()
|
|
21
|
+
|
|
22
|
+
await proxyAdmin
|
|
23
|
+
.connect(await ethers.getSigner(esdm))
|
|
24
|
+
.changeProxyAdmin(Bridge.address, BridgeProxyAdminWithDeputy.address)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default func
|
|
28
|
+
|
|
29
|
+
func.tags = ["BridgeProxyAdminWithDeputy"]
|
|
30
|
+
func.dependencies = ["Bridge"]
|
|
31
|
+
|
|
32
|
+
// TODO: For now we skip this script as DAO is not yet established.
|
|
33
|
+
func.skip = async () => true
|