Skip to content

Commit

Permalink
Update docs for assetsBalanceOf and maxWithdraw override (#412)
Browse files Browse the repository at this point in the history
This PR contains two changes:

1. [Improve documentation of assetsBalanceOf
function](fd741e6)
The function is used to show accounts' position in the dApp. It should
not include any fees, just the conversion of shares to assets.

2. [Define maxWithdraw as a public
function](65a5a8e)
To match ERC4626Upgradable contract implementation we use the same name
of the `maxWithdraw` function to correctly override it in ERC4626Fees
contract.
  • Loading branch information
dimpar authored May 10, 2024
2 parents 330b37c + 548a0fc commit cf23ff9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions solidity/contracts/BitcoinDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ contract BitcoinDepositor is AbstractTBTCDepositor, Ownable2StepUpgradeable {
/// event emitted in the same transaction.
/// @param depositKey Deposit key identifying the deposit.
/// @param caller Address that finalized the deposit.
/// @param referral Data used for referral program.
/// @param initialAmount Amount of funding transaction.
/// @param bridgedAmount Amount of tBTC tokens that was bridged by the tBTC bridge.
/// @param depositorFee Depositor fee amount.
Expand Down
16 changes: 9 additions & 7 deletions solidity/contracts/lib/ERC4626Fees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ abstract contract ERC4626Fees is ERC4626Upgradeable {

// === Overrides ===

/// @dev Calculate the maximum amount of assets that can be withdrawn
/// by an account including fees. See {IERC4626-maxWithdraw}.
function maxWithdraw(
address account
) public view virtual override returns (uint256) {
uint256 maxAssets = super.maxWithdraw(account);
return maxAssets - _feeOnTotal(maxAssets, _exitFeeBasisPoints());
}

/// @dev Preview taking an entry fee on deposit. See {IERC4626-previewDeposit}.
function previewDeposit(
uint256 assets
Expand Down Expand Up @@ -84,13 +93,6 @@ abstract contract ERC4626Fees is ERC4626Upgradeable {
}
}

/// @dev Calculate the maximum amount of assets that can be withdrawn
/// by an account including fees. See {IERC4626-maxWithdraw}.
function _maxWithdraw(address account) internal view returns (uint256) {
uint256 maxAssets = super.maxWithdraw(account);
return maxAssets - _feeOnTotal(maxAssets, _exitFeeBasisPoints());
}

// === Fee configuration ===

// slither-disable-next-line dead-code
Expand Down
12 changes: 7 additions & 5 deletions solidity/contracts/stBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ contract stBTC is ERC4626Fees, PausableOwnable {
if (paused()) {
return 0;
}
return _maxWithdraw(owner);
return super.maxWithdraw(owner);
}

/// @dev Returns the maximum amount of Vault shares that can be redeemed from
Expand All @@ -347,10 +347,12 @@ contract stBTC is ERC4626Fees, PausableOwnable {
return super.maxRedeem(owner);
}

/// @notice Returns value of assets that would be exchanged for the amount of
/// shares owned by the `account`.
/// @param account Owner of shares.
/// @return Assets amount.
/// @notice Returns the number of assets that corresponds to the amount of
/// shares held by the specified account.
/// @dev This function is used to convert shares to assets position for
/// the given account. It does not take fees into account.
/// @param account The owner of the shares.
/// @return The amount of assets.
function assetsBalanceOf(address account) public view returns (uint256) {
return convertToAssets(balanceOf(account));
}
Expand Down

0 comments on commit cf23ff9

Please sign in to comment.