Skip to content

Commit

Permalink
Merge pull request #43 from meTokens/fix/events
Browse files Browse the repository at this point in the history
Fix/events
  • Loading branch information
Carl Farterson authored Nov 9, 2021
2 parents 6066b78 + 9410b9f commit ab1185c
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .solhintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
rules: {
"prettier/prettier": "error",
"code-complexity": ["error", 10],
"function-max-lines": ["error", 100],
"function-max-lines": ["error", 110],
"max-line-length": ["error", 140],
"max-states-count": ["error", 20],
"no-empty-blocks": "off",
Expand Down
122 changes: 61 additions & 61 deletions contracts/Foundry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,67 @@ contract Foundry is IFoundry, Ownable, Initializable {
IERC20(_asset).approve(_vault, type(uint256).max);
}

function viewBurn(
address _sender,
address _meToken,
uint256 _meTokensBurned
) external view returns (uint256 actualtokensReturned) {
Details.MeToken memory meToken_ = meTokenRegistry.getDetails(_meToken);
Details.Hub memory hub_ = hub.getDetails(meToken_.hubId);

// Calculate how many tokens tokens are returned
uint256 tokensReturned = calculateBurnReturn(_meToken, _meTokensBurned);

uint256 feeRate;
uint256 actualTokensReturned;
// 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) {
feeRate = fees.burnOwnerFee();
actualTokensReturned =
tokensReturned +
(((PRECISION * _meTokensBurned) /
IERC20(_meToken).totalSupply()) * meToken_.balanceLocked) /
PRECISION;
} else {
feeRate = fees.burnBuyerFee();
if (hub_.targetRefundRatio == 0 && meToken_.targetHubId == 0) {
// Not updating targetRefundRatio or resubscribing
actualTokensReturned =
(tokensReturned * hub_.refundRatio) /
MAX_REFUND_RATIO;
} else {
if (hub_.targetRefundRatio > 0) {
// Hub is updating
actualTokensReturned =
(tokensReturned *
WeightedAverage.calculate(
hub_.refundRatio,
hub_.targetRefundRatio,
hub_.startTime,
hub_.endTime
)) /
MAX_REFUND_RATIO;
} else {
// meToken is resubscribing
Details.Hub memory targetHub_ = hub.getDetails(
meToken_.targetHubId
);
actualTokensReturned =
(tokensReturned *
WeightedAverage.calculate(
hub_.refundRatio,
targetHub_.refundRatio,
meToken_.startTime,
meToken_.endTime
)) /
MAX_REFUND_RATIO;
}
}
}
}

// NOTE: for now this does not include fees
function calculateMintReturn(address _meToken, uint256 _tokensDeposited)
public
Expand Down Expand Up @@ -296,67 +357,6 @@ contract Foundry is IFoundry, Ownable, Initializable {
}
}

function viewBurn(
address _sender,
address _meToken,
uint256 _meTokensBurned
) external view returns (uint256 actualtokensReturned) {
Details.MeToken memory meToken_ = meTokenRegistry.getDetails(_meToken);
Details.Hub memory hub_ = hub.getDetails(meToken_.hubId);

// Calculate how many tokens tokens are returned
uint256 tokensReturned = calculateBurnReturn(_meToken, _meTokensBurned);

uint256 feeRate;
uint256 actualTokensReturned;
// 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) {
feeRate = fees.burnOwnerFee();
actualTokensReturned =
tokensReturned +
(((PRECISION * _meTokensBurned) /
IERC20(_meToken).totalSupply()) * meToken_.balanceLocked) /
PRECISION;
} else {
feeRate = fees.burnBuyerFee();
if (hub_.targetRefundRatio == 0 && meToken_.targetHubId == 0) {
// Not updating targetRefundRatio or resubscribing
actualTokensReturned =
(tokensReturned * hub_.refundRatio) /
MAX_REFUND_RATIO;
} else {
if (hub_.targetRefundRatio > 0) {
// Hub is updating
actualTokensReturned =
(tokensReturned *
WeightedAverage.calculate(
hub_.refundRatio,
hub_.targetRefundRatio,
hub_.startTime,
hub_.endTime
)) /
MAX_REFUND_RATIO;
} else {
// meToken is resubscribing
Details.Hub memory targetHub_ = hub.getDetails(
meToken_.targetHubId
);
actualTokensReturned =
(tokensReturned *
WeightedAverage.calculate(
hub_.refundRatio,
targetHub_.refundRatio,
meToken_.startTime,
meToken_.endTime
)) /
MAX_REFUND_RATIO;
}
}
}
}

