Skip to content

Commit

Permalink
Updates to Module
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Oct 14, 2024
1 parent b8e5c27 commit 259af8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
13 changes: 5 additions & 8 deletions src/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,24 @@ contract Module {
}

function _maxRedeem(address owner) public view virtual returns (uint256) {
// return balanceOf(owner);
ERC20Storage storage $ = Storage._getERC20Storage();
return $.balanceOf(owner);
}

/** @dev See {IERC4626-previewDeposit}. */
function previewDeposit(uint256 assets) public view virtual returns (uint256) {
// return _convertToShares(assets, Math.Rounding.Floor);
return _convertToShares(assets, Math.Rounding.Floor);
}

/** @dev See {IERC4626-previewMint}. */
function previewMint(uint256 shares) public view virtual returns (uint256) {
// return _convertToAssets(shares, Math.Rounding.Ceil);
return _convertToAssets(shares, Math.Rounding.Ceil);
}

/** @dev See {IERC4626-previewWithdraw}. */
function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Ceil);
}

/** @dev See {IERC4626-previewRedeem}. */
function previewRedeem(uint256 shares) public view virtual returns (uint256) {
// return _convertToAssets(shares, Math.Rounding.Floor);
return _convertToAssets(shares, Math.Rounding.Floor);
}

/** @dev See {IERC4626-deposit}. */
Expand Down
38 changes: 9 additions & 29 deletions src/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,28 @@ import {
Storage
} from "./Common.sol";

contract Vault is IVault, Storage {
contract Vault is IVault, Storage, Module {

using SafeERC20 for IERC20;
using Address for address;

/** @dev See {IERC4626-decimals}. */
function decimals() public view virtual override(IERC20Metadata, ERC20Upgradeable) returns (uint8) {
VaultStorage storage $ = VaultLib.getVaultStorage();
return $.underlyingDecimals + _decimalsOffset();
}

/** @dev See {IERC4626-assets}. */
function asset() public view virtual returns (address) {
VaultStorage storage $ = VaultLib.getVaultStorage();
return $.denominationAsset;
return _asset();
}

/** @dev Returns all the underlying assets */
function assets() public view returns (address[] memory assets_) {
AssetStorage storage $ = VaultLib.getAssetStorage();
uint256 assetListLength = $.assetList.length;
assets_ = new address[](assetListLength);
for (uint256 i = 0; i < assetListLength; i++) {
assets_[i] = $.assetList[i];
}
return _assets();
}

/** @dev See {IERC4626-decimals}. */
function decimals() public view virtual override(IERC20Metadata, ERC20Upgradeable) returns (uisnt8) {
return _decimals();
}

function getStrategyWithLowestBalance() public view returns (address strategyAddress, uint256 lowestBalance) {
StrategyStorage storage $ = VaultLib.getStrategyStorage();
uint256 lowestBalanceFound = type(uint256).max;
address strategyWithLowestBalance;

for (uint256 i = 0; i < $.strategyList.length; i++) {
address strategy = $.strategyList[i];
uint256 currentBalance = $.strategies[strategy].currentBalance;
if (currentBalance < lowestBalanceFound) {
lowestBalanceFound = currentBalance;
strategyWithLowestBalance = strategy;
}
}

return (strategyWithLowestBalance, lowestBalanceFound);
return _getStrategyWithLowestBalance();
}

/** @dev See {IERC4626-totalAssets}. */
Expand Down

0 comments on commit 259af8d

Please sign in to comment.