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

Refactor ManagedPool constructor arguments #2078

Merged
merged 5 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ contract ControlledManagedPoolFactory {
* @dev Deploys a new `ManagedPool`.
*/
function create(
ManagedPoolSettings.NewPoolParams memory poolParams,
ManagedPool.ManagedPoolParams memory params,
ManagedPoolSettings.ManagedPoolSettingsParams memory settingsParams,
BasePoolController.BasePoolRights calldata basePoolRights,
ManagedPoolController.ManagedPoolRights calldata managedPoolRights,
uint256 minWeightChangeDuration,
Expand All @@ -53,7 +54,7 @@ contract ControlledManagedPoolFactory {
);

// Let the base factory deploy the pool (owner is the controller)
pool = ManagedPoolFactory(managedPoolFactory).create(poolParams, address(poolController));
pool = ManagedPoolFactory(managedPoolFactory).create(params, settingsParams, address(poolController));

// Finally, initialize the controller
poolController.initialize(pool);
Expand Down
39 changes: 25 additions & 14 deletions pkg/pool-weighted/contracts/managed/ManagedPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,43 @@ contract ManagedPool is ManagedPoolSettings {
uint256 private constant _PREMINTED_TOKEN_BALANCE = 2**(111);
IExternalWeightedMath private immutable _weightedMath;

struct ManagedPoolParams {
string name;
string symbol;
address[] assetManagers;
}

struct ManagedPoolConfigParams {
IVault vault;
IProtocolFeePercentagesProvider protocolFeeProvider;
IExternalWeightedMath weightedMath;
uint256 pauseWindowDuration;
uint256 bufferPeriodDuration;
}

constructor(
NewPoolParams memory params,
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
IExternalWeightedMath weightedMath,
address owner,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration
ManagedPoolParams memory params,
ManagedPoolConfigParams memory configParams,
ManagedPoolSettingsParams memory settingsParams,
address owner
)
NewBasePool(
vault,
configParams.vault,
PoolRegistrationLib.registerComposablePool(
vault,
configParams.vault,
IVault.PoolSpecialization.MINIMAL_SWAP_INFO,
params.tokens,
settingsParams.tokens,
params.assetManagers
),
params.name,
params.symbol,
pauseWindowDuration,
bufferPeriodDuration,
configParams.pauseWindowDuration,
configParams.bufferPeriodDuration,
owner
)
ManagedPoolSettings(params, protocolFeeProvider)
ManagedPoolSettings(settingsParams, configParams.protocolFeeProvider)
{
_weightedMath = weightedMath;
_weightedMath = configParams.weightedMath;
}

function _getWeightedMath() internal view returns (IExternalWeightedMath) {
Expand Down
30 changes: 14 additions & 16 deletions pkg/pool-weighted/contracts/managed/ManagedPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,21 @@ contract ManagedPoolFactory is BasePoolFactory, FactoryWidePauseWindow {
/**
* @dev Deploys a new `ManagedPool`. The owner should be a contract, deployed by another factory.
*/
function create(ManagedPoolSettings.NewPoolParams memory poolParams, address owner)
external
returns (address pool)
{
function create(
ManagedPool.ManagedPoolParams memory params,
ManagedPoolSettings.ManagedPoolSettingsParams memory settingsParams,
address owner
) external returns (address pool) {
(uint256 pauseWindowDuration, uint256 bufferPeriodDuration) = getPauseConfiguration();

return
_create(
abi.encode(
poolParams,
getVault(),
getProtocolFeePercentagesProvider(),
_weightedMath,
owner,
pauseWindowDuration,
bufferPeriodDuration
)
);
ManagedPool.ManagedPoolConfigParams memory configParams = ManagedPool.ManagedPoolConfigParams({
vault: getVault(),
protocolFeeProvider: getProtocolFeePercentagesProvider(),
weightedMath: _weightedMath,
pauseWindowDuration: pauseWindowDuration,
bufferPeriodDuration: bufferPeriodDuration
});

return _create(abi.encode(params, configParams, settingsParams, owner));
}
}
9 changes: 3 additions & 6 deletions pkg/pool-weighted/contracts/managed/ManagedPoolSettings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,17 @@ 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;

struct NewPoolParams {
string name;
string symbol;
struct ManagedPoolSettingsParams {
IERC20[] tokens;
uint256[] normalizedWeights;
address[] assetManagers;
uint256 swapFeePercentage;
bool swapEnabledOnStart;
bool mustAllowlistLPs;
uint256 managementAumFeePercentage;
uint256 aumFeeId;
}

constructor(NewPoolParams memory params, IProtocolFeePercentagesProvider protocolFeeProvider)
constructor(ManagedPoolSettingsParams memory params, IProtocolFeePercentagesProvider protocolFeeProvider)
ProtocolFeeCache(
protocolFeeProvider,
ProviderFeeIDs({ swap: ProtocolFeeType.SWAP, yield: ProtocolFeeType.YIELD, aum: params.aumFeeId })
Expand All @@ -114,7 +111,7 @@ abstract contract ManagedPoolSettings is NewBasePool, ProtocolFeeCache, IManaged
_require(totalTokens >= _MIN_TOKENS, Errors.MIN_TOKENS);
_require(totalTokens <= _MAX_TOKENS, Errors.MAX_TOKENS);

InputHelpers.ensureInputLengthMatch(totalTokens, params.normalizedWeights.length, params.assetManagers.length);
InputHelpers.ensureInputLengthMatch(totalTokens, params.normalizedWeights.length);

// Validate and set initial fees
_setManagementAumFeePercentage(params.managementAumFeePercentage);
Expand Down
13 changes: 5 additions & 8 deletions pkg/pool-weighted/contracts/test/MockManagedPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ import "../ExternalWeightedMath.sol";

contract MockManagedPool is ManagedPool {
constructor(
NewPoolParams memory params,
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
ExternalWeightedMath weightedMath,
address owner,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration
) ManagedPool(params, vault, protocolFeeProvider, weightedMath, owner, pauseWindowDuration, bufferPeriodDuration) {
ManagedPoolParams memory params,
ManagedPoolConfigParams memory configParams,
ManagedPoolSettingsParams memory settingsParams,
address owner
) ManagedPool(params, configParams, settingsParams, owner) {
// solhint-disable-previous-line no-empty-blocks
}

Expand Down
27 changes: 15 additions & 12 deletions pkg/pool-weighted/contracts/test/MockManagedPoolSettings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,28 @@ contract MockManagedPoolSettings is ManagedPoolSettings {
ExternalWeightedMath private immutable _weightedMath;

constructor(
NewPoolParams memory params,
ManagedPoolSettingsParams memory settingsParams,
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
ExternalWeightedMath weightedMath,
address owner,
uint256 pauseWindowDuration,
uint256 bufferPeriodDuration
address[] memory asssetManagers,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
address[] memory asssetManagers,
address[] memory assetManagers,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐍

address owner
)
NewBasePool(
vault,
PoolRegistrationLib.registerPoolWithAssetManagers(
vault,
IVault.PoolSpecialization.MINIMAL_SWAP_INFO,
params.tokens,
params.assetManagers
settingsParams.tokens,
asssetManagers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
asssetManagers
assetManagers

),
params.name,
params.symbol,
pauseWindowDuration,
bufferPeriodDuration,
"MockManagedPoolName",
"MockManagedPoolSymbol",
90 days,
30 days,
owner
)
ManagedPoolSettings(params, protocolFeeProvider)
ManagedPoolSettings(settingsParams, protocolFeeProvider)
{
_weightedMath = weightedMath;
}
Expand All @@ -55,7 +54,11 @@ contract MockManagedPoolSettings is ManagedPoolSettings {
return _getVirtualSupply();
}

function _onInitializePool(address, address, bytes memory userData) internal override returns (uint256, uint256[] memory) {
function _onInitializePool(
address,
address,
bytes memory userData
) internal override returns (uint256, uint256[] memory) {
WeightedPoolUserData.JoinKind kind = userData.joinKind();
_require(kind == WeightedPoolUserData.JoinKind.INIT, Errors.UNINITIALIZED);

Expand Down
16 changes: 13 additions & 3 deletions pkg/pool-weighted/test/ControlledManagedPoolFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ describe('ControlledManagedPoolFactory', function () {
const assetManagers: string[] = Array(tokens.length).fill(ZERO_ADDRESS);
assetManagers[tokens.indexOf(tokens.DAI)] = assetManager.address;

const newPoolParams: ManagedPoolParams = {
const poolParams = {
name: NAME,
symbol: SYMBOL,
assetManagers,
};

const settingsParams: ManagedPoolParams = {
tokens: tokens.addresses,
normalizedWeights: WEIGHTS,
assetManagers: assetManagers,
swapFeePercentage: POOL_SWAP_FEE_PERCENTAGE,
swapEnabledOnStart: swapsEnabled,
mustAllowlistLPs: mustAllowlistLPs,
Expand All @@ -104,7 +107,14 @@ describe('ControlledManagedPoolFactory', function () {
const receipt = await (
await controlledFactory
.connect(manager)
.create(newPoolParams, basePoolRights, managedPoolRights, MIN_WEIGHT_CHANGE_DURATION, manager.address)
.create(
poolParams,
settingsParams,
basePoolRights,
managedPoolRights,
MIN_WEIGHT_CHANGE_DURATION,
manager.address
)
).wait();

const event = expectEvent.inReceipt(receipt, 'ManagedPoolCreated');
Expand Down
1 change: 0 additions & 1 deletion pkg/pool-weighted/test/ManagedPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ describe('ManagedPool', function () {
owner: owner.address,
aumFeeId: ProtocolFee.AUM,
poolType: WeightedPoolType.MOCK_MANAGED_POOL,
mockContractName: 'MockManagedPool',
...overrides,
};
return WeightedPool.create(params);
Expand Down
9 changes: 6 additions & 3 deletions pkg/pool-weighted/test/ManagedPoolFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,23 @@ describe('ManagedPoolFactory', function () {
const assetManagers: string[] = Array(tokens.length).fill(ZERO_ADDRESS);
assetManagers[tokens.indexOf(tokens.DAI)] = assetManager.address;

const newPoolParams: ManagedPoolParams = {
const poolParams = {
name: NAME,
symbol: SYMBOL,
assetManagers: assetManagers,
};

const settingsParams: ManagedPoolParams = {
tokens: tokens.addresses,
normalizedWeights: WEIGHTS,
assetManagers: assetManagers,
swapFeePercentage: POOL_SWAP_FEE_PERCENTAGE,
swapEnabledOnStart: swapsEnabled,
mustAllowlistLPs: mustAllowlistLPs,
managementAumFeePercentage: POOL_MANAGEMENT_AUM_FEE_PERCENTAGE,
aumFeeId: ProtocolFee.AUM,
};

const receipt = await (await factory.connect(manager).create(newPoolParams, manager.address)).wait();
const receipt = await (await factory.connect(manager).create(poolParams, settingsParams, manager.address)).wait();

const event = expectEvent.inReceipt(receipt, 'PoolCreated');
return deployedAt('ManagedPool', event.args.pool);
Expand Down
11 changes: 1 addition & 10 deletions pkg/pool-weighted/test/ManagedPoolSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ describe('ManagedPoolSettings', function () {
const fullParams = {
...params,
swapFeePercentage: INITIAL_SWAP_FEE,
poolType: WeightedPoolType.MOCK_MANAGED_POOL,
mockContractName: 'MockManagedPoolSettings',
poolType: WeightedPoolType.MOCK_MANAGED_POOL_SETTINGS,
};
return WeightedPool.create(fullParams);
}
Expand Down Expand Up @@ -162,13 +161,6 @@ describe('ManagedPoolSettings', function () {

expect(poolScalingFactors).to.deep.equal(tokenScalingFactors);
});

it('sets asset managers', async () => {
await tokens.asyncEach(async (token, i) => {
const info = await pool.getTokenInfo(token);
expect(info.assetManager).to.eq(assetManagers[i]);
});
});
});
});
}
Expand Down Expand Up @@ -462,7 +454,6 @@ describe('ManagedPoolSettings', function () {
context('when the sender is not the owner', () => {
it('non-owners cannot update weights', async () => {
const now = await currentTimestamp();

await expect(pool.updateWeightsGradually(other, now, now, poolWeights)).to.be.revertedWith(
'SENDER_NOT_ALLOWED'
);
Expand Down
16 changes: 8 additions & 8 deletions pkg/pool-weighted/test/managed/ownerOnlyActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ describe('ManagedPool owner only actions', () => {
const circuitBreakerLib = await deploy('CircuitBreakerLib');
pool = await deploy('MockManagedPool', {
args: [
{ name: '', symbol: '', assetManagers: new Array(2).fill(ZERO_ADDRESS) },
{
vault: vault.address,
protocolFeeProvider: vault.getFeesProvider().address,
weightedMath: math.address,
pauseWindowDuration: 0,
bufferPeriodDuration: 0,
},
{
name: '',
symbol: '',
tokens: tokens.addresses,
normalizedWeights: [fp(0.5), fp(0.5)],
assetManagers: new Array(2).fill(ZERO_ADDRESS),
swapFeePercentage: fp(0.05),
swapEnabledOnStart: true,
mustAllowlistLPs: false,
managementAumFeePercentage: fp(0),
aumFeeId: ProtocolFee.AUM,
},
vault.address,
vault.getFeesProvider().address,
math.address,
ZERO_ADDRESS,
0,
0,
],
libraries: {
CircuitBreakerLib: circuitBreakerLib.address,
Expand Down
6 changes: 5 additions & 1 deletion pvt/helpers/src/models/pools/weighted/WeightedPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,11 @@ export default class WeightedPool extends BasePool {
}

private _isManagedPool() {
return this.poolType == WeightedPoolType.MANAGED_POOL || this.poolType == WeightedPoolType.MOCK_MANAGED_POOL;
return (
this.poolType == WeightedPoolType.MANAGED_POOL ||
this.poolType == WeightedPoolType.MOCK_MANAGED_POOL ||
this.poolType == WeightedPoolType.MOCK_MANAGED_POOL_SETTINGS
);
}

async setSwapEnabled(from: SignerWithAddress, swapEnabled: boolean): Promise<ContractTransaction> {
Expand Down
Loading