@keep-network/tbtc-v2 0.1.1-dev.82 → 0.1.1-dev.83

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 (69) hide show
  1. package/artifacts/Bank.json +8 -8
  2. package/artifacts/Bridge.json +33 -11
  3. package/artifacts/Deposit.json +7 -7
  4. package/artifacts/DepositSweep.json +7 -7
  5. package/artifacts/EcdsaDkgValidator.json +1 -1
  6. package/artifacts/EcdsaInactivity.json +1 -1
  7. package/artifacts/EcdsaSortitionPool.json +2 -2
  8. package/artifacts/Fraud.json +7 -7
  9. package/artifacts/KeepRegistry.json +1 -1
  10. package/artifacts/KeepStake.json +2 -2
  11. package/artifacts/KeepToken.json +2 -2
  12. package/artifacts/KeepTokenStaking.json +1 -1
  13. package/artifacts/MovingFunds.json +9 -9
  14. package/artifacts/NuCypherStakingEscrow.json +1 -1
  15. package/artifacts/NuCypherToken.json +2 -2
  16. package/artifacts/RandomBeaconStub.json +1 -1
  17. package/artifacts/Redemption.json +26 -14
  18. package/artifacts/ReimbursementPool.json +2 -2
  19. package/artifacts/Relay.json +11 -11
  20. package/artifacts/T.json +2 -2
  21. package/artifacts/TBTC.json +13 -13
  22. package/artifacts/TBTCToken.json +13 -13
  23. package/artifacts/TBTCVault.json +12 -12
  24. package/artifacts/TokenStaking.json +1 -1
  25. package/artifacts/TokenholderGovernor.json +9 -9
  26. package/artifacts/TokenholderTimelock.json +8 -8
  27. package/artifacts/VendingMachine.json +11 -11
  28. package/artifacts/VendingMachineKeep.json +1 -1
  29. package/artifacts/VendingMachineNuCypher.json +1 -1
  30. package/artifacts/WalletRegistry.json +5 -5
  31. package/artifacts/WalletRegistryGovernance.json +2 -2
  32. package/artifacts/Wallets.json +9 -9
  33. package/artifacts/solcInputs/{5cd0a97e230d515eacf46fb60ea8963a.json → 21fcfd91cc383ddf1b3799814408151d.json} +9 -6
  34. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  35. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  36. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +1 -1
  37. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  38. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  39. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  40. package/build/contracts/bridge/Bridge.sol/Bridge.json +73 -42
  41. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +2 -2
  43. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  44. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  45. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +1 -1
  46. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +2 -2
  47. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  48. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  49. package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -2
  50. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +1 -1
  51. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  52. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  53. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +2 -2
  54. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
  55. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +2 -2
  56. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
  57. package/build/contracts/bridge/Redemption.sol/Redemption.json +2 -2
  58. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  59. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  60. package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
  61. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  62. package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +1 -1
  63. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  64. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  65. package/contracts/bridge/BitcoinTx.sol +1 -1
  66. package/contracts/bridge/Bridge.sol +85 -6
  67. package/contracts/bridge/Redemption.sol +160 -6
  68. package/export.json +22 -0
  69. package/package.json +1 -1
