Skip to content

Commit

Permalink
Adding redeeming function
Browse files Browse the repository at this point in the history
Took assets from stBTC first before calling for withdrawal on the Dispatcher
contract.
  • Loading branch information
dimpar committed Apr 8, 2024
1 parent 67993ce commit fe19447
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/contracts/stBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ contract stBTC is ERC4626Fees, PausableOwnable {
uint256 assets,
address receiver,
address owner
) public override returns (uint256) {
) public override whenNotPaused returns (uint256) {
if (assets > totalAssets()) {
uint256 missingAmount = assets - totalAssets();
dispatcher.withdraw(missingAmount);
Expand All @@ -240,12 +240,23 @@ contract stBTC is ERC4626Fees, PausableOwnable {
return super.withdraw(assets, receiver, owner);
}

// TODO: change this function to pull assets from the dispatcher.
/// @notice Redeems shares for assets and transfers them to the receiver.
/// @dev Redeem unallocated assets first and and if not enough, then pull
/// the assets from the dispatcher.
/// @param shares Amount of shares to redeem.
/// @param receiver The address to which the assets will be transferred.
/// @param owner The address of the owner of the shares.
function redeem(
uint256 shares,
address receiver,
address owner
) public override whenNotPaused returns (uint256) {
uint256 assets = super.previewRedeem(shares);
if (assets > totalAssets()) {
uint256 missingAmount = assets - totalAssets();
dispatcher.withdraw(missingAmount);
}

return super.redeem(shares, receiver, owner);
}

Expand Down

0 comments on commit fe19447

Please sign in to comment.