Skip to content

Commit

Permalink
Merge pull request #132 from meTokens/chore/inheritance
Browse files Browse the repository at this point in the history
chore: inheritance, import order, natspec
  • Loading branch information
Carter Carlson authored Mar 7, 2022
2 parents 1562488 + 34904d6 commit ec3263e
Show file tree
Hide file tree
Showing 17 changed files with 233 additions and 176 deletions.
2 changes: 1 addition & 1 deletion contracts/Diamond.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pragma solidity 0.8.9;
* Implementation of a diamond.
/******************************************************************************/

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

contract Diamond {
constructor(address firstController, address diamondCutFacet) payable {
Expand Down
8 changes: 4 additions & 4 deletions contracts/DiamondInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
pragma solidity 0.8.9;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IRegistry} from "./interfaces/IRegistry.sol";
import {IMigrationRegistry} from "./interfaces/IMigrationRegistry.sol";
import {IDiamondCut} from "./interfaces/IDiamondCut.sol";
import {IDiamondLoupe} from "./interfaces/IDiamondLoupe.sol";
import {LibDiamond} from "./libs/LibDiamond.sol";
import {IMigrationRegistry} from "./interfaces/IMigrationRegistry.sol";
import {IRegistry} from "./interfaces/IRegistry.sol";
import {AppStorage} from "./libs/LibAppStorage.sol";
import {LibDiamond} from "./libs/LibDiamond.sol";

/// @title Diamond Init
/// @author Carter Carlson (@cartercarlson), @zgorizzo69
/// @notice Contract to initialize state variables, similar to OZ's initilize()
/// @notice Contract to initialize state variables, similar to OZ's initialize()
contract DiamondInit {
struct Args {
uint256 mintFee;
Expand Down
2 changes: 1 addition & 1 deletion contracts/MeToken.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;

import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

/// @title MeToken
/// @author Carter Carlson (@cartercarlson)
Expand Down
4 changes: 2 additions & 2 deletions contracts/facets/FeesFacet.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;

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

contract FeesFacet is Modifiers, IFeesFacet {
contract FeesFacet is IFeesFacet, Modifiers {
/// @inheritdoc IFeesFacet
function setMintFee(uint256 rate) external override onlyFeesController {
require(rate != s.mintFee && rate < s.PRECISION, "out of range");
Expand Down
16 changes: 8 additions & 8 deletions contracts/facets/FoundryFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
pragma solidity 0.8.9;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IVault} from "../interfaces/IVault.sol";
import {IMigration} from "../interfaces/IMigration.sol";
import {IMeToken} from "../interfaces/IMeToken.sol";
import {IFoundryFacet} from "../interfaces/IFoundryFacet.sol";
import {ICurve} from "../interfaces/ICurve.sol";
import {IFoundryFacet} from "../interfaces/IFoundryFacet.sol";
import {IMeToken} from "../interfaces/IMeToken.sol";
import {IMigration} from "../interfaces/IMigration.sol";
import {IVault} from "../interfaces/IVault.sol";

import {LibMeToken, MeTokenInfo} from "../libs/LibMeToken.sol";
import {LibHub, HubInfo} from "../libs/LibHub.sol";
import {LibMeta} from "../libs/LibMeta.sol";
import {LibMeToken, MeTokenInfo} from "../libs/LibMeToken.sol";
import {LibWeightedAverage} from "../libs/LibWeightedAverage.sol";
import {Modifiers} from "../libs/LibAppStorage.sol";
import {LibMeta} from "../libs/LibMeta.sol";

contract FoundryFacet is IFoundryFacet, Modifiers {
// MINT FLOW CHART
Expand All @@ -35,7 +35,7 @@ contract FoundryFacet is IFoundryFacet, Modifiers {
// .sub(fees) //
// //
****************************************************************************/

/// @inheritdoc IFoundryFacet
function mint(
address meToken,
uint256 assetsDeposited,
Expand Down Expand Up @@ -214,6 +214,7 @@ contract FoundryFacet is IFoundryFacet, Modifiers {
);
}

/// @inheritdoc IFoundryFacet
function donate(address meToken, uint256 assetsDeposited)
external
override
Expand All @@ -233,7 +234,6 @@ contract FoundryFacet is IFoundryFacet, Modifiers {
emit Donate(meToken, asset, sender, assetsDeposited);
}

// NOTE: for now this does not include fees
function _calculateMeTokensMinted(address meToken, uint256 assetsDeposited)
private
view
Expand Down
101 changes: 55 additions & 46 deletions contracts/facets/HubFacet.sol
Original file line number Diff line number Diff line change
@@ -1,42 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

import {LibMeta} from "../libs/LibMeta.sol";
import {ICurve} from "../interfaces/ICurve.sol";
import {IFoundryFacet} from "../interfaces/IFoundryFacet.sol";
import {IHubFacet} from "../interfaces/IHubFacet.sol";
import {IRegistry} from "../interfaces/IRegistry.sol";
import {IVault} from "../interfaces/IVault.sol";
import {LibDiamond} from "../libs/LibDiamond.sol";
import {LibHub, HubInfo} from "../libs/LibHub.sol";
import {LibMeta} from "../libs/LibMeta.sol";
import {Modifiers} from "../libs/LibAppStorage.sol";
import {IHubFacet} from "../interfaces/IHubFacet.sol";
import {IVault} from "../interfaces/IVault.sol";
import {IRegistry} from "../interfaces/IRegistry.sol";
import {ICurve} from "../interfaces/ICurve.sol";
import {IFoundryFacet} from "../interfaces/IFoundryFacet.sol";

contract HubFacet is Modifiers {
event Register(
uint256 id,
address owner,
address asset,
address vault,
address curve,
uint256 refundRatio,
bytes encodedCurveInfo,
bytes encodedVaultArgs
);
event Deactivate(uint256 id);
event InitUpdate(
uint256 id,
address targetCurve,
uint256 targetRefundRatio,
bytes encodedCurveInfo,
bool reconfigure,
uint256 startTime,
uint256 endTime,
uint256 endCooldown
);
event FinishUpdate(uint256 id);
event CancelUpdate(uint256 id);
event TransferHubOwnership(uint256 id, address newOwner);

contract HubFacet is IHubFacet, Modifiers {
/// @inheritdoc IHubFacet
function register(
address owner,
address asset,
Expand All @@ -45,7 +21,7 @@ contract HubFacet is Modifiers {
uint256 refundRatio,
bytes memory encodedCurveInfo,
bytes memory encodedVaultArgs
) external onlyRegisterController {
) external override onlyRegisterController {
require(s.curveRegistry.isApproved(address(curve)), "curve !approved");
require(s.vaultRegistry.isApproved(address(vault)), "vault !approved");
require(refundRatio < s.MAX_REFUND_RATIO, "refundRatio > MAX");
Expand Down Expand Up @@ -77,7 +53,8 @@ contract HubFacet is Modifiers {
);
}

function deactivate(uint256 id) external {
/// @inheritdoc IHubFacet
function deactivate(uint256 id) external override {
address sender = LibMeta.msgSender();
HubInfo storage hubInfo = s.hubs[id];
require(
Expand All @@ -89,12 +66,13 @@ contract HubFacet is Modifiers {
emit Deactivate(id);
}

/// @inheritdoc IHubFacet
function initUpdate(
uint256 id,
address targetCurve,
uint256 targetRefundRatio,
bytes memory encodedCurveInfo
) external {
) external override {
HubInfo storage hubInfo = s.hubs[id];
address sender = LibMeta.msgSender();
require(sender == hubInfo.owner, "!owner");
Expand Down Expand Up @@ -160,11 +138,13 @@ contract HubFacet is Modifiers {
);
}

function finishUpdate(uint256 id) external {
/// @inheritdoc IHubFacet
function finishUpdate(uint256 id) external override {
LibHub.finishUpdate(id);
}

function cancelUpdate(uint256 id) external {
/// @inheritdoc IHubFacet
function cancelUpdate(uint256 id) external override {
HubInfo storage hubInfo = s.hubs[id];
address sender = LibMeta.msgSender();
require(sender == hubInfo.owner, "!owner");
Expand All @@ -182,7 +162,11 @@ contract HubFacet is Modifiers {
emit CancelUpdate(id);
}

function transferHubOwnership(uint256 id, address newOwner) external {
/// @inheritdoc IHubFacet
function transferHubOwnership(uint256 id, address newOwner)
external
override
{
HubInfo storage hubInfo = s.hubs[id];
address sender = LibMeta.msgSender();
require(sender == hubInfo.owner, "!owner");
Expand All @@ -192,38 +176,63 @@ contract HubFacet is Modifiers {
emit TransferHubOwnership(id, newOwner);
}

function setHubWarmup(uint256 warmup) external onlyDurationsController {
/// @inheritdoc IHubFacet
function setHubWarmup(uint256 warmup)
external
override
onlyDurationsController
{
require(warmup != s.hubWarmup, "same warmup");
s.hubWarmup = warmup;
}

function setHubDuration(uint256 duration) external onlyDurationsController {
/// @inheritdoc IHubFacet
function setHubDuration(uint256 duration)
external
override
onlyDurationsController
{
require(duration != s.hubDuration, "same duration");
s.hubDuration = duration;
}

function setHubCooldown(uint256 cooldown) external onlyDurationsController {
/// @inheritdoc IHubFacet
function setHubCooldown(uint256 cooldown)
external
override
onlyDurationsController
{
require(cooldown != s.hubCooldown, "same cooldown");
s.hubCooldown = cooldown;
}

function getHubInfo(uint256 id) external view returns (HubInfo memory) {
/// @inheritdoc IHubFacet
function getHubInfo(uint256 id)
external
view
override
returns (HubInfo memory)
{
return LibHub.getHubInfo(id);
}

function count() external view returns (uint256) {
/// @inheritdoc IHubFacet
function count() external view override returns (uint256) {
return s.hubCount;
}

function hubWarmup() external view returns (uint256) {
/// @inheritdoc IHubFacet
function hubWarmup() external view override returns (uint256) {
return LibHub.warmup();
}

function hubDuration() external view returns (uint256) {
/// @inheritdoc IHubFacet
function hubDuration() external view override returns (uint256) {
return LibHub.duration();
}

function hubCooldown() external view returns (uint256) {
/// @inheritdoc IHubFacet
function hubCooldown() external view override returns (uint256) {
return LibHub.cooldown();
}
}
Loading

0 comments on commit ec3263e

Please sign in to comment.