@onecraft/wallet 0.0.0-stage → 0.1.145
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/.claude-plugin/marketplace.json +20 -0
- package/.openclaw/AGENTS.md +100 -0
- package/.openclaw/extensions/agent-wallet/README.md +195 -0
- package/.openclaw/extensions/agent-wallet/dist/index.js +2198 -0
- package/.openclaw/extensions/agent-wallet/index.ts +2198 -0
- package/.openclaw/extensions/agent-wallet/openclaw.plugin.json +251 -0
- package/.openclaw/extensions/agent-wallet/package.json +49 -0
- package/.openclaw/extensions/agent-wallet/skills/cards/SKILL.md +211 -0
- package/.openclaw/extensions/agent-wallet/skills/wallet-operator/SKILL.md +30 -0
- package/CHANGELOG.md +1232 -0
- package/LICENSE +104 -0
- package/README.md +193 -2
- package/VERSION +1 -0
- package/agent-wallet/.env.example +63 -0
- package/agent-wallet/AGENTS.md +130 -0
- package/agent-wallet/CARD_VAULT.md +640 -0
- package/agent-wallet/README.md +615 -0
- package/agent-wallet/UPGRADE_COMPATIBILITY.md +66 -0
- package/agent-wallet/agent_wallet/__init__.py +16 -0
- package/agent-wallet/agent_wallet/approval.py +165 -0
- package/agent-wallet/agent_wallet/autonomous_permissions.py +281 -0
- package/agent-wallet/agent_wallet/autonomous_policy.py +305 -0
- package/agent-wallet/agent_wallet/autonomous_session.py +236 -0
- package/agent-wallet/agent_wallet/boot_key_migration.py +155 -0
- package/agent-wallet/agent_wallet/boot_key_recovery.py +57 -0
- package/agent-wallet/agent_wallet/bootstrap.py +194 -0
- package/agent-wallet/agent_wallet/card_catalog.py +243 -0
- package/agent-wallet/agent_wallet/card_runtime_secrets.py +108 -0
- package/agent-wallet/agent_wallet/card_vault.py +331 -0
- package/agent-wallet/agent_wallet/card_vault_cli.py +174 -0
- package/agent-wallet/agent_wallet/card_vault_import.py +65 -0
- package/agent-wallet/agent_wallet/card_vault_keychain.py +239 -0
- package/agent-wallet/agent_wallet/config.py +719 -0
- package/agent-wallet/agent_wallet/connector_cli.py +198 -0
- package/agent-wallet/agent_wallet/connectors/__init__.py +28 -0
- package/agent-wallet/agent_wallet/connectors/catalog.py +68 -0
- package/agent-wallet/agent_wallet/connectors/client.py +308 -0
- package/agent-wallet/agent_wallet/connectors/intent_policy.py +243 -0
- package/agent-wallet/agent_wallet/connectors/manifest.py +192 -0
- package/agent-wallet/agent_wallet/connectors/registry.py +341 -0
- package/agent-wallet/agent_wallet/encrypted_storage.py +314 -0
- package/agent-wallet/agent_wallet/evm_user_wallets.py +910 -0
- package/agent-wallet/agent_wallet/exceptions.py +10 -0
- package/agent-wallet/agent_wallet/file_ops.py +34 -0
- package/agent-wallet/agent_wallet/http_client.py +25 -0
- package/agent-wallet/agent_wallet/kernel_browser.py +479 -0
- package/agent-wallet/agent_wallet/kernel_cli.py +57 -0
- package/agent-wallet/agent_wallet/kernel_gateway.py +95 -0
- package/agent-wallet/agent_wallet/keystore.py +503 -0
- package/agent-wallet/agent_wallet/laso_card_vault.py +246 -0
- package/agent-wallet/agent_wallet/models.py +66 -0
- package/agent-wallet/agent_wallet/morpho_monitor.py +298 -0
- package/agent-wallet/agent_wallet/nonce_registry.py +59 -0
- package/agent-wallet/agent_wallet/openclaw_adapter.py +9129 -0
- package/agent-wallet/agent_wallet/openclaw_cli.py +658 -0
- package/agent-wallet/agent_wallet/openclaw_runtime.py +194 -0
- package/agent-wallet/agent_wallet/plugin_bundle.py +44 -0
- package/agent-wallet/agent_wallet/providers/__init__.py +1 -0
- package/agent-wallet/agent_wallet/providers/bags.py +202 -0
- package/agent-wallet/agent_wallet/providers/dexscreener.py +147 -0
- package/agent-wallet/agent_wallet/providers/evm_activity.py +257 -0
- package/agent-wallet/agent_wallet/providers/evm_portfolio.py +459 -0
- package/agent-wallet/agent_wallet/providers/imd.py +720 -0
- package/agent-wallet/agent_wallet/providers/jupiter.py +519 -0
- package/agent-wallet/agent_wallet/providers/kamino.py +404 -0
- package/agent-wallet/agent_wallet/providers/lifi.py +302 -0
- package/agent-wallet/agent_wallet/providers/solana_rpc.py +447 -0
- package/agent-wallet/agent_wallet/providers/tokenized_stocks.py +189 -0
- package/agent-wallet/agent_wallet/providers/wdk_evm_local.py +346 -0
- package/agent-wallet/agent_wallet/providers/x402.py +1972 -0
- package/agent-wallet/agent_wallet/sealed_keys.py +118 -0
- package/agent-wallet/agent_wallet/solana_stake.py +103 -0
- package/agent-wallet/agent_wallet/solana_tx.py +93 -0
- package/agent-wallet/agent_wallet/spending_limits.py +119 -0
- package/agent-wallet/agent_wallet/telemetry.py +481 -0
- package/agent-wallet/agent_wallet/transaction_policy.py +573 -0
- package/agent-wallet/agent_wallet/update_check.py +190 -0
- package/agent-wallet/agent_wallet/user_wallets.py +573 -0
- package/agent-wallet/agent_wallet/validation.py +31 -0
- package/agent-wallet/agent_wallet/vault_executor.py +456 -0
- package/agent-wallet/agent_wallet/wallet_layer/__init__.py +1 -0
- package/agent-wallet/agent_wallet/wallet_layer/base.py +1204 -0
- package/agent-wallet/agent_wallet/wallet_layer/base58.py +44 -0
- package/agent-wallet/agent_wallet/wallet_layer/factory.py +117 -0
- package/agent-wallet/agent_wallet/wallet_layer/solana.py +5246 -0
- package/agent-wallet/agent_wallet/wallet_layer/wdk_evm.py +2705 -0
- package/agent-wallet/examples/bootstrap_wallet.py +21 -0
- package/agent-wallet/examples/openclaw_runtime_onboarding.py +28 -0
- package/agent-wallet/examples/openclaw_user_wallet_example.py +31 -0
- package/agent-wallet/examples/openclaw_wallet_adapter_example.py +33 -0
- package/agent-wallet/openclaw.plugin.json +118 -0
- package/agent-wallet/pyproject.toml +36 -0
- package/agent-wallet/scripts/bootstrap_openclaw_evm.py +312 -0
- package/agent-wallet/scripts/build_release_bundle.py +210 -0
- package/agent-wallet/scripts/finalize_openclaw_local_wallet_config.py +121 -0
- package/agent-wallet/scripts/install_agent_wallet.py +1357 -0
- package/agent-wallet/scripts/install_openclaw_local_config.py +421 -0
- package/agent-wallet/scripts/install_openclaw_sealed_keys.py +117 -0
- package/agent-wallet/scripts/manage_openclaw_evm_wallet.py +333 -0
- package/agent-wallet/scripts/security_utils.py +37 -0
- package/agent-wallet/scripts/setup_evm_wallet.sh +140 -0
- package/agent-wallet/scripts/switch_openclaw_wallet_network.py +109 -0
- package/agent-wallet/skills/wallet-operator/SKILL.md +157 -0
- package/bin/lib/boot-key.mjs +184 -0
- package/bin/lib/evm-daemon.mjs +389 -0
- package/bin/lib/host-detection.mjs +259 -0
- package/bin/lib/integrations.mjs +578 -0
- package/bin/lib/release-python.mjs +9 -0
- package/bin/lib/update-transaction.mjs +235 -0
- package/bin/openclaw-agent-wallet.mjs +3354 -0
- package/claude-code/plugins/agent-wallet/.claude-plugin/plugin.json +19 -0
- package/claude-code/plugins/agent-wallet/.mcp.json +14 -0
- package/claude-code/plugins/agent-wallet/AGENTLAYER_AGENT_GUIDE.md +282 -0
- package/claude-code/plugins/agent-wallet/README.md +134 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-approve.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/agentlayer-autonomous-revoke.md +17 -0
- package/claude-code/plugins/agent-wallet/commands/cards.md +129 -0
- package/claude-code/plugins/agent-wallet/commands/guide.md +40 -0
- package/claude-code/plugins/agent-wallet/commands/imd.md +125 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-base.md +60 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-ethereum.md +37 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-evm.md +39 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-setup.md +25 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-sol.md +51 -0
- package/claude-code/plugins/agent-wallet/commands/wallet-statusline.md +34 -0
- package/claude-code/plugins/agent-wallet/commands/x402.md +121 -0
- package/claude-code/plugins/agent-wallet/commands/yield.md +62 -0
- package/claude-code/plugins/agent-wallet/hooks/hooks.json +16 -0
- package/claude-code/plugins/agent-wallet/scripts/bootstrap_backend.sh +136 -0
- package/claude-code/plugins/agent-wallet/scripts/enable_statusline.py +52 -0
- package/claude-code/plugins/agent-wallet/scripts/resolve_wallet_addresses.py +69 -0
- package/claude-code/plugins/agent-wallet/scripts/run_mcp.sh +66 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline.py +130 -0
- package/claude-code/plugins/agent-wallet/scripts/wallet_statusline_setup.sh +40 -0
- package/claude-code/plugins/agent-wallet/skills/wallet-operator/SKILL.md +21 -0
- package/codex/plugins/agent-wallet/.codex-plugin/plugin.json +37 -0
- package/codex/plugins/agent-wallet/.mcp.json +15 -0
- package/codex/plugins/agent-wallet/README.md +158 -0
- package/codex/plugins/agent-wallet/scripts/run_mcp.sh +47 -0
- package/codex/plugins/agent-wallet/server.py +1797 -0
- package/codex/plugins/agent-wallet/skills/cards/SKILL.md +225 -0
- package/codex/plugins/agent-wallet/skills/imd/SKILL.md +145 -0
- package/codex/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/codex/plugins/agent-wallet/skills/wallet-operator/SKILL.md +85 -0
- package/codex/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/codex/plugins/agent-wallet/skills/x402/SKILL.md +159 -0
- package/codex/plugins/agent-wallet/skills/yield/SKILL.md +65 -0
- package/connectors/AGENTS.md +37 -0
- package/connectors/DEVELOPER_GUIDE.md +131 -0
- package/connectors/README.md +139 -0
- package/connectors/READ_ONLY_BETA.md +54 -0
- package/connectors/RELEASING.md +48 -0
- package/connectors/conformance/README.md +31 -0
- package/connectors/conformance/package.json +54 -0
- package/connectors/conformance/scripts/sync-license.mjs +3 -0
- package/connectors/conformance/scripts/sync-spec.mjs +16 -0
- package/connectors/conformance/src/cli.ts +43 -0
- package/connectors/conformance/src/index.ts +7 -0
- package/connectors/conformance/src/runner.ts +314 -0
- package/connectors/conformance/src/types.ts +27 -0
- package/connectors/conformance/test/fixtures/invalid-response-identity.json +14 -0
- package/connectors/conformance/test/fixtures/missing-tool-fixture.json +4 -0
- package/connectors/conformance/test/runner.test.mjs +151 -0
- package/connectors/conformance/tsconfig.json +17 -0
- package/connectors/examples/reference-crypto-data/Dockerfile +21 -0
- package/connectors/examples/reference-crypto-data/README.md +51 -0
- package/connectors/examples/reference-crypto-data/conformance.json +11 -0
- package/connectors/examples/reference-crypto-data/connector.json +95 -0
- package/connectors/examples/reference-crypto-data/package.json +21 -0
- package/connectors/examples/reference-crypto-data/railway.toml +9 -0
- package/connectors/examples/reference-crypto-data/src/connector.ts +137 -0
- package/connectors/examples/reference-crypto-data/src/server.ts +13 -0
- package/connectors/examples/reference-crypto-data/test/connector.test.mjs +97 -0
- package/connectors/examples/reference-crypto-data/tsconfig.json +17 -0
- package/connectors/package-lock.json +561 -0
- package/connectors/package.json +19 -0
- package/connectors/scripts/smoke-packed-packages.mjs +121 -0
- package/connectors/sdk-typescript/README.md +47 -0
- package/connectors/sdk-typescript/package.json +49 -0
- package/connectors/sdk-typescript/scripts/sync-license.mjs +3 -0
- package/connectors/sdk-typescript/src/connector.ts +204 -0
- package/connectors/sdk-typescript/src/errors.ts +11 -0
- package/connectors/sdk-typescript/src/http.ts +116 -0
- package/connectors/sdk-typescript/src/index.ts +26 -0
- package/connectors/sdk-typescript/src/types.ts +101 -0
- package/connectors/sdk-typescript/test/sdk.test.mjs +181 -0
- package/connectors/sdk-typescript/tsconfig.json +21 -0
- package/connectors/spec/connector-manifest.schema.json +340 -0
- package/connectors/spec/connector-protocol.md +159 -0
- package/connectors/spec/transaction-intent.schema.json +281 -0
- package/connectors/templates/read-only/.env.example +1 -0
- package/connectors/templates/read-only/Dockerfile +11 -0
- package/connectors/templates/read-only/README.md +33 -0
- package/connectors/templates/read-only/conformance.json +11 -0
- package/connectors/templates/read-only/connector.json +64 -0
- package/connectors/templates/read-only/package.json +21 -0
- package/connectors/templates/read-only/railway.toml +9 -0
- package/connectors/templates/read-only/src/connector.ts +61 -0
- package/connectors/templates/read-only/src/server.ts +14 -0
- package/connectors/templates/read-only/test/connector.test.mjs +62 -0
- package/connectors/templates/read-only/tsconfig.json +17 -0
- package/cursor/plugins/agent-wallet/.cursor-plugin/plugin.json +14 -0
- package/cursor/plugins/agent-wallet/README.md +62 -0
- package/cursor/plugins/agent-wallet/mcp.json +16 -0
- package/cursor/plugins/agent-wallet/scripts/run_mcp.sh +33 -0
- package/cursor/plugins/agent-wallet/server.py +33 -0
- package/cursor/plugins/agent-wallet/skills/cards/SKILL.md +210 -0
- package/cursor/plugins/agent-wallet/skills/wallet-base/SKILL.md +56 -0
- package/cursor/plugins/agent-wallet/skills/wallet-operator/SKILL.md +23 -0
- package/cursor/plugins/agent-wallet/skills/wallet-sol/SKILL.md +29 -0
- package/cursor/plugins/agent-wallet/skills/x402/SKILL.md +130 -0
- package/hermes/plugins/agent_wallet/README.md +54 -0
- package/hermes/plugins/agent_wallet/__init__.py +55 -0
- package/hermes/plugins/agent_wallet/plugin.yaml +9 -0
- package/hermes/plugins/agent_wallet/schemas.py +211 -0
- package/hermes/plugins/agent_wallet/tools.py +622 -0
- package/install-from-github.sh +139 -0
- package/integrations/hedera/treasury-guard/README.md +92 -0
- package/integrations/hedera/treasury-guard/examples/treasury-policy.example.json +9 -0
- package/integrations/hedera/treasury-guard/package-lock.json +880 -0
- package/integrations/hedera/treasury-guard/package.json +8 -0
- package/integrations/hedera/treasury-guard/skills/onecraft-hedera-treasury/SKILL.md +22 -0
- package/integrations/hedera/treasury-guard/src/hedera-mirror-client.mjs +106 -0
- package/integrations/hedera/treasury-guard/src/hedera-signer.mjs +120 -0
- package/integrations/hedera/treasury-guard/src/treasury-cli.mjs +177 -0
- package/integrations/hedera/treasury-guard/src/treasury-policy.mjs +155 -0
- package/mcp/README.md +39 -0
- package/mcp/scripts/run_mcp.sh +37 -0
- package/mcp/server.py +33 -0
- package/package.json +106 -4
- package/scripts/check_release_version.mjs +72 -0
- package/scripts/version_targets.mjs +60 -0
- package/setup.sh +87 -0
- package/wdk-evm-wallet/.env.example +38 -0
- package/wdk-evm-wallet/README.md +254 -0
- package/wdk-evm-wallet/bootstrap.sh +8 -0
- package/wdk-evm-wallet/package-lock.json +2359 -0
- package/wdk-evm-wallet/package.json +43 -0
- package/wdk-evm-wallet/run-local.sh +12 -0
- package/wdk-evm-wallet/src/config.js +461 -0
- package/wdk-evm-wallet/src/imd.js +231 -0
- package/wdk-evm-wallet/src/json.js +35 -0
- package/wdk-evm-wallet/src/local_vault.js +407 -0
- package/wdk-evm-wallet/src/network_state.js +96 -0
- package/wdk-evm-wallet/src/pending_transactions.js +148 -0
- package/wdk-evm-wallet/src/server.js +849 -0
- package/wdk-evm-wallet/src/shutdown.js +63 -0
- package/wdk-evm-wallet/src/wdk_evm_wallet.js +10036 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
"""Jupiter providers for swap routing and price flows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from agent_wallet.config import settings
|
|
10
|
+
from agent_wallet.exceptions import ProviderError
|
|
11
|
+
from agent_wallet.http_client import get_client
|
|
12
|
+
|
|
13
|
+
JUPITER_SWAP_FALLBACK_PRIORITY_MAX_LAMPORTS = 2_000_000
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _headers() -> dict[str, str]:
|
|
17
|
+
headers = {"Accept": "application/json"}
|
|
18
|
+
if settings.jupiter_api_key.strip():
|
|
19
|
+
headers["x-api-key"] = settings.jupiter_api_key.strip()
|
|
20
|
+
return headers
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _gateway_base_url() -> str:
|
|
24
|
+
return os.getenv("PROVIDER_GATEWAY_URL", settings.provider_gateway_url).strip().rstrip("/")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _gateway_headers() -> dict[str, str]:
|
|
28
|
+
headers = {"Accept": "application/json"}
|
|
29
|
+
bearer = os.getenv(
|
|
30
|
+
"PROVIDER_GATEWAY_BEARER_TOKEN",
|
|
31
|
+
settings.provider_gateway_bearer_token,
|
|
32
|
+
).strip()
|
|
33
|
+
if bearer:
|
|
34
|
+
headers["Authorization"] = f"Bearer {bearer}"
|
|
35
|
+
return headers
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _gateway_enabled() -> bool:
|
|
39
|
+
return bool(_gateway_base_url())
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
async def _gateway_get(path_suffix: str, *, params: dict[str, Any] | None = None) -> tuple[int, Any]:
|
|
43
|
+
"""Make a GET request through provider gateway."""
|
|
44
|
+
client = get_client()
|
|
45
|
+
response = await client.get(
|
|
46
|
+
f"{_gateway_base_url()}/v1/jupiter/swap/{path_suffix}",
|
|
47
|
+
params=params,
|
|
48
|
+
headers=_gateway_headers(),
|
|
49
|
+
)
|
|
50
|
+
if not response.content:
|
|
51
|
+
return response.status_code, {}
|
|
52
|
+
try:
|
|
53
|
+
return response.status_code, response.json()
|
|
54
|
+
except ValueError:
|
|
55
|
+
return response.status_code, response.text[:500]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def _gateway_post(path_suffix: str, *, body: dict[str, Any]) -> tuple[int, Any]:
|
|
59
|
+
"""Make a POST request through provider gateway."""
|
|
60
|
+
client = get_client()
|
|
61
|
+
response = await client.post(
|
|
62
|
+
f"{_gateway_base_url()}/v1/jupiter/swap/{path_suffix}",
|
|
63
|
+
json=body,
|
|
64
|
+
headers={**_gateway_headers(), "Content-Type": "application/json"},
|
|
65
|
+
)
|
|
66
|
+
if not response.content:
|
|
67
|
+
return response.status_code, {}
|
|
68
|
+
try:
|
|
69
|
+
return response.status_code, response.json()
|
|
70
|
+
except ValueError:
|
|
71
|
+
return response.status_code, response.text[:500]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _direct_jupiter_enabled() -> bool:
|
|
75
|
+
return bool(settings.jupiter_api_key.strip())
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _swap_fallback_prioritization_fee() -> dict[str, Any]:
|
|
79
|
+
return {
|
|
80
|
+
"priorityLevelWithMaxLamports": {
|
|
81
|
+
"priorityLevel": "veryHigh",
|
|
82
|
+
"maxLamports": JUPITER_SWAP_FALLBACK_PRIORITY_MAX_LAMPORTS,
|
|
83
|
+
"global": False,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _swap_fallback_build_body(
|
|
89
|
+
*,
|
|
90
|
+
user_public_key: str,
|
|
91
|
+
quote_response: dict[str, Any],
|
|
92
|
+
wrap_and_unwrap_sol: bool,
|
|
93
|
+
) -> dict[str, Any]:
|
|
94
|
+
return {
|
|
95
|
+
"userPublicKey": user_public_key,
|
|
96
|
+
"quoteResponse": quote_response,
|
|
97
|
+
"wrapAndUnwrapSol": wrap_and_unwrap_sol,
|
|
98
|
+
"dynamicComputeUnitLimit": True,
|
|
99
|
+
"dynamicSlippage": True,
|
|
100
|
+
"prioritizationFeeLamports": _swap_fallback_prioritization_fee(),
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _swap_v2_base_url() -> str:
|
|
105
|
+
return os.getenv(
|
|
106
|
+
"JUPITER_SWAP_V2_API_BASE_URL",
|
|
107
|
+
settings.jupiter_swap_v2_api_base_url,
|
|
108
|
+
).strip().rstrip("/")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
async def fetch_quote(
|
|
112
|
+
*,
|
|
113
|
+
input_mint: str,
|
|
114
|
+
output_mint: str,
|
|
115
|
+
amount_raw: int,
|
|
116
|
+
slippage_bps: int = 50,
|
|
117
|
+
restrict_intermediate_tokens: bool = True,
|
|
118
|
+
only_direct_routes: bool = False,
|
|
119
|
+
swap_mode: str = "ExactIn",
|
|
120
|
+
exclude_dexes: list[str] | None = None,
|
|
121
|
+
) -> dict[str, Any]:
|
|
122
|
+
"""Fetch a Jupiter quote for an exact-in swap.
|
|
123
|
+
|
|
124
|
+
Tries direct Jupiter API first. On free-tier errors (TOKEN_NOT_TRADABLE,
|
|
125
|
+
NOT_SUPPORTED) falls back to provider gateway when configured.
|
|
126
|
+
"""
|
|
127
|
+
# Try direct first
|
|
128
|
+
try:
|
|
129
|
+
return await _fetch_quote_direct(
|
|
130
|
+
input_mint=input_mint,
|
|
131
|
+
output_mint=output_mint,
|
|
132
|
+
amount_raw=amount_raw,
|
|
133
|
+
slippage_bps=slippage_bps,
|
|
134
|
+
restrict_intermediate_tokens=restrict_intermediate_tokens,
|
|
135
|
+
only_direct_routes=only_direct_routes,
|
|
136
|
+
swap_mode=swap_mode,
|
|
137
|
+
exclude_dexes=exclude_dexes,
|
|
138
|
+
)
|
|
139
|
+
except ProviderError as exc:
|
|
140
|
+
error_msg = str(exc).lower()
|
|
141
|
+
# Only fall back for known free-tier limitations
|
|
142
|
+
gateway_fallback_errors = (
|
|
143
|
+
"not tradable",
|
|
144
|
+
"token_not_tradable",
|
|
145
|
+
"not supported",
|
|
146
|
+
"restrict_intermediate_tokens",
|
|
147
|
+
)
|
|
148
|
+
if not any(phrase in error_msg for phrase in gateway_fallback_errors):
|
|
149
|
+
raise
|
|
150
|
+
if not _gateway_enabled():
|
|
151
|
+
raise
|
|
152
|
+
# Retry via gateway with relaxed restrictions
|
|
153
|
+
return await _fetch_quote_via_gateway(
|
|
154
|
+
input_mint=input_mint,
|
|
155
|
+
output_mint=output_mint,
|
|
156
|
+
amount_raw=amount_raw,
|
|
157
|
+
slippage_bps=slippage_bps,
|
|
158
|
+
restrict_intermediate_tokens=False,
|
|
159
|
+
only_direct_routes=only_direct_routes,
|
|
160
|
+
swap_mode=swap_mode,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
async def _fetch_quote_direct(
|
|
165
|
+
*,
|
|
166
|
+
input_mint: str,
|
|
167
|
+
output_mint: str,
|
|
168
|
+
amount_raw: int,
|
|
169
|
+
slippage_bps: int = 50,
|
|
170
|
+
restrict_intermediate_tokens: bool = True,
|
|
171
|
+
only_direct_routes: bool = False,
|
|
172
|
+
swap_mode: str = "ExactIn",
|
|
173
|
+
exclude_dexes: list[str] | None = None,
|
|
174
|
+
) -> dict[str, Any]:
|
|
175
|
+
"""Fetch a Jupiter quote directly from Jupiter API."""
|
|
176
|
+
client = get_client()
|
|
177
|
+
params = {
|
|
178
|
+
"inputMint": input_mint,
|
|
179
|
+
"outputMint": output_mint,
|
|
180
|
+
"amount": str(amount_raw),
|
|
181
|
+
"slippageBps": str(slippage_bps),
|
|
182
|
+
"swapMode": swap_mode,
|
|
183
|
+
"restrictIntermediateTokens": str(restrict_intermediate_tokens).lower(),
|
|
184
|
+
"onlyDirectRoutes": str(only_direct_routes).lower(),
|
|
185
|
+
}
|
|
186
|
+
if exclude_dexes:
|
|
187
|
+
params["excludeDexes"] = ",".join(str(d).strip() for d in exclude_dexes if str(d).strip())
|
|
188
|
+
response = await client.get(
|
|
189
|
+
f"{settings.jupiter_api_base_url.rstrip('/')}/quote",
|
|
190
|
+
params=params,
|
|
191
|
+
headers=_headers(),
|
|
192
|
+
)
|
|
193
|
+
if response.status_code != 200:
|
|
194
|
+
raise ProviderError("jupiter", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
195
|
+
data = response.json()
|
|
196
|
+
if not isinstance(data, dict) or "outAmount" not in data:
|
|
197
|
+
raise ProviderError("jupiter", "Unexpected quote response from Jupiter.")
|
|
198
|
+
return data
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
async def _fetch_quote_via_gateway(
|
|
202
|
+
*,
|
|
203
|
+
input_mint: str,
|
|
204
|
+
output_mint: str,
|
|
205
|
+
amount_raw: int,
|
|
206
|
+
slippage_bps: int = 50,
|
|
207
|
+
restrict_intermediate_tokens: bool = False,
|
|
208
|
+
only_direct_routes: bool = False,
|
|
209
|
+
swap_mode: str = "ExactIn",
|
|
210
|
+
) -> dict[str, Any]:
|
|
211
|
+
"""Fetch a Jupiter quote via provider gateway (uses API key)."""
|
|
212
|
+
params: dict[str, Any] = {
|
|
213
|
+
"inputMint": input_mint,
|
|
214
|
+
"outputMint": output_mint,
|
|
215
|
+
"amount": str(amount_raw),
|
|
216
|
+
"slippageBps": str(slippage_bps),
|
|
217
|
+
"swapMode": swap_mode,
|
|
218
|
+
}
|
|
219
|
+
if only_direct_routes:
|
|
220
|
+
params["onlyDirectRoutes"] = "true"
|
|
221
|
+
|
|
222
|
+
status_code, payload = await _gateway_get("quote", params=params)
|
|
223
|
+
if status_code != 200:
|
|
224
|
+
error_msg = payload if isinstance(payload, str) else json.dumps(payload)
|
|
225
|
+
raise ProviderError("jupiter-gateway", f"HTTP {status_code}: {error_msg}")
|
|
226
|
+
if isinstance(payload, dict) and payload.get("errorCode"):
|
|
227
|
+
raise ProviderError("jupiter-gateway", str(payload.get("error") or payload.get("errorCode")))
|
|
228
|
+
if not isinstance(payload, dict) or "outAmount" not in payload:
|
|
229
|
+
raise ProviderError("jupiter-gateway", "Unexpected quote response from gateway.")
|
|
230
|
+
return payload
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
async def fetch_ultra_order(
|
|
234
|
+
*,
|
|
235
|
+
input_mint: str,
|
|
236
|
+
output_mint: str,
|
|
237
|
+
amount_raw: int,
|
|
238
|
+
taker: str | None = None,
|
|
239
|
+
slippage_bps: int = 50,
|
|
240
|
+
swap_mode: str = "ExactIn",
|
|
241
|
+
) -> dict[str, Any]:
|
|
242
|
+
"""Fetch a Jupiter Ultra order for an exact-in swap."""
|
|
243
|
+
client = get_client()
|
|
244
|
+
params = {
|
|
245
|
+
"inputMint": input_mint,
|
|
246
|
+
"outputMint": output_mint,
|
|
247
|
+
"amount": str(amount_raw),
|
|
248
|
+
"swapMode": swap_mode,
|
|
249
|
+
"slippageBps": str(slippage_bps),
|
|
250
|
+
}
|
|
251
|
+
if taker:
|
|
252
|
+
params["taker"] = taker
|
|
253
|
+
response = await client.get(
|
|
254
|
+
f"{settings.jupiter_ultra_api_base_url.rstrip('/')}/order",
|
|
255
|
+
params=params,
|
|
256
|
+
headers=_headers(),
|
|
257
|
+
)
|
|
258
|
+
if response.status_code != 200:
|
|
259
|
+
raise ProviderError("jupiter-ultra", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
260
|
+
data = response.json()
|
|
261
|
+
if not isinstance(data, dict):
|
|
262
|
+
raise ProviderError("jupiter-ultra", "Unexpected order response from Jupiter Ultra.")
|
|
263
|
+
if data.get("error") or data.get("errorCode"):
|
|
264
|
+
raise ProviderError(
|
|
265
|
+
"jupiter-ultra",
|
|
266
|
+
str(data.get("error") or data.get("errorCode") or "Unknown Ultra error."),
|
|
267
|
+
)
|
|
268
|
+
if "outAmount" not in data:
|
|
269
|
+
raise ProviderError("jupiter-ultra", "Unexpected order response from Jupiter Ultra.")
|
|
270
|
+
return data
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
async def fetch_swap_v2_order(
|
|
274
|
+
*,
|
|
275
|
+
input_mint: str,
|
|
276
|
+
output_mint: str,
|
|
277
|
+
amount_raw: int,
|
|
278
|
+
taker: str,
|
|
279
|
+
slippage_bps: int | str | None = None,
|
|
280
|
+
exclude_routers: list[str] | None = None,
|
|
281
|
+
swap_mode: str = "ExactIn",
|
|
282
|
+
) -> dict[str, Any]:
|
|
283
|
+
"""Fetch a Jupiter Swap API V2 meta-aggregator order."""
|
|
284
|
+
client = get_client()
|
|
285
|
+
params: dict[str, Any] = {
|
|
286
|
+
"inputMint": input_mint,
|
|
287
|
+
"outputMint": output_mint,
|
|
288
|
+
"amount": str(amount_raw),
|
|
289
|
+
"taker": taker,
|
|
290
|
+
}
|
|
291
|
+
if swap_mode != "ExactIn":
|
|
292
|
+
params["swapMode"] = swap_mode
|
|
293
|
+
if slippage_bps is not None:
|
|
294
|
+
params["slippageBps"] = str(slippage_bps)
|
|
295
|
+
if exclude_routers:
|
|
296
|
+
params["excludeRouters"] = ",".join(str(item).strip() for item in exclude_routers if str(item).strip())
|
|
297
|
+
|
|
298
|
+
response = await client.get(
|
|
299
|
+
f"{_swap_v2_base_url()}/order",
|
|
300
|
+
params=params,
|
|
301
|
+
headers=_headers(),
|
|
302
|
+
)
|
|
303
|
+
if response.status_code != 200:
|
|
304
|
+
raise ProviderError("jupiter-v2", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
305
|
+
data = response.json()
|
|
306
|
+
if not isinstance(data, dict):
|
|
307
|
+
raise ProviderError("jupiter-v2", "Unexpected order response from Jupiter Swap V2.")
|
|
308
|
+
if data.get("error") or data.get("errorCode"):
|
|
309
|
+
raise ProviderError(
|
|
310
|
+
"jupiter-v2",
|
|
311
|
+
str(data.get("error") or data.get("errorCode") or "Unknown Swap V2 order error."),
|
|
312
|
+
details=data,
|
|
313
|
+
)
|
|
314
|
+
if "outAmount" not in data:
|
|
315
|
+
raise ProviderError("jupiter-v2", "Unexpected order response from Jupiter Swap V2.")
|
|
316
|
+
return data
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
async def build_swap_transaction(
|
|
320
|
+
*,
|
|
321
|
+
user_public_key: str,
|
|
322
|
+
quote_response: dict[str, Any],
|
|
323
|
+
wrap_and_unwrap_sol: bool = True,
|
|
324
|
+
) -> dict[str, Any]:
|
|
325
|
+
"""Build a serialized swap transaction from a Jupiter quote.
|
|
326
|
+
|
|
327
|
+
Tries direct Jupiter API first. Falls back to provider gateway on error.
|
|
328
|
+
"""
|
|
329
|
+
# Try direct first
|
|
330
|
+
try:
|
|
331
|
+
return await _build_swap_direct(
|
|
332
|
+
user_public_key=user_public_key,
|
|
333
|
+
quote_response=quote_response,
|
|
334
|
+
wrap_and_unwrap_sol=wrap_and_unwrap_sol,
|
|
335
|
+
)
|
|
336
|
+
except ProviderError as exc:
|
|
337
|
+
if not _gateway_enabled():
|
|
338
|
+
raise
|
|
339
|
+
# Fall back to gateway
|
|
340
|
+
return await _build_swap_via_gateway(
|
|
341
|
+
user_public_key=user_public_key,
|
|
342
|
+
quote_response=quote_response,
|
|
343
|
+
wrap_and_unwrap_sol=wrap_and_unwrap_sol,
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
async def _build_swap_direct(
|
|
348
|
+
*,
|
|
349
|
+
user_public_key: str,
|
|
350
|
+
quote_response: dict[str, Any],
|
|
351
|
+
wrap_and_unwrap_sol: bool = True,
|
|
352
|
+
) -> dict[str, Any]:
|
|
353
|
+
"""Build a swap transaction directly via Jupiter API."""
|
|
354
|
+
client = get_client()
|
|
355
|
+
body = _swap_fallback_build_body(
|
|
356
|
+
user_public_key=user_public_key,
|
|
357
|
+
quote_response=quote_response,
|
|
358
|
+
wrap_and_unwrap_sol=wrap_and_unwrap_sol,
|
|
359
|
+
)
|
|
360
|
+
response = await client.post(
|
|
361
|
+
f"{settings.jupiter_api_base_url.rstrip('/')}/swap",
|
|
362
|
+
json=body,
|
|
363
|
+
headers=_headers(),
|
|
364
|
+
)
|
|
365
|
+
if response.status_code != 200:
|
|
366
|
+
raise ProviderError("jupiter", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
367
|
+
data = response.json()
|
|
368
|
+
if not isinstance(data, dict) or "swapTransaction" not in data:
|
|
369
|
+
raise ProviderError("jupiter", "Unexpected swap response from Jupiter.")
|
|
370
|
+
return data
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
async def _build_swap_via_gateway(
|
|
374
|
+
*,
|
|
375
|
+
user_public_key: str,
|
|
376
|
+
quote_response: dict[str, Any],
|
|
377
|
+
wrap_and_unwrap_sol: bool = True,
|
|
378
|
+
) -> dict[str, Any]:
|
|
379
|
+
"""Build a swap transaction via provider gateway (uses API key)."""
|
|
380
|
+
body = _swap_fallback_build_body(
|
|
381
|
+
user_public_key=user_public_key,
|
|
382
|
+
quote_response=quote_response,
|
|
383
|
+
wrap_and_unwrap_sol=wrap_and_unwrap_sol,
|
|
384
|
+
)
|
|
385
|
+
status_code, payload = await _gateway_post("swap", body=body)
|
|
386
|
+
if status_code != 200:
|
|
387
|
+
error_msg = payload if isinstance(payload, str) else json.dumps(payload)
|
|
388
|
+
raise ProviderError("jupiter-gateway", f"HTTP {status_code}: {error_msg}")
|
|
389
|
+
if isinstance(payload, dict) and payload.get("errorCode"):
|
|
390
|
+
raise ProviderError("jupiter-gateway", str(payload.get("error") or payload.get("errorCode")))
|
|
391
|
+
if not isinstance(payload, dict) or "swapTransaction" not in payload:
|
|
392
|
+
raise ProviderError("jupiter-gateway", "Unexpected swap response from gateway.")
|
|
393
|
+
return payload
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
async def execute_ultra_order(
|
|
397
|
+
*,
|
|
398
|
+
signed_transaction_base64: str,
|
|
399
|
+
request_id: str,
|
|
400
|
+
) -> dict[str, Any]:
|
|
401
|
+
"""Execute a signed Jupiter Ultra order."""
|
|
402
|
+
client = get_client()
|
|
403
|
+
body = {
|
|
404
|
+
"signedTransaction": signed_transaction_base64,
|
|
405
|
+
"requestId": request_id,
|
|
406
|
+
}
|
|
407
|
+
response = await client.post(
|
|
408
|
+
f"{settings.jupiter_ultra_api_base_url.rstrip('/')}/execute",
|
|
409
|
+
json=body,
|
|
410
|
+
headers=_headers(),
|
|
411
|
+
)
|
|
412
|
+
if response.status_code != 200:
|
|
413
|
+
raise ProviderError("jupiter-ultra", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
414
|
+
data = response.json()
|
|
415
|
+
if not isinstance(data, dict):
|
|
416
|
+
raise ProviderError("jupiter-ultra", "Unexpected execute response from Jupiter Ultra.")
|
|
417
|
+
if data.get("error") or data.get("errorCode"):
|
|
418
|
+
raise ProviderError(
|
|
419
|
+
"jupiter-ultra",
|
|
420
|
+
str(data.get("error") or data.get("errorCode") or "Unknown Ultra execute error."),
|
|
421
|
+
)
|
|
422
|
+
return data
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
async def execute_swap_v2_order(
|
|
426
|
+
*,
|
|
427
|
+
signed_transaction_base64: str,
|
|
428
|
+
request_id: str,
|
|
429
|
+
last_valid_block_height: int | str | None = None,
|
|
430
|
+
) -> dict[str, Any]:
|
|
431
|
+
"""Execute a signed Jupiter Swap API V2 order."""
|
|
432
|
+
client = get_client()
|
|
433
|
+
body: dict[str, Any] = {
|
|
434
|
+
"signedTransaction": signed_transaction_base64,
|
|
435
|
+
"requestId": request_id,
|
|
436
|
+
}
|
|
437
|
+
if last_valid_block_height is not None:
|
|
438
|
+
body["lastValidBlockHeight"] = str(last_valid_block_height)
|
|
439
|
+
response = await client.post(
|
|
440
|
+
f"{_swap_v2_base_url()}/execute",
|
|
441
|
+
json=body,
|
|
442
|
+
headers={**_headers(), "Content-Type": "application/json"},
|
|
443
|
+
)
|
|
444
|
+
if response.status_code != 200:
|
|
445
|
+
raise ProviderError("jupiter-v2", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
446
|
+
data = response.json()
|
|
447
|
+
if not isinstance(data, dict):
|
|
448
|
+
raise ProviderError("jupiter-v2", "Unexpected execute response from Jupiter Swap V2.")
|
|
449
|
+
if data.get("error") or data.get("errorCode"):
|
|
450
|
+
raise ProviderError(
|
|
451
|
+
"jupiter-v2",
|
|
452
|
+
str(data.get("error") or data.get("errorCode") or "Unknown Swap V2 execute error."),
|
|
453
|
+
details=data,
|
|
454
|
+
)
|
|
455
|
+
if str(data.get("status") or "").strip().lower() == "failed":
|
|
456
|
+
message = data.get("error") or data.get("code") or "Swap V2 execute failed."
|
|
457
|
+
raise ProviderError("jupiter-v2", str(message), details=data)
|
|
458
|
+
return data
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
async def fetch_prices(
|
|
462
|
+
*,
|
|
463
|
+
mints: list[str],
|
|
464
|
+
show_extra_info: bool = False,
|
|
465
|
+
) -> dict[str, Any]:
|
|
466
|
+
"""Fetch token prices from Jupiter Price API V3."""
|
|
467
|
+
if not mints:
|
|
468
|
+
raise ProviderError("jupiter", "At least one mint is required for price lookup.")
|
|
469
|
+
client = get_client()
|
|
470
|
+
params = {
|
|
471
|
+
"ids": ",".join(mints),
|
|
472
|
+
}
|
|
473
|
+
if show_extra_info:
|
|
474
|
+
params["showExtraInfo"] = "true"
|
|
475
|
+
response = await client.get(
|
|
476
|
+
settings.jupiter_price_api_base_url,
|
|
477
|
+
params=params,
|
|
478
|
+
headers=_headers(),
|
|
479
|
+
)
|
|
480
|
+
if response.status_code != 200:
|
|
481
|
+
raise ProviderError("jupiter", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
482
|
+
data = response.json()
|
|
483
|
+
if not isinstance(data, dict):
|
|
484
|
+
raise ProviderError("jupiter", "Unexpected price response from Jupiter.")
|
|
485
|
+
return data
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
async def fetch_token_metadata(*, mints: list[str]) -> dict[str, dict[str, Any]]:
|
|
489
|
+
"""Look up token symbol/name for a batch of mints via Jupiter's token
|
|
490
|
+
search API. Keyed by mint address; mints Jupiter doesn't index (very new
|
|
491
|
+
or illiquid tokens) are simply absent from the result rather than
|
|
492
|
+
raising, since this is display-only enrichment on top of the price data.
|
|
493
|
+
"""
|
|
494
|
+
if not mints:
|
|
495
|
+
return {}
|
|
496
|
+
client = get_client()
|
|
497
|
+
params = {"query": ",".join(mints)}
|
|
498
|
+
response = await client.get(
|
|
499
|
+
f"{settings.jupiter_token_search_api_base_url.rstrip('/')}/search",
|
|
500
|
+
params=params,
|
|
501
|
+
headers=_headers(),
|
|
502
|
+
)
|
|
503
|
+
if response.status_code != 200:
|
|
504
|
+
raise ProviderError("jupiter", f"HTTP {response.status_code}: {response.text[:300]}")
|
|
505
|
+
data = response.json()
|
|
506
|
+
if not isinstance(data, list):
|
|
507
|
+
raise ProviderError("jupiter", "Unexpected token search response from Jupiter.")
|
|
508
|
+
result: dict[str, dict[str, Any]] = {}
|
|
509
|
+
for item in data:
|
|
510
|
+
if not isinstance(item, dict):
|
|
511
|
+
continue
|
|
512
|
+
mint = str(item.get("id") or "").strip()
|
|
513
|
+
if not mint:
|
|
514
|
+
continue
|
|
515
|
+
result[mint] = {
|
|
516
|
+
"symbol": item.get("symbol"),
|
|
517
|
+
"name": item.get("name"),
|
|
518
|
+
}
|
|
519
|
+
return result
|