Create Trading Pair broken in dapp: #276 fee not attached + CREATE_PAIR_GAS_LIMIT below actual gas #345
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#345
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?
Severity: High — the Create Trading Pair page fails on every attempt; permissionless pair creation is unusable from the UI. Fails safely (no fund risk), contract is fine.
Reachability: any user, 100% of create-pair attempts.
Found: #337 CP-00-02.
Repro
Create page → two whitelisted, unpaired CW20s (both show "Code ID whitelisted") → Create Pair:
Root cause — two separate bugs
1. #276 creation fee not attached.
frontend-dapp/src/services/terraclassic/factory.tscreatePair()callsexecuteTerraContract(walletAddress, factory, { create_pair: {...} })with nocoinsargument, so zeroulunais sent. The factory requirespair_creation_fee_uluna(live value100000000) attached as funds, so it reverts. (origin/main still has this — not fixed upstream.)2.
CREATE_PAIR_GAS_LIMITtoo low.terraGas.tspins it at800000, but a realcreate_pair(instantiate pair + LP token) costs 871,552 gas. So even once the fee is attached, it OOGs ("needed more gas than estimated"). Same class as the add-liquidity gas gap.Contract is fine (isolation)
create_pairvia terrad with the fee attached succeeds:terrad tx wasm execute <factory> '{"create_pair":{"asset_infos":[IRON, AMBER]}}' --amount 100000000uluna --gas auto855DEFDE…, code 0,gas_used=871552, eventscreate_pair → instantiate → reply_instantiate_pair. New IRON/AMBER pair instantiated.Suggested fix
createPair()attachcoins: [{ denom: 'uluna', amount: <fee> }]. Read the fee from the factory config (pair_creation_fee_uluna) rather than hardcode, so it tracks governance changes (and skip/attach 0 when the fee is 0).CREATE_PAIR_GAS_LIMIT800000 → ~1000000 (over the measured 871,552 with headroom).Related (separate, lower priority)
New pairs are discovered lazily by the indexer —
sync_all_pairsruns once at startup (poller.rs:22); after that a pair is only added when the parser first sees a swap/fill/placement on it (parser.rs:367/777/1068). So a freshly-created empty pair won't appear in the pool/markets list until it's traded or the indexer restarts (#311 design). Worth a look as part of the create→discover flow.mentioned in issue #337
The same gas-underestimate class shows up on the fee-tier register, flagging here since it's the same root. The dapp register (feeDiscount.ts
register->{register:{tier_id}}) isn't handled ingetGasLimitForTx, so it falls through toBASE_GAS_LIMIT(200000). Measuredregistergas_used=208940 -> OOGs the same way ("needed more gas than estimated"). Contract is fine (terrad register tier 9 = code 0, get_discount 9500 bps).So the fixed gas limits in terraGas.ts look broadly uncalibrated vs current contract costs:
Might be worth a holistic pass — measure each execute path's real gas and set limits with headroom (or simulate per-tx) rather than chasing them one bug at a time.
mentioned in commit
1f1933956fmentioned in merge request !845
MR !844 opened
Changes:
createPair()readspair_creation_fee_ulunaand attaches uluna coins;CREATE_PAIR_GAS_LIMIT→ 1M; Create Pair page shows fee.Verify
npm test -- factory.test.tsgas_used≥ 871552Follow-up: indexer lazy empty-pair discovery (#311) unchanged.
mentioned in merge request !847
mentioned in merge request !849
mentioned in merge request !844
mentioned in merge request !846
mentioned in merge request !848
mentioned in commit
e7fba864e5mentioned in issue #353