@keep-network/tbtc-v2 0.1.1-dev.76 → 0.1.1-dev.79

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 (84) hide show
  1. package/artifacts/Bank.json +32 -27
  2. package/artifacts/Bridge.json +34 -34
  3. package/artifacts/Deposit.json +10 -10
  4. package/artifacts/DepositSweep.json +10 -10
  5. package/artifacts/EcdsaDkgValidator.json +16 -17
  6. package/artifacts/EcdsaInactivity.json +6 -6
  7. package/artifacts/EcdsaSortitionPool.json +1004 -0
  8. package/artifacts/Fraud.json +10 -10
  9. package/artifacts/KeepRegistry.json +1 -1
  10. package/artifacts/KeepStake.json +2 -2
  11. package/artifacts/KeepToken.json +2 -2
  12. package/artifacts/KeepTokenStaking.json +1 -1
  13. package/artifacts/MovingFunds.json +10 -10
  14. package/artifacts/NuCypherStakingEscrow.json +1 -1
  15. package/artifacts/NuCypherToken.json +2 -2
  16. package/artifacts/RandomBeaconStub.json +6 -6
  17. package/artifacts/Redemption.json +10 -10
  18. package/artifacts/ReimbursementPool.json +24 -24
  19. package/artifacts/Relay.json +12 -12
  20. package/artifacts/T.json +2 -2
  21. package/artifacts/TBTC.json +19 -19
  22. package/artifacts/TBTCToken.json +19 -19
  23. package/artifacts/TokenStaking.json +1 -1
  24. package/artifacts/TokenholderGovernor.json +9 -9
  25. package/artifacts/TokenholderTimelock.json +8 -8
  26. package/artifacts/VendingMachine.json +24 -24
  27. package/artifacts/VendingMachineKeep.json +1 -1
  28. package/artifacts/VendingMachineNuCypher.json +1 -1
  29. package/artifacts/WalletRegistry.json +893 -1167
  30. package/artifacts/WalletRegistryGovernance.json +2754 -0
  31. package/artifacts/Wallets.json +10 -10
  32. package/artifacts/solcInputs/{49c80d59bf0ae61f27a8bb5db19af68a.json → 4f6d4f5cd1e3d835e20ed55926a445cd.json} +113 -74
  33. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  34. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  35. package/build/contracts/bank/Bank.sol/Bank.json +8 -3
  36. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +4 -0
  37. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.json +34 -0
  38. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  39. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  40. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  41. package/build/contracts/bridge/Bridge.sol/Bridge.json +2 -2
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  43. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +2 -2
  44. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  45. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  46. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +1 -1
  47. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +2 -2
  48. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  49. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  50. package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -2
  51. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +1 -1
  52. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  53. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  54. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +2 -2
  55. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
  56. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +2 -2
  57. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
  58. package/build/contracts/bridge/Redemption.sol/Redemption.json +2 -2
  59. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  60. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  61. package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
  62. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  63. package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +1 -1
  64. package/build/contracts/vault/DonationVault.sol/DonationVault.json +7 -2
  65. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  66. package/build/contracts/vault/IVault.sol/IVault.json +5 -0
  67. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  68. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +7 -2
  69. package/contracts/bank/Bank.sol +18 -9
  70. package/contracts/bank/IReceiveBalanceApproval.sol +45 -0
  71. package/contracts/hardhat-dependency-compiler/@keep-network/ecdsa/contracts/WalletRegistry.sol +3 -0
  72. package/contracts/vault/DonationVault.sol +5 -5
  73. package/contracts/vault/IVault.sol +3 -19
  74. package/contracts/vault/TBTCVault.sol +5 -5
  75. package/deploy/05_deploy_bridge.ts +5 -1
  76. package/deploy/09_transfer_proxy_admin_ownership.ts +15 -8
  77. package/export.json +2527 -3066
  78. package/package.json +1 -1
  79. package/artifacts/DefaultProxyAdmin.json +0 -259
  80. package/artifacts/SortitionPool.json +0 -1005
  81. package/artifacts/WalletRegistry_Implementation.json +0 -2824
  82. package/artifacts/WalletRegistry_Proxy.json +0 -259
  83. package/artifacts/solcInputs/1635d55d57a0a2552952c0d22586ed23.json +0 -56
  84. package/deploy/00_resolve_wallet_registry.ts +0 -83
@@ -17,6 +17,7 @@ pragma solidity ^0.8.9;
17
17
 
