refactor: converge portfolio risk and venue integrations - #59
Merged
Conversation
Use the published struct-returning venue ABIs so predictive snapshots no longer depend on the removed value-only compatibility getter. Co-authored-by: Cursor <cursoragent@cursor.com>
Route keeper maintenance and settlement through dedicated contract methods and remove unused market-maker multicall wrappers. Co-authored-by: Cursor <cursoragent@cursor.com>
Expired futures orders no longer consume global limits, so remove scheduled cleanup and scope market-maker reads to each delivery. Co-authored-by: Cursor <cursoragent@cursor.com>
Let markets answer portfolio liquidation order gates from their aggregate indexes without computing full risk views or reading price oracles. Co-authored-by: Cursor <cursoragent@cursor.com>
Price IM and MM from one market/options snapshot and oracle read so post-liquidation guards avoid duplicating every portfolio call. Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Aug 8, 2026
Prevent stale or non-positive oracle answers from erasing portfolio stress requirements during critical margin checks. Co-authored-by: Cursor <cursoragent@cursor.com>
Stress signed net gamma and vega so short option exposure cannot be interpreted as protective long convexity. Co-authored-by: Cursor <cursoragent@cursor.com>
Skip options and oracle stress reads when linear markets report no resting-order exposure. Co-authored-by: Cursor <cursoragent@cursor.com>
Compute the minimum signed delta and vega endpoints directly now that both option Greeks preserve direction. Co-authored-by: Cursor <cursoragent@cursor.com>
shev-titan
added a commit
to Lumerin-protocol/futures-marketplace
that referenced
this pull request
Aug 9, 2026
## Summary - index resting orders per participant and delivery, enforcing the 100-order cap independently for each expiration - use a write-maintained delivery bitmap so active order/risk views skip empty and historical buckets without cleanup - share one live oracle mark across position and order risk aggregation, and expose a narrow resting-order state read - use the PME combined IM/MM snapshot in post-liquidation guards - add an owner-only, single-transaction legacy-order cutover script and update ABIs, UI, indexer, docs, and gas snapshots ## Dependencies - Stacked on [#255](#255) - Coordinated with [collateral-margin#59](Lumerin-protocol/collateral-margin#59) ## Gas highlights - `getOrderAggregate`: 123,998 → 45,080 - representative `getRiskView`: 122,426 → 76,200 - partial `liquidatePosition`: 228,595 → 200,883 ## Test plan - [x] `pnpm test` (176 contract tests) - [x] forced compile and EIP-170 size check - [x] `pnpm typecheck` - [x] `pnpm lint` - [x] full indexer integration tests, typecheck, and lint - [x] keeper and market-maker tests/typechecks - [ ] Full UI typecheck (blocked by existing dependency and unrelated React/wagmi type errors) Made with [Cursor](https://cursor.com)
Align the perps mock position tuple with production semantics while preserving the price-based test setter. Co-authored-by: Cursor <cursoragent@cursor.com>
Use an exact local getter ABI so snapshots and venue PnL match the deployed signed position tuple without waiting on an external ABI release. Co-authored-by: Cursor <cursoragent@cursor.com>
Read the exact local position tuple and derive average entry prices for both long and short inventory without depending on an unpublished ABI. Co-authored-by: Cursor <cursoragent@cursor.com>
Run the keeper test node with integration-only size limits disabled and deploy Futures through its current initializer surface. Co-authored-by: Cursor <cursoragent@cursor.com>
Vendor the renamed generated ABI so keeper and market-maker remain independently buildable before the upstream packages publish it. Co-authored-by: Cursor <cursoragent@cursor.com>
lsheva
changed the base branch from
refactor/use-typed-contract-batches
to
dev
August 10, 2026 11:31
Co-authored-by: Cursor <cursoragent@cursor.com>
Follow the thinner futures ABI: discover ids and aggregates over getExpirationDates instead of removed cross-expiry getters. Co-authored-by: Cursor <cursoragent@cursor.com>
…icate Liquidatability is a property of the portfolio (balance < portfolio MM), not of any single venue, so the predicate moves here. The venues' own isLiquidatable views answered it inconsistently (futures gated on venue-local state, perps on portfolio-wide order delta) and are being removed; whether a venue holds anything actionable stays answerable via its hasRestingOrderDelta and position views. Co-authored-by: Cursor <cursoragent@cursor.com>
The venues removed their isLiquidatable views; the PME predicate added in the previous commit is the single source. PerpsDEXMock loses the dead balance/maintenance-margin model, MarginEngineMock answers the new interface member, the keeper/market-maker HashPowerFutures ABI copies are synced from the regenerated futures ABI, and the pending MM process test reads the predicate from the PME. Co-authored-by: Cursor <cursoragent@cursor.com>
3 tasks
pnpm 11.1.1 records git subpath dependencies as integrity-only, dropping the `path:` field. A cold store then unpacks the whole repository into node_modules, so collateral-margin-abi/CollateralVault.ts and @hashpower/portfolio-margin do not resolve and TypeCheck fails with TS2307 on every CI run.
Node 22 refuses to strip types from .ts files under node_modules, so any test reaching perps-contracts/abi/HashPowerPerpsDEX.ts crashes on import. Match the keeper workflow, which already runs node 24.
The keeper integration harness deploys HashPowerFutures and reads a signed netEntryValue, neither of which exists at the previously pinned commits, so every fixture failed on a missing Hardhat artifact. Track futures #258 and perps #97 until both land on dev.
The test public client has no multicall3 configured, matching every other reader in this file, so readFuturesOrderIds must fan out readContract calls instead of batching them.
Invoking node directly skipped `--import=amaro/strip`, so the first test to load a contract ABI shipped as .ts inside node_modules crashed with ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING. Match the keeper workflow's action versions too, and drop the pnpm cache from both so CI always installs against a cold store — a warm store is what hid the git subpath breakage.
pnpm 11.1.1 dropped the `path:` field from git subpath resolutions, which made installs depend on store state (pnpm/pnpm#12304, fixed in 11.7.0). Move every package to a release carrying that fix instead of holding keeper back on pnpm 10, and restore the CI store cache now that a warm store can no longer mask a lossy lockfile. pnpm 11 migrates the contracts build allowance out of package.json into pnpm-workspace.yaml.
pnpm 11 stopped reading `pnpm.onlyBuiltDependencies` from package.json and turned ignored build scripts into a hard install error, so market-maker and points-indexer both failed to install. Move the allowances to allowBuilds and name the packages that must stay unbuilt. Git dependencies are keyed by exact resolution, so matchstick-ts is listed at both pinned commits.
Follow the v0.4.2 tag instead of a raw commit and repoint the allowBuilds entries at the resolution it pins.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan