Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
UniswapV3Pool
copy icon
Uniswap-Labs
• version 1.0.0
Token
ERC20
DEX

UniswapV3Pool

Create a Uniswap Pool, and facilitate swaps between tokens. Uniswap V3 supports: -Arbitrary token pools -Range defined liquidity providing -Liquidity Providers receive an NFT with their position -More gas efficient token swapping

*Visit desktop site to download or deploy

Version

1.0.0

Recent Use

🍞 0x6860 downloaded

Last Publish

1/13/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
checkTicks(int24,int24) :
This function checks that the given tickLower and tickUpper values are valid. It requires that tickLower is less than tickUpper, that tickLower is greater than or equal to the minimum tick value, and that tickUpper is less than or equal to the maximum tick value. If any of these conditions are not met, an error is thrown. (autogenerated documentation)
_blockTimestamp() :
This function is an internal view function that returns the timestamp of the current block. It works by using the block.timestamp property of the Ethereum Virtual Machine to return the timestamp of the current block as a uint32. (autogenerated documentation)
balance0() :
This function is a private view function that retrieves the balance of the contract from the token0 contract. It uses the staticcall function to call the balanceOf function from the IERC20Minimal interface, passing in the address of the contract as an argument. The function then requires that the call was successful and that the data returned is at least 32 bytes long. Finally, it decodes the data and returns the balance as a uint256. (autogenerated documentation)
balance1() :
This function is a private view function that retrieves the balance of the contract from the token1 contract. It uses the staticcall function to call the balanceOf function from the IERC20Minimal interface, passing in the address of the contract as an argument. The function then requires that the call was successful and that the data returned is at least 32 bytes long. Finally, it decodes the data and returns the balance as a uint256. (autogenerated documentation)
snapshotCumulativesInside(int24,int24) :
This function takes two 24-bit integers (tickLower and tickUpper) as input and returns three values: tickCumulativeInside, secondsPerLiquidityInsideX128, and secondsInside. It is used to calculate the cumulative tick count, the cumulative liquidity-adjusted seconds, and the cumulative seconds between two given ticks. The function first checks that the two input ticks are valid. It then retrieves the tickCumulativeOutside, secondsPerLiquidityOutsideX128, and secondsOutside values for both the lower and upper ticks from the ticks storage array. It then checks the current slot0 tick to determine which of the three possible scenarios is applicable: 1. If the slot0 tick is (autogenerated documentation)
observe(uint32[]) :
This function allows users to observe the liquidity of the contract over a given period of time. It takes an array of uint32 values representing the number of seconds ago that the user wishes to observe the liquidity. It then returns two arrays, one containing the tick cumulatives and one containing the seconds per liquidity cumulative x128s. The function uses the _blockTimestamp() to determine the current block timestamp, the slot0.tick, slot0.observationIndex, liquidity, and slot0.observationCardinality to calculate the tick cumulatives and seconds per liquidity cumulative x128s. (autogenerated documentation)
increaseObservationCardinalityNext(uint16) :
This function increases the observationCardinalityNext of the slot0 contract. It takes in a uint16 argument, observationCardinalityNext, and uses the grow() function from the observations contract to increase the observationCardinalityNext of the slot0 contract. If the observationCardinalityNext is successfully increased, an IncreaseObservationCardinalityNext event is emitted. (autogenerated documentation)
initialize(uint160) :
This function initializes the contract by setting the sqrtPriceX96, tick, observationIndex, observationCardinality, observationCardinalityNext, feeProtocol, and unlocked variables. It uses the TickMath.getTickAtSqrtRatio() function to calculate the tick value based on the sqrtPriceX96 parameter. It also uses the observations.initialize() function to calculate the observationCardinality and observationCardinalityNext values. Finally, it emits an Initialize event with the sqrtPriceX96 and tick values. (autogenerated documentation)
_modifyPosition() :
This function is used to modify the position of a user in the market. It takes in a ModifyPositionParams memory struct containing the owner, tickLower, tickUpper, and liquidityDelta. It then checks that the tickLower and tickUpper are valid. It then updates the position of the user and calculates the amount0 and amount1 based on the liquidityDelta. If the liquidityDelta is not 0, it will then write an observation to the observations array and update the liquidity. (autogenerated documentation)
_updatePosition(address,int24,int24,int128,int24) :
This function updates the position of an owner in the market. It takes in the address of the owner, the lower and upper tick values, the liquidity delta, and the tick value as parameters. It then calculates the fee growth inside the tick range, updates the position of the owner, and flips the tick values if necessary. Finally, it clears the tick values if the liquidity delta is negative. (autogenerated documentation)
mint(address,int24,int24,uint128) :
This function mints a new position in the UniswapV3 contract. It takes in an address of the recipient, a lower and upper tick value, an amount of tokens to mint, and an optional data parameter. It then calls the _modifyPosition function to modify the position, and emits a Mint event. It also calls the IUniswapV3MintCallback function to execute any additional logic. Finally, it checks that the balances of the tokens have increased by the amount specified. (autogenerated documentation)
collect(address,int24,int24,uint128,uint128) :
This function allows a user to collect tokens from a position they have opened in the contract. It takes in the address of the recipient, the lower and upper bounds of the tick, and the amount of tokens requested for each token type. It then checks the position storage to see if the requested amount is greater than the amount owed, and if so, sets the amount to the amount owed. It then transfers the tokens to the recipient and emits an event. (autogenerated documentation)
burn(int24,int24,uint128) :
This function is used to burn tokens from a position in the Position contract. It takes in three parameters: tickLower, tickUpper, and amount. It then calculates the amount of tokens owed for each token in the position, subtracts the amount from the position, and emits a Burn event. (autogenerated documentation)
swap(address,bool,int256,uint160) :
This function is used to swap tokens between two parties. It takes in the address of the recipient, a boolean value indicating whether the swap is a zero-for-one swap, the amount of tokens to be swapped, a price limit, and any additional data that may be needed. It then checks that the amount specified is not zero, that the slot is unlocked, and that the price limit is within the acceptable range. It then sets the slot to be locked and initializes a SwapCache and SwapState. It then enters a loop that computes the swap step, updates the state, and checks for any changes in the price or liquidity. Once the loop is finished, it updates the slot, transfers any tokens that need to be (autogenerated documentation)
flash(address,uint256,uint256) :
This function is used to transfer tokens from the UniswapV3 contract to a recipient address. It takes in four parameters: the recipient address, the amount of token0 to be transferred, the amount of token1 to be transferred, and an optional data parameter. It first checks that the liquidity of the contract is greater than 0, and then calculates the fees for each token based on the fee rate. It then transfers the tokens to the recipient address, and calls the IUniswapV3FlashCallback contract to process the fees. Finally, it updates the protocol fees and fee growth global variables, and emits a Flash event. (autogenerated documentation)
setFeeProtocol(uint8,uint8) :
This function sets the fee protocol for the contract. It takes two uint8 parameters, feeProtocol0 and feeProtocol1, and requires that both of them are either 0 or between 4 and 10. It then stores the two parameters in slot0.feeProtocol, and emits an event with the old and new fee protocols. (autogenerated documentation)
collectProtocol(address,uint128,uint128) :
This function collects protocol fees from the Factory contract. It takes in three parameters: the address of the recipient, the amount of token 0 requested, and the amount of token 1 requested. It then checks if the requested amounts are greater than the protocol fees available, and if so, sets the amount to the protocol fees available. It then transfers the amount of token 0 and token 1 to the recipient, and emits an event to log the transaction. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i UniswapV3Pool
copy icon

Recent Use

🍞 0x6860 downloaded

Last Publish

1/13/2023

Version

1.0.0

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.