Verified contractExactGPL-3.0
VaultProxy
Address0xfe68d7e5903f98a79b2d649cd0548a02e8ebdd67
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.6.12
- Same code
1,548 more contracts
Details
- Compiler
- solc 0.6.12+commit.27d51765
- Language
- solidity
- Optimization
- No
- EVM version
- istanbul
- License
- GPL-3.0
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 22,705,131
- Creation transaction
- 0x94ad6f5b04…bc02c6d48e
- Proxy implementation
- 0x891dee04…33468a38VaultLib
- Main copy (most transactions)
- 0x4819ac09…31fa6ab6
138 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/persistent/vault/VaultProxy.solmain2.47 KB
- @openzeppelin/contracts/GSN/Context.sol933 B
- @openzeppelin/contracts/access/Ownable.sol2.23 KB
- @openzeppelin/contracts/math/SafeMath.sol5.2 KB
- @openzeppelin/contracts/math/SignedSafeMath.sol2.66 KB
- @openzeppelin/contracts/token/ERC20/ERC20.sol10.79 KB
- @openzeppelin/contracts/token/ERC20/ERC20Burnable.sol1.17 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.7 KB
- @openzeppelin/contracts/token/ERC20/SafeERC20.sol3.71 KB
- @openzeppelin/contracts/utils/Address.sol5.88 KB
- @openzeppelin/contracts/utils/EnumerableSet.sol7.79 KB
- contracts/mocks/MockVaultLib.sol905 B
- contracts/mocks/adapters/MockGenericAdapter.sol6.22 KB
- contracts/mocks/integratees/MockChaiIntegratee.sol2.12 KB
- contracts/mocks/integratees/MockGenericIntegratee.sol1.32 KB
- contracts/mocks/integratees/MockKyberIntegratee.sol3.86 KB
- contracts/mocks/integratees/MockParaSwapIntegratee.sol3.93 KB
- contracts/mocks/integratees/MockSynthetixIntegratee.sol5.8 KB
- contracts/mocks/integratees/MockUniswapV2Integratee.sol9.59 KB
- contracts/mocks/integratees/compound/MockCEtherIntegratee.sol1.26 KB
- contracts/mocks/integratees/compound/MockCTokenBase.sol3.74 KB
- contracts/mocks/integratees/compound/MockCTokenIntegratee.sol1.39 KB
- contracts/mocks/integratees/utils/MockIntegrateeBase.sol1.6 KB
- contracts/mocks/integratees/utils/SimpleMockIntegrateeBase.sol1.13 KB
- contracts/mocks/prices/CentralizedRateProvider.sol8.27 KB
- contracts/mocks/prices/MockChaiPriceSource.sol925 B
- contracts/mocks/prices/MockChainlinkPriceSource.sol1.25 KB
- contracts/mocks/prices/MockSynthetixPriceSource.sol4.03 KB
- contracts/mocks/prices/MockUniswapV2PriceSource.sol1.92 KB
- contracts/mocks/tokens/MockReentrancyToken.sol1.58 KB
- contracts/mocks/tokens/MockSynthetixToken.sol2.02 KB
- contracts/mocks/tokens/MockToken.sol913 B
- contracts/mocks/utils/EthConstantMixin.sol405 B
- contracts/mocks/utils/NormalizedRateProviderBase.sol1.67 KB
- contracts/mocks/utils/RateProviderBase.sol2.2 KB
- contracts/mocks/utils/SwapperBase.sol2.87 KB
- contracts/persistent/dispatcher/Dispatcher.sol24.68 KB
- contracts/persistent/dispatcher/IDispatcher.sol2.57 KB
- contracts/persistent/utils/IMigratableVault.sol751 B
- contracts/persistent/utils/IMigrationHookHandler.sol904 B
- contracts/persistent/vault/VaultLibBase1.sol979 B
- contracts/persistent/vault/VaultLibBaseCore.sol4.68 KB
- contracts/persistent/vault/utils/ProxiableVaultLib.sol1.75 KB
- contracts/persistent/vault/utils/SharesTokenBase.sol5.38 KB
- contracts/persistent/vault/utils/VaultLibSafeMath.sol2.13 KB
- contracts/release/core/fund-deployer/FundDeployer.sol19.78 KB
- contracts/release/core/fund-deployer/IFundDeployer.sol658 B
- contracts/release/core/fund/comptroller/ComptrollerLib.sol39.06 KB
- contracts/release/core/fund/comptroller/ComptrollerProxy.sol648 B
- contracts/release/core/fund/comptroller/IComptroller.sol1.26 KB
- contracts/release/core/fund/vault/IVault.sol1.29 KB
- contracts/release/core/fund/vault/VaultLib.sol8.88 KB
- contracts/release/extensions/IExtension.sol755 B
- contracts/release/extensions/fee-manager/FeeManager.sol21.61 KB
- contracts/release/extensions/fee-manager/IFee.sol1.67 KB
- contracts/release/extensions/fee-manager/IFeeManager.sol901 B
- contracts/release/extensions/fee-manager/fees/EntranceRateBurnFee.sol907 B
- contracts/release/extensions/fee-manager/fees/EntranceRateDirectFee.sol939 B
- contracts/release/extensions/fee-manager/fees/ManagementFee.sol7.02 KB
- contracts/release/extensions/fee-manager/fees/PerformanceFee.sol19.69 KB
- contracts/release/extensions/fee-manager/fees/utils/EntranceRateFeeBase.sol4.93 KB
- contracts/release/extensions/fee-manager/fees/utils/FeeBase.sol3.05 KB
- contracts/release/extensions/integration-manager/IIntegrationManager.sol522 B
- contracts/release/extensions/integration-manager/IntegrationManager.sol33.88 KB
- contracts/release/extensions/integration-manager/integrations/IIntegrationAdapter.sol989 B
- contracts/release/extensions/integration-manager/integrations/adapters/ChaiAdapter.sol5.83 KB
- contracts/release/extensions/integration-manager/integrations/adapters/CompoundAdapter.sol7.45 KB
- contracts/release/extensions/integration-manager/integrations/adapters/KyberAdapter.sol7.45 KB
- contracts/release/extensions/integration-manager/integrations/adapters/ParaSwapAdapter.sol10.75 KB
- contracts/release/extensions/integration-manager/integrations/adapters/SynthetixAdapter.sol5.95 KB
- contracts/release/extensions/integration-manager/integrations/adapters/TrackedAssetsAdapter.sol3.19 KB
- contracts/release/extensions/integration-manager/integrations/adapters/UniswapV2Adapter.sol12.38 KB
- contracts/release/extensions/integration-manager/integrations/adapters/ZeroExV2Adapter.sol13.77 KB
- contracts/release/extensions/integration-manager/integrations/utils/AdapterBase.sol4.57 KB
- contracts/release/extensions/integration-manager/integrations/utils/IntegrationSelectors.sol1.03 KB
- contracts/release/extensions/policy-manager/IPolicy.sol1.18 KB
- contracts/release/extensions/policy-manager/IPolicyManager.sol768 B
- contracts/release/extensions/policy-manager/PolicyManager.sol13.63 KB
- contracts/release/extensions/policy-manager/policies/buy-shares/BuySharesCallerWhitelist.sol3.66 KB
- contracts/release/extensions/policy-manager/policies/buy-shares/InvestorWhitelist.sol3.63 KB
- contracts/release/extensions/policy-manager/policies/buy-shares/MinMaxInvestment.sol5.39 KB
- contracts/release/extensions/policy-manager/policies/buy-shares/utils/BuySharesSetupPolicyBase.sol1.38 KB
- contracts/release/extensions/policy-manager/policies/buy-shares/utils/PreBuySharesValidatePolicyBase.sol1.41 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/AdapterBlacklist.sol2.5 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/AdapterWhitelist.sol2.5 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/AssetBlacklist.sol3.62 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/AssetWhitelist.sol3.66 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/GuaranteedRedemption.sol10.31 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/MaxConcentration.sol7 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/utils/PostCallOnIntegrationValidatePolicyBase.sol1.67 KB
- contracts/release/extensions/policy-manager/policies/call-on-integration/utils/PreCallOnIntegrationValidatePolicyBase.sol1.34 KB
- contracts/release/extensions/policy-manager/policies/utils/AddressListPolicyMixin.sol2.99 KB
- contracts/release/extensions/policy-manager/policies/utils/PolicyBase.sol1.68 KB
- contracts/release/extensions/utils/ExtensionBase.sol3.17 KB
- contracts/release/extensions/utils/FundDeployerOwnerMixin.sol1.49 KB
- contracts/release/extensions/utils/PermissionedVaultActionMixin.sol4.42 KB
- contracts/release/infrastructure/price-feeds/derivatives/AggregatedDerivativePriceFeed.sol6.82 KB
- contracts/release/infrastructure/price-feeds/derivatives/IAggregatedDerivativePriceFeed.sol563 B
- contracts/release/infrastructure/price-feeds/derivatives/IDerivativePriceFeed.sol683 B
- contracts/release/infrastructure/price-feeds/derivatives/feeds/ChaiPriceFeed.sol2.96 KB
- contracts/release/infrastructure/price-feeds/derivatives/feeds/CompoundPriceFeed.sol4 KB
- contracts/release/infrastructure/price-feeds/derivatives/feeds/SynthetixPriceFeed.sol6.81 KB
- contracts/release/infrastructure/price-feeds/derivatives/feeds/UniswapV2PoolPriceFeed.sol10.62 KB
- contracts/release/infrastructure/price-feeds/derivatives/feeds/WdgldPriceFeed.sol4.72 KB
- contracts/release/infrastructure/price-feeds/primitives/ChainlinkPriceFeed.sol19.13 KB
- contracts/release/infrastructure/price-feeds/primitives/IPrimitivePriceFeed.sol778 B
- contracts/release/infrastructure/price-feeds/utils/UniswapV2PoolTokenValueCalculator.sol7.22 KB
- contracts/release/infrastructure/utils/DispatcherOwnerMixin.sol1.45 KB
- contracts/release/infrastructure/value-interpreter/IValueInterpreter.sol1.01 KB
- contracts/release/infrastructure/value-interpreter/ValueInterpreter.sol8.41 KB
- contracts/release/interfaces/ICERC20.sol822 B
- contracts/release/interfaces/ICEther.sol490 B
- contracts/release/interfaces/IChai.sol614 B
- contracts/release/interfaces/IChainlinkAggregator.sol535 B
- contracts/release/interfaces/IKyberNetworkProxy.sol681 B
- contracts/release/interfaces/IMakerDaoPot.sol666 B
- contracts/release/interfaces/IParaSwapAugustusSwapper.sol929 B
- contracts/release/interfaces/ISynthetix.sol568 B
- contracts/release/interfaces/ISynthetixAddressResolver.sol513 B
- contracts/release/interfaces/ISynthetixExchangeRates.sol492 B
- contracts/release/interfaces/ISynthetixExchanger.sol768 B
- contracts/release/interfaces/ISynthetixProxyERC20.sol465 B
- contracts/release/interfaces/ISynthetixSynth.sol460 B
- contracts/release/interfaces/IUniswapV2Factory.sol621 B
- contracts/release/interfaces/IUniswapV2Pair.sol860 B
- contracts/release/interfaces/IUniswapV2Router2.sol1.12 KB
- contracts/release/interfaces/IWETH.sol462 B
- contracts/release/interfaces/IZeroExV2.sol1.87 KB
- contracts/release/peripheral/FundActionsWrapper.sol4.58 KB
- contracts/release/peripheral/shares-requestors/AuthUserExecutedSharesRequestorFactory.sol4.59 KB
- contracts/release/peripheral/shares-requestors/AuthUserExecutedSharesRequestorLib.sol12.05 KB
- contracts/release/peripheral/shares-requestors/AuthUserExecutedSharesRequestorProxy.sol551 B
- contracts/release/peripheral/shares-requestors/IAuthUserExecutedSharesRequestor.sol471 B
- contracts/release/utils/AddressArrayLib.sol2.61 KB
- contracts/release/utils/AssetFinalityResolver.sol2.66 KB
- contracts/release/utils/MakerDaoMath.sol2.32 KB
- contracts/release/utils/MathHelpers.sol1.4 KB
- contracts/release/utils/Proxy.sol1.94 KB
contracts/release/extensions/fee-manager/fees/PerformanceFee.sol
// SPDX-License-Identifier: GPL-3.0
/*
This file is part of the Enzyme Protocol.
(c) Enzyme Council <[email protected]>
For the full license information, please view the LICENSE
file that was distributed with this source code.
*/
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/math/SignedSafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "../../../core/fund/comptroller/ComptrollerLib.sol";
import "../FeeManager.sol";
import "./utils/FeeBase.sol";
/// @title PerformanceFee Contract
/// @author Enzyme Council <[email protected]>
/// @notice A performance-based fee with configurable rate and crystallization period, using
/// a high watermark
/// @dev This contract assumes that all shares in the VaultProxy are shares outstanding,
/// which is fine for this release. Even if they are not, they are still shares that
/// are only claimable by the fund owner.
contract PerformanceFee is FeeBase {
using SafeMath for uint256;
using SignedSafeMath for int256;
event ActivatedForFund(address indexed comptrollerProxy, uint256 highWaterMark);
event FundSettingsAdded(address indexed comptrollerProxy, uint256 rate, uint256 period);
event LastSharePriceUpdated(
address indexed comptrollerProxy,
uint256 prevSharePrice,
uint256 nextSharePrice
);
event PaidOut(
address indexed comptrollerProxy,
uint256 prevHighWaterMark,
uint256 nextHighWaterMark,
uint256 aggregateValueDue
);
event PerformanceUpdated(
address indexed comptrollerProxy,
uint256 prevAggregateValueDue,
uint256 nextAggregateValueDue,
int256 sharesOutstandingDiff
);
struct FeeInfo {
uint256 rate;
uint256 period;
uint256 activated;
uint256 lastPaid;
uint256 highWaterMark;
uint256 lastSharePrice;
uint256 aggregateValueDue;
}
uint256 private constant RATE_DIVISOR = 10**18;
uint256 private constant SHARE_UNIT = 10**18;
mapping(address => FeeInfo) private comptrollerProxyToFeeInfo;
constructor(address _feeManager) public FeeBase(_feeManager) {}
// EXTERNAL FUNCTIONS
/// @notice Activates the fee for a fund
/// @param _comptrollerProxy The ComptrollerProxy of the fund
function activateForFund(address _comptrollerProxy, address) external override onlyFeeManager {
FeeInfo storage feeInfo = comptrollerProxyToFeeInfo[_comptrollerProxy];
// We must not force asset finality, otherwise funds that have Synths as tracked assets
// would be susceptible to a DoS attack when attempting to migrate to a release that uses
// this fee: an attacker trades a negligible amount of a tracked Synth with the VaultProxy
// as the recipient, thus causing `calcGrossShareValue(true)` to fail.
(uint256 grossSharePrice, bool sharePriceIsValid) = ComptrollerLib(_comptrollerProxy)
.calcGrossShareValue(false);
require(sharePriceIsValid, "activateForFund: Invalid share price");
feeInfo.highWaterMark = grossSharePrice;
feeInfo.lastSharePrice = grossSharePrice;
feeInfo.activated = block.timestamp;
emit ActivatedForFund(_comptrollerProxy, grossSharePrice);
}
/// @notice Add the initial fee settings for a fund
/// @param _comptrollerProxy The ComptrollerProxy of the fund
/// @param _settingsData Encoded settings to apply to the policy for the fund
/// @dev `highWaterMark`, `lastSharePrice`, and `activated` are set during activation
function addFundSettings(address _comptrollerProxy, bytes calldata _settingsData)
external
override
onlyFeeManager
{
(uint256 feeRate, uint256 feePeriod) = abi.decode(_settingsData, (uint256, uint256));
require(feeRate > 0, "addFundSettings: feeRate must be greater than 0");
require(feePeriod > 0, "addFundSettings: feePeriod must be greater than 0");
comptrollerProxyToFeeInfo[_comptrollerProxy] = FeeInfo({
rate: feeRate,
period: feePeriod,
activated: 0,
lastPaid: 0,
highWaterMark: 0,
lastSharePrice: 0,
aggregateValueDue: 0
});
emit FundSettingsAdded(_comptrollerProxy, feeRate, feePeriod);
}
/// @notice Provides a constant string identifier for a fee
/// @return identifier_ The identifier string
function identifier() external pure override returns (string memory identifier_) {
return "PERFORMANCE";
}
/// @notice Gets the hooks that are implemented by the fee
/// @return implementedHooksForSettle_ The hooks during which settle() is implemented
/// @return implementedHooksForUpdate_ The hooks during which update() is implemented
/// @return usesGavOnSettle_ True if GAV is used during the settle() implementation
/// @return usesGavOnUpdate_ True if GAV is used during the update() implementation
/// @dev Used only during fee registration
function implementedHooks()
external
view
override
returns (
IFeeManager.FeeHook[] memory implementedHooksForSettle_,
IFeeManager.FeeHook[] memory implementedHooksForUpdate_,
bool usesGavOnSettle_,
bool usesGavOnUpdate_
)
{
implementedHooksForSettle_ = new IFeeManager.FeeHook[](3);
implementedHooksForSettle_[0] = IFeeManager.FeeHook.Continuous;
implementedHooksForSettle_[1] = IFeeManager.FeeHook.BuySharesSetup;
implementedHooksForSettle_[2] = IFeeManager.FeeHook.PreRedeemShares;
implementedHooksForUpdate_ = new IFeeManager.FeeHook[](3);
implementedHooksForUpdate_[0] = IFeeManager.FeeHook.Continuous;
implementedHooksForUpdate_[1] = IFeeManager.FeeHook.BuySharesCompleted;
implementedHooksForUpdate_[2] = IFeeManager.FeeHook.PreRedeemShares;
return (implementedHooksForSettle_, implementedHooksForUpdate_, true, true);
}
/// @notice Checks whether the shares outstanding for the fee can be paid out, and updates
/// the info for the fee's last payout
/// @param _comptrollerProxy The ComptrollerProxy of the fund
/// @return isPayable_ True if shares outstanding can be paid out
function payout(address _comptrollerProxy, address)
external
override
onlyFeeManager
returns (bool isPayable_)
{
if (!payoutAllowed(_comptrollerProxy)) {
return false;
}
FeeInfo storage feeInfo = comptrollerProxyToFeeInfo[_comptrollerProxy];
feeInfo.lastPaid = block.timestamp;
uint256 prevHighWaterMark = feeInfo.highWaterMark;
uint256 nextHighWaterMark = __calcUint256Max(feeInfo.lastSharePrice, prevHighWaterMark);
uint256 prevAggregateValueDue = feeInfo.aggregateValueDue;
// Update state as necessary
if (prevAggregateValueDue > 0) {
feeInfo.aggregateValueDue = 0;
}
if (nextHighWaterMark > prevHighWaterMark) {
feeInfo.highWaterMark = nextHighWaterMark;
}
emit PaidOut(
_comptrollerProxy,
prevHighWaterMark,
nextHighWaterMark,
prevAggregateValueDue
);
return true;
}
/// @notice Settles the fee and calculates shares due
/// @param _comptrollerProxy The ComptrollerProxy of the fund
/// @param _vaultProxy The VaultProxy of the fund
/// @param _gav The GAV of the fund
/// @return settlementType_ The type of settlement
/// @return (unused) The payer of shares due
/// @return sharesDue_ The amount of shares due
function settle(
address _comptrollerProxy,
address _vaultProxy,
IFeeManager.FeeHook,
bytes calldata,
uint256 _gav
)
external
override
onlyFeeManager
returns (
IFeeManager.SettlementType settlementType_,
address,
uint256 sharesDue_
)
{
if (_gav == 0) {
return (IFeeManager.SettlementType.None, address(0), 0);
}
int256 settlementSharesDue = __settleAndUpdatePerformance(
_comptrollerProxy,
_vaultProxy,
_gav
);
if (settlementSharesDue == 0) {
return (IFeeManager.SettlementType.None, address(0), 0);
} else if (settlementSharesDue > 0) {
// Settle by minting shares outstanding for custody
return (
IFeeManager.SettlementType.MintSharesOutstanding,
address(0),
uint256(settlementSharesDue)
);
} else {
// Settle by burning from shares outstanding
return (
IFeeManager.SettlementType.BurnSharesOutstanding,
address(0),
uint256(-settlementSharesDue)
);
}
}
/// @notice Updates the fee state after all fees have finished settle()
/// @param _comptrollerProxy The ComptrollerProxy of the fund
/// @param _vaultProxy The VaultProxy of the fund
/// @param _hook The FeeHook being executed
/// @param _settlementData Encoded args to use in calculating the settlement
/// @param _gav The GAV of the fund
function update(
address _comptrollerProxy,
address _vaultProxy,
IFeeManager.FeeHook _hook,
bytes calldata _settlementData,
uint256 _gav
) external override onlyFeeManager {
uint256 prevSharePrice = comptrollerProxyToFeeInfo[_comptrollerProxy].lastSharePrice;
uint256 nextSharePrice = __calcNextSharePrice(
_comptrollerProxy,
_vaultProxy,
_hook,
_settlementData,
_gav
);
if (nextSharePrice == prevSharePrice) {
return;
}
comptrollerProxyToFeeInfo[_comptrollerProxy].lastSharePrice = nextSharePrice;
emit LastSharePriceUpdated(_comptrollerProxy, prevSharePrice, nextSharePrice);
}
// PUBLIC FUNCTIONS
/// @notice Checks whether the shares outstanding can be paid out
/// @param _comptrollerProxy The ComptrollerProxy of the fund
/// @return payoutAllowed_ True if the fee payment is due
/// @dev Payout is allowed if fees have not yet been settled in a crystallization period,
/// and at least 1 crystallization period has passed since activation
function payoutAllowed(address _comptrollerProxy) public view returns (bool payoutAllowed_) {
FeeInfo memory feeInfo = comptrollerProxyToFeeInfo[_comptrollerProxy];
uint256 period = feeInfo.period;
uint256 timeSinceActivated = block.timestamp.sub(feeInfo.activated);
// Check if at least 1 crystallization period has passed since activation
if (timeSinceActivated < period) {
return false;
}
// Check that a full crystallization period has passed since the last payout
uint256 timeSincePeriodStart = timeSinceActivated % period;
uint256 periodStart = block.timestamp.sub(timeSincePeriodStart);
return feeInfo.lastPaid < periodStart;
}
// PRIVATE FUNCTIONS
/// @dev Helper to calculate the aggregated value accumulated to a fund since the last
/// settlement (happening at investment/redemption)
/// Validated:
/// _netSharesSupply > 0
/// _sharePriceWithoutPerformance != _prevSharePrice
function __calcAggregateValueDue(
uint256 _netSharesSupply,
uint256 _sharePriceWithoutPerformance,
uint256 _prevSharePrice,
uint256 _prevAggregateValueDue,
uint256 _feeRate,
uint256 _highWaterMark
) private pure returns (uint256) {
int256 superHWMValueSinceLastSettled = (
int256(__calcUint256Max(_highWaterMark, _sharePriceWithoutPerformance)).sub(
int256(__calcUint256Max(_highWaterMark, _prevSharePrice))
)
)
.mul(int256(_netSharesSupply))
.div(int256(SHARE_UNIT));
int256 valueDueSinceLastSettled = superHWMValueSinceLastSettled.mul(int256(_feeRate)).div(
int256(RATE_DIVISOR)
);
return
uint256(
__calcInt256Max(0, int256(_prevAggregateValueDue).add(valueDueSinceLastSettled))
);
}
/// @dev Helper to calculate the max of two int values
function __calcInt256Max(int256 _a, int256 _b) private pure returns (int256) {
if (_a >= _b) {
return _a;
}
return _b;
}
/// @dev Helper to calculate the next `lastSharePrice` value
function __calcNextSharePrice(
address _comptrollerProxy,
address _vaultProxy,
IFeeManager.FeeHook _hook,
bytes memory _settlementData,
uint256 _gav
) private view returns (uint256 nextSharePrice_) {
uint256 denominationAssetUnit = 10 **
uint256(ERC20(ComptrollerLib(_comptrollerProxy).getDenominationAsset()).decimals());
if (_gav == 0) {
return denominationAssetUnit;
}
// Get shares outstanding via VaultProxy balance and calc shares supply to get net shares supply
ERC20 vaultProxyContract = ERC20(_vaultProxy);
uint256 totalSharesSupply = vaultProxyContract.totalSupply();
uint256 nextNetSharesSupply = totalSharesSupply.sub(
vaultProxyContract.balanceOf(_vaultProxy)
);
if (nextNetSharesSupply == 0) {
return denominationAssetUnit;
}
uint256 nextGav = _gav;
// For both Continuous and BuySharesCompleted hooks, _gav and shares supply will not change,
// we only need additional calculations for PreRedeemShares
if (_hook == IFeeManager.FeeHook.PreRedeemShares) {
(, uint256 sharesDecrease) = __decodePreRedeemSharesSettlementData(_settlementData);
// Shares have not yet been burned
nextNetSharesSupply = nextNetSharesSupply.sub(sharesDecrease);
if (nextNetSharesSupply == 0) {
return denominationAssetUnit;
}
// Assets have not yet been withdrawn
uint256 gavDecrease = sharesDecrease
.mul(_gav)
.mul(SHARE_UNIT)
.div(totalSharesSupply)
.div(denominationAssetUnit);
nextGav = nextGav.sub(gavDecrease);
if (nextGav == 0) {
return denominationAssetUnit;
}
}
return nextGav.mul(SHARE_UNIT).div(nextNetSharesSupply);
}
/// @dev Helper to calculate the performance metrics for a fund.
/// Validated:
/// _totalSharesSupply > 0
/// _gav > 0
/// _totalSharesSupply != _totalSharesOutstanding
function __calcPerformance(
address _comptrollerProxy,
uint256 _totalSharesSupply,
uint256 _totalSharesOutstanding,
uint256 _prevAggregateValueDue,
FeeInfo memory feeInfo,
uint256 _gav
) private view returns (uint256 nextAggregateValueDue_, int256 sharesDue_) {
// Use the 'shares supply net shares outstanding' for performance calcs.
// Cannot be 0, as _totalSharesSupply != _totalSharesOutstanding
uint256 netSharesSupply = _totalSharesSupply.sub(_totalSharesOutstanding);
uint256 sharePriceWithoutPerformance = _gav.mul(SHARE_UNIT).div(netSharesSupply);
// If gross share price has not changed, can exit early
uint256 prevSharePrice = feeInfo.lastSharePrice;
if (sharePriceWithoutPerformance == prevSharePrice) {
return (_prevAggregateValueDue, 0);
}
nextAggregateValueDue_ = __calcAggregateValueDue(
netSharesSupply,
sharePriceWithoutPerformance,
prevSharePrice,
_prevAggregateValueDue,
feeInfo.rate,
feeInfo.highWaterMark
);
sharesDue_ = __calcSharesDue(
_comptrollerProxy,
netSharesSupply,
_gav,
nextAggregateValueDue_
);
return (nextAggregateValueDue_, sharesDue_);
}
/// @dev Helper to calculate sharesDue during settlement.
/// Validated:
/// _netSharesSupply > 0
/// _gav > 0
function __calcSharesDue(
address _comptrollerProxy,
uint256 _netSharesSupply,
uint256 _gav,
uint256 _nextAggregateValueDue
) private view returns (int256 sharesDue_) {
// If _nextAggregateValueDue > _gav, then no shares can be created.
// This is a known limitation of the model, which is only reached for unrealistically
// high performance fee rates (> 100%). A revert is allowed in such a case.
uint256 sharesDueForAggregateValueDue = _nextAggregateValueDue.mul(_netSharesSupply).div(
_gav.sub(_nextAggregateValueDue)
);
// Shares due is the +/- diff or the total shares outstanding already minted
return
int256(sharesDueForAggregateValueDue).sub(
int256(
FeeManager(FEE_MANAGER).getFeeSharesOutstandingForFund(
_comptrollerProxy,
address(this)
)
)
);
}
/// @dev Helper to calculate the max of two uint values
function __calcUint256Max(uint256 _a, uint256 _b) private pure returns (uint256) {
if (_a >= _b) {
return _a;
}
return _b;
}
/// @dev Helper to settle the fee and update performance state.
/// Validated:
/// _gav > 0
function __settleAndUpdatePerformance(
address _comptrollerProxy,
address _vaultProxy,
uint256 _gav
) private returns (int256 sharesDue_) {
ERC20 sharesTokenContract = ERC20(_vaultProxy);
uint256 totalSharesSupply = sharesTokenContract.totalSupply();
if (totalSharesSupply == 0) {
return 0;
}
uint256 totalSharesOutstanding = sharesTokenContract.balanceOf(_vaultProxy);
if (totalSharesOutstanding == totalSharesSupply) {
return 0;
}
FeeInfo storage feeInfo = comptrollerProxyToFeeInfo[_comptrollerProxy];
uint256 prevAggregateValueDue = feeInfo.aggregateValueDue;
uint256 nextAggregateValueDue;
(nextAggregateValueDue, sharesDue_) = __calcPerformance(
_comptrollerProxy,
totalSharesSupply,
totalSharesOutstanding,
prevAggregateValueDue,
feeInfo,
_gav
);
if (nextAggregateValueDue == prevAggregateValueDue) {
return 0;
}
// Update fee state
feeInfo.aggregateValueDue = nextAggregateValueDue;
emit PerformanceUpdated(
_comptrollerProxy,
prevAggregateValueDue,
nextAggregateValueDue,
sharesDue_
);
return sharesDue_;
}
///////////////////
// STATE GETTERS //
///////////////////
/// @notice Gets the feeInfo for a given fund
/// @param _comptrollerProxy The ComptrollerProxy contract of the fund
/// @return feeInfo_ The feeInfo
function getFeeInfoForFund(address _comptrollerProxy)
external
view
returns (FeeInfo memory feeInfo_)
{
return comptrollerProxyToFeeInfo[_comptrollerProxy];
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"libraries": {},
"optimizer": {
"runs": 200,
"details": {
"cse": true,
"yul": false,
"peephole": true,
"deduplicate": true,
"orderLiterals": true,
"jumpdestRemover": true,
"constantOptimizer": true
}
},
"evmVersion": "istanbul",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.