diff --git a/src/plugin/contracts/BasePluginV1Factory.sol b/src/plugin/contracts/BasePluginV1Factory.sol index b09161d7..6a36e71e 100644 --- a/src/plugin/contracts/BasePluginV1Factory.sol +++ b/src/plugin/contracts/BasePluginV1Factory.sol @@ -8,6 +8,7 @@ import './libraries/AdaptiveFee.sol'; import '@cryptoalgebra/algebra-modular-hub-v0.8.20/contracts/AlgebraModularHub.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol'; +import '@cryptoalgebra/integral-core/contracts/interfaces/plugin/IAlgebraPlugin.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/Plugins.sol'; /// @title Algebra Integral 1.1 default plugin factory @@ -63,19 +64,35 @@ contract BasePluginV1Factory is IBasePluginV1Factory { AlgebraModularHub modularHub = new AlgebraModularHub(pool, algebraFactory); - IAlgebraPool(pool).setPlugin(address(modularHub)); + InsertModuleParams[] memory moduleParams = new InsertModuleParams[](factoriesCounter); for (uint256 i = 0; i < factoriesCounter; ++i) { address moduleFactoryAddress = factoryByIndex[i]; address moduleAddress = IAlgebraModuleFactory(moduleFactoryAddress).deploy(address(modularHub)); uint256 globalModuleIndex = modularHub.registerModule(moduleAddress); - InsertModuleParams[] memory insertModuleParams = IAlgebraModuleFactory(moduleFactoryAddress).getInsertModuleParams(globalModuleIndex); + // InsertModuleParams[] memory insertModuleParams = IAlgebraModuleFactory(moduleFactoryAddress).getInsertModuleParams(globalModuleIndex); - modularHub.insertModulesToHookLists(insertModuleParams); + // modularHub.insertModulesToHookLists(insertModuleParams); + + moduleParams[i] = (InsertModuleParams({ + selector: IAlgebraPlugin.beforeInitialize.selector, + indexInHookList: i, + moduleGlobalIndex: globalModuleIndex, + useDelegate: true, + useDynamicFee: IAlgebraModuleFactory(moduleFactoryAddress).useDynamicFee() + })); } - IAlgebraPool(pool).setPluginConfig(uint8(Plugins.DYNAMIC_FEE)); + IAlgebraModularHub(modularHub).insertModulesToHookLists(moduleParams); + + // struct InsertModuleParams { + // bytes4 selector; + // uint256 indexInHookList; + // uint256 moduleGlobalIndex; + // bool useDelegate; + // bool useDynamicFee; + // } pluginByPool[pool] = address(modularHub); return address(modularHub); diff --git a/src/plugin/contracts/interfaces/IAlgebraModuleFactory.sol b/src/plugin/contracts/interfaces/IAlgebraModuleFactory.sol index 8263b265..76b9617f 100644 --- a/src/plugin/contracts/interfaces/IAlgebraModuleFactory.sol +++ b/src/plugin/contracts/interfaces/IAlgebraModuleFactory.sol @@ -5,9 +5,11 @@ import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraFactory.sol'; import '@cryptoalgebra/algebra-modular-hub-v0.8.20/contracts/types/InsertModuleParams.sol'; interface IAlgebraModuleFactory { - function algebraFactory() external returns (address); + function algebraFactory() external view returns (address); + + function useDynamicFee() external view returns (bool); function deploy(address modularHub) external returns (address); - function getInsertModuleParams(uint256 moduleGlobalIndex) external pure returns (InsertModuleParams[] memory); + // function getInsertModuleParams(uint256 moduleGlobalIndex) external pure returns (InsertModuleParams[] memory); } diff --git a/src/plugin/contracts/modules/DynamicFeeModule.sol b/src/plugin/contracts/modules/DynamicFeeModule.sol index a2b34d14..46d38a66 100644 --- a/src/plugin/contracts/modules/DynamicFeeModule.sol +++ b/src/plugin/contracts/modules/DynamicFeeModule.sol @@ -18,6 +18,8 @@ import '../interfaces/plugins/IVolatilityOracle.sol'; import '../libraries/AdaptiveFee.sol'; import '../libraries/VolatilityOracle.sol'; +import 'hardhat/console.sol'; + contract DynamicFeeModule is AlgebraModule, IDynamicFeeManager, Timestamp { using Plugins for uint8; using AlgebraFeeConfigurationU144Lib for AlgebraFeeConfiguration; @@ -92,6 +94,34 @@ contract DynamicFeeModule is AlgebraModule, IDynamicFeeManager, Timestamp { (price, tick, fee, pluginConfig, , ) = IAlgebraPoolState(pool).globalState(); } + function _beforeInitialize( + bytes memory /* params */, + uint16 /* poolFeeCache */ + ) internal override { + console.log('Dynamic fee'); + + InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); + + // dynamic fee hooks shoule be called after oracle, so indexInHookList = 1 + insertModuleParams[0] = InsertModuleParams({ + selector: IAlgebraPlugin.afterInitialize.selector, + indexInHookList: 1, + moduleGlobalIndex: 2, // ❗❗❗ подумать как сделать получше ❗❗❗ + useDelegate: false, + useDynamicFee: true + }); + + insertModuleParams[1] = InsertModuleParams({ + selector: IAlgebraPlugin.beforeSwap.selector, + indexInHookList: 1, + moduleGlobalIndex: 2, + useDelegate: false, + useDynamicFee: true + }); + + IAlgebraModularHub(modularHub).insertModulesToHookLists(insertModuleParams); + } + function _afterInitialize( bytes memory /* params */, uint16 /* poolFeeCache */ diff --git a/src/plugin/contracts/modules/DynamicFeeModuleFactory.sol b/src/plugin/contracts/modules/DynamicFeeModuleFactory.sol index df2a1924..e35b8e6f 100644 --- a/src/plugin/contracts/modules/DynamicFeeModuleFactory.sol +++ b/src/plugin/contracts/modules/DynamicFeeModuleFactory.sol @@ -10,6 +10,9 @@ import '@cryptoalgebra/integral-core/contracts/interfaces/plugin/IAlgebraPlugin. contract DynamicFeeModuleFactory is AlgebraModuleFactory { event DefaultFeeConfiguration(AlgebraFeeConfiguration newConfig); + /// @inheritdoc IAlgebraModuleFactory + bool public override useDynamicFee = true; + AlgebraFeeConfiguration public defaultFeeConfiguration; // values of constants for sigmoids in fee calculation formula constructor(address _algebraFactory) AlgebraModuleFactory(_algebraFactory) { @@ -35,26 +38,26 @@ contract DynamicFeeModuleFactory is AlgebraModuleFactory { return address(dynamicFeeModule); } - function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { - InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); - - // dynamic fee hooks shoule be called after oracle, so indexInHookList = 1 - insertModuleParams[0] = InsertModuleParams({ - selector: IAlgebraPlugin.afterInitialize.selector, - indexInHookList: 1, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: true - }); - - insertModuleParams[1] = InsertModuleParams({ - selector: IAlgebraPlugin.beforeSwap.selector, - indexInHookList: 1, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: true - }); - - return insertModuleParams; - } + // function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { + // InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); + + // // dynamic fee hooks shoule be called after oracle, so indexInHookList = 1 + // insertModuleParams[0] = InsertModuleParams({ + // selector: IAlgebraPlugin.afterInitialize.selector, + // indexInHookList: 1, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: true + // }); + + // insertModuleParams[1] = InsertModuleParams({ + // selector: IAlgebraPlugin.beforeSwap.selector, + // indexInHookList: 1, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: true + // }); + + // return insertModuleParams; + // } } diff --git a/src/plugin/contracts/modules/FarmingModule.sol b/src/plugin/contracts/modules/FarmingModule.sol index cc7a599a..a26617fb 100644 --- a/src/plugin/contracts/modules/FarmingModule.sol +++ b/src/plugin/contracts/modules/FarmingModule.sol @@ -81,12 +81,27 @@ contract FarmingModule is AlgebraModule, IFarmingPlugin, Timestamp { (price, tick, fee, pluginConfig, , ) = IAlgebraPoolState(pool).globalState(); } + function _beforeInitialize( + bytes memory /* params */, + uint16 /* poolFeeCache */ + ) internal override { + InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](1); + + insertModuleParams[0] = InsertModuleParams({ + selector: IAlgebraPlugin.afterSwap.selector, + indexInHookList: 0, + moduleGlobalIndex: 3, + useDelegate: false, + useDynamicFee: false + }); + + IAlgebraModularHub(modularHub).insertModulesToHookLists(insertModuleParams); + } + function _afterSwap( bytes memory params , uint16 /* poolFeeCache */ ) internal override { - // console.log("Farming afterInitialize"); - AfterSwapParams memory decodedParams = abi.decode(params, (AfterSwapParams)); address _incentive = incentive; diff --git a/src/plugin/contracts/modules/FarmingModuleFactory.sol b/src/plugin/contracts/modules/FarmingModuleFactory.sol index 03d408d1..2c977599 100644 --- a/src/plugin/contracts/modules/FarmingModuleFactory.sol +++ b/src/plugin/contracts/modules/FarmingModuleFactory.sol @@ -6,8 +6,12 @@ import '../base/AlgebraModuleFactory.sol'; import './FarmingModule.sol'; contract FarmingModuleFactory is AlgebraModuleFactory, IAlgebraFarmingModuleFactory { + /// @inheritdoc IAlgebraFarmingModuleFactory address public override farmingAddress; + /// @inheritdoc IAlgebraModuleFactory + bool public override useDynamicFee = false; + constructor(address _algebraFactory) AlgebraModuleFactory(_algebraFactory) {} function setFarmingAddress(address newFarmingAddress) external override onlyAdministrator { @@ -24,17 +28,17 @@ contract FarmingModuleFactory is AlgebraModuleFactory, IAlgebraFarmingModuleFact return address(farmingModule); } - function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { - InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](1); + // function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { + // InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](1); - insertModuleParams[0] = InsertModuleParams({ - selector: IAlgebraPlugin.afterSwap.selector, - indexInHookList: 0, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: false - }); + // insertModuleParams[0] = InsertModuleParams({ + // selector: IAlgebraPlugin.afterSwap.selector, + // indexInHookList: 0, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: false + // }); - return insertModuleParams; - } + // return insertModuleParams; + // } } diff --git a/src/plugin/contracts/modules/OracleModule.sol b/src/plugin/contracts/modules/OracleModule.sol index b3a8c363..c80b0482 100644 --- a/src/plugin/contracts/modules/OracleModule.sol +++ b/src/plugin/contracts/modules/OracleModule.sol @@ -45,7 +45,7 @@ contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { function initialize() external { require(!isInitialized, 'Already initialized'); require(IAlgebraModularHub(modularHub).moduleAddressToIndex(address(this)) != 0, 'Plugin not attached'); - (uint160 price, int24 tick, , ) = _getPoolState(pool); + (uint160 price, int24 tick, , ) = _getPoolState(); require(price != 0, 'Pool is not initialized'); uint32 time = _blockTimestamp(); @@ -57,7 +57,7 @@ contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { /// @inheritdoc IVolatilityOracle function getSingleTimepoint(uint32 secondsAgo) external view override returns (int56 tickCumulative, uint88 volatilityCumulative) { // `volatilityCumulative` values for timestamps after the last timepoint _should not_ be compared: they may differ due to interpolation errors - (, int24 tick, , ) = _getPoolState(IAlgebraModularHub(modularHub).pool()); + (, int24 tick, , ) = _getPoolState(); uint16 lastTimepointIndex = timepointIndex; uint16 oldestIndex = timepoints.getOldestIndex(lastTimepointIndex); VolatilityOracle.Timepoint memory result = timepoints.getSingleTimepoint(_blockTimestamp(), secondsAgo, tick, lastTimepointIndex, oldestIndex); @@ -69,7 +69,7 @@ contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { uint32[] memory secondsAgos ) external view override returns (int56[] memory tickCumulatives, uint88[] memory volatilityCumulatives) { // `volatilityCumulative` values for timestamps after the last timepoint _should not_ be compared: they may differ due to interpolation errors - (, int24 tick, , ) = _getPoolState(IAlgebraModularHub(modularHub).pool()); + (, int24 tick, , ) = _getPoolState(); return timepoints.getTimepoints(_blockTimestamp(), secondsAgos, tick, timepointIndex); } @@ -89,7 +89,7 @@ contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { uint16 lastIndex = timepointIndex; uint16 oldestIndex = timepoints.getOldestIndex(lastIndex); - (, int24 tick, , ) = _getPoolState(IAlgebraModularHub(modularHub).pool()); + (, int24 tick, , ) = _getPoolState(); return timepoints.getAverageVolatility(_blockTimestamp(), tick, lastIndex, oldestIndex); } @@ -103,14 +103,40 @@ contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { return timepoints.getAverageVolatility(currentTime, tick, lastIndex, oldestIndex); } - function _getPoolState(address pool) internal view returns (uint160 price, int24 tick, uint16 fee, uint8 pluginConfig) { + function _getPoolState() internal view returns (uint160 price, int24 tick, uint16 fee, uint8 pluginConfig) { (price, tick, fee, pluginConfig, , ) = IAlgebraPoolState(pool).globalState(); } - function _getPluginInPool(address pool) internal view returns (address plugin) { + function _getPluginInPool() internal view returns (address plugin) { return IAlgebraPool(pool).plugin(); } + function _beforeInitialize( + bytes memory /* params */, + uint16 /* poolFeeCache */ + ) internal override { + InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); + + // oracle module must be first, so indexInHookList = 0 + insertModuleParams[0] = InsertModuleParams({ + selector: IAlgebraPlugin.afterInitialize.selector, + indexInHookList: 0, + moduleGlobalIndex: 1, + useDelegate: false, + useDynamicFee: false + }); + + insertModuleParams[1] = InsertModuleParams({ + selector: IAlgebraPlugin.beforeSwap.selector, + indexInHookList: 0, + moduleGlobalIndex: 1, + useDelegate: false, + useDynamicFee: false + }); + + IAlgebraModularHub(modularHub).insertModulesToHookLists(insertModuleParams); + } + function _afterInitialize( bytes memory params, uint16 /* poolFeeCache */ @@ -124,14 +150,13 @@ contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { } function _beforeSwap( - bytes memory params, + bytes memory /* params */, uint16 /* poolFeeCache */ ) internal override { - BeforeSwapParams memory decodedParams = abi.decode(params, (BeforeSwapParams)); - _writeTimepoint(decodedParams.pool); + _writeTimepoint(); } - function _writeTimepoint(address pool) internal { + function _writeTimepoint() internal { // console.log('Write timepoint called'); // single SLOAD @@ -145,7 +170,7 @@ contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { if (_lastTimepointTimestamp == currentTimestamp) return; - (, int24 tick, , ) = _getPoolState(pool); + (, int24 tick, , ) = _getPoolState(); // (uint16 newLastIndex, ) = timepoints.write(_lastIndex, currentTimestamp, tick); (uint16 newLastIndex, ) = timepoints.write(_lastIndex, currentTimestamp, tick); diff --git a/src/plugin/contracts/modules/OracleModuleFactory.sol b/src/plugin/contracts/modules/OracleModuleFactory.sol index 3bfb3c9a..15bf4421 100644 --- a/src/plugin/contracts/modules/OracleModuleFactory.sol +++ b/src/plugin/contracts/modules/OracleModuleFactory.sol @@ -5,6 +5,8 @@ import '../base/AlgebraModuleFactory.sol'; import './OracleModule.sol'; contract OracleModuleFactory is AlgebraModuleFactory { + /// @inheritdoc IAlgebraModuleFactory + bool public override useDynamicFee = false; constructor(address _algebraFactory) AlgebraModuleFactory(_algebraFactory) {} function deploy(address modularHub) external onlyAdministrator override returns (address) { @@ -15,26 +17,26 @@ contract OracleModuleFactory is AlgebraModuleFactory { return address(oracleModule); } - function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { - InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); - - // oracle module must be first, so indexInHookList = 0 - insertModuleParams[0] = InsertModuleParams({ - selector: IAlgebraPlugin.afterInitialize.selector, - indexInHookList: 0, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: false - }); - - insertModuleParams[1] = InsertModuleParams({ - selector: IAlgebraPlugin.beforeSwap.selector, - indexInHookList: 0, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: false - }); - - return insertModuleParams; - } + // function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { + // InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); + + // // oracle module must be first, so indexInHookList = 0 + // insertModuleParams[0] = InsertModuleParams({ + // selector: IAlgebraPlugin.afterInitialize.selector, + // indexInHookList: 0, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: false + // }); + + // insertModuleParams[1] = InsertModuleParams({ + // selector: IAlgebraPlugin.beforeSwap.selector, + // indexInHookList: 0, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: false + // }); + + // return insertModuleParams; + // } } diff --git a/src/plugin/contracts/test/MockTimeDSFactory.sol b/src/plugin/contracts/test/MockTimeDSFactory.sol index e35be01b..e4bc3275 100644 --- a/src/plugin/contracts/test/MockTimeDSFactory.sol +++ b/src/plugin/contracts/test/MockTimeDSFactory.sol @@ -60,17 +60,29 @@ contract MockTimeDSFactory is IBasePluginV1Factory { MockPool(pool).setPlugin(address(modularHub)); MockPool(pool).setPluginConfig(uint8(Plugins.DYNAMIC_FEE)); + + InsertModuleParams[] memory moduleParams = new InsertModuleParams[](factoriesCounter); for (uint256 i = 0; i < factoriesCounter; ++i) { address moduleFactoryAddress = factoryByIndex[i]; address moduleAddress = IAlgebraModuleFactory(moduleFactoryAddress).deploy(address(modularHub)); uint256 globalModuleIndex = modularHub.registerModule(moduleAddress); - InsertModuleParams[] memory insertModuleParams = IAlgebraModuleFactory(moduleFactoryAddress).getInsertModuleParams(globalModuleIndex); + // InsertModuleParams[] memory insertModuleParams = IAlgebraModuleFactory(moduleFactoryAddress).getInsertModuleParams(globalModuleIndex); + + // modularHub.insertModulesToHookLists(insertModuleParams); - modularHub.insertModulesToHookLists(insertModuleParams); + moduleParams[i] = (InsertModuleParams({ + selector: IAlgebraPlugin.beforeInitialize.selector, + indexInHookList: i, + moduleGlobalIndex: globalModuleIndex, + useDelegate: true, + useDynamicFee: IAlgebraModuleFactory(moduleFactoryAddress).useDynamicFee() + })); } + IAlgebraModularHub(modularHub).insertModulesToHookLists(moduleParams); + pluginByPool[pool] = address(modularHub); return address(modularHub); } diff --git a/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol b/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol index 96b6f344..8cddfc40 100644 --- a/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol +++ b/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol @@ -10,6 +10,9 @@ import '@cryptoalgebra/integral-core/contracts/interfaces/plugin/IAlgebraPlugin. contract MockTimeDynamicFeeModuleFactory is AlgebraModuleFactory { event DefaultFeeConfiguration(AlgebraFeeConfiguration newConfig); + /// @inheritdoc IAlgebraModuleFactory + bool public override useDynamicFee = true; + AlgebraFeeConfiguration public defaultFeeConfiguration; // values of constants for sigmoids in fee calculation formula constructor(address _algebraFactory) AlgebraModuleFactory(_algebraFactory) { @@ -29,26 +32,26 @@ contract MockTimeDynamicFeeModuleFactory is AlgebraModuleFactory { return address(dynamicFeeModule); } - function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { - InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); - - // dynamic fee hooks shoule be called after oracle, so indexInHookList = 1 - insertModuleParams[0] = InsertModuleParams({ - selector: IAlgebraPlugin.afterInitialize.selector, - indexInHookList: 1, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: true - }); - - insertModuleParams[1] = InsertModuleParams({ - selector: IAlgebraPlugin.beforeSwap.selector, - indexInHookList: 1, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: true - }); - - return insertModuleParams; - } + // function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { + // InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); + + // // dynamic fee hooks shoule be called after oracle, so indexInHookList = 1 + // insertModuleParams[0] = InsertModuleParams({ + // selector: IAlgebraPlugin.afterInitialize.selector, + // indexInHookList: 1, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: true + // }); + + // insertModuleParams[1] = InsertModuleParams({ + // selector: IAlgebraPlugin.beforeSwap.selector, + // indexInHookList: 1, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: true + // }); + + // return insertModuleParams; + // } } diff --git a/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol b/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol index 9d10a459..0ac691eb 100644 --- a/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol +++ b/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol @@ -5,6 +5,9 @@ import '../base/AlgebraModuleFactory.sol'; import './MockTimeOracleModule.sol'; contract MockTimeOracleModuleFactory is AlgebraModuleFactory { + /// @inheritdoc IAlgebraModuleFactory + bool public override useDynamicFee = false; + constructor(address _algebraFactory) AlgebraModuleFactory(_algebraFactory) {} function deploy(address modularHub) external override returns (address) { @@ -13,25 +16,25 @@ contract MockTimeOracleModuleFactory is AlgebraModuleFactory { return address(oracleModule); } - function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { - InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); - - insertModuleParams[0] = InsertModuleParams({ - selector: IAlgebraPlugin.afterInitialize.selector, - indexInHookList: 0, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: false - }); - - insertModuleParams[1] = InsertModuleParams({ - selector: IAlgebraPlugin.beforeSwap.selector, - indexInHookList: 0, - moduleGlobalIndex: moduleGlobalIndex, - useDelegate: false, - useDynamicFee: false - }); - - return insertModuleParams; - } + // function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { + // InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); + + // insertModuleParams[0] = InsertModuleParams({ + // selector: IAlgebraPlugin.afterInitialize.selector, + // indexInHookList: 0, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: false + // }); + + // insertModuleParams[1] = InsertModuleParams({ + // selector: IAlgebraPlugin.beforeSwap.selector, + // indexInHookList: 0, + // moduleGlobalIndex: moduleGlobalIndex, + // useDelegate: false, + // useDynamicFee: false + // }); + + // return insertModuleParams; + // } } diff --git a/src/plugin/test/AlgebraPool.gas.spec.ts b/src/plugin/test/AlgebraPool.gas.spec.ts index 9d7a3d12..89fada6a 100644 --- a/src/plugin/test/AlgebraPool.gas.spec.ts +++ b/src/plugin/test/AlgebraPool.gas.spec.ts @@ -52,6 +52,8 @@ describe('AlgebraPool gas tests [ @skip-on-coverage ]', () => { await mockPluginFactory.beforeCreatePoolHook(pool, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, '0x'); const pluginAddress = await mockPluginFactory.pluginByPool(pool); + await fix.factory.grantRole(ethers.keccak256(ethers.toUtf8Bytes("POOLS_ADMINISTRATOR")), pluginAddress); + const mockDSOperatorFactory = await ethers.getContractFactory('AlgebraModularHub'); const plugin = mockDSOperatorFactory.attach(pluginAddress) as any as AlgebraModularHub; @@ -83,7 +85,7 @@ describe('AlgebraPool gas tests [ @skip-on-coverage ]', () => { const virtualPoolMockFactory = await ethers.getContractFactory('MockTimeVirtualPool'); const virtualPoolMock = (await virtualPoolMockFactory.deploy()) as any as MockTimeVirtualPool; - + await pool.initialize(encodePriceSqrt(1, 1)); await pool.setCommunityVault(wallet.address); diff --git a/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap b/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap index f1356262..7bc4ffc8 100644 --- a/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap +++ b/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap @@ -1,24 +1,24 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee large swap crossing several initialized ticks 1`] = `264198`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee large swap crossing several initialized ticks 1`] = `262643`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle 1`] = `214138`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle 1`] = `212583`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 4h 1`] = `247643`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 4h 1`] = `246088`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 8h 1`] = `242407`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 8h 1`] = `240852`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 24h 1`] = `215878`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 24h 1`] = `214323`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee large swap crossing several initialized ticks 1`] = `264198`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee large swap crossing several initialized ticks 1`] = `262643`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle 1`] = `214138`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle 1`] = `212583`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 4h 1`] = `247735`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 4h 1`] = `246180`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 8h 1`] = `258746`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 8h 1`] = `257191`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 24h 1`] = `215878`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 24h 1`] = `214323`; exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn above current price burn when only position using ticks 1`] = `115281`; @@ -62,82 +62,82 @@ exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #mint below curre exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #poke best case 1`] = `61481`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `204662`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `203107`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement 1`] = `204631`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement 1`] = `203076`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `204202`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `202647`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `221170`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `219615`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `254564`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `253009`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `204729`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `203174`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `254564`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `253009`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `273764`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `272209`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `176868`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `175346`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block with no tick movement 1`] = `176832`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block with no tick movement 1`] = `175310`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `192561`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `191039`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `226776`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `225254`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 several large swaps with pauses 1`] = `281593`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 several large swaps with pauses 1`] = `280038`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `212329`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `210774`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `204723`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `203168`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block with no tick movement 1`] = `204671`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block with no tick movement 1`] = `203116`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 second swap in block with no tick movement 1`] = `176893`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 second swap in block with no tick movement 1`] = `175371`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `231850`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `230295`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block with no tick movement 1`] = `231798`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block with no tick movement 1`] = `230243`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected second swap in block with no tick movement 1`] = `186920`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected second swap in block with no tick movement 1`] = `185398`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `212485`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `210930`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `212454`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `210899`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `204439`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `202884`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `229230`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `227675`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `263335`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `261780`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `212552`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `210997`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `263335`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `261780`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `282535`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `280980`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `184691`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `183169`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `184655`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `183133`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `200621`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `199099`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `235547`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `234025`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `290364`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `288809`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `212566`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `211011`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `212546`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `210991`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `212494`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `210939`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `184716`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `183194`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `239673`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `238118`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `239621`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `238066`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `194743`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `193221`; diff --git a/src/plugin/test/shared/fixtures.ts b/src/plugin/test/shared/fixtures.ts index 09d2df48..01b4ba4f 100644 --- a/src/plugin/test/shared/fixtures.ts +++ b/src/plugin/test/shared/fixtures.ts @@ -56,6 +56,7 @@ export const pluginFixture: Fixture = async function (): Promise< await mockPluginFactory.beforeCreatePoolHook(mockPool, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, '0x'); const pluginAddress = await mockPluginFactory.pluginByPool(mockPool); + await mockFactory.grantRole(ethers.keccak256(ethers.toUtf8Bytes("POOLS_ADMINISTRATOR")), pluginAddress); const algebraModularHubFactory = await ethers.getContractFactory('AlgebraModularHub'); const plugin = algebraModularHubFactory.attach(pluginAddress) as any as AlgebraModularHub;