Skip to content

Commit efbbdeb

Browse files
committed
Added ultra endpoints implementation
1 parent b043666 commit efbbdeb

11 files changed

+119
-235
lines changed

jup_ag_sdk/clients/jupiter_client.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import base58
66
import httpx
7-
from solana.rpc.api import Client
8-
from solders.solders import Keypair, SendTransactionResp, VersionedTransaction
7+
from solders.solders import Keypair, VersionedTransaction
98

109

1110
class JupiterClient:
@@ -17,12 +16,10 @@ class JupiterClient:
1716
def __init__(
1817
self,
1918
api_key: Optional[str],
20-
rpc_url: Optional[str],
2119
private_key_env_var: str,
2220
timeout: int,
2321
):
2422
self.api_key = api_key
25-
self.rpc = Client(rpc_url) if rpc_url else None
2623
self.base_url = (
2724
"https://api.jup.ag" if api_key else "https://lite-api.jup.ag"
2825
)
@@ -56,13 +53,6 @@ def _get_public_key(self) -> str:
5653
)
5754
return str(wallet.pubkey())
5855

59-
def _send_transaction(
60-
self, transaction: VersionedTransaction
61-
) -> SendTransactionResp:
62-
if not self.rpc:
63-
raise ValueError("Client was initialized without RPC URL.")
64-
return self.rpc.send_transaction(transaction)
65-
6656
def _sign_base64_transaction(
6757
self, transaction_base64: str
6858
) -> VersionedTransaction:

jup_ag_sdk/clients/swap_api_client.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

jup_ag_sdk/clients/ultra_api_client.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class UltraApiClient(JupiterClient):
1313
"""
14-
A client for interacting with the Jupiter Swap API.
14+
A client for interacting with the Jupiter Ultra API.
1515
Inherits from JupiterClient.
1616
"""
1717

@@ -23,7 +23,6 @@ def __init__(
2323
):
2424
super().__init__(
2525
api_key=api_key,
26-
rpc_url=None,
2726
private_key_env_var=private_key_env_var,
2827
timeout=timeout,
2928
)
@@ -93,3 +92,41 @@ def order_and_execute(self, request: UltraOrderRequest) -> Dict[str, Any]:
9392
)
9493

9594
return self.execute(execute_request)
95+
96+
def balances(self, address: str) -> Dict[str, Any]:
97+
"""
98+
Get token balances of an account from the Jupiter Ultra API.
99+
100+
Args:
101+
address (str): The public key of the account to get balances for.
102+
103+
Returns:
104+
dict: The dict api response.
105+
"""
106+
url = f"{self.base_url}/ultra/v1/balances/{address}"
107+
response = self.client.get(url, headers=self._get_headers())
108+
response.raise_for_status()
109+
110+
return response.json() # type: ignore
111+
112+
def shield(self, mints: list[str]) -> Dict[str, Any]:
113+
"""
114+
Get token information and warnings for specific mints
115+
from the Jupiter Ultra API.
116+
117+
Args:
118+
mints (list[str]): List of token mint addresses
119+
to get information for.
120+
121+
Returns:
122+
dict: The dict api response with warnings information.
123+
"""
124+
params = {"mints": ",".join(mints)}
125+
126+
url = f"{self.base_url}/ultra/v1/shield"
127+
response = self.client.get(
128+
url, params=params, headers=self._get_headers()
129+
)
130+
response.raise_for_status()
131+
132+
return response.json() # type: ignore

jup_ag_sdk/models/swap_api/__init__.py

Whitespace-only changes.

jup_ag_sdk/models/swap_api/quote_request_model.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

jup_ag_sdk/models/swap_api/swap_request_model.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

jup_ag_sdk/models/ultra_api/ultra_order_request_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class UltraOrderRequest(BaseModel):
99
output_mint: str
1010
amount: int
1111
taker: Optional[str] = None
12+
referral_account: Optional[str] = None
13+
referral_fee: Optional[int] = None
1214

1315
def to_dict(self) -> Dict[str, Any]:
1416
params = self.model_dump(exclude_none=True)

tests/test_swap_client.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/test_ultra_balances.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from dotenv import load_dotenv
2+
3+
from jup_ag_sdk.clients.ultra_api_client import UltraApiClient
4+
5+
6+
def test_ultra_get_balances() -> None:
7+
"""
8+
Test the UltraApiClient balances method.
9+
"""
10+
load_dotenv()
11+
client = UltraApiClient()
12+
13+
address = client._get_public_key()
14+
15+
try:
16+
balances_response = client.balances(str(address))
17+
assert (
18+
"SOL" in balances_response
19+
), "Response does not contain 'SOL' key."
20+
21+
print()
22+
print("Balances API Response:")
23+
for token, details in balances_response.items():
24+
print(f"Token: {token}")
25+
print(f" - Amount: {details['amount']}")
26+
print(f" - UI Amount: {details['uiAmount']}")
27+
print(f" - Slot: {details['slot']}")
28+
print(f" - Is Frozen: {details['isFrozen']}")
29+
30+
except Exception as e:
31+
print("Error occurred while fetching balances:", str(e))
32+
finally:
33+
client.close()

tests/test_ultra_client.py renamed to tests/test_ultra_order_and_execute.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ def test_ultra_get_order_and_execute() -> None:
2121
)
2222

2323
try:
24-
rpc_response = client.order_and_execute(order_request)
25-
signature = str(rpc_response["signature"])
24+
client_response = client.order_and_execute(order_request)
25+
signature = str(client_response["signature"])
2626
assert (
2727
signature is not None
2828
), "Transaction signature is missing or invalid."
29-
print(
30-
f"Transaction sent successfully!"
31-
f"View transaction on Solscan: https://solscan.io/tx/{signature}"
32-
)
29+
30+
print()
31+
print("Order and Execute API Response:")
32+
print(f" - Transaction Signature: {signature}")
33+
print(f" - View on Solscan: https://solscan.io/tx/{signature}")
3334

3435
except Exception as e:
3536
print("Error occurred while processing the order:", str(e))

0 commit comments

Comments
 (0)