From 4df0b72db7d6292da6165affa3dfc97d3dcde0a9 Mon Sep 17 00:00:00 2001 From: fourlen Date: Mon, 3 Jun 2024 16:06:45 +0300 Subject: [PATCH] tests --- src/farming/test/unit/FarmingCenter.spec.ts | 62 +++++++---- src/farming/test/unit/Multicall.spec.ts | 1 + .../__snapshots__/EternalFarms.spec.ts.snap | 7 ++ .../contracts/modules/DynamicFeeModule.sol | 5 - .../contracts/modules/FarmingModule.sol | 3 - src/plugin/contracts/modules/OracleModule.sol | 2 + src/plugin/contracts/test/MockPool.sol | 2 + .../contracts/test/MockTimeDSFactory.sol | 9 +- .../test/MockTimeDynamicFeeModuleFactory.sol | 1 - .../test/MockTimeOracleModuleFactory.sol | 1 + src/plugin/test/AlgebraPool.gas.spec.ts | 1 + .../AlgebraPool.gas.spec.ts.snap | 100 ++++++++--------- .../VolatilityOracle.spec.ts.snap | 101 ++++++++++++++++++ src/plugin/test/shared/fixtures.ts | 2 + 14 files changed, 214 insertions(+), 83 deletions(-) create mode 100644 src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap create mode 100644 src/plugin/test/__snapshots__/VolatilityOracle.spec.ts.snap diff --git a/src/farming/test/unit/FarmingCenter.spec.ts b/src/farming/test/unit/FarmingCenter.spec.ts index 9b77a2c9e..eb87760f7 100644 --- a/src/farming/test/unit/FarmingCenter.spec.ts +++ b/src/farming/test/unit/FarmingCenter.spec.ts @@ -1,7 +1,7 @@ import { ethers } from 'hardhat'; import { Wallet } from 'ethers'; import { loadFixture, impersonateAccount, stopImpersonatingAccount, setBalance } from '@nomicfoundation/hardhat-network-helpers'; -import { TestERC20, AlgebraEternalFarming, NftPosManagerMock, FarmingCenter } from '../../typechain'; +import { TestERC20, AlgebraEternalFarming, NftPosManagerMock, FarmingCenter, IFarmingPlugin } from '../../typechain'; import { algebraFixture, AlgebraFixtureType, mintPosition } from '../shared/fixtures'; import { expect, @@ -82,7 +82,8 @@ describe('unit/FarmingCenter', () => { await impersonateAccount(eternalFarmingAddress); await setBalance(eternalFarmingAddress, 10 ** 18); const fakeSigner = await ethers.getSigner(eternalFarmingAddress); - await context.farmingCenter.connect(fakeSigner).connectVirtualPoolToPlugin(context.pool01, context.pluginObj, { from: eternalFarmingAddress }); + const farmingModuleAddress = await context.farmingModuleFactory.poolToPlugin(context.poolObj); + await context.farmingCenter.connect(fakeSigner).connectVirtualPoolToPlugin(context.pool01, farmingModuleAddress, { from: eternalFarmingAddress }); await setBalance(eternalFarmingAddress, 0); await stopImpersonatingAccount(eternalFarmingAddress); expect(await context.farmingCenter.virtualPoolAddresses(context.pool01)).to.not.be.eq(ZERO_ADDRESS); @@ -93,11 +94,15 @@ describe('unit/FarmingCenter', () => { await impersonateAccount(eternalFarmingAddress); await setBalance(eternalFarmingAddress, 10 ** 18); const fakeSigner = await ethers.getSigner(eternalFarmingAddress); - await context.pluginFactory.setFarmingAddress(incentiveCreator); - await context.pluginObj.connect(incentiveCreator).setIncentive(eternalFarmingAddress); - await context.pluginFactory.setFarmingAddress(context.farmingCenter); + + const farmingModuleAddress = await context.farmingModuleFactory.poolToPlugin(context.pool01); + const farmingModule = await ethers.getContractAt('FarmingModule', farmingModuleAddress) as any as IFarmingPlugin; + + await context.farmingModuleFactory.setFarmingAddress(incentiveCreator); + await farmingModule.connect(incentiveCreator).setIncentive(eternalFarmingAddress); + await context.farmingModuleFactory.setFarmingAddress(context.farmingCenter); await expect( - context.farmingCenter.connect(fakeSigner).connectVirtualPoolToPlugin(context.pool01, context.pluginObj, { from: eternalFarmingAddress }) + context.farmingCenter.connect(fakeSigner).connectVirtualPoolToPlugin(context.pool01, farmingModule, { from: eternalFarmingAddress }) ).to.be.revertedWith('Another incentive is connected'); await setBalance(eternalFarmingAddress, 0); await stopImpersonatingAccount(eternalFarmingAddress); @@ -143,10 +148,11 @@ describe('unit/FarmingCenter', () => { await impersonateAccount(eternalFarmingAddress); await setBalance(eternalFarmingAddress, 10 ** 18); const fakeSigner = await ethers.getSigner(eternalFarmingAddress); - await context.farmingCenter.connect(fakeSigner).connectVirtualPoolToPlugin(context.pool01, context.pluginObj, { from: eternalFarmingAddress }); + const farmingModuleAddress = await context.farmingModuleFactory.poolToPlugin(context.pool01); + await context.farmingCenter.connect(fakeSigner).connectVirtualPoolToPlugin(context.pool01, farmingModuleAddress, { from: eternalFarmingAddress }); await context.farmingCenter .connect(fakeSigner) - .disconnectVirtualPoolFromPlugin(context.pool01, context.pluginObj, { from: eternalFarmingAddress }); + .disconnectVirtualPoolFromPlugin(context.pool01, farmingModuleAddress, { from: eternalFarmingAddress }); await setBalance(eternalFarmingAddress, 0); await stopImpersonatingAccount(eternalFarmingAddress); expect(await context.farmingCenter.virtualPoolAddresses(context.pool01)).to.be.eq(ZERO_ADDRESS); @@ -157,12 +163,16 @@ describe('unit/FarmingCenter', () => { await impersonateAccount(eternalFarmingAddress); await setBalance(eternalFarmingAddress, 10 ** 18); const fakeSigner = await ethers.getSigner(eternalFarmingAddress); - await context.pluginFactory.setFarmingAddress(incentiveCreator); - await context.pluginObj.connect(incentiveCreator).setIncentive(eternalFarmingAddress); - await context.pluginFactory.setFarmingAddress(context.farmingCenter); + + const farmingModuleAddress = await context.farmingModuleFactory.poolToPlugin(context.pool01); + const farmingModule = await ethers.getContractAt('FarmingModule', farmingModuleAddress) as any as IFarmingPlugin; + + await context.farmingModuleFactory.setFarmingAddress(incentiveCreator); + await farmingModule.connect(incentiveCreator).setIncentive(eternalFarmingAddress); + await context.farmingModuleFactory.setFarmingAddress(context.farmingCenter); await context.farmingCenter .connect(fakeSigner) - .disconnectVirtualPoolFromPlugin(context.pool01, context.pluginObj, { from: eternalFarmingAddress }); + .disconnectVirtualPoolFromPlugin(context.pool01, farmingModule, { from: eternalFarmingAddress }); await setBalance(eternalFarmingAddress, 0); await stopImpersonatingAccount(eternalFarmingAddress); expect(await context.farmingCenter.virtualPoolAddresses(context.pool01)).to.be.eq(ZERO_ADDRESS); @@ -185,6 +195,7 @@ describe('unit/FarmingCenter', () => { totalReward, bonusReward, poolAddress: await context.poolObj.getAddress(), + farmingModuleFactory: context.farmingModuleFactory, nonce, rewardRate: 100n, bonusRewardRate: 50n, @@ -198,6 +209,7 @@ describe('unit/FarmingCenter', () => { ticks: [getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]), getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM])], amountsToFarm: [amountDesired, amountDesired], createIncentiveResult: createIncentiveResultEternal, + farmingModuleFactory: context.farmingModuleFactory }); tokenIdEternal = mintResultEternal.tokenId; }); @@ -258,9 +270,12 @@ describe('unit/FarmingCenter', () => { }); it('works if liquidity decreased and incentive deactivated automatically', async () => { - await context.pluginFactory.setFarmingAddress(actors.algebraRootUser().address); + await context.farmingModuleFactory.setFarmingAddress(actors.algebraRootUser().address); - const incentiveAddress = await context.pluginObj.connect(actors.algebraRootUser()).incentive(); + const farmingModuleAddress = await context.farmingModuleFactory.poolToPlugin(context.pool01); + const farmingModule = await ethers.getContractAt('FarmingModule', farmingModuleAddress) as any as IFarmingPlugin; + + const incentiveAddress = await farmingModule.incentive(); await erc20Helper.ensureBalancesAndApprovals(lpUser0, [context.token0, context.token1], amountDesired, await context.nft.getAddress()); @@ -289,11 +304,11 @@ describe('unit/FarmingCenter', () => { _tokenId ); - await context.pluginObj.connect(actors.algebraRootUser()).setIncentive(ZERO_ADDRESS); + await farmingModule.connect(actors.algebraRootUser()).setIncentive(ZERO_ADDRESS); await helpers.moveTickTo({ direction: 'down', desiredValue: -160, trader: actors.farmingDeployer() }); - await context.pluginObj.connect(actors.algebraRootUser()).setIncentive(incentiveAddress); + await farmingModule.connect(actors.algebraRootUser()).setIncentive(incentiveAddress); await helpers.moveTickTo({ direction: 'up', desiredValue: -140, trader: actors.farmingDeployer() }); @@ -311,9 +326,12 @@ describe('unit/FarmingCenter', () => { }); it('works if liquidity decreased and incentive detached indirectly', async () => { - await context.pluginFactory.setFarmingAddress(actors.algebraRootUser().address); + await context.farmingModuleFactory.setFarmingAddress(actors.algebraRootUser().address); + + const farmingModuleAddress = await context.farmingModuleFactory.poolToPlugin(context.pool01); + const farmingModule = await ethers.getContractAt('FarmingModule', farmingModuleAddress) as any as IFarmingPlugin; - const incentiveAddress = await context.pluginObj.connect(actors.algebraRootUser()).incentive(); + const incentiveAddress = await farmingModule.incentive(); await erc20Helper.ensureBalancesAndApprovals(lpUser0, [context.token0, context.token1], amountDesired, await context.nft.getAddress()); @@ -342,11 +360,11 @@ describe('unit/FarmingCenter', () => { _tokenId ); - await context.pluginObj.connect(actors.algebraRootUser()).setIncentive(ZERO_ADDRESS); + await farmingModule.connect(actors.algebraRootUser()).setIncentive(ZERO_ADDRESS); await helpers.moveTickTo({ direction: 'down', desiredValue: -160, trader: actors.farmingDeployer() }); - await context.pluginObj.connect(actors.algebraRootUser()).setIncentive(incentiveAddress); + await farmingModule.connect(actors.algebraRootUser()).setIncentive(incentiveAddress); await expect( context.nft.connect(lpUser0).decreaseLiquidity({ @@ -432,6 +450,7 @@ describe('unit/FarmingCenter', () => { totalReward, bonusReward, poolAddress: await context.poolObj.getAddress(), + farmingModuleFactory: context.farmingModuleFactory, nonce, rewardRate: 100n, bonusRewardRate: 50n, @@ -443,6 +462,7 @@ describe('unit/FarmingCenter', () => { ticks: [getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]), getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM])], amountsToFarm: [amountDesired, amountDesired], createIncentiveResult: createIncentiveResultEternal, + farmingModuleFactory: context.farmingModuleFactory }); tokenIdEternal = mintResultEternal.tokenId; }); @@ -484,6 +504,7 @@ describe('unit/FarmingCenter', () => { totalReward, bonusReward, poolAddress: await context.poolObj.getAddress(), + farmingModuleFactory: context.farmingModuleFactory, nonce, rewardRate: 100n, bonusRewardRate: 50n, @@ -497,6 +518,7 @@ describe('unit/FarmingCenter', () => { ticks: [getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]), getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM])], amountsToFarm: [amountDesired, amountDesired], createIncentiveResult: createIncentiveResultEternal, + farmingModuleFactory: context.farmingModuleFactory }); tokenIdEternal = mintResultEternal.tokenId; diff --git a/src/farming/test/unit/Multicall.spec.ts b/src/farming/test/unit/Multicall.spec.ts index 3f9f4f8b8..c28d7674a 100644 --- a/src/farming/test/unit/Multicall.spec.ts +++ b/src/farming/test/unit/Multicall.spec.ts @@ -73,6 +73,7 @@ describe('unit/Multicall', () => { totalReward, bonusReward, poolAddress: await context.poolObj.getAddress(), + farmingModuleFactory: context.farmingModuleFactory, nonce: 0n, rewardRate: 10n, bonusRewardRate: 50n, diff --git a/src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap b/src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap new file mode 100644 index 000000000..086a74c8f --- /dev/null +++ b/src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`unit/EternalFarms #claimReward when requesting the full amount has gas cost [ @skip-on-coverage ] 1`] = `60801`; + +exports[`unit/EternalFarms #enterFarming works and has gas cost [ @skip-on-coverage ] 1`] = `494839`; + +exports[`unit/EternalFarms #exitFarming after end time works and has gas cost [ @skip-on-coverage ] 1`] = `169695`; diff --git a/src/plugin/contracts/modules/DynamicFeeModule.sol b/src/plugin/contracts/modules/DynamicFeeModule.sol index 9a26e37b2..f74adfe19 100644 --- a/src/plugin/contracts/modules/DynamicFeeModule.sol +++ b/src/plugin/contracts/modules/DynamicFeeModule.sol @@ -105,16 +105,11 @@ contract DynamicFeeModule is AlgebraModule, IDynamicFeeManager, Timestamp { bytes memory /* params */, uint16 /* poolFeeCache */ ) internal view override { - console.log('dynamicFeeModule beforeswap called'); uint16 newFee = _getNewFee(); - console.log('dynamicFeeModule after newFee'); ModuleUtils.returnDynamicFeeResult(newFee, false); - console.log('dynamicFeeModule beforeswap end'); } function _getNewFee() internal view returns (uint16 newFee) { - console.log('getNewfee entered'); - console.log('oracleModule address: ', oracleModule); uint16 lastTimepointIndex = IVolatilityOracle(oracleModule).timepointIndex(); uint16 lastTimepointIndexOutsideCurrentBlock; diff --git a/src/plugin/contracts/modules/FarmingModule.sol b/src/plugin/contracts/modules/FarmingModule.sol index b14ae674a..b98a0ca6f 100644 --- a/src/plugin/contracts/modules/FarmingModule.sol +++ b/src/plugin/contracts/modules/FarmingModule.sol @@ -86,12 +86,9 @@ contract FarmingModule is AlgebraModule, IFarmingPlugin, Timestamp { bytes memory params , uint16 /* poolFeeCache */ ) internal override { - console.log("Farming afterInitialize"); - AfterSwapParams memory decodedParams = abi.decode(params, (AfterSwapParams)); address _incentive = incentive; - console.log('incentive: ', _incentive); if (_incentive != address(0)) { (, int24 tick, , ) = _getPoolState(); IAlgebraVirtualPool(_incentive).crossTo(tick, decodedParams.zeroToOne); diff --git a/src/plugin/contracts/modules/OracleModule.sol b/src/plugin/contracts/modules/OracleModule.sol index b3a8c3631..84d59c1da 100644 --- a/src/plugin/contracts/modules/OracleModule.sol +++ b/src/plugin/contracts/modules/OracleModule.sol @@ -16,6 +16,8 @@ import '../libraries/VolatilityOracle.sol'; import '../interfaces/plugins/IVolatilityOracle.sol'; import '../interfaces/plugins/IDynamicFeeManager.sol'; +import 'hardhat/console.sol'; + contract OracleModule is AlgebraModule, IVolatilityOracle, Timestamp { using Plugins for uint8; diff --git a/src/plugin/contracts/test/MockPool.sol b/src/plugin/contracts/test/MockPool.sol index d482ac1e2..b5d6aae07 100644 --- a/src/plugin/contracts/test/MockPool.sol +++ b/src/plugin/contracts/test/MockPool.sol @@ -122,6 +122,7 @@ contract MockPool is IAlgebraPoolActions, IAlgebraPoolPermissionedActions, IAlge globalState.price = initialPrice; globalState.tick = tick; + console.log('plugin config: ', pluginConfig); if (pluginConfig & Plugins.AFTER_INIT_FLAG != 0) { IAlgebraPlugin(plugin).afterInitialize(msg.sender, initialPrice, tick); } @@ -231,6 +232,7 @@ contract MockPool is IAlgebraPoolActions, IAlgebraPoolPermissionedActions, IAlge /// @inheritdoc IAlgebraPoolPermissionedActions function setPluginConfig(uint8 newConfig) external override { // require(msg.sender == owner || msg.sender == plugin || msg.sender == pluginFactory); + console.log('newConfig: ', newConfig); globalState.pluginConfig = newConfig; } diff --git a/src/plugin/contracts/test/MockTimeDSFactory.sol b/src/plugin/contracts/test/MockTimeDSFactory.sol index 1e2ddba2a..861fc0c9d 100644 --- a/src/plugin/contracts/test/MockTimeDSFactory.sol +++ b/src/plugin/contracts/test/MockTimeDSFactory.sol @@ -40,8 +40,8 @@ contract MockTimeDSFactory is IBasePluginV1Factory { } function afterCreatePoolHook(address modularHub, address pool, address) external override { - _insertModules(modularHub); MockPool(pool).setPluginConfig(uint8(Plugins.DYNAMIC_FEE)); + _insertModules(modularHub); } function createPluginForExistingPool(address token0, address token1) external override returns (address) { @@ -77,10 +77,11 @@ contract MockTimeDSFactory is IBasePluginV1Factory { } function _insertModules(address modularHub) internal { - for (uint256 i = 0; i < factoriesCounter; ++i) { - address moduleFactoryAddress = factoryByIndex[i]; + for (uint256 i = factoriesCounter; i > 0; --i) { + address moduleFactoryAddress = factoryByIndex[i - 1]; + InsertModuleParams[] memory insertModuleParams = IAlgebraModuleFactory(moduleFactoryAddress).getInsertModuleParams(i); IAlgebraModularHub(modularHub).insertModulesToHookLists( - IAlgebraModuleFactory(moduleFactoryAddress).getInsertModuleParams(i + 1) + insertModuleParams ); } } diff --git a/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol b/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol index 324b8c9d2..1bcfd2b3e 100644 --- a/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol +++ b/src/plugin/contracts/test/MockTimeDynamicFeeModuleFactory.sol @@ -32,7 +32,6 @@ contract MockTimeDynamicFeeModuleFactory is AlgebraModuleFactory { 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: 0, diff --git a/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol b/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol index 9d10a4590..e064e96f0 100644 --- a/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol +++ b/src/plugin/contracts/test/MockTimeOracleModuleFactory.sol @@ -14,6 +14,7 @@ contract MockTimeOracleModuleFactory is AlgebraModuleFactory { } function getInsertModuleParams(uint256 moduleGlobalIndex) external override pure returns (InsertModuleParams[] memory) { + console.log('getInsertModuleParams in oracle module has called'); InsertModuleParams[] memory insertModuleParams = new InsertModuleParams[](2); insertModuleParams[0] = InsertModuleParams({ diff --git a/src/plugin/test/AlgebraPool.gas.spec.ts b/src/plugin/test/AlgebraPool.gas.spec.ts index 9d7a3d12d..6dbe7cfe7 100644 --- a/src/plugin/test/AlgebraPool.gas.spec.ts +++ b/src/plugin/test/AlgebraPool.gas.spec.ts @@ -51,6 +51,7 @@ 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 mockPluginFactory.afterCreatePoolHook(pluginAddress, pool, ZERO_ADDRESS); const mockDSOperatorFactory = await ethers.getContractFactory('AlgebraModularHub'); const plugin = mockDSOperatorFactory.attach(pluginAddress) as any as AlgebraModularHub; diff --git a/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap b/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap index d796564f4..eac2a9438 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`] = `264295`; +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 small swap with filled volatilityOracle 1`] = `214235`; +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 after 4h 1`] = `247740`; +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 8h 1`] = `242504`; +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 24h 1`] = `213975`; +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 static fee large swap crossing several initialized ticks 1`] = `264295`; +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 small swap with filled volatilityOracle 1`] = `214235`; +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 after 4h 1`] = `247832`; +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 8h 1`] = `258843`; +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 24h 1`] = `213975`; +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 ] 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`] = `207149`; +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 with no tick movement 1`] = `207118`; +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, static fee 1`] = `204299`; +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, large swap crossing a single initialized tick 1`] = `223657`; +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 several initialized ticks 1`] = `257051`; +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, no initialized crossings 1`] = `207216`; +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 large swap crossing several initialized ticks after some time passes 1`] = `257051`; +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 second time after some time passes 1`] = `276251`; +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 second swap in block moves tick, no initialized crossings 1`] = `176965`; +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 with no tick movement 1`] = `176929`; +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, large swap crossing a single initialized tick 1`] = `192658`; +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 several initialized ticks 1`] = `226873`; +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 several large swaps with pauses 1`] = `287628`; +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 small swap after several large swaps with pauses 1`] = `218364`; +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 #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `207210`; +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 with no tick movement 1`] = `207158`; +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 second swap in block with no tick movement 1`] = `176990`; +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 farming connected first swap in block moves tick, no initialized crossings 1`] = `234337`; +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 with no tick movement 1`] = `234285`; +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 second swap in block with no tick movement 1`] = `187017`; +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 on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `214972`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `212473`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `214941`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `212442`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `204536`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `204427`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `231717`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `229218`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `265822`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `263323`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `215039`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `212540`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `265822`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `263323`; -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`] = `285022`; +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`] = `282523`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `184788`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `184679`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `184752`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `184643`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `200718`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `200609`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `235644`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `235535`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `296399`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `290352`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `218601`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `212554`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `215033`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `212534`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `214981`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `212482`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `184813`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `184704`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `242160`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `239661`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `242108`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `239609`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `194840`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `194731`; diff --git a/src/plugin/test/__snapshots__/VolatilityOracle.spec.ts.snap b/src/plugin/test/__snapshots__/VolatilityOracle.spec.ts.snap new file mode 100644 index 000000000..a1c05ceea --- /dev/null +++ b/src/plugin/test/__snapshots__/VolatilityOracle.spec.ts.snap @@ -0,0 +1,101 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`VolatilityOracle #getTimepoints before initialization gas for getTimepoints since most recent [ @skip-on-coverage ] 1`] = `8271`; + +exports[`VolatilityOracle #getTimepoints before initialization gas for single timepoint at current time [ @skip-on-coverage ] 1`] = `6327`; + +exports[`VolatilityOracle #getTimepoints before initialization gas for single timepoint at current time after some time [ @skip-on-coverage ] 1`] = `8137`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 5 fetch many values 1`] = ` +Object { + "tickCumulatives": Array [ + "-13", + "-31", + "-43", + "-37", + "-15", + "9", + "15", + ], +} +`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 5 gas all of last 20 seconds [ @skip-on-coverage ] 1`] = `100743`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 5 gas between oldest and oldest + 1 [ @skip-on-coverage ] 1`] = `17966`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 5 gas latest equal [ @skip-on-coverage ] 1`] = `6327`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 5 gas latest transform [ @skip-on-coverage ] 1`] = `10137`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 5 gas middle [ @skip-on-coverage ] 1`] = `17453`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 5 gas oldest [ @skip-on-coverage ] 1`] = `17030`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 4294967291 fetch many values 1`] = ` +Object { + "tickCumulatives": Array [ + "-13", + "-31", + "-43", + "-37", + "-15", + "9", + "15", + ], +} +`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 4294967291 gas all of last 20 seconds [ @skip-on-coverage ] 1`] = `100395`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 4294967291 gas between oldest and oldest + 1 [ @skip-on-coverage ] 1`] = `17908`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 4294967291 gas latest equal [ @skip-on-coverage ] 1`] = `6327`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 4294967291 gas latest transform [ @skip-on-coverage ] 1`] = `10166`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 4294967291 gas middle [ @skip-on-coverage ] 1`] = `17424`; + +exports[`VolatilityOracle #getTimepoints initialized with 5 timepoints with starting time of 4294967291 gas oldest [ @skip-on-coverage ] 1`] = `16972`; + +exports[`VolatilityOracle #initialize gas [ @skip-on-coverage ] 1`] = `50443`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(0) [ @skip-on-coverage ] 1`] = `6335`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(0) after 5 seconds [ @skip-on-coverage ] 1`] = `16887`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(5) after 5 seconds [ @skip-on-coverage ] 1`] = `6469`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(24h ago) [ @skip-on-coverage ] 1`] = `13127`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(24h ago) after 5 seconds [ @skip-on-coverage ] 1`] = `14592`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(24h ago) after 15 minutes [ @skip-on-coverage ] 1`] = `54263`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(200 * 13 + 5) [ @skip-on-coverage ] 1`] = `49033`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(200 * 13) [ @skip-on-coverage ] 1`] = `48978`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(middle) [ @skip-on-coverage ] 1`] = `12476`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(oldest) [ @skip-on-coverage ] 1`] = `47091`; + +exports[`VolatilityOracle full volatilityOracle gas cost of getTimepoints(oldest) after 5 seconds [ @skip-on-coverage ] 1`] = `47091`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(0) [ @skip-on-coverage ] 1`] = `6335`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(0) after 5 seconds [ @skip-on-coverage ] 1`] = `8174`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(5) after 5 seconds [ @skip-on-coverage ] 1`] = `6469`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(24h ago) after 12 hours [ @skip-on-coverage ] 1`] = `69074`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(200 * 1 + 5) [ @skip-on-coverage ] 1`] = `71383`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(200 * 1) [ @skip-on-coverage ] 1`] = `65785`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(middle) [ @skip-on-coverage ] 1`] = `12516`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(oldest) [ @skip-on-coverage ] 1`] = `47131`; + +exports[`VolatilityOracle full volatilityOracle, maximal density gas cost of getTimepoints(oldest) after 5 seconds [ @skip-on-coverage ] 1`] = `47131`; diff --git a/src/plugin/test/shared/fixtures.ts b/src/plugin/test/shared/fixtures.ts index 28182821c..5319ba2b1 100644 --- a/src/plugin/test/shared/fixtures.ts +++ b/src/plugin/test/shared/fixtures.ts @@ -55,7 +55,9 @@ 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 mockPluginFactory.afterCreatePoolHook(pluginAddress, mockPool, ZERO_ADDRESS); + console.log('mockpool pluginconfig: ', (await mockPool.globalState()).pluginConfig); const algebraModularHubFactory = await ethers.getContractFactory('AlgebraModularHub'); const plugin = algebraModularHubFactory.attach(pluginAddress) as any as AlgebraModularHub;