18
18
  import "@openzeppelin/contracts/access/Ownable.sol";
19
19
 
20
+ import "./IReceiveBalanceApproval.sol";
20
21
  import "../vault/IVault.sol";
21
22
 
22
23
  /// @title Bitcoin Bank
@@ -114,19 +115,27 @@ contract Bank is Ownable {
114
115
  _approveBalance(msg.sender, spender, amount);
115
116
  }
116
117
 
117
- /// @notice Sets `amount` as the allowance of a smart contract `vault` over
118
- /// the caller's balance and calls the vault via
118
+ /// @notice Sets the `amount` as an allowance of a smart contract `spender`
119
+ /// over the caller's balance and calls the `spender` via
119
120
  /// `receiveBalanceApproval`.
120
- /// @dev If the `amount` is set to `type(uint256).max` then the logic in
121
- /// `receiveBalanceApproval` or later call to `transferBalanceFrom` by
122
- /// the vault will not reduce an allowance. Beware that changing an
123
- /// allowance with this function brings the risk that vault may use
121
+ /// @dev If the `amount` is set to `type(uint256).max`, the potential
122
+ /// `transferBalanceFrom` executed in `receiveBalanceApproval` of
123
+ /// `spender` will not reduce an allowance. Beware that changing an
124
+ /// allowance with this function brings the risk that `spender` may use
124
125
  /// both the old and the new allowance by unfortunate transaction
125
126
  /// ordering. Please use `increaseBalanceAllowance` and
126
127
  /// `decreaseBalanceAllowance` to eliminate the risk.
