Skip to content

[FEATURE] Automation: Volume-based triggers for DEX pools #330

Open
sotoJ24 wants to merge 6 commits into
Galaxy-KJ:mainfrom
sotoJ24:issue/303
Open

[FEATURE] Automation: Volume-based triggers for DEX pools #330
sotoJ24 wants to merge 6 commits into
Galaxy-KJ:mainfrom
sotoJ24:issue/303

Conversation

@sotoJ24

@sotoJ24 sotoJ24 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements volume-based automation triggers for Stellar DEX liquidity
pools, allowing the automation engine to fire when a pool's rolling 24-hour
trade volume exceeds a configurable threshold (roadmap item #48, issue #303).

Closes #303.

Files

  • packages/core/automation/src/triggers/volume-trigger.ts — trigger + types
  • packages/core/automation/src/test/volume-trigger.test.ts — unit tests

Design

API surface (matches issue spec)

export class VolumeTrigger {
  constructor(
    options?: VolumeTriggerOptions,
    fetcher?: HorizonFetcher,     // injectable for testing
  );

  // Spec method — returns boolean
  async trackPoolVolume(poolId: string, threshold24h: string): Promise<boolean>;

  // Extended method — returns full diagnostics
  async check(config: VolumeTrackConfig): Promise<VolumeCheckResult>;
}

trackPoolVolume returns boolean as specified. check returns the full
VolumeCheckResult with volume24h, tradeCount, threshold, triggered,
and checkedAt for callers that need observability beyond a boolean signal.

Volume computation

Horizon has no single "pool volume" endpoint. Volume is derived by:

  1. Fetching /trades?liquidity_pool_id={poolId}&trade_type=liquidity_pool&order=desc&limit=200
  2. Filtering records to the rolling window (Date.now() - windowMs, default 24 h)
  3. Summing base_amount across all matching trades

trade_type=liquidity_pool ensures only AMM trades are counted — orderbook
trades that happen to involve the same assets are excluded.

Threshold semantics

Strictly greater-than (volume > threshold) — matching the issue's "exceeds"
wording. A volume equal to the threshold does not trigger.

Dependency injection

HorizonFetcher is the only external I/O boundary. A DefaultHorizonFetcher
wraps the real fetch API for production. Tests inject a jest.fn() mock —
no global patching needed. This mirrors the pattern used by PriceTrigger
(injectable OracleAggregator) and EventTrigger (injectable
ContractEventMonitor).

Input validation

  • threshold24h must be a non-negative numeric string — throws otherwise
  • poolId must be a non-empty, non-whitespace string — throws otherwise
  • Non-numeric base_amount values in Horizon responses are skipped
    gracefully (treated as 0) rather than throwing

Tests

Screenshot from 2026-06-30 20-12-26

All tests use jest.useFakeTimers() + jest.setSystemTime() for
deterministic rolling-window boundary assertions.

Acceptance criteria

  • Queries Horizon trade history for volume computation via
    /trades?liquidity_pool_id=…&trade_type=liquidity_pool
  • Threshold trigger evaluates correctly — volume must strictly exceed
    threshold to return true
  • Mock tests written (19 tests, all passing)
  • Rolling 24-hour window filters out stale trades
  • No hard dependencies — HorizonFetcher is injectable for testing
    and future protocol changes
  • Consistent with existing trigger patterns (PriceTrigger,
    EventTrigger) in the same package

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@sotoJ24, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 350bdc84-9905-4815-a4e7-cdf982b00550

📥 Commits

Reviewing files that changed from the base of the PR and between deb9ad9 and 743f79e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • packages/contracts/governance/Cargo.toml
  • packages/contracts/governance/src/lib.rs
  • packages/core/automation/jest.config.cjs
  • packages/core/automation/package.json
  • packages/core/automation/src/execution-chain/index.ts
  • packages/core/automation/src/test/execution.chain.test.ts
  • packages/core/automation/src/test/volume-trigger.test.ts
  • packages/core/automation/src/triggers/volume-trigger.ts
  • packages/core/automation/tsconfig.json
  • packages/core/automation/tsconfig.test.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

[FEATURE] Automation: Volume-based triggers for DEX pools (#48)

1 participant