@keep-network/tbtc-v2 0.1.1-ropsten.4 → 0.1.1-ropsten.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 +16 -16
- package/artifacts/VendingMachine.json +26 -26
- package/artifacts/solcInputs/{0c46d22cee2363c42c8bb0664dc1be66.json → 02b9e185d8beb23545e98201d474fc6b.json} +3 -0
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- 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/contracts/bridge/Bridge.sol +161 -0
- package/export.json +25 -25
- package/package.json +2 -2
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_format": "hh-sol-artifact-1",
|
|
3
|
+
"contractName": "Bridge",
|
|
4
|
+
"sourceName": "contracts/bridge/Bridge.sol",
|
|
5
|
+
"abi": [
|
|
6
|
+
{
|
|
7
|
+
"anonymous": false,
|
|
8
|
+
"inputs": [
|
|
9
|
+
{
|
|
10
|
+
"indexed": false,
|
|
11
|
+
"internalType": "uint256",
|
|
12
|
+
"name": "depositId",
|
|
13
|
+
"type": "uint256"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"indexed": false,
|
|
17
|
+
"internalType": "bytes32",
|
|
18
|
+
"name": "fundingTxHash",
|
|
19
|
+
"type": "bytes32"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"indexed": false,
|
|
23
|
+
"internalType": "uint8",
|
|
24
|
+
"name": "fundingOutputIndex",
|
|
25
|
+
"type": "uint8"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"indexed": false,
|
|
29
|
+
"internalType": "address",
|
|
30
|
+
"name": "depositor",
|
|
31
|
+
"type": "address"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"indexed": false,
|
|
35
|
+
"internalType": "uint64",
|
|
36
|
+
"name": "blindingFactor",
|
|
37
|
+
"type": "uint64"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"indexed": false,
|
|
41
|
+
"internalType": "bytes",
|
|
42
|
+
"name": "refundPubKey",
|
|
43
|
+
"type": "bytes"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"indexed": false,
|
|
47
|
+
"internalType": "uint64",
|
|
48
|
+
"name": "amount",
|
|
49
|
+
"type": "uint64"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"indexed": false,
|
|
53
|
+
"internalType": "address",
|
|
54
|
+
"name": "vault",
|
|
55
|
+
"type": "address"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"name": "DepositRevealed",
|
|
59
|
+
"type": "event"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"inputs": [
|
|
63
|
+
{
|
|
64
|
+
"internalType": "bytes32",
|
|
65
|
+
"name": "fundingTxHash",
|
|
66
|
+
"type": "bytes32"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"internalType": "uint8",
|
|
70
|
+
"name": "fundingOutputIndex",
|
|
71
|
+
"type": "uint8"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"internalType": "uint64",
|
|
75
|
+
"name": "blindingFactor",
|
|
76
|
+
"type": "uint64"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"internalType": "bytes",
|
|
80
|
+
"name": "refundPubKey",
|
|
81
|
+
"type": "bytes"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"internalType": "uint64",
|
|
85
|
+
"name": "amount",
|
|
86
|
+
"type": "uint64"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"internalType": "address",
|
|
90
|
+
"name": "vault",
|
|
91
|
+
"type": "address"
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"name": "revealDeposit",
|
|
95
|
+
"outputs": [],
|
|
96
|
+
"stateMutability": "nonpayable",
|
|
97
|
+
"type": "function"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"inputs": [
|
|
101
|
+
{
|
|
102
|
+
"internalType": "bytes4",
|
|
103
|
+
"name": "txVersion",
|
|
104
|
+
"type": "bytes4"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"internalType": "bytes",
|
|
108
|
+
"name": "txInputVector",
|
|
109
|
+
"type": "bytes"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"internalType": "bytes",
|
|
113
|
+
"name": "txOutput",
|
|
114
|
+
"type": "bytes"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"internalType": "bytes4",
|
|
118
|
+
"name": "txLocktime",
|
|
119
|
+
"type": "bytes4"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"internalType": "bytes",
|
|
123
|
+
"name": "merkleProof",
|
|
124
|
+
"type": "bytes"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"internalType": "uint256",
|
|
128
|
+
"name": "txIndexInBlock",
|
|
129
|
+
"type": "uint256"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"internalType": "bytes",
|
|
133
|
+
"name": "bitcoinHeaders",
|
|
134
|
+
"type": "bytes"
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"name": "sweep",
|
|
138
|
+
"outputs": [],
|
|
139
|
+
"stateMutability": "nonpayable",
|
|
140
|
+
"type": "function"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"inputs": [
|
|
144
|
+
{
|
|
145
|
+
"internalType": "uint256",
|
|
146
|
+
"name": "",
|
|
147
|
+
"type": "uint256"
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"name": "unswept",
|
|
151
|
+
"outputs": [
|
|
152
|
+
{
|
|
153
|
+
"internalType": "uint64",
|
|
154
|
+
"name": "amount",
|
|
155
|
+
"type": "uint64"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"internalType": "address",
|
|
159
|
+
"name": "vault",
|
|
160
|
+
"type": "address"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"internalType": "uint32",
|
|
164
|
+
"name": "revealedAt",
|
|
165
|
+
"type": "uint32"
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
"stateMutability": "view",
|
|
169
|
+
"type": "function"
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
"bytecode": "0x608060405234801561001057600080fd5b506109f0806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80632c3e1d121461004657806342b1f1a41461006257806343c6de291461007e575b600080fd5b610060600480360381019061005b91906103df565b6100b0565b005b61007c60048036038101906100779190610486565b610238565b005b61009860048036038101906100939190610584565b610241565b6040516100a793929190610735565b60405180910390f35b60008787336040516020016100c793929190610657565b6040516020818303038152906040528051906020012060001c905060008060008381526020019081526020016000209050600081600001601c9054906101000a900463ffffffff1663ffffffff1614610155576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161014c9061068e565b60405180910390fd5b838160000160006101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550828160000160086101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055504281600001601c6101000a81548163ffffffff021916908363ffffffff1602179055507fed7e2a3180a53ccf8540bf67f1679359557837b4c2350f3c7f1d1409eaac3739828a8a338b8b8b8b8b604051610225999897969594939291906106ae565b60405180910390a1505050505050505050565b50505050505050565b60006020528060005260406000206000915090508060000160009054906101000a900467ffffffffffffffff16908060000160089054906101000a900473ffffffffffffffffffffffffffffffffffffffff169080600001601c9054906101000a900463ffffffff16905083565b60006102c26102bd84610791565b61076c565b9050828152602081018484840111156102da57600080fd5b6102e5848285610887565b509392505050565b6000813590506102fc81610930565b92915050565b60008135905061031181610947565b92915050565b6000813590506103268161095e565b92915050565b60008083601f84011261033e57600080fd5b8235905067ffffffffffffffff81111561035757600080fd5b60208301915083600182028301111561036f57600080fd5b9250929050565b600082601f83011261038757600080fd5b81356103978482602086016102af565b91505092915050565b6000813590506103af81610975565b92915050565b6000813590506103c48161098c565b92915050565b6000813590506103d9816109a3565b92915050565b600080600080600080600060c0888a0312156103fa57600080fd5b60006104088a828b01610302565b97505060206104198a828b016103ca565b965050604061042a8a828b016103b5565b955050606088013567ffffffffffffffff81111561044757600080fd5b6104538a828b0161032c565b945094505060806104668a828b016103b5565b92505060a06104778a828b016102ed565b91505092959891949750929550565b600080600080600080600060e0888a0312156104a157600080fd5b60006104af8a828b01610317565b975050602088013567ffffffffffffffff8111156104cc57600080fd5b6104d88a828b01610376565b965050604088013567ffffffffffffffff8111156104f557600080fd5b6105018a828b01610376565b95505060606105128a828b01610317565b945050608088013567ffffffffffffffff81111561052f57600080fd5b61053b8a828b01610376565b93505060a061054c8a828b016103a0565b92505060c088013567ffffffffffffffff81111561056957600080fd5b6105758a828b01610376565b91505092959891949750929550565b60006020828403121561059657600080fd5b60006105a4848285016103a0565b91505092915050565b6105b6816107e4565b82525050565b6105c5816107f6565b82525050565b60006105d783856107c2565b93506105e4838584610887565b6105ed836108f6565b840190509392505050565b60006106056018836107d3565b915061061082610907565b602082019050919050565b6106248161084c565b82525050565b61063381610856565b82525050565b61064281610866565b82525050565b6106518161087a565b82525050565b600060608201905061066c60008301866105bc565b6106796020830185610648565b61068660408301846105ad565b949350505050565b600060208201905081810360008301526106a7816105f8565b9050919050565b6000610100820190506106c4600083018c61061b565b6106d1602083018b6105bc565b6106de604083018a610648565b6106eb60608301896105ad565b6106f86080830188610639565b81810360a083015261070b8186886105cb565b905061071a60c0830185610639565b61072760e08301846105ad565b9a9950505050505050505050565b600060608201905061074a6000830186610639565b61075760208301856105ad565b610764604083018461062a565b949350505050565b6000610776610787565b90506107828282610896565b919050565b6000604051905090565b600067ffffffffffffffff8211156107ac576107ab6108c7565b5b6107b5826108f6565b9050602081019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b60006107ef8261082c565b9050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600063ffffffff82169050919050565b600067ffffffffffffffff82169050919050565b600060ff82169050919050565b82818337600083830152505050565b61089f826108f6565b810181811067ffffffffffffffff821117156108be576108bd6108c7565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f4465706f73697420616c72656164792072657665616c65640000000000000000600082015250565b610939816107e4565b811461094457600080fd5b50565b610950816107f6565b811461095b57600080fd5b50565b61096781610800565b811461097257600080fd5b50565b61097e8161084c565b811461098957600080fd5b50565b61099581610866565b81146109a057600080fd5b50565b6109ac8161087a565b81146109b757600080fd5b5056fea2646970667358221220bca337d7cb05b6b689ca49ecdd85c75dc9cdde9d5b5a54318aba5449dda2e35064736f6c63430008040033",
|
|
173
|
+
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c80632c3e1d121461004657806342b1f1a41461006257806343c6de291461007e575b600080fd5b610060600480360381019061005b91906103df565b6100b0565b005b61007c60048036038101906100779190610486565b610238565b005b61009860048036038101906100939190610584565b610241565b6040516100a793929190610735565b60405180910390f35b60008787336040516020016100c793929190610657565b6040516020818303038152906040528051906020012060001c905060008060008381526020019081526020016000209050600081600001601c9054906101000a900463ffffffff1663ffffffff1614610155576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161014c9061068e565b60405180910390fd5b838160000160006101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550828160000160086101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055504281600001601c6101000a81548163ffffffff021916908363ffffffff1602179055507fed7e2a3180a53ccf8540bf67f1679359557837b4c2350f3c7f1d1409eaac3739828a8a338b8b8b8b8b604051610225999897969594939291906106ae565b60405180910390a1505050505050505050565b50505050505050565b60006020528060005260406000206000915090508060000160009054906101000a900467ffffffffffffffff16908060000160089054906101000a900473ffffffffffffffffffffffffffffffffffffffff169080600001601c9054906101000a900463ffffffff16905083565b60006102c26102bd84610791565b61076c565b9050828152602081018484840111156102da57600080fd5b6102e5848285610887565b509392505050565b6000813590506102fc81610930565b92915050565b60008135905061031181610947565b92915050565b6000813590506103268161095e565b92915050565b60008083601f84011261033e57600080fd5b8235905067ffffffffffffffff81111561035757600080fd5b60208301915083600182028301111561036f57600080fd5b9250929050565b600082601f83011261038757600080fd5b81356103978482602086016102af565b91505092915050565b6000813590506103af81610975565b92915050565b6000813590506103c48161098c565b92915050565b6000813590506103d9816109a3565b92915050565b600080600080600080600060c0888a0312156103fa57600080fd5b60006104088a828b01610302565b97505060206104198a828b016103ca565b965050604061042a8a828b016103b5565b955050606088013567ffffffffffffffff81111561044757600080fd5b6104538a828b0161032c565b945094505060806104668a828b016103b5565b92505060a06104778a828b016102ed565b91505092959891949750929550565b600080600080600080600060e0888a0312156104a157600080fd5b60006104af8a828b01610317565b975050602088013567ffffffffffffffff8111156104cc57600080fd5b6104d88a828b01610376565b965050604088013567ffffffffffffffff8111156104f557600080fd5b6105018a828b01610376565b95505060606105128a828b01610317565b945050608088013567ffffffffffffffff81111561052f57600080fd5b61053b8a828b01610376565b93505060a061054c8a828b016103a0565b92505060c088013567ffffffffffffffff81111561056957600080fd5b6105758a828b01610376565b91505092959891949750929550565b60006020828403121561059657600080fd5b60006105a4848285016103a0565b91505092915050565b6105b6816107e4565b82525050565b6105c5816107f6565b82525050565b60006105d783856107c2565b93506105e4838584610887565b6105ed836108f6565b840190509392505050565b60006106056018836107d3565b915061061082610907565b602082019050919050565b6106248161084c565b82525050565b61063381610856565b82525050565b61064281610866565b82525050565b6106518161087a565b82525050565b600060608201905061066c60008301866105bc565b6106796020830185610648565b61068660408301846105ad565b949350505050565b600060208201905081810360008301526106a7816105f8565b9050919050565b6000610100820190506106c4600083018c61061b565b6106d1602083018b6105bc565b6106de604083018a610648565b6106eb60608301896105ad565b6106f86080830188610639565b81810360a083015261070b8186886105cb565b905061071a60c0830185610639565b61072760e08301846105ad565b9a9950505050505050505050565b600060608201905061074a6000830186610639565b61075760208301856105ad565b610764604083018461062a565b949350505050565b6000610776610787565b90506107828282610896565b919050565b6000604051905090565b600067ffffffffffffffff8211156107ac576107ab6108c7565b5b6107b5826108f6565b9050602081019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b60006107ef8261082c565b9050919050565b6000819050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600063ffffffff82169050919050565b600067ffffffffffffffff82169050919050565b600060ff82169050919050565b82818337600083830152505050565b61089f826108f6565b810181811067ffffffffffffffff821117156108be576108bd6108c7565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f8301169050919050565b7f4465706f73697420616c72656164792072657665616c65640000000000000000600082015250565b610939816107e4565b811461094457600080fd5b50565b610950816107f6565b811461095b57600080fd5b50565b61096781610800565b811461097257600080fd5b50565b61097e8161084c565b811461098957600080fd5b50565b61099581610866565b81146109a057600080fd5b50565b6109ac8161087a565b81146109b757600080fd5b5056fea2646970667358221220bca337d7cb05b6b689ca49ecdd85c75dc9cdde9d5b5a54318aba5449dda2e35064736f6c63430008040033",
|
|
174
|
+
"linkReferences": {},
|
|
175
|
+
"deployedLinkReferences": {}
|
|
176
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
pragma solidity 0.8.4;
|
|
2
|
+
|
|
3
|
+
/// @title BTC Bridge
|
|
4
|
+
/// @notice Bridge manages BTC deposit and redemption and is increasing and
|
|
5
|
+
/// decreasing balances in the Bank as a result of BTC deposit and
|
|
6
|
+
/// redemption operations.
|
|
7
|
+
///
|
|
8
|
+
/// Depositors send BTC funds to the most-recently-created-wallet of the
|
|
9
|
+
/// bridge using pay-to-script-hash (P2SH) which contains hashed
|
|
10
|
+
/// information about the depositor’s minting Ethereum address. Then,
|
|
11
|
+
/// the depositor reveals their desired Ethereum minting address to the
|
|
12
|
+
/// Ethereum chain. The Bridge listens for these sorts of messages and
|
|
13
|
+
/// when it gets one, it checks the Bitcoin network to make sure the
|
|
14
|
+
/// funds line up. If they do, the off-chain wallet may decide to pick
|
|
15
|
+
/// this transaction for sweeping, and when the sweep operation is
|
|
16
|
+
/// confirmed on the Bitcoin network, the wallet informs the Bridge
|
|
17
|
+
/// about the sweep increasing appropriate balances in the Bank.
|
|
18
|
+
/// @dev Bridge is an upgradeable component of the Bank.
|
|
19
|
+
contract Bridge {
|
|
20
|
+
struct DepositInfo {
|
|
21
|
+
uint64 amount;
|
|
22
|
+
address vault;
|
|
23
|
+
uint32 revealedAt;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// @notice Collection of all unswept deposits indexed by
|
|
27
|
+
/// keccak256(fundingTxHash | fundingOutputIndex | depositorAddress).
|
|
28
|
+
/// This mapping may contain valid and invalid deposits and the
|
|
29
|
+
/// wallet is responsible for validating them before attempting to
|
|
30
|
+
/// execute a sweep.
|
|
31
|
+
mapping(uint256 => DepositInfo) public unswept;
|
|
32
|
+
|
|
33
|
+
event DepositRevealed(
|
|
34
|
+
uint256 depositId,
|
|
35
|
+
bytes32 fundingTxHash,
|
|
36
|
+
uint8 fundingOutputIndex,
|
|
37
|
+
address depositor,
|
|
38
|
+
uint64 blindingFactor,
|
|
39
|
+
bytes refundPubKey,
|
|
40
|
+
uint64 amount,
|
|
41
|
+
address vault
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
/// @notice Used by the depositor to reveal information about their P2SH
|
|
45
|
+
/// Bitcoin deposit to the Bridge on Ethereum chain. The off-chain
|
|
46
|
+
/// wallet listens for revealed deposit events and may decide to
|
|
47
|
+
/// include the revealed deposit in the next executed sweep.
|
|
48
|
+
/// Information about the Bitcoin deposit can be revealed before or
|
|
49
|
+
/// after the Bitcoin transaction with P2SH deposit is mined on the
|
|
50
|
+
/// Bitcoin chain.
|
|
51
|
+
/// @param fundingTxHash The BTC transaction hash containing BTC P2SH
|
|
52
|
+
/// deposit funding transaction
|
|
53
|
+
/// @param fundingOutputIndex The index of the transaction output in the
|
|
54
|
+
/// funding TX with P2SH deposit, max 256
|
|
55
|
+
/// @param blindingFactor The blinding factor used in the BTC P2SH deposit,
|
|
56
|
+
/// max 2^64
|
|
57
|
+
/// @param refundPubKey The refund pub key used in the BTC P2SH deposit
|
|
58
|
+
/// @param amount The amount locked in the BTC P2SH deposit
|
|
59
|
+
/// @param vault Bank vault to which the swept deposit should be routed
|
|
60
|
+
/// @dev Requirements:
|
|
61
|
+
/// - `msg.sender` must be the Ethereum address used in the P2SH BTC deposit,
|
|
62
|
+
/// - `blindingFactor` must be the blinding factor used in the P2SH BTC deposit,
|
|
63
|
+
/// - `refundPubKey` must be the refund pub key used in the P2SH BTC deposit,
|
|
64
|
+
/// - `amount` must be the same as locked in the P2SH BTC deposit,
|
|
65
|
+
/// - BTC deposit for the given `fundingTxHash`, `fundingOutputIndex`
|
|
66
|
+
/// can be revealed by `msg.sender` only one time.
|
|
67
|
+
///
|
|
68
|
+
/// If any of these requirements is not met, the wallet _must_ refuse
|
|
69
|
+
/// to sweep the deposit and the depositor has to wait until the
|
|
70
|
+
/// deposit script unlocks to receive their BTC back.
|
|
71
|
+
function revealDeposit(
|
|
72
|
+
bytes32 fundingTxHash,
|
|
73
|
+
uint8 fundingOutputIndex,
|
|
74
|
+
uint64 blindingFactor,
|
|
75
|
+
bytes calldata refundPubKey,
|
|
76
|
+
uint64 amount,
|
|
77
|
+
address vault
|
|
78
|
+
) external {
|
|
79
|
+
uint256 depositId =
|
|
80
|
+
uint256(
|
|
81
|
+
keccak256(
|
|
82
|
+
abi.encode(fundingTxHash, fundingOutputIndex, msg.sender)
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
DepositInfo storage deposit = unswept[depositId];
|
|
87
|
+
require(deposit.revealedAt == 0, "Deposit already revealed");
|
|
88
|
+
|
|
89
|
+
deposit.amount = amount;
|
|
90
|
+
deposit.vault = vault;
|
|
91
|
+
/* solhint-disable-next-line not-rely-on-time */
|
|
92
|
+
deposit.revealedAt = uint32(block.timestamp);
|
|
93
|
+
|
|
94
|
+
emit DepositRevealed(
|
|
95
|
+
depositId,
|
|
96
|
+
fundingTxHash,
|
|
97
|
+
fundingOutputIndex,
|
|
98
|
+
msg.sender,
|
|
99
|
+
blindingFactor,
|
|
100
|
+
refundPubKey,
|
|
101
|
+
amount,
|
|
102
|
+
vault
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// @notice Used by the wallet to prove the BTC deposit sweep transaction
|
|
107
|
+
/// and to update Bank balances accordingly. Sweep is only accepted
|
|
108
|
+
/// if it satisfies SPV proof.
|
|
109
|
+
///
|
|
110
|
+
/// The function is performing Bank balance updates by first
|
|
111
|
+
/// computing the Bitcoin fee for the sweep transaction. The fee is
|
|
112
|
+
/// divided evenly between all swept deposits. Each depositor
|
|
113
|
+
/// receives a balance in the bank equal to the amount they have
|
|
114
|
+
/// declared during the reveal transaction, minus their fee share.
|
|
115
|
+
///
|
|
116
|
+
/// It is possible to prove the given sweep only one time.
|
|
117
|
+
/// @param txVersion Transaction version number (4-byte LE)
|
|
118
|
+
/// @param txInputVector All transaction inputs prepended by the number of
|
|
119
|
+
/// inputs encoded as a VarInt, max 0xFC(252) inputs
|
|
120
|
+
/// @param txOutput Single sweep transaction output
|
|
121
|
+
/// @param txLocktime Final 4 bytes of the transaction
|
|
122
|
+
/// @param merkleProof The merkle proof of transaction inclusion in a block
|
|
123
|
+
/// @param txIndexInBlock Transaction index in the block (0-indexed)
|
|
124
|
+
/// @param bitcoinHeaders Single bytestring of 80-byte bitcoin headers,
|
|
125
|
+
/// lowest height first
|
|
126
|
+
function sweep(
|
|
127
|
+
bytes4 txVersion,
|
|
128
|
+
bytes memory txInputVector,
|
|
129
|
+
bytes memory txOutput,
|
|
130
|
+
bytes4 txLocktime,
|
|
131
|
+
bytes memory merkleProof,
|
|
132
|
+
uint256 txIndexInBlock,
|
|
133
|
+
bytes memory bitcoinHeaders
|
|
134
|
+
) external {
|
|
135
|
+
// TODO We need to read `fundingTxHash`, `fundingOutputIndex` and
|
|
136
|
+
// P2SH script depositor address from `txInputVector`.
|
|
137
|
+
// We then hash them to obtain deposit identifier and read
|
|
138
|
+
// DepositInfo. From DepositInfo we know what amount was declared
|
|
139
|
+
// by the depositor in their reveal transaction and we use that
|
|
140
|
+
// amount to update their Bank balance, minus fee.
|
|
141
|
+
//
|
|
142
|
+
// TODO We need to validate if the sum in the output minus the
|
|
143
|
+
// amount from the previous wallet balance input minus fees is
|
|
144
|
+
// equal to the amount by which Bank balances were increased.
|
|
145
|
+
//
|
|
146
|
+
// TODO We need to validate txOutput to see if the balance was not
|
|
147
|
+
// transferred away from the wallet before increasing balances in
|
|
148
|
+
// the bank.
|
|
149
|
+
//
|
|
150
|
+
// TODO Delete deposit from unswept mapping or mark it as swept
|
|
151
|
+
// depending on the gas costs. Alternativly, do not allow to
|
|
152
|
+
// use the same TX input vector twice. Sweep should be provable
|
|
153
|
+
// only one time.
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// TODO It is possible a malicious wallet can sweep deposits that can not
|
|
157
|
+
// be later proved on Ethereum. For example, a deposit with
|
|
158
|
+
// an incorrect amount revealed. We need to provide a function for honest
|
|
159
|
+
// depositors, next to sweep, to prove their swept balances on Ethereum
|
|
160
|
+
// selectively, based on deposits they have earlier received.
|
|
161
|
+
}
|
package/export.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"abi": []
|
|
7
7
|
},
|
|
8
8
|
"BTCUtils": {
|
|
9
|
-
"address": "
|
|
9
|
+
"address": "0x24918Ba054467ceebCe42658d31c24b6Af24dECc",
|
|
10
10
|
"abi": [
|
|
11
11
|
{
|
|
12
12
|
"constant": true,
|
|
@@ -71,11 +71,11 @@
|
|
|
71
71
|
]
|
|
72
72
|
},
|
|
73
73
|
"BytesLib": {
|
|
74
|
-
"address": "
|
|
74
|
+
"address": "0xDa4168790087B8Fe8A865a156fEACa3b93F44E96",
|
|
75
75
|
"abi": []
|
|
76
76
|
},
|
|
77
77
|
"CheckBitcoinSigs": {
|
|
78
|
-
"address": "
|
|
78
|
+
"address": "0xF296B23dF56D532d4F35B4f4974C6D4E53924824",
|
|
79
79
|
"abi": []
|
|
80
80
|
},
|
|
81
81
|
"CloneFactory": {
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"abi": []
|
|
150
150
|
},
|
|
151
151
|
"Deposit": {
|
|
152
|
-
"address": "
|
|
152
|
+
"address": "0xD99F386928626EC09C7e18d21fEAe9cec8d565B9",
|
|
153
153
|
"abi": [
|
|
154
154
|
{
|
|
155
155
|
"inputs": [],
|
|
@@ -866,7 +866,7 @@
|
|
|
866
866
|
]
|
|
867
867
|
},
|
|
868
868
|
"DepositFactory": {
|
|
869
|
-
"address": "
|
|
869
|
+
"address": "0x34EeACB4ce3c32b69B95c0e166181f261B5aa482",
|
|
870
870
|
"abi": [
|
|
871
871
|
{
|
|
872
872
|
"inputs": [
|
|
@@ -1051,11 +1051,11 @@
|
|
|
1051
1051
|
]
|
|
1052
1052
|
},
|
|
1053
1053
|
"DepositFunding": {
|
|
1054
|
-
"address": "
|
|
1054
|
+
"address": "0x04523c557e941bCE159C41450dc05Be531d0A072",
|
|
1055
1055
|
"abi": []
|
|
1056
1056
|
},
|
|
1057
1057
|
"DepositLiquidation": {
|
|
1058
|
-
"address": "
|
|
1058
|
+
"address": "0x1aa0c96e2aC929c1C56a86bAC3ec65577747eAFb",
|
|
1059
1059
|
"abi": []
|
|
1060
1060
|
},
|
|
1061
1061
|
"DepositLog": {
|
|
@@ -1620,15 +1620,15 @@
|
|
|
1620
1620
|
]
|
|
1621
1621
|
},
|
|
1622
1622
|
"DepositRedemption": {
|
|
1623
|
-
"address": "
|
|
1623
|
+
"address": "0xb91A49A243a70141992A1ED21c92ceAB4152Afaa",
|
|
1624
1624
|
"abi": []
|
|
1625
1625
|
},
|
|
1626
1626
|
"DepositStates": {
|
|
1627
|
-
"address": "
|
|
1627
|
+
"address": "0x6F9e8Ca9906ECabEc68f671604E3B87F83e2F413",
|
|
1628
1628
|
"abi": []
|
|
1629
1629
|
},
|
|
1630
1630
|
"DepositUtils": {
|
|
1631
|
-
"address": "
|
|
1631
|
+
"address": "0x272214784592e1401844bF958a1a6c81fB7cF984",
|
|
1632
1632
|
"abi": [
|
|
1633
1633
|
{
|
|
1634
1634
|
"constant": true,
|
|
@@ -3437,7 +3437,7 @@
|
|
|
3437
3437
|
]
|
|
3438
3438
|
},
|
|
3439
3439
|
"ETHBTCPriceFeedMock": {
|
|
3440
|
-
"address": "
|
|
3440
|
+
"address": "0xB7e539655f9B8f72599635947b6D6cbcBe020863",
|
|
3441
3441
|
"abi": [
|
|
3442
3442
|
{
|
|
3443
3443
|
"anonymous": false,
|
|
@@ -3565,7 +3565,7 @@
|
|
|
3565
3565
|
]
|
|
3566
3566
|
},
|
|
3567
3567
|
"FeeRebateToken": {
|
|
3568
|
-
"address": "
|
|
3568
|
+
"address": "0xDc18909B4c22bC0A5B84f3F043D7f291d3532587",
|
|
3569
3569
|
"abi": [
|
|
3570
3570
|
{
|
|
3571
3571
|
"inputs": [
|
|
@@ -3979,7 +3979,7 @@
|
|
|
3979
3979
|
]
|
|
3980
3980
|
},
|
|
3981
3981
|
"FundingScript": {
|
|
3982
|
-
"address": "
|
|
3982
|
+
"address": "0x2FBC1AB15EeB772C3F0a7b82659C428f8a6c4e90",
|
|
3983
3983
|
"abi": [
|
|
3984
3984
|
{
|
|
3985
3985
|
"inputs": [
|
|
@@ -6207,7 +6207,7 @@
|
|
|
6207
6207
|
]
|
|
6208
6208
|
},
|
|
6209
6209
|
"KeepFactorySelection": {
|
|
6210
|
-
"address": "
|
|
6210
|
+
"address": "0xEd42b8ad1988f2faB836122Dc2dA64d3C6EE0226",
|
|
6211
6211
|
"abi": []
|
|
6212
6212
|
},
|
|
6213
6213
|
"KeepFactorySelectionStub": {
|
|
@@ -6441,7 +6441,7 @@
|
|
|
6441
6441
|
]
|
|
6442
6442
|
},
|
|
6443
6443
|
"Migrations": {
|
|
6444
|
-
"address": "
|
|
6444
|
+
"address": "0x721e01A2838c4965908A895cF6AFB1E015622B45",
|
|
6445
6445
|
"abi": [
|
|
6446
6446
|
{
|
|
6447
6447
|
"inputs": [],
|
|
@@ -7407,7 +7407,7 @@
|
|
|
7407
7407
|
]
|
|
7408
7408
|
},
|
|
7409
7409
|
"OutsourceDepositLogging": {
|
|
7410
|
-
"address": "
|
|
7410
|
+
"address": "0x6986D8b8FF3dbD37833a676CF24f4171c1a055A8",
|
|
7411
7411
|
"abi": []
|
|
7412
7412
|
},
|
|
7413
7413
|
"Ownable": {
|
|
@@ -7494,7 +7494,7 @@
|
|
|
7494
7494
|
]
|
|
7495
7495
|
},
|
|
7496
7496
|
"RedemptionScript": {
|
|
7497
|
-
"address": "
|
|
7497
|
+
"address": "0x5417009AFa82b799B920ee7112109E570b5FEC32",
|
|
7498
7498
|
"abi": [
|
|
7499
7499
|
{
|
|
7500
7500
|
"inputs": [
|
|
@@ -7885,7 +7885,7 @@
|
|
|
7885
7885
|
"abi": []
|
|
7886
7886
|
},
|
|
7887
7887
|
"SatWeiPriceFeed": {
|
|
7888
|
-
"address": "
|
|
7888
|
+
"address": "0xB0217c04eff95Cf73cB1186e6dF04D30d0E5756e",
|
|
7889
7889
|
"abi": [
|
|
7890
7890
|
{
|
|
7891
7891
|
"inputs": [],
|
|
@@ -8034,7 +8034,7 @@
|
|
|
8034
8034
|
]
|
|
8035
8035
|
},
|
|
8036
8036
|
"TBTCConstants": {
|
|
8037
|
-
"address": "
|
|
8037
|
+
"address": "0xd4a5Ac06D8a7C3f4DdFeeBa07Ef6a5c48db87027",
|
|
8038
8038
|
"abi": [
|
|
8039
8039
|
{
|
|
8040
8040
|
"constant": true,
|
|
@@ -8399,7 +8399,7 @@
|
|
|
8399
8399
|
]
|
|
8400
8400
|
},
|
|
8401
8401
|
"TBTCDepositToken": {
|
|
8402
|
-
"address": "
|
|
8402
|
+
"address": "0x84bDAfC4de8C6B5759bced508F682d83a3E4497b",
|
|
8403
8403
|
"abi": [
|
|
8404
8404
|
{
|
|
8405
8405
|
"inputs": [
|
|
@@ -9223,7 +9223,7 @@
|
|
|
9223
9223
|
]
|
|
9224
9224
|
},
|
|
9225
9225
|
"TBTCSystem": {
|
|
9226
|
-
"address": "
|
|
9226
|
+
"address": "0xB6E6A2EDC695ED7028b76f118d9feFA5ab649F00",
|
|
9227
9227
|
"abi": [
|
|
9228
9228
|
{
|
|
9229
9229
|
"inputs": [
|
|
@@ -13863,7 +13863,7 @@
|
|
|
13863
13863
|
]
|
|
13864
13864
|
},
|
|
13865
13865
|
"TBTCToken": {
|
|
13866
|
-
"address": "
|
|
13866
|
+
"address": "0x18CCD4198da08cC97a69Afc5c685cb9F94Ec57ba",
|
|
13867
13867
|
"abi": [
|
|
13868
13868
|
{
|
|
13869
13869
|
"inputs": [
|
|
@@ -21796,11 +21796,11 @@
|
|
|
21796
21796
|
]
|
|
21797
21797
|
},
|
|
21798
21798
|
"ValidateSPV": {
|
|
21799
|
-
"address": "
|
|
21799
|
+
"address": "0xE31876f707AD15867269910AA19ed46F000a0139",
|
|
21800
21800
|
"abi": []
|
|
21801
21801
|
},
|
|
21802
21802
|
"VendingMachine": {
|
|
21803
|
-
"address": "
|
|
21803
|
+
"address": "0x91f4fEe57463Ed05cf97F40939dBc40B660f1080",
|
|
21804
21804
|
"abi": [
|
|
21805
21805
|
{
|
|
21806
21806
|
"inputs": [
|
|
@@ -22328,7 +22328,7 @@
|
|
|
22328
22328
|
]
|
|
22329
22329
|
},
|
|
22330
22330
|
"TBTC": {
|
|
22331
|
-
"address": "
|
|
22331
|
+
"address": "0xc53D0feBE9B825A522F8649E342a763a300a367c",
|
|
22332
22332
|
"abi": [
|
|
22333
22333
|
{
|
|
22334
22334
|
"inputs": [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keep-network/tbtc-v2",
|
|
3
|
-
"version": "0.1.1-ropsten.
|
|
3
|
+
"version": "0.1.1-ropsten.5+main.f1e973362e57e2749005254202db8ab46acf0b5f",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"artifacts/",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"prepublishOnly": "./scripts/prepare-artifacts.sh --network $npm_config_network"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@keep-network/tbtc": "1.1.2-ropsten.
|
|
29
|
+
"@keep-network/tbtc": "1.1.2-ropsten.13",
|
|
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"
|