liquidity manager compiles
This commit is contained in:
parent
acec4c4c57
commit
1204943718
2 changed files with 15 additions and 21 deletions
|
|
@ -1,3 +1,3 @@
|
||||||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
|
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
|
||||||
@uniswap/v3-core/=lib/v3-core/
|
@uniswap/v3-core/=lib/v3-core/
|
||||||
@uniswap/v3-periphery/=lib/v3-periphery-foundry/
|
@uniswap/v3-periphery/=lib/v3-periphery/
|
||||||
|
|
|
||||||
|
|
@ -140,20 +140,13 @@ contract LiquidityManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Add liquidity to an initialized pool
|
/// @notice Add liquidity to an initialized pool
|
||||||
function addLiquidity(AddLiquidityParams memory params)
|
function addLiquidity(AddLiquidityParams memory params) external checkDeadline(params.deadline) {
|
||||||
external
|
|
||||||
checkDeadline(params.deadline)
|
|
||||||
returns (
|
|
||||||
uint128 liquidity,
|
|
||||||
uint256 amount0,
|
|
||||||
uint256 amount1
|
|
||||||
)
|
|
||||||
{
|
|
||||||
PoolAddress.PoolKey memory poolKey =
|
PoolAddress.PoolKey memory poolKey =
|
||||||
PoolAddress.PoolKey({token0: params.token0, token1: params.token1, fee: FEE});
|
PoolAddress.PoolKey({token0: params.token0, token1: params.token1, fee: FEE});
|
||||||
IUniswapV3Pool pool = IUniswapV3Pool(PoolAddress.computeAddress(factory, poolKey));
|
IUniswapV3Pool pool = IUniswapV3Pool(PoolAddress.computeAddress(factory, poolKey));
|
||||||
|
|
||||||
// compute the liquidity amount
|
// compute the liquidity amount
|
||||||
|
uint128 liquidity;
|
||||||
{
|
{
|
||||||
(uint160 sqrtPriceX96, , , , , , ) = pool.slot0();
|
(uint160 sqrtPriceX96, , , , , , ) = pool.slot0();
|
||||||
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(params.tickLower);
|
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(params.tickLower);
|
||||||
|
|
@ -168,15 +161,19 @@ contract LiquidityManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
(amount0, amount1) = pool.mint(
|
(bool token0isWeth, address token) = getToken(params.token0, params.token1);
|
||||||
address(this),
|
{
|
||||||
params.tickLower,
|
(uint256 amount0, uint256 amount1) = pool.mint(
|
||||||
params.tickUpper,
|
address(this),
|
||||||
liquidity,
|
params.tickLower,
|
||||||
abi.encode(poolKey)
|
params.tickUpper,
|
||||||
);
|
liquidity,
|
||||||
|
abi.encode(poolKey)
|
||||||
|
);
|
||||||
|
|
||||||
require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, 'Price slippage check');
|
require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, 'Price slippage check');
|
||||||
|
emit IncreaseLiquidity(token, liquidity, amount0, amount1);
|
||||||
|
}
|
||||||
|
|
||||||
bytes32 positionKey = PositionKey.compute(address(this), params.tickLower, params.tickUpper);
|
bytes32 positionKey = PositionKey.compute(address(this), params.tickLower, params.tickUpper);
|
||||||
|
|
||||||
|
|
@ -184,7 +181,6 @@ contract LiquidityManager {
|
||||||
(, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, , ) = pool.positions(positionKey);
|
(, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, , ) = pool.positions(positionKey);
|
||||||
|
|
||||||
|
|
||||||
(bool token0isWeth, address token) = getToken(params.token0, params.token1);
|
|
||||||
TokenPosition memory position = _positions[posKey(token, params.tickLower, params.tickUpper)];
|
TokenPosition memory position = _positions[posKey(token, params.tickLower, params.tickUpper)];
|
||||||
if (liquidity == 0) {
|
if (liquidity == 0) {
|
||||||
// create entry
|
// create entry
|
||||||
|
|
@ -213,8 +209,6 @@ contract LiquidityManager {
|
||||||
position.feeGrowthInside1LastX128 = feeGrowthInside1LastX128;
|
position.feeGrowthInside1LastX128 = feeGrowthInside1LastX128;
|
||||||
position.liquidity += liquidity;
|
position.liquidity += liquidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit IncreaseLiquidity(token, liquidity, amount0, amount1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
|
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue