@keep-network/tbtc-v2 0.1.1-dev.0 → 0.1.1-dev.12

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.
Files changed (30) hide show
  1. package/artifacts/TBTC.json +24 -24
  2. package/artifacts/TBTCToken.json +24 -24
  3. package/artifacts/VendingMachine.json +17 -17
  4. package/artifacts/solcInputs/258c81d1106a1d8dae0e3424749db907.json +134 -0
  5. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  6. package/build/contracts/bank/Bank.sol/Bank.dbg.json +4 -0
  7. package/build/contracts/bank/Bank.sol/Bank.json +537 -0
  8. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +4 -0
  9. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +10 -0
  10. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +4 -0
  11. package/build/contracts/bridge/Bridge.sol/Bridge.json +473 -0
  12. package/build/contracts/bridge/Bridge.sol/IRelay.dbg.json +4 -0
  13. package/build/contracts/bridge/Bridge.sol/IRelay.json +37 -0
  14. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  15. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
  16. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  17. package/build/contracts/token/TBTC.sol/TBTC.json +4 -4
  18. package/build/contracts/vault/IVault.sol/IVault.dbg.json +4 -0
  19. package/build/contracts/vault/IVault.sol/IVault.json +47 -0
  20. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +4 -0
  21. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +181 -0
  22. package/contracts/bank/Bank.sol +389 -0
  23. package/contracts/bridge/BitcoinTx.sol +125 -0
  24. package/contracts/bridge/Bridge.sol +804 -0
  25. package/contracts/vault/IVault.sol +60 -0
  26. package/contracts/vault/TBTCVault.sol +146 -0
  27. package/deploy/00_resolve_tbtc_v1_token.ts +1 -1
  28. package/export.json +4 -4
  29. package/package.json +25 -15
  30. package/artifacts/solcInputs/7cc3eda3cb3ff2522d18b5e7b31ea228.json +0 -104
