hak-saucerswap-plugin 1.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Juanma Gomez
3
+ Copyright (c) 2026 Juan Manuel Gómez López
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -15,6 +15,14 @@ lets AI agents:
15
15
  - Add/remove liquidity via router transactions
16
16
  - Discover farming opportunities
17
17
 
18
+ ## Documentation
19
+
20
+ - **[Configuration](./docs/CONFIGURATION.md)** — full settings table, env vs. plugin-config
21
+ precedence, and pointers to the official SaucerSwap contract deployment list.
22
+ - **[Tools](./docs/TOOLS.md)** — per-tool reference (parameters, return shape, example prompts,
23
+ error behavior) for all six tools registered by the plugin.
24
+ - **[Examples](./docs/EXAMPLES.md)** — dry-run swap, CLI wrapper, and integration smoke test.
25
+
18
26
  ## Installation
19
27
 
20
28
  ```bash
@@ -24,108 +32,48 @@ npm install hak-saucerswap-plugin
24
32
  ## Quick Start
25
33
 
26
34
  ```ts
27
- import { saucerswapPlugin } from "hak-saucerswap-plugin";
35
+ import { saucerswapPlugin, SAUCERSWAP_MAINNET } from "hak-saucerswap-plugin";
28
36
 
29
- const agent = new HederaAgent({
30
- plugins: [saucerswapPlugin]
31
- });
32
- ```
33
-
34
- ## Configuration
35
-
36
- Provide router contract IDs and (optionally) token aliases via environment or plugin config.
37
-
38
- ```bash
39
- export SAUCERSWAP_ROUTER_CONTRACT_ID=0.0.123456
40
- export SAUCERSWAP_ROUTER_V2_CONTRACT_ID=0.0.654321
41
- export SAUCERSWAP_WRAPPED_HBAR_TOKEN_ID=0.0.987654
42
- ```
43
-
44
- ```ts
45
37
  const agent = new HederaAgent({
46
38
  plugins: [saucerswapPlugin],
47
39
  config: {
48
40
  saucerswap: {
49
- routerContractId: "0.0.123456",
50
- routerV2ContractId: "0.0.654321",
51
- wrappedHbarTokenId: "0.0.987654",
52
- tokenAliases: { HBAR: "0.0.987654" },
53
- defaultPoolVersion: "v2"
54
- }
55
- }
41
+ ...SAUCERSWAP_MAINNET,
42
+ apiKey: process.env.SAUCERSWAP_API_KEY,
43
+ },
44
+ },
56
45
  });
57
46
  ```
58
47
 
59
- ## Tools
60
-
61
- - `saucerswap_get_swap_quote` - Fetches swap quotes from SaucerSwap API.
62
- - `saucerswap_swap_tokens` - Builds/executes swap transactions with slippage protection.
63
- - `saucerswap_get_pools` - Lists pools or finds a pool by token pair.
64
- - `saucerswap_add_liquidity` - Builds/executes add-liquidity transactions.
65
- - `saucerswap_remove_liquidity` - Builds/executes remove-liquidity transactions.
66
- - `saucerswap_get_farms` - Lists farming opportunities.
67
-
68
- ## Dry-Run Swap Example
69
-
70
- Build a swap transaction without executing it by setting `mode` to `returnBytes`.
48
+ Or use the `network` shorthand and set `SAUCERSWAP_NETWORK=mainnet` in your environment — no
49
+ contract addresses needed:
71
50
 
72
51
  ```ts
73
- import { Client } from "@hashgraph/sdk";
74
- import { saucerswapPlugin } from "@your-org/hak-saucerswap-plugin";
75
-
76
- const client = Client.forTestnet();
77
- client.setOperator(process.env.HEDERA_ACCOUNT_ID!, process.env.HEDERA_PRIVATE_KEY!);
78
-
79
- const context = { mode: "returnBytes" };
80
- const tools = saucerswapPlugin.tools(context);
81
- const swapTool = tools.find((tool) => tool.method === "saucerswap_swap_tokens");
82
-
83
- if (!swapTool) {
84
- throw new Error("Swap tool not registered.");
85
- }
86
-
87
- const result = await swapTool.execute(client, context, {
88
- fromToken: "0.0.123456",
89
- toToken: "0.0.654321",
90
- amount: "1.5",
91
- slippageTolerance: 0.5
52
+ const agent = new HederaAgent({
53
+ plugins: [saucerswapPlugin],
54
+ config: {
55
+ saucerswap: { network: "mainnet", apiKey: process.env.SAUCERSWAP_API_KEY },
56
+ },
92
57
  });
93
-
94
- console.log(result);
95
58
  ```
96
59
 
97
- Or run the built-in CLI wrapper after building:
60
+ The SaucerSwap API requires an `x-api-key` header. Get a key from
61
+ [saucerswap.finance](https://www.saucerswap.finance) and supply it via either
62
+ `SAUCERSWAP_API_KEY` in the environment or `config.saucerswap.apiKey`. See
63
+ [`.env.example`](./.env.example) for a copy-paste template of all supported environment variables.
98
64
 
99
- ```bash
100
- npm run build
65
+ ## Network Defaults
101
66
 
102
- export HEDERA_NETWORK=testnet
103
- export HEDERA_ACCOUNT_ID=0.0.1234
104
- export HEDERA_PRIVATE_KEY=302e020100300506032b657004220420...
105
- export SAUCERSWAP_ROUTER_CONTRACT_ID=0.0.123456
106
- export SAUCERSWAP_SWAP_FROM=0.0.111111
107
- export SAUCERSWAP_SWAP_TO=0.0.222222
108
- export SAUCERSWAP_SWAP_AMOUNT=1.5
67
+ The plugin ships with official contract addresses for both networks. Import the constants
68
+ directly or use the `network` shorthand — individual fields always take precedence if set.
109
69
 
110
- npm run dry-run:swap
111
- ```
70
+ | Export | Network | routerContractId | routerV2ContractId | wrappedHbarTokenId |
71
+ |----------------------|---------|------------------|--------------------|-------------------|
72
+ | `SAUCERSWAP_MAINNET` | mainnet | `0.0.3045981` | `0.0.3949434` | `0.0.1456986` |
73
+ | `SAUCERSWAP_TESTNET` | testnet | `0.0.19264` | `0.0.1414040` | `0.0.15058` |
112
74
 
113
- ## Integration Smoke Test
114
-
115
- Hit the SaucerSwap API and print basic counts.
116
-
117
- ```bash
118
- npm run test:integration
119
- ```
120
-
121
- Optional environment overrides:
122
-
123
- ```bash
124
- export SAUCERSWAP_BASE_URL=https://api.saucerswap.finance
125
- export SAUCERSWAP_TEST_FROM_TOKEN=0.0.123456
126
- export SAUCERSWAP_TEST_TO_TOKEN=0.0.654321
127
- export SAUCERSWAP_TEST_AMOUNT=1
128
- ```
75
+ Both constants also include `tokenAliases` for `SAUCE` and `XSAUCE`. Contract addresses sourced
76
+ from the [official SaucerSwap deployment docs](https://docs.saucerswap.finance/developerx/contract-deployments).
129
77
 
130
78
  ## Development
131
79