Fee verification: discount tiers, pool vs limit book, hybrid parity, treasury #100
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#100
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?
Goal
Confirm that on-chain fee behavior matches product expectations across pool-only swaps, limit-book flows, hybrid swaps, the fee-discount registry, and treasury settlement. This issue tracks verification (docs, tests, targeted code review, and external audit alignment), not a single bugfix.
Intended fee semantics (reference)
The following is the documented / implemented model in this repo; reviewers should validate it end-to-end.
Fee discount tiers (CL8Y registry)
fee_bps * (10000 - discount_bps) / 10000(integer division). Seedocs/reference/fee-discount-tiers.mdandsmartcontracts/packages/dex-common/src/fee_discount.rswire types.governance_only: false; tier 0 / 255 are governance-assigned. Trusted router registration matters for router-originatedtraderforwarding (seedocs/testing.mdintegration section).Pool (AMM) swaps
effective_fee_bpsof gross output on the constant-product leg; fee is sent to the pair’s configuredtreasury(seeexecute_swappath insmartcontracts/contracts/pair/src/contract.rs).Limit orders (FIFO book)
PlaceLimitOrderfrom escrow;remainingis reduced; treasury receives the maker fee.taker_fee_bps = effective - floor(effective/2)so maker+taker equals effective). Basis: bids — token1cost; asks — token0 fill. Seeorderbook::maker_fee_bps/taker_fee_bpsinsmartcontracts/contracts/pair/src/orderbook.rs.UpdateLimitOrderPrice) does not re-charge the maker placement fee.Hybrid swaps (pool + book in one tx)
effective_fee_bps; book fills use the taker half per fill (maker half was paid at placement). Integration testhybrid_book_fill_uses_taker_discounted_effective_fee_bpsinsmartcontracts/tests/src/limit_order_tests.rsasserts the book leg uses the taker’s discountedeffective_fee_bps(GitLab #83).AfterSwap.commission_amountis pool leg only; book fees appear vialimit_order_fill/ treasury transfers — seedocs/integrators.mdand invariant L7 indocs/contracts-security-audit.md.Treasury
treasuryper pairFeeConfig(CW20 sends in the relevant token).Verification checklist
Documentation
docs/reference/fee-discount-tiers.md— tier math and governance/registration rules.docs/limit-orders.md— hybrid execution order, maker/taker split, events.docs/integrators.md— hook semantics for hybrid (commission_amount= pool only).docs/contracts-security-audit.md— invariants (e.g. L7, L8) still match code.Tests — how to run
CosmWasm workspace (primary for fee logic):
Focus areas:
smartcontracts/tests/src/limit_order_tests.rs— hybrid fee parity, treasury balances, maker/taker splits, discount registry.docs/testing.md).docs/testing.mdIntegration Tests (Contracts)).Coverage (optional):
Or from repo root:
make coverage-contracts.Frontend (fee tier UX):
frontend-dapp—npm run test:run, e2e underfrontend-dapp/e2e/fee-*.spec.tsif UI parity is in scope.Code review (targeted)
smartcontracts/contracts/pair/src/contract.rs—effective_fee_bpsresolution, pool commission,PlaceLimitOrdermaker fee, treasury sends.smartcontracts/contracts/pair/src/orderbook.rs—maker_fee_bps/taker_fee_bps, bid/ask commission accounting.traderforwarding when discount registry is set (trusted router).Audit
Deliverable
A short sign-off comment on this issue (or linked note) stating whether behavior matches expectations, listing any gaps between docs and code, and pointing to the test commands used.
@brouie The fee semantics in this issue are documented and covered by the referenced contract tests and docs (e.g.
docs/reference/fee-discount-tiers.md,docs/integrators.md,docs/contracts-security-audit.md,smartcontracts/tests/src/limit_order_tests.rsincluding hybrid/treasury cases). Could you please run through the verification checklist on this issue and add a short sign-off comment with any gaps you find and the test commands you used?@PlasticDigits Sign-off on fee verification. Tested on current main.
Documentation
Tests
Ran cargo test on full smartcontracts workspace:
309 passed, 0 failed across all crates including:
Relevant fee-specific tests all green (verified individually on earlier issues):
Code review
Gaps / findings
No gaps identified between docs and code. Fee math, discount tiers, pool-vs-book split, hybrid parity (maker at placement + taker per fill), treasury routing, and post-swap hook scope all aligned. L7 (hook pool-only) and L8 (hybrid-aware quoting required for book-inclusive estimates) explicit in docs and asserted in tests.
Sign-off
Fee behavior matches product expectations across the specified dimensions. Closing.