@@ -233,15 +233,21 @@ library Redemption {
233
233
 
234
234
  /// @notice Requests redemption of the given amount from the specified
235
235
  /// wallet to the redeemer Bitcoin output script.
236
+ /// This function handles the simplest case, where balance owner is
237
+ /// the redeemer.
236
238
  /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
237
239
  /// using Bitcoin HASH160 over the compressed ECDSA public key).
238
240
  /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
239
241
  /// the Ethereum chain.
242
+ /// @param balanceOwner The address of the Bank balance owner whose balance
243
+ /// is getting redeemed. Balance owner address is stored as
244
+ /// a redemeer address who will be able co claim back the Bank
245
+ /// balance if anything goes wrong during the redemption.
240
246
  /// @param redeemerOutputScript The redeemer's length-prefixed output
241
247
  /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
242
248
  /// redeemed BTC.
243
- /// @param amount Requested amount in satoshi. This is also the TBTC amount
244
- /// that is taken from redeemer's balance in the Bank upon request.
249
+ /// @param amount Requested amount in satoshi. This is also the Bank balance
250
+ /// that is taken from the `balanceOwner` upon request.
245
251
  /// Once the request is handled, the actual amount of BTC locked
246
252
  /// on the redeemer output script will be always lower than this value
247
253
  /// since the treasury and Bitcoin transaction fees must be incurred.
@@ -258,15 +264,163 @@ library Redemption {
258
264
  /// - Given `walletPubKeyHash` and `redeemerOutputScript` pair can be
259
265
  /// used for only one pending request at the same time,
260
266
  /// - Wallet must have enough Bitcoin balance to proceed the request,
261
- /// - Redeemer must make an allowance in the Bank that the Bridge
267
+ /// - Balance owner must make an allowance in the Bank that the Bridge
262
268
  /// contract can spend the given `amount`.
263
269
  function requestRedemption(
264
270
  BridgeState.Storage storage self,
265
271
  bytes20 walletPubKeyHash,
266
272
  BitcoinTx.UTXO calldata mainUtxo,
273
+ address balanceOwner,
267
274
  bytes calldata redeemerOutputScript,
268
275
  uint64 amount
269
276
  ) external {
277
+ requestRedemption(
278
+ self,
279
+ walletPubKeyHash,
280
+ mainUtxo,
281
+ balanceOwner,
282
+ balanceOwner,
283
+ redeemerOutputScript,
284
+ amount
285
+ );
286
+ }
287
+
288
+ /// @notice Requests redemption of the given amount from the specified
289
+ /// wallet to the redeemer Bitcoin output script. Used by
290
+ /// `Bridge.receiveBalanceApproval`. Can handle more complex cases
291
+ /// where balance owner may be someone else than the redeemer.
292
+ /// @param balanceOwner The address of the Bank balance owner whose balance
293
+ /// is getting redeemed.
294
+ /// @param amount Requested amount in satoshi. This is also the Bank balance
295
+ /// that is taken from the `balanceOwner` upon request.
296
+ /// Once the request is handled, the actual amount of BTC locked
297
+ /// on the redeemer output script will be always lower than this value
298
+ /// since the treasury and Bitcoin transaction fees must be incurred.
299
+ /// The minimal amount satisfying the request can be computed as:
300
+ /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
301
+ /// Fees values are taken at the moment of request creation.
302
+ /// @param redemptionData ABI-encoded redemption data:
303
+ /// [
304
+ /// address redeemer,
305
+ /// bytes20 walletPubKeyHash,
306
+ /// bytes32 mainUtxoTxHash,
307
+ /// uint32 mainUtxoTxOutputIndex,
308
+ /// uint64 mainUtxoTxOutputValue,
309
+ /// bytes redeemerOutputScript
310
+ /// ]
311
+ ///
312
+ /// - redeemer: The Ethereum address of the redeemer who will be able
313
+ /// to claim Bank balance if anything goes wrong during the redemption.
314
+ /// In the most basic case, when someone redeems their Bitcoin
315
+ /// balance from the Bank, `balanceOwner` is the same as `redemeer`.
316
+ /// However, when a Vault is redeeming part of its balance for some
317
+ /// redeemer address (for example, someone who has earlier deposited
318
+ /// into that Vault), `balanceOwner` is the Vault, and `redemeer` is
319
+ /// the address for which the vault is redeeming its balance to,
320
+ /// - walletPubKeyHash: The 20-byte wallet public key hash (computed
321
+ /// using Bitcoin HASH160 over the compressed ECDSA public key),
322
+ /// - mainUtxoTxHash: Data of the wallet's main UTXO TX hash, as
323
+ /// currently known on the Ethereum chain,
324
+ /// - mainUtxoTxOutputIndex: Data of the wallet's main UTXO output
325
+ /// index, as currently known on Ethereum chain,
326
+ /// - mainUtxoTxOutputValue: Data of the wallet's main UTXO output
327
+ /// value, as currently known on Ethereum chain,
328
+ /// - redeemerOutputScript The redeemer's length-prefixed output
329
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
330
+ /// redeemed BTC.
331
+ /// @dev Requirements:
332
+ /// - Wallet behind `walletPubKeyHash` must be live,
333
+ /// - `mainUtxo*` components must point to the recent main UTXO
334
+ /// of the given wallet, as currently known on the Ethereum chain,
335
+ /// - `redeemerOutputScript` must be a proper Bitcoin script,
336
+ /// - `redeemerOutputScript` cannot have wallet PKH as payload,
337
+ /// - `amount` must be above or equal the `redemptionDustThreshold`,
338
+ /// - Given `walletPubKeyHash` and `redeemerOutputScript` pair can be
339
+ /// used for only one pending request at the same time,
340
+ /// - Wallet must have enough Bitcoin balance to proceed the request,
341
+ /// - Balance owner must make an allowance in the Bank that the Bridge
342
+ /// contract can spend the given `amount`.
343
+ function requestRedemption(
344
+ BridgeState.Storage storage self,
345
+ address balanceOwner,
346
+ uint64 amount,
347
+ bytes calldata redemptionData
348
+ ) external {
349
+ (
350
+ address redeemer,
351
+ bytes20 walletPubKeyHash,
352
+ bytes32 mainUtxoTxHash,
353
+ uint32 mainUtxoTxOutputIndex,
354
+ uint64 mainUtxoTxOutputValue,
355
+ bytes memory redeemerOutputScript
356
+ ) = abi.decode(
357
+ redemptionData,
358
+ (address, bytes20, bytes32, uint32, uint64, bytes)
359
+ );
360
+
361
+ requestRedemption(
362
+ self,
363
+ walletPubKeyHash,
364
+ BitcoinTx.UTXO(
365
+ mainUtxoTxHash,
366
+ mainUtxoTxOutputIndex,
367
+ mainUtxoTxOutputValue
368
+ ),
369
+ balanceOwner,
370
+ redeemer,
371
+ redeemerOutputScript,
372
+ amount
373
+ );
374
+ }
375
+
376
+ /// @notice Requests redemption of the given amount from the specified
377
+ /// wallet to the redeemer Bitcoin output script.
378
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
379
+ /// using Bitcoin HASH160 over the compressed ECDSA public key).
380
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
381
+ /// the Ethereum chain.
382
+ /// @param balanceOwner The address of the Bank balance owner whose balance
383
+ /// is getting redeemed.
384
+ /// @param redeemer The Ethereum address of the redeemer who will be able to
385
+ /// claim Bank balance if anything goes wrong during the redemption.
386
+ /// In the most basic case, when someone redeems their Bitcoin
387
+ /// balance from the Bank, `balanceOwner` is the same as `redemeer`.
388
+ /// However, when a Vault is redeeming part of its balance for some
389
+ /// redeemer address (for example, someone who has earlier deposited
390
+ /// into that Vault), `balanceOwner` is the Vault, and `redemeer` is
391
+ /// the address for which the vault is redeeming its balance to.
392
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
393
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
394
+ /// redeemed BTC.
395
+ /// @param amount Requested amount in satoshi. This is also the Bank balance
396
+ /// that is taken from the `balanceOwner` upon request.
397
+ /// Once the request is handled, the actual amount of BTC locked
398
+ /// on the redeemer output script will be always lower than this value
399
+ /// since the treasury and Bitcoin transaction fees must be incurred.
400
+ /// The minimal amount satisfying the request can be computed as:
401
+ /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
402
+ /// Fees values are taken at the moment of request creation.
403
+ /// @dev Requirements:
404
+ /// - Wallet behind `walletPubKeyHash` must be live,
405
+ /// - `mainUtxo` components must point to the recent main UTXO
406
+ /// of the given wallet, as currently known on the Ethereum chain,
407
+ /// - `redeemerOutputScript` must be a proper Bitcoin script,
408
+ /// - `redeemerOutputScript` cannot have wallet PKH as payload,
409
+ /// - `amount` must be above or equal the `redemptionDustThreshold`,
410
+ /// - Given `walletPubKeyHash` and `redeemerOutputScript` pair can be
411
+ /// used for only one pending request at the same time,
412
+ /// - Wallet must have enough Bitcoin balance to proceed the request,
413
+ /// - Balance owner must make an allowance in the Bank that the Bridge
414
+ /// contract can spend the given `amount`.
415
+ function requestRedemption(
416
+ BridgeState.Storage storage self,
417
+ bytes20 walletPubKeyHash,
418
+ BitcoinTx.UTXO memory mainUtxo,
419
+ address balanceOwner,
420
+ address redeemer,
421
+ bytes memory redeemerOutputScript,
422
+ uint64 amount
423
+ ) internal {
270
424
  Wallets.Wallet storage wallet = self.registeredWallets[
271
425
  walletPubKeyHash
272
426
  ];
@@ -358,7 +512,7 @@ library Redemption {
358
512
  );
359
513
 
360
514
  self.pendingRedemptions[redemptionKey] = RedemptionRequest(
361
- msg.sender,
515
+ redeemer,
362
516
  amount,
363
517
  treasuryFee,
364
518
  txMaxFee,
@@ -369,13 +523,13 @@ library Redemption {
369
523
  emit RedemptionRequested(
370
524
  walletPubKeyHash,
371
525
  redeemerOutputScript,
372
- msg.sender,
526
+ redeemer,
373
527
  amount,
374
528
  treasuryFee,
375
529
  txMaxFee
376
530
  );
377
531
 
378
- self.bank.transferBalanceFrom(msg.sender, address(this), amount);
532
+ self.bank.transferBalanceFrom(balanceOwner, address(this), amount);
379
533
  }
380
534
 
381
535
  /// @notice Used by the wallet to prove the BTC redemption transaction
package/export.json CHANGED
@@ -15515,6 +15515,28 @@
15515
15515
  ],
15516
15516
  "outputs": []
15517
15517
  },
15518
+ {
15519
+ "type": "function",
15520
+ "name": "receiveBalanceApproval",
15521
+ "constant": false,
15522
+ "payable": false,
15523
+ "gas": 29000000,
15524
+ "inputs": [
15525
+ {
15526
+ "type": "address",
15527
+ "name": "balanceOwner"
15528
+ },
15529
+ {
15530
+ "type": "uint256",
15531
+ "name": "amount"
15532
+ },
15533
+ {
15534
+ "type": "bytes",
15535
+ "name": "redemptionData"
15536
+ }
15537
+ ],
15538
+ "outputs": []
15539
+ },
15518
15540
  {
15519
15541
  "type": "function",
15520
15542
  "name": "redemptionParameters",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keep-network/tbtc-v2",
3
- "version": "0.1.1-dev.82+main.f32a8631eecc96968b05012266fd6bcd34b9852e",
3
+ "version": "0.1.1-dev.83+main.c3c80fb5df859b160f905226f2c6fb7e3296b9ac",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "artifacts/",