Skip to content

Commit

Permalink
Merge 147f141 into fa1d506
Browse files Browse the repository at this point in the history
  • Loading branch information
alsco77 committed Mar 4, 2021
2 parents fa1d506 + 147f141 commit 20ba6d1
Show file tree
Hide file tree
Showing 21 changed files with 142,760 additions and 138,088 deletions.
6 changes: 4 additions & 2 deletions contracts/feeders/FeederLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ library FeederLogic {
{
// Calculate mAsset redemption quantities
scaledFee = _inputQuantity.mulTruncate(_data.redemptionFee);

// Calc cache and total mAsset circulating
// cache = (config.supply - inputQuantity) * 0.2
uint256 maxCache = _getCacheDetails(_data, _config.supply - _inputQuantity);

// Load the bAsset data from storage into memory
Expand Down Expand Up @@ -716,6 +715,9 @@ library FeederLogic {
scaledSwapFee = ((k1 - k0) * _feeRate) / 1e18;
// 5. Calc output bAsset
uint256 newOutputReserve = _solveInvariant(x, _config.a, _o, k0 + scaledSwapFee);
// Convert swap fee to fpToken terms
// fpFee = fee * s / k
scaledSwapFee = scaledSwapFee * _config.supply / k0;
uint256 output = x[_o] - newOutputReserve - 1;
bAssetOutputQuantity = (output * 1e8) / _bAssets[_o].ratio;
// 6. Check for bounds
Expand Down
51 changes: 50 additions & 1 deletion contracts/feeders/FeederPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ contract FeederPool is
data.swapFee = 8e14;
data.redemptionFee = 4e14;
data.cacheSize = 1e17;
data.govFee = 1e17;
}

/**
Expand Down Expand Up @@ -324,6 +325,11 @@ contract FeederPool is
_recipient
);

uint256 govFee = data.govFee;
if(govFee > 0) {
data.pendingFees += (localFee * govFee / 1e18);
}

emit Swapped(msg.sender, input.addr, output.addr, swapOutput, localFee, _recipient);
}

Expand Down Expand Up @@ -446,6 +452,11 @@ contract FeederPool is
_recipient
);

uint256 govFee = data.govFee;
if(govFee > 0) {
data.pendingFees += (localFee * govFee / 1e18);
}

emit Redeemed(
msg.sender,
_recipient,
Expand Down Expand Up @@ -486,6 +497,11 @@ contract FeederPool is
_recipient
);

uint256 govFee = data.govFee;
if(govFee > 0) {
data.pendingFees += (scaledFee * govFee / 1e18);
}

emit RedeemedMulti(
msg.sender,
_recipient,
Expand Down Expand Up @@ -529,6 +545,10 @@ contract FeederPool is
);

_burn(msg.sender, fpTokenQuantity);
uint256 govFee = data.govFee;
if(govFee > 0) {
data.pendingFees += (localFee * govFee / 1e18);
}

emit RedeemedMulti(
msg.sender,
Expand Down Expand Up @@ -688,7 +708,7 @@ contract FeederPool is
* @dev Gets all config needed for general InvariantValidator calls
*/
function _getConfig() internal view returns (FeederConfig memory) {
return FeederConfig(totalSupply(), _getA(), data.weightLimits);
return FeederConfig(totalSupply() + data.pendingFees, _getA(), data.weightLimits);
}

/**
Expand Down Expand Up @@ -743,10 +763,39 @@ contract FeederPool is
mintAmount = FeederLogic.computeMintMulti(data.bAssetData, idxs, gains, _getConfig());
newSupply = totalSupply() + mintAmount;
require(mintAmount > 0, "Must collect something");

uint256 govFee = data.govFee;
if(govFee > 0) {
data.pendingFees += (mintAmount * govFee / 1e18);
}

// Dummy mint event to catch the collections here
emit MintedMulti(address(this), msg.sender, 0, new address[](0), gains);
}

/**
* @dev Collects the pending gov fees extracted from swap, redeem and platform interest.
*/
function collectPendingFees()
external
onlyInterestValidator
{
uint256 fees = data.pendingFees;
if (fees > 1) {
uint256 mintAmount = fees - 1;
data.pendingFees = 1;

_mint(msg.sender, mintAmount);
emit MintedMulti(
address(this),
msg.sender,
mintAmount,
new address[](0),
new uint256[](0)
);
}
}

/***************************************
STATE
****************************************/
Expand Down
2 changes: 2 additions & 0 deletions contracts/masset/MassetStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct AmpData {
struct FeederData {
uint256 swapFee;
uint256 redemptionFee;
uint256 govFee;
uint256 pendingFees;
uint256 cacheSize;
BassetPersonal[] bAssetPersonal;
BassetData[] bAssetData;
Expand Down
Loading

0 comments on commit 20ba6d1

Please sign in to comment.