Limit orders impossible on UST1/USTR: 6-vs-18-decimal pair breaches MAX_LIMIT_PRICE ~79,000x #529
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#529
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?
Summary
No limit order can be placed on UST1/USTR in either orientation, so one of the three launch pairs has no usable order book. Pool swaps are unaffected.
The pair contract bounds limit prices to
[MIN_LIMIT_PRICE, MAX_LIMIT_PRICE]=[1e-9, 1e9]token1-per-token0 in raw base units (limit_placement.rs, from #467). UST1 has 6 decimals, USTR has 18, so the raw price carries a ×10¹² unit factor on top of the human price:78.76 × 10¹² ≈ 7.9e13→ over MAX by ~78,760×≈ 1.3e-14→ under MIN by ~78,760×Every
place_limit_order_batchreverts withInvalid hybrid parameters(e.g.EF2AD63D440B9112E133FABCB97E63603E6CFACCF76E34955D9DD7D2DE66918F,0A4DFD172517B67E5BBA743CE449F58A1DD77131B8B4F3C2219D090096CAC28A). Any pair with a large decimals gap will hit the same wall.Root cause
#467's bounds guard against
Uint128overflow infill × price/1/price— a property of raw magnitudes — but "extreme" was implicitly calibrated for like-decimal pairs. A 6-vs-18 pair is economically ordinary (79 USTR per UST1) yet numerically extreme purely from unit scale.Recommended fix: validate a decimals-normalized price
Apply the
[1e-9, 1e9]bounds toprice_raw × 10^(dec0 − dec1)(i.e. the human-scale price), keeping the raw value for execution. This preserves #467's intent — reject economically absurd prices — without penalizing legitimate decimal gaps.Overflow check (so this doesn't reopen #467): on UST1/USTR at 7.9e13 raw,
fill × pricefor a 1,000,000-UST1 order is ≈7.9e25 vsUint128::MAX≈3.4e38 — ~4e12× headroom; a 1-UST1 order sits at 7.9e19. The raw price also fitsDecimal(max ≈3.4e20) comfortably. Normalizing the validation is therefore safe without touching the fill arithmetic for any realistic 6/18 pair.Alternatives considered
Both inferior to normalization.
Happy to retest instantly once a fix is migrated — we have the book ready to go live on UST1/USTR.
mentioned in issue #530
mentioned in merge request !1060
mentioned in issue #532
marked as related to #532
Deploy/migrate tracker: #532 (pair wasm + factory
pair_code_id+ frontend ship). Code fix is !1060.Ops note: pair
CONTRACT_VERSIONis still1.12.0in !1060 — same-versionwasm migratewill be rejected. Bump to1.13.0before store/migrate. Details and sequence are on #532.Merge sanity check for !1060 (before landing on main):
make verify-issue-529was green on the MR SHA.Invalid hybrid parameterson live 6/18 pairs.mentioned in commit
f77caabb5cmentioned in commit
781f87c52dmentioned in commit
9ee15f75ecmentioned in commit
9fd8b4eadfmentioned in issue #534
mentioned in commit
f7668ffefamentioned in commit
8ef35d4cf1columbus-5 migrate + dApp deploy are live. Please smoke a UST1/USTR limit.
@leonardocolucci you offered to retest as soon as this was migrated — the book should place now.
On-chain
data_hashb5f40d61fe98bec120bad5f078d274e26b1b51927a33ceeb6d95420ca53a2cd9)76FF330225FC8323E0A0E8F5553B58F36DDBE14A555FA1C34C8CF7055F0CCDE5cl8y-dex-pair/1.13.0), including UST1/USTRterra16vxrhpvpcucu05y0nr862vf9hnqeh274uaff4s7hz4n0ea74006qf5hgqyABE79F5AE309BF4798617B2253E37C809FD8A9A318D6A42C363473C1F37ECEB9pair_code_id11582:8EFA819279F2BCBA99BE6B963E06AC46C2ADBB77720D57D9F4844373D6AA9AEBf7668ff(cw2 bump) +40e614a(frontend tsc) +8ef35d4(optimizer checksums)Placement now applies
[1e-9, 1e9]to the human priceraw × 10^(decimals0 − decimals1)(L20). Execution still stores raw. Typed ~79 USTR/UST1 is in-band.dApp
https://dex.cl8y.comrebuilt frommain(Coolify). UI stays human; submit scales human → raw.Smoke
Invalid hybrid parameters)Indexer was not redeployed (limit-book
pricestrings stay raw).Retested on mainnet after the migrate — book places now.
0944E85F3BD54EC9A75FC3A5E6A99A8BAC96DFA7E79D4BFAED3CF0914AB256EE(order #4)0ED3D8C2D5E4824FF6DAFD58607AFD982E0D0881F67DCBC210C45174227F56DD(order #5)Both rested and cancelled cleanly (
93585F9D352565BD94FBE52D70E71D8D7A792AC6D8D37953D9D25EE0F71EDE72). Thanks for the fast turnaround.Side note from the smoke (separate issue incoming):
effective_fee_bpscame back 180 → the pair has no discount registry set (discount_registryraw state = null on all three economic pairs).mentioned in issue #546
mentioned in issue #564
mentioned in issue #589
mentioned in issue #676
mentioned in issue #717