Pure-book hybrid: require belief_price or minimum_receive — directions 2 & 3 (GitLab #273 follow-up) #334
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#334
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?
Parent
Follow-up to GitLab #273 (hybrid no-belief slippage — open, direction 1 merged) and #307 (material pool leg — closed). Issue discussion (Brouie 2026-06-04) deferred directions 2 & 3 as frontend-coordinated work. User note: pure-book hybrid (
declared_pool_input = 0) still unguarded on no-belief path.Current codebase
Shipped (#273 + #307)
dex_common::max_spreadno-belief branch foldsbook_shortfallvs pool net rate when bothpool_input > 0andbook_input > 0.validate_declared_hybrid_pool_leg_for_no_beliefrequiresdeclared_pool_input ≥ 10%of offer andpool_net > 0when book leg present withoutbelief_price.declared_pool_input == 0, #307 guard skipped; max_spread comment: metric cannot bound book — requiresbelief_priceorminimum_receive(docs/integrators.md,docs/contracts-security-audit.mdL9).Gaps (directions 2 & 3 — not shipped)
min_returnon Swap hook — hard floor independent ofbelief_pricebelief_priceorminimum_receivewhenbook_input > 0(includes pure-book)Router / frontend today
belief_price: None(smartcontracts/contracts/router/src/contract.rs).minimum_receiveis optional onExecuteSwapOperations.belief_priceon hybrid book legs — pure-book swaps can execute with onlymax_spread(unbounded for book leg).Why this is needed
pool_input = 0, full size to book) has no no-belief slippage floor — toxic book fills pass if user omitsbelief_priceandminimum_receive.Constraints / guardrails
belief_priceorminimum_receiveon book hops.book_input == 0paths unaffected.belief_pricebefore contract enforces direction 3.swapMaxSpread.tspreflight must align with new revert reasons.min_returnon pair Swap) can ship as schema addition but remains optional until frontend passes it.Relevant files
smartcontracts/packages/dex-common/src/max_spread.rssmartcontracts/contracts/pair/src/contract.rs—execute_swap, hybrid validationsmartcontracts/packages/dex-common/src/pair.rs—Swap,Cw20HookMsgsmartcontracts/contracts/router/src/contract.rs— hop build,minimum_receivesmartcontracts/tests/src/limit_order_tests.rs,max_spread.rs,lib.rsrouter testsfrontend-dapp/src/utils/swapMaxSpread.ts,swapMaxSpread.test.tsSwapPage.tsx,TradeMarketOrderPanel.tsx,transactions.tsdocs/integrators.md,docs/contracts-security-audit.md(L9),docs/swap-max-spread-ux.mdRecommended direction
Phase 1 — Frontend + router floors (unblock direction 3)
belief_priceor ensure routerminimum_receiveon every hybrid submit withbook_input > 0(including pure-book UI path).minimum_receiveon final hop from slippage tolerance; consider per-hop min for multihop book legs.Phase 2 — Contract enforcement (direction 3)
execute_swap(nobelief_price): whenhybrid.book_input > 0, requirebelief_price.is_some()OR caller proves router-levelminimum_receivecovers book leg (router-only path) — or simpler: requirebelief_priceon pair hook whenbook_input > 0and no router min.pool_input = 0): same requirement — no carve-out.Phase 3 — Direction 2 (optional, same release)
min_returnto pairSwap/ CW20 hook msg.Tests
belief_price→ pass.minimum_receive→ pass.Acceptance criteria
belief_priceorminimum_receivereverts on-chain.make test-contracts+ frontend preflight tests green.docs/integrators.mdand L9 audit row updated.Test plan — all paths
Test plan — attack / abuse / hack vectors
Verification criteria
cargo test -p cl8y-dex-testshybrid pure-book reject + accept cases pass.make test-frontendswap submit tests pass with new params.marked as related to #273
mentioned in commit
ce83a11750mentioned in merge request !819
Implementation opened as !819 (branch
cursor/gitlab-issue-workflow-dd14).Verification run locally:
make test-contracts(375 tests),make test-frontend(852 tests), newhybrid_pure_book_requires_slippage_floor_without_belief.Removed
agent:implement/agent:verifylabels.mentioned in commit
1fbca4fba6mentioned in commit
2f6fd97095mentioned in commit
6e2ebbe1d0#334 verified at the contract + router + docs layers on current main (merged via !819, commits
ce83a11/1fbca4f/2f6fd97). The frontend half — make test-frontend + the dapp-driven live swap — is the browser layer; I did not run that here (flagged at the bottom). The headline, pure-book reverting without a floor, I proved on-chain.On-chain revert proof (the security criterion):
"failed to execute message; message index: 0: Hybrid swap with book_input 10000000 requires belief_price or min_return without belief_price"
Acceptance criteria:
Verification criteria:
So contract enforcement + router forwarding + docs are solid and the on-chain revert is proven. What remains is purely the browser layer: make test-frontend (swap submit + swapMaxSpread preflight) and the dapp-driven pure-book swap on LocalTerra — that is my laptop pass, I will run it there. @PlasticDigits — contract side is good; flagging the frontend layer as the remaining laptop check before close.
Frontend layer needs verification
Verification complete — GitLab #334
Issue: https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/work_items/334
Branch verified:
main(implementation merged via !819)Acceptance criteria
belief_priceorminimum_receivereverts on-chaincargo test -p cl8y-dex-tests hybrid_pure_book_requires_slippage_floor_without_belief— negative pathis_errwithbelief_price/min_returnin root cause. Live LocalTerra CW20 send (EMBER→EMBER/CORAL pair,pool_input=0,book_input=10000000, no floor) reverts:Hybrid swap with book_input 10000000 requires belief_price or min_return without belief_price.SwapPage.tsx/TradeMarketOrderPanel.tsxcallcomputeDirectHybridMinReturn+enrichSwapOperationsWithHopMinReturns;pair.tsemitsmin_return;router/src/contract.rsthreads per-hopmin_returnviavalidate_hybrid_hop_execute_slippage_floor. Shipped in !819.make test-contracts+ frontend preflight tests greenmake test-contracts→ 375/0 (cl8y-dex-tests).make test-frontend(Node 24) → 871/0 incl.swapMaxSpread.test.ts#334hybridBookRequiresSlippageFloor+ targetedSwapPage.test.tsx/pair.test.ts/swapRoutePreflight.test.ts(41/0).docs/integrators.md+ L9 audit row updatedintegrators.md§ Slippage (pure-book execute floor + router per-hopmin_return);contracts-security-audit.mdL9 cites #334 +hybrid_pure_book_requires_slippage_floor_without_belief;swap-max-spread-ux.mddocuments #334 revert +enrichSwapOperationsWithHopMinReturns.min_returnon pair hook) + direction 3 (require floor whenbook_input > 0, incl. pure-book) enforced on-chain and in dapp/router submit paths. Closing #273 is a separate maintainer decision.Verification criteria
cargo testhybrid pure-book reject + acceptcargo test -p cl8y-dex-tests hybrid_pure_book→ 1 passedmake test-frontendswap submit + preflightmake test-frontend→ 871 passedmin_return=1→ tx238FE88D…code 0 (send,swap,transfer×3). Dapp:npx playwright test e2e/hybrid-swap.spec.ts --project=e2e-tx -g "hybrid swap emits"→ 1 passed (14.4s) — Simulated Wallet hybrid submit with automin_returnfills book (limit_order_fill,book_return_amount > 0).docs/integrators.mddocuments pure-book execute requirementTest-plan spot checks
min_returnhybrid_no_belief_*) in suitevalidate_hybrid_hop_execute_slippage_flooron first + intermediate hopsEnvironment
make setup-cloud-localterrascripts/e2e-seed-hybrid-book.shfor resting bidchromium_headless_shell-1208)All acceptance and verification items PASS. No repo changes required from this verification run.
mentioned in merge request !835
mentioned in issue #337
mentioned in commit
06eb2d8bb5mentioned in commit
737f47e0ccmentioned in issue #339
mentioned in issue #292
mentioned in commit
7a64050001mentioned in commit
606a0f0d1dmentioned in commit
d5d0c6a8bcmentioned in commit
807480f30fmentioned in commit
53b8658c58mentioned in commit
ff12f65dbfmentioned in commit 81b1b85c16807e7b5e68e36b517cbf6502746ecf
mentioned in commit
5f27d35187mentioned in commit
06c3610effmentioned in commit
4bc07345b1mentioned in commit
05ee14db17mentioned in commit
8f0ca4009dmentioned in commit
e6e71f29e7mentioned in commit
a0cccd0456mentioned in merge request !841
mentioned in merge request !842
mentioned in merge request !849
mentioned in issue #376
mentioned in issue #418
mentioned in issue #428
mentioned in issue #708