feat: ILedgerLensScore composability interface - #24
Merged
Inkman007 merged 1 commit intoJun 17, 2026
Conversation
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.
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
Defines and implements the
ILedgerLensScorecomposability 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-engineeringget_scoreand 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. Returnstrueonly when a score exists and is strictly< gate_threshold;falseon>=or no score (fails closed — unknown wallets treated as risky). Backed by a new TTL-preservingstorage::peek_scoreread 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, exactRiskScore/AggregateRiskScoreXDR field layout, versioning policy, stable error-code table + guarantees, security rationale, integration patterns (gate-on-threshold, cache-with-TTL, fallback onScoreNotFound, feature-detect).examples/amm_gate.rs— referenceLedgerLensGatedAmmcontract 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,RiskScoreXDR round-trip, error discriminant stability, and a 1000-input never-panics fuzz.RiskScoresnippets that were missingmodel_version.Security considerations
query_risk_gatereturnsbool(notResult) and is engineered to never panic, so it cannot be used to grief a calling protocol's gas or disable its guard.ScoreNotFoundcase folds intofalse(conservative default), documented explicitly.Verification
All CI-equivalent checks pass locally:
cargo fmt --all -- --check— cleancargo clippy --all-targets -- -D warnings— cleancargo test --workspace— 60 passedcargo build --target wasm32-unknown-unknown --release -p ledgerlens-score— succeeds (33 KB)cargo build --example amm_gate -p ledgerlens-score— compiles against the current SDKNote
The issue's
supports_interfaceprose mentioned "a map of capabilities," but the specified signature takes a singlecapability: 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