From 02bc0833e0323d69ecc316c002f093364e35b129 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Ubeira Date: Tue, 22 Nov 2022 13:47:27 -0300 Subject: [PATCH 1/7] WIP: version for ComposableStablePool. --- .../contracts/pool-utils/IVersionProvider.sol | 28 +++++++++++++++ .../contracts/ComposableStablePool.sol | 4 +++ .../contracts/ComposableStablePoolFactory.sol | 14 ++++++-- pkg/pool-utils/contracts/Version.sol | 35 +++++++++++++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 pkg/interfaces/contracts/pool-utils/IVersionProvider.sol create mode 100644 pkg/pool-utils/contracts/Version.sol diff --git a/pkg/interfaces/contracts/pool-utils/IVersionProvider.sol b/pkg/interfaces/contracts/pool-utils/IVersionProvider.sol new file mode 100644 index 0000000000..091c940ec8 --- /dev/null +++ b/pkg/interfaces/contracts/pool-utils/IVersionProvider.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity >=0.7.0 <0.9.0; + +/** + * @notice Simple interface to retrieve the version of a deployed contract. + * + * @dev The contract implementing the interface may provide the actual version, or forward the call to another + * version provider (e.g. a pool will forward the call to its respective pool factory). + */ +interface IVersionProvider { + /** + * @dev Returns a JSON representation of the contract version containing name, version number and task ID. + */ + function version() external view returns (string memory); +} diff --git a/pkg/pool-stable/contracts/ComposableStablePool.sol b/pkg/pool-stable/contracts/ComposableStablePool.sol index eabd0a288f..92c75a55b1 100644 --- a/pkg/pool-stable/contracts/ComposableStablePool.sol +++ b/pkg/pool-stable/contracts/ComposableStablePool.sol @@ -26,6 +26,7 @@ import "@balancer-labs/v2-solidity-utils/contracts/helpers/ERC20Helpers.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; import "@balancer-labs/v2-pool-utils/contracts/BaseGeneralPool.sol"; +import "@balancer-labs/v2-pool-utils/contracts/Version.sol"; import "@balancer-labs/v2-pool-utils/contracts/rates/PriceRateCache.sol"; import "./ComposableStablePoolStorage.sol"; @@ -50,6 +51,7 @@ import "./StableMath.sol"; */ contract ComposableStablePool is IRateProvider, + Version, BaseGeneralPool, StablePoolAmplification, ComposableStablePoolRates, @@ -79,6 +81,7 @@ contract ComposableStablePool is uint256 pauseWindowDuration; uint256 bufferPeriodDuration; address owner; + IVersionProvider versionProvider; } constructor(NewPoolParams memory params) @@ -98,6 +101,7 @@ contract ComposableStablePool is ComposableStablePoolStorage(_extractStorageParams(params)) ComposableStablePoolRates(_extractRatesParams(params)) ProtocolFeeCache(params.protocolFeeProvider, ProtocolFeeCache.DELEGATE_PROTOCOL_SWAP_FEES_SENTINEL) + Version(params.versionProvider) { // solhint-disable-previous-line no-empty-blocks } diff --git a/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol b/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol index bf9067353b..2207831ea5 100644 --- a/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol +++ b/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol @@ -15,6 +15,7 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; +import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersionProvider.sol"; import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol"; import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeePercentagesProvider.sol"; @@ -23,13 +24,19 @@ import "@balancer-labs/v2-pool-utils/contracts/factories/FactoryWidePauseWindow. import "./ComposableStablePool.sol"; -contract ComposableStablePoolFactory is BasePoolSplitCodeFactory, FactoryWidePauseWindow { +contract ComposableStablePoolFactory is IVersionProvider, BasePoolSplitCodeFactory, FactoryWidePauseWindow { IProtocolFeePercentagesProvider private _protocolFeeProvider; + string private _version; - constructor(IVault vault, IProtocolFeePercentagesProvider protocolFeeProvider) + constructor(IVault vault, IProtocolFeePercentagesProvider protocolFeeProvider, string memory version) BasePoolSplitCodeFactory(vault, type(ComposableStablePool).creationCode) { _protocolFeeProvider = protocolFeeProvider; + _version = version; + } + + function version() external view override returns (string memory) { + return _version; } /** @@ -64,7 +71,8 @@ contract ComposableStablePoolFactory is BasePoolSplitCodeFactory, FactoryWidePau swapFeePercentage: swapFeePercentage, pauseWindowDuration: pauseWindowDuration, bufferPeriodDuration: bufferPeriodDuration, - owner: owner + owner: owner, + versionProvider: this }) ) ) diff --git a/pkg/pool-utils/contracts/Version.sol b/pkg/pool-utils/contracts/Version.sol new file mode 100644 index 0000000000..7d9e1322b8 --- /dev/null +++ b/pkg/pool-utils/contracts/Version.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity ^0.7.0; + +import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersionProvider.sol"; + +/** + * @notice Retrieves a contract's version using the given provider. + * + * @dev The contract happens to have the same interface as the version provider, but it only holds a reference + * to the version provider to be more efficient in terms of deployed bytecode size. + */ +contract Version is IVersionProvider { + IVersionProvider private immutable _versionProvider; + + constructor(IVersionProvider versionProvider) { + _versionProvider = versionProvider; + } + + function version() external view override returns (string memory) { + return _versionProvider.version(); + } +} From 5f6c56bb95ab1c5941c9795036555d246156799a Mon Sep 17 00:00:00 2001 From: Juan Ignacio Ubeira Date: Tue, 22 Nov 2022 14:43:40 -0300 Subject: [PATCH 2/7] Fix stack too deep error and adjust tests. --- .../contracts/ComposableStablePool.sol | 13 +++++++++---- .../contracts/ComposableStablePoolFactory.sol | 8 +++++--- .../test/ComposableStablePool.test.ts | 12 ++++++++++++ .../MockVersionProvider.sol} | 17 ++++++----------- .../models/pools/stable/StablePoolDeployer.ts | 4 ++++ pvt/helpers/src/models/pools/stable/types.ts | 2 ++ pvt/helpers/src/models/types/TypesConverter.ts | 3 +++ 7 files changed, 41 insertions(+), 18 deletions(-) rename pkg/pool-utils/contracts/{Version.sol => test/MockVersionProvider.sol} (63%) diff --git a/pkg/pool-stable/contracts/ComposableStablePool.sol b/pkg/pool-stable/contracts/ComposableStablePool.sol index 92c75a55b1..f7b53ee433 100644 --- a/pkg/pool-stable/contracts/ComposableStablePool.sol +++ b/pkg/pool-stable/contracts/ComposableStablePool.sol @@ -19,6 +19,7 @@ import "@balancer-labs/v2-interfaces/contracts/pool-stable/StablePoolUserData.so import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol"; import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeePercentagesProvider.sol"; import "@balancer-labs/v2-interfaces/contracts/pool-utils/IRateProvider.sol"; +import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersionProvider.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol"; @@ -26,7 +27,6 @@ import "@balancer-labs/v2-solidity-utils/contracts/helpers/ERC20Helpers.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; import "@balancer-labs/v2-pool-utils/contracts/BaseGeneralPool.sol"; -import "@balancer-labs/v2-pool-utils/contracts/Version.sol"; import "@balancer-labs/v2-pool-utils/contracts/rates/PriceRateCache.sol"; import "./ComposableStablePoolStorage.sol"; @@ -51,7 +51,7 @@ import "./StableMath.sol"; */ contract ComposableStablePool is IRateProvider, - Version, + IVersionProvider, BaseGeneralPool, StablePoolAmplification, ComposableStablePoolRates, @@ -66,6 +66,8 @@ contract ComposableStablePool is // We are preminting half of that value (rounded up). uint256 private constant _PREMINTED_TOKEN_BALANCE = 2**(111); + IVersionProvider private immutable _versionProvider; + // The constructor arguments are received in a struct to work around stack-too-deep issues struct NewPoolParams { IVault vault; @@ -101,9 +103,8 @@ contract ComposableStablePool is ComposableStablePoolStorage(_extractStorageParams(params)) ComposableStablePoolRates(_extractRatesParams(params)) ProtocolFeeCache(params.protocolFeeProvider, ProtocolFeeCache.DELEGATE_PROTOCOL_SWAP_FEES_SENTINEL) - Version(params.versionProvider) { - // solhint-disable-previous-line no-empty-blocks + _versionProvider = params.versionProvider; } // Translate parameters to avoid stack-too-deep issues in the constructor @@ -134,6 +135,10 @@ contract ComposableStablePool is }); } + function version() external view override returns (string memory) { + return _versionProvider.version(); + } + /** * @notice Return the minimum BPT balance, required to avoid minimum token balances. * @dev This amount is minted and immediately burned on pool initialization, so that the total supply diff --git a/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol b/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol index 2207831ea5..257bf4f038 100644 --- a/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol +++ b/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol @@ -28,9 +28,11 @@ contract ComposableStablePoolFactory is IVersionProvider, BasePoolSplitCodeFacto IProtocolFeePercentagesProvider private _protocolFeeProvider; string private _version; - constructor(IVault vault, IProtocolFeePercentagesProvider protocolFeeProvider, string memory version) - BasePoolSplitCodeFactory(vault, type(ComposableStablePool).creationCode) - { + constructor( + IVault vault, + IProtocolFeePercentagesProvider protocolFeeProvider, + string memory version + ) BasePoolSplitCodeFactory(vault, type(ComposableStablePool).creationCode) { _protocolFeeProvider = protocolFeeProvider; _version = version; } diff --git a/pkg/pool-stable/test/ComposableStablePool.test.ts b/pkg/pool-stable/test/ComposableStablePool.test.ts index ea88ad82d9..005b262232 100644 --- a/pkg/pool-stable/test/ComposableStablePool.test.ts +++ b/pkg/pool-stable/test/ComposableStablePool.test.ts @@ -76,6 +76,7 @@ describe('ComposableStablePool', () => { function itBehavesAsComposableStablePool(numberOfTokens: number): void { let pool: StablePool, tokens: TokenList; let deployTimestamp: BigNumber, bptIndex: number, initialBalances: BigNumberish[]; + let version: string; const rateProviders: Contract[] = []; const tokenRateCacheDurations: number[] = []; @@ -97,6 +98,12 @@ describe('ComposableStablePool', () => { exemptFromYieldProtocolFeeFlags[i] = i % 2 == 0; // set true for even tokens } + version = JSON.stringify({ + name: 'ComposableStablePool', + version: '0', + deployment: 'test-deployment', + }); + pool = await StablePool.create({ tokens, rateProviders, @@ -104,6 +111,7 @@ describe('ComposableStablePool', () => { exemptFromYieldProtocolFeeFlags, owner, admin, + version, ...params, }); @@ -121,6 +129,10 @@ describe('ComposableStablePool', () => { await deployPool({ swapFeePercentage, amplificationParameter: AMPLIFICATION_PARAMETER }, tokenRates); }); + it('sets the version', async () => { + expect(await pool.instance.version()).to.equal(version); + }); + it('sets the name', async () => { expect(await pool.name()).to.equal('Balancer Pool Token'); }); diff --git a/pkg/pool-utils/contracts/Version.sol b/pkg/pool-utils/contracts/test/MockVersionProvider.sol similarity index 63% rename from pkg/pool-utils/contracts/Version.sol rename to pkg/pool-utils/contracts/test/MockVersionProvider.sol index 7d9e1322b8..59e3c24ce2 100644 --- a/pkg/pool-utils/contracts/Version.sol +++ b/pkg/pool-utils/contracts/test/MockVersionProvider.sol @@ -13,23 +13,18 @@ // along with this program. If not, see . pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersionProvider.sol"; -/** - * @notice Retrieves a contract's version using the given provider. - * - * @dev The contract happens to have the same interface as the version provider, but it only holds a reference - * to the version provider to be more efficient in terms of deployed bytecode size. - */ -contract Version is IVersionProvider { - IVersionProvider private immutable _versionProvider; +contract MockVersionProvider is IVersionProvider { + string private _version; - constructor(IVersionProvider versionProvider) { - _versionProvider = versionProvider; + constructor(string memory version) { + _version = version; } function version() external view override returns (string memory) { - return _versionProvider.version(); + return _version; } } diff --git a/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts b/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts index b4a98def62..e1fbc26b7e 100644 --- a/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts +++ b/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts @@ -36,10 +36,13 @@ export default { bufferPeriodDuration, amplificationParameter, from, + version, } = params; const owner = TypesConverter.toAddress(params.owner); + const versionProvider = await deploy('v2-pool-utils/MockVersionProvider', { args: [version] }); + return deploy('v2-pool-stable/MockComposableStablePool', { args: [ { @@ -56,6 +59,7 @@ export default { pauseWindowDuration, bufferPeriodDuration, owner, + versionProvider: versionProvider.address, }, ], from, diff --git a/pvt/helpers/src/models/pools/stable/types.ts b/pvt/helpers/src/models/pools/stable/types.ts index 45793b1eb0..83d4cb1ad6 100644 --- a/pvt/helpers/src/models/pools/stable/types.ts +++ b/pvt/helpers/src/models/pools/stable/types.ts @@ -125,6 +125,7 @@ export type RawStablePoolDeployment = { from?: SignerWithAddress; vault?: Vault; mockedVault?: boolean; + version?: string; }; export type StablePoolDeployment = { @@ -134,6 +135,7 @@ export type StablePoolDeployment = { rateProviders: Account[]; tokenRateCacheDurations: BigNumberish[]; exemptFromYieldProtocolFeeFlags: boolean[]; + version: string; pauseWindowDuration?: BigNumberish; bufferPeriodDuration?: BigNumberish; owner?: SignerWithAddress; diff --git a/pvt/helpers/src/models/types/TypesConverter.ts b/pvt/helpers/src/models/types/TypesConverter.ts index 0548c8fcf2..aad12f7f99 100644 --- a/pvt/helpers/src/models/types/TypesConverter.ts +++ b/pvt/helpers/src/models/types/TypesConverter.ts @@ -134,6 +134,7 @@ export default { swapFeePercentage, pauseWindowDuration, bufferPeriodDuration, + version, } = params; if (!tokens) tokens = new TokenList(); @@ -144,6 +145,7 @@ export default { if (!pauseWindowDuration) pauseWindowDuration = 3 * MONTH; if (!bufferPeriodDuration) bufferPeriodDuration = MONTH; if (!exemptFromYieldProtocolFeeFlags) exemptFromYieldProtocolFeeFlags = Array(tokens.length).fill(false); + if (!version) version = 'test'; return { tokens, @@ -155,6 +157,7 @@ export default { pauseWindowDuration, bufferPeriodDuration, owner: params.owner, + version, }; }, From 1b7790a05ea5c0750e4d7ddbb722889dec6fe455 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Ubeira Date: Tue, 22 Nov 2022 16:45:25 -0300 Subject: [PATCH 3/7] ComposableStablePoolFactory test. --- .../test/ComposableStablePool.test.ts | 11 ----------- .../test/ComposableStablePoolFactory.test.ts | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pkg/pool-stable/test/ComposableStablePool.test.ts b/pkg/pool-stable/test/ComposableStablePool.test.ts index 005b262232..cb3a8a74f9 100644 --- a/pkg/pool-stable/test/ComposableStablePool.test.ts +++ b/pkg/pool-stable/test/ComposableStablePool.test.ts @@ -98,12 +98,6 @@ describe('ComposableStablePool', () => { exemptFromYieldProtocolFeeFlags[i] = i % 2 == 0; // set true for even tokens } - version = JSON.stringify({ - name: 'ComposableStablePool', - version: '0', - deployment: 'test-deployment', - }); - pool = await StablePool.create({ tokens, rateProviders, @@ -111,7 +105,6 @@ describe('ComposableStablePool', () => { exemptFromYieldProtocolFeeFlags, owner, admin, - version, ...params, }); @@ -129,10 +122,6 @@ describe('ComposableStablePool', () => { await deployPool({ swapFeePercentage, amplificationParameter: AMPLIFICATION_PARAMETER }, tokenRates); }); - it('sets the version', async () => { - expect(await pool.instance.version()).to.equal(version); - }); - it('sets the name', async () => { expect(await pool.name()).to.equal('Balancer Pool Token'); }); diff --git a/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts b/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts index 110fdc8e90..fbd288bb99 100644 --- a/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts +++ b/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts @@ -27,6 +27,7 @@ describe('ComposableStablePoolFactory', function () { let createTime: BigNumber; let protocolFeeExemptFlags: boolean[]; + let version: string; before('setup signers', async () => { [, owner] = await ethers.getSigners(); @@ -34,7 +35,14 @@ describe('ComposableStablePoolFactory', function () { sharedBeforeEach('deploy factory & tokens', async () => { vault = await Vault.create(); - factory = await deploy('ComposableStablePoolFactory', { args: [vault.address, vault.getFeesProvider().address] }); + version = JSON.stringify({ + name: 'ComposableStablePool', + version: '0', + deployment: 'test-deployment', + }); + factory = await deploy('ComposableStablePoolFactory', { + args: [vault.address, vault.getFeesProvider().address, version], + }); createTime = await currentTimestamp(); tokens = await TokenList.create(['baDAI', 'baUSDC', 'baUSDT'], { sorted: true }); @@ -70,10 +78,18 @@ describe('ComposableStablePoolFactory', function () { pool = await createPool(); }); + it('checks the version in the factory', async () => { + expect(await factory.version()).to.equal(version); + }); + it('sets the vault', async () => { expect(await pool.getVault()).to.equal(vault.address); }); + it('sets the version in the pool', async () => { + expect(await pool.version()).to.equal(version); + }); + it('registers tokens in the vault', async () => { const poolId = await pool.getPoolId(); const poolTokens = await vault.getPoolTokens(poolId); From 74736d7e6df78b327b1e8ce793e79a8ebc05bb57 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Ubeira Date: Tue, 22 Nov 2022 17:16:43 -0300 Subject: [PATCH 4/7] Remove unused var. --- pkg/pool-stable/test/ComposableStablePool.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/pool-stable/test/ComposableStablePool.test.ts b/pkg/pool-stable/test/ComposableStablePool.test.ts index cb3a8a74f9..ea88ad82d9 100644 --- a/pkg/pool-stable/test/ComposableStablePool.test.ts +++ b/pkg/pool-stable/test/ComposableStablePool.test.ts @@ -76,7 +76,6 @@ describe('ComposableStablePool', () => { function itBehavesAsComposableStablePool(numberOfTokens: number): void { let pool: StablePool, tokens: TokenList; let deployTimestamp: BigNumber, bptIndex: number, initialBalances: BigNumberish[]; - let version: string; const rateProviders: Contract[] = []; const tokenRateCacheDurations: number[] = []; From 3051a3d45460b5740e43fc34583e272af7bd5bf2 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Ubeira Date: Wed, 23 Nov 2022 09:36:58 -0300 Subject: [PATCH 5/7] Add factory version / pool version. --- .../contracts/pool-utils/IPoolVersion.sol | 28 +++++++++++++++++++ .../contracts/pool-utils/IVersion.sol} | 23 ++++++--------- .../contracts/ComposableStablePool.sol | 12 ++++---- .../contracts/ComposableStablePoolFactory.sol | 18 ++++++++---- .../test/ComposableStablePoolFactory.test.ts | 23 ++++++++++----- .../models/pools/stable/StablePoolDeployer.ts | 4 +-- 6 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 pkg/interfaces/contracts/pool-utils/IPoolVersion.sol rename pkg/{pool-utils/contracts/test/MockVersionProvider.sol => interfaces/contracts/pool-utils/IVersion.sol} (63%) diff --git a/pkg/interfaces/contracts/pool-utils/IPoolVersion.sol b/pkg/interfaces/contracts/pool-utils/IPoolVersion.sol new file mode 100644 index 0000000000..56d3e4cf88 --- /dev/null +++ b/pkg/interfaces/contracts/pool-utils/IPoolVersion.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity >=0.7.0 <0.9.0; + +/** + * @notice Simple interface to retrieve the version of pools deployed by a pool factory. + */ +interface IPoolVersion { + /** + * @dev Returns a JSON representation of the deployed pool version containing name, version number and task ID. + * + * This is typically only useful in complex Pool deployment schemes, where multiple subsystems need to know about + * each other. Note that this value will only be updated at factory creation time. + */ + function getPoolVersion() external view returns (string memory); +} diff --git a/pkg/pool-utils/contracts/test/MockVersionProvider.sol b/pkg/interfaces/contracts/pool-utils/IVersion.sol similarity index 63% rename from pkg/pool-utils/contracts/test/MockVersionProvider.sol rename to pkg/interfaces/contracts/pool-utils/IVersion.sol index 59e3c24ce2..9079808ee2 100644 --- a/pkg/pool-utils/contracts/test/MockVersionProvider.sol +++ b/pkg/interfaces/contracts/pool-utils/IVersion.sol @@ -12,19 +12,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -pragma solidity ^0.7.0; -pragma experimental ABIEncoderV2; +pragma solidity >=0.7.0 <0.9.0; -import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersionProvider.sol"; - -contract MockVersionProvider is IVersionProvider { - string private _version; - - constructor(string memory version) { - _version = version; - } - - function version() external view override returns (string memory) { - return _version; - } +/** + * @notice Simple interface to retrieve the version of a deployed contract. + */ +interface IVersion { + /** + * @dev Returns a JSON representation of the contract version containing name, version number and task ID. + */ + function version() external view returns (string memory); } diff --git a/pkg/pool-stable/contracts/ComposableStablePool.sol b/pkg/pool-stable/contracts/ComposableStablePool.sol index f7b53ee433..2c76cef5b8 100644 --- a/pkg/pool-stable/contracts/ComposableStablePool.sol +++ b/pkg/pool-stable/contracts/ComposableStablePool.sol @@ -19,7 +19,7 @@ import "@balancer-labs/v2-interfaces/contracts/pool-stable/StablePoolUserData.so import "@balancer-labs/v2-interfaces/contracts/solidity-utils/helpers/BalancerErrors.sol"; import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeePercentagesProvider.sol"; import "@balancer-labs/v2-interfaces/contracts/pool-utils/IRateProvider.sol"; -import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersionProvider.sol"; +import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersion.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/FixedPoint.sol"; import "@balancer-labs/v2-solidity-utils/contracts/math/Math.sol"; @@ -51,7 +51,7 @@ import "./StableMath.sol"; */ contract ComposableStablePool is IRateProvider, - IVersionProvider, + IVersion, BaseGeneralPool, StablePoolAmplification, ComposableStablePoolRates, @@ -66,7 +66,7 @@ contract ComposableStablePool is // We are preminting half of that value (rounded up). uint256 private constant _PREMINTED_TOKEN_BALANCE = 2**(111); - IVersionProvider private immutable _versionProvider; + string private _version; // The constructor arguments are received in a struct to work around stack-too-deep issues struct NewPoolParams { @@ -83,7 +83,7 @@ contract ComposableStablePool is uint256 pauseWindowDuration; uint256 bufferPeriodDuration; address owner; - IVersionProvider versionProvider; + string version; } constructor(NewPoolParams memory params) @@ -104,7 +104,7 @@ contract ComposableStablePool is ComposableStablePoolRates(_extractRatesParams(params)) ProtocolFeeCache(params.protocolFeeProvider, ProtocolFeeCache.DELEGATE_PROTOCOL_SWAP_FEES_SENTINEL) { - _versionProvider = params.versionProvider; + _version = params.version; } // Translate parameters to avoid stack-too-deep issues in the constructor @@ -136,7 +136,7 @@ contract ComposableStablePool is } function version() external view override returns (string memory) { - return _versionProvider.version(); + return _version; } /** diff --git a/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol b/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol index 257bf4f038..c3036b8ba8 100644 --- a/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol +++ b/pkg/pool-stable/contracts/ComposableStablePoolFactory.sol @@ -15,7 +15,8 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; -import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersionProvider.sol"; +import "@balancer-labs/v2-interfaces/contracts/pool-utils/IPoolVersion.sol"; +import "@balancer-labs/v2-interfaces/contracts/pool-utils/IVersion.sol"; import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol"; import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IProtocolFeePercentagesProvider.sol"; @@ -24,23 +25,30 @@ import "@balancer-labs/v2-pool-utils/contracts/factories/FactoryWidePauseWindow. import "./ComposableStablePool.sol"; -contract ComposableStablePoolFactory is IVersionProvider, BasePoolSplitCodeFactory, FactoryWidePauseWindow { +contract ComposableStablePoolFactory is IVersion, IPoolVersion, BasePoolSplitCodeFactory, FactoryWidePauseWindow { IProtocolFeePercentagesProvider private _protocolFeeProvider; string private _version; + string private _poolVersion; constructor( IVault vault, IProtocolFeePercentagesProvider protocolFeeProvider, - string memory version + string memory factoryVersion, + string memory poolVersion ) BasePoolSplitCodeFactory(vault, type(ComposableStablePool).creationCode) { _protocolFeeProvider = protocolFeeProvider; - _version = version; + _version = factoryVersion; + _poolVersion = poolVersion; } function version() external view override returns (string memory) { return _version; } + function getPoolVersion() public view override returns (string memory) { + return _poolVersion; + } + /** * @dev Deploys a new `ComposableStablePool`. */ @@ -74,7 +82,7 @@ contract ComposableStablePoolFactory is IVersionProvider, BasePoolSplitCodeFacto pauseWindowDuration: pauseWindowDuration, bufferPeriodDuration: bufferPeriodDuration, owner: owner, - versionProvider: this + version: getPoolVersion() }) ) ) diff --git a/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts b/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts index fbd288bb99..e7a4fbad8c 100644 --- a/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts +++ b/pkg/pool-stable/test/ComposableStablePoolFactory.test.ts @@ -27,7 +27,7 @@ describe('ComposableStablePoolFactory', function () { let createTime: BigNumber; let protocolFeeExemptFlags: boolean[]; - let version: string; + let factoryVersion: string, poolVersion: string; before('setup signers', async () => { [, owner] = await ethers.getSigners(); @@ -35,13 +35,18 @@ describe('ComposableStablePoolFactory', function () { sharedBeforeEach('deploy factory & tokens', async () => { vault = await Vault.create(); - version = JSON.stringify({ + factoryVersion = JSON.stringify({ + name: 'ComposableStablePoolFactory', + version: '1', + deployment: 'test-deployment', + }); + poolVersion = JSON.stringify({ name: 'ComposableStablePool', version: '0', deployment: 'test-deployment', }); factory = await deploy('ComposableStablePoolFactory', { - args: [vault.address, vault.getFeesProvider().address, version], + args: [vault.address, vault.getFeesProvider().address, factoryVersion, poolVersion], }); createTime = await currentTimestamp(); @@ -78,16 +83,20 @@ describe('ComposableStablePoolFactory', function () { pool = await createPool(); }); - it('checks the version in the factory', async () => { - expect(await factory.version()).to.equal(version); + it('sets the factory version', async () => { + expect(await factory.version()).to.equal(factoryVersion); }); it('sets the vault', async () => { expect(await pool.getVault()).to.equal(vault.address); }); - it('sets the version in the pool', async () => { - expect(await pool.version()).to.equal(version); + it('sets the pool version', async () => { + expect(await pool.version()).to.equal(poolVersion); + }); + + it('gets pool version from the factory', async () => { + expect(await factory.getPoolVersion()).to.equal(poolVersion); }); it('registers tokens in the vault', async () => { diff --git a/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts b/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts index e1fbc26b7e..044f53326a 100644 --- a/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts +++ b/pvt/helpers/src/models/pools/stable/StablePoolDeployer.ts @@ -41,8 +41,6 @@ export default { const owner = TypesConverter.toAddress(params.owner); - const versionProvider = await deploy('v2-pool-utils/MockVersionProvider', { args: [version] }); - return deploy('v2-pool-stable/MockComposableStablePool', { args: [ { @@ -59,7 +57,7 @@ export default { pauseWindowDuration, bufferPeriodDuration, owner, - versionProvider: versionProvider.address, + version: version, }, ], from, From 758891683cffee3fa359083821dd0c62d1e9fb0f Mon Sep 17 00:00:00 2001 From: Juan Ignacio Ubeira Date: Wed, 23 Nov 2022 09:52:09 -0300 Subject: [PATCH 6/7] Fix benchmarks. --- pvt/benchmarks/misc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvt/benchmarks/misc.ts b/pvt/benchmarks/misc.ts index 1cfde07f16..88fe0a26b1 100644 --- a/pvt/benchmarks/misc.ts +++ b/pvt/benchmarks/misc.ts @@ -208,7 +208,7 @@ async function deployPoolFromFactory( }); factory = await deploy(`${fullName}Factory`, { args: [baseFactory.address] }); } else if (poolName == 'ComposableStablePool') { - factory = await deploy(`${fullName}Factory`, { args: [vault.address, protocolFeesProvider.address] }); + factory = await deploy(`${fullName}Factory`, { args: [vault.address, protocolFeesProvider.address, '', ''] }); } else { factory = await deploy(`${fullName}Factory`, { args: [vault.address] }); } From 15b1d83767583bc2d06df1efdbd361705acfefca Mon Sep 17 00:00:00 2001 From: Juan Ignacio Ubeira Date: Wed, 23 Nov 2022 09:52:58 -0300 Subject: [PATCH 7/7] Remove IVersionProvider. --- .../contracts/pool-utils/IVersionProvider.sol | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 pkg/interfaces/contracts/pool-utils/IVersionProvider.sol diff --git a/pkg/interfaces/contracts/pool-utils/IVersionProvider.sol b/pkg/interfaces/contracts/pool-utils/IVersionProvider.sol deleted file mode 100644 index 091c940ec8..0000000000 --- a/pkg/interfaces/contracts/pool-utils/IVersionProvider.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -pragma solidity >=0.7.0 <0.9.0; - -/** - * @notice Simple interface to retrieve the version of a deployed contract. - * - * @dev The contract implementing the interface may provide the actual version, or forward the call to another - * version provider (e.g. a pool will forward the call to its respective pool factory). - */ -interface IVersionProvider { - /** - * @dev Returns a JSON representation of the contract version containing name, version number and task ID. - */ - function version() external view returns (string memory); -}