Skip to content

[SDK] Add the composition constraint engine #1199

Open

Description

@collinsezedike

Summary

Add a pure constraint validator that enforces allocation and aggregate-exposure limits on a composition at init and after every rebalance.

Motivation

The engine bounds risk per strategy and per trade only: leverage is limited to 1 to 20 in packages/strategies/src/sizing.ts:11-16, and slippage is bounded in the slippage model. Nothing constrains a composition, where the same asset can be reached through several members at once. A user could hold the same asset through three members without seeing the combined exposure, because no single member shows it. Composition is exactly where that hidden concentration appears, so it needs an explicit check.

Proposed Solution

  • Add a CompositionConstraints type covering a maximum weight per member, a maximum aggregate exposure per asset, a maximum member count, and a required cash buffer.
  • Add a pure validateComposition(constraints, composition, portfolioView) that returns typed violations. It computes aggregate exposure across members rather than per member.
  • Support two policies: reject (throw a typed error) or clamp (reduce the offending order before it is applied). Default to reject, and keep the mode explicit in config.
  • The composition applies the decision when merging member orders; members never mutate one another's orders.

Scope

Field Value
Area SDK
Protocol affected None
Network testnet
Breaking change? No

Alternatives Considered

  • Fold the limits into each member's own config. Rejected, because the whole point is the aggregate view, which no single member can see.
  • Validate only in the UI. Rejected, because the engine must reject an invalid composition regardless of caller.

Acceptance Criteria

  • A composition that breaches a constraint is rejected, or clamped per the configured mode, with a typed error naming the constraint.
  • Aggregate per-asset exposure is computed across members, not per member.
  • Constraints are validated at init and after each rebalance.
  • Tests cover each constraint and both modes.
  • pnpm --filter @meridian/strategies test and npx tsc --noEmit pass.

Additional Context

Depends on the composition interface, #1197, and the capital allocation, #1198. Part of the Meridian Strategies initiative.

Star the repo

Please star this repository before picking up this issue. It is a small ask that meaningfully helps the project reach more people.

Activity

  1. added
    enhancementNew feature or request
    mediumRequires familiarity with the Meridian codebase or relevant tooling; expect 4–8 hours
    sdkInvolves Blend or DeFindex SDK helpers in packages/stellar-sdk-helpers
    on Oct 19, 2026
  2. CodlithLab commented on Oct 19, 2026

    @CodlithLab

    @CodlithLab has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    I Have gone through this issue and can fix it, Please assign it to me

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @CodlithLab to this issue.

  3. liutingqiu commented on Oct 20, 2026

    @liutingqiu
    Contributor

    @liutingqiu has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    I'll add a CompositionConstraints type and a pure validateComposition(constraints, composition, portfolioView) in the SDK, computing aggregate exposure across members rather than per member, and returning typed violations. The composition will apply the decision when merging member orders, with reject as the default and clamp as an explicit config mode, so members never mutate one another's orders. I'll wire the validator into composition init and the post-rebalance path.

    Tests will cover each constraint individually (max member weight, max aggregate asset exposure, max member count, required cash buffer), the aggregate case where the same asset is reached through several members and no single member breaches its own limit, both reject and clamp policies, and the negative case where an invalid composition is rejected with a typed error rather than silently applied.

    I've merged PRs #1175 and #1176 in drydocs/meridian and 65 PRs in Sottara-Labs/sottara. ETA is same or next day.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @liutingqiu to this issue.

  4. Shalombonet commented on Oct 20, 2026

    @Shalombonet
    Contributor

    @Shalombonet has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    i would like to assigned on this issue. it will be very much appreciated

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Shalombonet to this issue.

  5. drips-wave commented on Oct 20, 2026

    @drips-wave

    Congratulations, @CodlithLab! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on October 22, 2026.

    🧑‍💻 @CodlithLab: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or requestmediumRequires familiarity with the Meridian codebase or relevant tooling; expect 4–8 hourssdkInvolves Blend or DeFindex SDK helpers in packages/stellar-sdk-helpers

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions