Skip to content

fix: make price smoothing direction independent - #1552

Merged
enthusiastmartin merged 15 commits into
masterfrom
fix/direction-independent-slow-ema
Oct 16, 2026
Merged

enthusiastmartin merged 15 commits into
masterfrom
fix/direction-independent-slow-ema

Conversation

@mrq1911

@mrq1911 mrq1911 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Price smoothing currently depends on the stored asset order because smoothing a price and then taking its reciprocal is not equivalent to smoothing the reciprocal directly. This change applies the slower legacy response consistently in both directions, so querying either orientation of an asset pair produces reciprocal prices with the same effective weighting.

The runtime migration settles stale EMA entries through the last completed block with the legacy arithmetic calculation before enabling the new calculation. Runtime upgrade hooks run before System::initialize, so the stored system block already identifies that completed block and must not be decremented again. This addresses audit finding IND-01 and avoids applying one direction-independent update to legacy history. The storage layout is unchanged.

The one-block migration processes at most 768 oracle rows, which keeps the estimated oracle proof near 2 MiB and covers all 547 rows in the validated production snapshot with headroom. If the limit is reached, later rows remain unchanged while the v3 storage-version upgrade completes; there is no lazy follow-up migration. The migration charges the existing benchmarked EMA finalize weight so its returned weight includes EMA computation and storage proof size.

The ORML token and XYK benchmark assertions are aligned with the base branch's retired insufficient-asset ED scheme. External and XYK share benchmark assets now correctly expect zero system sufficient references; these changes repair benchmark validation without changing runtime behavior.

Versions are bumped to runtime-integration-tests 1.126.1, hydra-dx-math 13.2.4, pallet-ema-oracle 1.13.1, and Hydration runtime spec 454.

Validation:

  • make test — passed; runtime integration tests: 1,236 passed, 50 ignored
  • make test-release — passed; runtime integration tests: 1,236 passed, 50 ignored
  • make build-release — passed
  • make clippy-all — passed
  • cargo fmt --all -- --check and git diff --check — passed after merging current master
  • scripts/list_crate_updates.sh — passed with all modified crate and runtime versions recognized
  • Quick benchmark CI — passed for every pallet
  • Full pallet_ema_oracle benchmark — passed at 50 steps and 20 repeats; generated weights committed as c1bdb8f8a
  • ORML token and XYK generated release benchmark test suites — passed
  • All 90 pallet-ema-oracle tests pass, including a 769-row case proving that exactly 768 rows migrate and the excess row remains unchanged
  • cargo check -p pallet-ema-oracle --features try-runtime --locked — passed after merging current master
  • Migration lifecycle matrix covers Short, TenMinutes, and Day periods with falling, unchanged, and rising prices
  • Chopsticks Hydration fork retained the original mainnet block-height context and passed the EMA-specific migration check for all 547 entries
  • Zombienet fork from wss://hdx.tarn.hydration.cloud at finalized block 15,835,245 applied the preauthorized production WASM through system.applyAuthorizedUpgrade
  • Exact Zombienet activation check: EMA storage v2 at block 13 became v3 at block 14; all 547 keys were preserved and every entry was settled through block 13, the last completed block
  • Replayed all six evaluated pools with the expected slow-symmetric results

The repository-wide live-fork try-runtime All flow is currently blocked after the EMA migration by existing DCA and global storage-version checks against the selected mainnet snapshot. The EMA-specific migration check passes.

A full pallet_ema_oracle benchmark on the dedicated runner is tracked in workflow run 38907027281.

@github-actions

Copy link
Copy Markdown

Crate versions that have been updated:

  • runtime-integration-tests: v1.126.0 -> v1.126.1
  • hydra-dx-math: v13.2.3 -> v13.2.4
  • pallet-ema-oracle: v1.13.0 -> v1.13.1
  • hydradx-runtime: v453.0.0 -> v454.0.0

Runtime version has been increased.

@cl0w5 cl0w5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@github-actions

Copy link
Copy Markdown

Quick benchmark at commit 25d0ebb has been executed successfully.
View results

@enthusiastmartin
enthusiastmartin merged commit 7e8c411 into master Oct 16, 2026
17 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants