Skip to content

Commit

Permalink
refactor: mainnet cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pegahcarter committed Sep 20, 2022
1 parent c37ee59 commit dc65269
Show file tree
Hide file tree
Showing 34 changed files with 305 additions and 191 deletions.
21 changes: 9 additions & 12 deletions contracts/Diamond.sol
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

/******************************************************************************\
* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
*
* Implementation of a diamond.
/******************************************************************************/

import {IDiamondCut} from "./interfaces/IDiamondCut.sol";
import {IDiamondCutFacet} from "./interfaces/IDiamondCutFacet.sol";
import {LibAppStorage} from "./libs/LibAppStorage.sol";
import {LibDiamond} from "./libs/LibDiamond.sol";

/// @title MeTokens protocol Diamond
/// @author Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)
/// @notice The meTokens protocol core proxy contract.
contract Diamond {
constructor(address firstController, address diamondCutFacet) payable {
LibAppStorage.initControllers(firstController);

// Add the diamondCut external function from the diamondCutFacet
IDiamondCut.FacetCut[] memory cut = new IDiamondCut.FacetCut[](1);
IDiamondCutFacet.FacetCut[]
memory cut = new IDiamondCutFacet.FacetCut[](1);
bytes4[] memory functionSelectors = new bytes4[](1);
functionSelectors[0] = IDiamondCut.diamondCut.selector;
cut[0] = IDiamondCut.FacetCut({
functionSelectors[0] = IDiamondCutFacet.diamondCut.selector;
cut[0] = IDiamondCutFacet.FacetCut({
facetAddress: diamondCutFacet,
action: IDiamondCut.FacetCutAction.Add,
action: IDiamondCutFacet.FacetCutAction.Add,
functionSelectors: functionSelectors
});
LibDiamond.diamondCut(cut, address(0), "");
Expand Down
6 changes: 3 additions & 3 deletions contracts/DiamondInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.9;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IDiamondCut} from "./interfaces/IDiamondCut.sol";
import {IDiamondCutFacet} from "./interfaces/IDiamondCutFacet.sol";
import {IDiamondLoupeFacet} from "./interfaces/IDiamondLoupeFacet.sol";
import {IMigrationRegistry} from "./interfaces/IMigrationRegistry.sol";
import {IVaultRegistry} from "./interfaces/IVaultRegistry.sol";
Expand All @@ -13,7 +13,7 @@ import {LibCurve} from "./libs/LibCurve.sol";
import {ABDKMathQuad} from "./utils/ABDKMathQuad.sol";

/// @title Diamond Init
/// @author Carter Carlson (@cartercarlson), @zgorizzo69
/// @author Carter Carlson (@cartercarlson), @zgorizzo69, @mudgen
/// @notice Contract to initialize state variables, similar to OZ's initialize()
contract DiamondInit {
using ABDKMathQuad for uint256;
Expand Down Expand Up @@ -55,7 +55,7 @@ contract DiamondInit {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();

// Adding erc165 data
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondCutFacet).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondLoupeFacet).interfaceId] = true;
ds.supportedInterfaces[type(IERC165).interfaceId] = true;

Expand Down
1 change: 1 addition & 0 deletions contracts/facets/CurveFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ICurveFacet} from "../interfaces/ICurveFacet.sol";

/// @title MeTokens Curve Facet
/// @author @cartercarlson, @zgorizzo69, @cbobrobison, @parv3213
/// @notice This contract provides direct views to the meTokens Protocol curve.
contract CurveFacet is Modifiers, ICurveFacet {
/// @inheritdoc ICurveFacet
function viewMeTokensMinted(
Expand Down
11 changes: 3 additions & 8 deletions contracts/facets/DiamondCutFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ pragma solidity 0.8.9;
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/

import {IDiamondCut} from "../interfaces/IDiamondCut.sol";
import {IDiamondCutFacet} from "../interfaces/IDiamondCutFacet.sol";
import {LibDiamond} from "../libs/LibDiamond.sol";
import {Modifiers} from "../libs/LibAppStorage.sol";

contract DiamondCutFacet is IDiamondCut, Modifiers {
/// @notice Add/replace/remove any number of functions and optionally execute
/// a function with delegatecall
/// @param cut Contains the facet addresses and function selectors
/// @param init The address of the contract or facet to execute calldata
/// @param data A function call, including function selector and arguments
/// calldata is executed with delegatecall on init
contract DiamondCutFacet is IDiamondCutFacet, Modifiers {
/// @inheritdoc IDiamondCutFacet
function diamondCut(
FacetCut[] calldata cut,
address init,
Expand Down
2 changes: 1 addition & 1 deletion contracts/facets/FeesFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Modifiers} from "../libs/LibAppStorage.sol";

/// @title meTokens Fees Facet
/// @author @cartercarlson, @parv3213
/// @notice This contract defines the fee structure for meTokens protocol
/// @notice This contract defines the fee structure for meTokens Protocol
contract FeesFacet is IFeesFacet, Modifiers {
/// @inheritdoc IFeesFacet
function setMintFee(uint256 rate) external override onlyFeesController {
Expand Down
14 changes: 7 additions & 7 deletions contracts/facets/FoundryFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {IVault} from "../interfaces/IVault.sol";

/// @title meTokens Foundry Facet
/// @author @cartercarlson, @parv3213
/// @notice This contract manages all minting / burning for meTokens protocol
/// @notice This contract manages all minting / burning for meTokens Protocol
contract FoundryFacet is IFoundryFacet, Modifiers {
/// @inheritdoc IFoundryFacet
function mint(
address meToken,
uint256 assetsDeposited,
address recipient
) external override {
LibFoundry.mint(meToken, assetsDeposited, recipient);
) external override returns (uint256 meTokensMinted) {
meTokensMinted = LibFoundry.mint(meToken, assetsDeposited, recipient);
}

/// @inheritdoc IFoundryFacet
Expand All @@ -31,8 +31,8 @@ contract FoundryFacet is IFoundryFacet, Modifiers {
uint8 vSig,
bytes32 rSig,
bytes32 sSig
) external override {
LibFoundry.mintWithPermit(
) external override returns (uint256 meTokensMinted) {
meTokensMinted = LibFoundry.mintWithPermit(
meToken,
assetsDeposited,
recipient,
Expand All @@ -48,8 +48,8 @@ contract FoundryFacet is IFoundryFacet, Modifiers {
address meToken,
uint256 meTokensBurned,
address recipient
) external override {
LibFoundry.burn(meToken, meTokensBurned, recipient);
) external override returns (uint256 assetsReturned) {
assetsReturned = LibFoundry.burn(meToken, meTokensBurned, recipient);
}

/// @inheritdoc IFoundryFacet
Expand Down
25 changes: 24 additions & 1 deletion contracts/facets/HubFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Modifiers} from "../libs/LibAppStorage.sol";

/// @title meTokens Hub Facet
/// @author @cartercarlson, @zgorizzo69, @parv3213
/// @notice This contract manages all hub configurations for meTokens protocol
/// @notice This contract manages all hub configurations for meTokens Protocol
contract HubFacet is IHubFacet, Modifiers {
/// @inheritdoc IHubFacet
function register(
Expand Down Expand Up @@ -198,6 +198,29 @@ contract HubFacet is IHubFacet, Modifiers {
s.hubCooldown = cooldown;
}

/// @inheritdoc IHubFacet
function getBasicHubInfo(uint256 id)
external
view
override
returns (
uint256 refundRatio,
address owner,
address vault,
address asset,
bool updating,
bool active
)
{
HubInfo storage hubInfo = s.hubs[id];
refundRatio = hubInfo.refundRatio;
owner = hubInfo.owner;
vault = hubInfo.vault;
asset = hubInfo.asset;
updating = hubInfo.updating;
active = hubInfo.active;
}

/// @inheritdoc IHubFacet
function getHubInfo(uint256 id)
external
Expand Down
50 changes: 34 additions & 16 deletions contracts/facets/MeTokenRegistryFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ pragma solidity 0.8.9;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IHubFacet} from "../interfaces/IHubFacet.sol";
import {IMeToken} from "../interfaces/IMeToken.sol";
import {IMeTokenFactory} from "../interfaces/IMeTokenFactory.sol";
import {IMeTokenRegistryFacet} from "../interfaces/IMeTokenRegistryFacet.sol";
import {IMigration} from "../interfaces/IMigration.sol";
import {IMigrationRegistry} from "../interfaces/IMigrationRegistry.sol";
import {IVault} from "../interfaces/IVault.sol";
import {LibCurve} from "../libs/LibCurve.sol";
import {LibDiamond} from "../libs/LibDiamond.sol";
import {LibHub, HubInfo} from "../libs/LibHub.sol";
import {HubInfo} from "../libs/LibHub.sol";
import {LibMeta} from "../libs/LibMeta.sol";
import {LibMeToken, MeTokenInfo} from "../libs/LibMeToken.sol";
import {Modifiers} from "../libs/LibAppStorage.sol";

/// @title meTokens Registry Facet
/// @author @cbobrobison, @cartercarlson, @zgorizzo69, @parv3213
/// @notice This contract tracks info about a meToken within meTokens protocol
/// @notice This contract tracks info about a meToken within meTokens Protocol
contract MeTokenRegistryFacet is IMeTokenRegistryFacet, Modifiers {
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -243,29 +240,50 @@ contract MeTokenRegistryFacet is IMeTokenRegistryFacet, Modifiers {
}

/// @inheritdoc IMeTokenRegistryFacet
function setMeTokenWarmup(uint256 warmup) external onlyDurationsController {
require(warmup != s.meTokenWarmup, "same warmup");
require(warmup + s.meTokenDuration < s.hubWarmup, "too long");
s.meTokenWarmup = warmup;
function setMeTokenWarmup(uint256 period) external onlyDurationsController {
require(period != s.meTokenWarmup, "same warmup");
require(period + s.meTokenDuration < s.hubWarmup, "too long");
s.meTokenWarmup = period;
}

/// @inheritdoc IMeTokenRegistryFacet
function setMeTokenDuration(uint256 duration)
function setMeTokenDuration(uint256 period)
external
onlyDurationsController
{
require(duration != s.meTokenDuration, "same duration");
require(s.meTokenWarmup + duration < s.hubWarmup, "too long");
s.meTokenDuration = duration;
require(period != s.meTokenDuration, "same duration");
require(s.meTokenWarmup + period < s.hubWarmup, "too long");
s.meTokenDuration = period;
}

/// @inheritdoc IMeTokenRegistryFacet
function setMeTokenCooldown(uint256 cooldown)
function setMeTokenCooldown(uint256 period)
external
onlyDurationsController
{
require(cooldown != s.meTokenCooldown, "same cooldown");
s.meTokenCooldown = cooldown;
require(period != s.meTokenCooldown, "same cooldown");
s.meTokenCooldown = period;
}

/// @inheritdoc IMeTokenRegistryFacet
function getBasicMeTokenInfo(address meToken)
external
view
override
returns (
address owner,
uint256 hubId,
uint256 balancePooled,
uint256 balanceLocked,
address migration
)
{
MeTokenInfo storage meTokenInfo = s.meTokens[meToken];
owner = meTokenInfo.owner;
hubId = meTokenInfo.hubId;
balancePooled = meTokenInfo.balancePooled;
balanceLocked = meTokenInfo.balanceLocked;
migration = meTokenInfo.migration;
}

/// @inheritdoc IMeTokenRegistryFacet
Expand Down
29 changes: 15 additions & 14 deletions contracts/facets/OwnershipFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ pragma solidity 0.8.9;

import {LibDiamond} from "../libs/LibDiamond.sol";
import {Modifiers} from "../libs/LibAppStorage.sol";
import {IOwnershipFacet} from "../interfaces/IOwnershipFacet.sol";

/// @title meTokens Ownership Facet
/// @author @cartercarlson, @zgorizzo69, @parv3213
/// @notice This contract provides access control for meTokens protocol
contract OwnershipFacet is Modifiers {
/// @notice This contract provides access control for meTokens Protocol
contract OwnershipFacet is Modifiers, IOwnershipFacet {
/// @inheritdoc IOwnershipFacet
function setDiamondController(address newController)
external
onlyDiamondController
Expand All @@ -16,6 +18,7 @@ contract OwnershipFacet is Modifiers {
s.diamondController = newController;
}

/// @inheritdoc IOwnershipFacet
function setTrustedForwarder(address forwarder)
external
onlyDiamondController
Expand All @@ -24,6 +27,7 @@ contract OwnershipFacet is Modifiers {
s.trustedForwarder = forwarder;
}

/// @inheritdoc IOwnershipFacet
function setFeesController(address newController)
external
onlyFeesController
Expand All @@ -32,6 +36,7 @@ contract OwnershipFacet is Modifiers {
s.feesController = newController;
}

/// @inheritdoc IOwnershipFacet
function setDurationsController(address newController)
external
onlyDurationsController
Expand All @@ -40,14 +45,7 @@ contract OwnershipFacet is Modifiers {
s.durationsController = newController;
}

function setMeTokenRegistryController(address newController)
external
onlyMeTokenRegistryController
{
_sameAsPreviousError(s.meTokenRegistryController, newController);
s.meTokenRegistryController = newController;
}

/// @inheritdoc IOwnershipFacet
function setRegisterController(address newController)
external
onlyRegisterController
Expand All @@ -56,6 +54,7 @@ contract OwnershipFacet is Modifiers {
s.registerController = newController;
}

/// @inheritdoc IOwnershipFacet
function setDeactivateController(address newController)
external
onlyDeactivateController
Expand All @@ -64,30 +63,32 @@ contract OwnershipFacet is Modifiers {
s.deactivateController = newController;
}

/// @inheritdoc IOwnershipFacet
function trustedForwarder() external view returns (address) {
return s.trustedForwarder;
}

/// @inheritdoc IOwnershipFacet
function diamondController() external view returns (address) {
return s.diamondController;
}

/// @inheritdoc IOwnershipFacet
function feesController() external view returns (address) {
return s.feesController;
}

/// @inheritdoc IOwnershipFacet
function durationsController() external view returns (address) {
return s.durationsController;
}

function meTokenRegistryController() external view returns (address) {
return s.meTokenRegistryController;
}

/// @inheritdoc IOwnershipFacet
function registerController() external view returns (address) {
return s.registerController;
}

/// @inheritdoc IOwnershipFacet
function deactivateController() external view returns (address) {
return s.deactivateController;
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/interfaces/ICurveFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity 0.8.9;

import {LibCurve} from "../libs/LibCurve.sol";

/// @title Curve Facet interface
/// @title meTokens Protocol Curve Facet interface
/// @author Carter Carlson (@cartercarlson), @zgorizzo69
interface ICurveFacet {
/// @notice Get curveInfo for a hub
/// @param hubId Unique hub identifier
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IDiamondCut.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma solidity 0.8.9;
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/

interface IDiamondCut {
interface IDiamondCutFacet {
enum FacetCutAction {
Add,
Replace,
Expand Down
Loading

0 comments on commit dc65269

Please sign in to comment.