Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/decrease_position_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn decrease_position(env: &Env, p: &DecreasePositionParams) -> DecreasePosit
let size_delta_usd = p.size_delta_usd.min(position.size_in_usd);

// 2. Update market funding + borrowing state
let index_price_mid = p.index_token_price.mid_price();
let index_price_mid = p.index_token_price.pick_price_for_pnl(p.is_long, false);
update_funding_state(
env,
p.data_store,
Expand Down
2 changes: 1 addition & 1 deletion libs/increase_position_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn increase_position(env: &Env, p: &IncreasePositionParams) -> PositionProps
// and price-impact pool writes are omitted to stay within Soroban's 40 ledger-entry
// read budget. Funding/borrowing rates are zero when OI is zero (empty market), and
// position open/close operations will refresh them once OI exists.
let index_price = p.index_token_price.mid_price();
let index_price = p.index_token_price.pick_price_for_pnl(p.is_long, true);
let impact_usd: i128 = 0; // price impact skipped to save ledger entries

// Execution price (no impact)
Expand Down
15 changes: 15 additions & 0 deletions tests/static_execution_price_spread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path


INCREASE = Path("libs/increase_position_utils/src/lib.rs").read_text()
DECREASE = Path("libs/decrease_position_utils/src/lib.rs").read_text()


def test_increase_uses_worst_case_spread_side():
assert "pick_price_for_pnl(p.is_long, true)" in INCREASE
assert "let index_price = p.index_token_price.mid_price();" not in INCREASE


def test_decrease_uses_inverse_spread_side():
assert "pick_price_for_pnl(p.is_long, false)" in DECREASE
assert "let index_price_mid = p.index_token_price.mid_price();" not in DECREASE