Skip to content

feat: ILedgerLensScore composability interface - #24

Merged
Inkman007 merged 1 commit into
Ledger-Lenz:mainfrom
Manuel1234477:feat/composability-interface
Jun 17, 2026
Merged

feat: ILedgerLensScore composability interface#24
Inkman007 merged 1 commit into
Ledger-Lenz:mainfrom
Manuel1234477:feat/composability-interface

Conversation

@Manuel1234477

@Manuel1234477 Manuel1234477 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Defines and implements the ILedgerLensScore composability interface — a stable, versioned ABI that third-party Soroban protocols (AMMs, lending markets, DEX aggregators) can target as the canonical LedgerLens integration point, instead of reverse-engineering get_score and risking silent breakage on any future change.

What's included

  • query_risk_gate(wallet, asset_pair, gate_threshold) -> bool — the integration primitive. Infallible, never-panics, side-effect-free. Returns true only when a score exists and is strictly < gate_threshold; false on >= or no score (fails closed — unknown wallets treated as risky). Backed by a new TTL-preserving storage::peek_score read so it has zero observable side effects when called cross-contract.
  • supports_interface(capability) -> bool — runtime capability registry (score, history, batch, gate, aggr) so callers feature-detect instead of hardcoding version numbers.
  • docs/interface-spec.md — canonical spec: signatures, exact RiskScore/AggregateRiskScore XDR field layout, versioning policy, stable error-code table + guarantees, security rationale, integration patterns (gate-on-threshold, cache-with-TTL, fallback on ScoreNotFound, feature-detect).
  • examples/amm_gate.rs — reference LedgerLensGatedAmm contract demonstrating the swap guard-clause pattern, registered as a lib-crate-type [[example]].
  • src/test_interface.rs — interface stability suite: gate semantics (safe / risky / at-threshold / no-score), capability registry, RiskScore XDR round-trip, error discriminant stability, and a 1000-input never-panics fuzz.
  • README — new Composability section with the AMM pattern; documents the new functions; fixes stale RiskScore snippets that were missing model_version.

Security considerations

  • query_risk_gate returns bool (not Result) and is engineered to never panic, so it cannot be used to grief a calling protocol's gas or disable its guard.
  • The ScoreNotFound case folds into false (conservative default), documented explicitly.
  • Capability symbols are append-only within a major version — removing one is a breaking change.

Verification

All CI-equivalent checks pass locally:

  • cargo fmt --all -- --check — clean
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo test --workspace60 passed
  • cargo build --target wasm32-unknown-unknown --release -p ledgerlens-score — succeeds (33 KB)
  • cargo build --example amm_gate -p ledgerlens-score — compiles against the current SDK

Note

The issue's supports_interface prose mentioned "a map of capabilities," but the specified signature takes a single capability: Symbol. I implemented the signature (single lookup → bool), which is what the registry pattern and the required test (supports_interface("score") == true) call for.

Closes #14

Add a stable, versioned ABI surface that third-party Soroban protocols
(AMMs, lending markets, DEX aggregators) can target as the canonical
LedgerLens integration point.

- query_risk_gate(wallet, asset_pair, gate_threshold) -> bool: infallible,
  never-panics, side-effect-free gate facade. Returns true only when a score
  exists and is strictly below the threshold; false on >= or no score
  (fails closed). Backed by a new TTL-preserving storage::peek_score read.
- supports_interface(capability) -> bool: runtime capability registry
  (score, history, batch, gate, aggr) so callers feature-detect instead of
  hardcoding version numbers.
- docs/interface-spec.md: canonical spec — signatures, RiskScore XDR layout,
  versioning policy, error-code stability guarantees, integration patterns.
- examples/amm_gate.rs: reference LedgerLensGatedAmm contract registered as a
  lib-crate-type [[example]] showing the swap guard-clause pattern.
- src/test_interface.rs: interface stability suite (gate semantics, capability
  registry, RiskScore XDR round-trip, error discriminant stability, 1000-input
  never-panics fuzz).
- README: Composability section with the AMM pattern; document new functions;
  fix stale RiskScore snippets missing model_version.
@Inkman007
Inkman007 merged commit dcf8221 into Ledger-Lenz:main Jun 17, 2026
5 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.

Design and implement standardized cross-contract composability interface for AMMs and lending protocols

2 participants