diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 485258dba..ed660fc72 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -3,10 +3,10 @@ name: Checks on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: Codespell: diff --git a/.github/workflows/echidna_core.yml b/.github/workflows/echidna_core.yml index ee4e228de..dc7c6f3b5 100644 --- a/.github/workflows/echidna_core.yml +++ b/.github/workflows/echidna_core.yml @@ -3,10 +3,10 @@ name: Echidna Core on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: IntegrationInvariants: diff --git a/.github/workflows/echidna_farming.yml b/.github/workflows/echidna_farming.yml index 8be296d17..f627e8752 100644 --- a/.github/workflows/echidna_farming.yml +++ b/.github/workflows/echidna_farming.yml @@ -3,10 +3,10 @@ name: Echidna Farming on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: UnitAsserts: diff --git a/.github/workflows/echidna_periphery.yml b/.github/workflows/echidna_periphery.yml index 58944a223..2a9941d77 100644 --- a/.github/workflows/echidna_periphery.yml +++ b/.github/workflows/echidna_periphery.yml @@ -3,10 +3,10 @@ name: Echidna Periphery on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: UnitAsserts: diff --git a/.github/workflows/echidna_plugin.yml b/.github/workflows/echidna_plugin.yml index 7c510490d..f82de3cc1 100644 --- a/.github/workflows/echidna_plugin.yml +++ b/.github/workflows/echidna_plugin.yml @@ -3,10 +3,10 @@ name: Echidna Plugin on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: UnitAsserts: diff --git a/.github/workflows/tests_core.yml b/.github/workflows/tests_core.yml index cd9c934bc..4a326e861 100644 --- a/.github/workflows/tests_core.yml +++ b/.github/workflows/tests_core.yml @@ -3,10 +3,10 @@ name: Autotests Core on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: Autotests: diff --git a/.github/workflows/tests_farmings.yml b/.github/workflows/tests_farmings.yml index 286fa7345..ce0943d39 100644 --- a/.github/workflows/tests_farmings.yml +++ b/.github/workflows/tests_farmings.yml @@ -3,10 +3,10 @@ name: Autotests Farmings on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: Autotests: diff --git a/.github/workflows/tests_periphery.yml b/.github/workflows/tests_periphery.yml index 3129ac3f3..bbee9e9cb 100644 --- a/.github/workflows/tests_periphery.yml +++ b/.github/workflows/tests_periphery.yml @@ -3,10 +3,10 @@ name: Autotests Periphery on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: Autotests: diff --git a/.github/workflows/tests_plugin.yml b/.github/workflows/tests_plugin.yml index 131c9fd2a..87667ca1f 100644 --- a/.github/workflows/tests_plugin.yml +++ b/.github/workflows/tests_plugin.yml @@ -3,10 +3,10 @@ name: Autotests Plugin on: push: branches: - - integral-v1.2.1 + - integral-v1.2.2 pull_request: branches: - - integral-v1.2.1 + - integral-v1.2.2 jobs: Autotests: diff --git a/deploys.json b/deploys.json index 9e26dfeeb..5af31f7f9 100644 --- a/deploys.json +++ b/deploys.json @@ -1 +1 @@ -{} \ No newline at end of file +{"poolDeployer":"0x578Eb01f7553689952B4A6194A8229E85955D47f","factory":"0x9548F884eC3737088796f91aec95d434e71229b0","vault":"0x7BDA9347Ba87A159e881679cfe5Bf39b80579C07","vaultFactory":"0x206fcA591F1A225667b7d269CA8773E4C4Ef5E59","BasePluginV1Factory":"0xCc486a16f069D6618c007eFCde79B9A817cBc41A","wrapped":"0x4200000000000000000000000000000000000006","entryPoint":"0x58aB9482D1687844602cAc637b2eEa5dDebD5583","tickLens":"0x1afd3e533278f627891c3D21997514e82B327fEC","quoter":"0x7ed5739C642aD9e6098815b819cA8111FA9E70dD","quoterV2":"0x428Be1356f68a31E867b6478dfA9AA76914a5834","swapRouter":"0x1E23BF717Ae4385B4494AaAe866e91568c0ac763","nftDescriptor":"0x3471870A22F8D1d5355714AfC034DD2C911F56aD","proxy":"0x982b9f8B80ed9E351cf9cCCB2Ce870b8E4Eec801","admin":"0xDeaD1F5aF792afc125812E875A891b038f888258","nonfungiblePositionManager":"0x645302e6E95F1441415a879DA24A110d14C94B2E","mcall":"0x49af1aCbB203019f048E03c808D16F011BC1CA8F","eternal":"0x8d5413c086d14b04A90aA913a4e12f2331EF7Fad","fc":"0xdbB7Fa758662400F8081a71fcfA1A09A11920A9a"} \ No newline at end of file diff --git a/docs/Contracts/Core/AlgebraCommunityVault.md b/docs/Contracts/Core/AlgebraCommunityVault.md index 81b40fd41..445893d44 100644 --- a/docs/Contracts/Core/AlgebraCommunityVault.md +++ b/docs/Contracts/Core/AlgebraCommunityVault.md @@ -8,9 +8,9 @@ Algebra community fee vault Community fee from pools is sent here, if it is enabled *Developer note: Role system is used to withdraw tokens -Version: Algebra Integral* +Version: Algebra Integral 1.2.2* -**Inherits:** [IAlgebraCommunityVault](interfaces/IAlgebraCommunityVault.md) +**Inherits:** [IAlgebraCommunityVault](interfaces/vault/IAlgebraCommunityVault.md) ## Modifiers ### onlyAdministrator @@ -118,13 +118,14 @@ Address of Algebra fee manager ### constructor ```solidity -constructor(address _algebraFeeManager) public +constructor(address _factory, address _algebraFeeManager) public ``` | Name | Type | Description | | ---- | ---- | ----------- | +| _factory | address | | | _algebraFeeManager | address | | ### withdraw diff --git a/docs/Contracts/Core/AlgebraFactory.md b/docs/Contracts/Core/AlgebraFactory.md index e105453c0..90097e43e 100644 --- a/docs/Contracts/Core/AlgebraFactory.md +++ b/docs/Contracts/Core/AlgebraFactory.md @@ -7,9 +7,9 @@ Algebra factory Is used to deploy pools and its plugins -*Developer note: Version: Algebra Integral* +*Developer note: Version: Algebra Integral 1.2.2* -**Inherits:** [IAlgebraFactory](interfaces/IAlgebraFactory.md) [Ownable2Step](https://docs.openzeppelin.com/contracts/4.x/) [AccessControlEnumerable](https://docs.openzeppelin.com/contracts/4.x/) +**Inherits:** [IAlgebraFactory](interfaces/IAlgebraFactory.md) [Ownable2Step](https://docs.openzeppelin.com/contracts/4.x/) [AccessControlEnumerable](https://docs.openzeppelin.com/contracts/4.x/) [ReentrancyGuard](https://docs.openzeppelin.com/contracts/4.x/) ## Public variables ### POOLS_ADMINISTRATOR_ROLE @@ -21,22 +21,22 @@ bytes32 constant POOLS_ADMINISTRATOR_ROLE = 0xb73ce166ead2f8e9add217713a7989e4ed role that can change communityFee and tickspacing in pools -### poolDeployer +### CUSTOM_POOL_DEPLOYER ```solidity -address immutable poolDeployer +bytes32 constant CUSTOM_POOL_DEPLOYER = 0xc9cf812513d9983585eb40fcfe6fd49fbb6a45815663ec33b30a6c6c7de3683b ``` -**Selector**: `0x3119049a` +**Selector**: `0x07810754` -Returns the current poolDeployerAddress +role that can call `createCustomPool` function -### communityVault +### poolDeployer ```solidity -address immutable communityVault +address immutable poolDeployer ``` -**Selector**: `0x53e97868` +**Selector**: `0x3119049a` -Returns the current communityVaultAddress +Returns the current poolDeployerAddress ### defaultCommunityFee @@ -83,6 +83,17 @@ contract IAlgebraPluginFactory defaultPluginFactory Return the current pluginFactory address +*Developer note: This contract is used to automatically set a plugin address in new liquidity pools* + +### vaultFactory +```solidity +contract IAlgebraVaultFactory vaultFactory +``` +**Selector**: `0xd8a06f73` + +Return the current vaultFactory address + +*Developer note: This contract is used to automatically set a vault address in new liquidity pools* ### poolByPair ```solidity @@ -94,9 +105,19 @@ Returns the pool address for a given pair of tokens, or address 0 if it does not *Developer note: tokenA and tokenB may be passed in either token0/token1 or token1/token0 order* +### customPoolByPair +```solidity +mapping(address => mapping(address => mapping(address => address))) customPoolByPair +``` +**Selector**: `0x23da36cc` + +Returns the custom pool address for a customDeployer and a given pair of tokens, or address 0 if it does not exist + +*Developer note: tokenA and tokenB may be passed in either token0/token1 or token1/token0 order* + ### POOL_INIT_CODE_HASH ```solidity -bytes32 constant POOL_INIT_CODE_HASH = 0x177d5fbf994f4d130c008797563306f1a168dc689f81b2fa23b4396931014d91 +bytes32 constant POOL_INIT_CODE_HASH = 0x62441ebe4e4315cf3d49d5957f94d66b253dbabe7006f34ad7f70947e60bf15c ``` **Selector**: `0xdc6fd8ab` @@ -162,7 +183,7 @@ function defaultConfigurationForPool() external view returns (uint16 communityFe ``` **Selector**: `0x25b355d6` -Returns the default communityFee and tickspacing +Returns the default communityFee, tickspacing, fee and communityFeeVault for pool **Returns:** @@ -194,12 +215,35 @@ Deterministically computes the pool address given the token0 and token1 | ---- | ---- | ----------- | | pool | address | The contract address of the Algebra pool | +### computeCustomPoolAddress + +```solidity +function computeCustomPoolAddress(address deployer, address token0, address token1) public view returns (address customPool) +``` +**Selector**: `0x1ba89df4` + +Deterministically computes the custom pool address given the customDeployer, token0 and token1 + +*Developer note: The method does not check if such a pool has been created* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| deployer | address | | +| token0 | address | first token | +| token1 | address | second token | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | The contract address of the Algebra pool | + ### createPool ```solidity -function createPool(address tokenA, address tokenB) external returns (address pool) +function createPool(address tokenA, address tokenB, bytes data) external returns (address pool) ``` -**Selector**: `0xe3433615` +**Selector**: `0x321935c6` Creates a pool for the given two tokens @@ -210,6 +254,7 @@ The call will revert if the pool already exists or the token arguments are inval | ---- | ---- | ----------- | | tokenA | address | One of the two tokens in the desired pool | | tokenB | address | The other of the two tokens in the desired pool | +| data | bytes | Data for plugin creation | **Returns:** @@ -217,6 +262,32 @@ The call will revert if the pool already exists or the token arguments are inval | ---- | ---- | ----------- | | pool | address | The address of the newly created pool | +### createCustomPool + +```solidity +function createCustomPool(address deployer, address creator, address tokenA, address tokenB, bytes data) external returns (address customPool) +``` +**Selector**: `0xdbbf3db4` + +Creates a custom pool for the given two tokens using `deployer` contract + +*Developer note: tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. +The call will revert if the pool already exists or the token arguments are invalid.* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| deployer | address | The address of plugin deployer, also used for custom pool address calculation | +| creator | address | The initiator of custom pool creation | +| tokenA | address | One of the two tokens in the desired pool | +| tokenB | address | The other of the two tokens in the desired pool | +| data | bytes | The additional data bytes | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | The address of the newly created custom pool | + ### setDefaultCommunityFee ```solidity @@ -277,6 +348,21 @@ function setDefaultPluginFactory(address newDefaultPluginFactory) external | ---- | ---- | ----------- | | newDefaultPluginFactory | address | address of new plugin factory | +### setVaultFactory + +```solidity +function setVaultFactory(address newVaultFactory) external +``` +**Selector**: `0x3ea7fbdb` + + + +*Developer note: updates vaultFactory address* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newVaultFactory | address | address of new vault factory | + ### startRenounceOwnership ```solidity diff --git a/docs/Contracts/Core/AlgebraPool.md b/docs/Contracts/Core/AlgebraPool.md index 72a507e8d..6c8c5c83b 100644 --- a/docs/Contracts/Core/AlgebraPool.md +++ b/docs/Contracts/Core/AlgebraPool.md @@ -7,10 +7,24 @@ Algebra concentrated liquidity pool This contract is responsible for liquidity positions, swaps and flashloans -*Developer note: Version: Algebra Integral* +*Developer note: Version: Algebra Integral 1.2.2* **Inherits:** [AlgebraPoolBase](base/AlgebraPoolBase.md) [TickStructure](base/TickStructure.md) ReentrancyGuard [Positions](base/Positions.md) SwapCalculation [ReservesManager](base/ReservesManager.md) +## Structs +### SwapEventParams + + + +```solidity +struct SwapEventParams { + uint160 currentPrice; + int24 currentTick; + uint128 currentLiquidity; +} +``` + + ## Functions ### initialize @@ -234,11 +248,27 @@ function setPluginConfig(uint8 newConfig) external ``` **Selector**: `0xbca57f81` -Set new plugin config +Set new plugin config. Only factory owner or POOLS_ADMINISTRATOR_ROLE role + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newConfig | uint8 | In the new configuration of the plugin, each bit of which is responsible for a particular hook. | + +### setCommunityVault + +```solidity +function setCommunityVault(address newCommunityVault) external +``` +**Selector**: `0xd8544cf3` + +Set new community fee vault address. Only factory owner or POOLS_ADMINISTRATOR_ROLE role + +*Developer note: Community fee vault receives collected community fees. +**accumulated but not yet sent to the vault community fees once will be sent to the `newCommunityVault` address*** | Name | Type | Description | | ---- | ---- | ----------- | -| newConfig | uint8 | In the new configuration of the plugin, each bit of which is responsible for a particular hook. Only factory owner or POOLS_ADMINISTRATOR_ROLE role | +| newCommunityVault | address | The address of new community fee vault | ### setFee @@ -254,3 +284,25 @@ Called by the plugin if dynamic fee is enabled | ---- | ---- | ----------- | | newFee | uint16 | The new fee value | +### sync + +```solidity +function sync() external +``` +**Selector**: `0xfff6cae9` + +Forces balances to match reserves. Excessive tokens will be distributed between active LPs + +*Developer note: Only plugin can call this function* + +### skim + +```solidity +function skim() external +``` +**Selector**: `0x1dd19cb4` + +Forces balances to match reserves. Excessive tokens will be sent to msg.sender + +*Developer note: Only plugin can call this function* + diff --git a/docs/Contracts/Core/AlgebraPoolDeployer.md b/docs/Contracts/Core/AlgebraPoolDeployer.md index 48fbcc0c8..a75f4a80c 100644 --- a/docs/Contracts/Core/AlgebraPoolDeployer.md +++ b/docs/Contracts/Core/AlgebraPoolDeployer.md @@ -7,7 +7,7 @@ Algebra pool deployer Is used by AlgebraFactory to deploy pools -*Developer note: Version: Algebra Integral* +*Developer note: Version: Algebra Integral 1.2.2* **Inherits:** [IAlgebraPoolDeployer](interfaces/IAlgebraPoolDeployer.md) @@ -15,7 +15,7 @@ Is used by AlgebraFactory to deploy pools ### constructor ```solidity -constructor(address _factory, address _communityVault) public +constructor(address _factory) public ``` @@ -23,12 +23,11 @@ constructor(address _factory, address _communityVault) public | Name | Type | Description | | ---- | ---- | ----------- | | _factory | address | | -| _communityVault | address | | ### getDeployParameters ```solidity -function getDeployParameters() external view returns (address _plugin, address _factory, address _communityVault, address _token0, address _token1) +function getDeployParameters() external view returns (address _plugin, address _factory, address _token0, address _token1) ``` **Selector**: `0x04889e26` @@ -42,16 +41,15 @@ Get the parameters to be used in constructing the pool, set transiently during p | ---- | ---- | ----------- | | _plugin | address | | | _factory | address | | -| _communityVault | address | | | _token0 | address | | | _token1 | address | | ### deploy ```solidity -function deploy(address plugin, address token0, address token1) external returns (address pool) +function deploy(address plugin, address token0, address token1, address deployer) external returns (address pool) ``` -**Selector**: `0xd9181cd3` +**Selector**: `0xfd82b73a` @@ -62,6 +60,7 @@ function deploy(address plugin, address token0, address token1) external returns | plugin | address | The pool associated plugin (if any) | | token0 | address | The first token of the pool by address sort order | | token1 | address | The second token of the pool by address sort order | +| deployer | address | | **Returns:** diff --git a/docs/Contracts/Core/AlgebraVaultFactoryStub.md b/docs/Contracts/Core/AlgebraVaultFactoryStub.md new file mode 100644 index 000000000..6e56e50f7 --- /dev/null +++ b/docs/Contracts/Core/AlgebraVaultFactoryStub.md @@ -0,0 +1,77 @@ + + +# AlgebraVaultFactoryStub + + +Algebra vault factory stub + +This contract is used to set AlgebraCommunityVault as communityVault in new pools + +**Inherits:** [IAlgebraVaultFactory](interfaces/vault/IAlgebraVaultFactory.md) + +## Public variables +### defaultAlgebraCommunityVault +```solidity +address immutable defaultAlgebraCommunityVault +``` +**Selector**: `0xb7a85452` + +the address of AlgebraCommunityVault + + + +## Functions +### constructor + +```solidity +constructor(address _algebraCommunityVault) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _algebraCommunityVault | address | | + +### getVaultForPool + +```solidity +function getVaultForPool(address) external view returns (address) +``` +**Selector**: `0x7570e389` + +returns address of the community fee vault for the pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | | + +### createVaultForPool + +```solidity +function createVaultForPool(address, address, address, address, address) external view returns (address) +``` +**Selector**: `0xb8a1d3c6` + +creates the community fee vault for the pool if needed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | address | | +| | address | | +| | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | | + diff --git a/docs/Contracts/Core/base/AlgebraPoolBase.md b/docs/Contracts/Core/base/AlgebraPoolBase.md index 266ecb097..74a8373e1 100644 --- a/docs/Contracts/Core/base/AlgebraPoolBase.md +++ b/docs/Contracts/Core/base/AlgebraPoolBase.md @@ -92,15 +92,6 @@ address immutable token1 The second of the two tokens of the pool, sorted by address -### communityVault -```solidity -address immutable communityVault -``` -**Selector**: `0x53e97868` - -The contract to which community fees are transferred - - ### totalFeeGrowth0Token ```solidity uint256 totalFeeGrowth0Token @@ -142,13 +133,13 @@ Look up information about a specific tick in the pool *Developer note: **important security note: caller should check reentrancy lock to prevent read-only reentrancy*** -### communityFeeLastTimestamp +### lastFeeTransferTimestamp ```solidity -uint32 communityFeeLastTimestamp +uint32 lastFeeTransferTimestamp ``` -**Selector**: `0x1131b110` +**Selector**: `0x77f8c3a9` -The timestamp of the last sending of tokens to community vault +The timestamp of the last sending of tokens to vault/plugin ### plugin @@ -161,6 +152,15 @@ Returns the address of currently used plugin *Developer note: The plugin is subject to change* +### communityVault +```solidity +address communityVault +``` +**Selector**: `0x53e97868` + +The contract to which community fees are transferred + + ### tickTable ```solidity mapping(int16 => uint256) tickTable @@ -276,6 +276,24 @@ The amounts of token0 and token1 that will be sent to the vault | [0] | uint128 | | | [1] | uint128 | | +### getPluginFeePending + +```solidity +function getPluginFeePending() external view returns (uint128, uint128) +``` +**Selector**: `0xa1eded87` + +The amounts of token0 and token1 that will be sent to the plugin + +*Developer note: Will be sent FEE_TRANSFER_FREQUENCY after feeLastTransferTimestamp* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint128 | | +| [1] | uint128 | | + ### fee ```solidity diff --git a/docs/Contracts/Core/interfaces/IAlgebraFactory.md b/docs/Contracts/Core/interfaces/IAlgebraFactory.md index 5bd586aa2..31ffa8bef 100644 --- a/docs/Contracts/Core/interfaces/IAlgebraFactory.md +++ b/docs/Contracts/Core/interfaces/IAlgebraFactory.md @@ -63,6 +63,21 @@ Emitted when a pool is created | token1 | address | The second token of the pool by address sort order | | pool | address | The address of the created pool | +### CustomPool + +```solidity +event CustomPool(address deployer, address token0, address token1, address pool) +``` + +Emitted when a pool is created + +| Name | Type | Description | +| ---- | ---- | ----------- | +| deployer | address | The corresponding custom deployer contract | +| token0 | address | The first token of the pool by address sort order | +| token1 | address | The second token of the pool by address sort order | +| pool | address | The address of the created pool | + ### DefaultCommunityFee ```solidity @@ -111,6 +126,18 @@ Emitted when the defaultPluginFactory address is changed | ---- | ---- | ----------- | | defaultPluginFactoryAddress | address | The new defaultPluginFactory address | +### VaultFactory + +```solidity +event VaultFactory(address newVaultFactory) +``` + +Emitted when the vaultFactory address is changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newVaultFactory | address | The new vaultFactory address | + ## Functions ### POOLS_ADMINISTRATOR_ROLE @@ -128,6 +155,21 @@ role that can change communityFee and tickspacing in pools | ---- | ---- | ----------- | | [0] | bytes32 | The hash corresponding to this role | +### CUSTOM_POOL_DEPLOYER + +```solidity +function CUSTOM_POOL_DEPLOYER() external view returns (bytes32) +``` +**Selector**: `0x07810754` + +role that can call `createCustomPool` function + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes32 | The hash corresponding to this role | + ### hasRoleOrOwner ```solidity @@ -180,21 +222,6 @@ Returns the current poolDeployerAddress | ---- | ---- | ----------- | | [0] | address | The address of the poolDeployer | -### communityVault - -```solidity -function communityVault() external view returns (address) -``` -**Selector**: `0x53e97868` - -Returns the current communityVaultAddress - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| [0] | address | The address to which community fees are transferred | - ### defaultCommunityFee ```solidity @@ -249,12 +276,31 @@ function defaultPluginFactory() external view returns (contract IAlgebraPluginFa Return the current pluginFactory address +*Developer note: This contract is used to automatically set a plugin address in new liquidity pools* + **Returns:** | Name | Type | Description | | ---- | ---- | ----------- | | [0] | contract IAlgebraPluginFactory | Algebra plugin factory | +### vaultFactory + +```solidity +function vaultFactory() external view returns (contract IAlgebraVaultFactory) +``` +**Selector**: `0xd8a06f73` + +Return the current vaultFactory address + +*Developer note: This contract is used to automatically set a vault address in new liquidity pools* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | contract IAlgebraVaultFactory | Algebra vault factory | + ### defaultConfigurationForPool ```solidity @@ -262,7 +308,7 @@ function defaultConfigurationForPool() external view returns (uint16 communityFe ``` **Selector**: `0x25b355d6` -Returns the default communityFee and tickspacing +Returns the default communityFee, tickspacing, fee and communityFeeVault for pool **Returns:** @@ -294,6 +340,29 @@ Deterministically computes the pool address given the token0 and token1 | ---- | ---- | ----------- | | pool | address | The contract address of the Algebra pool | +### computeCustomPoolAddress + +```solidity +function computeCustomPoolAddress(address customDeployer, address token0, address token1) external view returns (address customPool) +``` +**Selector**: `0x1ba89df4` + +Deterministically computes the custom pool address given the customDeployer, token0 and token1 + +*Developer note: The method does not check if such a pool has been created* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customDeployer | address | the address of custom plugin deployer | +| token0 | address | first token | +| token1 | address | second token | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | The contract address of the Algebra pool | + ### poolByPair ```solidity @@ -316,6 +385,29 @@ Returns the pool address for a given pair of tokens, or address 0 if it does not | ---- | ---- | ----------- | | pool | address | The pool address | +### customPoolByPair + +```solidity +function customPoolByPair(address customDeployer, address tokenA, address tokenB) external view returns (address customPool) +``` +**Selector**: `0x23da36cc` + +Returns the custom pool address for a customDeployer and a given pair of tokens, or address 0 if it does not exist + +*Developer note: tokenA and tokenB may be passed in either token0/token1 or token1/token0 order* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customDeployer | address | The address of custom plugin deployer | +| tokenA | address | The contract address of either token0 or token1 | +| tokenB | address | The contract address of the other token | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | The pool address | + ### POOL_INIT_CODE_HASH ```solidity @@ -351,9 +443,9 @@ function renounceOwnershipStartTimestamp() external view returns (uint256 timest ### createPool ```solidity -function createPool(address tokenA, address tokenB) external returns (address pool) +function createPool(address tokenA, address tokenB, bytes data) external returns (address pool) ``` -**Selector**: `0xe3433615` +**Selector**: `0x321935c6` Creates a pool for the given two tokens @@ -364,6 +456,7 @@ The call will revert if the pool already exists or the token arguments are inval | ---- | ---- | ----------- | | tokenA | address | One of the two tokens in the desired pool | | tokenB | address | The other of the two tokens in the desired pool | +| data | bytes | Data for plugin creation | **Returns:** @@ -371,6 +464,32 @@ The call will revert if the pool already exists or the token arguments are inval | ---- | ---- | ----------- | | pool | address | The address of the newly created pool | +### createCustomPool + +```solidity +function createCustomPool(address deployer, address creator, address tokenA, address tokenB, bytes data) external returns (address customPool) +``` +**Selector**: `0xdbbf3db4` + +Creates a custom pool for the given two tokens using `deployer` contract + +*Developer note: tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. +The call will revert if the pool already exists or the token arguments are invalid.* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| deployer | address | The address of plugin deployer, also used for custom pool address calculation | +| creator | address | The initiator of custom pool creation | +| tokenA | address | One of the two tokens in the desired pool | +| tokenB | address | The other of the two tokens in the desired pool | +| data | bytes | The additional data bytes | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | The address of the newly created custom pool | + ### setDefaultCommunityFee ```solidity @@ -431,6 +550,21 @@ function setDefaultPluginFactory(address newDefaultPluginFactory) external | ---- | ---- | ----------- | | newDefaultPluginFactory | address | address of new plugin factory | +### setVaultFactory + +```solidity +function setVaultFactory(address newVaultFactory) external +``` +**Selector**: `0x3ea7fbdb` + + + +*Developer note: updates vaultFactory address* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newVaultFactory | address | address of new vault factory | + ### startRenounceOwnership ```solidity diff --git a/docs/Contracts/Core/interfaces/IAlgebraPoolDeployer.md b/docs/Contracts/Core/interfaces/IAlgebraPoolDeployer.md index 004a4dcae..38311f843 100644 --- a/docs/Contracts/Core/interfaces/IAlgebraPoolDeployer.md +++ b/docs/Contracts/Core/interfaces/IAlgebraPoolDeployer.md @@ -17,7 +17,7 @@ https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces* ### getDeployParameters ```solidity -function getDeployParameters() external view returns (address plugin, address factory, address communityVault, address token0, address token1) +function getDeployParameters() external view returns (address plugin, address factory, address token0, address token1) ``` **Selector**: `0x04889e26` @@ -31,16 +31,15 @@ Get the parameters to be used in constructing the pool, set transiently during p | ---- | ---- | ----------- | | plugin | address | The pool associated plugin (if any) | | factory | address | The Algebra Factory address | -| communityVault | address | The community vault address | | token0 | address | The first token of the pool by address sort order | | token1 | address | The second token of the pool by address sort order | ### deploy ```solidity -function deploy(address plugin, address token0, address token1) external returns (address pool) +function deploy(address plugin, address token0, address token1, address deployer) external returns (address pool) ``` -**Selector**: `0xd9181cd3` +**Selector**: `0xfd82b73a` @@ -51,6 +50,7 @@ function deploy(address plugin, address token0, address token1) external returns | plugin | address | The pool associated plugin (if any) | | token0 | address | The first token of the pool by address sort order | | token1 | address | The second token of the pool by address sort order | +| deployer | address | | **Returns:** diff --git a/docs/Contracts/Core/interfaces/plugin/IAlgebraPlugin.md b/docs/Contracts/Core/interfaces/plugin/IAlgebraPlugin.md index 56cdaff50..f832fc23f 100644 --- a/docs/Contracts/Core/interfaces/plugin/IAlgebraPlugin.md +++ b/docs/Contracts/Core/interfaces/plugin/IAlgebraPlugin.md @@ -26,6 +26,26 @@ Returns plugin config | ---- | ---- | ----------- | | [0] | uint8 | config Each bit of the config is responsible for enabling/disabling the hooks. The last bit indicates whether the plugin contains dynamic fees logic | +### handlePluginFee + +```solidity +function handlePluginFee(uint256 pluginFee0, uint256 pluginFee1) external returns (bytes4) +``` +**Selector**: `0xaa6b14bb` + +Handle plugin fee transfer on plugin contract + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pluginFee0 | uint256 | Fee0 amount transferred to plugin | +| pluginFee1 | uint256 | Fee1 amount transferred to plugin | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | bytes4 The function selector | + ### beforeInitialize ```solidity @@ -70,7 +90,7 @@ The hook called after the state of a pool is initialized ### beforeModifyPosition ```solidity -function beforeModifyPosition(address sender, address recipient, int24 bottomTick, int24 topTick, int128 desiredLiquidityDelta, bytes data) external returns (bytes4) +function beforeModifyPosition(address sender, address recipient, int24 bottomTick, int24 topTick, int128 desiredLiquidityDelta, bytes data) external returns (bytes4 selector, uint24 pluginFee) ``` **Selector**: `0x5e2411b2` @@ -89,7 +109,8 @@ The hook called before a position is modified | Name | Type | Description | | ---- | ---- | ----------- | -| [0] | bytes4 | bytes4 The function selector for the hook | +| selector | bytes4 | The function selector for the hook | +| pluginFee | uint24 | | ### afterModifyPosition @@ -120,7 +141,7 @@ The hook called after a position is modified ### beforeSwap ```solidity -function beforeSwap(address sender, address recipient, bool zeroToOne, int256 amountRequired, uint160 limitSqrtPrice, bool withPaymentInAdvance, bytes data) external returns (bytes4) +function beforeSwap(address sender, address recipient, bool zeroToOne, int256 amountRequired, uint160 limitSqrtPrice, bool withPaymentInAdvance, bytes data) external returns (bytes4 selector, uint24 feeOverride, uint24 pluginFee) ``` **Selector**: `0x029c1cb7` @@ -140,7 +161,9 @@ The hook called before a swap | Name | Type | Description | | ---- | ---- | ----------- | -| [0] | bytes4 | bytes4 The function selector for the hook | +| selector | bytes4 | The function selector for the hook | +| feeOverride | uint24 | | +| pluginFee | uint24 | | ### afterSwap diff --git a/docs/Contracts/Core/interfaces/plugin/IAlgebraPluginFactory.md b/docs/Contracts/Core/interfaces/plugin/IAlgebraPluginFactory.md index 5c05a087d..0f0a6de8d 100644 --- a/docs/Contracts/Core/interfaces/plugin/IAlgebraPluginFactory.md +++ b/docs/Contracts/Core/interfaces/plugin/IAlgebraPluginFactory.md @@ -7,22 +7,28 @@ An interface for a contract that is capable of deploying Algebra plugins -*Developer note: Such a factory is needed if the plugin should be automatically created and connected to each new pool* +*Developer note: Such a factory can be used for automatic plugin creation for new pools. +Also a factory be used as an entry point for custom (additional) pools creation* ## Functions -### createPlugin +### beforeCreatePoolHook ```solidity -function createPlugin(address pool) external returns (address) +function beforeCreatePoolHook(address pool, address creator, address deployer, address token0, address token1, bytes data) external returns (address) ``` -**Selector**: `0x361c0f76` +**Selector**: `0x1d0338d9` Deploys new plugin contract for pool | Name | Type | Description | | ---- | ---- | ----------- | -| pool | address | The address of the pool for which the new plugin will be created | +| pool | address | The address of the new pool | +| creator | address | The address that initiated the pool creation | +| deployer | address | The address of new plugin deployer contract (0 if not used) | +| token0 | address | First token of the pool | +| token1 | address | Second token of the pool | +| data | bytes | | **Returns:** @@ -30,3 +36,18 @@ Deploys new plugin contract for pool | ---- | ---- | ----------- | | [0] | address | New plugin address | +### afterCreatePoolHook + +```solidity +function afterCreatePoolHook(address plugin, address pool, address deployer) external +``` +**Selector**: `0x8d5ef8d1` + +Called after the pool is created + +| Name | Type | Description | +| ---- | ---- | ----------- | +| plugin | address | The plugin address | +| pool | address | The address of the new pool | +| deployer | address | The address of new plugin deployer contract (0 if not used) | + diff --git a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolErrors.md b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolErrors.md index 559ae130a..2f36a1ebe 100644 --- a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolErrors.md +++ b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolErrors.md @@ -65,6 +65,15 @@ error invalidAmountRequired() Emitted if invalid amount is passed as amountRequired to swap function +## incorrectPluginFee + +```solidity +error incorrectPluginFee() +``` +**Selector**: `0x15b2afa9` + +Emitted if plugin fee param greater than fee/override fee + ## insufficientInputAmount ```solidity diff --git a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolEvents.md b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolEvents.md index 3067db532..4c3e07a29 100644 --- a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolEvents.md +++ b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolEvents.md @@ -81,6 +81,19 @@ Emitted when a position's liquidity is removed | amount0 | uint256 | The amount of token0 withdrawn | | amount1 | uint256 | The amount of token1 withdrawn | +### BurnFee + +```solidity +event BurnFee(address owner, uint24 pluginFee) +``` + +Emitted when a plugin fee is applied during a burn + +| Name | Type | Description | +| ---- | ---- | ----------- | +| owner | address | The owner of the position | +| pluginFee | uint24 | The fee to be sent to the plugin | + ### Swap ```solidity @@ -99,6 +112,20 @@ Emitted by the pool for any swaps between token0 and token1 | liquidity | uint128 | The liquidity of the pool after the swap | | tick | int24 | The log base 1.0001 of price of the pool after the swap | +### SwapFee + +```solidity +event SwapFee(address sender, uint24 overrideFee, uint24 pluginFee) +``` + +Emitted by the pool after any swaps + +| Name | Type | Description | +| ---- | ---- | ----------- | +| sender | address | The address that initiated the swap | +| overrideFee | uint24 | The fee to be applied to the trade | +| pluginFee | uint24 | The fee to be sent to the plugin | + ### Flash ```solidity @@ -116,6 +143,22 @@ Emitted by the pool for any flashes of token0/token1 | paid0 | uint256 | The amount of token0 paid for the flash, which can exceed the amount0 plus the fee | | paid1 | uint256 | The amount of token1 paid for the flash, which can exceed the amount1 plus the fee | +### ExcessTokens + +```solidity +event ExcessTokens(uint256 amount0, uint256 amount1) +``` + +Emitted when the pool has higher balances than expected. +Any excess of tokens will be distributed between liquidity providers as fee. + +*Developer note: Fees after flash also will trigger this event due to mechanics of flash.* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| amount0 | uint256 | The excess of token0 | +| amount1 | uint256 | The excess of token1 | + ### CommunityFee ```solidity @@ -176,3 +219,29 @@ Emitted when the fee changes inside the pool | ---- | ---- | ----------- | | fee | uint16 | The current fee in hundredths of a bip, i.e. 1e-6 | +### CommunityVault + +```solidity +event CommunityVault(address newCommunityVault) +``` + +Emitted when the community vault address changes + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newCommunityVault | address | New community vault | + +### Skim + +```solidity +event Skim(address to, uint256 amount0, uint256 amount1) +``` + +Emitted when the plugin does skim the excess of tokens + +| Name | Type | Description | +| ---- | ---- | ----------- | +| to | address | THe receiver of tokens (plugin) | +| amount0 | uint256 | The amount of token0 | +| amount1 | uint256 | The amount of token1 | + diff --git a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolImmutables.md b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolImmutables.md index 5488fc987..afd86b473 100644 --- a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolImmutables.md +++ b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolImmutables.md @@ -57,21 +57,6 @@ The second of the two tokens of the pool, sorted by address | ---- | ---- | ----------- | | [0] | address | The token contract address | -### communityVault - -```solidity -function communityVault() external view returns (address) -``` -**Selector**: `0x53e97868` - -The contract to which community fees are transferred - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| [0] | address | The communityVault address | - ### maxLiquidityPerTick ```solidity diff --git a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolPermissionedActions.md b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolPermissionedActions.md index c51eacb10..b9f9c52ae 100644 --- a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolPermissionedActions.md +++ b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolPermissionedActions.md @@ -58,11 +58,27 @@ function setPluginConfig(uint8 newConfig) external ``` **Selector**: `0xbca57f81` -Set new plugin config +Set new plugin config. Only factory owner or POOLS_ADMINISTRATOR_ROLE role | Name | Type | Description | | ---- | ---- | ----------- | -| newConfig | uint8 | In the new configuration of the plugin, each bit of which is responsible for a particular hook. Only factory owner or POOLS_ADMINISTRATOR_ROLE role | +| newConfig | uint8 | In the new configuration of the plugin, each bit of which is responsible for a particular hook. | + +### setCommunityVault + +```solidity +function setCommunityVault(address newCommunityVault) external +``` +**Selector**: `0xd8544cf3` + +Set new community fee vault address. Only factory owner or POOLS_ADMINISTRATOR_ROLE role + +*Developer note: Community fee vault receives collected community fees. +**accumulated but not yet sent to the vault community fees once will be sent to the `newCommunityVault` address*** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newCommunityVault | address | The address of new community fee vault | ### setFee @@ -78,3 +94,25 @@ Called by the plugin if dynamic fee is enabled | ---- | ---- | ----------- | | newFee | uint16 | The new fee value | +### sync + +```solidity +function sync() external +``` +**Selector**: `0xfff6cae9` + +Forces balances to match reserves. Excessive tokens will be distributed between active LPs + +*Developer note: Only plugin can call this function* + +### skim + +```solidity +function skim() external +``` +**Selector**: `0x1dd19cb4` + +Forces balances to match reserves. Excessive tokens will be sent to msg.sender + +*Developer note: Only plugin can call this function* + diff --git a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolState.md b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolState.md index b27fea7b3..ca87a6962 100644 --- a/docs/Contracts/Core/interfaces/pool/IAlgebraPoolState.md +++ b/docs/Contracts/Core/interfaces/pool/IAlgebraPoolState.md @@ -105,14 +105,14 @@ Look up information about a specific tick in the pool | outerFeeGrowth0Token | uint256 | The fee growth on the other side of the tick from the current tick in token0 | | outerFeeGrowth1Token | uint256 | The fee growth on the other side of the tick from the current tick in token1 In addition, these values are only relative and must be used only in comparison to previous snapshots for a specific position. | -### communityFeeLastTimestamp +### lastFeeTransferTimestamp ```solidity -function communityFeeLastTimestamp() external view returns (uint32) +function lastFeeTransferTimestamp() external view returns (uint32) ``` -**Selector**: `0x1131b110` +**Selector**: `0x77f8c3a9` -The timestamp of the last sending of tokens to community vault +The timestamp of the last sending of tokens to vault/plugin **Returns:** @@ -138,6 +138,24 @@ The amounts of token0 and token1 that will be sent to the vault | communityFeePending0 | uint128 | The amount of token0 that will be sent to the vault | | communityFeePending1 | uint128 | The amount of token1 that will be sent to the vault | +### getPluginFeePending + +```solidity +function getPluginFeePending() external view returns (uint128 pluginFeePending0, uint128 pluginFeePending1) +``` +**Selector**: `0xa1eded87` + +The amounts of token0 and token1 that will be sent to the plugin + +*Developer note: Will be sent FEE_TRANSFER_FREQUENCY after feeLastTransferTimestamp* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pluginFeePending0 | uint128 | The amount of token0 that will be sent to the plugin | +| pluginFeePending1 | uint128 | The amount of token1 that will be sent to the plugin | + ### plugin ```solidity @@ -155,6 +173,21 @@ Returns the address of currently used plugin | ---- | ---- | ----------- | | pluginAddress | address | The address of currently used plugin | +### communityVault + +```solidity +function communityVault() external view returns (address communityVaultAddress) +``` +**Selector**: `0x53e97868` + +The contract to which community fees are transferred + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| communityVaultAddress | address | The communityVault address | + ### tickTable ```solidity diff --git a/docs/Contracts/Core/interfaces/vault/IAlgebraCommunityVault.md b/docs/Contracts/Core/interfaces/vault/IAlgebraCommunityVault.md new file mode 100644 index 000000000..7f61a52b3 --- /dev/null +++ b/docs/Contracts/Core/interfaces/vault/IAlgebraCommunityVault.md @@ -0,0 +1,257 @@ + + +# IAlgebraCommunityVault + + +The interface for the Algebra community fee vault + +Community fee from pools is sent here, if it is enabled + +*Developer note: Version: Algebra Integral* + + +## Events +### TokensWithdrawal + +```solidity +event TokensWithdrawal(address token, address to, uint256 amount) +``` + +Event emitted when a fees has been claimed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token | address | The address of token fee | +| to | address | The address where claimed rewards were sent to | +| amount | uint256 | The amount of fees tokens claimed by communityFeeReceiver | + +### AlgebraTokensWithdrawal + +```solidity +event AlgebraTokensWithdrawal(address token, address to, uint256 amount) +``` + +Event emitted when a fees has been claimed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token | address | The address of token fee | +| to | address | The address where claimed rewards were sent to | +| amount | uint256 | The amount of fees tokens claimed by Algebra | + +### AlgebraFeeReceiver + +```solidity +event AlgebraFeeReceiver(address newAlgebraFeeReceiver) +``` + +Emitted when a AlgebraFeeReceiver address changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newAlgebraFeeReceiver | address | New Algebra fee receiver address | + +### PendingAlgebraFeeManager + +```solidity +event PendingAlgebraFeeManager(address pendingAlgebraFeeManager) +``` + +Emitted when a AlgebraFeeManager address change proposed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pendingAlgebraFeeManager | address | New pending Algebra fee manager address | + +### AlgebraFeeProposal + +```solidity +event AlgebraFeeProposal(uint16 proposedNewAlgebraFee) +``` + +Emitted when a new Algebra fee value proposed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| proposedNewAlgebraFee | uint16 | The new proposed Algebra fee value | + +### CancelAlgebraFeeProposal + +```solidity +event CancelAlgebraFeeProposal() +``` + +Emitted when a Algebra fee proposal canceled + +### AlgebraFeeManager + +```solidity +event AlgebraFeeManager(address newAlgebraFeeManager) +``` + +Emitted when a AlgebraFeeManager address changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newAlgebraFeeManager | address | New Algebra fee manager address | + +### AlgebraFee + +```solidity +event AlgebraFee(uint16 newAlgebraFee) +``` + +Emitted when the Algebra fee is changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newAlgebraFee | uint16 | The new Algebra fee value | + +### CommunityFeeReceiver + +```solidity +event CommunityFeeReceiver(address newCommunityFeeReceiver) +``` + +Emitted when a CommunityFeeReceiver address changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newCommunityFeeReceiver | address | New fee receiver address | + + +## Structs +### WithdrawTokensParams + + + +```solidity +struct WithdrawTokensParams { + address token; + uint256 amount; +} +``` + + +## Functions +### withdraw + +```solidity +function withdraw(address token, uint256 amount) external +``` +**Selector**: `0xf3fef3a3` + +Withdraw protocol fees from vault + +*Developer note: Can only be called by algebraFeeManager or communityFeeReceiver* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token | address | The token address | +| amount | uint256 | The amount of token | + +### withdrawTokens + +```solidity +function withdrawTokens(struct IAlgebraCommunityVault.WithdrawTokensParams[] params) external +``` +**Selector**: `0xdfadc794` + +Withdraw protocol fees from vault. Used to claim fees for multiple tokens + +*Developer note: Can be called by algebraFeeManager or communityFeeReceiver* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| params | struct IAlgebraCommunityVault.WithdrawTokensParams[] | Array of WithdrawTokensParams objects containing token addresses and amounts to withdraw | + +### acceptAlgebraFeeChangeProposal + +```solidity +function acceptAlgebraFeeChangeProposal(uint16 newAlgebraFee) external +``` +**Selector**: `0xff3c43e1` + +Accepts the proposed new Algebra fee + +*Developer note: Can only be called by the factory owner. +The new value will also be used for previously accumulated tokens that have not yet been withdrawn* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newAlgebraFee | uint16 | New Algebra fee value | + +### changeCommunityFeeReceiver + +```solidity +function changeCommunityFeeReceiver(address newCommunityFeeReceiver) external +``` +**Selector**: `0xb5f680ae` + +Change community fee receiver address + +*Developer note: Can only be called by the factory owner* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newCommunityFeeReceiver | address | New community fee receiver address | + +### transferAlgebraFeeManagerRole + +```solidity +function transferAlgebraFeeManagerRole(address _newAlgebraFeeManager) external +``` +**Selector**: `0x50eea0c8` + +Transfers Algebra fee manager role + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _newAlgebraFeeManager | address | new Algebra fee manager address | + +### acceptAlgebraFeeManagerRole + +```solidity +function acceptAlgebraFeeManagerRole() external +``` +**Selector**: `0xad6129ac` + +accept Algebra FeeManager role + +### proposeAlgebraFeeChange + +```solidity +function proposeAlgebraFeeChange(uint16 newAlgebraFee) external +``` +**Selector**: `0xd9fb4353` + +Proposes new Algebra fee value for protocol + +*Developer note: the new value will also be used for previously accumulated tokens that have not yet been withdrawn* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newAlgebraFee | uint16 | new Algebra fee value | + +### cancelAlgebraFeeChangeProposal + +```solidity +function cancelAlgebraFeeChangeProposal() external +``` +**Selector**: `0xd17bc783` + +Cancels Algebra fee change proposal + +### changeAlgebraFeeReceiver + +```solidity +function changeAlgebraFeeReceiver(address newAlgebraFeeReceiver) external +``` +**Selector**: `0x48a50fcf` + +Change Algebra community fee part receiver + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newAlgebraFeeReceiver | address | The address of new Algebra fee receiver | + diff --git a/docs/Contracts/Core/interfaces/vault/IAlgebraVaultFactory.md b/docs/Contracts/Core/interfaces/vault/IAlgebraVaultFactory.md new file mode 100644 index 000000000..7ea849e36 --- /dev/null +++ b/docs/Contracts/Core/interfaces/vault/IAlgebraVaultFactory.md @@ -0,0 +1,55 @@ + + +# IAlgebraVaultFactory + + +The interface for the Algebra Vault Factory + +This contract can be used for automatic vaults creation + +*Developer note: Version: Algebra Integral* + + +## Functions +### getVaultForPool + +```solidity +function getVaultForPool(address pool) external view returns (address communityFeeVault) +``` +**Selector**: `0x7570e389` + +returns address of the community fee vault for the pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | the address of Algebra Integral pool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| communityFeeVault | address | the address of community fee vault | + +### createVaultForPool + +```solidity +function createVaultForPool(address pool, address creator, address deployer, address token0, address token1) external returns (address communityFeeVault) +``` +**Selector**: `0xb8a1d3c6` + +creates the community fee vault for the pool if needed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | the address of Algebra Integral pool | +| creator | address | | +| deployer | address | | +| token0 | address | | +| token1 | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| communityFeeVault | address | the address of community fee vault | + diff --git a/docs/Contracts/Core/test/FaultyVaultFactoryStub.md b/docs/Contracts/Core/test/FaultyVaultFactoryStub.md new file mode 100644 index 000000000..aef4f18af --- /dev/null +++ b/docs/Contracts/Core/test/FaultyVaultFactoryStub.md @@ -0,0 +1,77 @@ + + +# FaultyVaultFactoryStub + + +Algebra vault factory stub + +This contract is used to set AlgebraCommunityVault as communityVault in new pools + +**Inherits:** [IAlgebraVaultFactory](../interfaces/vault/IAlgebraVaultFactory.md) + +## Public variables +### defaultAlgebraCommunityVault +```solidity +address immutable defaultAlgebraCommunityVault +``` +**Selector**: `0xb7a85452` + +the address of AlgebraCommunityVault + + + +## Functions +### constructor + +```solidity +constructor(address _algebraCommunityVault) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _algebraCommunityVault | address | | + +### getVaultForPool + +```solidity +function getVaultForPool(address) external view returns (address) +``` +**Selector**: `0x7570e389` + +returns address of the community fee vault for the pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | | + +### createVaultForPool + +```solidity +function createVaultForPool(address, address, address, address, address) external view returns (address) +``` +**Selector**: `0xb8a1d3c6` + +creates the community fee vault for the pool if needed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | address | | +| | address | | +| | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | | + diff --git a/docs/Contracts/Farming/FarmingCenter.md b/docs/Contracts/Farming/FarmingCenter.md index 8b167cb03..1820b347e 100644 --- a/docs/Contracts/Farming/FarmingCenter.md +++ b/docs/Contracts/Farming/FarmingCenter.md @@ -3,7 +3,7 @@ # FarmingCenter -Algebra main farming contract +Algebra Integral 1.2.2 main farming contract @@ -164,7 +164,7 @@ Used to collect reward from eternal farming. Then reward can be claimed. ### claimReward ```solidity -function claimReward(contract IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 reward) +function claimReward(contract IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 rewardBalanceBefore) ``` **Selector**: `0x2f2d783d` @@ -182,7 +182,7 @@ Used to claim and send rewards from farming(s) | Name | Type | Description | | ---- | ---- | ----------- | -| reward | uint256 | The summary amount of claimed rewards | +| rewardBalanceBefore | uint256 | The total amount of unclaimed reward *before* claim | ### connectVirtualPoolToPlugin diff --git a/docs/Contracts/Farming/farmings/AlgebraEternalFarming.md b/docs/Contracts/Farming/farmings/AlgebraEternalFarming.md index 48b507e97..6640fd568 100644 --- a/docs/Contracts/Farming/farmings/AlgebraEternalFarming.md +++ b/docs/Contracts/Farming/farmings/AlgebraEternalFarming.md @@ -3,7 +3,7 @@ # AlgebraEternalFarming -Algebra eternal (v2-like) farming +Algebra Integral 1.2.2 eternal (v2-like) farming Manages rewards and virtual pools @@ -131,6 +131,16 @@ Returns information about a farmed liquidity NFT *Developer note: farms[tokenId][incentiveHash] => Farm* +### incentiveKeys +```solidity +mapping(address => struct IncentiveKey) incentiveKeys +``` +**Selector**: `0x57655846` + +Returns connected to pool incentive key + +*Developer note: pool => IncentiveKey* + ### numOfIncentives ```solidity uint256 numOfIncentives @@ -189,9 +199,9 @@ Check if incentive is deactivated (manually or automatically) ### createEternalFarming ```solidity -function createEternalFarming(struct IncentiveKey key, struct IAlgebraEternalFarming.IncentiveParams params) external returns (address virtualPool) +function createEternalFarming(struct IncentiveKey key, struct IAlgebraEternalFarming.IncentiveParams params, address plugin) external returns (address virtualPool) ``` -**Selector**: `0x566d3c71` +**Selector**: `0x547b6da9` Creates a new liquidity farming incentive program @@ -199,6 +209,7 @@ Creates a new liquidity farming incentive program | ---- | ---- | ----------- | | key | struct IncentiveKey | Details of the incentive to create | | params | struct IAlgebraEternalFarming.IncentiveParams | Params of incentive | +| plugin | address | The address of corresponding plugin | **Returns:** @@ -342,7 +353,7 @@ Transfers `amountRequested` of accrued `rewardToken` (if pos | Name | Type | Description | | ---- | ---- | ----------- | -| reward | uint256 | The amount of reward tokens claimed | +| reward | uint256 | | ### claimRewardFrom @@ -365,7 +376,7 @@ only for FarmingCenter | Name | Type | Description | | ---- | ---- | ----------- | -| reward | uint256 | The amount of reward tokens claimed | +| reward | uint256 | | ### getRewardInfo diff --git a/docs/Contracts/Farming/farmings/EternalVirtualPool.md b/docs/Contracts/Farming/farmings/EternalVirtualPool.md index 026b87781..476c06539 100644 --- a/docs/Contracts/Farming/farmings/EternalVirtualPool.md +++ b/docs/Contracts/Farming/farmings/EternalVirtualPool.md @@ -3,7 +3,7 @@ # EternalVirtualPool -Algebra eternal virtual pool +Algebra Integral 1.2.2 eternal virtual pool used to track active liquidity in farming and distribute rewards diff --git a/docs/Contracts/Farming/interfaces/IAlgebraEternalFarming.md b/docs/Contracts/Farming/interfaces/IAlgebraEternalFarming.md index be90afb8d..2b5291b21 100644 --- a/docs/Contracts/Farming/interfaces/IAlgebraEternalFarming.md +++ b/docs/Contracts/Farming/interfaces/IAlgebraEternalFarming.md @@ -446,7 +446,7 @@ exitFarmings for Algebra LP token ### claimReward ```solidity -function claimReward(contract IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 reward) +function claimReward(contract IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 rewardBalanceBefore) ``` **Selector**: `0x2f2d783d` @@ -462,12 +462,12 @@ Transfers `amountRequested` of accrued `rewardToken` (if pos | Name | Type | Description | | ---- | ---- | ----------- | -| reward | uint256 | The amount of reward tokens claimed | +| rewardBalanceBefore | uint256 | The total amount of unclaimed reward *before* claim | ### claimRewardFrom ```solidity -function claimRewardFrom(contract IERC20Minimal rewardToken, address from, address to, uint256 amountRequested) external returns (uint256 reward) +function claimRewardFrom(contract IERC20Minimal rewardToken, address from, address to, uint256 amountRequested) external returns (uint256 rewardBalanceBefore) ``` **Selector**: `0x0a530754` @@ -485,7 +485,7 @@ only for FarmingCenter | Name | Type | Description | | ---- | ---- | ----------- | -| reward | uint256 | The amount of reward tokens claimed | +| rewardBalanceBefore | uint256 | The total amount of unclaimed reward *before* claim | ### getRewardInfo @@ -532,12 +532,34 @@ Returns information about a farmed liquidity NFT | innerRewardGrowth0 | uint256 | The last saved reward0 growth inside position, | | innerRewardGrowth1 | uint256 | The last saved reward1 growth inside position | +### incentiveKeys + +```solidity +function incentiveKeys(address poolAddress) external view returns (contract IERC20Minimal rewardToken, contract IERC20Minimal bonusRewardToken, contract IAlgebraPool pool, uint256 nonce) +``` +**Selector**: `0x57655846` + +Returns connected to pool incentive key + +| Name | Type | Description | +| ---- | ---- | ----------- | +| poolAddress | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| rewardToken | contract IERC20Minimal | | +| bonusRewardToken | contract IERC20Minimal | | +| pool | contract IAlgebraPool | | +| nonce | uint256 | | + ### createEternalFarming ```solidity -function createEternalFarming(struct IncentiveKey key, struct IAlgebraEternalFarming.IncentiveParams params) external returns (address virtualPool) +function createEternalFarming(struct IncentiveKey key, struct IAlgebraEternalFarming.IncentiveParams params, address plugin) external returns (address virtualPool) ``` -**Selector**: `0x566d3c71` +**Selector**: `0x547b6da9` Creates a new liquidity farming incentive program @@ -545,6 +567,7 @@ Creates a new liquidity farming incentive program | ---- | ---- | ----------- | | key | struct IncentiveKey | Details of the incentive to create | | params | struct IAlgebraEternalFarming.IncentiveParams | Params of incentive | +| plugin | address | The address of corresponding plugin | **Returns:** diff --git a/docs/Contracts/Farming/interfaces/IFarmingCenter.md b/docs/Contracts/Farming/interfaces/IFarmingCenter.md index 65501f13a..3f026a3bf 100644 --- a/docs/Contracts/Farming/interfaces/IFarmingCenter.md +++ b/docs/Contracts/Farming/interfaces/IFarmingCenter.md @@ -207,7 +207,7 @@ Used to collect reward from eternal farming. Then reward can be claimed. ### claimReward ```solidity -function claimReward(contract IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 reward) +function claimReward(contract IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 rewardBalanceBefore) ``` **Selector**: `0x2f2d783d` @@ -225,5 +225,5 @@ Used to claim and send rewards from farming(s) | Name | Type | Description | | ---- | ---- | ----------- | -| reward | uint256 | The summary amount of claimed rewards | +| rewardBalanceBefore | uint256 | The total amount of unclaimed reward *before* claim | diff --git a/docs/Contracts/Periphery/AlgebraCustomPoolEntryPoint.md b/docs/Contracts/Periphery/AlgebraCustomPoolEntryPoint.md new file mode 100644 index 000000000..ab409c63a --- /dev/null +++ b/docs/Contracts/Periphery/AlgebraCustomPoolEntryPoint.md @@ -0,0 +1,177 @@ + + +# AlgebraCustomPoolEntryPoint + + +Algebra custom pool entry point + +Is used to create custom pools + +*Developer note: Version: Algebra Integral 1.2.2* + +**Inherits:** [IAlgebraCustomPoolEntryPoint](interfaces/IAlgebraCustomPoolEntryPoint.md) +## Modifiers +### onlyCustomDeployer + +```solidity +modifier onlyCustomDeployer(address pool) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | | + + +## Public variables +### factory +```solidity +address immutable factory +``` +**Selector**: `0xc45a0155` + +Returns the address of corresponding AlgebraFactory contract + + + +## Functions +### constructor + +```solidity +constructor(address _factory) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _factory | address | | + +### createCustomPool + +```solidity +function createCustomPool(address deployer, address creator, address tokenA, address tokenB, bytes data) external returns (address customPool) +``` +**Selector**: `0xdbbf3db4` + +Using for custom pools creation + +| Name | Type | Description | +| ---- | ---- | ----------- | +| deployer | address | The address of plugin deployer, also used for custom pool address calculation | +| creator | address | The initiator of custom pool creation | +| tokenA | address | One of the two tokens in the desired pool | +| tokenB | address | The other of the two tokens in the desired pool | +| data | bytes | The additional data bytes | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | | + +### beforeCreatePoolHook + +```solidity +function beforeCreatePoolHook(address pool, address creator, address deployer, address token0, address token1, bytes data) external returns (address) +``` +**Selector**: `0x1d0338d9` + +Deploys new plugin contract for pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the new pool | +| creator | address | The address that initiated the pool creation | +| deployer | address | The address of new plugin deployer contract (0 if not used) | +| token0 | address | First token of the pool | +| token1 | address | Second token of the pool | +| data | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | New plugin address | + +### afterCreatePoolHook + +```solidity +function afterCreatePoolHook(address plugin, address pool, address deployer) external +``` +**Selector**: `0x8d5ef8d1` + +Called after the pool is created + +| Name | Type | Description | +| ---- | ---- | ----------- | +| plugin | address | The plugin address | +| pool | address | The address of the new pool | +| deployer | address | The address of new plugin deployer contract (0 if not used) | + +### setTickSpacing + +```solidity +function setTickSpacing(address pool, int24 newTickSpacing) external +``` +**Selector**: `0x4bf092cd` + +Changes the tick spacing value in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newTickSpacing | int24 | The new tick spacing value | + +### setPlugin + +```solidity +function setPlugin(address pool, address newPluginAddress) external +``` +**Selector**: `0xf9f4c09a` + +Changes the plugin address in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newPluginAddress | address | The new plugin address | + +### setPluginConfig + +```solidity +function setPluginConfig(address pool, uint8 newConfig) external +``` +**Selector**: `0x054bee3d` + +Changes the plugin configuration in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newConfig | uint8 | The new plugin configuration bitmap | + +### setFee + +```solidity +function setFee(address pool, uint16 newFee) external +``` +**Selector**: `0x337f3a31` + +Changes the fee value in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function. +Fee can be changed manually only if pool does not have "dynamic fee" configuration* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newFee | uint16 | The new fee value | + diff --git a/docs/Contracts/Periphery/NonfungiblePositionManager.md b/docs/Contracts/Periphery/NonfungiblePositionManager.md index d5e968675..e58e61205 100644 --- a/docs/Contracts/Periphery/NonfungiblePositionManager.md +++ b/docs/Contracts/Periphery/NonfungiblePositionManager.md @@ -3,7 +3,7 @@ # NonfungiblePositionManager -NFT positions +Algebra Integral 1.2.2 NFT positions Wraps Algebra positions in the ERC721 non-fungible token interface @@ -104,7 +104,7 @@ constructor(address _factory, address _WNativeToken, address _tokenDescriptor_, ### positions ```solidity -function positions(uint256 tokenId) external view returns (uint88 nonce, address operator, address token0, address token1, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1) +function positions(uint256 tokenId) external view returns (uint88 nonce, address operator, address token0, address token1, address deployer, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1) ``` **Selector**: `0x99fbab88` @@ -124,6 +124,7 @@ Returns the position information associated with a given token ID. | operator | address | The address that is approved for spending | | token0 | address | The address of the token0 for a specific pool | | token1 | address | The address of the token1 for a specific pool | +| deployer | address | The address of the custom pool deployer | | tickLower | int24 | The lower end of the tick range for the position | | tickUpper | int24 | The higher end of the tick range for the position | | liquidity | uint128 | The liquidity of the position | @@ -137,12 +138,13 @@ Returns the position information associated with a given token ID. ```solidity function mint(struct INonfungiblePositionManager.MintParams params) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) ``` -**Selector**: `0x9cc1a283` +**Selector**: `0xfe3f3be7` Creates a new position wrapped in a NFT *Developer note: Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized -a method does not exist, i.e. the pool is assumed to be initialized.* +a method does not exist, i.e. the pool is assumed to be initialized. +If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* | Name | Type | Description | | ---- | ---- | ----------- | @@ -166,6 +168,8 @@ function increaseLiquidity(struct INonfungiblePositionManager.IncreaseLiquidityP Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` +*Developer note: If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* + | Name | Type | Description | | ---- | ---- | ----------- | | params | struct INonfungiblePositionManager.IncreaseLiquidityParams | tokenId The ID of the token for which liquidity is being increased, amount0Desired The desired amount of token0 to be spent, amount1Desired The desired amount of token1 to be spent, amount0Min The minimum amount of token0 to spend, which serves as a slippage check, amount1Min The minimum amount of token1 to spend, which serves as a slippage check, deadline The time by which the transaction must be included to effect the change | diff --git a/docs/Contracts/Periphery/SwapRouter.md b/docs/Contracts/Periphery/SwapRouter.md index 2a358a428..3f32086f7 100644 --- a/docs/Contracts/Periphery/SwapRouter.md +++ b/docs/Contracts/Periphery/SwapRouter.md @@ -3,7 +3,7 @@ # SwapRouter -Algebra Swap Router +Algebra Integral 1.2.2 Swap Router Router for stateless execution of swaps against Algebra @@ -64,7 +64,7 @@ amount0Delta and amount1Delta can both be 0 if no tokens were swapped.* ```solidity function exactInputSingle(struct ISwapRouter.ExactInputSingleParams params) external payable returns (uint256 amountOut) ``` -**Selector**: `0xbc651188` +**Selector**: `0x1679c792` Swaps `amountIn` of one token for as much as possible of another token @@ -102,7 +102,7 @@ Swaps `amountIn` of one token for as much as possible of another along ```solidity function exactInputSingleSupportingFeeOnTransferTokens(struct ISwapRouter.ExactInputSingleParams params) external payable returns (uint256 amountOut) ``` -**Selector**: `0xb87d2524` +**Selector**: `0x6eb38adc` Swaps `amountIn` of one token for as much as possible of another along the specified path @@ -123,10 +123,12 @@ Swaps `amountIn` of one token for as much as possible of another along ```solidity function exactOutputSingle(struct ISwapRouter.ExactOutputSingleParams params) external payable returns (uint256 amountIn) ``` -**Selector**: `0x61d4d5b3` +**Selector**: `0x1764babc` Swaps as little as possible of one token for `amountOut` of another token +*Developer note: If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* + | Name | Type | Description | | ---- | ---- | ----------- | | params | struct ISwapRouter.ExactOutputSingleParams | The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata | @@ -146,6 +148,8 @@ function exactOutput(struct ISwapRouter.ExactOutputParams params) external payab Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) +*Developer note: If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* + | Name | Type | Description | | ---- | ---- | ----------- | | params | struct ISwapRouter.ExactOutputParams | The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata | diff --git a/docs/Contracts/Periphery/V3Migrator.md b/docs/Contracts/Periphery/V3Migrator.md index f64522d2a..f9894bbc6 100644 --- a/docs/Contracts/Periphery/V3Migrator.md +++ b/docs/Contracts/Periphery/V3Migrator.md @@ -52,7 +52,7 @@ receive() external payable ```solidity function migrate(struct IV3Migrator.MigrateParams params) external ``` -**Selector**: `0x8be74fb6` +**Selector**: `0xad40d131` Migrates liquidity to Algebra by burning v2 liquidity and minting a new position for Algebra diff --git a/docs/Contracts/Periphery/base/LiquidityManagement.md b/docs/Contracts/Periphery/base/LiquidityManagement.md index 01c640d94..1f9d167bb 100644 --- a/docs/Contracts/Periphery/base/LiquidityManagement.md +++ b/docs/Contracts/Periphery/base/LiquidityManagement.md @@ -32,6 +32,7 @@ struct MintCallbackData { struct AddLiquidityParams { address token0; address token1; + address deployer; address recipient; int24 tickLower; int24 tickUpper; diff --git a/docs/Contracts/Periphery/base/PoolInitializer.md b/docs/Contracts/Periphery/base/PoolInitializer.md index 16a96d29c..84b605f7c 100644 --- a/docs/Contracts/Periphery/base/PoolInitializer.md +++ b/docs/Contracts/Periphery/base/PoolInitializer.md @@ -16,9 +16,9 @@ https://github.com/Uniswap/v3-periphery* ### createAndInitializePoolIfNecessary ```solidity -function createAndInitializePoolIfNecessary(address token0, address token1, uint160 sqrtPriceX96) external payable returns (address pool) +function createAndInitializePoolIfNecessary(address token0, address token1, address deployer, uint160 sqrtPriceX96, bytes data) external payable returns (address pool) ``` -**Selector**: `0x51246d6e` +**Selector**: `0x72426eb1` Creates a new pool if it does not exist, then initializes if not initialized @@ -28,7 +28,9 @@ Creates a new pool if it does not exist, then initializes if not initialized | ---- | ---- | ----------- | | token0 | address | The contract address of token0 of the pool | | token1 | address | The contract address of token1 of the pool | +| deployer | address | | | sqrtPriceX96 | uint160 | The initial square root price of the pool as a Q64.96 value | +| data | bytes | Data for plugin initialization | **Returns:** diff --git a/docs/Contracts/Periphery/interfaces/IAlgebraCustomPoolEntryPoint.md b/docs/Contracts/Periphery/interfaces/IAlgebraCustomPoolEntryPoint.md new file mode 100644 index 000000000..278c3d25b --- /dev/null +++ b/docs/Contracts/Periphery/interfaces/IAlgebraCustomPoolEntryPoint.md @@ -0,0 +1,117 @@ + + +# IAlgebraCustomPoolEntryPoint + + +An interface for a contract that is used to deploy and manage Algebra Integral custom pools + + + +*Developer note: This contract should be called by every custom pool deployer to create new custom pools or manage existing ones.* + +**Inherits:** [IAlgebraPluginFactory](../../Core/interfaces/plugin/IAlgebraPluginFactory.md) + +## Functions +### factory + +```solidity +function factory() external view returns (address factory) +``` +**Selector**: `0xc45a0155` + +Returns the address of corresponding AlgebraFactory contract + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| factory | address | The address of AlgebraFactory | + +### createCustomPool + +```solidity +function createCustomPool(address deployer, address creator, address tokenA, address tokenB, bytes data) external returns (address customPool) +``` +**Selector**: `0xdbbf3db4` + +Using for custom pools creation + +| Name | Type | Description | +| ---- | ---- | ----------- | +| deployer | address | The address of plugin deployer, also used for custom pool address calculation | +| creator | address | The initiator of custom pool creation | +| tokenA | address | One of the two tokens in the desired pool | +| tokenB | address | The other of the two tokens in the desired pool | +| data | bytes | The additional data bytes | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | | + +### setTickSpacing + +```solidity +function setTickSpacing(address pool, int24 newTickSpacing) external +``` +**Selector**: `0x4bf092cd` + +Changes the tick spacing value in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newTickSpacing | int24 | The new tick spacing value | + +### setPlugin + +```solidity +function setPlugin(address pool, address newPluginAddress) external +``` +**Selector**: `0xf9f4c09a` + +Changes the plugin address in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newPluginAddress | address | The new plugin address | + +### setPluginConfig + +```solidity +function setPluginConfig(address pool, uint8 newConfig) external +``` +**Selector**: `0x054bee3d` + +Changes the plugin configuration in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newConfig | uint8 | The new plugin configuration bitmap | + +### setFee + +```solidity +function setFee(address pool, uint16 newFee) external +``` +**Selector**: `0x337f3a31` + +Changes the fee value in the Algebra Integral custom pool + +*Developer note: Only corresponding custom pool deployer contract can call this function. +Fee can be changed manually only if pool does not have "dynamic fee" configuration* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the Algebra Integral custom pool | +| newFee | uint16 | The new fee value | + diff --git a/docs/Contracts/Periphery/interfaces/INonfungiblePositionManager.md b/docs/Contracts/Periphery/interfaces/INonfungiblePositionManager.md index 3c1cbcb27..241bcb7d5 100644 --- a/docs/Contracts/Periphery/interfaces/INonfungiblePositionManager.md +++ b/docs/Contracts/Periphery/interfaces/INonfungiblePositionManager.md @@ -79,18 +79,6 @@ Emitted if farming failed in call from NonfungiblePositionManager. | ---- | ---- | ----------- | | tokenId | uint256 | The ID of corresponding token | -### FarmingCenter - -```solidity -event FarmingCenter(address farmingCenterAddress) -``` - -Emitted after farming center address change - -| Name | Type | Description | -| ---- | ---- | ----------- | -| farmingCenterAddress | address | The new address of connected farming center | - ## Structs ### MintParams @@ -101,6 +89,7 @@ Emitted after farming center address change struct MintParams { address token0; address token1; + address deployer; int24 tickLower; int24 tickUpper; uint256 amount0Desired; @@ -159,7 +148,7 @@ struct CollectParams { ### positions ```solidity -function positions(uint256 tokenId) external view returns (uint88 nonce, address operator, address token0, address token1, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1) +function positions(uint256 tokenId) external view returns (uint88 nonce, address operator, address token0, address token1, address deployer, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1) ``` **Selector**: `0x99fbab88` @@ -179,6 +168,7 @@ Returns the position information associated with a given token ID. | operator | address | The address that is approved for spending | | token0 | address | The address of the token0 for a specific pool | | token1 | address | The address of the token1 for a specific pool | +| deployer | address | The address of the custom pool deployer | | tickLower | int24 | The lower end of the tick range for the position | | tickUpper | int24 | The higher end of the tick range for the position | | liquidity | uint128 | The liquidity of the position | @@ -192,12 +182,13 @@ Returns the position information associated with a given token ID. ```solidity function mint(struct INonfungiblePositionManager.MintParams params) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) ``` -**Selector**: `0x9cc1a283` +**Selector**: `0xfe3f3be7` Creates a new position wrapped in a NFT *Developer note: Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized -a method does not exist, i.e. the pool is assumed to be initialized.* +a method does not exist, i.e. the pool is assumed to be initialized. +If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* | Name | Type | Description | | ---- | ---- | ----------- | @@ -221,6 +212,8 @@ function increaseLiquidity(struct INonfungiblePositionManager.IncreaseLiquidityP Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` +*Developer note: If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* + | Name | Type | Description | | ---- | ---- | ----------- | | params | struct INonfungiblePositionManager.IncreaseLiquidityParams | tokenId The ID of the token for which liquidity is being increased, amount0Desired The desired amount of token0 to be spent, amount1Desired The desired amount of token1 to be spent, amount0Min The minimum amount of token0 to spend, which serves as a slippage check, amount1Min The minimum amount of token1 to spend, which serves as a slippage check, deadline The time by which the transaction must be included to effect the change | diff --git a/docs/Contracts/Periphery/interfaces/IPoolInitializer.md b/docs/Contracts/Periphery/interfaces/IPoolInitializer.md index 1bc7bd2c1..a2369240d 100644 --- a/docs/Contracts/Periphery/interfaces/IPoolInitializer.md +++ b/docs/Contracts/Periphery/interfaces/IPoolInitializer.md @@ -16,9 +16,9 @@ https://github.com/Uniswap/v3-periphery* ### createAndInitializePoolIfNecessary ```solidity -function createAndInitializePoolIfNecessary(address token0, address token1, uint160 sqrtPriceX96) external payable returns (address pool) +function createAndInitializePoolIfNecessary(address token0, address token1, address deployer, uint160 sqrtPriceX96, bytes data) external payable returns (address pool) ``` -**Selector**: `0x51246d6e` +**Selector**: `0x72426eb1` Creates a new pool if it does not exist, then initializes if not initialized @@ -28,7 +28,9 @@ Creates a new pool if it does not exist, then initializes if not initialized | ---- | ---- | ----------- | | token0 | address | The contract address of token0 of the pool | | token1 | address | The contract address of token1 of the pool | +| deployer | address | | | sqrtPriceX96 | uint160 | The initial square root price of the pool as a Q64.96 value | +| data | bytes | Data for plugin initialization | **Returns:** diff --git a/docs/Contracts/Periphery/interfaces/IQuoter.md b/docs/Contracts/Periphery/interfaces/IQuoter.md index a57b12f7b..c9ba1baaf 100644 --- a/docs/Contracts/Periphery/interfaces/IQuoter.md +++ b/docs/Contracts/Periphery/interfaces/IQuoter.md @@ -38,9 +38,9 @@ Returns the amount out received for a given exact input swap without executing t ### quoteExactInputSingle ```solidity -function quoteExactInputSingle(address tokenIn, address tokenOut, uint256 amountIn, uint160 limitSqrtPrice) external returns (uint256 amountOut, uint16 fee) +function quoteExactInputSingle(address tokenIn, address tokenOut, address deployer, uint256 amountIn, uint160 limitSqrtPrice) external returns (uint256 amountOut, uint16 fee) ``` -**Selector**: `0x2d9ebd1d` +**Selector**: `0x57028211` Returns the amount out received for a given exact input but for a swap of a single pool @@ -48,6 +48,7 @@ Returns the amount out received for a given exact input but for a swap of a sing | ---- | ---- | ----------- | | tokenIn | address | The token being swapped in | | tokenOut | address | The token being swapped out | +| deployer | address | | | amountIn | uint256 | The desired input amount | | limitSqrtPrice | uint160 | The price limit of the pool that cannot be exceeded by the swap | @@ -82,9 +83,9 @@ Returns the amount in required for a given exact output swap without executing t ### quoteExactOutputSingle ```solidity -function quoteExactOutputSingle(address tokenIn, address tokenOut, uint256 amountOut, uint160 limitSqrtPrice) external returns (uint256 amountIn, uint16 fee) +function quoteExactOutputSingle(address tokenIn, address tokenOut, address deployer, uint256 amountOut, uint160 limitSqrtPrice) external returns (uint256 amountIn, uint16 fee) ``` -**Selector**: `0x9e73c81d` +**Selector**: `0x719c8b31` Returns the amount in required to receive the given exact output amount but for a swap of a single pool @@ -92,6 +93,7 @@ Returns the amount in required to receive the given exact output amount but for | ---- | ---- | ----------- | | tokenIn | address | The token being swapped in | | tokenOut | address | The token being swapped out | +| deployer | address | | | amountOut | uint256 | The desired output amount | | limitSqrtPrice | uint160 | The price limit of the pool that cannot be exceeded by the swap | diff --git a/docs/Contracts/Periphery/interfaces/IQuoterV2.md b/docs/Contracts/Periphery/interfaces/IQuoterV2.md index 03c7d27b1..80df1ec8c 100644 --- a/docs/Contracts/Periphery/interfaces/IQuoterV2.md +++ b/docs/Contracts/Periphery/interfaces/IQuoterV2.md @@ -23,6 +23,7 @@ https://github.com/Uniswap/v3-periphery* struct QuoteExactInputSingleParams { address tokenIn; address tokenOut; + address deployer; uint256 amountIn; uint160 limitSqrtPrice; } @@ -36,6 +37,7 @@ struct QuoteExactInputSingleParams { struct QuoteExactOutputSingleParams { address tokenIn; address tokenOut; + address deployer; uint256 amount; uint160 limitSqrtPrice; } @@ -46,7 +48,7 @@ struct QuoteExactOutputSingleParams { ### quoteExactInput ```solidity -function quoteExactInput(bytes path, uint256 amountInRequired) external returns (uint256 amountOut, uint256 amountIn, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) +function quoteExactInput(bytes path, uint256 amountInRequired) external returns (uint256[] amountOutList, uint256[] amountInList, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) ``` **Selector**: `0xcdca1753` @@ -61,8 +63,8 @@ Returns the amount out received for a given exact input swap without executing t | Name | Type | Description | | ---- | ---- | ----------- | -| amountOut | uint256 | The amount of the last token that would be received | -| amountIn | uint256 | The amount of the last token that should be paid | +| amountOutList | uint256[] | The amount of the last token that would be received | +| amountInList | uint256[] | The amount of the last token that should be paid | | sqrtPriceX96AfterList | uint160[] | List of the sqrt price after the swap for each pool in the path | | initializedTicksCrossedList | uint32[] | List of the initialized ticks that the swap crossed for each pool in the path | | gasEstimate | uint256 | The estimate of the gas that the swap consumes | @@ -73,7 +75,7 @@ Returns the amount out received for a given exact input swap without executing t ```solidity function quoteExactInputSingle(struct IQuoterV2.QuoteExactInputSingleParams params) external returns (uint256 amountOut, uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate, uint16 fee) ``` -**Selector**: `0x5e5e6e0f` +**Selector**: `0xe94764c4` Returns the amount out received for a given exact input but for a swap of a single pool @@ -95,7 +97,7 @@ Returns the amount out received for a given exact input but for a swap of a sing ### quoteExactOutput ```solidity -function quoteExactOutput(bytes path, uint256 amountOutRequired) external returns (uint256 amountOut, uint256 amountIn, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) +function quoteExactOutput(bytes path, uint256 amountOutRequired) external returns (uint256[] amountOutList, uint256[] amountInList, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) ``` **Selector**: `0x2f80bb1d` @@ -110,8 +112,8 @@ Returns the amount in required for a given exact output swap without executing t | Name | Type | Description | | ---- | ---- | ----------- | -| amountOut | uint256 | The amount of the last token that would be received | -| amountIn | uint256 | The amount of first token required to be paid | +| amountOutList | uint256[] | The amount of the last token that would be received | +| amountInList | uint256[] | The amount of first token required to be paid | | sqrtPriceX96AfterList | uint160[] | List of the sqrt price after the swap for each pool in the path | | initializedTicksCrossedList | uint32[] | List of the initialized ticks that the swap crossed for each pool in the path | | gasEstimate | uint256 | The estimate of the gas that the swap consumes | @@ -122,7 +124,7 @@ Returns the amount in required for a given exact output swap without executing t ```solidity function quoteExactOutputSingle(struct IQuoterV2.QuoteExactOutputSingleParams params) external returns (uint256 amountOut, uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate, uint16 fee) ``` -**Selector**: `0x5877c9b9` +**Selector**: `0x62086e24` Returns the amount in required to receive the given exact output amount but for a swap of a single pool diff --git a/docs/Contracts/Periphery/interfaces/ISwapRouter.md b/docs/Contracts/Periphery/interfaces/ISwapRouter.md index 4e16b558b..6db194b6c 100644 --- a/docs/Contracts/Periphery/interfaces/ISwapRouter.md +++ b/docs/Contracts/Periphery/interfaces/ISwapRouter.md @@ -21,6 +21,7 @@ https://github.com/Uniswap/v3-periphery* struct ExactInputSingleParams { address tokenIn; address tokenOut; + address deployer; address recipient; uint256 deadline; uint256 amountIn; @@ -51,6 +52,7 @@ struct ExactInputParams { struct ExactOutputSingleParams { address tokenIn; address tokenOut; + address deployer; address recipient; uint256 deadline; uint256 amountOut; @@ -80,7 +82,7 @@ struct ExactOutputParams { ```solidity function exactInputSingle(struct ISwapRouter.ExactInputSingleParams params) external payable returns (uint256 amountOut) ``` -**Selector**: `0xbc651188` +**Selector**: `0x1679c792` Swaps `amountIn` of one token for as much as possible of another token @@ -118,10 +120,12 @@ Swaps `amountIn` of one token for as much as possible of another along ```solidity function exactOutputSingle(struct ISwapRouter.ExactOutputSingleParams params) external payable returns (uint256 amountIn) ``` -**Selector**: `0x61d4d5b3` +**Selector**: `0x1764babc` Swaps as little as possible of one token for `amountOut` of another token +*Developer note: If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* + | Name | Type | Description | | ---- | ---- | ----------- | | params | struct ISwapRouter.ExactOutputSingleParams | The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata | @@ -141,6 +145,8 @@ function exactOutput(struct ISwapRouter.ExactOutputParams params) external payab Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) +*Developer note: If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens* + | Name | Type | Description | | ---- | ---- | ----------- | | params | struct ISwapRouter.ExactOutputParams | The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata | @@ -156,7 +162,7 @@ Swaps as little as possible of one token for `amountOut` of another al ```solidity function exactInputSingleSupportingFeeOnTransferTokens(struct ISwapRouter.ExactInputSingleParams params) external payable returns (uint256 amountOut) ``` -**Selector**: `0xb87d2524` +**Selector**: `0x6eb38adc` Swaps `amountIn` of one token for as much as possible of another along the specified path diff --git a/docs/Contracts/Periphery/interfaces/IV3Migrator.md b/docs/Contracts/Periphery/interfaces/IV3Migrator.md index 94c96df3a..b76f658a1 100644 --- a/docs/Contracts/Periphery/interfaces/IV3Migrator.md +++ b/docs/Contracts/Periphery/interfaces/IV3Migrator.md @@ -24,6 +24,7 @@ struct MigrateParams { uint8 percentageToMigrate; address token0; address token1; + address deployer; int24 tickLower; int24 tickUpper; uint256 amount0Min; @@ -41,7 +42,7 @@ struct MigrateParams { ```solidity function migrate(struct IV3Migrator.MigrateParams params) external ``` -**Selector**: `0x8be74fb6` +**Selector**: `0xad40d131` Migrates liquidity to Algebra by burning v2 liquidity and minting a new position for Algebra diff --git a/docs/Contracts/Periphery/lens/AlgebraInterfaceMulticall.md b/docs/Contracts/Periphery/lens/AlgebraInterfaceMulticall.md index 79f7378be..e22c27940 100644 --- a/docs/Contracts/Periphery/lens/AlgebraInterfaceMulticall.md +++ b/docs/Contracts/Periphery/lens/AlgebraInterfaceMulticall.md @@ -72,6 +72,36 @@ function getEthBalance(address addr) public view returns (uint256 balance) | ---- | ---- | ----------- | | balance | uint256 | | +### gaslimit + +```solidity +function gaslimit() external view returns (uint256) +``` +**Selector**: `0x2a722839` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint256 | | + +### gasLeft + +```solidity +function gasLeft() external view returns (uint256) +``` +**Selector**: `0x2ddb301b` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint256 | | + ### multicall ```solidity @@ -92,3 +122,25 @@ function multicall(struct AlgebraInterfaceMulticall.Call[] calls) public returns | blockNumber | uint256 | | | returnData | struct AlgebraInterfaceMulticall.Result[] | | +### multicallWithGasLimitation + +```solidity +function multicallWithGasLimitation(struct AlgebraInterfaceMulticall.Call[] calls, uint256 gasBuffer) public returns (uint256 blockNumber, struct AlgebraInterfaceMulticall.Result[] returnData, uint256 lastSuccessIndex) +``` +**Selector**: `0xd8f95843` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| calls | struct AlgebraInterfaceMulticall.Call[] | | +| gasBuffer | uint256 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| blockNumber | uint256 | | +| returnData | struct AlgebraInterfaceMulticall.Result[] | | +| lastSuccessIndex | uint256 | | + diff --git a/docs/Contracts/Periphery/lens/Quoter.md b/docs/Contracts/Periphery/lens/Quoter.md index c3392c418..5b8e0298e 100644 --- a/docs/Contracts/Periphery/lens/Quoter.md +++ b/docs/Contracts/Periphery/lens/Quoter.md @@ -3,7 +3,7 @@ # Quoter -Provides quotes for swaps +Algebra Integral 1.2.2 Quoter Allows getting the expected amount out or amount in for a given swap without executing the swap @@ -51,9 +51,9 @@ amount0Delta and amount1Delta can both be 0 if no tokens were swapped.* ### quoteExactInputSingle ```solidity -function quoteExactInputSingle(address tokenIn, address tokenOut, uint256 amountIn, uint160 limitSqrtPrice) public returns (uint256 amountOut, uint16 fee) +function quoteExactInputSingle(address tokenIn, address tokenOut, address deployer, uint256 amountIn, uint160 limitSqrtPrice) public returns (uint256 amountOut, uint16 fee) ``` -**Selector**: `0x2d9ebd1d` +**Selector**: `0x57028211` Returns the amount out received for a given exact input but for a swap of a single pool @@ -61,6 +61,7 @@ Returns the amount out received for a given exact input but for a swap of a sing | ---- | ---- | ----------- | | tokenIn | address | The token being swapped in | | tokenOut | address | The token being swapped out | +| deployer | address | | | amountIn | uint256 | The desired input amount | | limitSqrtPrice | uint160 | The price limit of the pool that cannot be exceeded by the swap | @@ -95,9 +96,9 @@ Returns the amount out received for a given exact input swap without executing t ### quoteExactOutputSingle ```solidity -function quoteExactOutputSingle(address tokenIn, address tokenOut, uint256 amountOut, uint160 limitSqrtPrice) public returns (uint256 amountIn, uint16 fee) +function quoteExactOutputSingle(address tokenIn, address tokenOut, address deployer, uint256 amountOut, uint160 limitSqrtPrice) public returns (uint256 amountIn, uint16 fee) ``` -**Selector**: `0x9e73c81d` +**Selector**: `0x719c8b31` Returns the amount in required to receive the given exact output amount but for a swap of a single pool @@ -105,6 +106,7 @@ Returns the amount in required to receive the given exact output amount but for | ---- | ---- | ----------- | | tokenIn | address | The token being swapped in | | tokenOut | address | The token being swapped out | +| deployer | address | | | amountOut | uint256 | The desired output amount | | limitSqrtPrice | uint160 | The price limit of the pool that cannot be exceeded by the swap | diff --git a/docs/Contracts/Periphery/lens/QuoterV2.md b/docs/Contracts/Periphery/lens/QuoterV2.md index de60a7c5a..ca010c3fe 100644 --- a/docs/Contracts/Periphery/lens/QuoterV2.md +++ b/docs/Contracts/Periphery/lens/QuoterV2.md @@ -3,7 +3,7 @@ # QuoterV2 -Provides quotes for swaps +Algebra Integral 1.2.2 QuoterV2 Allows getting the expected amount out or amount in for a given swap without executing the swap @@ -53,7 +53,7 @@ amount0Delta and amount1Delta can both be 0 if no tokens were swapped.* ```solidity function quoteExactInputSingle(struct IQuoterV2.QuoteExactInputSingleParams params) public returns (uint256 amountOut, uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate, uint16 fee) ``` -**Selector**: `0x5e5e6e0f` +**Selector**: `0xe94764c4` Returns the amount out received for a given exact input but for a swap of a single pool @@ -75,7 +75,7 @@ Returns the amount out received for a given exact input but for a swap of a sing ### quoteExactInput ```solidity -function quoteExactInput(bytes path, uint256 amountInRequired) public returns (uint256 amountOut, uint256 amountIn, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) +function quoteExactInput(bytes path, uint256 amountInRequired) public returns (uint256[] amountOutList, uint256[] amountInList, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) ``` **Selector**: `0xcdca1753` @@ -90,8 +90,8 @@ Returns the amount out received for a given exact input swap without executing t | Name | Type | Description | | ---- | ---- | ----------- | -| amountOut | uint256 | The amount of the last token that would be received | -| amountIn | uint256 | The amount of the last token that should be paid | +| amountOutList | uint256[] | The amount of the last token that would be received | +| amountInList | uint256[] | The amount of the last token that should be paid | | sqrtPriceX96AfterList | uint160[] | List of the sqrt price after the swap for each pool in the path | | initializedTicksCrossedList | uint32[] | List of the initialized ticks that the swap crossed for each pool in the path | | gasEstimate | uint256 | The estimate of the gas that the swap consumes | @@ -102,7 +102,7 @@ Returns the amount out received for a given exact input swap without executing t ```solidity function quoteExactOutputSingle(struct IQuoterV2.QuoteExactOutputSingleParams params) public returns (uint256 amountOut, uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate, uint16 fee) ``` -**Selector**: `0x5877c9b9` +**Selector**: `0x62086e24` Returns the amount in required to receive the given exact output amount but for a swap of a single pool @@ -124,7 +124,7 @@ Returns the amount in required to receive the given exact output amount but for ### quoteExactOutput ```solidity -function quoteExactOutput(bytes path, uint256 amountOutRequired) public returns (uint256 amountOut, uint256 amountIn, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) +function quoteExactOutput(bytes path, uint256 amountOutRequired) public returns (uint256[] amountOutList, uint256[] amountInList, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate, uint16[] feeList) ``` **Selector**: `0x2f80bb1d` @@ -139,8 +139,8 @@ Returns the amount in required for a given exact output swap without executing t | Name | Type | Description | | ---- | ---- | ----------- | -| amountOut | uint256 | The amount of the last token that would be received | -| amountIn | uint256 | The amount of first token required to be paid | +| amountOutList | uint256[] | The amount of the last token that would be received | +| amountInList | uint256[] | The amount of first token required to be paid | | sqrtPriceX96AfterList | uint160[] | List of the sqrt price after the swap for each pool in the path | | initializedTicksCrossedList | uint32[] | List of the initialized ticks that the swap crossed for each pool in the path | | gasEstimate | uint256 | The estimate of the gas that the swap consumes | diff --git a/docs/Contracts/Periphery/lens/TickLens.md b/docs/Contracts/Periphery/lens/TickLens.md index 76c3e8933..713e53b18 100644 --- a/docs/Contracts/Periphery/lens/TickLens.md +++ b/docs/Contracts/Periphery/lens/TickLens.md @@ -3,7 +3,7 @@ # TickLens -Tick Lens contract +Algebra Integral 1.2.2 Tick Lens contract diff --git a/docs/Contracts/Periphery/test/CustomPlugin.md b/docs/Contracts/Periphery/test/CustomPlugin.md new file mode 100644 index 000000000..42861e316 --- /dev/null +++ b/docs/Contracts/Periphery/test/CustomPlugin.md @@ -0,0 +1,262 @@ + + +# CustomPlugin + + + + + + +**Inherits:** Timestamp [IAlgebraPlugin](../../Core/interfaces/plugin/IAlgebraPlugin.md) + +## Public variables +### pool +```solidity +address pool +``` +**Selector**: `0x16f0115b` + + + + +### ALGEBRA_BASE_PLUGIN_MANAGER +```solidity +bytes32 constant ALGEBRA_BASE_PLUGIN_MANAGER = 0x8e8000aba5b365c0be9685da1153f7f096e76d1ecfb42c050ae1e387aa65b4f5 +``` +**Selector**: `0x31b25d1a` + + + + +### defaultPluginConfig +```solidity +uint8 constant defaultPluginConfig +``` +**Selector**: `0x689ea370` + +Returns plugin config + + + +## Functions +### beforeInitialize + +```solidity +function beforeInitialize(address, uint160) external returns (bytes4) +``` +**Selector**: `0x636fd804` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterInitialize + +```solidity +function afterInitialize(address, uint160, int24) external returns (bytes4) +``` +**Selector**: `0x82dd6522` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | +| | int24 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeModifyPosition + +```solidity +function beforeModifyPosition(address, address, int24, int24, int128, bytes) external returns (bytes4, uint24) +``` +**Selector**: `0x5e2411b2` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | + +### afterModifyPosition + +```solidity +function afterModifyPosition(address, address, int24, int24, int128, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0xd6852010` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeSwap + +```solidity +function beforeSwap(address, address, bool, int256, uint160, bool, bytes) external returns (bytes4, uint24, uint24) +``` +**Selector**: `0x029c1cb7` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | bool | | +| | int256 | | +| | uint160 | | +| | bool | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | +| [2] | uint24 | | + +### afterSwap + +```solidity +function afterSwap(address, address, bool, int256, uint160, int256, int256, bytes) external returns (bytes4) +``` +**Selector**: `0x9cb5a963` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | bool | | +| | int256 | | +| | uint160 | | +| | int256 | | +| | int256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### handlePluginFee + +```solidity +function handlePluginFee(uint256, uint256) external pure returns (bytes4) +``` +**Selector**: `0xaa6b14bb` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | uint256 | | +| | uint256 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeFlash + +```solidity +function beforeFlash(address, address, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x8de0a8ee` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterFlash + +```solidity +function afterFlash(address, address, uint256, uint256, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x343d37ff` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + diff --git a/docs/Contracts/Plugin/AlgebraBasePluginV1.md b/docs/Contracts/Plugin/AlgebraBasePluginV1.md index 4fad59140..c0ab77aba 100644 --- a/docs/Contracts/Plugin/AlgebraBasePluginV1.md +++ b/docs/Contracts/Plugin/AlgebraBasePluginV1.md @@ -3,32 +3,13 @@ # AlgebraBasePluginV1 -Algebra default plugin - -This contract stores timepoints and calculates adaptive fee and statistical averages - -**Inherits:** [IAlgebraBasePluginV1](interfaces/IAlgebraBasePluginV1.md) Timestamp [IAlgebraPlugin](../Core/interfaces/plugin/IAlgebraPlugin.md) -## Modifiers -### onlyPool - -```solidity -modifier onlyPool() -``` +Algebra Integral 1.2.2 adaptive fee plugin +**Inherits:** [DynamicFeePlugin](plugins/DynamicFeePlugin.md) [FarmingProxyPlugin](plugins/FarmingProxyPlugin.md) [VolatilityOraclePlugin](plugins/VolatilityOraclePlugin.md) ## Public variables -### ALGEBRA_BASE_PLUGIN_MANAGER -```solidity -bytes32 constant ALGEBRA_BASE_PLUGIN_MANAGER = 0x8e8000aba5b365c0be9685da1153f7f096e76d1ecfb42c050ae1e387aa65b4f5 -``` -**Selector**: `0x31b25d1a` - - - -*Developer note: The role can be granted in AlgebraFactory* - ### defaultPluginConfig ```solidity uint8 constant defaultPluginConfig @@ -38,68 +19,12 @@ uint8 constant defaultPluginConfig Returns plugin config -### pool -```solidity -address immutable pool -``` -**Selector**: `0x16f0115b` - -Returns the address of the pool the plugin is created for - - -### timepoints -```solidity -struct VolatilityOracle.Timepoint[65536] timepoints -``` -**Selector**: `0x74eceae6` - -Returns data belonging to a certain timepoint - -*Developer note: There is more convenient function to fetch a timepoint: getTimepoints(). Which requires not an index but seconds* - -### timepointIndex -```solidity -uint16 timepointIndex -``` -**Selector**: `0x0786feb6` - -Returns the index of the last timepoint that was written. - - -### lastTimepointTimestamp -```solidity -uint32 lastTimepointTimestamp -``` -**Selector**: `0xf5985d35` - -Returns the timestamp of the last timepoint that was written. - - -### isInitialized -```solidity -bool isInitialized -``` -**Selector**: `0x392e53cd` - -Returns information about whether oracle is initialized - - -### incentive -```solidity -address incentive -``` -**Selector**: `0x1d4632ac` - -Returns the address of active incentive - -*Developer note: if there is no active incentive at the moment, incentiveAddress would be equal to address(0)* - ## Functions ### constructor ```solidity -constructor(address _pool, address _factory, address _pluginFactory) public +constructor(address _pool, address _factory, address _pluginFactory, struct AlgebraFeeConfiguration _config) public ``` @@ -109,172 +34,8 @@ constructor(address _pool, address _factory, address _pluginFactory) public | _pool | address | | | _factory | address | | | _pluginFactory | address | | - -### feeConfig - -```solidity -function feeConfig() external view returns (uint16 alpha1, uint16 alpha2, uint32 beta1, uint32 beta2, uint16 gamma1, uint16 gamma2, uint16 baseFee) -``` -**Selector**: `0x1e5eb1d0` - -Current dynamic fee configuration - -*Developer note: See the AdaptiveFee struct for more details* - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| alpha1 | uint16 | | -| alpha2 | uint16 | | -| beta1 | uint32 | | -| beta2 | uint32 | | -| gamma1 | uint16 | | -| gamma2 | uint16 | | -| baseFee | uint16 | | - -### initialize - -```solidity -function initialize() external -``` -**Selector**: `0x8129fc1c` - -Initialize the plugin externally - -*Developer note: This function allows to initialize the plugin if it was created after the pool was created* - -### getSingleTimepoint - -```solidity -function getSingleTimepoint(uint32 secondsAgo) external view returns (int56 tickCumulative, uint88 volatilityCumulative) -``` -**Selector**: `0x88f2e862` - - - -*Developer note: Reverts if a timepoint at or before the desired timepoint timestamp does not exist. -0 may be passed as `secondsAgo' to return the current cumulative values. -If called with a timestamp falling between two timepoints, returns the counterfactual accumulator values -at exactly the timestamp between the two timepoints. -`volatilityCumulative` values for timestamps after the last timepoint _should not_ be compared because they may differ due to interpolation errors* - -| Name | Type | Description | -| ---- | ---- | ----------- | -| secondsAgo | uint32 | The amount of time to look back, in seconds, at which point to return a timepoint | - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| tickCumulative | int56 | The cumulative tick since the pool was first initialized, as of `secondsAgo` | -| volatilityCumulative | uint88 | The cumulative volatility value since the pool was first initialized, as of `secondsAgo` | - -### getTimepoints - -```solidity -function getTimepoints(uint32[] secondsAgos) external view returns (int56[] tickCumulatives, uint88[] volatilityCumulatives) -``` -**Selector**: `0x9d3a5241` - -Returns the accumulator values as of each time seconds ago from the given time in the array of `secondsAgos` - -*Developer note: Reverts if `secondsAgos` > oldest timepoint -`volatilityCumulative` values for timestamps after the last timepoint _should not_ be compared because they may differ due to interpolation errors* - -| Name | Type | Description | -| ---- | ---- | ----------- | -| secondsAgos | uint32[] | Each amount of time to look back, in seconds, at which point to return a timepoint | - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| tickCumulatives | int56[] | The cumulative tick since the pool was first initialized, as of each `secondsAgo` | -| volatilityCumulatives | uint88[] | The cumulative volatility values since the pool was first initialized, as of each `secondsAgo` | - -### prepayTimepointsStorageSlots - -```solidity -function prepayTimepointsStorageSlots(uint16 startIndex, uint16 amount) external -``` -**Selector**: `0xda705235` - -Fills uninitialized timepoints with nonzero value - -*Developer note: Can be used to reduce the gas cost of future swaps* - -| Name | Type | Description | -| ---- | ---- | ----------- | -| startIndex | uint16 | The start index, must be not initialized | -| amount | uint16 | of slots to fill, startIndex + amount must be <= type(uint16).max | - -### changeFeeConfiguration - -```solidity -function changeFeeConfiguration(struct AlgebraFeeConfiguration _config) external -``` -**Selector**: `0x1d39215e` - -Changes fee configuration for the pool - -| Name | Type | Description | -| ---- | ---- | ----------- | | _config | struct AlgebraFeeConfiguration | | -### getCurrentFee - -```solidity -function getCurrentFee() external view returns (uint16 fee) -``` -**Selector**: `0xf70d9362` - -Returns fee from plugin - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| fee | uint16 | The pool fee value in hundredths of a bip, i.e. 1e-6 | - -### setIncentive - -```solidity -function setIncentive(address newIncentive) external -``` -**Selector**: `0x7c1fe0c8` - -Connects or disconnects an incentive. - -*Developer note: Only farming can connect incentives. -The one who connected it and the current farming has the right to disconnect the incentive.* - -| Name | Type | Description | -| ---- | ---- | ----------- | -| newIncentive | address | The address associated with the incentive or zero address | - -### isIncentiveConnected - -```solidity -function isIncentiveConnected(address targetIncentive) external view returns (bool) -``` -**Selector**: `0xe63015f0` - -Checks if the incentive is connected to pool - -*Developer note: Returns false if the plugin has a different incentive set, the plugin is not connected to the pool, -or the plugin configuration is incorrect.* - -| Name | Type | Description | -| ---- | ---- | ----------- | -| targetIncentive | address | The address of the incentive to be checked | - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| [0] | bool | Indicates whether the target incentive is active | - ### beforeInitialize ```solidity @@ -319,7 +80,7 @@ function afterInitialize(address, uint160, int24 tick) external returns (bytes4) ### beforeModifyPosition ```solidity -function beforeModifyPosition(address, address, int24, int24, int128, bytes) external returns (bytes4) +function beforeModifyPosition(address, address, int24, int24, int128, bytes) external returns (bytes4, uint24) ``` **Selector**: `0x5e2411b2` @@ -341,6 +102,7 @@ function beforeModifyPosition(address, address, int24, int24, int128, bytes) ext | Name | Type | Description | | ---- | ---- | ----------- | | [0] | bytes4 | | +| [1] | uint24 | | ### afterModifyPosition @@ -373,7 +135,7 @@ function afterModifyPosition(address, address, int24, int24, int128, uint256, ui ### beforeSwap ```solidity -function beforeSwap(address, address, bool, int256, uint160, bool, bytes) external returns (bytes4) +function beforeSwap(address, address, bool, int256, uint160, bool, bytes) external returns (bytes4, uint24, uint24) ``` **Selector**: `0x029c1cb7` @@ -394,6 +156,8 @@ function beforeSwap(address, address, bool, int256, uint160, bool, bytes) extern | Name | Type | Description | | ---- | ---- | ----------- | | [0] | bytes4 | | +| [1] | uint24 | | +| [2] | uint24 | | ### afterSwap @@ -473,3 +237,18 @@ function afterFlash(address, address, uint256, uint256, uint256, uint256, bytes) | ---- | ---- | ----------- | | [0] | bytes4 | | +### getCurrentFee + +```solidity +function getCurrentFee() external view returns (uint16 fee) +``` +**Selector**: `0xf70d9362` + +Returns fee from plugin + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| fee | uint16 | The pool fee value in hundredths of a bip, i.e. 1e-6 | + diff --git a/docs/Contracts/Plugin/AlgebraBasePluginV2.md b/docs/Contracts/Plugin/AlgebraBasePluginV2.md new file mode 100644 index 000000000..b07498054 --- /dev/null +++ b/docs/Contracts/Plugin/AlgebraBasePluginV2.md @@ -0,0 +1,239 @@ + + +# AlgebraBasePluginV2 + + +Algebra Integral 1.2.2 sliding fee plugin + + + +**Inherits:** [SlidingFeePlugin](plugins/SlidingFeePlugin.md) [FarmingProxyPlugin](plugins/FarmingProxyPlugin.md) [VolatilityOraclePlugin](plugins/VolatilityOraclePlugin.md) + +## Public variables +### defaultPluginConfig +```solidity +uint8 constant defaultPluginConfig +``` +**Selector**: `0x689ea370` + +Returns plugin config + + + +## Functions +### constructor + +```solidity +constructor(address _pool, address _factory, address _pluginFactory, uint16 _baseFee) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _pool | address | | +| _factory | address | | +| _pluginFactory | address | | +| _baseFee | uint16 | | + +### beforeInitialize + +```solidity +function beforeInitialize(address, uint160) external returns (bytes4) +``` +**Selector**: `0x636fd804` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterInitialize + +```solidity +function afterInitialize(address, uint160, int24 tick) external returns (bytes4) +``` +**Selector**: `0x82dd6522` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | +| tick | int24 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeModifyPosition + +```solidity +function beforeModifyPosition(address, address, int24, int24, int128, bytes) external returns (bytes4, uint24) +``` +**Selector**: `0x5e2411b2` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | + +### afterModifyPosition + +```solidity +function afterModifyPosition(address, address, int24, int24, int128, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0xd6852010` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeSwap + +```solidity +function beforeSwap(address, address, bool zeroToOne, int256, uint160, bool, bytes) external returns (bytes4, uint24, uint24) +``` +**Selector**: `0x029c1cb7` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| zeroToOne | bool | | +| | int256 | | +| | uint160 | | +| | bool | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | +| [2] | uint24 | | + +### afterSwap + +```solidity +function afterSwap(address, address, bool zeroToOne, int256, uint160, int256, int256, bytes) external returns (bytes4) +``` +**Selector**: `0x9cb5a963` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| zeroToOne | bool | | +| | int256 | | +| | uint160 | | +| | int256 | | +| | int256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeFlash + +```solidity +function beforeFlash(address, address, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x8de0a8ee` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterFlash + +```solidity +function afterFlash(address, address, uint256, uint256, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x343d37ff` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + diff --git a/docs/Contracts/Plugin/AlgebraSecurityPlugin.md b/docs/Contracts/Plugin/AlgebraSecurityPlugin.md new file mode 100644 index 000000000..e48085424 --- /dev/null +++ b/docs/Contracts/Plugin/AlgebraSecurityPlugin.md @@ -0,0 +1,240 @@ + + +# AlgebraSecurityPlugin + + +Algebra Integral 1.2.1 security plugin + + + +**Inherits:** [SecurityPlugin](plugins/SecurityPlugin.md) + +## Public variables +### defaultPluginConfig +```solidity +uint8 constant defaultPluginConfig +``` +**Selector**: `0x689ea370` + +Returns plugin config + + + +## Functions +### constructor + +```solidity +constructor(address _pool, address _factory, address _pluginFactory) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _pool | address | | +| _factory | address | | +| _pluginFactory | address | | + +### beforeInitialize + +```solidity +function beforeInitialize(address, uint160) external returns (bytes4) +``` +**Selector**: `0x636fd804` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterInitialize + +```solidity +function afterInitialize(address, uint160, int24) external returns (bytes4) +``` +**Selector**: `0x82dd6522` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | +| | int24 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeModifyPosition + +```solidity +function beforeModifyPosition(address, address, int24, int24, int128 liquidity, bytes) external returns (bytes4, uint24) +``` +**Selector**: `0x5e2411b2` + +@dev + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| liquidity | int128 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | + +### afterModifyPosition + +```solidity +function afterModifyPosition(address, address, int24, int24, int128, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0xd6852010` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeSwap + +```solidity +function beforeSwap(address, address, bool, int256, uint160, bool, bytes) external returns (bytes4, uint24, uint24) +``` +**Selector**: `0x029c1cb7` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | bool | | +| | int256 | | +| | uint160 | | +| | bool | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | +| [2] | uint24 | | + +### afterSwap + +```solidity +function afterSwap(address, address, bool, int256, uint160, int256, int256, bytes) external returns (bytes4) +``` +**Selector**: `0x9cb5a963` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | bool | | +| | int256 | | +| | uint160 | | +| | int256 | | +| | int256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeFlash + +```solidity +function beforeFlash(address, address, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x8de0a8ee` + +@dev + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterFlash + +```solidity +function afterFlash(address, address, uint256, uint256, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x343d37ff` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + diff --git a/docs/Contracts/Plugin/BasePluginV1Factory.md b/docs/Contracts/Plugin/BasePluginV1Factory.md index dca3407bc..34c1bca44 100644 --- a/docs/Contracts/Plugin/BasePluginV1Factory.md +++ b/docs/Contracts/Plugin/BasePluginV1Factory.md @@ -3,9 +3,11 @@ # BasePluginV1Factory -Algebra default plugin factory +Algebra Integral 1.2.2 default plugin factory -This contract creates Algebra default plugins for Algebra liquidity pools +This contract creates Algebra adaptive fee plugins for Algebra liquidity pools + +*Developer note: This plugin factory can only be used for Algebra base pools* **Inherits:** [IBasePluginV1Factory](interfaces/IBasePluginV1Factory.md) ## Modifiers @@ -81,18 +83,23 @@ constructor(address _algebraFactory) public | ---- | ---- | ----------- | | _algebraFactory | address | | -### createPlugin +### beforeCreatePoolHook ```solidity -function createPlugin(address pool) external returns (address) +function beforeCreatePoolHook(address pool, address, address, address, address, bytes) external returns (address) ``` -**Selector**: `0x361c0f76` +**Selector**: `0x1d0338d9` Deploys new plugin contract for pool | Name | Type | Description | | ---- | ---- | ----------- | -| pool | address | The address of the pool for which the new plugin will be created | +| pool | address | The address of the new pool | +| | address | | +| | address | | +| | address | | +| | address | | +| | bytes | | **Returns:** @@ -100,6 +107,21 @@ Deploys new plugin contract for pool | ---- | ---- | ----------- | | [0] | address | New plugin address | +### afterCreatePoolHook + +```solidity +function afterCreatePoolHook(address, address, address) external view +``` +**Selector**: `0x8d5ef8d1` + +Called after the pool is created + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | address | | + ### createPluginForExistingPool ```solidity diff --git a/docs/Contracts/Plugin/BasePluginV2Factory.md b/docs/Contracts/Plugin/BasePluginV2Factory.md new file mode 100644 index 000000000..bc0001d38 --- /dev/null +++ b/docs/Contracts/Plugin/BasePluginV2Factory.md @@ -0,0 +1,170 @@ + + +# BasePluginV2Factory + + +Algebra Integral 1.2.2 default plugin factory + +This contract creates Algebra sliding fee plugins for Algebra liquidity pools + +*Developer note: This plugin factory can only be used for Algebra base pools* + +**Inherits:** [IBasePluginV2Factory](interfaces/IBasePluginV2Factory.md) +## Modifiers +### onlyAdministrator + +```solidity +modifier onlyAdministrator() +``` + + + + +## Public variables +### ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR +```solidity +bytes32 constant ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR = 0x267da724c255813ae00f4522fe843cb70148a4b8099cbc5af64f9a4151e55ed6 +``` +**Selector**: `0xcddff269` + +The hash of 'ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR' used as role + +*Developer note: allows to change settings of BasePluginV2Factory* + +### algebraFactory +```solidity +address immutable algebraFactory +``` +**Selector**: `0xa7b64b04` + +Returns the address of AlgebraFactory + + +### farmingAddress +```solidity +address farmingAddress +``` +**Selector**: `0x8a2ade58` + +Returns current farming address + + +### defaultBaseFee +```solidity +uint16 defaultBaseFee +``` +**Selector**: `0x675ec3d7` + + + + +### pluginByPool +```solidity +mapping(address => address) pluginByPool +``` +**Selector**: `0xcdef16f6` + +Returns address of plugin created for given AlgebraPool + + + +## Functions +### constructor + +```solidity +constructor(address _algebraFactory) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _algebraFactory | address | | + +### beforeCreatePoolHook + +```solidity +function beforeCreatePoolHook(address pool, address, address, address, address, bytes) external returns (address) +``` +**Selector**: `0x1d0338d9` + +Deploys new plugin contract for pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the new pool | +| | address | | +| | address | | +| | address | | +| | address | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | New plugin address | + +### afterCreatePoolHook + +```solidity +function afterCreatePoolHook(address, address, address) external view +``` +**Selector**: `0x8d5ef8d1` + +Called after the pool is created + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | address | | + +### createPluginForExistingPool + +```solidity +function createPluginForExistingPool(address token0, address token1) external returns (address) +``` +**Selector**: `0x27733026` + +Create plugin for already existing pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token0 | address | The address of first token in pool | +| token1 | address | The address of second token in pool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of created plugin | + +### setFarmingAddress + +```solidity +function setFarmingAddress(address newFarmingAddress) external +``` +**Selector**: `0xb001f618` + + + +*Developer note: updates farmings manager address on the factory* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newFarmingAddress | address | The new tokenomics contract address | + +### setDefaultBaseFee + +```solidity +function setDefaultBaseFee(uint16 newDefaultBaseFee) external +``` +**Selector**: `0x0bc614c4` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newDefaultBaseFee | uint16 | | + diff --git a/docs/Contracts/Plugin/HydrexBasePlugin.md b/docs/Contracts/Plugin/HydrexBasePlugin.md new file mode 100644 index 000000000..39833a24d --- /dev/null +++ b/docs/Contracts/Plugin/HydrexBasePlugin.md @@ -0,0 +1,255 @@ + + +# HydrexBasePlugin + + +Algebra Integral 1.2.1 plugin. Contains adaptive + sliding fee, safety switch and twap oracle + + + +**Inherits:** [DynamicFeePlugin](plugins/DynamicFeePlugin.md) [VolatilityOraclePlugin](plugins/VolatilityOraclePlugin.md) [SlidingFeePlugin](plugins/SlidingFeePlugin.md) [SecurityPlugin](plugins/SecurityPlugin.md) [AlmPlugin](plugins/AlmPlugin.md) + +## Public variables +### defaultPluginConfig +```solidity +uint8 constant defaultPluginConfig +``` +**Selector**: `0x689ea370` + +Returns plugin config + + + +## Functions +### constructor + +```solidity +constructor(address _pool, address _factory, address _pluginFactory, struct AlgebraFeeConfiguration _config, uint16 _baseFee) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _pool | address | | +| _factory | address | | +| _pluginFactory | address | | +| _config | struct AlgebraFeeConfiguration | | +| _baseFee | uint16 | | + +### beforeInitialize + +```solidity +function beforeInitialize(address, uint160) external returns (bytes4) +``` +**Selector**: `0x636fd804` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterInitialize + +```solidity +function afterInitialize(address, uint160, int24 tick) external returns (bytes4) +``` +**Selector**: `0x82dd6522` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | +| tick | int24 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeModifyPosition + +```solidity +function beforeModifyPosition(address, address, int24, int24, int128 liquidity, bytes) external returns (bytes4, uint24) +``` +**Selector**: `0x5e2411b2` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| liquidity | int128 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | + +### afterModifyPosition + +```solidity +function afterModifyPosition(address, address, int24, int24, int128, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0xd6852010` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeSwap + +```solidity +function beforeSwap(address, address, bool zeroToOne, int256, uint160, bool, bytes) external returns (bytes4, uint24, uint24) +``` +**Selector**: `0x029c1cb7` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| zeroToOne | bool | | +| | int256 | | +| | uint160 | | +| | bool | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | +| [2] | uint24 | | + +### afterSwap + +```solidity +function afterSwap(address, address, bool, int256, uint160, int256, int256, bytes) external returns (bytes4) +``` +**Selector**: `0x9cb5a963` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | bool | | +| | int256 | | +| | uint160 | | +| | int256 | | +| | int256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeFlash + +```solidity +function beforeFlash(address, address, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x8de0a8ee` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterFlash + +```solidity +function afterFlash(address, address, uint256, uint256, uint256, uint256, bytes) external returns (bytes4) +``` +**Selector**: `0x343d37ff` + + + +*Developer note: unused* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### getCurrentFee + +```solidity +function getCurrentFee() external view returns (uint16 fee) +``` +**Selector**: `0xf70d9362` + +Returns fee from plugin + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| fee | uint16 | The pool fee value in hundredths of a bip, i.e. 1e-6 | + diff --git a/docs/Contracts/Plugin/SecurityPluginFactory.md b/docs/Contracts/Plugin/SecurityPluginFactory.md new file mode 100644 index 000000000..78cdaab04 --- /dev/null +++ b/docs/Contracts/Plugin/SecurityPluginFactory.md @@ -0,0 +1,146 @@ + + +# SecurityPluginFactory + + +Algebra Integral 1.2.1 security plugin factory + + + +**Inherits:** [ISecurityPluginFactory](interfaces/ISecurityPluginFactory.md) +## Modifiers +### onlyAdministrator + +```solidity +modifier onlyAdministrator() +``` + + + + +## Public variables +### ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR +```solidity +bytes32 constant ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR = 0x267da724c255813ae00f4522fe843cb70148a4b8099cbc5af64f9a4151e55ed6 +``` +**Selector**: `0xcddff269` + +The hash of 'ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR' used as role + +*Developer note: allows to change settings of BasePluginV1Factory* + +### algebraFactory +```solidity +address immutable algebraFactory +``` +**Selector**: `0xa7b64b04` + +Returns the address of AlgebraFactory + + +### securityRegistry +```solidity +address securityRegistry +``` +**Selector**: `0x9b21f9ae` + +Returns current securityRegistry address + + +### pluginByPool +```solidity +mapping(address => address) pluginByPool +``` +**Selector**: `0xcdef16f6` + +Returns address of plugin created for given AlgebraPool + + + +## Functions +### constructor + +```solidity +constructor(address _algebraFactory) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _algebraFactory | address | | + +### beforeCreatePoolHook + +```solidity +function beforeCreatePoolHook(address pool, address, address, address, address, bytes) external returns (address) +``` +**Selector**: `0x1d0338d9` + +Deploys new plugin contract for pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the new pool | +| | address | | +| | address | | +| | address | | +| | address | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | New plugin address | + +### afterCreatePoolHook + +```solidity +function afterCreatePoolHook(address, address, address) external view +``` +**Selector**: `0x8d5ef8d1` + +Called after the pool is created + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | address | | + +### createPluginForExistingPool + +```solidity +function createPluginForExistingPool(address token0, address token1) external returns (address) +``` +**Selector**: `0x27733026` + +Create plugin for already existing pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token0 | address | The address of first token in pool | +| token1 | address | The address of second token in pool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of created plugin | + +### setSecurityRegistry + +```solidity +function setSecurityRegistry(address _securityRegistry) external +``` +**Selector**: `0x64fae8a9` + + + +*Developer note: updates securoty registry address on the factory* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _securityRegistry | address | | + diff --git a/docs/Contracts/Plugin/base/BasePlugin.md b/docs/Contracts/Plugin/base/BasePlugin.md new file mode 100644 index 000000000..96420caea --- /dev/null +++ b/docs/Contracts/Plugin/base/BasePlugin.md @@ -0,0 +1,270 @@ + + +# BasePlugin + + +Algebra Integral 1.2.2 plugin base + +This contract simplifies development process of plugins by providing base functionality + +**Inherits:** [IBasePlugin](../interfaces/IBasePlugin.md) Timestamp +## Modifiers +### onlyPool + +```solidity +modifier onlyPool() +``` + + + + +## Public variables +### ALGEBRA_BASE_PLUGIN_MANAGER +```solidity +bytes32 constant ALGEBRA_BASE_PLUGIN_MANAGER = 0x8e8000aba5b365c0be9685da1153f7f096e76d1ecfb42c050ae1e387aa65b4f5 +``` +**Selector**: `0x31b25d1a` + + + +*Developer note: The role can be granted in AlgebraFactory* + +### pool +```solidity +address immutable pool +``` +**Selector**: `0x16f0115b` + + + + + +## Functions +### collectPluginFee + +```solidity +function collectPluginFee(address token, uint256 amount, address recipient) external +``` +**Selector**: `0xe72c652d` + +Claim plugin fee + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token | address | The token address | +| amount | uint256 | Amount of tokens | +| recipient | address | Recipient address | + +### handlePluginFee + +```solidity +function handlePluginFee(uint256, uint256) external view returns (bytes4) +``` +**Selector**: `0xaa6b14bb` + +Handle plugin fee transfer on plugin contract + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | uint256 | | +| | uint256 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | bytes4 The function selector | + +### beforeInitialize + +```solidity +function beforeInitialize(address, uint160) external virtual returns (bytes4) +``` +**Selector**: `0x636fd804` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterInitialize + +```solidity +function afterInitialize(address, uint160, int24) external virtual returns (bytes4) +``` +**Selector**: `0x82dd6522` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | uint160 | | +| | int24 | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeModifyPosition + +```solidity +function beforeModifyPosition(address, address, int24, int24, int128, bytes) external virtual returns (bytes4, uint24) +``` +**Selector**: `0x5e2411b2` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | + +### afterModifyPosition + +```solidity +function afterModifyPosition(address, address, int24, int24, int128, uint256, uint256, bytes) external virtual returns (bytes4) +``` +**Selector**: `0xd6852010` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | int24 | | +| | int24 | | +| | int128 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeSwap + +```solidity +function beforeSwap(address, address, bool, int256, uint160, bool, bytes) external virtual returns (bytes4, uint24, uint24) +``` +**Selector**: `0x029c1cb7` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | bool | | +| | int256 | | +| | uint160 | | +| | bool | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | +| [1] | uint24 | | +| [2] | uint24 | | + +### afterSwap + +```solidity +function afterSwap(address, address, bool, int256, uint160, int256, int256, bytes) external virtual returns (bytes4) +``` +**Selector**: `0x9cb5a963` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | bool | | +| | int256 | | +| | uint160 | | +| | int256 | | +| | int256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### beforeFlash + +```solidity +function beforeFlash(address, address, uint256, uint256, bytes) external virtual returns (bytes4) +``` +**Selector**: `0x8de0a8ee` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + +### afterFlash + +```solidity +function afterFlash(address, address, uint256, uint256, uint256, uint256, bytes) external virtual returns (bytes4) +``` +**Selector**: `0x343d37ff` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | uint256 | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes4 | | + diff --git a/docs/Contracts/Plugin/base/BasePluginFactory.md b/docs/Contracts/Plugin/base/BasePluginFactory.md new file mode 100644 index 000000000..cf2c96ae6 --- /dev/null +++ b/docs/Contracts/Plugin/base/BasePluginFactory.md @@ -0,0 +1,85 @@ + + +# BasePluginFactory + + + + + + +**Inherits:** [IBasePluginFactory](../interfaces/IBasePluginFactory.md) + +## Public variables +### entryPoint +```solidity +address immutable entryPoint +``` +**Selector**: `0xb0d691fe` + +Returns the address of AlgebraCustomPoolEntryPoint + +*Developer note: This is a main entry point for creating, managing plugins* + + +## Functions +### createCustomPool + +```solidity +function createCustomPool(address creator, address tokenA, address tokenB, bytes data) external virtual returns (address customPool) +``` +**Selector**: `0x819dbd89` + +Create a custom pool with a plugin + +| Name | Type | Description | +| ---- | ---- | ----------- | +| creator | address | The address that initiated the pool creation | +| tokenA | address | The address of first token in pool | +| tokenB | address | The address of second token in pool | +| data | bytes | The data to be passed to beforeCreatePoolHook | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | The address of created plugin | + +### beforeCreatePoolHook + +```solidity +function beforeCreatePoolHook(address pool, address, address, address, address, bytes) external virtual returns (address) +``` +**Selector**: `0x1d0338d9` + +Deploys new plugin contract for pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of the new pool | +| | address | | +| | address | | +| | address | | +| | address | | +| | bytes | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | New plugin address | + +### afterCreatePoolHook + +```solidity +function afterCreatePoolHook(address, address, address) external view virtual +``` +**Selector**: `0x8d5ef8d1` + +Called after the pool is created + +| Name | Type | Description | +| ---- | ---- | ----------- | +| | address | | +| | address | | +| | address | | + diff --git a/docs/Contracts/Plugin/interfaces/IBasePlugin.md b/docs/Contracts/Plugin/interfaces/IBasePlugin.md new file mode 100644 index 000000000..dc4c8db92 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/IBasePlugin.md @@ -0,0 +1,27 @@ + + +# IBasePlugin + + +The interface for the BasePlugin + + + +**Inherits:** [IAlgebraPlugin](../../Core/interfaces/plugin/IAlgebraPlugin.md) + +## Functions +### collectPluginFee + +```solidity +function collectPluginFee(address token, uint256 amount, address recipient) external +``` +**Selector**: `0xe72c652d` + +Claim plugin fee + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token | address | The token address | +| amount | uint256 | Amount of tokens | +| recipient | address | Recipient address | + diff --git a/docs/Contracts/Plugin/interfaces/IBasePluginFactory.md b/docs/Contracts/Plugin/interfaces/IBasePluginFactory.md new file mode 100644 index 000000000..ecab08ef1 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/IBasePluginFactory.md @@ -0,0 +1,107 @@ + + +# IBasePluginFactory + + +The interface for the BasePluginFactory + + + +**Inherits:** [IAlgebraPluginFactory](../../Core/interfaces/plugin/IAlgebraPluginFactory.md) + +## Functions +### entryPoint + +```solidity +function entryPoint() external view returns (address) +``` +**Selector**: `0xb0d691fe` + +Returns the address of AlgebraCustomPoolEntryPoint + +*Developer note: This is a main entry point for creating, managing plugins* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The AlgebraCustomPoolEntryPoint contract address | + +### createCustomPool + +```solidity +function createCustomPool(address creator, address tokenA, address tokenB, bytes data) external returns (address customPool) +``` +**Selector**: `0x819dbd89` + +Create a custom pool with a plugin + +| Name | Type | Description | +| ---- | ---- | ----------- | +| creator | address | The address that initiated the pool creation | +| tokenA | address | The address of first token in pool | +| tokenB | address | The address of second token in pool | +| data | bytes | The data to be passed to beforeCreatePoolHook | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| customPool | address | The address of created plugin | + +### setTickSpacing + +```solidity +function setTickSpacing(address pool, int24 newTickSpacing) external +``` +**Selector**: `0x4bf092cd` + +Sets tick spacing in a deployed custom pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of custom pool | +| newTickSpacing | int24 | The new tick spacing | + +### setPlugin + +```solidity +function setPlugin(address pool, address newPluginAddress) external +``` +**Selector**: `0xf9f4c09a` + +Sets plugin in a deployed custom pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of custom pool | +| newPluginAddress | address | The new plugin | + +### setPluginConfig + +```solidity +function setPluginConfig(address pool, uint8 newConfig) external +``` +**Selector**: `0x054bee3d` + +Sets plugin config in a deployed custom pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of custom pool | +| newConfig | uint8 | The new config | + +### setFee + +```solidity +function setFee(address pool, uint16 newFee) external +``` +**Selector**: `0x337f3a31` + +Sets fee in a deployed custom pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of custom pool | +| newFee | uint16 | The new fee | + diff --git a/docs/Contracts/Plugin/interfaces/IBasePluginV2Factory.md b/docs/Contracts/Plugin/interfaces/IBasePluginV2Factory.md new file mode 100644 index 000000000..0b9bc7943 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/IBasePluginV2Factory.md @@ -0,0 +1,167 @@ + + +# IBasePluginV2Factory + + +The interface for the BasePluginV2Factory + +This contract creates Algebra default plugins for Algebra liquidity pools + +**Inherits:** [IAlgebraPluginFactory](../../Core/interfaces/plugin/IAlgebraPluginFactory.md) + +## Events +### FarmingAddress + +```solidity +event FarmingAddress(address newFarmingAddress) +``` + +Emitted when the farming address is changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newFarmingAddress | address | The farming address after the address was changed | + +### DefaultBaseFee + +```solidity +event DefaultBaseFee(uint16 newDefaultBaseFee) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newDefaultBaseFee | uint16 | | + + +## Functions +### ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR + +```solidity +function ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR() external pure returns (bytes32) +``` +**Selector**: `0xcddff269` + +The hash of 'ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR' used as role + +*Developer note: allows to change settings of BasePluginV2Factory* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes32 | | + +### algebraFactory + +```solidity +function algebraFactory() external view returns (address) +``` +**Selector**: `0xa7b64b04` + +Returns the address of AlgebraFactory + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The AlgebraFactory contract address | + +### farmingAddress + +```solidity +function farmingAddress() external view returns (address) +``` +**Selector**: `0x8a2ade58` + +Returns current farming address + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The farming contract address | + +### defaultBaseFee + +```solidity +function defaultBaseFee() external view returns (uint16) +``` +**Selector**: `0x675ec3d7` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint16 | | + +### pluginByPool + +```solidity +function pluginByPool(address pool) external view returns (address) +``` +**Selector**: `0xcdef16f6` + +Returns address of plugin created for given AlgebraPool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of AlgebraPool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of corresponding plugin | + +### createPluginForExistingPool + +```solidity +function createPluginForExistingPool(address token0, address token1) external returns (address) +``` +**Selector**: `0x27733026` + +Create plugin for already existing pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token0 | address | The address of first token in pool | +| token1 | address | The address of second token in pool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of created plugin | + +### setFarmingAddress + +```solidity +function setFarmingAddress(address newFarmingAddress) external +``` +**Selector**: `0xb001f618` + + + +*Developer note: updates farmings manager address on the factory* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newFarmingAddress | address | The new tokenomics contract address | + +### setDefaultBaseFee + +```solidity +function setDefaultBaseFee(uint16 newDefaultBaseFee) external +``` +**Selector**: `0x0bc614c4` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newDefaultBaseFee | uint16 | | + diff --git a/docs/Contracts/Plugin/interfaces/IHydrexBasePluginFactory.md b/docs/Contracts/Plugin/interfaces/IHydrexBasePluginFactory.md new file mode 100644 index 000000000..49f80eb65 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/IHydrexBasePluginFactory.md @@ -0,0 +1,301 @@ + + +# IHydrexBasePluginFactory + + +The interface for the HydrexBasePluginFactory + +This contract creates Algebra base plugins for Algebra liquidity pools + +**Inherits:** [IAlgebraPluginFactory](../../Core/interfaces/plugin/IAlgebraPluginFactory.md) + +## Events +### DefaultFeeConfiguration + +```solidity +event DefaultFeeConfiguration(struct AlgebraFeeConfiguration newConfig) +``` + +Emitted when the default fee configuration is changed + +*Developer note: See the AdaptiveFee library for more details* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newConfig | struct AlgebraFeeConfiguration | The structure with dynamic fee parameters | + +### DefaultBaseFee + +```solidity +event DefaultBaseFee(uint16 newDefaultBaseFee) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newDefaultBaseFee | uint16 | | + +### DynamicFeeStatus + +```solidity +event DynamicFeeStatus(bool isEnabled) +``` + +Emitted when the dynamic fee status is changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| isEnabled | bool | Dynamic fee new status | + +### SlidingFeeStatus + +```solidity +event SlidingFeeStatus(bool isEnabled) +``` + +Emitted when the sliding fee status is changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| isEnabled | bool | Sliding fee new status | + +### SecurityRegistry + +```solidity +event SecurityRegistry(address securityRegistry) +``` + +Emitted when the security registry address is changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| securityRegistry | address | The security registry address after the address was changed | + + +## Functions +### ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR + +```solidity +function ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR() external pure returns (bytes32) +``` +**Selector**: `0xcddff269` + +The hash of 'ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR' used as role + +*Developer note: allows to change settings of BasePluginV1Factory* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes32 | | + +### algebraFactory + +```solidity +function algebraFactory() external view returns (address) +``` +**Selector**: `0xa7b64b04` + +Returns the address of AlgebraFactory + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The AlgebraFactory contract address | + +### defaultBaseFee + +```solidity +function defaultBaseFee() external view returns (uint16) +``` +**Selector**: `0x675ec3d7` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint16 | | + +### slidingFeeStatus + +```solidity +function slidingFeeStatus() external view returns (bool) +``` +**Selector**: `0xeb7bfd70` + +Returns the status of the sliding fee + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bool | The status of the sliding fee | + +### dynamicFeeStatus + +```solidity +function dynamicFeeStatus() external view returns (bool) +``` +**Selector**: `0xb7c53e79` + +Returns the status of the dynamic fee + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bool | The status of the dynamic fee | + +### securityRegistry + +```solidity +function securityRegistry() external view returns (address) +``` +**Selector**: `0x9b21f9ae` + +Returns current securityRegistry address + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The securityRegistry contract address | + +### defaultFeeConfiguration + +```solidity +function defaultFeeConfiguration() external view returns (uint16 alpha1, uint16 alpha2, uint32 beta1, uint32 beta2, uint16 gamma1, uint16 gamma2, uint16 baseFee) +``` +**Selector**: `0x4e09a96a` + +Current default dynamic fee configuration + +*Developer note: See the AdaptiveFee struct for more details about params. +This value is set by default in new plugins* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| alpha1 | uint16 | | +| alpha2 | uint16 | | +| beta1 | uint32 | | +| beta2 | uint32 | | +| gamma1 | uint16 | | +| gamma2 | uint16 | | +| baseFee | uint16 | | + +### pluginByPool + +```solidity +function pluginByPool(address pool) external view returns (address) +``` +**Selector**: `0xcdef16f6` + +Returns address of plugin created for given AlgebraPool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of AlgebraPool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of corresponding plugin | + +### createPluginForExistingPool + +```solidity +function createPluginForExistingPool(address token0, address token1) external returns (address) +``` +**Selector**: `0x27733026` + +Create plugin for already existing pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token0 | address | The address of first token in pool | +| token1 | address | The address of second token in pool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of created plugin | + +### setDefaultFeeConfiguration + +```solidity +function setDefaultFeeConfiguration(struct AlgebraFeeConfiguration newConfig) external +``` +**Selector**: `0xf718949a` + +Changes initial fee configuration for new pools + +*Developer note: changes coefficients for sigmoids: α / (1 + e^( (β-x) / γ)) +alpha1 + alpha2 + baseFee (max possible fee) must be <= type(uint16).max and gammas must be > 0* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newConfig | struct AlgebraFeeConfiguration | new default fee configuration. See the #AdaptiveFee.sol library for details | + +### setDynamicFeeStatus + +```solidity +function setDynamicFeeStatus(bool status) external +``` +**Selector**: `0x141773b3` + +Changes dynamic fee status + +| Name | Type | Description | +| ---- | ---- | ----------- | +| status | bool | New status of dynamic fee | + +### setSlidingFeeStatus + +```solidity +function setSlidingFeeStatus(bool status) external +``` +**Selector**: `0x03801165` + +Changes sliding fee status + +| Name | Type | Description | +| ---- | ---- | ----------- | +| status | bool | New status of sliding fee | + +### setSecurityRegistry + +```solidity +function setSecurityRegistry(address newSecurityRegistry) external +``` +**Selector**: `0x64fae8a9` + + + +*Developer note: updates securoty registry address on the factory* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newSecurityRegistry | address | The new security registry contract address | + +### setDefaultBaseFee + +```solidity +function setDefaultBaseFee(uint16 newDefaultBaseFee) external +``` +**Selector**: `0x0bc614c4` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newDefaultBaseFee | uint16 | | + diff --git a/docs/Contracts/Plugin/interfaces/ISecurityPluginFactory.md b/docs/Contracts/Plugin/interfaces/ISecurityPluginFactory.md new file mode 100644 index 000000000..270246fee --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/ISecurityPluginFactory.md @@ -0,0 +1,127 @@ + + +# ISecurityPluginFactory + + +The interface for the SecurityPluginFactory + + + +**Inherits:** [IAlgebraPluginFactory](../../Core/interfaces/plugin/IAlgebraPluginFactory.md) + +## Events +### SecurityRegistry + +```solidity +event SecurityRegistry(address securityRegistry) +``` + +Emitted when the security registry address is changed + +| Name | Type | Description | +| ---- | ---- | ----------- | +| securityRegistry | address | The security registry address after the address was changed | + + +## Functions +### ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR + +```solidity +function ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR() external pure returns (bytes32) +``` +**Selector**: `0xcddff269` + +The hash of 'ALGEBRA_BASE_PLUGIN_FACTORY_ADMINISTRATOR' used as role + +*Developer note: allows to change settings of BasePluginV1Factory* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes32 | | + +### algebraFactory + +```solidity +function algebraFactory() external view returns (address) +``` +**Selector**: `0xa7b64b04` + +Returns the address of AlgebraFactory + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The AlgebraFactory contract address | + +### securityRegistry + +```solidity +function securityRegistry() external view returns (address) +``` +**Selector**: `0x9b21f9ae` + +Returns current securityRegistry address + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The securityRegistry contract address | + +### pluginByPool + +```solidity +function pluginByPool(address pool) external view returns (address) +``` +**Selector**: `0xcdef16f6` + +Returns address of plugin created for given AlgebraPool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | The address of AlgebraPool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of corresponding plugin | + +### createPluginForExistingPool + +```solidity +function createPluginForExistingPool(address token0, address token1) external returns (address) +``` +**Selector**: `0x27733026` + +Create plugin for already existing pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| token0 | address | The address of first token in pool | +| token1 | address | The address of second token in pool | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | The address of created plugin | + +### setSecurityRegistry + +```solidity +function setSecurityRegistry(address newSecurityRegistry) external +``` +**Selector**: `0x64fae8a9` + + + +*Developer note: updates securoty registry address on the factory* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newSecurityRegistry | address | The new security registry contract address | + diff --git a/docs/Contracts/Plugin/interfaces/plugins/IAlmPlugin.md b/docs/Contracts/Plugin/interfaces/plugins/IAlmPlugin.md new file mode 100644 index 000000000..1d53132a1 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/plugins/IAlmPlugin.md @@ -0,0 +1,110 @@ + + +# IAlmPlugin + + + + + + + +## Functions +### initializeALM + +```solidity +function initializeALM(address _rebalanceManager, uint32 _slowTwapPeriod, uint32 _fastTwapPeriod) external +``` +**Selector**: `0xd49dda85` + +Initializing ALM plugin + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _rebalanceManager | address | address of rebalance manager | +| _slowTwapPeriod | uint32 | period in seconds to get slow TWAP | +| _fastTwapPeriod | uint32 | period in seconds to get fast TWAP | + +### setSlowTwapPeriod + +```solidity +function setSlowTwapPeriod(uint32 _slowTwapPeriod) external +``` +**Selector**: `0x48b2acdd` + +Set slow TWAP period + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _slowTwapPeriod | uint32 | period in seconds to get slow TWAP | + +### setFastTwapPeriod + +```solidity +function setFastTwapPeriod(uint32 _fastTwapPeriod) external +``` +**Selector**: `0x08095141` + +Set slow TWAP period + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _fastTwapPeriod | uint32 | period in seconds to get fast TWAP | + +### setRebalanceManager + +```solidity +function setRebalanceManager(address _rebalanceManager) external +``` +**Selector**: `0x918a1ab0` + +Set rebalance manager + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _rebalanceManager | address | address of rebalance manager | + +### rebalanceManager + +```solidity +function rebalanceManager() external view returns (address) +``` +**Selector**: `0x6fb5bad1` + +Returns address of rebalance manager + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | Address of rebalance manager | + +### slowTwapPeriod + +```solidity +function slowTwapPeriod() external view returns (uint32) +``` +**Selector**: `0x841c6a37` + +Returns time interval in seconds of slow TWAP period + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint32 | Time interval in seconds of slow TWAP period | + +### fastTwapPeriod + +```solidity +function fastTwapPeriod() external view returns (uint32) +``` +**Selector**: `0xad1c3743` + +Returns time interval in seconds of fast TWAP period + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | uint32 | Time interval in seconds of fast TWAP period | + diff --git a/docs/Contracts/Plugin/interfaces/plugins/IFarmingPlugin.md b/docs/Contracts/Plugin/interfaces/plugins/IFarmingPlugin.md index 2e0e2243c..2335a78eb 100644 --- a/docs/Contracts/Plugin/interfaces/plugins/IFarmingPlugin.md +++ b/docs/Contracts/Plugin/interfaces/plugins/IFarmingPlugin.md @@ -25,21 +25,6 @@ Emitted when new activeIncentive is set ## Functions -### pool - -```solidity -function pool() external view returns (address) -``` -**Selector**: `0x16f0115b` - -Returns the address of the pool the plugin is created for - -**Returns:** - -| Name | Type | Description | -| ---- | ---- | ----------- | -| [0] | address | address of the pool | - ### setIncentive ```solidity @@ -95,3 +80,18 @@ Returns the address of active incentive | ---- | ---- | ----------- | | [0] | address | The address associated with the current active incentive | +### getPool + +```solidity +function getPool() external view returns (address) +``` +**Selector**: `0x026b1d5f` + +Returns the address of the pool the plugin is created for + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | address of the pool | + diff --git a/docs/Contracts/Plugin/interfaces/plugins/IRebalanceManager.md b/docs/Contracts/Plugin/interfaces/plugins/IRebalanceManager.md new file mode 100644 index 000000000..e1f08ef30 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/plugins/IRebalanceManager.md @@ -0,0 +1,170 @@ + + +# IRebalanceManager + + + + + + + +## Events +### SetPriceChangeThreshold + +```solidity +event SetPriceChangeThreshold(uint16 priceChangeThreshold) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| priceChangeThreshold | uint16 | | + +### SetPercentages + +```solidity +event SetPercentages(uint16 baseLowPct, uint16 baseHighPct, uint16 limitReservePct) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| baseLowPct | uint16 | | +| baseHighPct | uint16 | | +| limitReservePct | uint16 | | + +### SetTriggers + +```solidity +event SetTriggers(uint16 simulate, uint16 normalThreshold, uint16 underInventoryThreshold, uint16 overInventoryThreshold) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| simulate | uint16 | | +| normalThreshold | uint16 | | +| underInventoryThreshold | uint16 | | +| overInventoryThreshold | uint16 | | + +### SetDtrDelta + +```solidity +event SetDtrDelta(uint16 dtrDelta) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| dtrDelta | uint16 | | + +### SetHighVolatility + +```solidity +event SetHighVolatility(uint16 highVolatility) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| highVolatility | uint16 | | + +### SetSomeVolatility + +```solidity +event SetSomeVolatility(uint16 someVolatility) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| someVolatility | uint16 | | + +### SetExtremeVolatility + +```solidity +event SetExtremeVolatility(uint16 extremeVolatility) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| extremeVolatility | uint16 | | + +### SetDepositTokenUnusedThreshold + +```solidity +event SetDepositTokenUnusedThreshold(uint16 depositTokenUnusedThreshold) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| depositTokenUnusedThreshold | uint16 | | + +### SetMinTimeBetweenRebalances + +```solidity +event SetMinTimeBetweenRebalances(uint32 minTimeBetweenRebalances) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| minTimeBetweenRebalances | uint32 | | + +### SetVault + +```solidity +event SetVault(address vault) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| vault | address | | + +### Paused + +```solidity +event Paused() +``` + + + +### Unpaused + +```solidity +event Unpaused() +``` + + + + +## Functions +### obtainTWAPAndRebalance + +```solidity +function obtainTWAPAndRebalance(int24 currentTick, int24 slowTwapTick, int24 fastTwapTick, uint32 lastBlockTimestamp) external +``` +**Selector**: `0x7e7b25f1` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| currentTick | int24 | | +| slowTwapTick | int24 | | +| fastTwapTick | int24 | | +| lastBlockTimestamp | uint32 | | + diff --git a/docs/Contracts/Plugin/interfaces/plugins/ISecurityPlugin.md b/docs/Contracts/Plugin/interfaces/plugins/ISecurityPlugin.md new file mode 100644 index 000000000..9b57d66b4 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/plugins/ISecurityPlugin.md @@ -0,0 +1,73 @@ + + +# ISecurityPlugin + + + + + + + +## Events +### SecurityRegistry + +```solidity +event SecurityRegistry(address registry) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| registry | address | | + + +## Functions +### setSecurityRegistry + +```solidity +function setSecurityRegistry(address registry) external +``` +**Selector**: `0x64fae8a9` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| registry | address | | + +### getSecurityRegistry + +```solidity +function getSecurityRegistry() external view returns (address) +``` +**Selector**: `0x20501a91` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | | + + +## Errors +## PoolDisabled + +```solidity +error PoolDisabled() +``` +**Selector**: `0x19d5b294` + + + +## BurnOnly + +```solidity +error BurnOnly() +``` +**Selector**: `0x5261f42a` + + + diff --git a/docs/Contracts/Plugin/interfaces/plugins/ISecurityRegistry.md b/docs/Contracts/Plugin/interfaces/plugins/ISecurityRegistry.md new file mode 100644 index 000000000..d7f972c49 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/plugins/ISecurityRegistry.md @@ -0,0 +1,155 @@ + + +# ISecurityRegistry + + + + + + + +## Events +### GlobalStatus + +```solidity +event GlobalStatus(enum ISecurityRegistry.Status status) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| status | enum ISecurityRegistry.Status | | + +### PoolStatus + +```solidity +event PoolStatus(address pool, enum ISecurityRegistry.Status status) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | | +| status | enum ISecurityRegistry.Status | | + + +## Functions +### setGlobalStatus + +```solidity +function setGlobalStatus(enum ISecurityRegistry.Status newStatus) external +``` +**Selector**: `0x24b62cd0` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newStatus | enum ISecurityRegistry.Status | | + +### getPoolStatus + +```solidity +function getPoolStatus(address pool) external returns (enum ISecurityRegistry.Status) +``` +**Selector**: `0x15d9d2f9` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | enum ISecurityRegistry.Status | | + +### setPoolsStatus + +```solidity +function setPoolsStatus(address[] pools, enum ISecurityRegistry.Status[] newStatuses) external +``` +**Selector**: `0x6547cd53` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pools | address[] | | +| newStatuses | enum ISecurityRegistry.Status[] | | + +### algebraFactory + +```solidity +function algebraFactory() external view returns (address) +``` +**Selector**: `0xa7b64b04` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | | + +### GUARD + +```solidity +function GUARD() external pure returns (bytes32) +``` +**Selector**: `0xfe3348f9` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bytes32 | | + +### globalStatus + +```solidity +function globalStatus() external view returns (enum ISecurityRegistry.Status) +``` +**Selector**: `0xb73f7951` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | enum ISecurityRegistry.Status | | + +### isPoolStatusOverrided + +```solidity +function isPoolStatusOverrided() external view returns (bool) +``` +**Selector**: `0x853b8c5c` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bool | | + + +## Errors +## OnlyOwner + +```solidity +error OnlyOwner() +``` +**Selector**: `0x5fc483c5` + + + diff --git a/docs/Contracts/Plugin/interfaces/plugins/ISlidingFeePlugin.md b/docs/Contracts/Plugin/interfaces/plugins/ISlidingFeePlugin.md new file mode 100644 index 000000000..400dc2e87 --- /dev/null +++ b/docs/Contracts/Plugin/interfaces/plugins/ISlidingFeePlugin.md @@ -0,0 +1,63 @@ + + +# ISlidingFeePlugin + + + + + + + +## Events +### PriceChangeFactor + +```solidity +event PriceChangeFactor(uint256 priceChangeFactor) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| priceChangeFactor | uint256 | | + +### BaseFee + +```solidity +event BaseFee(uint16 baseFee) +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| baseFee | uint16 | | + + +## Functions +### setBaseFee + +```solidity +function setBaseFee(uint16 newBaseFee) external +``` +**Selector**: `0x3b586c7f` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newBaseFee | uint16 | | + +### setPriceChangeFactor + +```solidity +function setPriceChangeFactor(uint16 newPriceChangeFactor) external +``` +**Selector**: `0xa37a8456` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newPriceChangeFactor | uint16 | | + diff --git a/docs/Contracts/Plugin/interfaces/plugins/IVolatilityOracle.md b/docs/Contracts/Plugin/interfaces/plugins/IVolatilityOracle.md index 9eb85f77a..84c995508 100644 --- a/docs/Contracts/Plugin/interfaces/plugins/IVolatilityOracle.md +++ b/docs/Contracts/Plugin/interfaces/plugins/IVolatilityOracle.md @@ -53,6 +53,17 @@ Returns the index of the last timepoint that was written. | ---- | ---- | ----------- | | [0] | uint16 | index of the last timepoint written | +### initialize + +```solidity +function initialize() external +``` +**Selector**: `0x8129fc1c` + +Initialize the plugin externally + +*Developer note: This function allows to initialize the plugin if it was created after the pool was created* + ### lastTimepointTimestamp ```solidity diff --git a/docs/Contracts/Plugin/lens/AlgebraOracleV1TWAP.md b/docs/Contracts/Plugin/lens/AlgebraOracleV1TWAP.md index 7b680e2a5..c3d79e9bf 100644 --- a/docs/Contracts/Plugin/lens/AlgebraOracleV1TWAP.md +++ b/docs/Contracts/Plugin/lens/AlgebraOracleV1TWAP.md @@ -3,7 +3,7 @@ # AlgebraOracleV1TWAP -Algebra base plugin V1 oracle frontend +Algebra Integral 1.2.2 base plugin V1 oracle frontend Provides data from oracle corresponding pool diff --git a/docs/Contracts/Plugin/plugins/AlmPlugin.md b/docs/Contracts/Plugin/plugins/AlmPlugin.md new file mode 100644 index 000000000..844906f25 --- /dev/null +++ b/docs/Contracts/Plugin/plugins/AlmPlugin.md @@ -0,0 +1,95 @@ + + +# AlmPlugin + + + + + + +**Inherits:** AlgebraBasePlugin [IAlmPlugin](../interfaces/plugins/IAlmPlugin.md) + +## Public variables +### rebalanceManager +```solidity +address rebalanceManager +``` +**Selector**: `0x6fb5bad1` + +@inheritdoc IAlmPlugin + + +### slowTwapPeriod +```solidity +uint32 slowTwapPeriod +``` +**Selector**: `0x841c6a37` + +@inheritdoc IAlmPlugin + + +### fastTwapPeriod +```solidity +uint32 fastTwapPeriod +``` +**Selector**: `0xad1c3743` + +@inheritdoc IAlmPlugin + + + +## Functions +### initializeALM + +```solidity +function initializeALM(address _rebalanceManager, uint32 _slowTwapPeriod, uint32 _fastTwapPeriod) external +``` +**Selector**: `0xd49dda85` + +@inheritdoc IAlmPlugin + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _rebalanceManager | address | | +| _slowTwapPeriod | uint32 | | +| _fastTwapPeriod | uint32 | | + +### setSlowTwapPeriod + +```solidity +function setSlowTwapPeriod(uint32 _slowTwapPeriod) external +``` +**Selector**: `0x48b2acdd` + +@inheritdoc IAlmPlugin + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _slowTwapPeriod | uint32 | | + +### setFastTwapPeriod + +```solidity +function setFastTwapPeriod(uint32 _fastTwapPeriod) external +``` +**Selector**: `0x08095141` + +@inheritdoc IAlmPlugin + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _fastTwapPeriod | uint32 | | + +### setRebalanceManager + +```solidity +function setRebalanceManager(address _rebalanceManager) external +``` +**Selector**: `0x918a1ab0` + +@inheritdoc IAlmPlugin + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _rebalanceManager | address | | + diff --git a/docs/Contracts/Plugin/plugins/DynamicFeePlugin.md b/docs/Contracts/Plugin/plugins/DynamicFeePlugin.md new file mode 100644 index 000000000..fbe791f7d --- /dev/null +++ b/docs/Contracts/Plugin/plugins/DynamicFeePlugin.md @@ -0,0 +1,48 @@ + + +# DynamicFeePlugin + + +Algebra Integral 1.2.2 default plugin + +This contract stores timepoints and calculates adaptive fee and statistical averages + +**Inherits:** AlgebraBasePlugin [IDynamicFeeManager](../interfaces/plugins/IDynamicFeeManager.md) + +## Functions +### feeConfig + +```solidity +function feeConfig() external view returns (uint16 alpha1, uint16 alpha2, uint32 beta1, uint32 beta2, uint16 gamma1, uint16 gamma2, uint16 baseFee) +``` +**Selector**: `0x1e5eb1d0` + +Current dynamic fee configuration + +*Developer note: See the AdaptiveFee struct for more details* + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| alpha1 | uint16 | | +| alpha2 | uint16 | | +| beta1 | uint32 | | +| beta2 | uint32 | | +| gamma1 | uint16 | | +| gamma2 | uint16 | | +| baseFee | uint16 | | + +### changeFeeConfiguration + +```solidity +function changeFeeConfiguration(struct AlgebraFeeConfiguration _config) external +``` +**Selector**: `0x1d39215e` + +Changes fee configuration for the pool + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _config | struct AlgebraFeeConfiguration | | + diff --git a/docs/Contracts/Plugin/plugins/FarmingProxyPlugin.md b/docs/Contracts/Plugin/plugins/FarmingProxyPlugin.md new file mode 100644 index 000000000..a5314dfba --- /dev/null +++ b/docs/Contracts/Plugin/plugins/FarmingProxyPlugin.md @@ -0,0 +1,77 @@ + + +# FarmingProxyPlugin + + +Algebra Integral 1.2.2 default plugin + +This contract stores timepoints and calculates adaptive fee and statistical averages + +**Inherits:** AlgebraBasePlugin [IFarmingPlugin](../interfaces/plugins/IFarmingPlugin.md) + +## Public variables +### incentive +```solidity +address incentive +``` +**Selector**: `0x1d4632ac` + +Returns the address of active incentive + +*Developer note: if there is no active incentive at the moment, incentiveAddress would be equal to address(0)* + + +## Functions +### setIncentive + +```solidity +function setIncentive(address newIncentive) external +``` +**Selector**: `0x7c1fe0c8` + +Connects or disconnects an incentive. + +*Developer note: Only farming can connect incentives. +The one who connected it and the current farming has the right to disconnect the incentive.* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newIncentive | address | The address associated with the incentive or zero address | + +### isIncentiveConnected + +```solidity +function isIncentiveConnected(address targetIncentive) external view returns (bool) +``` +**Selector**: `0xe63015f0` + +Checks if the incentive is connected to pool + +*Developer note: Returns false if the plugin has a different incentive set, the plugin is not connected to the pool, +or the plugin configuration is incorrect.* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| targetIncentive | address | The address of the incentive to be checked | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | bool | Indicates whether the target incentive is active | + +### getPool + +```solidity +function getPool() external view returns (address) +``` +**Selector**: `0x026b1d5f` + +Returns the address of the pool the plugin is created for + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | address of the pool | + diff --git a/docs/Contracts/Plugin/plugins/SecurityPlugin.md b/docs/Contracts/Plugin/plugins/SecurityPlugin.md new file mode 100644 index 000000000..5389b4bf4 --- /dev/null +++ b/docs/Contracts/Plugin/plugins/SecurityPlugin.md @@ -0,0 +1,40 @@ + + +# SecurityPlugin + + +Algebra Integral 1.2 security plugin + + + +**Inherits:** AlgebraBasePlugin [ISecurityPlugin](../interfaces/plugins/ISecurityPlugin.md) + +## Functions +### setSecurityRegistry + +```solidity +function setSecurityRegistry(address _securityRegistry) external +``` +**Selector**: `0x64fae8a9` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _securityRegistry | address | | + +### getSecurityRegistry + +```solidity +function getSecurityRegistry() external view returns (address) +``` +**Selector**: `0x20501a91` + + + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | address | | + diff --git a/docs/Contracts/Plugin/plugins/SecurityRegistry.md b/docs/Contracts/Plugin/plugins/SecurityRegistry.md new file mode 100644 index 000000000..edcb10929 --- /dev/null +++ b/docs/Contracts/Plugin/plugins/SecurityRegistry.md @@ -0,0 +1,117 @@ + + +# SecurityRegistry + + + + + + +**Inherits:** [ISecurityRegistry](../interfaces/plugins/ISecurityRegistry.md) + +## Public variables +### algebraFactory +```solidity +address immutable algebraFactory +``` +**Selector**: `0xa7b64b04` + + + + +### GUARD +```solidity +bytes32 constant GUARD = 0x25bca7788d8c23352e368ccd4774eb5b5fc3d40422de2c14e98631ab71f33415 +``` +**Selector**: `0xfe3348f9` + + + + +### globalStatus +```solidity +enum ISecurityRegistry.Status globalStatus +``` +**Selector**: `0xb73f7951` + + + + +### isPoolStatusOverrided +```solidity +bool isPoolStatusOverrided +``` +**Selector**: `0x853b8c5c` + + + + +### poolStatus +```solidity +mapping(address => enum ISecurityRegistry.Status) poolStatus +``` +**Selector**: `0x3c38ccbb` + + + + + +## Functions +### constructor + +```solidity +constructor(address _algebraFactory) public +``` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| _algebraFactory | address | | + +### setPoolsStatus + +```solidity +function setPoolsStatus(address[] pools, enum ISecurityRegistry.Status[] newStatuses) external +``` +**Selector**: `0x6547cd53` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pools | address[] | | +| newStatuses | enum ISecurityRegistry.Status[] | | + +### setGlobalStatus + +```solidity +function setGlobalStatus(enum ISecurityRegistry.Status newStatus) external +``` +**Selector**: `0x24b62cd0` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newStatus | enum ISecurityRegistry.Status | | + +### getPoolStatus + +```solidity +function getPoolStatus(address pool) external view returns (enum ISecurityRegistry.Status) +``` +**Selector**: `0x15d9d2f9` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| pool | address | | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| [0] | enum ISecurityRegistry.Status | | + diff --git a/docs/Contracts/Plugin/plugins/SlidingFeePlugin.md b/docs/Contracts/Plugin/plugins/SlidingFeePlugin.md new file mode 100644 index 000000000..b0cd05dca --- /dev/null +++ b/docs/Contracts/Plugin/plugins/SlidingFeePlugin.md @@ -0,0 +1,80 @@ + + +# SlidingFeePlugin + + + + + + +**Inherits:** AlgebraBasePlugin [ISlidingFeePlugin](../interfaces/plugins/ISlidingFeePlugin.md) + +## Structs +### FeeFactors + + + +```solidity +struct FeeFactors { + uint128 zeroToOneFeeFactor; + uint128 oneToZeroFeeFactor; +} +``` + + +## Public variables +### s_feeFactors +```solidity +struct SlidingFeePlugin.FeeFactors s_feeFactors +``` +**Selector**: `0x58e31bfd` + + + + +### s_priceChangeFactor +```solidity +uint16 s_priceChangeFactor +``` +**Selector**: `0x7b3de5c6` + + + + +### s_baseFee +```solidity +uint16 s_baseFee +``` +**Selector**: `0x08cd1975` + + + + + +## Functions +### setPriceChangeFactor + +```solidity +function setPriceChangeFactor(uint16 newPriceChangeFactor) external +``` +**Selector**: `0xa37a8456` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newPriceChangeFactor | uint16 | | + +### setBaseFee + +```solidity +function setBaseFee(uint16 newBaseFee) external +``` +**Selector**: `0x3b586c7f` + + + +| Name | Type | Description | +| ---- | ---- | ----------- | +| newBaseFee | uint16 | | + diff --git a/docs/Contracts/Plugin/plugins/VolatilityOraclePlugin.md b/docs/Contracts/Plugin/plugins/VolatilityOraclePlugin.md new file mode 100644 index 000000000..e784f9dae --- /dev/null +++ b/docs/Contracts/Plugin/plugins/VolatilityOraclePlugin.md @@ -0,0 +1,127 @@ + + +# VolatilityOraclePlugin + + +Algebra Integral 1.2.2 VolatilityOraclePlugin plugin + +This contract stores timepoints and calculates adaptive fee and statistical averages + +**Inherits:** AlgebraBasePlugin [IVolatilityOracle](../interfaces/plugins/IVolatilityOracle.md) + +## Public variables +### timepoints +```solidity +struct VolatilityOracle.Timepoint[65536] timepoints +``` +**Selector**: `0x74eceae6` + +Returns data belonging to a certain timepoint + +*Developer note: There is more convenient function to fetch a timepoint: getTimepoints(). Which requires not an index but seconds* + +### timepointIndex +```solidity +uint16 timepointIndex +``` +**Selector**: `0x0786feb6` + +Returns the index of the last timepoint that was written. + + +### lastTimepointTimestamp +```solidity +uint32 lastTimepointTimestamp +``` +**Selector**: `0xf5985d35` + +Returns the timestamp of the last timepoint that was written. + + +### isInitialized +```solidity +bool isInitialized +``` +**Selector**: `0x392e53cd` + +Returns information about whether oracle is initialized + + + +## Functions +### initialize + +```solidity +function initialize() external +``` +**Selector**: `0x8129fc1c` + +Initialize the plugin externally + +*Developer note: This function allows to initialize the plugin if it was created after the pool was created* + +### getSingleTimepoint + +```solidity +function getSingleTimepoint(uint32 secondsAgo) external view returns (int56 tickCumulative, uint88 volatilityCumulative) +``` +**Selector**: `0x88f2e862` + + + +*Developer note: Reverts if a timepoint at or before the desired timepoint timestamp does not exist. +0 may be passed as `secondsAgo' to return the current cumulative values. +If called with a timestamp falling between two timepoints, returns the counterfactual accumulator values +at exactly the timestamp between the two timepoints. +`volatilityCumulative` values for timestamps after the last timepoint _should not_ be compared because they may differ due to interpolation errors* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| secondsAgo | uint32 | The amount of time to look back, in seconds, at which point to return a timepoint | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| tickCumulative | int56 | The cumulative tick since the pool was first initialized, as of `secondsAgo` | +| volatilityCumulative | uint88 | The cumulative volatility value since the pool was first initialized, as of `secondsAgo` | + +### getTimepoints + +```solidity +function getTimepoints(uint32[] secondsAgos) external view returns (int56[] tickCumulatives, uint88[] volatilityCumulatives) +``` +**Selector**: `0x9d3a5241` + +Returns the accumulator values as of each time seconds ago from the given time in the array of `secondsAgos` + +*Developer note: Reverts if `secondsAgos` > oldest timepoint +`volatilityCumulative` values for timestamps after the last timepoint _should not_ be compared because they may differ due to interpolation errors* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| secondsAgos | uint32[] | Each amount of time to look back, in seconds, at which point to return a timepoint | + +**Returns:** + +| Name | Type | Description | +| ---- | ---- | ----------- | +| tickCumulatives | int56[] | The cumulative tick since the pool was first initialized, as of each `secondsAgo` | +| volatilityCumulatives | uint88[] | The cumulative volatility values since the pool was first initialized, as of each `secondsAgo` | + +### prepayTimepointsStorageSlots + +```solidity +function prepayTimepointsStorageSlots(uint16 startIndex, uint16 amount) external +``` +**Selector**: `0xda705235` + +Fills uninitialized timepoints with nonzero value + +*Developer note: Can be used to reduce the gas cost of future swaps* + +| Name | Type | Description | +| ---- | ---- | ----------- | +| startIndex | uint16 | The start index, must be not initialized | +| amount | uint16 | of slots to fill, startIndex + amount must be <= type(uint16).max | + diff --git a/hardhat.base.config.ts b/hardhat.base.config.ts index babb1010b..fa3e22ddb 100644 --- a/hardhat.base.config.ts +++ b/hardhat.base.config.ts @@ -87,9 +87,9 @@ export default { chainId: 41, accounts: [`0x${MNEMONIC || '1000000000000000000000000000000000000000000000000000000000000000'}`], }, - beraTestnet: { - url: `https://artio.rpc.berachain.com/`, - chainId: 80085, + baseTestnet: { + url: `https://base-sepolia-rpc.publicnode.com`, + chainId: 84532, accounts: [`0x${MNEMONIC || '1000000000000000000000000000000000000000000000000000000000000000'}`], }, maticMainnet: { @@ -117,6 +117,14 @@ export default { browserURL: 'https://seitrace.com/', }, }, + { + network: 'baseTestnet', + chainId: 84532, + urls: { + apiURL: 'https://api-sepolia.basescan.org/api', + browserURL: 'https://sepolia.basescan.org/', + }, + }, { network: 'mode', chainId: 34443, diff --git a/src/core/contracts/AlgebraCommunityVault.sol b/src/core/contracts/AlgebraCommunityVault.sol index 64bb8b7bc..bd7618921 100644 --- a/src/core/contracts/AlgebraCommunityVault.sol +++ b/src/core/contracts/AlgebraCommunityVault.sol @@ -10,7 +10,7 @@ import './interfaces/vault/IAlgebraCommunityVault.sol'; /// @title Algebra community fee vault /// @notice Community fee from pools is sent here, if it is enabled /// @dev Role system is used to withdraw tokens -/// @dev Version: Algebra Integral 1.2.1 +/// @dev Version: Algebra Integral 1.2.2 contract AlgebraCommunityVault is IAlgebraCommunityVault { /// @dev The role can be granted in AlgebraFactory bytes32 public constant COMMUNITY_FEE_WITHDRAWER_ROLE = keccak256('COMMUNITY_FEE_WITHDRAWER'); diff --git a/src/core/contracts/AlgebraFactory.sol b/src/core/contracts/AlgebraFactory.sol index 7466deda6..d856e707c 100644 --- a/src/core/contracts/AlgebraFactory.sol +++ b/src/core/contracts/AlgebraFactory.sol @@ -17,7 +17,7 @@ import '@openzeppelin/contracts/security/ReentrancyGuard.sol'; /// @title Algebra factory /// @notice Is used to deploy pools and its plugins -/// @dev Version: Algebra Integral 1.2.1 +/// @dev Version: Algebra Integral 1.2.2 contract AlgebraFactory is IAlgebraFactory, Ownable2Step, AccessControlEnumerable, ReentrancyGuard { /// @inheritdoc IAlgebraFactory bytes32 public constant override POOLS_ADMINISTRATOR_ROLE = keccak256('POOLS_ADMINISTRATOR'); // it`s here for the public visibility of the value @@ -57,7 +57,7 @@ contract AlgebraFactory is IAlgebraFactory, Ownable2Step, AccessControlEnumerabl /// @inheritdoc IAlgebraFactory /// @dev keccak256 of AlgebraPool init bytecode. Used to compute pool address deterministically - bytes32 public constant POOL_INIT_CODE_HASH = 0xa18736c3ee97fe3c96c9428c0cc2a9116facec18e84f95f9da30543f8238a782; + bytes32 public constant POOL_INIT_CODE_HASH = 0x62441ebe4e4315cf3d49d5957f94d66b253dbabe7006f34ad7f70947e60bf15c; constructor(address _poolDeployer) { require(_poolDeployer != address(0)); diff --git a/src/core/contracts/AlgebraPool.sol b/src/core/contracts/AlgebraPool.sol index f4c4f6146..1ab8d3675 100644 --- a/src/core/contracts/AlgebraPool.sol +++ b/src/core/contracts/AlgebraPool.sol @@ -21,7 +21,7 @@ import './interfaces/IAlgebraFactory.sol'; /// @title Algebra concentrated liquidity pool /// @notice This contract is responsible for liquidity positions, swaps and flashloans -/// @dev Version: Algebra Integral 1.2.1 +/// @dev Version: Algebra Integral 1.2.2 contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positions, SwapCalculation, ReservesManager { using SafeCast for uint256; using SafeCast for uint128; @@ -165,8 +165,11 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio } } - if (amount | amount0 | amount1 != 0) emit Burn(msg.sender, bottomTick, topTick, amount, amount0, amount1, pluginFee); - + if (amount | amount0 | amount1 != 0) { + emit BurnFee(msg.sender, pluginFee); + emit Burn(msg.sender, bottomTick, topTick, amount, amount0, amount1); + } + _unlock(); _afterModifyPos(msg.sender, bottomTick, topTick, liquidityDelta, amount0, amount1, data); } @@ -385,7 +388,8 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio uint24 overrideFee, uint24 pluginFee ) private { - emit Swap(msg.sender, recipient, amount0, amount1, newPrice, newLiquidity, newTick, overrideFee, pluginFee); + emit SwapFee(msg.sender, overrideFee, pluginFee); + emit Swap(msg.sender, recipient, amount0, amount1, newPrice, newLiquidity, newTick); } function _beforeSwap( diff --git a/src/core/contracts/AlgebraPoolDeployer.sol b/src/core/contracts/AlgebraPoolDeployer.sol index 304e5df6c..866f5c069 100644 --- a/src/core/contracts/AlgebraPoolDeployer.sol +++ b/src/core/contracts/AlgebraPoolDeployer.sol @@ -8,7 +8,7 @@ import './AlgebraPool.sol'; /// @title Algebra pool deployer /// @notice Is used by AlgebraFactory to deploy pools -/// @dev Version: Algebra Integral 1.2.1 +/// @dev Version: Algebra Integral 1.2.2 contract AlgebraPoolDeployer is IAlgebraPoolDeployer { /// @dev two storage slots for dense cache packing bytes32 private cache0; diff --git a/src/core/contracts/interfaces/pool/IAlgebraPoolEvents.sol b/src/core/contracts/interfaces/pool/IAlgebraPoolEvents.sol index 2385a2336..a4f04c962 100644 --- a/src/core/contracts/interfaces/pool/IAlgebraPoolEvents.sol +++ b/src/core/contracts/interfaces/pool/IAlgebraPoolEvents.sol @@ -46,17 +46,20 @@ interface IAlgebraPoolEvents { /// @param liquidityAmount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn - /// @param pluginFee The fee to be sent to the plugin event Burn( address indexed owner, int24 indexed bottomTick, int24 indexed topTick, uint128 liquidityAmount, uint256 amount0, - uint256 amount1, - uint24 pluginFee + uint256 amount1 ); + /// @notice Emitted when a plugin fee is applied during a burn + /// @param owner The owner of the position + /// @param pluginFee The fee to be sent to the plugin + event BurnFee(address indexed owner, uint24 pluginFee); + /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap @@ -65,8 +68,7 @@ interface IAlgebraPoolEvents { /// @param price The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap - /// @param overrideFee The fee to be applied to the trade - /// @param pluginFee The fee to be sent to the plugin + event Swap( address indexed sender, address indexed recipient, @@ -74,11 +76,15 @@ interface IAlgebraPoolEvents { int256 amount1, uint160 price, uint128 liquidity, - int24 tick, - uint24 overrideFee, - uint24 pluginFee + int24 tick ); + /// @notice Emitted by the pool after any swaps + /// @param sender The address that initiated the swap + /// @param overrideFee The fee to be applied to the trade + /// @param pluginFee The fee to be sent to the plugin + event SwapFee(address indexed sender, uint24 overrideFee, uint24 pluginFee); + /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash diff --git a/src/core/package.json b/src/core/package.json index fa8386512..c6de827a2 100644 --- a/src/core/package.json +++ b/src/core/package.json @@ -5,7 +5,7 @@ "publishConfig": { "access": "public" }, - "version": "1.2.5", + "version": "1.2.9", "keywords": [ "algebra" ], @@ -34,9 +34,11 @@ "precommit": "pretty-quick --staged --pattern '**/*.sol' && hardhat compile && node ../../scripts/updatePoolHash.js", "solhint": "solhint ./contracts/**/*.sol", "compile": "hardhat compile", + "build": "npx tsc", "test": "hardhat test --parallel", "coverage": "hardhat coverage --solcoverjs ./.solcover.js", - "validateNatspec": "hardhat validateOutput" + "validateNatspec": "hardhat validateOutput", + "prepublishOnly": "npm run compile && npm run build" }, "engines": { "npm": ">=8.0.0", diff --git a/src/core/test/AlgebraPool.spec.ts b/src/core/test/AlgebraPool.spec.ts index 5cd9e4fac..5eef0299d 100644 --- a/src/core/test/AlgebraPool.spec.ts +++ b/src/core/test/AlgebraPool.spec.ts @@ -1131,7 +1131,7 @@ describe('AlgebraPool', () => { await swapExact1For0(expandTo18Decimals(2), other.address); await expect(pool.burn(0, 120, expandTo18Decimals(1), '0x')) .to.emit(pool, 'Burn') - .withArgs(wallet.address, 0, 120, expandTo18Decimals(1), 0, '6017734268818165', 0) + .withArgs(wallet.address, 0, 120, expandTo18Decimals(1), 0, '6017734268818165') .to.not.emit(token0, 'Transfer') .to.not.emit(token1, 'Transfer'); await expect(pool.collect(wallet.address, 0, 120, MaxUint128, MaxUint128)) @@ -1149,7 +1149,7 @@ describe('AlgebraPool', () => { await swapExact0For1(expandTo18Decimals(2), other.address); await expect(pool.burn(-120, 0, expandTo18Decimals(1), '0x')) .to.emit(pool, 'Burn') - .withArgs(wallet.address, -120, 0, expandTo18Decimals(1), '6017734268818165', 0, 0) + .withArgs(wallet.address, -120, 0, expandTo18Decimals(1), '6017734268818165', 0) .to.not.emit(token0, 'Transfer') .to.not.emit(token1, 'Transfer'); await expect(pool.collect(wallet.address, -120, 0, MaxUint128, MaxUint128)) @@ -1169,7 +1169,7 @@ describe('AlgebraPool', () => { await swapExact1For0(expandTo18Decimals(2), other.address); await expect(pool.burn(0, 120, expandTo18Decimals(1), '0x')) .to.emit(pool, 'Burn') - .withArgs(wallet.address, 0, 120, expandTo18Decimals(1), 0, '6017734268818165', 0) + .withArgs(wallet.address, 0, 120, expandTo18Decimals(1), 0, '6017734268818165') .to.not.emit(token0, 'Transfer') .to.not.emit(token1, 'Transfer'); await expect(pool.collect(wallet.address, 0, 120, MaxUint128, MaxUint128)) @@ -1186,7 +1186,7 @@ describe('AlgebraPool', () => { await swapExact0For1(expandTo18Decimals(2), other.address); await expect(pool.burn(-120, 0, expandTo18Decimals(1), '0x')) .to.emit(pool, 'Burn') - .withArgs(wallet.address, -120, 0, expandTo18Decimals(1),'6017734268818165', 0, 0) + .withArgs(wallet.address, -120, 0, expandTo18Decimals(1),'6017734268818165', 0) .to.not.emit(token0, 'Transfer') .to.not.emit(token1, 'Transfer'); await expect(pool.collect(wallet.address, -120, 0, MaxUint128, MaxUint128)) @@ -2055,7 +2055,7 @@ describe('AlgebraPool', () => { await swapExact1For0(expandTo18Decimals(1), wallet.address); await expect(pool.burn(120000, 121200, liquidityAmount, '0x')) .to.emit(pool, 'Burn') - .withArgs(wallet.address, 120000, 121200, liquidityAmount, '30012388425661', '999499999999999999', 0) + .withArgs(wallet.address, 120000, 121200, liquidityAmount, '30012388425661', '999499999999999999') .to.not.emit(token0, 'Transfer') .to.not.emit(token1, 'Transfer'); expect((await pool.globalState()).tick).to.eq(120197); @@ -2066,7 +2066,7 @@ describe('AlgebraPool', () => { await swapExact0For1(expandTo18Decimals(1), wallet.address); await expect(pool.burn(-121200, -120000, liquidityAmount, '0x')) .to.emit(pool, 'Burn') - .withArgs(wallet.address, -121200, -120000, liquidityAmount, '999499999999999999', '30012388425661', 0) + .withArgs(wallet.address, -121200, -120000, liquidityAmount, '999499999999999999', '30012388425661') .to.not.emit(token0, 'Transfer') .to.not.emit(token1, 'Transfer'); expect((await pool.globalState()).tick).to.eq(-120198); @@ -2666,7 +2666,10 @@ describe('AlgebraPool', () => { -497487437185929648n, 39813146992092631956554748913n, 1000000000000000000n, - -13764, + -13764 + ) + await expect(swapExact0For1(expandTo18Decimals(1), wallet.address)).to.be.emit(pool, 'SwapFee').withArgs( + await swapTarget.getAddress(), 4000, 6000 ) @@ -2676,8 +2679,8 @@ describe('AlgebraPool', () => { await poolPlugin.setPluginFees(4000, 6000); await mint(wallet.address, 60, 120, expandTo18Decimals(1)); await expect(pool.burn(60, 120, expandTo18Decimals(1), '0x')) - .to.emit(pool, 'Burn') - .withArgs(wallet.address, 60, 120, expandTo18Decimals(1), '2968464507771288', 0, 6000) + .to.emit(pool, 'BurnFee') + .withArgs(wallet.address, 6000) }) diff --git a/src/core/test/AlgebraPool.swaps.spec.ts b/src/core/test/AlgebraPool.swaps.spec.ts index d4121e3ad..709926733 100644 --- a/src/core/test/AlgebraPool.swaps.spec.ts +++ b/src/core/test/AlgebraPool.swaps.spec.ts @@ -701,9 +701,7 @@ describe('AlgebraPool swap tests', () => { poolBalance1Delta, globalStateAfter.price, liquidityAfter, - globalStateAfter.tick, - 0, - 0 + globalStateAfter.tick ); const executionPrice = new Decimal(poolBalance1Delta.toString()).div(poolBalance0Delta.toString()).mul(-1); diff --git a/src/core/test/__snapshots__/AlgebraFactory.spec.ts.snap b/src/core/test/__snapshots__/AlgebraFactory.spec.ts.snap index f6f4a6b00..eecca655c 100644 --- a/src/core/test/__snapshots__/AlgebraFactory.spec.ts.snap +++ b/src/core/test/__snapshots__/AlgebraFactory.spec.ts.snap @@ -1,13 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AlgebraFactory #createCustomPool gas [ @skip-on-coverage ] 1`] = `4763938`; +exports[`AlgebraFactory #createCustomPool gas [ @skip-on-coverage ] 1`] = `4782614`; -exports[`AlgebraFactory #createCustomPool gas for second pool [ @skip-on-coverage ] 1`] = `4763938`; +exports[`AlgebraFactory #createCustomPool gas for second pool [ @skip-on-coverage ] 1`] = `4782614`; -exports[`AlgebraFactory #createPool gas [ @skip-on-coverage ] 1`] = `4751741`; +exports[`AlgebraFactory #createPool gas [ @skip-on-coverage ] 1`] = `4770418`; -exports[`AlgebraFactory #createPool gas for second pool [ @skip-on-coverage ] 1`] = `4751741`; +exports[`AlgebraFactory #createPool gas for second pool [ @skip-on-coverage ] 1`] = `4770418`; exports[`AlgebraFactory factory bytecode size [ @skip-on-coverage ] 1`] = `10699`; -exports[`AlgebraFactory pool bytecode size [ @skip-on-coverage ] 1`] = `22493`; +exports[`AlgebraFactory pool bytecode size [ @skip-on-coverage ] 1`] = `22586`; diff --git a/src/core/test/__snapshots__/AlgebraPool.gas.spec.ts.snap b/src/core/test/__snapshots__/AlgebraPool.gas.spec.ts.snap index f64e7999e..64e5d97c3 100644 --- a/src/core/test/__snapshots__/AlgebraPool.gas.spec.ts.snap +++ b/src/core/test/__snapshots__/AlgebraPool.gas.spec.ts.snap @@ -2,29 +2,29 @@ exports[`AlgebraPool gas tests [ @skip-on-coverage ] #setFee by owner 1`] = `33263`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price burn entire position after some time passes 1`] = `117308`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price burn entire position after some time passes 1`] = `118239`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price burn when only position using ticks 1`] = `117308`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price burn when only position using ticks 1`] = `118239`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price entire position burn but other positions are using the ticks 1`] = `111161`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price entire position burn but other positions are using the ticks 1`] = `112324`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price partial position burn 1`] = `115961`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn above current price partial position burn 1`] = `117124`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price burn entire position after some time passes 1`] = `127188`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price burn entire position after some time passes 1`] = `128118`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price burn when only position using ticks 1`] = `127188`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price burn when only position using ticks 1`] = `128118`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price entire position burn but other positions are using the ticks 1`] = `115569`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price entire position burn but other positions are using the ticks 1`] = `116732`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price partial position burn 1`] = `120369`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn around current price partial position burn 1`] = `121532`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price burn entire position after some time passes 1`] = `126744`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price burn entire position after some time passes 1`] = `127675`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price burn when only position using ticks 1`] = `126744`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price burn when only position using ticks 1`] = `127675`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price entire position burn but other positions are using the ticks 1`] = `111822`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price entire position burn but other positions are using the ticks 1`] = `112985`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price partial position burn 1`] = `116622`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #burn below current price partial position burn 1`] = `117785`; exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #collect close to worst case 1`] = `52641`; @@ -56,69 +56,69 @@ exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #mint below curr exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #poke best case 1`] = `63735`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `103944`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `105101`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block with no tick movement 1`] = `103913`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block with no tick movement 1`] = `105070`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `119689`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `120846`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `153203`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `154360`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `104082`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `105239`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `153203`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `154360`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `172403`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `173560`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `103944`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `105101`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block with no tick movement 1`] = `103908`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block with no tick movement 1`] = `105065`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `120513`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `121670`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `154054`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `155211`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 several large swaps with pauses 1`] = `172403`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 several large swaps with pauses 1`] = `173560`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 small swap after several large swaps with pauses 1`] = `103782`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 small swap after several large swaps with pauses 1`] = `104939`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 small swap with filled dataStorage 1`] = `103778`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact0For1 small swap with filled dataStorage 1`] = `104935`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `104005`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `105162`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 first swap in block with no tick movement 1`] = `103953`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 first swap in block with no tick movement 1`] = `105110`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 second swap in block with no tick movement 1`] = `103969`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 second swap in block with no tick movement 1`] = `105126`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 with plugin fee on first swap in block moves tick, no initialized crossings, with transfer 1`] = `158141`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 with plugin fee on first swap in block moves tick, no initialized crossings, with transfer 1`] = `159301`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 with plugin fee on first swap in block with no tick movement, with transfer 1`] = `158089`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 with plugin fee on first swap in block with no tick movement, with transfer 1`] = `159249`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 with plugin fee on first swap in block with no tick movement, without transfer 1`] = `132629`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swapExact1For0 with plugin fee on first swap in block with no tick movement, without transfer 1`] = `133789`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price burn entire position after some time passes 1`] = `117308`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price burn entire position after some time passes 1`] = `118239`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price burn when only position using ticks 1`] = `117308`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price burn when only position using ticks 1`] = `118239`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price entire position burn but other positions are using the ticks 1`] = `111161`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price entire position burn but other positions are using the ticks 1`] = `112324`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price partial position burn 1`] = `115961`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn above current price partial position burn 1`] = `117124`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price burn entire position after some time passes 1`] = `127188`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price burn entire position after some time passes 1`] = `128118`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price burn when only position using ticks 1`] = `127188`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price burn when only position using ticks 1`] = `128118`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price entire position burn but other positions are using the ticks 1`] = `115569`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price entire position burn but other positions are using the ticks 1`] = `116732`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price partial position burn 1`] = `120369`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn around current price partial position burn 1`] = `121532`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price burn entire position after some time passes 1`] = `126744`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price burn entire position after some time passes 1`] = `127675`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price burn when only position using ticks 1`] = `126744`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price burn when only position using ticks 1`] = `127675`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price entire position burn but other positions are using the ticks 1`] = `111822`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price entire position burn but other positions are using the ticks 1`] = `112985`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price partial position burn 1`] = `116622`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #burn below current price partial position burn 1`] = `117785`; exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #collect close to worst case 1`] = `52641`; @@ -150,42 +150,42 @@ exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #mint below curre exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #poke best case 1`] = `63735`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `112743`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `113900`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block with no tick movement 1`] = `112712`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block with no tick movement 1`] = `113869`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `128725`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `129882`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `162950`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `164107`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `112881`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `114038`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `162950`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `164107`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `182150`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 large swap crossing several initialized ticks second time after some time passes 1`] = `183307`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `112743`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `113900`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block with no tick movement 1`] = `104145`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block with no tick movement 1`] = `105302`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `129549`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `130706`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `163801`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `164958`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 several large swaps with pauses 1`] = `182150`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 several large swaps with pauses 1`] = `183307`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 small swap after several large swaps with pauses 1`] = `104019`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 small swap after several large swaps with pauses 1`] = `105176`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 small swap with filled dataStorage 1`] = `104015`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact0For1 small swap with filled dataStorage 1`] = `105172`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `112815`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `113972`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 first swap in block with no tick movement 1`] = `112763`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 first swap in block with no tick movement 1`] = `113920`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 second swap in block with no tick movement 1`] = `104206`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 second swap in block with no tick movement 1`] = `105363`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 with plugin fee on first swap in block moves tick, no initialized crossings, with transfer 1`] = `169456`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 with plugin fee on first swap in block moves tick, no initialized crossings, with transfer 1`] = `170616`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 with plugin fee on first swap in block with no tick movement, with transfer 1`] = `169404`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 with plugin fee on first swap in block with no tick movement, with transfer 1`] = `170564`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 with plugin fee on first swap in block with no tick movement, without transfer 1`] = `136334`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swapExact1For0 with plugin fee on first swap in block with no tick movement, without transfer 1`] = `137494`; diff --git a/src/farming/contracts/FarmingCenter.sol b/src/farming/contracts/FarmingCenter.sol index 1118cac89..fd60a6f3d 100644 --- a/src/farming/contracts/FarmingCenter.sol +++ b/src/farming/contracts/FarmingCenter.sol @@ -12,7 +12,7 @@ import '@cryptoalgebra/integral-base-plugin/contracts/interfaces/plugins/IFarmin import './interfaces/IFarmingCenter.sol'; import './libraries/IncentiveId.sol'; -/// @title Algebra Integral 1.2.1 main farming contract +/// @title Algebra Integral 1.2.2 main farming contract /// @dev Manages farmings and performs entry, exit and other actions. contract FarmingCenter is IFarmingCenter, IPositionFollower, Multicall { /// @inheritdoc IFarmingCenter diff --git a/src/farming/contracts/farmings/AlgebraEternalFarming.sol b/src/farming/contracts/farmings/AlgebraEternalFarming.sol index 8cb81d78a..54381f914 100644 --- a/src/farming/contracts/farmings/AlgebraEternalFarming.sol +++ b/src/farming/contracts/farmings/AlgebraEternalFarming.sol @@ -23,7 +23,7 @@ import '../libraries/NFTPositionInfo.sol'; import './EternalVirtualPool.sol'; -/// @title Algebra Integral 1.2.1 eternal (v2-like) farming +/// @title Algebra Integral 1.2.2 eternal (v2-like) farming /// @notice Manages rewards and virtual pools contract AlgebraEternalFarming is IAlgebraEternalFarming { using SafeCast for int256; diff --git a/src/farming/contracts/farmings/EternalVirtualPool.sol b/src/farming/contracts/farmings/EternalVirtualPool.sol index c62a1c247..dd25b8cd0 100644 --- a/src/farming/contracts/farmings/EternalVirtualPool.sol +++ b/src/farming/contracts/farmings/EternalVirtualPool.sol @@ -12,7 +12,7 @@ import '@cryptoalgebra/integral-core/contracts/interfaces/pool/IAlgebraPoolError import '../base/VirtualTickStructure.sol'; -/// @title Algebra Integral 1.2.1 eternal virtual pool +/// @title Algebra Integral 1.2.2 eternal virtual pool /// @notice used to track active liquidity in farming and distribute rewards contract EternalVirtualPool is Timestamp, VirtualTickStructure { using TickManagement for mapping(int24 => TickManagement.Tick); diff --git a/src/farming/package-lock.json b/src/farming/package-lock.json index e54c18e91..ea307c0f4 100644 --- a/src/farming/package-lock.json +++ b/src/farming/package-lock.json @@ -9,7 +9,7 @@ "version": "1.2.1", "license": "GPL-3.0-or-later", "dependencies": { - "@cryptoalgebra/integral-core": "1.2.1", + "@cryptoalgebra/integral-periphery": "1.2.1", "@openzeppelin/contracts": "4.9.3" }, "devDependencies": { @@ -44,6 +44,15 @@ "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", "dev": true }, + "node_modules/@uniswap/v2-core": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@uniswap/v2-core/-/v2-core-1.0.1.tgz", + "integrity": "sha512-MtybtkUPSyysqLY2U210NBDeCHX+ltHt3oADGdjqoThZaFRDKwM6k1Nb3F0A3hk5hwuQvytFWhrWHOEq6nVJ8Q==", + "license": "GPL-3.0-or-later", + "engines": { + "node": ">=10" + } + }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", diff --git a/src/farming/package.json b/src/farming/package.json index 827823031..bc26c2e96 100644 --- a/src/farming/package.json +++ b/src/farming/package.json @@ -2,7 +2,7 @@ "name": "@cryptoalgebra/integral-farming", "description": "Liquidity mining contracts for Algebra Integral protocol", "license": "GPL-3.0-or-later", - "version": "1.2.1", + "version": "1.2.4", "publishConfig": { "access": "public" }, @@ -24,9 +24,9 @@ ], "dependencies": { "@openzeppelin/contracts": "4.9.3", - "@cryptoalgebra/integral-core": "~1.2.1", - "@cryptoalgebra/integral-periphery": "~1.2.1", - "@cryptoalgebra/integral-base-plugin": "~1.2.1" + "@cryptoalgebra/integral-core": "~1.2.7", + "@cryptoalgebra/integral-periphery": "~1.2.4", + "@cryptoalgebra/integral-base-plugin": "~1.2.4" }, "devDependencies": { "@types/lodash": "^4.14.170", diff --git a/src/farming/test/helpers/index.ts b/src/farming/test/helpers/index.ts index f4e7a09b4..3becc17f8 100644 --- a/src/farming/test/helpers/index.ts +++ b/src/farming/test/helpers/index.ts @@ -236,6 +236,7 @@ export class HelperCommands { await this.nft.connect(params.lp).decreaseLiquidity( { + pluginData: "0x", tokenId: params.tokenId, liquidity, amount0Min: 0, @@ -347,6 +348,7 @@ export class HelperCommands { await this.router.connect(actor).exactInput( { + pluginData: ["0x"], recipient: actor.address, deadline: MaxUint256, path, @@ -406,6 +408,7 @@ export class HelperCommands { await this.router.connect(actor).exactInputSingle( { + pluginData: "0x", recipient: actor.address, deadline: MaxUint256, tokenIn: zto ? tok0Address : tok1Address, @@ -465,6 +468,7 @@ export class HelperCommands { await this.router.connect(actor).exactInput( { + pluginData: ["0x"], recipient: actor.address, deadline: MaxUint256, path, @@ -525,6 +529,7 @@ export class HelperCommands { return this.router.connect(actor).exactInput( { + pluginData: ["0x"], recipient: actor.address, deadline: MaxUint256, path, diff --git a/src/farming/test/shared/fixtures.ts b/src/farming/test/shared/fixtures.ts index 3fdc27682..b835d6e32 100644 --- a/src/farming/test/shared/fixtures.ts +++ b/src/farming/test/shared/fixtures.ts @@ -180,6 +180,7 @@ export const mintPosition = async ( const receipt = await ( await nft.mint( { + pluginData: "0x", token0: mintParams.token0, token1: mintParams.token1, deployer: ZERO_ADDRESS, diff --git a/src/farming/test/unit/EternalFarms.spec.ts b/src/farming/test/unit/EternalFarms.spec.ts index 51ac99c6b..cbc0becb2 100644 --- a/src/farming/test/unit/EternalFarms.spec.ts +++ b/src/farming/test/unit/EternalFarms.spec.ts @@ -618,6 +618,7 @@ describe('unit/EternalFarms', () => { let farmBefore = await context.eternalFarming.farms(tokenId, incentiveId); await context.nft.connect(lpUser0).increaseLiquidity({ + pluginData: "0x", tokenId: tokenId, amount0Desired: amountDesired, amount1Desired: amountDesired, @@ -714,6 +715,7 @@ describe('unit/EternalFarms', () => { await context.nft.connect(lpUser0).approveForFarming(tokenId2, true, context.farmingCenter); await context.nft.connect(lpUser0).decreaseLiquidity({ + pluginData: "0x", tokenId: tokenId2, liquidity: (await context.nft.positions(tokenId2)).liquidity, amount0Min: 0, @@ -2044,6 +2046,7 @@ describe('unit/EternalFarms', () => { await erc20Helper.ensureBalancesAndApprovals(lpUser0, [token0, token1], amountDesired, await context.router.getAddress()); const swapData = { + pluginData: "0x", tokenIn: tokenReentrant, tokenOut: context.token1, deployer: ZERO_ADDRESS, diff --git a/src/farming/test/unit/FarmingCenter.spec.ts b/src/farming/test/unit/FarmingCenter.spec.ts index c1542518a..7ce4d11d8 100644 --- a/src/farming/test/unit/FarmingCenter.spec.ts +++ b/src/farming/test/unit/FarmingCenter.spec.ts @@ -209,6 +209,7 @@ describe('unit/FarmingCenter', () => { it('works if liquidity decreased', async () => { await expect( context.nft.connect(lpUser0).decreaseLiquidity({ + pluginData: "0x", tokenId: tokenIdEternal, liquidity: 100, amount0Min: 0, @@ -228,6 +229,7 @@ describe('unit/FarmingCenter', () => { await expect( context.nft.connect(lpUser0).decreaseLiquidity({ + pluginData: "0x", tokenId: tokenIdEternal, liquidity: 5, amount0Min: 0, @@ -244,6 +246,7 @@ describe('unit/FarmingCenter', () => { await expect( context.nft.connect(lpUser0).decreaseLiquidity({ + pluginData: "0x", tokenId: tokenIdEternal, liquidity: 5, amount0Min: 0, @@ -299,6 +302,7 @@ describe('unit/FarmingCenter', () => { await expect( context.nft.connect(lpUser0).decreaseLiquidity({ + pluginData: "0x", tokenId: tokenIdEternal, liquidity: 5, amount0Min: 0, @@ -350,6 +354,7 @@ describe('unit/FarmingCenter', () => { await expect( context.nft.connect(lpUser0).decreaseLiquidity({ + pluginData: "0x", tokenId: tokenIdEternal, liquidity: 5, amount0Min: 0, @@ -367,6 +372,7 @@ describe('unit/FarmingCenter', () => { await expect( context.nft.connect(lpUser0).increaseLiquidity({ + pluginData: "0x", tokenId: tokenIdEternal, amount0Desired: 100, amount1Desired: 100, @@ -381,6 +387,7 @@ describe('unit/FarmingCenter', () => { const liquidity = (await context.nft.positions(tokenIdEternal)).liquidity; await expect( context.nft.connect(lpUser0).decreaseLiquidity({ + pluginData: "0x", tokenId: tokenIdEternal, liquidity: liquidity, amount0Min: 0, diff --git a/src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap b/src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap index 13ae62c36..68a9b0d3b 100644 --- a/src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap +++ b/src/farming/test/unit/__snapshots__/EternalFarms.spec.ts.snap @@ -2,6 +2,6 @@ exports[`unit/EternalFarms #claimReward when requesting the full amount has gas cost [ @skip-on-coverage ] 1`] = `60858`; -exports[`unit/EternalFarms #enterFarming works and has gas cost [ @skip-on-coverage ] 1`] = `499827`; +exports[`unit/EternalFarms #enterFarming works and has gas cost [ @skip-on-coverage ] 1`] = `499839`; -exports[`unit/EternalFarms #exitFarming after end time works and has gas cost [ @skip-on-coverage ] 1`] = `177400`; +exports[`unit/EternalFarms #exitFarming after end time works and has gas cost [ @skip-on-coverage ] 1`] = `177412`; diff --git a/src/periphery/contracts/AlgebraCustomPoolEntryPoint.sol b/src/periphery/contracts/AlgebraCustomPoolEntryPoint.sol index bacc6e4d5..4ffffb04b 100644 --- a/src/periphery/contracts/AlgebraCustomPoolEntryPoint.sol +++ b/src/periphery/contracts/AlgebraCustomPoolEntryPoint.sol @@ -7,7 +7,7 @@ import {IAlgebraFactory} from '@cryptoalgebra/integral-core/contracts/interfaces /// @title Algebra custom pool entry point /// @notice Is used to create custom pools -/// @dev Version: Algebra Integral 1.2.1 +/// @dev Version: Algebra Integral 1.2.2 contract AlgebraCustomPoolEntryPoint is IAlgebraCustomPoolEntryPoint { /// @inheritdoc IAlgebraCustomPoolEntryPoint address public immutable override factory; diff --git a/src/periphery/contracts/NonfungiblePositionManager.sol b/src/periphery/contracts/NonfungiblePositionManager.sol index 7cf1c84d6..5a251c36c 100644 --- a/src/periphery/contracts/NonfungiblePositionManager.sol +++ b/src/periphery/contracts/NonfungiblePositionManager.sol @@ -19,7 +19,7 @@ import './base/PeripheryValidation.sol'; import './base/SelfPermit.sol'; import './base/PoolInitializer.sol'; -/// @title Algebra Integral 1.2.1 NFT positions +/// @title Algebra Integral 1.2.2 NFT positions /// @notice Wraps Algebra positions in the ERC721 non-fungible token interface /// @dev Credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-periphery @@ -165,7 +165,8 @@ contract NonfungiblePositionManager is amount0Desired: params.amount0Desired, amount1Desired: params.amount1Desired, amount0Min: params.amount0Min, - amount1Min: params.amount1Min + amount1Min: params.amount1Min, + pluginData: params.pluginData }) ); unchecked { @@ -278,7 +279,8 @@ contract NonfungiblePositionManager is amount1Desired: params.amount1Desired, amount0Min: params.amount0Min, amount1Min: params.amount1Min, - recipient: address(this) + recipient: address(this), + pluginData: params.pluginData }) ); @@ -328,7 +330,7 @@ contract NonfungiblePositionManager is require(positionLiquidity >= params.liquidity); IAlgebraPool pool = IAlgebraPool(_getPoolById(poolId)); - (amount0, amount1) = pool._burnPositionInPool(tickLower, tickUpper, params.liquidity); + (amount0, amount1) = pool._burnPositionInPool(tickLower, tickUpper, params.liquidity, params.pluginData); require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, 'Price slippage check'); @@ -376,7 +378,7 @@ contract NonfungiblePositionManager is (uint128 tokensOwed0, uint128 tokensOwed1) = (position.tokensOwed0, position.tokensOwed1); if (positionLiquidity > 0) { - pool._burnPositionInPool(tickLower, tickUpper, 0); + pool._burnPositionInPool(tickLower, tickUpper, 0, '0x0'); (uint128 _tokensOwed0, uint128 _tokensOwed1) = _updateUncollectedFees( position, pool, diff --git a/src/periphery/contracts/SwapRouter.sol b/src/periphery/contracts/SwapRouter.sol index 3d3555caf..160c14821 100644 --- a/src/periphery/contracts/SwapRouter.sol +++ b/src/periphery/contracts/SwapRouter.sol @@ -15,7 +15,7 @@ import './libraries/Path.sol'; import './libraries/PoolAddress.sol'; import './libraries/CallbackValidation.sol'; -/// @title Algebra Integral 1.2.1 Swap Router +/// @title Algebra Integral 1.2.2 Swap Router /// @notice Router for stateless execution of swaps against Algebra /// @dev Credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-periphery @@ -48,11 +48,18 @@ contract SwapRouter is return IAlgebraPool(PoolAddress.computeAddress(poolDeployer, PoolAddress.getPoolKey(deployer, tokenA, tokenB))); } - struct SwapCallbackData { - bytes path; - address payer; + function skipPluginDataElement(bytes[] memory pluginDataForward) private pure returns (bytes[] memory) { + if (pluginDataForward.length > 0){ + bytes[] memory pluginDataForwardCut = new bytes[](pluginDataForward.length - 1); + for(uint i; i < pluginDataForwardCut.length; i++){ + pluginDataForwardCut[i] = pluginDataForward[i + 1]; + } + return pluginDataForwardCut; + } + return new bytes[](0); } + /// @inheritdoc IAlgebraSwapCallback function algebraSwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata _data) external override { require(amount0Delta > 0 || amount1Delta > 0, 'Zero liquidity swap'); // swaps entirely within 0-liquidity regions are not supported @@ -69,6 +76,8 @@ contract SwapRouter is // either initiate the next swap or pay if (data.path.hasMultiplePools()) { data.path = data.path.skipToken(); + data.pluginData = data.pluginDataForward[0]; + data.pluginDataForward = skipPluginDataElement(data.pluginDataForward); exactOutputInternal(amountToPay, msg.sender, 0, data); } else { amountInCached = amountToPay; @@ -90,7 +99,6 @@ contract SwapRouter is (address tokenIn, address deployer, address tokenOut) = data.path.decodeFirstPool(); bool zeroToOne = tokenIn < tokenOut; - (int256 amount0, int256 amount1) = getPool(deployer, tokenIn, tokenOut).swap( recipient, zeroToOne, @@ -113,8 +121,10 @@ contract SwapRouter is params.recipient, params.limitSqrtPrice, SwapCallbackData({ + pluginData: params.pluginData, path: abi.encodePacked(params.tokenIn, params.deployer, params.tokenOut), - payer: msg.sender + payer: msg.sender, + pluginDataForward: new bytes[](0) }) ); require(amountOut >= params.amountOutMinimum, 'Too little received'); @@ -125,10 +135,9 @@ contract SwapRouter is ExactInputParams memory params ) external payable override checkDeadline(params.deadline) returns (uint256 amountOut) { address payer = msg.sender; // msg.sender pays for the first hop - + uint i; while (true) { bool hasMultiplePools = params.path.hasMultiplePools(); - // the outputs of prior swaps become the inputs to subsequent ones params.amountIn = exactInputInternal( params.amountIn, @@ -136,7 +145,9 @@ contract SwapRouter is 0, SwapCallbackData({ path: params.path.getFirstPool(), // only the first pool in the path is necessary - payer: payer + payer: payer, + pluginData: params.pluginData[i], + pluginDataForward: new bytes[](0) }) ); @@ -144,6 +155,7 @@ contract SwapRouter is if (hasMultiplePools) { payer = address(this); // at this point, the caller has paid params.path = params.path.skipToken(); + i++; } else { amountOut = params.amountIn; break; @@ -158,8 +170,10 @@ contract SwapRouter is ExactInputSingleParams calldata params ) external payable override checkDeadline(params.deadline) returns (uint256 amountOut) { SwapCallbackData memory data = SwapCallbackData({ + pluginData: params.pluginData, path: abi.encodePacked(params.tokenIn, params.deployer, params.tokenOut), - payer: msg.sender + payer: msg.sender, + pluginDataForward: new bytes[](0) }); address recipient = params.recipient == address(0) ? address(this) : params.recipient; @@ -194,7 +208,6 @@ contract SwapRouter is (address tokenOut, address deployer, address tokenIn) = data.path.decodeFirstPool(); bool zeroToOne = tokenIn < tokenOut; - (int256 amount0Delta, int256 amount1Delta) = getPool(deployer, tokenIn, tokenOut).swap( recipient, zeroToOne, @@ -224,8 +237,10 @@ contract SwapRouter is params.recipient, params.limitSqrtPrice, SwapCallbackData({ + pluginData: params.pluginData, path: abi.encodePacked(params.tokenOut, params.deployer, params.tokenIn), - payer: msg.sender + payer: msg.sender, + pluginDataForward: new bytes[](0) }) ); @@ -237,14 +252,14 @@ contract SwapRouter is function exactOutput( ExactOutputParams calldata params ) external payable override checkDeadline(params.deadline) returns (uint256 amountIn) { + // it's okay that the payer is fixed to msg.sender here, as they're only paying for the "final" exact output // swap, which happens first, and subsequent swaps are paid for within nested callback frames - exactOutputInternal( params.amountOut, params.recipient, 0, - SwapCallbackData({path: params.path, payer: msg.sender}) + SwapCallbackData({pluginData: params.pluginData[0], path: params.path, payer: msg.sender, pluginDataForward: skipPluginDataElement(params.pluginData)}) ); amountIn = amountInCached; diff --git a/src/periphery/contracts/V3Migrator.sol b/src/periphery/contracts/V3Migrator.sol index 8089e46d2..338438197 100644 --- a/src/periphery/contracts/V3Migrator.sol +++ b/src/periphery/contracts/V3Migrator.sol @@ -65,7 +65,8 @@ contract V3Migrator is IV3Migrator, PeripheryImmutableState, PoolInitializer, Mu amount0Min: params.amount0Min, amount1Min: params.amount1Min, recipient: params.recipient, - deadline: params.deadline + deadline: params.deadline, + pluginData: params.pluginData }) ); diff --git a/src/periphery/contracts/base/LiquidityManagement.sol b/src/periphery/contracts/base/LiquidityManagement.sol index 532a71375..b3298a53c 100644 --- a/src/periphery/contracts/base/LiquidityManagement.sol +++ b/src/periphery/contracts/base/LiquidityManagement.sol @@ -23,6 +23,7 @@ abstract contract LiquidityManagement is IAlgebraMintCallback, PeripheryImmutabl struct MintCallbackData { PoolAddress.PoolKey poolKey; address payer; + bytes pluginData; } /// @inheritdoc IAlgebraMintCallback @@ -45,6 +46,7 @@ abstract contract LiquidityManagement is IAlgebraMintCallback, PeripheryImmutabl uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; + bytes pluginData; } /// @notice Add liquidity to an initialized pool @@ -83,7 +85,7 @@ abstract contract LiquidityManagement is IAlgebraMintCallback, PeripheryImmutabl params.tickLower, params.tickUpper, liquidity, - abi.encode(MintCallbackData({poolKey: poolKey, payer: msg.sender})) + abi.encode(MintCallbackData({poolKey: poolKey, payer: msg.sender, pluginData: params.pluginData})) ); require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, 'Price slippage check'); diff --git a/src/periphery/contracts/interfaces/INonfungiblePositionManager.sol b/src/periphery/contracts/interfaces/INonfungiblePositionManager.sol index 43d01cbed..ed8e9ab0e 100644 --- a/src/periphery/contracts/interfaces/INonfungiblePositionManager.sol +++ b/src/periphery/contracts/interfaces/INonfungiblePositionManager.sol @@ -107,6 +107,7 @@ interface INonfungiblePositionManager is uint256 amount1Min; address recipient; uint256 deadline; + bytes pluginData; } /// @notice Creates a new position wrapped in a NFT @@ -129,6 +130,7 @@ interface INonfungiblePositionManager is uint256 amount0Min; uint256 amount1Min; uint256 deadline; + bytes pluginData; } /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` @@ -152,6 +154,7 @@ interface INonfungiblePositionManager is uint256 amount0Min; uint256 amount1Min; uint256 deadline; + bytes pluginData; } /// @notice Decreases the amount of liquidity in a position and accounts it to the position diff --git a/src/periphery/contracts/interfaces/IQuoterV2.sol b/src/periphery/contracts/interfaces/IQuoterV2.sol index 5c55f38a4..4a1fb4553 100644 --- a/src/periphery/contracts/interfaces/IQuoterV2.sol +++ b/src/periphery/contracts/interfaces/IQuoterV2.sol @@ -12,6 +12,7 @@ pragma abicoder v2; interface IQuoterV2 { /// @notice Returns the amount out received for a given exact input swap without executing the swap /// @param path The path of the swap, i.e. each token pair + /// @param pluginsData The swap plugin data /// @param amountInRequired The desired amount of the first token to swap /// @return amountOutList The amount of the last token that would be received /// @return amountInList The amount of the last token that should be paid @@ -21,6 +22,7 @@ interface IQuoterV2 { /// @return feeList List of the fee values used for swaps in the path function quoteExactInput( bytes memory path, + bytes[] memory pluginsData, uint256 amountInRequired ) external @@ -34,6 +36,7 @@ interface IQuoterV2 { ); struct QuoteExactInputSingleParams { + bytes pluginData; address tokenIn; address tokenOut; address deployer; @@ -68,6 +71,7 @@ interface IQuoterV2 { /// @notice Returns the amount in required for a given exact output swap without executing the swap /// @param path The path of the swap, i.e. each token pair. Path must be provided in reverse order + /// @param pluginsData The swap plugin data /// @param amountOutRequired The amount of the last token to receive /// @return amountOutList The amount of the last token that would be received /// @return amountInList The amount of first token required to be paid @@ -77,6 +81,7 @@ interface IQuoterV2 { /// @return feeList List of the fee values used for swaps in the path function quoteExactOutput( bytes memory path, + bytes[] memory pluginsData, uint256 amountOutRequired ) external @@ -90,6 +95,7 @@ interface IQuoterV2 { ); struct QuoteExactOutputSingleParams { + bytes pluginData; address tokenIn; address tokenOut; address deployer; diff --git a/src/periphery/contracts/interfaces/ISwapRouter.sol b/src/periphery/contracts/interfaces/ISwapRouter.sol index 8bc91702d..82886cf40 100644 --- a/src/periphery/contracts/interfaces/ISwapRouter.sol +++ b/src/periphery/contracts/interfaces/ISwapRouter.sol @@ -9,7 +9,20 @@ import '@cryptoalgebra/integral-core/contracts/interfaces/callback/IAlgebraSwapC /// @dev Credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-periphery interface ISwapRouter is IAlgebraSwapCallback { + + /// @notice Data struct for swap callbacks + /// @member pluginData Data passed to the pool plugin + /// @member path Swap path + /// @member payer The address that pays for the swap + /// @member pluginDataForward Array of plugin data elements that used in exactOutput multihop swap + struct SwapCallbackData { + bytes pluginData; + bytes path; + address payer; + bytes[] pluginDataForward; + } struct ExactInputSingleParams { + bytes pluginData; address tokenIn; address tokenOut; address deployer; @@ -26,6 +39,7 @@ interface ISwapRouter is IAlgebraSwapCallback { function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut); struct ExactInputParams { + bytes[] pluginData; bytes path; address recipient; uint256 deadline; @@ -34,11 +48,13 @@ interface ISwapRouter is IAlgebraSwapCallback { } /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path + /// @dev pluginData array length should be equal to the number of swap hops /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut); struct ExactOutputSingleParams { + bytes pluginData; address tokenIn; address tokenOut; address deployer; @@ -56,6 +72,7 @@ interface ISwapRouter is IAlgebraSwapCallback { function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); struct ExactOutputParams { + bytes[] pluginData; bytes path; address recipient; uint256 deadline; @@ -65,6 +82,7 @@ interface ISwapRouter is IAlgebraSwapCallback { /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) /// @dev If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens + /// @dev pluginData array length should be equal to the number of swap hops /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata /// @return amountIn The amount of the input token function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn); diff --git a/src/periphery/contracts/interfaces/IV3Migrator.sol b/src/periphery/contracts/interfaces/IV3Migrator.sol index 665de349c..2935dcfe0 100644 --- a/src/periphery/contracts/interfaces/IV3Migrator.sol +++ b/src/periphery/contracts/interfaces/IV3Migrator.sol @@ -25,6 +25,7 @@ interface IV3Migrator is IMulticall, ISelfPermit, IPoolInitializer { address recipient; uint256 deadline; bool refundAsNative; + bytes pluginData; } /// @notice Migrates liquidity to Algebra by burning v2 liquidity and minting a new position for Algebra diff --git a/src/periphery/contracts/lens/AlgebraInterfaceMulticall.sol b/src/periphery/contracts/lens/AlgebraInterfaceMulticall.sol index 45ff5883d..124db2fc6 100644 --- a/src/periphery/contracts/lens/AlgebraInterfaceMulticall.sol +++ b/src/periphery/contracts/lens/AlgebraInterfaceMulticall.sol @@ -25,6 +25,14 @@ contract AlgebraInterfaceMulticall { balance = addr.balance; } + function gaslimit() external view returns (uint256) { + return block.gaslimit; + } + + function gasLeft() external view returns (uint256) { + return gasleft(); + } + function multicall(Call[] memory calls) public returns (uint256 blockNumber, Result[] memory returnData) { blockNumber = block.number; returnData = new Result[](calls.length); @@ -40,4 +48,31 @@ contract AlgebraInterfaceMulticall { returnData[i] = Result(success, gasUsed, ret); } } + + function multicallWithGasLimitation( + Call[] memory calls, + uint256 gasBuffer + ) public returns (uint256 blockNumber, Result[] memory returnData, uint256 lastSuccessIndex) { + blockNumber = block.number; + returnData = new Result[](calls.length); + + for (uint256 i = 0; i < calls.length; i++) { + (address target, uint256 gasLimit, bytes memory callData) = ( + calls[i].target, + calls[i].gasLimit, + calls[i].callData + ); + + uint256 gasLeftBefore = gasleft(); + (bool success, bytes memory ret) = target.call{gas: gasLimit}(callData); + uint256 gasUsed = gasLeftBefore - gasleft(); + returnData[i] = Result(success, gasUsed, ret); + + if (gasleft() < gasBuffer) { + return (blockNumber, returnData, i); + } + } + + return (blockNumber, returnData, calls.length - 1); + } } diff --git a/src/periphery/contracts/lens/Quoter.sol b/src/periphery/contracts/lens/Quoter.sol index 49c4262d2..bed1bc877 100644 --- a/src/periphery/contracts/lens/Quoter.sol +++ b/src/periphery/contracts/lens/Quoter.sol @@ -14,7 +14,7 @@ import '../libraries/Path.sol'; import '../libraries/PoolAddress.sol'; import '../libraries/CallbackValidation.sol'; -/// @title Algebra Integral 1.2.1 Quoter +/// @title Algebra Integral 1.2.2 Quoter /// @notice Allows getting the expected amount out or amount in for a given swap without executing the swap /// @dev These functions are not gas efficient and should _not_ be called on chain. Instead, optimistically execute /// the swap and check the amounts in the callback. diff --git a/src/periphery/contracts/lens/QuoterV2.sol b/src/periphery/contracts/lens/QuoterV2.sol index ea26d6a41..dcfbcecec 100644 --- a/src/periphery/contracts/lens/QuoterV2.sol +++ b/src/periphery/contracts/lens/QuoterV2.sol @@ -7,13 +7,14 @@ import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/callback/IAlgebraSwapCallback.sol'; import '../interfaces/IQuoterV2.sol'; +import '../interfaces/ISwapRouter.sol'; import '../base/PeripheryImmutableState.sol'; import '../libraries/Path.sol'; import '../libraries/PoolAddress.sol'; import '../libraries/CallbackValidation.sol'; import '../libraries/PoolTicksCounter.sol'; -/// @title Algebra Integral 1.2.1 QuoterV2 +/// @title Algebra Integral 1.2.2 QuoterV2 /// @notice Allows getting the expected amount out or amount in for a given swap without executing the swap /// @dev These functions are not gas efficient and should _not_ be called on chain. Instead, optimistically execute /// the swap and check the amounts in the callback. @@ -38,9 +39,10 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { } /// @inheritdoc IAlgebraSwapCallback - function algebraSwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory path) external view override { + function algebraSwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory callbackData) external view override { require(amount0Delta > 0 || amount1Delta > 0, 'Zero liquidity swap'); // swaps entirely within 0-liquidity regions are not supported - (address tokenIn, address deployer, address tokenOut) = path.decodeFirstPool(); + ISwapRouter.SwapCallbackData memory swapCallbackData = abi.decode(callbackData, (ISwapRouter.SwapCallbackData)); + (address tokenIn, address deployer, address tokenOut) = swapCallbackData.path.decodeFirstPool(); CallbackValidation.verifyCallback(poolDeployer, deployer, tokenIn, tokenOut); (bool isExactInput, uint256 amountToPay, uint256 amountReceived) = amount0Delta > 0 @@ -136,7 +138,12 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { IAlgebraPool pool = getPool(params.deployer, params.tokenIn, params.tokenOut); uint256 gasBefore = gasleft(); - bytes memory data = abi.encodePacked(params.tokenIn, params.deployer, params.tokenOut); + ISwapRouter.SwapCallbackData memory swapData = ISwapRouter.SwapCallbackData({ + pluginData: params.pluginData, + path: abi.encodePacked(params.tokenIn, params.deployer, params.tokenOut), + payer: address(0), + pluginDataForward: new bytes[](0) + }); try pool.swap( address(this), // address(0) might cause issues with some tokens @@ -145,7 +152,7 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { params.limitSqrtPrice == 0 ? (zeroToOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1) : params.limitSqrtPrice, - data + abi.encode(swapData) ) {} catch (bytes memory reason) { gasEstimate = gasBefore - gasleft(); @@ -155,6 +162,7 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { function quoteExactInput( bytes memory path, + bytes[] memory pluginsData, uint256 amountInRequired ) public @@ -180,6 +188,7 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { { (address tokenIn, address deployer, address tokenOut) = path.decodeFirstPool(); + params.pluginData = pluginsData[i]; params.tokenIn = tokenIn; params.deployer = deployer; params.tokenOut = tokenOut; @@ -237,7 +246,12 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { // if no price limit has been specified, cache the output amount for comparison in the swap callback if (params.limitSqrtPrice == 0) amountOutCached = params.amount; uint256 gasBefore = gasleft(); - bytes memory data = abi.encodePacked(params.tokenOut, params.deployer, params.tokenIn); + ISwapRouter.SwapCallbackData memory swapData = ISwapRouter.SwapCallbackData({ + pluginData: params.pluginData, + path: abi.encodePacked(params.tokenIn, params.deployer, params.tokenOut), + payer: address(0), + pluginDataForward: new bytes[](0) + }); try pool.swap( address(this), // address(0) might cause issues with some tokens @@ -246,7 +260,7 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { params.limitSqrtPrice == 0 ? (zeroToOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1) : params.limitSqrtPrice, - data + abi.encode(swapData) ) {} catch (bytes memory reason) { gasEstimate = gasBefore - gasleft(); @@ -257,6 +271,7 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { function quoteExactOutput( bytes memory path, + bytes[] memory pluginsData, uint256 amountOutRequired ) public @@ -282,6 +297,7 @@ contract QuoterV2 is IQuoterV2, IAlgebraSwapCallback, PeripheryImmutableState { { (address tokenOut, address deployer, address tokenIn) = path.decodeFirstPool(); + params.pluginData = pluginsData[i]; params.tokenIn = tokenIn; params.deployer = deployer; params.tokenOut = tokenOut; diff --git a/src/periphery/contracts/lens/TickLens.sol b/src/periphery/contracts/lens/TickLens.sol index 386a2338d..16365762a 100644 --- a/src/periphery/contracts/lens/TickLens.sol +++ b/src/periphery/contracts/lens/TickLens.sol @@ -6,7 +6,7 @@ import '@cryptoalgebra/integral-core/contracts/libraries/TickTree.sol'; import '../interfaces/ITickLens.sol'; -/// @title Algebra Integral 1.2.1 Tick Lens contract +/// @title Algebra Integral 1.2.2 Tick Lens contract /// @dev Credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-periphery contract TickLens is ITickLens { diff --git a/src/periphery/contracts/libraries/Path.sol b/src/periphery/contracts/libraries/Path.sol index df5b59ca5..55c857c24 100644 --- a/src/periphery/contracts/libraries/Path.sol +++ b/src/periphery/contracts/libraries/Path.sol @@ -62,4 +62,12 @@ library Path { function skipToken(bytes memory path) internal pure returns (bytes memory) { return path.slice(NEXT_OFFSET, path.length - NEXT_OFFSET); } + + /// @notice Skips a chunk element from the buffer and returns the remainder + /// @param pluginData The swap plugin data + /// @param chunkSize The number of bytes to skip + /// @return The remaining token elements in the path + function skipChunk(bytes memory pluginData, uint256 chunkSize) internal pure returns (bytes memory) { + return pluginData.slice(chunkSize, pluginData.length - chunkSize); + } } diff --git a/src/periphery/contracts/libraries/PoolAddress.sol b/src/periphery/contracts/libraries/PoolAddress.sol index 9fd5c9776..6a807fdf5 100644 --- a/src/periphery/contracts/libraries/PoolAddress.sol +++ b/src/periphery/contracts/libraries/PoolAddress.sol @@ -5,7 +5,7 @@ pragma solidity >=0.5.0; /// @dev Credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-periphery library PoolAddress { - bytes32 internal constant POOL_INIT_CODE_HASH = 0xa18736c3ee97fe3c96c9428c0cc2a9116facec18e84f95f9da30543f8238a782; + bytes32 internal constant POOL_INIT_CODE_HASH = 0x62441ebe4e4315cf3d49d5957f94d66b253dbabe7006f34ad7f70947e60bf15c; /// @notice The identifying key of the pool struct PoolKey { diff --git a/src/periphery/contracts/libraries/PoolInteraction.sol b/src/periphery/contracts/libraries/PoolInteraction.sol index 7d18f1e70..492a8cdc2 100644 --- a/src/periphery/contracts/libraries/PoolInteraction.sol +++ b/src/periphery/contracts/libraries/PoolInteraction.sol @@ -34,8 +34,9 @@ library PoolInteraction { IAlgebraPool pool, int24 tickLower, int24 tickUpper, - uint128 liquidity + uint128 liquidity, + bytes memory data ) internal returns (uint256 amount0, uint256 amount1) { - return pool.burn(tickLower, tickUpper, liquidity, '0x0'); + return pool.burn(tickLower, tickUpper, liquidity, data); } } diff --git a/src/periphery/contracts/test/MockPlugin.sol b/src/periphery/contracts/test/MockPlugin.sol index 4b073c70c..f215ffe16 100644 --- a/src/periphery/contracts/test/MockPlugin.sol +++ b/src/periphery/contracts/test/MockPlugin.sol @@ -2,8 +2,17 @@ pragma solidity =0.8.20; import '@cryptoalgebra/integral-core/contracts/interfaces/plugin/IAlgebraPlugin.sol'; +import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol'; +import '../interfaces/ISwapRouter.sol'; +import '../base/LiquidityManagement.sol'; +import '../libraries/PoolAddress.sol'; + contract MockPlugin is IAlgebraPlugin { + + uint24 public swapCalldata; + uint128 public mintCallData; + function defaultPluginConfig() external pure returns (uint8) { return 0; } @@ -21,9 +30,15 @@ contract MockPlugin is IAlgebraPlugin { address, int24, int24, - int128, - bytes calldata - ) external pure returns (bytes4, uint24) { + int128 liquidity, + bytes calldata data + ) external returns (bytes4, uint24) { + if(liquidity > 0 ) { + LiquidityManagement.MintCallbackData memory mintData = abi.decode(data, (LiquidityManagement.MintCallbackData)); + (, mintCallData) = mintData.pluginData.length > 0 ? abi.decode(mintData.pluginData, (uint24, uint128)) : (0, 0); + } else { + (, mintCallData) = data.length > 0 ? abi.decode(data, (uint24, uint128)) : (0, 0); + } return (IAlgebraPlugin.beforeModifyPosition.selector, 0); } @@ -44,8 +59,11 @@ contract MockPlugin is IAlgebraPlugin { return IAlgebraPlugin.afterModifyPosition.selector; } - function beforeSwap(address, address, bool, int256, uint160, bool, bytes calldata) external pure returns (bytes4, uint24, uint24) { - return (IAlgebraPlugin.beforeSwap.selector, 0, 0); + function beforeSwap(address, address, bool, int256, uint160, bool, bytes calldata data) external returns (bytes4, uint24, uint24) { + ISwapRouter.SwapCallbackData memory swapData; + if (data.length > 0 ) swapData = abi.decode(data, (ISwapRouter.SwapCallbackData)); + swapCalldata = swapData.pluginData.length > 0 ? abi.decode(swapData.pluginData, (uint24)) : 0; + return (IAlgebraPlugin.beforeSwap.selector, swapCalldata, 0); } function afterSwap( diff --git a/src/periphery/contracts/test/PathTest.sol b/src/periphery/contracts/test/PathTest.sol index 435418148..cf9211cbb 100644 --- a/src/periphery/contracts/test/PathTest.sol +++ b/src/periphery/contracts/test/PathTest.sol @@ -20,6 +20,10 @@ contract PathTest { return Path.skipToken(path); } + function skipPluginChunk(bytes memory path, uint256 chunkSize) public pure returns (bytes memory) { + return Path.skipChunk(path, chunkSize); + } + // gas funcs function getGasCostOfDecodeFirstPool(bytes memory path) public view returns (uint256) { uint256 gasBefore = gasleft(); diff --git a/src/periphery/package-lock.json b/src/periphery/package-lock.json index 8b227cfaf..6333d3dd2 100644 --- a/src/periphery/package-lock.json +++ b/src/periphery/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cryptoalgebra/integral-periphery", - "version": "1.2.1", + "version": "1.3.0-alpha.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cryptoalgebra/integral-periphery", - "version": "1.2.1", + "version": "1.3.0-alpha.0", "license": "GPL-2.0-or-later", "dependencies": { "@cryptoalgebra/integral-core": "1.2.1", diff --git a/src/periphery/package.json b/src/periphery/package.json index 79c98fe3b..0789f1049 100644 --- a/src/periphery/package.json +++ b/src/periphery/package.json @@ -5,7 +5,7 @@ "publishConfig": { "access": "public" }, - "version": "1.2.1", + "version": "1.2.4", "keywords": [ "algebra", "periphery" @@ -27,7 +27,7 @@ "dependencies": { "@openzeppelin/contracts": "4.9.3", "@uniswap/v2-core": "1.0.1", - "@cryptoalgebra/integral-core": "~1.2.1" + "@cryptoalgebra/integral-core": "~1.2.8" }, "devDependencies": { "is-svg": "^4.3.1" @@ -45,4 +45,4 @@ "npm": ">=8.0.0", "node": ">=16.0.0" } -} \ No newline at end of file +} diff --git a/src/periphery/test/NonfungiblePositionManager.spec.ts b/src/periphery/test/NonfungiblePositionManager.spec.ts index e20768e67..33959c1e6 100644 --- a/src/periphery/test/NonfungiblePositionManager.spec.ts +++ b/src/periphery/test/NonfungiblePositionManager.spec.ts @@ -1,4 +1,4 @@ -import { BigNumberish, Wallet, MaxUint256, ZeroAddress } from 'ethers'; +import { BigNumberish, Wallet, MaxUint256, ZeroAddress, AbiCoder } from 'ethers'; import { ethers } from 'hardhat'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { @@ -9,6 +9,7 @@ import { IAlgebraFactory, SwapRouter, MockPositionFollower, + MockPlugin } from '../typechain'; import completeFixture from './shared/completeFixture'; import { computePoolAddress } from './shared/computePoolAddress'; @@ -26,6 +27,7 @@ import { extractJSONFromURI } from './shared/extractJSONFromURI'; import { abi as IAlgebraPoolABI } from '@cryptoalgebra/integral-core/artifacts/contracts/interfaces/IAlgebraPool.sol/IAlgebraPool.json'; import { ZERO_ADDRESS } from './CallbackValidation.spec'; +import { pool } from '../typechain/@cryptoalgebra/integral-core/contracts/interfaces'; describe('NonfungiblePositionManager', () => { let wallets: Wallet[]; @@ -61,6 +63,8 @@ describe('NonfungiblePositionManager', () => { let tokens: [TestERC20, TestERC20, TestERC20]; let wnative: IWNativeToken; let router: SwapRouter; + let pluginData: string; + let poolAddress: string; before('create fixture loader', async () => { wallets = await (ethers as any).getSigners(); @@ -69,6 +73,11 @@ describe('NonfungiblePositionManager', () => { beforeEach('load fixture', async () => { ({ nft, factory, tokens, wnative, router } = await loadFixture(nftFixture)); + pluginData = "0x" + poolAddress = computePoolAddress(await factory.poolDeployer(), [ + await tokens[0].getAddress(), + await tokens[1].getAddress(), + ]); }); it('bytecode size [ @skip-on-coverage ]', async () => { @@ -155,6 +164,7 @@ describe('NonfungiblePositionManager', () => { amount1Min: 0, recipient: wallet.address, deadline: 1, + pluginData: pluginData, }) ).to.be.reverted; }); @@ -175,6 +185,7 @@ describe('NonfungiblePositionManager', () => { amount1Min: 0, recipient: wallet.address, deadline: 1, + pluginData: pluginData, }) ).to.be.revertedWith('STF'); }); @@ -195,6 +206,7 @@ describe('NonfungiblePositionManager', () => { amount1Min: 0, recipient: wallet.address, deadline: 1, + pluginData: pluginData, }) ).to.be.revertedWith('Transaction too old'); }); @@ -219,6 +231,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }); expect(await nft.balanceOf(other.getAddress())).to.eq(1); expect(await nft.tokenOfOwnerByIndex(other.getAddress(), 0)).to.eq(1); @@ -271,6 +284,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }, ]); @@ -288,6 +302,42 @@ describe('NonfungiblePositionManager', () => { expect(balanceBefore - balanceAfter - gasPrice * rcpt.gasUsed).to.eq(100); }); + it('pass data to plugin', async () => { + pluginData = AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]) + await nft.createAndInitializePoolIfNecessary( + tokens[0].getAddress(), + tokens[1].getAddress(), + ZERO_ADDRESS, + encodePriceSqrt(1, 1), + '0x' + ); + + const pluginContractFactory = await ethers.getContractFactory('MockPlugin'); + + const pool = new ethers.Contract(poolAddress, IAlgebraPoolABI, wallet) + await pool.setPluginConfig(4) + let pluginAddress = await pool.plugin() + let plugin = (pluginContractFactory.attach(pluginAddress)) as any as MockPlugin; + + await nft.mint({ + token0: tokens[0].getAddress(), + token1: tokens[1].getAddress(), + deployer: ZERO_ADDRESS, + tickLower: getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]), + tickUpper: getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM]), + recipient: wallet.address, + amount0Desired: 100, + amount1Desired: 100, + amount0Min: 0, + amount1Min: 0, + deadline: 10, + pluginData: pluginData, + }) + + expect(await plugin.mintCallData()).to.eq(10000); + + }); + it('emits an event'); it('gas first mint for pool [ @skip-on-coverage ]', async () => { @@ -312,10 +362,12 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }) ); }); + it('gas first mint for pool using eth with zero refund [ @skip-on-coverage ]', async () => { const [token0, token1] = await sortedTokens(wnative, tokens[0]); await nft.createAndInitializePoolIfNecessary(token0, token1, ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); @@ -336,6 +388,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }, ]), nft.interface.encodeFunctionData('refundNativeToken'), @@ -365,6 +418,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }, ]), nft.interface.encodeFunctionData('refundNativeToken'), @@ -389,6 +443,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }); await snapshotGasCost( @@ -404,6 +459,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }) ); }); @@ -429,6 +485,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }); await snapshotGasCost( @@ -444,6 +501,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: pluginData, }) ); }); @@ -472,6 +530,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }); }); @@ -483,6 +542,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }); const { liquidity } = await nft.positions(tokenId); expect(liquidity).to.eq(1100); @@ -501,12 +561,44 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }); const { tokensOwed0, tokensOwed1 } = await nft.positions(tokenId); expect(tokensOwed0).to.eq(1000); expect(tokensOwed1).to.eq(1000); }); + it('pass data to plugin', async () => { + pluginData = AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]) + await nft.createAndInitializePoolIfNecessary( + tokens[0].getAddress(), + tokens[1].getAddress(), + ZERO_ADDRESS, + encodePriceSqrt(1, 1), + '0x' + ); + + const pluginContractFactory = await ethers.getContractFactory('MockPlugin'); + + const pool = new ethers.Contract(poolAddress, IAlgebraPoolABI, wallet) + await pool.setPluginConfig(4) + let pluginAddress = await pool.plugin() + let plugin = (pluginContractFactory.attach(pluginAddress)) as any as MockPlugin; + + await nft.increaseLiquidity({ + tokenId: tokenId, + amount0Desired: 100, + amount1Desired: 100, + amount0Min: 0, + amount1Min: 0, + deadline: 1, + pluginData: pluginData, + }); + + expect(await plugin.mintCallData()).to.eq(10000); + + }); + it('emits an event'); it('fails if deadline passed', async () => { @@ -519,6 +611,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }) ).to.be.revertedWith('Transaction too old'); }); @@ -543,6 +636,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }, ]); const refundNativeTokenData = nft.interface.encodeFunctionData('unwrapWNativeToken', [0, other.address]); @@ -556,6 +650,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }, ]); await nft.multicall([increaseLiquidityData, refundNativeTokenData], { value: expandTo18Decimals(1) }); @@ -570,6 +665,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }) ); }); @@ -598,6 +694,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }); }); @@ -606,37 +703,37 @@ describe('NonfungiblePositionManager', () => { it('fails if past deadline', async () => { await nft.setTime(2); await expect( - nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }) + nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 , pluginData: pluginData}) ).to.be.revertedWith('Transaction too old'); }); it('fails if slippage too high', async () => { await expect( - nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 100000, amount1Min: 0, deadline: 1 }) + nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 100000, amount1Min: 0, deadline: 1, pluginData: pluginData}) ).to.be.revertedWith('Price slippage check'); await expect( - nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 100000, deadline: 1 }) + nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 100000, deadline: 1, pluginData: pluginData}) ).to.be.revertedWith('Price slippage check'); await expect( nft .connect(other) - .decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 100000, amount1Min: 100000, deadline: 1 }) + .decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 100000, amount1Min: 100000, deadline: 1, pluginData: pluginData}) ).to.be.revertedWith('Price slippage check'); }); it('cannot be called by other addresses', async () => { await expect( - nft.decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }) + nft.decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}) ).to.be.revertedWith('Not approved'); }); it('cannot use 0 as liquidityDelta', async () => { - expect(nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 0, amount0Min: 0, amount1Min: 0, deadline: 1 })) + expect(nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 0, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData})) .to.be.revertedWithoutReason; }); it('decreases position liquidity', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 25, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 25, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); const { liquidity } = await nft.positions(tokenId); expect(liquidity).to.eq(75); }); @@ -644,11 +741,11 @@ describe('NonfungiblePositionManager', () => { it('is payable', async () => { await nft .connect(other) - .decreaseLiquidity({ tokenId, liquidity: 25, amount0Min: 0, amount1Min: 0, deadline: 1 }, { value: 1 }); + .decreaseLiquidity({ tokenId, liquidity: 25, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}, { value: 1 }); }); it('accounts for tokens owed', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 25, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 25, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); const { tokensOwed0, tokensOwed1 } = await nft.positions(tokenId); expect(tokensOwed0).to.eq(24); expect(tokensOwed1).to.eq(24); @@ -657,17 +754,40 @@ describe('NonfungiblePositionManager', () => { it('can decrease for all the liquidity', async () => { await nft .connect(other) - .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1 }); + .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); const { liquidity } = await nft.positions(tokenId); expect(liquidity).to.eq(0); }); it('cannot decrease for more than all the liquidity', async () => { await expect( - nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 101, amount0Min: 0, amount1Min: 0, deadline: 1 }) + nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 101, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}) ).to.be.reverted; }); + it('pass data to plugin', async () => { + pluginData = AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]) + await nft.createAndInitializePoolIfNecessary( + tokens[0].getAddress(), + tokens[1].getAddress(), + ZERO_ADDRESS, + encodePriceSqrt(1, 1), + '0x' + ); + + const pluginContractFactory = await ethers.getContractFactory('MockPlugin'); + + const pool = new ethers.Contract(poolAddress, IAlgebraPoolABI, wallet) + await pool.setPluginConfig(4) + let pluginAddress = await pool.plugin() + let plugin = (pluginContractFactory.attach(pluginAddress)) as any as MockPlugin; + + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 25, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); + + expect(await plugin.mintCallData()).to.eq(10000); + + }); + it('cannot decrease for more than the liquidity of the nft position', async () => { await nft.mint({ token0: tokens[0].getAddress(), @@ -681,21 +801,22 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }); await expect( - nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 101, amount0Min: 0, amount1Min: 0, deadline: 1 }) + nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 101, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}) ).to.be.reverted; }); it('gas partial decrease [ @skip-on-coverage ]', async () => { await snapshotGasCost( - nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }) + nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}) ); }); it('gas complete decrease [ @skip-on-coverage ]', async () => { await snapshotGasCost( - nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1 }) + nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}) ); }); }); @@ -723,6 +844,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData, }); }); @@ -733,6 +855,7 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }) ).to.be.revertedWith('Not approved'); }); @@ -744,6 +867,7 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: 0, amount1Max: 0, + pluginData: pluginData }) ).to.be.reverted; }); @@ -755,6 +879,7 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: 0, amount1Max: 100, + pluginData: pluginData }) ).to.be.not.reverted; }); @@ -766,6 +891,7 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }) ) .to.not.emit(tokens[0], 'Transfer') @@ -773,7 +899,7 @@ describe('NonfungiblePositionManager', () => { }); it('transfers tokens owed from burn', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); const poolAddress = computePoolAddress(await factory.poolDeployer(), [ await tokens[0].getAddress(), await tokens[1].getAddress(), @@ -784,6 +910,7 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }) ) .to.emit(tokens[0], 'Transfer') @@ -793,7 +920,7 @@ describe('NonfungiblePositionManager', () => { }); it('transfers tokens owed from burn to nft if recipient is 0', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); const poolAddress = computePoolAddress(await factory.poolDeployer(), [ await tokens[0].getAddress(), await tokens[1].getAddress(), @@ -804,6 +931,7 @@ describe('NonfungiblePositionManager', () => { recipient: ZeroAddress, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }) ) .to.emit(tokens[0], 'Transfer') @@ -813,37 +941,40 @@ describe('NonfungiblePositionManager', () => { }); it('gas transfers both [ @skip-on-coverage ]', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); await snapshotGasCost( nft.connect(other).collect({ tokenId, recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }) ); }); it('gas transfers token0 only [ @skip-on-coverage ]', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); await snapshotGasCost( nft.connect(other).collect({ tokenId, recipient: wallet.address, amount0Max: MaxUint128, amount1Max: 0, + pluginData: pluginData }) ); }); it('gas transfers token1 only [ @skip-on-coverage ]', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); await snapshotGasCost( nft.connect(other).collect({ tokenId, recipient: wallet.address, amount0Max: 0, amount1Max: MaxUint128, + pluginData: pluginData }) ); }); @@ -872,6 +1003,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); }); @@ -886,26 +1018,27 @@ describe('NonfungiblePositionManager', () => { }); it('cannot be called while there is still partial liquidity', async () => { - await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1 }); + await nft.connect(other).decreaseLiquidity({ tokenId, liquidity: 50, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); await expect(nft.connect(other).burn(tokenId)).to.be.reverted; }); it('cannot be called while there is still tokens owed', async () => { await nft .connect(other) - .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1 }); + .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); await expect(nft.connect(other).burn(tokenId)).to.be.reverted; }); it('deletes the token', async () => { await nft .connect(other) - .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1 }); + .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); await nft.connect(other).collect({ tokenId, recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData, }); await nft.connect(other).burn(tokenId); await expect(nft.positions(tokenId)).to.be.revertedWith('Invalid token ID'); @@ -914,12 +1047,13 @@ describe('NonfungiblePositionManager', () => { it('gas [ @skip-on-coverage ]', async () => { await nft .connect(other) - .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1 }); + .decreaseLiquidity({ tokenId, liquidity: 100, amount0Min: 0, amount1Min: 0, deadline: 1, pluginData: pluginData}); await nft.connect(other).collect({ tokenId, recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }); await snapshotGasCost(nft.connect(other).burn(tokenId)); }); @@ -954,6 +1088,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); }); @@ -1011,6 +1146,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); }); @@ -1077,6 +1213,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); }); @@ -1138,6 +1275,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); }); @@ -1157,7 +1295,7 @@ describe('NonfungiblePositionManager', () => { recipient: string; }) { const decreaseLiquidityData = nft.interface.encodeFunctionData('decreaseLiquidity', [ - { tokenId, liquidity, amount0Min, amount1Min, deadline: 1 }, + { tokenId, liquidity, amount0Min, amount1Min, deadline: 1, pluginData: pluginData}, ]); const collectData = nft.interface.encodeFunctionData('collect', [ { @@ -1165,6 +1303,7 @@ describe('NonfungiblePositionManager', () => { recipient, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }, ]); const burnData = nft.interface.encodeFunctionData('burn', [tokenId]); @@ -1228,6 +1367,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); }); @@ -1269,6 +1409,7 @@ describe('NonfungiblePositionManager', () => { amount1Min: 0, deadline: 1, recipient: wallet.address, + pluginData: pluginData }); // nft 2 earns 75% of fees await nft.mint({ @@ -1283,6 +1424,7 @@ describe('NonfungiblePositionManager', () => { amount1Min: 0, deadline: 1, recipient: wallet.address, + pluginData: pluginData }); }); @@ -1291,6 +1433,7 @@ describe('NonfungiblePositionManager', () => { const swapAmount = 3_333_333; await tokens[0].approve(router.getAddress(), swapAmount); await router.exactInput({ + pluginData: ["0x"], recipient: wallet.address, deadline: 1, path: encodePath([await tokens[0].getAddress(), ZERO_ADDRESS, await tokens[1].getAddress()]), @@ -1304,12 +1447,14 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }); const { amount0: nft2Amount0, amount1: nft2Amount1 } = await nft.collect.staticCall({ tokenId: 2, recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }); expect(nft1Amount0).to.eq(416); expect(nft1Amount1).to.eq(0); @@ -1329,6 +1474,7 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }) ) .to.emit(tokens[0], 'Transfer') @@ -1340,6 +1486,7 @@ describe('NonfungiblePositionManager', () => { recipient: wallet.address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: pluginData }) ) .to.emit(tokens[0], 'Transfer') @@ -1372,6 +1519,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); }); @@ -1507,6 +1655,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); expect(await mockFollower.wasCalled()).to.be.true; @@ -1526,6 +1675,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); expect(await mockFollower.wasCalled()).to.be.false; @@ -1545,6 +1695,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); expect(await mockFollower.wasCalled()).to.be.false; @@ -1565,6 +1716,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }) ) .to.emit(nft, 'FarmingFailed') @@ -1581,6 +1733,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }) ) .to.emit(nft, 'FarmingFailed') @@ -1604,6 +1757,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }) ) .to.emit(nft, 'FarmingFailed') @@ -1626,6 +1780,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }) ).to.be.revertedWithoutReason; expect(await mockFollower.wasCalled()).to.be.false; @@ -1646,6 +1801,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }) ).to.be.revertedWithCustomError(mockFollower, 'someCustomError'); expect(await mockFollower.wasCalled()).to.be.false; @@ -1664,6 +1820,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }); await mockFollower.setFailForToken(tokenId, 6); @@ -1676,6 +1833,7 @@ describe('NonfungiblePositionManager', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: pluginData }, { gasLimit: gasLimit + 10000n } ) diff --git a/src/periphery/test/NonfungibleTokenPositionDescriptor.spec.ts b/src/periphery/test/NonfungibleTokenPositionDescriptor.spec.ts index 87e854715..1096211f5 100644 --- a/src/periphery/test/NonfungibleTokenPositionDescriptor.spec.ts +++ b/src/periphery/test/NonfungibleTokenPositionDescriptor.spec.ts @@ -130,6 +130,7 @@ describe('NonfungibleTokenPositionDescriptor', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: "0x" }); const metadata = extractJSONFromURI(await nft.tokenURI(1)); @@ -155,6 +156,7 @@ describe('NonfungibleTokenPositionDescriptor', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: "0x" }); const metadata = extractJSONFromURI(await nft.tokenURI(1)); diff --git a/src/periphery/test/PositionValue.spec.ts b/src/periphery/test/PositionValue.spec.ts index 415a3aabb..acfa194a4 100644 --- a/src/periphery/test/PositionValue.spec.ts +++ b/src/periphery/test/PositionValue.spec.ts @@ -90,6 +90,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); const swapAmount = expandTo18Decimals(1_000); @@ -98,6 +99,7 @@ describe('PositionValue', async () => { // accumulate token0 fees await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[0].getAddress(), ZERO_ADDRESS, await tokens[1].getAddress()]), @@ -107,6 +109,7 @@ describe('PositionValue', async () => { // accumulate token1 fees await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[1].getAddress(), ZERO_ADDRESS, await tokens[0].getAddress()]), @@ -152,6 +155,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); const principal = await positionValue.principal(nft, 1, sqrtRatioX96); @@ -172,6 +176,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); const principal = await positionValue.principal(nft, 1, sqrtRatioX96); @@ -192,6 +197,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); const principal = await positionValue.principal(nft, 1, sqrtRatioX96); @@ -212,6 +218,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); const principal = await positionValue.principal(nft, 1, sqrtRatioX96); @@ -232,6 +239,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); const principal = await positionValue.principal(nft, 1, sqrtRatioX96); @@ -252,6 +260,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); await snapshotGasCost(positionValue.principalGas(nft, 1, sqrtRatioX96)); @@ -277,6 +286,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); }); @@ -294,6 +304,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); const swapAmount = expandTo18Decimals(1_000); @@ -302,6 +313,7 @@ describe('PositionValue', async () => { // accumulate token0 fees await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[0].getAddress(), ZERO_ADDRESS, await tokens[1].getAddress()]), @@ -311,6 +323,7 @@ describe('PositionValue', async () => { // accumulate token1 fees await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[1].getAddress(), ZERO_ADDRESS, await tokens[0].getAddress()]), @@ -325,6 +338,7 @@ describe('PositionValue', async () => { recipient: wallets[0].address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: "0x" }); const feeAmounts = await positionValue.fees(nft, tokenId); @@ -340,6 +354,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: "0x" }); const swapAmount = expandTo18Decimals(1_000); @@ -347,6 +362,7 @@ describe('PositionValue', async () => { // accumulate more token0 fees after clearing initial amount await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[0].getAddress(), ZERO_ADDRESS, await tokens[1].getAddress()]), @@ -359,6 +375,7 @@ describe('PositionValue', async () => { recipient: wallets[0].address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: "0x" }); const feeAmounts = await positionValue.fees(nft, tokenId); expect(feeAmounts[0]).to.equal(feesFromCollect[0]); @@ -384,6 +401,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); await tokens[0].approve(router, MaxUint256); @@ -391,6 +409,7 @@ describe('PositionValue', async () => { // accumulate token1 fees await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[1].getAddress(), ZERO_ADDRESS, await tokens[0].getAddress()]), @@ -400,6 +419,7 @@ describe('PositionValue', async () => { // accumulate token0 fees and push price below tickLower await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[0].getAddress(), ZERO_ADDRESS, await tokens[1].getAddress()]), @@ -414,6 +434,7 @@ describe('PositionValue', async () => { recipient: wallets[0].address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: "0x" }); const feeAmounts = await positionValue.fees(nft, tokenId); @@ -441,6 +462,7 @@ describe('PositionValue', async () => { amount0Min: 0, amount1Min: 0, deadline: 10, + pluginData: "0x" }); await tokens[0].approve(router, MaxUint256); @@ -448,6 +470,7 @@ describe('PositionValue', async () => { // accumulate token0 fees await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[0].getAddress(), ZERO_ADDRESS, await tokens[1].getAddress()]), @@ -457,6 +480,7 @@ describe('PositionValue', async () => { // accumulate token1 fees and push price above tickUpper await router.exactInput({ + pluginData: ["0x"], recipient: wallets[0].address, deadline: 1, path: encodePath([await tokens[1].getAddress(), ZERO_ADDRESS, await tokens[0].getAddress()]), @@ -471,6 +495,7 @@ describe('PositionValue', async () => { recipient: wallets[0].address, amount0Max: MaxUint128, amount1Max: MaxUint128, + pluginData: "0x" }); const feeAmounts = await positionValue.fees(nft, tokenId); expect(feeAmounts[0]).to.equal(feesFromCollect[0]); diff --git a/src/periphery/test/Quoter.spec.ts b/src/periphery/test/Quoter.spec.ts index 08ea4bf8b..002063db9 100644 --- a/src/periphery/test/Quoter.spec.ts +++ b/src/periphery/test/Quoter.spec.ts @@ -118,6 +118,7 @@ describe('Quoter', () => { const value = inputIsWNativeToken ? amountIn : 0; const params = { + pluginData: ["0x", "0x"], path: encodePath(tokens), recipient: outputIsWNativeToken ? ZeroAddress : trader.address, deadline: 1, diff --git a/src/periphery/test/QuoterV2.spec.ts b/src/periphery/test/QuoterV2.spec.ts index 4c963e94b..118c6faff 100644 --- a/src/periphery/test/QuoterV2.spec.ts +++ b/src/periphery/test/QuoterV2.spec.ts @@ -1,4 +1,4 @@ -import { MaxUint256, Wallet } from 'ethers'; +import { MaxUint256, Wallet, AbiCoder } from 'ethers'; import { ethers } from 'hardhat'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { CustomPoolDeployerTest, IAlgebraFactory, MockTimeNonfungiblePositionManager, QuoterV2, TestERC20 } from '../typechain'; @@ -12,6 +12,8 @@ import { createPool, createPoolWithMultiplePositions, createPoolWithZeroTickInit import snapshotGasCost from './shared/snapshotGasCost'; import { ZERO_ADDRESS } from './CallbackValidation.spec'; +import { abi as IAlgebraPoolABI } from '@cryptoalgebra/integral-core/artifacts/contracts/interfaces/IAlgebraPool.sol/IAlgebraPool.json'; + type TestERC20WithAddress = TestERC20 & { address: string }; describe('QuoterV2', function () { @@ -56,6 +58,7 @@ describe('QuoterV2', function () { let path: [string, string, string, string, string]; let quoter: QuoterV2; let factory: IAlgebraFactory; + let pluginsData = ['0x', '0x']; before('create fixture loader', async () => { const wallets = await (ethers as any).getSigners(); @@ -66,10 +69,18 @@ describe('QuoterV2', function () { const subFixture = async () => { const { tokens, customPoolDeployer, path, nft, quoter, factory } = await swapRouterFixture(); await createPool(nft, wallet, tokens[0].address, tokens[1].address, ZERO_ADDRESS); + const pool0Address = await factory.poolByPair(tokens[0].address, tokens[1].address); + const pool0 = new ethers.Contract(pool0Address, IAlgebraPoolABI, wallet); + await pool0.setPluginConfig(128 + 1); await customPoolDeployer.createCustomPool(customPoolDeployer, wallet.address, await tokens[1].getAddress(), await tokens[2].getAddress(), '0x'); await createPool(nft, wallet, tokens[1].address, tokens[2].address, await customPoolDeployer.getAddress()); + const pool1Address = await factory.computeCustomPoolAddress(await customPoolDeployer.getAddress(), tokens[1].address, tokens[2].address); + const pool1 = new ethers.Contract(pool1Address, IAlgebraPoolABI, wallet); + await pool1.setPluginConfig(128 + 1); + await createPoolWithMultiplePositions(nft, wallet, tokens[0].address, tokens[2].address); + return { tokens, path, @@ -84,9 +95,25 @@ describe('QuoterV2', function () { }); describe('#quoteExactInput', () => { + it('0 -> 1 with plugin data', async () => { + pluginsData = [ + AbiCoder.defaultAbiCoder().encode(['uint24'], [1000]) + ]; + + const { amountOutList, amountInList } = + await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[1].address]), pluginsData, 10000); + expect(amountOutList.length).to.eq(1); + expect(amountInList[0]).to.eq(10000); + expect(amountOutList[0]).to.eq(9891); // fee = 1% + + pluginsData = [ + '0x', '0x' + ] + }); + it('0 -> 2 cross 2 tick', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 10000); + await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 10000); ////await snapshotGasCost(gasEstimate) expect(sqrtPriceX96AfterList.length).to.eq(1); @@ -100,7 +127,7 @@ describe('QuoterV2', function () { // The swap amount is set such that the active tick after the swap is -120. // -120 is an initialized tick for this pool. We check that we don't count it. const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 6200); + await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 6200); ////await snapshotGasCost(gasEstimate) expect(sqrtPriceX96AfterList.length).to.eq(1); @@ -113,7 +140,7 @@ describe('QuoterV2', function () { it('0 -> 2 cross 1 tick', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 4000); + await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 4000); ////await snapshotGasCost(gasEstimate) expect(initializedTicksCrossedList[0]).to.eq(1); @@ -126,7 +153,7 @@ describe('QuoterV2', function () { it('0 -> 2 cross 0 tick, starting tick not initialized', async () => { // Tick before 0, tick after -1. const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 10); + await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 10); ////await snapshotGasCost(gasEstimate) expect(initializedTicksCrossedList[0]).to.eq(0); @@ -141,7 +168,7 @@ describe('QuoterV2', function () { await createPoolWithZeroTickInitialized(nft, wallet, tokens[0].address, tokens[2].address); const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 10); + await quoter.quoteExactInput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 10); ////await snapshotGasCost(gasEstimate) expect(initializedTicksCrossedList[0]).to.eq(1); @@ -153,7 +180,7 @@ describe('QuoterV2', function () { it('2 -> 0 cross 2', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 10000); + await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 10000); ////await snapshotGasCost(gasEstimate) expect(initializedTicksCrossedList[0]).to.eq(2); @@ -169,7 +196,7 @@ describe('QuoterV2', function () { // 120 is an initialized tick for this pool. We check we don't count it. const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 6250); + await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 6250); ////await snapshotGasCost(gasEstimate) expect(initializedTicksCrossedList[0]).to.eq(2); @@ -185,7 +212,7 @@ describe('QuoterV2', function () { await createPoolWithZeroTickInitialized(nft, wallet, tokens[0].address, tokens[2].address); const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 200); + await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 200); ////await snapshotGasCost(gasEstimate) expect(initializedTicksCrossedList[0]).to.eq(0); @@ -199,7 +226,7 @@ describe('QuoterV2', function () { it('2 -> 0 cross 0 tick, starting tick not initialized', async () => { // Tick 0 initialized. Tick after = 1 const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 103); + await quoter.quoteExactInput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 103); ////await snapshotGasCost(gasEstimate) expect(initializedTicksCrossedList[0]).to.eq(0); @@ -210,10 +237,10 @@ describe('QuoterV2', function () { expect(amountInList[0]).to.eq(103); }); - it('2 -> 1', async () => { + it('2 -> 1 jeppa', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactInput.staticCall(encodePath([path[4], path[3], path[2]]), 10000); + await quoter.quoteExactInput.staticCall(encodePath([path[4], path[3], path[2]]), pluginsData, 10000); ////await snapshotGasCost(gasEstimate) expect(sqrtPriceX96AfterList.length).to.eq(1); @@ -227,6 +254,7 @@ describe('QuoterV2', function () { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = await quoter.quoteExactInput.staticCall( encodePath([path[0], ZERO_ADDRESS, path[4], path[3], path[2]]), + ['0x', '0x', '0x'], 10000 ); @@ -250,6 +278,7 @@ describe('QuoterV2', function () { initializedTicksCrossed, fee, } = await quoter.quoteExactInputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[0].address, tokenOut: tokens[2].address, deployer: ZERO_ADDRESS, @@ -273,6 +302,7 @@ describe('QuoterV2', function () { await expect( quoter.quoteExactInputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[0].address, tokenOut: tokens[2].address, deployer: ZERO_ADDRESS, @@ -291,6 +321,7 @@ describe('QuoterV2', function () { sqrtPriceX96After, initializedTicksCrossed, } = await quoter.quoteExactInputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[2].address, tokenOut: tokens[0].address, deployer: ZERO_ADDRESS, @@ -310,6 +341,7 @@ describe('QuoterV2', function () { describe('gas [ @skip-on-coverage ]', () => { it('0 -> 2', async () => { const { gasEstimate } = await quoter.quoteExactInputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[0].address, tokenOut: tokens[2].address, deployer: ZERO_ADDRESS, @@ -323,6 +355,7 @@ describe('QuoterV2', function () { it('2 -> 0', async () => { const { gasEstimate } = await quoter.quoteExactInputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[2].address, tokenOut: tokens[0].address, deployer: ZERO_ADDRESS, @@ -339,7 +372,7 @@ describe('QuoterV2', function () { describe('#quoteExactOutput', () => { it('0 -> 2 cross 2 tick', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 15000); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 15000); expect(initializedTicksCrossedList.length).to.eq(1); expect(initializedTicksCrossedList[0]).to.eq(2); @@ -354,7 +387,7 @@ describe('QuoterV2', function () { // The swap amount is set such that the active tick after the swap is -120. // -120 is an initialized tick for this pool. We check that we count it. const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 6158); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 6158); expect(sqrtPriceX96AfterList.length).to.eq(1); expect(sqrtPriceX96AfterList[0]).to.eq('78756056567076985409608047254'); @@ -366,7 +399,7 @@ describe('QuoterV2', function () { it('0 -> 2 cross 1 tick', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 4000); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 4000); expect(initializedTicksCrossedList.length).to.eq(1); expect(initializedTicksCrossedList[0]).to.eq(1); @@ -381,7 +414,7 @@ describe('QuoterV2', function () { // Tick before 0, tick after 1. Tick 0 initialized. await createPoolWithZeroTickInitialized(nft, wallet, tokens[0].address, tokens[2].address); const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 100); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 100); expect(initializedTicksCrossedList.length).to.eq(1); expect(initializedTicksCrossedList[0]).to.eq(1); @@ -394,7 +427,7 @@ describe('QuoterV2', function () { it('0 -> 2 cross 0 tick starting tick not initialized', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), 10); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), pluginsData, 10); expect(initializedTicksCrossedList.length).to.eq(1); expect(initializedTicksCrossedList[0]).to.eq(0); @@ -407,7 +440,7 @@ describe('QuoterV2', function () { it('2 -> 0 cross 2 ticks', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 15000); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 15000); expect(initializedTicksCrossedList.length).to.eq(1); expect(initializedTicksCrossedList[0]).to.eq(2); @@ -421,7 +454,7 @@ describe('QuoterV2', function () { // The swap amount is set such that the active tick after the swap is 120. // 120 is an initialized tick for this pool. We check that we don't count it. const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 6223); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 6223); expect(initializedTicksCrossedList[0]).to.eq(2); expect(sqrtPriceX96AfterList.length).to.eq(1); @@ -433,7 +466,7 @@ describe('QuoterV2', function () { it('2 -> 0 cross 1 tick', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), 6000); + await quoter.quoteExactOutput.staticCall(encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), pluginsData, 6000); expect(initializedTicksCrossedList[0]).to.eq(1); expect(sqrtPriceX96AfterList.length).to.eq(1); @@ -445,7 +478,7 @@ describe('QuoterV2', function () { it('2 -> 1', async () => { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = - await quoter.quoteExactOutput.staticCall(encodePath([path[2], path[3], path[4]]), 9897); + await quoter.quoteExactOutput.staticCall(encodePath([path[2], path[3], path[4]]), pluginsData, 9897); expect(sqrtPriceX96AfterList.length).to.eq(1); expect(sqrtPriceX96AfterList[0]).to.eq('80020121658316697953186638498'); @@ -458,6 +491,7 @@ describe('QuoterV2', function () { const { amountOutList, amountInList, sqrtPriceX96AfterList, initializedTicksCrossedList } = await quoter.quoteExactOutput.staticCall( encodePath([path[0], ZERO_ADDRESS, path[4], path[3], path[2]].reverse()), + ['0x', '0x', '0x'], 9795 ); @@ -476,6 +510,7 @@ describe('QuoterV2', function () { it('0 -> 2 cross 2 tick', async () => { const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), + pluginsData, 15000 ); @@ -487,6 +522,7 @@ describe('QuoterV2', function () { // -120 is an initialized tick for this pool. We check that we count it. const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), + pluginsData, 6158 ); @@ -496,6 +532,7 @@ describe('QuoterV2', function () { it('0 -> 2 cross 1 tick', async () => { const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), + pluginsData, 4000 ); @@ -507,6 +544,7 @@ describe('QuoterV2', function () { await createPoolWithZeroTickInitialized(nft, wallet, tokens[0].address, tokens[2].address); const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), + pluginsData, 100 ); @@ -516,6 +554,7 @@ describe('QuoterV2', function () { it('0 -> 2 cross 0 tick starting tick not initialized', async () => { const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[2].address, ZERO_ADDRESS, tokens[0].address]), + pluginsData, 10 ); @@ -525,6 +564,7 @@ describe('QuoterV2', function () { it('2 -> 0 cross 2 ticks', async () => { const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), + pluginsData, 15000 ); @@ -536,6 +576,7 @@ describe('QuoterV2', function () { // 120 is an initialized tick for this pool. We check that we don't count it. const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), + pluginsData, 6223 ); @@ -545,6 +586,7 @@ describe('QuoterV2', function () { it('2 -> 0 cross 1 tick', async () => { const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([tokens[0].address, ZERO_ADDRESS, tokens[2].address]), + pluginsData, 6000 ); @@ -554,6 +596,7 @@ describe('QuoterV2', function () { it('2 -> 1', async () => { const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([path[2], path[3], path[4]]), + pluginsData, 9897 ); @@ -563,6 +606,7 @@ describe('QuoterV2', function () { it('0 -> 2 -> 1', async () => { const { gasEstimate } = await quoter.quoteExactOutput.staticCall( encodePath([path[0], ZERO_ADDRESS, path[4], path[3], path[2]].reverse()), + ['0x', '0x', '0x'], 9795 ); @@ -575,6 +619,7 @@ describe('QuoterV2', function () { it('0 -> 1', async () => { const { amountOut, amountIn, sqrtPriceX96After, initializedTicksCrossed } = await quoter.quoteExactOutputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[0].address, tokenOut: tokens[1].address, deployer: ZERO_ADDRESS, @@ -591,6 +636,7 @@ describe('QuoterV2', function () { it('1 -> 0', async () => { const { amountOut, amountIn, sqrtPriceX96After, initializedTicksCrossed } = await quoter.quoteExactOutputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[1].address, tokenOut: tokens[0].address, deployer: ZERO_ADDRESS, @@ -607,6 +653,7 @@ describe('QuoterV2', function () { describe('gas [ @skip-on-coverage ]', () => { it('0 -> 1', async () => { const { gasEstimate } = await quoter.quoteExactOutputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[0].address, tokenOut: tokens[1].address, deployer: ZERO_ADDRESS, @@ -619,6 +666,7 @@ describe('QuoterV2', function () { it('1 -> 0', async () => { const { gasEstimate } = await quoter.quoteExactOutputSingle.staticCall({ + pluginData: '0x', tokenIn: tokens[1].address, tokenOut: tokens[0].address, deployer: ZERO_ADDRESS, diff --git a/src/periphery/test/SwapRouter.spec.ts b/src/periphery/test/SwapRouter.spec.ts index 2d3a4cb1f..baa6b79f2 100644 --- a/src/periphery/test/SwapRouter.spec.ts +++ b/src/periphery/test/SwapRouter.spec.ts @@ -1,7 +1,7 @@ -import { MaxUint256, Contract, ContractTransactionResponse, Wallet, ZeroAddress } from 'ethers'; +import { MaxUint256, Contract, ContractTransactionResponse, Wallet, ZeroAddress, AbiCoder } from 'ethers'; import { ethers } from 'hardhat'; import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; -import { IWNativeToken, MockTimeNonfungiblePositionManager, MockTimeSwapRouter, TestERC20 } from '../typechain'; +import { IWNativeToken, MockTimeNonfungiblePositionManager, MockTimeSwapRouter, MockPlugin, TestERC20 } from '../typechain'; import completeFixture from './shared/completeFixture'; import { FeeAmount, TICK_SPACINGS } from './shared/constants'; import snapshotGasCost from './shared/snapshotGasCost'; @@ -13,12 +13,15 @@ import { getMaxTick, getMinTick } from './shared/ticks'; import { computePoolAddress, computeCustomPoolAddress } from './shared/computePoolAddress'; import { ZERO_ADDRESS } from './CallbackValidation.spec'; +import { abi as IAlgebraPoolABI } from '@cryptoalgebra/integral-core/artifacts/contracts/interfaces/IAlgebraPool.sol/IAlgebraPool.json'; + type TestERC20WithAddress = TestERC20 & { address: string }; describe('SwapRouter', function () { this.timeout(40000); let wallet: Wallet; let trader: Wallet; + let pluginDatas: string[]; let factory: Contract; let wnative: IWNativeToken; @@ -26,8 +29,10 @@ describe('SwapRouter', function () { let nft: MockTimeNonfungiblePositionManager; let tokens: [TestERC20WithAddress, TestERC20WithAddress, TestERC20WithAddress]; let path: [string, string, string, string, string]; + let plugin0: MockPlugin; + let plugin1: MockPlugin; - let getBalances: (who: string | MockTimeSwapRouter) => Promise<{ + let getBalances: (who: string | MockTimeSwapRouter) => Promise<{ wnative: bigint; token0: bigint; token1: bigint; @@ -61,6 +66,7 @@ describe('SwapRouter', function () { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: "0x" }; return _nft.mint(liquidityParams); @@ -86,11 +92,25 @@ describe('SwapRouter', function () { token.address = await token.getAddress(); } + const pluginContractFactory = await ethers.getContractFactory('MockPlugin'); + await createPool(nft, wallet, _tokens[0].address, _tokens[1].address, ZERO_ADDRESS); + const pool0Address = await factory.poolByPair(_tokens[0].address, _tokens[1].address); + const pool0 = new ethers.Contract(pool0Address, IAlgebraPoolABI, wallet); + await pool0.setPluginConfig(128 + 1) + + const plugin0Address = await pool0.plugin(); + plugin0 = (pluginContractFactory.attach(plugin0Address)) as any as MockPlugin; await customPoolDeployer.createCustomPool(customPoolDeployer, wallet.address, _tokens[1].getAddress(), _tokens[2].getAddress(), '0x'); await createPool(nft, wallet, _tokens[1].address, _tokens[2].address, await customPoolDeployer.getAddress()); + const pool1Address = await factory.computeCustomPoolAddress(await customPoolDeployer.getAddress(), _tokens[1].address, _tokens[2].address); + const pool1 = new ethers.Contract(pool1Address, IAlgebraPoolABI, wallet); + await pool1.setPluginConfig(128 + 1) + let plugin1Address = await pool1.plugin() + plugin1 = (pluginContractFactory.attach(plugin1Address)) as any as MockPlugin; + return { wnative, factory: factory as any as Contract, @@ -114,7 +134,12 @@ describe('SwapRouter', function () { // helper for getting wnative and token balances beforeEach('load fixture', async () => { ({ router, wnative, factory, tokens, path, nft } = await loadFixture(swapRouterFixture)); + // encoded 10000, 100000 + pluginDatas = [ + "0x","0x" + ]; + getBalances = async (who: string | MockTimeSwapRouter) => { let addr; if (typeof who == 'string') addr = who; @@ -158,10 +183,12 @@ describe('SwapRouter', function () { amount1Min: 0, liquidity: _liquidity, deadline: 2, + pluginData: "0x" }); await expect( router.exactInputSingle({ + pluginData: pluginDatas[0], tokenIn: tokens[0].address, tokenOut: tokens[1].address, deployer: ZERO_ADDRESS, @@ -185,13 +212,13 @@ describe('SwapRouter', function () { const outputIsWNativeToken = _tokens[_tokens.length - 1] === (await wnative.getAddress()); const value = inputIsWNativeToken ? amountIn : 0; - const params = { + pluginData: pluginDatas, path: encodePath(_tokens), recipient: outputIsWNativeToken ? ZeroAddress : trader.address, deadline: 1, amountIn, - amountOutMinimum, + amountOutMinimum }; const data = [router.interface.encodeFunctionData('exactInput', [params])]; @@ -216,7 +243,7 @@ describe('SwapRouter', function () { path.slice(0, 3), 3, 1, - 2 + 2, ) ).to.be.revertedWith('Transaction too old'); }); @@ -263,10 +290,21 @@ describe('SwapRouter', function () { expect(poolAfter.token0).to.be.eq(poolBefore.token0 - 1n); expect(poolAfter.token1).to.be.eq(poolBefore.token1 + 3n); }); + + it('0 -> 1 with plugin data', async () => { + pluginDatas = [ + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]), + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [1000, 10001]) + ]; + + await exactInput(path.slice(0, 3)); + expect(await plugin0.swapCalldata()).to.be.eq(2000) + }); }); describe('multi-pool', () => { it('0 -> 1 -> 2', async () => { + const traderBefore = await getBalances(trader.address); await exactInput( @@ -290,6 +328,23 @@ describe('SwapRouter', function () { expect(traderAfter.token2).to.be.eq(traderBefore.token2 - 5n); expect(traderAfter.token0).to.be.eq(traderBefore.token0 + 1n); + + }); + + it('2 -> 1 -> 0 with plugin data', async () => { + pluginDatas = [ + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]), + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [1000, 10001]) + ]; + + await exactInput(path.slice().reverse(), 5, 1); + + expect(await plugin0.swapCalldata()).to.be.eq(1000) + expect(await plugin1.swapCalldata()).to.be.eq(2000) + }); + + it('gas cost [ @skip-on-coverage ]', async () => { + await snapshotGasCost(exactInput(path.slice().reverse(), 5, 1)) }); it('gas cost [ @skip-on-coverage ]', async () => { @@ -431,6 +486,7 @@ describe('SwapRouter', function () { const value = inputIsWNativeToken ? amountIn : 0; const params = { + pluginData: pluginDatas[0], tokenIn, tokenOut, deployer: deployer, @@ -508,6 +564,17 @@ describe('SwapRouter', function () { expect(poolAfter.token1).to.be.eq(poolBefore.token1 + 3n); }); + it('1 -> 0 with plugin data', async () => { + pluginDatas = [ + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]), + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [1000, 10001]) + ]; + + await exactInputSingle(tokens[1].address, tokens[0].address, ZERO_ADDRESS); + + expect(await plugin0.swapCalldata()).to.be.eq(2000) + }); + it('gas cost [ @skip-on-coverage ]', async () => { await snapshotGasCost(exactInputSingle(tokens[1].address, tokens[0].address, ZERO_ADDRESS)) }); @@ -586,6 +653,7 @@ describe('SwapRouter', function () { const value = inputIsWNativeToken ? amountIn : 0; const params = { + pluginData: pluginDatas[0], tokenIn, tokenOut, deployer: deployer, @@ -669,6 +737,17 @@ describe('SwapRouter', function () { expect(poolAfter.token1).to.be.eq(poolBefore.token1 + 285000n); }); + it('1 -> 0 with pluginData', async () => { + pluginDatas = [ + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]), + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [1000, 10001]) + ]; + + await exactInputSingleSupportingFeeOnTransferTokens(tokens[1].address, tokens[0].address, ZERO_ADDRESS); + + expect(await plugin0.swapCalldata()).to.be.eq(2000) + }); + it('gas cost [ @skip-on-coverage ]', async () => { await snapshotGasCost(exactInputSingleSupportingFeeOnTransferTokens(tokens[1].address, tokens[0].address, ZERO_ADDRESS)) }); @@ -716,6 +795,7 @@ describe('SwapRouter', function () { const value = inputIsWNativeToken ? amountInMaximum : 0; const params = { + pluginData: pluginDatas, path: encodePath(_tokens.slice().reverse()), recipient: outputIsWNativeToken ? ZeroAddress : trader.address, deadline: 1, @@ -793,9 +873,18 @@ describe('SwapRouter', function () { expect(poolAfter.token1).to.be.eq(poolBefore.token1 + 3n); }); - it('gas cost [ @skip-on-coverage ]', async () => { - const pool = await factory.poolByPair(tokens[1].address, tokens[0].address); + it('0 -> 1 with plugin data', async () => { + pluginDatas = [ + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]), + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [1000, 10001]) + ]; + + await exactOutput(path.slice(0, 3)); + expect(await plugin0.swapCalldata()).to.be.eq(2000) + }); + + it('gas cost [ @skip-on-coverage ]', async () => { await snapshotGasCost( exactOutput( path @@ -833,6 +922,17 @@ describe('SwapRouter', function () { expect(traderAfter.token0).to.be.eq(traderBefore.token0 + 1n); }); + it('2 -> 1 -> 0 with plugin data', async () => { + pluginDatas = [ + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]), + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [1000, 10001]) + ]; + await exactOutput(path.slice().reverse(), 1, 5); + + expect(await plugin0.swapCalldata()).to.be.eq(2000) + expect(await plugin1.swapCalldata()).to.be.eq(1000) + }); + it('gas cost [ @skip-on-coverage ]', async () => { await snapshotGasCost(exactOutput(path.slice().reverse(), 1, 5)) }); @@ -969,6 +1069,7 @@ describe('SwapRouter', function () { const value = inputIsWNativeToken ? amountInMaximum : 0; const params = { + pluginData: pluginDatas[0], tokenIn, tokenOut, deployer: ZERO_ADDRESS, @@ -1044,6 +1145,16 @@ describe('SwapRouter', function () { expect(poolAfter.token1).to.be.eq(poolBefore.token1 + 3n); }); + it('1 -> 0', async () => { + pluginDatas = [ + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [2000, 10000]), + AbiCoder.defaultAbiCoder().encode(['uint24', 'uint128'], [1000, 10001]) + ] + await exactOutputSingle(tokens[1].address, tokens[0].address); + + expect(await plugin0.swapCalldata()).to.be.eq(2000) + }); + it('gas cost [ @skip-on-coverage ]', async () => { await snapshotGasCost(exactOutputSingle(tokens[1].address, tokens[0].address)) }); @@ -1112,6 +1223,7 @@ describe('SwapRouter', function () { it('#sweepTokenWithFee', async () => { const amountOutMinimum = 100; const params = { + pluginData: pluginDatas, path: encodePath([tokens[0].address, ZERO_ADDRESS, tokens[1].address]), recipient: await router.getAddress(), deadline: 1, @@ -1142,6 +1254,7 @@ describe('SwapRouter', function () { const amountOutMinimum = 100; const params = { + pluginData: pluginDatas, path: encodePath([tokens[0].address, ZERO_ADDRESS, await wnative.getAddress()]), recipient: await router.getAddress(), deadline: 1, diff --git a/src/periphery/test/TickLens.spec.ts b/src/periphery/test/TickLens.spec.ts index 06ba8ec13..847dc7189 100644 --- a/src/periphery/test/TickLens.spec.ts +++ b/src/periphery/test/TickLens.spec.ts @@ -10,6 +10,7 @@ import { getMaxTick, getMinTick } from './shared/ticks'; import { computePoolAddress } from './shared/computePoolAddress'; import snapshotGasCost from './shared/snapshotGasCost'; import { ZERO_ADDRESS } from './CallbackValidation.spec'; +import { plugin } from '../typechain/@cryptoalgebra/integral-core/contracts/interfaces'; type TestERC20WithAddress = TestERC20 & { address: string }; @@ -63,6 +64,7 @@ describe('TickLens', () => { amount1Min: 0, recipient: wallets[0].address, deadline: 1, + pluginData: "0x" }; const { liquidity } = await nft.mint.staticCall(mintParams); @@ -93,6 +95,7 @@ describe('TickLens', () => { amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: "0x" }; await _nft.mint(liquidityParams); diff --git a/src/periphery/test/V3Migrator.spec.ts b/src/periphery/test/V3Migrator.spec.ts index be596283e..17a0378ea 100644 --- a/src/periphery/test/V3Migrator.spec.ts +++ b/src/periphery/test/V3Migrator.spec.ts @@ -137,6 +137,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: false, + pluginData: "0x" }) ).to.be.reverted; }); @@ -160,6 +161,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: false, + pluginData: "0x" }); const position = await nft.positions(1); @@ -192,6 +194,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: false, + pluginData: "0x" }); const tokenBalanceAfter = await token.balanceOf(wallet.address); @@ -230,6 +233,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: false, + pluginData: "0x" }); const tokenBalanceAfter = await token.balanceOf(wallet.address); @@ -274,6 +278,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: false, + pluginData: "0x" }); const tokenBalanceAfter = await token.balanceOf(wallet.address); @@ -318,6 +323,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: true, + pluginData: "0x" }) ) .to.emit(wnative, 'Withdrawal') @@ -362,6 +368,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: true, + pluginData: "0x" }) ) .to.emit(wnative, 'Withdrawal') @@ -404,6 +411,7 @@ describe('V3Migrator', () => { recipient: wallet.address, deadline: 1, refundAsNative: false, + pluginData: "0x" }) ); }); diff --git a/src/periphery/test/__snapshots__/NFTDescriptor.spec.ts.snap b/src/periphery/test/__snapshots__/NFTDescriptor.spec.ts.snap index 158095bd3..f245f1c65 100644 --- a/src/periphery/test/__snapshots__/NFTDescriptor.spec.ts.snap +++ b/src/periphery/test/__snapshots__/NFTDescriptor.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`NFTDescriptor #constructTokenURI gas [ @skip-on-coverage ] 1`] = `1625406`; +exports[`NFTDescriptor #constructTokenURI gas [ @skip-on-coverage ] 1`] = `1625388`; exports[`NFTDescriptor #constructTokenURI snapshot matches 1`] = `"data:application/json;base64,eyJuYW1lIjoiQWxnZWJyYSAtIFVOSS9XTmF0aXZlVG9rZW4gLSAxLjAwMDA8PjEuMTA1MiIsICJkZXNjcmlwdGlvbiI6IlRoaXMgTkZUIHJlcHJlc2VudHMgYSBsaXF1aWRpdHkgcG9zaXRpb24gaW4gYSBBbGdlYnJhIFVOSS1XTmF0aXZlVG9rZW4gcG9vbC4gVGhlIG93bmVyIG9mIHRoaXMgTkZUIGNhbiBtb2RpZnkgb3IgcmVkZWVtIHRoZSBwb3NpdGlvbi5cblxuUG9vbCBBZGRyZXNzOiAweGJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJcblVOSSBBZGRyZXNzOiAweGFiY2RlYWJjZGVmYWJjZGVmYWJjZGVmYWJjZGVmYWJjZGVmYWJjZGZcbldOYXRpdmVUb2tlbiBBZGRyZXNzOiAweDEyMzQ1Njc4OTAxMjM0NTY3ODkxMjM0NTY3ODkwMTIzNDU2Nzg5MDFcblRva2VuIElEOiAxXG5cbuKaoO+4jyBESVNDTEFJTUVSOiBEdWUgZGlsaWdlbmNlIGlzIGltcGVyYXRpdmUgd2hlbiBhc3Nlc3NpbmcgdGhpcyBORlQuIE1ha2Ugc3VyZSB0b2tlbiBhZGRyZXNzZXMgbWF0Y2ggdGhlIGV4cGVjdGVkIHRva2VucywgYXMgdG9rZW4gc3ltYm9scyBtYXkgYmUgaW1pdGF0ZWQuIiwgImltYWdlIjogImRhdGE6aW1hZ2Uvc3ZnK3htbDtiYXNlNjQsUEhOMlp5QjNhV1IwYUQwaU1qa3dJaUJvWldsbmFIUTlJalV3TUNJZ2RtbGxkMEp2ZUQwaU1DQXdJREk1TUNBMU1EQWlJSGh0Ykc1elBTSm9kSFJ3T2k4dmQzZDNMbmN6TG05eVp5OHlNREF3TDNOMlp5SWdlRzFzYm5NNmVHeHBibXM5SjJoMGRIQTZMeTkzZDNjdWR6TXViM0puTHpFNU9Ua3ZlR3hwYm1zblBqeGtaV1p6UGp4bWFXeDBaWElnYVdROUltWXhJajQ4Wm1WSmJXRm5aU0J5WlhOMWJIUTlJbkF3SWlCNGJHbHVhenBvY21WbVBTSmtZWFJoT21sdFlXZGxMM04yWnl0NGJXdzdZbUZ6WlRZMExGQklUakphZVVJellWZFNNR0ZFTUc1TmFtdDNTbmxDYjFwWGJHNWhTRkU1U25wVmQwMURZMmRrYld4c1pEQktkbVZFTUc1TlEwRjNTVVJKTlUxRFFURk5SRUZ1U1Vob2RHSkhOWHBRVTJSdlpFaFNkMDlwT0haa00yUXpURzVqZWt4dE9YbGFlVGg1VFVSQmQwd3pUakphZVdNclVFaEtiRmt6VVdka01teHJaRWRuT1VwNlNUVk5TRUkwU25sQ2IxcFhiRzVoU0ZFNVNucFZkMDFJUWpSS2VVSnRZVmQ0YzFCVFkycFpWMHBxV2tkV2FFcDVPQ3RRUXpsNlpHMWpLeUl2UGp4bVpVbHRZV2RsSUhKbGMzVnNkRDBpY0RFaUlIaHNhVzVyT21oeVpXWTlJbVJoZEdFNmFXMWhaMlV2YzNabkszaHRiRHRpWVhObE5qUXNVRWhPTWxwNVFqTmhWMUl3WVVRd2JrMXFhM2RLZVVKdldsZHNibUZJVVRsS2VsVjNUVU5qWjJSdGJHeGtNRXAyWlVRd2JrMURRWGRKUkVrMVRVTkJNVTFFUVc1SlNHaDBZa2MxZWxCVFpHOWtTRkozVDJrNGRtUXpaRE5NYm1ONlRHMDVlVnA1T0hsTlJFRjNURE5PTWxwNVl5dFFSMDV3WTIxT2MxcFRRbXBsUkRCdVRXcFpORXA1UW1wbFZEQnVUV3BWTVVwNVFubFFVMk40VFdwQ2QyVkRZMmRhYld4ellrUXdia2w2UlhsTmVsRXhUbWxqZGxCcWQzWmpNMXB1VUdjOVBTSXZQanhtWlVsdFlXZGxJSEpsYzNWc2REMGljRElpSUhoc2FXNXJPbWh5WldZOUltUmhkR0U2YVcxaFoyVXZjM1puSzNodGJEdGlZWE5sTmpRc1VFaE9NbHA1UWpOaFYxSXdZVVF3YmsxcWEzZEtlVUp2V2xkc2JtRklVVGxLZWxWM1RVTmpaMlJ0Ykd4a01FcDJaVVF3YmsxRFFYZEpSRWsxVFVOQk1VMUVRVzVKU0doMFlrYzFlbEJUWkc5a1NGSjNUMms0ZG1RelpETk1ibU42VEcwNWVWcDVPSGxOUkVGM1RETk9NbHA1WXl0UVIwNXdZMjFPYzFwVFFtcGxSREJ1VFdwQk1rcDVRbXBsVkRCdVRWUlZlVXA1UW5sUVUyTjRUV3BDZDJWRFkyZGFiV3h6WWtRd2Jra3lXbWhaYlU1cldtbGpkbEJxZDNaak0xcHVVR2M5UFNJZ0x6NDhabVZKYldGblpTQnlaWE4xYkhROUluQXpJaUI0YkdsdWF6cG9jbVZtUFNKa1lYUmhPbWx0WVdkbEwzTjJaeXQ0Yld3N1ltRnpaVFkwTEZCSVRqSmFlVUl6WVZkU01HRkVNRzVOYW10M1NubENiMXBYYkc1aFNGRTVTbnBWZDAxRFkyZGtiV3hzWkRCS2RtVkVNRzVOUTBGM1NVUkpOVTFEUVRGTlJFRnVTVWhvZEdKSE5YcFFVMlJ2WkVoU2QwOXBPSFprTTJRelRHNWpla3h0T1hsYWVUaDVUVVJCZDB3elRqSmFlV01yVUVkT2NHTnRUbk5hVTBKcVpVUXdiazFxVVhkS2VVSnFaVlF3YmsxNlFUSktlVUo1VUZOamVFMUVRbmRsUTJObldtMXNjMkpFTUc1SmVsa3pUMFJyZDAxVFkzWlFhbmQyWXpOYWJsQm5QVDBpSUM4K1BHWmxRbXhsYm1RZ2JXOWtaVDBpYjNabGNteGhlU0lnYVc0OUluQXdJaUJwYmpJOUluQXhJaUF2UGp4bVpVSnNaVzVrSUcxdlpHVTlJbVY0WTJ4MWMybHZiaUlnYVc0eVBTSndNaUlnTHo0OFptVkNiR1Z1WkNCdGIyUmxQU0p2ZG1WeWJHRjVJaUJwYmpJOUluQXpJaUJ5WlhOMWJIUTlJbUpzWlc1a1QzVjBJaUF2UGp4bVpVZGhkWE56YVdGdVFteDFjaUJwYmowaVlteGxibVJQZFhRaUlITjBaRVJsZG1saGRHbHZiajBpTkRJaUlDOCtQQzltYVd4MFpYSStJRHhqYkdsd1VHRjBhQ0JwWkQwaVkyOXlibVZ5Y3lJK1BISmxZM1FnZDJsa2RHZzlJakk1TUNJZ2FHVnBaMmgwUFNJMU1EQWlJSEo0UFNJME1pSWdjbms5SWpReUlpQXZQand2WTJ4cGNGQmhkR2crUEhCaGRHZ2dhV1E5SW5SbGVIUXRjR0YwYUMxaElpQmtQU0pOTkRBZ01USWdTREkxTUNCQk1qZ2dNamdnTUNBd0lERWdNamM0SURRd0lGWTBOakFnUVRJNElESTRJREFnTUNBeElESTFNQ0EwT0RnZ1NEUXdJRUV5T0NBeU9DQXdJREFnTVNBeE1pQTBOakFnVmpRd0lFRXlPQ0F5T0NBd0lEQWdNU0EwTUNBeE1pQjZJaUF2UGp4d1lYUm9JR2xrUFNKdGFXNXBiV0Z3SWlCa1BTSk5Nak0wSURRME5FTXlNelFnTkRVM0xqazBPU0F5TkRJdU1qRWdORFl6SURJMU15QTBOak1pSUM4K1BHWnBiSFJsY2lCcFpEMGlkRzl3TFhKbFoybHZiaTFpYkhWeUlqNDhabVZIWVhWemMybGhia0pzZFhJZ2FXNDlJbE52ZFhKalpVZHlZWEJvYVdNaUlITjBaRVJsZG1saGRHbHZiajBpTWpRaUlDOCtQQzltYVd4MFpYSStQR3hwYm1WaGNrZHlZV1JwWlc1MElHbGtQU0puY21Ga0xYVndJaUI0TVQwaU1TSWdlREk5SWpBaUlIa3hQU0l4SWlCNU1qMGlNQ0krUEhOMGIzQWdiMlptYzJWMFBTSXdMakFpSUhOMGIzQXRZMjlzYjNJOUluZG9hWFJsSWlCemRHOXdMVzl3WVdOcGRIazlJakVpSUM4K1BITjBiM0FnYjJabWMyVjBQU0l1T1NJZ2MzUnZjQzFqYjJ4dmNqMGlkMmhwZEdVaUlITjBiM0F0YjNCaFkybDBlVDBpTUNJZ0x6NDhMMnhwYm1WaGNrZHlZV1JwWlc1MFBqeHNhVzVsWVhKSGNtRmthV1Z1ZENCcFpEMGlaM0poWkMxa2IzZHVJaUI0TVQwaU1DSWdlREk5SWpFaUlIa3hQU0l3SWlCNU1qMGlNU0krUEhOMGIzQWdiMlptYzJWMFBTSXdMakFpSUhOMGIzQXRZMjlzYjNJOUluZG9hWFJsSWlCemRHOXdMVzl3WVdOcGRIazlJakVpSUM4K1BITjBiM0FnYjJabWMyVjBQU0l3TGpraUlITjBiM0F0WTI5c2IzSTlJbmRvYVhSbElpQnpkRzl3TFc5d1lXTnBkSGs5SWpBaUlDOCtQQzlzYVc1bFlYSkhjbUZrYVdWdWRENDhiV0Z6YXlCcFpEMGlabUZrWlMxMWNDSWdiV0Z6YTBOdmJuUmxiblJWYm1sMGN6MGliMkpxWldOMFFtOTFibVJwYm1kQ2IzZ2lQanh5WldOMElIZHBaSFJvUFNJeElpQm9aV2xuYUhROUlqRWlJR1pwYkd3OUluVnliQ2dqWjNKaFpDMTFjQ2tpSUM4K1BDOXRZWE5yUGp4dFlYTnJJR2xrUFNKbVlXUmxMV1J2ZDI0aUlHMWhjMnREYjI1MFpXNTBWVzVwZEhNOUltOWlhbVZqZEVKdmRXNWthVzVuUW05NElqNDhjbVZqZENCM2FXUjBhRDBpTVNJZ2FHVnBaMmgwUFNJeElpQm1hV3hzUFNKMWNtd29JMmR5WVdRdFpHOTNiaWtpSUM4K1BDOXRZWE5yUGp4dFlYTnJJR2xrUFNKdWIyNWxJaUJ0WVhOclEyOXVkR1Z1ZEZWdWFYUnpQU0p2WW1wbFkzUkNiM1Z1WkdsdVowSnZlQ0krUEhKbFkzUWdkMmxrZEdnOUlqRWlJR2hsYVdkb2REMGlNU0lnWm1sc2JEMGlkMmhwZEdVaUlDOCtQQzl0WVhOclBqeHNhVzVsWVhKSGNtRmthV1Z1ZENCcFpEMGlaM0poWkMxemVXMWliMndpUGp4emRHOXdJRzltWm5ObGREMGlNQzQzSWlCemRHOXdMV052Ykc5eVBTSjNhR2wwWlNJZ2MzUnZjQzF2Y0dGamFYUjVQU0l4SWlBdlBqeHpkRzl3SUc5bVpuTmxkRDBpTGprMUlpQnpkRzl3TFdOdmJHOXlQU0ozYUdsMFpTSWdjM1J2Y0MxdmNHRmphWFI1UFNJd0lpQXZQand2YkdsdVpXRnlSM0poWkdsbGJuUStQRzFoYzJzZ2FXUTlJbVpoWkdVdGMzbHRZbTlzSWlCdFlYTnJRMjl1ZEdWdWRGVnVhWFJ6UFNKMWMyVnlVM0JoWTJWUGJsVnpaU0krUEhKbFkzUWdkMmxrZEdnOUlqSTVNSEI0SWlCb1pXbG5hSFE5SWpJd01IQjRJaUJtYVd4c1BTSjFjbXdvSTJkeVlXUXRjM2x0WW05c0tTSWdMejQ4TDIxaGMycytQQzlrWldaelBqeG5JR05zYVhBdGNHRjBhRDBpZFhKc0tDTmpiM0p1WlhKektTSStQSEpsWTNRZ1ptbHNiRDBpWVdKalpHVmhJaUI0UFNJd2NIZ2lJSGs5SWpCd2VDSWdkMmxrZEdnOUlqSTVNSEI0SWlCb1pXbG5hSFE5SWpVd01IQjRJaUF2UGp4eVpXTjBJSE4wZVd4bFBTSm1hV3gwWlhJNklIVnliQ2dqWmpFcElpQjRQU0l3Y0hnaUlIazlJakJ3ZUNJZ2QybGtkR2c5SWpJNU1IQjRJaUJvWldsbmFIUTlJalV3TUhCNElpQXZQaUE4WnlCemRIbHNaVDBpWm1sc2RHVnlPblZ5YkNnamRHOXdMWEpsWjJsdmJpMWliSFZ5S1RzZ2RISmhibk5tYjNKdE9uTmpZV3hsS0RFdU5TazdJSFJ5WVc1elptOXliUzF2Y21sbmFXNDZZMlZ1ZEdWeUlIUnZjRHNpUGp4eVpXTjBJR1pwYkd3OUltNXZibVVpSUhnOUlqQndlQ0lnZVQwaU1IQjRJaUIzYVdSMGFEMGlNamt3Y0hnaUlHaGxhV2RvZEQwaU5UQXdjSGdpSUM4K1BHVnNiR2x3YzJVZ1kzZzlJalV3SlNJZ1kzazlJakJ3ZUNJZ2NuZzlJakU0TUhCNElpQnllVDBpTVRJd2NIZ2lJR1pwYkd3OUlpTXdNREFpSUc5d1lXTnBkSGs5SWpBdU9EVWlJQzgrUEM5blBqeHlaV04wSUhnOUlqQWlJSGs5SWpBaUlIZHBaSFJvUFNJeU9UQWlJR2hsYVdkb2REMGlOVEF3SWlCeWVEMGlORElpSUhKNVBTSTBNaUlnWm1sc2JEMGljbWRpWVNnd0xEQXNNQ3d3S1NJZ2MzUnliMnRsUFNKeVoySmhLREkxTlN3eU5UVXNNalUxTERBdU1pa2lJQzgrUEM5blBqeDBaWGgwSUhSbGVIUXRjbVZ1WkdWeWFXNW5QU0p2Y0hScGJXbDZaVk53WldWa0lqNDhkR1Y0ZEZCaGRHZ2djM1JoY25SUFptWnpaWFE5SWkweE1EQWxJaUJtYVd4c1BTSjNhR2wwWlNJZ1ptOXVkQzFtWVcxcGJIazlJaWREYjNWeWFXVnlJRTVsZHljc0lHMXZibTl6Y0dGalpTSWdabTl1ZEMxemFYcGxQU0l4TUhCNElpQjRiR2x1YXpwb2NtVm1QU0lqZEdWNGRDMXdZWFJvTFdFaVBqQjRNVEl6TkRVMk56ZzVNREV5TXpRMU5qYzRPVEV5TXpRMU5qYzRPVEF4TWpNME5UWTNPRGt3TVNEaWdLSWdWMDVoZEdsMlpWUnZhMlZ1SUR4aGJtbHRZWFJsSUdGa1pHbDBhWFpsUFNKemRXMGlJR0YwZEhKcFluVjBaVTVoYldVOUluTjBZWEowVDJabWMyVjBJaUJtY205dFBTSXdKU0lnZEc4OUlqRXdNQ1VpSUdKbFoybHVQU0l3Y3lJZ1pIVnlQU0l6TUhNaUlISmxjR1ZoZEVOdmRXNTBQU0pwYm1SbFptbHVhWFJsSWlBdlBqd3ZkR1Y0ZEZCaGRHZytJRHgwWlhoMFVHRjBhQ0J6ZEdGeWRFOW1abk5sZEQwaU1DVWlJR1pwYkd3OUluZG9hWFJsSWlCbWIyNTBMV1poYldsc2VUMGlKME52ZFhKcFpYSWdUbVYzSnl3Z2JXOXViM053WVdObElpQm1iMjUwTFhOcGVtVTlJakV3Y0hnaUlIaHNhVzVyT21oeVpXWTlJaU4wWlhoMExYQmhkR2d0WVNJK01IZ3hNak0wTlRZM09Ea3dNVEl6TkRVMk56ZzVNVEl6TkRVMk56ZzVNREV5TXpRMU5qYzRPVEF4SU9LQW9pQlhUbUYwYVhabFZHOXJaVzRnUEdGdWFXMWhkR1VnWVdSa2FYUnBkbVU5SW5OMWJTSWdZWFIwY21saWRYUmxUbUZ0WlQwaWMzUmhjblJQWm1aelpYUWlJR1p5YjIwOUlqQWxJaUIwYnowaU1UQXdKU0lnWW1WbmFXNDlJakJ6SWlCa2RYSTlJak13Y3lJZ2NtVndaV0YwUTI5MWJuUTlJbWx1WkdWbWFXNXBkR1VpSUM4K0lEd3ZkR1Y0ZEZCaGRHZytQSFJsZUhSUVlYUm9JSE4wWVhKMFQyWm1jMlYwUFNJMU1DVWlJR1pwYkd3OUluZG9hWFJsSWlCbWIyNTBMV1poYldsc2VUMGlKME52ZFhKcFpYSWdUbVYzSnl3Z2JXOXViM053WVdObElpQm1iMjUwTFhOcGVtVTlJakV3Y0hnaUlIaHNhVzVyT21oeVpXWTlJaU4wWlhoMExYQmhkR2d0WVNJK01IaGhZbU5rWldGaVkyUmxabUZpWTJSbFptRmlZMlJsWm1GaVkyUmxabUZpWTJSbFptRmlZMlJtSU9LQW9pQlZUa2tnUEdGdWFXMWhkR1VnWVdSa2FYUnBkbVU5SW5OMWJTSWdZWFIwY21saWRYUmxUbUZ0WlQwaWMzUmhjblJQWm1aelpYUWlJR1p5YjIwOUlqQWxJaUIwYnowaU1UQXdKU0lnWW1WbmFXNDlJakJ6SWlCa2RYSTlJak13Y3lJZ2NtVndaV0YwUTI5MWJuUTlJbWx1WkdWbWFXNXBkR1VpSUM4K1BDOTBaWGgwVUdGMGFENDhkR1Y0ZEZCaGRHZ2djM1JoY25SUFptWnpaWFE5SWkwMU1DVWlJR1pwYkd3OUluZG9hWFJsSWlCbWIyNTBMV1poYldsc2VUMGlKME52ZFhKcFpYSWdUbVYzSnl3Z2JXOXViM053WVdObElpQm1iMjUwTFhOcGVtVTlJakV3Y0hnaUlIaHNhVzVyT21oeVpXWTlJaU4wWlhoMExYQmhkR2d0WVNJK01IaGhZbU5rWldGaVkyUmxabUZpWTJSbFptRmlZMlJsWm1GaVkyUmxabUZpWTJSbFptRmlZMlJtSU9LQW9pQlZUa2tnUEdGdWFXMWhkR1VnWVdSa2FYUnBkbVU5SW5OMWJTSWdZWFIwY21saWRYUmxUbUZ0WlQwaWMzUmhjblJQWm1aelpYUWlJR1p5YjIwOUlqQWxJaUIwYnowaU1UQXdKU0lnWW1WbmFXNDlJakJ6SWlCa2RYSTlJak13Y3lJZ2NtVndaV0YwUTI5MWJuUTlJbWx1WkdWbWFXNXBkR1VpSUM4K1BDOTBaWGgwVUdGMGFENDhMM1JsZUhRK1BHY2diV0Z6YXowaWRYSnNLQ05tWVdSbExYTjViV0p2YkNraVBqeHlaV04wSUdacGJHdzlJbTV2Ym1VaUlIZzlJakJ3ZUNJZ2VUMGlNSEI0SWlCM2FXUjBhRDBpTWprd2NIZ2lJR2hsYVdkb2REMGlNakF3Y0hnaUlDOCtJRHgwWlhoMElIazlJamN3Y0hnaUlIZzlJak15Y0hnaUlHWnBiR3c5SW5kb2FYUmxJaUJtYjI1MExXWmhiV2xzZVQwaUowTnZkWEpwWlhJZ1RtVjNKeXdnYlc5dWIzTndZV05sSWlCbWIyNTBMWGRsYVdkb2REMGlNakF3SWlCbWIyNTBMWE5wZW1VOUlqTTJjSGdpUGxWT1NTOVhUbUYwYVhabFZHOXJaVzQ4TDNSbGVIUStQQzluUGp4eVpXTjBJSGc5SWpFMklpQjVQU0l4TmlJZ2QybGtkR2c5SWpJMU9DSWdhR1ZwWjJoMFBTSTBOamdpSUhKNFBTSXlOaUlnY25rOUlqSTJJaUJtYVd4c1BTSnlaMkpoS0RBc01Dd3dMREFwSWlCemRISnZhMlU5SW5KblltRW9NalUxTERJMU5Td3lOVFVzTUM0eUtTSWdMejQ4WnlCdFlYTnJQU0oxY213b0kyWmhaR1V0Wkc5M2Jpa2lJSE4wZVd4bFBTSjBjbUZ1YzJadmNtMDZkSEpoYm5Oc1lYUmxLRGN5Y0hnc01UZzVjSGdwSWo0OGNtVmpkQ0I0UFNJdE1UWndlQ0lnZVQwaUxURTJjSGdpSUhkcFpIUm9QU0l4T0RCd2VDSWdhR1ZwWjJoMFBTSXhPREJ3ZUNJZ1ptbHNiRDBpYm05dVpTSWdMejQ4Y0dGMGFDQmtQU0pOTVNBeFF6TXpJRFUzSURnNUlERXhNeUF4TkRVZ01UUTFJaUJ6ZEhKdmEyVTlJbkpuWW1Fb01Dd3dMREFzTUM0ektTSWdjM1J5YjJ0bExYZHBaSFJvUFNJek1uQjRJaUJtYVd4c1BTSnViMjVsSWlCemRISnZhMlV0YkdsdVpXTmhjRDBpY205MWJtUWlJQzgrUEM5blBqeG5JRzFoYzJzOUluVnliQ2dqWm1Ga1pTMWtiM2R1S1NJZ2MzUjViR1U5SW5SeVlXNXpabTl5YlRwMGNtRnVjMnhoZEdVb056SndlQ3d4T0Rsd2VDa2lQanh5WldOMElIZzlJaTB4Tm5CNElpQjVQU0l0TVRad2VDSWdkMmxrZEdnOUlqRTRNSEI0SWlCb1pXbG5hSFE5SWpFNE1IQjRJaUJtYVd4c1BTSnViMjVsSWlBdlBqeHdZWFJvSUdROUlrMHhJREZETXpNZ05UY2dPRGtnTVRFeklERTBOU0F4TkRVaUlITjBjbTlyWlQwaWNtZGlZU2d5TlRVc01qVTFMREkxTlN3eEtTSWdabWxzYkQwaWJtOXVaU0lnYzNSeWIydGxMV3hwYm1WallYQTlJbkp2ZFc1a0lpQXZQand2Wno0OFkybHlZMnhsSUdONFBTSTNNM0I0SWlCamVUMGlNVGt3Y0hnaUlISTlJalJ3ZUNJZ1ptbHNiRDBpZDJocGRHVWlJQzgrUEdOcGNtTnNaU0JqZUQwaU56TndlQ0lnWTNrOUlqRTVNSEI0SWlCeVBTSXlOSEI0SWlCbWFXeHNQU0p1YjI1bElpQnpkSEp2YTJVOUluZG9hWFJsSWlBdlBpQThaeUJ6ZEhsc1pUMGlkSEpoYm5ObWIzSnRPblJ5WVc1emJHRjBaU2d5T1hCNExDQXpPRFJ3ZUNraVBqeHlaV04wSUhkcFpIUm9QU0kyTTNCNElpQm9aV2xuYUhROUlqSTJjSGdpSUhKNFBTSTRjSGdpSUhKNVBTSTRjSGdpSUdacGJHdzlJbkpuWW1Fb01Dd3dMREFzTUM0MktTSWdMejQ4ZEdWNGRDQjRQU0l4TW5CNElpQjVQU0l4TjNCNElpQm1iMjUwTFdaaGJXbHNlVDBpSjBOdmRYSnBaWElnVG1WM0p5d2diVzl1YjNOd1lXTmxJaUJtYjI1MExYTnBlbVU5SWpFeWNIZ2lJR1pwYkd3OUluZG9hWFJsSWo0OGRITndZVzRnWm1sc2JEMGljbWRpWVNneU5UVXNNalUxTERJMU5Td3dMallwSWo1SlJEb2dQQzkwYzNCaGJqNHhQQzkwWlhoMFBqd3ZaejRnUEdjZ2MzUjViR1U5SW5SeVlXNXpabTl5YlRwMGNtRnVjMnhoZEdVb01qbHdlQ3dnTkRFMGNIZ3BJajQ4Y21WamRDQjNhV1IwYUQwaU1UQTFjSGdpSUdobGFXZG9kRDBpTWpad2VDSWdjbmc5SWpod2VDSWdjbms5SWpod2VDSWdabWxzYkQwaWNtZGlZU2d3TERBc01Dd3dMallwSWlBdlBqeDBaWGgwSUhnOUlqRXljSGdpSUhrOUlqRTNjSGdpSUdadmJuUXRabUZ0YVd4NVBTSW5RMjkxY21sbGNpQk9aWGNuTENCdGIyNXZjM0JoWTJVaUlHWnZiblF0YzJsNlpUMGlNVEp3ZUNJZ1ptbHNiRDBpZDJocGRHVWlQangwYzNCaGJpQm1hV3hzUFNKeVoySmhLREkxTlN3eU5UVXNNalUxTERBdU5pa2lQazFwYmlCVWFXTnJPaUE4TDNSemNHRnVQakE4TDNSbGVIUStQQzluUGlBOFp5QnpkSGxzWlQwaWRISmhibk5tYjNKdE9uUnlZVzV6YkdGMFpTZ3lPWEI0TENBME5EUndlQ2tpUGp4eVpXTjBJSGRwWkhSb1BTSXhNalp3ZUNJZ2FHVnBaMmgwUFNJeU5uQjRJaUJ5ZUQwaU9IQjRJaUJ5ZVQwaU9IQjRJaUJtYVd4c1BTSnlaMkpoS0RBc01Dd3dMREF1TmlraUlDOCtQSFJsZUhRZ2VEMGlNVEp3ZUNJZ2VUMGlNVGR3ZUNJZ1ptOXVkQzFtWVcxcGJIazlJaWREYjNWeWFXVnlJRTVsZHljc0lHMXZibTl6Y0dGalpTSWdabTl1ZEMxemFYcGxQU0l4TW5CNElpQm1hV3hzUFNKM2FHbDBaU0krUEhSemNHRnVJR1pwYkd3OUluSm5ZbUVvTWpVMUxESTFOU3d5TlRVc01DNDJLU0krVFdGNElGUnBZMnM2SUR3dmRITndZVzQrTVRBd01Ed3ZkR1Y0ZEQ0OEwyYytQR2NnYzNSNWJHVTlJblJ5WVc1elptOXliVHAwY21GdWMyeGhkR1VvTWpJMmNIZ3NJRFF6TTNCNEtTSStQSEpsWTNRZ2QybGtkR2c5SWpNMmNIZ2lJR2hsYVdkb2REMGlNelp3ZUNJZ2NuZzlJamh3ZUNJZ2NuazlJamh3ZUNJZ1ptbHNiRDBpYm05dVpTSWdjM1J5YjJ0bFBTSnlaMkpoS0RJMU5Td3lOVFVzTWpVMUxEQXVNaWtpSUM4K1BIQmhkR2dnYzNSeWIydGxMV3hwYm1WallYQTlJbkp2ZFc1a0lpQmtQU0pOT0NBNVF6Z3VNREF3TURRZ01qSXVPVFE1TkNBeE5pNHlNRGs1SURJNElESTNJREk0SWlCbWFXeHNQU0p1YjI1bElpQnpkSEp2YTJVOUluZG9hWFJsSWlBdlBqeGphWEpqYkdVZ2MzUjViR1U5SW5SeVlXNXpabTl5YlRwMGNtRnVjMnhoZEdVelpDZ3hNM0I0TENBeU0zQjRMQ0F3Y0hncElpQmplRDBpTUhCNElpQmplVDBpTUhCNElpQnlQU0kwY0hnaUlHWnBiR3c5SW5kb2FYUmxJaTgrUEM5blBqeG5JSE4wZVd4bFBTSjBjbUZ1YzJadmNtMDZkSEpoYm5Oc1lYUmxLREl5Tm5CNExDQXpPVEp3ZUNraVBqeHlaV04wSUhkcFpIUm9QU0l6Tm5CNElpQm9aV2xuYUhROUlqTTJjSGdpSUhKNFBTSTRjSGdpSUhKNVBTSTRjSGdpSUdacGJHdzlJbTV2Ym1VaUlITjBjbTlyWlQwaWNtZGlZU2d5TlRVc01qVTFMREkxTlN3d0xqSXBJaUF2UGp4blBqeHdZWFJvSUhOMGVXeGxQU0owY21GdWMyWnZjbTA2ZEhKaGJuTnNZWFJsS0Rad2VDdzJjSGdwSWlCa1BTSk5NVElnTUV3eE1pNDJOVEl5SURrdU5UWTFPRGRNTVRnZ01TNDJNRGMzVERFekxqYzRNVGtnTVRBdU1qRTRNVXd5TWk0ek9USXpJRFpNTVRRdU5ETTBNU0F4TVM0ek5EYzRUREkwSURFeVRERTBMalF6TkRFZ01USXVOalV5TWt3eU1pNHpPVEl6SURFNFRERXpMamM0TVRrZ01UTXVOemd4T1V3eE9DQXlNaTR6T1RJelRERXlMalkxTWpJZ01UUXVORE0wTVV3eE1pQXlORXd4TVM0ek5EYzRJREUwTGpRek5ERk1OaUF5TWk0ek9USXpUREV3TGpJeE9ERWdNVE11TnpneE9Vd3hMall3TnpjZ01UaE1PUzQxTmpVNE55QXhNaTQyTlRJeVREQWdNVEpNT1M0MU5qVTROeUF4TVM0ek5EYzRUREV1TmpBM055QTJUREV3TGpJeE9ERWdNVEF1TWpFNE1VdzJJREV1TmpBM04wd3hNUzR6TkRjNElEa3VOVFkxT0RkTU1USWdNRm9pSUdacGJHdzlJbmRvYVhSbElpQXZQanhoYm1sdFlYUmxWSEpoYm5ObWIzSnRJR0YwZEhKcFluVjBaVTVoYldVOUluUnlZVzV6Wm05eWJTSWdkSGx3WlQwaWNtOTBZWFJsSWlCbWNtOXRQU0l3SURFNElERTRJaUIwYnowaU16WXdJREU0SURFNElpQmtkWEk5SWpFd2N5SWdjbVZ3WldGMFEyOTFiblE5SW1sdVpHVm1hVzVwZEdVaUx6NDhMMmMrUEM5blBqd3ZjM1puUGc9PSJ9"`; diff --git a/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap b/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap index 7ef50c573..75c258d76 100644 --- a/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap +++ b/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap @@ -1,39 +1,39 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`NonfungiblePositionManager #burn gas [ @skip-on-coverage ] 1`] = `62302`; +exports[`NonfungiblePositionManager #burn gas [ @skip-on-coverage ] 1`] = `62284`; -exports[`NonfungiblePositionManager #collect gas transfers both [ @skip-on-coverage ] 1`] = `126407`; +exports[`NonfungiblePositionManager #collect gas transfers both [ @skip-on-coverage ] 1`] = `126789`; -exports[`NonfungiblePositionManager #collect gas transfers token0 only [ @skip-on-coverage ] 1`] = `122745`; +exports[`NonfungiblePositionManager #collect gas transfers token0 only [ @skip-on-coverage ] 1`] = `123127`; -exports[`NonfungiblePositionManager #collect gas transfers token1 only [ @skip-on-coverage ] 1`] = `122936`; +exports[`NonfungiblePositionManager #collect gas transfers token1 only [ @skip-on-coverage ] 1`] = `123318`; -exports[`NonfungiblePositionManager #createAndInitializePoolIfNecessary gas [ @skip-on-coverage ] 1`] = `5245683`; +exports[`NonfungiblePositionManager #createAndInitializePoolIfNecessary gas [ @skip-on-coverage ] 1`] = `5264360`; -exports[`NonfungiblePositionManager #decreaseLiquidity gas complete decrease [ @skip-on-coverage ] 1`] = `171889`; +exports[`NonfungiblePositionManager #decreaseLiquidity gas complete decrease [ @skip-on-coverage ] 1`] = `172820`; -exports[`NonfungiblePositionManager #decreaseLiquidity gas partial decrease [ @skip-on-coverage ] 1`] = `176869`; +exports[`NonfungiblePositionManager #decreaseLiquidity gas partial decrease [ @skip-on-coverage ] 1`] = `178032`; -exports[`NonfungiblePositionManager #increaseLiquidity gas [ @skip-on-coverage ] 1`] = `184149`; +exports[`NonfungiblePositionManager #increaseLiquidity gas [ @skip-on-coverage ] 1`] = `187685`; -exports[`NonfungiblePositionManager #mint gas first mint for pool [ @skip-on-coverage ] 1`] = `636761`; +exports[`NonfungiblePositionManager #mint gas first mint for pool [ @skip-on-coverage ] 1`] = `638156`; -exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with non-zero refund [ @skip-on-coverage ] 1`] = `651124`; +exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with non-zero refund [ @skip-on-coverage ] 1`] = `652502`; -exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with zero refund [ @skip-on-coverage ] 1`] = `643957`; +exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with zero refund [ @skip-on-coverage ] 1`] = `645335`; -exports[`NonfungiblePositionManager #mint gas mint for same pool, different ticks [ @skip-on-coverage ] 1`] = `442373`; +exports[`NonfungiblePositionManager #mint gas mint for same pool, different ticks [ @skip-on-coverage ] 1`] = `443768`; -exports[`NonfungiblePositionManager #mint gas mint on same ticks [ @skip-on-coverage ] 1`] = `332144`; +exports[`NonfungiblePositionManager #mint gas mint on same ticks [ @skip-on-coverage ] 1`] = `333539`; exports[`NonfungiblePositionManager #permit owned by eoa gas [ @skip-on-coverage ] 1`] = `60036`; exports[`NonfungiblePositionManager #permit owned by verifying contract gas [ @skip-on-coverage ] 1`] = `63902`; -exports[`NonfungiblePositionManager #transferFrom gas [ @skip-on-coverage ] 1`] = `86323`; +exports[`NonfungiblePositionManager #transferFrom gas [ @skip-on-coverage ] 1`] = `86301`; -exports[`NonfungiblePositionManager #transferFrom gas comes from approved [ @skip-on-coverage ] 1`] = `87247`; +exports[`NonfungiblePositionManager #transferFrom gas comes from approved [ @skip-on-coverage ] 1`] = `87225`; -exports[`NonfungiblePositionManager bytecode size [ @skip-on-coverage ] 1`] = `22035`; +exports[`NonfungiblePositionManager bytecode size [ @skip-on-coverage ] 1`] = `22643`; -exports[`NonfungiblePositionManager multicall exit gas [ @skip-on-coverage ] 1`] = `247656`; +exports[`NonfungiblePositionManager multicall exit gas [ @skip-on-coverage ] 1`] = `248587`; diff --git a/src/periphery/test/__snapshots__/PoolAddress.spec.ts.snap b/src/periphery/test/__snapshots__/PoolAddress.spec.ts.snap index 6733903ea..4e964728f 100644 --- a/src/periphery/test/__snapshots__/PoolAddress.spec.ts.snap +++ b/src/periphery/test/__snapshots__/PoolAddress.spec.ts.snap @@ -2,4 +2,4 @@ exports[`PoolAddress #computeAddress gas cost [ @skip-on-coverage ] 1`] = `673`; -exports[`PoolAddress #computeAddress matches example from core repo 1`] = `"0xb02b623725743aF173D5d58d776e9f99102FeE95"`; +exports[`PoolAddress #computeAddress matches example from core repo 1`] = `"0x6e0AB3e9378f2d1E848fAF676C3ca96ce3E38f09"`; diff --git a/src/periphery/test/__snapshots__/PositionValue.spec.ts.snap b/src/periphery/test/__snapshots__/PositionValue.spec.ts.snap index 4b6cbc34b..3e1c19599 100644 --- a/src/periphery/test/__snapshots__/PositionValue.spec.ts.snap +++ b/src/periphery/test/__snapshots__/PositionValue.spec.ts.snap @@ -1,11 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PositionValue #fees when price is above the position range gas 1`] = `53868`; +exports[`PositionValue #fees when price is above the position range gas 1`] = `53846`; -exports[`PositionValue #fees when price is below the position range gas 1`] = `53934`; +exports[`PositionValue #fees when price is below the position range gas 1`] = `53912`; -exports[`PositionValue #fees when price is within the position range gas 1`] = `60204`; +exports[`PositionValue #fees when price is within the position range gas 1`] = `60182`; exports[`PositionValue #principal gas 1`] = `26316`; -exports[`PositionValue #total gas 1`] = `63295`; +exports[`PositionValue #total gas 1`] = `63273`; diff --git a/src/periphery/test/__snapshots__/QuoterV2.spec.ts.snap b/src/periphery/test/__snapshots__/QuoterV2.spec.ts.snap index ca33b944c..608ccd2c5 100644 --- a/src/periphery/test/__snapshots__/QuoterV2.spec.ts.snap +++ b/src/periphery/test/__snapshots__/QuoterV2.spec.ts.snap @@ -1,29 +1,29 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`QuoterV2 quotes #quoteExactInputSingle gas [ @skip-on-coverage ] 0 -> 2 1`] = `158020`; +exports[`QuoterV2 quotes #quoteExactInputSingle gas [ @skip-on-coverage ] 0 -> 2 1`] = `161742`; -exports[`QuoterV2 quotes #quoteExactInputSingle gas [ @skip-on-coverage ] 2 -> 0 1`] = `157926`; +exports[`QuoterV2 quotes #quoteExactInputSingle gas [ @skip-on-coverage ] 2 -> 0 1`] = `161648`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 -> 1 1`] = `250787`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 -> 1 1`] = `268387`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 0 tick starting tick initialized 1`] = `107457`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 0 tick starting tick initialized 1`] = `110920`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 0 tick starting tick not initialized 1`] = `91987`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 0 tick starting tick not initialized 1`] = `95450`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 1 tick 1`] = `127553`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 1 tick 1`] = `131016`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 2 tick 1`] = `157897`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 2 tick 1`] = `161360`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 2 where tick after is initialized 1`] = `127562`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 0 -> 2 cross 2 where tick after is initialized 1`] = `131025`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 0 cross 1 tick 1`] = `127917`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 0 cross 1 tick 1`] = `131416`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 0 cross 2 ticks 1`] = `158532`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 0 cross 2 ticks 1`] = `162031`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 0 cross 2 where tick after is initialized 1`] = `158536`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 0 cross 2 where tick after is initialized 1`] = `162035`; -exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 1 1`] = `92909`; +exports[`QuoterV2 quotes #quoteExactOutput gas [ @skip-on-coverage ] 2 -> 1 1`] = `107038`; -exports[`QuoterV2 quotes #quoteExactOutputSingle gas [ @skip-on-coverage ] 0 -> 1 1`] = `92968`; +exports[`QuoterV2 quotes #quoteExactOutputSingle gas [ @skip-on-coverage ] 0 -> 1 1`] = `105180`; -exports[`QuoterV2 quotes #quoteExactOutputSingle gas [ @skip-on-coverage ] 1 -> 0 1`] = `92985`; +exports[`QuoterV2 quotes #quoteExactOutputSingle gas [ @skip-on-coverage ] 1 -> 0 1`] = `105233`; diff --git a/src/periphery/test/__snapshots__/SwapRouter.spec.ts.snap b/src/periphery/test/__snapshots__/SwapRouter.spec.ts.snap index 3fc20ad13..6ddccf87b 100644 --- a/src/periphery/test/__snapshots__/SwapRouter.spec.ts.snap +++ b/src/periphery/test/__snapshots__/SwapRouter.spec.ts.snap @@ -2,16 +2,16 @@ exports[`SwapRouter bytecode size [ @skip-on-coverage ] 1`] = `12653`; -exports[`SwapRouter swaps #exactInput multi-pool gas cost [ @skip-on-coverage ] 1`] = `214969`; +exports[`SwapRouter swaps #exactInput multi-pool gas cost [ @skip-on-coverage ] 1`] = `217289`; -exports[`SwapRouter swaps #exactInputSingle gas cost [ @skip-on-coverage ] 1`] = `126233`; +exports[`SwapRouter swaps #exactInputSingle gas cost [ @skip-on-coverage ] 1`] = `127393`; -exports[`SwapRouter swaps #exactInputSingleSupportingFeeOnTransferTokens gas cost [ @skip-on-coverage ] 1`] = `179210`; +exports[`SwapRouter swaps #exactInputSingleSupportingFeeOnTransferTokens gas cost [ @skip-on-coverage ] 1`] = `180364`; -exports[`SwapRouter swaps #exactOutput Native input WNativeToken gas cost [ @skip-on-coverage ] 1`] = `217734`; +exports[`SwapRouter swaps #exactOutput Native input WNativeToken gas cost [ @skip-on-coverage ] 1`] = `220054`; -exports[`SwapRouter swaps #exactOutput multi-pool gas cost [ @skip-on-coverage ] 1`] = `213861`; +exports[`SwapRouter swaps #exactOutput multi-pool gas cost [ @skip-on-coverage ] 1`] = `216181`; -exports[`SwapRouter swaps #exactOutput single-pool gas cost [ @skip-on-coverage ] 1`] = `132059`; +exports[`SwapRouter swaps #exactOutput single-pool gas cost [ @skip-on-coverage ] 1`] = `133219`; -exports[`SwapRouter swaps #exactOutputSingle gas cost [ @skip-on-coverage ] 1`] = `132317`; +exports[`SwapRouter swaps #exactOutputSingle gas cost [ @skip-on-coverage ] 1`] = `133477`; diff --git a/src/periphery/test/__snapshots__/V3Migrator.spec.ts.snap b/src/periphery/test/__snapshots__/V3Migrator.spec.ts.snap index 50541e227..c965682de 100644 --- a/src/periphery/test/__snapshots__/V3Migrator.spec.ts.snap +++ b/src/periphery/test/__snapshots__/V3Migrator.spec.ts.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`V3Migrator #migrate gas [ @skip-on-coverage ] 1`] = `755875`; +exports[`V3Migrator #migrate gas [ @skip-on-coverage ] 1`] = `757946`; diff --git a/src/periphery/test/shared/completeFixture.ts b/src/periphery/test/shared/completeFixture.ts index bf7da8c1b..c281821ad 100644 --- a/src/periphery/test/shared/completeFixture.ts +++ b/src/periphery/test/shared/completeFixture.ts @@ -9,6 +9,7 @@ import { NonfungibleTokenPositionDescriptor, TestERC20, AlgebraFactory, + MockPlugin, MockPluginFactory, AlgebraCustomPoolEntryPoint, CustomPoolDeployerTest, @@ -106,8 +107,11 @@ const completeFixture: () => Promise<{ const entryPointFactory = await ethers.getContractFactory("AlgebraCustomPoolEntryPoint"); const entryPoint = await entryPointFactory.deploy(factory) as any as AlgebraCustomPoolEntryPoint; + const customPluginFactory = await ethers.getContractFactory("MockPlugin"); + const customPlugin = await customPluginFactory.deploy() as any as MockPlugin; + const customPoolDeployerFactory = await ethers.getContractFactory("CustomPoolDeployerTest"); - const customPoolDeployer = await customPoolDeployerFactory.deploy(entryPoint, ZERO_ADDRESS) as any as CustomPoolDeployerTest; + const customPoolDeployer = await customPoolDeployerFactory.deploy(entryPoint, customPlugin) as any as CustomPoolDeployerTest; let customPoolDeployerRole = await factory.CUSTOM_POOL_DEPLOYER() let poolAdministratorRole = await factory.POOLS_ADMINISTRATOR_ROLE() @@ -130,7 +134,7 @@ const completeFixture: () => Promise<{ customPoolDeployer, path, nft, - nftDescriptor: nftDescriptorProxied, + nftDescriptor: nftDescriptorProxied }; }; diff --git a/src/periphery/test/shared/quoter.ts b/src/periphery/test/shared/quoter.ts index f94e69a01..953b7c1b6 100644 --- a/src/periphery/test/shared/quoter.ts +++ b/src/periphery/test/shared/quoter.ts @@ -29,6 +29,7 @@ export async function createPool( amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: '0x', }; return nft.mint(liquidityParams); @@ -57,6 +58,7 @@ export async function createPoolWithMultiplePositions( amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: '0x', }; await nft.mint(liquidityParams); @@ -73,6 +75,7 @@ export async function createPoolWithMultiplePositions( amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: '0x', }; await nft.mint(liquidityParams2); @@ -89,6 +92,7 @@ export async function createPoolWithMultiplePositions( amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: '0x', }; return nft.mint(liquidityParams3); @@ -117,6 +121,7 @@ export async function createPoolWithZeroTickInitialized( amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: '0x', }; await nft.mint(liquidityParams); @@ -133,6 +138,7 @@ export async function createPoolWithZeroTickInitialized( amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: '0x', }; await nft.mint(liquidityParams2); @@ -149,6 +155,7 @@ export async function createPoolWithZeroTickInitialized( amount0Min: 0, amount1Min: 0, deadline: 1, + pluginData: '0x', }; return nft.mint(liquidityParams3); diff --git a/src/plugin/contracts/AlgebraBasePluginV1.sol b/src/plugin/contracts/AlgebraBasePluginV1.sol index 9f244b361..e7eb7c290 100644 --- a/src/plugin/contracts/AlgebraBasePluginV1.sol +++ b/src/plugin/contracts/AlgebraBasePluginV1.sol @@ -10,7 +10,7 @@ import './plugins/FarmingProxyPlugin.sol'; import './plugins/SlidingFeePlugin.sol'; import './plugins/VolatilityOraclePlugin.sol'; -/// @title Algebra Integral 1.2.1 adaptive fee plugin +/// @title Algebra Integral 1.2.2 adaptive fee plugin contract AlgebraBasePluginV1 is DynamicFeePlugin, FarmingProxyPlugin, VolatilityOraclePlugin { using Plugins for uint8; diff --git a/src/plugin/contracts/AlgebraBasePluginV2.sol b/src/plugin/contracts/AlgebraBasePluginV2.sol index cbbeed0e6..90d0e657a 100644 --- a/src/plugin/contracts/AlgebraBasePluginV2.sol +++ b/src/plugin/contracts/AlgebraBasePluginV2.sol @@ -9,7 +9,7 @@ import './plugins/FarmingProxyPlugin.sol'; import './plugins/SlidingFeePlugin.sol'; import './plugins/VolatilityOraclePlugin.sol'; -/// @title Algebra Integral 1.2.1 sliding fee plugin +/// @title Algebra Integral 1.2.2 sliding fee plugin contract AlgebraBasePluginV2 is SlidingFeePlugin, FarmingProxyPlugin, VolatilityOraclePlugin { using Plugins for uint8; diff --git a/src/plugin/contracts/BasePluginV1Factory.sol b/src/plugin/contracts/BasePluginV1Factory.sol index 42e8d89d6..5dbcd0e0d 100644 --- a/src/plugin/contracts/BasePluginV1Factory.sol +++ b/src/plugin/contracts/BasePluginV1Factory.sol @@ -5,7 +5,7 @@ import './interfaces/IBasePluginV1Factory.sol'; import './libraries/AdaptiveFee.sol'; import './AlgebraBasePluginV1.sol'; -/// @title Algebra Integral 1.2.1 default plugin factory +/// @title Algebra Integral 1.2.2 default plugin factory /// @notice This contract creates Algebra adaptive fee plugins for Algebra liquidity pools /// @dev This plugin factory can only be used for Algebra base pools contract BasePluginV1Factory is IBasePluginV1Factory { diff --git a/src/plugin/contracts/BasePluginV2Factory.sol b/src/plugin/contracts/BasePluginV2Factory.sol index 2714c2ce3..2afc35f34 100644 --- a/src/plugin/contracts/BasePluginV2Factory.sol +++ b/src/plugin/contracts/BasePluginV2Factory.sol @@ -5,7 +5,7 @@ import './interfaces/IBasePluginV2Factory.sol'; import './AlgebraBasePluginV2.sol'; import './interfaces/plugins/ISlidingFeePlugin.sol'; -/// @title Algebra Integral 1.2.1 default plugin factory +/// @title Algebra Integral 1.2.2 default plugin factory /// @notice This contract creates Algebra sliding fee plugins for Algebra liquidity pools /// @dev This plugin factory can only be used for Algebra base pools contract BasePluginV2Factory is IBasePluginV2Factory { diff --git a/src/plugin/contracts/base/AlgebraBasePlugin.sol b/src/plugin/contracts/base/AlgebraBasePlugin.sol index f7b1c378c..a713ab0c1 100644 --- a/src/plugin/contracts/base/AlgebraBasePlugin.sol +++ b/src/plugin/contracts/base/AlgebraBasePlugin.sol @@ -3,7 +3,7 @@ pragma solidity =0.8.20; import './BasePlugin.sol'; -/// @title Algebra' internal Integral 1.2.1 plugin base +/// @title Algebra' internal Integral 1.2.2 plugin base /// @notice This contract inherits BasePlugin and implements virtual functions abstract contract AlgebraBasePlugin is BasePlugin { address internal immutable factory; diff --git a/src/plugin/contracts/base/BasePlugin.sol b/src/plugin/contracts/base/BasePlugin.sol index 691a3455e..5cfcffbc8 100644 --- a/src/plugin/contracts/base/BasePlugin.sol +++ b/src/plugin/contracts/base/BasePlugin.sol @@ -11,7 +11,7 @@ import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol'; import '../interfaces/IBasePlugin.sol'; -/// @title Algebra Integral 1.2.1 plugin base +/// @title Algebra Integral 1.2.2 plugin base /// @notice This contract simplifies development process of plugins by providing base functionality abstract contract BasePlugin is IBasePlugin, Timestamp { using Plugins for uint8; diff --git a/src/plugin/contracts/lens/AlgebraOracleV1TWAP.sol b/src/plugin/contracts/lens/AlgebraOracleV1TWAP.sol index e9646e8ef..5bc1a0365 100644 --- a/src/plugin/contracts/lens/AlgebraOracleV1TWAP.sol +++ b/src/plugin/contracts/lens/AlgebraOracleV1TWAP.sol @@ -8,7 +8,7 @@ import './IAlgebraOracleV1TWAP.sol'; import '../libraries/integration/OracleLibrary.sol'; -/// @title Algebra Integral 1.2.1 base plugin V1 oracle frontend +/// @title Algebra Integral 1.2.2 base plugin V1 oracle frontend /// @notice Provides data from oracle corresponding pool /// @dev These functions are not very gas efficient and it is better not to use them on-chain contract AlgebraOracleV1TWAP is IAlgebraOracleV1TWAP { diff --git a/src/plugin/contracts/plugins/DynamicFeePlugin.sol b/src/plugin/contracts/plugins/DynamicFeePlugin.sol index 7262c662c..ef98e3e5d 100644 --- a/src/plugin/contracts/plugins/DynamicFeePlugin.sol +++ b/src/plugin/contracts/plugins/DynamicFeePlugin.sol @@ -13,7 +13,7 @@ import '../libraries/AdaptiveFee.sol'; import '../types/AlgebraFeeConfigurationU144.sol'; import '../base/AlgebraBasePlugin.sol'; -/// @title Algebra Integral 1.2.1 default plugin +/// @title Algebra Integral 1.2.2 default plugin /// @notice This contract stores timepoints and calculates adaptive fee and statistical averages abstract contract DynamicFeePlugin is AlgebraBasePlugin, IDynamicFeeManager { using Plugins for uint8; diff --git a/src/plugin/contracts/plugins/FarmingProxyPlugin.sol b/src/plugin/contracts/plugins/FarmingProxyPlugin.sol index 32655e199..cc22a2ee3 100644 --- a/src/plugin/contracts/plugins/FarmingProxyPlugin.sol +++ b/src/plugin/contracts/plugins/FarmingProxyPlugin.sol @@ -11,7 +11,7 @@ import '../interfaces/plugins/IFarmingPlugin.sol'; import '../base/AlgebraBasePlugin.sol'; -/// @title Algebra Integral 1.2.1 default plugin +/// @title Algebra Integral 1.2.2 default plugin /// @notice This contract stores timepoints and calculates adaptive fee and statistical averages abstract contract FarmingProxyPlugin is AlgebraBasePlugin, IFarmingPlugin { using Plugins for uint8; diff --git a/src/plugin/contracts/plugins/VolatilityOraclePlugin.sol b/src/plugin/contracts/plugins/VolatilityOraclePlugin.sol index 5ac9cb8de..0b0ff5eed 100644 --- a/src/plugin/contracts/plugins/VolatilityOraclePlugin.sol +++ b/src/plugin/contracts/plugins/VolatilityOraclePlugin.sol @@ -10,7 +10,7 @@ import '../interfaces/plugins/IVolatilityOracle.sol'; import '../libraries/VolatilityOracle.sol'; import '../base/AlgebraBasePlugin.sol'; -/// @title Algebra Integral 1.2.1 VolatilityOraclePlugin plugin +/// @title Algebra Integral 1.2.2 VolatilityOraclePlugin plugin /// @notice This contract stores timepoints and calculates adaptive fee and statistical averages abstract contract VolatilityOraclePlugin is AlgebraBasePlugin, IVolatilityOracle { using Plugins for uint8; diff --git a/src/plugin/package.json b/src/plugin/package.json index 91689c121..cb65ab378 100644 --- a/src/plugin/package.json +++ b/src/plugin/package.json @@ -5,7 +5,7 @@ "publishConfig": { "access": "public" }, - "version": "1.2.1", + "version": "1.2.4", "keywords": [ "algebra" ], @@ -27,8 +27,8 @@ "url": "https://github.com/cryptoalgebra/Algebra/" }, "dependencies": { - "@cryptoalgebra/integral-core": "~1.2.5", - "@cryptoalgebra/integral-periphery": "~1.2.1" + "@cryptoalgebra/integral-core": "~1.2.8", + "@cryptoalgebra/integral-periphery": "~1.2.4" }, "scripts": { "precommit": "pretty-quick --staged --pattern '**/*.sol' && hardhat compile", diff --git a/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap b/src/plugin/test/__snapshots__/AlgebraPool.gas.spec.ts.snap index d407c3cde..5d145f367 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`] = `215202`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee large swap crossing several initialized ticks 1`] = `216359`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle 1`] = `164907`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle 1`] = `166064`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 4h 1`] = `200345`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 4h 1`] = `201502`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 8h 1`] = `193131`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 8h 1`] = `194288`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 24h 1`] = `163709`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps dynamic fee small swap with filled volatilityOracle after 24h 1`] = `164866`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee large swap crossing several initialized ticks 1`] = `213973`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee large swap crossing several initialized ticks 1`] = `215130`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle 1`] = `163720`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle 1`] = `164877`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 4h 1`] = `197185`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 4h 1`] = `198342`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 8h 1`] = `208119`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 8h 1`] = `209276`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 24h 1`] = `163192`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] Filled VolatilityOracle swaps static fee small swap with filled volatilityOracle after 24h 1`] = `164349`; -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 burn when only position using ticks 1`] = `118220`; -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 entire position burn but other positions are using the ticks 1`] = `112300`; -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 above current price partial position burn 1`] = `117100`; -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 burn when only position using ticks 1`] = `128099`; -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 entire position burn but other positions are using the ticks 1`] = `116708`; -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 around current price partial position burn 1`] = `121508`; -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 burn when only position using ticks 1`] = `127656`; -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 entire position burn but other positions are using the ticks 1`] = `112961`; -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 #burn below current price partial position burn 1`] = `117761`; 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`] = `156630`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `157775`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement 1`] = `156599`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement 1`] = `157744`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `156075`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `157220`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `173190`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `174335`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `206740`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `207885`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `156697`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `157842`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `206740`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `207885`; -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`] = `225940`; +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`] = `227085`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `126863`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `128008`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block with no tick movement 1`] = `126827`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block with no tick movement 1`] = `127972`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `142608`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `143753`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `176979`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `178124`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 several large swaps with pauses 1`] = `233702`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 several large swaps with pauses 1`] = `234847`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `164230`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `165375`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `156691`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `157836`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block with no tick movement 1`] = `156639`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 first swap in block with no tick movement 1`] = `157784`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 second swap in block with no tick movement 1`] = `126888`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap #swapExact1For0 second swap in block with no tick movement 1`] = `128033`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `188038`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `189186`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block with no tick movement 1`] = `187986`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected first swap in block with no tick movement 1`] = `189134`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected second swap in block with no tick movement 1`] = `141135`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is off #swap farming connected second swap in block with no tick movement 1`] = `142283`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `165429`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block moves tick, no initialized crossings 1`] = `166586`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `165398`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement 1`] = `166555`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `156312`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block with no tick movement, static fee 1`] = `157469`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `182226`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing a single initialized tick 1`] = `183383`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `216487`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap crossing several initialized ticks 1`] = `217644`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `165496`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 first swap in block, large swap, no initialized crossings 1`] = `166653`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `216487`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 large swap crossing several initialized ticks after some time passes 1`] = `217644`; -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`] = `235687`; +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`] = `236844`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `135662`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block moves tick, no initialized crossings 1`] = `136819`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `135626`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block with no tick movement 1`] = `136783`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `151644`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing a single initialized tick 1`] = `152801`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `186726`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 second swap in block, large swap crossing several initialized ticks 1`] = `187883`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `243449`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 several large swaps with pauses 1`] = `244606`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `164467`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact0For1 small swap after several large swaps with pauses 1`] = `165624`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `165501`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block moves tick, no initialized crossings 1`] = `166658`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `165449`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 first swap in block with no tick movement 1`] = `166606`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `135698`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap #swapExact1For0 second swap in block with no tick movement 1`] = `136855`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `196848`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block moves tick, no initialized crossings 1`] = `198008`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `196796`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected first swap in block with no tick movement 1`] = `197956`; -exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `149945`; +exports[`AlgebraPool gas tests [ @skip-on-coverage ] fee is on #swap farming connected second swap in block with no tick movement 1`] = `151105`;