From 8e5967b90dfc219947f8fda021a6eb5c54817317 Mon Sep 17 00:00:00 2001 From: IliaAzhel Date: Mon, 7 Oct 2024 21:31:25 +0300 Subject: [PATCH] [Plugin] add some tests for plugin fee && update snapshots --- src/plugin/contracts/AlgebraBasePluginV2.sol | 18 ++- src/plugin/contracts/test/SlidingFeeTest.sol | 4 +- src/plugin/test/AlgebraBasePluginV1.spec.ts | 8 -- src/plugin/test/AlgebraBasePluginV2.spec.ts | 52 ++++++-- src/plugin/test/BasePluginV2Factory.spec.ts | 125 ++++++++++++++++++ src/plugin/test/SlidingFee.spec.ts | 44 +++++- .../AlgebraBasePluginV1.spec.ts.snap | 2 +- .../AlgebraBasePluginV2.spec.ts.snap | 123 ----------------- .../AlgebraPool.gas.spec.ts.snap | 118 ++++++++--------- .../__snapshots__/SlidingFee.spec.ts.snap | 6 +- src/plugin/test/shared/fixtures.ts | 12 ++ 11 files changed, 301 insertions(+), 211 deletions(-) create mode 100644 src/plugin/test/BasePluginV2Factory.spec.ts delete mode 100644 src/plugin/test/__snapshots__/AlgebraBasePluginV2.spec.ts.snap diff --git a/src/plugin/contracts/AlgebraBasePluginV2.sol b/src/plugin/contracts/AlgebraBasePluginV2.sol index 06d5c3556..ca4ae7726 100644 --- a/src/plugin/contracts/AlgebraBasePluginV2.sol +++ b/src/plugin/contracts/AlgebraBasePluginV2.sol @@ -45,8 +45,16 @@ contract AlgebraBasePluginV2 is SlidingFeePlugin, FarmingProxyPlugin, Volatility return IAlgebraPlugin.afterModifyPosition.selector; } - function beforeSwap(address, address, bool zeroToOne, int256, uint160, bool, bytes calldata) external override onlyPool returns (bytes4, uint24, uint24) { - ( , int24 currentTick, , ) = _getPoolState(); + function beforeSwap( + address, + address, + bool zeroToOne, + int256, + uint160, + bool, + bytes calldata + ) external override onlyPool returns (bytes4, uint24, uint24) { + (, int24 currentTick, , ) = _getPoolState(); int24 lastTick = _getLastTick(); uint16 newFee = _getFeeAndUpdateFactors(zeroToOne, currentTick, lastTick); @@ -70,8 +78,4 @@ contract AlgebraBasePluginV2 is SlidingFeePlugin, FarmingProxyPlugin, Volatility _updatePluginConfigInPool(defaultPluginConfig); // should not be called, reset config return IAlgebraPlugin.afterFlash.selector; } - - function getCurrentFee() external view returns (uint16 fee) { - (, , fee, ) = _getPoolState(); - } -} \ No newline at end of file +} diff --git a/src/plugin/contracts/test/SlidingFeeTest.sol b/src/plugin/contracts/test/SlidingFeeTest.sol index 9d47fa8ca..e2d9cc886 100644 --- a/src/plugin/contracts/test/SlidingFeeTest.sol +++ b/src/plugin/contracts/test/SlidingFeeTest.sol @@ -4,11 +4,13 @@ pragma solidity =0.8.20; import '../plugins/SlidingFeePlugin.sol'; contract SlidingFeeTest is SlidingFeePlugin { + event Fee(uint16 fee); uint8 public constant override defaultPluginConfig = 0; constructor() BasePlugin(msg.sender, msg.sender, msg.sender) {} function getFeeForSwap(bool zeroToOne, int24 lastTick, int24 currentTick) external returns (uint16 fee) { fee = _getFeeAndUpdateFactors(zeroToOne, currentTick, lastTick); + emit Fee(fee); } function getGasCostOfGetFeeForSwap(bool zeroToOne, int24 lastTick, int24 currentTick) external returns (uint256) { @@ -26,4 +28,4 @@ contract SlidingFeeTest is SlidingFeePlugin { function changeFactor(uint16 newFactor) external { s_priceChangeFactor = newFactor; } -} \ No newline at end of file +} diff --git a/src/plugin/test/AlgebraBasePluginV1.spec.ts b/src/plugin/test/AlgebraBasePluginV1.spec.ts index a82a3cd57..b4637fc78 100644 --- a/src/plugin/test/AlgebraBasePluginV1.spec.ts +++ b/src/plugin/test/AlgebraBasePluginV1.spec.ts @@ -106,14 +106,6 @@ describe('AlgebraBasePluginV1', () => { expect((await mockPool.globalState()).pluginConfig).to.be.eq(defaultConfig); }); - it('resets config after afterSwap', async () => { - await mockPool.initialize(encodePriceSqrt(1, 1)); - await mockPool.setPluginConfig(PLUGIN_FLAGS.AFTER_SWAP_FLAG); - expect((await mockPool.globalState()).pluginConfig).to.be.eq(PLUGIN_FLAGS.AFTER_SWAP_FLAG); - await mockPool.swapToTick(100); - expect((await mockPool.globalState()).pluginConfig).to.be.eq(defaultConfig); - }); - it('resets config after beforeFlash', async () => { await mockPool.setPluginConfig(PLUGIN_FLAGS.BEFORE_FLASH_FLAG); expect((await mockPool.globalState()).pluginConfig).to.be.eq(PLUGIN_FLAGS.BEFORE_FLASH_FLAG); diff --git a/src/plugin/test/AlgebraBasePluginV2.spec.ts b/src/plugin/test/AlgebraBasePluginV2.spec.ts index 2b30f8bbd..6c732703d 100644 --- a/src/plugin/test/AlgebraBasePluginV2.spec.ts +++ b/src/plugin/test/AlgebraBasePluginV2.spec.ts @@ -106,14 +106,6 @@ describe('AlgebraBasePluginV2', () => { expect((await mockPool.globalState()).pluginConfig).to.be.eq(defaultConfig); }); - it('resets config after afterSwap', async () => { - await mockPool.initialize(encodePriceSqrt(1, 1)); - await mockPool.setPluginConfig(PLUGIN_FLAGS.AFTER_SWAP_FLAG); - expect((await mockPool.globalState()).pluginConfig).to.be.eq(PLUGIN_FLAGS.AFTER_SWAP_FLAG); - await mockPool.swapToTick(100); - expect((await mockPool.globalState()).pluginConfig).to.be.eq(defaultConfig); - }); - it('resets config after beforeFlash', async () => { await mockPool.setPluginConfig(PLUGIN_FLAGS.BEFORE_FLASH_FLAG); expect((await mockPool.globalState()).pluginConfig).to.be.eq(PLUGIN_FLAGS.BEFORE_FLASH_FLAG); @@ -318,6 +310,46 @@ describe('AlgebraBasePluginV2', () => { }); }); + describe('#SlidingFee', () => { + + beforeEach('initialize pool', async () => { + await mockPool.setPlugin(plugin); + await initializeAtZeroTick(mockPool); + }); + + describe('#setPriceChangeFactor', () => { + it('works correct', async () => { + await plugin.setPriceChangeFactor(1500) + let factor = await plugin.s_priceChangeFactor() + expect(factor).to.be.equal(1500); + }); + + it('emit event', async () => { + await expect(plugin.setPriceChangeFactor(1500)).to.emit(plugin, "PriceChangeFactor"); + }); + + it('fails if caller is not owner or manager', async () => { + await expect(plugin.connect(other).setPriceChangeFactor(1500)).to.be.reverted; + }); + }) + + describe('#setBaseFee', () => { + it('works correct', async () => { + await plugin.setBaseFee(1500) + let baseFee = await plugin.s_baseFee() + expect(baseFee).to.be.equal(1500); + }); + + it('emit event', async () => { + await expect(plugin.setBaseFee(1500)).to.emit(plugin, "BaseFee"); + }); + + it('fails if caller is not owner or manager', async () => { + await expect(plugin.connect(other).setBaseFee(1500)).to.be.reverted; + }); + }) + }) + describe('#FarmingPlugin', () => { describe('virtual pool tests', () => { let virtualPoolMock: MockTimeVirtualPool; @@ -328,6 +360,10 @@ describe('AlgebraBasePluginV2', () => { virtualPoolMock = (await virtualPoolMockFactory.deploy()) as any as MockTimeVirtualPool; }); + it('returns pool address', async () => { + expect(await plugin.getPool()).to.be.eq(mockPool); + }); + it('set incentive works', async () => { await mockPool.setPlugin(plugin); await plugin.setIncentive(virtualPoolMock); diff --git a/src/plugin/test/BasePluginV2Factory.spec.ts b/src/plugin/test/BasePluginV2Factory.spec.ts new file mode 100644 index 000000000..787c6f5df --- /dev/null +++ b/src/plugin/test/BasePluginV2Factory.spec.ts @@ -0,0 +1,125 @@ +import { Wallet } from 'ethers'; +import { ethers } from 'hardhat'; +import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; +import { expect } from './shared/expect'; +import { ZERO_ADDRESS, pluginFactoryFixtureV2 } from './shared/fixtures'; + +import { BasePluginV2Factory, AlgebraBasePluginV2, MockFactory } from '../typechain'; + +describe('BasePluginV2Factory', () => { + let wallet: Wallet, other: Wallet; + + let pluginFactory: BasePluginV2Factory; + let mockAlgebraFactory: MockFactory; + + before('prepare signers', async () => { + [wallet, other] = await (ethers as any).getSigners(); + }); + + beforeEach('deploy test volatilityOracle', async () => { + ({ pluginFactory, mockFactory: mockAlgebraFactory } = await loadFixture(pluginFactoryFixtureV2)); + }); + + describe('#Create plugin', () => { + it('only factory', async () => { + expect(pluginFactory.beforeCreatePoolHook(wallet.address, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, '0x')).to.be + .revertedWithoutReason; + }); + + it('factory can create plugin', async () => { + const pluginFactoryFactory = await ethers.getContractFactory('BasePluginV2Factory'); + const pluginFactoryMock = (await pluginFactoryFactory.deploy(wallet.address)) as any as BasePluginV2Factory; + + const pluginAddress = await pluginFactoryMock.beforeCreatePoolHook.staticCall( + wallet.address, + ZERO_ADDRESS, + ZERO_ADDRESS, + ZERO_ADDRESS, + ZERO_ADDRESS, + '0x' + ); + await pluginFactoryMock.beforeCreatePoolHook(wallet.address, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, ZERO_ADDRESS, '0x'); + + const pluginMock = (await ethers.getContractFactory('AlgebraBasePluginV2')).attach(pluginAddress) as any as AlgebraBasePluginV2; + const baseFee = await pluginMock.s_baseFee(); + expect(baseFee).to.be.not.eq(0); + }); + }); + + describe('#CreatePluginForExistingPool', () => { + it('only if has role', async () => { + expect(pluginFactory.connect(other).createPluginForExistingPool(wallet.address, other.address)).to.be.revertedWithoutReason; + }); + + it('cannot create for nonexistent pool', async () => { + await expect(pluginFactory.createPluginForExistingPool(wallet.address, other.address)).to.be.revertedWith('Pool not exist'); + }); + + it('can create for existing pool', async () => { + await mockAlgebraFactory.stubPool(wallet.address, other.address, other.address); + + await pluginFactory.createPluginForExistingPool(wallet.address, other.address); + const pluginAddress = await pluginFactory.pluginByPool(other.address); + expect(pluginAddress).to.not.be.eq(ZERO_ADDRESS); + const pluginMock = (await ethers.getContractFactory('AlgebraBasePluginV2')).attach(pluginAddress) as any as AlgebraBasePluginV2; + const baseFee = await pluginMock.s_baseFee(); + expect(baseFee).to.be.not.eq(0); + }); + + it('cannot create twice for existing pool', async () => { + await mockAlgebraFactory.stubPool(wallet.address, other.address, other.address); + + await pluginFactory.createPluginForExistingPool(wallet.address, other.address); + + await expect(pluginFactory.createPluginForExistingPool(wallet.address, other.address)).to.be.revertedWith('Already created'); + }); + }); + + describe('#Default base fee ', () => { + describe('#setDefaultBaseFee', () => { + + it('fails if caller is not owner', async () => { + await expect(pluginFactory.connect(other).setDefaultBaseFee(1000)).to.be.revertedWith('Only administrator'); + }); + + it('fails if try to set same value', async () => { + await expect(pluginFactory.connect(other).setDefaultBaseFee(500)).to.be.reverted; + }); + + it('updates defaultFeeConfiguration', async () => { + await pluginFactory.setDefaultBaseFee(1000); + + const newFee = await pluginFactory.defaultBaseFee(); + + expect(newFee).to.eq(1000); + }); + + it('emits event', async () => { + await expect(pluginFactory.setDefaultBaseFee(1000)) + .to.emit(pluginFactory, 'DefaultBaseFee') + .withArgs(1000); + }); + + }); + }); + + describe('#setFarmingAddress', () => { + it('fails if caller is not owner', async () => { + await expect(pluginFactory.connect(other).setFarmingAddress(wallet.address)).to.be.revertedWith('Only administrator'); + }); + + it('updates farmingAddress', async () => { + await pluginFactory.setFarmingAddress(other.address); + expect(await pluginFactory.farmingAddress()).to.eq(other.address); + }); + + it('emits event', async () => { + await expect(pluginFactory.setFarmingAddress(other.address)).to.emit(pluginFactory, 'FarmingAddress').withArgs(other.address); + }); + + it('cannot set current address', async () => { + await pluginFactory.setFarmingAddress(other.address); + await expect(pluginFactory.setFarmingAddress(other.address)).to.be.reverted; + }); + }); +}); diff --git a/src/plugin/test/SlidingFee.spec.ts b/src/plugin/test/SlidingFee.spec.ts index 57e5ed6b2..73cc8d4f9 100644 --- a/src/plugin/test/SlidingFee.spec.ts +++ b/src/plugin/test/SlidingFee.spec.ts @@ -24,7 +24,7 @@ describe('SlidingFee', () => { expect(await slidingFeePlugin.s_priceChangeFactor()).to.be.eq(1000) }); - describe('#getSlidingFee', () => { + describe('#FeeFactors', () => { beforeEach('set config', async () => { await slidingFeePlugin.changeBaseFee(500) await slidingFeePlugin.changeFactor(1000) @@ -194,6 +194,48 @@ describe('SlidingFee', () => { }); + describe('#getSlidingFee', () => { + + async function getFee(zto: boolean, lastTick: number, currentTick: number) : Promise{ + let tx = await slidingFeePlugin.getFeeForSwap(zto, lastTick, currentTick); + return (await tx.wait()).logs[0].args['fee'] + } + + beforeEach('set config', async () => { + await slidingFeePlugin.changeBaseFee(500) + await slidingFeePlugin.changeFactor(1000) + }); + + it("returns base fee value", async function () { + let fee = await getFee(false, 10000, 10000) + expect(fee).to.be.eq(500) + }); + + it("one to zero fee should be increased x1.5", async function () { + let feeOtZ = await getFee(false, 10000, 14055) + expect(feeOtZ).to.be.eq(750) + }); + + it("zero to one fee should be decreased x1.5", async function () { + let feeZtO = await getFee(true, 10000, 14054) + expect(feeZtO).to.be.eq(250) + }); + + it("handle overflow", async function () { + await slidingFeePlugin.changeBaseFee(50000) + let feeOtZ = await getFee(false, 10000,100000) + expect(feeOtZ).to.be.eq(65535) + }); + + it("MIN fee is 1 (0.0001%)", async function () { + await slidingFeePlugin.changeBaseFee(50000) + let feeOtZ = await getFee(true, 10000,100000) + expect(feeOtZ).to.be.eq(1) + }); + + }) + + describe('#getFee gas cost [ @skip-on-coverage ]', () => { it('gas cost of same tick', async () => { await snapshotGasCost(slidingFeePlugin.getGasCostOfGetFeeForSwap(true, 100, 100)); diff --git a/src/plugin/test/__snapshots__/AlgebraBasePluginV1.spec.ts.snap b/src/plugin/test/__snapshots__/AlgebraBasePluginV1.spec.ts.snap index 369d2135e..f1a709f59 100644 --- a/src/plugin/test/__snapshots__/AlgebraBasePluginV1.spec.ts.snap +++ b/src/plugin/test/__snapshots__/AlgebraBasePluginV1.spec.ts.snap @@ -120,4 +120,4 @@ Array [ ] `; -exports[`AlgebraBasePluginV1 AlgebraBasePluginV1 external methods #changeFeeConfiguration feeConfig getter gas cost [ @skip-on-coverage ] 1`] = `23774`; +exports[`AlgebraBasePluginV1 AlgebraBasePluginV1 external methods #changeFeeConfiguration feeConfig getter gas cost [ @skip-on-coverage ] 1`] = `23708`; diff --git a/src/plugin/test/__snapshots__/AlgebraBasePluginV2.spec.ts.snap b/src/plugin/test/__snapshots__/AlgebraBasePluginV2.spec.ts.snap deleted file mode 100644 index 63e73906c..000000000 --- a/src/plugin/test/__snapshots__/AlgebraBasePluginV2.spec.ts.snap +++ /dev/null @@ -1,123 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AlgebraBasePluginV2 #DynamicFeeManager #adaptiveFee single huge spike after day 1`] = ` -Array [ - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 123 ", - "Fee: 124 ", - "Fee: 124 ", - "Fee: 124 ", - "Fee: 124 ", - "Fee: 100 ", -] -`; - -exports[`AlgebraBasePluginV2 #DynamicFeeManager #adaptiveFee single huge spike after initialization 1`] = ` -Array [ - "Fee: 3714 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 2965 ", - "Fee: 2602 ", - "Fee: 1733 ", - "Fee: 995 ", - "Fee: 607 ", - "Fee: 411 ", - "Fee: 309 ", - "Fee: 250 ", - "Fee: 215 ", - "Fee: 191 ", - "Fee: 174 ", - "Fee: 163 ", - "Fee: 154 ", - "Fee: 147 ", - "Fee: 142 ", - "Fee: 139 ", - "Fee: 135 ", - "Fee: 132 ", - "Fee: 130 ", - "Fee: 128 ", - "Fee: 126 ", - "Fee: 100 ", -] -`; - -exports[`AlgebraBasePluginV2 #DynamicFeeManager #adaptiveFee single huge step after day 1`] = ` -Array [ - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 3000 ", - "Fee: 100 ", -] -`; - -exports[`AlgebraBasePluginV2 #DynamicFeeManager #adaptiveFee single huge step after initialization 1`] = ` -Array [ - "Fee: 15000 ", - "Fee: 15000 ", - "Fee: 15000 ", - "Fee: 15000 ", - "Fee: 14311 ", - "Fee: 11402 ", - "Fee: 7651 ", - "Fee: 5386 ", - "Fee: 4312 ", - "Fee: 3795 ", - "Fee: 3525 ", - "Fee: 3371 ", - "Fee: 3277 ", - "Fee: 3216 ", - "Fee: 3174 ", - "Fee: 3144 ", - "Fee: 3123 ", - "Fee: 3106 ", - "Fee: 3093 ", - "Fee: 3083 ", - "Fee: 3075 ", - "Fee: 3068 ", - "Fee: 3062 ", - "Fee: 3058 ", - "Fee: 3037 ", -] -`; - -exports[`AlgebraBasePluginV2 AlgebraBasePluginV1 external methods #changeFeeConfiguration feeConfig getter gas cost [ @skip-on-coverage ] 1`] = `23708`; diff --git a/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap b/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap index ef3c1b4a2..7371eda9f 100644 --- a/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap +++ b/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap @@ -1,42 +1,42 @@ // 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`] = `216020`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee large swap crossing several initialized ticks 1`] = `216571`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle 1`] = `168035`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle 1`] = `168586`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 4h 1`] = `203473`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 4h 1`] = `204024`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 8h 1`] = `196259`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 8h 1`] = `196810`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 24h 1`] = `164527`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 24h 1`] = `165078`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee large swap crossing several initialized ticks 1`] = `214790`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee large swap crossing several initialized ticks 1`] = `215341`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle 1`] = `164537`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle 1`] = `165088`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 4h 1`] = `198002`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 4h 1`] = `198553`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 8h 1`] = `208936`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 8h 1`] = `209487`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 24h 1`] = `164009`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 24h 1`] = `164560`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn above current price burn when only position using ticks 1`] = `117065`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn above current price burn when only position using ticks 1`] = `117289`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn above current price entire position burn but other positions are using the ticks 1`] = `110857`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn above current price entire position burn but other positions are using the ticks 1`] = `111137`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn above current price partial position burn 1`] = `115657`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn above current price partial position burn 1`] = `115937`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn around current price burn when only position using ticks 1`] = `126944`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn around current price burn when only position using ticks 1`] = `127168`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn around current price entire position burn but other positions are using the ticks 1`] = `115265`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn around current price entire position burn but other positions are using the ticks 1`] = `115545`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn around current price partial position burn 1`] = `120065`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn around current price partial position burn 1`] = `120345`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn below current price burn when only position using ticks 1`] = `126501`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn below current price burn when only position using ticks 1`] = `126725`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn below current price entire position burn but other positions are using the ticks 1`] = `111518`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn below current price entire position burn but other positions are using the ticks 1`] = `111798`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn below current price partial position burn 1`] = `116318`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #burn below current price partial position burn 1`] = `116598`; exports[`AlgebraPool gas tests [ @skip-on-coverage ] Positions #collect close to worst case 1`] = `52593`; @@ -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`] = `63711`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `157448`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `157999`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement 1`] = `157417`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement 1`] = `157968`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `159202`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `159753`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `174008`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `174559`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `207558`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `208109`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `157515`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `158066`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `207558`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `208109`; -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`] = `226758`; +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`] = `227309`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `127681`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `128232`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block with no tick movement 1`] = `127645`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block with no tick movement 1`] = `128196`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `143426`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `143977`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `177797`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `178348`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 several large swaps with pauses 1`] = `234520`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 several large swaps with pauses 1`] = `235071`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `165048`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `165599`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `157509`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `158060`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block with no tick movement 1`] = `157457`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block with no tick movement 1`] = `158008`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 second swap in block with no tick movement 1`] = `127706`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 second swap in block with no tick movement 1`] = `128257`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `188859`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `189407`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block with no tick movement 1`] = `188807`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block with no tick movement 1`] = `189355`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected second swap in block with no tick movement 1`] = `141956`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected second swap in block with no tick movement 1`] = `142504`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `167935`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `166798`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `167904`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `166767`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `159427`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `159990`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `184732`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `183595`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `218993`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `217856`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `168002`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `166865`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `218993`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `217856`; -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`] = `238193`; +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`] = `237056`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `138168`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `137031`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `138132`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `136995`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `154150`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `153013`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `189232`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `188095`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `245955`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `244818`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `165273`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `165836`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `168007`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `166870`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `167955`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `166818`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `138204`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `137067`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `199357`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `198217`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `199305`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `198165`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `152454`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `151314`; diff --git a/src/plugin/test/__snapshots__/SlidingFee.spec.ts.snap b/src/plugin/test/__snapshots__/SlidingFee.spec.ts.snap index 6efd0b687..08bddc64a 100644 --- a/src/plugin/test/__snapshots__/SlidingFee.spec.ts.snap +++ b/src/plugin/test/__snapshots__/SlidingFee.spec.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`SlidingFee #getFee gas cost [ @skip-on-coverage ] gas cost of same tick 1`] = `26753`; +exports[`SlidingFee #getFee gas cost [ @skip-on-coverage ] gas cost of same tick 1`] = `26776`; -exports[`SlidingFee #getFee gas cost [ @skip-on-coverage ] gas cost of tick decrease 1`] = `31852`; +exports[`SlidingFee #getFee gas cost [ @skip-on-coverage ] gas cost of tick decrease 1`] = `31875`; -exports[`SlidingFee #getFee gas cost [ @skip-on-coverage ] gas cost of tick increase 1`] = `31738`; +exports[`SlidingFee #getFee gas cost [ @skip-on-coverage ] gas cost of tick increase 1`] = `31766`; diff --git a/src/plugin/test/shared/fixtures.ts b/src/plugin/test/shared/fixtures.ts index b6614ef1f..2e464009b 100644 --- a/src/plugin/test/shared/fixtures.ts +++ b/src/plugin/test/shared/fixtures.ts @@ -64,6 +64,18 @@ export const pluginFactoryFixture: Fixture = async functio }; }; +export const pluginFactoryFixtureV2: Fixture = async function (): Promise { + const { mockFactory } = await mockFactoryFixture(); + + const pluginFactoryFactory = await ethers.getContractFactory('BasePluginV2Factory'); + const pluginFactory = (await pluginFactoryFactory.deploy(mockFactory)) as any as BasePluginV2Factory; + + return { + pluginFactory, + mockFactory, + }; +}; + export const pluginFixtureV2: Fixture = async function (): Promise { const { mockFactory } = await mockFactoryFixture();