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

After pool creation hook #118

Merged
merged 4 commits into from
Jun 17, 2024
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
8 changes: 8 additions & 0 deletions src/core/contracts/AlgebraFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ contract AlgebraFactory is IAlgebraFactory, Ownable2Step, AccessControlEnumerabl

pool = IAlgebraPoolDeployer(poolDeployer).deploy(plugin, token0, token1, deployer);

if (deployer == address(0)) {
if (address(defaultPluginFactory) != address(0)) {
defaultPluginFactory.afterCreatePoolHook(plugin, pool, deployer);
}
} else {
IAlgebraPluginFactory(msg.sender).afterCreatePoolHook(plugin, pool, deployer);
}

_poolByPair[token0][token1] = pool;
_poolByPair[token1][token0] = pool;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ interface IAlgebraPluginFactory {
address token1,
bytes calldata data
) external returns (address);

/// @notice Called after the pool is created
/// @param plugin The plugin address
/// @param pool The address of the new pool
/// @param deployer The address of new plugin deployer contract (0 if not used)
function afterCreatePoolHook(address plugin, address pool, address deployer) external;
}
2 changes: 2 additions & 0 deletions src/core/contracts/test/MockCustomPoolCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ contract MockCustomPoolCreator is IAlgebraPluginFactory {
emit BeforeCreateHook(pool, creator, deployer, token0, token1, data);
}

function afterCreatePoolHook(address plugin, address pool, address deployer) external override {}

function createCustomPool(address factory, address tokenA, address tokenB, bytes calldata data) external returns (address pool) {
pool = IAlgebraFactory(factory).createCustomPool(address(this), msg.sender, tokenA, tokenB, data);
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/contracts/test/MockDefaultPluginFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import './MockPoolPlugin.sol';
contract MockDefaultPluginFactory is IAlgebraPluginFactory {
mapping(address => address) public pluginsForPools;

function afterCreatePoolHook(address plugin, address pool, address deployer) external override {}

function beforeCreatePoolHook(address pool, address, address, address, address, bytes calldata) external override returns (address plugin) {
plugin = address(new MockPoolPlugin(pool));
pluginsForPools[pool] = plugin;
Expand Down
10 changes: 5 additions & 5 deletions src/core/test/__snapshots__/AlgebraFactory.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AlgebraFactory #createCustomPool gas [ @skip-on-coverage ] 1`] = `4833064`;
exports[`AlgebraFactory #createCustomPool gas [ @skip-on-coverage ] 1`] = `4833685`;

exports[`AlgebraFactory #createCustomPool gas for second pool [ @skip-on-coverage ] 1`] = `4833064`;
exports[`AlgebraFactory #createCustomPool gas for second pool [ @skip-on-coverage ] 1`] = `4833685`;

exports[`AlgebraFactory #createPool gas [ @skip-on-coverage ] 1`] = `4820775`;
exports[`AlgebraFactory #createPool gas [ @skip-on-coverage ] 1`] = `4820932`;

exports[`AlgebraFactory #createPool gas for second pool [ @skip-on-coverage ] 1`] = `4820775`;
exports[`AlgebraFactory #createPool gas for second pool [ @skip-on-coverage ] 1`] = `4820932`;

exports[`AlgebraFactory factory bytecode size [ @skip-on-coverage ] 1`] = `10254`;
exports[`AlgebraFactory factory bytecode size [ @skip-on-coverage ] 1`] = `10609`;

exports[`AlgebraFactory pool bytecode size [ @skip-on-coverage ] 1`] = `22844`;
7 changes: 7 additions & 0 deletions src/periphery/contracts/AlgebraCustomPoolEntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ contract AlgebraCustomPoolEntryPoint is IAlgebraCustomPoolEntryPoint {
return IAlgebraPluginFactory(deployer).beforeCreatePoolHook(pool, creator, deployer, token0, token1, data);
}

/// @inheritdoc IAlgebraPluginFactory
function afterCreatePoolHook(address plugin, address pool, address deployer) external override {
require(msg.sender == factory, 'Only factory');

IAlgebraPluginFactory(deployer).afterCreatePoolHook(plugin, pool, deployer);
}

// ####### Permissioned actions #######
// AlgebraCustomPoolEntryPoint must have a "POOLS_ADMINISTRATOR" role to be able to use permissioned actions

Expand Down
4 changes: 4 additions & 0 deletions src/periphery/contracts/test/CustomPoolDeployerTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ contract CustomPoolDeployerTest {
return poolToPlugin[pool];
}

function afterCreatePoolHook(address, address, address) external pure {
return;
}

function setPluginForPool(address pool, address plugin) external {
poolToPlugin[pool] = plugin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`NonfungiblePositionManager #collect gas transfers token0 only [ @skip-o

exports[`NonfungiblePositionManager #collect gas transfers token1 only [ @skip-on-coverage ] 1`] = `116994`;

exports[`NonfungiblePositionManager #createAndInitializePoolIfNecessary gas [ @skip-on-coverage ] 1`] = `4812858`;
exports[`NonfungiblePositionManager #createAndInitializePoolIfNecessary gas [ @skip-on-coverage ] 1`] = `4813015`;

exports[`NonfungiblePositionManager #decreaseLiquidity gas complete decrease [ @skip-on-coverage ] 1`] = `167586`;

Expand Down
5 changes: 5 additions & 0 deletions src/plugin/contracts/BasePluginV1Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ contract BasePluginV1Factory is IBasePluginV1Factory {
return _createPlugin(pool);
}

/// @inheritdoc IAlgebraPluginFactory
function afterCreatePoolHook(address, address, address) external view override {
require(msg.sender == algebraFactory);
}

/// @inheritdoc IBasePluginV1Factory
function createPluginForExistingPool(address token0, address token1) external override returns (address) {
IAlgebraFactory factory = IAlgebraFactory(algebraFactory);
Expand Down
5 changes: 5 additions & 0 deletions src/plugin/contracts/test/MockTimeDSFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ contract MockTimeDSFactory is IBasePluginV1Factory {
return _createPlugin(pool);
}

/// @inheritdoc IAlgebraPluginFactory
function afterCreatePoolHook(address, address, address) external view override {
require(msg.sender == algebraFactory);
}

function createPluginForExistingPool(address token0, address token1) external override returns (address) {
IAlgebraFactory factory = IAlgebraFactory(algebraFactory);
require(factory.hasRoleOrOwner(factory.POOLS_ADMINISTRATOR_ROLE(), msg.sender));
Expand Down
Loading