Skip to content

refactor: converge portfolio risk and venue integrations - #59

Merged
shev-titan merged 26 commits into
devfrom
refactor/remove-outdated-order-sweeper
Aug 17, 2026
Merged

refactor: converge portfolio risk and venue integrations#59
shev-titan merged 26 commits into
devfrom
refactor/remove-outdated-order-sweeper

Conversation

@lsheva

@lsheva lsheva commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retire the expired-order sweeper and optimize PME stress, margin, and venue risk reads
  • preserve signed option convexity and fail closed on invalid spot prices
  • update keeper, market maker, and contract mocks for exact signed Perps entry values
  • align the integration harness with current sibling contracts and consume the HashPowerFutures artifact

Test plan

  • Contracts compile, lint, typecheck, and 147 tests
  • Keeper lint, typecheck, and 195 unit tests
  • Keeper integration suite: 27 tests
  • Market maker lint, typecheck, and 303 tests
  • Vendored HashPowerFutures ABI verified byte-for-byte against generated source

shev-titan and others added 5 commits August 7, 2026 21:40
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>
@lsheva lsheva changed the title refactor: retire expired-order sweeper perf: retire sweeper and optimize portfolio risk reads Aug 8, 2026
shev-titan and others added 4 commits August 8, 2026 23:44
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)
shev-titan and others added 5 commits August 10, 2026 12:18
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 lsheva changed the title perf: retire sweeper and optimize portfolio risk reads refactor: converge portfolio risk and venue integrations Aug 10, 2026
@lsheva
lsheva changed the base branch from refactor/use-typed-contract-batches to dev August 10, 2026 11:31
shev-titan and others added 4 commits August 10, 2026 13:46
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>
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.
@shev-titan
shev-titan merged commit f012946 into dev Aug 17, 2026
23 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.

2 participants