Skip to content

hedge jit [idea] #1

@0xbigz

Description

@0xbigz
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions