Skip to content

Commit b183138

Browse files
committed
add withdrawal fee
1 parent 628084e commit b183138

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/uBTC.sol

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import "@solady/auth/Ownable.sol";
77
import "./lib/CorsaBitcoin.sol";
88

99
contract uBTC is WETH, Ownable {
10+
// Fixed withdrawal fee in satoshis
11+
uint256 public constant WITHDRAWAL_FEE = 1000000;
12+
1013
error InvalidOutput(string expected, string actual);
1114
error InsufficientDeposit();
1215
error InsufficientInput();
16+
error InsufficientAmount();
1317
error UnsignedInput();
1418
error InvalidLocktime();
1519
error BroadcastFailure();
@@ -86,9 +90,14 @@ contract uBTC is WETH, Ownable {
8690
}
8791

8892
function withdraw(uint64 amount, uint32 btcBlockHeight, string calldata dest) public {
89-
// burn uBTC
90-
// TODO(powvt): this hardcoded amount is the btc withdraw gas fee paid by the network
91-
_burn(msg.sender, uint256(amount) + 1000000);
93+
// Check if user has enough balance for both amount and fee
94+
uint256 totalRequired = uint256(amount) + WITHDRAWAL_FEE;
95+
if (balanceOf(msg.sender) < totalRequired) {
96+
revert InsufficientAmount();
97+
}
98+
99+
// Burn both the withdrawal amount and the fee
100+
_burn(msg.sender, totalRequired);
92101

93102
// Create Bitcoin transaction using the UTXOs
94103
bytes memory signedTx = CorsaBitcoin.createAndSignBitcoinTx(address(this), amount, btcBlockHeight, dest);

0 commit comments

Comments
 (0)