Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing withdrawal functionality in stBTC #350

Merged
merged 8 commits into from
Apr 23, 2024
4 changes: 2 additions & 2 deletions solidity/contracts/lib/ERC4626Fees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ abstract contract ERC4626Fees is ERC4626Upgradeable {
function _feeOnRaw(
uint256 assets,
uint256 feeBasisPoints
) private pure returns (uint256) {
) internal pure returns (uint256) {
return
assets.mulDiv(
feeBasisPoints,
Expand All @@ -117,7 +117,7 @@ abstract contract ERC4626Fees is ERC4626Upgradeable {
function _feeOnTotal(
uint256 assets,
uint256 feeBasisPoints
) private pure returns (uint256) {
) internal pure returns (uint256) {
return
assets.mulDiv(
feeBasisPoints,
Expand Down
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 = assets + _feeOnRaw(assets, exitFeeBasisPoints);
if (assetsWithFees > currentAssetsBalance) {
dispatcher.withdraw(assetsWithFees - currentAssetsBalance);
}

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