From 3b718bb163cc8843d156d037d5c0aab3925ac01a Mon Sep 17 00:00:00 2001 From: roigecode Date: Tue, 17 Sep 2024 08:42:40 +0200 Subject: [PATCH] added basic comments on hedge --- README.md | 2 +- src/Hedge/hedge-manager.sol | 10 ++++++++ src/Hook/univ4-risk-neutral-hook.sol | 37 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/Hedge/hedge-manager.sol diff --git a/README.md b/README.md index 9265b45..2cadad2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Foundry +## Uniswap v4 Risk Neutral Hook **Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** diff --git a/src/Hedge/hedge-manager.sol b/src/Hedge/hedge-manager.sol new file mode 100644 index 0000000..4a01c16 --- /dev/null +++ b/src/Hedge/hedge-manager.sol @@ -0,0 +1,10 @@ +pragma solidity ^0.8.19; + +contract HedgeManager { + function modifyHedgePosition(uint256 priceMovement) external onlyOwner{ + // Detect from mapping if LP is delta-gamma hedge with a power-perp or future / borrowing + // Change accordingly to price movement and rebalance threshold if only delta-neutral + + + } +} \ No newline at end of file diff --git a/src/Hook/univ4-risk-neutral-hook.sol b/src/Hook/univ4-risk-neutral-hook.sol index f7e05c7..f36734a 100644 --- a/src/Hook/univ4-risk-neutral-hook.sol +++ b/src/Hook/univ4-risk-neutral-hook.sol @@ -9,6 +9,7 @@ import {PoolKey} from "v4-core/types/PoolKey.sol"; import {BalanceDelta} from "v4-core/types/BalanceDelta.sol"; import {LPFeeLibrary} from "v4-core/libraries/LPFeeLibrary.sol"; import {BeforeSwapDelta, BeforeSwapDeltaLibrary} from "v4-core/types/BeforeSwapDelta.sol"; +import {HedgeManager} from "v4-hedge/src/HedgeManager.sol"; // OpenZeppelin imports for access control import "@openzeppelin/contracts/access/Ownable.sol"; @@ -95,6 +96,21 @@ contract univ4riskneutralhook is BaseHook, Ownable { // Nonce to generate unique swapId and avoid collisions uint256 private swapNonce; + // Re-hedge params + struct LpGreeks { + int256 delta; + int256 gamma; + } + + struct LpHedge { + bool isHedged; + bool isPowerPerp; + bool isBorrowing; + } + + // Hedge Manager + HedgeManager hedgeManager; + /** * @notice Constructor that initializes the hook and sets the oracle addresses. * @param _poolManager Address of the Uniswap v4 PoolManager. @@ -309,6 +325,12 @@ contract univ4riskneutralhook is BaseHook, Ownable { // Emit post-swap adjustment event // emit SwapAdjusted(poolAddress, adjustment); + // Adjust LP Greeks + // updateLpGreeks(); + + // Re-hedge positions accordingly + // hedgeManager.modifyHedgePosition(); + // Update the gas price moving average with the gas price of this swap updateMovingAverage(); @@ -647,6 +669,21 @@ contract univ4riskneutralhook is BaseHook, Ownable { } + // TODO: Compute LP Greeks + function computeLpGreeks() internal view { + // Calculate delta and gamma for LPs + // for(uint 256 i=0; i<=L) { + // uint256 deltaLp = L*(1/sqrt(p) - 1/sqrt(p_b)) + // uint256 gammaLp = 0.5*L*p**(-3/2) + + // Buy + + // unchecked { + // ++i; + // } + //} + } + /////////////////// // Brevis ///////////////////