Skip to content

Commit

Permalink
Merge pull request #117 from meTokens/revert-113-feat/meta
Browse files Browse the repository at this point in the history
Revert "feat(meta): replace msg.sender"
  • Loading branch information
Carter Carlson authored Feb 16, 2022
2 parents 92d32a4 + 204b720 commit dd32ab8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 55 deletions.
22 changes: 9 additions & 13 deletions contracts/facets/FoundryFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {LibMeToken} from "../libs/LibMeToken.sol";
import {LibHub} from "../libs/LibHub.sol";
import {LibWeightedAverage} from "../libs/LibWeightedAverage.sol";
import "../libs/Details.sol";
import "../libs/LibMeta.sol";

contract FoundryFacet is IFoundry, Modifiers {
// MINT FLOW CHART
Expand Down Expand Up @@ -42,7 +41,6 @@ contract FoundryFacet is IFoundry, Modifiers {
uint256 _assetsDeposited,
address _recipient
) external override {
address sender = LibMeta.msgSender();
MeTokenInfo memory meToken_ = s.meTokens[_meToken];
HubInfo memory hub_ = s.hubs[meToken_.hubId];

Expand Down Expand Up @@ -82,7 +80,7 @@ contract FoundryFacet is IFoundry, Modifiers {
asset = s.hubs[meToken_.targetHubId].asset;
}

vault.handleDeposit(sender, asset, _assetsDeposited, fee);
vault.handleDeposit(msg.sender, asset, _assetsDeposited, fee);

LibMeToken.updateBalancePooled(
true,
Expand All @@ -94,7 +92,7 @@ contract FoundryFacet is IFoundry, Modifiers {
emit Mint(
_meToken,
asset,
sender,
msg.sender,
_recipient,
_assetsDeposited,
meTokensMinted
Expand Down Expand Up @@ -139,7 +137,6 @@ contract FoundryFacet is IFoundry, Modifiers {
uint256 _meTokensBurned,
address _recipient
) external override {
address sender = LibMeta.msgSender();
MeTokenInfo memory meToken_ = s.meTokens[_meToken];
HubInfo memory hub_ = s.hubs[meToken_.hubId];

Expand All @@ -157,7 +154,7 @@ contract FoundryFacet is IFoundry, Modifiers {
_meTokensBurned
);
uint256 assetsReturned = _calculateActualAssetsReturned(
sender,
msg.sender,
_meToken,
_meTokensBurned,
rawAssetsReturned
Expand All @@ -167,19 +164,19 @@ contract FoundryFacet is IFoundry, Modifiers {
// If msg.sender == owner, give owner the sell rate. - all of tokens returned plus a %
// of balancePooled based on how much % of supply will be burned
// If msg.sender != owner, give msg.sender the burn rate
if (sender == meToken_.owner) {
if (msg.sender == meToken_.owner) {
feeRate = s.burnOwnerFee;
} else {
feeRate = s.burnBuyerFee;
}

// Burn metoken from user
IMeToken(_meToken).burn(sender, _meTokensBurned);
IMeToken(_meToken).burn(msg.sender, _meTokensBurned);

// Subtract tokens returned from balance pooled
LibMeToken.updateBalancePooled(false, _meToken, rawAssetsReturned);

if (sender == meToken_.owner) {
if (msg.sender == meToken_.owner) {
// Is owner, subtract from balance locked
LibMeToken.updateBalanceLocked(
false,
Expand Down Expand Up @@ -213,7 +210,7 @@ contract FoundryFacet is IFoundry, Modifiers {
emit Burn(
_meToken,
asset,
sender,
msg.sender,
_recipient,
_meTokensBurned,
assetsReturned
Expand All @@ -224,19 +221,18 @@ contract FoundryFacet is IFoundry, Modifiers {
external
override
{
address sender = LibMeta.msgSender();
MeTokenInfo memory meToken_ = s.meTokens[_meToken];
HubInfo memory hub_ = s.hubs[meToken_.hubId];
require(meToken_.migration == address(0), "meToken resubscribing");

IVault vault = IVault(hub_.vault);
address asset = hub_.asset;

vault.handleDeposit(sender, asset, _assetsDeposited, 0);
vault.handleDeposit(msg.sender, asset, _assetsDeposited, 0);

LibMeToken.updateBalanceLocked(true, _meToken, _assetsDeposited);

emit Donate(_meToken, asset, sender, _assetsDeposited);
emit Donate(_meToken, asset, msg.sender, _assetsDeposited);
}

// NOTE: for now this does not include fees
Expand Down
14 changes: 4 additions & 10 deletions contracts/facets/HubFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ contract HubFacet is Modifiers {

function deactivate(uint256 _id) external {
HubInfo storage hub_ = s.hubs[_id];

address sender = LibMeta.msgSender();
require(
sender == hub_.owner || sender == s.deactivateController,
msg.sender == hub_.owner || msg.sender == s.deactivateController,
"!owner && !deactivateController"
);
require(hub_.active, "!active");
Expand All @@ -104,9 +102,7 @@ contract HubFacet is Modifiers {
bytes memory _encodedCurveDetails
) external {
HubInfo storage hub_ = s.hubs[_id];

address sender = LibMeta.msgSender();
require(sender == hub_.owner, "!owner");
require(msg.sender == hub_.owner, "!owner");
if (hub_.updating && block.timestamp > hub_.endTime) {
LibHub.finishUpdate(_id);
}
Expand Down Expand Up @@ -175,8 +171,7 @@ contract HubFacet is Modifiers {

function cancelUpdate(uint256 _id) external {
HubInfo storage hub_ = s.hubs[_id];
address sender = LibMeta.msgSender();
require(sender == hub_.owner, "!owner");
require(msg.sender == hub_.owner, "!owner");
require(hub_.updating, "!updating");
require(block.timestamp < hub_.startTime, "Update has started");

Expand All @@ -193,8 +188,7 @@ contract HubFacet is Modifiers {

function transferHubOwnership(uint256 _id, address _newOwner) external {
HubInfo storage hub_ = s.hubs[_id];
address sender = LibMeta.msgSender();
require(sender == hub_.owner, "!owner");
require(msg.sender == hub_.owner, "!owner");
require(_newOwner != hub_.owner, "Same owner");
hub_.owner = _newOwner;

Expand Down
61 changes: 29 additions & 32 deletions contracts/facets/MeTokenRegistryFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ contract MeTokenRegistryFacet is Modifiers {
uint256 _hubId,
uint256 _assetsDeposited
) external {
address sender = LibMeta.msgSender();
require(!isOwner(sender), "msg.sender already owns a meToken");
require(!isOwner(msg.sender), "msg.sender already owns a meToken");
HubInfo memory hub_ = s.hubs[_hubId];
require(hub_.active, "Hub inactive");
require(!hub_.updating, "Hub updating");

if (_assetsDeposited > 0) {
require(
IERC20(hub_.asset).transferFrom(
sender,
msg.sender,
hub_.vault,
_assetsDeposited
),
Expand All @@ -90,21 +89,21 @@ contract MeTokenRegistryFacet is Modifiers {
0, // _supply
0 // _balancePooled
);
IMeToken(meTokenAddr).mint(sender, _meTokensMinted);
IMeToken(meTokenAddr).mint(msg.sender, _meTokensMinted);
}

// Register the address which created a meToken
s.meTokenOwners[sender] = meTokenAddr;
s.meTokenOwners[msg.sender] = meTokenAddr;

// Add meToken to registry
// MeTokenInfo storage meToken_ = s.meTokens[meTokenAddr];
s.meTokens[meTokenAddr].owner = sender;
s.meTokens[meTokenAddr].hubId = _hubId;
s.meTokens[meTokenAddr].balancePooled = _assetsDeposited;
MeTokenInfo storage meToken_ = s.meTokens[meTokenAddr];
meToken_.owner = msg.sender;
meToken_.hubId = _hubId;
meToken_.balancePooled = _assetsDeposited;

emit Subscribe(
meTokenAddr,
sender,
msg.sender,
_meTokensMinted,
hub_.asset,
_assetsDeposited,
Expand All @@ -123,8 +122,8 @@ contract MeTokenRegistryFacet is Modifiers {
MeTokenInfo storage meToken_ = s.meTokens[_meToken];
HubInfo memory hub_ = s.hubs[meToken_.hubId];
HubInfo memory targetHub_ = s.hubs[_targetHubId];
address sender = LibMeta.msgSender();
require(sender == meToken_.owner, "!owner");

require(msg.sender == meToken_.owner, "!owner");
require(
block.timestamp >= meToken_.endCooldown,
"Cooldown not complete"
Expand Down Expand Up @@ -181,8 +180,7 @@ contract MeTokenRegistryFacet is Modifiers {

function cancelResubscribe(address _meToken) external {
MeTokenInfo storage meToken_ = s.meTokens[_meToken];
address sender = LibMeta.msgSender();
require(sender == meToken_.owner, "!owner");
require(msg.sender == meToken_.owner, "!owner");
require(meToken_.targetHubId != 0, "!resubscribing");
require(
block.timestamp < meToken_.startTime,
Expand All @@ -199,8 +197,7 @@ contract MeTokenRegistryFacet is Modifiers {

function updateBalances(address _meToken, uint256 _newBalance) external {
MeTokenInfo storage meToken_ = s.meTokens[_meToken];
address sender = LibMeta.msgSender();
require(sender == meToken_.migration, "!migration");
require(msg.sender == meToken_.migration, "!migration");
uint256 balancePooled = meToken_.balancePooled;
uint256 balanceLocked = meToken_.balanceLocked;
uint256 oldBalance = balancePooled + balanceLocked;
Expand All @@ -217,48 +214,48 @@ contract MeTokenRegistryFacet is Modifiers {
}

function transferMeTokenOwnership(address _newOwner) external {
address sender = LibMeta.msgSender();
require(
s.pendingMeTokenOwners[sender] == address(0),
s.pendingMeTokenOwners[msg.sender] == address(0),
"transfer ownership already pending"
);
require(!isOwner(_newOwner), "_newOwner already owns a meToken");
require(_newOwner != address(0), "Cannot transfer to 0 address");
address meToken_ = s.meTokenOwners[sender];
address meToken_ = s.meTokenOwners[msg.sender];
require(meToken_ != address(0), "meToken does not exist");
s.pendingMeTokenOwners[sender] = _newOwner;
s.pendingMeTokenOwners[msg.sender] = _newOwner;

emit TransferMeTokenOwnership(sender, _newOwner, meToken_);
emit TransferMeTokenOwnership(msg.sender, _newOwner, meToken_);
}

function cancelTransferMeTokenOwnership() external {
address sender = LibMeta.msgSender();
address _meToken = s.meTokenOwners[sender];
address _meToken = s.meTokenOwners[msg.sender];
require(_meToken != address(0), "meToken does not exist");

require(
s.pendingMeTokenOwners[sender] != address(0),
s.pendingMeTokenOwners[msg.sender] != address(0),
"transferMeTokenOwnership() not initiated"
);

delete s.pendingMeTokenOwners[sender];
emit CancelTransferMeTokenOwnership(sender, _meToken);
delete s.pendingMeTokenOwners[msg.sender];
emit CancelTransferMeTokenOwnership(msg.sender, _meToken);
}

function claimMeTokenOwnership(address _oldOwner) external {
address sender = LibMeta.msgSender();
require(!isOwner(sender), "Already owns a meToken");
require(sender == s.pendingMeTokenOwners[_oldOwner], "!_pendingOwner");
require(!isOwner(msg.sender), "Already owns a meToken");
require(
msg.sender == s.pendingMeTokenOwners[_oldOwner],
"!_pendingOwner"
);

address _meToken = s.meTokenOwners[_oldOwner];

s.meTokens[_meToken].owner = sender;
s.meTokenOwners[sender] = _meToken;
s.meTokens[_meToken].owner = msg.sender;
s.meTokenOwners[msg.sender] = _meToken;

delete s.meTokenOwners[_oldOwner];
delete s.pendingMeTokenOwners[_oldOwner];

emit ClaimMeTokenOwnership(_oldOwner, sender, _meToken);
emit ClaimMeTokenOwnership(_oldOwner, msg.sender, _meToken);
}

function setMeTokenWarmup(uint256 _warmup)
Expand Down

0 comments on commit dd32ab8

Please sign in to comment.