Update tbtcToBtc to use new Redemption logic
@@ -108,32 +108,33 @@ contract VendingMachine {
tdtToTbtc(uint256(_depositAddress));
}
- /// @notice Redeems a Deposit by purchasing a TDT with TBTC, and using the TDT to redeem corresponding Deposit.
+ /// @notice Redeems a Deposit by purchasing a TDT with TBTC for _finalRecipient,
+ /// and using the TDT to redeem corresponding Deposit as _finalRecipient.
/// This function will revert if the Deposit is not in ACTIVE state.
/// @dev Vending Machine transfers TBTC allowance to Deposit.
/// @param _depositAddress The address of the Deposit to redeem.
/// @param _outputValueBytes The 8-byte Bitcoin transaction output size in Little Endian.
/// @param _requesterPKH The 20-byte Bitcoin pubkeyhash to which to send funds.
+ /// @param _finalRecipient The deposit redeemer. This address will receive the TDT.
function tbtcToBtc(
address payable _depositAddress,
bytes8 _outputValueBytes,
- bytes20 _requesterPKH
+ bytes20 _requesterPKH,
+ address payable _finalRecipient
) public {
+ require(tbtcDepositToken.exists(uint256(_depositAddress)), "tBTC Deposit Token does not exist");
Deposit _d = Deposit(_depositAddress);
- tbtcToTdt(uint256(_depositAddress));
+ tbtcToken.burnFrom(msg.sender, TBTCConstants.getLotSizeTbtc());
+ tbtcDepositToken.approve(_depositAddress, uint256(_depositAddress));
- uint256 tbtcOwed = _d.getRedemptionTbtcRequirement(msg.sender);
+ uint256 tbtcOwed = _d.getOwnerRedemptionTbtcRequirement(msg.sender);
if(tbtcOwed != 0){
tbtcToken.transferFrom(msg.sender, address(this), tbtcOwed);
tbtcToken.approve(_depositAddress, tbtcOwed);
}
- _d.requestRedemption(
- _outputValueBytes,
- _requesterPKH,
- msg.sender
- );
+ _d.requestRedemptionAndTransfer(_outputValueBytes, _requesterPKH, _finalRecipient);
}
}
