Enforce net swap and AutoLP issuance floors with bounded hook work (#1398) #1425

Merged
PlasticDigits merged 1 commit from fix/issue-1398-net-floors into main 2026-10-06 06:23:37 +00:00
Owner

Hook deductions could reduce swap receipts below pre-hook price protection, hook lists had no admission cap, and AutoLP provided balances without an issuance floor. This implements the source remediation for #1398.

Pair execution now requires a positive signed net min_return whenever hooks are registered, while retaining the existing market max_spread calculation. Forward quotes share fail-closed tax/burn/LP-hook pricing with settlement; output-deducting hook reverse quotes explicitly error. Swap and Trade sign fresh direct-pool and hybrid net floors, preserving stronger reverse receive targets. Hook lists admit at most eight unique addresses; invalid legacy lists require explicit governance replacement.

AutoLP stores manager-approved reserves/share economics at pair binding, carries swap/LP/ratio bounds through replies, and checks the LP recipient's actual balance increase before unlocking. Failed swaps/provides/mints roll back balances, allowances, treasury payments, LP supply and state. Modular pricing and LP-policy helpers keep the guards shared and testable.

Pair 1.21.0, factory 1.12.0, router 1.4.0 and AutoLP 1.1.0 distinguish these changes. Router accounting explicitly recognizes the reviewed pair version while preserving the 33-per-hop/96-per-request ceilings and opaque future-version handling. Legacy AutoLP needs an initialized pool and explicit rebind by its actual manager; token-owned legacy managers need a separate authorized refresh path.

Issue acceptance, verified in source and synthetic tests:

  • AC1: Direct, pool/book/mixed, greedy and taxed router callers enforce signed post-hook net protection; missing, zero and excessive floors fail atomically.
  • AC2: Forward quote/execute deduction parity, explicit unsupported pricing, guarded reverse behavior and retained bounded hook-free reverse support.
  • AC3: Oversized/duplicate lists reject before mutation; exactly eight and ordered bounded legacy replacement are tested.
  • AC4: Anchored AutoLP net/LP/ratio floors, actual issuance reconciliation, prior-transaction front-run rejection and full failed-reply rollback.

Validation on commit 33ede534:

  • CONTRACTS_CARGO_HOME=/tmp/cl8y-1398-cargo-home CARGO_NET_OFFLINE=true make verify-issue-1398: 7 PASS, 0 FAIL, 0 SKIP in source scope; 977 workspace tests, 61 focused contract checks per pass, and 167 frontend tests per pass, with focused retest.
  • Strict workspace/all-targets Clippy, Rust/Prettier formatting, production frontend types/build and commit hooks passed. Frontend lint has five existing warnings and no errors; secret scan found no leaks.
  • Related make verify-issue-1390 and make verify-issue-1389 passed with explicit infrastructure skips. make verify-issue-1376 passed including all 14 Playwright receive-lifecycle smoke tests. The clean make verify-issue-1381 rerun completed 10 PASS, 0 FAIL, 4 SKIP, validating full contract/route regressions with the same documented infrastructure skips.
  • Earlier real-config and fixture failures, missing signed-floor mocks and reviewed-version budget mismatch were corrected and retested; no failed assertion was relabeled as a skip.

Agent review instructions and invariants:

  1. Read NE1398-1–NE1398-10 and the checked acceptance/review checklist.
  2. Check out this branch, run make verify-issue-1398, review the concrete balance/escrow/supply assertions, and retest after fixes.
  3. Complete available optimized-chain/gas/deployment checks. If an item cannot be completed, record SKIP with its observed reason, leave that item unchecked, and permit overall PASS WITH SKIPS when all executed checks pass. Executed failures remain FAIL until fixed and retested.

Unverified scope:

  • Final optimized wasm, isolated-chain acceptance and maximum-eight-hook/skim gas: isolated provisioning was attempted, but RPC refused/reset for over six minutes and Docker controls timed out. The obsolete optimizer run was canceled after source-receipt drift; no final artifact was accepted.
  • Indexer database checks: official Postgres setup timed out after 60 seconds; an isolated fallback remained Created after 30 seconds. No indexer source changed.
  • Production migration/signing, live receipts and token-owned legacy policy refresh: outside this source PR. Source PASS does not certify deployment; the issue remains open for review.
Hook deductions could reduce swap receipts below pre-hook price protection, hook lists had no admission cap, and AutoLP provided balances without an issuance floor. This implements the source remediation for [#1398](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1398). Pair execution now requires a positive signed net `min_return` whenever hooks are registered, while retaining the existing market `max_spread` calculation. Forward quotes share fail-closed tax/burn/LP-hook pricing with settlement; output-deducting hook reverse quotes explicitly error. Swap and Trade sign fresh direct-pool and hybrid net floors, preserving stronger reverse receive targets. Hook lists admit at most eight unique addresses; invalid legacy lists require explicit governance replacement. AutoLP stores manager-approved reserves/share economics at pair binding, carries swap/LP/ratio bounds through replies, and checks the LP recipient's actual balance increase before unlocking. Failed swaps/provides/mints roll back balances, allowances, treasury payments, LP supply and state. Modular pricing and LP-policy helpers keep the guards shared and testable. Pair 1.21.0, factory 1.12.0, router 1.4.0 and AutoLP 1.1.0 distinguish these changes. Router accounting explicitly recognizes the reviewed pair version while preserving the 33-per-hop/96-per-request ceilings and opaque future-version handling. Legacy AutoLP needs an initialized pool and explicit rebind by its actual manager; token-owned legacy managers need a separate authorized refresh path. Issue acceptance, verified in source and synthetic tests: - [x] AC1: Direct, pool/book/mixed, greedy and taxed router callers enforce signed post-hook net protection; missing, zero and excessive floors fail atomically. - [x] AC2: Forward quote/execute deduction parity, explicit unsupported pricing, guarded reverse behavior and retained bounded hook-free reverse support. - [x] AC3: Oversized/duplicate lists reject before mutation; exactly eight and ordered bounded legacy replacement are tested. - [x] AC4: Anchored AutoLP net/LP/ratio floors, actual issuance reconciliation, prior-transaction front-run rejection and full failed-reply rollback. Validation on commit `33ede534`: - `CONTRACTS_CARGO_HOME=/tmp/cl8y-1398-cargo-home CARGO_NET_OFFLINE=true make verify-issue-1398`: 7 PASS, 0 FAIL, 0 SKIP in source scope; 977 workspace tests, 61 focused contract checks per pass, and 167 frontend tests per pass, with focused retest. - Strict workspace/all-targets Clippy, Rust/Prettier formatting, production frontend types/build and commit hooks passed. Frontend lint has five existing warnings and no errors; secret scan found no leaks. - Related `make verify-issue-1390` and `make verify-issue-1389` passed with explicit infrastructure skips. `make verify-issue-1376` passed including all 14 Playwright receive-lifecycle smoke tests. The clean `make verify-issue-1381` rerun completed 10 PASS, 0 FAIL, 4 SKIP, validating full contract/route regressions with the same documented infrastructure skips. - Earlier real-config and fixture failures, missing signed-floor mocks and reviewed-version budget mismatch were corrected and retested; no failed assertion was relabeled as a skip. Agent review instructions and invariants: 1. Read [NE1398-1–NE1398-10](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/issue-1398-net-floors/skills/AGENTS_NET_EXECUTION_FLOORS.md) and the [checked acceptance/review checklist](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/fix/issue-1398-net-floors/docs/qa/issue-1398/README.md). 2. Check out this branch, run `make verify-issue-1398`, review the concrete balance/escrow/supply assertions, and retest after fixes. 3. Complete available optimized-chain/gas/deployment checks. If an item cannot be completed, record SKIP with its observed reason, leave that item unchecked, and permit overall PASS WITH SKIPS when all executed checks pass. Executed failures remain FAIL until fixed and retested. Unverified scope: - [ ] Final optimized wasm, isolated-chain acceptance and maximum-eight-hook/skim gas: isolated provisioning was attempted, but RPC refused/reset for over six minutes and Docker controls timed out. The obsolete optimizer run was canceled after source-receipt drift; no final artifact was accepted. - [ ] Indexer database checks: official Postgres setup timed out after 60 seconds; an isolated fallback remained Created after 30 seconds. No indexer source changed. - [ ] Production migration/signing, live receipts and token-owned legacy policy refresh: outside this source PR. Source PASS does not certify deployment; the issue remains open for review.
Enforce hook net floors and bounded AutoLP issuance
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
33ede5347c
Require signed net minima for hook-bearing swaps, cap hook fanout at eight, and anchor AutoLP issuance to approved pool economics. Preserve reverse query budgets across pair and router upgrades.
Sign in to join this conversation.
No reviewers
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!1425
No description provided.