diff --git a/contracts/protocol-viewers/StreamingFeeModuleViewer.sol b/contracts/protocol-viewers/StreamingFeeModuleViewer.sol index b23a59553..ecb04af20 100644 --- a/contracts/protocol-viewers/StreamingFeeModuleViewer.sol +++ b/contracts/protocol-viewers/StreamingFeeModuleViewer.sol @@ -21,7 +21,7 @@ pragma experimental "ABIEncoderV2"; import { ISetToken } from "../interfaces/ISetToken.sol"; import { IStreamingFeeModule } from "../interfaces/IStreamingFeeModule.sol"; -import { StreamingFeeModule } from "../protocol/modules/StreamingFeeModule.sol"; +import { StreamingFeeModule } from "../protocol/modules/v1/StreamingFeeModule.sol"; /** diff --git a/contracts/protocol/modules/AaveLeverageModule.sol b/contracts/protocol/modules/v1/AaveLeverageModule.sol similarity index 95% rename from contracts/protocol/modules/AaveLeverageModule.sol rename to contracts/protocol/modules/v1/AaveLeverageModule.sol index 80d72c246..a4799d518 100644 --- a/contracts/protocol/modules/AaveLeverageModule.sol +++ b/contracts/protocol/modules/v1/AaveLeverageModule.sol @@ -23,23 +23,23 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; -import { AaveV2 } from "../integration/lib/AaveV2.sol"; -import { IAToken } from "../../interfaces/external/aave-v2/IAToken.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IDebtIssuanceModule } from "../../interfaces/IDebtIssuanceModule.sol"; -import { IExchangeAdapter } from "../../interfaces/IExchangeAdapter.sol"; -import { ILendingPool } from "../../interfaces/external/aave-v2/ILendingPool.sol"; -import { ILendingPoolAddressesProvider } from "../../interfaces/external/aave-v2/ILendingPoolAddressesProvider.sol"; -import { IModuleIssuanceHook } from "../../interfaces/IModuleIssuanceHook.sol"; -import { IProtocolDataProvider } from "../../interfaces/external/aave-v2/IProtocolDataProvider.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IVariableDebtToken } from "../../interfaces/external/aave-v2/IVariableDebtToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; +import { AaveV2 } from "../../integration/lib/AaveV2.sol"; +import { IAToken } from "../../../interfaces/external/aave-v2/IAToken.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IDebtIssuanceModule } from "../../../interfaces/IDebtIssuanceModule.sol"; +import { IExchangeAdapter } from "../../../interfaces/IExchangeAdapter.sol"; +import { ILendingPool } from "../../../interfaces/external/aave-v2/ILendingPool.sol"; +import { ILendingPoolAddressesProvider } from "../../../interfaces/external/aave-v2/ILendingPoolAddressesProvider.sol"; +import { IModuleIssuanceHook } from "../../../interfaces/IModuleIssuanceHook.sol"; +import { IProtocolDataProvider } from "../../../interfaces/external/aave-v2/IProtocolDataProvider.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IVariableDebtToken } from "../../../interfaces/external/aave-v2/IVariableDebtToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; /** * @title AaveLeverageModule - * @author Set Protocol - * @notice Smart contract that enables leverage trading using Aave as the lending protocol. + * @author Set Protocol + * @notice Smart contract that enables leverage trading using Aave as the lending protocol. * @dev Do not use this module in conjunction with other debt modules that allow Aave debt positions as it could lead to double counting of * debt when borrowed assets are the same. */ @@ -48,7 +48,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu /* ============ Structs ============ */ - struct EnabledAssets { + struct EnabledAssets { address[] collateralAssets; // Array of enabled underlying collateral assets for a SetToken address[] borrowAssets; // Array of enabled underlying borrow assets for a SetToken } @@ -69,7 +69,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu IAToken aToken; // Reserve's aToken instance IVariableDebtToken variableDebtToken; // Reserve's variable debt token instance } - + /* ============ Events ============ */ /** @@ -135,19 +135,19 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu bool indexed _added, IERC20[] _assets ); - + /** * @dev Emitted when `underlyingToReserveTokensMappings` is updated * @param _underlying Address of the underlying asset * @param _aToken Updated aave reserve aToken - * @param _variableDebtToken Updated aave reserve variable debt token + * @param _variableDebtToken Updated aave reserve variable debt token */ event ReserveTokensUpdated( IERC20 indexed _underlying, IAToken indexed _aToken, IVariableDebtToken indexed _variableDebtToken ); - + /** * @dev Emitted on updateAllowedSetToken() * @param _setToken SetToken being whose allowance to initialize this module is being updated @@ -163,14 +163,14 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu * @param _anySetAllowed true if any set is allowed to initialize this module, false otherwise */ event AnySetAllowedUpdated( - bool indexed _anySetAllowed + bool indexed _anySetAllowed ); /* ============ Constants ============ */ // This module only supports borrowing in variable rate mode from Aave which is represented by 2 uint256 constant internal BORROW_RATE_MODE = 2; - + // String identifying the DebtIssuanceModule in the IntegrationRegistry. Note: Governance must add DefaultIssuanceModule as // the string as the integration name string constant internal DEFAULT_ISSUANCE_MODULE_NAME = "DefaultIssuanceModule"; @@ -180,23 +180,23 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu /* ============ State Variables ============ */ - // Mapping to efficiently fetch reserve token addresses. Tracking Aave reserve token addresses and updating them + // Mapping to efficiently fetch reserve token addresses. Tracking Aave reserve token addresses and updating them // upon requirement is more efficient than fetching them each time from Aave. // Note: For an underlying asset to be enabled as collateral/borrow asset on SetToken, it must be added to this mapping first. mapping(IERC20 => ReserveTokens) public underlyingToReserveTokens; // Used to fetch reserves and user data from AaveV2 IProtocolDataProvider public immutable protocolDataProvider; - + // Used to fetch lendingPool address. This contract is immutable and its address will never change. ILendingPoolAddressesProvider public immutable lendingPoolAddressesProvider; - + // Mapping to efficiently check if collateral asset is enabled in SetToken mapping(ISetToken => mapping(IERC20 => bool)) public collateralAssetEnabled; - + // Mapping to efficiently check if a borrow asset is enabled in SetToken mapping(ISetToken => mapping(IERC20 => bool)) public borrowAssetEnabled; - + // Internal mapping of enabled collateral and borrow tokens for syncing positions mapping(ISetToken => EnabledAssets) internal enabledAssets; @@ -205,7 +205,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu // Boolean that returns if any SetToken can initialize this module. If false, then subject to allow list. Updateable by governance. bool public anySetAllowed; - + /* ============ Constructor ============ */ /** @@ -226,16 +226,16 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu _lendingPoolAddressesProvider.getAddress(0x0100000000000000000000000000000000000000000000000000000000000000) ); protocolDataProvider = _protocolDataProvider; - + IProtocolDataProvider.TokenData[] memory reserveTokens = _protocolDataProvider.getAllReservesTokens(); for(uint256 i = 0; i < reserveTokens.length; i++) { (address aToken, , address variableDebtToken) = _protocolDataProvider.getReserveTokensAddresses(reserveTokens[i].tokenAddress); underlyingToReserveTokens[IERC20(reserveTokens[i].tokenAddress)] = ReserveTokens(IAToken(aToken), IVariableDebtToken(variableDebtToken)); } } - + /* ============ External Functions ============ */ - + /** * @dev MANAGER ONLY: Increases leverage for a given collateral position using an enabled borrow asset. * Borrows _borrowAsset from Aave. Performs a DEX trade, exchanging the _borrowAsset for _collateralAsset. @@ -262,7 +262,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu nonReentrant onlyManagerAndValidSet(_setToken) { - // For levering up, send quantity is derived from borrow asset and receive quantity is derived from + // For levering up, send quantity is derived from borrow asset and receive quantity is derived from // collateral asset ActionInfo memory leverInfo = _createAndValidateActionInfo( _setToken, @@ -296,7 +296,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu protocolFee ); } - + /** * @dev MANAGER ONLY: Decrease leverage for a given collateral position using an enabled borrow asset. * Withdraws _collateralAsset from Aave. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset. @@ -323,7 +323,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu nonReentrant onlyManagerAndValidSet(_setToken) { - // Note: for delevering, send quantity is derived from collateral asset and receive quantity is derived from + // Note: for delevering, send quantity is derived from collateral asset and receive quantity is derived from // repay asset ActionInfo memory deleverInfo = _createAndValidateActionInfo( _setToken, @@ -358,9 +358,9 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu ); } - /** @dev MANAGER ONLY: Pays down the borrow asset to 0 selling off a given amount of collateral asset. - * Withdraws _collateralAsset from Aave. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset. - * Minimum receive amount for the DEX trade is set to the current variable debt balance of the borrow asset. + /** @dev MANAGER ONLY: Pays down the borrow asset to 0 selling off a given amount of collateral asset. + * Withdraws _collateralAsset from Aave. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset. + * Minimum receive amount for the DEX trade is set to the current variable debt balance of the borrow asset. * Repays received _repayAsset to Aave which burns corresponding debt tokens. Any extra received borrow asset is . * updated as equity. No protocol fee is charged. * Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset. @@ -370,7 +370,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu * @param _repayAsset Address of underlying asset being repaid * @param _redeemQuantityUnits Quantity of collateral asset to delever in position units * @param _tradeAdapterName Name of trade adapter - * @param _tradeData Arbitrary data for trade + * @param _tradeData Arbitrary data for trade * @return uint256 Notional repay quantity */ function deleverToZeroBorrowBalance( @@ -388,7 +388,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu { uint256 setTotalSupply = _setToken.totalSupply(); uint256 notionalRedeemQuantity = _redeemQuantityUnits.preciseMul(setTotalSupply); - + require(borrowAssetEnabled[_setToken][_repayAsset], "Borrow not enabled"); uint256 notionalRepayQuantity = underlyingToReserveTokens[_repayAsset].variableDebtToken.balanceOf(address(_setToken)); require(notionalRepayQuantity > 0, "Borrow balance is zero"); @@ -426,7 +426,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu } /** - * @dev CALLABLE BY ANYBODY: Sync Set positions with ALL enabled Aave collateral and borrow positions. + * @dev CALLABLE BY ANYBODY: Sync Set positions with ALL enabled Aave collateral and borrow positions. * For collateral assets, update aToken default position. For borrow assets, update external borrow position. * - Collateral assets may come out of sync when interest is accrued or a position is liquidated * - Borrow assets may come out of sync when interest is accrued or position is liquidated and borrow is repaid @@ -437,13 +437,13 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu function sync(ISetToken _setToken) public nonReentrant onlyValidAndInitializedSet(_setToken) { uint256 setTotalSupply = _setToken.totalSupply(); - // Only sync positions when Set supply is not 0. Without this check, if sync is called by someone before the + // Only sync positions when Set supply is not 0. Without this check, if sync is called by someone before the // first issuance, then editDefaultPosition would remove the default positions from the SetToken if (setTotalSupply > 0) { address[] memory collateralAssets = enabledAssets[_setToken].collateralAssets; for(uint256 i = 0; i < collateralAssets.length; i++) { IAToken aToken = underlyingToReserveTokens[IERC20(collateralAssets[i])].aToken; - + uint256 previousPositionUnit = _setToken.getDefaultPositionRealUnit(address(aToken)).toUint256(); uint256 newPositionUnit = _getCollateralPosition(_setToken, aToken, setTotalSupply); @@ -452,7 +452,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu _updateCollateralPosition(_setToken, aToken, newPositionUnit); } } - + address[] memory borrowAssets = enabledAssets[_setToken].borrowAssets; for(uint256 i = 0; i < borrowAssets.length; i++) { IERC20 borrowAsset = IERC20(borrowAssets[i]); @@ -500,7 +500,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu for(uint256 i = 0; i < modules.length; i++) { try IDebtIssuanceModule(modules[i]).registerToIssuanceModule(_setToken) {} catch {} } - + // _collateralAssets and _borrowAssets arrays are validated in their respective internal functions _addCollateralAssets(_setToken, _collateralAssets); _addBorrowAssets(_setToken, _borrowAssets); @@ -508,7 +508,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu /** * @dev MANAGER ONLY: Removes this module from the SetToken, via call by the SetToken. Any deposited collateral assets - * are disabled to be used as collateral on Aave. Aave Settings and manager enabled assets state is deleted. + * are disabled to be used as collateral on Aave. Aave Settings and manager enabled assets state is deleted. * Note: Function will revert is there is any debt remaining on Aave */ function removeModule() external override onlyValidAndInitializedSet(ISetToken(msg.sender)) { @@ -521,7 +521,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu for(uint256 i = 0; i < borrowAssets.length; i++) { IERC20 borrowAsset = IERC20(borrowAssets[i]); require(underlyingToReserveTokens[borrowAsset].variableDebtToken.balanceOf(address(setToken)) == 0, "Variable debt remaining"); - + delete borrowAssetEnabled[setToken][borrowAsset]; } @@ -532,7 +532,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu delete collateralAssetEnabled[setToken][collateralAsset]; } - + delete enabledAssets[setToken]; // Try if unregister exists on any of the modules @@ -543,7 +543,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu } /** - * @dev MANAGER ONLY: Add registration of this module on the debt issuance module for the SetToken. + * @dev MANAGER ONLY: Add registration of this module on the debt issuance module for the SetToken. * Note: if the debt issuance module is not added to SetToken before this module is initialized, then this function * needs to be called if the debt issuance module is later added and initialized to prevent state inconsistencies * @param _setToken Instance of the SetToken @@ -567,14 +567,14 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu // An active reserve is an alias for a valid reserve on Aave. (,,,,,,,, bool isActive,) = protocolDataProvider.getReserveConfigurationData(address(_underlying)); require(isActive, "Invalid aave reserve"); - + _addUnderlyingToReserveTokensMapping(_underlying); } /** * @dev MANAGER ONLY: Add collateral assets. aTokens corresponding to collateral assets are tracked for syncing positions. * Note: Reverts with "Collateral already enabled" if there are duplicate assets in the passed _newCollateralAssets array. - * + * * NOTE: ALL ADDED COLLATERAL ASSETS CAN BE ADDED AS A POSITION ON THE SET TOKEN WITHOUT MANAGER'S EXPLICIT PERMISSION. * UNWANTED EXTRA POSITIONS CAN BREAK EXTERNAL LOGIC, INCREASE COST OF MINT/REDEEM OF SET TOKEN, AMONG OTHER POTENTIAL UNINTENDED CONSEQUENCES. * SO, PLEASE ADD ONLY THOSE COLLATERAL ASSETS WHOSE CORRESPONDING aTOKENS ARE NEEDED AS DEFAULT POSITIONS ON THE SET TOKEN. @@ -585,20 +585,20 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu function addCollateralAssets(ISetToken _setToken, IERC20[] memory _newCollateralAssets) external onlyManagerAndValidSet(_setToken) { _addCollateralAssets(_setToken, _newCollateralAssets); } - + /** * @dev MANAGER ONLY: Remove collateral assets. Disable deposited assets to be used as collateral on Aave market. * @param _setToken Instance of the SetToken * @param _collateralAssets Addresses of collateral underlying assets to remove */ function removeCollateralAssets(ISetToken _setToken, IERC20[] memory _collateralAssets) external onlyManagerAndValidSet(_setToken) { - + for(uint256 i = 0; i < _collateralAssets.length; i++) { IERC20 collateralAsset = _collateralAssets[i]; require(collateralAssetEnabled[_setToken][collateralAsset], "Collateral not enabled"); - + _updateUseReserveAsCollateral(_setToken, collateralAsset, false); - + delete collateralAssetEnabled[_setToken][collateralAsset]; enabledAssets[_setToken].collateralAssets.removeStorage(address(collateralAsset)); } @@ -622,13 +622,13 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu * @param _borrowAssets Addresses of borrow underlying assets to remove */ function removeBorrowAssets(ISetToken _setToken, IERC20[] memory _borrowAssets) external onlyManagerAndValidSet(_setToken) { - + for(uint256 i = 0; i < _borrowAssets.length; i++) { IERC20 borrowAsset = _borrowAssets[i]; - + require(borrowAssetEnabled[_setToken][borrowAsset], "Borrow not enabled"); require(underlyingToReserveTokens[borrowAsset].variableDebtToken.balanceOf(address(_setToken)) == 0, "Variable debt remaining"); - + delete borrowAssetEnabled[_setToken][borrowAsset]; enabledAssets[_setToken].borrowAssets.removeStorage(address(borrowAsset)); } @@ -673,7 +673,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu } /** - * @dev MODULE ONLY: Hook called prior to looping through each component on issuance. Invokes borrow in order for + * @dev MODULE ONLY: Hook called prior to looping through each component on issuance. Invokes borrow in order for * module to return debt to issuer. Only callable by valid module. * @param _setToken Instance of the SetToken * @param _setTokenQuantity Quantity of SetToken @@ -693,7 +693,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu } /** - * @dev MODULE ONLY: Hook called prior to looping through each component on redemption. Invokes repay after + * @dev MODULE ONLY: Hook called prior to looping through each component on redemption. Invokes repay after * the issuance module transfers debt from the issuer. Only callable by valid module. * @param _setToken Instance of the SetToken * @param _setTokenQuantity Quantity of SetToken @@ -711,7 +711,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu _repayBorrowForHook(_setToken, _component, notionalDebt); } } - + /* ============ External Getter Functions ============ */ /** @@ -727,7 +727,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu } /* ============ Internal Functions ============ */ - + /** * @dev Invoke deposit from SetToken using AaveV2 library. Mints aTokens for SetToken. */ @@ -773,7 +773,7 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu function _borrowForHook(ISetToken _setToken, IERC20 _asset, uint256 _notionalQuantity) internal { _borrow(_setToken, ILendingPool(lendingPoolAddressesProvider.getLendingPool()), _asset, _notionalQuantity); } - + /** * @dev Invokes approvals, gets trade call data from exchange adapter and invokes trade from SetToken * @return uint256 The quantity of tokens received post-trade @@ -821,12 +821,12 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu } /** - * @dev Calculates protocol fee on module and pays protocol fee from SetToken + * @dev Calculates protocol fee on module and pays protocol fee from SetToken * @return uint256 Total protocol fee paid */ function _accrueProtocolFee(ISetToken _setToken, IERC20 _receiveToken, uint256 _exchangedQuantity) internal returns(uint256) { uint256 protocolFeeTotal = getModuleFee(PROTOCOL_TRADE_FEE_INDEX, _exchangedQuantity); - + payProtocolFeeFromSetToken(_setToken, address(_receiveToken), protocolFeeTotal); return protocolFeeTotal; @@ -875,13 +875,13 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu _updateLeverPositions(_actionInfo, _repayAsset); } - + /** * @dev Updates default position unit for given aToken on SetToken */ function _updateCollateralPosition(ISetToken _setToken, IAToken _aToken, uint256 _newPositionUnit) internal { _setToken.editDefaultPosition(address(_aToken), _newPositionUnit); - } + } /** * @dev Updates external position unit for given borrow asset on SetToken @@ -920,9 +920,9 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu totalSupply ); } - + /** - * @dev Construct the ActionInfo struct for lever and delever accepting notional units + * @dev Construct the ActionInfo struct for lever and delever accepting notional units * @return ActionInfo Instance of constructed ActionInfo struct */ function _createAndValidateActionInfoNotional( @@ -974,10 +974,10 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu function _addCollateralAssets(ISetToken _setToken, IERC20[] memory _newCollateralAssets) internal { for(uint256 i = 0; i < _newCollateralAssets.length; i++) { IERC20 collateralAsset = _newCollateralAssets[i]; - + _validateNewCollateralAsset(_setToken, collateralAsset); _updateUseReserveAsCollateral(_setToken, collateralAsset, true); - + collateralAssetEnabled[_setToken][collateralAsset] = true; enabledAssets[_setToken].collateralAssets.push(address(collateralAsset)); } @@ -991,9 +991,9 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu function _addBorrowAssets(ISetToken _setToken, IERC20[] memory _newBorrowAssets) internal { for(uint256 i = 0; i < _newBorrowAssets.length; i++) { IERC20 borrowAsset = _newBorrowAssets[i]; - + _validateNewBorrowAsset(_setToken, borrowAsset); - + borrowAssetEnabled[_setToken][borrowAsset] = true; enabledAssets[_setToken].borrowAssets.push(address(borrowAsset)); } @@ -1005,22 +1005,22 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu */ function _updateUseReserveAsCollateral(ISetToken _setToken, IERC20 _asset, bool _useAsCollateral) internal { /* - Note: Aave ENABLES an asset to be used as collateral by `to` address in an `aToken.transfer(to, amount)` call provided + Note: Aave ENABLES an asset to be used as collateral by `to` address in an `aToken.transfer(to, amount)` call provided 1. msg.sender (from address) isn't the same as `to` address - 2. `to` address had zero aToken balance before the transfer + 2. `to` address had zero aToken balance before the transfer 3. transfer `amount` is greater than 0 - - Note: Aave DISABLES an asset to be used as collateral by `msg.sender`in an `aToken.transfer(to, amount)` call provided + + Note: Aave DISABLES an asset to be used as collateral by `msg.sender`in an `aToken.transfer(to, amount)` call provided 1. msg.sender (from address) isn't the same as `to` address 2. msg.sender has zero balance after the transfer Different states of the SetToken and what this function does in those states: Case 1: Manager adds collateral asset to SetToken before first issuance - - Since aToken.balanceOf(setToken) == 0, we do not call `setToken.invokeUserUseReserveAsCollateral` because Aave - requires aToken balance to be greater than 0 before enabling/disabling the underlying asset to be used as collateral + - Since aToken.balanceOf(setToken) == 0, we do not call `setToken.invokeUserUseReserveAsCollateral` because Aave + requires aToken balance to be greater than 0 before enabling/disabling the underlying asset to be used as collateral on Aave markets. - + Case 2: First issuance of the SetToken - SetToken was initialized with aToken as default position - DebtIssuanceModule reads the default position and transfers corresponding aToken from the issuer to the SetToken @@ -1028,15 +1028,15 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu - Manager calls lever() and the aToken is used as collateral to borrow other assets Case 3: Manager removes collateral asset from the SetToken - - Disable asset to be used as collateral on SetToken by calling `setToken.invokeSetUserUseReserveAsCollateral` with + - Disable asset to be used as collateral on SetToken by calling `setToken.invokeSetUserUseReserveAsCollateral` with useAsCollateral equals false - Note: If health factor goes below 1 by removing the collateral asset, then Aave reverts on the above call, thus whole transaction reverts, and manager can't remove corresponding collateral asset - + Case 4: Manager adds collateral asset after removing it - - If aToken.balanceOf(setToken) > 0, we call `setToken.invokeUserUseReserveAsCollateral` and the corresponding aToken + - If aToken.balanceOf(setToken) > 0, we call `setToken.invokeUserUseReserveAsCollateral` and the corresponding aToken is re-enabled as collateral on Aave - + Case 5: On redemption/delever/liquidated and aToken balance becomes zero - Aave disables aToken to be used as collateral by SetToken @@ -1087,13 +1087,13 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu */ function _validateNewCollateralAsset(ISetToken _setToken, IERC20 _asset) internal view { require(!collateralAssetEnabled[_setToken][_asset], "Collateral already enabled"); - + (address aToken, , ) = protocolDataProvider.getReserveTokensAddresses(address(_asset)); require(address(underlyingToReserveTokens[_asset].aToken) == aToken, "Invalid aToken address"); - + ( , , , , , bool usageAsCollateralEnabled, , , bool isActive, bool isFrozen) = protocolDataProvider.getReserveConfigurationData(address(_asset)); // An active reserve is an alias for a valid reserve on Aave. - // We are checking for the availability of the reserve directly on Aave rather than checking our internal `underlyingToReserveTokens` mappings, + // We are checking for the availability of the reserve directly on Aave rather than checking our internal `underlyingToReserveTokens` mappings, // because our mappings can be out-of-date if a new reserve is added to Aave require(isActive, "Invalid aave reserve"); // A frozen reserve doesn't allow any new deposit, borrow or rate swap but allows repayments, liquidations and withdrawals @@ -1106,10 +1106,10 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu */ function _validateNewBorrowAsset(ISetToken _setToken, IERC20 _asset) internal view { require(!borrowAssetEnabled[_setToken][_asset], "Borrow already enabled"); - + ( , , address variableDebtToken) = protocolDataProvider.getReserveTokensAddresses(address(_asset)); require(address(underlyingToReserveTokens[_asset].variableDebtToken) == variableDebtToken, "Invalid variable debt token address"); - + (, , , , , , bool borrowingEnabled, , bool isActive, bool isFrozen) = protocolDataProvider.getReserveConfigurationData(address(_asset)); require(isActive, "Invalid aave reserve"); require(!isFrozen, "Frozen aave reserve"); @@ -1119,13 +1119,13 @@ contract AaveLeverageModule is ModuleBase, ReentrancyGuard, Ownable, IModuleIssu /** * @dev Reads aToken balance and calculates default position unit for given collateral aToken and SetToken * - * @return uint256 default collateral position unit + * @return uint256 default collateral position unit */ function _getCollateralPosition(ISetToken _setToken, IAToken _aToken, uint256 _setTotalSupply) internal view returns (uint256) { uint256 collateralNotionalBalance = _aToken.balanceOf(address(_setToken)); return collateralNotionalBalance.preciseDiv(_setTotalSupply); } - + /** * @dev Reads variableDebtToken balance and calculates external position unit for given borrow asset and SetToken * diff --git a/contracts/protocol/modules/AirdropModule.sol b/contracts/protocol/modules/v1/AirdropModule.sol similarity index 96% rename from contracts/protocol/modules/AirdropModule.sol rename to contracts/protocol/modules/v1/AirdropModule.sol index 4d6e7a3fd..8cacbcac2 100644 --- a/contracts/protocol/modules/AirdropModule.sol +++ b/contracts/protocol/modules/v1/AirdropModule.sol @@ -24,13 +24,13 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** @@ -51,7 +51,7 @@ contract AirdropModule is ModuleBase, ReentrancyGuard { using Position for ISetToken; /* ============ Structs ============ */ - + struct AirdropSettings { address[] airdrops; // Array of tokens manager is allowing to be absorbed address feeRecipient; // Address airdrop fees are sent to @@ -150,7 +150,7 @@ contract AirdropModule is ModuleBase, ReentrancyGuard { * SET MANAGER ONLY. Removes tokens from list to be absorbed. * * @param _setToken Address of SetToken - * @param _airdrop Component to remove from airdrop list + * @param _airdrop Component to remove from airdrop list */ function removeAirdrop(ISetToken _setToken, IERC20 _airdrop) external onlyManagerAndValidSet(_setToken) { require(isAirdropToken(_setToken, _airdrop), "Token not added."); @@ -307,7 +307,7 @@ contract AirdropModule is ModuleBase, ReentrancyGuard { if (amountAirdropped > 0) { (uint256 managerTake, uint256 protocolTake, uint256 totalFees) = _handleFees(_setToken, _token, amountAirdropped); - + uint256 newUnit = _getPostAirdropUnit(_setToken, preFeeTokenBalance, totalFees); _setToken.editDefaultPosition(address(_token), newUnit); @@ -338,12 +338,12 @@ contract AirdropModule is ModuleBase, ReentrancyGuard { if (airdropFee > 0) { totalFees = _amountAirdropped.preciseMul(airdropFee); - + protocolTake = getModuleFee(AIRDROP_MODULE_PROTOCOL_FEE_INDEX, totalFees); netManagerTake = totalFees.sub(protocolTake); _setToken.strictInvokeTransfer(address(_component), airdropSettings[_setToken].feeRecipient, netManagerTake); - + payProtocolFeeFromSetToken(_setToken, address(_component), protocolTake); return (netManagerTake, protocolTake, totalFees); @@ -354,7 +354,7 @@ contract AirdropModule is ModuleBase, ReentrancyGuard { /** * Retrieve new unit, which is the current balance less fees paid divided by total supply - */ + */ function _getPostAirdropUnit( ISetToken _setToken, uint256 _totalComponentBalance, @@ -370,8 +370,8 @@ contract AirdropModule is ModuleBase, ReentrancyGuard { /** * If absorption is confined to the manager, manager must be caller - */ + */ function _isValidCaller(ISetToken _setToken) internal view returns(bool) { - return airdropSettings[_setToken].anyoneAbsorb || isSetManager(_setToken, msg.sender); + return airdropSettings[_setToken].anyoneAbsorb || isSetManager(_setToken, msg.sender); } } \ No newline at end of file diff --git a/contracts/protocol/modules/AmmModule.sol b/contracts/protocol/modules/v1/AmmModule.sol similarity index 95% rename from contracts/protocol/modules/AmmModule.sol rename to contracts/protocol/modules/v1/AmmModule.sol index d8a943d65..2d202c848 100644 --- a/contracts/protocol/modules/AmmModule.sol +++ b/contracts/protocol/modules/v1/AmmModule.sol @@ -25,14 +25,14 @@ import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IIntegrationRegistry } from "../../interfaces/IIntegrationRegistry.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IAmmAdapter } from "../../interfaces/IAmmAdapter.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IIntegrationRegistry } from "../../../interfaces/IIntegrationRegistry.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IAmmAdapter } from "../../../interfaces/IAmmAdapter.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** @@ -40,7 +40,7 @@ import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; * @author Set Protocol * * A smart contract module that enables joining and exiting of AMM Pools using multiple or a single ERC20s. - * Examples of intended protocols include Curve, Uniswap, and Balancer. + * Examples of intended protocols include Curve, Uniswap, and Balancer. */ contract AmmModule is ModuleBase, ReentrancyGuard { using SafeCast for int256; @@ -61,7 +61,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard { address[] _components, int256[] _componentBalancesDelta // Change in SetToken component token balances ); - + event LiquidityRemoved( ISetToken indexed _setToken, address indexed _ammPool, @@ -80,11 +80,11 @@ contract AmmModule is ModuleBase, ReentrancyGuard { address liquidityToken; // Address of the AMM pool token uint256 preActionLiquidityTokenBalance; // Balance of liquidity token before add/remove liquidity action uint256[] preActionComponentBalances; // Balance of components before add/remove liquidity action - uint256 liquidityQuantity; // When adding liquidity, minimum quantity of liquidity required. + uint256 liquidityQuantity; // When adding liquidity, minimum quantity of liquidity required. // When removing liquidity, quantity to dispose of uint256[] totalNotionalComponents; // When adding liquidity, maximum components provided // When removing liquidity, minimum components to receive - uint256[] componentUnits; // List of inputted component real units + uint256[] componentUnits; // List of inputted component real units address[] components; // List of component addresses for providing/removing liquidity } @@ -138,11 +138,11 @@ contract AmmModule is ModuleBase, ReentrancyGuard { emit LiquidityAdded(_setToken, _ammPool, liquidityTokenDelta, _components, componentsDelta); } - + /** - * SET MANAGER ONLY. Adds liquidity to an AMM pool for a specified AMM using a single asset if supported. + * SET MANAGER ONLY. Adds liquidity to an AMM pool for a specified AMM using a single asset if supported. * Differs from addLiquidity as it will opt to use the AMMs single asset liquidity function if it exists - * User specifies what component and component quantity to contribute and the minimum number of + * User specifies what component and component quantity to contribute and the minimum number of * liquidity pool tokens to receive. * * @param _setToken Address of SetToken @@ -193,7 +193,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard { } /** - * SET MANAGER ONLY. Removes liquidity from an AMM pool for a specified AMM. User specifies the exact number of + * SET MANAGER ONLY. Removes liquidity from an AMM pool for a specified AMM. User specifies the exact number of * liquidity pool tokens to provide and the components and minimum quantity of component units to receive * * @param _setToken Address of SetToken @@ -240,7 +240,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard { liquidityTokenDelta, _components, componentsDelta - ); + ); } /** @@ -262,7 +262,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard { uint256 _poolTokenPositionUnits, address _component, uint256 _minComponentUnitsReceived - ) + ) external nonReentrant onlyManagerAndValidSet(_setToken) @@ -339,14 +339,14 @@ contract AmmModule is ModuleBase, ReentrancyGuard { actionInfo.preActionComponentBalances = _getTokenBalances(address(_setToken), _components); actionInfo.liquidityQuantity = actionInfo.totalSupply.getDefaultTotalNotional(_poolTokenInPositionUnit); - + actionInfo.totalNotionalComponents = _getTotalNotionalComponents(_setToken, _componentUnits); actionInfo.componentUnits = _componentUnits; - - actionInfo.components = _components; - return actionInfo; + actionInfo.components = _components; + + return actionInfo; } function _getActionInfoSingleAsset( @@ -426,7 +426,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard { ); } } - + function _executeAddLiquidity(ActionInfo memory _actionInfo) internal { ( address targetAmm, uint256 callValue, bytes memory methodData @@ -456,9 +456,9 @@ contract AmmModule is ModuleBase, ReentrancyGuard { _executeComponentApprovals(_actionInfo); - _actionInfo.setToken.invoke(targetAmm, callValue, methodData); + _actionInfo.setToken.invoke(targetAmm, callValue, methodData); } - + function _executeRemoveLiquidity(ActionInfo memory _actionInfo) internal { ( address targetAmm, uint256 callValue, bytes memory methodData @@ -476,7 +476,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard { _actionInfo.liquidityQuantity ); - _actionInfo.setToken.invoke(targetAmm, callValue, methodData); + _actionInfo.setToken.invoke(targetAmm, callValue, methodData); } function _executeRemoveLiquiditySingleAsset(ActionInfo memory _actionInfo) internal { @@ -496,9 +496,9 @@ contract AmmModule is ModuleBase, ReentrancyGuard { _actionInfo.liquidityQuantity ); - _actionInfo.setToken.invoke(targetAmm, callValue, methodData); + _actionInfo.setToken.invoke(targetAmm, callValue, methodData); } - + function _validateMinimumLiquidityReceived(ActionInfo memory _actionInfo) internal view { uint256 liquidityTokenBalance = IERC20(_actionInfo.liquidityToken).balanceOf(address(_actionInfo.setToken)); diff --git a/contracts/protocol/modules/BasicIssuanceModule.sol b/contracts/protocol/modules/v1/BasicIssuanceModule.sol similarity index 95% rename from contracts/protocol/modules/BasicIssuanceModule.sol rename to contracts/protocol/modules/v1/BasicIssuanceModule.sol index 57707c053..2c5d9eb06 100644 --- a/contracts/protocol/modules/BasicIssuanceModule.sol +++ b/contracts/protocol/modules/v1/BasicIssuanceModule.sol @@ -20,13 +20,13 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IManagerIssuanceHook } from "../../interfaces/IManagerIssuanceHook.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IManagerIssuanceHook } from "../../../interfaces/IManagerIssuanceHook.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** * @title BasicIssuanceModule @@ -87,7 +87,7 @@ contract BasicIssuanceModule is ModuleBase, ReentrancyGuard { ISetToken _setToken, uint256 _quantity, address _to - ) + ) external nonReentrant onlyValidAndInitializedSet(_setToken) diff --git a/contracts/protocol/modules/ClaimModule.sol b/contracts/protocol/modules/v1/ClaimModule.sol similarity index 97% rename from contracts/protocol/modules/ClaimModule.sol rename to contracts/protocol/modules/v1/ClaimModule.sol index 67dbf5134..51e8fc5ef 100644 --- a/contracts/protocol/modules/ClaimModule.sol +++ b/contracts/protocol/modules/v1/ClaimModule.sol @@ -17,11 +17,11 @@ pragma experimental "ABIEncoderV2"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { IClaimAdapter } from "../../interfaces/IClaimAdapter.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { IClaimAdapter } from "../../../interfaces/IClaimAdapter.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; /** @@ -29,13 +29,13 @@ import { ModuleBase } from "../lib/ModuleBase.sol"; * @author Set Protocol * * Module that enables managers to claim tokens from external protocols given to the Set as part of participating in - * incentivized activities of other protocols. The ClaimModule works in conjunction with ClaimAdapters, in which the + * incentivized activities of other protocols. The ClaimModule works in conjunction with ClaimAdapters, in which the * claimAdapterID / integrationNames are stored on the integration registry. - * + * * Design: * The ecosystem is coalescing around a few standards of how reward programs are created, using forks of popular * contracts such as Synthetix's Mintr. Thus, the Claim architecture reflects a more functional vs external-protocol - * approach where an adapter with common functionality can be used across protocols. + * approach where an adapter with common functionality can be used across protocols. * * Definitions: * Reward Pool: A reward pool is a contract associated with an external protocol's reward. Examples of reward pools @@ -232,7 +232,7 @@ contract ClaimModule is ModuleBase { _removeClaim(_setToken, _rewardPools[i], _integrationNames[i]); } } - + /** * SET MANAGER ONLY. Initializes this module to the SetToken. * @@ -278,11 +278,11 @@ contract ClaimModule is ModuleBase { } delete claimSettings[ISetToken(msg.sender)][setTokenPoolList[i]]; } - + for (uint256 i = 0; i < rewardPoolList[ISetToken(msg.sender)].length; i++) { address toRemove = rewardPoolList[ISetToken(msg.sender)][i]; rewardPoolStatus[ISetToken(msg.sender)][toRemove] = false; - + delete rewardPoolList[ISetToken(msg.sender)][i]; } delete rewardPoolList[ISetToken(msg.sender)]; @@ -439,7 +439,7 @@ contract ClaimModule is ModuleBase { } /** - * Internal version. Adds a new rewardPool to the list to perform claims for the SetToken indicating the list of claim + * Internal version. Adds a new rewardPool to the list to perform claims for the SetToken indicating the list of claim * integrations. Each claim integration is associated to an adapter that provides the functionality to claim the rewards * for a specific token. * @@ -464,7 +464,7 @@ contract ClaimModule is ModuleBase { /** * Validates and stores the adapter address used to claim rewards for the passed rewardPool. If no adapters - * left after removal then remove rewardPool from rewardPoolList and delete entry in claimSettings. + * left after removal then remove rewardPool from rewardPoolList and delete entry in claimSettings. * * @param _setToken Address of SetToken * @param _rewardPool Address of the rewardPool that identifies the contract governing claims @@ -484,7 +484,7 @@ contract ClaimModule is ModuleBase { } /** - * For batch functions validate arrays are of equal length and not empty. Return length of array for iteration. + * For batch functions validate arrays are of equal length and not empty. Return length of array for iteration. * * @param _rewardPools Addresses of the rewardPool that identifies the contract governing claims * @param _integrationNames IDs of claim module integration (mapping on integration registry) diff --git a/contracts/protocol/modules/CompoundLeverageModule.sol b/contracts/protocol/modules/v1/CompoundLeverageModule.sol similarity index 98% rename from contracts/protocol/modules/CompoundLeverageModule.sol rename to contracts/protocol/modules/v1/CompoundLeverageModule.sol index e86b23859..94c6cc4eb 100644 --- a/contracts/protocol/modules/CompoundLeverageModule.sol +++ b/contracts/protocol/modules/v1/CompoundLeverageModule.sol @@ -23,14 +23,14 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; -import { Compound } from "../integration/lib/Compound.sol"; -import { ICErc20 } from "../../interfaces/external/ICErc20.sol"; -import { IComptroller } from "../../interfaces/external/IComptroller.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IDebtIssuanceModule } from "../../interfaces/IDebtIssuanceModule.sol"; -import { IExchangeAdapter } from "../../interfaces/IExchangeAdapter.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; +import { Compound } from "../../integration/lib/Compound.sol"; +import { ICErc20 } from "../../../interfaces/external/ICErc20.sol"; +import { IComptroller } from "../../../interfaces/external/IComptroller.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IDebtIssuanceModule } from "../../../interfaces/IDebtIssuanceModule.sol"; +import { IExchangeAdapter } from "../../../interfaces/IExchangeAdapter.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; /** * @title CompoundLeverageModule diff --git a/contracts/protocol/modules/CustomOracleNAVIssuanceModule.sol b/contracts/protocol/modules/v1/CustomOracleNAVIssuanceModule.sol similarity index 98% rename from contracts/protocol/modules/CustomOracleNAVIssuanceModule.sol rename to contracts/protocol/modules/v1/CustomOracleNAVIssuanceModule.sol index 571dc2b57..0d202b333 100644 --- a/contracts/protocol/modules/CustomOracleNAVIssuanceModule.sol +++ b/contracts/protocol/modules/v1/CustomOracleNAVIssuanceModule.sol @@ -26,17 +26,17 @@ import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { ISetValuer } from "../../interfaces/ISetValuer.sol"; -import { INAVIssuanceHook } from "../../interfaces/INAVIssuanceHook.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IWETH } from "../../interfaces/external/IWETH.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; -import { ResourceIdentifier } from "../lib/ResourceIdentifier.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { ISetValuer } from "../../../interfaces/ISetValuer.sol"; +import { INAVIssuanceHook } from "../../../interfaces/INAVIssuanceHook.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IWETH } from "../../../interfaces/external/IWETH.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; +import { ResourceIdentifier } from "../../lib/ResourceIdentifier.sol"; /** * @title CustomOracleNavIssuanceModule diff --git a/contracts/protocol/modules/DebtIssuanceModule.sol b/contracts/protocol/modules/v1/DebtIssuanceModule.sol similarity index 97% rename from contracts/protocol/modules/DebtIssuanceModule.sol rename to contracts/protocol/modules/v1/DebtIssuanceModule.sol index 8cf1814b2..9f4d085b4 100644 --- a/contracts/protocol/modules/DebtIssuanceModule.sol +++ b/contracts/protocol/modules/v1/DebtIssuanceModule.sol @@ -25,15 +25,15 @@ import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IManagerIssuanceHook } from "../../interfaces/IManagerIssuanceHook.sol"; -import { IModuleIssuanceHook } from "../../interfaces/IModuleIssuanceHook.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IManagerIssuanceHook } from "../../../interfaces/IManagerIssuanceHook.sol"; +import { IModuleIssuanceHook } from "../../../interfaces/IModuleIssuanceHook.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** @@ -98,7 +98,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard { /* ============ External Functions ============ */ /** - * Deposits components to the SetToken, replicates any external module component positions and mints + * Deposits components to the SetToken, replicates any external module component positions and mints * the SetToken. If the token has a debt position all collateral will be transferred in first then debt * will be returned to the minting address. If specified, a fee will be charged on issuance. * @@ -167,7 +167,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard { address _to ) external - virtual + virtual nonReentrant onlyValidAndInitializedSet(_setToken) { @@ -365,7 +365,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard { IssuanceSettings memory setIssuanceSettings = issuanceSettings[_setToken]; uint256 protocolFeeSplit = controller.getModuleFee(address(this), ISSUANCE_MODULE_PROTOCOL_FEE_SPLIT_INDEX); uint256 totalFeeRate = _isIssue ? setIssuanceSettings.managerIssueFee : setIssuanceSettings.managerRedeemFee; - + uint256 totalFee = totalFeeRate.preciseMul(_quantity); protocolFee = totalFee.preciseMul(protocolFeeSplit); managerFee = totalFee.sub(protocolFee); @@ -512,7 +512,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard { address[] memory externalPositions = _setToken.getExternalPositionModules(component); if (externalPositions.length > 0) { - for (uint256 j = 0; j < externalPositions.length; j++) { + for (uint256 j = 0; j < externalPositions.length; j++) { int256 externalPositionUnit = _setToken.getExternalPositionRealUnit(component, externalPositions[j]); // If positionUnit <= 0 it will be "added" to debt position @@ -613,7 +613,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard { /** * If any manager fees mints Sets to the defined feeRecipient. If protocol fee is enabled mints Sets to protocol - * feeRecipient. + * feeRecipient. */ function _resolveFees(ISetToken _setToken, uint256 managerFee, uint256 protocolFee) internal { if (managerFee > 0) { @@ -647,7 +647,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard { return address(0); } - + /** * Calls all modules that have registered with the DebtIssuanceModule that have a moduleIssueHook. */ @@ -669,7 +669,7 @@ contract DebtIssuanceModule is ModuleBase, ReentrancyGuard { } /** - * For each component's external module positions, calculate the total notional quantity, and + * For each component's external module positions, calculate the total notional quantity, and * call the module's issue hook or redeem hook. * Note: It is possible that these hooks can cause the states of other modules to change. * It can be problematic if the hook called an external function that called back into a module, resulting in state inconsistencies. diff --git a/contracts/protocol/modules/DebtIssuanceModuleV2.sol b/contracts/protocol/modules/v1/DebtIssuanceModuleV2.sol similarity index 96% rename from contracts/protocol/modules/DebtIssuanceModuleV2.sol rename to contracts/protocol/modules/v1/DebtIssuanceModuleV2.sol index c857d4d52..8606d3858 100644 --- a/contracts/protocol/modules/DebtIssuanceModuleV2.sol +++ b/contracts/protocol/modules/v1/DebtIssuanceModuleV2.sol @@ -23,11 +23,11 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import { DebtIssuanceModule } from "./DebtIssuanceModule.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IssuanceValidationUtils } from "../lib/IssuanceValidationUtils.sol"; -import { Position } from "../lib/Position.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IssuanceValidationUtils } from "../../lib/IssuanceValidationUtils.sol"; +import { Position } from "../../lib/Position.sol"; /** * @title DebtIssuanceModuleV2 @@ -37,14 +37,14 @@ import { Position } from "../lib/Position.sol"; * external positions, including debt positions. Module hooks are added to allow for syncing of positions, and component * level hooks are added to ensure positions are replicated correctly. The manager can define arbitrary issuance logic * in the manager hook, as well as specify issue and redeem fees. - * - * NOTE: + * + * NOTE: * DebtIssuanceModule contract confirms increase/decrease in balance of component held by the SetToken after every transfer in/out - * for each component during issuance/redemption. This contract replaces those strict checks with slightly looser checks which + * for each component during issuance/redemption. This contract replaces those strict checks with slightly looser checks which * ensure that the SetToken remains collateralized after every transfer in/out for each component during issuance/redemption. * This module should be used to issue/redeem SetToken whose one or more components return a balance value with +/-1 wei error. * For example, this module can be used to issue/redeem SetTokens which has one or more aTokens as its components. - * The new checks do NOT apply to any transfers that are part of an external position. A token that has rounding issues may lead to + * The new checks do NOT apply to any transfers that are part of an external position. A token that has rounding issues may lead to * reverts if it is included as an external position unless explicitly allowed in a module hook. * * The getRequiredComponentIssuanceUnits function on this module assumes that Default token balances will be synced on every issuance @@ -52,20 +52,20 @@ import { Position } from "../lib/Position.sol"; */ contract DebtIssuanceModuleV2 is DebtIssuanceModule { using Position for uint256; - + /* ============ Constructor ============ */ - + constructor(IController _controller) public DebtIssuanceModule(_controller) {} /* ============ External Functions ============ */ /** - * Deposits components to the SetToken, replicates any external module component positions and mints + * Deposits components to the SetToken, replicates any external module component positions and mints * the SetToken. If the token has a debt position all collateral will be transferred in first then debt * will be returned to the minting address. If specified, a fee will be charged on issuance. - * + * * NOTE: Overrides DebtIssuanceModule#issue external function and adds undercollateralization checks in place of the - * previous default strict balances checks. The undercollateralization checks are implemented in IssuanceValidationUtils library and they + * previous default strict balances checks. The undercollateralization checks are implemented in IssuanceValidationUtils library and they * revert upon undercollateralization of the SetToken post component transfer. * * @param _setToken Instance of the SetToken to issue @@ -88,7 +88,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { _callModulePreIssueHooks(_setToken, _quantity); - + uint256 initialSetSupply = _setToken.totalSupply(); ( @@ -98,7 +98,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { ) = calculateTotalFees(_setToken, _quantity, true); // Prevent stack too deep - { + { ( address[] memory components, uint256[] memory equityUnits, @@ -111,7 +111,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { _resolveDebtPositions(_setToken, quantityWithFees, true, components, debtUnits, initialSetSupply, finalSetSupply); _resolveFees(_setToken, managerFee, protocolFee); } - + _setToken.mint(_to, _quantity); emit SetTokenIssued( @@ -132,7 +132,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { * will be returned to the minting address. If specified, a fee will be charged on redeem. * * NOTE: Overrides DebtIssuanceModule#redeem internal function and adds undercollateralization checks in place of the - * previous default strict balances checks. The undercollateralization checks are implemented in IssuanceValidationUtils library + * previous default strict balances checks. The undercollateralization checks are implemented in IssuanceValidationUtils library * and they revert upon undercollateralization of the SetToken post component transfer. * * @param _setToken Instance of the SetToken to redeem @@ -145,7 +145,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { address _to ) external - override + override nonReentrant onlyValidAndInitializedSet(_setToken) { @@ -241,7 +241,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { } /* ============ Internal Functions ============ */ - + /** * Resolve equity positions associated with SetToken. On issuance, the total equity position for an asset (including default and external * positions) is transferred in. Then any external position hooks are called to transfer the external positions to their necessary place. @@ -310,7 +310,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { if (componentQuantity > 0) { if (_isIssue) { _executeExternalPositionHooks(_setToken, _quantity, IERC20(component), true, false); - + // Call Invoke#invokeTransfer instead of Invoke#strictInvokeTransfer _setToken.invokeTransfer(component, msg.sender, componentQuantity); @@ -366,7 +366,7 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule { address[] memory externalPositions = _setToken.getExternalPositionModules(component); if (externalPositions.length > 0) { - for (uint256 j = 0; j < externalPositions.length; j++) { + for (uint256 j = 0; j < externalPositions.length; j++) { int256 externalPositionUnit = _setToken.getExternalPositionRealUnit(component, externalPositions[j]); // If positionUnit <= 0 it will be "added" to debt position diff --git a/contracts/protocol/modules/GeneralIndexModule.sol b/contracts/protocol/modules/v1/GeneralIndexModule.sol similarity index 98% rename from contracts/protocol/modules/GeneralIndexModule.sol rename to contracts/protocol/modules/v1/GeneralIndexModule.sol index f73b7abdd..98cb03eb1 100644 --- a/contracts/protocol/modules/GeneralIndexModule.sol +++ b/contracts/protocol/modules/v1/GeneralIndexModule.sol @@ -25,16 +25,16 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IIndexExchangeAdapter } from "../../interfaces/IIndexExchangeAdapter.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IWETH } from "../../interfaces/external/IWETH.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; -import { Uint256ArrayUtils } from "../../lib/Uint256ArrayUtils.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IIndexExchangeAdapter } from "../../../interfaces/IIndexExchangeAdapter.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IWETH } from "../../../interfaces/external/IWETH.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; +import { Uint256ArrayUtils } from "../../../lib/Uint256ArrayUtils.sol"; /** diff --git a/contracts/protocol/modules/GovernanceModule.sol b/contracts/protocol/modules/v1/GovernanceModule.sol similarity index 95% rename from contracts/protocol/modules/GovernanceModule.sol rename to contracts/protocol/modules/v1/GovernanceModule.sol index 151d69dd6..5e9421be2 100644 --- a/contracts/protocol/modules/GovernanceModule.sol +++ b/contracts/protocol/modules/v1/GovernanceModule.sol @@ -21,11 +21,11 @@ pragma experimental "ABIEncoderV2"; import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IGovernanceAdapter } from "../../interfaces/IGovernanceAdapter.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IGovernanceAdapter } from "../../../interfaces/IGovernanceAdapter.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; /** @@ -33,7 +33,7 @@ import { ModuleBase } from "../lib/ModuleBase.sol"; * @author Set Protocol * * A smart contract module that enables participating in governance of component tokens held in the SetToken. - * Examples of intended protocols include Compound, Uniswap, and Maker governance. + * Examples of intended protocols include Compound, Uniswap, and Maker governance. */ contract GovernanceModule is ModuleBase, ReentrancyGuard { using Invoke for ISetToken; diff --git a/contracts/protocol/modules/IssuanceModule.sol b/contracts/protocol/modules/v1/IssuanceModule.sol similarity index 93% rename from contracts/protocol/modules/IssuanceModule.sol rename to contracts/protocol/modules/v1/IssuanceModule.sol index 8875b5e44..77ec317f7 100644 --- a/contracts/protocol/modules/IssuanceModule.sol +++ b/contracts/protocol/modules/v1/IssuanceModule.sol @@ -20,7 +20,7 @@ pragma solidity 0.6.10; pragma experimental "ABIEncoderV2"; import { DebtIssuanceModuleV2 } from "./DebtIssuanceModuleV2.sol"; -import { IController } from "../../interfaces/IController.sol"; +import { IController } from "../../../interfaces/IController.sol"; /** * @title IssuanceModule @@ -28,7 +28,7 @@ import { IController } from "../../interfaces/IController.sol"; * * The IssuanceModule is a module that enables users to issue and redeem SetTokens that contain default and all * external positions, including debt positions. The manager can define arbitrary issuance logic in the manager - * hook, as well as specify issue and redeem fees. The manager can remove the module. + * hook, as well as specify issue and redeem fees. The manager can remove the module. */ contract IssuanceModule is DebtIssuanceModuleV2 { diff --git a/contracts/protocol/modules/SingleIndexModule.sol b/contracts/protocol/modules/v1/SingleIndexModule.sol similarity index 97% rename from contracts/protocol/modules/SingleIndexModule.sol rename to contracts/protocol/modules/v1/SingleIndexModule.sol index 789998393..21701e0ab 100644 --- a/contracts/protocol/modules/SingleIndexModule.sol +++ b/contracts/protocol/modules/v1/SingleIndexModule.sol @@ -25,15 +25,15 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IWETH } from "../../interfaces/external/IWETH.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; -import { Uint256ArrayUtils } from "../../lib/Uint256ArrayUtils.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IWETH } from "../../../interfaces/external/IWETH.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; +import { Uint256ArrayUtils } from "../../../lib/Uint256ArrayUtils.sol"; /** @@ -169,7 +169,7 @@ contract SingleIndexModule is ModuleBase, ReentrancyGuard { ) external onlyManagerAndValidSet(index) - { + { // Don't use validate arrays because empty arrays are valid require(_newComponents.length == _newComponentsTargetUnits.length, "Array length mismatch"); @@ -329,7 +329,7 @@ contract SingleIndexModule is ModuleBase, ReentrancyGuard { } /** - * MANAGER ONLY: Toggle ability for passed addresses to trade from current state + * MANAGER ONLY: Toggle ability for passed addresses to trade from current state * * @param _traders Array trader addresses to toggle status * @param _statuses Booleans indicating if matching trader can trade @@ -393,7 +393,7 @@ contract SingleIndexModule is ModuleBase, ReentrancyGuard { */ function getTargetUnits(address[] calldata _components) external view returns(uint256[] memory) { uint256 currentPositionMultiplier = index.positionMultiplier().toUint256(); - + uint256[] memory targetUnits = new uint256[](_components.length); for (uint256 i = 0; i < _components.length; i++) { targetUnits[i] = _normalizeTargetUnit(_components[i], currentPositionMultiplier); @@ -483,7 +483,7 @@ contract SingleIndexModule is ModuleBase, ReentrancyGuard { virtual { uint256 wethBalance = weth.balanceOf(address(index)); - + ( address exchangeAddress, bytes memory tradeCallData @@ -561,7 +561,7 @@ contract SingleIndexModule is ModuleBase, ReentrancyGuard { BALANCER_POOL_LIMIT ); - return (exchangeAddress, tradeCallData); + return (exchangeAddress, tradeCallData); } /** @@ -579,7 +579,7 @@ contract SingleIndexModule is ModuleBase, ReentrancyGuard { returns(address, bytes memory) { address exchangeAddress = _exchange == uint256(ExchangeId.Uniswap) ? uniswapRouter : sushiswapRouter; - + string memory functionSignature; address[] memory path = new address[](2); uint256 limit; @@ -592,7 +592,7 @@ contract SingleIndexModule is ModuleBase, ReentrancyGuard { } path[0] = _sellComponent; path[1] = _buyComponent; - + bytes memory tradeCallData = abi.encodeWithSignature( functionSignature, _amount, diff --git a/contracts/protocol/modules/SlippageIssuanceModule.sol b/contracts/protocol/modules/v1/SlippageIssuanceModule.sol similarity index 98% rename from contracts/protocol/modules/SlippageIssuanceModule.sol rename to contracts/protocol/modules/v1/SlippageIssuanceModule.sol index ad39bbe15..9bd8bf0cc 100644 --- a/contracts/protocol/modules/SlippageIssuanceModule.sol +++ b/contracts/protocol/modules/v1/SlippageIssuanceModule.sol @@ -20,9 +20,9 @@ pragma solidity 0.6.10; pragma experimental "ABIEncoderV2"; import { DebtIssuanceModule } from "./DebtIssuanceModule.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IModuleIssuanceHookV2 } from "../../interfaces/IModuleIssuanceHookV2.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IModuleIssuanceHookV2 } from "../../../interfaces/IModuleIssuanceHookV2.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; /** * @title SlippageIssuanceModule @@ -43,7 +43,7 @@ contract SlippageIssuanceModule is DebtIssuanceModule { /* ============ External Functions ============ */ /** - * Deposits components to the SetToken, replicates any external module component positions and mints + * Deposits components to the SetToken, replicates any external module component positions and mints * the SetToken. If the token has a debt position all collateral will be transferred in first then debt * will be returned to the minting address. If specified, a fee will be charged on issuance. Issuer can * also pass in a max amount of tokens they are willing to pay for each component. They are NOT required @@ -85,7 +85,7 @@ contract SlippageIssuanceModule is DebtIssuanceModule { uint256 managerFee, uint256 protocolFee ) = calculateTotalFees(_setToken, _setQuantity, isIssue); - + // Scoping logic to avoid stack too deep errors { ( @@ -142,7 +142,7 @@ contract SlippageIssuanceModule is DebtIssuanceModule { address _to ) external - virtual + virtual nonReentrant onlyValidAndInitializedSet(_setToken) { @@ -348,7 +348,7 @@ contract SlippageIssuanceModule is DebtIssuanceModule { bool _isIssue ) internal - returns (int256[] memory, int256[] memory) + returns (int256[] memory, int256[] memory) { uint256 componentsLength = _setToken.getComponents().length; int256[] memory cumulativeEquityAdjustments = new int256[](componentsLength); @@ -418,7 +418,7 @@ contract SlippageIssuanceModule is DebtIssuanceModule { pure { require(_setQuantity > 0, "SetToken quantity must be > 0"); - + uint256 componentsLength = _components.length; require(componentsLength == _componentLimits.length, "Array length mismatch"); if (componentsLength > 0) { diff --git a/contracts/protocol/modules/StakingModule.sol b/contracts/protocol/modules/v1/StakingModule.sol similarity index 96% rename from contracts/protocol/modules/StakingModule.sol rename to contracts/protocol/modules/v1/StakingModule.sol index f9723a23b..f59c30558 100644 --- a/contracts/protocol/modules/StakingModule.sol +++ b/contracts/protocol/modules/v1/StakingModule.sol @@ -24,14 +24,14 @@ import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IModuleIssuanceHook } from "../../interfaces/IModuleIssuanceHook.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IStakingAdapter } from "../../interfaces/IStakingAdapter.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IModuleIssuanceHook } from "../../../interfaces/IModuleIssuanceHook.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IStakingAdapter } from "../../../interfaces/IStakingAdapter.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; /** @@ -179,7 +179,7 @@ contract StakingModule is ModuleBase, IModuleIssuanceHook { /** * MODULE ONLY: On issuance, replicates all staking positions for a given component by staking the component transferred into * the SetToken by an issuer. The amount staked should only be the notional amount required to replicate a _setTokenQuantity - * amount of a position. No updates to positions should take place. + * amount of a position. No updates to positions should take place. * * @param _setToken Address of SetToken contract * @param _component Address of token being staked @@ -205,7 +205,7 @@ contract StakingModule is ModuleBase, IModuleIssuanceHook { /** * MODULE ONLY: On redemption, unwind all staking positions for a given asset by unstaking the given component. The amount * unstaked should only be the notional amount required to unwind a _setTokenQuantity amount of a position. No updates to - * positions should take place. + * positions should take place. * * @param _setToken Address of SetToken contract * @param _component Address of token being staked @@ -266,7 +266,7 @@ contract StakingModule is ModuleBase, IModuleIssuanceHook { function hasStakingPosition(ISetToken _setToken, IERC20 _component, address _stakeContract) public view returns(bool) { return getStakingContracts(_setToken, _component).contains(_stakeContract); } - + function getStakingContracts(ISetToken _setToken, IERC20 _component) public view returns(address[] memory) { return stakingPositions[_setToken][_component].stakingContracts; } @@ -391,7 +391,7 @@ contract StakingModule is ModuleBase, IModuleIssuanceHook { uint256 newDefaultTokenUnit = _setToken.getDefaultPositionRealUnit(address(_component)).toUint256().sub(_componentPositionUnits); _setToken.editDefaultPosition(address(_component), newDefaultTokenUnit); - + int256 newExternalTokenUnit = _setToken.getExternalPositionRealUnit(address(_component), address(this)) .add(_componentPositionUnits.toInt256()); _setToken.editExternalPosition(address(_component), address(this), newExternalTokenUnit, ""); @@ -417,7 +417,7 @@ contract StakingModule is ModuleBase, IModuleIssuanceHook { uint256 _componentPositionUnits ) internal - { + { uint256 remainingPositionUnits = getStakingPositionUnit(_setToken, _component, _stakeContract).sub(_componentPositionUnits); if (remainingPositionUnits > 0) { @@ -428,12 +428,12 @@ contract StakingModule is ModuleBase, IModuleIssuanceHook { } uint256 newTokenUnit = _setToken.getDefaultPositionRealUnit(address(_component)).toUint256().add(_componentPositionUnits); - + _setToken.editDefaultPosition(address(_component), newTokenUnit); - + int256 newExternalTokenUnit = _setToken.getExternalPositionRealUnit(address(_component), address(this)) .sub(_componentPositionUnits.toInt256()); - + _setToken.editExternalPosition(address(_component), address(this), newExternalTokenUnit, ""); } } \ No newline at end of file diff --git a/contracts/protocol/modules/StreamingFeeModule.sol b/contracts/protocol/modules/v1/StreamingFeeModule.sol similarity index 97% rename from contracts/protocol/modules/StreamingFeeModule.sol rename to contracts/protocol/modules/v1/StreamingFeeModule.sol index 0acb0b876..5257656b2 100644 --- a/contracts/protocol/modules/StreamingFeeModule.sol +++ b/contracts/protocol/modules/v1/StreamingFeeModule.sol @@ -24,10 +24,10 @@ import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** diff --git a/contracts/protocol/modules/TradeModule.sol b/contracts/protocol/modules/v1/TradeModule.sol similarity index 95% rename from contracts/protocol/modules/TradeModule.sol rename to contracts/protocol/modules/v1/TradeModule.sol index de8312033..c98919d8a 100644 --- a/contracts/protocol/modules/TradeModule.sol +++ b/contracts/protocol/modules/v1/TradeModule.sol @@ -23,15 +23,15 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; -import { IController } from "../../interfaces/IController.sol"; +import { IController } from "../../../interfaces/IController.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { IExchangeAdapter } from "../../interfaces/IExchangeAdapter.sol"; -import { IIntegrationRegistry } from "../../interfaces/IIntegrationRegistry.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { IExchangeAdapter } from "../../../interfaces/IExchangeAdapter.sol"; +import { IIntegrationRegistry } from "../../../interfaces/IIntegrationRegistry.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** * @title TradeModule @@ -289,9 +289,9 @@ contract TradeModule is ModuleBase, ReentrancyGuard { */ function _accrueProtocolFee(TradeInfo memory _tradeInfo, uint256 _exchangedQuantity) internal returns (uint256) { uint256 protocolFeeTotal = getModuleFee(TRADE_MODULE_PROTOCOL_FEE_INDEX, _exchangedQuantity); - + payProtocolFeeFromSetToken(_tradeInfo.setToken, _tradeInfo.receiveToken, protocolFeeTotal); - + return protocolFeeTotal; } diff --git a/contracts/protocol/modules/WrapModule.sol b/contracts/protocol/modules/v1/WrapModule.sol similarity index 95% rename from contracts/protocol/modules/WrapModule.sol rename to contracts/protocol/modules/v1/WrapModule.sol index 2d842ac10..ddcad6d64 100644 --- a/contracts/protocol/modules/WrapModule.sol +++ b/contracts/protocol/modules/v1/WrapModule.sol @@ -24,15 +24,15 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IIntegrationRegistry } from "../../interfaces/IIntegrationRegistry.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IWETH } from "../../interfaces/external/IWETH.sol"; -import { IWrapAdapter } from "../../interfaces/IWrapAdapter.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IIntegrationRegistry } from "../../../interfaces/IIntegrationRegistry.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IWETH } from "../../../interfaces/external/IWETH.sol"; +import { IWrapAdapter } from "../../../interfaces/IWrapAdapter.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** * @title WrapModule @@ -90,7 +90,7 @@ contract WrapModule is ModuleBase, ReentrancyGuard { } /* ============ External Functions ============ */ - + /** * MANAGER-ONLY: Instructs the SetToken to wrap an underlying asset into a wrappedToken via a specified adapter. * @@ -106,7 +106,7 @@ contract WrapModule is ModuleBase, ReentrancyGuard { address _wrappedToken, uint256 _underlyingUnits, string calldata _integrationName - ) + ) external nonReentrant onlyManagerAndValidSet(_setToken) @@ -148,7 +148,7 @@ contract WrapModule is ModuleBase, ReentrancyGuard { address _wrappedToken, uint256 _underlyingUnits, string calldata _integrationName - ) + ) external nonReentrant onlyManagerAndValidSet(_setToken) @@ -290,7 +290,7 @@ contract WrapModule is ModuleBase, ReentrancyGuard { ISetToken _setToken, address _transactPosition, uint256 _transactPositionUnits - ) + ) internal view { @@ -303,9 +303,9 @@ contract WrapModule is ModuleBase, ReentrancyGuard { } /** - * The WrapModule calculates the total notional underlying to wrap, approves the underlying to the 3rd party + * The WrapModule calculates the total notional underlying to wrap, approves the underlying to the 3rd party * integration contract, then invokes the SetToken to call wrap by passing its calldata along. When raw ETH - * is being used (_usesEther = true) WETH position must first be unwrapped and underlyingAddress sent to + * is being used (_usesEther = true) WETH position must first be unwrapped and underlyingAddress sent to * adapter must be external protocol's ETH representative address. * * Returns notional amount of underlying tokens and wrapped tokens that were wrapped. @@ -317,7 +317,7 @@ contract WrapModule is ModuleBase, ReentrancyGuard { address _wrappedToken, uint256 _underlyingUnits, bool _usesEther - ) + ) internal returns (uint256, uint256) { @@ -499,7 +499,7 @@ contract WrapModule is ModuleBase, ReentrancyGuard { return ( underlyingTokenBalance, - wrapTokenBalance + wrapTokenBalance ); } } \ No newline at end of file diff --git a/contracts/protocol/modules/WrapModuleV2.sol b/contracts/protocol/modules/v1/WrapModuleV2.sol similarity index 96% rename from contracts/protocol/modules/WrapModuleV2.sol rename to contracts/protocol/modules/v1/WrapModuleV2.sol index bfee1c525..c1c371080 100644 --- a/contracts/protocol/modules/WrapModuleV2.sol +++ b/contracts/protocol/modules/v1/WrapModuleV2.sol @@ -24,15 +24,15 @@ import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.s import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol"; import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IIntegrationRegistry } from "../../interfaces/IIntegrationRegistry.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IWETH } from "../../interfaces/external/IWETH.sol"; -import { IWrapV2Adapter } from "../../interfaces/IWrapV2Adapter.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IIntegrationRegistry } from "../../../interfaces/IIntegrationRegistry.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IWETH } from "../../../interfaces/external/IWETH.sol"; +import { IWrapV2Adapter } from "../../../interfaces/IWrapV2Adapter.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** * @title WrapModuleV2 @@ -90,7 +90,7 @@ contract WrapModuleV2 is ModuleBase, ReentrancyGuard { } /* ============ External Functions ============ */ - + /** * MANAGER-ONLY: Instructs the SetToken to wrap an underlying asset into a wrappedToken via a specified adapter. * @@ -108,7 +108,7 @@ contract WrapModuleV2 is ModuleBase, ReentrancyGuard { uint256 _underlyingUnits, string calldata _integrationName, bytes memory _wrapData - ) + ) external nonReentrant onlyManagerAndValidSet(_setToken) @@ -153,7 +153,7 @@ contract WrapModuleV2 is ModuleBase, ReentrancyGuard { uint256 _underlyingUnits, string calldata _integrationName, bytes memory _wrapData - ) + ) external nonReentrant onlyManagerAndValidSet(_setToken) @@ -302,7 +302,7 @@ contract WrapModuleV2 is ModuleBase, ReentrancyGuard { ISetToken _setToken, address _transactPosition, uint256 _transactPositionUnits - ) + ) internal view { @@ -315,9 +315,9 @@ contract WrapModuleV2 is ModuleBase, ReentrancyGuard { } /** - * The WrapModule calculates the total notional underlying to wrap, approves the underlying to the 3rd party + * The WrapModule calculates the total notional underlying to wrap, approves the underlying to the 3rd party * integration contract, then invokes the SetToken to call wrap by passing its calldata along. When raw ETH - * is being used (_usesEther = true) WETH position must first be unwrapped and underlyingAddress sent to + * is being used (_usesEther = true) WETH position must first be unwrapped and underlyingAddress sent to * adapter must be external protocol's ETH representative address. * * Returns notional amount of underlying tokens and wrapped tokens that were wrapped. @@ -330,7 +330,7 @@ contract WrapModuleV2 is ModuleBase, ReentrancyGuard { uint256 _underlyingUnits, bytes memory _wrapData, bool _usesEther - ) + ) internal returns (uint256, uint256) { @@ -522,7 +522,7 @@ contract WrapModuleV2 is ModuleBase, ReentrancyGuard { return ( underlyingTokenBalance, - wrapTokenBalance + wrapTokenBalance ); } } \ No newline at end of file diff --git a/contracts/protocol/modules/PerpV2BasisTradingModule.sol b/contracts/protocol/modules/v2/PerpV2BasisTradingModule.sol similarity index 97% rename from contracts/protocol/modules/PerpV2BasisTradingModule.sol rename to contracts/protocol/modules/v2/PerpV2BasisTradingModule.sol index 96008f11e..061025865 100644 --- a/contracts/protocol/modules/PerpV2BasisTradingModule.sol +++ b/contracts/protocol/modules/v2/PerpV2BasisTradingModule.sol @@ -19,17 +19,17 @@ pragma solidity 0.6.10; pragma experimental "ABIEncoderV2"; -import { IController } from "../../interfaces/IController.sol"; +import { IController } from "../../../interfaces/IController.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { IMarketRegistry } from "../../interfaces/external/perp-v2/IMarketRegistry.sol"; -import { Invoke } from "../lib/Invoke.sol"; -import { IQuoter } from "../../interfaces/external/perp-v2/IQuoter.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { IVault } from "../../interfaces/external/perp-v2/IVault.sol"; -import { ModuleBase } from "../lib/ModuleBase.sol"; +import { IMarketRegistry } from "../../../interfaces/external/perp-v2/IMarketRegistry.sol"; +import { Invoke } from "../../lib/Invoke.sol"; +import { IQuoter } from "../../../interfaces/external/perp-v2/IQuoter.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { IVault } from "../../../interfaces/external/perp-v2/IVault.sol"; +import { ModuleBase } from "../../lib/ModuleBase.sol"; import { PerpV2LeverageModuleV2 } from "./PerpV2LeverageModuleV2.sol"; -import { Position } from "../lib/Position.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; +import { Position } from "../../lib/Position.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; /** * @title PerpV2BasisTradingModule diff --git a/contracts/protocol/modules/PerpV2LeverageModuleV2.sol b/contracts/protocol/modules/v2/PerpV2LeverageModuleV2.sol similarity index 97% rename from contracts/protocol/modules/PerpV2LeverageModuleV2.sol rename to contracts/protocol/modules/v2/PerpV2LeverageModuleV2.sol index 5912949b2..3bbebbaf5 100644 --- a/contracts/protocol/modules/PerpV2LeverageModuleV2.sol +++ b/contracts/protocol/modules/v2/PerpV2LeverageModuleV2.sol @@ -26,26 +26,26 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; -import { PerpV2LibraryV2 } from "../integration/lib/PerpV2LibraryV2.sol"; -import { PerpV2Positions } from "../integration/lib/PerpV2Positions.sol"; -import { UniswapV3Math } from "../integration/lib/UniswapV3Math.sol"; -import { IAccountBalance } from "../../interfaces/external/perp-v2/IAccountBalance.sol"; -import { IClearingHouse } from "../../interfaces/external/perp-v2/IClearingHouse.sol"; -import { IClearingHouseConfig } from "../../interfaces/external/perp-v2/IClearingHouseConfig.sol"; -import { IExchange } from "../../interfaces/external/perp-v2/IExchange.sol"; -import { IIndexPrice } from "../../interfaces/external/perp-v2/IIndexPrice.sol"; -import { IVault } from "../../interfaces/external/perp-v2/IVault.sol"; -import { IQuoter } from "../../interfaces/external/perp-v2/IQuoter.sol"; -import { IMarketRegistry } from "../../interfaces/external/perp-v2/IMarketRegistry.sol"; -import { IController } from "../../interfaces/IController.sol"; -import { IDebtIssuanceModule } from "../../interfaces/IDebtIssuanceModule.sol"; -import { IModuleIssuanceHookV2 } from "../../interfaces/IModuleIssuanceHookV2.sol"; -import { ISetToken } from "../../interfaces/ISetToken.sol"; -import { ModuleBaseV2 } from "../lib/ModuleBaseV2.sol"; -import { SetTokenAccessible } from "../lib/SetTokenAccessible.sol"; -import { PreciseUnitMath } from "../../lib/PreciseUnitMath.sol"; -import { AddressArrayUtils } from "../../lib/AddressArrayUtils.sol"; -import { UnitConversionUtils } from "../../lib/UnitConversionUtils.sol"; +import { PerpV2LibraryV2 } from "../../integration/lib/PerpV2LibraryV2.sol"; +import { PerpV2Positions } from "../../integration/lib/PerpV2Positions.sol"; +import { UniswapV3Math } from "../../integration/lib/UniswapV3Math.sol"; +import { IAccountBalance } from "../../../interfaces/external/perp-v2/IAccountBalance.sol"; +import { IClearingHouse } from "../../../interfaces/external/perp-v2/IClearingHouse.sol"; +import { IClearingHouseConfig } from "../../../interfaces/external/perp-v2/IClearingHouseConfig.sol"; +import { IExchange } from "../../../interfaces/external/perp-v2/IExchange.sol"; +import { IIndexPrice } from "../../../interfaces/external/perp-v2/IIndexPrice.sol"; +import { IVault } from "../../../interfaces/external/perp-v2/IVault.sol"; +import { IQuoter } from "../../../interfaces/external/perp-v2/IQuoter.sol"; +import { IMarketRegistry } from "../../../interfaces/external/perp-v2/IMarketRegistry.sol"; +import { IController } from "../../../interfaces/IController.sol"; +import { IDebtIssuanceModule } from "../../../interfaces/IDebtIssuanceModule.sol"; +import { IModuleIssuanceHookV2 } from "../../../interfaces/IModuleIssuanceHookV2.sol"; +import { ISetToken } from "../../../interfaces/ISetToken.sol"; +import { ModuleBaseV2 } from "../../lib/ModuleBaseV2.sol"; +import { SetTokenAccessible } from "../../lib/SetTokenAccessible.sol"; +import { PreciseUnitMath } from "../../../lib/PreciseUnitMath.sol"; +import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol"; +import { UnitConversionUtils } from "../../../lib/UnitConversionUtils.sol"; /** * @title PerpV2LeverageModuleV2 diff --git a/test/protocol/modules/aaveLeverageModule.spec.ts b/test/protocol/modules/v1/aaveLeverageModule.spec.ts similarity index 100% rename from test/protocol/modules/aaveLeverageModule.spec.ts rename to test/protocol/modules/v1/aaveLeverageModule.spec.ts diff --git a/test/protocol/modules/airdropModule.spec.ts b/test/protocol/modules/v1/airdropModule.spec.ts similarity index 100% rename from test/protocol/modules/airdropModule.spec.ts rename to test/protocol/modules/v1/airdropModule.spec.ts diff --git a/test/protocol/modules/ammModule.spec.ts b/test/protocol/modules/v1/ammModule.spec.ts similarity index 100% rename from test/protocol/modules/ammModule.spec.ts rename to test/protocol/modules/v1/ammModule.spec.ts diff --git a/test/protocol/modules/basicIssuanceModule.spec.ts b/test/protocol/modules/v1/basicIssuanceModule.spec.ts similarity index 100% rename from test/protocol/modules/basicIssuanceModule.spec.ts rename to test/protocol/modules/v1/basicIssuanceModule.spec.ts diff --git a/test/protocol/modules/claimModule.spec.ts b/test/protocol/modules/v1/claimModule.spec.ts similarity index 100% rename from test/protocol/modules/claimModule.spec.ts rename to test/protocol/modules/v1/claimModule.spec.ts diff --git a/test/protocol/modules/compoundLeverageModule.spec.ts b/test/protocol/modules/v1/compoundLeverageModule.spec.ts similarity index 100% rename from test/protocol/modules/compoundLeverageModule.spec.ts rename to test/protocol/modules/v1/compoundLeverageModule.spec.ts diff --git a/test/protocol/modules/compoundLeverageModule2.spec.ts b/test/protocol/modules/v1/compoundLeverageModule2.spec.ts similarity index 100% rename from test/protocol/modules/compoundLeverageModule2.spec.ts rename to test/protocol/modules/v1/compoundLeverageModule2.spec.ts diff --git a/test/protocol/modules/customOracleNAVIssuanceModule.spec.ts b/test/protocol/modules/v1/customOracleNAVIssuanceModule.spec.ts similarity index 99% rename from test/protocol/modules/customOracleNAVIssuanceModule.spec.ts rename to test/protocol/modules/v1/customOracleNAVIssuanceModule.spec.ts index 09aa812d6..05f990443 100644 --- a/test/protocol/modules/customOracleNAVIssuanceModule.spec.ts +++ b/test/protocol/modules/v1/customOracleNAVIssuanceModule.spec.ts @@ -30,7 +30,7 @@ import { getSystemFixture, } from "@utils/test/index"; import { SystemFixture } from "@utils/fixtures"; -import { ERC20__factory } from "../../../typechain/factories/ERC20__factory"; +import { ERC20__factory } from "@typechain/factories/ERC20__factory"; const expect = getWaffleExpect(); diff --git a/test/protocol/modules/debtIssuanceModule.spec.ts b/test/protocol/modules/v1/debtIssuanceModule.spec.ts similarity index 100% rename from test/protocol/modules/debtIssuanceModule.spec.ts rename to test/protocol/modules/v1/debtIssuanceModule.spec.ts diff --git a/test/protocol/modules/debtIssuanceModuleV2.spec.ts b/test/protocol/modules/v1/debtIssuanceModuleV2.spec.ts similarity index 100% rename from test/protocol/modules/debtIssuanceModuleV2.spec.ts rename to test/protocol/modules/v1/debtIssuanceModuleV2.spec.ts diff --git a/test/protocol/modules/generalIndexModule.spec.ts b/test/protocol/modules/v1/generalIndexModule.spec.ts similarity index 100% rename from test/protocol/modules/generalIndexModule.spec.ts rename to test/protocol/modules/v1/generalIndexModule.spec.ts diff --git a/test/protocol/modules/governanceModule.spec.ts b/test/protocol/modules/v1/governanceModule.spec.ts similarity index 100% rename from test/protocol/modules/governanceModule.spec.ts rename to test/protocol/modules/v1/governanceModule.spec.ts diff --git a/test/protocol/modules/issuanceModule.spec.ts b/test/protocol/modules/v1/issuanceModule.spec.ts similarity index 100% rename from test/protocol/modules/issuanceModule.spec.ts rename to test/protocol/modules/v1/issuanceModule.spec.ts diff --git a/test/protocol/modules/singleIndexModule.spec.ts b/test/protocol/modules/v1/singleIndexModule.spec.ts similarity index 100% rename from test/protocol/modules/singleIndexModule.spec.ts rename to test/protocol/modules/v1/singleIndexModule.spec.ts diff --git a/test/protocol/modules/slippageIssuanceModule.spec.ts b/test/protocol/modules/v1/slippageIssuanceModule.spec.ts similarity index 100% rename from test/protocol/modules/slippageIssuanceModule.spec.ts rename to test/protocol/modules/v1/slippageIssuanceModule.spec.ts diff --git a/test/protocol/modules/stakingModule.spec.ts b/test/protocol/modules/v1/stakingModule.spec.ts similarity index 100% rename from test/protocol/modules/stakingModule.spec.ts rename to test/protocol/modules/v1/stakingModule.spec.ts diff --git a/test/protocol/modules/streamingFeeModule.spec.ts b/test/protocol/modules/v1/streamingFeeModule.spec.ts similarity index 100% rename from test/protocol/modules/streamingFeeModule.spec.ts rename to test/protocol/modules/v1/streamingFeeModule.spec.ts diff --git a/test/protocol/modules/tradeModule.spec.ts b/test/protocol/modules/v1/tradeModule.spec.ts similarity index 100% rename from test/protocol/modules/tradeModule.spec.ts rename to test/protocol/modules/v1/tradeModule.spec.ts diff --git a/test/protocol/modules/wrapModule.spec.ts b/test/protocol/modules/v1/wrapModule.spec.ts similarity index 100% rename from test/protocol/modules/wrapModule.spec.ts rename to test/protocol/modules/v1/wrapModule.spec.ts diff --git a/test/protocol/modules/wrapModuleV2.spec.ts b/test/protocol/modules/v1/wrapModuleV2.spec.ts similarity index 100% rename from test/protocol/modules/wrapModuleV2.spec.ts rename to test/protocol/modules/v1/wrapModuleV2.spec.ts diff --git a/test/protocol/modules/perpV2BasisTradingModule.spec.ts b/test/protocol/modules/v2/perpV2BasisTradingModule.spec.ts similarity index 100% rename from test/protocol/modules/perpV2BasisTradingModule.spec.ts rename to test/protocol/modules/v2/perpV2BasisTradingModule.spec.ts diff --git a/test/protocol/modules/perpV2LeverageModuleV2.spec.ts b/test/protocol/modules/v2/perpV2LeverageModuleV2.spec.ts similarity index 100% rename from test/protocol/modules/perpV2LeverageModuleV2.spec.ts rename to test/protocol/modules/v2/perpV2LeverageModuleV2.spec.ts