-
Notifications
You must be signed in to change notification settings - Fork 42
Remove TBTC minting from Vending Machine Deposit qualification #377
Changes from all commits
55eb406
1c47b9f
0886d7e
b039d70
f5f7bd3
6148eac
d98d4a0
899cfab
8171ba8
1b08301
7e0602c
da8d414
6e14515
fb589b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,35 +21,6 @@ contract VendingMachine { | |
depositOwnerToken = DepositOwnerToken(_depositOwnerToken); | ||
} | ||
|
||
/// @notice Qualifies a deposit for minting TBTC. | ||
function qualifyDeposit( | ||
address payable _depositAddress, | ||
bytes4 _txVersion, | ||
bytes memory _txInputVector, | ||
bytes memory _txOutputVector, | ||
bytes4 _txLocktime, | ||
uint8 _fundingOutputIndex, | ||
bytes memory _merkleProof, | ||
uint256 _txIndexInBlock, | ||
bytes memory _bitcoinHeaders | ||
) public { | ||
Deposit _d = Deposit(_depositAddress); | ||
require( | ||
_d.provideBTCFundingProof( | ||
_txVersion, | ||
_txInputVector, | ||
_txOutputVector, | ||
_txLocktime, | ||
_fundingOutputIndex, | ||
_merkleProof, | ||
_txIndexInBlock, | ||
_bitcoinHeaders | ||
), | ||
"failed to provide funding proof"); | ||
// mint the signer fee to the Deposit | ||
tbtcToken.mint(_depositAddress, DepositUtils.signerFee()); | ||
} | ||
|
||
/// @notice Determines whether a deposit is qualified for minting TBTC. | ||
/// @param _depositAddress the address of the deposit | ||
function isQualified(address payable _depositAddress) public returns (bool) { | ||
|
@@ -63,8 +34,9 @@ contract VendingMachine { | |
require(depositOwnerToken.exists(_dotId), "Deposit Owner Token does not exist"); | ||
require(isQualified(address(_dotId)), "Deposit must be qualified"); | ||
|
||
require(tbtcToken.balanceOf(msg.sender) >= getDepositValueLessSignerFee(), "Not enough TBTC for DOT exchange"); | ||
tbtcToken.burnFrom(msg.sender, getDepositValueLessSignerFee()); | ||
uint256 getDepositValue = getDepositValue(); | ||
require(tbtcToken.balanceOf(msg.sender) >= getDepositValue, "Not enough TBTC for DOT exchange"); | ||
tbtcToken.burnFrom(msg.sender, getDepositValue); | ||
|
||
// TODO do we need the owner check below? transferFrom can be approved for a user, which might be an interesting use case. | ||
require(depositOwnerToken.ownerOf(_dotId) == address(this), "Deposit is locked"); | ||
|
@@ -79,16 +51,66 @@ contract VendingMachine { | |
require(isQualified(address(_dotId)), "Deposit must be qualified"); | ||
|
||
depositOwnerToken.transferFrom(msg.sender, address(this), _dotId); | ||
tbtcToken.mint(msg.sender, getDepositValueLessSignerFee()); | ||
|
||
// If the backing Deposit does not have a signer fee in escrow, mint it. | ||
if(tbtcToken.balanceOf(address(_dotId)) < DepositUtils.signerFee()){ | ||
tbtcToken.mint(msg.sender, getDepositValueLessSignerFee()); | ||
tbtcToken.mint(address(_dotId), DepositUtils.signerFee()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still feels wrong---in particular, that we're potentially at nonzero escrow but are minting the full signer fee to the deposit, putting us at > signer fee escrow. I can't reason my way all the way through it right now, but I want us to work through it a little. For now, let's roll with it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't find any issues with it. Escrow gets distributed as a final step before contract halt. Any TBTC more than signerFee left in the Deposit is just locked, and this will be user error (like sending to address(0)). There is no logical reason for more TBTC to be in the deposit. If someone wants to do that for some reason there's no sence in preventing them, they're not gaining anything so shrug. Will take a deeper look at the state machine to make sure there are no corner cases |
||
} | ||
else{ | ||
tbtcToken.mint(msg.sender, getDepositValue()); | ||
} | ||
} | ||
|
||
// WRAPPERS | ||
|
||
/// @notice Qualifies a deposit and mints TBTC. | ||
/// @dev User must allow VendingManchine to transfer DOT | ||
function unqualifiedDepositToTbtc( | ||
address payable _depositAddress, | ||
bytes4 _txVersion, | ||
bytes memory _txInputVector, | ||
bytes memory _txOutputVector, | ||
bytes4 _txLocktime, | ||
uint8 _fundingOutputIndex, | ||
bytes memory _merkleProof, | ||
uint256 _txIndexInBlock, | ||
bytes memory _bitcoinHeaders | ||
) public { | ||
Deposit _d = Deposit(_depositAddress); | ||
require( | ||
_d.provideBTCFundingProof( | ||
_txVersion, | ||
_txInputVector, | ||
_txOutputVector, | ||
_txLocktime, | ||
_fundingOutputIndex, | ||
_merkleProof, | ||
_txIndexInBlock, | ||
_bitcoinHeaders | ||
), | ||
"failed to provide funding proof"); | ||
|
||
dotToTbtc(uint256(_depositAddress)); | ||
} | ||
|
||
// HELPERS | ||
|
||
// TODO temporary helper function | ||
/// @notice Gets the Deposit lot size less signer fees | ||
/// @return amount in TBTC | ||
function getDepositValueLessSignerFee() internal returns (uint) { | ||
function getDepositValue() internal returns (uint) { | ||
liamzebedee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uint256 _multiplier = TBTCConstants.getSatoshiMultiplier(); | ||
uint256 _signerFee = DepositUtils.signerFee(); | ||
uint256 _totalValue = TBTCConstants.getLotSize().mul(_multiplier); | ||
return _totalValue; | ||
} | ||
|
||
// TODO temporary helper function | ||
/// @notice Gets the Deposit lot size | ||
/// @return amount in TBTC | ||
function getDepositValueLessSignerFee() internal returns (uint) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason we wouldn't just… Do this inline? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, think this looks cleaner though. Expecting to use one of these functions in redemption wrappers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm… Whether or not we escrow signing fees, we're unlikely to be needing the lot size minus signer fee except at mint-time. Everything else is done in terms of lot size. But we can wait and see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
agree
👍 |
||
uint256 _signerFee = DepositUtils.signerFee(); | ||
uint256 _totalValue = getDepositValue(); | ||
return _totalValue.sub(_signerFee); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NicholasDotSol can you fix up
getDepositValue
in #385?