Skip to content

Commit

Permalink
Fixing withdrawal functionality in stBTC
Browse files Browse the repository at this point in the history
Upon withdrawal we need to take into account fees that will be collected
by the treasury. A user will get the desired assets, but on top we need
to pull the funds from Mezo covering not only what a user wants but also
pull a bit more to cover the withdrawal fees.

Added tests to cover scenarios with allocated funds to Mezo Portal and
then withdrawing and redeeming from Acre.
  • Loading branch information
dimpar committed Apr 12, 2024
1 parent 965f38b commit 49b4be9
Show file tree
Hide file tree
Showing 2 changed files with 378 additions and 201 deletions.
7 changes: 5 additions & 2 deletions solidity/contracts/stBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ contract stBTC is ERC4626Fees, PausableOwnable {
address owner
) public override whenNotPaused returns (uint256) {
uint256 currentAssetsBalance = IERC20(asset()).balanceOf(address(this));
if (assets > currentAssetsBalance) {
dispatcher.withdraw(assets - currentAssetsBalance);
// If there is not enough assets in stBTC to cover user withdrawals and
// withdrawal fees then pull the assets from the dispatcher.
uint256 assetsWithFees = convertToAssets(previewWithdraw(assets));
if (assetsWithFees > currentAssetsBalance) {
dispatcher.withdraw(assetsWithFees - currentAssetsBalance);
}

return super.withdraw(assets, receiver, owner);
Expand Down
Loading

0 comments on commit 49b4be9

Please sign in to comment.