Skip to content

Commit 6edc700

Browse files
committed
add withdrawal checks
1 parent 97afb2a commit 6edc700

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/SovaBTC.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,25 @@ contract SovaBTC is ISovaBTC, UBTC20, Ownable, ReentrancyGuard {
220220
// decode signed tx so that we can validate it against the user request
221221
SovaBitcoin.BitcoinTx memory btcTx = SovaBitcoin.decodeBitcoinTx(signedTx);
222222

223-
// TODO ensure the signed tx fulfills the user request
224-
225223
UserWithdrawRequest memory request = _pendingUserWithdrawRequests[user];
226224

225+
// Check that a withdraw request exists
226+
if (request.amount == 0) {
227+
revert PendingTransactionExists();
228+
}
229+
227230
uint256 totalRequired = request.amount + uint256(request.btcGasLimit);
228231

232+
if (balanceOf(user) < totalRequired) revert InsufficientAmount();
233+
229234
if (_pendingWithdrawals[user].amount > 0) revert PendingWithdrawalExists();
230235

231236
// Track pending withdrawal
232237
_setPendingWithdrawal(user, totalRequired);
233238

239+
// Clear the withdraw request
240+
delete _pendingUserWithdrawRequests[user];
241+
234242
// Broadcast the signed BTC tx
235243
SovaBitcoin.broadcastBitcoinTx(signedTx);
236244

0 commit comments

Comments
 (0)