Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: add version to managed pool. #2075

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkg/pool-weighted/contracts/managed/ManagedPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,25 @@ contract ManagedPool is ManagedPoolSettings {
bufferPeriodDuration,
owner
)
ManagedPoolSettings(params, protocolFeeProvider)
ManagedPoolSettings(_extractSettings(params), protocolFeeProvider)
{
_weightedMath = weightedMath;
}

function _extractSettings(NewPoolParams memory params) private pure returns (PoolSettings memory) {
return PoolSettings({
tokens: params.tokens,
normalizedWeights: params.normalizedWeights,
assetManagers: params.assetManagers,
swapFeePercentage: params.swapFeePercentage,
swapEnabledOnStart: params.swapEnabledOnStart,
mustAllowlistLPs: params.mustAllowlistLPs,
managementAumFeePercentage: params.managementAumFeePercentage,
aumFeeId: params.aumFeeId,
version: params.version
});
}

function _getWeightedMath() internal view returns (IExternalWeightedMath) {
return _weightedMath;
}
Expand Down
34 changes: 25 additions & 9 deletions pkg/pool-weighted/contracts/managed/ManagedPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-pool-utils/contracts/factories/BasePoolFactory.sol";
import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeePercentagesProvider.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-utils/IFactoryCreatedPoolVersion.sol";

import "@balancer-labs/v2-pool-utils/contracts/factories/BasePoolFactory.sol";
import "@balancer-labs/v2-pool-utils/contracts/factories/FactoryWidePauseWindow.sol";
import "@balancer-labs/v2-pool-utils/contracts/Version.sol";

import "./ManagedPool.sol";
import "../ExternalWeightedMath.sol";
Expand All @@ -34,27 +37,40 @@ import "../ExternalWeightedMath.sol";
* In this design, other client-specific factories will deploy a contract, then call this factory
* to deploy the pool, passing in that contract address as the owner.
*/
contract ManagedPoolFactory is BasePoolFactory, FactoryWidePauseWindow {
contract ManagedPoolFactory is IFactoryCreatedPoolVersion, Version, BasePoolFactory, FactoryWidePauseWindow {
IExternalWeightedMath private immutable _weightedMath;
string private _poolVersion;

constructor(IVault vault, IProtocolFeePercentagesProvider protocolFeeProvider)
BasePoolFactory(vault, protocolFeeProvider, type(ManagedPool).creationCode)
{
constructor(
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
string memory factoryVersion,
string memory poolVersion
) BasePoolFactory(vault, protocolFeeProvider, type(ManagedPool).creationCode) Version(factoryVersion) {
_weightedMath = new ExternalWeightedMath();
_poolVersion = poolVersion;
}

function getWeightedMath() external view returns (IExternalWeightedMath) {
return _weightedMath;
}

function getPoolVersion() public view override returns (string memory) {
return _poolVersion;
}

/**
* @dev Deploys a new `ManagedPool`. The owner should be a contract, deployed by another factory.
*
* The pool version in the arguments will be overridden by the pool version stored at contract creation time.
* The version is bundled in the parameters so as to prevent stack too deep errors.
*/
function create(ManagedPoolSettings.NewPoolParams memory poolParams, address owner)
external
returns (address pool)
{
function create(
ManagedPoolSettings.NewPoolParams memory poolParams,
address owner
) external returns (address pool) {
(uint256 pauseWindowDuration, uint256 bufferPeriodDuration) = getPauseConfiguration();
poolParams.version = getPoolVersion();

return
_create(
Expand Down
26 changes: 24 additions & 2 deletions pkg/pool-weighted/contracts/managed/ManagedPoolSettings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/pool-weighted/WeightedPoolUserData.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-utils/IManagedPool.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersion.sol";
import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeePercentagesProvider.sol";

import "@balancer-labs/v2-solidity-utils/contracts/helpers/ERC20Helpers.sol";
Expand All @@ -41,7 +42,7 @@ import "./ManagedPoolAddRemoveTokenLib.sol";
/**
* @title Managed Pool Settings
*/
abstract contract ManagedPoolSettings is NewBasePool, ProtocolFeeCache, IManagedPool {
abstract contract ManagedPoolSettings is IVersion, NewBasePool, ProtocolFeeCache, IManagedPool {
// ManagedPool weights and swap fees can change over time: these periods are expected to be long enough (e.g. days)
// that any timestamp manipulation would achieve very little.
// solhint-disable not-rely-on-time
Expand Down Expand Up @@ -91,6 +92,8 @@ abstract contract ManagedPoolSettings is NewBasePool, ProtocolFeeCache, IManaged
// If mustAllowlistLPs is enabled, this is the list of addresses allowed to join the pool
mapping(address => bool) private _allowedAddresses;

string private _version;

struct NewPoolParams {
string name;
string symbol;
Expand All @@ -102,14 +105,29 @@ abstract contract ManagedPoolSettings is NewBasePool, ProtocolFeeCache, IManaged
bool mustAllowlistLPs;
uint256 managementAumFeePercentage;
uint256 aumFeeId;
string version;
}

struct PoolSettings {
IERC20[] tokens;
uint256[] normalizedWeights;
address[] assetManagers;
uint256 swapFeePercentage;
bool swapEnabledOnStart;
bool mustAllowlistLPs;
uint256 managementAumFeePercentage;
uint256 aumFeeId;
string version;
}

constructor(NewPoolParams memory params, IProtocolFeePercentagesProvider protocolFeeProvider)
constructor(PoolSettings memory params, IProtocolFeePercentagesProvider protocolFeeProvider)
ProtocolFeeCache(
protocolFeeProvider,
ProviderFeeIDs({ swap: ProtocolFeeType.SWAP, yield: ProtocolFeeType.YIELD, aum: params.aumFeeId })
)
{
_version = params.version;

uint256 totalTokens = params.tokens.length;
_require(totalTokens >= _MIN_TOKENS, Errors.MIN_TOKENS);
_require(totalTokens <= _MAX_TOKENS, Errors.MAX_TOKENS);
Expand Down Expand Up @@ -149,6 +167,10 @@ abstract contract ManagedPoolSettings is NewBasePool, ProtocolFeeCache, IManaged
_setMustAllowlistLPs(params.mustAllowlistLPs);
}

function version() public view override returns (string memory) {
return _version;
}

function _getPoolState() internal view returns (bytes32) {
return _poolState;
}
Expand Down
16 changes: 15 additions & 1 deletion pkg/pool-weighted/contracts/test/MockManagedPoolSettings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,25 @@ contract MockManagedPoolSettings is ManagedPoolSettings {
bufferPeriodDuration,
owner
)
ManagedPoolSettings(params, protocolFeeProvider)
ManagedPoolSettings(_extractSettings(params), protocolFeeProvider)
{
_weightedMath = weightedMath;
}

function _extractSettings(NewPoolParams memory params) private pure returns (PoolSettings memory) {
return PoolSettings({
tokens: params.tokens,
normalizedWeights: params.normalizedWeights,
assetManagers: params.assetManagers,
swapFeePercentage: params.swapFeePercentage,
swapEnabledOnStart: params.swapEnabledOnStart,
mustAllowlistLPs: params.mustAllowlistLPs,
managementAumFeePercentage: params.managementAumFeePercentage,
aumFeeId: params.aumFeeId,
version: params.version
});
}

function getVirtualSupply() external view returns (uint256) {
return _getVirtualSupply();
}
Expand Down