feat(core): add minimal DEX swap_tokens_tool (#7)#893
Open
jmgomezl wants to merge 2 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Adds a minimal token swap tool, addressing #7.
It introduces a small
core-dex-pluginwith a singleswap_tokens_toolthat calls a Uniswap V2 style router'sswapExactTokensForTokens(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
swapExactTokensForTokensParametersand anormaliseSwapExactTokensForTokensParamsnormaliser that resolves the route + recipient to EVM addresses, encodes the call withethers, and defaults the deadline to 20 minutes out.HederaBuilder.executeTransaction, mode-awarehandleTransaction).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, andpnpm test:unitall pass.Possible follow-ups (out of scope here)
approvetool (core currently only has the HTS allowance tool).Happy to adjust the naming, parameters, or structure to fit your conventions. Thanks for taking a look!