@keep-network/tbtc-v2 1.0.3-dev.1 → 1.0.3-dev.2
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/BLS.json +1 -1
- package/artifacts/Bank.json +3 -3
- package/artifacts/BeaconAuthorization.json +1 -1
- package/artifacts/BeaconDkg.json +1 -1
- package/artifacts/BeaconDkgValidator.json +1 -1
- package/artifacts/BeaconInactivity.json +1 -1
- package/artifacts/BeaconSortitionPool.json +3 -3
- package/artifacts/Bridge.json +5 -5
- package/artifacts/BridgeGovernance.json +2 -2
- package/artifacts/BridgeGovernanceParameters.json +2 -2
- package/artifacts/Deposit.json +2 -2
- package/artifacts/DepositSweep.json +2 -2
- package/artifacts/DonationVault.json +3 -3
- package/artifacts/EcdsaDkgValidator.json +1 -1
- package/artifacts/EcdsaInactivity.json +1 -1
- package/artifacts/EcdsaSortitionPool.json +3 -3
- package/artifacts/Fraud.json +2 -2
- package/artifacts/KeepRegistry.json +1 -1
- package/artifacts/KeepStake.json +2 -2
- package/artifacts/KeepToken.json +2 -2
- package/artifacts/KeepTokenStaking.json +1 -1
- package/artifacts/LightRelay.json +18 -18
- package/artifacts/MaintainerProxy.json +19 -19
- package/artifacts/MovingFunds.json +2 -2
- package/artifacts/NuCypherStakingEscrow.json +1 -1
- package/artifacts/NuCypherToken.json +2 -2
- package/artifacts/RandomBeacon.json +2 -2
- package/artifacts/RandomBeaconChaosnet.json +2 -2
- package/artifacts/RandomBeaconGovernance.json +2 -2
- package/artifacts/Redemption.json +2 -2
- package/artifacts/ReimbursementPool.json +2 -2
- package/artifacts/T.json +2 -2
- package/artifacts/TBTC.json +3 -3
- package/artifacts/TBTCToken.json +3 -3
- package/artifacts/TBTCVault.json +23 -23
- package/artifacts/TokenStaking.json +1 -1
- package/artifacts/TokenholderGovernor.json +9 -9
- package/artifacts/TokenholderTimelock.json +8 -8
- package/artifacts/VendingMachine.json +3 -3
- package/artifacts/VendingMachineKeep.json +1 -1
- package/artifacts/VendingMachineNuCypher.json +1 -1
- package/artifacts/VendingMachineV2.json +360 -0
- package/artifacts/VendingMachineV3.json +405 -0
- package/artifacts/WalletRegistry.json +5 -5
- package/artifacts/WalletRegistryGovernance.json +2 -2
- package/artifacts/Wallets.json +2 -2
- package/artifacts/solcInputs/{5835b0a74f2a5433fcfb8074d31a6e8a.json → b0025f1f7efe4824592ac0c9793776c3.json} +6 -0
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
- package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +1 -1
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
- package/build/contracts/bridge/BridgeGovernanceParameters.sol/BridgeGovernanceParameters.dbg.json +1 -1
- package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
- package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
- package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +1 -1
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
- package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
- package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +1 -1
- package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
- package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
- package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/bridge/VendingMachineV2.sol/VendingMachineV2.dbg.json +4 -0
- package/build/contracts/bridge/VendingMachineV2.sol/VendingMachineV2.json +245 -0
- package/build/contracts/bridge/VendingMachineV3.sol/VendingMachineV3.dbg.json +4 -0
- package/build/contracts/bridge/VendingMachineV3.sol/VendingMachineV3.json +282 -0
- package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
- package/build/contracts/l2/L2TBTC.sol/L2TBTC.dbg.json +1 -1
- package/build/contracts/maintainer/MaintainerProxy.sol/MaintainerProxy.dbg.json +1 -1
- package/build/contracts/relay/LightRelay.sol/ILightRelay.dbg.json +1 -1
- package/build/contracts/relay/LightRelay.sol/LightRelay.dbg.json +1 -1
- package/build/contracts/relay/LightRelay.sol/RelayUtils.dbg.json +1 -1
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +1 -1
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
- package/build/contracts/vault/TBTCOptimisticMinting.sol/TBTCOptimisticMinting.dbg.json +1 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
- package/contracts/bridge/VendingMachineV2.sol +114 -0
- package/contracts/bridge/VendingMachineV3.sol +134 -0
- package/deploy/24_transfer_tbtc_ownership.ts +7 -14
- package/deploy/30_deploy_vending_machine_v2.ts +34 -0
- package/deploy/31_deploy_vending_machine_v3.ts +34 -0
- package/deploy/32_transfer_vending_machine_v2_ownership.ts +19 -0
- package/deploy/33_transfer_vending_machine_v3_ownership.ts +19 -0
- package/export/artifacts/@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol/BTCUtils.json +20 -20
- package/export/artifacts/@keep-network/ecdsa/contracts/EcdsaDkgValidator.sol/EcdsaDkgValidator.json +1986 -1986
- package/export/artifacts/@keep-network/ecdsa/contracts/libraries/EcdsaDkg.sol/EcdsaDkg.json +20 -20
- package/export/artifacts/@keep-network/ecdsa/contracts/libraries/EcdsaInactivity.sol/EcdsaInactivity.json +1836 -1836
- package/export/artifacts/@keep-network/random-beacon/contracts/ReimbursementPool.sol/ReimbursementPool.json +545 -545
- package/export/artifacts/@keep-network/sortition-pools/contracts/Chaosnet.sol/Chaosnet.json +506 -506
- package/export/artifacts/@keep-network/sortition-pools/contracts/Rewards.sol/Rewards.json +23 -23
- package/export/artifacts/@keep-network/sortition-pools/contracts/SortitionPool.sol/SortitionPool.json +2456 -2456
- package/export/artifacts/@keep-network/sortition-pools/contracts/SortitionTree.sol/SortitionTree.json +465 -465
- package/export/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json +568 -568
- package/export/artifacts/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +603 -603
- package/export/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +1001 -1001
- package/export/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.json +1877 -1877
- package/export/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol/ERC20Upgradeable.json +654 -654
- package/export/artifacts/@thesis/solidity-contracts/contracts/token/ERC20WithPermit.sol/ERC20WithPermit.json +2534 -2534
- package/export/artifacts/@thesis/solidity-contracts/contracts/token/MisfundRecovery.sol/MisfundRecovery.json +736 -736
- package/export/artifacts/contracts/bank/Bank.sol/Bank.json +1872 -1872
- package/export/artifacts/contracts/bridge/Bridge.sol/Bridge.json +7083 -7083
- package/export/artifacts/contracts/bridge/VendingMachine.sol/VendingMachine.json +1257 -1257
- package/export/artifacts/contracts/bridge/VendingMachineV2.sol/VendingMachineV2.json +6199 -0
- package/export/artifacts/contracts/bridge/VendingMachineV3.sol/VendingMachineV3.json +7151 -0
- package/export/artifacts/contracts/l2/L2TBTC.sol/L2TBTC.json +3002 -3002
- package/export/artifacts/contracts/maintainer/MaintainerProxy.sol/MaintainerProxy.json +2393 -2393
- package/export/artifacts/contracts/relay/LightRelay.sol/LightRelay.json +1922 -1922
- package/export/artifacts/contracts/test/BankStub.sol/BankStub.json +1874 -1874
- package/export/artifacts/contracts/test/BridgeStub.sol/BridgeStub.json +8122 -8122
- package/export/artifacts/contracts/test/GoerliLightRelay.sol/GoerliLightRelay.json +1922 -1922
- package/export/artifacts/contracts/test/HeartbeatStub.sol/HeartbeatStub.json +130 -130
- package/export/artifacts/contracts/test/LightRelayStub.sol/LightRelayStub.json +2047 -2047
- package/export/artifacts/contracts/test/ReceiveApprovalStub.sol/ReceiveApprovalStub.json +354 -354
- package/export/artifacts/contracts/test/SystemTestRelay.sol/SystemTestRelay.json +568 -568
- package/export/artifacts/contracts/test/TestERC20.sol/TestERC20.json +2291 -2291
- package/export/artifacts/contracts/test/TestERC721.sol/TestERC721.json +1698 -1698
- package/export/artifacts/contracts/test/TestEcdsaLib.sol/TestEcdsaLib.json +189 -189
- package/export/artifacts/contracts/token/TBTC.sol/TBTC.json +2847 -2847
- package/export/artifacts/contracts/vault/DonationVault.sol/DonationVault.json +858 -858
- package/export/artifacts/contracts/vault/TBTCVault.sol/TBTCVault.json +3476 -3476
- package/export/deploy/24_transfer_tbtc_ownership.js +14 -14
- package/export/deploy/30_deploy_vending_machine_v2.js +86 -0
- package/export/deploy/31_deploy_vending_machine_v3.js +86 -0
- package/export/deploy/32_transfer_vending_machine_v2_ownership.js +60 -0
- package/export/deploy/33_transfer_vending_machine_v3_ownership.js +60 -0
- package/export/hardhat.config.js +5 -0
- package/export/typechain/VendingMachineV2.js +2 -0
- package/export/typechain/VendingMachineV3.js +2 -0
- package/export/typechain/factories/VendingMachineV2__factory.js +324 -0
- package/export/typechain/factories/VendingMachineV3__factory.js +361 -0
- package/export/typechain/index.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_format": "hh-sol-artifact-1",
|
|
3
|
+
"contractName": "VendingMachineV3",
|
|
4
|
+
"sourceName": "contracts/bridge/VendingMachineV3.sol",
|
|
5
|
+
"abi": [
|
|
6
|
+
{
|
|
7
|
+
"inputs": [
|
|
8
|
+
{
|
|
9
|
+
"internalType": "contract IERC20",
|
|
10
|
+
"name": "_tbtcV1",
|
|
11
|
+
"type": "address"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"internalType": "contract TBTC",
|
|
15
|
+
"name": "_tbtcV2",
|
|
16
|
+
"type": "address"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"stateMutability": "nonpayable",
|
|
20
|
+
"type": "constructor"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"anonymous": false,
|
|
24
|
+
"inputs": [
|
|
25
|
+
{
|
|
26
|
+
"indexed": false,
|
|
27
|
+
"internalType": "address",
|
|
28
|
+
"name": "from",
|
|
29
|
+
"type": "address"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"indexed": false,
|
|
33
|
+
"internalType": "uint256",
|
|
34
|
+
"name": "amount",
|
|
35
|
+
"type": "uint256"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"name": "Deposited",
|
|
39
|
+
"type": "event"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"anonymous": false,
|
|
43
|
+
"inputs": [
|
|
44
|
+
{
|
|
45
|
+
"indexed": true,
|
|
46
|
+
"internalType": "address",
|
|
47
|
+
"name": "to",
|
|
48
|
+
"type": "address"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"indexed": false,
|
|
52
|
+
"internalType": "uint256",
|
|
53
|
+
"name": "amount",
|
|
54
|
+
"type": "uint256"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"name": "Exchanged",
|
|
58
|
+
"type": "event"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"anonymous": false,
|
|
62
|
+
"inputs": [
|
|
63
|
+
{
|
|
64
|
+
"indexed": false,
|
|
65
|
+
"internalType": "address",
|
|
66
|
+
"name": "token",
|
|
67
|
+
"type": "address"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"indexed": false,
|
|
71
|
+
"internalType": "address",
|
|
72
|
+
"name": "to",
|
|
73
|
+
"type": "address"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"indexed": false,
|
|
77
|
+
"internalType": "uint256",
|
|
78
|
+
"name": "amount",
|
|
79
|
+
"type": "uint256"
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
"name": "FundsRecovered",
|
|
83
|
+
"type": "event"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"anonymous": false,
|
|
87
|
+
"inputs": [
|
|
88
|
+
{
|
|
89
|
+
"indexed": true,
|
|
90
|
+
"internalType": "address",
|
|
91
|
+
"name": "previousOwner",
|
|
92
|
+
"type": "address"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"indexed": true,
|
|
96
|
+
"internalType": "address",
|
|
97
|
+
"name": "newOwner",
|
|
98
|
+
"type": "address"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"name": "OwnershipTransferred",
|
|
102
|
+
"type": "event"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"anonymous": false,
|
|
106
|
+
"inputs": [
|
|
107
|
+
{
|
|
108
|
+
"indexed": false,
|
|
109
|
+
"internalType": "address",
|
|
110
|
+
"name": "to",
|
|
111
|
+
"type": "address"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"indexed": false,
|
|
115
|
+
"internalType": "uint256",
|
|
116
|
+
"name": "amount",
|
|
117
|
+
"type": "uint256"
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"name": "TbtcV2Withdrawn",
|
|
121
|
+
"type": "event"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"inputs": [
|
|
125
|
+
{
|
|
126
|
+
"internalType": "uint256",
|
|
127
|
+
"name": "amount",
|
|
128
|
+
"type": "uint256"
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"name": "depositTbtcV2",
|
|
132
|
+
"outputs": [],
|
|
133
|
+
"stateMutability": "nonpayable",
|
|
134
|
+
"type": "function"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"inputs": [
|
|
138
|
+
{
|
|
139
|
+
"internalType": "uint256",
|
|
140
|
+
"name": "amount",
|
|
141
|
+
"type": "uint256"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"name": "exchange",
|
|
145
|
+
"outputs": [],
|
|
146
|
+
"stateMutability": "nonpayable",
|
|
147
|
+
"type": "function"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"inputs": [],
|
|
151
|
+
"name": "owner",
|
|
152
|
+
"outputs": [
|
|
153
|
+
{
|
|
154
|
+
"internalType": "address",
|
|
155
|
+
"name": "",
|
|
156
|
+
"type": "address"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"stateMutability": "view",
|
|
160
|
+
"type": "function"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"inputs": [
|
|
164
|
+
{
|
|
165
|
+
"internalType": "address",
|
|
166
|
+
"name": "from",
|
|
167
|
+
"type": "address"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"internalType": "uint256",
|
|
171
|
+
"name": "amount",
|
|
172
|
+
"type": "uint256"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"internalType": "address",
|
|
176
|
+
"name": "token",
|
|
177
|
+
"type": "address"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"internalType": "bytes",
|
|
181
|
+
"name": "",
|
|
182
|
+
"type": "bytes"
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
"name": "receiveApproval",
|
|
186
|
+
"outputs": [],
|
|
187
|
+
"stateMutability": "nonpayable",
|
|
188
|
+
"type": "function"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"inputs": [
|
|
192
|
+
{
|
|
193
|
+
"internalType": "contract IERC20",
|
|
194
|
+
"name": "token",
|
|
195
|
+
"type": "address"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"internalType": "address",
|
|
199
|
+
"name": "recipient",
|
|
200
|
+
"type": "address"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"internalType": "uint256",
|
|
204
|
+
"name": "amount",
|
|
205
|
+
"type": "uint256"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
"name": "recoverFunds",
|
|
209
|
+
"outputs": [],
|
|
210
|
+
"stateMutability": "nonpayable",
|
|
211
|
+
"type": "function"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"inputs": [],
|
|
215
|
+
"name": "renounceOwnership",
|
|
216
|
+
"outputs": [],
|
|
217
|
+
"stateMutability": "nonpayable",
|
|
218
|
+
"type": "function"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"inputs": [],
|
|
222
|
+
"name": "tbtcV1",
|
|
223
|
+
"outputs": [
|
|
224
|
+
{
|
|
225
|
+
"internalType": "contract IERC20",
|
|
226
|
+
"name": "",
|
|
227
|
+
"type": "address"
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"stateMutability": "view",
|
|
231
|
+
"type": "function"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"inputs": [],
|
|
235
|
+
"name": "tbtcV2",
|
|
236
|
+
"outputs": [
|
|
237
|
+
{
|
|
238
|
+
"internalType": "contract TBTC",
|
|
239
|
+
"name": "",
|
|
240
|
+
"type": "address"
|
|
241
|
+
}
|
|
242
|
+
],
|
|
243
|
+
"stateMutability": "view",
|
|
244
|
+
"type": "function"
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"inputs": [
|
|
248
|
+
{
|
|
249
|
+
"internalType": "address",
|
|
250
|
+
"name": "newOwner",
|
|
251
|
+
"type": "address"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
"name": "transferOwnership",
|
|
255
|
+
"outputs": [],
|
|
256
|
+
"stateMutability": "nonpayable",
|
|
257
|
+
"type": "function"
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"inputs": [
|
|
261
|
+
{
|
|
262
|
+
"internalType": "address",
|
|
263
|
+
"name": "recipient",
|
|
264
|
+
"type": "address"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"internalType": "uint256",
|
|
268
|
+
"name": "amount",
|
|
269
|
+
"type": "uint256"
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
"name": "withdrawTbtcV2",
|
|
273
|
+
"outputs": [],
|
|
274
|
+
"stateMutability": "nonpayable",
|
|
275
|
+
"type": "function"
|
|
276
|
+
}
|
|
277
|
+
],
|
|
278
|
+
"bytecode": "0x60c060405234801561001057600080fd5b506040516110d93803806110d983398101604081905261002f916100b7565b6100383361004f565b6001600160a01b039182166080521660a0526100f1565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b03811681146100b457600080fd5b50565b600080604083850312156100ca57600080fd5b82516100d58161009f565b60208401519092506100e68161009f565b809150509250929050565b60805160a051610f7e61015b60003960008181610172015281816101d101528181610312015281816104d40152818161064f0152818161071b015261088701526000818160c801528181610391015281816105010152818161058b01526108520152610f7e6000f3fe608060405234801561001057600080fd5b50600436106100be5760003560e01c80638da5cb5b1161007657806395de5a411161005b57806395de5a411461016d578063d46219ee14610194578063f2fde38b146101a757600080fd5b80638da5cb5b146101495780638f4ffcb11461015a57600080fd5b80635d3590d5116100a75780635d3590d51461011b578063715018a61461012e5780638a9636141461013657600080fd5b80633678252f146100c35780635355655914610106575b600080fd5b6100ea7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b610119610114366004610cfc565b6101ba565b005b610119610129366004610d2a565b6101c7565b6101196102df565b610119610144366004610d6b565b6102f3565b6000546001600160a01b03166100ea565b610119610168366004610d97565b6104ff565b6100ea7f000000000000000000000000000000000000000000000000000000000000000081565b6101196101a2366004610cfc565b610609565b6101196101b5366004610e36565b610677565b6101c43382610704565b50565b6101cf6108ae565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03160361027b5760405162461bcd60e51b815260206004820152603f60248201527f7442544320763220746f6b656e732063616e206e6f74206265207265636f766560448201527f7265642c2075736520776974686472617754627463563220696e73746561640060648201526084015b60405180910390fd5b604080516001600160a01b038086168252841660208201529081018290527f13e06184555481b6d2cb327155e8d2e1d0b1f0252a7fe6621e32cf99881488359060600160405180910390a16102da6001600160a01b0384168383610908565b505050565b6102e76108ae565b6102f160006109b1565b565b6102fb6108ae565b6040516370a0823160e01b815230600482015281907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa158015610361573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103859190610e5a565b61038f9190610e73565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104119190610e5a565b11156104855760405162461bcd60e51b815260206004820152602160248201527f74425443207631206d757374206e6f74206265206c65667420756e6261636b6560448201527f64000000000000000000000000000000000000000000000000000000000000006064820152608401610272565b604080516001600160a01b0384168152602081018390527f203ed6b401d271b305e85b1c1421e1aef411cb0acb1bcd87f625547e090261ad910160405180910390a16104fb6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383610908565b5050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316146105805760405162461bcd60e51b815260206004820152601460248201527f546f6b656e206973206e6f7420744254432076310000000000000000000000006044820152606401610272565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105f85760405162461bcd60e51b815260206004820152601b60248201527f4f6e6c7920744254432076312063616c6c657220616c6c6f77656400000000006044820152606401610272565b6106028585610704565b5050505050565b60408051338152602081018390527f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c4910160405180910390a16101c46001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084610a19565b61067f6108ae565b6001600160a01b0381166106fb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610272565b6101c4816109b1565b6040516370a0823160e01b815230600482015281907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa15801561076a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078e9190610e5a565b10156108025760405162461bcd60e51b815260206004820152603360248201527f4e6f7420656e6f756768207442544320763220617661696c61626c6520696e2060448201527f7468652056656e64696e67204d616368696e65000000000000000000000000006064820152608401610272565b816001600160a01b03167f6ea412b125ed242bc34c304877264761547306c2429c03d7fd1b477aa61a3f5d8260405161083d91815260200190565b60405180910390a261087a6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016833084610a19565b6104fb6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383610908565b6000546001600160a01b031633146102f15760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610272565b6040516001600160a01b0383166024820152604481018290526102da9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152610a70565b600080546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b0380851660248301528316604482015260648101829052610a6a9085907f23b872dd000000000000000000000000000000000000000000000000000000009060840161094d565b50505050565b6000610ac5826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610b559092919063ffffffff16565b8051909150156102da5780806020019051810190610ae39190610eb3565b6102da5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610272565b6060610b648484600085610b6c565b949350505050565b606082471015610be45760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610272565b600080866001600160a01b03168587604051610c009190610ef9565b60006040518083038185875af1925050503d8060008114610c3d576040519150601f19603f3d011682016040523d82523d6000602084013e610c42565b606091505b5091509150610c5387838387610c5e565b979650505050505050565b60608315610ccd578251600003610cc6576001600160a01b0385163b610cc65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610272565b5081610b64565b610b648383815115610ce25781518083602001fd5b8060405162461bcd60e51b81526004016102729190610f15565b600060208284031215610d0e57600080fd5b5035919050565b6001600160a01b03811681146101c457600080fd5b600080600060608486031215610d3f57600080fd5b8335610d4a81610d15565b92506020840135610d5a81610d15565b929592945050506040919091013590565b60008060408385031215610d7e57600080fd5b8235610d8981610d15565b946020939093013593505050565b600080600080600060808688031215610daf57600080fd5b8535610dba81610d15565b9450602086013593506040860135610dd181610d15565b9250606086013567ffffffffffffffff80821115610dee57600080fd5b818801915088601f830112610e0257600080fd5b813581811115610e1157600080fd5b896020828501011115610e2357600080fd5b9699959850939650602001949392505050565b600060208284031215610e4857600080fd5b8135610e5381610d15565b9392505050565b600060208284031215610e6c57600080fd5b5051919050565b81810381811115610ead577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b600060208284031215610ec557600080fd5b81518015158114610e5357600080fd5b60005b83811015610ef0578181015183820152602001610ed8565b50506000910152565b60008251610f0b818460208701610ed5565b9190910192915050565b6020815260008251806020840152610f34816040850160208701610ed5565b601f01601f1916919091016040019291505056fea26469706673582212200db484236e1da91f5f13f8216e7ca3faf20d1d632427f6e63f6ba0cffb70a3e864736f6c63430008110033",
|
|
279
|
+
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100be5760003560e01c80638da5cb5b1161007657806395de5a411161005b57806395de5a411461016d578063d46219ee14610194578063f2fde38b146101a757600080fd5b80638da5cb5b146101495780638f4ffcb11461015a57600080fd5b80635d3590d5116100a75780635d3590d51461011b578063715018a61461012e5780638a9636141461013657600080fd5b80633678252f146100c35780635355655914610106575b600080fd5b6100ea7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b610119610114366004610cfc565b6101ba565b005b610119610129366004610d2a565b6101c7565b6101196102df565b610119610144366004610d6b565b6102f3565b6000546001600160a01b03166100ea565b610119610168366004610d97565b6104ff565b6100ea7f000000000000000000000000000000000000000000000000000000000000000081565b6101196101a2366004610cfc565b610609565b6101196101b5366004610e36565b610677565b6101c43382610704565b50565b6101cf6108ae565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03160361027b5760405162461bcd60e51b815260206004820152603f60248201527f7442544320763220746f6b656e732063616e206e6f74206265207265636f766560448201527f7265642c2075736520776974686472617754627463563220696e73746561640060648201526084015b60405180910390fd5b604080516001600160a01b038086168252841660208201529081018290527f13e06184555481b6d2cb327155e8d2e1d0b1f0252a7fe6621e32cf99881488359060600160405180910390a16102da6001600160a01b0384168383610908565b505050565b6102e76108ae565b6102f160006109b1565b565b6102fb6108ae565b6040516370a0823160e01b815230600482015281907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa158015610361573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103859190610e5a565b61038f9190610e73565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104119190610e5a565b11156104855760405162461bcd60e51b815260206004820152602160248201527f74425443207631206d757374206e6f74206265206c65667420756e6261636b6560448201527f64000000000000000000000000000000000000000000000000000000000000006064820152608401610272565b604080516001600160a01b0384168152602081018390527f203ed6b401d271b305e85b1c1421e1aef411cb0acb1bcd87f625547e090261ad910160405180910390a16104fb6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383610908565b5050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b0316146105805760405162461bcd60e51b815260206004820152601460248201527f546f6b656e206973206e6f7420744254432076310000000000000000000000006044820152606401610272565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105f85760405162461bcd60e51b815260206004820152601b60248201527f4f6e6c7920744254432076312063616c6c657220616c6c6f77656400000000006044820152606401610272565b6106028585610704565b5050505050565b60408051338152602081018390527f2da466a7b24304f47e87fa2e1e5a81b9831ce54fec19055ce277ca2f39ba42c4910160405180910390a16101c46001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084610a19565b61067f6108ae565b6001600160a01b0381166106fb5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610272565b6101c4816109b1565b6040516370a0823160e01b815230600482015281907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa15801561076a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078e9190610e5a565b10156108025760405162461bcd60e51b815260206004820152603360248201527f4e6f7420656e6f756768207442544320763220617661696c61626c6520696e2060448201527f7468652056656e64696e67204d616368696e65000000000000000000000000006064820152608401610272565b816001600160a01b03167f6ea412b125ed242bc34c304877264761547306c2429c03d7fd1b477aa61a3f5d8260405161083d91815260200190565b60405180910390a261087a6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016833084610a19565b6104fb6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383610908565b6000546001600160a01b031633146102f15760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610272565b6040516001600160a01b0383166024820152604481018290526102da9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152610a70565b600080546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b0380851660248301528316604482015260648101829052610a6a9085907f23b872dd000000000000000000000000000000000000000000000000000000009060840161094d565b50505050565b6000610ac5826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610b559092919063ffffffff16565b8051909150156102da5780806020019051810190610ae39190610eb3565b6102da5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610272565b6060610b648484600085610b6c565b949350505050565b606082471015610be45760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610272565b600080866001600160a01b03168587604051610c009190610ef9565b60006040518083038185875af1925050503d8060008114610c3d576040519150601f19603f3d011682016040523d82523d6000602084013e610c42565b606091505b5091509150610c5387838387610c5e565b979650505050505050565b60608315610ccd578251600003610cc6576001600160a01b0385163b610cc65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610272565b5081610b64565b610b648383815115610ce25781518083602001fd5b8060405162461bcd60e51b81526004016102729190610f15565b600060208284031215610d0e57600080fd5b5035919050565b6001600160a01b03811681146101c457600080fd5b600080600060608486031215610d3f57600080fd5b8335610d4a81610d15565b92506020840135610d5a81610d15565b929592945050506040919091013590565b60008060408385031215610d7e57600080fd5b8235610d8981610d15565b946020939093013593505050565b600080600080600060808688031215610daf57600080fd5b8535610dba81610d15565b9450602086013593506040860135610dd181610d15565b9250606086013567ffffffffffffffff80821115610dee57600080fd5b818801915088601f830112610e0257600080fd5b813581811115610e1157600080fd5b896020828501011115610e2357600080fd5b9699959850939650602001949392505050565b600060208284031215610e4857600080fd5b8135610e5381610d15565b9392505050565b600060208284031215610e6c57600080fd5b5051919050565b81810381811115610ead577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b92915050565b600060208284031215610ec557600080fd5b81518015158114610e5357600080fd5b60005b83811015610ef0578181015183820152602001610ed8565b50506000910152565b60008251610f0b818460208701610ed5565b9190910192915050565b6020815260008251806020840152610f34816040850160208701610ed5565b601f01601f1916919091016040019291505056fea26469706673582212200db484236e1da91f5f13f8216e7ca3faf20d1d632427f6e63f6ba0cffb70a3e864736f6c63430008110033",
|
|
280
|
+
"linkReferences": {},
|
|
281
|
+
"deployedLinkReferences": {}
|
|
282
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import "@openzeppelin/contracts/access/Ownable.sol";
|
|
6
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
7
|
+
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
8
|
+
|
|
9
|
+
import "../token/TBTC.sol";
|
|
10
|
+
|
|
11
|
+
/// @title VendingMachineV2
|
|
12
|
+
/// @notice VendingMachineV2 is used to exchange tBTC v1 to tBTC v2 in a 1:1
|
|
13
|
+
/// ratio during the process of tBTC v1 bridge sunsetting. The redeemer
|
|
14
|
+
/// selected by the DAO based on the "TIP-027b tBTC v1: The Sunsetting"
|
|
15
|
+
/// proposal will deposit tBTC v2 tokens into VendingMachineV2 so that
|
|
16
|
+
/// outstanding tBTC v1 token owners can upgrade to tBTC v2 tokens.
|
|
17
|
+
/// The redeemer will withdraw the tBTC v1 tokens deposited into the
|
|
18
|
+
/// contract to perform tBTC v1 redemptions.
|
|
19
|
+
/// The redeemer may decide to withdraw their deposited tBTC v2 at any
|
|
20
|
+
/// moment in time. The amount withdrawable is lower than the amount
|
|
21
|
+
/// deposited in case tBTC v1 was exchanged for tBTC v2.
|
|
22
|
+
/// This contract is owned by the redeemer.
|
|
23
|
+
contract VendingMachineV2 is Ownable {
|
|
24
|
+
using SafeERC20 for IERC20;
|
|
25
|
+
using SafeERC20 for TBTC;
|
|
26
|
+
|
|
27
|
+
IERC20 public immutable tbtcV1;
|
|
28
|
+
TBTC public immutable tbtcV2;
|
|
29
|
+
|
|
30
|
+
event Exchanged(address indexed to, uint256 amount);
|
|
31
|
+
event Deposited(address from, uint256 amount);
|
|
32
|
+
event Withdrawn(address token, address to, uint256 amount);
|
|
33
|
+
|
|
34
|
+
constructor(IERC20 _tbtcV1, TBTC _tbtcV2) {
|
|
35
|
+
tbtcV1 = _tbtcV1;
|
|
36
|
+
tbtcV2 = _tbtcV2;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// @notice Exchange tBTC v1 for tBTC v2 in a 1:1 ratio.
|
|
40
|
+
/// The caller needs to have at least `amount` of tBTC v1 balance
|
|
41
|
+
/// approved for transfer to the `VendingMachineV2` before calling
|
|
42
|
+
/// this function.
|
|
43
|
+
/// @param amount The amount of tBTC v1 to exchange for tBTC v2.
|
|
44
|
+
function exchange(uint256 amount) external {
|
|
45
|
+
_exchange(msg.sender, amount);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// @notice Exchange tBTC v1 for tBTC v2 in a 1:1 ratio.
|
|
49
|
+
/// The caller needs to have at least `amount` of tBTC v1 balance
|
|
50
|
+
/// approved for transfer to the `VendingMachineV2` before calling
|
|
51
|
+
/// this function.
|
|
52
|
+
/// @dev This function is a shortcut for `approve` + `exchange`. Only tBTC
|
|
53
|
+
/// v1 token caller is allowed and only tBTC v1 is allowed as a token
|
|
54
|
+
/// to transfer.
|
|
55
|
+
/// @param from tBTC v1 token holder exchanging tBTC v1 to tBTC v2.
|
|
56
|
+
/// @param amount The amount of tBTC v1 to exchange for tBTC v2.
|
|
57
|
+
/// @param token tBTC v1 token address.
|
|
58
|
+
function receiveApproval(
|
|
59
|
+
address from,
|
|
60
|
+
uint256 amount,
|
|
61
|
+
address token,
|
|
62
|
+
bytes calldata
|
|
63
|
+
) external {
|
|
64
|
+
require(token == address(tbtcV1), "Token is not tBTC v1");
|
|
65
|
+
require(msg.sender == address(tbtcV1), "Only tBTC v1 caller allowed");
|
|
66
|
+
_exchange(from, amount);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// @notice Allows to deposit tBTC v2 tokens to the contract.
|
|
70
|
+
/// VendingMachineV2 can not mint tBTC v2 tokens so tBTC v2 needs
|
|
71
|
+
/// to be deposited into the contract so that tBTC v1 to tBTC v2
|
|
72
|
+
/// exchange can happen.
|
|
73
|
+
/// The caller needs to have at least `amount` of tBTC v2 balance
|
|
74
|
+
/// approved for transfer to the `VendingMachineV2` before calling
|
|
75
|
+
/// this function.
|
|
76
|
+
/// @dev This function is for the redeemer and tBTC v1 operators. This is
|
|
77
|
+
/// NOT a function for tBTC v1 token holders.
|
|
78
|
+
/// @param amount The amount of tBTC v2 to deposit into the contract.
|
|
79
|
+
function depositTbtcV2(uint256 amount) external {
|
|
80
|
+
emit Deposited(msg.sender, amount);
|
|
81
|
+
tbtcV2.safeTransferFrom(msg.sender, address(this), amount);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// @notice Allows the contract owner to withdraw tokens. This function is
|
|
85
|
+
/// used in two cases: 1) when the redeemer wants to redeem tBTC v1
|
|
86
|
+
/// tokens to perform tBTC v2 redemptions; 2) when the deadline for
|
|
87
|
+
/// tBTC v1 -> tBTC v2 exchange passed and the redeemer wants their
|
|
88
|
+
/// tBTC v2 back.
|
|
89
|
+
/// @dev This function is for the redeemer. This is NOT a function for
|
|
90
|
+
/// tBTC v1 token holders.
|
|
91
|
+
/// @param token The address of a token to withdraw.
|
|
92
|
+
/// @param recipient The address which should receive withdrawn tokens.
|
|
93
|
+
/// @param amount The amount to withdraw.
|
|
94
|
+
function withdrawFunds(
|
|
95
|
+
IERC20 token,
|
|
96
|
+
address recipient,
|
|
97
|
+
uint256 amount
|
|
98
|
+
) external onlyOwner {
|
|
99
|
+
emit Withdrawn(address(token), recipient, amount);
|
|
100
|
+
token.safeTransfer(recipient, amount);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function _exchange(address tokenOwner, uint256 amount) internal {
|
|
104
|
+
require(
|
|
105
|
+
tbtcV2.balanceOf(address(this)) >= amount,
|
|
106
|
+
"Not enough tBTC v2 available in the Vending Machine"
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
emit Exchanged(tokenOwner, amount);
|
|
110
|
+
tbtcV1.safeTransferFrom(tokenOwner, address(this), amount);
|
|
111
|
+
|
|
112
|
+
tbtcV2.safeTransfer(tokenOwner, amount);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
|
|
3
|
+
pragma solidity 0.8.17;
|
|
4
|
+
|
|
5
|
+
import "@openzeppelin/contracts/access/Ownable.sol";
|
|
6
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
7
|
+
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
8
|
+
|
|
9
|
+
import "../token/TBTC.sol";
|
|
10
|
+
|
|
11
|
+
/// @title VendingMachineV3
|
|
12
|
+
/// @notice VendingMachineV3 is used to exchange tBTC v1 to tBTC v2 in a 1:1
|
|
13
|
+
/// ratio after the tBTC v1 bridge sunsetting is completed. Since
|
|
14
|
+
/// tBTC v1 bridge is no longer working, tBTC v1 tokens can not be used
|
|
15
|
+
/// to perform BTC redemptions. This contract allows tBTC v1 owners to
|
|
16
|
+
/// upgrade to tBTC v2 without any deadline. This way, tBTC v1 tokens
|
|
17
|
+
/// left on the market are always backed by Bitcoin. The governance will
|
|
18
|
+
/// deposit tBTC v2 into the contract in the amount equal to tBTC v1
|
|
19
|
+
/// supply. The governance is allowed to withdraw tBTC v2 only if tBTC
|
|
20
|
+
/// v2 left in this contract is enough to cover the upgrade of all tBTC
|
|
21
|
+
/// v1 left on the market. This contract is owned by the governance.
|
|
22
|
+
contract VendingMachineV3 is Ownable {
|
|
23
|
+
using SafeERC20 for IERC20;
|
|
24
|
+
using SafeERC20 for TBTC;
|
|
25
|
+
|
|
26
|
+
IERC20 public immutable tbtcV1;
|
|
27
|
+
TBTC public immutable tbtcV2;
|
|
28
|
+
|
|
29
|
+
event Exchanged(address indexed to, uint256 amount);
|
|
30
|
+
event Deposited(address from, uint256 amount);
|
|
31
|
+
event TbtcV2Withdrawn(address to, uint256 amount);
|
|
32
|
+
event FundsRecovered(address token, address to, uint256 amount);
|
|
33
|
+
|
|
34
|
+
constructor(IERC20 _tbtcV1, TBTC _tbtcV2) {
|
|
35
|
+
tbtcV1 = _tbtcV1;
|
|
36
|
+
tbtcV2 = _tbtcV2;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// @notice Exchange tBTC v1 for tBTC v2 in a 1:1 ratio.
|
|
40
|
+
/// The caller needs to have at least `amount` of tBTC v1 balance
|
|
41
|
+
/// approved for transfer to the `VendingMachineV3` before calling
|
|
42
|
+
/// this function.
|
|
43
|
+
/// @param amount The amount of tBTC v1 to exchange for tBTC v2.
|
|
44
|
+
function exchange(uint256 amount) external {
|
|
45
|
+
_exchange(msg.sender, amount);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// @notice Exchange tBTC v1 for tBTC v2 in a 1:1 ratio.
|
|
49
|
+
/// The caller needs to have at least `amount` of tBTC v1 balance
|
|
50
|
+
/// approved for transfer to the `VendingMachineV3` before calling
|
|
51
|
+
/// this function.
|
|
52
|
+
/// @dev This function is a shortcut for `approve` + `exchange`. Only tBTC
|
|
53
|
+
/// v1 caller is allowed and only tBTC v1 is allowed as a token to
|
|
54
|
+
/// transfer.
|
|
55
|
+
/// @param from tBTC v1 token holder exchanging tBTC v1 to tBTC v2.
|
|
56
|
+
/// @param amount The amount of tBTC v1 to exchange for tBTC v2.
|
|
57
|
+
/// @param token tBTC v1 token address.
|
|
58
|
+
function receiveApproval(
|
|
59
|
+
address from,
|
|
60
|
+
uint256 amount,
|
|
61
|
+
address token,
|
|
62
|
+
bytes calldata
|
|
63
|
+
) external {
|
|
64
|
+
require(token == address(tbtcV1), "Token is not tBTC v1");
|
|
65
|
+
require(msg.sender == address(tbtcV1), "Only tBTC v1 caller allowed");
|
|
66
|
+
_exchange(from, amount);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// @notice Allows to deposit tBTC v2 tokens to the contract.
|
|
70
|
+
/// `VendingMachineV3` can not mint tBTC v2 tokens so tBTC v2 needs
|
|
71
|
+
/// to be deposited into the contract so that tBTC v1 to tBTC v2
|
|
72
|
+
/// exchange can happen.
|
|
73
|
+
/// The caller needs to have at least `amount` of tBTC v2 balance
|
|
74
|
+
/// approved for transfer to the `VendingMachineV3` before calling
|
|
75
|
+
/// this function.
|
|
76
|
+
/// @dev This function is for the redeemer and tBTC v1 operators. This is
|
|
77
|
+
/// NOT a function for tBTC v1 token holders.
|
|
78
|
+
/// @param amount The amount of tBTC v2 to deposit into the contract.
|
|
79
|
+
function depositTbtcV2(uint256 amount) external {
|
|
80
|
+
emit Deposited(msg.sender, amount);
|
|
81
|
+
tbtcV2.safeTransferFrom(msg.sender, address(this), amount);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// @notice Allows the governance to withdraw tBTC v2 deposited into this
|
|
85
|
+
/// contract. The governance is allowed to withdraw tBTC v2
|
|
86
|
+
/// only if tBTC v2 left in this contract is enough to cover the
|
|
87
|
+
/// upgrade of all tBTC v1 left on the market.
|
|
88
|
+
/// @param recipient The address which should receive withdrawn tokens.
|
|
89
|
+
/// @param amount The amount to withdraw.
|
|
90
|
+
function withdrawTbtcV2(address recipient, uint256 amount)
|
|
91
|
+
external
|
|
92
|
+
onlyOwner
|
|
93
|
+
{
|
|
94
|
+
require(
|
|
95
|
+
tbtcV1.totalSupply() <= tbtcV2.balanceOf(address(this)) - amount,
|
|
96
|
+
"tBTC v1 must not be left unbacked"
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
emit TbtcV2Withdrawn(recipient, amount);
|
|
100
|
+
tbtcV2.safeTransfer(recipient, amount);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// @notice Allows the governance to recover ERC20 sent to this contract
|
|
104
|
+
/// by mistake or tBTC v1 locked in the contract to exchange to
|
|
105
|
+
/// tBTC v2. No tBTC v2 can be withdrawn using this function.
|
|
106
|
+
/// @param token The address of a token to recover.
|
|
107
|
+
/// @param recipient The address which should receive recovered tokens.
|
|
108
|
+
/// @param amount The amount to recover.
|
|
109
|
+
function recoverFunds(
|
|
110
|
+
IERC20 token,
|
|
111
|
+
address recipient,
|
|
112
|
+
uint256 amount
|
|
113
|
+
) external onlyOwner {
|
|
114
|
+
require(
|
|
115
|
+
address(token) != address(tbtcV2),
|
|
116
|
+
"tBTC v2 tokens can not be recovered, use withdrawTbtcV2 instead"
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
emit FundsRecovered(address(token), recipient, amount);
|
|
120
|
+
token.safeTransfer(recipient, amount);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function _exchange(address tokenOwner, uint256 amount) internal {
|
|
124
|
+
require(
|
|
125
|
+
tbtcV2.balanceOf(address(this)) >= amount,
|
|
126
|
+
"Not enough tBTC v2 available in the Vending Machine"
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
emit Exchanged(tokenOwner, amount);
|
|
130
|
+
tbtcV1.safeTransferFrom(tokenOwner, address(this), amount);
|
|
131
|
+
|
|
132
|
+
tbtcV2.safeTransfer(tokenOwner, amount);
|
|
133
|
+
}
|
|
134
|
+
}
|