Contracts: unify assert_max_spread for pool-only and hybrid swaps #197
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#197
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem statement
assert_max_spread/ slippage checks are validated primarily against pool path inputs; combined hybrid return (book + pool) may not match product intent forbelief_price/max_spreadguards.Evidence / context
smartcontracts/contracts/pair/src/contract.rs.Proposed solution
Acceptance criteria
docs/integrators.mdor security audit.max_spreadper chosen rule; pool-only unchanged.Priority
P2
mentioned in commit
be40461810Implementation summary (GitLab #197)
Unified pool-only and hybrid
max_spread/belief_priceslippage checks behind a single shared module and documented the product rule as invariant L9.What changed
dex_common::max_spread— pool-only isbook_net_return = 0; hybrid uses the same code path.assert_max_spreaddelegates todex_common::max_spread::check_max_spread.belief_price):min(pool_spread, pool_gross) / (pool_gross + book_net)must not strictly exceedmax_spread.belief_price): shortfall vsoffer / belief_priceusingbook_net + pool_net + pool_commissionas actual output.hybrid_max_spread_exact_tolerance_succeedshybrid_max_spread_tighter_than_simulation_rejectedhybrid_belief_price_max_spread_rejects_shortfall_on_total_outputtest_swap_max_spreaddocs/contracts-security-audit.md,docs/integrators.md, ADR 0001,docs/swap-max-spread-ux.md, newskills/AGENTS_MAX_SPREAD_HYBRID.md; cross-links inAGENTS_HYBRID_QUOTING.mdandAGENTS_TESTING_MULTIHOP_HYBRID.md.Merged to
mainin commitbe40461.Verification checklist
cd smartcontracts && cargo test -p dex-common max_spreadcd smartcontracts && cargo test -p cl8y-dex-tests hybrid_max_spreadcd smartcontracts && cargo test -p cl8y-dex-tests hybrid_belief_price_max_spreadcd smartcontracts && cargo test -p cl8y-dex-tests test_swap_max_spread(pool-only unchanged)docs/integrators.mdslippage section matches integrator expectationsswapMaxSpread.tsstill mirrors L9 for retail swaps (nobelief_price)@brouie — please verify the hybrid slippage semantics and test checklist above. Leaving this issue open until sign-off.
mentioned in commit
f31fa823f7mentioned in issue #196
Verification sign-off (@brouie agent, 2026-05-27)
Verified GitLab #197 on
main(commitsbe40461,f31fa82). No additional code changes were required.Verification checklist
cd smartcontracts && cargo test -p dex-common max_spread— 5/5 passedcd smartcontracts && cargo test -p cl8y-dex-tests hybrid_max_spread— 2/2 passedcd smartcontracts && cargo test -p cl8y-dex-tests hybrid_belief_price_max_spread— 1/1 passedcd smartcontracts && cargo test -p cl8y-dex-tests test_swap_max_spread— pool-only regression passeddocs/integrators.mdslippage section matches invariant L9 (dex_common::max_spread, total-gross denominator for hybrid)swapMaxSpread.ts+ vitest (swapMaxSpread.test.ts) — 5/5 passed; mirrors no-belief L9 formulahttp://127.0.0.1:5175— EMBER→CORAL 100-unit quote shows Price impact 0.10%, slippage 0.5%, min received (preflight path live against indexer :3001)Infra used
127.0.0.1:26657):5432accepting connectionshttp://127.0.0.1:3001/health)Worktree
fix/issue-197-verifywas used for isolated verification; merged state is already onorigin/main(no delta to push).mentioned in issue #273
mentioned in merge request !746
mentioned in issue #307