Skip to content

Commit

Permalink
maxDeposit and maxWithdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodelatorre7 committed Nov 28, 2023
1 parent 6b260cf commit ff5411a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contracts/SharedSmartVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ contract SharedSmartVault is AccessControlUpgradeable, UUPSUpgradeable, ERC4626U
);
}

function maxDeposit(address owner) public view virtual override returns (uint256) {
uint256 max = 0;
for (uint256 i = 0; i < _investments.length; i++) {
max += _investments[i].maxDeposit(owner);
if (max == type(uint256).max) return max;
}
return max;
}

function _withdraw(
address caller,
address receiver,
Expand All @@ -146,6 +155,14 @@ contract SharedSmartVault is AccessControlUpgradeable, UUPSUpgradeable, ERC4626U
super._withdraw(caller, receiver, owner, assets, shares);
}

function maxWithdraw(address owner) public view virtual override returns (uint256) {
uint256 max = 0;
for (uint256 i = 0; i < _investments.length; i++) {
max += _investments[i].maxWithdraw(owner);
}
return Math.min(super.maxWithdraw(owner), max);
}

function totalAssets() public view virtual override returns (uint256) {
uint256 assets = IERC20Metadata(asset()).balanceOf(_smartVault);
for (uint256 i = 0; i < _investments.length; i++) {
Expand Down

0 comments on commit ff5411a

Please sign in to comment.