Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hedge jit [idea] #1

Open
0xbigz opened this issue Jun 24, 2023 · 0 comments
Open

hedge jit [idea] #1

0xbigz opened this issue Jun 24, 2023 · 0 comments

Comments

@0xbigz
Copy link
Member

0xbigz commented Jun 24, 2023

pub struct JitParams {
    pub taker_order_id: u32,
    pub max_position: i64,
    pub worst_price: u64,
    pub post_only: Option<PostOnlyParam>,
}

jit params could include

  • max_base_per_fill: as a mitigation for high swap price impact
  • spot_market_index: spot market leg
  • perp_market_index: perp market leg
  • spot_hedge_factor: multiplier for acceptable fill price on hedge leg

for a specific taker_order, you can calculate the maker_base_asset_amount (based on the taker unfilled + position/trade constraints)

inspect the current spot token amount and perp position base amount

on each jit crank:

  1. compute gap (spot token amount * spot_hedge_factor) vs perp position base amount + maker_base_asset_amount
  2. do begin_swap + end_swap for "SPOT"/USDC pair (up to maker_base_asset_amount s.t. it closes this gap)
  3. calculate price of this swap, $P_{swap}$, and multiply by spot_hedge_factor
  4. if user's auction price is better maker, then fill base amount up to maker_base_asset_amount, otherwise fail

the worst thing that can happen:

  • the perp pnl is sufficiently negative and starts to open expensive usdc borrow (potentially risking liquidation)
  • the initial deposit for this strategy is not USDC, the delta hedge logic would need to examine spot hedge gap and fix
  • filling users better than oracle enough could lead to hourly funding rate out of favor for maker

example: SOL-PERP maker who hedges with mSOL

  • deposit 100 USDC, enable margin trading
  • watch user accounts with auction orders (using memcpy for rpc get program accounts)
  • attempt to fulfill 1 SOL-PERP long at 1 bps better than oracle (maker short)
  • margin borrow 1 * (spot_hedge_factor=1/1.112) mSOL -> USDC @ $17.8
  • if auction price > 17.8 * 1/1.112, fulfill 1 SOL-PERP long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant