diff --git a/contracts/contracts/harvest/BaseHarvester.sol b/contracts/contracts/harvest/BaseHarvester.sol index 0244878d3a..c14ab2df0f 100644 --- a/contracts/contracts/harvest/BaseHarvester.sol +++ b/contracts/contracts/harvest/BaseHarvester.sol @@ -100,15 +100,13 @@ abstract contract BaseHarvester is Governable { /** * Address receiving rewards proceeds. Initially the Vault contract later will possibly * be replaced by another contract that eases out rewards distribution. - * - */ + **/ address public rewardProceedsAddress; /** * All tokens are swapped to this token before it gets transferred * to the `rewardProceedsAddress`. USDT for OUSD and WETH for OETH. - * - */ + **/ address public immutable baseTokenAddress; // Cached decimals for `baseTokenAddress` uint256 public immutable baseTokenDecimals; @@ -126,7 +124,6 @@ abstract contract BaseHarvester is Governable { uint128 baseTokenIndex; } // Packed indices of assets on the Curve pool - mapping(address => CurvePoolIndices) public curvePoolIndices; constructor(address _vaultAddress, address _baseTokenAddress) { @@ -140,11 +137,9 @@ abstract contract BaseHarvester is Governable { baseTokenDecimals = Helpers.getDecimals(_baseTokenAddress); } - /** - * - * Configuration - * - */ + /*************************************** + Configuration + ****************************************/ /** * Set the Address receiving rewards proceeds. @@ -392,11 +387,9 @@ abstract contract BaseHarvester is Governable { emit SupportedStrategyUpdate(_strategyAddress, _isSupported); } - /** - * - * Rewards - * - */ + /*************************************** + Rewards + ****************************************/ /** * @dev Transfer token to governor. Intended for recovering tokens stuck in @@ -509,11 +502,11 @@ abstract contract BaseHarvester is Governable { // Oracle price is 1e18 uint256 minExpected = (balance * - (1e4 - tokenConfig.allowedSlippageBps) * - oraclePrice).scaleBy( // max allowed slippage - baseTokenDecimals, - Helpers.getDecimals(_swapToken) - ) / + (1e4 - tokenConfig.allowedSlippageBps) * // max allowed slippage + oraclePrice).scaleBy( + baseTokenDecimals, + Helpers.getDecimals(_swapToken) + ) / 1e4 / // fix the max slippage decimal position 1e18; // and oracle price decimals position diff --git a/contracts/contracts/harvest/Dripper.sol b/contracts/contracts/harvest/Dripper.sol index a8ac02d596..02301a7e53 100644 --- a/contracts/contracts/harvest/Dripper.sol +++ b/contracts/contracts/harvest/Dripper.sol @@ -43,6 +43,7 @@ import { IVault } from "../interfaces/IVault.sol"; * longer curve the more collect() is called without incoming yield. * */ + contract Dripper is Governable { using SafeERC20 for IERC20; diff --git a/contracts/contracts/interfaces/morpho/IMorpho.sol b/contracts/contracts/interfaces/morpho/IMorpho.sol index bfeed0f9b2..60ec3d376c 100644 --- a/contracts/contracts/interfaces/morpho/IMorpho.sol +++ b/contracts/contracts/interfaces/morpho/IMorpho.sol @@ -9,10 +9,10 @@ import "./compound/ICompoundOracle.sol"; interface IMorpho { function comptroller() external view returns (IComptroller); function supply(address _poolTokenAddress, address _onBehalf, uint256 _amount) external; - function supply(address _poolTokenAddress, address _onBehalf, uint256 _amount, uint256 _maxGasForMatching) - external; + function supply(address _poolTokenAddress, address _onBehalf, uint256 _amount, uint256 _maxGasForMatching) external; function withdraw(address _poolTokenAddress, uint256 _amount) external; - function claimRewards(address[] calldata _cTokenAddresses, bool _tradeForMorphoToken) - external - returns (uint256 claimedAmount); + function claimRewards( + address[] calldata _cTokenAddresses, + bool _tradeForMorphoToken + ) external returns (uint256 claimedAmount); } diff --git a/contracts/contracts/mocks/MockAave.sol b/contracts/contracts/mocks/MockAave.sol index ee58b33097..bae0d9f81d 100644 --- a/contracts/contracts/mocks/MockAave.sol +++ b/contracts/contracts/mocks/MockAave.sol @@ -19,7 +19,6 @@ import { StableMath } from "../utils/StableMath.sol"; contract MockAToken is MintableERC20 { address public lendingPool; IERC20 public underlyingToken; - using SafeERC20 for IERC20; constructor( diff --git a/contracts/contracts/mocks/MockAaveIncentivesController.sol b/contracts/contracts/mocks/MockAaveIncentivesController.sol index 5e8dacae04..041c4f5b01 100644 --- a/contracts/contracts/mocks/MockAaveIncentivesController.sol +++ b/contracts/contracts/mocks/MockAaveIncentivesController.sol @@ -19,8 +19,7 @@ contract MockAaveIncentivesController { * @dev Returns the total of rewards of an user, already accrued + not yet accrued * @param user The address of the user * @return The rewards - * - */ + **/ // solhint-disable-next-line no-unused-vars function getRewardsBalance(address[] calldata assets, address user) external @@ -35,8 +34,7 @@ contract MockAaveIncentivesController { * @param amount Amount of rewards to claim * @param to Address that will be receiving the rewards * @return Rewards claimed - * - */ + **/ function claimRewards( // solhint-disable-next-line no-unused-vars address[] calldata assets, diff --git a/contracts/contracts/mocks/MockBalancerVault.sol b/contracts/contracts/mocks/MockBalancerVault.sol index 3a05246c28..eb140d01e8 100644 --- a/contracts/contracts/mocks/MockBalancerVault.sol +++ b/contracts/contracts/mocks/MockBalancerVault.sol @@ -10,7 +10,6 @@ import { StableMath } from "../utils/StableMath.sol"; contract MockBalancerVault { using StableMath for uint256; - uint256 public slippage = 1 ether; bool public transferDisabled = false; bool public slippageErrorDisabled = false; diff --git a/contracts/contracts/mocks/MockOGN.sol b/contracts/contracts/mocks/MockOGN.sol index 3a1fd782ce..35663cf22b 100644 --- a/contracts/contracts/mocks/MockOGN.sol +++ b/contracts/contracts/mocks/MockOGN.sol @@ -95,11 +95,11 @@ contract MockOGN is MintableERC20, BurnableERC20 { // // Functions for maintaining whitelist // + modifier onlyOwner() { require(msg.sender == owner); _; } - modifier allowedTransfer(address _from, address _to) { require( // solium-disable-next-line operator-whitespace @@ -149,6 +149,7 @@ contract MockOGN is MintableERC20, BurnableERC20 { // ERC20 transfer functions that have been overridden to enforce the // whitelist. // + function transfer(address _to, uint256 _value) public override diff --git a/contracts/contracts/mocks/MockStkAave.sol b/contracts/contracts/mocks/MockStkAave.sol index 0705c7f8a4..ad91e5cb52 100644 --- a/contracts/contracts/mocks/MockStkAave.sol +++ b/contracts/contracts/mocks/MockStkAave.sol @@ -31,8 +31,7 @@ contract MockStkAave is MintableERC20 { * @dev Redeems staked tokens, and stop earning rewards * @param to Address to redeem to * @param amount Amount to redeem - * - */ + **/ function redeem(address to, uint256 amount) external { uint256 cooldownStartTimestamp = stakersCooldowns[msg.sender]; uint256 windowStart = cooldownStartTimestamp + COOLDOWN_SECONDS; @@ -55,8 +54,7 @@ contract MockStkAave is MintableERC20 { /** * @dev Activates the cooldown period to unstake * - It can't be called if the user is not staking - * - */ + **/ function cooldown() external { require(balanceOf(msg.sender) != 0, "INVALID_BALANCE_ON_COOLDOWN"); stakersCooldowns[msg.sender] = block.timestamp; @@ -64,8 +62,7 @@ contract MockStkAave is MintableERC20 { /** * @dev Test helper function to allow changing the cooldown - * - */ + **/ function setCooldown(address account, uint256 _cooldown) external { stakersCooldowns[account] = _cooldown; } diff --git a/contracts/contracts/oracle/AuraWETHPriceFeed.sol b/contracts/contracts/oracle/AuraWETHPriceFeed.sol index 81c3755fa0..89f1b2e78a 100644 --- a/contracts/contracts/oracle/AuraWETHPriceFeed.sol +++ b/contracts/contracts/oracle/AuraWETHPriceFeed.sol @@ -41,8 +41,7 @@ contract AuraWETHPriceFeed is AggregatorV3Interface, Strategizable { * TWAP price. * * @return price The price scaled to 18 decimals - * - */ + **/ function price() external view returns (int256) { return _price(); } @@ -86,8 +85,7 @@ contract AuraWETHPriceFeed is AggregatorV3Interface, Strategizable { /** * Pauses the price feed. Callable by Strategist as well. - * - */ + **/ function pause() external onlyGovernorOrStrategist { if (paused) { revert PriceFeedPausedError(); @@ -98,8 +96,7 @@ contract AuraWETHPriceFeed is AggregatorV3Interface, Strategizable { /** * Unpauses the price feed. Only Governor can call it - * - */ + **/ function unpause() external onlyGovernor { if (!paused) { revert PriceFeedUnpausedError(); @@ -113,8 +110,7 @@ contract AuraWETHPriceFeed is AggregatorV3Interface, Strategizable { * two different price points. * * @param _tolerance New tolerance value - * - */ + **/ function setTolerance(uint256 _tolerance) external onlyGovernor { if (_tolerance > 0.1 ether) { revert InvalidToleranceBps(); @@ -131,8 +127,7 @@ contract AuraWETHPriceFeed is AggregatorV3Interface, Strategizable { * The `answer` returned by this is same as what `price()` would return. * * It doesn't return any data about rounds (since those doesn't exist). - * - */ + **/ function latestRoundData() external view @@ -154,8 +149,7 @@ contract AuraWETHPriceFeed is AggregatorV3Interface, Strategizable { * with AggregatorV3Interface. * * Always reverts since there're no round data in this contract. - * - */ + **/ function getRoundData(uint80) external pure diff --git a/contracts/contracts/strategies/AaveStrategy.sol b/contracts/contracts/strategies/AaveStrategy.sol index 66f53eca8c..629df13876 100644 --- a/contracts/contracts/strategies/AaveStrategy.sol +++ b/contracts/contracts/strategies/AaveStrategy.sol @@ -190,8 +190,8 @@ contract AaveStrategy is InitializableAbstractStrategy { /** * @dev Internal method to respond to the addition of new asset / aTokens - * We need to give the AAVE lending pool approval to transfer the - * asset. + We need to give the AAVE lending pool approval to transfer the + asset. * @param _asset Address of the asset to approve * @param _aToken Address of the aToken */ diff --git a/contracts/contracts/strategies/BaseCompoundStrategy.sol b/contracts/contracts/strategies/BaseCompoundStrategy.sol index 7099952192..6ec4e3520b 100644 --- a/contracts/contracts/strategies/BaseCompoundStrategy.sol +++ b/contracts/contracts/strategies/BaseCompoundStrategy.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.0; * @title Base Compound Abstract Strategy * @author Origin Protocol Inc */ + import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { ICERC20 } from "./ICompound.sol"; import { IComptroller } from "../interfaces/IComptroller.sol"; diff --git a/contracts/contracts/strategies/CompoundStrategy.sol b/contracts/contracts/strategies/CompoundStrategy.sol index b4c115bead..b195c3b9cc 100644 --- a/contracts/contracts/strategies/CompoundStrategy.sol +++ b/contracts/contracts/strategies/CompoundStrategy.sol @@ -15,7 +15,6 @@ import { IERC20 } from "../utils/InitializableAbstractStrategy.sol"; contract CompoundStrategy is BaseCompoundStrategy { using SafeERC20 for IERC20; - event SkippedWithdrawal(address asset, uint256 amount); constructor(BaseStrategyConfig memory _stratConfig) diff --git a/contracts/contracts/strategies/ConvexEthMetaStrategy.sol b/contracts/contracts/strategies/ConvexEthMetaStrategy.sol index 983d4d9ec4..8a347c1b5e 100644 --- a/contracts/contracts/strategies/ConvexEthMetaStrategy.sol +++ b/contracts/contracts/strategies/ConvexEthMetaStrategy.sol @@ -157,11 +157,9 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { _approveBase(); } - /** - * - * Deposit - * - */ + /*************************************** + Deposit + ****************************************/ /** * @notice Deposit WETH into the Curve pool @@ -252,11 +250,9 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { } } - /** - * - * Withdraw - * - */ + /*************************************** + Withdraw + ****************************************/ /** * @notice Withdraw ETH and OETH from the Curve pool, burn the OETH, @@ -369,11 +365,9 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { emit Withdrawal(address(oeth), address(lpToken), oethToBurn); } - /** - * - * Curve pool Rebalancing - * - */ + /*************************************** + Curve pool Rebalancing + ****************************************/ /** * @notice Mint OTokens and one-sided add to the Curve pool. @@ -514,11 +508,9 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { ); } - /** - * - * Assets and Rewards - * - */ + /*************************************** + Assets and Rewards + ****************************************/ /** * @notice Collect accumulated CRV and CVX rewards and send to the Harvester. @@ -569,11 +561,9 @@ contract ConvexEthMetaStrategy is InitializableAbstractStrategy { return _asset == address(weth); } - /** - * - * Approvals - * - */ + /*************************************** + Approvals + ****************************************/ /** * @notice Approve the spending of all assets by their corresponding pool tokens, diff --git a/contracts/contracts/strategies/ConvexOUSDMetaStrategy.sol b/contracts/contracts/strategies/ConvexOUSDMetaStrategy.sol index df23e56ba2..742e8050b1 100644 --- a/contracts/contracts/strategies/ConvexOUSDMetaStrategy.sol +++ b/contracts/contracts/strategies/ConvexOUSDMetaStrategy.sol @@ -126,7 +126,8 @@ contract ConvexOUSDMetaStrategy is BaseConvexMetaStrategy { // simplifying below to: `uint256 diff = (num3CrvTokens - 1) * k` causes loss of precision // prettier-ignore // slither-disable-next-line divide-before-multiply - uint256 diff = crvPoolBalance * k - (crvPoolBalance - num3CrvTokens - 1) * k; + uint256 diff = crvPoolBalance * k - + (crvPoolBalance - num3CrvTokens - 1) * k; uint256 lpToBurn = diff / 1e36; uint256 gaugeTokens = IRewardStaking(cvxRewardStakerAddress).balanceOf( diff --git a/contracts/contracts/strategies/FluxStrategy.sol b/contracts/contracts/strategies/FluxStrategy.sol index 07be6d94e8..1a41f0fe5b 100644 --- a/contracts/contracts/strategies/FluxStrategy.sol +++ b/contracts/contracts/strategies/FluxStrategy.sol @@ -6,6 +6,7 @@ pragma solidity ^0.8.0; * @notice Investment strategy for investing stablecoins via Flux * @author Origin Protocol Inc */ + import { CompoundStrategy } from "./CompoundStrategy.sol"; contract FluxStrategy is CompoundStrategy { diff --git a/contracts/contracts/strategies/IAave.sol b/contracts/contracts/strategies/IAave.sol index c1051eeea3..59fcdf4b70 100644 --- a/contracts/contracts/strategies/IAave.sol +++ b/contracts/contracts/strategies/IAave.sol @@ -16,8 +16,7 @@ interface IAaveLendingPool { * is a different wallet * @param referralCode Code used to register the integrator originating the operation, for potential rewards. * 0 if the action is executed directly by the user, without any middle-man - * - */ + **/ function deposit( address asset, uint256 amount, @@ -35,8 +34,7 @@ interface IAaveLendingPool { * wants to receive it on his own wallet, or a different address if the beneficiary is a * different wallet * @return The final amount withdrawn - * - */ + **/ function withdraw( address asset, uint256 amount, diff --git a/contracts/contracts/strategies/IAaveIncentivesController.sol b/contracts/contracts/strategies/IAaveIncentivesController.sol index f9e5b9639b..7eff4f86fe 100644 --- a/contracts/contracts/strategies/IAaveIncentivesController.sol +++ b/contracts/contracts/strategies/IAaveIncentivesController.sol @@ -62,8 +62,7 @@ interface IAaveIncentivesController { * @param asset The address of the user * @param userBalance The balance of the user of the asset in the lending pool * @param totalSupply The total supply of the asset in the lending pool - * - */ + **/ function handleAction( address asset, uint256 userBalance, @@ -74,8 +73,7 @@ interface IAaveIncentivesController { * @dev Returns the total of rewards of an user, already accrued + not yet accrued * @param user The address of the user * @return The rewards - * - */ + **/ function getRewardsBalance(address[] calldata assets, address user) external view @@ -87,8 +85,7 @@ interface IAaveIncentivesController { * @param amount Amount of rewards to claim * @param to Address that will be receiving the rewards * @return Rewards claimed - * - */ + **/ function claimRewards( address[] calldata assets, uint256 amount, @@ -103,8 +100,7 @@ interface IAaveIncentivesController { * @param user Address to check and claim rewards * @param to Address that will be receiving the rewards * @return Rewards claimed - * - */ + **/ function claimRewardsOnBehalf( address[] calldata assets, uint256 amount, diff --git a/contracts/contracts/strategies/MorphoCompoundStrategy.sol b/contracts/contracts/strategies/MorphoCompoundStrategy.sol index 79a2efa08f..6bb685ad88 100644 --- a/contracts/contracts/strategies/MorphoCompoundStrategy.sol +++ b/contracts/contracts/strategies/MorphoCompoundStrategy.sol @@ -16,7 +16,6 @@ import "../utils/Helpers.sol"; contract MorphoCompoundStrategy is BaseCompoundStrategy { address public constant MORPHO = 0x8888882f8f843896699869179fB6E4f7e3B58888; address public constant LENS = 0x930f1b46e1D081Ec1524efD95752bE3eCe51EF67; - using SafeERC20 for IERC20; using StableMath for uint256; @@ -104,6 +103,7 @@ contract MorphoCompoundStrategy is BaseCompoundStrategy { * * For the above reasoning such "optimization" is not implemented */ + address[] memory poolTokens = new address[](assetsMapped.length); for (uint256 i = 0; i < assetsMapped.length; i++) { poolTokens[i] = assetToPToken[assetsMapped[i]]; diff --git a/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol b/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol index 7c5ac05480..d8d0a789ca 100644 --- a/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol +++ b/contracts/contracts/strategies/balancer/BaseAuraStrategy.sol @@ -5,6 +5,7 @@ pragma solidity ^0.8.0; * @title OETH Base Balancer Abstract Strategy * @author Origin Protocol Inc */ + import { BaseBalancerStrategy } from "./BaseBalancerStrategy.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { IERC20 } from "../../utils/InitializableAbstractStrategy.sol"; diff --git a/contracts/contracts/swapper/Swapper1InchV5.sol b/contracts/contracts/swapper/Swapper1InchV5.sol index b9990ed8c5..d1bb9d656d 100644 --- a/contracts/contracts/swapper/Swapper1InchV5.sol +++ b/contracts/contracts/swapper/Swapper1InchV5.sol @@ -8,6 +8,7 @@ pragma solidity ^0.8.0; * This can happen with some tokens that don't send the full transfer amount. * These dust amounts can build up over time and be used by anyone who calls the `swap` function. */ + import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; diff --git a/contracts/contracts/token/OUSD.sol b/contracts/contracts/token/OUSD.sol index 67314d2ab8..5f8dba4c46 100644 --- a/contracts/contracts/token/OUSD.sol +++ b/contracts/contracts/token/OUSD.sol @@ -20,6 +20,7 @@ import { Governable } from "../governance/Governable.sol"; * balanceOf(x) for all x is not >= totalSupply(). This is a consequence of the * rebasing design. Any integrations with OUSD should be aware. */ + contract OUSD is Initializable, InitializableERC20Detailed, Governable { using SafeMath for uint256; using StableMath for uint256; @@ -321,7 +322,7 @@ contract OUSD is Initializable, InitializableERC20Detailed, Governable { /** * @dev Decrease the amount of tokens that an owner has allowed to - * `_spender`. + `_spender`. * @param _spender The address which will spend the funds. * @param _subtractedValue The amount of tokens to decrease the allowance * by. diff --git a/contracts/contracts/token/WOETH.sol b/contracts/contracts/token/WOETH.sol index 83bcd844dc..a15aa6283e 100644 --- a/contracts/contracts/token/WOETH.sol +++ b/contracts/contracts/token/WOETH.sol @@ -14,6 +14,7 @@ import { OETH } from "./OETH.sol"; * @title OETH Token Contract * @author Origin Protocol Inc */ + contract WOETH is ERC4626, Governable, Initializable { using SafeERC20 for IERC20; diff --git a/contracts/contracts/utils/InitializableAbstractStrategy.sol b/contracts/contracts/utils/InitializableAbstractStrategy.sol index de3705866c..9daff9c8c0 100644 --- a/contracts/contracts/utils/InitializableAbstractStrategy.sol +++ b/contracts/contracts/utils/InitializableAbstractStrategy.sol @@ -289,11 +289,10 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { harvesterAddress = _harvesterAddress; } - /** - * - * Abstract - * - */ + /*************************************** + Abstract + ****************************************/ + function _abstractSetPToken(address _asset, address _pToken) internal virtual; diff --git a/contracts/contracts/utils/StableMath.sol b/contracts/contracts/utils/StableMath.sol index 9fcc292b0e..5dc19d2960 100644 --- a/contracts/contracts/utils/StableMath.sol +++ b/contracts/contracts/utils/StableMath.sol @@ -15,11 +15,9 @@ library StableMath { */ uint256 private constant FULL_SCALE = 1e18; - /** - * - * Helpers - * - */ + /*************************************** + Helpers + ****************************************/ /** * @dev Adjust the scale of an integer @@ -40,11 +38,9 @@ library StableMath { return x; } - /** - * - * Precise Arithmetic - * - */ + /*************************************** + Precise Arithmetic + ****************************************/ /** * @dev Multiplies two precise units, and then truncates by the full scale diff --git a/contracts/contracts/vault/VaultAdmin.sol b/contracts/contracts/vault/VaultAdmin.sol index 5593d10383..5d4adcf2e1 100644 --- a/contracts/contracts/vault/VaultAdmin.sol +++ b/contracts/contracts/vault/VaultAdmin.sol @@ -6,6 +6,7 @@ pragma solidity ^0.8.0; * @notice The VaultAdmin contract makes configuration and admin calls on the vault. * @author Origin Protocol Inc */ + import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { IOracle } from "../interfaces/IOracle.sol"; @@ -30,11 +31,9 @@ contract VaultAdmin is VaultStorage { _; } - /** - * - * Configuration - * - */ + /*************************************** + Configuration + ****************************************/ /** * @notice Set address of price provider. @@ -103,7 +102,7 @@ contract VaultAdmin is VaultStorage { /** * @notice Set the default Strategy for an asset, i.e. the one which the asset - * will be automatically allocated to and withdrawn from + will be automatically allocated to and withdrawn from * @param _asset Address of the asset * @param _strategy Address of the Strategy */ @@ -155,11 +154,9 @@ contract VaultAdmin is VaultStorage { emit NetOusdMintForStrategyThresholdChanged(_threshold); } - /** - * - * Swaps - * - */ + /*************************************** + Swaps + ****************************************/ /** * @notice Strategist swaps collateral assets sitting in the vault. @@ -258,11 +255,9 @@ contract VaultAdmin is VaultStorage { emit Swapped(_fromAsset, _toAsset, _fromAssetAmount, toAssetAmount); } - /** - * - * Swap Config - * - */ + /*************************************** + Swap Config + ****************************************/ /** * @notice Set the contract the performs swaps of collateral assets. @@ -316,11 +311,9 @@ contract VaultAdmin is VaultStorage { emit SwapSlippageChanged(_asset, _allowedOracleSlippageBps); } - /** - * - * Asset Config - * - */ + /*************************************** + Asset Config + ****************************************/ /** * @notice Add a supported asset to the contract, i.e. one that can be @@ -359,11 +352,9 @@ contract VaultAdmin is VaultStorage { _cacheDecimals(_asset); } - /** - * - * Strategy Config - * - */ + /*************************************** + Strategy Config + ****************************************/ /** * @notice Add a strategy to the Vault. @@ -380,6 +371,7 @@ contract VaultAdmin is VaultStorage { * @notice Remove a strategy from the Vault. * @param _addr Address of the strategy to remove */ + function removeStrategy(address _addr) external onlyGovernor { require(strategies[_addr].isSupported, "Strategy not approved"); @@ -417,11 +409,9 @@ contract VaultAdmin is VaultStorage { } } - /** - * - * Strategies - * - */ + /*************************************** + Strategies + ****************************************/ /** * @notice Deposit multiple assets from the vault into the strategy. @@ -548,11 +538,9 @@ contract VaultAdmin is VaultStorage { emit OusdMetaStrategyUpdated(_ousdMetaStrategy); } - /** - * - * Pause - * - */ + /*************************************** + Pause + ****************************************/ /** * @notice Set the deposit paused flag to true to prevent rebasing. @@ -586,11 +574,9 @@ contract VaultAdmin is VaultStorage { emit CapitalUnpaused(); } - /** - * - * Utils - * - */ + /*************************************** + Utils + ****************************************/ /** * @notice Transfer token to governor. Intended for recovering tokens stuck in @@ -606,11 +592,9 @@ contract VaultAdmin is VaultStorage { IERC20(_asset).safeTransfer(governor(), _amount); } - /** - * - * Strategies Admin - * - */ + /*************************************** + Strategies Admin + ****************************************/ /** * @notice Withdraws all assets from the strategy and sends assets to the Vault. @@ -638,11 +622,10 @@ contract VaultAdmin is VaultStorage { } } - /** - * - * Utils - * - */ + /*************************************** + Utils + ****************************************/ + function _cacheDecimals(address token) internal { Asset storage tokenAsset = assets[token]; if (tokenAsset.decimals != 0) { diff --git a/contracts/contracts/vault/VaultCore.sol b/contracts/contracts/vault/VaultCore.sol index dedad921c2..814dcda9e5 100644 --- a/contracts/contracts/vault/VaultCore.sol +++ b/contracts/contracts/vault/VaultCore.sol @@ -4,12 +4,13 @@ pragma solidity ^0.8.0; /** * @title OToken VaultCore contract * @notice The Vault contract stores assets. On a deposit, OTokens will be minted - * and sent to the depositor. On a withdrawal, OTokens will be burned and - * assets will be sent to the withdrawer. The Vault accepts deposits of - * interest from yield bearing strategies which will modify the supply - * of OTokens. + and sent to the depositor. On a withdrawal, OTokens will be burned and + assets will be sent to the withdrawer. The Vault accepts deposits of + interest from yield bearing strategies which will modify the supply + of OTokens. * @author Origin Protocol Inc */ + import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { StableMath } from "../utils/StableMath.sol"; @@ -22,7 +23,6 @@ contract VaultCore is VaultInitializer { using SafeERC20 for IERC20; using StableMath for uint256; // max signed int - uint256 internal constant MAX_INT = 2**255 - 1; // max un-signed int uint256 internal constant MAX_UINT = @@ -278,16 +278,14 @@ contract VaultCore is VaultInitializer { /** * @notice Allocate unallocated funds on Vault to strategies. - * - */ + **/ function allocate() external whenNotCapitalPaused nonReentrant { _allocate(); } /** * @dev Allocate unallocated funds on Vault to strategies. - * - */ + **/ function _allocate() internal { uint256 vaultValue = _totalValueInVault(); // Nothing in vault to allocate @@ -579,11 +577,9 @@ contract VaultCore is VaultInitializer { } } - /** - * - * Pricing - * - */ + /*************************************** + Pricing + ****************************************/ /** * @notice Returns the total price in 18 digit units for a given asset. @@ -629,11 +625,9 @@ contract VaultCore is VaultInitializer { price = (_toUnitPrice(asset, false) * units) / 1e18; } - /** - * - * Utils - * - */ + /*************************************** + Utils + ****************************************/ /** * @dev Convert a quantity of a token into 1e18 fixed decimal "units" diff --git a/contracts/contracts/vault/VaultInitializer.sol b/contracts/contracts/vault/VaultInitializer.sol index 06cf5ea0d0..3f4b48d981 100644 --- a/contracts/contracts/vault/VaultInitializer.sol +++ b/contracts/contracts/vault/VaultInitializer.sol @@ -6,6 +6,7 @@ pragma solidity ^0.8.0; * @notice The Vault contract initializes the vault. * @author Origin Protocol Inc */ + import "./VaultStorage.sol"; contract VaultInitializer is VaultStorage { diff --git a/contracts/contracts/vault/VaultStorage.sol b/contracts/contracts/vault/VaultStorage.sol index 31ef8bbd2b..6687400048 100644 --- a/contracts/contracts/vault/VaultStorage.sol +++ b/contracts/contracts/vault/VaultStorage.sol @@ -6,6 +6,7 @@ pragma solidity ^0.8.0; * @notice The VaultStorage contract defines the storage for the Vault contracts * @author Origin Protocol Inc */ + import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { Address } from "@openzeppelin/contracts/utils/Address.sol"; @@ -58,7 +59,6 @@ contract VaultStorage is Initializable, Governable { 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. @@ -83,7 +83,6 @@ contract VaultStorage is Initializable, Governable { uint256 _deprecated; // Deprecated storage slot } /// @dev mapping of strategy contracts to their configiration - mapping(address => Strategy) internal strategies; /// @dev list of all vault strategies address[] internal allStrategies; @@ -164,7 +163,6 @@ contract VaultStorage is Initializable, Governable { // For example 100 == 1% uint16 allowedUndervalueBps; } - SwapConfig internal swapConfig = SwapConfig(address(0), 0); // For future use diff --git a/contracts/lib/openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol b/contracts/lib/openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol index eaebfb3df8..9318fd1126 100644 --- a/contracts/lib/openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol +++ b/contracts/lib/openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol @@ -2,10 +2,10 @@ pragma solidity ^0.8.0; -import {IERC4626} from "../../../../interfaces/IERC4626.sol"; -import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; +import { IERC4626 } from "../../../../interfaces/IERC4626.sol"; +import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; // From Open Zeppelin draft PR commit: // fac43034dca85ff539db3fc8aa2a7084b843d454 @@ -18,16 +18,12 @@ abstract contract ERC4626 is ERC20, IERC4626 { _asset = __asset; } - /** - * @dev See {IERC4262-asset} - */ + /** @dev See {IERC4262-asset} */ function asset() public view virtual override returns (address) { return address(_asset); } - /** - * @dev See {IERC4262-totalAssets} - */ + /** @dev See {IERC4262-totalAssets} */ function totalAssets() public view virtual override returns (uint256) { return _asset.balanceOf(address(this)); } @@ -41,81 +37,62 @@ abstract contract ERC4626 is ERC20, IERC4626 { function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) { uint256 supply = totalSupply(); - return (assets == 0 || supply == 0) - ? (assets * 10 ** decimals()) / 10 ** _asset.decimals() - : (assets * supply) / totalAssets(); + return + (assets == 0 || supply == 0) + ? (assets * 10**decimals()) / 10**_asset.decimals() + : (assets * supply) / totalAssets(); } - /** - * @dev See {IERC4262-convertToAssets} - */ + /** @dev See {IERC4262-convertToAssets} */ function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) { uint256 supply = totalSupply(); - return (supply == 0) ? (shares * 10 ** _asset.decimals()) / 10 ** decimals() : (shares * totalAssets()) / supply; + return (supply == 0) ? (shares * 10**_asset.decimals()) / 10**decimals() : (shares * totalAssets()) / supply; } - /** - * @dev See {IERC4262-maxDeposit} - */ + /** @dev See {IERC4262-maxDeposit} */ function maxDeposit(address) public view virtual override returns (uint256) { return type(uint256).max; } - /** - * @dev See {IERC4262-maxMint} - */ + /** @dev See {IERC4262-maxMint} */ function maxMint(address) public view virtual override returns (uint256) { return type(uint256).max; } - /** - * @dev See {IERC4262-maxWithdraw} - */ + /** @dev See {IERC4262-maxWithdraw} */ function maxWithdraw(address owner) public view virtual override returns (uint256) { return convertToAssets(balanceOf(owner)); } - /** - * @dev See {IERC4262-maxRedeem} - */ + /** @dev See {IERC4262-maxRedeem} */ function maxRedeem(address owner) public view virtual override returns (uint256) { return balanceOf(owner); } - /** - * @dev See {IERC4262-previewDeposit} - */ + /** @dev See {IERC4262-previewDeposit} */ function previewDeposit(uint256 assets) public view virtual override returns (uint256) { return convertToShares(assets); } - /** - * @dev See {IERC4262-previewMint} - */ + /** @dev See {IERC4262-previewMint} */ function previewMint(uint256 shares) public view virtual override returns (uint256) { uint256 assets = convertToAssets(shares); return assets + (convertToShares(assets) < shares ? 1 : 0); } - /** - * @dev See {IERC4262-previewWithdraw} - */ + /** @dev See {IERC4262-previewWithdraw} */ function previewWithdraw(uint256 assets) public view virtual override returns (uint256) { uint256 shares = convertToShares(assets); return shares + (convertToAssets(shares) < assets ? 1 : 0); } - /** - * @dev See {IERC4262-previewRedeem} - */ + /** @dev See {IERC4262-previewRedeem} */ function previewRedeem(uint256 shares) public view virtual override returns (uint256) { return convertToAssets(shares); } - /** - * @dev See {IERC4262-deposit} - */ + /** @dev See {IERC4262-deposit} */ function deposit(uint256 assets, address receiver) public virtual override returns (uint256) { require(assets <= maxDeposit(receiver), "ERC4626: deposit more then max"); @@ -132,9 +109,7 @@ abstract contract ERC4626 is ERC20, IERC4626 { return shares; } - /** - * @dev See {IERC4262-mint} - */ + /** @dev See {IERC4262-mint} */ function mint(uint256 shares, address receiver) public virtual override returns (uint256) { require(shares <= maxMint(receiver), "ERC4626: mint more then max"); @@ -151,10 +126,12 @@ abstract contract ERC4626 is ERC20, IERC4626 { return assets; } - /** - * @dev See {IERC4262-withdraw} - */ - function withdraw(uint256 assets, address receiver, address owner) public virtual override returns (uint256) { + /** @dev See {IERC4262-withdraw} */ + function withdraw( + uint256 assets, + address receiver, + address owner + ) public virtual override returns (uint256) { require(assets <= maxWithdraw(owner), "ERC4626: withdraw more then max"); address caller = _msgSender(); @@ -174,10 +151,12 @@ abstract contract ERC4626 is ERC20, IERC4626 { return shares; } - /** - * @dev See {IERC4262-redeem} - */ - function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256) { + /** @dev See {IERC4262-redeem} */ + function redeem( + uint256 shares, + address receiver, + address owner + ) public virtual override returns (uint256) { require(shares <= maxRedeem(owner), "ERC4626: redeem more then max"); address caller = _msgSender(); @@ -199,7 +178,11 @@ abstract contract ERC4626 is ERC20, IERC4626 { // Included here, since this method was not yet present in // the version of Open Zeppelin ERC20 code we use. - function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { + function _spendAllowance( + address owner, + address spender, + uint256 amount + ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); @@ -208,4 +191,4 @@ abstract contract ERC4626 is ERC20, IERC4626 { } } } -} +} \ No newline at end of file diff --git a/contracts/lib/openzeppelin/interfaces/IERC4626.sol b/contracts/lib/openzeppelin/interfaces/IERC4626.sol index f82b2dc200..506e9e2dcd 100644 --- a/contracts/lib/openzeppelin/interfaces/IERC4626.sol +++ b/contracts/lib/openzeppelin/interfaces/IERC4626.sol @@ -2,14 +2,18 @@ pragma solidity ^0.8.0; -import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IERC4626 is IERC20, IERC20Metadata { event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares); event Withdraw( - address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares + address indexed caller, + address indexed receiver, + address indexed owner, + uint256 assets, + uint256 shares ); /** @@ -176,7 +180,11 @@ interface IERC4626 is IERC20, IERC20Metadata { * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ - function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares); + function withdraw( + uint256 assets, + address receiver, + address owner + ) external returns (uint256 shares); /** * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, @@ -217,5 +225,9 @@ interface IERC4626 is IERC20, IERC20Metadata { * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ - function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets); -} + function redeem( + uint256 shares, + address receiver, + address owner + ) external returns (uint256 assets); +} \ No newline at end of file