bug: Swap input not scaled by token decimals — sends micro-units instead of tokens #15
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#15
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?
Description
The swap page passes the user's input amount directly to the swap contract without multiplying by 10^decimals. Entering '10000' sends 10000 micro-units (0.01 tokens) instead of 10000 tokens (10000000000 micro-units).
Root Cause
SwapPage.tsx line 102 passes raw inputAmount to swap():
return swap(address, offerLabel, selectedPair.contract_addr, inputAmount, ...)No conversion like
BigInt(parseFloat(inputAmount) * 10**6).toString()is applied.Evidence
Expected
User input should be multiplied by 10^decimals (10^6 for CW20 tokens) before sending to the contract.
Impact
Critical — all swaps execute at dust amounts. Users think they swapped 10000 tokens but actually swapped 0.01 tokens.
mentioned in issue #1
Same decimals bug confirmed on Pool page. Provide Liquidity also passes raw user input without scaling by 10^decimals. Entering 1000 EMBER/CORAL added ~0.001 tokens to the pool instead of 1000 tokens.
Affects: SwapPage.tsx, PoolPage.tsx — likely anywhere user input amounts are sent to contracts.
mentioned in issue #18
Fix pushed on branch
fix/issue-15-decimal-scaling(commite5da3ec).Changes:
toRawAmount(humanAmount, decimals)andfromRawAmount(rawAmount, decimals)utility functions toformatAmount.tssimulateSwap()andswap()now receive amounts scaled by 10^decimals;insufficientBalancecheck compares raw units correctly; Max button sets human-readable amountprovideLiquidity()andwithdrawLiquidity()now receive amounts scaled by 10^decimals; LP Max button usesfromRawAmountinstead of abbreviated display valueAll user-facing inputs (swap, provide liquidity, withdraw liquidity) are now properly converted from human-readable token amounts to on-chain micro-units before being sent to contracts.
Requesting review from @Brouie.
mentioned in merge request !720
mentioned in commit
e5da3ec330mentioned in commit
d1a230e1e4Verified fixed — swapping 100 EMBER now deducts exactly 100,000,000 micro-units (100 tokens). Before: 895770474907, After: 895670474907. Decimals scaling working correctly.
mentioned in issue #49
mentioned in issue #50