127
- function approveBalanceAndCall(address vault, uint256 amount) external {
128
- _approveBalance(msg.sender, vault, amount);
129
- IVault(vault).receiveBalanceApproval(msg.sender, amount);
128
+ function approveBalanceAndCall(
129
+ address spender,
130
+ uint256 amount,
131
+ bytes memory extraData
132
+ ) external {
133
+ _approveBalance(msg.sender, spender, amount);
134
+ IReceiveBalanceApproval(spender).receiveBalanceApproval(
135
+ msg.sender,
136
+ amount,
137
+ extraData
138
+ );
130
139
  }
131
140
 
132
141
  /// @notice Atomically increases the balance allowance granted to `spender`
@@ -0,0 +1,45 @@
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 IReceiveBalanceApproval
19
+ /// @notice `IReceiveBalanceApproval` is an interface for a smart contract
20
+ /// consuming Bank balances approved to them in the same transaction by
21
+ /// other contracts or externally owned accounts (EOA).
22
+ interface IReceiveBalanceApproval {
23
+ /// @notice Called by the Bank in `approveBalanceAndCall` function after
24
+ /// the balance `owner` approved `amount` of their balance in the
25
+ /// Bank for the contract. This way, the depositor can approve
26
+ /// balance and call the contract to use the approved balance in
27
+ /// a single transaction.
28
+ /// @param owner Address of the Bank balance owner who approved their
29
+ /// balance to be used by the contract.
30
+ /// @param amount The amount of the Bank balance approved by the owner
31
+ /// to be used by the contract.
32
+ /// @param extraData The `extraData` passed to `Bank.approveBalanceAndCall`.
33
+ // @dev The implementation must ensure this function can only be called
34
+ /// by the Bank. The Bank does _not_ guarantee that the `amount`
35
+ /// approved by the `owner` currently exists on their balance. That is,
36
+ /// the `owner` could approve more balance than they currently have.
37
+ /// This works the same as `Bank.approve` function. The contract must
38
+ /// ensure the actual balance is checked before performing any action
39
+ /// based on it.
40
+ function receiveBalanceApproval(
41
+ address owner,
42
+ uint256 amount,
43
+ bytes memory extraData
44
+ ) external;
45
+ }
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity >0.0.0;
3
+ import '@keep-network/ecdsa/contracts/WalletRegistry.sol';
@@ -80,11 +80,11 @@ contract DonationVault is IVault {
80
80
  /// - Can only be called by the Bank via `approveBalanceAndCall`,
81
81
  /// - The `owner` balance in the Bank must be greater than or equal
82
82
  /// to the `amount`.
83
- function receiveBalanceApproval(address owner, uint256 amount)
84
- external
85
- override
86
- onlyBank
87
- {
83
+ function receiveBalanceApproval(
84
+ address owner,
85
+ uint256 amount,
86
+ bytes memory
87
+ ) external override onlyBank {
88
88
  require(
89
89
  bank.balanceOf(owner) >= amount,
90
90
  "Amount exceeds balance in the bank"
@@ -15,28 +15,12 @@
15
15
 
16
16
  pragma solidity ^0.8.9;
17
17
 
18
+ import "../bank/IReceiveBalanceApproval.sol";
19
+
18
20
  /// @title Bank Vault interface
19
21
  /// @notice `IVault` is an interface for a smart contract consuming Bank
20
22
  /// balances of other contracts or externally owned accounts (EOA).
21
- interface IVault {
22
- /// @notice Called by the Bank in `approveBalanceAndCall` function after
23
- /// the balance `owner` approved `amount` of their balance in the
24
- /// Bank for the vault. This way, the depositor can approve balance
25
- /// and call the vault to use the approved balance in a single
26
- /// transaction.
27
- /// @param owner Address of the Bank balance owner who approved their
28
- /// balance to be used by the vault.
29
- /// @param amount The amount of the Bank balance approved by the owner
30
- /// to be used by the vault.
31
- // @dev The implementation must ensure this function can only be called
32
- /// by the Bank. The Bank does _not_ guarantee that the `amount`
33
- /// approved by the `owner` currently exists on their balance. That is,
34
- /// the `owner` could approve more balance than they currently have.
35
- /// This works the same as `Bank.approve` function. The vault must
36
- /// ensure the actual balance is checked before performing any action
37
- /// based on it.
38
- function receiveBalanceApproval(address owner, uint256 amount) external;
39
-
23
+ interface IVault is IReceiveBalanceApproval {
40
24
  /// @notice Called by the Bank in `increaseBalanceAndCall` function after
41
25
  /// increasing the balance in the Bank for the vault. It happens in
42
26
  /// the same transaction in which deposits were swept by the Bridge.
@@ -107,11 +107,11 @@ contract TBTCVault is IVault, Governable {
107
107
  /// @dev Can only be called by the Bank via `approveBalanceAndCall`.
108
108
  /// @param owner The owner who approved their Bank balance.
109
109
  /// @param amount Amount of TBTC to mint.
110
- function receiveBalanceApproval(address owner, uint256 amount)
111
- external
112
- override
113
- onlyBank
114
- {
110
+ function receiveBalanceApproval(
111
+ address owner,
112
+ uint256 amount,
113
+ bytes memory
114
+ ) external override onlyBank {
115
115
  require(
116
116
  bank.balanceOf(owner) >= amount,
117
117
  "Amount exceeds balance in the bank"
@@ -24,7 +24,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
24
24
  log: true,
25
25
  })
26
26
  const Redemption = await deploy("Redemption", { from: deployer, log: true })
27
- const Wallets = await deploy("Wallets", { from: deployer, log: true })
27
+ const Wallets = await deploy("Wallets", {
28
+ contract: "contracts/bridge/Wallets.sol:Wallets",
29
+ from: deployer,
30
+ log: true,
31
+ })
28
32
  const Fraud = await deploy("Fraud", { from: deployer, log: true })
29
33
  const MovingFunds = await deploy("MovingFunds", {
30
34
  from: deployer,
@@ -2,19 +2,26 @@ import type { HardhatRuntimeEnvironment } from "hardhat/types"
2
2
  import type { DeployFunction } from "hardhat-deploy/types"
3
3
 
4
4
  const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
5
- const { ethers, helpers, getNamedAccounts, upgrades, deployments } = hre
6
- const { esdm } = await getNamedAccounts()
7
- const { deployer } = await helpers.signers.getNamedSigners()
5
+ const { helpers, upgrades, deployments } = hre
6
+ const { esdm, deployer } = await helpers.signers.getNamedSigners()
7
+ const { log } = deployments
8
8
 
9
9
  // TODO: Once a DAO is established we want to switch to ProxyAdminWithDeputy and
10
10
  // use the DAO as the proxy admin owner and ESDM as the deputy. Until then we
11
- // use governance as the owner of ProxyAdmin contract.
12
- const newProxyAdminOwner = esdm
13
-
14
- deployments.log(`transferring ProxyAdmin ownership to ${newProxyAdminOwner}`)
11
+ // use ESDM as the owner of ProxyAdmin contract.
12
+ const newProxyAdminOwner = esdm.address
15
13
 
16
14
  const proxyAdmin = await upgrades.admin.getInstance()
17
- await proxyAdmin.connect(deployer).transferOwnership(newProxyAdminOwner)
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
+ }
18
25
  }
19
26
 
20
27
  export default func