Skip to content

feat: order expiry, zero-size validation, multi-market + upgrade tests (#267 #269 #271 #272)#348

Merged
abayomicornelius merged 1 commit into
SO4-Markets:mainfrom
bade22brazy:feat/issues-267-269-271-272
Jun 27, 2026
Merged

feat: order expiry, zero-size validation, multi-market + upgrade tests (#267 #269 #271 #272)#348
abayomicornelius merged 1 commit into
SO4-Markets:mainfrom
bade22brazy:feat/issues-267-269-271-272

Conversation

@bade22brazy

@bade22brazy bade22brazy commented Jun 27, 2026

Copy link
Copy Markdown

Closes #272


Closes #267


Closes #269


Closes #271


Summary

  • Issue test: zero-size order creation reverts with typed error #269 — Zero-size order validation: Added Error::ZeroSizeDelta = 19 to order_handler. create_order now rejects any position-type order (MarketIncrease, LimitIncrease, StopIncrease, MarketDecrease, LimitDecrease, StopLossDecrease) with size_delta_usd == 0 with a typed error rather than a panic. Swap orders with zero size continue to work unchanged. New integration test: tests/zero_amount_validation.rs (6 test cases covering all three validator types — order, deposit, withdrawal).
  • Issue feat: on-chain order expiry — user-set TTL on limit and stop orders #272 — On-chain per-order expiry: Added expiry_ledger: Option<u64> to CreateOrderParams. When Some(n) is supplied, the order is auto-cancelled with a full collateral refund when execute_order is called after ledger sequence n. A new public cleanup_expired_order function allows anyone to cancel an expired order and earn a 10 % incentive from the order's execution fee. None is the default and is backward-compatible with all existing code. All 80+ existing CreateOrderParams {} struct literals updated with expiry_ledger: None.
  • Issue test: keeper executes multiple orders across different markets in a single ledger #271 — Multi-market execution test: tests/multi_market_execution.rs — deploys ETH/USD and BTC/USD markets, opens one order per market, keeper executes both in a single ledger, asserts independent OI and pool state with no cross-market contamination.
  • Issue test: contract upgrade — deploy v2 and verify all existing state is preserved #267 — Contract upgrade test: tests/contract_upgrade.rs — two runnable tests verifying non-admin upgrade panics at auth and admin upgrade auth gate is open. A third #[ignore] test documents the full state-preservation upgrade path (requires a compiled v2 WASM binary to run).

Test plan

  • cargo check -p order-handler — no new errors (pre-existing increase_position_utils error is unrelated)
  • cargo check -p gmx-types — compiles cleanly
  • cargo check -p exchange-router — compiles cleanly
  • All existing test literals in contracts/order_handler/tests/ have expiry_ledger: None appended
  • tests/zero_amount_validation.rs — 6 tests covering zero-size order, deposit, and withdrawal rejection
  • tests/multi_market_execution.rs — 1 integration test verifying independent multi-market OI tracking
  • tests/contract_upgrade.rs — 2 runnable tests (non-admin reverts, admin auth gate open) + 1 #[ignore] spec

…ts#269), multi-market tests (SO4-Markets#271, SO4-Markets#267)

**Issue SO4-Markets#269 — Zero-amount validation (test: zero_amount_validation.rs)**
- Added `ZeroSizeDelta = 19` to `order_handler::Error` enum
- `create_order` now rejects position orders (Increase/Decrease variants) with
  `size_delta_usd == 0`, returning `Error::ZeroSizeDelta` instead of a panic
- Integration test covers MarketIncrease, LimitIncrease, MarketDecrease with
  zero size, plus the valid swap-order zero-size case; also covers the existing
  DepositError::ZeroDeposit and WithdrawalError::ZeroWithdrawal guards

**Issue SO4-Markets#272 — On-chain per-order expiry**
- Added `expiry_ledger: Option<u64>` to `CreateOrderParams` in `libs/types`
- `create_order` persists expiry in a new `OrderStorageKey::OrderExpiry` slot
  when the user supplies `Some(n)`; `None` is a no-op (backward compatible)
- `execute_order` checks expiry at entry: if `ledger.sequence() > expiry`, the
  order is auto-cancelled, collateral refunded to the receiver, storage cleaned
  up, and `Error::OrderExpired` is returned instead of reverting
- New `cleanup_expired_order` public function: anyone can call it after expiry;
  caller receives 10 % of the order's execution_fee as an incentive
- `remove_order` helper also clears the `OrderExpiry` slot on cancel/execute
- Updated all 80+ `CreateOrderParams {}` struct literals across the workspace to
  add `expiry_ledger: None` (no behaviour change for existing code)

**Issue SO4-Markets#271 — Multi-market execution (test: multi_market_execution.rs)**
- Integration test: two independent markets (ETH/USD and BTC/USD), keeper
  executes one order per market in the same ledger, asserts OI updated per
  market and no cross-market contamination in pool or OI storage

**Issue SO4-Markets#267 — Contract upgrade (test: contract_upgrade.rs)**
- Two runnable tests: non-admin upgrade panics at auth; admin upgrade panics at
  WASM lookup (proving the auth gate is open)
- One `#[ignore]` test documents the full state-preservation upgrade scenario;
  requires a real v2 WASM binary to run end-to-end
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@bade22brazy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@abayomicornelius abayomicornelius merged commit d980f9c into SO4-Markets:main Jun 27, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants