Fix: deploy-dex-local flat fees over-burn on terrad v4 (GitLab #292 followup) #315

Closed
opened 2026-06-05 04:08:29 +00:00 by PlasticDigits · 7 comments
PlasticDigits commented 2026-06-05 04:08:29 +00:00 (Migrated from gitlab.com)

Current codebase

scripts/deploy-dex-local.sh defines terrad_tx() with:

--gas auto \
--gas-adjustment 1.3 \
--fees 500000000uluna \

Every deploy-phase transaction (factory instantiate, pair creates, treasury fund, router setup, token mints, liquidity seeds) pays a flat 500M uluna fee regardless of actual gas used.

On LocalTerra terrad v4 / SDK 0.53 (GitLab #292), minimum gas price is ~28.325 uluna/gas. With --gas auto, actual gas wanted is typically far below 500M/28.325 — the script over-burns fees. Genesis test1 balance has drifted 1M → ~680k LUNC on repeated deploys.

Treasury funding step [9b.10]:

if terrad_query tx "$TX_HASH" | jq -e '.code == 0' >/dev/null 2>&1; then
  echo "  Treasury funded: ..."
else
  echo "  WARNING: Treasury fund tx may have failed ..."
fi

Failures only WARN; deploy continues. Wrap E2E may fail later with opaque errors.

scripts/deploy-dex-local.sh already writes VITE_GAS_PRICE_ULUNA=28.325 to .env.local (per skills/AGENTS_TERRACLASSIC_GAS.md) but does not use it for deploy txs.

Follow-up: GitLab #292.

Why this is needed

Repeated local deploys drain the single test1 genesis account, eventually breaking make deploy-local / E2E / swarm funding mid-run. Silent treasury fund failure wastes ~15 min optimizer+deploy before wrap tests fail.

Constraints / guardrails

  • Must work inside docker exec … terrad against pinned LocalTerra image (docs/localterra-sdk53.md).
  • Do not break CI e2e job or make qa-verify-deploy.
  • Keep terrad_tx helper as single choke point.
  • Prefer --gas-prices 28.325uluna (or query chain min) over flat --fees when using --gas auto.
  • Treasury fund failure should exit non-zero (or retry once) — not WARN-only.
  • Document env override e.g. DEPLOY_GAS_PRICES for future fee market changes.

Relevant files

Area Path
Deploy script scripts/deploy-dex-local.sh (terrad_tx, treasury fund)
Swarm funding packages/localnet-trading-swarm/src/funding.ts (also uses 500000000uluna)
Docs docs/localterra-sdk53.md, skills/AGENTS_TERRACLASSIC_GAS.md
QA scripts/qa/verify-deploy.sh, skills/AGENTS_QA_DEPLOY_VERIFY.md
  1. Replace --fees 500000000uluna with --gas-prices ${DEPLOY_GAS_PRICES:-28.325uluna} in terrad_tx.
  2. Optionally log actual fee paid on first tx for debugging.
  3. Change treasury fund check: on code != 0, print tx log and exit 1.
  4. Align packages/localnet-trading-swarm/src/funding.ts fee pattern.
  5. Note genesis headroom in deploy script header comment.

Acceptance criteria

  • Deploy script completes on fresh LocalTerra with test1 balance loss ≪ 500M×N uluna.
  • Treasury fund failure aborts deploy with actionable error.
  • make deploy-local / CI e2e path unchanged functionally.
  • Swarm funding uses consistent gas price approach.

Test plan (all paths)

Path Steps Expected
Full deploy make start && bash scripts/deploy-dex-local.sh Success; test1 balance documented
Treasury fail inject Mock insufficient balance for fund tx Script exits 1, no silent WARN
Repeat deploy Run deploy twice Second run still succeeds
Gas price override DEPLOY_GAS_PRICES=28.325uluna Same behavior

Attack / abuse / hack vectors

Vector N/A / note
Fee underpay → stuck txs --gas auto + min gas prices prevents
Script continues on failed fund Fixed by fail-fast

Verification criteria

  • Compare test1 uluna before/after deploy — overhead reduced vs baseline 500M flat fee.
  • make qa-verify-deploy passes after deploy.
  • Wrap E2E passes without manual treasury send.
## Current codebase `scripts/deploy-dex-local.sh` defines `terrad_tx()` with: ```bash --gas auto \ --gas-adjustment 1.3 \ --fees 500000000uluna \ ``` Every deploy-phase transaction (factory instantiate, pair creates, treasury fund, router setup, token mints, liquidity seeds) pays a **flat 500M uluna fee** regardless of actual gas used. On LocalTerra **terrad v4 / SDK 0.53** (GitLab **#292**), minimum gas price is ~**28.325 uluna/gas**. With `--gas auto`, actual gas wanted is typically far below 500M/28.325 — the script **over-burns** fees. Genesis test1 balance has drifted **1M → ~680k LUNC** on repeated deploys. Treasury funding step `[9b.10]`: ```bash if terrad_query tx "$TX_HASH" | jq -e '.code == 0' >/dev/null 2>&1; then echo " Treasury funded: ..." else echo " WARNING: Treasury fund tx may have failed ..." fi ``` Failures only **WARN**; deploy continues. Wrap E2E may fail later with opaque errors. `scripts/deploy-dex-local.sh` already writes `VITE_GAS_PRICE_ULUNA=28.325` to `.env.local` (per `skills/AGENTS_TERRACLASSIC_GAS.md`) but does not use it for deploy txs. Follow-up: GitLab **#292**. ## Why this is needed Repeated local deploys drain the single test1 genesis account, eventually breaking `make deploy-local` / E2E / swarm funding mid-run. Silent treasury fund failure wastes ~15 min optimizer+deploy before wrap tests fail. ## Constraints / guardrails - Must work inside `docker exec … terrad` against pinned LocalTerra image (`docs/localterra-sdk53.md`). - Do not break CI `e2e` job or `make qa-verify-deploy`. - Keep `terrad_tx` helper as single choke point. - Prefer `--gas-prices 28.325uluna` (or query chain min) over flat `--fees` when using `--gas auto`. - Treasury fund failure should **exit non-zero** (or retry once) — not WARN-only. - Document env override e.g. `DEPLOY_GAS_PRICES` for future fee market changes. ## Relevant files | Area | Path | |------|------| | Deploy script | `scripts/deploy-dex-local.sh` (`terrad_tx`, treasury fund) | | Swarm funding | `packages/localnet-trading-swarm/src/funding.ts` (also uses `500000000uluna`) | | Docs | `docs/localterra-sdk53.md`, `skills/AGENTS_TERRACLASSIC_GAS.md` | | QA | `scripts/qa/verify-deploy.sh`, `skills/AGENTS_QA_DEPLOY_VERIFY.md` | ## Recommended direction 1. Replace `--fees 500000000uluna` with `--gas-prices ${DEPLOY_GAS_PRICES:-28.325uluna}` in `terrad_tx`. 2. Optionally log actual fee paid on first tx for debugging. 3. Change treasury fund check: on `code != 0`, print tx log and `exit 1`. 4. Align `packages/localnet-trading-swarm/src/funding.ts` fee pattern. 5. Note genesis headroom in deploy script header comment. ## Acceptance criteria - [ ] Deploy script completes on fresh LocalTerra with test1 balance loss ≪ 500M×N uluna. - [ ] Treasury fund failure aborts deploy with actionable error. - [ ] `make deploy-local` / CI e2e path unchanged functionally. - [ ] Swarm funding uses consistent gas price approach. ## Test plan (all paths) | Path | Steps | Expected | |------|-------|----------| | Full deploy | `make start && bash scripts/deploy-dex-local.sh` | Success; test1 balance documented | | Treasury fail inject | Mock insufficient balance for fund tx | Script exits 1, no silent WARN | | Repeat deploy | Run deploy twice | Second run still succeeds | | Gas price override | `DEPLOY_GAS_PRICES=28.325uluna` | Same behavior | ## Attack / abuse / hack vectors | Vector | N/A / note | |--------|------------| | Fee underpay → stuck txs | `--gas auto` + min gas prices prevents | | Script continues on failed fund | Fixed by fail-fast | ## Verification criteria - Compare test1 uluna before/after deploy — overhead reduced vs baseline 500M flat fee. - `make qa-verify-deploy` passes after deploy. - Wrap E2E passes without manual treasury send.
PlasticDigits commented 2026-06-05 04:08:30 +00:00 (Migrated from gitlab.com)

marked as related to #292

marked as related to #292
Brouie commented 2026-06-05 06:10:49 +00:00 (Migrated from gitlab.com)

mentioned in merge request !772

mentioned in merge request !772
Brouie commented 2026-06-05 06:11:10 +00:00 (Migrated from gitlab.com)

Bundled this with #318 since both live in the deploy path.

  • terrad_tx and the swarm funding.ts now use --gas-prices ${DEPLOY_GAS_PRICES:-28.325uluna} instead of the flat --fees 500000000uluna, so deploy stops over-burning on terrad v4.
  • Treasury fund step now exits non-zero (prints the raw log) on a failed tx instead of WARN-and-continue, so a bad fund doesn't silently break wrap E2E later.

Checked live: a tx now pays ~5,155,150 uluna (gas_wanted 182000 × 28.325) vs the old flat 500,000,000 — about 97% less per tx, which is what was draining test1 across repeated deploys.

Branch qa/318-315-deploy-fee-gas, commit f5747ed, MR !772. @PlasticDigits

Bundled this with #318 since both live in the deploy path. - terrad_tx and the swarm funding.ts now use --gas-prices ${DEPLOY_GAS_PRICES:-28.325uluna} instead of the flat --fees 500000000uluna, so deploy stops over-burning on terrad v4. - Treasury fund step now exits non-zero (prints the raw log) on a failed tx instead of WARN-and-continue, so a bad fund doesn't silently break wrap E2E later. Checked live: a tx now pays ~5,155,150 uluna (gas_wanted 182000 × 28.325) vs the old flat 500,000,000 — about 97% less per tx, which is what was draining test1 across repeated deploys. Branch qa/318-315-deploy-fee-gas, commit f5747ed, MR !772. @PlasticDigits
Brouie commented 2026-06-05 06:11:10 +00:00 (Migrated from gitlab.com)

mentioned in issue #318

mentioned in issue #318
PlasticDigits commented 2026-06-05 07:59:29 +00:00 (Migrated from gitlab.com)

mentioned in commit 019ded61e2

mentioned in commit 019ded61e24c4de8f99d570f8c43aa5ffea2953d
totdking commented 2026-06-05 09:48:34 +00:00 (Migrated from gitlab.com)

mentioned in issue #325

mentioned in issue #325
PlasticDigits (Migrated from gitlab.com) closed this issue 2026-06-05 10:35:14 +00:00
PlasticDigits commented 2026-06-05 10:35:22 +00:00 (Migrated from gitlab.com)

Verification report — GitLab #315

Issue: Fix: deploy-dex-local flat fees over-burn on terrad v4 (#292 followup)

Implementation: Merged via !772 (fix(deploy): attach pair-creation fee + gas-prices on local deploy (#318, #315)). Verified on main @ 1c4ad92.

Acceptance criteria

Criterion Result How verified
Deploy completes with test1 gas overhead ≪ 500M×N uluna PASS Full deploy (./scripts/setup-cloud-agent-localterra.sh --no-indexer) completed; 237 txs logged gas estimate. Per-tx fee on-chain: 5,155,150 uluna (gas 182k × 28.325) vs old flat 500,000,000 (99% less gas per tx). Hypothetical flat total: 118.5B uluna; estimated gas-prices total: ~1.22B uluna.
Treasury fund failure aborts deploy (not WARN-only) PASS grep 'ERROR: Treasury fund tx failed' scripts/deploy-dex-local.sh — exits 1 + prints raw_log. No WARNING: Treasury fund tx may have failed remains. Insufficient-funds bank send fails at terrad_tx (set -e) before silent continue.
make deploy-local / CI e2e path unchanged functionally PASS make qa-verify-deploy and make test-qa-verify-deploy OK after deploy. Repeat deploy with DEPLOY_GAS_PRICES=28.325uluna completed end-to-end.
Swarm funding uses consistent gas-prices PASS packages/localnet-trading-swarm/src/funding.ts uses process.env.DEPLOY_GAS_PRICES ?? '28.325uluna'. npm run test:run in swarm package: 14/14 tests passed.

Test plan

Path Result Evidence
Full deploy PASS /tmp/setup-localterra.log — EXIT=0, Phase 6.3 stamp written
Treasury fail inject PASS Script fail-fast path confirmed; oversized bank send rejected (no silent WARN)
Repeat deploy PASS Second DEPLOY_GAS_PRICES=28.325uluna bash scripts/deploy-dex-local.sh succeeded; treasury funded line present
Gas price override PASS Same as repeat deploy with explicit DEPLOY_GAS_PRICES

Additional checks

  • bash -n scripts/deploy-dex-local.sh — PASS
  • terrad_tx choke point uses --gas-prices "${DEPLOY_GAS_PRICES:-28.325uluna}" — PASS
  • Genesis headroom comment at [9b.10] — PASS
  • make qa-verify-deploy after both deploys — PASS

Notes

  • test1 uluna after two deploys on this reused volume: 274,214,818,083 micro-LUNC (genesis 1M LUNC minus pair-creation fees, treasury funding, liquidity seeds, and gas — deploy remains repeatable).
  • DEPLOY_GAS_PRICES is implemented in deploy + swarm code; optional doc cross-link in docs/localterra-sdk53.md / skills/AGENTS_TERRACLASSIC_GAS.md was not required for functional acceptance.

Verifier: Cursor Cloud Agent (agent:verify automation)

## Verification report — GitLab #315 **Issue:** [Fix: deploy-dex-local flat fees over-burn on terrad v4 (#292 followup)](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/work_items/315) **Implementation:** Merged via [!772](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/54) (`fix(deploy): attach pair-creation fee + gas-prices on local deploy (#318, #315)`). Verified on `main` @ `1c4ad92`. ### Acceptance criteria | Criterion | Result | How verified | |-----------|--------|--------------| | Deploy completes with test1 gas overhead ≪ 500M×N uluna | **PASS** | Full deploy (`./scripts/setup-cloud-agent-localterra.sh --no-indexer`) completed; **237** txs logged `gas estimate`. Per-tx fee on-chain: **5,155,150 uluna** (gas ~182k × 28.325) vs old flat **500,000,000** (~**99%** less gas per tx). Hypothetical flat total: 118.5B uluna; estimated gas-prices total: ~1.22B uluna. | | Treasury fund failure aborts deploy (not WARN-only) | **PASS** | `grep 'ERROR: Treasury fund tx failed' scripts/deploy-dex-local.sh` — exits 1 + prints `raw_log`. No `WARNING: Treasury fund tx may have failed` remains. Insufficient-funds bank send fails at `terrad_tx` (`set -e`) before silent continue. | | `make deploy-local` / CI e2e path unchanged functionally | **PASS** | `make qa-verify-deploy` and `make test-qa-verify-deploy` OK after deploy. Repeat deploy with `DEPLOY_GAS_PRICES=28.325uluna` completed end-to-end. | | Swarm funding uses consistent gas-prices | **PASS** | `packages/localnet-trading-swarm/src/funding.ts` uses `process.env.DEPLOY_GAS_PRICES ?? '28.325uluna'`. `npm run test:run` in swarm package: **14/14** tests passed. | ### Test plan | Path | Result | Evidence | |------|--------|----------| | Full deploy | **PASS** | `/tmp/setup-localterra.log` — `EXIT=0`, Phase 6.3 stamp written | | Treasury fail inject | **PASS** | Script fail-fast path confirmed; oversized bank send rejected (no silent WARN) | | Repeat deploy | **PASS** | Second `DEPLOY_GAS_PRICES=28.325uluna bash scripts/deploy-dex-local.sh` succeeded; treasury funded line present | | Gas price override | **PASS** | Same as repeat deploy with explicit `DEPLOY_GAS_PRICES` | ### Additional checks - `bash -n scripts/deploy-dex-local.sh` — **PASS** - `terrad_tx` choke point uses `--gas-prices "${DEPLOY_GAS_PRICES:-28.325uluna}"` — **PASS** - Genesis headroom comment at `[9b.10]` — **PASS** - `make qa-verify-deploy` after both deploys — **PASS** ### Notes - test1 uluna after two deploys on this reused volume: **274,214,818,083** micro-LUNC (genesis 1M LUNC minus pair-creation fees, treasury funding, liquidity seeds, and gas — deploy remains repeatable). - `DEPLOY_GAS_PRICES` is implemented in deploy + swarm code; optional doc cross-link in `docs/localterra-sdk53.md` / `skills/AGENTS_TERRACLASSIC_GAS.md` was not required for functional acceptance. **Verifier:** Cursor Cloud Agent (`agent:verify` automation)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic#315
No description provided.