@@ -0,0 +1,181 @@
1
+ {
2
+ "_format": "hh-sol-artifact-1",
3
+ "contractName": "TBTCVault",
4
+ "sourceName": "contracts/vault/TBTCVault.sol",
5
+ "abi": [
6
+ {
7
+ "inputs": [
8
+ {
9
+ "internalType": "contract Bank",
10
+ "name": "_bank",
11
+ "type": "address"
12
+ },
13
+ {
14
+ "internalType": "contract TBTC",
15
+ "name": "_tbtcToken",
16
+ "type": "address"
17
+ }
18
+ ],
19
+ "stateMutability": "nonpayable",
20
+ "type": "constructor"
21
+ },
22
+ {
23
+ "anonymous": false,
24
+ "inputs": [
25
+ {
26
+ "indexed": true,
27
+ "internalType": "address",
28
+ "name": "to",
29
+ "type": "address"
30
+ },
31
+ {
32
+ "indexed": false,
33
+ "internalType": "uint256",
34
+ "name": "amount",
35
+ "type": "uint256"
36
+ }
37
+ ],
38
+ "name": "Minted",
39
+ "type": "event"
40
+ },
41
+ {
42
+ "anonymous": false,
43
+ "inputs": [
44
+ {
45
+ "indexed": true,
46
+ "internalType": "address",
47
+ "name": "from",
48
+ "type": "address"
49
+ },
50
+ {
51
+ "indexed": false,
52
+ "internalType": "uint256",
53
+ "name": "amount",
54
+ "type": "uint256"
55
+ }
56
+ ],
57
+ "name": "Redeemed",
58
+ "type": "event"
59
+ },
60
+ {
61
+ "inputs": [],
62
+ "name": "bank",
63
+ "outputs": [
64
+ {
65
+ "internalType": "contract Bank",
66
+ "name": "",
67
+ "type": "address"
68
+ }
69
+ ],
70
+ "stateMutability": "view",
71
+ "type": "function"
72
+ },
73
+ {
74
+ "inputs": [
75
+ {
76
+ "internalType": "uint256",
77
+ "name": "amount",
78
+ "type": "uint256"
79
+ }
80
+ ],
81
+ "name": "mint",
82
+ "outputs": [],
83
+ "stateMutability": "nonpayable",
84
+ "type": "function"
85
+ },
86
+ {
87
+ "inputs": [
88
+ {
89
+ "internalType": "address",
90
+ "name": "from",
91
+ "type": "address"
92
+ },
93
+ {
94
+ "internalType": "uint256",
95
+ "name": "amount",
96
+ "type": "uint256"
97
+ },
98
+ {
99
+ "internalType": "address",
100
+ "name": "token",
101
+ "type": "address"
102
+ },
103
+ {
104
+ "internalType": "bytes",
105
+ "name": "",
106
+ "type": "bytes"
107
+ }
108
+ ],
109
+ "name": "receiveApproval",
110
+ "outputs": [],
111
+ "stateMutability": "nonpayable",
112
+ "type": "function"
113
+ },
114
+ {
115
+ "inputs": [
116
+ {
117
+ "internalType": "address",
118
+ "name": "owner",
119
+ "type": "address"
120
+ },
121
+ {
122
+ "internalType": "uint256",
123
+ "name": "amount",
124
+ "type": "uint256"
125
+ }
126
+ ],
127
+ "name": "receiveBalanceApproval",
128
+ "outputs": [],
129
+ "stateMutability": "nonpayable",
130
+ "type": "function"
131
+ },
132
+ {
133
+ "inputs": [
134
+ {
135
+ "internalType": "address[]",
136
+ "name": "depositors",
137
+ "type": "address[]"
138
+ },
139
+ {
140
+ "internalType": "uint256[]",
141
+ "name": "depositedAmounts",
142
+ "type": "uint256[]"
143
+ }
144
+ ],
145
+ "name": "receiveBalanceIncrease",
146
+ "outputs": [],
147
+ "stateMutability": "nonpayable",
148
+ "type": "function"
149
+ },
150
+ {
151
+ "inputs": [
152
+ {
153
+ "internalType": "uint256",
154
+ "name": "amount",
155
+ "type": "uint256"
156
+ }
157
+ ],
158
+ "name": "redeem",
159
+ "outputs": [],
160
+ "stateMutability": "nonpayable",
161
+ "type": "function"
162
+ },
163
+ {
164
+ "inputs": [],
165
+ "name": "tbtcToken",
166
+ "outputs": [
167
+ {
168
+ "internalType": "contract TBTC",
169
+ "name": "",
170
+ "type": "address"
171
+ }
172
+ ],
173
+ "stateMutability": "view",
174
+ "type": "function"
175
+ }
176
+ ],
177
+ "bytecode": "0x60806040523480156200001157600080fd5b5060405162001589380380620015898339818101604052810190620000379190620001d4565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415620000aa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620000a19062000285565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156200011d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620001149062000263565b60405180910390fd5b816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050620003c0565b600081519050620001b7816200038c565b92915050565b600081519050620001ce81620003a6565b92915050565b60008060408385031215620001e857600080fd5b6000620001f885828601620001a6565b92505060206200020b85828601620001bd565b9150509250929050565b600062000224602683620002a7565b9150620002318262000314565b604082019050919050565b60006200024b602083620002a7565b9150620002588262000363565b602082019050919050565b600060208201905081810360008301526200027e8162000215565b9050919050565b60006020820190508181036000830152620002a0816200023c565b9050919050565b600082825260208201905092915050565b6000620002c582620002f4565b9050919050565b6000620002d982620002b8565b9050919050565b6000620002ed82620002b8565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b7f5442544320746f6b656e2063616e206e6f7420626520746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f42616e6b2063616e206e6f7420626520746865207a65726f2061646472657373600082015250565b6200039781620002cc565b8114620003a357600080fd5b50565b620003b181620002e0565b8114620003bd57600080fd5b50565b6111b980620003d06000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638f4ffcb11161005b5780638f4ffcb1146100d8578063a0712d68146100f4578063db006a7514610110578063e5d3d7141461012c5761007d565b8063461c637314610082578063537941371461009e57806376cdb03b146100ba575b600080fd5b61009c60048036038101906100979190610c37565b61014a565b005b6100b860048036038101906100b39190610b7b565b6102dd565b005b6100c26104f3565b6040516100cf9190610e64565b60405180910390f35b6100f260048036038101906100ed9190610bb7565b610517565b005b61010e60048036038101906101099190610cac565b610626565b005b61012a60048036038101906101259190610cac565b6107b3565b005b6101346107c0565b6040516101419190610e7f565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101cf90610eda565b60405180910390fd5b600084849050141561021f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161021690610efa565b60405180910390fd5b60005b848490508110156102d6576102c3858583818110610269577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200201602081019061027e9190610b52565b8484848181106102b7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200201356107e6565b80806102ce90610fea565b915050610222565b5050505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461036b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161036290610eda565b60405180910390fd5b8060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231846040518263ffffffff1660e01b81526004016103c59190610de9565b60206040518083038186803b1580156103dd57600080fd5b505afa1580156103f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104159190610cd5565b1015610456576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161044d90610f1a565b60405180910390fd5b61046082826107e6565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c6db49c8330846040518463ffffffff1660e01b81526004016104bd93929190610e04565b600060405180830381600087803b1580156104d757600080fd5b505af11580156104eb573d6000803e3d6000fd5b505050505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16146105a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161059e90610eba565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610615576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161060c90610e9a565b60405180910390fd5b61061f85856108c7565b5050505050565b60003390508160008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b81526004016106859190610de9565b60206040518083038186803b15801561069d57600080fd5b505afa1580156106b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d59190610cd5565b1015610716576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161070d90610f1a565b60405180910390fd5b61072081836107e6565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c6db49c8230856040518463ffffffff1660e01b815260040161077d93929190610e04565b600060405180830381600087803b15801561079757600080fd5b505af11580156107ab573d6000803e3d6000fd5b505050505050565b6107bd33826108c7565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b8173ffffffffffffffffffffffffffffffffffffffff167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161082c9190610f3a565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1983836040518363ffffffff1660e01b8152600401610891929190610e3b565b600060405180830381600087803b1580156108ab57600080fd5b505af11580156108bf573d6000803e3d6000fd5b505050505050565b8173ffffffffffffffffffffffffffffffffffffffff167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b93698260405161090d9190610f3a565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166379cc679083836040518363ffffffff1660e01b8152600401610972929190610e3b565b600060405180830381600087803b15801561098c57600080fd5b505af11580156109a0573d6000803e3d6000fd5b5050505060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166356a6d9ef83836040518363ffffffff1660e01b81526004016109ff929190610e3b565b600060405180830381600087803b158015610a1957600080fd5b505af1158015610a2d573d6000803e3d6000fd5b505050505050565b600081359050610a4481611155565b92915050565b60008083601f840112610a5c57600080fd5b8235905067ffffffffffffffff811115610a7557600080fd5b602083019150836020820283011115610a8d57600080fd5b9250929050565b60008083601f840112610aa657600080fd5b8235905067ffffffffffffffff811115610abf57600080fd5b602083019150836020820283011115610ad757600080fd5b9250929050565b60008083601f840112610af057600080fd5b8235905067ffffffffffffffff811115610b0957600080fd5b602083019150836001820283011115610b2157600080fd5b9250929050565b600081359050610b378161116c565b92915050565b600081519050610b4c8161116c565b92915050565b600060208284031215610b6457600080fd5b6000610b7284828501610a35565b91505092915050565b60008060408385031215610b8e57600080fd5b6000610b9c85828601610a35565b9250506020610bad85828601610b28565b9150509250929050565b600080600080600060808688031215610bcf57600080fd5b6000610bdd88828901610a35565b9550506020610bee88828901610b28565b9450506040610bff88828901610a35565b935050606086013567ffffffffffffffff811115610c1c57600080fd5b610c2888828901610ade565b92509250509295509295909350565b60008060008060408587031215610c4d57600080fd5b600085013567ffffffffffffffff811115610c6757600080fd5b610c7387828801610a4a565b9450945050602085013567ffffffffffffffff811115610c9257600080fd5b610c9e87828801610a94565b925092505092959194509250565b600060208284031215610cbe57600080fd5b6000610ccc84828501610b28565b91505092915050565b600060208284031215610ce757600080fd5b6000610cf584828501610b3d565b91505092915050565b610d0781610f66565b82525050565b610d1681610fa2565b82525050565b610d2581610fc6565b82525050565b6000610d38601883610f55565b9150610d4382611062565b602082019050919050565b6000610d5b601183610f55565b9150610d668261108b565b602082019050919050565b6000610d7e601683610f55565b9150610d89826110b4565b602082019050919050565b6000610da1601783610f55565b9150610dac826110dd565b602082019050919050565b6000610dc4602283610f55565b9150610dcf82611106565b604082019050919050565b610de381610f98565b82525050565b6000602082019050610dfe6000830184610cfe565b92915050565b6000606082019050610e196000830186610cfe565b610e266020830185610cfe565b610e336040830184610dda565b949350505050565b6000604082019050610e506000830185610cfe565b610e5d6020830184610dda565b9392505050565b6000602082019050610e796000830184610d0d565b92915050565b6000602082019050610e946000830184610d1c565b92915050565b60006020820190508181036000830152610eb381610d2b565b9050919050565b60006020820190508181036000830152610ed381610d4e565b9050919050565b60006020820190508181036000830152610ef381610d71565b9050919050565b60006020820190508181036000830152610f1381610d94565b9050919050565b60006020820190508181036000830152610f3381610db7565b9050919050565b6000602082019050610f4f6000830184610dda565b92915050565b600082825260208201905092915050565b6000610f7182610f78565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000610fad82610fb4565b9050919050565b6000610fbf82610f78565b9050919050565b6000610fd182610fd8565b9050919050565b6000610fe382610f78565b9050919050565b6000610ff582610f98565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561102857611027611033565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000600082015250565b7f546f6b656e206973206e6f742054425443000000000000000000000000000000600082015250565b7f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000600082015250565b7f4e6f206465706f7369746f727320737065636966696564000000000000000000600082015250565b7f416d6f756e7420657863656564732062616c616e636520696e2074686520626160008201527f6e6b000000000000000000000000000000000000000000000000000000000000602082015250565b61115e81610f66565b811461116957600080fd5b50565b61117581610f98565b811461118057600080fd5b5056fea264697066735822122092c1be47215fc7822adb5e6bedef65d4620ae8ae5ccb0ed2dadf2b1d89e02ec264736f6c63430008040033",
178
+ "deployedBytecode": "0x608060405234801561001057600080fd5b506004361061007d5760003560e01c80638f4ffcb11161005b5780638f4ffcb1146100d8578063a0712d68146100f4578063db006a7514610110578063e5d3d7141461012c5761007d565b8063461c637314610082578063537941371461009e57806376cdb03b146100ba575b600080fd5b61009c60048036038101906100979190610c37565b61014a565b005b6100b860048036038101906100b39190610b7b565b6102dd565b005b6100c26104f3565b6040516100cf9190610e64565b60405180910390f35b6100f260048036038101906100ed9190610bb7565b610517565b005b61010e60048036038101906101099190610cac565b610626565b005b61012a60048036038101906101259190610cac565b6107b3565b005b6101346107c0565b6040516101419190610e7f565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101cf90610eda565b60405180910390fd5b600084849050141561021f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161021690610efa565b60405180910390fd5b60005b848490508110156102d6576102c3858583818110610269577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200201602081019061027e9190610b52565b8484848181106102b7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b905060200201356107e6565b80806102ce90610fea565b915050610222565b5050505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461036b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161036290610eda565b60405180910390fd5b8060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231846040518263ffffffff1660e01b81526004016103c59190610de9565b60206040518083038186803b1580156103dd57600080fd5b505afa1580156103f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104159190610cd5565b1015610456576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161044d90610f1a565b60405180910390fd5b61046082826107e6565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c6db49c8330846040518463ffffffff1660e01b81526004016104bd93929190610e04565b600060405180830381600087803b1580156104d757600080fd5b505af11580156104eb573d6000803e3d6000fd5b505050505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16146105a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161059e90610eba565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610615576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161060c90610e9a565b60405180910390fd5b61061f85856108c7565b5050505050565b60003390508160008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b81526004016106859190610de9565b60206040518083038186803b15801561069d57600080fd5b505afa1580156106b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106d59190610cd5565b1015610716576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161070d90610f1a565b60405180910390fd5b61072081836107e6565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c6db49c8230856040518463ffffffff1660e01b815260040161077d93929190610e04565b600060405180830381600087803b15801561079757600080fd5b505af11580156107ab573d6000803e3d6000fd5b505050505050565b6107bd33826108c7565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b8173ffffffffffffffffffffffffffffffffffffffff167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161082c9190610f3a565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1983836040518363ffffffff1660e01b8152600401610891929190610e3b565b600060405180830381600087803b1580156108ab57600080fd5b505af11580156108bf573d6000803e3d6000fd5b505050505050565b8173ffffffffffffffffffffffffffffffffffffffff167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b93698260405161090d9190610f3a565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166379cc679083836040518363ffffffff1660e01b8152600401610972929190610e3b565b600060405180830381600087803b15801561098c57600080fd5b505af11580156109a0573d6000803e3d6000fd5b5050505060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166356a6d9ef83836040518363ffffffff1660e01b81526004016109ff929190610e3b565b600060405180830381600087803b158015610a1957600080fd5b505af1158015610a2d573d6000803e3d6000fd5b505050505050565b600081359050610a4481611155565b92915050565b60008083601f840112610a5c57600080fd5b8235905067ffffffffffffffff811115610a7557600080fd5b602083019150836020820283011115610a8d57600080fd5b9250929050565b60008083601f840112610aa657600080fd5b8235905067ffffffffffffffff811115610abf57600080fd5b602083019150836020820283011115610ad757600080fd5b9250929050565b60008083601f840112610af057600080fd5b8235905067ffffffffffffffff811115610b0957600080fd5b602083019150836001820283011115610b2157600080fd5b9250929050565b600081359050610b378161116c565b92915050565b600081519050610b4c8161116c565b92915050565b600060208284031215610b6457600080fd5b6000610b7284828501610a35565b91505092915050565b60008060408385031215610b8e57600080fd5b6000610b9c85828601610a35565b9250506020610bad85828601610b28565b9150509250929050565b600080600080600060808688031215610bcf57600080fd5b6000610bdd88828901610a35565b9550506020610bee88828901610b28565b9450506040610bff88828901610a35565b935050606086013567ffffffffffffffff811115610c1c57600080fd5b610c2888828901610ade565b92509250509295509295909350565b60008060008060408587031215610c4d57600080fd5b600085013567ffffffffffffffff811115610c6757600080fd5b610c7387828801610a4a565b9450945050602085013567ffffffffffffffff811115610c9257600080fd5b610c9e87828801610a94565b925092505092959194509250565b600060208284031215610cbe57600080fd5b6000610ccc84828501610b28565b91505092915050565b600060208284031215610ce757600080fd5b6000610cf584828501610b3d565b91505092915050565b610d0781610f66565b82525050565b610d1681610fa2565b82525050565b610d2581610fc6565b82525050565b6000610d38601883610f55565b9150610d4382611062565b602082019050919050565b6000610d5b601183610f55565b9150610d668261108b565b602082019050919050565b6000610d7e601683610f55565b9150610d89826110b4565b602082019050919050565b6000610da1601783610f55565b9150610dac826110dd565b602082019050919050565b6000610dc4602283610f55565b9150610dcf82611106565b604082019050919050565b610de381610f98565b82525050565b6000602082019050610dfe6000830184610cfe565b92915050565b6000606082019050610e196000830186610cfe565b610e266020830185610cfe565b610e336040830184610dda565b949350505050565b6000604082019050610e506000830185610cfe565b610e5d6020830184610dda565b9392505050565b6000602082019050610e796000830184610d0d565b92915050565b6000602082019050610e946000830184610d1c565b92915050565b60006020820190508181036000830152610eb381610d2b565b9050919050565b60006020820190508181036000830152610ed381610d4e565b9050919050565b60006020820190508181036000830152610ef381610d71565b9050919050565b60006020820190508181036000830152610f1381610d94565b9050919050565b60006020820190508181036000830152610f3381610db7565b9050919050565b6000602082019050610f4f6000830184610dda565b92915050565b600082825260208201905092915050565b6000610f7182610f78565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000610fad82610fb4565b9050919050565b6000610fbf82610f78565b9050919050565b6000610fd182610fd8565b9050919050565b6000610fe382610f78565b9050919050565b6000610ff582610f98565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561102857611027611033565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000600082015250565b7f546f6b656e206973206e6f742054425443000000000000000000000000000000600082015250565b7f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000600082015250565b7f4e6f206465706f7369746f727320737065636966696564000000000000000000600082015250565b7f416d6f756e7420657863656564732062616c616e636520696e2074686520626160008201527f6e6b000000000000000000000000000000000000000000000000000000000000602082015250565b61115e81610f66565b811461116957600080fd5b50565b61117581610f98565b811461118057600080fd5b5056fea264697066735822122092c1be47215fc7822adb5e6bedef65d4620ae8ae5ccb0ed2dadf2b1d89e02ec264736f6c63430008040033",
179
+ "linkReferences": {},
180
+ "deployedLinkReferences": {}
181
+ }
@@ -0,0 +1,389 @@
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 "@openzeppelin/contracts/access/Ownable.sol";
19
+
20
+ import "../vault/IVault.sol";
21
+
22
+ /// @title Bitcoin Bank
23
+ /// @notice Bank is a central component tracking Bitcoin balances. Balances can
24
+ /// be transferred between holders and holders can approve their
25
+ /// balances to be spent by others. Balances in the Bank are updated for
26
+ /// depositors who deposit their Bitcoin into the Bridge and only the
27
+ /// Bridge can increase balances.
28
+ /// @dev Bank is a governable contract and the Governance can upgrade the Bridge
29
+ /// address.
30
+ contract Bank is Ownable {
31
+ address public bridge;
32
+
33
+ /// @notice The balance of a given account in the Bank. Zero by default.
34
+ mapping(address => uint256) public balanceOf;
35
+
36
+ /// @notice The remaining amount of balance a spender will be
37
+ /// allowed to transfer on behalf of an owner using
38
+ /// `transferBalanceFrom`. Zero by default.
39
+ mapping(address => mapping(address => uint256)) public allowance;
40
+
41
+ /// @notice Returns the current nonce for EIP2612 permission for the
42
+ /// provided balance owner for a replay protection. Used to
43
+ /// construct EIP2612 signature provided to `permit` function.
44
+ mapping(address => uint256) public nonce;
45
+
46
+ uint256 public immutable cachedChainId;
47
+ bytes32 public immutable cachedDomainSeparator;
48
+
49
+ /// @notice Returns EIP2612 Permit message hash. Used to construct EIP2612
50
+ /// signature provided to `permit` function.
51
+ bytes32 public constant PERMIT_TYPEHASH =
52
+ keccak256(
53
+ "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
54
+ );
55
+
56
+ event BalanceTransferred(
57
+ address indexed from,
58
+ address indexed to,
59
+ uint256 amount
60
+ );
61
+
62
+ event BalanceApproved(
63
+ address indexed owner,
64
+ address indexed spender,
65
+ uint256 amount
66
+ );
67
+
68
+ event BalanceIncreased(address indexed owner, uint256 amount);
69
+
70
+ event BalanceDecreased(address indexed owner, uint256 amount);
71
+
72
+ event BridgeUpdated(address newBridge);
73
+
74
+ modifier onlyBridge() {
75
+ require(msg.sender == address(bridge), "Caller is not the bridge");
76
+ _;
77
+ }
78
+
79
+ constructor() {
80
+ cachedChainId = block.chainid;
81
+ cachedDomainSeparator = buildDomainSeparator();
82
+ }
83
+
84
+ /// @notice Allows the Governance to upgrade the Bridge address.
85
+ /// @dev The function does not implement any governance delay and does not
86
+ /// check the status of the Bridge. The Governance implementation needs
87
+ /// to ensure all requirements for the upgrade are satisfied before
88
+ /// executing this function.
89
+ function updateBridge(address _bridge) external onlyOwner {
90
+ require(_bridge != address(0), "Bridge address must not be 0x0");
91
+ bridge = _bridge;
92
+ emit BridgeUpdated(_bridge);
93
+ }
94
+
95
+ /// @notice Moves the given `amount` of balance from the caller to
96
+ /// `recipient`.
97
+ /// @dev Requirements:
98
+ /// - `recipient` cannot be the zero address,
99
+ /// - the caller must have a balance of at least `amount`.
100
+ function transferBalance(address recipient, uint256 amount) external {
101
+ _transferBalance(msg.sender, recipient, amount);
102
+ }
103
+
104
+ /// @notice Sets `amount` as the allowance of `spender` over the caller's
105
+ /// balance.
106
+ /// @dev If the `amount` is set to `type(uint256).max` then
107
+ /// `transferBalanceFrom` will not reduce an allowance.
108
+ /// Beware that changing an allowance with this function brings the
109
+ /// risk that someone may use both the old and the new allowance by
110
+ /// unfortunate transaction ordering. Please use
111
+ /// `increaseBalanceAllowance` and `decreaseBalanceAllowance` to
112
+ /// eliminate the risk.
113
+ function approveBalance(address spender, uint256 amount) external {
114
+ _approveBalance(msg.sender, spender, amount);
115
+ }
116
+
117
+ /// @notice Sets `amount` as the allowance of a smart contract `vault` over
118
+ /// the caller's balance and calls the vault via
119
+ /// `receiveBalanceApproval`.
120
+ /// @dev If the `amount` is set to `type(uint256).max` then the logic in
121
+ /// `receiveBalanceApproval` or later call to `transferBalanceFrom` by
122
+ /// the vault will not reduce an allowance. Beware that changing an
123
+ /// allowance with this function brings the risk that vault may use
124
+ /// both the old and the new allowance by unfortunate transaction
125
+ /// ordering. Please use `increaseBalanceAllowance` and
126
+ /// `decreaseBalanceAllowance` to eliminate the risk.
127
+ function approveBalanceAndCall(address vault, uint256 amount) external {
128
+ _approveBalance(msg.sender, vault, amount);
129
+ IVault(vault).receiveBalanceApproval(msg.sender, amount);
130
+ }
131
+
132
+ /// @notice Atomically increases the balance allowance granted to `spender`
133
+ /// by the caller by the given `addedValue`.
134
+ function increaseBalanceAllowance(address spender, uint256 addedValue)
135
+ external
136
+ {
137
+ _approveBalance(
138
+ msg.sender,
139
+ spender,
140
+ allowance[msg.sender][spender] + addedValue
141
+ );
142
+ }
143
+
144
+ /// @notice Atomically decreases the balance allowance granted to `spender`
145
+ /// by the caller by the given `subtractedValue`.
146
+ function decreaseBalanceAllowance(address spender, uint256 subtractedValue)
147
+ external
148
+ {
149
+ uint256 currentAllowance = allowance[msg.sender][spender];
150
+ require(
151
+ currentAllowance >= subtractedValue,
152
+ "Can not decrease balance allowance below zero"
153
+ );
154
+ unchecked {
155
+ _approveBalance(
156
+ msg.sender,
157
+ spender,
158
+ currentAllowance - subtractedValue
159
+ );
160
+ }
161
+ }
162
+
163
+ /// @notice Moves `amount` of balance from `spender` to `recipient` using the
164
+ /// allowance mechanism. `amount` is then deducted from the caller's
165
+ /// allowance unless the allowance was made for `type(uint256).max`.
166
+ /// @dev Requirements:
167
+ /// - `recipient` cannot be the zero address,
168
+ /// - `spender` must have a balance of at least `amount`,
169
+ /// - the caller must have allowance for `spender`'s balance of at
170
+ /// least `amount`.
171
+ function transferBalanceFrom(
172
+ address spender,
173
+ address recipient,
174
+ uint256 amount
175
+ ) external {
176
+ uint256 currentAllowance = allowance[spender][msg.sender];
177
+ if (currentAllowance != type(uint256).max) {
178
+ require(
179
+ currentAllowance >= amount,
180
+ "Transfer amount exceeds allowance"
181
+ );
182
+ unchecked {
183
+ _approveBalance(spender, msg.sender, currentAllowance - amount);
184
+ }
185
+ }
186
+ _transferBalance(spender, recipient, amount);
187
+ }
188
+
189
+ /// @notice EIP2612 approval made with secp256k1 signature.
190
+ /// Users can authorize a transfer of their balance with a signature
191
+ /// conforming EIP712 standard, rather than an on-chain transaction
192
+ /// from their address. Anyone can submit this signature on the
193
+ /// user's behalf by calling the permit function, paying gas fees,
194
+ /// and possibly performing other actions in the same transaction.
195
+ /// @dev The deadline argument can be set to `type(uint256).max to create
196
+ /// permits that effectively never expire. If the `amount` is set
197
+ /// to `type(uint256).max` then `transferBalanceFrom` will not
198
+ /// reduce an allowance. Beware that changing an allowance with this
199
+ /// function brings the risk that someone may use both the old and the
200
+ /// new allowance by unfortunate transaction ordering. Please use
201
+ /// `increaseBalanceAllowance` and `decreaseBalanceAllowance` to
202
+ /// eliminate the risk.
203
+ function permit(
204
+ address owner,
205
+ address spender,
206
+ uint256 amount,
207
+ uint256 deadline,
208
+ uint8 v,
209
+ bytes32 r,
210
+ bytes32 s
211
+ ) external {
212
+ /* solhint-disable-next-line not-rely-on-time */
213
+ require(deadline >= block.timestamp, "Permission expired");
214
+
215
+ // Validate `s` and `v` values for a malleability concern described in EIP2.
216
+ // Only signatures with `s` value in the lower half of the secp256k1
217
+ // curve's order and `v` value of 27 or 28 are considered valid.
218
+ require(
219
+ uint256(s) <=
220
+ 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
221
+ "Invalid signature 's' value"
222
+ );
223
+ require(v == 27 || v == 28, "Invalid signature 'v' value");
224
+
225
+ bytes32 digest =
226
+ keccak256(
227
+ abi.encodePacked(
228
+ "\x19\x01",
229
+ DOMAIN_SEPARATOR(),
230
+ keccak256(
231
+ abi.encode(
232
+ PERMIT_TYPEHASH,
233
+ owner,
234
+ spender,
235
+ amount,
236
+ nonce[owner]++,
237
+ deadline
238
+ )
239
+ )
240
+ )
241
+ );
242
+ address recoveredAddress = ecrecover(digest, v, r, s);
243
+ require(
244
+ recoveredAddress != address(0) && recoveredAddress == owner,
245
+ "Invalid signature"
246
+ );
247
+ _approveBalance(owner, spender, amount);
248
+ }
249
+
250
+ /// @notice Increases balances of the provided `recipients` by the provided
251
+ /// `amounts`. Can only be called by the Bridge.
252
+ /// @dev Requirements:
253
+ /// - length of `recipients` and `amounts` must be the same.
254
+ function increaseBalances(
255
+ address[] calldata recipients,
256
+ uint256[] calldata amounts
257
+ ) external onlyBridge {
258
+ require(
259
+ recipients.length == amounts.length,
260
+ "Arrays must have the same length"
261
+ );
262
+ for (uint256 i = 0; i < recipients.length; i++) {
263
+ _increaseBalance(recipients[i], amounts[i]);
264
+ }
265
+ }
266
+
267
+ /// @notice Increases balance of the provided `recipient` by the provided
268
+ /// `amount`. Can only be called by the Bridge.
269
+ function increaseBalance(address recipient, uint256 amount)
270
+ external
271
+ onlyBridge
272
+ {
273
+ _increaseBalance(recipient, amount);
274
+ }
275
+
276
+ /// @notice Increases the given smart contract `vault`'s balance and
277
+ /// notifies the `vault` contract. Called by the Bridge after
278
+ /// the deposits routed by depositors to that `vault` have been
279
+ /// swept by the Bridge. This way, the depositor does not have to
280
+ /// issue a separate transaction to the `vault` contract.
281
+ /// Can be called only by the Bridge.
282
+ /// @dev Requirements:
283
+ /// - `vault` must implement `IVault` interface,
284
+ /// - length of `depositors` and `depositedAmounts` must be the same.
285
+ /// @param vault Address of `IVault` recipient contract
286
+ /// @param depositors Addresses of depositors whose deposits have been swept
287
+ /// @param depositedAmounts Amounts deposited by individual depositors and
288
+ /// swept. The `vault`'s balance in the Bank will be increased by the
289
+ /// sum of all elements in this array.
290
+ function increaseBalanceAndCall(
291
+ address vault,
292
+ address[] calldata depositors,
293
+ uint256[] calldata depositedAmounts
294
+ ) external onlyBridge {
295
+ require(
296
+ depositors.length == depositedAmounts.length,
297
+ "Arrays must have the same length"
298
+ );
299
+ uint256 totalAmount = 0;
300
+ for (uint256 i = 0; i < depositedAmounts.length; i++) {
301
+ totalAmount += depositedAmounts[i];
302
+ }
303
+ _increaseBalance(vault, totalAmount);
304
+ IVault(vault).receiveBalanceIncrease(depositors, depositedAmounts);
305
+ }
306
+
307
+ /// @notice Decreases caller's balance by the provided `amount`. There is no
308
+ /// way to restore the balance so do not call this function unless
309
+ /// you really know what you are doing!
310
+ function decreaseBalance(uint256 amount) external {
311
+ balanceOf[msg.sender] -= amount;
312
+ emit BalanceDecreased(msg.sender, amount);
313
+ }
314
+
315
+ /// @notice Returns hash of EIP712 Domain struct with `TBTC Bank` as
316
+ /// a signing domain and Bank contract as a verifying contract.
317
+ /// Used to construct EIP2612 signature provided to `permit`
318
+ /// function.
319
+ /* solhint-disable-next-line func-name-mixedcase */
320
+ function DOMAIN_SEPARATOR() public view returns (bytes32) {
321
+ // As explained in EIP-2612, if the DOMAIN_SEPARATOR contains the
322
+ // chainId and is defined at contract deployment instead of
323
+ // reconstructed for every signature, there is a risk of possible replay
324
+ // attacks between chains in the event of a future chain split.
325
+ // To address this issue, we check the cached chain ID against the
326
+ // current one and in case they are different, we build domain separator
327
+ // from scratch.
328
+ if (block.chainid == cachedChainId) {
329
+ return cachedDomainSeparator;
330
+ } else {
331
+ return buildDomainSeparator();
332
+ }
333
+ }
334
+
335
+ function _increaseBalance(address recipient, uint256 amount) internal {
336
+ require(
337
+ recipient != address(this),
338
+ "Can not increase balance for Bank"
339
+ );
340
+ balanceOf[recipient] += amount;
341
+ emit BalanceIncreased(recipient, amount);
342
+ }
343
+
344
+ function _transferBalance(
345
+ address spender,
346
+ address recipient,
347
+ uint256 amount
348
+ ) private {
349
+ require(
350
+ recipient != address(0),
351
+ "Can not transfer to the zero address"
352
+ );
353
+ require(
354
+ recipient != address(this),
355
+ "Can not transfer to the Bank address"
356
+ );
357
+
358
+ uint256 spenderBalance = balanceOf[spender];
359
+ require(spenderBalance >= amount, "Transfer amount exceeds balance");
360
+ unchecked {balanceOf[spender] = spenderBalance - amount;}
361
+ balanceOf[recipient] += amount;
362
+ emit BalanceTransferred(spender, recipient, amount);
363
+ }
364
+
365
+ function _approveBalance(
366
+ address owner,
367
+ address spender,
368
+ uint256 amount
369
+ ) private {
370
+ require(spender != address(0), "Can not approve to the zero address");
371
+ allowance[owner][spender] = amount;
372
+ emit BalanceApproved(owner, spender, amount);
373
+ }
374
+
375
+ function buildDomainSeparator() private view returns (bytes32) {
376
+ return
377
+ keccak256(
378
+ abi.encode(
379
+ keccak256(
380
+ "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
381
+ ),
382
+ keccak256(bytes("TBTC Bank")),
383
+ keccak256(bytes("1")),
384
+ block.chainid,
385
+ address(this)
386
+ )
387
+ );
388
+ }
389
+ }