@keep-network/tbtc-v2 0.1.1-dev.3 → 0.1.1-dev.4

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.
@@ -15,6 +15,7 @@
15
15
 
16
16
  pragma solidity 0.8.4;
17
17
 
18
+ import "./IVault.sol";
18
19
  import "../bank/Bank.sol";
19
20
  import "../token/TBTC.sol";
20
21
 
@@ -26,7 +27,7 @@ import "../token/TBTC.sol";
26
27
  /// Bank.
27
28
  /// @dev TBTC Vault is the owner of TBTC token contract and is the only contract
28
29
  /// minting the token.
29
- contract TBTCVault {
30
+ contract TBTCVault is IVault {
30
31
  Bank public bank;
31
32
  TBTC public tbtcToken;
32
33
 
@@ -34,6 +35,11 @@ contract TBTCVault {
34
35
 
35
36
  event Redeemed(address indexed from, uint256 amount);
36
37
 
38
+ modifier onlyBank() {
39
+ require(msg.sender == address(bank), "Caller is not the Bank");
40
+ _;
41
+ }
42
+
37
43
  constructor(Bank _bank, TBTC _tbtcToken) {
38
44
  require(
39
45
  address(_bank) != address(0),
@@ -55,7 +61,29 @@ contract TBTCVault {
55
61
  /// for at least `amount`.
56
62
  /// @param amount Amount of TBTC to mint
57
63
  function mint(uint256 amount) external {
58
- _mint(msg.sender, amount);
64
+ address minter = msg.sender;
65
+ require(
66
+ bank.balanceOf(minter) >= amount,
67
+ "Amount exceeds balance in the bank"
68
+ );
69
+ _mint(minter, amount);
70
+ bank.transferBalanceFrom(minter, address(this), amount);
71
+ }
72
+
73
+ /// @notice Mints the same amount of TBTC as the deposited amount for each
74
+ /// depositor in the array. Can only be called by the Bank after the
75
+ /// Bridge swept deposits and Bank increased balance for the
76
+ /// vault.
77
+ /// @dev Fails if `depositors` array is empty. Expects the length of
78
+ /// `depositors` and `depositedAmounts` is the same.
79
+ function onBalanceIncreased(
80
+ address[] calldata depositors,
81
+ uint256[] calldata depositedAmounts
82
+ ) external override onlyBank {
83
+ require(depositors.length != 0, "No depositors specified");
84
+ for (uint256 i = 0; i < depositors.length; i++) {
85
+ _mint(depositors[i], depositedAmounts[i]);
86
+ }
59
87
  }
60
88
 
61
89
  /// @notice Burns `amount` of TBTC from the caller's account and transfers
@@ -86,13 +114,9 @@ contract TBTCVault {
86
114
  _redeem(from, amount);
87
115
  }
88
116
 
117
+ // slither-disable-next-line calls-loop
89
118
  function _mint(address minter, uint256 amount) internal {
90
- require(
91
- bank.balanceOf(minter) >= amount,
92
- "Amount exceeds balance in the bank"
93
- );
94
119
  emit Minted(minter, amount);
95
- bank.transferBalanceFrom(minter, address(this), amount);
96
120
  tbtcToken.mint(minter, amount);
97
121
  }
98
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keep-network/tbtc-v2",
3
- "version": "0.1.1-dev.3+main.653c854b1f5ee8e14afc2124201abb620500c772",
3
+ "version": "0.1.1-dev.4+main.eb81aee2070bc7ec075c974011ac571313a5bfd7",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "artifacts/",