hak-saucerswap-plugin 1.0.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 +21 -0
- package/README.md +140 -0
- package/dist/index.cjs +692 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +683 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Juanma Gomez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Hedera Agent Kit - SaucerSwap Plugin
|
|
2
|
+
|
|
3
|
+
A plugin for [Hedera Agent Kit](https://github.com/hashgraph/hedera-agent-kit) that integrates with
|
|
4
|
+
[SaucerSwap](https://saucerswap.finance) to enable token swaps, liquidity management, and farm
|
|
5
|
+
insights on Hedera.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
SaucerSwap is Hedera's leading DEX with deep liquidity and active DeFi opportunities. This plugin
|
|
10
|
+
lets AI agents:
|
|
11
|
+
|
|
12
|
+
- Execute swaps with slippage protection
|
|
13
|
+
- Fetch swap quotes and price impact estimates
|
|
14
|
+
- Query pool reserves and token metadata
|
|
15
|
+
- Add/remove liquidity via router transactions
|
|
16
|
+
- Discover farming opportunities
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install hak-saucerswap-plugin
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { saucerswapPlugin } from "hak-saucerswap-plugin";
|
|
28
|
+
|
|
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
|
+
const agent = new HederaAgent({
|
|
46
|
+
plugins: [saucerswapPlugin],
|
|
47
|
+
config: {
|
|
48
|
+
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
|
+
}
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
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`.
|
|
71
|
+
|
|
72
|
+
```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
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log(result);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or run the built-in CLI wrapper after building:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm run build
|
|
101
|
+
|
|
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
|
|
109
|
+
|
|
110
|
+
npm run dry-run:swap
|
|
111
|
+
```
|
|
112
|
+
|
|
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
|
+
```
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm run build
|
|
134
|
+
npm run test
|
|
135
|
+
npm run lint
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT
|