Skip to content

feat(core): add minimal DEX swap_tokens_tool (#7)#893

Open
jmgomezl wants to merge 2 commits into
hashgraph:mainfrom
jmgomezl:feat/dex-swap-token-pair
Open

feat(core): add minimal DEX swap_tokens_tool (#7)#893
jmgomezl wants to merge 2 commits into
hashgraph:mainfrom
jmgomezl:feat/dex-swap-token-pair

Conversation

@jmgomezl

@jmgomezl jmgomezl commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What this does

Adds a minimal token swap tool, addressing #7.

It introduces a small core-dex-plugin with a single swap_tokens_tool that calls a Uniswap V2 style router's swapExactTokensForTokens(amountIn, amountOutMin, path, to, deadline). It's deliberately vendor-neutral: you pass the router contract, the token route, the amounts, and an optional deadline, so it works with any compatible Hedera DEX (SaucerSwap and similar) without baking in a specific provider.

I kept the surface area intentionally small, in line with the "minimal proof of concept" note on the issue.

How it works

  • New schema swapExactTokensForTokensParameters and a normaliseSwapExactTokensForTokensParams normaliser that resolves the route + recipient to EVM addresses, encodes the call with ethers, and defaults the deadline to 20 minutes out.
  • The tool follows the same shape as the existing ERC-20 tools (ECDSA operator assertion, HederaBuilder.executeTransaction, mode-aware handleTransaction).
  • Registered in the plugins barrel and documented in HEDERATOOLS.md / HEDERAPLUGINS.md.

A note on allowances

The input token needs an allowance granted to the router before swapping. Rather than bundle that in, the tool documents the prerequisite and points to the existing approve_token_allowance_tool, keeping each tool focused.

Testing

  • pnpm lint:check, pnpm build, and pnpm test:unit all pass.
  • New unit test covers metadata, the happy path, and error handling.

Possible follow-ups (out of scope here)

  • A dedicated ERC-20 approve tool (core currently only has the HTS allowance tool).
  • Quote/slippage helpers and multi-hop routing convenience.

Happy to adjust the naming, parameters, or structure to fit your conventions. Thanks for taking a look!

jmgomezl and others added 2 commits June 2, 2026 22:22
Implements a minimal, vendor-neutral token swap for issue hashgraph#7. Adds a new
core-dex-plugin with a single swap_tokens_tool that calls a Uniswap V2
style router's swapExactTokensForTokens(amountIn, amountOutMin, path, to,
deadline). Works with any compatible Hedera DEX router (e.g. SaucerSwap).

- shared/parameter-schemas/dex.zod.ts: swapExactTokensForTokensParameters
- shared/constants/contracts.ts: DEX swap ABI + function name
- shared/hedera-utils/hedera-parameter-normaliser.ts:
  normaliseSwapExactTokensForTokensParams (resolves route + recipient to
  EVM addresses, encodes via ethers, defaults deadline to +20m)
- plugins/core-dex-plugin: tool + plugin, registered in the plugins barrel
- tests/unit/tools/swap-tokens.unit.test.ts: metadata, happy path, error

The input token allowance to the router is a prerequisite; documented in
the tool prompt and delegated to the existing approve_token_allowance_tool.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: jmgomezl <juanmag.lpez@gmail.com>
Add the swap_tokens_tool reference (parameters, examples, scheduled
example) to HEDERATOOLS.md and the core-dex-plugin entry to
HEDERAPLUGINS.md, mirroring the existing EVM tool/plugin docs. Notes the
input-token allowance prerequisite and links the approve allowance tool.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: jmgomezl <juanmag.lpez@gmail.com>
@jmgomezl jmgomezl requested review from a team as code owners June 3, 2026 03:48
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