fix(create-market): preserve Hyperp oracle mode on mainnet - #2434
fix(create-market): preserve Hyperp oracle mode on mainnet#2434Bayyan16 wants to merge 1 commit into
Conversation
|
@Bayyan16 is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Independent verification — not an approval (QA/Security own that), just evidence for whoever reviews. Verdict: the fix is right and the test binds. Method: faithfully restored #2433 on the PR branch — const isDevnetMirror =
input.network === "devnet" && input.hasMainnetCA;
↓
const isDevnetMirror = input.hasMainnetCA;Result: That's precisely the reported defect, and it's the only test that moves — the other five cover combinations that legitimately shouldn't change. Clean, well-targeted matrix, and extracting the rule into a pure function is the right shape for something this easy to get subtly wrong. One thing worth a look before mergeThe coverage is entirely on the helper; nothing exercises const network = getNetwork(); // :1380 — solid, single source of truth
const oracleMode = resolveMarketOracleMode({
requestedMode: resolvedOracleMode,
network,
hasMainnetCA: !!params.mainnetCA,
});
But it's worth naming why this gap is a bit sharper here than in the sibling PRs: the original bug was itself a call-site inference error — inferring "devnet" from token metadata. The helper now encodes the correct rule, but the class of bug it fixes lives at the boundary the tests don't reach. If Cheapest guard, if you want one: assert Not blocking — the fix is real and verified. Flagging for consistency with the same note I left on #2442. |
|
Thank you for the careful mutation check and for inspecting the production call-site inputs directly. Understood: the six-case helper matrix faithfully catches #2433, while the remaining gap is future protection at the useCreateMarket boundary. The current wiring obtains Since this is non-blocking and no hook-level test is being requested, I’ll keep the production patch and current regression suite unchanged and await the formal QA/Security review. If the boundary assertion becomes a merge requirement, I’ll add only the smallest focused call-site guard rather than a broad hook test. |
Fixes #2433
Summary
This PR fixes a deterministic oracle-mode integrity issue in the market-creation flow where a user-selected
hyperporacle mode could be silently downgraded toadminon mainnet.The affected logic treated the presence of
params.mainnetCAas sufficient proof that the market was a devnet mirror:However, the create-market wizard populates
mainnetCAduring normal mainnet market creation as token metadata:As a result, the following valid mainnet configuration:
was incorrectly resolved as:
instead of:
This PR makes the fallback network-aware so that Hyperp is downgraded to Admin only for an actual devnet mirror.
Root Cause
The issue was caused by using
mainnetCAas a proxy for the active runtime network.The previous implementation effectively used:
This assumption is unsafe because
mainnetCArepresents token metadata and may be populated on both mainnet and devnet.The code therefore conflated two separate concepts:
and:
The intended fallback is valid only when both of the following are true:
Security Invariant
The effective oracle mode used during market creation must match the mode selected by the creator, except for the intentional devnet-mirror compatibility fallback.
This PR enforces the following invariant matrix:
In particular,
mainnetCAmust not independently determine the active runtime network.Changes
1. Added a pure oracle-mode resolver
A new helper was added:
The resolver explicitly receives:
mainnetCAis present.The corrected condition is:
Hyperp falls back to Admin only when the request is running on devnet and represents a mirrored mainnet token.
2. Updated the production market-creation flow
app/hooks/useCreateMarket.tsnow resolves the runtime network before selecting the effective oracle mode:This removes the incorrect assumption that the presence of
mainnetCAalone indicates a devnet mirror.The existing
isDevnetEnvvalue continues to be used by the remaining devnet-specific market-creation logic.3. Added regression coverage
A focused regression suite was added:
The tests cover:
Before This Fix
The affected implementation treated
mainnetCAas proof of a devnet mirror:The mainnet regression test failed with:
The failure was isolated to this invariant:
The other five control cases continued to pass.
After This Fix
The resolver now requires an actual devnet runtime:
The same regression suite now passes:
Verified behavior:
Validation
Targeted oracle regression tests
Command:
pnpm --filter @percolator/app exec vitest run \ __tests__/lib/resolveMarketOracleMode.test.ts \ __tests__/lib/oraclePrice.test.ts \ --reporter=verboseResult:
This includes the new resolver tests and the existing oracle-price regression suite.
TypeScript validation
Command:
pnpm --filter @percolator/app exec tsc \ --noEmit \ -p tsconfig.jsonResult:
Production build
Command:
Result:
The build emitted existing non-fatal warnings related to Next.js configuration deprecations, middleware migration,
module.register(), and the BigInt native-binding fallback. None were introduced by this PR and none caused the build to fail.Patch integrity
Commands:
Result:
Files Changed
Patch statistics:
Scope
This PR is intentionally limited to the oracle-mode resolution defect reported in #2433.
It does not modify:
No unrelated refactoring is included.
Impact of the Fix
After this change:
mainnetCA;Review Notes
The most important review points are:
getNetwork()is evaluated before oracle-mode resolution.mainnetCAis treated as metadata rather than a standalone network signal.Hyperp falls back to Admin only for:
Existing oracle modes are not altered.
Regression tests explicitly cover both the affected mainnet condition and the intended devnet fallback.
Commit