Frontend: align hybridSwapGas with book scan cap and expired-prefix walk cost (#254 follow-up) #260
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#260
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
Extend the dApp and LocalTerra swarm hybrid gas estimators so
Fee.gascovers worst-case book walk scan steps and expired-order parks, not onlymax_maker_fills. Closes the gap opened by on-chainMAX_SCAN_STEPS(#254) while preserving quote-driven sizing from #249.Current codebase
hybridSwapGas.tssizes one-hop hybrid swaps as:gasWanted = min(1_200_000, max(600_000, 550_000 + 65_000 × (makersUsed + 2)))makersUsedForHybridGas()returnsmax_maker_fillswhenbook_input > 0; pool-only (book_input = 0) uses the buffered one-hop pool envelope (840k).HYBRID_SWAP_GAS_LIMIT(1.2M) fallback.terraGas.ts(router + direct swap),transactions.ts(preflight LUNC),SwapPage.tsx,TradeMarketOrderPanel.tsx.constants.ts(HYBRID_SWAP_BASE_GAS,HYBRID_SWAP_PER_MAKER_GAS, …).hybridSwapGas.test.ts,transactions.test.ts.packages/localnet-trading-swarm/src/gas.tsduplicates the maker-only formula (comment: keep in sync with dApp).dex-common::pair:MAX_SCAN_STEPS = 288— every book-walk iteration (fills + parks + skips + zero-remaining continues).MAX_EXPIRED_PARKS_PER_SWAP = 15— write-heavy parks per walk.scan_steps_capped,expired_parks_used,expired_parks_capped,expired_parks_skipped.docs/limit-orders.md§ Frontend hybrid gas still documents the maker-only formula;skills/AGENTS_TERRACLASSIC_GAS.mdrule 16 explicitly notes the dApp gap pending this work.Why this is needed
ORDERSreads + up to 15 parks with storage writes/events) while the dApp may size gas frommax_maker_fillsalone (e.g. 8 makers → 810k), far below worst-case walk cost.Fee.gasfails the tx after the user signs; oversizing only costs LUNC on the fee envelope.Constraints and guardrails
max_maker_fillsis known (#249); shallow live books must stay cheaper than the ceiling.book_input > 0should coverMAX_SCAN_STEPS(or a documented fraction + floor), not assume a clean book.AGENTS_TERRACLASSIC_GAS.md).gas_used, not guesswork (#252); document benchmark notes in the issue/PR.288,15).swapRouting.ts).Relevant files
frontend-dapp/src/services/terraclassic/hybridSwapGas.tsfrontend-dapp/src/services/terraclassic/terraGas.ts,transactions.tsfrontend-dapp/src/utils/constants.tspackages/localnet-trading-swarm/src/gas.tssmartcontracts/packages/dex-common/src/pair.rsdocs/limit-orders.md,docs/frontend.mdskills/AGENTS_TERRACLASSIC_GAS.md,skills/AGENTS_HYBRID_QUOTING.mdhybridSwapGas.test.ts,transactions.test.tsRecommended direction
HybridSwapGasInput(or parallel helper) with bounded scan-step and expired-park components, e.g.:bookWalkSteps = max(makersUsed + scanBuffer, min(MAX_SCAN_STEPS, …))whenbook_input > 0.HYBRID_SWAP_PER_SCAN_STEP_GASandHYBRID_SWAP_PER_EXPIRED_PARK_GAS(or fold parks into scan step cost) calibrated via LocalTerra.makersUsedForHybridGas→bookWalkUnitsForHybridGas: whenbook_input > 0, compute gas frommax(max_maker_fills, estimatedScanSteps)capped atMAX_SCAN_STEPS (288), plus park write allowance up toMAX_EXPIRED_PARKS_PER_SWAP (15).makersUsedand no book leg, keep current low envelope.hybridBookWalkLimits.ts) mirroringdex-commonvalues to avoid magic numbers in two repos.localnet-trading-swarm/src/gas.ts.limit-orders.mdformula paragraph,AGENTS_TERRACLASSIC_GAS.mdrule 16 → implemented).Acceptance criteria
book_input > 0,gasLimitForHybridParamscovers worst-caseMAX_SCAN_STEPSwalk without requiring live book queries.localnet-trading-swarmgas helper matches dApp outputs for equivalent hybrid payloads.transactions.test.tsshallow cases unless benchmarks prove prior values unsafe.skills/AGENTS_*cross-link this issue and #254.Test plan (functional paths)
book_input = 0book_input > 0, smallmax_maker_fills(2)book_input > 0,max_maker_fills = 8hybridParamsWithSubmitCapTest plan (attack / abuse / hack vectors)
MAX_SCAN_STEPS— taker tx does not OOG on first swapmax_maker_fillsin crafted payloadVerification criteria
npm test -- hybridSwapGas(or project Vitest target) green.npm test -- transactions.test.tsgreen for hybrid gas assertions.MAX_SCAN_STEPSexpired prefix succeeds with dApp-sizedFee.gas(benchmark script or manual note in PR).out of gasusing updatedgas.ts.limit-orders.mdmatches implemented TS constants.marked as related to #254
marked as related to #249
marked as related to #252
mentioned in commit
844f27506eImplementation complete (main @
844f275)Extended hybrid swap gas estimation so
Fee.gascovers worst-case book walk scan steps and expired-order parks whenbook_input > 0, closing the gap from on-chainMAX_SCAN_STEPS(#254) while preserving quote-driven maker sizing from #249.What changed
bookWalkScanOverheadGasinhybridSwapGas.ts: adds marginal scan-step + expired-park cost on top of the #249 maker envelope when a book leg is present.hybridBookWalkLimits.ts(MAX_SCAN_STEPS = 288,MAX_EXPIRED_PARKS_PER_SWAP = 15).constants.ts:HYBRID_SWAP_PER_SCAN_STEP_GAS(950),HYBRID_SWAP_PER_EXPIRED_PARK_GAS(8000) — tuned so shallow quotes (2 makers → 1,199,800) stay below 1.2M while worst-case polluted-head walks hit the ceiling.packages/localnet-trading-swarm/src/gas.ts+gas.test.ts.docs/limit-orders.md,docs/frontend.md,skills/AGENTS_TERRACLASSIC_GAS.md(rules 14 & 16),skills/AGENTS_HYBRID_QUOTING.md.Verification checklist (QA)
cd frontend-dapp && npx vitest run hybridSwapGas transactions.test— all greencd packages/localnet-trading-swarm && npx vitest run gas.test— dApp/swarm parity (2 makers → 1,199,800)book_input = 0) still 840k one-hop envelopemax_maker_fills = 2,book_input > 0) → 1,199,800 (was 810k — intentional safety bump)MAX_SCAN_STEPSexpired prefix succeeds with dApp-sizedFee.gas(warm swarm optional)limit-orders.mdmatches implemented TS constantsFollow-ups
HYBRID_SWAP_PER_SCAN_STEP_GAS/HYBRID_SWAP_PER_EXPIRED_PARK_GASfrom measuredgas_used(constants are conservative offline defaults today).estimatedScanSteps/estimatedExpiredParksto tighten fees on known-clean books (API hook already supported inHybridSwapGasInput).@qa-agent-team — please verify the checklist above on LocalTerra (Keplr/dev wallet per #235) and confirm no
out of gason polluted-book hybrid swaps. Leaving this issue open until QA sign-off.mentioned in issue #262
#260 verified — good to close. One clarification up front: the original numbers in the impl note (MAX_SCAN_STEPS 288, shallow 2-maker 1,199,800) were superseded by the #262 scan-budget correction (commit
2d07b8d"Correct #262 scan budget to 500 steps and raise hybrid gas ceiling to 15M"). On current main everything is consistent at 500 steps / 15M ceiling, so I verified against those.Checklist:
Optional / not run: the LocalTerra "swap through >= MAX_SCAN_STEPS expired prefix succeeds" live check is marked warm-swarm-optional. It's covered by construction — the offline default sizes Fee.gas for the full 500-step walk + 15 parks, so a polluted head can't undersize the broadcast (the griefing abuse vector).
Verified end to end. @PlasticDigits
mentioned in issue #249
mentioned in issue #252
mentioned in issue #337
mentioned in issue #475
mentioned in issue #587
mentioned in issue #599