Skip to content

feat: integrate pyth_sponsor_rule — sponsor Pyth fees#40

Merged
JustaLiang merged 6 commits intomainfrom
feat/pyth-sponsor-rule
Apr 17, 2026
Merged

feat: integrate pyth_sponsor_rule — sponsor Pyth fees#40
JustaLiang merged 6 commits intomainfrom
feat/pyth-sponsor-rule

Conversation

@JustaLiang
Copy link
Copy Markdown
Contributor

Summary

  • Default trading path now uses PythSponsor to pay Pyth price update fees (no tx.splitCoins(tx.gas, ...))
  • New selfPayPyth param on all trading builders to opt out and pay from gas
  • Codegen + constants for pyth_sponsor_rule package (testnet deployed)
  • reimburseSponsorFund() adds PythSponsorRule witness to TradingRequest before execute
  • Removed updatePythPrice: true from e2e tests — default sponsor path covers it
  • Added xStock markets (AAPLX, GOOGLX, METAX, NVDAX, QQQX, SPYX, TSLAX) to lifecycle e2e tests

Test plan

  • pnpm typecheck passes
  • pnpm lint passes
  • 246 unit tests pass
  • 77 e2e simulate tests pass (same skip count as before)
  • e2e passes with updatePythPrice: true removed — default sponsor path works

🤖 Generated with Claude Code

JustaLiang and others added 6 commits April 17, 2026 22:09
Default trading path now uses PythSponsor to pay Pyth price update fees
instead of splitting from tx.gas. The sponsor Fund hot-potato is created
before Hermes fetch, split for each feed update, then reimbursed onto
the TradingRequest (adding PythSponsorRule witness).

- Add pyth_sponsor_rule to codegen pipeline and constants
- Add pythSponsorRulePackageId / pythSponsorId to WaterXConfig
- Modify buildPythPriceUpdateCalls to accept optional sponsorFund
- New addPriceFeeds default: sponsor-paid Hermes+Pyth update
- selfPayPyth param opts out to legacy gas-paid path
- Add reimburseSponsorFund helper (utils/sponsor.ts)
- Thread sponsorFund through all trading builders and user functions
- Remove updatePythPrice:true from e2e tests (default sponsor covers it)
- Add xStock markets to lifecycle e2e test coverage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- fetchSimulatedUsdPricesForBases falls back to per-base simulates when
  batch TX fails (DEEP's broken aggregator no longer blocks all markets)
- Add per-base price guard in trading-negative and prd-product-coverage
- Fix cancelOrder test: use scaled triggerPrice + wildcard orderTypeTag
- Adjust BTC e2ePtb sizes to match on-chain position (size=588)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…iceFeeds

- buildResolveSize now uses trading::resolve_size (takes collateralPriceResult)
  instead of deprecated trading::resize
- Export addPriceFeeds for test helpers and custom PTB construction
- Simplify simulate-resize-size helper to use addPriceFeeds

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Exact max leverage (positive) and max+1 (negative) now use leverage-only
path with on-chain resolve_size — no approxPrice off-chain estimate.
Removed unused fetchSimulatedUsdPricesForBases import from prd tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Withdraws nearly all collateral from existing positions — verifies
on-chain err_exceed_max_leverage (104) abort when remaining collateral
would push effective leverage above market max.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Guard against undefined prices[base] (e.g. DEEP broken aggregator)
in scratchSimulateOpenApproxOracle — prevents NaN→BigInt crash in CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JustaLiang JustaLiang merged commit 2cf8504 into main Apr 17, 2026
11 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.

1 participant