@keep-network/tbtc-v2 0.1.1-dev.0 → 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.
- package/artifacts/TBTC.json +17 -17
- package/artifacts/TBTCToken.json +17 -17
- package/artifacts/VendingMachine.json +16 -16
- package/artifacts/solcInputs/{7cc3eda3cb3ff2522d18b5e7b31ea228.json → d71966212a658480bad5748ad85b1396.json} +31 -19
- 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/bridge/VendingMachine.sol/VendingMachine.json +2 -2
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/token/TBTC.sol/TBTC.json +4 -4
- 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/deploy/00_resolve_tbtc_v1_token.ts +1 -1
- package/export.json +4 -4
- package/package.json +23 -14
|
@@ -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
|
+
}
|
|
@@ -13,7 +13,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
|
|
|
13
13
|
} else if (hre.network.name !== "hardhat") {
|
|
14
14
|
throw new Error("deployed TBTCToken contract not found")
|
|
15
15
|
} else {
|
|
16
|
-
log(
|
|
16
|
+
log("deploying TBTCToken stub")
|
|
17
17
|
|
|
18
18
|
await deployments.deploy("TBTCToken", {
|
|
19
19
|
contract: "TestERC20",
|
package/export.json
CHANGED
|
@@ -336,7 +336,7 @@
|
|
|
336
336
|
"type": "address"
|
|
337
337
|
}
|
|
338
338
|
],
|
|
339
|
-
"name": "
|
|
339
|
+
"name": "nonce",
|
|
340
340
|
"outputs": [
|
|
341
341
|
{
|
|
342
342
|
"internalType": "uint256",
|
|
@@ -464,7 +464,7 @@
|
|
|
464
464
|
"inputs": [
|
|
465
465
|
{
|
|
466
466
|
"internalType": "address",
|
|
467
|
-
"name": "
|
|
467
|
+
"name": "spender",
|
|
468
468
|
"type": "address"
|
|
469
469
|
},
|
|
470
470
|
{
|
|
@@ -812,7 +812,7 @@
|
|
|
812
812
|
"type": "address"
|
|
813
813
|
}
|
|
814
814
|
],
|
|
815
|
-
"name": "
|
|
815
|
+
"name": "nonce",
|
|
816
816
|
"outputs": [
|
|
817
817
|
{
|
|
818
818
|
"internalType": "uint256",
|
|
@@ -991,7 +991,7 @@
|
|
|
991
991
|
"inputs": [
|
|
992
992
|
{
|
|
993
993
|
"internalType": "address",
|
|
994
|
-
"name": "
|
|
994
|
+
"name": "spender",
|
|
995
995
|
"type": "address"
|
|
996
996
|
},
|
|
997
997
|
{
|
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.4+main.eb81aee2070bc7ec075c974011ac571313a5bfd7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"artifacts/",
|
|
@@ -11,15 +11,16 @@
|
|
|
11
11
|
"export.json"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
+
"clean": "hardhat clean",
|
|
14
15
|
"build": "hardhat compile",
|
|
15
16
|
"deploy": "hardhat deploy --export export.json",
|
|
16
17
|
"format": "npm run lint && prettier --check .",
|
|
17
18
|
"format:fix": "npm run lint:fix && prettier --write .",
|
|
18
|
-
"lint": "npm run lint:
|
|
19
|
-
"lint:
|
|
19
|
+
"lint": "npm run lint:eslint && npm run lint:sol",
|
|
20
|
+
"lint:fix": "npm run lint:fix:eslint && npm run lint:fix:sol",
|
|
21
|
+
"lint:eslint": "eslint .",
|
|
22
|
+
"lint:fix:eslint": "eslint . --fix",
|
|
20
23
|
"lint:sol": "solhint 'contracts/**/*.sol'",
|
|
21
|
-
"lint:fix": "npm run lint:fix:js && npm run lint:fix:sol",
|
|
22
|
-
"lint:fix:js": "eslint . --fix",
|
|
23
24
|
"lint:fix:sol": "solhint 'contracts/**/*.sol' --fix",
|
|
24
25
|
"test": "hardhat test",
|
|
25
26
|
"prepublishOnly": "./scripts/prepare-artifacts.sh --network $npm_config_network"
|
|
@@ -28,28 +29,36 @@
|
|
|
28
29
|
"@keep-network/tbtc": ">1.1.2-dev <1.1.2-ropsten",
|
|
29
30
|
"@openzeppelin/contracts": "^4.1.0",
|
|
30
31
|
"@tenderly/hardhat-tenderly": "^1.0.12",
|
|
31
|
-
"@thesis/solidity-contracts": "github:thesis/solidity-contracts#
|
|
32
|
+
"@thesis/solidity-contracts": "github:thesis/solidity-contracts#4985bcf"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@keep-network/hardhat-helpers": "
|
|
35
|
+
"@keep-network/hardhat-helpers": "0.4.1-pre.1",
|
|
35
36
|
"@keep-network/hardhat-local-networks-config": "^0.1.0-pre.0",
|
|
36
37
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
|
37
38
|
"@nomiclabs/hardhat-etherscan": "^2.1.4",
|
|
38
39
|
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
|
40
|
+
"@thesis-co/eslint-config": "github:thesis/eslint-config",
|
|
41
|
+
"@typechain/ethers-v5": "^7.2.0",
|
|
42
|
+
"@typechain/hardhat": "^2.3.1",
|
|
43
|
+
"@types/chai": "^4.2.22",
|
|
44
|
+
"@types/mocha": "^9.0.0",
|
|
45
|
+
"@types/node": "^16.10.5",
|
|
39
46
|
"chai": "^4.3.4",
|
|
40
|
-
"eslint": "^7.
|
|
41
|
-
"eslint-config-keep": "github:keep-network/eslint-config-keep#
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
47
|
+
"eslint": "^7.30.0",
|
|
48
|
+
"eslint-config-keep": "github:keep-network/eslint-config-keep#0c27ade",
|
|
49
|
+
"eslint-plugin-import": "^2.18.2",
|
|
50
|
+
"ethereum-waffle": "^3.4.0",
|
|
51
|
+
"ethers": "^5.4.7",
|
|
52
|
+
"hardhat": "^2.6.4",
|
|
45
53
|
"hardhat-deploy": "^0.8.11",
|
|
46
54
|
"hardhat-gas-reporter": "^1.0.4",
|
|
47
55
|
"prettier": "^2.3.0",
|
|
48
56
|
"prettier-plugin-solidity": "^1.0.0-beta.11 ",
|
|
49
57
|
"solhint": "^3.3.6",
|
|
50
58
|
"solhint-config-keep": "github:keep-network/solhint-config-keep",
|
|
51
|
-
"ts-node": "^10.1
|
|
52
|
-
"
|
|
59
|
+
"ts-node": "^10.2.1",
|
|
60
|
+
"typechain": "^5.2.0",
|
|
61
|
+
"typescript": "^4.4.3"
|
|
53
62
|
},
|
|
54
63
|
"engines": {
|
|
55
64
|
"node": ">= 14.0.0"
|