Prevent Position Decrease from reducing a position below a configured size reserve #43

Closed
opened 2026-07-25 19:34:44 +02:00 by minimons · 0 comments
Owner

Background

A Position Decrease can currently reduce an open Jupiter Perps position completely to zero.

We need a configurable minimum remaining position size so Evelyn can retain part of the position.

The reserve must be based on the position's USD size, not its collateral amount.

For example:

Collateral: 1 USDC
Leverage:   10x
Size:       10 USD

The Position Decrease therefore represents a $10 reduction of the position size. It is this $10 size reduction that must be used when checking the reserve.

Configuration

Add a mandatory top-level configuration field:

RESERVE_POSITION_SIZE_USD_LIMIT 10

The value defines the minimum sizeUsd that must remain after a Position Decrease.

A value of 0 explicitly disables the reserve and permits the position to be reduced completely to zero.

Missing, duplicate or negative values must cause a clear configuration error.

Behavior

Before building, signing or submitting a Position Decrease transaction, calculate:

remainingPositionSize =
        currentPositionSizeUsd - decreaseSizeUsd

The decrease may only continue when:

remainingPositionSize >= RESERVE_POSITION_SIZE_USD_LIMIT

This is equivalent to requiring:

currentPositionSizeUsd >=
        decreaseSizeUsd + RESERVE_POSITION_SIZE_USD_LIMIT

decreaseSizeUsd must be the resolved position size reduction derived from the configured collateral and leverage. The collateral amount alone must not be used for this check.

If the decrease would leave the position below the configured reserve, skip the entire action. Do not automatically reduce or otherwise modify the requested decrease amount.

Log a clear message containing:

  • The current position size
  • The requested position size decrease
  • The configured reserve
  • The resulting position size

Examples

With:

RESERVE_POSITION_SIZE_USD_LIMIT 10
  • Position size $30, decrease size $10 → continue; $20 remains.
  • Position size $20, decrease size $10 → continue; exactly $10 remains.
  • Position size $15, decrease size $10 → skip; only $5 would remain.
  • Position size $10, decrease size $10 → skip; the position would be closed.

Acceptance criteria

  • RESERVE_POSITION_SIZE_USD_LIMIT is mandatory.
  • Zero is allowed and disables the reserve.
  • Negative values, duplicate definitions and missing values are rejected.
  • The check uses the decrease's calculated sizeUsd, including leverage.
  • The check uses the current position's sizeUsd, not its collateral.
  • A decrease leaving exactly the configured reserve is allowed.
  • A decrease leaving less than the reserve is skipped before any Jupiter transaction is built.
  • The requested decrease amount is never adjusted automatically.
  • Existing behavior is preserved when the reserve is explicitly set to zero.
  • The project compiles successfully.
## Background A Position Decrease can currently reduce an open Jupiter Perps position completely to zero. We need a configurable minimum remaining position size so Evelyn can retain part of the position. The reserve must be based on the position's USD size, not its collateral amount. For example: ```text Collateral: 1 USDC Leverage: 10x Size: 10 USD ``` The Position Decrease therefore represents a `$10` reduction of the position size. It is this `$10` size reduction that must be used when checking the reserve. ## Configuration Add a mandatory top-level configuration field: ```text RESERVE_POSITION_SIZE_USD_LIMIT 10 ``` The value defines the minimum `sizeUsd` that must remain after a Position Decrease. A value of `0` explicitly disables the reserve and permits the position to be reduced completely to zero. Missing, duplicate or negative values must cause a clear configuration error. ## Behavior Before building, signing or submitting a Position Decrease transaction, calculate: ```text remainingPositionSize = currentPositionSizeUsd - decreaseSizeUsd ``` The decrease may only continue when: ```text remainingPositionSize >= RESERVE_POSITION_SIZE_USD_LIMIT ``` This is equivalent to requiring: ```text currentPositionSizeUsd >= decreaseSizeUsd + RESERVE_POSITION_SIZE_USD_LIMIT ``` `decreaseSizeUsd` must be the resolved position size reduction derived from the configured collateral and leverage. The collateral amount alone must not be used for this check. If the decrease would leave the position below the configured reserve, skip the entire action. Do not automatically reduce or otherwise modify the requested decrease amount. Log a clear message containing: * The current position size * The requested position size decrease * The configured reserve * The resulting position size ## Examples With: ```text RESERVE_POSITION_SIZE_USD_LIMIT 10 ``` * Position size `$30`, decrease size `$10` → continue; `$20` remains. * Position size `$20`, decrease size `$10` → continue; exactly `$10` remains. * Position size `$15`, decrease size `$10` → skip; only `$5` would remain. * Position size `$10`, decrease size `$10` → skip; the position would be closed. ## Acceptance criteria * `RESERVE_POSITION_SIZE_USD_LIMIT` is mandatory. * Zero is allowed and disables the reserve. * Negative values, duplicate definitions and missing values are rejected. * The check uses the decrease's calculated `sizeUsd`, including leverage. * The check uses the current position's `sizeUsd`, not its collateral. * A decrease leaving exactly the configured reserve is allowed. * A decrease leaving less than the reserve is skipped before any Jupiter transaction is built. * The requested decrease amount is never adjusted automatically. * Existing behavior is preserved when the reserve is explicitly set to zero. * The project compiles successfully.
minimons added the enhancement label 2026-07-25 19:34:44 +02:00
minimons self-assigned this 2026-07-25 19:34:44 +02:00
minimons added this to the Evelyn project 2026-07-25 19:34:44 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: r35157/com_r35157_nenjim-hubd-impl_ref#43