Skip to content

Commit

Permalink
Stash current
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Oct 17, 2024
1 parent 8610d5e commit 6f725e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
28 changes: 19 additions & 9 deletions src/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ERC20PermitUpgradeable
} from "./Common.sol";

abstract contract Vault is IVault, Storage, ERC20PermitUpgradeable {
contract Vault is IVault, Storage, ERC20PermitUpgradeable {

using SafeERC20 for IERC20;
using Address for address;
Expand Down Expand Up @@ -60,10 +60,17 @@ abstract contract Vault is IVault, Storage, ERC20PermitUpgradeable {
return _convertToShares(assets, Math.Rounding.Floor);
}

function previewDepositAsset(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Floor);
}

function previewMint(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Ceil);
}

function previewMintAsset(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Ceil);
}
function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Ceil);
}
Expand All @@ -74,15 +81,15 @@ abstract contract Vault is IVault, Storage, ERC20PermitUpgradeable {

/** @dev See {IERC4626-deposit}. */
function deposit(uint256 assets, address receiver) public virtual returns (uint256) {
// uint256 maxAssets = maxDeposit(receiver);
// if (assets > maxAssets) {
// revert ERC4626ExceededMaxDeposit(receiver, assets, maxAssets);
// }
uint256 maxAssets = maxDeposit(receiver);
if (assets > maxAssets) {
revert ExceededMaxDeposit(receiver, assets, maxAssets);
}

// uint256 shares = previewDeposit(assets);
// _deposit(_msgSender(), receiver, assets, shares);
uint256 shares = previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);

// return shares;
return shares;
}

/** @dev See {IAssetVault-depositAsset}. */
Expand Down Expand Up @@ -144,7 +151,10 @@ abstract contract Vault is IVault, Storage, ERC20PermitUpgradeable {
/**
* @dev Internal conversion function (from assets to shares) with support for rounding direction.
*/
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
function _convertToShares(address asset, uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {

uint256 convertedAssets = _convertToBasePrice(asset, assets);

return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
}

Expand Down
13 changes: 7 additions & 6 deletions src/interface/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ interface IVault is IERC4626, IAccessControl {
error ZeroAddress();
error InvalidString();
error InvalidArray();

error ExceededMaxDeposit();

event DepositAsset(address indexed asset, address indexed vault, uint256 amount, address indexed receiver);

// Internal storage vs balanceOf storage
// QUESTION: What issues are there with lending markets or other issues
struct VaultStorage {
// Version
uint8 version;
// Decimals of the Vault token
uint8 baseDecimals;
// Base underlying asset of the Vault
address baseAsset; // ETH, WETH
address asset; // WETH
// Decimals of the Vault token
uint8 underlyingDecimals;
// Balance of total assets priced in base asset
uint256 totalAssets;
}
Expand Down Expand Up @@ -90,8 +91,8 @@ interface IVault is IERC4626, IAccessControl {
function maxWithdraw(address owner) external view returns (uint256);
function maxRedeem(address owner) external view returns (uint256);

function previewDeposit(uint256 assets) external view returns (uint256);
function previewMint(uint256 shares) external view returns (uint256);
function previewDepositAsset(uint256 assets) external view returns (uint256);
function previewMintAsset(uint256 shares) external view returns (uint256);
function previewWithdraw(uint256 assets) external view returns (uint256);
function previewRedeem(uint256 shares) external view returns (uint256);

Expand Down

0 comments on commit 6f725e2

Please sign in to comment.