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

Add version to managed pool #2087

Merged
merged 11 commits into from
Dec 1, 2022
Merged
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
10 changes: 9 additions & 1 deletion pkg/pool-weighted/contracts/managed/ManagedPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

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

Expand Down Expand Up @@ -43,7 +44,7 @@ import "./ManagedPoolSettings.sol";
* rebalancing through token changes, gradual weight or fee updates, fine-grained control of protocol and
* management fees, allowlisting of LPs, and more.
*/
contract ManagedPool is ManagedPoolSettings {
contract ManagedPool is IVersion, ManagedPoolSettings {
// 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 All @@ -57,6 +58,7 @@ contract ManagedPool is ManagedPoolSettings {
// conceivable real liquidity - to allow for minting new BPT as a result of regular joins.
uint256 private constant _PREMINTED_TOKEN_BALANCE = 2**(111);
IExternalWeightedMath private immutable _weightedMath;
string private _version;

struct ManagedPoolParams {
string name;
Expand All @@ -70,6 +72,7 @@ contract ManagedPool is ManagedPoolSettings {
IExternalWeightedMath weightedMath;
uint256 pauseWindowDuration;
uint256 bufferPeriodDuration;
string version;
}

constructor(
Expand All @@ -95,6 +98,11 @@ contract ManagedPool is ManagedPoolSettings {
ManagedPoolSettings(settingsParams, configParams.protocolFeeProvider)
{
_weightedMath = configParams.weightedMath;
_version = configParams.version;
}

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

function _getWeightedMath() internal view returns (IExternalWeightedMath) {
Expand Down
25 changes: 19 additions & 6 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/pool-utils/IFactoryCreatedPoolVersion.sol";
import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeePercentagesProvider.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,13 +37,22 @@ 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 getPoolVersion() public view override returns (string memory) {
return _poolVersion;
}

function getWeightedMath() external view returns (IExternalWeightedMath) {
Expand All @@ -62,7 +74,8 @@ contract ManagedPoolFactory is BasePoolFactory, FactoryWidePauseWindow {
protocolFeeProvider: getProtocolFeePercentagesProvider(),
weightedMath: _weightedMath,
pauseWindowDuration: pauseWindowDuration,
bufferPeriodDuration: bufferPeriodDuration
bufferPeriodDuration: bufferPeriodDuration,
version: getPoolVersion()
});

return _create(abi.encode(params, configParams, settingsParams, owner));
Expand Down
4 changes: 2 additions & 2 deletions pkg/pool-weighted/contracts/test/MockManagedPoolSettings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract MockManagedPoolSettings is ManagedPoolSettings {
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
ExternalWeightedMath weightedMath,
address[] memory asssetManagers,
address[] memory assetManagers,
address owner
)
NewBasePool(
Expand All @@ -37,7 +37,7 @@ contract MockManagedPoolSettings is ManagedPoolSettings {
vault,
IVault.PoolSpecialization.MINIMAL_SWAP_INFO,
settingsParams.tokens,
asssetManagers
assetManagers
),
"MockManagedPoolName",
"MockManagedPoolSymbol",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('ControlledManagedPoolFactory', function () {
const circuitBreakerLib = await deploy('CircuitBreakerLib');
const addRemoveTokenLib = await deploy('ManagedPoolAddRemoveTokenLib');
factory = await deploy('ManagedPoolFactory', {
args: [vault.address, vault.getFeesProvider().address],
args: [vault.address, vault.getFeesProvider().address, 'factoryVersion', 'poolVersion'],
libraries: {
CircuitBreakerLib: circuitBreakerLib.address,
ManagedPoolAddRemoveTokenLib: addRemoveTokenLib.address,
Expand Down
11 changes: 11 additions & 0 deletions pkg/pool-weighted/test/ManagedPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ describe('ManagedPool', function () {
let pool: WeightedPool;
let vault: Vault;

const poolVersion = JSON.stringify({
name: 'ManagedPool',
version: '0',
deployment: 'test-deployment',
});

before('setup signers', async () => {
[, admin, owner, other] = await ethers.getSigners();
});
Expand Down Expand Up @@ -70,6 +76,7 @@ describe('ManagedPool', function () {
owner: owner.address,
aumFeeId: ProtocolFee.AUM,
poolType: WeightedPoolType.MOCK_MANAGED_POOL,
poolVersion,
...overrides,
};
return WeightedPool.create(params);
Expand Down Expand Up @@ -121,6 +128,10 @@ describe('ManagedPool', function () {
expect(assetManager).to.be.eq(ZERO_ADDRESS);
});
});

it('returns the expected pool version', async () => {
expect(await pool.version()).to.be.eq(poolVersion);
});
});
});

Expand Down
25 changes: 24 additions & 1 deletion pkg/pool-weighted/test/ManagedPoolFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ describe('ManagedPoolFactory', function () {
let manager: SignerWithAddress;
let assetManager: SignerWithAddress;

const factoryVersion = JSON.stringify({
name: 'ManagedPoolFactory',
version: '4',
deployment: 'test-deployment',
});
const poolVersion = JSON.stringify({
name: 'ManagedPool',
version: '0',
deployment: 'test-deployment',
});

const NAME = 'Balancer Pool Token';
const SYMBOL = 'BPT';
const POOL_SWAP_FEE_PERCENTAGE = fp(0.01);
Expand All @@ -44,7 +55,7 @@ describe('ManagedPoolFactory', function () {
const addRemoveTokenLib = await deploy('ManagedPoolAddRemoveTokenLib');
const circuitBreakerLib = await deploy('CircuitBreakerLib');
factory = await deploy('ManagedPoolFactory', {
args: [vault.address, vault.getFeesProvider().address],
args: [vault.address, vault.getFeesProvider().address, factoryVersion, poolVersion],
libraries: {
CircuitBreakerLib: circuitBreakerLib.address,
ManagedPoolAddRemoveTokenLib: addRemoveTokenLib.address,
Expand Down Expand Up @@ -142,6 +153,18 @@ describe('ManagedPoolFactory', function () {
it('sets the decimals', async () => {
expect(await pool.decimals()).to.equal(18);
});

it('sets factory version', async () => {
expect(await factory.version()).to.be.eq(factoryVersion);
});

it('sets pool version', async () => {
expect(await factory.getPoolVersion()).to.be.eq(poolVersion);
});

it('sets pool version in the pool', async () => {
expect(await pool.version()).to.be.eq(poolVersion);
});
});

describe('temporarily pausable', () => {
Expand Down
1 change: 1 addition & 0 deletions pkg/pool-weighted/test/managed/ownerOnlyActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('ManagedPool owner only actions', () => {
weightedMath: math.address,
pauseWindowDuration: 0,
bufferPeriodDuration: 0,
version: '',
},
{
tokens: tokens.addresses,
Expand Down
2 changes: 1 addition & 1 deletion pvt/benchmarks/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function deployPoolFromFactory(
const addRemoveTokenLib = await deploy('v2-pool-weighted/ManagedPoolAddRemoveTokenLib');
const circuitBreakerLib = await deploy('v2-pool-weighted/CircuitBreakerLib');
const baseFactory = await deploy('v2-pool-weighted/ManagedPoolFactory', {
args: [vault.address, vault.getFeesProvider().address],
args: [vault.address, vault.getFeesProvider().address, 'factoryVersion', 'poolVersion'],
libraries: {
CircuitBreakerLib: circuitBreakerLib.address,
ManagedPoolAddRemoveTokenLib: addRemoveTokenLib.address,
Expand Down
7 changes: 7 additions & 0 deletions pvt/helpers/src/models/pools/weighted/WeightedPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class WeightedPool extends BasePool {
mustAllowlistLPs: boolean;
managementAumFeePercentage: BigNumberish;
aumProtocolFeesCollector: string;
poolVersion: string;

static async create(params: RawWeightedPoolDeployment = {}): Promise<WeightedPool> {
return WeightedPoolDeployer.deploy(params);
Expand All @@ -81,6 +82,7 @@ export default class WeightedPool extends BasePool {
mustAllowlistLPs: boolean,
managementAumFeePercentage: BigNumberish,
aumProtocolFeesCollector: string,
poolVersion: string,
owner?: SignerWithAddress
) {
super(instance, poolId, vault, tokens, swapFeePercentage, owner);
Expand All @@ -93,6 +95,7 @@ export default class WeightedPool extends BasePool {
this.mustAllowlistLPs = mustAllowlistLPs;
this.managementAumFeePercentage = managementAumFeePercentage;
this.aumProtocolFeesCollector = aumProtocolFeesCollector;
this.poolVersion = poolVersion;
}

get maxWeight(): BigNumberish {
Expand Down Expand Up @@ -148,6 +151,10 @@ export default class WeightedPool extends BasePool {
return this.instance.getNormalizedWeights();
}

async version(): Promise<string[]> {
return this.instance.version();
}

async estimateSpotPrice(currentBalances?: BigNumberish[]): Promise<BigNumber> {
if (!currentBalances) currentBalances = await this.getBalances();

Expand Down
11 changes: 9 additions & 2 deletions pvt/helpers/src/models/pools/weighted/WeightedPoolDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default {
mustAllowlistLPs,
managementAumFeePercentage,
aumProtocolFeesCollector,
poolVersion,
} = deployment;

return new WeightedPool(
Expand All @@ -55,7 +56,8 @@ export default {
swapEnabledOnStart,
mustAllowlistLPs,
managementAumFeePercentage,
aumProtocolFeesCollector
aumProtocolFeesCollector,
poolVersion
);
},

Expand All @@ -76,6 +78,7 @@ export default {
owner,
from,
aumFeeId,
poolVersion,
} = params;

let result: Promise<Contract>;
Expand Down Expand Up @@ -116,6 +119,7 @@ export default {
weightedMath: math.address,
pauseWindowDuration,
bufferPeriodDuration,
version: poolVersion,
},
{
tokens: tokens.addresses,
Expand Down Expand Up @@ -155,6 +159,7 @@ export default {
weightedMath: math.address,
pauseWindowDuration,
bufferPeriodDuration,
version: poolVersion,
},
{
tokens: tokens.addresses,
Expand Down Expand Up @@ -248,6 +253,8 @@ export default {
owner,
from,
aumFeeId,
factoryVersion,
poolVersion,
} = params;

let result: Promise<Contract>;
Expand Down Expand Up @@ -276,7 +283,7 @@ export default {
const addRemoveTokenLib = await deploy('v2-pool-weighted/ManagedPoolAddRemoveTokenLib');
const circuitBreakerLib = await deploy('v2-pool-weighted/CircuitBreakerLib');
const factory = await deploy('v2-pool-weighted/ManagedPoolFactory', {
args: [vault.address, vault.getFeesProvider().address],
args: [vault.address, vault.getFeesProvider().address, factoryVersion, poolVersion],
from,
libraries: {
CircuitBreakerLib: circuitBreakerLib.address,
Expand Down
4 changes: 4 additions & 0 deletions pvt/helpers/src/models/pools/weighted/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type RawWeightedPoolDeployment = {
poolType?: WeightedPoolType;
aumFeeId?: BigNumberish;
mockContractName?: string;
factoryVersion?: string;
poolVersion?: string;
};

export type WeightedPoolDeployment = {
Expand All @@ -51,6 +53,8 @@ export type WeightedPoolDeployment = {
mustAllowlistLPs: boolean;
managementAumFeePercentage: BigNumberish;
aumProtocolFeesCollector: string;
factoryVersion: string;
poolVersion: string;
aumFeeId?: BigNumberish;
owner?: string;
admin?: SignerWithAddress;
Expand Down
7 changes: 6 additions & 1 deletion pvt/helpers/src/models/types/TypesConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default {
aumProtocolFeesCollector,
poolType,
aumFeeId,
factoryVersion,
poolVersion,
} = params;
if (!params.owner) params.owner = ZERO_ADDRESS;
if (!tokens) tokens = new TokenList();
Expand All @@ -84,6 +86,8 @@ export default {
if (undefined == swapEnabledOnStart) swapEnabledOnStart = true;
if (undefined == mustAllowlistLPs) mustAllowlistLPs = false;
if (undefined == managementAumFeePercentage) managementAumFeePercentage = FP_ZERO;
if (undefined == factoryVersion) factoryVersion = 'default factory version';
if (undefined == poolVersion) poolVersion = 'default pool version';
return {
tokens,
weights,
Expand All @@ -100,7 +104,8 @@ export default {
from: params.from,
poolType,
aumFeeId,
mockContractName: params.mockContractName,
factoryVersion,
poolVersion,
};
},

Expand Down