Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contracts/contracts/vault/OETHPlumeVaultCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ contract OETHPlumeVaultCore is OETHVaultCore {

// @inheritdoc OETHVaultCore
function _mint(
address _asset,
address,
uint256 _amount,
uint256 _minimumOusdAmount
) internal virtual override {
uint256
) internal virtual {
// Only Strategist or Governor can mint using the Vault for now.
// This allows the strateigst to fund the Vault with WETH when
// removing liquidi from wOETH strategy.
Expand All @@ -24,7 +24,7 @@ contract OETHPlumeVaultCore is OETHVaultCore {
"Caller is not the Strategist or Governor"
);

super._mint(_asset, _amount, _minimumOusdAmount);
super._mint(_amount);
}

// @inheritdoc OETHVaultCore
Expand Down
39 changes: 16 additions & 23 deletions contracts/contracts/vault/VaultCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,37 @@ abstract contract VaultCore is VaultInitializer {
////////////////////////////////////////////////////
/**
* @notice Deposit a supported asset and mint OTokens.
* @param _asset Address of the asset being deposited
* @dev Deprecated: use `mint(uint256 _amount)` instead.
* @dev Deprecated: param _asset Address of the asset being deposited
* @param _amount Amount of the asset being deposited
* @param _minimumOusdAmount Minimum OTokens to mint
* @dev Deprecated: param _minimumOusdAmount Minimum OTokens to mint
*/
function mint(
address _asset,
address,
uint256 _amount,
uint256 _minimumOusdAmount
uint256
) external whenNotCapitalPaused nonReentrant {
_mint(_asset, _amount, _minimumOusdAmount);
_mint(_amount);
}

/**
* @notice Deposit a supported asset and mint OTokens.
* @param _amount Amount of the asset being deposited
*/
function mint(uint256 _amount) external whenNotCapitalPaused nonReentrant {
_mint(_amount);
}

// slither-disable-start reentrancy-no-eth
/**
* @dev Deposit a supported asset and mint OTokens.
* @param _asset Address of the asset being deposited
* @param _amount Amount of the asset being deposited
* @param _minimumOusdAmount Minimum OTokens to mint
*/
function _mint(
address _asset,
uint256 _amount,
uint256 _minimumOusdAmount
) internal virtual {
require(_asset == asset, "Asset is not supported");
function _mint(uint256 _amount) internal virtual {
require(_amount > 0, "Amount must be greater than 0");

// Scale amount to 18 decimals
uint256 scaledAmount = _amount.scaleBy(18, assetDecimals);
require(
scaledAmount >= _minimumOusdAmount,
"Mint amount lower than minimum"
);

emit Mint(msg.sender, scaledAmount);

Expand All @@ -91,7 +89,7 @@ abstract contract VaultCore is VaultInitializer {
// Mint oTokens
oUSD.mint(msg.sender, scaledAmount);

IERC20(_asset).safeTransferFrom(msg.sender, address(this), _amount);
IERC20(asset).safeTransferFrom(msg.sender, address(this), _amount);

// Give priority to the withdrawal queue for the new asset liquidity
_addWithdrawalQueueLiquidity();
Expand Down Expand Up @@ -881,11 +879,6 @@ abstract contract VaultCore is VaultInitializer {
}
}

function abs(int256 x) private pure returns (uint256) {
require(x < int256(MAX_INT), "Amount too high");
return x >= 0 ? uint256(x) : uint256(-x);
}

function _min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
Expand Down
36 changes: 2 additions & 34 deletions contracts/contracts/vault/VaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,8 @@ abstract contract VaultStorage is Initializable, Governable {
// slither-disable-start uninitialized-state
// slither-disable-start constable-states

// Assets supported by the Vault, i.e. Stablecoins
enum UnitConversion {
DECIMALS,
GETEXCHANGERATE
}
// Changed to fit into a single storage slot so the decimals needs to be recached
struct Asset {
// Note: OETHVaultCore doesn't use `isSupported` when minting,
// redeeming or checking balance of assets.
bool isSupported;
UnitConversion unitConversion;
uint8 decimals;
// Max allowed slippage from the Oracle price when swapping collateral assets in basis points.
// For example 40 == 0.4% slippage
uint16 allowedOracleSlippageBps;
}

/// @dev mapping of supported vault assets to their configuration
mapping(address => Asset) internal _deprecated_assets;
mapping(address => uint256) internal _deprecated_assets;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified further to just
uint256 private _deprecated_assets;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Changed in this commit: 955b851.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was suggesting to go one step further by getting rid of the mapping. eg
mapping(address => uint256) private _deprecated_assets;
becomes
uint256 private _deprecated_assets;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in this commit d0c45e6.
I merged the PR a bit too fast. I just opened new one here #2736

/// @dev list of all assets supported by the vault.
address[] internal _deprecated_allAssets;

Expand Down Expand Up @@ -145,8 +128,6 @@ abstract contract VaultStorage is Initializable, Governable {
/// @dev Deprecated: Tokens that should be swapped for stablecoins
address[] private _deprecated_swapTokens;

uint256 constant MINT_MINIMUM_UNIT_PRICE = 0.998e18;

/// @notice Metapool strategy that is allowed to mint/burn OTokens without changing collateral

address private _deprecated_ousdMetaStrategy;
Expand All @@ -157,20 +138,7 @@ abstract contract VaultStorage is Initializable, Governable {
/// @notice How much net total OTokens are allowed to be minted by all strategies
uint256 private _deprecated_netOusdMintForStrategyThreshold;

uint256 constant MIN_UNIT_PRICE_DRIFT = 0.7e18;
uint256 constant MAX_UNIT_PRICE_DRIFT = 1.3e18;

/// @notice Collateral swap configuration.
/// @dev is packed into a single storage slot to save gas.
struct SwapConfig {
// Contract that swaps the vault's collateral assets
address swapper;
// Max allowed percentage the total value can drop below the total supply in basis points.
// For example 100 == 1%
uint16 allowedUndervalueBps;
}

SwapConfig internal _deprecated_swapConfig = SwapConfig(address(0), 0);
uint256 internal _deprecated_swapConfig;

// List of strategies that can mint oTokens directly
// Used in OETHBaseVaultCore
Expand Down
11 changes: 0 additions & 11 deletions contracts/test/vault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ describe("Vault", function () {
await expect(matt).has.a.balanceOf("100.00", ousd);
});

it("Should revert mint if minMintAmount check fails", async () => {
const { vault, matt, ousd, usdc } = fixture;

await expect(
vault.connect(matt).mint(usdc.address, usdcUnits("50"), ousdUnits("100"))
).to.be.revertedWith("Mint amount lower than minimum");

await expect(matt).has.a.balanceOf("100.00", ousd);
expect(await ousd.totalSupply()).to.eq(ousdUnits("200.0"));
});

it("Should allow transfer of arbitrary token by Governor", async () => {
const { vault, ousd, usdc, matt, governor } = fixture;

Expand Down
14 changes: 0 additions & 14 deletions contracts/test/vault/oeth-vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,6 @@ describe("OETH Vault", function () {
);
});

it("Fail to mint with any other asset", async () => {
const { oethVault, frxETH, stETH, reth, josh } = fixture;

const amount = parseUnits("1", 18);
const minOeth = parseUnits("0.8", 18);

for (const asset of [frxETH, stETH, reth]) {
await asset.connect(josh).approve(oethVault.address, amount);
const tx = oethVault.connect(josh).mint(asset.address, amount, minOeth);

await expect(tx).to.be.revertedWith("Asset is not supported");
}
});

it("Fail to mint if amount is zero", async () => {
const { oethVault, weth, josh } = fixture;

Expand Down
14 changes: 0 additions & 14 deletions contracts/test/vault/oeth-vault.mainnet.fork-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,6 @@ describe("ForkTest: OETH Vault", function () {
.withArgs(josh.address, amount);
});

it("should not mint with any other asset", async () => {
const { oethVault, frxETH, stETH, reth, josh } = fixture;

const amount = parseUnits("1", 18);
const minOeth = parseUnits("0.8", 18);

for (const asset of [frxETH, stETH, reth]) {
await asset.connect(josh).approve(oethVault.address, amount);
const tx = oethVault.connect(josh).mint(asset.address, amount, minOeth);

await expect(tx).to.be.revertedWith("Asset is not supported");
}
});

it("should have 0.1% redeem fee", async () => {
const { oethVault } = fixture;

Expand Down
Loading