Skip to content

Commit

Permalink
added basic comments on hedge
Browse files Browse the repository at this point in the history
  • Loading branch information
roigecode committed Sep 17, 2024
1 parent 726c21e commit 3b718bb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.**

Expand Down
10 changes: 10 additions & 0 deletions src/Hedge/hedge-manager.sol
Original file line number Diff line number Diff line change
@@ -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


}
}
37 changes: 37 additions & 0 deletions src/Hook/univ4-risk-neutral-hook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
///////////////////
Expand Down

0 comments on commit 3b718bb

Please sign in to comment.