Skip to content

Commit

Permalink
added way to get liquidity when minting new position
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericselvig committed Nov 25, 2024
1 parent d810a93 commit 7deb611
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 121 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"solidity.compileUsingRemoteVersion": "v0.8.26+commit.8a97fa7a",
"solidity.defaultCompiler": "localNodeModule"
"solidity.defaultCompiler": "localNodeModule",
"solidity.compileUsingLocalVersion": "/home/eric/JIT-Hook/soljson-v0.8.26+commit.8a97fa7a.js"
}
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ hardhat/=lib/v4-core/node_modules/hardhat/
openzeppelin-contracts/=lib/openzeppelin-contracts/
permit2/=lib/v4-periphery/lib/permit2/
solmate/=lib/v4-core/lib/solmate/
v4-core/=lib/v4-periphery/lib/v4-core/src/
v4-core/=lib/v4-periphery/lib/v4-core/
v4-periphery/=lib/v4-periphery/
@chainlink/=lib/chainlink-brownie-contracts/
111 changes: 0 additions & 111 deletions soljson-v0.8.26+commit.8a97fa7a.js

This file was deleted.

25 changes: 17 additions & 8 deletions src/JITHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
pragma solidity 0.8.26;

import {BaseHook} from "v4-periphery/src/base/hooks/BaseHook.sol";
import {IPoolManager} from "v4-core/interfaces/IPoolManager.sol";
import {Hooks} from "v4-core/libraries/Hooks.sol";
import {PoolId, PoolIdLibrary} from "v4-core/types/PoolId.sol";
import {PoolKey} from "v4-core/types/PoolKey.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "v4-core/types/BeforeSwapDelta.sol";
import {BalanceDelta} from "v4-core/types/BalanceDelta.sol";
import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";
import {Hooks} from "v4-core/src/libraries/Hooks.sol";
import {PoolId, PoolIdLibrary} from "v4-core/src/types/PoolId.sol";
import {PoolKey} from "v4-core/src/types/PoolKey.sol";
import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "v4-core/src/types/BeforeSwapDelta.sol";
import {BalanceDelta} from "v4-core/src/types/BalanceDelta.sol";
import {ERC20} from "solmate/src/tokens/ERC20.sol";
import {Currency, CurrencyLibrary} from "v4-core/types/Currency.sol";
import {Currency, CurrencyLibrary} from "v4-core/src/types/Currency.sol";
import {IStrategiesController} from "./interfaces/IStrategiesController.sol";
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
import {IStrategy} from "./interfaces/IStrategy.sol";
import {IPositionManager} from "v4-periphery/src/interfaces/IPositionManager.sol";
import {Actions} from "v4-periphery/src/libraries/Actions.sol";
import {LiquidityAmounts} from "v4-core/test/utils/LiquidityAmounts.sol";
import {TickMath} from "v4-core/src/libraries/TickMath.sol";

contract JITHook is BaseHook {
using PoolIdLibrary for PoolId;
Expand Down Expand Up @@ -164,7 +166,6 @@ contract JITHook is BaseHook {
PoolKey memory key,
int24 tickLower,
int24 tickUpper,
int256 liquidity,
uint128 amount0Max,
uint128 amount1Max
) internal returns (int256 liquidityDelta) {
Expand All @@ -173,6 +174,14 @@ contract JITHook is BaseHook {
Actions.SETTLE_PAIR
);
bytes[] memory params = new bytes[](2);

int256 liquidity = LiquidityAmounts.getLiquidityForAmounts(
TickMath.getSqrtRatioAtTick(tickLower),
TickMath.getSqrtRatioAtTick(tickUpper),
amount0Max,
amount1Max
);

params[0] = abi.encode(
key,
tickLower,
Expand Down

0 comments on commit 7deb611

Please sign in to comment.