Skip to content

fix: integrate validated V1 swaps and liquidity with canonical EVM recipients - #7

Merged
jmgomezl merged 4 commits into
mainfrom
prototype/uint256-deadline-compat
Nov 16, 2026
Merged

jmgomezl merged 4 commits into
mainfrom
prototype/uint256-deadline-compat

Conversation

@jmgomezl

Copy link
Copy Markdown
Collaborator

Integration

Cumulative integration of #5 and #6, preserving their commits, plus exact uint256 encoding, explicit deadline compatibility, canonical mirror-resolved EVM recipients, and testnet REST API defaults. Targets main so CI validates the complete stack rather than landing known-broken intermediate states. Merge with a merge commit to preserve ancestry.

Validation

  • 122 unit tests, typecheck, lint and build pass locally.
  • SDK 2.84.0 and 2.91.0 tested; ESM/CJS transaction uint256 roundtrip (0, 2^64, max256) and overflow rejection pass.
  • Controlled testnet swaps in both directions, add liquidity, remove only minted LP, and allowance cleanup succeeded. No mainnet transactions. Final LP and router allowances zero.
  • Package dry-run contains only the 9 intended package files, no credentials or private harness.

Limitations and safeguards

  • Exact uint256 decimal strings use supported SDK runtime behavior through a documented type boundary; legacy deadline semantics intentionally retained; explicit timestamp/minutes fields remove ambiguity for new callers.
  • Default 2M gas was insufficient for tested removal. Successful retry used an exact read-only gas estimate and conservative cap. No automatic cap increase: applications must estimate exact calls, budget gas separately from nominal maximum transaction fee, and resolve uncertain transaction outcomes before any retry. See docs/CONFIGURATION.md.
  • VM native Node gRPC dropped and default Axios REST reads returned HTTP 502. Controlled testnet execution used official SDK browser gRPC-Web and injected read-only REST clients. These adapters are not shipped; default target-environment transport and full Agent Kit execute/secondaryAction modes need separate validation.
  • No production-readiness or mainnet validation claim. No npm publishing workflow is added or triggered; Juan will publish npm himself.

User explicitly authorized merging the completed fixes; this draft awaits checks before merge.

jmgomezl and others added 4 commits September 29, 2026 22:45
SaucerSwap's REST API has no quote endpoint: GET /v1/swap/quote returns
404 on mainnet and testnet, so the quote and swap tools always failed
and no swap transaction was ever built.

- Quote with the V1 router getAmountsOut through the mirror node
  POST /api/v1/contracts/call (free, no API key). Try the direct pair
  and a two-hop route through WHBAR, keep the best output.
- Derive price impact from each pair's getReserves/token0.
- HBAR input uses swapExactETHForTokens with a payable amount; HBAR
  output uses swapExactTokensForETH.
- Check the router token allowance for HTS input on the mirror node and
  return approval instructions instead of a transaction that reverts.
- Swaps always use the V1 router; the V2 router has a different ABI.
- Report estimatedOutput and minOutput in decimal units. The core
  payload shape { transaction, extras } is unchanged.
- New mirrorNodeUrl / SAUCERSWAP_MIRROR_NODE_URL setting.
- toUint256 is unsigned; formatUnits handles 0 decimals.
- Bump to 2.2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Juan Gomez <juanmag.lpez@gmail.com>
The liquidity tools sent V1-style addLiquidity/removeLiquidity calls to
the V2 router whenever defaultPoolVersion was "v2" (the default). The
V2 router is a concentrated-liquidity router with a different ABI, so
those transactions could never succeed.

- Add and remove liquidity always use the V1 router (routerContractId).
- HBAR as one side: addLiquidityETH with the HBAR amount as payable,
  removeLiquidityETH on removal.
- Remove liquidity looks up the pool and LP token in the V1 pool list.
- Check router allowances on the mirror node before building: every HTS
  deposit on add, the LP token on remove. Return approval instructions
  instead of a transaction that reverts.
- Share the allowance check with the swap tool (src/utils/allowance.ts)
  and the V1 router requirement (requireV1Router).
- Docs: liquidity sections, router allowances, v2 router not used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Juan Gomez <juanmag.lpez@gmail.com>
Validate account mirror metadata, cover recipient ABI encoding and network defaults, and document gas budgets and transport validation limits. 122 tests plus typecheck/lint/build and ESM/CJS encoding validation pass. No mainnet validation or stable release.
@jmgomezl
jmgomezl marked this pull request as ready for review November 16, 2026 23:20
@jmgomezl
jmgomezl merged commit 434c0ec into main Nov 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant