@keep-network/tbtc-v2 0.1.1-dev.1 → 0.1.1-dev.5
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/artifacts/TBTC.json +3 -3
- package/artifacts/TBTCToken.json +3 -3
- package/artifacts/VendingMachine.json +10 -10
- package/artifacts/solcInputs/{0c46d22cee2363c42c8bb0664dc1be66.json → d71966212a658480bad5748ad85b1396.json} +29 -17
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +4 -0
- package/build/contracts/bank/Bank.sol/Bank.json +519 -0
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +4 -0
- package/build/contracts/bridge/Bridge.sol/Bridge.json +176 -0
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +4 -0
- package/build/contracts/vault/IVault.sol/IVault.json +29 -0
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +4 -0
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +163 -0
- package/contracts/bank/Bank.sol +374 -0
- package/contracts/bridge/Bridge.sol +176 -0
- package/contracts/vault/IVault.sol +38 -0
- package/contracts/vault/TBTCVault.sol +128 -0
- package/package.json +3 -3
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
// ██████████████ ▐████▌ ██████████████
|
|
4
|
+
// ██████████████ ▐████▌ ██████████████
|
|
5
|
+
// ▐████▌ ▐████▌
|
|
6
|
+
// ▐████▌ ▐████▌
|
|
7
|
+
// ██████████████ ▐████▌ ██████████████
|
|
8
|
+
// ██████████████ ▐████▌ ██████████████
|
|
9
|
+
// ▐████▌ ▐████▌
|
|
10
|
+
// ▐████▌ ▐████▌
|
|
11
|
+
// ▐████▌ ▐████▌
|
|
12
|
+
// ▐████▌ ▐████▌
|
|
13
|
+
// ▐████▌ ▐████▌
|
|
14
|
+
// ▐████▌ ▐████▌
|
|
15
|
+
|
|
16
|
+
pragma solidity 0.8.4;
|
|
17
|
+
|
|
18
|
+
import "./IVault.sol";
|
|
19
|
+
import "../bank/Bank.sol";
|
|
20
|
+
import "../token/TBTC.sol";
|
|
21
|
+
|
|
22
|
+
/// @title TBTC application vault
|
|
23
|
+
/// @notice TBTC is a fully Bitcoin-backed ERC-20 token pegged to the price of
|
|
24
|
+
/// Bitcoin. It facilitates Bitcoin holders to act on the Ethereum
|
|
25
|
+
/// blockchain and access the decentralized finance (DeFi) ecosystem.
|
|
26
|
+
/// TBTC Vault mints and redeems TBTC based on Bitcoin balances in the
|
|
27
|
+
/// Bank.
|
|
28
|
+
/// @dev TBTC Vault is the owner of TBTC token contract and is the only contract
|
|
29
|
+
/// minting the token.
|
|
30
|
+
contract TBTCVault is IVault {
|
|
31
|
+
Bank public bank;
|
|
32
|
+
TBTC public tbtcToken;
|
|
33
|
+
|
|
34
|
+
event Minted(address indexed to, uint256 amount);
|
|
35
|
+
|
|
36
|
+
event Redeemed(address indexed from, uint256 amount);
|
|
37
|
+
|
|
38
|
+
modifier onlyBank() {
|
|
39
|
+
require(msg.sender == address(bank), "Caller is not the Bank");
|
|
40
|
+
_;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
constructor(Bank _bank, TBTC _tbtcToken) {
|
|
44
|
+
require(
|
|
45
|
+
address(_bank) != address(0),
|
|
46
|
+
"Bank can not be the zero address"
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
require(
|
|
50
|
+
address(_tbtcToken) != address(0),
|
|
51
|
+
"TBTC token can not be the zero address"
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
bank = _bank;
|
|
55
|
+
tbtcToken = _tbtcToken;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// @notice Transfers the given `amount` of the Bank balance from caller
|
|
59
|
+
/// to TBTC Vault, and mints `amount` of TBTC to the caller.
|
|
60
|
+
/// @dev TBTC Vault must have an allowance for caller's balance in the Bank
|
|
61
|
+
/// for at least `amount`.
|
|
62
|
+
/// @param amount Amount of TBTC to mint
|
|
63
|
+
function mint(uint256 amount) external {
|
|
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
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/// @notice Burns `amount` of TBTC from the caller's account and transfers
|
|
90
|
+
/// `amount` back to the caller's balance in the Bank.
|
|
91
|
+
/// @dev Caller must have at least `amount` of TBTC approved to
|
|
92
|
+
/// TBTC Vault.
|
|
93
|
+
/// @param amount Amount of TBTC to redeem
|
|
94
|
+
function redeem(uint256 amount) external {
|
|
95
|
+
_redeem(msg.sender, amount);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// @notice Burns `amount` of TBTC from the caller's account and transfers
|
|
99
|
+
/// `amount` back to the caller's balance in the Bank.
|
|
100
|
+
/// @dev This function is doing the same as `redeem` but it allows to
|
|
101
|
+
/// execute redemption without an additional approval transaction.
|
|
102
|
+
/// 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
|
|
106
|
+
function receiveApproval(
|
|
107
|
+
address from,
|
|
108
|
+
uint256 amount,
|
|
109
|
+
address token,
|
|
110
|
+
bytes calldata
|
|
111
|
+
) external {
|
|
112
|
+
require(token == address(tbtcToken), "Token is not TBTC");
|
|
113
|
+
require(msg.sender == token, "Only TBTC caller allowed");
|
|
114
|
+
_redeem(from, amount);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// slither-disable-next-line calls-loop
|
|
118
|
+
function _mint(address minter, uint256 amount) internal {
|
|
119
|
+
emit Minted(minter, amount);
|
|
120
|
+
tbtcToken.mint(minter, amount);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function _redeem(address redeemer, uint256 amount) internal {
|
|
124
|
+
emit Redeemed(redeemer, amount);
|
|
125
|
+
tbtcToken.burnFrom(redeemer, amount);
|
|
126
|
+
bank.transferBalance(redeemer, amount);
|
|
127
|
+
}
|
|
128
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keep-network/tbtc-v2",
|
|
3
|
-
"version": "0.1.1-dev.
|
|
3
|
+
"version": "0.1.1-dev.5+main.3acedd01fc600bf979696aa8c68149bd44794418",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"artifacts/",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"prepublishOnly": "./scripts/prepare-artifacts.sh --network $npm_config_network"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@keep-network/tbtc": ">1.1.2-dev <1.1.2-
|
|
29
|
+
"@keep-network/tbtc": ">1.1.2-dev <1.1.2-pre",
|
|
30
30
|
"@openzeppelin/contracts": "^4.1.0",
|
|
31
31
|
"@tenderly/hardhat-tenderly": "^1.0.12",
|
|
32
32
|
"@thesis/solidity-contracts": "github:thesis/solidity-contracts#4985bcf"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@keep-network/hardhat-helpers": "
|
|
35
|
+
"@keep-network/hardhat-helpers": "0.4.1-pre.1",
|
|
36
36
|
"@keep-network/hardhat-local-networks-config": "^0.1.0-pre.0",
|
|
37
37
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
|
38
38
|
"@nomiclabs/hardhat-etherscan": "^2.1.4",
|