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 3 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/IVersionProvider.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 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);
}
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;
IVersionProvider versionProvider;
}

constructor(ConstructorArgs memory args)
Expand All @@ -51,6 +53,7 @@ contract AaveLinearPool is LinearPool {
args.bufferPeriodDuration,
args.owner
)
Version(args.versionProvider)
{
_lendingPool = IStaticAToken(address(args.wrappedToken)).LENDING_POOL();
_require(address(args.mainToken) == IStaticAToken(address(args.wrappedToken)).ASSET(), Errors.TOKENS_MISMATCH);
Expand Down
21 changes: 18 additions & 3 deletions pkg/pool-linear/contracts/aave/AaveLinearPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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/IVersionProvider.sol";

import "@balancer-labs/v2-pool-utils/contracts/factories/BasePoolFactory.sol";
import "@balancer-labs/v2-pool-utils/contracts/factories/FactoryWidePauseWindow.sol";
Expand All @@ -28,20 +29,33 @@ 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,
IVersionProvider,
BasePoolFactory,
ReentrancyGuard,
FactoryWidePauseWindow
{
// Used for create2 deployments
uint256 private _nextRebalancerSalt;

IBalancerQueries private immutable _queries;
string private _version;

address private _lastCreatedPool;

constructor(
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
IBalancerQueries queries
IBalancerQueries queries,
string memory version
) BasePoolFactory(vault, protocolFeeProvider, type(AaveLinearPool).creationCode) {
_queries = queries;
_version = version;
}

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

function getLastCreatedPool() external view override returns (address) {
Expand Down Expand Up @@ -103,7 +117,8 @@ contract AaveLinearPoolFactory is ILastCreatedPoolFactory, BasePoolFactory, Reen
swapFeePercentage: swapFeePercentage,
pauseWindowDuration: pauseWindowDuration,
bufferPeriodDuration: bufferPeriodDuration,
owner: owner
owner: owner,
versionProvider: this
});

AaveLinearPool pool = AaveLinearPool(_create(abi.encode(args)));
Expand Down
3 changes: 2 additions & 1 deletion pkg/pool-linear/test/AaveLinearPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ describe('AaveLinearPool', function () {
sharedBeforeEach('deploy pool factory', async () => {
vault = await Vault.create();
const queries = await deploy('v2-standalone-utils/BalancerQueries', { args: [vault.address] });
const version = 'test';
poolFactory = await deploy('AaveLinearPoolFactory', {
args: [vault.address, vault.getFeesProvider().address, queries.address],
args: [vault.address, vault.getFeesProvider().address, queries.address, version],
});
});

Expand Down
18 changes: 16 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 version: string;

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

Expand All @@ -58,7 +64,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 +78,14 @@ describe('AaveLinearPoolFactory', function () {
expect(await pool.getVault()).to.equal(vault.address);
});

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

it('checks the pool version', async () => {
expect(await pool.version()).to.equal(version);
});
nventuro marked this conversation as resolved.
Show resolved Hide resolved

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

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();
}
}