fix: lazy TTL bump, market config cache, exchange router docs, keeper risk assessment#346
Merged
abayomicornelius merged 2 commits intoJun 26, 2026
Conversation
…eper risk assessment Closes SO4-Markets#297 — lazy persistent TTL bumping: - Add PERSISTENT_BUMP_TARGET (518 400 ledgers ≈ 30 days) and MIN_BUMP_THRESHOLD (259 200 ledgers ≈ 15 days) constants in order_handler and referral_storage. - extend_ttl fires only when remaining TTL < MIN_BUMP_THRESHOLD, halving unnecessary rent payments on busy markets. - order_handler: bump Order key on create_order, update_order; bump OrderFrozen key on freeze_order. - referral_storage: bump on every write and on every read (register_code, set_trader_referral_code, set_referrer_tier, set_tier_config, get_trader_referrer, get_trader_discount_bps). Closes SO4-Markets#299 — instance-storage cache for market config: - Add InstanceU128 variant to DataKey enum in data_store. - Add set_u128_config (write-through: persistent + instance) for rarely-changing config (fee factors, OI caps, leverage limits). - Add get_u128_cached (check instance first, populate on miss) so subsequent reads skip the persistent round-trip. - Expose get_u128_cached in DataStoreClient trait of order_handler and liquidation_handler. Closes SO4-Markets#291 — exchange router API reference: - New docs/exchange-router-api.md documents all 10 entrypoints (multicall, create_order, cancel_order, create_deposit, cancel_deposit, create_withdrawal, cancel_withdrawal, claim_funding_fees, send_tokens, upgrade) with signatures, auth, pre-conditions, side effects, events, errors, and examples. Closes SO4-Markets#296 — keeper front-running risk assessment: - New docs/keeper-risk.md assesses order-reordering, liquidation cherry-picking, ADL selection bias, and deposit/withdrawal timing risks; documents all mitigations already in place and monitoring guidance for operators.
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
PERSISTENT_BUMP_TARGET(≈30 days) andMIN_BUMP_THRESHOLD(≈15 days) constants added.extend_ttlfires only when remaining TTL < threshold, halving redundant rent payments. Applied toorder_handler(Order + OrderFrozen keys) andreferral_storage(all writes and reads).DataKey::InstanceU128variant added;set_u128_config(write-through) andget_u128_cached(check instance first, populate on miss) added to DataStore.get_u128_cachedexposed in DataStoreClient traits oforder_handlerandliquidation_handler.docs/exchange-router-api.md— full API reference for all 10 exchange router entrypoints (signatures, auth, pre-conditions, side effects, events, errors, runnable examples).docs/keeper-risk.md— risk assessment for keeper front-running across 4 vectors (order reordering, liquidation cherry-picking, ADL selection, deposit/withdrawal timing), with severity/likelihood ratings and mitigation status.Test plan
cargo test -p data-store— 8 tests passcargo test -p referral-storage— passescargo check -p order-handler -p liquidation-handler— no new errors (pre-existingcontracterrorissues in shared libs are unrelated)docs/exchange-router-api.mdanddocs/keeper-risk.mdfor completenessCloses #297
Closes #299
Closes #291
Closes #296