diff --git a/.gitignore b/.gitignore index 483f0b586..bbd8a6289 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,10 @@ typechain/ .env +# ignore forge-doc artifacts as they are copied to the proper location +forge-docs/v4-core/* +forge-docs/v4-periphery/* + # Debugging logs npm-debug.log* yarn-debug.log* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..40cf8375c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "submodules/v4-core"] + path = submodules/v4-core + url = https://github.com/uniswap/v4-core +[submodule "submodules/v4-periphery"] + path = submodules/v4-periphery + url = https://github.com/uniswap/v4-periphery diff --git a/docs/contracts/v4/reference/core/ERC6909.md b/docs/contracts/v4/reference/core/ERC6909.md new file mode 100644 index 000000000..c78872297 --- /dev/null +++ b/docs/contracts/v4/reference/core/ERC6909.md @@ -0,0 +1,89 @@ +# ERC6909 +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/ERC6909.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IERC6909Claims](contracts/v4/reference/core/interfaces/IERC6909Claims.md) + +**Author:** +Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC6909.sol) + +Minimalist and gas efficient standard ERC6909 implementation. + +*Copied from the commit at 4b47a19038b798b4a33d9749d25e570443520647* + +*This contract has been modified from the implementation at the above link.* + + +## State Variables +### isOperator + +```solidity +mapping(address owner => mapping(address operator => bool isOperator)) public isOperator; +``` + + +### balanceOf + +```solidity +mapping(address owner => mapping(uint256 id => uint256 balance)) public balanceOf; +``` + + +### allowance + +```solidity +mapping(address owner => mapping(address spender => mapping(uint256 id => uint256 amount))) public allowance; +``` + + +## Functions +### transfer + + +```solidity +function transfer(address receiver, uint256 id, uint256 amount) public virtual returns (bool); +``` + +### transferFrom + + +```solidity +function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public virtual returns (bool); +``` + +### approve + + +```solidity +function approve(address spender, uint256 id, uint256 amount) public virtual returns (bool); +``` + +### setOperator + + +```solidity +function setOperator(address operator, bool approved) public virtual returns (bool); +``` + +### supportsInterface + + +```solidity +function supportsInterface(bytes4 interfaceId) public view virtual returns (bool); +``` + +### _mint + + +```solidity +function _mint(address receiver, uint256 id, uint256 amount) internal virtual; +``` + +### _burn + + +```solidity +function _burn(address sender, uint256 id, uint256 amount) internal virtual; +``` + diff --git a/docs/contracts/v4/reference/core/ERC6909Claims.md b/docs/contracts/v4/reference/core/ERC6909Claims.md new file mode 100644 index 000000000..9f9000dc8 --- /dev/null +++ b/docs/contracts/v4/reference/core/ERC6909Claims.md @@ -0,0 +1,30 @@ +# ERC6909Claims +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/ERC6909Claims.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[ERC6909](contracts/v4/reference/core/ERC6909.md) + +ERC6909Claims inherits ERC6909 and implements an internal burnFrom function + + +## Functions +### _burnFrom + +Burn `amount` tokens of token type `id` from `from`. + +*if sender is not `from` they must be an operator or have sufficient allowance.* + + +```solidity +function _burnFrom(address from, uint256 id, uint256 amount) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`from`|`address`|The address to burn tokens from.| +|`id`|`uint256`|The currency to burn.| +|`amount`|`uint256`|The amount to burn.| + + diff --git a/docs/contracts/v4/reference/core/Extsload.md b/docs/contracts/v4/reference/core/Extsload.md new file mode 100644 index 000000000..5a002ea92 --- /dev/null +++ b/docs/contracts/v4/reference/core/Extsload.md @@ -0,0 +1,76 @@ +# Extsload +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/Extsload.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IExtsload](contracts/v4/reference/core/interfaces/IExtsload.md) + +Enables public storage access for efficient state retrieval by external contracts. +https://eips.ethereum.org/EIPS/eip-2330#rationale + + +## Functions +### extsload + +Called by external contracts to access granular pool state + + +```solidity +function extsload(bytes32 slot) external view returns (bytes32); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`bytes32`|Key of slot to sload| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|value The value of the slot as bytes32| + + +### extsload + +Called by external contracts to access granular pool state + + +```solidity +function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`startSlot`|`bytes32`|| +|`nSlots`|`uint256`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32[]`|value The value of the slot as bytes32| + + +### extsload + +Called by external contracts to access granular pool state + + +```solidity +function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slots`|`bytes32[]`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32[]`|value The value of the slot as bytes32| + + diff --git a/docs/contracts/v4/reference/core/Exttload.md b/docs/contracts/v4/reference/core/Exttload.md new file mode 100644 index 000000000..ec8ad2254 --- /dev/null +++ b/docs/contracts/v4/reference/core/Exttload.md @@ -0,0 +1,54 @@ +# Exttload +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/Exttload.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IExttload](contracts/v4/reference/core/interfaces/IExttload.md) + +Enables public transient storage access for efficient state retrieval by external contracts. +https://eips.ethereum.org/EIPS/eip-2330#rationale + + +## Functions +### exttload + +Called by external contracts to access transient storage of the contract + + +```solidity +function exttload(bytes32 slot) external view returns (bytes32); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`bytes32`|Key of slot to tload| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|value The value of the slot as bytes32| + + +### exttload + +Called by external contracts to access transient storage of the contract + + +```solidity +function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slots`|`bytes32[]`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32[]`|value The value of the slot as bytes32| + + diff --git a/docs/contracts/v4/reference/core/NoDelegateCall.md b/docs/contracts/v4/reference/core/NoDelegateCall.md new file mode 100644 index 000000000..605f10922 --- /dev/null +++ b/docs/contracts/v4/reference/core/NoDelegateCall.md @@ -0,0 +1,51 @@ +# NoDelegateCall +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/NoDelegateCall.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Base contract that provides a modifier for preventing delegatecall to methods in a child contract + + +## State Variables +### original +*The original address of this contract* + + +```solidity +address private immutable original; +``` + + +## Functions +### constructor + + +```solidity +constructor(); +``` + +### checkNotDelegateCall + +*Private method is used instead of inlining into modifier because modifiers are copied into each method, +and the use of immutable means the address bytes are copied in every place the modifier is used.* + + +```solidity +function checkNotDelegateCall() private view; +``` + +### noDelegateCall + +Prevents delegatecall into the modified method + + +```solidity +modifier noDelegateCall(); +``` + +## Errors +### DelegateCallNotAllowed + +```solidity +error DelegateCallNotAllowed(); +``` + diff --git a/docs/contracts/v4/reference/core/PoolManager.md b/docs/contracts/v4/reference/core/PoolManager.md new file mode 100644 index 000000000..47b80f1d6 --- /dev/null +++ b/docs/contracts/v4/reference/core/PoolManager.md @@ -0,0 +1,381 @@ +# PoolManager +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/PoolManager.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IPoolManager](contracts/v4/reference/core/interfaces/IPoolManager.md), [ProtocolFees](contracts/v4/reference/core/ProtocolFees.md), [NoDelegateCall](contracts/v4/reference/core/NoDelegateCall.md), [ERC6909Claims](contracts/v4/reference/core/ERC6909Claims.md), [Extsload](contracts/v4/reference/core/Extsload.md), [Exttload](contracts/v4/reference/core/Exttload.md) + +Holds the state for all pools + + +## State Variables +### MAX_TICK_SPACING + +```solidity +int24 private constant MAX_TICK_SPACING = TickMath.MAX_TICK_SPACING; +``` + + +### MIN_TICK_SPACING + +```solidity +int24 private constant MIN_TICK_SPACING = TickMath.MIN_TICK_SPACING; +``` + + +### _pools + +```solidity +mapping(PoolId id => Pool.State) internal _pools; +``` + + +## Functions +### onlyWhenUnlocked + +This will revert if the contract is locked + + +```solidity +modifier onlyWhenUnlocked(); +``` + +### unlock + +All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement +`IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract. + +*The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`* + + +```solidity +function unlock(bytes calldata data) external override returns (bytes memory result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`result`|`bytes`|The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`| + + +### initialize + +Initialize the state for a given pool ID + +*A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee* + + +```solidity +function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData) + external + noDelegateCall + returns (int24 tick); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool key for the pool to initialize| +|`sqrtPriceX96`|`uint160`|The initial square root price| +|`hookData`|`bytes`|The data to pass through to the initialize hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tick`|`int24`|The initial tick of the pool| + + +### modifyLiquidity + +Modify the liquidity for the given pool + +*Poke by calling with a zero liquidityDelta* + + +```solidity +function modifyLiquidity(PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, bytes calldata hookData) + external + onlyWhenUnlocked + noDelegateCall + returns (BalanceDelta callerDelta, BalanceDelta feesAccrued); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool to modify liquidity in| +|`params`|`IPoolManager.ModifyLiquidityParams`|The parameters for modifying the liquidity| +|`hookData`|`bytes`|The data to pass through to the add/removeLiquidity hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`callerDelta`|`BalanceDelta`|The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable| +|`feesAccrued`|`BalanceDelta`|The balance delta of the fees generated in the liquidity range. Returned for informational purposes| + + +### swap + +Swap against the given pool + +*Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified. +Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG +the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.* + + +```solidity +function swap(PoolKey memory key, IPoolManager.SwapParams memory params, bytes calldata hookData) + external + onlyWhenUnlocked + noDelegateCall + returns (BalanceDelta swapDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool to swap in| +|`params`|`IPoolManager.SwapParams`|The parameters for swapping| +|`hookData`|`bytes`|The data to pass through to the swap hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`swapDelta`|`BalanceDelta`|The balance delta of the address swapping| + + +### _swap + +Internal swap function to execute a swap, take protocol fees on input token, and emit the swap event + + +```solidity +function _swap(Pool.State storage pool, PoolId id, Pool.SwapParams memory params, Currency inputCurrency) + internal + returns (BalanceDelta); +``` + +### donate + +Donate the given currency amounts to the in-range liquidity providers of a pool + +*Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds. +Donors should keep this in mind when designing donation mechanisms.* + + +```solidity +function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) + external + onlyWhenUnlocked + noDelegateCall + returns (BalanceDelta delta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to donate to| +|`amount0`|`uint256`|The amount of currency0 to donate| +|`amount1`|`uint256`|The amount of currency1 to donate| +|`hookData`|`bytes`|The data to pass through to the donate hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`delta`|`BalanceDelta`|BalanceDelta The delta of the caller after the donate| + + +### sync + +Writes the current ERC20 balance of the specified currency to transient storage +This is used to checkpoint balances for the manager and derive deltas for the caller. + +*This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped +for native tokens because the amount to settle is determined by the sent value. +However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle +native funds, this function can be called with the native currency to then be able to settle the native currency* + + +```solidity +function sync(Currency currency) external onlyWhenUnlocked; +``` + +### take + +Called by the user to net out some value owed to the user + +*Can also be used as a mechanism for _free_ flash loans* + + +```solidity +function take(Currency currency, address to, uint256 amount) external onlyWhenUnlocked; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|The currency to withdraw from the pool manager| +|`to`|`address`|The address to withdraw to| +|`amount`|`uint256`|The amount of currency to withdraw| + + +### settle + +Called by the user to pay what is owed + + +```solidity +function settle() external payable onlyWhenUnlocked returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|paid The amount of currency settled| + + +### settleFor + +Called by the user to pay on behalf of another address + + +```solidity +function settleFor(address recipient) external payable onlyWhenUnlocked returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`recipient`|`address`|The address to credit for the payment| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|paid The amount of currency settled| + + +### clear + +WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently. +A call to clear will zero out a positive balance WITHOUT a corresponding transfer. + +*This could be used to clear a balance that is considered dust. +Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.* + + +```solidity +function clear(Currency currency, uint256 amount) external onlyWhenUnlocked; +``` + +### mint + +Called by the user to move value into ERC6909 balance + +*The id is converted to a uint160 to correspond to a currency address +If the upper 12 bytes are not 0, they will be 0-ed out* + + +```solidity +function mint(address to, uint256 id, uint256 amount) external onlyWhenUnlocked; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|The address to mint the tokens to| +|`id`|`uint256`|The currency address to mint to ERC6909s, as a uint256| +|`amount`|`uint256`|The amount of currency to mint| + + +### burn + +Called by the user to move value from ERC6909 balance + +*The id is converted to a uint160 to correspond to a currency address +If the upper 12 bytes are not 0, they will be 0-ed out* + + +```solidity +function burn(address from, uint256 id, uint256 amount) external onlyWhenUnlocked; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`from`|`address`|The address to burn the tokens from| +|`id`|`uint256`|The currency address to burn from ERC6909s, as a uint256| +|`amount`|`uint256`|The amount of currency to burn| + + +### updateDynamicLPFee + +Updates the pools lp fees for the a pool that has enabled dynamic lp fees. + +*A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee* + + +```solidity +function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to update dynamic LP fees for| +|`newDynamicLPFee`|`uint24`|The new dynamic pool LP fee| + + +### _settle + + +```solidity +function _settle(address recipient) internal returns (uint256 paid); +``` + +### _accountDelta + +Adds a balance delta in a currency for a target address + + +```solidity +function _accountDelta(Currency currency, int128 delta, address target) internal; +``` + +### _accountPoolBalanceDelta + +Accounts the deltas of 2 currencies to a target address + + +```solidity +function _accountPoolBalanceDelta(PoolKey memory key, BalanceDelta delta, address target) internal; +``` + +### _getPool + +Implementation of the _getPool function defined in ProtocolFees + + +```solidity +function _getPool(PoolId id) internal view override returns (Pool.State storage); +``` + +### _isUnlocked + +Implementation of the _isUnlocked function defined in ProtocolFees + + +```solidity +function _isUnlocked() internal view override returns (bool); +``` + diff --git a/docs/contracts/v4/reference/core/ProtocolFees.md b/docs/contracts/v4/reference/core/ProtocolFees.md new file mode 100644 index 000000000..ce63a3b0b --- /dev/null +++ b/docs/contracts/v4/reference/core/ProtocolFees.md @@ -0,0 +1,143 @@ +# ProtocolFees +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/ProtocolFees.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IProtocolFees](contracts/v4/reference/core/interfaces/IProtocolFees.md), Owned + +Contract handling the setting and accrual of protocol fees + + +## State Variables +### protocolFeesAccrued +Given a currency address, returns the protocol fees accrued in that currency + + +```solidity +mapping(Currency currency => uint256 amount) public protocolFeesAccrued; +``` + + +### protocolFeeController +Returns the current protocol fee controller address + + +```solidity +IProtocolFeeController public protocolFeeController; +``` + + +### BLOCK_LIMIT_BPS + +```solidity +uint256 private constant BLOCK_LIMIT_BPS = 100; +``` + + +## Functions +### constructor + + +```solidity +constructor() Owned(msg.sender); +``` + +### setProtocolFeeController + +Sets the protocol fee controller + + +```solidity +function setProtocolFeeController(IProtocolFeeController controller) external onlyOwner; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`controller`|`IProtocolFeeController`|The new protocol fee controller| + + +### setProtocolFee + +Sets the protocol fee for the given pool + + +```solidity +function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to set a protocol fee for| +|`newProtocolFee`|`uint24`|The fee to set| + + +### collectProtocolFees + +Collects the protocol fees for a given recipient and currency, returning the amount collected + +*This will revert if the contract is unlocked* + + +```solidity +function collectProtocolFees(address recipient, Currency currency, uint256 amount) + external + returns (uint256 amountCollected); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`recipient`|`address`|The address to receive the protocol fees| +|`currency`|`Currency`|The currency to withdraw| +|`amount`|`uint256`|The amount of currency to withdraw| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountCollected`|`uint256`|The amount of currency successfully withdrawn| + + +### _isUnlocked + +*abstract internal function to allow the ProtocolFees contract to access the lock* + + +```solidity +function _isUnlocked() internal virtual returns (bool); +``` + +### _getPool + +*abstract internal function to allow the ProtocolFees contract to access pool state* + +*this is overridden in PoolManager.sol to give access to the _pools mapping* + + +```solidity +function _getPool(PoolId id) internal virtual returns (Pool.State storage); +``` + +### _fetchProtocolFee + +Fetch the protocol fees for a given pool + +*the success of this function is false if the call fails or the returned fees are invalid* + +*to prevent an invalid protocol fee controller from blocking pools from being initialized +the success of this function is NOT checked on initialize and if the call fails, the protocol fees are set to 0.* + + +```solidity +function _fetchProtocolFee(PoolKey memory key) internal returns (uint24 protocolFee); +``` + +### _updateProtocolFees + + +```solidity +function _updateProtocolFees(Currency currency, uint256 amount) internal; +``` + diff --git a/docs/contracts/v4/reference/core/interfaces/IERC20Minimal.md b/docs/contracts/v4/reference/core/interfaces/IERC20Minimal.md new file mode 100644 index 000000000..37700680b --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IERC20Minimal.md @@ -0,0 +1,151 @@ +# IERC20Minimal +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/external/IERC20Minimal.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Contains a subset of the full ERC20 interface that is used in Uniswap V3 + + +## Functions +### balanceOf + +Returns an account's balance in the token + + +```solidity +function balanceOf(address account) external view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`account`|`address`|The account for which to look up the number of tokens it has, i.e. its balance| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The number of tokens held by the account| + + +### transfer + +Transfers the amount of token from the `msg.sender` to the recipient + + +```solidity +function transfer(address recipient, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`recipient`|`address`|The account that will receive the amount transferred| +|`amount`|`uint256`|The number of tokens to send from the sender to the recipient| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Returns true for a successful transfer, false for an unsuccessful transfer| + + +### allowance + +Returns the current allowance given to a spender by an owner + + +```solidity +function allowance(address owner, address spender) external view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The account of the token owner| +|`spender`|`address`|The account of the token spender| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The current allowance granted by `owner` to `spender`| + + +### approve + +Sets the allowance of a spender from the `msg.sender` to the value `amount` + + +```solidity +function approve(address spender, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The account which will be allowed to spend a given amount of the owners tokens| +|`amount`|`uint256`|The amount of tokens allowed to be used by `spender`| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Returns true for a successful approval, false for unsuccessful| + + +### transferFrom + +Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender` + + +```solidity +function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The account from which the transfer will be initiated| +|`recipient`|`address`|The recipient of the transfer| +|`amount`|`uint256`|The amount of the transfer| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|Returns true for a successful transfer, false for unsuccessful| + + +## Events +### Transfer +Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`. + + +```solidity +event Transfer(address indexed from, address indexed to, uint256 value); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`from`|`address`|The account from which the tokens were sent, i.e. the balance decreased| +|`to`|`address`|The account to which the tokens were sent, i.e. the balance increased| +|`value`|`uint256`|The amount of tokens that were transferred| + +### Approval +Event emitted when the approval amount for the spender of a given owner's tokens changes. + + +```solidity +event Approval(address indexed owner, address indexed spender, uint256 value); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The account that approved spending of its tokens| +|`spender`|`address`|The account for which the spending allowance was modified| +|`value`|`uint256`|The new allowance from the owner to the spender| + diff --git a/docs/contracts/v4/reference/core/interfaces/IERC6909Claims.md b/docs/contracts/v4/reference/core/interfaces/IERC6909Claims.md new file mode 100644 index 000000000..48c33b0f2 --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IERC6909Claims.md @@ -0,0 +1,186 @@ +# IERC6909Claims +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/external/IERC6909Claims.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface for claims over a contract balance, wrapped as a ERC6909 + + +## Functions +### balanceOf + +Owner balance of an id. + + +```solidity +function balanceOf(address owner, uint256 id) external view returns (uint256 amount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`id`|`uint256`|The id of the token.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The balance of the token.| + + +### allowance + +Spender allowance of an id. + + +```solidity +function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`spender`|`address`|The address of the spender.| +|`id`|`uint256`|The id of the token.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The allowance of the token.| + + +### isOperator + +Checks if a spender is approved by an owner as an operator + + +```solidity +function isOperator(address owner, address spender) external view returns (bool approved); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the owner.| +|`spender`|`address`|The address of the spender.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`approved`|`bool`|The approval status.| + + +### transfer + +Transfers an amount of an id from the caller to a receiver. + + +```solidity +function transfer(address receiver, uint256 id, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`receiver`|`address`|The address of the receiver.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True, always, unless the function reverts| + + +### transferFrom + +Transfers an amount of an id from a sender to a receiver. + + +```solidity +function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The address of the sender.| +|`receiver`|`address`|The address of the receiver.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True, always, unless the function reverts| + + +### approve + +Approves an amount of an id to a spender. + + +```solidity +function approve(address spender, uint256 id, uint256 amount) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The address of the spender.| +|`id`|`uint256`|The id of the token.| +|`amount`|`uint256`|The amount of the token.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True, always| + + +### setOperator + +Sets or removes an operator for the caller. + + +```solidity +function setOperator(address operator, bool approved) external returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`operator`|`address`|The address of the operator.| +|`approved`|`bool`|The approval status.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True, always| + + +## Events +### OperatorSet + +```solidity +event OperatorSet(address indexed owner, address indexed operator, bool approved); +``` + +### Approval + +```solidity +event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount); +``` + +### Transfer + +```solidity +event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount); +``` + diff --git a/docs/contracts/v4/reference/core/interfaces/IExtsload.md b/docs/contracts/v4/reference/core/interfaces/IExtsload.md new file mode 100644 index 000000000..d7e7aaf31 --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IExtsload.md @@ -0,0 +1,72 @@ +# IExtsload +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/IExtsload.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface for functions to access any storage slot in a contract + + +## Functions +### extsload + +Called by external contracts to access granular pool state + + +```solidity +function extsload(bytes32 slot) external view returns (bytes32 value); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`bytes32`|Key of slot to sload| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`bytes32`|The value of the slot as bytes32| + + +### extsload + +Called by external contracts to access granular pool state + + +```solidity +function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory values); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`startSlot`|`bytes32`|Key of slot to start sloading from| +|`nSlots`|`uint256`|Number of slots to load into return value| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`values`|`bytes32[]`|List of loaded values.| + + +### extsload + +Called by external contracts to access sparse pool state + + +```solidity +function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slots`|`bytes32[]`|List of slots to SLOAD from.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`values`|`bytes32[]`|List of loaded values.| + + diff --git a/docs/contracts/v4/reference/core/interfaces/IExttload.md b/docs/contracts/v4/reference/core/interfaces/IExttload.md new file mode 100644 index 000000000..37275893b --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IExttload.md @@ -0,0 +1,50 @@ +# IExttload +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/IExttload.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface for functions to access any transient storage slot in a contract + + +## Functions +### exttload + +Called by external contracts to access transient storage of the contract + + +```solidity +function exttload(bytes32 slot) external view returns (bytes32 value); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slot`|`bytes32`|Key of slot to tload| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`value`|`bytes32`|The value of the slot as bytes32| + + +### exttload + +Called by external contracts to access sparse transient pool state + + +```solidity +function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory values); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`slots`|`bytes32[]`|List of slots to tload| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`values`|`bytes32[]`|List of loaded values| + + diff --git a/docs/contracts/v4/reference/core/interfaces/IHooks.md b/docs/contracts/v4/reference/core/interfaces/IHooks.md new file mode 100644 index 000000000..3f567d0dd --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IHooks.md @@ -0,0 +1,314 @@ +# IHooks +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/IHooks.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +V4 decides whether to invoke specific hooks by inspecting the least significant bits +of the address that the hooks contract is deployed to. +For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400 +has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used. +See the Hooks library for the full spec. + +*Should only be callable by the v4 PoolManager.* + + +## Functions +### beforeInitialize + +The hook called before the state of a pool is initialized + + +```solidity +function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, bytes calldata hookData) + external + returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the initialize call| +|`key`|`PoolKey`|The key for the pool being initialized| +|`sqrtPriceX96`|`uint160`|The sqrt(price) of the pool as a Q64.96| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the initializer to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### afterInitialize + +The hook called after the state of a pool is initialized + + +```solidity +function afterInitialize( + address sender, + PoolKey calldata key, + uint160 sqrtPriceX96, + int24 tick, + bytes calldata hookData +) external returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the initialize call| +|`key`|`PoolKey`|The key for the pool being initialized| +|`sqrtPriceX96`|`uint160`|The sqrt(price) of the pool as a Q64.96| +|`tick`|`int24`|The current tick after the state of a pool is initialized| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the initializer to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### beforeAddLiquidity + +The hook called before liquidity is added + + +```solidity +function beforeAddLiquidity( + address sender, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + bytes calldata hookData +) external returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the add liquidity call| +|`key`|`PoolKey`|The key for the pool| +|`params`|`IPoolManager.ModifyLiquidityParams`|The parameters for adding liquidity| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### afterAddLiquidity + +The hook called after liquidity is added + + +```solidity +function afterAddLiquidity( + address sender, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + BalanceDelta delta, + BalanceDelta feesAccrued, + bytes calldata hookData +) external returns (bytes4, BalanceDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the add liquidity call| +|`key`|`PoolKey`|The key for the pool| +|`params`|`IPoolManager.ModifyLiquidityParams`|The parameters for adding liquidity| +|`delta`|`BalanceDelta`|The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta| +|`feesAccrued`|`BalanceDelta`|The fees accrued since the last time fees were collected from this position| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`BalanceDelta`|BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| + + +### beforeRemoveLiquidity + +The hook called before liquidity is removed + + +```solidity +function beforeRemoveLiquidity( + address sender, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + bytes calldata hookData +) external returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the remove liquidity call| +|`key`|`PoolKey`|The key for the pool| +|`params`|`IPoolManager.ModifyLiquidityParams`|The parameters for removing liquidity| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### afterRemoveLiquidity + +The hook called after liquidity is removed + + +```solidity +function afterRemoveLiquidity( + address sender, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + BalanceDelta delta, + BalanceDelta feesAccrued, + bytes calldata hookData +) external returns (bytes4, BalanceDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the remove liquidity call| +|`key`|`PoolKey`|The key for the pool| +|`params`|`IPoolManager.ModifyLiquidityParams`|The parameters for removing liquidity| +|`delta`|`BalanceDelta`|The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta| +|`feesAccrued`|`BalanceDelta`|The fees accrued since the last time fees were collected from this position| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`BalanceDelta`|BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| + + +### beforeSwap + +The hook called before a swap + + +```solidity +function beforeSwap( + address sender, + PoolKey calldata key, + IPoolManager.SwapParams calldata params, + bytes calldata hookData +) external returns (bytes4, BeforeSwapDelta, uint24); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the swap call| +|`key`|`PoolKey`|The key for the pool| +|`params`|`IPoolManager.SwapParams`|The parameters for the swap| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`BeforeSwapDelta`|BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| +|``|`uint24`|uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)| + + +### afterSwap + +The hook called after a swap + + +```solidity +function afterSwap( + address sender, + PoolKey calldata key, + IPoolManager.SwapParams calldata params, + BalanceDelta delta, + bytes calldata hookData +) external returns (bytes4, int128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the swap call| +|`key`|`PoolKey`|The key for the pool| +|`params`|`IPoolManager.SwapParams`|The parameters for the swap| +|`delta`|`BalanceDelta`|The amount owed to the caller (positive) or owed to the pool (negative)| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`int128`|int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| + + +### beforeDonate + +The hook called before donate + + +```solidity +function beforeDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData) + external + returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the donate call| +|`key`|`PoolKey`|The key for the pool| +|`amount0`|`uint256`|The amount of token0 being donated| +|`amount1`|`uint256`|The amount of token1 being donated| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### afterDonate + +The hook called after donate + + +```solidity +function afterDonate(address sender, PoolKey calldata key, uint256 amount0, uint256 amount1, bytes calldata hookData) + external + returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sender`|`address`|The initial msg.sender for the donate call| +|`key`|`PoolKey`|The key for the pool| +|`amount0`|`uint256`|The amount of token0 being donated| +|`amount1`|`uint256`|The amount of token1 being donated| +|`hookData`|`bytes`|Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + diff --git a/docs/contracts/v4/reference/core/interfaces/IPoolManager.md b/docs/contracts/v4/reference/core/interfaces/IPoolManager.md new file mode 100644 index 000000000..5e031e1b2 --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IPoolManager.md @@ -0,0 +1,503 @@ +# IPoolManager +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/IPoolManager.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IProtocolFees](contracts/v4/reference/core/interfaces/IProtocolFees.md), [IERC6909Claims](contracts/v4/reference/core/interfaces/IERC6909Claims.md), [IExtsload](contracts/v4/reference/core/interfaces/IExtsload.md), [IExttload](contracts/v4/reference/core/interfaces/IExttload.md) + +Interface for the PoolManager + + +## Functions +### unlock + +All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement +`IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract. + +*The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`* + + +```solidity +function unlock(bytes calldata data) external returns (bytes memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes`|The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`| + + +### initialize + +Initialize the state for a given pool ID + +*A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee* + + +```solidity +function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData) external returns (int24 tick); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool key for the pool to initialize| +|`sqrtPriceX96`|`uint160`|The initial square root price| +|`hookData`|`bytes`|The data to pass through to the initialize hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tick`|`int24`|The initial tick of the pool| + + +### modifyLiquidity + +Modify the liquidity for the given pool + +*Poke by calling with a zero liquidityDelta* + + +```solidity +function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData) + external + returns (BalanceDelta callerDelta, BalanceDelta feesAccrued); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool to modify liquidity in| +|`params`|`ModifyLiquidityParams`|The parameters for modifying the liquidity| +|`hookData`|`bytes`|The data to pass through to the add/removeLiquidity hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`callerDelta`|`BalanceDelta`|The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable| +|`feesAccrued`|`BalanceDelta`|The balance delta of the fees generated in the liquidity range. Returned for informational purposes| + + +### swap + +Swap against the given pool + +*Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified. +Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG +the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.* + + +```solidity +function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData) + external + returns (BalanceDelta swapDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool to swap in| +|`params`|`SwapParams`|The parameters for swapping| +|`hookData`|`bytes`|The data to pass through to the swap hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`swapDelta`|`BalanceDelta`|The balance delta of the address swapping| + + +### donate + +Donate the given currency amounts to the in-range liquidity providers of a pool + +*Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds. +Donors should keep this in mind when designing donation mechanisms.* + +*This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of +a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to +`donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)). +Read the comments in `Pool.swap()` for more information about this.* + + +```solidity +function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) + external + returns (BalanceDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to donate to| +|`amount0`|`uint256`|The amount of currency0 to donate| +|`amount1`|`uint256`|The amount of currency1 to donate| +|`hookData`|`bytes`|The data to pass through to the donate hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`BalanceDelta`|BalanceDelta The delta of the caller after the donate| + + +### sync + +Writes the current ERC20 balance of the specified currency to transient storage +This is used to checkpoint balances for the manager and derive deltas for the caller. + +*This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped +for native tokens because the amount to settle is determined by the sent value. +However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle +native funds, this function can be called with the native currency to then be able to settle the native currency* + + +```solidity +function sync(Currency currency) external; +``` + +### take + +Called by the user to net out some value owed to the user + +*Can also be used as a mechanism for _free_ flash loans* + + +```solidity +function take(Currency currency, address to, uint256 amount) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|The currency to withdraw from the pool manager| +|`to`|`address`|The address to withdraw to| +|`amount`|`uint256`|The amount of currency to withdraw| + + +### settle + +Called by the user to pay what is owed + + +```solidity +function settle() external payable returns (uint256 paid); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`paid`|`uint256`|The amount of currency settled| + + +### settleFor + +Called by the user to pay on behalf of another address + + +```solidity +function settleFor(address recipient) external payable returns (uint256 paid); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`recipient`|`address`|The address to credit for the payment| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`paid`|`uint256`|The amount of currency settled| + + +### clear + +WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently. +A call to clear will zero out a positive balance WITHOUT a corresponding transfer. + +*This could be used to clear a balance that is considered dust. +Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.* + + +```solidity +function clear(Currency currency, uint256 amount) external; +``` + +### mint + +Called by the user to move value into ERC6909 balance + +*The id is converted to a uint160 to correspond to a currency address +If the upper 12 bytes are not 0, they will be 0-ed out* + + +```solidity +function mint(address to, uint256 id, uint256 amount) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|The address to mint the tokens to| +|`id`|`uint256`|The currency address to mint to ERC6909s, as a uint256| +|`amount`|`uint256`|The amount of currency to mint| + + +### burn + +Called by the user to move value from ERC6909 balance + +*The id is converted to a uint160 to correspond to a currency address +If the upper 12 bytes are not 0, they will be 0-ed out* + + +```solidity +function burn(address from, uint256 id, uint256 amount) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`from`|`address`|The address to burn the tokens from| +|`id`|`uint256`|The currency address to burn from ERC6909s, as a uint256| +|`amount`|`uint256`|The amount of currency to burn| + + +### updateDynamicLPFee + +Updates the pools lp fees for the a pool that has enabled dynamic lp fees. + +*A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee* + + +```solidity +function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to update dynamic LP fees for| +|`newDynamicLPFee`|`uint24`|The new dynamic pool LP fee| + + +## Events +### Initialize +Emitted when a new pool is initialized + + +```solidity +event Initialize( + PoolId indexed id, + Currency indexed currency0, + Currency indexed currency1, + uint24 fee, + int24 tickSpacing, + IHooks hooks, + uint160 sqrtPriceX96, + int24 tick +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`id`|`PoolId`|The abi encoded hash of the pool key struct for the new pool| +|`currency0`|`Currency`|The first currency of the pool by address sort order| +|`currency1`|`Currency`|The second currency of the pool by address sort order| +|`fee`|`uint24`|The fee collected upon every swap in the pool, denominated in hundredths of a bip| +|`tickSpacing`|`int24`|The minimum number of ticks between initialized ticks| +|`hooks`|`IHooks`|The hooks contract address for the pool, or address(0) if none| +|`sqrtPriceX96`|`uint160`|The price of the pool on initialization| +|`tick`|`int24`|The initial tick of the pool corresponding to the intialized price| + +### ModifyLiquidity +Emitted when a liquidity position is modified + + +```solidity +event ModifyLiquidity( + PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`id`|`PoolId`|The abi encoded hash of the pool key struct for the pool that was modified| +|`sender`|`address`|The address that modified the pool| +|`tickLower`|`int24`|The lower tick of the position| +|`tickUpper`|`int24`|The upper tick of the position| +|`liquidityDelta`|`int256`|The amount of liquidity that was added or removed| +|`salt`|`bytes32`|The extra data to make positions unique| + +### Swap +Emitted for swaps between currency0 and currency1 + + +```solidity +event Swap( + PoolId indexed id, + address indexed sender, + int128 amount0, + int128 amount1, + uint160 sqrtPriceX96, + uint128 liquidity, + int24 tick, + uint24 fee +); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`id`|`PoolId`|The abi encoded hash of the pool key struct for the pool that was modified| +|`sender`|`address`|The address that initiated the swap call, and that received the callback| +|`amount0`|`int128`|The delta of the currency0 balance of the pool| +|`amount1`|`int128`|The delta of the currency1 balance of the pool| +|`sqrtPriceX96`|`uint160`|The sqrt(price) of the pool after the swap, as a Q64.96| +|`liquidity`|`uint128`|The liquidity of the pool after the swap| +|`tick`|`int24`|The log base 1.0001 of the price of the pool after the swap| +|`fee`|`uint24`|The swap fee in hundredths of a bip| + +### Donate +Emitted for donations + + +```solidity +event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`id`|`PoolId`|The abi encoded hash of the pool key struct for the pool that was donated to| +|`sender`|`address`|The address that initiated the donate call| +|`amount0`|`uint256`|The amount donated in currency0| +|`amount1`|`uint256`|The amount donated in currency1| + +## Errors +### CurrencyNotSettled +Thrown when a currency is not netted out after the contract is unlocked + + +```solidity +error CurrencyNotSettled(); +``` + +### PoolNotInitialized +Thrown when trying to interact with a non-initialized pool + + +```solidity +error PoolNotInitialized(); +``` + +### AlreadyUnlocked +Thrown when unlock is called, but the contract is already unlocked + + +```solidity +error AlreadyUnlocked(); +``` + +### ManagerLocked +Thrown when a function is called that requires the contract to be unlocked, but it is not + + +```solidity +error ManagerLocked(); +``` + +### TickSpacingTooLarge +Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow + + +```solidity +error TickSpacingTooLarge(int24 tickSpacing); +``` + +### TickSpacingTooSmall +Pools must have a positive non-zero tickSpacing passed to #initialize + + +```solidity +error TickSpacingTooSmall(int24 tickSpacing); +``` + +### CurrenciesOutOfOrderOrEqual +PoolKey must have currencies where address(currency0) < address(currency1) + + +```solidity +error CurrenciesOutOfOrderOrEqual(address currency0, address currency1); +``` + +### UnauthorizedDynamicLPFeeUpdate +Thrown when a call to updateDynamicLPFee is made by an address that is not the hook, +or on a pool that does not have a dynamic swap fee. + + +```solidity +error UnauthorizedDynamicLPFeeUpdate(); +``` + +### SwapAmountCannotBeZero +Thrown when trying to swap amount of 0 + + +```solidity +error SwapAmountCannotBeZero(); +``` + +### NonzeroNativeValue +Thrown when native currency is passed to a non native settlement + + +```solidity +error NonzeroNativeValue(); +``` + +### MustClearExactPositiveDelta +Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta. + + +```solidity +error MustClearExactPositiveDelta(); +``` + +## Structs +### ModifyLiquidityParams + +```solidity +struct ModifyLiquidityParams { + int24 tickLower; + int24 tickUpper; + int256 liquidityDelta; + bytes32 salt; +} +``` + +### SwapParams + +```solidity +struct SwapParams { + bool zeroForOne; + int256 amountSpecified; + uint160 sqrtPriceLimitX96; +} +``` + diff --git a/docs/contracts/v4/reference/core/interfaces/IProtocolFeeController.md b/docs/contracts/v4/reference/core/interfaces/IProtocolFeeController.md new file mode 100644 index 000000000..a4bff3399 --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IProtocolFeeController.md @@ -0,0 +1,29 @@ +# IProtocolFeeController +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/IProtocolFeeController.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface to fetch the protocol fees for a pool from the protocol fee controller + + +## Functions +### protocolFeeForPool + +Returns the protocol fees for a pool given the conditions of this contract + + +```solidity +function protocolFeeForPool(PoolKey memory poolKey) external view returns (uint24 protocolFee); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolKey`|`PoolKey`|The pool key to identify the pool. The controller may want to use attributes on the pool to determine the protocol fee, hence the entire key is needed.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`protocolFee`|`uint24`|The pool's protocol fee, expressed in hundredths of a bip. The upper 12 bits are for 1->0 and the lower 12 are for 0->1. The maximum is 1000 - meaning the maximum protocol fee is 0.1%. the protocolFee is taken from the input first, then the lpFee is taken from the remaining input| + + diff --git a/docs/contracts/v4/reference/core/interfaces/IProtocolFees.md b/docs/contracts/v4/reference/core/interfaces/IProtocolFees.md new file mode 100644 index 000000000..d33660f52 --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IProtocolFees.md @@ -0,0 +1,152 @@ +# IProtocolFees +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/IProtocolFees.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface for all protocol-fee related functions in the pool manager + + +## Functions +### protocolFeesAccrued + +Given a currency address, returns the protocol fees accrued in that currency + + +```solidity +function protocolFeesAccrued(Currency currency) external view returns (uint256 amount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|The currency to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount of protocol fees accrued in the currency| + + +### setProtocolFee + +Sets the protocol fee for the given pool + + +```solidity +function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to set a protocol fee for| +|`newProtocolFee`|`uint24`|The fee to set| + + +### setProtocolFeeController + +Sets the protocol fee controller + + +```solidity +function setProtocolFeeController(IProtocolFeeController controller) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`controller`|`IProtocolFeeController`|The new protocol fee controller| + + +### collectProtocolFees + +Collects the protocol fees for a given recipient and currency, returning the amount collected + +*This will revert if the contract is unlocked* + + +```solidity +function collectProtocolFees(address recipient, Currency currency, uint256 amount) + external + returns (uint256 amountCollected); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`recipient`|`address`|The address to receive the protocol fees| +|`currency`|`Currency`|The currency to withdraw| +|`amount`|`uint256`|The amount of currency to withdraw| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountCollected`|`uint256`|The amount of currency successfully withdrawn| + + +### protocolFeeController + +Returns the current protocol fee controller address + + +```solidity +function protocolFeeController() external view returns (IProtocolFeeController); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`IProtocolFeeController`|IProtocolFeeController The currency protocol fee controller| + + +## Events +### ProtocolFeeControllerUpdated +Emitted when the protocol fee controller address is updated in setProtocolFeeController. + + +```solidity +event ProtocolFeeControllerUpdated(address indexed protocolFeeController); +``` + +### ProtocolFeeUpdated +Emitted when the protocol fee is updated for a pool. + + +```solidity +event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee); +``` + +## Errors +### ProtocolFeeCannotBeFetched +Thrown when not enough gas is provided to look up the protocol fee + + +```solidity +error ProtocolFeeCannotBeFetched(); +``` + +### ProtocolFeeTooLarge +Thrown when protocol fee is set too high + + +```solidity +error ProtocolFeeTooLarge(uint24 fee); +``` + +### ContractUnlocked +Thrown when the contract is unlocked + + +```solidity +error ContractUnlocked(); +``` + +### InvalidCaller +Thrown when collectProtocolFees or setProtocolFee is not called by the controller. + + +```solidity +error InvalidCaller(); +``` + diff --git a/docs/contracts/v4/reference/core/interfaces/IUnlockCallback.md b/docs/contracts/v4/reference/core/interfaces/IUnlockCallback.md new file mode 100644 index 000000000..694cd96c8 --- /dev/null +++ b/docs/contracts/v4/reference/core/interfaces/IUnlockCallback.md @@ -0,0 +1,29 @@ +# IUnlockCallback +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/interfaces/callback/IUnlockCallback.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface for the callback executed when an address unlocks the pool manager + + +## Functions +### unlockCallback + +Called by the pool manager on `msg.sender` when the manager is unlocked + + +```solidity +function unlockCallback(bytes calldata data) external returns (bytes memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|The data that was passed to the call to unlock| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes`|Any data that you want to be returned from the unlock call| + + diff --git a/docs/contracts/v4/reference/core/libraries/BipsLibrary.md b/docs/contracts/v4/reference/core/libraries/BipsLibrary.md new file mode 100644 index 000000000..3dc5321f3 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/BipsLibrary.md @@ -0,0 +1,37 @@ +# BipsLibrary +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/BipsLibrary.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## State Variables +### BPS_DENOMINATOR + +```solidity +uint256 internal constant BPS_DENOMINATOR = 10_000; +``` + + +## Functions +### calculatePortion + + +```solidity +function calculatePortion(uint256 amount, uint256 bips) internal pure returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The total amount to calculate a percentage of| +|`bips`|`uint256`|The percentage to calculate, in bips| + + +## Errors +### InvalidBips +emitted when an invalid percentage is provided + + +```solidity +error InvalidBips(); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/BitMath.md b/docs/contracts/v4/reference/core/libraries/BitMath.md new file mode 100644 index 000000000..4c883ff37 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/BitMath.md @@ -0,0 +1,55 @@ +# BitMath +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/BitMath.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Author:** +Solady (https://github.com/Vectorized/solady/blob/8200a70e8dc2a77ecb074fc2e99a2a0d36547522/src/utils/LibBit.sol) + +*This library provides functionality for computing bit properties of an unsigned integer* + + +## Functions +### mostSignificantBit + +Returns the index of the most significant bit of the number, +where the least significant bit is at index 0 and the most significant bit is at index 255 + + +```solidity +function mostSignificantBit(uint256 x) internal pure returns (uint8 r); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint256`|the value for which to compute the most significant bit, must be greater than 0| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`r`|`uint8`|the index of the most significant bit| + + +### leastSignificantBit + +Returns the index of the least significant bit of the number, +where the least significant bit is at index 0 and the most significant bit is at index 255 + + +```solidity +function leastSignificantBit(uint256 x) internal pure returns (uint8 r); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint256`|the value for which to compute the least significant bit, must be greater than 0| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`r`|`uint8`|the index of the least significant bit| + + diff --git a/docs/contracts/v4/reference/core/libraries/CurrencyDelta.md b/docs/contracts/v4/reference/core/libraries/CurrencyDelta.md new file mode 100644 index 000000000..8f5773d74 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/CurrencyDelta.md @@ -0,0 +1,40 @@ +# CurrencyDelta +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/CurrencyDelta.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +*this library implements the equivalent of a mapping, as transient storage can only be accessed in assembly* + + +## Functions +### _computeSlot + +calculates which storage slot a delta should be stored in for a given account and currency + + +```solidity +function _computeSlot(address target, Currency currency) internal pure returns (bytes32 hashSlot); +``` + +### getDelta + + +```solidity +function getDelta(Currency currency, address target) internal view returns (int256 delta); +``` + +### applyDelta + +applies a new currency delta for a given account and currency + + +```solidity +function applyDelta(Currency currency, address target, int128 delta) internal returns (int256 previous, int256 next); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`previous`|`int256`|The prior value| +|`next`|`int256`|The modified result| + + diff --git a/docs/contracts/v4/reference/core/libraries/CurrencyReserves.md b/docs/contracts/v4/reference/core/libraries/CurrencyReserves.md new file mode 100644 index 000000000..efcf3b9c4 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/CurrencyReserves.md @@ -0,0 +1,53 @@ +# CurrencyReserves +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/CurrencyReserves.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## State Variables +### RESERVES_OF_SLOT +bytes32(uint256(keccak256("ReservesOf")) - 1) + + +```solidity +bytes32 constant RESERVES_OF_SLOT = 0x1e0745a7db1623981f0b2a5d4232364c00787266eb75ad546f190e6cebe9bd95; +``` + + +### CURRENCY_SLOT +bytes32(uint256(keccak256("Currency")) - 1) + + +```solidity +bytes32 constant CURRENCY_SLOT = 0x27e098c505d44ec3574004bca052aabf76bd35004c182099d8c575fb238593b9; +``` + + +## Functions +### getSyncedCurrency + + +```solidity +function getSyncedCurrency() internal view returns (Currency currency); +``` + +### resetCurrency + + +```solidity +function resetCurrency() internal; +``` + +### syncCurrencyAndReserves + + +```solidity +function syncCurrencyAndReserves(Currency currency, uint256 value) internal; +``` + +### getSyncedReserves + + +```solidity +function getSyncedReserves() internal view returns (uint256 value); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/CustomRevert.md b/docs/contracts/v4/reference/core/libraries/CustomRevert.md new file mode 100644 index 000000000..bac7499bd --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/CustomRevert.md @@ -0,0 +1,87 @@ +# CustomRevert +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/CustomRevert.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Contains functions for reverting with custom errors with different argument types efficiently + +*To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with +`CustomError.selector.revertWith()`* + +*The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately* + + +## Functions +### revertWith + +*Reverts with the selector of a custom error in the scratch space* + + +```solidity +function revertWith(bytes4 selector) internal pure; +``` + +### revertWith + +*Reverts with a custom error with an address argument in the scratch space* + + +```solidity +function revertWith(bytes4 selector, address addr) internal pure; +``` + +### revertWith + +*Reverts with a custom error with an int24 argument in the scratch space* + + +```solidity +function revertWith(bytes4 selector, int24 value) internal pure; +``` + +### revertWith + +*Reverts with a custom error with a uint160 argument in the scratch space* + + +```solidity +function revertWith(bytes4 selector, uint160 value) internal pure; +``` + +### revertWith + +*Reverts with a custom error with two int24 arguments* + + +```solidity +function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure; +``` + +### revertWith + +*Reverts with a custom error with two uint160 arguments* + + +```solidity +function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure; +``` + +### revertWith + +*Reverts with a custom error with two address arguments* + + +```solidity +function revertWith(bytes4 selector, address value1, address value2) internal pure; +``` + +### bubbleUpAndRevertWith + +bubble up the revert message returned by a call and revert with the selector provided + +*this function should only be used with custom errors of the type `CustomError(address target, bytes revertReason)`* + + +```solidity +function bubbleUpAndRevertWith(bytes4 selector, address addr) internal pure; +``` + diff --git a/docs/contracts/v4/reference/core/libraries/FixedPoint128.md b/docs/contracts/v4/reference/core/libraries/FixedPoint128.md new file mode 100644 index 000000000..1697cd59b --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/FixedPoint128.md @@ -0,0 +1,15 @@ +# FixedPoint128 +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/FixedPoint128.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) + + +## State Variables +### Q128 + +```solidity +uint256 internal constant Q128 = 0x100000000000000000000000000000000; +``` + + diff --git a/docs/contracts/v4/reference/core/libraries/FixedPoint96.md b/docs/contracts/v4/reference/core/libraries/FixedPoint96.md new file mode 100644 index 000000000..0e1ba21f7 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/FixedPoint96.md @@ -0,0 +1,24 @@ +# FixedPoint96 +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/FixedPoint96.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) + +*Used in SqrtPriceMath.sol* + + +## State Variables +### RESOLUTION + +```solidity +uint8 internal constant RESOLUTION = 96; +``` + + +### Q96 + +```solidity +uint256 internal constant Q96 = 0x1000000000000000000000000; +``` + + diff --git a/docs/contracts/v4/reference/core/libraries/FullMath.md b/docs/contracts/v4/reference/core/libraries/FullMath.md new file mode 100644 index 000000000..5228571ae --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/FullMath.md @@ -0,0 +1,58 @@ +# FullMath +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/FullMath.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision + +*Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits* + + +## Functions +### mulDiv + +Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 + +*Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv* + + +```solidity +function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`a`|`uint256`|The multiplicand| +|`b`|`uint256`|The multiplier| +|`denominator`|`uint256`|The divisor| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`result`|`uint256`|The 256-bit result| + + +### mulDivRoundingUp + +Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 + + +```solidity +function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`a`|`uint256`|The multiplicand| +|`b`|`uint256`|The multiplier| +|`denominator`|`uint256`|The divisor| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`result`|`uint256`|The 256-bit result| + + diff --git a/docs/contracts/v4/reference/core/libraries/Hooks.md b/docs/contracts/v4/reference/core/libraries/Hooks.md new file mode 100644 index 000000000..10b8f7cf4 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/Hooks.md @@ -0,0 +1,373 @@ +# Hooks +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/Hooks.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +V4 decides whether to invoke specific hooks by inspecting the least significant bits +of the address that the hooks contract is deployed to. +For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400 +has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used. + + +## State Variables +### ALL_HOOK_MASK + +```solidity +uint160 internal constant ALL_HOOK_MASK = uint160((1 << 14) - 1); +``` + + +### BEFORE_INITIALIZE_FLAG + +```solidity +uint160 internal constant BEFORE_INITIALIZE_FLAG = 1 << 13; +``` + + +### AFTER_INITIALIZE_FLAG + +```solidity +uint160 internal constant AFTER_INITIALIZE_FLAG = 1 << 12; +``` + + +### BEFORE_ADD_LIQUIDITY_FLAG + +```solidity +uint160 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 11; +``` + + +### AFTER_ADD_LIQUIDITY_FLAG + +```solidity +uint160 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 10; +``` + + +### BEFORE_REMOVE_LIQUIDITY_FLAG + +```solidity +uint160 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 9; +``` + + +### AFTER_REMOVE_LIQUIDITY_FLAG + +```solidity +uint160 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 8; +``` + + +### BEFORE_SWAP_FLAG + +```solidity +uint160 internal constant BEFORE_SWAP_FLAG = 1 << 7; +``` + + +### AFTER_SWAP_FLAG + +```solidity +uint160 internal constant AFTER_SWAP_FLAG = 1 << 6; +``` + + +### BEFORE_DONATE_FLAG + +```solidity +uint160 internal constant BEFORE_DONATE_FLAG = 1 << 5; +``` + + +### AFTER_DONATE_FLAG + +```solidity +uint160 internal constant AFTER_DONATE_FLAG = 1 << 4; +``` + + +### BEFORE_SWAP_RETURNS_DELTA_FLAG + +```solidity +uint160 internal constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 3; +``` + + +### AFTER_SWAP_RETURNS_DELTA_FLAG + +```solidity +uint160 internal constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 2; +``` + + +### AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG + +```solidity +uint160 internal constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 1; +``` + + +### AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG + +```solidity +uint160 internal constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 0; +``` + + +## Functions +### validateHookPermissions + +Utility function intended to be used in hook constructors to ensure +the deployed hooks address causes the intended hooks to be called + +*permissions param is memory as the function will be called from constructors* + + +```solidity +function validateHookPermissions(IHooks self, Permissions memory permissions) internal pure; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`IHooks`|| +|`permissions`|`Permissions`|The hooks that are intended to be called| + + +### isValidHookAddress + +Ensures that the hook address includes at least one hook flag or dynamic fees, or is the 0 address + + +```solidity +function isValidHookAddress(IHooks self, uint24 fee) internal pure returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`IHooks`|The hook to verify| +|`fee`|`uint24`|The fee of the pool the hook is used with| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True if the hook address is valid| + + +### callHook + +performs a hook call using the given calldata on the given hook that doesnt return a delta + + +```solidity +function callHook(IHooks self, bytes memory data) internal returns (bytes memory result); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`result`|`bytes`|The complete data returned by the hook| + + +### callHookWithReturnDelta + +performs a hook call using the given calldata on the given hook + + +```solidity +function callHookWithReturnDelta(IHooks self, bytes memory data, bool parseReturn) internal returns (int256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`int256`|int256 The delta returned by the hook| + + +### noSelfCall + +modifier to prevent calling a hook if they initiated the action + + +```solidity +modifier noSelfCall(IHooks self); +``` + +### beforeInitialize + +calls beforeInitialize hook if permissioned and validates return value + + +```solidity +function beforeInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData) + internal + noSelfCall(self); +``` + +### afterInitialize + +calls afterInitialize hook if permissioned and validates return value + + +```solidity +function afterInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96, int24 tick, bytes calldata hookData) + internal + noSelfCall(self); +``` + +### beforeModifyLiquidity + +calls beforeModifyLiquidity hook if permissioned and validates return value + + +```solidity +function beforeModifyLiquidity( + IHooks self, + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + bytes calldata hookData +) internal noSelfCall(self); +``` + +### afterModifyLiquidity + +calls afterModifyLiquidity hook if permissioned and validates return value + + +```solidity +function afterModifyLiquidity( + IHooks self, + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + BalanceDelta delta, + BalanceDelta feesAccrued, + bytes calldata hookData +) internal returns (BalanceDelta callerDelta, BalanceDelta hookDelta); +``` + +### beforeSwap + +calls beforeSwap hook if permissioned and validates return value + + +```solidity +function beforeSwap(IHooks self, PoolKey memory key, IPoolManager.SwapParams memory params, bytes calldata hookData) + internal + returns (int256 amountToSwap, BeforeSwapDelta hookReturn, uint24 lpFeeOverride); +``` + +### afterSwap + +calls afterSwap hook if permissioned and validates return value + + +```solidity +function afterSwap( + IHooks self, + PoolKey memory key, + IPoolManager.SwapParams memory params, + BalanceDelta swapDelta, + bytes calldata hookData, + BeforeSwapDelta beforeSwapHookReturn +) internal returns (BalanceDelta, BalanceDelta); +``` + +### beforeDonate + +calls beforeDonate hook if permissioned and validates return value + + +```solidity +function beforeDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) + internal + noSelfCall(self); +``` + +### afterDonate + +calls afterDonate hook if permissioned and validates return value + + +```solidity +function afterDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) + internal + noSelfCall(self); +``` + +### hasPermission + + +```solidity +function hasPermission(IHooks self, uint160 flag) internal pure returns (bool); +``` + +## Errors +### HookAddressNotValid +Thrown if the address will not lead to the specified hook calls being called + + +```solidity +error HookAddressNotValid(address hooks); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`hooks`|`address`|The address of the hooks contract| + +### InvalidHookResponse +Hook did not return its selector + + +```solidity +error InvalidHookResponse(); +``` + +### Wrap__FailedHookCall +thrown when a hook call fails + + +```solidity +error Wrap__FailedHookCall(address hook, bytes revertReason); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`hook`|`address`|| +|`revertReason`|`bytes`|bubbled up revert reason| + +### HookDeltaExceedsSwapAmount +The hook's delta changed the swap from exactIn to exactOut or vice versa + + +```solidity +error HookDeltaExceedsSwapAmount(); +``` + +## Structs +### Permissions + +```solidity +struct Permissions { + bool beforeInitialize; + bool afterInitialize; + bool beforeAddLiquidity; + bool afterAddLiquidity; + bool beforeRemoveLiquidity; + bool afterRemoveLiquidity; + bool beforeSwap; + bool afterSwap; + bool beforeDonate; + bool afterDonate; + bool beforeSwapReturnDelta; + bool afterSwapReturnDelta; + bool afterAddLiquidityReturnDelta; + bool afterRemoveLiquidityReturnDelta; +} +``` + diff --git a/docs/contracts/v4/reference/core/libraries/LPFeeLibrary.md b/docs/contracts/v4/reference/core/libraries/LPFeeLibrary.md new file mode 100644 index 000000000..a9fcddb3f --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/LPFeeLibrary.md @@ -0,0 +1,197 @@ +# LPFeeLibrary +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/LPFeeLibrary.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Library of helper functions for a pools LP fee + + +## State Variables +### DYNAMIC_FEE_FLAG +An lp fee of exactly 0b1000000... signals a dynamic fee pool. This isnt a valid static fee as it is > MAX_LP_FEE + + +```solidity +uint24 public constant DYNAMIC_FEE_FLAG = 0x800000; +``` + + +### OVERRIDE_FEE_FLAG +the second bit of the fee returned by beforeSwap is used to signal if the stored LP fee should be overridden in this swap + + +```solidity +uint24 public constant OVERRIDE_FEE_FLAG = 0x400000; +``` + + +### REMOVE_OVERRIDE_MASK +mask to remove the override fee flag from a fee returned by the beforeSwaphook + + +```solidity +uint24 public constant REMOVE_OVERRIDE_MASK = 0xBFFFFF; +``` + + +### MAX_LP_FEE +the lp fee is represented in hundredths of a bip, so the max is 100% + + +```solidity +uint24 public constant MAX_LP_FEE = 1000000; +``` + + +## Functions +### isDynamicFee + +returns true if a pool's LP fee signals that the pool has a dynamic fee + + +```solidity +function isDynamicFee(uint24 self) internal pure returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`uint24`|The fee to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True of the fee is dynamic| + + +### isValid + +returns true if an LP fee is valid, aka not above the maximum permitted fee + + +```solidity +function isValid(uint24 self) internal pure returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`uint24`|The fee to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True of the fee is valid| + + +### validate + +validates whether an LP fee is larger than the maximum, and reverts if invalid + + +```solidity +function validate(uint24 self) internal pure; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`uint24`|The fee to validate| + + +### getInitialLPFee + +gets and validates the initial LP fee for a pool. Dynamic fee pools have an initial fee of 0. + +*if a dynamic fee pool wants a non-0 initial fee, it should call `updateDynamicLPFee` in the afterInitialize hook* + + +```solidity +function getInitialLPFee(uint24 self) internal pure returns (uint24); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`uint24`|The fee to get the initial LP from| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint24`|initialFee 0 if the fee is dynamic, otherwise the fee (if valid)| + + +### isOverride + +returns true if the fee has the override flag set (2nd highest bit of the uint24) + + +```solidity +function isOverride(uint24 self) internal pure returns (bool); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`uint24`|The fee to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|bool True of the fee has the override flag set| + + +### removeOverrideFlag + +returns a fee with the override flag removed + + +```solidity +function removeOverrideFlag(uint24 self) internal pure returns (uint24); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`uint24`|The fee to remove the override flag from| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint24`|fee The fee without the override flag set| + + +### removeOverrideFlagAndValidate + +Removes the override flag and validates the fee (reverts if the fee is too large) + + +```solidity +function removeOverrideFlagAndValidate(uint24 self) internal pure returns (uint24 fee); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`uint24`|The fee to remove the override flag from, and then validate| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`fee`|`uint24`|The fee without the override flag set (if valid)| + + +## Errors +### LPFeeTooLarge +Thrown when the static or dynamic fee on a pool exceeds 100%. + + +```solidity +error LPFeeTooLarge(uint24 fee); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/LiquidityMath.md b/docs/contracts/v4/reference/core/libraries/LiquidityMath.md new file mode 100644 index 000000000..03c1136b8 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/LiquidityMath.md @@ -0,0 +1,28 @@ +# LiquidityMath +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/LiquidityMath.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### addDelta + +Add a signed liquidity delta to liquidity and revert if it overflows or underflows + + +```solidity +function addDelta(uint128 x, int128 y) internal pure returns (uint128 z); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint128`|The liquidity before change| +|`y`|`int128`|The delta by which liquidity should be changed| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`z`|`uint128`|The liquidity delta| + + diff --git a/docs/contracts/v4/reference/core/libraries/Lock.md b/docs/contracts/v4/reference/core/libraries/Lock.md new file mode 100644 index 000000000..b578a70d9 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/Lock.md @@ -0,0 +1,38 @@ +# Lock +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/Lock.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +This is a temporary library that allows us to use transient storage (tstore/tload) +TODO: This library can be deleted when we have the transient keyword support in solidity. + + +## State Variables +### IS_UNLOCKED_SLOT + +```solidity +bytes32 internal constant IS_UNLOCKED_SLOT = 0xc090fc4683624cfc3884e9d8de5eca132f2d0ec062aff75d43c0465d5ceeab23; +``` + + +## Functions +### unlock + + +```solidity +function unlock() internal; +``` + +### lock + + +```solidity +function lock() internal; +``` + +### isUnlocked + + +```solidity +function isUnlocked() internal view returns (bool unlocked); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/NonzeroDeltaCount.md b/docs/contracts/v4/reference/core/libraries/NonzeroDeltaCount.md new file mode 100644 index 000000000..bff21999c --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/NonzeroDeltaCount.md @@ -0,0 +1,42 @@ +# NonzeroDeltaCount +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/NonzeroDeltaCount.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +This is a temporary library that allows us to use transient storage (tstore/tload) +for the nonzero delta count. +TODO: This library can be deleted when we have the transient keyword support in solidity. + + +## State Variables +### NONZERO_DELTA_COUNT_SLOT + +```solidity +bytes32 internal constant NONZERO_DELTA_COUNT_SLOT = 0x7d4b3164c6e45b97e7d87b7125a44c5828d005af88f9d751cfd78729c5d99a0b; +``` + + +## Functions +### read + + +```solidity +function read() internal view returns (uint256 count); +``` + +### increment + + +```solidity +function increment() internal; +``` + +### decrement + +Potential to underflow. Ensure checks are performed by integrating contracts to ensure this does not happen. +Current usage ensures this will not happen because we call decrement with known boundaries (only up to the number of times we call increment). + + +```solidity +function decrement() internal; +``` + diff --git a/docs/contracts/v4/reference/core/libraries/ParseBytes.md b/docs/contracts/v4/reference/core/libraries/ParseBytes.md new file mode 100644 index 000000000..a5e153249 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/ParseBytes.md @@ -0,0 +1,32 @@ +# ParseBytes +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/ParseBytes.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Parses bytes returned from hooks and the byte selector used to check return selectors from hooks. + +*parseSelector also is used to parse the expected selector +For parsing hook returns, note that all hooks return either bytes4 or (bytes4, 32-byte-delta) or (bytes4, 32-byte-delta, uint24).* + + +## Functions +### parseSelector + + +```solidity +function parseSelector(bytes memory result) internal pure returns (bytes4 selector); +``` + +### parseFee + + +```solidity +function parseFee(bytes memory result) internal pure returns (uint24 lpFee); +``` + +### parseReturnDelta + + +```solidity +function parseReturnDelta(bytes memory result) internal pure returns (int256 hookReturn); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/Pool.md b/docs/contracts/v4/reference/core/libraries/Pool.md new file mode 100644 index 000000000..d5c0fd413 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/Pool.md @@ -0,0 +1,421 @@ +# Pool +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/Pool.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +a library with all actions that can be performed on a pool + + +## Functions +### checkTicks + +*Common checks for valid tick inputs.* + + +```solidity +function checkTicks(int24 tickLower, int24 tickUpper) private pure; +``` + +### initialize + + +```solidity +function initialize(State storage self, uint160 sqrtPriceX96, uint24 protocolFee, uint24 lpFee) + internal + returns (int24 tick); +``` + +### setProtocolFee + + +```solidity +function setProtocolFee(State storage self, uint24 protocolFee) internal; +``` + +### setLPFee + +Only dynamic fee pools may update the lp fee. + + +```solidity +function setLPFee(State storage self, uint24 lpFee) internal; +``` + +### modifyLiquidity + +Effect changes to a position in a pool + +*PoolManager checks that the pool is initialized before calling* + + +```solidity +function modifyLiquidity(State storage self, ModifyLiquidityParams memory params) + internal + returns (BalanceDelta delta, BalanceDelta feeDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`State`|| +|`params`|`ModifyLiquidityParams`|the position details and the change to the position's liquidity to effect| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`delta`|`BalanceDelta`|the deltas of the token balances of the pool, from the liquidity change| +|`feeDelta`|`BalanceDelta`|the fees generated by the liquidity range| + + +### swap + +Executes a swap against the state, and returns the amount deltas of the pool + +*PoolManager checks that the pool is initialized before calling* + + +```solidity +function swap(State storage self, SwapParams memory params) + internal + returns (BalanceDelta swapDelta, uint256 amountToProtocol, uint24 swapFee, SwapResult memory result); +``` + +### donate + +Donates the given amount of currency0 and currency1 to the pool + + +```solidity +function donate(State storage state, uint256 amount0, uint256 amount1) internal returns (BalanceDelta delta); +``` + +### getFeeGrowthInside + +Retrieves fee growth data + + +```solidity +function getFeeGrowthInside(State storage self, int24 tickLower, int24 tickUpper) + internal + view + returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`State`|The Pool state struct| +|`tickLower`|`int24`|The lower tick boundary of the position| +|`tickUpper`|`int24`|The upper tick boundary of the position| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feeGrowthInside0X128`|`uint256`|The all-time fee growth in token0, per unit of liquidity, inside the position's tick boundaries| +|`feeGrowthInside1X128`|`uint256`|The all-time fee growth in token1, per unit of liquidity, inside the position's tick boundaries| + + +### updateTick + +Updates a tick and returns true if the tick was flipped from initialized to uninitialized, or vice versa + + +```solidity +function updateTick(State storage self, int24 tick, int128 liquidityDelta, bool upper) + internal + returns (bool flipped, uint128 liquidityGrossAfter); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`State`|The mapping containing all tick information for initialized ticks| +|`tick`|`int24`|The tick that will be updated| +|`liquidityDelta`|`int128`|A new amount of liquidity to be added (subtracted) when tick is crossed from left to right (right to left)| +|`upper`|`bool`|true for updating a position's upper tick, or false for updating a position's lower tick| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`flipped`|`bool`|Whether the tick was flipped from initialized to uninitialized, or vice versa| +|`liquidityGrossAfter`|`uint128`|The total amount of liquidity for all positions that references the tick after the update| + + +### tickSpacingToMaxLiquidityPerTick + +Derives max liquidity per tick from given tick spacing + +*Executed when adding liquidity* + + +```solidity +function tickSpacingToMaxLiquidityPerTick(int24 tickSpacing) internal pure returns (uint128 result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tickSpacing`|`int24`|The amount of required tick separation, realized in multiples of `tickSpacing` e.g., a tickSpacing of 3 requires ticks to be initialized every 3rd tick i.e., ..., -6, -3, 0, 3, 6, ...| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`result`|`uint128`|The max liquidity per tick| + + +### checkPoolInitialized + +Reverts if the given pool has not been initialized + + +```solidity +function checkPoolInitialized(State storage self) internal view; +``` + +### clearTick + +Clears tick data + + +```solidity +function clearTick(State storage self, int24 tick) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`State`|The mapping containing all initialized tick information for initialized ticks| +|`tick`|`int24`|The tick that will be cleared| + + +### crossTick + +Transitions to next tick as needed by price movement + + +```solidity +function crossTick(State storage self, int24 tick, uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128) + internal + returns (int128 liquidityNet); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`State`|The Pool state struct| +|`tick`|`int24`|The destination tick of the transition| +|`feeGrowthGlobal0X128`|`uint256`|The all-time global fee growth, per unit of liquidity, in token0| +|`feeGrowthGlobal1X128`|`uint256`|The all-time global fee growth, per unit of liquidity, in token1| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidityNet`|`int128`|The amount of liquidity added (subtracted) when tick is crossed from left to right (right to left)| + + +## Errors +### TicksMisordered +Thrown when tickLower is not below tickUpper + + +```solidity +error TicksMisordered(int24 tickLower, int24 tickUpper); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tickLower`|`int24`|The invalid tickLower| +|`tickUpper`|`int24`|The invalid tickUpper| + +### TickLowerOutOfBounds +Thrown when tickLower is less than min tick + + +```solidity +error TickLowerOutOfBounds(int24 tickLower); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tickLower`|`int24`|The invalid tickLower| + +### TickUpperOutOfBounds +Thrown when tickUpper exceeds max tick + + +```solidity +error TickUpperOutOfBounds(int24 tickUpper); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tickUpper`|`int24`|The invalid tickUpper| + +### TickLiquidityOverflow +For the tick spacing, the tick has too much liquidity + + +```solidity +error TickLiquidityOverflow(int24 tick); +``` + +### PoolAlreadyInitialized +Thrown when trying to initialize an already initialized pool + + +```solidity +error PoolAlreadyInitialized(); +``` + +### PoolNotInitialized +Thrown when trying to interact with a non-initialized pool + + +```solidity +error PoolNotInitialized(); +``` + +### PriceLimitAlreadyExceeded +Thrown when sqrtPriceLimitX96 on a swap has already exceeded its limit + + +```solidity +error PriceLimitAlreadyExceeded(uint160 sqrtPriceCurrentX96, uint160 sqrtPriceLimitX96); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceCurrentX96`|`uint160`|The invalid, already surpassed sqrtPriceLimitX96| +|`sqrtPriceLimitX96`|`uint160`|The surpassed price limit| + +### PriceLimitOutOfBounds +Thrown when sqrtPriceLimitX96 lies outside of valid tick/price range + + +```solidity +error PriceLimitOutOfBounds(uint160 sqrtPriceLimitX96); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceLimitX96`|`uint160`|The invalid, out-of-bounds sqrtPriceLimitX96| + +### NoLiquidityToReceiveFees +Thrown by donate if there is currently 0 liquidity, since the fees will not go to any liquidity providers + + +```solidity +error NoLiquidityToReceiveFees(); +``` + +### InvalidFeeForExactOut +Thrown when trying to swap with max lp fee and specifying an output amount + + +```solidity +error InvalidFeeForExactOut(); +``` + +## Structs +### TickInfo + +```solidity +struct TickInfo { + uint128 liquidityGross; + int128 liquidityNet; + uint256 feeGrowthOutside0X128; + uint256 feeGrowthOutside1X128; +} +``` + +### State +*The state of a pool* + + +```solidity +struct State { + Slot0 slot0; + uint256 feeGrowthGlobal0X128; + uint256 feeGrowthGlobal1X128; + uint128 liquidity; + mapping(int24 tick => TickInfo) ticks; + mapping(int16 wordPos => uint256) tickBitmap; + mapping(bytes32 positionKey => Position.State) positions; +} +``` + +### ModifyLiquidityParams + +```solidity +struct ModifyLiquidityParams { + address owner; + int24 tickLower; + int24 tickUpper; + int128 liquidityDelta; + int24 tickSpacing; + bytes32 salt; +} +``` + +### ModifyLiquidityState + +```solidity +struct ModifyLiquidityState { + bool flippedLower; + uint128 liquidityGrossAfterLower; + bool flippedUpper; + uint128 liquidityGrossAfterUpper; +} +``` + +### SwapResult + +```solidity +struct SwapResult { + uint160 sqrtPriceX96; + int24 tick; + uint128 liquidity; +} +``` + +### StepComputations + +```solidity +struct StepComputations { + uint160 sqrtPriceStartX96; + int24 tickNext; + bool initialized; + uint160 sqrtPriceNextX96; + uint256 amountIn; + uint256 amountOut; + uint256 feeAmount; + uint256 feeGrowthGlobalX128; +} +``` + +### SwapParams + +```solidity +struct SwapParams { + int256 amountSpecified; + int24 tickSpacing; + bool zeroForOne; + uint160 sqrtPriceLimitX96; + uint24 lpFeeOverride; +} +``` + diff --git a/docs/contracts/v4/reference/core/libraries/Position.md b/docs/contracts/v4/reference/core/libraries/Position.md new file mode 100644 index 000000000..221ec3a00 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/Position.md @@ -0,0 +1,106 @@ +# Position +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/Position.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Positions represent an owner address' liquidity between a lower and upper tick boundary + +*Positions store additional state for tracking fees owed to the position* + + +## Functions +### get + +Returns the State struct of a position, given an owner and position boundaries + + +```solidity +function get(mapping(bytes32 => State) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt) + internal + view + returns (State storage position); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`mapping(bytes32 => State)`|The mapping containing all user positions| +|`owner`|`address`|The address of the position owner| +|`tickLower`|`int24`|The lower tick boundary of the position| +|`tickUpper`|`int24`|The upper tick boundary of the position| +|`salt`|`bytes32`|A unique value to differentiate between multiple positions in the same range| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`position`|`State`|The position info struct of the given owners' position| + + +### calculatePositionKey + +A helper function to calculate the position key + + +```solidity +function calculatePositionKey(address owner, int24 tickLower, int24 tickUpper, bytes32 salt) + internal + pure + returns (bytes32 positionKey); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address of the position owner| +|`tickLower`|`int24`|the lower tick boundary of the position| +|`tickUpper`|`int24`|the upper tick boundary of the position| +|`salt`|`bytes32`|A unique value to differentiate between multiple positions in the same range, by the same owner. Passed in by the caller.| + + +### update + +Credits accumulated fees to a user's position + + +```solidity +function update(State storage self, int128 liquidityDelta, uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) + internal + returns (uint256 feesOwed0, uint256 feesOwed1); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`State`|The individual position to update| +|`liquidityDelta`|`int128`|The change in pool liquidity as a result of the position update| +|`feeGrowthInside0X128`|`uint256`|The all-time fee growth in currency0, per unit of liquidity, inside the position's tick boundaries| +|`feeGrowthInside1X128`|`uint256`|The all-time fee growth in currency1, per unit of liquidity, inside the position's tick boundaries| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feesOwed0`|`uint256`|The amount of currency0 owed to the position owner| +|`feesOwed1`|`uint256`|The amount of currency1 owed to the position owner| + + +## Errors +### CannotUpdateEmptyPosition +Cannot update a position with no liquidity + + +```solidity +error CannotUpdateEmptyPosition(); +``` + +## Structs +### State + +```solidity +struct State { + uint128 liquidity; + uint256 feeGrowthInside0LastX128; + uint256 feeGrowthInside1LastX128; +} +``` + diff --git a/docs/contracts/v4/reference/core/libraries/ProtocolFeeLibrary.md b/docs/contracts/v4/reference/core/libraries/ProtocolFeeLibrary.md new file mode 100644 index 000000000..52e5bd26c --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/ProtocolFeeLibrary.md @@ -0,0 +1,75 @@ +# ProtocolFeeLibrary +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/ProtocolFeeLibrary.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +library of functions related to protocol fees + + +## State Variables +### MAX_PROTOCOL_FEE +Max protocol fee is 0.1% (1000 pips) + +*Increasing these values could lead to overflow in Pool.swap* + + +```solidity +uint16 public constant MAX_PROTOCOL_FEE = 1000; +``` + + +### FEE_0_THRESHOLD +Thresholds used for optimized bounds checks on protocol fees + + +```solidity +uint24 internal constant FEE_0_THRESHOLD = 1001; +``` + + +### FEE_1_THRESHOLD + +```solidity +uint24 internal constant FEE_1_THRESHOLD = 1001 << 12; +``` + + +### PIPS_DENOMINATOR +the protocol fee is represented in hundredths of a bip + + +```solidity +uint256 internal constant PIPS_DENOMINATOR = 1_000_000; +``` + + +## Functions +### getZeroForOneFee + + +```solidity +function getZeroForOneFee(uint24 self) internal pure returns (uint16); +``` + +### getOneForZeroFee + + +```solidity +function getOneForZeroFee(uint24 self) internal pure returns (uint16); +``` + +### isValidProtocolFee + + +```solidity +function isValidProtocolFee(uint24 self) internal pure returns (bool valid); +``` + +### calculateSwapFee + +*here `self` is just a single direction's protocol fee, not a packed type of 2 protocol fees* + + +```solidity +function calculateSwapFee(uint16 self, uint24 lpFee) internal pure returns (uint24 swapFee); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/SafeCast.md b/docs/contracts/v4/reference/core/libraries/SafeCast.md new file mode 100644 index 000000000..8865bf34a --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/SafeCast.md @@ -0,0 +1,141 @@ +# SafeCast +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/SafeCast.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Contains methods for safely casting between types + + +## Functions +### toUint160 + +Cast a uint256 to a uint160, revert on overflow + + +```solidity +function toUint160(uint256 x) internal pure returns (uint160 y); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint256`|The uint256 to be downcasted| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`y`|`uint160`|The downcasted integer, now type uint160| + + +### toUint128 + +Cast a uint256 to a uint128, revert on overflow + + +```solidity +function toUint128(uint256 x) internal pure returns (uint128 y); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint256`|The uint256 to be downcasted| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`y`|`uint128`|The downcasted integer, now type uint128| + + +### toUint128 + +Cast a int128 to a uint128, revert on overflow or underflow + + +```solidity +function toUint128(int128 x) internal pure returns (uint128 y); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`int128`|The int128 to be casted| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`y`|`uint128`|The casted integer, now type uint128| + + +### toInt128 + +Cast a int256 to a int128, revert on overflow or underflow + + +```solidity +function toInt128(int256 x) internal pure returns (int128 y); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`int256`|The int256 to be downcasted| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`y`|`int128`|The downcasted integer, now type int128| + + +### toInt256 + +Cast a uint256 to a int256, revert on overflow + + +```solidity +function toInt256(uint256 x) internal pure returns (int256 y); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint256`|The uint256 to be casted| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`y`|`int256`|The casted integer, now type int256| + + +### toInt128 + +Cast a uint256 to a int128, revert on overflow + + +```solidity +function toInt128(uint256 x) internal pure returns (int128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint256`|The uint256 to be downcasted| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`int128`|The downcasted integer, now type int128| + + +## Errors +### SafeCastOverflow + +```solidity +error SafeCastOverflow(); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/SqrtPriceMath.md b/docs/contracts/v4/reference/core/libraries/SqrtPriceMath.md new file mode 100644 index 000000000..a6ca55748 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/SqrtPriceMath.md @@ -0,0 +1,282 @@ +# SqrtPriceMath +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/SqrtPriceMath.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas + + +## Functions +### getNextSqrtPriceFromAmount0RoundingUp + +Gets the next sqrt price given a delta of currency0 + +*Always rounds up, because in the exact output case (increasing price) we need to move the price at least +far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the +price less in order to not send too much output. +The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96), +if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount).* + + +```solidity +function getNextSqrtPriceFromAmount0RoundingUp(uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add) + internal + pure + returns (uint160); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPX96`|`uint160`|The starting price, i.e. before accounting for the currency0 delta| +|`liquidity`|`uint128`|The amount of usable liquidity| +|`amount`|`uint256`|How much of currency0 to add or remove from virtual reserves| +|`add`|`bool`|Whether to add or remove the amount of currency0| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint160`|The price after adding or removing amount, depending on add| + + +### getNextSqrtPriceFromAmount1RoundingDown + +Gets the next sqrt price given a delta of currency1 + +*Always rounds down, because in the exact output case (decreasing price) we need to move the price at least +far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the +price less in order to not send too much output. +The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity* + + +```solidity +function getNextSqrtPriceFromAmount1RoundingDown(uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add) + internal + pure + returns (uint160); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPX96`|`uint160`|The starting price, i.e., before accounting for the currency1 delta| +|`liquidity`|`uint128`|The amount of usable liquidity| +|`amount`|`uint256`|How much of currency1 to add, or remove, from virtual reserves| +|`add`|`bool`|Whether to add, or remove, the amount of currency1| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint160`|The price after adding or removing `amount`| + + +### getNextSqrtPriceFromInput + +Gets the next sqrt price given an input amount of currency0 or currency1 + +*Throws if price or liquidity are 0, or if the next price is out of bounds* + + +```solidity +function getNextSqrtPriceFromInput(uint160 sqrtPX96, uint128 liquidity, uint256 amountIn, bool zeroForOne) + internal + pure + returns (uint160); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPX96`|`uint160`|The starting price, i.e., before accounting for the input amount| +|`liquidity`|`uint128`|The amount of usable liquidity| +|`amountIn`|`uint256`|How much of currency0, or currency1, is being swapped in| +|`zeroForOne`|`bool`|Whether the amount in is currency0 or currency1| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint160`|uint160 The price after adding the input amount to currency0 or currency1| + + +### getNextSqrtPriceFromOutput + +Gets the next sqrt price given an output amount of currency0 or currency1 + +*Throws if price or liquidity are 0 or the next price is out of bounds* + + +```solidity +function getNextSqrtPriceFromOutput(uint160 sqrtPX96, uint128 liquidity, uint256 amountOut, bool zeroForOne) + internal + pure + returns (uint160); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPX96`|`uint160`|The starting price before accounting for the output amount| +|`liquidity`|`uint128`|The amount of usable liquidity| +|`amountOut`|`uint256`|How much of currency0, or currency1, is being swapped out| +|`zeroForOne`|`bool`|Whether the amount out is currency1 or currency0| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint160`|uint160 The price after removing the output amount of currency0 or currency1| + + +### getAmount0Delta + +Gets the amount0 delta between two prices + +*Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper), +i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))* + + +```solidity +function getAmount0Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint128 liquidity, bool roundUp) + internal + pure + returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceAX96`|`uint160`|A sqrt price| +|`sqrtPriceBX96`|`uint160`|Another sqrt price| +|`liquidity`|`uint128`|The amount of usable liquidity| +|`roundUp`|`bool`|Whether to round the amount up or down| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|uint256 Amount of currency0 required to cover a position of size liquidity between the two passed prices| + + +### absDiff + +Equivalent to: `a >= b ? a - b : b - a` + + +```solidity +function absDiff(uint160 a, uint160 b) internal pure returns (uint256 res); +``` + +### getAmount1Delta + +Gets the amount1 delta between two prices + +*Calculates liquidity * (sqrt(upper) - sqrt(lower))* + + +```solidity +function getAmount1Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint128 liquidity, bool roundUp) + internal + pure + returns (uint256 amount1); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceAX96`|`uint160`|A sqrt price| +|`sqrtPriceBX96`|`uint160`|Another sqrt price| +|`liquidity`|`uint128`|The amount of usable liquidity| +|`roundUp`|`bool`|Whether to round the amount up, or down| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount1`|`uint256`|Amount of currency1 required to cover a position of size liquidity between the two passed prices| + + +### getAmount0Delta + +Equivalent to: +amount1 = roundUp +? FullMath.mulDivRoundingUp(liquidity, sqrtPriceBX96 - sqrtPriceAX96, FixedPoint96.Q96) +: FullMath.mulDiv(liquidity, sqrtPriceBX96 - sqrtPriceAX96, FixedPoint96.Q96); +Cannot overflow because `type(uint128).max * type(uint160).max >> 96 < (1 << 192)`. + +Helper that gets signed currency0 delta + + +```solidity +function getAmount0Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, int128 liquidity) + internal + pure + returns (int256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceAX96`|`uint160`|A sqrt price| +|`sqrtPriceBX96`|`uint160`|Another sqrt price| +|`liquidity`|`int128`|The change in liquidity for which to compute the amount0 delta| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`int256`|int256 Amount of currency0 corresponding to the passed liquidityDelta between the two prices| + + +### getAmount1Delta + +Helper that gets signed currency1 delta + + +```solidity +function getAmount1Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, int128 liquidity) + internal + pure + returns (int256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceAX96`|`uint160`|A sqrt price| +|`sqrtPriceBX96`|`uint160`|Another sqrt price| +|`liquidity`|`int128`|The change in liquidity for which to compute the amount1 delta| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`int256`|int256 Amount of currency1 corresponding to the passed liquidityDelta between the two prices| + + +## Errors +### InvalidPriceOrLiquidity + +```solidity +error InvalidPriceOrLiquidity(); +``` + +### InvalidPrice + +```solidity +error InvalidPrice(); +``` + +### NotEnoughLiquidity + +```solidity +error NotEnoughLiquidity(); +``` + +### PriceOverflow + +```solidity +error PriceOverflow(); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/StateLibrary.md b/docs/contracts/v4/reference/core/libraries/StateLibrary.md new file mode 100644 index 000000000..bdec514ac --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/StateLibrary.md @@ -0,0 +1,405 @@ +# StateLibrary +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/StateLibrary.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +A helper library to provide state getters that use extsload + + +## State Variables +### POOLS_SLOT +index of pools mapping in the PoolManager + + +```solidity +bytes32 public constant POOLS_SLOT = bytes32(uint256(6)); +``` + + +### FEE_GROWTH_GLOBAL0_OFFSET +index of feeGrowthGlobal0X128 in Pool.State + + +```solidity +uint256 public constant FEE_GROWTH_GLOBAL0_OFFSET = 1; +``` + + +### LIQUIDITY_OFFSET +index of liquidity in Pool.State + + +```solidity +uint256 public constant LIQUIDITY_OFFSET = 3; +``` + + +### TICKS_OFFSET +index of TicksInfo mapping in Pool.State: mapping(int24 => TickInfo) ticks; + + +```solidity +uint256 public constant TICKS_OFFSET = 4; +``` + + +### TICK_BITMAP_OFFSET +index of tickBitmap mapping in Pool.State + + +```solidity +uint256 public constant TICK_BITMAP_OFFSET = 5; +``` + + +### POSITIONS_OFFSET +index of Position.State mapping in Pool.State: mapping(bytes32 => Position.State) positions; + + +```solidity +uint256 public constant POSITIONS_OFFSET = 6; +``` + + +## Functions +### getSlot0 + +Get Slot0 of the pool: sqrtPriceX96, tick, protocolFee, lpFee + +*Corresponds to pools[poolId].slot0* + + +```solidity +function getSlot0(IPoolManager manager, PoolId poolId) + internal + view + returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceX96`|`uint160`|The square root of the price of the pool, in Q96 precision.| +|`tick`|`int24`|The current tick of the pool.| +|`protocolFee`|`uint24`|The protocol fee of the pool.| +|`lpFee`|`uint24`|The swap fee of the pool.| + + +### getTickInfo + +Retrieves the tick information of a pool at a specific tick. + +*Corresponds to pools[poolId].ticks[tick]* + + +```solidity +function getTickInfo(IPoolManager manager, PoolId poolId, int24 tick) + internal + view + returns (uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int24`|The tick to retrieve information for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidityGross`|`uint128`|The total position liquidity that references this tick| +|`liquidityNet`|`int128`|The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)| +|`feeGrowthOutside0X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| +|`feeGrowthOutside1X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| + + +### getTickLiquidity + +Retrieves the liquidity information of a pool at a specific tick. + +*Corresponds to pools[poolId].ticks[tick].liquidityGross and pools[poolId].ticks[tick].liquidityNet. A more gas efficient version of getTickInfo* + + +```solidity +function getTickLiquidity(IPoolManager manager, PoolId poolId, int24 tick) + internal + view + returns (uint128 liquidityGross, int128 liquidityNet); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int24`|The tick to retrieve liquidity for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidityGross`|`uint128`|The total position liquidity that references this tick| +|`liquidityNet`|`int128`|The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)| + + +### getTickFeeGrowthOutside + +Retrieves the fee growth outside a tick range of a pool + +*Corresponds to pools[poolId].ticks[tick].feeGrowthOutside0X128 and pools[poolId].ticks[tick].feeGrowthOutside1X128. A more gas efficient version of getTickInfo* + + +```solidity +function getTickFeeGrowthOutside(IPoolManager manager, PoolId poolId, int24 tick) + internal + view + returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int24`|The tick to retrieve fee growth for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feeGrowthOutside0X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| +|`feeGrowthOutside1X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| + + +### getFeeGrowthGlobals + +Retrieves the global fee growth of a pool. + +*Corresponds to pools[poolId].feeGrowthGlobal0X128 and pools[poolId].feeGrowthGlobal1X128* + + +```solidity +function getFeeGrowthGlobals(IPoolManager manager, PoolId poolId) + internal + view + returns (uint256 feeGrowthGlobal0, uint256 feeGrowthGlobal1); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feeGrowthGlobal0`|`uint256`|The global fee growth for token0.| +|`feeGrowthGlobal1`|`uint256`|The global fee growth for token1.| + + +### getLiquidity + +Retrieves total the liquidity of a pool. + +*Corresponds to pools[poolId].liquidity* + + +```solidity +function getLiquidity(IPoolManager manager, PoolId poolId) internal view returns (uint128 liquidity); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the pool.| + + +### getTickBitmap + +Retrieves the tick bitmap of a pool at a specific tick. + +*Corresponds to pools[poolId].tickBitmap[tick]* + + +```solidity +function getTickBitmap(IPoolManager manager, PoolId poolId, int16 tick) internal view returns (uint256 tickBitmap); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int16`|The tick to retrieve the bitmap for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tickBitmap`|`uint256`|The bitmap of the tick.| + + +### getPositionInfo + +Retrieves the position information of a pool without needing to calculate the `positionId`. + +*Corresponds to pools[poolId].positions[positionId]* + + +```solidity +function getPositionInfo( + IPoolManager manager, + PoolId poolId, + address owner, + int24 tickLower, + int24 tickUpper, + bytes32 salt +) internal view returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|| +|`poolId`|`PoolId`|The ID of the pool.| +|`owner`|`address`|The owner of the liquidity position.| +|`tickLower`|`int24`|The lower tick of the liquidity range.| +|`tickUpper`|`int24`|The upper tick of the liquidity range.| +|`salt`|`bytes32`|The bytes32 randomness to further distinguish position state.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the position.| +|`feeGrowthInside0LastX128`|`uint256`|The fee growth inside the position for token0.| +|`feeGrowthInside1LastX128`|`uint256`|The fee growth inside the position for token1.| + + +### getPositionInfo + +Retrieves the position information of a pool at a specific position ID. + +*Corresponds to pools[poolId].positions[positionId]* + + +```solidity +function getPositionInfo(IPoolManager manager, PoolId poolId, bytes32 positionId) + internal + view + returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| +|`positionId`|`bytes32`|The ID of the position.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the position.| +|`feeGrowthInside0LastX128`|`uint256`|The fee growth inside the position for token0.| +|`feeGrowthInside1LastX128`|`uint256`|The fee growth inside the position for token1.| + + +### getPositionLiquidity + +Retrieves the liquidity of a position. + +*Corresponds to pools[poolId].positions[positionId].liquidity. More gas efficient for just retrieiving liquidity as compared to getPositionInfo* + + +```solidity +function getPositionLiquidity(IPoolManager manager, PoolId poolId, bytes32 positionId) + internal + view + returns (uint128 liquidity); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| +|`positionId`|`bytes32`|The ID of the position.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the position.| + + +### getFeeGrowthInside + +Calculate the fee growth inside a tick range of a pool + +*pools[poolId].feeGrowthInside0LastX128 in Position.State is cached and can become stale. This function will calculate the up to date feeGrowthInside* + + +```solidity +function getFeeGrowthInside(IPoolManager manager, PoolId poolId, int24 tickLower, int24 tickUpper) + internal + view + returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| +|`poolId`|`PoolId`|The ID of the pool.| +|`tickLower`|`int24`|The lower tick of the range.| +|`tickUpper`|`int24`|The upper tick of the range.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feeGrowthInside0X128`|`uint256`|The fee growth inside the tick range for token0.| +|`feeGrowthInside1X128`|`uint256`|The fee growth inside the tick range for token1.| + + +### _getPoolStateSlot + + +```solidity +function _getPoolStateSlot(PoolId poolId) internal pure returns (bytes32); +``` + +### _getTickInfoSlot + + +```solidity +function _getTickInfoSlot(PoolId poolId, int24 tick) internal pure returns (bytes32); +``` + +### _getPositionInfoSlot + + +```solidity +function _getPositionInfoSlot(PoolId poolId, bytes32 positionId) internal pure returns (bytes32); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/SwapMath.md b/docs/contracts/v4/reference/core/libraries/SwapMath.md new file mode 100644 index 000000000..3a3ccd4a2 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/SwapMath.md @@ -0,0 +1,84 @@ +# SwapMath +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/SwapMath.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Contains methods for computing the result of a swap within a single tick price range, i.e., a single tick. + + +## State Variables +### MAX_SWAP_FEE +the swap fee is represented in hundredths of a bip, so the max is 100% + +*the swap fee is the total fee on a swap, including both LP and Protocol fee* + + +```solidity +uint256 internal constant MAX_SWAP_FEE = 1e6; +``` + + +## Functions +### getSqrtPriceTarget + +Computes the sqrt price target for the next swap step + + +```solidity +function getSqrtPriceTarget(bool zeroForOne, uint160 sqrtPriceNextX96, uint160 sqrtPriceLimitX96) + internal + pure + returns (uint160 sqrtPriceTargetX96); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`zeroForOne`|`bool`|The direction of the swap, true for currency0 to currency1, false for currency1 to currency0| +|`sqrtPriceNextX96`|`uint160`|The Q64.96 sqrt price for the next initialized tick| +|`sqrtPriceLimitX96`|`uint160`|The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceTargetX96`|`uint160`|The price target for the next swap step| + + +### computeSwapStep + +Computes the result of swapping some amount in, or amount out, given the parameters of the swap + +*If the swap's amountSpecified is negative, the combined fee and input amount will never exceed the absolute value of the remaining amount.* + +*feePips must be no larger than MAX_SWAP_FEE for this function. We ensure that before setting a fee using LPFeeLibrary.isValid.* + + +```solidity +function computeSwapStep( + uint160 sqrtPriceCurrentX96, + uint160 sqrtPriceTargetX96, + uint128 liquidity, + int256 amountRemaining, + uint24 feePips +) internal pure returns (uint160 sqrtPriceNextX96, uint256 amountIn, uint256 amountOut, uint256 feeAmount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceCurrentX96`|`uint160`|The current sqrt price of the pool| +|`sqrtPriceTargetX96`|`uint160`|The price that cannot be exceeded, from which the direction of the swap is inferred| +|`liquidity`|`uint128`|The usable liquidity| +|`amountRemaining`|`int256`|How much input or output amount is remaining to be swapped in/out| +|`feePips`|`uint24`|The fee taken from the input amount, expressed in hundredths of a bip| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceNextX96`|`uint160`|The price after swapping the amount in/out, not to exceed the price target| +|`amountIn`|`uint256`|The amount to be swapped in, of either currency0 or currency1, based on the direction of the swap| +|`amountOut`|`uint256`|The amount to be received, of either currency0 or currency1, based on the direction of the swap| +|`feeAmount`|`uint256`|The amount of input that will be taken as a fee| + + diff --git a/docs/contracts/v4/reference/core/libraries/TickBitmap.md b/docs/contracts/v4/reference/core/libraries/TickBitmap.md new file mode 100644 index 000000000..975119714 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/TickBitmap.md @@ -0,0 +1,105 @@ +# TickBitmap +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/TickBitmap.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Stores a packed mapping of tick index to its initialized state + +*The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.* + + +## Functions +### compress + +*round towards negative infinity* + + +```solidity +function compress(int24 tick, int24 tickSpacing) internal pure returns (int24 compressed); +``` + +### position + +Computes the position in the mapping where the initialized bit for a tick lives + + +```solidity +function position(int24 tick) internal pure returns (int16 wordPos, uint8 bitPos); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tick`|`int24`|The tick for which to compute the position| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`wordPos`|`int16`|The key in the mapping containing the word in which the bit is stored| +|`bitPos`|`uint8`|The bit position in the word where the flag is stored| + + +### flipTick + +Flips the initialized state for a given tick from false to true, or vice versa + + +```solidity +function flipTick(mapping(int16 => uint256) storage self, int24 tick, int24 tickSpacing) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`mapping(int16 => uint256)`|The mapping in which to flip the tick| +|`tick`|`int24`|The tick to flip| +|`tickSpacing`|`int24`|The spacing between usable ticks| + + +### nextInitializedTickWithinOneWord + +Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either +to the left (less than or equal to) or right (greater than) of the given tick + + +```solidity +function nextInitializedTickWithinOneWord( + mapping(int16 => uint256) storage self, + int24 tick, + int24 tickSpacing, + bool lte +) internal view returns (int24 next, bool initialized); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`self`|`mapping(int16 => uint256)`|The mapping in which to compute the next initialized tick| +|`tick`|`int24`|The starting tick| +|`tickSpacing`|`int24`|The spacing between usable ticks| +|`lte`|`bool`|Whether to search for the next initialized tick to the left (less than or equal to the starting tick)| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`next`|`int24`|The next initialized or uninitialized tick up to 256 ticks away from the current tick| +|`initialized`|`bool`|Whether the next tick is initialized, as the function only searches within up to 256 ticks| + + +## Errors +### TickMisaligned +Thrown when the tick is not enumerated by the tick spacing + + +```solidity +error TickMisaligned(int24 tick, int24 tickSpacing); +``` + +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tick`|`int24`|the invalid tick| +|`tickSpacing`|`int24`|The tick spacing of the pool| + diff --git a/docs/contracts/v4/reference/core/libraries/TickMath.md b/docs/contracts/v4/reference/core/libraries/TickMath.md new file mode 100644 index 000000000..f1c7e664d --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/TickMath.md @@ -0,0 +1,160 @@ +# TickMath +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/TickMath.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports +prices between 2**-128 and 2**128 + + +## State Variables +### MIN_TICK +*The minimum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**-128* + +*If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used* + + +```solidity +int24 internal constant MIN_TICK = -887272; +``` + + +### MAX_TICK +*The maximum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**128* + +*If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used* + + +```solidity +int24 internal constant MAX_TICK = 887272; +``` + + +### MIN_TICK_SPACING +*The minimum tick spacing value drawn from the range of type int16 that is greater than 0, i.e. min from the range [1, 32767]* + + +```solidity +int24 internal constant MIN_TICK_SPACING = 1; +``` + + +### MAX_TICK_SPACING +*The maximum tick spacing value drawn from the range of type int16, i.e. max from the range [1, 32767]* + + +```solidity +int24 internal constant MAX_TICK_SPACING = type(int16).max; +``` + + +### MIN_SQRT_PRICE +*The minimum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MIN_TICK)* + + +```solidity +uint160 internal constant MIN_SQRT_PRICE = 4295128739; +``` + + +### MAX_SQRT_PRICE +*The maximum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MAX_TICK)* + + +```solidity +uint160 internal constant MAX_SQRT_PRICE = 1461446703485210103287273052203988822378723970342; +``` + + +### MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE +*A threshold used for optimized bounds check, equals `MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1`* + + +```solidity +uint160 internal constant MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE = + 1461446703485210103287273052203988822378723970342 - 4295128739 - 1; +``` + + +## Functions +### maxUsableTick + +Given a tickSpacing, compute the maximum usable tick + + +```solidity +function maxUsableTick(int24 tickSpacing) internal pure returns (int24); +``` + +### minUsableTick + +Given a tickSpacing, compute the minimum usable tick + + +```solidity +function minUsableTick(int24 tickSpacing) internal pure returns (int24); +``` + +### getSqrtPriceAtTick + +Calculates sqrt(1.0001^tick) * 2^96 + +*Throws if |tick| > max tick* + + +```solidity +function getSqrtPriceAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tick`|`int24`|The input tick for the above formula| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceX96`|`uint160`|A Fixed point Q64.96 number representing the sqrt of the price of the two assets (currency1/currency0) at the given tick| + + +### getTickAtSqrtPrice + +Calculates the greatest tick value such that getSqrtPriceAtTick(tick) <= sqrtPriceX96 + +*Throws in case sqrtPriceX96 < MIN_SQRT_PRICE, as MIN_SQRT_PRICE is the lowest value getSqrtPriceAtTick may +ever return.* + + +```solidity +function getTickAtSqrtPrice(uint160 sqrtPriceX96) internal pure returns (int24 tick); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceX96`|`uint160`|The sqrt price for which to compute the tick as a Q64.96| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tick`|`int24`|The greatest tick for which the getSqrtPriceAtTick(tick) is less than or equal to the input sqrtPriceX96| + + +## Errors +### InvalidTick +Thrown when the tick passed to #getSqrtPriceAtTick is not between MIN_TICK and MAX_TICK + + +```solidity +error InvalidTick(int24 tick); +``` + +### InvalidSqrtPrice +Thrown when the price passed to #getTickAtSqrtPrice does not correspond to a price between MIN_TICK and MAX_TICK + + +```solidity +error InvalidSqrtPrice(uint160 sqrtPriceX96); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/TransientStateLibrary.md b/docs/contracts/v4/reference/core/libraries/TransientStateLibrary.md new file mode 100644 index 000000000..bd9be0025 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/TransientStateLibrary.md @@ -0,0 +1,74 @@ +# TransientStateLibrary +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/TransientStateLibrary.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +A helper library to provide state getters that use exttload + + +## Functions +### getSyncedReserves + +returns the reserves for the synced currency + +*returns 0 if the reserves are not synced or value is 0. +Checks the synced currency to only return valid reserve values (after a sync and before a settle).* + + +```solidity +function getSyncedReserves(IPoolManager manager) internal view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|The pool manager contract.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|uint256 The reserves of the currency.| + + +### getSyncedCurrency + + +```solidity +function getSyncedCurrency(IPoolManager manager) internal view returns (Currency); +``` + +### getNonzeroDeltaCount + +Returns the number of nonzero deltas open on the PoolManager that must be zeroed out before the contract is locked + + +```solidity +function getNonzeroDeltaCount(IPoolManager manager) internal view returns (uint256); +``` + +### currencyDelta + +Get the current delta for a caller in the given currency + + +```solidity +function currencyDelta(IPoolManager manager, address target, Currency currency) internal view returns (int256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`manager`|`IPoolManager`|| +|`target`|`address`|The credited account address| +|`currency`|`Currency`|The currency for which to lookup the delta| + + +### isUnlocked + +Returns whether the contract is unlocked or not + + +```solidity +function isUnlocked(IPoolManager manager) internal view returns (bool); +``` + diff --git a/docs/contracts/v4/reference/core/libraries/UnsafeMath.md b/docs/contracts/v4/reference/core/libraries/UnsafeMath.md new file mode 100644 index 000000000..0b6423831 --- /dev/null +++ b/docs/contracts/v4/reference/core/libraries/UnsafeMath.md @@ -0,0 +1,57 @@ +# UnsafeMath +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/libraries/UnsafeMath.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Contains methods that perform common math functions but do not do any overflow or underflow checks + + +## Functions +### divRoundingUp + +Returns ceil(x / y) + +*division by 0 has unspecified behavior, and must be checked externally* + + +```solidity +function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`x`|`uint256`|The dividend| +|`y`|`uint256`|The divisor| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`z`|`uint256`|The quotient, ceil(x / y)| + + +### simpleMulDiv + +Calculates floor(a×b÷denominator) + +*division by 0 has unspecified behavior, and must be checked externally* + + +```solidity +function simpleMulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`a`|`uint256`|The multiplicand| +|`b`|`uint256`|The multiplier| +|`denominator`|`uint256`|The divisor| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`result`|`uint256`|The 256-bit result, floor(a×b÷denominator)| + + diff --git a/docs/contracts/v4/reference/core/test/ActionsRouter.md b/docs/contracts/v4/reference/core/test/ActionsRouter.md new file mode 100644 index 000000000..a4d256f30 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/ActionsRouter.md @@ -0,0 +1,145 @@ +# ActionsRouter +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/ActionsRouter.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IUnlockCallback](/src/interfaces/callback/IUnlockCallback.sol/interface.IUnlockCallback.md), Test, GasSnapshot + +A router that handles an arbitrary input of actions. +TODO: Can continue to add functions per action. + + +## State Variables +### manager + +```solidity +IPoolManager manager; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager); +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata data) external returns (bytes memory); +``` + +### executeActions + + +```solidity +function executeActions(Actions[] memory actions, bytes[] memory params) external payable; +``` + +### _settle + + +```solidity +function _settle() internal; +``` + +### _settleNative + + +```solidity +function _settleNative(bytes memory params) internal; +``` + +### _settleFor + + +```solidity +function _settleFor(bytes memory params) internal; +``` + +### _take + + +```solidity +function _take(bytes memory params) internal; +``` + +### _prankTakeFrom + + +```solidity +function _prankTakeFrom(bytes memory params) internal; +``` + +### _sync + + +```solidity +function _sync(bytes memory params) internal; +``` + +### _mint + + +```solidity +function _mint(bytes memory params) internal; +``` + +### _clear + + +```solidity +function _clear(bytes memory params) internal; +``` + +### _assertBalanceEquals + + +```solidity +function _assertBalanceEquals(bytes memory params) internal view; +``` + +### _assertReservesEquals + + +```solidity +function _assertReservesEquals(bytes memory params) internal view; +``` + +### _assertDeltaEquals + + +```solidity +function _assertDeltaEquals(bytes memory params) internal view; +``` + +### _assertNonzeroDeltaCountEquals + + +```solidity +function _assertNonzeroDeltaCountEquals(bytes memory params) internal view; +``` + +### _transferFrom + + +```solidity +function _transferFrom(bytes memory params) internal; +``` + +## Errors +### ActionNotSupported + +```solidity +error ActionNotSupported(); +``` + +### CheckParameters + +```solidity +error CheckParameters(); +``` + diff --git a/docs/contracts/v4/reference/core/test/BaseTestHooks.md b/docs/contracts/v4/reference/core/test/BaseTestHooks.md new file mode 100644 index 000000000..2e8e924e0 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/BaseTestHooks.md @@ -0,0 +1,112 @@ +# BaseTestHooks +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/BaseTestHooks.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IHooks](contracts/v4/reference/core/interfaces/IHooks.md) + + +## Functions +### beforeInitialize + + +```solidity +function beforeInitialize(address, PoolKey calldata, uint160, bytes calldata) external virtual returns (bytes4); +``` + +### afterInitialize + + +```solidity +function afterInitialize(address, PoolKey calldata, uint160, int24, bytes calldata) external virtual returns (bytes4); +``` + +### beforeAddLiquidity + + +```solidity +function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata) + external + virtual + returns (bytes4); +``` + +### afterAddLiquidity + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata +) external virtual returns (bytes4, BalanceDelta); +``` + +### beforeRemoveLiquidity + + +```solidity +function beforeRemoveLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata) + external + virtual + returns (bytes4); +``` + +### afterRemoveLiquidity + + +```solidity +function afterRemoveLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata +) external virtual returns (bytes4, BalanceDelta); +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, bytes calldata) + external + virtual + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### afterSwap + + +```solidity +function afterSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata) + external + virtual + returns (bytes4, int128); +``` + +### beforeDonate + + +```solidity +function beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) external virtual returns (bytes4); +``` + +### afterDonate + + +```solidity +function afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) external virtual returns (bytes4); +``` + +## Errors +### HookNotImplemented + +```solidity +error HookNotImplemented(); +``` + diff --git a/docs/contracts/v4/reference/core/test/CurrencyTest.md b/docs/contracts/v4/reference/core/test/CurrencyTest.md new file mode 100644 index 000000000..c3119de34 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/CurrencyTest.md @@ -0,0 +1,48 @@ +# CurrencyTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/CurrencyTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### transfer + + +```solidity +function transfer(Currency currency, address to, uint256 amount) external; +``` + +### balanceOfSelf + + +```solidity +function balanceOfSelf(Currency currency) external view returns (uint256); +``` + +### balanceOf + + +```solidity +function balanceOf(Currency currency, address owner) external view returns (uint256); +``` + +### isAddressZero + + +```solidity +function isAddressZero(Currency currency) external pure returns (bool); +``` + +### toId + + +```solidity +function toId(Currency currency) external pure returns (uint256); +``` + +### fromId + + +```solidity +function fromId(uint256 id) external pure returns (Currency); +``` + diff --git a/docs/contracts/v4/reference/core/test/CustomCurveHook.md b/docs/contracts/v4/reference/core/test/CustomCurveHook.md new file mode 100644 index 000000000..873aee153 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/CustomCurveHook.md @@ -0,0 +1,73 @@ +# CustomCurveHook +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/CustomCurveHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[BaseTestHooks](contracts/v4/reference/core/test/BaseTestHooks.md) + + +## State Variables +### manager + +```solidity +IPoolManager immutable manager; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager); +``` + +### onlyPoolManager + + +```solidity +modifier onlyPoolManager(); +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata) + external + override + onlyPoolManager + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### afterAddLiquidity + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata +) external view override onlyPoolManager returns (bytes4, BalanceDelta); +``` + +### _getInputOutputAndAmount + + +```solidity +function _getInputOutputAndAmount(PoolKey calldata key, IPoolManager.SwapParams calldata params) + internal + pure + returns (Currency input, Currency output, uint256 amount); +``` + +## Errors +### AddLiquidityDirectToHook + +```solidity +error AddLiquidityDirectToHook(); +``` + diff --git a/docs/contracts/v4/reference/core/test/DeltaReturningHook.md b/docs/contracts/v4/reference/core/test/DeltaReturningHook.md new file mode 100644 index 000000000..683df0a79 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/DeltaReturningHook.md @@ -0,0 +1,112 @@ +# DeltaReturningHook +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/DeltaReturningHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[BaseTestHooks](contracts/v4/reference/core/test/BaseTestHooks.md) + + +## State Variables +### manager + +```solidity +IPoolManager immutable manager; +``` + + +### deltaSpecified + +```solidity +int128 deltaSpecified; +``` + + +### deltaUnspecifiedBeforeSwap + +```solidity +int128 deltaUnspecifiedBeforeSwap; +``` + + +### deltaUnspecifiedAfterSwap + +```solidity +int128 deltaUnspecifiedAfterSwap; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager); +``` + +### onlyPoolManager + + +```solidity +modifier onlyPoolManager(); +``` + +### setDeltaSpecified + + +```solidity +function setDeltaSpecified(int128 delta) external; +``` + +### setDeltaUnspecifiedBeforeSwap + + +```solidity +function setDeltaUnspecifiedBeforeSwap(int128 delta) external; +``` + +### setDeltaUnspecifiedAfterSwap + + +```solidity +function setDeltaUnspecifiedAfterSwap(int128 delta) external; +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata) + external + override + onlyPoolManager + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### afterSwap + + +```solidity +function afterSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, BalanceDelta, bytes calldata) + external + override + onlyPoolManager + returns (bytes4, int128); +``` + +### _sortCurrencies + + +```solidity +function _sortCurrencies(PoolKey calldata key, IPoolManager.SwapParams calldata params) + internal + pure + returns (Currency specified, Currency unspecified); +``` + +### _settleOrTake + + +```solidity +function _settleOrTake(Currency currency, int128 delta) internal; +``` + diff --git a/docs/contracts/v4/reference/core/test/DynamicFeesTestHook.md b/docs/contracts/v4/reference/core/test/DynamicFeesTestHook.md new file mode 100644 index 000000000..0396f4846 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/DynamicFeesTestHook.md @@ -0,0 +1,65 @@ +# DynamicFeesTestHook +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/DynamicFeesTestHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[BaseTestHooks](contracts/v4/reference/core/test/BaseTestHooks.md) + + +## State Variables +### fee + +```solidity +uint24 internal fee; +``` + + +### manager + +```solidity +IPoolManager manager; +``` + + +## Functions +### setManager + + +```solidity +function setManager(IPoolManager _manager) external; +``` + +### setFee + + +```solidity +function setFee(uint24 _fee) external; +``` + +### afterInitialize + + +```solidity +function afterInitialize(address, PoolKey calldata key, uint160, int24, bytes calldata) + external + override + returns (bytes4); +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata) + external + override + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### forcePoolFeeUpdate + + +```solidity +function forcePoolFeeUpdate(PoolKey calldata _key, uint24 _fee) external; +``` + diff --git a/docs/contracts/v4/reference/core/test/DynamicReturnFeeTestHook.md b/docs/contracts/v4/reference/core/test/DynamicReturnFeeTestHook.md new file mode 100644 index 000000000..54175aeda --- /dev/null +++ b/docs/contracts/v4/reference/core/test/DynamicReturnFeeTestHook.md @@ -0,0 +1,56 @@ +# DynamicReturnFeeTestHook +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/DynamicReturnFeeTestHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[BaseTestHooks](contracts/v4/reference/core/test/BaseTestHooks.md) + + +## State Variables +### fee + +```solidity +uint24 internal fee; +``` + + +### manager + +```solidity +IPoolManager manager; +``` + + +## Functions +### setManager + + +```solidity +function setManager(IPoolManager _manager) external; +``` + +### setFee + + +```solidity +function setFee(uint24 _fee) external; +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, bytes calldata) + external + view + override + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### forcePoolFeeUpdate + + +```solidity +function forcePoolFeeUpdate(PoolKey calldata _key, uint24 _fee) external; +``` + diff --git a/docs/contracts/v4/reference/core/test/EmptyRevertContract.md b/docs/contracts/v4/reference/core/test/EmptyRevertContract.md new file mode 100644 index 000000000..4debb6afe --- /dev/null +++ b/docs/contracts/v4/reference/core/test/EmptyRevertContract.md @@ -0,0 +1,13 @@ +# EmptyRevertContract +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/EmptyRevertContract.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### fallback + + +```solidity +fallback() external; +``` + diff --git a/docs/contracts/v4/reference/core/test/EmptyTestHooks.md b/docs/contracts/v4/reference/core/test/EmptyTestHooks.md new file mode 100644 index 000000000..45d387d19 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/EmptyTestHooks.md @@ -0,0 +1,128 @@ +# EmptyTestHooks +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/EmptyTestHooks.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IHooks](contracts/v4/reference/core/interfaces/IHooks.md) + + +## Functions +### constructor + + +```solidity +constructor(); +``` + +### beforeInitialize + + +```solidity +function beforeInitialize(address, PoolKey calldata, uint160, bytes calldata) external pure override returns (bytes4); +``` + +### afterInitialize + + +```solidity +function afterInitialize(address, PoolKey calldata, uint160, int24, bytes calldata) + external + pure + override + returns (bytes4); +``` + +### beforeAddLiquidity + + +```solidity +function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata) + external + pure + override + returns (bytes4); +``` + +### afterAddLiquidity + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata +) external pure override returns (bytes4, BalanceDelta); +``` + +### beforeRemoveLiquidity + + +```solidity +function beforeRemoveLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata) + external + pure + override + returns (bytes4); +``` + +### afterRemoveLiquidity + + +```solidity +function afterRemoveLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata +) external pure override returns (bytes4, BalanceDelta); +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, bytes calldata) + external + pure + override + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### afterSwap + + +```solidity +function afterSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata) + external + pure + override + returns (bytes4, int128); +``` + +### beforeDonate + + +```solidity +function beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) + external + pure + override + returns (bytes4); +``` + +### afterDonate + + +```solidity +function afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) + external + pure + override + returns (bytes4); +``` + diff --git a/docs/contracts/v4/reference/core/test/FeeTakingHook.md b/docs/contracts/v4/reference/core/test/FeeTakingHook.md new file mode 100644 index 000000000..14753a00c --- /dev/null +++ b/docs/contracts/v4/reference/core/test/FeeTakingHook.md @@ -0,0 +1,93 @@ +# FeeTakingHook +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/FeeTakingHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[BaseTestHooks](contracts/v4/reference/core/test/BaseTestHooks.md) + + +## State Variables +### manager + +```solidity +IPoolManager immutable manager; +``` + + +### LIQUIDITY_FEE + +```solidity +uint128 public constant LIQUIDITY_FEE = 543; +``` + + +### SWAP_FEE_BIPS + +```solidity +uint128 public constant SWAP_FEE_BIPS = 123; +``` + + +### TOTAL_BIPS + +```solidity +uint128 public constant TOTAL_BIPS = 10000; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager); +``` + +### onlyPoolManager + + +```solidity +modifier onlyPoolManager(); +``` + +### afterSwap + + +```solidity +function afterSwap( + address, + PoolKey calldata key, + IPoolManager.SwapParams calldata params, + BalanceDelta delta, + bytes calldata +) external override onlyPoolManager returns (bytes4, int128); +``` + +### afterRemoveLiquidity + + +```solidity +function afterRemoveLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta delta, + BalanceDelta, + bytes calldata +) external override onlyPoolManager returns (bytes4, BalanceDelta); +``` + +### afterAddLiquidity + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta delta, + BalanceDelta, + bytes calldata +) external override onlyPoolManager returns (bytes4, BalanceDelta); +``` + diff --git a/docs/contracts/v4/reference/core/test/Fuzzers.md b/docs/contracts/v4/reference/core/test/Fuzzers.md new file mode 100644 index 000000000..cd688d408 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/Fuzzers.md @@ -0,0 +1,130 @@ +# Fuzzers +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/Fuzzers.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +StdUtils + + +## State Variables +### _vm + +```solidity +Vm internal constant _vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); +``` + + +## Functions +### boundLiquidityDelta + + +```solidity +function boundLiquidityDelta(PoolKey memory key, int256 liquidityDeltaUnbounded, int256 liquidityMaxByAmount) + internal + pure + returns (int256); +``` + +### boundLiquidityDeltaTightly + + +```solidity +function boundLiquidityDeltaTightly( + PoolKey memory key, + int256 liquidityDeltaUnbounded, + int256 liquidityMaxByAmount, + uint256 maxPositions +) internal pure returns (int256); +``` + +### getLiquidityDeltaFromAmounts + + +```solidity +function getLiquidityDeltaFromAmounts(int24 tickLower, int24 tickUpper, uint160 sqrtPriceX96) + internal + pure + returns (int256); +``` + +### boundTicks + + +```solidity +function boundTicks(int24 tickLower, int24 tickUpper, int24 tickSpacing) internal pure returns (int24, int24); +``` + +### boundTicks + + +```solidity +function boundTicks(PoolKey memory key, int24 tickLower, int24 tickUpper) internal pure returns (int24, int24); +``` + +### createRandomSqrtPriceX96 + + +```solidity +function createRandomSqrtPriceX96(int24 tickSpacing, int256 seed) internal pure returns (uint160); +``` + +### createFuzzyLiquidityParams + +*Obtain fuzzed and bounded parameters for creating liquidity* + + +```solidity +function createFuzzyLiquidityParams( + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + uint160 sqrtPriceX96 +) internal pure returns (IPoolManager.ModifyLiquidityParams memory result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool key| +|`params`|`IPoolManager.ModifyLiquidityParams`|IPoolManager.ModifyLiquidityParams Note that these parameters are unbounded| +|`sqrtPriceX96`|`uint160`|The current sqrt price| + + +### createFuzzyLiquidityParamsWithTightBound + + +```solidity +function createFuzzyLiquidityParamsWithTightBound( + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + uint160 sqrtPriceX96, + uint256 maxPositions +) internal pure returns (IPoolManager.ModifyLiquidityParams memory result); +``` + +### createFuzzyLiquidity + + +```solidity +function createFuzzyLiquidity( + PoolModifyLiquidityTest modifyLiquidityRouter, + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + uint160 sqrtPriceX96, + bytes memory hookData +) internal returns (IPoolManager.ModifyLiquidityParams memory result, BalanceDelta delta); +``` + +### createFuzzyLiquidityWithTightBound + + +```solidity +function createFuzzyLiquidityWithTightBound( + PoolModifyLiquidityTest modifyLiquidityRouter, + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + uint160 sqrtPriceX96, + bytes memory hookData, + uint256 maxPositions +) internal returns (IPoolManager.ModifyLiquidityParams memory result, BalanceDelta delta); +``` + diff --git a/docs/contracts/v4/reference/core/test/HooksTest.md b/docs/contracts/v4/reference/core/test/HooksTest.md new file mode 100644 index 000000000..b2ad68fa2 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/HooksTest.md @@ -0,0 +1,107 @@ +# HooksTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/HooksTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### validateHookPermissions + + +```solidity +function validateHookPermissions(address hookAddress, Hooks.Permissions calldata params) external pure; +``` + +### isValidHookAddress + + +```solidity +function isValidHookAddress(address hookAddress, uint24 fee) external pure returns (bool); +``` + +### shouldCallBeforeInitialize + + +```solidity +function shouldCallBeforeInitialize(address hookAddress) external pure returns (bool); +``` + +### shouldCallAfterInitialize + + +```solidity +function shouldCallAfterInitialize(address hookAddress) external pure returns (bool); +``` + +### shouldCallBeforeSwap + + +```solidity +function shouldCallBeforeSwap(address hookAddress) external pure returns (bool); +``` + +### shouldCallAfterSwap + + +```solidity +function shouldCallAfterSwap(address hookAddress) external pure returns (bool); +``` + +### shouldCallBeforeAddLiquidity + + +```solidity +function shouldCallBeforeAddLiquidity(address hookAddress) external pure returns (bool); +``` + +### shouldCallAfterAddLiquidity + + +```solidity +function shouldCallAfterAddLiquidity(address hookAddress) external pure returns (bool); +``` + +### shouldCallBeforeRemoveLiquidity + + +```solidity +function shouldCallBeforeRemoveLiquidity(address hookAddress) external pure returns (bool); +``` + +### shouldCallAfterRemoveLiquidity + + +```solidity +function shouldCallAfterRemoveLiquidity(address hookAddress) external pure returns (bool); +``` + +### shouldCallBeforeDonate + + +```solidity +function shouldCallBeforeDonate(address hookAddress) external pure returns (bool); +``` + +### shouldCallAfterDonate + + +```solidity +function shouldCallAfterDonate(address hookAddress) external pure returns (bool); +``` + +### getGasCostOfShouldCall + + +```solidity +function getGasCostOfShouldCall(address hookAddress) external view returns (uint256); +``` + +### getGasCostOfValidateHookAddress + + +```solidity +function getGasCostOfValidateHookAddress(address hookAddress, Hooks.Permissions calldata params) + external + view + returns (uint256); +``` + diff --git a/docs/contracts/v4/reference/core/test/LPFeeTakingHook.md b/docs/contracts/v4/reference/core/test/LPFeeTakingHook.md new file mode 100644 index 000000000..3fb4560dc --- /dev/null +++ b/docs/contracts/v4/reference/core/test/LPFeeTakingHook.md @@ -0,0 +1,63 @@ +# LPFeeTakingHook +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/LPFeeTakingHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[BaseTestHooks](contracts/v4/reference/core/test/BaseTestHooks.md) + +a hook that takes all of the LP fee revenue + +*an example test hook to validate the data is provided correctly* + + +## State Variables +### manager + +```solidity +IPoolManager immutable manager; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager); +``` + +### onlyPoolManager + + +```solidity +modifier onlyPoolManager(); +``` + +### afterRemoveLiquidity + + +```solidity +function afterRemoveLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta feeDelta, + bytes calldata +) external override onlyPoolManager returns (bytes4, BalanceDelta); +``` + +### afterAddLiquidity + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta feeDelta, + bytes calldata +) external override onlyPoolManager returns (bytes4, BalanceDelta); +``` + diff --git a/docs/contracts/v4/reference/core/test/LiquidityMathTest.md b/docs/contracts/v4/reference/core/test/LiquidityMathTest.md new file mode 100644 index 000000000..9b1233578 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/LiquidityMathTest.md @@ -0,0 +1,13 @@ +# LiquidityMathTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/LiquidityMathTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### addDelta + + +```solidity +function addDelta(uint128 x, int128 y) external pure returns (uint128 z); +``` + diff --git a/docs/contracts/v4/reference/core/test/MockContract.md b/docs/contracts/v4/reference/core/test/MockContract.md new file mode 100644 index 000000000..f71b022b0 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/MockContract.md @@ -0,0 +1,105 @@ +# MockContract +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/MockContract.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +Proxy + +Mock contract that tracks the number of calls to various functions by selector + +*allows for proxying to an implementation contract +if real logic or return values are needed* + + +## State Variables +### calls + +```solidity +mapping(bytes32 => uint256) public calls; +``` + + +### callParams + +```solidity +mapping(bytes32 => mapping(bytes => uint256)) public callParams; +``` + + +### impl +If set, delegatecall to implementation after tracking call + + +```solidity +address internal impl; +``` + + +## Functions +### timesCalledSelector + + +```solidity +function timesCalledSelector(bytes32 selector) public view returns (uint256); +``` + +### timesCalled + + +```solidity +function timesCalled(string calldata fnSig) public view returns (uint256); +``` + +### calledWithSelector + + +```solidity +function calledWithSelector(bytes32 selector, bytes calldata params) public view returns (bool); +``` + +### calledWith + + +```solidity +function calledWith(string calldata fnSig, bytes calldata params) public view returns (bool); +``` + +### _implementation + +exposes implementation contract address + + +```solidity +function _implementation() internal view override returns (address); +``` + +### setImplementation + + +```solidity +function setImplementation(address _impl) external; +``` + +### _beforeFallback + +Captures calls by selector + + +```solidity +function _beforeFallback() internal; +``` + +### _fallback + + +```solidity +function _fallback() internal override; +``` + +### receive + + +```solidity +receive() external payable; +``` + diff --git a/docs/contracts/v4/reference/core/test/MockERC6909Claims.md b/docs/contracts/v4/reference/core/test/MockERC6909Claims.md new file mode 100644 index 000000000..189fc85bc --- /dev/null +++ b/docs/contracts/v4/reference/core/test/MockERC6909Claims.md @@ -0,0 +1,38 @@ +# MockERC6909Claims +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/MockERC6909Claims.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[ERC6909Claims](contracts/v4/reference/core/ERC6909Claims.md) + +Mock contract for testing ERC6909Claims + + +## Functions +### mint + +mocked mint logic + + +```solidity +function mint(address to, uint256 id, uint256 amount) public; +``` + +### burn + +mocked burn logic + + +```solidity +function burn(uint256 id, uint256 amount) public; +``` + +### burnFrom + +mocked burn logic without checking sender allowance + + +```solidity +function burnFrom(address from, uint256 id, uint256 amount) public; +``` + diff --git a/docs/contracts/v4/reference/core/test/MockHooks.md b/docs/contracts/v4/reference/core/test/MockHooks.md new file mode 100644 index 000000000..544b7e7f5 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/MockHooks.md @@ -0,0 +1,220 @@ +# MockHooks +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/MockHooks.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IHooks](contracts/v4/reference/core/interfaces/IHooks.md) + + +## State Variables +### beforeInitializeData + +```solidity +bytes public beforeInitializeData; +``` + + +### afterInitializeData + +```solidity +bytes public afterInitializeData; +``` + + +### beforeAddLiquidityData + +```solidity +bytes public beforeAddLiquidityData; +``` + + +### afterAddLiquidityData + +```solidity +bytes public afterAddLiquidityData; +``` + + +### beforeRemoveLiquidityData + +```solidity +bytes public beforeRemoveLiquidityData; +``` + + +### afterRemoveLiquidityData + +```solidity +bytes public afterRemoveLiquidityData; +``` + + +### beforeSwapData + +```solidity +bytes public beforeSwapData; +``` + + +### afterSwapData + +```solidity +bytes public afterSwapData; +``` + + +### beforeDonateData + +```solidity +bytes public beforeDonateData; +``` + + +### afterDonateData + +```solidity +bytes public afterDonateData; +``` + + +### returnValues + +```solidity +mapping(bytes4 => bytes4) public returnValues; +``` + + +### lpFees + +```solidity +mapping(PoolId => uint16) public lpFees; +``` + + +## Functions +### beforeInitialize + + +```solidity +function beforeInitialize(address, PoolKey calldata, uint160, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### afterInitialize + + +```solidity +function afterInitialize(address, PoolKey calldata, uint160, int24, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### beforeAddLiquidity + + +```solidity +function beforeAddLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + bytes calldata hookData +) external override returns (bytes4); +``` + +### afterAddLiquidity + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata hookData +) external override returns (bytes4, BalanceDelta); +``` + +### beforeRemoveLiquidity + + +```solidity +function beforeRemoveLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + bytes calldata hookData +) external override returns (bytes4); +``` + +### afterRemoveLiquidity + + +```solidity +function afterRemoveLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata hookData +) external override returns (bytes4, BalanceDelta); +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, bytes calldata hookData) + external + override + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### afterSwap + + +```solidity +function afterSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata hookData) + external + override + returns (bytes4, int128); +``` + +### beforeDonate + + +```solidity +function beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### afterDonate + + +```solidity +function afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### setReturnValue + + +```solidity +function setReturnValue(bytes4 key, bytes4 value) external; +``` + +### setlpFee + + +```solidity +function setlpFee(PoolKey calldata key, uint16 value) external; +``` + diff --git a/docs/contracts/v4/reference/core/test/NativeERC20.md b/docs/contracts/v4/reference/core/test/NativeERC20.md new file mode 100644 index 000000000..2a7bf1d3f --- /dev/null +++ b/docs/contracts/v4/reference/core/test/NativeERC20.md @@ -0,0 +1,88 @@ +# NativeERC20 +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/NativeERC20.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +Test + +*This token contract simulates the ERC20 representation of a native token where on `transfer` and `transferFrom` the native balances are modified using a precompile* + + +## State Variables +### name + +```solidity +string public name = "NativeERC20"; +``` + + +### symbol + +```solidity +string public symbol = "NERC20"; +``` + + +### decimals + +```solidity +uint8 public decimals = 18; +``` + + +### allowance + +```solidity +mapping(address => mapping(address => uint256)) public allowance; +``` + + +## Functions +### totalSupply + + +```solidity +function totalSupply() public view returns (uint256); +``` + +### approve + + +```solidity +function approve(address guy, uint256 wad) public returns (bool); +``` + +### transfer + + +```solidity +function transfer(address dst, uint256 wad) public returns (bool); +``` + +### transferFrom + + +```solidity +function transferFrom(address src, address dst, uint256 wad) public returns (bool); +``` + +### balanceOf + + +```solidity +function balanceOf(address account) external view returns (uint256); +``` + +## Events +### Approval + +```solidity +event Approval(address indexed src, address indexed guy, uint256 wad); +``` + +### Transfer + +```solidity +event Transfer(address indexed src, address indexed dst, uint256 wad); +``` + diff --git a/docs/contracts/v4/reference/core/test/NoDelegateCallTest.md b/docs/contracts/v4/reference/core/test/NoDelegateCallTest.md new file mode 100644 index 000000000..2113d21f6 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/NoDelegateCallTest.md @@ -0,0 +1,51 @@ +# NoDelegateCallTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/NoDelegateCallTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[NoDelegateCall](contracts/v4/reference/core/NoDelegateCall.md) + + +## Functions +### canBeDelegateCalled + + +```solidity +function canBeDelegateCalled() public view returns (uint256); +``` + +### cannotBeDelegateCalled + + +```solidity +function cannotBeDelegateCalled() public view noDelegateCall returns (uint256); +``` + +### getGasCostOfCanBeDelegateCalled + + +```solidity +function getGasCostOfCanBeDelegateCalled() external view returns (uint256); +``` + +### getGasCostOfCannotBeDelegateCalled + + +```solidity +function getGasCostOfCannotBeDelegateCalled() external view returns (uint256); +``` + +### callsIntoNoDelegateCallFunction + + +```solidity +function callsIntoNoDelegateCallFunction() external view; +``` + +### noDelegateCallPrivate + + +```solidity +function noDelegateCallPrivate() private view noDelegateCall; +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolClaimsTest.md b/docs/contracts/v4/reference/core/test/PoolClaimsTest.md new file mode 100644 index 000000000..814b573d4 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolClaimsTest.md @@ -0,0 +1,54 @@ +# PoolClaimsTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolClaimsTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) PoolTestBase(_manager); +``` + +### deposit + +Convert ERC20 into a claimable 6909 + + +```solidity +function deposit(Currency currency, address user, uint256 amount) external payable; +``` + +### withdraw + +Redeem claimable 6909 for ERC20 + + +```solidity +function withdraw(Currency currency, address user, uint256 amount) external payable; +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata rawData) external returns (bytes memory); +``` + +## Structs +### CallbackData + +```solidity +struct CallbackData { + address sender; + address user; + Currency currency; + uint256 amount; + bool deposit; +} +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolDonateTest.md b/docs/contracts/v4/reference/core/test/PoolDonateTest.md new file mode 100644 index 000000000..6711be4fd --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolDonateTest.md @@ -0,0 +1,46 @@ +# PoolDonateTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolDonateTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) PoolTestBase(_manager); +``` + +### donate + + +```solidity +function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes memory hookData) + external + payable + returns (BalanceDelta delta); +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata rawData) external returns (bytes memory); +``` + +## Structs +### CallbackData + +```solidity +struct CallbackData { + address sender; + PoolKey key; + uint256 amount0; + uint256 amount1; + bytes hookData; +} +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolEmptyUnlockTest.md b/docs/contracts/v4/reference/core/test/PoolEmptyUnlockTest.md new file mode 100644 index 000000000..77b16f1d4 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolEmptyUnlockTest.md @@ -0,0 +1,47 @@ +# PoolEmptyUnlockTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolEmptyUnlockTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IUnlockCallback](/src/interfaces/callback/IUnlockCallback.sol/interface.IUnlockCallback.md) + + +## State Variables +### manager + +```solidity +IPoolManager manager; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager); +``` + +### unlock + + +```solidity +function unlock() external; +``` + +### unlockCallback + +Called by the pool manager on `msg.sender` when the manager is unlocked + + +```solidity +function unlockCallback(bytes calldata) external override returns (bytes memory); +``` + +## Events +### UnlockCallback + +```solidity +event UnlockCallback(); +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolModifyLiquidityTest.md b/docs/contracts/v4/reference/core/test/PoolModifyLiquidityTest.md new file mode 100644 index 000000000..fed6cc3a5 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolModifyLiquidityTest.md @@ -0,0 +1,60 @@ +# PoolModifyLiquidityTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolModifyLiquidityTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) PoolTestBase(_manager); +``` + +### modifyLiquidity + + +```solidity +function modifyLiquidity(PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, bytes memory hookData) + external + payable + returns (BalanceDelta delta); +``` + +### modifyLiquidity + + +```solidity +function modifyLiquidity( + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + bytes memory hookData, + bool settleUsingBurn, + bool takeClaims +) public payable returns (BalanceDelta delta); +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata rawData) external returns (bytes memory); +``` + +## Structs +### CallbackData + +```solidity +struct CallbackData { + address sender; + PoolKey key; + IPoolManager.ModifyLiquidityParams params; + bytes hookData; + bool settleUsingBurn; + bool takeClaims; +} +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolModifyLiquidityTestNoChecks.md b/docs/contracts/v4/reference/core/test/PoolModifyLiquidityTestNoChecks.md new file mode 100644 index 000000000..0dfe79578 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolModifyLiquidityTestNoChecks.md @@ -0,0 +1,60 @@ +# PoolModifyLiquidityTestNoChecks +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolModifyLiquidityTestNoChecks.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) PoolTestBase(_manager); +``` + +### modifyLiquidity + + +```solidity +function modifyLiquidity(PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, bytes memory hookData) + external + payable + returns (BalanceDelta delta); +``` + +### modifyLiquidity + + +```solidity +function modifyLiquidity( + PoolKey memory key, + IPoolManager.ModifyLiquidityParams memory params, + bytes memory hookData, + bool settleUsingBurn, + bool takeClaims +) public payable returns (BalanceDelta delta); +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata rawData) external returns (bytes memory); +``` + +## Structs +### CallbackData + +```solidity +struct CallbackData { + address sender; + PoolKey key; + IPoolManager.ModifyLiquidityParams params; + bytes hookData; + bool settleUsingBurn; + bool takeClaims; +} +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolNestedActionsTest.md b/docs/contracts/v4/reference/core/test/PoolNestedActionsTest.md new file mode 100644 index 000000000..5e905eea8 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolNestedActionsTest.md @@ -0,0 +1,139 @@ +# NestedActionExecutor +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolNestedActionsTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +Test, [PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## State Variables +### key + +```solidity +PoolKey internal key; +``` + + +### user + +```solidity +address user; +``` + + +### ADD_LIQUIDITY_PARAMS + +```solidity +IPoolManager.ModifyLiquidityParams internal ADD_LIQUIDITY_PARAMS = + IPoolManager.ModifyLiquidityParams({tickLower: -120, tickUpper: 120, liquidityDelta: 1e18, salt: 0}); +``` + + +### REMOVE_LIQUIDITY_PARAMS + +```solidity +IPoolManager.ModifyLiquidityParams internal REMOVE_LIQUIDITY_PARAMS = + IPoolManager.ModifyLiquidityParams({tickLower: -120, tickUpper: 120, liquidityDelta: -1e18, salt: 0}); +``` + + +### SWAP_PARAMS + +```solidity +IPoolManager.SwapParams internal SWAP_PARAMS = + IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: Constants.SQRT_PRICE_1_2}); +``` + + +### DONATE_AMOUNT0 + +```solidity +uint256 internal DONATE_AMOUNT0 = 12345e6; +``` + + +### DONATE_AMOUNT1 + +```solidity +uint256 internal DONATE_AMOUNT1 = 98765e4; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager, address _user) PoolTestBase(_manager); +``` + +### setKey + + +```solidity +function setKey(PoolKey memory _key) external; +``` + +### execute + + +```solidity +function execute(Action[] memory actions) public; +``` + +### _nestedUnlock + + +```solidity +function _nestedUnlock() internal; +``` + +### _swap + + +```solidity +function _swap(address caller) internal; +``` + +### _addLiquidity + + +```solidity +function _addLiquidity(address caller) internal; +``` + +### _removeLiquidity + + +```solidity +function _removeLiquidity(address caller) internal; +``` + +### _donate + + +```solidity +function _donate(address caller) internal; +``` + +### _initialize + + +```solidity +function _initialize() internal; +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata) external pure override returns (bytes memory); +``` + +## Errors +### KeyNotSet + +```solidity +error KeyNotSet(); +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolSwapTest.md b/docs/contracts/v4/reference/core/test/PoolSwapTest.md new file mode 100644 index 000000000..79dbc23c9 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolSwapTest.md @@ -0,0 +1,64 @@ +# PoolSwapTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolSwapTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) PoolTestBase(_manager); +``` + +### swap + + +```solidity +function swap( + PoolKey memory key, + IPoolManager.SwapParams memory params, + TestSettings memory testSettings, + bytes memory hookData +) external payable returns (BalanceDelta delta); +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata rawData) external returns (bytes memory); +``` + +## Errors +### NoSwapOccurred + +```solidity +error NoSwapOccurred(); +``` + +## Structs +### CallbackData + +```solidity +struct CallbackData { + address sender; + TestSettings testSettings; + PoolKey key; + IPoolManager.SwapParams params; + bytes hookData; +} +``` + +### TestSettings + +```solidity +struct TestSettings { + bool takeClaims; + bool settleUsingBurn; +} +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolTakeTest.md b/docs/contracts/v4/reference/core/test/PoolTakeTest.md new file mode 100644 index 000000000..c1fc3522b --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolTakeTest.md @@ -0,0 +1,49 @@ +# PoolTakeTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolTakeTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) PoolTestBase(_manager); +``` + +### take + + +```solidity +function take(PoolKey memory key, uint256 amount0, uint256 amount1) external payable; +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata rawData) external returns (bytes memory); +``` + +### _testTake + + +```solidity +function _testTake(Currency currency, address sender, uint256 amount) internal; +``` + +## Structs +### CallbackData + +```solidity +struct CallbackData { + address sender; + PoolKey key; + uint256 amount0; + uint256 amount1; +} +``` + diff --git a/docs/contracts/v4/reference/core/test/PoolTestBase.md b/docs/contracts/v4/reference/core/test/PoolTestBase.md new file mode 100644 index 000000000..d08f9b757 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/PoolTestBase.md @@ -0,0 +1,34 @@ +# PoolTestBase +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/PoolTestBase.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IUnlockCallback](/src/interfaces/callback/IUnlockCallback.sol/interface.IUnlockCallback.md) + + +## State Variables +### manager + +```solidity +IPoolManager public immutable manager; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager); +``` + +### _fetchBalances + + +```solidity +function _fetchBalances(Currency currency, address user, address deltaHolder) + internal + view + returns (uint256 userBalance, uint256 poolBalance, int256 delta); +``` + diff --git a/docs/contracts/v4/reference/core/test/ProtocolFeeControllerTest.md b/docs/contracts/v4/reference/core/test/ProtocolFeeControllerTest.md new file mode 100644 index 000000000..ca6c6cab0 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/ProtocolFeeControllerTest.md @@ -0,0 +1,18 @@ +# RevertingProtocolFeeControllerTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/ProtocolFeeControllerTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IProtocolFeeController](contracts/v4/reference/core/interfaces/IProtocolFeeController.md) + +Reverts on call + + +## Functions +### protocolFeeForPool + + +```solidity +function protocolFeeForPool(PoolKey memory) external pure returns (uint24); +``` + diff --git a/docs/contracts/v4/reference/core/test/ProtocolFeesImplementation.md b/docs/contracts/v4/reference/core/test/ProtocolFeesImplementation.md new file mode 100644 index 000000000..9b6fe3366 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/ProtocolFeesImplementation.md @@ -0,0 +1,66 @@ +# ProtocolFeesImplementation +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/ProtocolFeesImplementation.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[ProtocolFees](contracts/v4/reference/core/ProtocolFees.md) + + +## State Variables +### _pools + +```solidity +mapping(PoolId id => Pool.State) internal _pools; +``` + + +### isUnlocked + +```solidity +bool internal isUnlocked; +``` + + +## Functions +### setPrice + + +```solidity +function setPrice(PoolKey memory key, uint160 sqrtPriceX96) public; +``` + +### _getPool + + +```solidity +function _getPool(PoolId id) internal view override returns (Pool.State storage); +``` + +### setIsUnlocked + + +```solidity +function setIsUnlocked(bool newValue) public; +``` + +### _isUnlocked + + +```solidity +function _isUnlocked() internal view override returns (bool); +``` + +### fetchProtocolFee + + +```solidity +function fetchProtocolFee(PoolKey memory key) public returns (uint24); +``` + +### updateProtocolFees + + +```solidity +function updateProtocolFees(Currency currency, uint256 amount) public; +``` + diff --git a/docs/contracts/v4/reference/core/test/ProxyPoolManager.md b/docs/contracts/v4/reference/core/test/ProxyPoolManager.md new file mode 100644 index 000000000..89e430fa3 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/ProxyPoolManager.md @@ -0,0 +1,368 @@ +# ProxyPoolManager +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/ProxyPoolManager.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IPoolManager](contracts/v4/reference/core/interfaces/IPoolManager.md), [ProtocolFees](contracts/v4/reference/core/ProtocolFees.md), [NoDelegateCall](contracts/v4/reference/core/NoDelegateCall.md), [ERC6909Claims](contracts/v4/reference/core/ERC6909Claims.md), [Extsload](contracts/v4/reference/core/Extsload.md), [Exttload](contracts/v4/reference/core/Exttload.md) + +A proxy pool manager that delegates calls to the real/delegate pool manager + + +## State Variables +### MAX_TICK_SPACING + +```solidity +int24 private constant MAX_TICK_SPACING = TickMath.MAX_TICK_SPACING; +``` + + +### MIN_TICK_SPACING + +```solidity +int24 private constant MIN_TICK_SPACING = TickMath.MIN_TICK_SPACING; +``` + + +### _pools + +```solidity +mapping(PoolId id => Pool.State) internal _pools; +``` + + +### _delegateManager + +```solidity +address internal immutable _delegateManager; +``` + + +## Functions +### constructor + + +```solidity +constructor(address delegateManager); +``` + +### onlyWhenUnlocked + +This will revert if the contract is locked + + +```solidity +modifier onlyWhenUnlocked(); +``` + +### unlock + +All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement +`IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract. + +*The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`* + + +```solidity +function unlock(bytes calldata data) external noDelegateCall returns (bytes memory result); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`result`|`bytes`|The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`| + + +### initialize + +Initialize the state for a given pool ID + +*A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee* + + +```solidity +function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData) + external + noDelegateCall + returns (int24 tick); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool key for the pool to initialize| +|`sqrtPriceX96`|`uint160`|The initial square root price| +|`hookData`|`bytes`|The data to pass through to the initialize hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tick`|`int24`|The initial tick of the pool| + + +### modifyLiquidity + +Modify the liquidity for the given pool + +*Poke by calling with a zero liquidityDelta* + + +```solidity +function modifyLiquidity(PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params, bytes calldata hookData) + external + onlyWhenUnlocked + noDelegateCall + returns (BalanceDelta callerDelta, BalanceDelta feesAccrued); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool to modify liquidity in| +|`params`|`IPoolManager.ModifyLiquidityParams`|The parameters for modifying the liquidity| +|`hookData`|`bytes`|The data to pass through to the add/removeLiquidity hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`callerDelta`|`BalanceDelta`|The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable| +|`feesAccrued`|`BalanceDelta`|The balance delta of the fees generated in the liquidity range. Returned for informational purposes| + + +### swap + +Swap against the given pool + +*Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified. +Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG +the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.* + + +```solidity +function swap(PoolKey memory key, IPoolManager.SwapParams memory params, bytes calldata hookData) + external + onlyWhenUnlocked + noDelegateCall + returns (BalanceDelta swapDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The pool to swap in| +|`params`|`IPoolManager.SwapParams`|The parameters for swapping| +|`hookData`|`bytes`|The data to pass through to the swap hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`swapDelta`|`BalanceDelta`|The balance delta of the address swapping| + + +### donate + +Donate the given currency amounts to the in-range liquidity providers of a pool + +*Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds. +Donors should keep this in mind when designing donation mechanisms.* + + +```solidity +function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData) + external + onlyWhenUnlocked + noDelegateCall + returns (BalanceDelta delta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to donate to| +|`amount0`|`uint256`|The amount of currency0 to donate| +|`amount1`|`uint256`|The amount of currency1 to donate| +|`hookData`|`bytes`|The data to pass through to the donate hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`delta`|`BalanceDelta`|BalanceDelta The delta of the caller after the donate| + + +### sync + +Writes the current ERC20 balance of the specified currency to transient storage +This is used to checkpoint balances for the manager and derive deltas for the caller. + +*This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped +for native tokens because the amount to settle is determined by the sent value. +However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle +native funds, this function can be called with the native currency to then be able to settle the native currency* + + +```solidity +function sync(Currency currency) public; +``` + +### take + +Called by the user to net out some value owed to the user + +*Can also be used as a mechanism for _free_ flash loans* + + +```solidity +function take(Currency currency, address to, uint256 amount) external onlyWhenUnlocked noDelegateCall; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|The currency to withdraw from the pool manager| +|`to`|`address`|The address to withdraw to| +|`amount`|`uint256`|The amount of currency to withdraw| + + +### settle + +Called by the user to pay what is owed + + +```solidity +function settle() external payable onlyWhenUnlocked noDelegateCall returns (uint256 paid); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`paid`|`uint256`|The amount of currency settled| + + +### settleFor + +Called by the user to pay on behalf of another address + + +```solidity +function settleFor(address recipient) external payable onlyWhenUnlocked noDelegateCall returns (uint256 paid); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`recipient`|`address`|The address to credit for the payment| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`paid`|`uint256`|The amount of currency settled| + + +### clear + +WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently. +A call to clear will zero out a positive balance WITHOUT a corresponding transfer. + +*This could be used to clear a balance that is considered dust. +Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.* + + +```solidity +function clear(Currency currency, uint256 amount) external onlyWhenUnlocked; +``` + +### mint + +Called by the user to move value into ERC6909 balance + +*The id is converted to a uint160 to correspond to a currency address +If the upper 12 bytes are not 0, they will be 0-ed out* + + +```solidity +function mint(address to, uint256 id, uint256 amount) external onlyWhenUnlocked noDelegateCall; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`to`|`address`|The address to mint the tokens to| +|`id`|`uint256`|The currency address to mint to ERC6909s, as a uint256| +|`amount`|`uint256`|The amount of currency to mint| + + +### burn + +Called by the user to move value from ERC6909 balance + +*The id is converted to a uint160 to correspond to a currency address +If the upper 12 bytes are not 0, they will be 0-ed out* + + +```solidity +function burn(address from, uint256 id, uint256 amount) external onlyWhenUnlocked noDelegateCall; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`from`|`address`|The address to burn the tokens from| +|`id`|`uint256`|The currency address to burn from ERC6909s, as a uint256| +|`amount`|`uint256`|The amount of currency to burn| + + +### updateDynamicLPFee + +Updates the pools lp fees for the a pool that has enabled dynamic lp fees. + +*A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee* + + +```solidity +function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|The key of the pool to update dynamic LP fees for| +|`newDynamicLPFee`|`uint24`|The new dynamic pool LP fee| + + +### _delegateCall + +Make a delegate call, bubble up any error or return the result + + +```solidity +function _delegateCall(address target, bytes memory data) internal returns (bytes memory result); +``` + +### _getPool + +Implementation of the _getPool function defined in ProtocolFees + + +```solidity +function _getPool(PoolId id) internal view override returns (Pool.State storage); +``` + +### _isUnlocked + +Implementation of the _isUnlocked function defined in ProtocolFees + + +```solidity +function _isUnlocked() internal view override returns (bool); +``` + diff --git a/docs/contracts/v4/reference/core/test/SkipCallsTestHook.md b/docs/contracts/v4/reference/core/test/SkipCallsTestHook.md new file mode 100644 index 000000000..7bc7eb18c --- /dev/null +++ b/docs/contracts/v4/reference/core/test/SkipCallsTestHook.md @@ -0,0 +1,186 @@ +# SkipCallsTestHook +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/SkipCallsTestHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[BaseTestHooks](contracts/v4/reference/core/test/BaseTestHooks.md), Test + + +## State Variables +### counter + +```solidity +uint256 public counter; +``` + + +### manager + +```solidity +IPoolManager manager; +``` + + +## Functions +### setManager + + +```solidity +function setManager(IPoolManager _manager) external; +``` + +### beforeInitialize + + +```solidity +function beforeInitialize(address, PoolKey calldata key, uint160 sqrtPriceX96, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### afterInitialize + + +```solidity +function afterInitialize(address, PoolKey calldata key, uint160 sqrtPriceX96, int24, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### beforeAddLiquidity + + +```solidity +function beforeAddLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + bytes calldata hookData +) external override returns (bytes4); +``` + +### afterAddLiquidity + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + BalanceDelta, + BalanceDelta, + bytes calldata hookData +) external override returns (bytes4, BalanceDelta); +``` + +### beforeRemoveLiquidity + + +```solidity +function beforeRemoveLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + bytes calldata hookData +) external override returns (bytes4); +``` + +### afterRemoveLiquidity + + +```solidity +function afterRemoveLiquidity( + address, + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams calldata params, + BalanceDelta, + BalanceDelta, + bytes calldata hookData +) external override returns (bytes4, BalanceDelta); +``` + +### beforeSwap + + +```solidity +function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata hookData) + external + override + returns (bytes4, BeforeSwapDelta, uint24); +``` + +### afterSwap + + +```solidity +function afterSwap( + address, + PoolKey calldata key, + IPoolManager.SwapParams calldata params, + BalanceDelta, + bytes calldata hookData +) external override returns (bytes4, int128); +``` + +### beforeDonate + + +```solidity +function beforeDonate(address, PoolKey calldata key, uint256 amt0, uint256 amt1, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### afterDonate + + +```solidity +function afterDonate(address, PoolKey calldata key, uint256 amt0, uint256 amt1, bytes calldata hookData) + external + override + returns (bytes4); +``` + +### _initialize + + +```solidity +function _initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData) public; +``` + +### _swap + + +```solidity +function _swap(PoolKey calldata key, IPoolManager.SwapParams memory params, bytes calldata hookData) public; +``` + +### _addLiquidity + + +```solidity +function _addLiquidity(PoolKey calldata key, IPoolManager.ModifyLiquidityParams memory params, bytes calldata hookData) + public; +``` + +### _removeLiquidity + + +```solidity +function _removeLiquidity( + PoolKey calldata key, + IPoolManager.ModifyLiquidityParams memory params, + bytes calldata hookData +) public; +``` + +### _donate + + +```solidity +function _donate(PoolKey calldata key, uint256 amt0, uint256 amt1, bytes calldata hookData) public; +``` + diff --git a/docs/contracts/v4/reference/core/test/SqrtPriceMathEchidnaTest.md b/docs/contracts/v4/reference/core/test/SqrtPriceMathEchidnaTest.md new file mode 100644 index 000000000..2cfe2cc5d --- /dev/null +++ b/docs/contracts/v4/reference/core/test/SqrtPriceMathEchidnaTest.md @@ -0,0 +1,103 @@ +# SqrtPriceMathEchidnaTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/SqrtPriceMathEchidnaTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### mulDivRoundingUpInvariants + + +```solidity +function mulDivRoundingUpInvariants(uint256 x, uint256 y, uint256 z) external pure; +``` + +### getNextSqrtPriceFromInputInvariants + + +```solidity +function getNextSqrtPriceFromInputInvariants(uint160 sqrtP, uint128 liquidity, uint256 amountIn, bool zeroForOne) + external + pure; +``` + +### getNextSqrtPriceFromOutputInvariants + + +```solidity +function getNextSqrtPriceFromOutputInvariants(uint160 sqrtP, uint128 liquidity, uint256 amountOut, bool zeroForOne) + external + pure; +``` + +### getNextSqrtPriceFromAmount0RoundingUpInvariants + + +```solidity +function getNextSqrtPriceFromAmount0RoundingUpInvariants(uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add) + external + pure; +``` + +### getNextSqrtPriceFromAmount1RoundingDownInvariants + + +```solidity +function getNextSqrtPriceFromAmount1RoundingDownInvariants( + uint160 sqrtPX96, + uint128 liquidity, + uint256 amount, + bool add +) external pure; +``` + +### getAmount0DeltaInvariants + + +```solidity +function getAmount0DeltaInvariants(uint160 sqrtP, uint160 sqrtQ, uint128 liquidity) external pure; +``` + +### getAmount0DeltaEquivalency + + +```solidity +function getAmount0DeltaEquivalency(uint160 sqrtP, uint160 sqrtQ, uint128 liquidity, bool roundUp) external pure; +``` + +### getAmount1DeltaInvariants + + +```solidity +function getAmount1DeltaInvariants(uint160 sqrtP, uint160 sqrtQ, uint128 liquidity) external pure; +``` + +### getAmount0DeltaSignedInvariants + + +```solidity +function getAmount0DeltaSignedInvariants(uint160 sqrtP, uint160 sqrtQ, int128 liquidity) external pure; +``` + +### getAmount1DeltaSignedInvariants + + +```solidity +function getAmount1DeltaSignedInvariants(uint160 sqrtP, uint160 sqrtQ, int128 liquidity) external pure; +``` + +### getOutOfRangeMintInvariants + + +```solidity +function getOutOfRangeMintInvariants(uint160 sqrtA, uint160 sqrtB, int128 liquidity) external pure; +``` + +### getInRangeMintInvariants + + +```solidity +function getInRangeMintInvariants(uint160 sqrtLower, uint160 sqrtCurrent, uint160 sqrtUpper, int128 liquidity) + external + pure; +``` + diff --git a/docs/contracts/v4/reference/core/test/SwapRouterNoChecks.md b/docs/contracts/v4/reference/core/test/SwapRouterNoChecks.md new file mode 100644 index 000000000..71492fe1d --- /dev/null +++ b/docs/contracts/v4/reference/core/test/SwapRouterNoChecks.md @@ -0,0 +1,48 @@ +# SwapRouterNoChecks +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/SwapRouterNoChecks.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[PoolTestBase](contracts/v4/reference/core/test/PoolTestBase.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) PoolTestBase(_manager); +``` + +### swap + + +```solidity +function swap(PoolKey memory key, IPoolManager.SwapParams memory params) external payable; +``` + +### unlockCallback + + +```solidity +function unlockCallback(bytes calldata rawData) external returns (bytes memory); +``` + +## Errors +### NoSwapOccurred + +```solidity +error NoSwapOccurred(); +``` + +## Structs +### CallbackData + +```solidity +struct CallbackData { + address sender; + PoolKey key; + IPoolManager.SwapParams params; +} +``` + diff --git a/docs/contracts/v4/reference/core/test/TestERC20.md b/docs/contracts/v4/reference/core/test/TestERC20.md new file mode 100644 index 000000000..ab11fad9b --- /dev/null +++ b/docs/contracts/v4/reference/core/test/TestERC20.md @@ -0,0 +1,59 @@ +# TestERC20 +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/TestERC20.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IERC20Minimal](contracts/v4/reference/core/interfaces/IERC20Minimal.md) + + +## State Variables +### balanceOf + +```solidity +mapping(address => uint256) public override balanceOf; +``` + + +### allowance + +```solidity +mapping(address => mapping(address => uint256)) public override allowance; +``` + + +## Functions +### constructor + + +```solidity +constructor(uint256 amountToMint); +``` + +### mint + + +```solidity +function mint(address to, uint256 amount) public; +``` + +### transfer + + +```solidity +function transfer(address recipient, uint256 amount) external override returns (bool); +``` + +### approve + + +```solidity +function approve(address spender, uint256 amount) external override returns (bool); +``` + +### transferFrom + + +```solidity +function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool); +``` + diff --git a/docs/contracts/v4/reference/core/test/TestInvalidERC20.md b/docs/contracts/v4/reference/core/test/TestInvalidERC20.md new file mode 100644 index 000000000..2806696ee --- /dev/null +++ b/docs/contracts/v4/reference/core/test/TestInvalidERC20.md @@ -0,0 +1,59 @@ +# TestInvalidERC20 +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/TestInvalidERC20.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IERC20Minimal](contracts/v4/reference/core/interfaces/IERC20Minimal.md) + + +## State Variables +### balanceOf + +```solidity +mapping(address => uint256) public override balanceOf; +``` + + +### allowance + +```solidity +mapping(address => mapping(address => uint256)) public override allowance; +``` + + +## Functions +### constructor + + +```solidity +constructor(uint256 amountToMint); +``` + +### mint + + +```solidity +function mint(address to, uint256 amount) public; +``` + +### transfer + + +```solidity +function transfer(address recipient, uint256 amount) external override returns (bool); +``` + +### approve + + +```solidity +function approve(address spender, uint256 amount) external override returns (bool); +``` + +### transferFrom + + +```solidity +function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool); +``` + diff --git a/docs/contracts/v4/reference/core/test/TickMathEchidnaTest.md b/docs/contracts/v4/reference/core/test/TickMathEchidnaTest.md new file mode 100644 index 000000000..c8a82b170 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/TickMathEchidnaTest.md @@ -0,0 +1,20 @@ +# TickMathEchidnaTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/TickMathEchidnaTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### checkGetSqrtPriceAtTickInvariants + + +```solidity +function checkGetSqrtPriceAtTickInvariants(int24 tick) external pure; +``` + +### checkGetTickAtSqrtPriceInvariants + + +```solidity +function checkGetTickAtSqrtPriceInvariants(uint160 price) external pure; +``` + diff --git a/docs/contracts/v4/reference/core/test/TickMathTest.md b/docs/contracts/v4/reference/core/test/TickMathTest.md new file mode 100644 index 000000000..125d626fa --- /dev/null +++ b/docs/contracts/v4/reference/core/test/TickMathTest.md @@ -0,0 +1,62 @@ +# TickMathTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/TickMathTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### getSqrtPriceAtTick + + +```solidity +function getSqrtPriceAtTick(int24 tick) external pure returns (uint160); +``` + +### getGasCostOfGetSqrtPriceAtTick + + +```solidity +function getGasCostOfGetSqrtPriceAtTick(int24 tick) external view returns (uint256); +``` + +### getTickAtSqrtPrice + + +```solidity +function getTickAtSqrtPrice(uint160 sqrtPriceX96) external pure returns (int24); +``` + +### getGasCostOfGetTickAtSqrtPrice + + +```solidity +function getGasCostOfGetTickAtSqrtPrice(uint160 sqrtPriceX96) external view returns (uint256); +``` + +### MIN_SQRT_PRICE + + +```solidity +function MIN_SQRT_PRICE() external pure returns (uint160); +``` + +### MAX_SQRT_PRICE + + +```solidity +function MAX_SQRT_PRICE() external pure returns (uint160); +``` + +### MIN_TICK + + +```solidity +function MIN_TICK() external pure returns (int24); +``` + +### MAX_TICK + + +```solidity +function MAX_TICK() external pure returns (int24); +``` + diff --git a/docs/contracts/v4/reference/core/test/TickOverflowSafetyEchidnaTest.md b/docs/contracts/v4/reference/core/test/TickOverflowSafetyEchidnaTest.md new file mode 100644 index 000000000..94994b341 --- /dev/null +++ b/docs/contracts/v4/reference/core/test/TickOverflowSafetyEchidnaTest.md @@ -0,0 +1,98 @@ +# TickOverflowSafetyEchidnaTest +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/test/TickOverflowSafetyEchidnaTest.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## State Variables +### MIN_TICK + +```solidity +int24 private constant MIN_TICK = -16; +``` + + +### MAX_TICK + +```solidity +int24 private constant MAX_TICK = 16; +``` + + +### pool + +```solidity +Pool.State private pool; +``` + + +### tick + +```solidity +int24 private tick = 0; +``` + + +### feeGrowthGlobal0X128 + +```solidity +uint256 feeGrowthGlobal0X128 = type(uint256).max / 2; +``` + + +### feeGrowthGlobal1X128 + +```solidity +uint256 feeGrowthGlobal1X128 = type(uint256).max / 2; +``` + + +### totalLiquidity + +```solidity +int256 totalLiquidity = 0; +``` + + +### totalGrowth0 + +```solidity +uint256 private totalGrowth0 = 0; +``` + + +### totalGrowth1 + +```solidity +uint256 private totalGrowth1 = 0; +``` + + +## Functions +### increaseFeeGrowthGlobal0X128 + + +```solidity +function increaseFeeGrowthGlobal0X128(uint256 amount) external; +``` + +### increaseFeeGrowthGlobal1X128 + + +```solidity +function increaseFeeGrowthGlobal1X128(uint256 amount) external; +``` + +### setPosition + + +```solidity +function setPosition(int24 tickLower, int24 tickUpper, int128 liquidityDelta) external; +``` + +### moveToTick + + +```solidity +function moveToTick(int24 target) external; +``` + diff --git a/docs/contracts/v4/reference/core/types/PoolId.md b/docs/contracts/v4/reference/core/types/PoolId.md new file mode 100644 index 000000000..75802b558 --- /dev/null +++ b/docs/contracts/v4/reference/core/types/PoolId.md @@ -0,0 +1,9 @@ +# PoolId +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/types/PoolId.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +```solidity +type PoolId is bytes32; +``` + diff --git a/docs/contracts/v4/reference/core/types/Slot0.md b/docs/contracts/v4/reference/core/types/Slot0.md new file mode 100644 index 000000000..0ad18c3b8 --- /dev/null +++ b/docs/contracts/v4/reference/core/types/Slot0.md @@ -0,0 +1,25 @@ +# Slot0 +[Git Source](https://github.com/Uniswap/v4-core/blob/1141642f8ba4665a50660886a8a8401526677045/src/types/Slot0.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +*Slot0 is a packed version of solidity structure. +Using the packaged version saves gas by not storing the structure fields in memory slots. +Layout: +24 bits empty | 24 bits lpFee | 12 bits protocolFee 1->0 | 12 bits protocolFee 0->1 | 24 bits tick | 160 bits sqrtPriceX96 +Fields in the direction from the least significant bit: +The current price +uint160 sqrtPriceX96; +The current tick +int24 tick; +Protocol fee, expressed in hundredths of a bip, upper 12 bits are for 1->0, and the lower 12 are for 0->1 +the maximum is 1000 - meaning the maximum protocol fee is 0.1% +the protocolFee is taken from the input first, then the lpFee is taken from the remaining input +uint24 protocolFee; +The current LP fee of the pool. If the pool is dynamic, this does not include the dynamic fee flag. +uint24 lpFee;* + + +```solidity +type Slot0 is bytes32; +``` + diff --git a/docs/contracts/v4/reference/periphery/PositionManager.md b/docs/contracts/v4/reference/periphery/PositionManager.md new file mode 100644 index 000000000..930bb5413 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/PositionManager.md @@ -0,0 +1,331 @@ +# PositionManager +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/PositionManager.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IPositionManager](contracts/v4/reference/periphery/interfaces/IPositionManager.md), [ERC721Permit_v4](contracts/v4/reference/periphery/base/ERC721Permit_v4.md), [PoolInitializer](contracts/v4/reference/periphery/base/PoolInitializer.md), [Multicall_v4](contracts/v4/reference/periphery/base/Multicall_v4.md), [DeltaResolver](contracts/v4/reference/periphery/base/DeltaResolver.md), [ReentrancyLock](contracts/v4/reference/periphery/base/ReentrancyLock.md), [BaseActionsRouter](contracts/v4/reference/periphery/base/BaseActionsRouter.md), [Notifier](contracts/v4/reference/periphery/base/Notifier.md), [Permit2Forwarder](contracts/v4/reference/periphery/base/Permit2Forwarder.md) + +The PositionManager (PosM) contract is responsible for creating liquidity positions on v4. +PosM mints and manages ERC721 tokens associated with each position. + + +## State Variables +### nextTokenId +Used to get the ID that will be used for the next minted liquidity position + +*The ID of the next token that will be minted. Skips 0* + + +```solidity +uint256 public nextTokenId = 1; +``` + + +### positionInfo + +```solidity +mapping(uint256 tokenId => PositionInfo info) public positionInfo; +``` + + +### poolKeys + +```solidity +mapping(bytes25 poolId => PoolKey poolKey) public poolKeys; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager, IAllowanceTransfer _permit2, uint256 _unsubscribeGasLimit) + BaseActionsRouter(_poolManager) + Permit2Forwarder(_permit2) + ERC721Permit_v4("Uniswap V4 Positions NFT", "UNI-V4-POSM") + Notifier(_unsubscribeGasLimit); +``` + +### checkDeadline + +Reverts if the deadline has passed + + +```solidity +modifier checkDeadline(uint256 deadline); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`deadline`|`uint256`|The timestamp at which the call is no longer valid, passed in by the caller| + + +### onlyIfApproved + +Reverts if the caller is not the owner or approved for the ERC721 token + +*either msg.sender or msgSender() is passed in as the caller +msgSender() should ONLY be used if this is called from within the unlockCallback, unless the codepath has reentrancy protection* + + +```solidity +modifier onlyIfApproved(address caller, uint256 tokenId) override; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`caller`|`address`|The address of the caller| +|`tokenId`|`uint256`|the unique identifier of the ERC721 token| + + +### modifyLiquidities + +Unlocks Uniswap v4 PoolManager and batches actions for modifying liquidity + +*This is the standard entrypoint for the PositionManager* + + +```solidity +function modifyLiquidities(bytes calldata unlockData, uint256 deadline) + external + payable + isNotLocked + checkDeadline(deadline); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`unlockData`|`bytes`|is an encoding of actions, and parameters for those actions| +|`deadline`|`uint256`|is the deadline for the batched actions to be executed| + + +### modifyLiquiditiesWithoutUnlock + +Batches actions for modifying liquidity without unlocking v4 PoolManager + +*This must be called by a contract that has already unlocked the v4 PoolManager* + + +```solidity +function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params) external payable isNotLocked; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`actions`|`bytes`|the actions to perform| +|`params`|`bytes[]`|the parameters to provide for the actions| + + +### msgSender + +function that returns address considered executor of the actions + +*The other context functions, _msgData and _msgValue, are not supported by this contract +In many contracts this will be the address that calls the initial entry point that calls `_executeActions` +`msg.sender` shouldn't be used, as this will be the v4 pool manager contract that calls `unlockCallback` +If using ReentrancyLock.sol, this function can return _getLocker()* + + +```solidity +function msgSender() public view override returns (address); +``` + +### _handleAction + + +```solidity +function _handleAction(uint256 action, bytes calldata params) internal virtual override; +``` + +### _increase + +*Calling increase with 0 liquidity will credit the caller with any underlying fees of the position* + + +```solidity +function _increase(uint256 tokenId, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, bytes calldata hookData) + internal + onlyIfApproved(msgSender(), tokenId); +``` + +### _decrease + +*Calling decrease with 0 liquidity will credit the caller with any underlying fees of the position* + + +```solidity +function _decrease(uint256 tokenId, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData) + internal + onlyIfApproved(msgSender(), tokenId); +``` + +### _mint + + +```solidity +function _mint( + PoolKey calldata poolKey, + int24 tickLower, + int24 tickUpper, + uint256 liquidity, + uint128 amount0Max, + uint128 amount1Max, + address owner, + bytes calldata hookData +) internal; +``` + +### _burn + +*this is overloaded with ERC721Permit_v4._burn* + + +```solidity +function _burn(uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData) + internal + onlyIfApproved(msgSender(), tokenId); +``` + +### _settlePair + + +```solidity +function _settlePair(Currency currency0, Currency currency1) internal; +``` + +### _takePair + + +```solidity +function _takePair(Currency currency0, Currency currency1, address recipient) internal; +``` + +### _close + + +```solidity +function _close(Currency currency) internal; +``` + +### _clearOrTake + +*integrators may elect to forfeit positive deltas with clear +if the forfeit amount exceeds the user-specified max, the amount is taken instead* + + +```solidity +function _clearOrTake(Currency currency, uint256 amountMax) internal; +``` + +### _sweep + +Sweeps the entire contract balance of specified currency to the recipient + + +```solidity +function _sweep(Currency currency, address to) internal; +``` + +### _modifyLiquidity + + +```solidity +function _modifyLiquidity( + PositionInfo info, + PoolKey memory poolKey, + int256 liquidityChange, + bytes32 salt, + bytes calldata hookData +) internal returns (BalanceDelta liquidityDelta, BalanceDelta feesAccrued); +``` + +### _pay + + +```solidity +function _pay(Currency currency, address payer, uint256 amount) internal override; +``` + +### _setSubscribed + +an internal helper used by Notifier + + +```solidity +function _setSubscribed(uint256 tokenId) internal override; +``` + +### _setUnsubscribed + +an internal helper used by Notifier + + +```solidity +function _setUnsubscribed(uint256 tokenId) internal override; +``` + +### transferFrom + +*overrides solmate transferFrom in case a notification to subscribers is needed* + + +```solidity +function transferFrom(address from, address to, uint256 id) public virtual override; +``` + +### getPoolAndPositionInfo + + +```solidity +function getPoolAndPositionInfo(uint256 tokenId) public view returns (PoolKey memory poolKey, PositionInfo info); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`poolKey`|`PoolKey`|the pool key of the position| +|`info`|`PositionInfo`|poolKey the pool key of the position| + + +### getPositionLiquidity + +*this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library* + + +```solidity +function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|the position's liquidity, as a liquidityAmount| + + +### _getLiquidity + + +```solidity +function _getLiquidity(uint256 tokenId, PoolKey memory poolKey, int24 tickLower, int24 tickUpper) + internal + view + returns (uint128 liquidity); +``` + diff --git a/docs/contracts/v4/reference/periphery/V4Router.md b/docs/contracts/v4/reference/periphery/V4Router.md new file mode 100644 index 000000000..6f660622f --- /dev/null +++ b/docs/contracts/v4/reference/periphery/V4Router.md @@ -0,0 +1,69 @@ +# V4Router +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/V4Router.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IV4Router](contracts/v4/reference/periphery/interfaces/IV4Router.md), [BaseActionsRouter](contracts/v4/reference/periphery/base/BaseActionsRouter.md), [DeltaResolver](contracts/v4/reference/periphery/base/DeltaResolver.md) + +Abstract contract that contains all internal logic needed for routing through Uniswap V4 pools + +*the entry point to executing actions in this contract is calling `BaseActionsRouter._executeActions` +An inheriting contract should call _executeActions at the point that they wish actions to be executed* + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager) BaseActionsRouter(_poolManager); +``` + +### _handleAction + + +```solidity +function _handleAction(uint256 action, bytes calldata params) internal override; +``` + +### _swapExactInputSingle + + +```solidity +function _swapExactInputSingle(IV4Router.ExactInputSingleParams calldata params) private; +``` + +### _swapExactInput + + +```solidity +function _swapExactInput(IV4Router.ExactInputParams calldata params) private; +``` + +### _swapExactOutputSingle + + +```solidity +function _swapExactOutputSingle(IV4Router.ExactOutputSingleParams calldata params) private; +``` + +### _swapExactOutput + + +```solidity +function _swapExactOutput(IV4Router.ExactOutputParams calldata params) private; +``` + +### _swap + + +```solidity +function _swap( + PoolKey memory poolKey, + bool zeroForOne, + int256 amountSpecified, + uint160 sqrtPriceLimitX96, + bytes calldata hookData +) private returns (int128 reciprocalAmount); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/BaseActionsRouter.md b/docs/contracts/v4/reference/periphery/base/BaseActionsRouter.md new file mode 100644 index 000000000..b62d9e0d0 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/BaseActionsRouter.md @@ -0,0 +1,111 @@ +# BaseActionsRouter +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/BaseActionsRouter.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[SafeCallback](contracts/v4/reference/periphery/base/SafeCallback.md) + +Abstract contract for performing a combination of actions on Uniswap v4. + +*Suggested uint256 action values are defined in Actions.sol, however any definition can be used* + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager) SafeCallback(_poolManager); +``` + +### _executeActions + +internal function that triggers the execution of a set of actions on v4 + +*inheriting contracts should call this function to trigger execution* + + +```solidity +function _executeActions(bytes calldata unlockData) internal; +``` + +### _unlockCallback + +function that is called by the PoolManager through the SafeCallback.unlockCallback + + +```solidity +function _unlockCallback(bytes calldata data) internal override returns (bytes memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|Abi encoding of (bytes actions, bytes[] params) where params[i] is the encoded parameters for actions[i]| + + +### _executeActionsWithoutUnlock + + +```solidity +function _executeActionsWithoutUnlock(bytes calldata actions, bytes[] calldata params) internal; +``` + +### _handleAction + +function to handle the parsing and execution of an action and its parameters + + +```solidity +function _handleAction(uint256 action, bytes calldata params) internal virtual; +``` + +### msgSender + +function that returns address considered executor of the actions + +*The other context functions, _msgData and _msgValue, are not supported by this contract +In many contracts this will be the address that calls the initial entry point that calls `_executeActions` +`msg.sender` shouldn't be used, as this will be the v4 pool manager contract that calls `unlockCallback` +If using ReentrancyLock.sol, this function can return _getLocker()* + + +```solidity +function msgSender() public view virtual returns (address); +``` + +### _mapRecipient + +Calculates the address for a action + + +```solidity +function _mapRecipient(address recipient) internal view returns (address); +``` + +### _mapPayer + +Calculates the payer for an action + + +```solidity +function _mapPayer(bool payerIsUser) internal view returns (address); +``` + +## Errors +### InputLengthMismatch +emitted when different numbers of parameters and actions are provided + + +```solidity +error InputLengthMismatch(); +``` + +### UnsupportedAction +emitted when an inheriting contract does not support an action + + +```solidity +error UnsupportedAction(uint256 action); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/BaseHook.md b/docs/contracts/v4/reference/periphery/base/BaseHook.md new file mode 100644 index 000000000..807a727d6 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/BaseHook.md @@ -0,0 +1,371 @@ +# BaseHook +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/hooks/BaseHook.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +IHooks, [SafeCallback](contracts/v4/reference/periphery/base/SafeCallback.md) + +abstract contract for hook implementations + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _manager) SafeCallback(_manager); +``` + +### selfOnly + +*Only this address may call this function* + + +```solidity +modifier selfOnly(); +``` + +### onlyValidPools + +*Only pools with hooks set to this contract may call this function* + + +```solidity +modifier onlyValidPools(IHooks hooks); +``` + +### getHookPermissions + +Returns a struct of permissions to signal which hook functions are to be implemented + +*Used at deployment to validate the address correctly represents the expected permissions* + + +```solidity +function getHookPermissions() public pure virtual returns (Hooks.Permissions memory); +``` + +### validateHookAddress + +Validates the deployed hook address agrees with the expected permissions of the hook + +*this function is virtual so that we can override it during testing, +which allows us to deploy an implementation to any address +and then etch the bytecode into the correct address* + + +```solidity +function validateHookAddress(BaseHook _this) internal pure virtual; +``` + +### _unlockCallback + + +```solidity +function _unlockCallback(bytes calldata data) internal virtual override returns (bytes memory); +``` + +### beforeInitialize + +The hook called before the state of a pool is initialized + + +```solidity +function beforeInitialize(address, PoolKey calldata, uint160, bytes calldata) external virtual returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`uint160`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### afterInitialize + +The hook called after the state of a pool is initialized + + +```solidity +function afterInitialize(address, PoolKey calldata, uint160, int24, bytes calldata) external virtual returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`uint160`|| +|``|`int24`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### beforeAddLiquidity + +The hook called before liquidity is added + + +```solidity +function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata) + external + virtual + returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`IPoolManager.ModifyLiquidityParams`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### beforeRemoveLiquidity + +The hook called before liquidity is removed + + +```solidity +function beforeRemoveLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata) + external + virtual + returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`IPoolManager.ModifyLiquidityParams`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### afterAddLiquidity + +The hook called after liquidity is added + + +```solidity +function afterAddLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata +) external virtual returns (bytes4, BalanceDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`IPoolManager.ModifyLiquidityParams`|| +|``|`BalanceDelta`|| +|``|`BalanceDelta`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`BalanceDelta`|BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| + + +### afterRemoveLiquidity + +The hook called after liquidity is removed + + +```solidity +function afterRemoveLiquidity( + address, + PoolKey calldata, + IPoolManager.ModifyLiquidityParams calldata, + BalanceDelta, + BalanceDelta, + bytes calldata +) external virtual returns (bytes4, BalanceDelta); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`IPoolManager.ModifyLiquidityParams`|| +|``|`BalanceDelta`|| +|``|`BalanceDelta`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`BalanceDelta`|BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| + + +### beforeSwap + +The hook called before a swap + + +```solidity +function beforeSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, bytes calldata) + external + virtual + returns (bytes4, BeforeSwapDelta, uint24); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`IPoolManager.SwapParams`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`BeforeSwapDelta`|BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| +|``|`uint24`|uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)| + + +### afterSwap + +The hook called after a swap + + +```solidity +function afterSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata) + external + virtual + returns (bytes4, int128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`IPoolManager.SwapParams`|| +|``|`BalanceDelta`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| +|``|`int128`|int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency| + + +### beforeDonate + +The hook called before donate + + +```solidity +function beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) external virtual returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`uint256`|| +|``|`uint256`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +### afterDonate + +The hook called after donate + + +```solidity +function afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) external virtual returns (bytes4); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|| +|``|`PoolKey`|| +|``|`uint256`|| +|``|`uint256`|| +|``|`bytes`|| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes4`|bytes4 The function selector for the hook| + + +## Errors +### NotSelf + +```solidity +error NotSelf(); +``` + +### InvalidPool + +```solidity +error InvalidPool(); +``` + +### LockFailure + +```solidity +error LockFailure(); +``` + +### HookNotImplemented + +```solidity +error HookNotImplemented(); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/BaseV4Quoter.md b/docs/contracts/v4/reference/periphery/base/BaseV4Quoter.md new file mode 100644 index 000000000..19fc5ab59 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/BaseV4Quoter.md @@ -0,0 +1,65 @@ +# BaseV4Quoter +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/BaseV4Quoter.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[SafeCallback](contracts/v4/reference/periphery/base/SafeCallback.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager) SafeCallback(_poolManager); +``` + +### selfOnly + +*Only this address may call this function. Used to mimic internal functions, using an +external call to catch and parse revert reasons* + + +```solidity +modifier selfOnly(); +``` + +### _unlockCallback + + +```solidity +function _unlockCallback(bytes calldata data) internal override returns (bytes memory); +``` + +### _swap + +if amountSpecified < 0, the swap is exactInput, otherwise exactOutput + +*Execute a swap and return the balance delta* + + +```solidity +function _swap(PoolKey memory poolKey, bool zeroForOne, int256 amountSpecified, bytes calldata hookData) + internal + returns (BalanceDelta swapDelta); +``` + +## Errors +### NotEnoughLiquidity + +```solidity +error NotEnoughLiquidity(PoolId poolId); +``` + +### NotSelf + +```solidity +error NotSelf(); +``` + +### UnexpectedCallSuccess + +```solidity +error UnexpectedCallSuccess(); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/DeltaResolver.md b/docs/contracts/v4/reference/periphery/base/DeltaResolver.md new file mode 100644 index 000000000..13f3a80ff --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/DeltaResolver.md @@ -0,0 +1,145 @@ +# DeltaResolver +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/DeltaResolver.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[ImmutableState](contracts/v4/reference/periphery/base/ImmutableState.md) + +Abstract contract used to sync, send, and settle funds to the pool manager + +*Note that sync() is called before any erc-20 transfer in `settle`.* + + +## Functions +### _take + +Take an amount of currency out of the PoolManager + + +```solidity +function _take(Currency currency, address recipient, uint256 amount) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|Currency to take| +|`recipient`|`address`|Address to receive the currency| +|`amount`|`uint256`|Amount to take| + + +### _settle + +Pay and settle a currency to the PoolManager + +*The implementing contract must ensure that the `payer` is a secure address* + + +```solidity +function _settle(Currency currency, address payer, uint256 amount) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|Currency to settle| +|`payer`|`address`|Address of the payer| +|`amount`|`uint256`|Amount to send| + + +### _pay + +Abstract function for contracts to implement paying tokens to the poolManager + +*The recipient of the payment should be the poolManager* + + +```solidity +function _pay(Currency token, address payer, uint256 amount) internal virtual; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`token`|`Currency`|The token to settle. This is known not to be the native currency| +|`payer`|`address`|The address who should pay tokens| +|`amount`|`uint256`|The number of tokens to send| + + +### _getFullDebt + +Obtain the full amount owed by this contract (negative delta) + + +```solidity +function _getFullDebt(Currency currency) internal view returns (uint256 amount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|Currency to get the delta for| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount owed by this contract as a uint256| + + +### _getFullCredit + +Obtain the full credit owed to this contract (positive delta) + + +```solidity +function _getFullCredit(Currency currency) internal view returns (uint256 amount); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`currency`|`Currency`|Currency to get the delta for| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amount`|`uint256`|The amount owed to this contract as a uint256| + + +### _mapSettleAmount + +Calculates the amount for a settle action + + +```solidity +function _mapSettleAmount(uint256 amount, Currency currency) internal view returns (uint256); +``` + +### _mapTakeAmount + +Calculates the amount for a take action + + +```solidity +function _mapTakeAmount(uint256 amount, Currency currency) internal view returns (uint256); +``` + +## Errors +### DeltaNotPositive +Emitted trying to settle a positive delta. + + +```solidity +error DeltaNotPositive(Currency currency); +``` + +### DeltaNotNegative +Emitted trying to take a negative delta. + + +```solidity +error DeltaNotNegative(Currency currency); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/EIP712_v4.md b/docs/contracts/v4/reference/periphery/base/EIP712_v4.md new file mode 100644 index 000000000..c6e7d86cc --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/EIP712_v4.md @@ -0,0 +1,88 @@ +# EIP712_v4 +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/EIP712_v4.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IEIP712_v4](contracts/v4/reference/periphery/interfaces/IEIP712_v4.md) + +Generic EIP712 implementation + +*Maintains cross-chain replay protection in the event of a fork* + +*Should not be delegatecall'd because DOMAIN_SEPARATOR returns the cached hash and does not recompute with the delegatecallers address* + +*Reference: https://github.com/Uniswap/permit2/blob/3f17e8db813189a03950dc7fc8382524a095c053/src/EIP712.sol* + +*Reference: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/7bd2b2aaf68c21277097166a9a51eb72ae239b34/contracts/utils/cryptography/EIP712.sol* + + +## State Variables +### _CACHED_DOMAIN_SEPARATOR + +```solidity +bytes32 private immutable _CACHED_DOMAIN_SEPARATOR; +``` + + +### _CACHED_CHAIN_ID + +```solidity +uint256 private immutable _CACHED_CHAIN_ID; +``` + + +### _HASHED_NAME + +```solidity +bytes32 private immutable _HASHED_NAME; +``` + + +### _TYPE_HASH + +```solidity +bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); +``` + + +## Functions +### constructor + + +```solidity +constructor(string memory name); +``` + +### DOMAIN_SEPARATOR + +Returns the domain separator for the current chain. + + +```solidity +function DOMAIN_SEPARATOR() public view returns (bytes32); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|bytes32 The domain separator| + + +### _buildDomainSeparator + +Builds a domain separator using the current chainId and contract address. + + +```solidity +function _buildDomainSeparator() private view returns (bytes32); +``` + +### _hashTypedData + +Creates an EIP-712 typed data hash + + +```solidity +function _hashTypedData(bytes32 dataHash) internal view returns (bytes32 digest); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/ERC721Permit_v4.md b/docs/contracts/v4/reference/periphery/base/ERC721Permit_v4.md new file mode 100644 index 000000000..f164a7986 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/ERC721Permit_v4.md @@ -0,0 +1,153 @@ +# ERC721Permit_v4 +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/ERC721Permit_v4.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +ERC721, [IERC721Permit_v4](contracts/v4/reference/periphery/interfaces/IERC721Permit_v4.md), [EIP712_v4](contracts/v4/reference/periphery/base/EIP712_v4.md), [UnorderedNonce](contracts/v4/reference/periphery/base/UnorderedNonce.md) + +Nonfungible tokens that support an approve via signature, i.e. permit + + +## Functions +### constructor + +Computes the nameHash and versionHash + + +```solidity +constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) EIP712_v4(name_); +``` + +### checkSignatureDeadline + +Checks if the block's timestamp is before a signature's deadline + + +```solidity +modifier checkSignatureDeadline(uint256 deadline); +``` + +### permit + +Approve of a specific token ID for spending by spender via signature + +*payable so it can be multicalled with NATIVE related actions* + + +```solidity +function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature) + external + payable + checkSignatureDeadline(deadline); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The account that is being approved| +|`tokenId`|`uint256`|The ID of the token that is being approved for spending| +|`deadline`|`uint256`|The deadline timestamp by which the call must be mined for the approve to work| +|`nonce`|`uint256`|a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word| +|`signature`|`bytes`|Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)| + + +### permitForAll + +Set an operator with full permission to an owner's tokens via signature + +*payable so it can be multicalled with NATIVE related actions* + + +```solidity +function permitForAll( + address owner, + address operator, + bool approved, + uint256 deadline, + uint256 nonce, + bytes calldata signature +) external payable checkSignatureDeadline(deadline); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address that is setting the operator| +|`operator`|`address`|The address that will be set as an operator for the owner| +|`approved`|`bool`|The permission to set on the operator| +|`deadline`|`uint256`|The deadline timestamp by which the call must be mined for the approve to work| +|`nonce`|`uint256`|a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word| +|`signature`|`bytes`|Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)| + + +### setApprovalForAll + +Enable or disable approval for a third party ("operator") to manage +all of `msg.sender`'s assets + +*Emits the ApprovalForAll event. The contract MUST allow +multiple operators per owner.* + +*Override Solmate's ERC721 setApprovalForAll so setApprovalForAll() and permit() share the _approveForAll method* + + +```solidity +function setApprovalForAll(address operator, bool approved) public override; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`operator`|`address`|Address to add to the set of authorized operators| +|`approved`|`bool`|True if the operator is approved, false to revoke approval| + + +### _approveForAll + + +```solidity +function _approveForAll(address owner, address operator, bool approved) internal; +``` + +### approve + +Change or reaffirm the approved address for an NFT + +*override Solmate's ERC721 approve so approve() and permit() share the _approve method +Passing a spender address of zero can be used to remove any outstanding approvals +Throws error unless `msg.sender` is the current NFT owner, +or an authorized operator of the current owner.* + + +```solidity +function approve(address spender, uint256 id) public override; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The new approved NFT controller| +|`id`|`uint256`|The tokenId of the NFT to approve| + + +### _approve + + +```solidity +function _approve(address owner, address spender, uint256 id) internal; +``` + +### _isApprovedOrOwner + + +```solidity +function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool); +``` + +### tokenURI + + +```solidity +function tokenURI(uint256) public pure override returns (string memory); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/ImmutableState.md b/docs/contracts/v4/reference/periphery/base/ImmutableState.md new file mode 100644 index 000000000..237bf3816 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/ImmutableState.md @@ -0,0 +1,25 @@ +# ImmutableState +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/ImmutableState.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +A collection of immutable state variables, commonly used across multiple contracts + + +## State Variables +### poolManager +The Uniswap v4 PoolManager contract + + +```solidity +IPoolManager public immutable poolManager; +``` + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/Multicall_v4.md b/docs/contracts/v4/reference/periphery/base/Multicall_v4.md new file mode 100644 index 000000000..b271c7c01 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/Multicall_v4.md @@ -0,0 +1,35 @@ +# Multicall_v4 +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/Multicall_v4.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IMulticall_v4](contracts/v4/reference/periphery/interfaces/IMulticall_v4.md) + +Enables calling multiple methods in a single call to the contract + + +## Functions +### multicall + +Call multiple functions in the current contract and return the data from all of them if they all succeed + +*The `msg.value` is passed onto all subcalls, even if a previous subcall has consumed the ether. +Subcalls can instead use `address(this).value` to see the available ETH, and consume it using {value: x}.* + + +```solidity +function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes[]`|The encoded function data for each of the calls to make to this contract| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`results`|`bytes[]`|The results from each of the calls passed in via data| + + diff --git a/docs/contracts/v4/reference/periphery/base/Notifier.md b/docs/contracts/v4/reference/periphery/base/Notifier.md new file mode 100644 index 000000000..4ae9c0e0d --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/Notifier.md @@ -0,0 +1,143 @@ +# Notifier +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/Notifier.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[INotifier](contracts/v4/reference/periphery/interfaces/INotifier.md) + +Notifier is used to opt in to sending updates to external contracts about position modifications or transfers + + +## State Variables +### NO_SUBSCRIBER + +```solidity +ISubscriber private constant NO_SUBSCRIBER = ISubscriber(address(0)); +``` + + +### unsubscribeGasLimit +Returns and determines the maximum allowable gas-used for notifying unsubscribe + + +```solidity +uint256 public immutable unsubscribeGasLimit; +``` + + +### subscriber +Returns the subscriber for a respective position + + +```solidity +mapping(uint256 tokenId => ISubscriber subscriber) public subscriber; +``` + + +## Functions +### constructor + + +```solidity +constructor(uint256 _unsubscribeGasLimit); +``` + +### onlyIfApproved + +Only allow callers that are approved as spenders or operators of the tokenId + +*to be implemented by the parent contract (PositionManager)* + + +```solidity +modifier onlyIfApproved(address caller, uint256 tokenId) virtual; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`caller`|`address`|the address of the caller| +|`tokenId`|`uint256`|the tokenId of the position| + + +### _setUnsubscribed + + +```solidity +function _setUnsubscribed(uint256 tokenId) internal virtual; +``` + +### _setSubscribed + + +```solidity +function _setSubscribed(uint256 tokenId) internal virtual; +``` + +### subscribe + +Enables the subscriber to receive notifications for a respective position + +*Calling subscribe when a position is already subscribed will revert* + + +```solidity +function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data) + external + payable + onlyIfApproved(msg.sender, tokenId); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| +|`newSubscriber`|`address`|the address of the subscriber contract| +|`data`|`bytes`|caller-provided data that's forwarded to the subscriber contract| + + +### unsubscribe + +Removes the subscriber from receiving notifications for a respective position + +*Callers must specify a high gas limit (remaining gas should be higher than unsubscriberGasLimit) such that the subscriber can be notified* + + +```solidity +function unsubscribe(uint256 tokenId) external payable onlyIfApproved(msg.sender, tokenId); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| + + +### _unsubscribe + + +```solidity +function _unsubscribe(uint256 tokenId) internal; +``` + +### _notifyModifyLiquidity + + +```solidity +function _notifyModifyLiquidity(uint256 tokenId, int256 liquidityChange, BalanceDelta feesAccrued) internal; +``` + +### _notifyTransfer + + +```solidity +function _notifyTransfer(uint256 tokenId, address previousOwner, address newOwner) internal; +``` + +### _call + + +```solidity +function _call(address target, bytes memory encodedCall) internal returns (bool success); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/Permit2Forwarder.md b/docs/contracts/v4/reference/periphery/base/Permit2Forwarder.md new file mode 100644 index 000000000..4f6619e6e --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/Permit2Forwarder.md @@ -0,0 +1,71 @@ +# Permit2Forwarder +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/Permit2Forwarder.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +PermitForwarder allows permitting this contract as a spender on permit2 + +*This contract does not enforce the spender to be this contract, but that is the intended use case* + + +## State Variables +### permit2 +the Permit2 contract to forward approvals + + +```solidity +IAllowanceTransfer public immutable permit2; +``` + + +## Functions +### constructor + + +```solidity +constructor(IAllowanceTransfer _permit2); +``` + +### permit + +allows forwarding a single permit to permit2 + +*this function is payable to allow multicall with NATIVE based actions* + + +```solidity +function permit(address owner, IAllowanceTransfer.PermitSingle calldata permitSingle, bytes calldata signature) + external + payable + returns (bytes memory err); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|the owner of the tokens| +|`permitSingle`|`IAllowanceTransfer.PermitSingle`|the permit data| +|`signature`|`bytes`|the signature of the permit; abi.encodePacked(r, s, v)| + + +### permitBatch + +allows forwarding batch permits to permit2 + +*this function is payable to allow multicall with NATIVE based actions* + + +```solidity +function permitBatch(address owner, IAllowanceTransfer.PermitBatch calldata _permitBatch, bytes calldata signature) + external + payable + returns (bytes memory err); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|the owner of the tokens| +|`_permitBatch`|`IAllowanceTransfer.PermitBatch`|a batch of approvals| +|`signature`|`bytes`|the signature of the permit; abi.encodePacked(r, s, v)| + + diff --git a/docs/contracts/v4/reference/periphery/base/PoolInitializer.md b/docs/contracts/v4/reference/periphery/base/PoolInitializer.md new file mode 100644 index 000000000..8539df017 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/PoolInitializer.md @@ -0,0 +1,33 @@ +# PoolInitializer +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/PoolInitializer.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[ImmutableState](contracts/v4/reference/periphery/base/ImmutableState.md) + +Initializes a Uniswap v4 Pool + +*Enables create pool + mint liquidity in a single transaction with multicall* + + +## Functions +### initializePool + +Initialize a Uniswap v4 Pool + + +```solidity +function initializePool(PoolKey calldata key, uint160 sqrtPriceX96, bytes calldata hookData) + external + payable + returns (int24); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`key`|`PoolKey`|the PoolKey of the pool to initialize| +|`sqrtPriceX96`|`uint160`|the initial sqrtPriceX96 of the pool| +|`hookData`|`bytes`|the optional data passed to the hook's initialize functions| + + diff --git a/docs/contracts/v4/reference/periphery/base/ReentrancyLock.md b/docs/contracts/v4/reference/periphery/base/ReentrancyLock.md new file mode 100644 index 000000000..f482528dd --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/ReentrancyLock.md @@ -0,0 +1,29 @@ +# ReentrancyLock +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/ReentrancyLock.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +A transient reentrancy lock, that stores the caller's address as the lock + + +## Functions +### isNotLocked + + +```solidity +modifier isNotLocked(); +``` + +### _getLocker + + +```solidity +function _getLocker() internal view returns (address); +``` + +## Errors +### ContractLocked + +```solidity +error ContractLocked(); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/SafeCallback.md b/docs/contracts/v4/reference/periphery/base/SafeCallback.md new file mode 100644 index 000000000..b43628eb8 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/SafeCallback.md @@ -0,0 +1,68 @@ +# SafeCallback +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/SafeCallback.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[ImmutableState](contracts/v4/reference/periphery/base/ImmutableState.md), IUnlockCallback + +A contract that only allows the Uniswap v4 PoolManager to call the unlockCallback + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager) ImmutableState(_poolManager); +``` + +### onlyPoolManager + +Only allow calls from the PoolManager contract + + +```solidity +modifier onlyPoolManager(); +``` + +### unlockCallback + +Called by the pool manager on `msg.sender` when the manager is unlocked + +*We force the onlyPoolManager modifier by exposing a virtual function after the onlyPoolManager check.* + + +```solidity +function unlockCallback(bytes calldata data) external onlyPoolManager returns (bytes memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes`|The data that was passed to the call to unlock| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes`|Any data that you want to be returned from the unlock call| + + +### _unlockCallback + +*to be implemented by the child contract, to safely guarantee the logic is only executed by the PoolManager* + + +```solidity +function _unlockCallback(bytes calldata data) internal virtual returns (bytes memory); +``` + +## Errors +### NotPoolManager +Thrown when calling unlockCallback where the caller is not PoolManager + + +```solidity +error NotPoolManager(); +``` + diff --git a/docs/contracts/v4/reference/periphery/base/UnorderedNonce.md b/docs/contracts/v4/reference/periphery/base/UnorderedNonce.md new file mode 100644 index 000000000..29065b666 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/base/UnorderedNonce.md @@ -0,0 +1,56 @@ +# UnorderedNonce +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/base/UnorderedNonce.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Contract state and methods for using unordered nonces in signatures + + +## State Variables +### nonces +mapping of nonces consumed by each address, where a nonce is a single bit on the 256-bit bitmap + +*word is at most type(uint248).max* + + +```solidity +mapping(address owner => mapping(uint256 word => uint256 bitmap)) public nonces; +``` + + +## Functions +### _useUnorderedNonce + +Consume a nonce, reverting if it has already been used + + +```solidity +function _useUnorderedNonce(address owner, uint256 nonce) internal; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|address, the owner/signer of the nonce| +|`nonce`|`uint256`|uint256, the nonce to consume. The top 248 bits are the word, the bottom 8 bits indicate the bit position| + + +### revokeNonce + +Revoke a nonce by spending it, preventing it from being used again + +*Used in cases where a valid nonce has not been broadcasted onchain, and the owner wants to revoke the validity of the nonce* + +*payable so it can be multicalled with native-token related actions* + + +```solidity +function revokeNonce(uint256 nonce) external payable; +``` + +## Errors +### NonceAlreadyUsed + +```solidity +error NonceAlreadyUsed(); +``` + diff --git a/docs/contracts/v4/reference/periphery/interfaces/IEIP712_v4.md b/docs/contracts/v4/reference/periphery/interfaces/IEIP712_v4.md new file mode 100644 index 000000000..d4ced84bc --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/IEIP712_v4.md @@ -0,0 +1,23 @@ +# IEIP712_v4 +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IEIP712_v4.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +This interface is used for an EIP712 implementation + + +## Functions +### DOMAIN_SEPARATOR + +Returns the domain separator for the current chain. + + +```solidity +function DOMAIN_SEPARATOR() external view returns (bytes32); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bytes32`|bytes32 The domain separator| + + diff --git a/docs/contracts/v4/reference/periphery/interfaces/IERC721Permit_v4.md b/docs/contracts/v4/reference/periphery/interfaces/IERC721Permit_v4.md new file mode 100644 index 000000000..c2a7ac4e8 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/IERC721Permit_v4.md @@ -0,0 +1,79 @@ +# IERC721Permit_v4 +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IERC721Permit_v4.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Extension to ERC721 that includes a permit function for signature based approvals + + +## Functions +### permit + +Approve of a specific token ID for spending by spender via signature + +*payable so it can be multicalled with NATIVE related actions* + + +```solidity +function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature) + external + payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The account that is being approved| +|`tokenId`|`uint256`|The ID of the token that is being approved for spending| +|`deadline`|`uint256`|The deadline timestamp by which the call must be mined for the approve to work| +|`nonce`|`uint256`|a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word| +|`signature`|`bytes`|Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)| + + +### permitForAll + +Set an operator with full permission to an owner's tokens via signature + +*payable so it can be multicalled with NATIVE related actions* + + +```solidity +function permitForAll( + address owner, + address operator, + bool approved, + uint256 deadline, + uint256 nonce, + bytes calldata signature +) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`owner`|`address`|The address that is setting the operator| +|`operator`|`address`|The address that will be set as an operator for the owner| +|`approved`|`bool`|The permission to set on the operator| +|`deadline`|`uint256`|The deadline timestamp by which the call must be mined for the approve to work| +|`nonce`|`uint256`|a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word| +|`signature`|`bytes`|Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)| + + +## Errors +### SignatureDeadlineExpired + +```solidity +error SignatureDeadlineExpired(); +``` + +### NoSelfPermit + +```solidity +error NoSelfPermit(); +``` + +### Unauthorized + +```solidity +error Unauthorized(); +``` + diff --git a/docs/contracts/v4/reference/periphery/interfaces/IMulticall_v4.md b/docs/contracts/v4/reference/periphery/interfaces/IMulticall_v4.md new file mode 100644 index 000000000..d29f0ea54 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/IMulticall_v4.md @@ -0,0 +1,32 @@ +# IMulticall_v4 +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IMulticall_v4.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Enables calling multiple methods in a single call to the contract + + +## Functions +### multicall + +Call multiple functions in the current contract and return the data from all of them if they all succeed + +*The `msg.value` is passed onto all subcalls, even if a previous subcall has consumed the ether. +Subcalls can instead use `address(this).value` to see the available ETH, and consume it using {value: x}.* + + +```solidity +function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`data`|`bytes[]`|The encoded function data for each of the calls to make to this contract| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`results`|`bytes[]`|The results from each of the calls passed in via data| + + diff --git a/docs/contracts/v4/reference/periphery/interfaces/INotifier.md b/docs/contracts/v4/reference/periphery/interfaces/INotifier.md new file mode 100644 index 000000000..a0d0617c4 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/INotifier.md @@ -0,0 +1,160 @@ +# INotifier +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/INotifier.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +This interface is used to opt in to sending updates to external contracts about position modifications or transfers + + +## Functions +### subscriber + +Returns the subscriber for a respective position + + +```solidity +function subscriber(uint256 tokenId) external view returns (ISubscriber subscriber); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`subscriber`|`ISubscriber`|the subscriber contract| + + +### subscribe + +Enables the subscriber to receive notifications for a respective position + +*Calling subscribe when a position is already subscribed will revert* + +*payable so it can be multicalled with NATIVE related actions* + + +```solidity +function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| +|`newSubscriber`|`address`|the address of the subscriber contract| +|`data`|`bytes`|caller-provided data that's forwarded to the subscriber contract| + + +### unsubscribe + +Removes the subscriber from receiving notifications for a respective position + +*Callers must specify a high gas limit (remaining gas should be higher than unsubscriberGasLimit) such that the subscriber can be notified* + +*payable so it can be multicalled with NATIVE related actions* + +*Must always allow a user to unsubscribe. In the case of a malicious subscriber, a user can always unsubscribe safely, ensuring liquidity is always modifiable.* + + +```solidity +function unsubscribe(uint256 tokenId) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| + + +### unsubscribeGasLimit + +Returns and determines the maximum allowable gas-used for notifying unsubscribe + + +```solidity +function unsubscribeGasLimit() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|uint256 the maximum gas limit when notifying a subscriber's `notifyUnsubscribe` function| + + +## Events +### Subscription +Emitted on a successful call to subscribe + + +```solidity +event Subscription(uint256 indexed tokenId, address indexed subscriber); +``` + +### Unsubscription +Emitted on a successful call to unsubscribe + + +```solidity +event Unsubscription(uint256 indexed tokenId, address indexed subscriber); +``` + +## Errors +### NotSubscribed +Thrown when unsubscribing without a subscriber + + +```solidity +error NotSubscribed(); +``` + +### NoCodeSubscriber +Thrown when a subscriber does not have code + + +```solidity +error NoCodeSubscriber(); +``` + +### GasLimitTooLow +Thrown when a user specifies a gas limit too low to avoid valid unsubscribe notifications + + +```solidity +error GasLimitTooLow(); +``` + +### Wrap__SubscriptionReverted +Wraps the revert message of the subscriber contract on a reverting subscription + + +```solidity +error Wrap__SubscriptionReverted(address subscriber, bytes reason); +``` + +### Wrap__ModifyLiquidityNotificationReverted +Wraps the revert message of the subscriber contract on a reverting modify liquidity notification + + +```solidity +error Wrap__ModifyLiquidityNotificationReverted(address subscriber, bytes reason); +``` + +### Wrap__TransferNotificationReverted +Wraps the revert message of the subscriber contract on a reverting transfer notification + + +```solidity +error Wrap__TransferNotificationReverted(address subscriber, bytes reason); +``` + +### AlreadySubscribed +Thrown when a tokenId already has a subscriber + + +```solidity +error AlreadySubscribed(uint256 tokenId, address subscriber); +``` + diff --git a/docs/contracts/v4/reference/periphery/interfaces/IPositionManager.md b/docs/contracts/v4/reference/periphery/interfaces/IPositionManager.md new file mode 100644 index 000000000..03643f6b5 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/IPositionManager.md @@ -0,0 +1,120 @@ +# IPositionManager +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IPositionManager.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[INotifier](contracts/v4/reference/periphery/interfaces/INotifier.md) + +Interface for the PositionManager contract + + +## Functions +### modifyLiquidities + +Unlocks Uniswap v4 PoolManager and batches actions for modifying liquidity + +*This is the standard entrypoint for the PositionManager* + + +```solidity +function modifyLiquidities(bytes calldata unlockData, uint256 deadline) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`unlockData`|`bytes`|is an encoding of actions, and parameters for those actions| +|`deadline`|`uint256`|is the deadline for the batched actions to be executed| + + +### modifyLiquiditiesWithoutUnlock + +Batches actions for modifying liquidity without unlocking v4 PoolManager + +*This must be called by a contract that has already unlocked the v4 PoolManager* + + +```solidity +function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params) external payable; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`actions`|`bytes`|the actions to perform| +|`params`|`bytes[]`|the parameters to provide for the actions| + + +### nextTokenId + +Used to get the ID that will be used for the next minted liquidity position + + +```solidity +function nextTokenId() external view returns (uint256); +``` +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|uint256 The next token ID| + + +### getPositionLiquidity + +*this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library* + + +```solidity +function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|the position's liquidity, as a liquidityAmount| + + +### getPoolAndPositionInfo + + +```solidity +function getPoolAndPositionInfo(uint256 tokenId) external view returns (PoolKey memory, PositionInfo); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the ERC721 tokenId| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`PoolKey`|PositionInfo a uint256 packed value holding information about the position including the range (tickLower, tickUpper)| +|``|`PositionInfo`|poolKey the pool key of the position| + + +## Errors +### NotApproved +Thrown when the caller is not approved to modify a position + + +```solidity +error NotApproved(address caller); +``` + +### DeadlinePassed +Thrown when the block.timestamp exceeds the user-provided deadline + + +```solidity +error DeadlinePassed(uint256 deadline); +``` + diff --git a/docs/contracts/v4/reference/periphery/interfaces/IQuoter.md b/docs/contracts/v4/reference/periphery/interfaces/IQuoter.md new file mode 100644 index 000000000..0de91e2b2 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/IQuoter.md @@ -0,0 +1,127 @@ +# IQuoter +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IQuoter.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Supports quoting the delta amounts for exact input or exact output swaps. + +For each pool also tells you the sqrt price of the pool after the swap. + +*These functions are not marked view because they rely on calling non-view functions and reverting +to compute the result. They are also not gas efficient and should not be called on-chain.* + + +## Functions +### quoteExactInputSingle + +Returns the delta amounts for a given exact input swap of a single pool + + +```solidity +function quoteExactInputSingle(QuoteExactSingleParams memory params) + external + returns (uint256 amountOut, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactSingleParams`|The params for the quote, encoded as `QuoteExactSingleParams` poolKey The key for identifying a V4 pool zeroForOne If the swap is from currency0 to currency1 exactAmount The desired input amount hookData arbitrary hookData to pass into the associated hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|The output quote for the exactIn swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +### quoteExactInput + +Returns the delta amounts along the swap path for a given exact input swap + + +```solidity +function quoteExactInput(QuoteExactParams memory params) external returns (uint256 amountOut, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactParams`|the params for the quote, encoded as 'QuoteExactParams' currencyIn The input currency of the swap path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info exactAmount The desired input amount| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|The output quote for the exactIn swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +### quoteExactOutputSingle + +Returns the delta amounts for a given exact output swap of a single pool + + +```solidity +function quoteExactOutputSingle(QuoteExactSingleParams memory params) + external + returns (uint256 amountIn, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactSingleParams`|The params for the quote, encoded as `QuoteExactSingleParams` poolKey The key for identifying a V4 pool zeroForOne If the swap is from currency0 to currency1 exactAmount The desired output amount hookData arbitrary hookData to pass into the associated hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|The input quote for the exactOut swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +### quoteExactOutput + +Returns the delta amounts along the swap path for a given exact output swap + + +```solidity +function quoteExactOutput(QuoteExactParams memory params) external returns (uint256 amountIn, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactParams`|the params for the quote, encoded as 'QuoteExactParams' currencyOut The output currency of the swap path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info exactAmount The desired output amount| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|The input quote for the exactOut swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +## Structs +### QuoteExactSingleParams + +```solidity +struct QuoteExactSingleParams { + PoolKey poolKey; + bool zeroForOne; + uint128 exactAmount; + bytes hookData; +} +``` + +### QuoteExactParams + +```solidity +struct QuoteExactParams { + Currency exactCurrency; + PathKey[] path; + uint128 exactAmount; +} +``` + diff --git a/docs/contracts/v4/reference/periphery/interfaces/ISubscriber.md b/docs/contracts/v4/reference/periphery/interfaces/ISubscriber.md new file mode 100644 index 000000000..fd0ca8e00 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/ISubscriber.md @@ -0,0 +1,71 @@ +# ISubscriber +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/ISubscriber.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface that a Subscriber contract should implement to receive updates from the v4 position manager + + +## Functions +### notifySubscribe + + +```solidity +function notifySubscribe(uint256 tokenId, bytes memory data) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the token ID of the position| +|`data`|`bytes`|additional data passed in by the caller| + + +### notifyUnsubscribe + +Called when a position unsubscribes from the subscriber + +*This call's gas is capped at `unsubscribeGasLimit` (set at deployment)* + +*Because of EIP-150, solidity may only allocate 63/64 of gasleft()* + + +```solidity +function notifyUnsubscribe(uint256 tokenId) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the token ID of the position| + + +### notifyModifyLiquidity + + +```solidity +function notifyModifyLiquidity(uint256 tokenId, int256 liquidityChange, BalanceDelta feesAccrued) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the token ID of the position| +|`liquidityChange`|`int256`|the change in liquidity on the underlying position| +|`feesAccrued`|`BalanceDelta`|the fees to be collected from the position as a result of the modifyLiquidity call| + + +### notifyTransfer + + +```solidity +function notifyTransfer(uint256 tokenId, address previousOwner, address newOwner) external; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`tokenId`|`uint256`|the token ID of the position| +|`previousOwner`|`address`|address of the old owner| +|`newOwner`|`address`|address of the new owner| + + diff --git a/docs/contracts/v4/reference/periphery/interfaces/IV4Router.md b/docs/contracts/v4/reference/periphery/interfaces/IV4Router.md new file mode 100644 index 000000000..a28a11ef0 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/interfaces/IV4Router.md @@ -0,0 +1,81 @@ +# IV4Router +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IV4Router.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Interface containing all the structs and errors for different v4 swap types + + +## Errors +### V4TooLittleReceived +Emitted when an exactInput swap does not receive its minAmountOut + + +```solidity +error V4TooLittleReceived(uint256 minAmountOutReceived, uint256 amountReceived); +``` + +### V4TooMuchRequested +Emitted when an exactOutput is asked for more than its maxAmountIn + + +```solidity +error V4TooMuchRequested(uint256 maxAmountInRequested, uint256 amountRequested); +``` + +## Structs +### ExactInputSingleParams +Parameters for a single-hop exact-input swap + + +```solidity +struct ExactInputSingleParams { + PoolKey poolKey; + bool zeroForOne; + uint128 amountIn; + uint128 amountOutMinimum; + uint160 sqrtPriceLimitX96; + bytes hookData; +} +``` + +### ExactInputParams +Parameters for a multi-hop exact-input swap + + +```solidity +struct ExactInputParams { + Currency currencyIn; + PathKey[] path; + uint128 amountIn; + uint128 amountOutMinimum; +} +``` + +### ExactOutputSingleParams +Parameters for a single-hop exact-output swap + + +```solidity +struct ExactOutputSingleParams { + PoolKey poolKey; + bool zeroForOne; + uint128 amountOut; + uint128 amountInMaximum; + uint160 sqrtPriceLimitX96; + bytes hookData; +} +``` + +### ExactOutputParams +Parameters for a multi-hop exact-output swap + + +```solidity +struct ExactOutputParams { + Currency currencyOut; + PathKey[] path; + uint128 amountOut; + uint128 amountInMaximum; +} +``` + diff --git a/docs/contracts/v4/reference/periphery/lens/Quoter.md b/docs/contracts/v4/reference/periphery/lens/Quoter.md new file mode 100644 index 000000000..878442a4a --- /dev/null +++ b/docs/contracts/v4/reference/periphery/lens/Quoter.md @@ -0,0 +1,144 @@ +# Quoter +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/lens/Quoter.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[IQuoter](contracts/v4/reference/periphery/interfaces/IQuoter.md), [BaseV4Quoter](contracts/v4/reference/periphery/base/BaseV4Quoter.md) + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager) BaseV4Quoter(_poolManager); +``` + +### quoteExactInputSingle + +Returns the delta amounts for a given exact input swap of a single pool + + +```solidity +function quoteExactInputSingle(QuoteExactSingleParams memory params) + external + returns (uint256 amountOut, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactSingleParams`|The params for the quote, encoded as `QuoteExactSingleParams` poolKey The key for identifying a V4 pool zeroForOne If the swap is from currency0 to currency1 exactAmount The desired input amount hookData arbitrary hookData to pass into the associated hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|The output quote for the exactIn swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +### quoteExactInput + +Returns the delta amounts along the swap path for a given exact input swap + + +```solidity +function quoteExactInput(QuoteExactParams memory params) external returns (uint256 amountOut, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactParams`|the params for the quote, encoded as 'QuoteExactParams' currencyIn The input currency of the swap path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info exactAmount The desired input amount| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountOut`|`uint256`|The output quote for the exactIn swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +### quoteExactOutputSingle + +Returns the delta amounts for a given exact output swap of a single pool + + +```solidity +function quoteExactOutputSingle(QuoteExactSingleParams memory params) + external + returns (uint256 amountIn, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactSingleParams`|The params for the quote, encoded as `QuoteExactSingleParams` poolKey The key for identifying a V4 pool zeroForOne If the swap is from currency0 to currency1 exactAmount The desired output amount hookData arbitrary hookData to pass into the associated hooks| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|The input quote for the exactOut swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +### quoteExactOutput + +Returns the delta amounts along the swap path for a given exact output swap + + +```solidity +function quoteExactOutput(QuoteExactParams memory params) external returns (uint256 amountIn, uint256 gasEstimate); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`params`|`QuoteExactParams`|the params for the quote, encoded as 'QuoteExactParams' currencyOut The output currency of the swap path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info exactAmount The desired output amount| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`amountIn`|`uint256`|The input quote for the exactOut swap| +|`gasEstimate`|`uint256`|Estimated gas units used for the swap| + + +### _quoteExactInput + +*external function called within the _unlockCallback, to simulate an exact input swap, then revert with the result* + + +```solidity +function _quoteExactInput(QuoteExactParams calldata params) external selfOnly returns (bytes memory); +``` + +### _quoteExactInputSingle + +*external function called within the _unlockCallback, to simulate a single-hop exact input swap, then revert with the result* + + +```solidity +function _quoteExactInputSingle(QuoteExactSingleParams calldata params) external selfOnly returns (bytes memory); +``` + +### _quoteExactOutput + +*external function called within the _unlockCallback, to simulate an exact output swap, then revert with the result* + + +```solidity +function _quoteExactOutput(QuoteExactParams calldata params) external selfOnly returns (bytes memory); +``` + +### _quoteExactOutputSingle + +*external function called within the _unlockCallback, to simulate a single-hop exact output swap, then revert with the result* + + +```solidity +function _quoteExactOutputSingle(QuoteExactSingleParams calldata params) external selfOnly returns (bytes memory); +``` + diff --git a/docs/contracts/v4/reference/periphery/lens/StateView.md b/docs/contracts/v4/reference/periphery/lens/StateView.md new file mode 100644 index 000000000..a3d1ba952 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/lens/StateView.md @@ -0,0 +1,321 @@ +# StateView +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/lens/StateView.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +**Inherits:** +[ImmutableState](contracts/v4/reference/periphery/base/ImmutableState.md) + +A view only contract wrapping the StateLibrary.sol library for reading storage in v4-core. + + +## Functions +### constructor + + +```solidity +constructor(IPoolManager _poolManager) ImmutableState(_poolManager); +``` + +### getSlot0 + +Get Slot0 of the pool: sqrtPriceX96, tick, protocolFee, lpFee + +*Corresponds to pools[poolId].slot0* + + +```solidity +function getSlot0(PoolId poolId) + external + view + returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`sqrtPriceX96`|`uint160`|The square root of the price of the pool, in Q96 precision.| +|`tick`|`int24`|The current tick of the pool.| +|`protocolFee`|`uint24`|The protocol fee of the pool.| +|`lpFee`|`uint24`|The swap fee of the pool.| + + +### getTickInfo + +Retrieves the tick information of a pool at a specific tick. + +*Corresponds to pools[poolId].ticks[tick]* + + +```solidity +function getTickInfo(PoolId poolId, int24 tick) + external + view + returns (uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int24`|The tick to retrieve information for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidityGross`|`uint128`|The total position liquidity that references this tick| +|`liquidityNet`|`int128`|The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)| +|`feeGrowthOutside0X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| +|`feeGrowthOutside1X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| + + +### getTickLiquidity + +Retrieves the liquidity information of a pool at a specific tick. + +*Corresponds to pools[poolId].ticks[tick].liquidityGross and pools[poolId].ticks[tick].liquidityNet. A more gas efficient version of getTickInfo* + + +```solidity +function getTickLiquidity(PoolId poolId, int24 tick) + external + view + returns (uint128 liquidityGross, int128 liquidityNet); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int24`|The tick to retrieve liquidity for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidityGross`|`uint128`|The total position liquidity that references this tick| +|`liquidityNet`|`int128`|The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)| + + +### getTickFeeGrowthOutside + +Retrieves the fee growth outside a tick range of a pool + +*Corresponds to pools[poolId].ticks[tick].feeGrowthOutside0X128 and pools[poolId].ticks[tick].feeGrowthOutside1X128. A more gas efficient version of getTickInfo* + + +```solidity +function getTickFeeGrowthOutside(PoolId poolId, int24 tick) + external + view + returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int24`|The tick to retrieve fee growth for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feeGrowthOutside0X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| +|`feeGrowthOutside1X128`|`uint256`|fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)| + + +### getFeeGrowthGlobals + +Retrieves the global fee growth of a pool. + +*Corresponds to pools[poolId].feeGrowthGlobal0X128 and pools[poolId].feeGrowthGlobal1X128* + + +```solidity +function getFeeGrowthGlobals(PoolId poolId) + external + view + returns (uint256 feeGrowthGlobal0, uint256 feeGrowthGlobal1); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feeGrowthGlobal0`|`uint256`|The global fee growth for token0.| +|`feeGrowthGlobal1`|`uint256`|The global fee growth for token1.| + + +### getLiquidity + +Retrieves the total liquidity of a pool. + +*Corresponds to pools[poolId].liquidity* + + +```solidity +function getLiquidity(PoolId poolId) external view returns (uint128 liquidity); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the pool.| + + +### getTickBitmap + +Retrieves the tick bitmap of a pool at a specific tick. + +*Corresponds to pools[poolId].tickBitmap[tick]* + + +```solidity +function getTickBitmap(PoolId poolId, int16 tick) external view returns (uint256 tickBitmap); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`tick`|`int16`|The tick to retrieve the bitmap for.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`tickBitmap`|`uint256`|The bitmap of the tick.| + + +### getPositionInfo + +Retrieves the position info without needing to calculate the `positionId`. + +*Corresponds to pools[poolId].positions[positionId]* + + +```solidity +function getPositionInfo(PoolId poolId, address owner, int24 tickLower, int24 tickUpper, bytes32 salt) + external + view + returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`owner`|`address`|The owner of the liquidity position.| +|`tickLower`|`int24`|The lower tick of the liquidity range.| +|`tickUpper`|`int24`|The upper tick of the liquidity range.| +|`salt`|`bytes32`|The bytes32 randomness to further distinguish position state.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the position.| +|`feeGrowthInside0LastX128`|`uint256`|The fee growth inside the position for token0.| +|`feeGrowthInside1LastX128`|`uint256`|The fee growth inside the position for token1.| + + +### getPositionInfo + +Retrieves the position information of a pool at a specific position ID. + +*Corresponds to pools[poolId].positions[positionId]* + + +```solidity +function getPositionInfo(PoolId poolId, bytes32 positionId) + external + view + returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`positionId`|`bytes32`|The ID of the position.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the position.| +|`feeGrowthInside0LastX128`|`uint256`|The fee growth inside the position for token0.| +|`feeGrowthInside1LastX128`|`uint256`|The fee growth inside the position for token1.| + + +### getPositionLiquidity + +Retrieves the liquidity of a position. + +*Corresponds to pools[poolId].positions[positionId].liquidity. More gas efficient for just retrieving liquidity as compared to getPositionInfo* + + +```solidity +function getPositionLiquidity(PoolId poolId, bytes32 positionId) external view returns (uint128 liquidity); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`positionId`|`bytes32`|The ID of the position.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`liquidity`|`uint128`|The liquidity of the position.| + + +### getFeeGrowthInside + +Calculate the fee growth inside a tick range of a pool + +*pools[poolId].feeGrowthInside0LastX128 in Position.Info is cached and can become stale. This function will calculate the up to date feeGrowthInside* + + +```solidity +function getFeeGrowthInside(PoolId poolId, int24 tickLower, int24 tickUpper) + external + view + returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`poolId`|`PoolId`|The ID of the pool.| +|`tickLower`|`int24`|The lower tick of the range.| +|`tickUpper`|`int24`|The upper tick of the range.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`feeGrowthInside0X128`|`uint256`|The fee growth inside the tick range for token0.| +|`feeGrowthInside1X128`|`uint256`|The fee growth inside the tick range for token1.| + + diff --git a/docs/contracts/v4/reference/periphery/libraries/ActionConstants.md b/docs/contracts/v4/reference/periphery/libraries/ActionConstants.md new file mode 100644 index 000000000..a48587bf9 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/ActionConstants.md @@ -0,0 +1,48 @@ +# ActionConstants +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/ActionConstants.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Common constants used in actions + +*Constants are gas efficient alternatives to their literal values* + + +## State Variables +### OPEN_DELTA +used to signal that an action should use the input value of the open delta on the pool manager +or of the balance that the contract holds + + +```solidity +uint128 internal constant OPEN_DELTA = 0; +``` + + +### CONTRACT_BALANCE +used to signal that an action should use the contract's entire balance of a currency +This value is equivalent to 1<<255, i.e. a singular 1 in the most significant bit. + + +```solidity +uint256 internal constant CONTRACT_BALANCE = 0x8000000000000000000000000000000000000000000000000000000000000000; +``` + + +### MSG_SENDER +used to signal that the recipient of an action should be the msgSender + + +```solidity +address internal constant MSG_SENDER = address(1); +``` + + +### ADDRESS_THIS +used to signal that the recipient of an action should be the address(this) + + +```solidity +address internal constant ADDRESS_THIS = address(2); +``` + + diff --git a/docs/contracts/v4/reference/periphery/libraries/Actions.md b/docs/contracts/v4/reference/periphery/libraries/Actions.md new file mode 100644 index 000000000..1cb6d48ff --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/Actions.md @@ -0,0 +1,164 @@ +# Actions +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/Actions.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +Library to define different pool actions. + +*These are suggested common commands, however additional commands should be defined as required* + + +## State Variables +### INCREASE_LIQUIDITY + +```solidity +uint256 constant INCREASE_LIQUIDITY = 0x00; +``` + + +### DECREASE_LIQUIDITY + +```solidity +uint256 constant DECREASE_LIQUIDITY = 0x01; +``` + + +### MINT_POSITION + +```solidity +uint256 constant MINT_POSITION = 0x02; +``` + + +### BURN_POSITION + +```solidity +uint256 constant BURN_POSITION = 0x03; +``` + + +### SWAP_EXACT_IN_SINGLE + +```solidity +uint256 constant SWAP_EXACT_IN_SINGLE = 0x04; +``` + + +### SWAP_EXACT_IN + +```solidity +uint256 constant SWAP_EXACT_IN = 0x05; +``` + + +### SWAP_EXACT_OUT_SINGLE + +```solidity +uint256 constant SWAP_EXACT_OUT_SINGLE = 0x06; +``` + + +### SWAP_EXACT_OUT + +```solidity +uint256 constant SWAP_EXACT_OUT = 0x07; +``` + + +### DONATE + +```solidity +uint256 constant DONATE = 0x08; +``` + + +### SETTLE + +```solidity +uint256 constant SETTLE = 0x09; +``` + + +### SETTLE_ALL + +```solidity +uint256 constant SETTLE_ALL = 0x10; +``` + + +### SETTLE_PAIR + +```solidity +uint256 constant SETTLE_PAIR = 0x11; +``` + + +### TAKE + +```solidity +uint256 constant TAKE = 0x12; +``` + + +### TAKE_ALL + +```solidity +uint256 constant TAKE_ALL = 0x13; +``` + + +### TAKE_PORTION + +```solidity +uint256 constant TAKE_PORTION = 0x14; +``` + + +### TAKE_PAIR + +```solidity +uint256 constant TAKE_PAIR = 0x15; +``` + + +### SETTLE_TAKE_PAIR + +```solidity +uint256 constant SETTLE_TAKE_PAIR = 0x16; +``` + + +### CLOSE_CURRENCY + +```solidity +uint256 constant CLOSE_CURRENCY = 0x17; +``` + + +### CLEAR_OR_TAKE + +```solidity +uint256 constant CLEAR_OR_TAKE = 0x18; +``` + + +### SWEEP + +```solidity +uint256 constant SWEEP = 0x19; +``` + + +### MINT_6909 + +```solidity +uint256 constant MINT_6909 = 0x20; +``` + + +### BURN_6909 + +```solidity +uint256 constant BURN_6909 = 0x21; +``` + + diff --git a/docs/contracts/v4/reference/periphery/libraries/CalldataDecoder.md b/docs/contracts/v4/reference/periphery/libraries/CalldataDecoder.md new file mode 100644 index 000000000..4bba1d718 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/CalldataDecoder.md @@ -0,0 +1,236 @@ +# CalldataDecoder +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/CalldataDecoder.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## State Variables +### OFFSET_OR_LENGTH_MASK +mask used for offsets and lengths to ensure no overflow + +*no sane abi encoding will pass in an offset or length greater than type(uint32).max +(note that this does deviate from standard solidity behavior and offsets/lengths will +be interpreted as mod type(uint32).max which will only impact malicious/buggy callers)* + + +```solidity +uint256 constant OFFSET_OR_LENGTH_MASK = 0xffffffff; +``` + + +### OFFSET_OR_LENGTH_MASK_AND_WORD_ALIGN + +```solidity +uint256 constant OFFSET_OR_LENGTH_MASK_AND_WORD_ALIGN = 0xffffffe0; +``` + + +### SLICE_ERROR_SELECTOR +equivalent to SliceOutOfBounds.selector, stored in least-significant bits + + +```solidity +uint256 constant SLICE_ERROR_SELECTOR = 0x3b99b53d; +``` + + +## Functions +### decodeActionsRouterParams + +*equivalent to: abi.decode(params, (bytes, bytes[])) in calldata (requires strict abi encoding)* + + +```solidity +function decodeActionsRouterParams(bytes calldata _bytes) + internal + pure + returns (bytes calldata actions, bytes[] calldata params); +``` + +### decodeModifyLiquidityParams + +*equivalent to: abi.decode(params, (uint256, uint256, uint128, uint128, bytes)) in calldata* + + +```solidity +function decodeModifyLiquidityParams(bytes calldata params) + internal + pure + returns (uint256 tokenId, uint256 liquidity, uint128 amount0, uint128 amount1, bytes calldata hookData); +``` + +### decodeMintParams + +*equivalent to: abi.decode(params, (PoolKey, int24, int24, uint256, uint128, uint128, address, bytes)) in calldata* + + +```solidity +function decodeMintParams(bytes calldata params) + internal + pure + returns ( + PoolKey calldata poolKey, + int24 tickLower, + int24 tickUpper, + uint256 liquidity, + uint128 amount0Max, + uint128 amount1Max, + address owner, + bytes calldata hookData + ); +``` + +### decodeBurnParams + +*equivalent to: abi.decode(params, (uint256, uint128, uint128, bytes)) in calldata* + + +```solidity +function decodeBurnParams(bytes calldata params) + internal + pure + returns (uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData); +``` + +### decodeSwapExactInParams + +*equivalent to: abi.decode(params, (IV4Router.ExactInputParams))* + + +```solidity +function decodeSwapExactInParams(bytes calldata params) + internal + pure + returns (IV4Router.ExactInputParams calldata swapParams); +``` + +### decodeSwapExactInSingleParams + +*equivalent to: abi.decode(params, (IV4Router.ExactInputSingleParams))* + + +```solidity +function decodeSwapExactInSingleParams(bytes calldata params) + internal + pure + returns (IV4Router.ExactInputSingleParams calldata swapParams); +``` + +### decodeSwapExactOutParams + +*equivalent to: abi.decode(params, (IV4Router.ExactOutputParams))* + + +```solidity +function decodeSwapExactOutParams(bytes calldata params) + internal + pure + returns (IV4Router.ExactOutputParams calldata swapParams); +``` + +### decodeSwapExactOutSingleParams + +*equivalent to: abi.decode(params, (IV4Router.ExactOutputSingleParams))* + + +```solidity +function decodeSwapExactOutSingleParams(bytes calldata params) + internal + pure + returns (IV4Router.ExactOutputSingleParams calldata swapParams); +``` + +### decodeCurrency + +*equivalent to: abi.decode(params, (Currency)) in calldata* + + +```solidity +function decodeCurrency(bytes calldata params) internal pure returns (Currency currency); +``` + +### decodeCurrencyPair + +*equivalent to: abi.decode(params, (Currency, Currency)) in calldata* + + +```solidity +function decodeCurrencyPair(bytes calldata params) internal pure returns (Currency currency0, Currency currency1); +``` + +### decodeCurrencyPairAndAddress + +*equivalent to: abi.decode(params, (Currency, Currency, address)) in calldata* + + +```solidity +function decodeCurrencyPairAndAddress(bytes calldata params) + internal + pure + returns (Currency currency0, Currency currency1, address _address); +``` + +### decodeCurrencyAndAddress + +*equivalent to: abi.decode(params, (Currency, address)) in calldata* + + +```solidity +function decodeCurrencyAndAddress(bytes calldata params) internal pure returns (Currency currency, address _address); +``` + +### decodeCurrencyAddressAndUint256 + +*equivalent to: abi.decode(params, (Currency, address, uint256)) in calldata* + + +```solidity +function decodeCurrencyAddressAndUint256(bytes calldata params) + internal + pure + returns (Currency currency, address _address, uint256 amount); +``` + +### decodeCurrencyAndUint256 + +*equivalent to: abi.decode(params, (Currency, uint256)) in calldata* + + +```solidity +function decodeCurrencyAndUint256(bytes calldata params) internal pure returns (Currency currency, uint256 amount); +``` + +### decodeCurrencyUint256AndBool + +*equivalent to: abi.decode(params, (Currency, uint256, bool)) in calldata* + + +```solidity +function decodeCurrencyUint256AndBool(bytes calldata params) + internal + pure + returns (Currency currency, uint256 amount, bool boolean); +``` + +### toBytes + +Decode the `_arg`-th element in `_bytes` as `bytes` + + +```solidity +function toBytes(bytes calldata _bytes, uint256 _arg) internal pure returns (bytes calldata res); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_bytes`|`bytes`|The input bytes string to extract a bytes string from| +|`_arg`|`uint256`|The index of the argument to extract| + + +## Errors +### SliceOutOfBounds + +```solidity +error SliceOutOfBounds(); +``` + diff --git a/docs/contracts/v4/reference/periphery/libraries/ERC721PermitHash.md b/docs/contracts/v4/reference/periphery/libraries/ERC721PermitHash.md new file mode 100644 index 000000000..7a85b7ece --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/ERC721PermitHash.md @@ -0,0 +1,79 @@ +# ERC721PermitHash +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/ERC721PermitHash.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## State Variables +### PERMIT_TYPEHASH +*Value is equal to keccak256("Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline)");* + + +```solidity +bytes32 constant PERMIT_TYPEHASH = 0x49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad; +``` + + +### PERMIT_FOR_ALL_TYPEHASH +*Value is equal to keccak256("PermitForAll(address operator,bool approved,uint256 nonce,uint256 deadline)");* + + +```solidity +bytes32 constant PERMIT_FOR_ALL_TYPEHASH = 0x6673cb397ee2a50b6b8401653d3638b4ac8b3db9c28aa6870ffceb7574ec2f76; +``` + + +## Functions +### hashPermit + +Hashes the data that will be signed for IERC721Permit_v4.permit() + + +```solidity +function hashPermit(address spender, uint256 tokenId, uint256 nonce, uint256 deadline) + internal + pure + returns (bytes32 digest); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`spender`|`address`|The address which may spend the tokenId| +|`tokenId`|`uint256`|The tokenId of the owner, which may be spent by spender| +|`nonce`|`uint256`|A unique non-ordered value for each signature to prevent replay attacks| +|`deadline`|`uint256`|The time at which the signature expires| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`digest`|`bytes32`|The hash of the data to be signed; the equivalent to keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, nonce, deadline));| + + +### hashPermitForAll + +Hashes the data that will be signed for IERC721Permit_v4.permit() + + +```solidity +function hashPermitForAll(address operator, bool approved, uint256 nonce, uint256 deadline) + internal + pure + returns (bytes32 digest); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`operator`|`address`|The address which may spend any of the owner's tokenIds| +|`approved`|`bool`|true if the operator is to have full permission over the owner's tokenIds; false otherwise| +|`nonce`|`uint256`|A unique non-ordered value for each signature to prevent replay attacks| +|`deadline`|`uint256`|The time at which the signature expires| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`digest`|`bytes32`|The hash of the data to be signed; the equivalent to keccak256(abi.encode(PERMIT_FOR_ALL_TYPEHASH, operator, approved, nonce, deadline));| + + diff --git a/docs/contracts/v4/reference/periphery/libraries/Locker.md b/docs/contracts/v4/reference/periphery/libraries/Locker.md new file mode 100644 index 000000000..a1b62cf3d --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/Locker.md @@ -0,0 +1,31 @@ +# Locker +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/Locker.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +This is a temporary library that allows us to use transient storage (tstore/tload) +TODO: This library can be deleted when we have the transient keyword support in solidity. + + +## State Variables +### LOCKED_BY_SLOT + +```solidity +bytes32 constant LOCKED_BY_SLOT = 0x0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a; +``` + + +## Functions +### set + + +```solidity +function set(address locker) internal; +``` + +### get + + +```solidity +function get() internal view returns (address locker); +``` + diff --git a/docs/contracts/v4/reference/periphery/libraries/PathKey.md b/docs/contracts/v4/reference/periphery/libraries/PathKey.md new file mode 100644 index 000000000..c45203b92 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/PathKey.md @@ -0,0 +1,15 @@ +# PathKey +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/PathKey.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +```solidity +struct PathKey { + Currency intermediateCurrency; + uint24 fee; + int24 tickSpacing; + IHooks hooks; + bytes hookData; +} +``` + diff --git a/docs/contracts/v4/reference/periphery/libraries/PositionConfig.md b/docs/contracts/v4/reference/periphery/libraries/PositionConfig.md new file mode 100644 index 000000000..d337c1a39 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/PositionConfig.md @@ -0,0 +1,13 @@ +# PositionConfig +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/PositionConfig.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +```solidity +struct PositionConfig { + PoolKey poolKey; + int24 tickLower; + int24 tickUpper; +} +``` + diff --git a/docs/contracts/v4/reference/periphery/libraries/PositionConfigId.md b/docs/contracts/v4/reference/periphery/libraries/PositionConfigId.md new file mode 100644 index 000000000..42fd8b161 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/PositionConfigId.md @@ -0,0 +1,15 @@ +# PositionConfigId +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/PositionConfigId.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +A configId is set per tokenId +The lower 255 bits are used to store the truncated hash of the corresponding PositionConfig +The upper bit is used to signal if the tokenId has a subscriber + + +```solidity +struct PositionConfigId { + bytes32 id; +} +``` + diff --git a/docs/contracts/v4/reference/periphery/libraries/PositionInfoLibrary.md b/docs/contracts/v4/reference/periphery/libraries/PositionInfoLibrary.md new file mode 100644 index 000000000..bce95c32a --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/PositionInfoLibrary.md @@ -0,0 +1,139 @@ +# PositionInfoLibrary +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/PositionInfoLibrary.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## State Variables +### EMPTY_POSITION_INFO + +```solidity +PositionInfo internal constant EMPTY_POSITION_INFO = PositionInfo.wrap(0); +``` + + +### MASK_UPPER_200_BITS + +```solidity +uint256 internal constant MASK_UPPER_200_BITS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000; +``` + + +### MASK_8_BITS + +```solidity +uint256 internal constant MASK_8_BITS = 0xFF; +``` + + +### MASK_24_BITS + +```solidity +uint24 internal constant MASK_24_BITS = 0xFFFFFF; +``` + + +### SET_UNSUBSCRIBE + +```solidity +uint256 internal constant SET_UNSUBSCRIBE = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00; +``` + + +### SET_SUBSCRIBE + +```solidity +uint256 internal constant SET_SUBSCRIBE = 0x01; +``` + + +### TICK_LOWER_OFFSET + +```solidity +uint8 internal constant TICK_LOWER_OFFSET = 8; +``` + + +### TICK_UPPER_OFFSET + +```solidity +uint8 internal constant TICK_UPPER_OFFSET = 32; +``` + + +## Functions +### poolId + +*This poolId is NOT compatible with the poolId used in UniswapV4 core. It is truncated to 25 bytes, and just used to lookup PoolKey in the poolKeys mapping.* + + +```solidity +function poolId(PositionInfo info) internal pure returns (bytes25 _poolId); +``` + +### tickLower + + +```solidity +function tickLower(PositionInfo info) internal pure returns (int24 _tickLower); +``` + +### tickUpper + + +```solidity +function tickUpper(PositionInfo info) internal pure returns (int24 _tickUpper); +``` + +### hasSubscriber + + +```solidity +function hasSubscriber(PositionInfo info) internal pure returns (bool _hasSubscriber); +``` + +### setSubscribe + +*this does not actually set any storage* + + +```solidity +function setSubscribe(PositionInfo info) internal pure returns (PositionInfo _info); +``` + +### setUnsubscribe + +*this does not actually set any storage* + + +```solidity +function setUnsubscribe(PositionInfo info) internal pure returns (PositionInfo _info); +``` + +### initialize + +Creates the default PositionInfo struct + +*Called when minting a new position* + + +```solidity +function initialize(PoolKey memory _poolKey, int24 _tickLower, int24 _tickUpper) + internal + pure + returns (PositionInfo info); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_poolKey`|`PoolKey`|the pool key of the position| +|`_tickLower`|`int24`|the lower tick of the position| +|`_tickUpper`|`int24`|the upper tick of the position| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`info`|`PositionInfo`|packed position info, with the truncated poolId and the hasSubscriber flag set to false| + + diff --git a/docs/contracts/v4/reference/periphery/libraries/QuoterRevert.md b/docs/contracts/v4/reference/periphery/libraries/QuoterRevert.md new file mode 100644 index 000000000..0560e94de --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/QuoterRevert.md @@ -0,0 +1,57 @@ +# QuoterRevert +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/QuoterRevert.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + + +## Functions +### revertQuote + +reverts, where the revert data is the provided bytes + +*called when quoting, to record the quote amount in an error* + +*QuoteSwap is used to differentiate this error from other errors thrown when simulating the swap* + + +```solidity +function revertQuote(uint256 quoteAmount) internal pure; +``` + +### bubbleReason + +reverts using the revertData as the reason + +*to bubble up both the valid QuoteSwap(amount) error, or an alternative error thrown during simulation* + + +```solidity +function bubbleReason(bytes memory revertData) internal pure; +``` + +### parseQuoteAmount + +validates whether a revert reason is a valid swap quote or not +if valid, it decodes the quote to return. Otherwise it reverts. + + +```solidity +function parseQuoteAmount(bytes memory reason) internal pure returns (uint256 quoteAmount); +``` + +## Errors +### UnexpectedRevertBytes +error thrown when invalid revert bytes are thrown by the quote + + +```solidity +error UnexpectedRevertBytes(bytes revertData); +``` + +### QuoteSwap +error thrown containing the quote as the data, to be caught and parsed later + + +```solidity +error QuoteSwap(uint256 amount); +``` + diff --git a/docs/contracts/v4/reference/periphery/libraries/SlippageCheck.md b/docs/contracts/v4/reference/periphery/libraries/SlippageCheck.md new file mode 100644 index 000000000..fd99a8c10 --- /dev/null +++ b/docs/contracts/v4/reference/periphery/libraries/SlippageCheck.md @@ -0,0 +1,59 @@ +# SlippageCheck +[Git Source](https://github.com/Uniswap/v4-periphery/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/libraries/SlippageCheck.sol) +| Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc) + +a library for checking if a delta exceeds a maximum ceiling or fails to meet a minimum floor + + +## Functions +### validateMinOut + +Revert if one or both deltas does not meet a minimum output + +*This should be called when removing liquidity (burn or decrease)* + + +```solidity +function validateMinOut(BalanceDelta delta, uint128 amount0Min, uint128 amount1Min) internal pure; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`delta`|`BalanceDelta`|The principal amount of tokens to be removed, does not include any fees accrued| +|`amount0Min`|`uint128`|The minimum amount of token0 to receive| +|`amount1Min`|`uint128`|The minimum amount of token1 to receive| + + +### validateMaxIn + +Revert if one or both deltas exceeds a maximum input + +*This should be called when adding liquidity (mint or increase)* + + +```solidity +function validateMaxIn(BalanceDelta delta, uint128 amount0Max, uint128 amount1Max) internal pure; +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`delta`|`BalanceDelta`|The principal amount of tokens to be added, does not include any fees accrued (which is possible on increase)| +|`amount0Max`|`uint128`|The maximum amount of token0 to spend| +|`amount1Max`|`uint128`|The maximum amount of token1 to spend| + + +## Errors +### MaximumAmountExceeded + +```solidity +error MaximumAmountExceeded(uint128 maximumAmount, uint128 amountRequested); +``` + +### MinimumAmountInsufficient + +```solidity +error MinimumAmountInsufficient(uint128 minimumAmount, uint128 amountReceived); +``` + diff --git a/docs/contracts/v4/reference/periphery/positionmanager.mdx b/docs/contracts/v4/reference/periphery/positionmanager.mdx deleted file mode 100644 index b27831762..000000000 --- a/docs/contracts/v4/reference/periphery/positionmanager.mdx +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: PositionManager ---- - -... in progress, please see [mint position](../../guides/02-manage-liquidity/01-mint-position.mdx) \ No newline at end of file diff --git a/scripts/v4-forge-doc.sh b/scripts/v4-forge-doc.sh new file mode 100755 index 000000000..3f0dcecd0 --- /dev/null +++ b/scripts/v4-forge-doc.sh @@ -0,0 +1,58 @@ +# Usage: ./scripts/v4-forge-doc.sh, called from the root directory + +# regenerate docs +forge doc --root submodules/v4-core --out forge-docs/v4-core +rm -rf submodules/v4-core/forge-docs +forge doc --root submodules/v4-periphery --out forge-docs/v4-periphery +rm -rf submodules/v4-periphery/forge-docs + +copy_docs() { + local component=$1 + + find "forge-docs/v4-$component/src" -type f -regex '.*\.sol/[^.]*\.[^.]*\.md' | while read file; do + # Extract the directory part (e.g., base, base/hooks, libraries) + dir_structure=$(echo "$file" | sed -r 's|.*/src/([^/]+)/.*\.sol/.*|\1|') + + # if dir_structure is src, remove it so it appears at the root level + if [ "$dir_structure" == "src" ]; then + dir_structure="" + fi + + # Extract the base filename without the path and extension (e.g., Multicall_v4, BaseHook, Locker) + base_filename=$(echo "$file" | sed -r 's|.*/([^/]+)\.sol/[^/]*\.(.*)\.md|\1|') + + # Construct the new file path + new_file="docs/contracts/v4/reference/${component}/${dir_structure}/${base_filename}.md" + + # Create the new directory structure if it doesn't exist + mkdir -p "docs/contracts/v4/reference/${component}/${dir_structure}" + + # Copy the file to the new location + cp "$file" "$new_file" + + # Fix the Git source link + # replace `https://github.com/Uniswap/docs/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IPositionManager.sol` + # with `https://github.com/Uniswap/v4-{component}/blob/47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b/src/interfaces/IPositionManager.sol` + sed -i "s|Uniswap/docs/|Uniswap/v4-${component}/|g" "$new_file" + + # Add note: + sed -i '3i | Generated with [forge doc](https://book.getfoundry.sh/reference/forge/forge-doc)' "$new_file" + + # Replace relative path links within the file with full paths + sed -i "s|/src/\([^/]\+\)/\([^/]\+\)\.sol/\([^/]\+\)\.\([^/]\+\)\.md|contracts/v4/reference/${component}/\1/\2.md|g" "$new_file" + + # specially handle core paths + if [ "$component" == "core" ]; then + # replaces: /src/ProtocolFees.sol/abstract.ProtocolFees.md to contracts/v4/reference/core/ProtocolFees.md + sed -i -E 's|/src/([^/]+)\.sol/abstract\.[^/]+\.md|contracts/v4/reference/core/\1.md|g' "$new_file" + + # replaces: /src/interfaces/external/IERC6909Claims.sol/interface.IERC6909Claims.md to contracts/v4/reference/core/interfaces/IERC6909Claims.md + sed -i -E 's|/src/interfaces/external/([^/]+)\.sol/interface\.[^/]+\.md|contracts/v4/reference/core/interfaces/\1.md|g' "$new_file" + fi + + echo "Copied: $file -> $new_file" + done +} + +copy_docs "periphery" +copy_docs "core" \ No newline at end of file diff --git a/submodules/v4-core b/submodules/v4-core new file mode 160000 index 000000000..1141642f8 --- /dev/null +++ b/submodules/v4-core @@ -0,0 +1 @@ +Subproject commit 1141642f8ba4665a50660886a8a8401526677045 diff --git a/submodules/v4-periphery b/submodules/v4-periphery new file mode 160000 index 000000000..47e3c30ae --- /dev/null +++ b/submodules/v4-periphery @@ -0,0 +1 @@ +Subproject commit 47e3c30ae8a0d7c086bf3e41bd0e7e3a854e280b