diff --git a/contracts/contracts/vault/OETHVaultCore.sol b/contracts/contracts/vault/OETHVaultCore.sol index b0d2adb6e8..09231961d9 100644 --- a/contracts/contracts/vault/OETHVaultCore.sol +++ b/contracts/contracts/vault/OETHVaultCore.sol @@ -34,7 +34,7 @@ contract OETHVaultCore is VaultCore { */ function cacheWETHAssetIndex() external onlyGovernor { uint256 assetCount = allAssets.length; - for (uint256 i = 0; i < assetCount; ++i) { + for (uint256 i; i < assetCount; ++i) { if (allAssets[i] == weth) { wethAssetIndex = i; break; @@ -157,12 +157,12 @@ contract OETHVaultCore is VaultCore { * The OETH is burned on request and the WETH is transferred to the withdrawer on claim. * This request can be claimed once the withdrawal queue's `claimable` amount * is greater than or equal this request's `queued` amount. - * There is no minimum time or block number before a request can be claimed. It just needs + * There is a minimum of 10 minutes before a request can be claimed. After that, the request just needs * enough WETH liquidity in the Vault to satisfy all the outstanding requests to that point in the queue. * OETH is converted to WETH at 1:1. * @param _amount Amount of OETH to burn. - * @param requestId Unique ID for the withdrawal request - * @param queued Cumulative total of all WETH queued including already claimed requests. + * @return requestId Unique ID for the withdrawal request + * @return queued Cumulative total of all WETH queued including already claimed requests. */ function requestWithdrawal(uint256 _amount) external @@ -255,7 +255,7 @@ contract OETHVaultCore is VaultCore { * @return amounts Amount of WETH received for each request * @return totalAmount Total amount of WETH transferred to the withdrawer */ - function claimWithdrawals(uint256[] memory _requestIds) + function claimWithdrawals(uint256[] calldata _requestIds) external virtual whenNotCapitalPaused @@ -272,7 +272,7 @@ contract OETHVaultCore is VaultCore { _addWithdrawalQueueLiquidity(); amounts = new uint256[](_requestIds.length); - for (uint256 i = 0; i < _requestIds.length; ++i) { + for (uint256 i; i < _requestIds.length; ++i) { amounts[i] = _claimWithdrawal(_requestIds[i]); totalAmount += amounts[i]; } @@ -391,7 +391,7 @@ contract OETHVaultCore is VaultCore { /// @dev Get the balance of an asset held in Vault and all strategies /// less any WETH that is reserved for the withdrawal queue. - /// This will only return a non-zero balance for WETH. + /// WETH is the only asset that can return a non-zero balance. /// All other assets will return 0 even if there is some dust amounts left in the Vault. /// For example, there is 1 wei left of stETH in the OETH Vault but will return 0 in this function. /// diff --git a/contracts/contracts/vault/VaultAdmin.sol b/contracts/contracts/vault/VaultAdmin.sol index a67ab2d844..a66d277523 100644 --- a/contracts/contracts/vault/VaultAdmin.sol +++ b/contracts/contracts/vault/VaultAdmin.sol @@ -219,7 +219,7 @@ contract VaultAdmin is VaultStorage { bytes calldata _data ) internal virtual returns (uint256 toAssetAmount) { // Check fromAsset and toAsset are valid - Asset memory fromAssetConfig = assets[address(_fromAsset)]; + Asset memory fromAssetConfig = assets[_fromAsset]; Asset memory toAssetConfig = assets[_toAsset]; require(fromAssetConfig.isSupported, "From asset is not supported"); require(toAssetConfig.isSupported, "To asset is not supported"); diff --git a/contracts/contracts/vault/VaultCore.sol b/contracts/contracts/vault/VaultCore.sol index c1f1278c5e..1b7cd786e2 100644 --- a/contracts/contracts/vault/VaultCore.sol +++ b/contracts/contracts/vault/VaultCore.sol @@ -23,11 +23,8 @@ import "./VaultInitializer.sol"; contract VaultCore is VaultInitializer { using SafeERC20 for IERC20; using StableMath for uint256; - // max signed int + /// @dev max signed int uint256 internal constant MAX_INT = 2**255 - 1; - // max un-signed int - uint256 internal constant MAX_UINT = - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; /** * @dev Verifies that the rebasing is not paused. @@ -45,6 +42,9 @@ contract VaultCore is VaultInitializer { _; } + /** + * @dev Verifies that the caller is the AMO strategy. + */ modifier onlyOusdMetaStrategy() { require( msg.sender == ousdMetaStrategy, @@ -67,6 +67,12 @@ contract VaultCore is VaultInitializer { _mint(_asset, _amount, _minimumOusdAmount); } + /** + * @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, @@ -433,7 +439,7 @@ contract VaultCore is VaultInitializer { returns (uint256 value) { uint256 assetCount = allAssets.length; - for (uint256 y = 0; y < assetCount; ++y) { + for (uint256 y; y < assetCount; ++y) { address assetAddr = allAssets[y]; uint256 balance = IERC20(assetAddr).balanceOf(address(this)); if (balance > 0) { @@ -465,7 +471,7 @@ contract VaultCore is VaultInitializer { { IStrategy strategy = IStrategy(_strategyAddr); uint256 assetCount = allAssets.length; - for (uint256 y = 0; y < assetCount; ++y) { + for (uint256 y; y < assetCount; ++y) { address assetAddr = allAssets[y]; if (strategy.supportsAsset(assetAddr)) { uint256 balance = strategy.checkBalance(assetAddr); @@ -733,6 +739,11 @@ contract VaultCore is VaultInitializer { } } + /** + * @dev Get the number of decimals of a token asset + * @param _asset Address of the asset + * @return decimals number of decimals + */ function _getDecimals(address _asset) internal view @@ -751,6 +762,7 @@ contract VaultCore is VaultInitializer { /** * @notice Gets the vault configuration of a supported asset. + * @param _asset Address of the token asset */ function getAssetConfig(address _asset) public diff --git a/contracts/contracts/vault/VaultStorage.sol b/contracts/contracts/vault/VaultStorage.sol index 99aa9406e3..8375cc44dd 100644 --- a/contracts/contracts/vault/VaultStorage.sol +++ b/contracts/contracts/vault/VaultStorage.sol @@ -126,14 +126,15 @@ contract VaultStorage is Initializable, Governable { // slither-disable-next-line uninitialized-state OUSD internal oUSD; - //keccak256("OUSD.vault.governor.admin.impl"); + /// @dev Storage slot for the address of the VaultAdmin contract that is delegated to + // keccak256("OUSD.vault.governor.admin.impl"); bytes32 constant adminImplPosition = 0xa2bd3d3cf188a41358c8b401076eb59066b09dec5775650c0de4c55187d17bd9; - // Address of the contract responsible for post rebase syncs with AMMs + /// @dev Address of the contract responsible for post rebase syncs with AMMs address private _deprecated_rebaseHooksAddr = address(0); - // Deprecated: Address of Uniswap + /// @dev Deprecated: Address of Uniswap // slither-disable-next-line constable-states address private _deprecated_uniswapAddr = address(0); diff --git a/contracts/docs/OETHVaultAdminSquashed.svg b/contracts/docs/OETHVaultAdminSquashed.svg index 1f01da55bc..d5af64e4d8 100644 --- a/contracts/docs/OETHVaultAdminSquashed.svg +++ b/contracts/docs/OETHVaultAdminSquashed.svg @@ -9,9 +9,9 @@ UmlClassDiagram - + -232 +233 OETHVaultAdmin ../contracts/vault/OETHVaultAdmin.sol @@ -26,7 +26,7 @@   _deprecated_rebaseHooksAddr: address <<VaultStorage>>   _deprecated_uniswapAddr: address <<VaultStorage>>   _deprecated_swapTokens: address[] <<VaultStorage>> -   __gap: uint256[46] <<VaultStorage>> +   __gap: uint256[45] <<VaultStorage>> Internal:   assets: mapping(address=>Asset) <<VaultStorage>>   allAssets: address[] <<VaultStorage>> diff --git a/contracts/docs/OETHVaultCoreSquashed.svg b/contracts/docs/OETHVaultCoreSquashed.svg index 9e32946122..7ff1c7040e 100644 --- a/contracts/docs/OETHVaultCoreSquashed.svg +++ b/contracts/docs/OETHVaultCoreSquashed.svg @@ -4,39 +4,38 @@ - - + + UmlClassDiagram - - + + -233 - -OETHVaultCore -../contracts/vault/OETHVaultCore.sol - -Private: -   initialized: bool <<Initializable>> -   initializing: bool <<Initializable>> -   ______gap: uint256[50] <<Initializable>> -   governorPosition: bytes32 <<Governable>> -   pendingGovernorPosition: bytes32 <<Governable>> -   reentryStatusPosition: bytes32 <<Governable>> -   _deprecated_rebaseHooksAddr: address <<VaultStorage>> -   _deprecated_uniswapAddr: address <<VaultStorage>> -   _deprecated_swapTokens: address[] <<VaultStorage>> -   __gap: uint256[46] <<VaultStorage>> -   __gap: uint256[50] <<OETHVaultCore>> -Internal: -   assets: mapping(address=>Asset) <<VaultStorage>> -   allAssets: address[] <<VaultStorage>> -   strategies: mapping(address=>Strategy) <<VaultStorage>> -   allStrategies: address[] <<VaultStorage>> -   oUSD: OUSD <<VaultStorage>> -   swapConfig: SwapConfig <<VaultStorage>> -   MAX_INT: uint256 <<VaultCore>> -   MAX_UINT: uint256 <<VaultCore>> +234 + +OETHVaultCore +../contracts/vault/OETHVaultCore.sol + +Private: +   initialized: bool <<Initializable>> +   initializing: bool <<Initializable>> +   ______gap: uint256[50] <<Initializable>> +   governorPosition: bytes32 <<Governable>> +   pendingGovernorPosition: bytes32 <<Governable>> +   reentryStatusPosition: bytes32 <<Governable>> +   _deprecated_rebaseHooksAddr: address <<VaultStorage>> +   _deprecated_uniswapAddr: address <<VaultStorage>> +   _deprecated_swapTokens: address[] <<VaultStorage>> +   __gap: uint256[45] <<VaultStorage>> +   __gap: uint256[50] <<OETHVaultCore>> +Internal: +   assets: mapping(address=>Asset) <<VaultStorage>> +   allAssets: address[] <<VaultStorage>> +   strategies: mapping(address=>Strategy) <<VaultStorage>> +   allStrategies: address[] <<VaultStorage>> +   oUSD: OUSD <<VaultStorage>> +   swapConfig: SwapConfig <<VaultStorage>> +   MAX_INT: uint256 <<VaultCore>> Public:   _NOT_ENTERED: uint256 <<Governable>>   _ENTERED: uint256 <<Governable>> diff --git a/contracts/docs/OETHVaultHierarchy.svg b/contracts/docs/OETHVaultHierarchy.svg index 4e9795682a..ce6caafd6c 100644 --- a/contracts/docs/OETHVaultHierarchy.svg +++ b/contracts/docs/OETHVaultHierarchy.svg @@ -29,127 +29,127 @@ - + -224 +225 <<Abstract>> Initializable ../contracts/utils/Initializable.sol - + -215->224 +215->225 - + -227 +228 <<Abstract>> InitializableERC20Detailed ../contracts/utils/InitializableERC20Detailed.sol - + -215->227 +215->228 - + -232 +233 OETHVaultAdmin ../contracts/vault/OETHVaultAdmin.sol - + -236 +237 VaultAdmin ../contracts/vault/VaultAdmin.sol - + -232->236 +233->237 - + -233 +234 OETHVaultCore ../contracts/vault/OETHVaultCore.sol - + -237 +238 VaultCore ../contracts/vault/VaultCore.sol - + -233->237 +234->238 - + -239 +240 VaultStorage ../contracts/vault/VaultStorage.sol - + -236->239 +237->240 - + -238 +239 VaultInitializer ../contracts/vault/VaultInitializer.sol - + -237->238 +238->239 - + -238->215 +239->215 - + -238->239 +239->240 - + -239->20 +240->20 - + -239->215 +240->215 - + -239->224 +240->225 diff --git a/contracts/docs/VaultAdminSquashed.svg b/contracts/docs/VaultAdminSquashed.svg index da6d5b6985..dc1af3bc9f 100644 --- a/contracts/docs/VaultAdminSquashed.svg +++ b/contracts/docs/VaultAdminSquashed.svg @@ -9,9 +9,9 @@ UmlClassDiagram - + -236 +237 VaultAdmin ../contracts/vault/VaultAdmin.sol @@ -26,7 +26,7 @@   _deprecated_rebaseHooksAddr: address <<VaultStorage>>   _deprecated_uniswapAddr: address <<VaultStorage>>   _deprecated_swapTokens: address[] <<VaultStorage>> -   __gap: uint256[46] <<VaultStorage>> +   __gap: uint256[45] <<VaultStorage>> Internal:   assets: mapping(address=>Asset) <<VaultStorage>>   allAssets: address[] <<VaultStorage>> diff --git a/contracts/docs/VaultCoreSquashed.svg b/contracts/docs/VaultCoreSquashed.svg index 815ea72cf9..b7e10a7f97 100644 --- a/contracts/docs/VaultCoreSquashed.svg +++ b/contracts/docs/VaultCoreSquashed.svg @@ -4,38 +4,37 @@ - - + + UmlClassDiagram - - + + -237 - -VaultCore -../contracts/vault/VaultCore.sol - -Private: -   initialized: bool <<Initializable>> -   initializing: bool <<Initializable>> -   ______gap: uint256[50] <<Initializable>> -   governorPosition: bytes32 <<Governable>> -   pendingGovernorPosition: bytes32 <<Governable>> -   reentryStatusPosition: bytes32 <<Governable>> -   _deprecated_rebaseHooksAddr: address <<VaultStorage>> -   _deprecated_uniswapAddr: address <<VaultStorage>> -   _deprecated_swapTokens: address[] <<VaultStorage>> -   __gap: uint256[46] <<VaultStorage>> -Internal: -   assets: mapping(address=>Asset) <<VaultStorage>> -   allAssets: address[] <<VaultStorage>> -   strategies: mapping(address=>Strategy) <<VaultStorage>> -   allStrategies: address[] <<VaultStorage>> -   oUSD: OUSD <<VaultStorage>> -   swapConfig: SwapConfig <<VaultStorage>> -   MAX_INT: uint256 <<VaultCore>> -   MAX_UINT: uint256 <<VaultCore>> +238 + +VaultCore +../contracts/vault/VaultCore.sol + +Private: +   initialized: bool <<Initializable>> +   initializing: bool <<Initializable>> +   ______gap: uint256[50] <<Initializable>> +   governorPosition: bytes32 <<Governable>> +   pendingGovernorPosition: bytes32 <<Governable>> +   reentryStatusPosition: bytes32 <<Governable>> +   _deprecated_rebaseHooksAddr: address <<VaultStorage>> +   _deprecated_uniswapAddr: address <<VaultStorage>> +   _deprecated_swapTokens: address[] <<VaultStorage>> +   __gap: uint256[45] <<VaultStorage>> +Internal: +   assets: mapping(address=>Asset) <<VaultStorage>> +   allAssets: address[] <<VaultStorage>> +   strategies: mapping(address=>Strategy) <<VaultStorage>> +   allStrategies: address[] <<VaultStorage>> +   oUSD: OUSD <<VaultStorage>> +   swapConfig: SwapConfig <<VaultStorage>> +   MAX_INT: uint256 <<VaultCore>> Public:   _NOT_ENTERED: uint256 <<Governable>>   _ENTERED: uint256 <<Governable>> diff --git a/contracts/docs/VaultHierarchy.svg b/contracts/docs/VaultHierarchy.svg index 33b2a2a61e..044158df15 100644 --- a/contracts/docs/VaultHierarchy.svg +++ b/contracts/docs/VaultHierarchy.svg @@ -29,101 +29,101 @@ - + -224 +225 <<Abstract>> Initializable ../contracts/utils/Initializable.sol - + -215->224 +215->225 - + -227 +228 <<Abstract>> InitializableERC20Detailed ../contracts/utils/InitializableERC20Detailed.sol - + -215->227 +215->228 - + -236 +237 VaultAdmin ../contracts/vault/VaultAdmin.sol - + -239 +240 VaultStorage ../contracts/vault/VaultStorage.sol - + -236->239 +237->240 - + -237 +238 VaultCore ../contracts/vault/VaultCore.sol - + -238 +239 VaultInitializer ../contracts/vault/VaultInitializer.sol - + -237->238 +238->239 - + -238->215 +239->215 - + -238->239 +239->240 - + -239->20 +240->20 - + -239->215 +240->215 - + -239->224 +240->225