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:
- compute gap
(spot token amount * spot_hedge_factor) vs perp position base amount + maker_base_asset_amount
- do
begin_swap + end_swap for "SPOT"/USDC pair (up to maker_base_asset_amount s.t. it closes this gap)
- calculate price of this swap, $P_{swap}$, and multiply by
spot_hedge_factor
- 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
jit params could include
max_base_per_fill: as a mitigation for high swap price impactspot_market_index: spot market legperp_market_index: perp market legspot_hedge_factor: multiplier for acceptable fill price on hedge legfor 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 amountandperp position base amounton each jit crank:
(spot token amount * spot_hedge_factor)vsperp position base amount+maker_base_asset_amountbegin_swap+end_swapfor "SPOT"/USDC pair (up tomaker_base_asset_amounts.t. it closes this gap)spot_hedge_factormaker_base_asset_amount, otherwise failthe worst thing that can happen:
example: SOL-PERP maker who hedges with mSOL
spot_hedge_factor=1/1.112) mSOL -> USDC @ $17.817.8 * 1/1.112, fulfill 1 SOL-PERP long