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

Aave linear pool versioning #2032

Merged
merged 4 commits into from
Nov 22, 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
28 changes: 28 additions & 0 deletions pkg/interfaces/contracts/pool-utils/IPoolVersion.sol
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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);
}
25 changes: 25 additions & 0 deletions pkg/interfaces/contracts/pool-utils/IVersion.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

/**
* @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);
}
5 changes: 4 additions & 1 deletion pkg/pool-linear/contracts/aave/AaveLinearPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ pragma experimental ABIEncoderV2;

import "@balancer-labs/v2-interfaces/contracts/pool-linear/IStaticAToken.sol";
import "@balancer-labs/v2-pool-utils/contracts/lib/ExternalCallLib.sol";
import "@balancer-labs/v2-pool-utils/contracts/Version.sol";

import "../LinearPool.sol";

contract AaveLinearPool is LinearPool {
contract AaveLinearPool is LinearPool, Version {
ILendingPool private immutable _lendingPool;

struct ConstructorArgs {
Expand All @@ -35,6 +36,7 @@ contract AaveLinearPool is LinearPool {
uint256 pauseWindowDuration;
uint256 bufferPeriodDuration;
address owner;
string version;
}

constructor(ConstructorArgs memory args)
Expand All @@ -51,6 +53,7 @@ contract AaveLinearPool is LinearPool {
args.bufferPeriodDuration,
args.owner
)
Version(args.version)
{
_lendingPool = IStaticAToken(address(args.wrappedToken)).LENDING_POOL();
_require(address(args.mainToken) == IStaticAToken(address(args.wrappedToken)).ASSET(), Errors.TOKENS_MISMATCH);
Expand Down
26 changes: 22 additions & 4 deletions pkg/pool-linear/contracts/aave/AaveLinearPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import "@balancer-labs/v2-interfaces/contracts/standalone-utils/IBalancerQueries.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-utils/ILastCreatedPoolFactory.sol";
import "@balancer-labs/v2-interfaces/contracts/pool-utils/IPoolVersion.sol";

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

Expand All @@ -28,26 +30,41 @@ import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/ReentrancyGuard.
import "./AaveLinearPool.sol";
import "./AaveLinearPoolRebalancer.sol";

contract AaveLinearPoolFactory is ILastCreatedPoolFactory, BasePoolFactory, ReentrancyGuard, FactoryWidePauseWindow {
contract AaveLinearPoolFactory is
ILastCreatedPoolFactory,
IPoolVersion,
Version,
BasePoolFactory,
ReentrancyGuard,
FactoryWidePauseWindow
{
// Used for create2 deployments
uint256 private _nextRebalancerSalt;

IBalancerQueries private immutable _queries;

address private _lastCreatedPool;
string private _poolVersion;

constructor(
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
IBalancerQueries queries
) BasePoolFactory(vault, protocolFeeProvider, type(AaveLinearPool).creationCode) {
IBalancerQueries queries,
string memory factoryVersion,
string memory poolVersion
) BasePoolFactory(vault, protocolFeeProvider, type(AaveLinearPool).creationCode) Version(factoryVersion) {
_queries = queries;
_poolVersion = poolVersion;
}

function getLastCreatedPool() external view override returns (address) {
return _lastCreatedPool;
}

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

function _create(bytes memory constructorArgs) internal virtual override returns (address) {
address pool = super._create(constructorArgs);
_lastCreatedPool = pool;
Expand Down Expand Up @@ -103,7 +120,8 @@ contract AaveLinearPoolFactory is ILastCreatedPoolFactory, BasePoolFactory, Reen
swapFeePercentage: swapFeePercentage,
pauseWindowDuration: pauseWindowDuration,
bufferPeriodDuration: bufferPeriodDuration,
owner: owner
owner: owner,
version: getPoolVersion()
});

AaveLinearPool pool = AaveLinearPool(_create(abi.encode(args)));
Expand Down
2 changes: 1 addition & 1 deletion pkg/pool-linear/test/AaveLinearPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('AaveLinearPool', function () {
vault = await Vault.create();
const queries = await deploy('v2-standalone-utils/BalancerQueries', { args: [vault.address] });
poolFactory = await deploy('AaveLinearPoolFactory', {
args: [vault.address, vault.getFeesProvider().address, queries.address],
args: [vault.address, vault.getFeesProvider().address, queries.address, 'factoryVersion', 'poolVersion'],
});
});

Expand Down
27 changes: 25 additions & 2 deletions pkg/pool-linear/test/AaveLinearPoolFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Token from '@balancer-labs/v2-helpers/src/models/tokens/Token';
describe('AaveLinearPoolFactory', function () {
let vault: Vault, tokens: TokenList, factory: Contract;
let creationTime: BigNumber, owner: SignerWithAddress;
let factoryVersion: string, poolVersion: string;

const NAME = 'Balancer Linear Pool Token';
const SYMBOL = 'LPT';
Expand All @@ -30,8 +31,18 @@ describe('AaveLinearPoolFactory', function () {
sharedBeforeEach('deploy factory & tokens', async () => {
vault = await Vault.create();
const queries = await deploy('v2-standalone-utils/BalancerQueries', { args: [vault.address] });
factoryVersion = JSON.stringify({
name: 'AaveLinearPoolFactory',
version: '3',
deployment: 'test-deployment',
});
poolVersion = JSON.stringify({
name: 'AaveLinearPool',
version: '1',
deployment: 'test-deployment',
});
factory = await deploy('AaveLinearPoolFactory', {
args: [vault.address, vault.getFeesProvider().address, queries.address],
args: [vault.address, vault.getFeesProvider().address, queries.address, factoryVersion, poolVersion],
});
creationTime = await currentTimestamp();

Expand All @@ -58,7 +69,7 @@ describe('AaveLinearPoolFactory', function () {
);

const event = expectEvent.inReceipt(await receipt.wait(), 'PoolCreated');
return deployedAt('LinearPool', event.args.pool);
return deployedAt('AaveLinearPool', event.args.pool);
}

describe('constructor arguments', () => {
Expand All @@ -72,6 +83,18 @@ describe('AaveLinearPoolFactory', function () {
expect(await pool.getVault()).to.equal(vault.address);
});

it('checks the factory version', async () => {
expect(await factory.version()).to.equal(factoryVersion);
});

it('checks the pool version', async () => {
expect(await pool.version()).to.equal(poolVersion);
});

it('checks the pool version in the factory', async () => {
expect(await factory.getPoolVersion()).to.equal(poolVersion);
});

it('registers tokens in the vault', async () => {
const poolId = await pool.getPoolId();
const poolTokens = await vault.getPoolTokens(poolId);
Expand Down
32 changes: 32 additions & 0 deletions pkg/pool-utils/contracts/Version.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.0;

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

/**
* @notice Retrieves a contract's version set at creation time from storage.
*/
contract Version is IVersion {
string private _version;

constructor(string memory version) {
_version = version;
}

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