crewai-helmswap 0.1.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Summit Private Credit LLC
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.
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: crewai-helmswap
3
+ Version: 0.1.0
4
+ Summary: CrewAI tools for HelmSwap: quote and build unsigned swap transactions. The agent's wallet signs and sends. Never holds keys.
5
+ Author: Summit Private Credit LLC
6
+ License: MIT
7
+ Project-URL: Homepage, https://helmswap.com/developers
8
+ Project-URL: Repository, https://github.com/gambrelcolby63/crewai-helmswap
9
+ Keywords: helmswap,crewai,swap,non-custodial
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: crewai>=0.76
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=8; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # crewai-helmswap
19
+
20
+ CrewAI tools for [HelmSwap](https://helmswap.com/developers). They quote a swap and return an **unsigned** transaction. The agent's own wallet signs and sends it. The tools never hold private keys.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install crewai-helmswap
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ from crewai_helmswap import HelmswapQuoteTool, HelmswapBuildTool
32
+
33
+ tools = [HelmswapQuoteTool(), HelmswapBuildTool()]
34
+ ```
35
+
36
+ Set `HELMSWAP_API_KEY` (free key from https://helmswap.com/developers, never a wallet key) for Solana builds. `HELMSWAP_BASE_URL` is optional.
37
+
38
+ `amount_in` is integer base units.
39
+
40
+ ## License
41
+
42
+ MIT © Summit Private Credit LLC
@@ -0,0 +1,25 @@
1
+ # crewai-helmswap
2
+
3
+ CrewAI tools for [HelmSwap](https://helmswap.com/developers). They quote a swap and return an **unsigned** transaction. The agent's own wallet signs and sends it. The tools never hold private keys.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install crewai-helmswap
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from crewai_helmswap import HelmswapQuoteTool, HelmswapBuildTool
15
+
16
+ tools = [HelmswapQuoteTool(), HelmswapBuildTool()]
17
+ ```
18
+
19
+ Set `HELMSWAP_API_KEY` (free key from https://helmswap.com/developers, never a wallet key) for Solana builds. `HELMSWAP_BASE_URL` is optional.
20
+
21
+ `amount_in` is integer base units.
22
+
23
+ ## License
24
+
25
+ MIT © Summit Private Credit LLC
@@ -0,0 +1,6 @@
1
+ """CrewAI tools for HelmSwap: quote and build unsigned swap transactions."""
2
+
3
+ from .tools import HelmswapBuildTool, HelmswapQuoteTool
4
+
5
+ __all__ = ["HelmswapQuoteTool", "HelmswapBuildTool"]
6
+ __version__ = "0.1.0"
@@ -0,0 +1,269 @@
1
+ """HelmSwap public v1 HTTP client.
2
+
3
+ Verified against the 26 Nov 2026 audit fix-tree:
4
+ GET /api/v1/quote and POST /api/v1/build-tx.
5
+
6
+ Returns quotes and unsigned transactions. This client never holds keys,
7
+ never signs, and never broadcasts.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import json
13
+ import os
14
+ import urllib.error
15
+ import urllib.parse
16
+ import urllib.request
17
+ from dataclasses import dataclass
18
+ from typing import Any, Callable, Mapping, MutableMapping
19
+
20
+ DEFAULT_BASE_URL = "https://helmswap.com"
21
+ KEY_DOCS = "https://helmswap.com/developers"
22
+ WSOL = "So11111111111111111111111111111111111111112"
23
+ LIVE_EVM_CHAIN_IDS = (8453, 56, 1, 4663, 57073, 999, 99901, 5042)
24
+ QUOTE_ONLY_CHAIN_IDS = (42161, 137)
25
+
26
+ CHAIN_ALIASES: dict[str, int | str] = {
27
+ "solana": "solana",
28
+ "sol": "solana",
29
+ "base": 8453,
30
+ "8453": 8453,
31
+ "bnb": 56,
32
+ "bsc": 56,
33
+ "bnbchain": 56,
34
+ "56": 56,
35
+ "eth": 1,
36
+ "ethereum": 1,
37
+ "mainnet": 1,
38
+ "1": 1,
39
+ "robinhood": 4663,
40
+ "4663": 4663,
41
+ "ink": 57073,
42
+ "57073": 57073,
43
+ "hyperevm": 999,
44
+ "999": 999,
45
+ "elysium": 99901,
46
+ "99901": 99901,
47
+ "arc": 5042,
48
+ "5042": 5042,
49
+ "arbitrum": 42161,
50
+ "42161": 42161,
51
+ "polygon": 137,
52
+ "137": 137,
53
+ }
54
+
55
+
56
+ class HelmswapApiError(Exception):
57
+ def __init__(self, message: str, status: int, code: str | None = None, body: Any = None):
58
+ super().__init__(message)
59
+ self.status = status
60
+ self.code = code
61
+ self.body = body
62
+
63
+
64
+ def parse_chain(raw: str | int | None) -> int | str | None:
65
+ if raw is None or raw == "":
66
+ return None
67
+ if isinstance(raw, int):
68
+ return raw
69
+ trimmed = str(raw).strip()
70
+ if trimmed.isdigit():
71
+ return int(trimmed)
72
+ return CHAIN_ALIASES.get(trimmed.lower().replace(" ", ""))
73
+
74
+
75
+ def is_live_build_chain(chain: int | str) -> bool:
76
+ return chain == "solana" or chain in LIVE_EVM_CHAIN_IDS
77
+
78
+
79
+ def to_base_units(amount: str | int | float, decimals: int) -> str:
80
+ trimmed = str(amount).strip()
81
+ if not trimmed or trimmed.startswith("-"):
82
+ raise ValueError("amount must be greater than zero")
83
+ if "." in trimmed:
84
+ whole, frac = trimmed.split(".", 1)
85
+ else:
86
+ whole, frac = trimmed, ""
87
+ if not whole.isdigit() or (frac and not frac.isdigit()):
88
+ raise ValueError("amount must be a positive number")
89
+ frac_padded = (frac + ("0" * decimals))[:decimals]
90
+ raw = (whole + frac_padded).lstrip("0") or "0"
91
+ if raw == "0":
92
+ raise ValueError("amount must be greater than zero")
93
+ return raw
94
+
95
+
96
+ def from_base_units(raw: str, decimals: int) -> float:
97
+ if not str(raw).isdigit():
98
+ raise ValueError("base units must be a non-negative integer string")
99
+ padded = str(raw).zfill(decimals + 1)
100
+ whole, frac = padded[:-decimals], padded[-decimals:]
101
+ return float(f"{whole}.{frac}")
102
+
103
+
104
+ def native_or_mint(token: str, chain: int | str) -> str:
105
+ token = token.strip()
106
+ if chain == "solana" and token.upper() == "SOL":
107
+ return WSOL
108
+ return token
109
+
110
+
111
+ @dataclass
112
+ class SwapParams:
113
+ chain: int | str
114
+ token_in: str
115
+ token_out: str
116
+ amount_in: str
117
+ slippage_bps: int | None = None
118
+ referrer: str | None = None
119
+
120
+
121
+ def quote_query(params: SwapParams) -> dict[str, str]:
122
+ q: dict[str, str]
123
+ if params.chain == "solana":
124
+ q = {
125
+ "chain": "solana",
126
+ "inputMint": native_or_mint(params.token_in, "solana"),
127
+ "outputMint": native_or_mint(params.token_out, "solana"),
128
+ "amount": params.amount_in,
129
+ }
130
+ else:
131
+ q = {
132
+ "chainId": str(params.chain),
133
+ "tokenIn": params.token_in,
134
+ "tokenOut": params.token_out,
135
+ "amountIn": params.amount_in,
136
+ }
137
+ if params.slippage_bps is not None:
138
+ q["slippageBps"] = str(params.slippage_bps)
139
+ if params.referrer:
140
+ q["referrer"] = params.referrer
141
+ return q
142
+
143
+
144
+ def build_body(params: SwapParams, quote: Mapping[str, Any], recipient: str) -> dict[str, Any]:
145
+ ticket = quote.get("quoteTicket")
146
+ if not isinstance(ticket, Mapping):
147
+ raise HelmswapApiError(
148
+ "quote.quoteTicket is missing; call quote() first and pass the result unchanged.",
149
+ 400,
150
+ "NO_TICKET",
151
+ )
152
+ if params.chain == "solana":
153
+ q = quote_query(params)
154
+ body: dict[str, Any] = {
155
+ "chain": "solana",
156
+ "inputMint": q["inputMint"],
157
+ "outputMint": q["outputMint"],
158
+ "amount": q["amount"],
159
+ "recipient": recipient,
160
+ "quoteTicket": ticket,
161
+ }
162
+ else:
163
+ body = {
164
+ "chainId": params.chain,
165
+ "tokenIn": params.token_in,
166
+ "tokenOut": params.token_out,
167
+ "amountIn": params.amount_in,
168
+ "recipient": recipient,
169
+ "quoteTicket": ticket,
170
+ }
171
+ if params.slippage_bps is not None:
172
+ body["slippageBps"] = params.slippage_bps
173
+ if params.referrer:
174
+ body["referrer"] = params.referrer
175
+ return body
176
+
177
+
178
+ def net_out_amount(quote: Mapping[str, Any]) -> str:
179
+ inner = quote.get("quote") if isinstance(quote.get("quote"), Mapping) else {}
180
+ ticket = quote.get("quoteTicket") if isinstance(quote.get("quoteTicket"), Mapping) else {}
181
+ raw = inner.get("netOutAmount") or quote.get("netOutAmount") or ticket.get("quotedOutNet")
182
+ if raw is None:
183
+ raise HelmswapApiError("HelmSwap quote had no netOutAmount.", 502, "NO_NET_OUT", quote)
184
+ return str(raw)
185
+
186
+
187
+ def min_out_amount(quote: Mapping[str, Any]) -> str:
188
+ inner = quote.get("quote") if isinstance(quote.get("quote"), Mapping) else {}
189
+ return str(inner.get("minOutNet") or inner.get("minNetOutAmount") or net_out_amount(quote))
190
+
191
+
192
+ def evm_tx(built: Mapping[str, Any]) -> dict[str, Any]:
193
+ tx = built.get("tx")
194
+ if not isinstance(tx, Mapping) or not tx.get("to") or not tx.get("data"):
195
+ raise HelmswapApiError("HelmSwap build-tx response had no EVM tx.", 502, "NO_TX", built)
196
+ return dict(tx)
197
+
198
+
199
+ def solana_tx_base64(built: Mapping[str, Any]) -> str:
200
+ tx = built.get("tx")
201
+ if isinstance(tx, Mapping) and isinstance(tx.get("transactionBase64"), str):
202
+ return tx["transactionBase64"]
203
+ raise HelmswapApiError("HelmSwap build-tx response had no Solana transaction.", 502, "NO_TX", built)
204
+
205
+
206
+ class HelmswapApi:
207
+ def __init__(
208
+ self,
209
+ base_url: str | None = None,
210
+ api_key: str | None = None,
211
+ opener: Callable[..., Any] | None = None,
212
+ ):
213
+ self.base_url = (base_url or os.environ.get("HELMSWAP_BASE_URL") or DEFAULT_BASE_URL).rstrip("/")
214
+ self.api_key = api_key if api_key is not None else os.environ.get("HELMSWAP_API_KEY")
215
+ self._opener = opener or urllib.request.urlopen
216
+
217
+ @property
218
+ def has_api_key(self) -> bool:
219
+ return bool(self.api_key)
220
+
221
+ def quote(self, params: SwapParams) -> dict[str, Any]:
222
+ query = urllib.parse.urlencode(quote_query(params))
223
+ return self._request("GET", f"/api/v1/quote?{query}")
224
+
225
+ def build_tx(self, params: SwapParams, quote: Mapping[str, Any], recipient: str) -> dict[str, Any]:
226
+ if params.chain == "solana" and not self.api_key:
227
+ raise HelmswapApiError(
228
+ "A free HelmSwap API key is required to build Solana transactions. Create one at https://helmswap.com/developers.",
229
+ 401,
230
+ "API_KEY_REQUIRED",
231
+ )
232
+ if not is_live_build_chain(params.chain):
233
+ raise HelmswapApiError(
234
+ f"build-tx is not available on chain {params.chain} (quote-only).",
235
+ 503,
236
+ "FEE_ROUTER_NOT_CONFIGURED",
237
+ )
238
+ return self._request("POST", "/api/v1/build-tx", build_body(params, quote, recipient))
239
+
240
+ def _request(self, method: str, path: str, body: Mapping[str, Any] | None = None) -> dict[str, Any]:
241
+ headers: dict[str, str] = {"Accept": "application/json"}
242
+ data = None
243
+ if body is not None:
244
+ headers["Content-Type"] = "application/json"
245
+ data = json.dumps(body).encode("utf-8")
246
+ if self.api_key:
247
+ headers["X-Helm-Key"] = self.api_key
248
+ req = urllib.request.Request(self.base_url + path, data=data, headers=headers, method=method)
249
+ try:
250
+ with self._opener(req) as resp:
251
+ raw = resp.read()
252
+ status = getattr(resp, "status", 200)
253
+ except urllib.error.HTTPError as err:
254
+ raw = err.read()
255
+ status = err.code
256
+ try:
257
+ payload = json.loads(raw.decode("utf-8") or "{}")
258
+ except json.JSONDecodeError as err:
259
+ raise HelmswapApiError(f"HelmSwap returned a non-JSON response ({status})", status) from err
260
+ if not isinstance(payload, dict):
261
+ raise HelmswapApiError(f"HelmSwap returned a non-object response ({status})", status, body=payload)
262
+ if status >= 400 or payload.get("ok") is False:
263
+ raise HelmswapApiError(
264
+ payload.get("error") if isinstance(payload.get("error"), str) else f"HelmSwap request failed ({status})",
265
+ status,
266
+ payload.get("code") if isinstance(payload.get("code"), str) else None,
267
+ payload,
268
+ )
269
+ return payload
@@ -0,0 +1,115 @@
1
+ """CrewAI tools for the HelmSwap public API.
2
+
3
+ Quote a swap or build an unsigned transaction. The agent's wallet signs and
4
+ sends. These tools never hold private keys.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ # Reuse the same function implementations as the LangChain package by vendoring
10
+ # a thin wrapper around the shared client. Import locally so this package is
11
+ # self-contained.
12
+ import json
13
+ from typing import Any, Type
14
+
15
+ from .helmswap_client import (
16
+ HelmswapApi,
17
+ HelmswapApiError,
18
+ SwapParams,
19
+ evm_tx,
20
+ is_live_build_chain,
21
+ min_out_amount,
22
+ net_out_amount,
23
+ parse_chain,
24
+ solana_tx_base64,
25
+ )
26
+
27
+ try:
28
+ from crewai.tools import BaseTool
29
+ from pydantic import BaseModel, Field
30
+ except ImportError:
31
+ BaseTool = object # type: ignore
32
+ class BaseModel: # type: ignore
33
+ pass
34
+ def Field(*_args, **_kwargs): # type: ignore
35
+ return None
36
+
37
+
38
+ class HelmswapQuoteInput(BaseModel):
39
+ token_in: str = Field(..., description="Token to spend (address, or ETH, BNB, or SOL)")
40
+ token_out: str = Field(..., description="Token to receive (address, or ETH, BNB, or SOL)")
41
+ amount_in: str = Field(..., description="Integer base units of token_in")
42
+ chain: str = Field(default="base", description="Chain name or id: solana, base, ethereum, bsc, or a numeric chain id")
43
+ slippage_bps: int = Field(default=50, description="Slippage tolerance in basis points (0-1000, default 50)")
44
+ referrer: str | None = Field(default=None, description="Optional payout address. Address only, never a key.")
45
+
46
+
47
+ class HelmswapBuildInput(HelmswapQuoteInput):
48
+ recipient: str = Field(..., description="Wallet that will sign the unsigned transaction (0x or Solana base58)")
49
+
50
+
51
+ def _params(**kwargs) -> SwapParams:
52
+ parsed = parse_chain(kwargs.get("chain") or "base")
53
+ if parsed is None:
54
+ raise HelmswapApiError(f"Unknown chain '{kwargs.get('chain')}'.", 400, "BAD_CHAIN")
55
+ return SwapParams(
56
+ parsed,
57
+ kwargs["token_in"],
58
+ kwargs["token_out"],
59
+ kwargs["amount_in"],
60
+ int(kwargs.get("slippage_bps") or 50),
61
+ kwargs.get("referrer"),
62
+ )
63
+
64
+
65
+ class HelmswapQuoteTool(BaseTool):
66
+ name: str = "helmswap_quote"
67
+ description: str = (
68
+ "Get a HelmSwap quote for a token swap. Returns expected output, minimum output, "
69
+ "and the disclosed fee. Nothing is signed or sent."
70
+ )
71
+ args_schema: Type[BaseModel] = HelmswapQuoteInput
72
+
73
+ def _run(self, **kwargs: Any) -> str:
74
+ client = HelmswapApi()
75
+ params = _params(**kwargs)
76
+ quote = client.quote(params)
77
+ fee = quote.get("fee") or (quote.get("quote") or {}).get("fee") or {}
78
+ return json.dumps({
79
+ "ok": True,
80
+ "chain": params.chain,
81
+ "netOutAmount": net_out_amount(quote),
82
+ "minOutAmount": min_out_amount(quote),
83
+ "fee": fee,
84
+ "quoteTicket": quote.get("quoteTicket"),
85
+ "buildable": is_live_build_chain(params.chain),
86
+ "note": "Quote only. The user's wallet must sign any later transaction. HelmSwap never holds keys and never broadcasts.",
87
+ })
88
+
89
+
90
+ class HelmswapBuildTool(BaseTool):
91
+ name: str = "helmswap_build_swap"
92
+ description: str = (
93
+ "Build an unsigned HelmSwap transaction. The recipient wallet signs and sends it. "
94
+ "Never holds private keys. Solana builds need HELMSWAP_API_KEY (a free API key, not a wallet key)."
95
+ )
96
+ args_schema: Type[BaseModel] = HelmswapBuildInput
97
+
98
+ def _run(self, **kwargs: Any) -> str:
99
+ recipient = (kwargs.get("recipient") or "").strip()
100
+ if not recipient:
101
+ raise HelmswapApiError("recipient is required to build an unsigned transaction.", 400, "NO_RECIPIENT")
102
+ client = HelmswapApi()
103
+ params = _params(**kwargs)
104
+ quote = client.quote(params)
105
+ built = client.build_tx(params, quote, recipient)
106
+ tx = {"chain": "solana", "transactionBase64": solana_tx_base64(built)} if params.chain == "solana" else evm_tx(built)
107
+ return json.dumps({
108
+ "ok": True,
109
+ "chain": params.chain,
110
+ "recipient": recipient,
111
+ "netOutAmount": net_out_amount(quote),
112
+ "tx": tx,
113
+ "approvals": built.get("approvals") or [],
114
+ "note": "Unsigned transaction. The recipient wallet signs and sends it. HelmSwap never holds keys and never broadcasts.",
115
+ })
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: crewai-helmswap
3
+ Version: 0.1.0
4
+ Summary: CrewAI tools for HelmSwap: quote and build unsigned swap transactions. The agent's wallet signs and sends. Never holds keys.
5
+ Author: Summit Private Credit LLC
6
+ License: MIT
7
+ Project-URL: Homepage, https://helmswap.com/developers
8
+ Project-URL: Repository, https://github.com/gambrelcolby63/crewai-helmswap
9
+ Keywords: helmswap,crewai,swap,non-custodial
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: crewai>=0.76
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=8; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # crewai-helmswap
19
+
20
+ CrewAI tools for [HelmSwap](https://helmswap.com/developers). They quote a swap and return an **unsigned** transaction. The agent's own wallet signs and sends it. The tools never hold private keys.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install crewai-helmswap
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ from crewai_helmswap import HelmswapQuoteTool, HelmswapBuildTool
32
+
33
+ tools = [HelmswapQuoteTool(), HelmswapBuildTool()]
34
+ ```
35
+
36
+ Set `HELMSWAP_API_KEY` (free key from https://helmswap.com/developers, never a wallet key) for Solana builds. `HELMSWAP_BASE_URL` is optional.
37
+
38
+ `amount_in` is integer base units.
39
+
40
+ ## License
41
+
42
+ MIT © Summit Private Credit LLC
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ crewai_helmswap/__init__.py
5
+ crewai_helmswap/helmswap_client.py
6
+ crewai_helmswap/tools.py
7
+ crewai_helmswap.egg-info/PKG-INFO
8
+ crewai_helmswap.egg-info/SOURCES.txt
9
+ crewai_helmswap.egg-info/dependency_links.txt
10
+ crewai_helmswap.egg-info/requires.txt
11
+ crewai_helmswap.egg-info/top_level.txt
12
+ tests/test_tools.py
@@ -0,0 +1,4 @@
1
+ crewai>=0.76
2
+
3
+ [dev]
4
+ pytest>=8
@@ -0,0 +1 @@
1
+ crewai_helmswap
@@ -0,0 +1,24 @@
1
+ [project]
2
+ name = "crewai-helmswap"
3
+ version = "0.1.0"
4
+ description = "CrewAI tools for HelmSwap: quote and build unsigned swap transactions. The agent's wallet signs and sends. Never holds keys."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = { text = "MIT" }
8
+ authors = [{ name = "Summit Private Credit LLC" }]
9
+ keywords = ["helmswap", "crewai", "swap", "non-custodial"]
10
+ dependencies = ["crewai>=0.76"]
11
+
12
+ [project.optional-dependencies]
13
+ dev = ["pytest>=8"]
14
+
15
+ [project.urls]
16
+ Homepage = "https://helmswap.com/developers"
17
+ Repository = "https://github.com/gambrelcolby63/crewai-helmswap"
18
+
19
+ [build-system]
20
+ requires = ["setuptools>=69"]
21
+ build-backend = "setuptools.build_meta"
22
+
23
+ [tool.setuptools.packages.find]
24
+ include = ["crewai_helmswap*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,57 @@
1
+ from __future__ import annotations
2
+
3
+ import io
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
9
+
10
+ from crewai_helmswap.helmswap_client import HelmswapApi
11
+ from crewai_helmswap import tools as tools_mod
12
+
13
+
14
+ SAMPLE_QUOTE = {
15
+ "ok": True,
16
+ "quoteTicket": {"sig": "ticket", "quotedOutNet": "149250000"},
17
+ "quote": {"netOutAmount": "149250000", "minNetOutAmount": "148500000", "fee": {"disclosed": True, "feeBps": 25}},
18
+ "fee": {"disclosed": True, "feeBps": 25},
19
+ }
20
+
21
+ SAMPLE_BUILD = {"ok": True, "tx": {"to": "0xrouter", "data": "0xabc", "value": "0x0", "chainId": 1}, "approvals": []}
22
+
23
+
24
+ class FakeResponse(io.BytesIO):
25
+ def __init__(self, payload, status=200):
26
+ super().__init__(json.dumps(payload).encode())
27
+ self.status = status
28
+
29
+ def __enter__(self):
30
+ return self
31
+
32
+ def __exit__(self, *args):
33
+ return False
34
+
35
+
36
+ def test_quote_and_build_tools(monkeypatch):
37
+ def opener(req):
38
+ if req.get_method() == "GET":
39
+ return FakeResponse(SAMPLE_QUOTE)
40
+ return FakeResponse(SAMPLE_BUILD)
41
+
42
+ monkeypatch.setattr(tools_mod, "HelmswapApi", lambda: HelmswapApi(base_url="https://helmswap.com", opener=opener))
43
+ quoted = json.loads(tools_mod.HelmswapQuoteTool()._run(
44
+ token_in="ETH",
45
+ token_out="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
46
+ amount_in="10000000000000000",
47
+ chain="ethereum",
48
+ ))
49
+ assert quoted["netOutAmount"] == "149250000"
50
+ built = json.loads(tools_mod.HelmswapBuildTool()._run(
51
+ token_in="ETH",
52
+ token_out="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
53
+ amount_in="10000000000000000",
54
+ chain="ethereum",
55
+ recipient="0x1111111111111111111111111111111111111111",
56
+ ))
57
+ assert built["tx"]["to"] == "0xrouter"