Skip to content

Commit

Permalink
feat(reorg): Re-org modules into v1 and v2 directories (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Mar 24, 2022
1 parent 355c030 commit d43df0c
Show file tree
Hide file tree
Showing 44 changed files with 348 additions and 348 deletions.
2 changes: 1 addition & 1 deletion contracts/protocol-viewers/StreamingFeeModuleViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";


/**
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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";


/**
Expand All @@ -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
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ 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";


/**
* @title AmmModule
* @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;
Expand All @@ -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,
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -240,7 +240,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard {
liquidityTokenDelta,
_components,
componentsDelta
);
);
}

/**
Expand All @@ -262,7 +262,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard {
uint256 _poolTokenPositionUnits,
address _component,
uint256 _minComponentUnitsReceived
)
)
external
nonReentrant
onlyManagerAndValidSet(_setToken)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -426,7 +426,7 @@ contract AmmModule is ModuleBase, ReentrancyGuard {
);
}
}

function _executeAddLiquidity(ActionInfo memory _actionInfo) internal {
(
address targetAmm, uint256 callValue, bytes memory methodData
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,7 +87,7 @@ contract BasicIssuanceModule is ModuleBase, ReentrancyGuard {
ISetToken _setToken,
uint256 _quantity,
address _to
)
)
external
nonReentrant
onlyValidAndInitializedSet(_setToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ 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";


/**
* @title ClaimModule
* @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
Expand Down Expand Up @@ -232,7 +232,7 @@ contract ClaimModule is ModuleBase {
_removeClaim(_setToken, _rewardPools[i], _integrationNames[i]);
}
}

/**
* SET MANAGER ONLY. Initializes this module to the SetToken.
*
Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -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.
*
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit d43df0c

Please sign in to comment.