function calculateBurnReturn(address _meToken, uint256 _meTokensBurned)
public
view
Expand Down
110 changes: 69 additions & 41 deletions contracts/interfaces/IMeTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,104 @@ pragma solidity ^0.8.0;
import "../libs/Details.sol";

interface IMeTokenRegistry {
event Register(
address indexed meToken,
address indexed owner,
string name,
string symbol,
uint256 hubId
event Subscribe(
address indexed _meToken,
address indexed _owner,
string _name,
string _symbol,
uint256 _hubId
);
event TransferMeTokenOwnership(address from, address to, address meToken);
event UpdateBalancePooled(bool add, address meToken, uint256 amount);
event UpdateBalanceLocked(bool add, address meToken, uint256 amount);

function updateBalances(address _meToken, uint256 _newBalance) external;

function initResubscribe(
address _meToken,
event InitResubscribe(
address indexed _meToken,
uint256 _targetHubId,
address _migration
) external;

function finishResubscribe(address _meToken)
external
returns (Details.MeToken memory);
address _migration,
bytes _encodedMigrationArgs
);
event FinishResubscribe(address indexed _meToken);
event UpdateBalances(address _meToken, uint256 _newBalance);
event TransferMeTokenOwnership(
address _from,
address _to,
address _meToken
);
event UpdateBalancePooled(bool add, address _meToken, uint256 _amount);
event UpdateBalanceLocked(bool add, address _meToken, uint256 _amount);

/// @notice TODO
/// @param _name TODO
/// @param _symbol TODO
/// @param _hubId TODO
/// @param _tokensDeposited TODO
/// @param _assetsDeposited TODO
function subscribe(
string calldata _name,
string calldata _symbol,
uint256 _hubId,
uint256 _tokensDeposited
uint256 _assetsDeposited
) external;

// /// @notice TODO
// /// @return TODO
// function toggleUpdating() external returns (bool);

/// @notice TODO
/// @param _owner TODO
/// @return TODO
function isOwner(address _owner) external view returns (bool);
/// @param _meToken TODO
/// @param _targetHubId TODO
/// @param _migration TODO
/// @param _encodedMigrationArgs TODO
function initResubscribe(
address _meToken,
uint256 _targetHubId,
address _migration,
bytes memory _encodedMigrationArgs
) external;

/// @notice TODO
/// @param _owner TODO
/// @param _meToken TODO
/// @return TODO
function getOwnerMeToken(address _owner) external view returns (address);

/// @notice TODO
/// @param meToken Address of meToken queried
/// @return meToken_ details of the meToken
function getDetails(address meToken)
function finishResubscribe(address _meToken)
external
view
returns (Details.MeToken memory meToken_);

function transferMeTokenOwnership(address _newOwner) external;
returns (Details.MeToken memory);

// function updateBalances(address _meToken) external;
/// @notice TODO
/// @param _meToken TODO
/// @param _newBalance TODO
function updateBalances(address _meToken, uint256 _newBalance) external;

/// @notice TODO
/// @param add TODO
/// @param _meToken TODO
/// @param _amount TODO
function updateBalancePooled(
bool add,
address _meToken,
uint256 _amount
) external;

/// @notice TODO
/// @param add TODO
/// @param _meToken TODO
/// @param _amount TODO
function updateBalanceLocked(
bool add,
address _meToken,
uint256 _amount
) external;

/// @notice TODO
/// @param _newOwner TODO
function transferMeTokenOwnership(address _newOwner) external;

/// @notice TODO
/// @param _owner TODO
/// @return TODO
function getOwnerMeToken(address _owner) external view returns (address);

/// @notice TODO
/// @param meToken Address of meToken queried
/// @return meToken_ details of the meToken
function getDetails(address meToken)
external
view
returns (Details.MeToken memory meToken_);

/// @notice TODO
/// @param _owner TODO
/// @return TODO
function isOwner(address _owner) external view returns (bool);
}
Loading

0 comments on commit ab1185c

Please sign in to comment.