Pool: auto-fill provide counterpart amounts + withdraw receive preview #480
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#480
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
User feedback from mainnet Pool UX (
dex.cl8y.co):These are related Pool form improvements that share the same reserve math already used for Estimated LP /
min_assets. Bundle them in one issue.Related closed work: #109 added balances, Max/50%, Estimated LP, and the unbalanced-ratio warning, but did not implement counterpart auto-fill (it was listed as an optional direction). #462 added the pre-sign summary; withdraw still shows LP amount only.
Current codebase
Provide (
expanded === 'add'inPoolCard)frontend-dapp/src/pages/PoolPage.tsx— two independent inputs (amountA/amountB); Max/50% sets one side only; nolastEditedSide/ linked editing.frontend-dapp/src/utils/provideLiquidityEstimate.ts:estimateProvideLiquidityUserLp— mirrors on-chain LP mint.isProportionalAddAmounts— detects off-ratio deposits; UI shows donation warning whenfalse.min(lpA, lpB)and credits full declared amounts to reserves (excess is effectively donated to existing LPs). Warning is informational only.PoolPreSubmitSummary) shows typed A/B amounts.Withdraw (
expanded === 'remove')0.5/1.0/2.0).withdrawMinAssetAmountsinfrontend-dapp/src/utils/rawAmountMath.tscomputes slippage-adjustedmin_assetsfor the tx — not shown as a human “you receive ~X / ~Y” preview."X LP"only — no underlying token breakdown.Shared data already available
getPool/poolQuery→ reserves +total_share(no new contract or indexer API required).simulate_provide/simulate_withdrawquery; client-side BigInt floor math is the established pattern (same as Estimated LP).Relevant files
frontend-dapp/src/pages/PoolPage.tsxfrontend-dapp/src/utils/provideLiquidityEstimate.tsfrontend-dapp/src/utils/rawAmountMath.tswithdrawMinAssetAmounts(slippage mins)frontend-dapp/src/components/pool/PoolPreSubmitSummary.tsxfrontend-dapp/src/components/common/AmountBalanceActions.tsxfrontend-dapp/src/services/terraclassic/pair.tsgetPool,provideLiquidity,withdrawLiquidityfrontend-dapp/src/utils/maxSpendableAmount.tspackages/localnet-trading-swarm/src/liquidityGuards.tspickScaledProvideAmounts(reference only; not used by dApp)smartcontracts/contracts/pair/src/contract.rsfrontend-dapp/src/pages/PoolPage.test.tsxfrontend-dapp/src/utils/__tests__/provideLiquidityEstimate.test.tsfrontend-dapp/src/utils/__tests__/rawAmountMath.test.tsfrontend-dapp/e2e/pool.spec.ts/e2e/helpers/pool-ui.tsWhy this is needed
Constraints / guardrails
0, there is no pool price; do not auto-fill. User sets both amounts (initial price). Keep Estimated LP /MINIMUM_LIQUIDITYbehavior (#124).isProportionalAddAmounts === false.provideRawAddA/provideRawAddB), not gross UI strings alone.withdrawMinAssetAmounts. Actual execution uses on-chain state at inclusion time.PoolPagecurrently hardcodesLP_DECIMALS = 6while on-chain LP CW20 is 18 decimals (#124). Do not silently “fix” decimals as part of this issue unless required for correct preview; if touched, call it out in the MR and keep scope minimal.slippage_tolerancebut UI passesnull) — optional follow-up only.Recommended direction
A. Provide auto-fill
provideLiquidityEstimate.ts), e.g.computeProportionalCounterpartRaw(editedSide, editedRaw, pool.assets)→ counterpart raw ornull(empty/one-sided reserves).PoolCard, track last-edited side (state or ref) to avoid feedback loops.ratioBalancedwarning for deliberate off-ratio edits.Reference math for non-empty pool:
counterpart_B = floor(amount_A × reserve_B / reserve_A)(and symmetric).B. Withdraw estimation preview
estimateWithdrawAssetAmounts(lp, total_share, reserveA, reserveB)= pro-rata at 0% slippage (shared core withwithdrawMinAssetAmounts).lpAmount+poolQuery.dataare present, show e.g.Estimated receive: ~X TOKEN_A + ~Y TOKEN_B(aria-livelike Estimated LP).Minimum receive (N% slippage): …from existing helper.PoolPreSubmitSummaryamountLinesfor withdraw to include underlying token amounts (not LP-only).Acceptance criteria
Test plan (all paths)
Unit
computeProportionalCounterpartRaw(or equivalent): balanced round-trip floor cases; empty pool →null; zero/invalid input →null; asymmetric reserves.estimateWithdrawAssetAmounts: matches pro-rata floor; agrees withwithdrawMinAssetAmounts(..., 0)(or shared core); tiny LP → possible zero on one side.isProportionalAddAmounts/ LP estimate tests still pass with auto-filled amounts.Component (
PoolPage.test.tsx)data-testids.E2E (optional smoke)
e2e/pool.spec.ts: provide panel shows synced counterpart after typing one side (LocalTerra pair with reserves).Native wrap / CW20 paths
Test plan — attack / hack / abuse vectors
0; UI must not submit misleading “balanced” state; Estimated LP / gates handle zero.min_assets; document that expected ≠ guaranteed.Numberprecision loss for raw math.Verification criteria
/pool→ Provide on a pair with reserves → enter one amount → counterpart matchesfloor(amount × reserve_other / reserve_self)within display formatting.ratioBalanced !== false).minside.poolLCD query; changing slippage updates minimum line if shown; broadcast still uses existingwithdrawMinAssetAmounts.make test-frontend(or targeted vitest files above) green; optional Playwright smoke if added.Out of scope
slippage_toleranceUI.6→18) unless required for correctness of this preview (track separately if needed).marked as related to #109
marked as related to #462
mentioned in commit
cb0276629cmentioned in merge request !1017
mentioned in commit
21d3df31c6mentioned in issue #531
mentioned in issue #533
mentioned in issue #660
mentioned in issue #661