|
19 | 19 | from solders.message import to_bytes_versioned # type: ignore |
20 | 20 |
|
21 | 21 | from sakit.utils.trigger import JupiterTrigger |
| 22 | +from sakit.utils.wallet import send_raw_transaction_with_priority |
22 | 23 |
|
23 | 24 | logger = logging.getLogger(__name__) |
24 | 25 |
|
@@ -192,6 +193,7 @@ def __init__(self, registry: Optional[ToolRegistry] = None): |
192 | 193 | self._referral_account: Optional[str] = None |
193 | 194 | self._referral_fee: Optional[int] = None |
194 | 195 | self._payer_private_key: Optional[str] = None |
| 196 | + self._rpc_url: Optional[str] = None |
195 | 197 |
|
196 | 198 | def get_schema(self) -> Dict[str, Any]: |
197 | 199 | return { |
@@ -265,6 +267,7 @@ def configure(self, config: Dict[str, Any]) -> None: |
265 | 267 | self._referral_account = tool_cfg.get("referral_account") |
266 | 268 | self._referral_fee = tool_cfg.get("referral_fee") |
267 | 269 | self._payer_private_key = tool_cfg.get("payer_private_key") |
| 270 | + self._rpc_url = tool_cfg.get("rpc_url") |
268 | 271 |
|
269 | 272 | async def execute( |
270 | 273 | self, |
@@ -372,13 +375,28 @@ async def _sign_and_execute( # pragma: no cover |
372 | 375 | "message": "Failed to sign transaction via Privy.", |
373 | 376 | } |
374 | 377 |
|
375 | | - # Execute |
376 | | - exec_result = await trigger.execute(signed_tx, request_id) |
377 | | - |
378 | | - if not exec_result.success: |
379 | | - return {"status": "error", "message": exec_result.error} |
380 | | - |
381 | | - return {"status": "success", "signature": exec_result.signature} |
| 378 | + # Send via RPC or fallback to Jupiter execute |
| 379 | + if self._rpc_url: |
| 380 | + # Use configured RPC (Helius recommended) instead of Jupiter's execute endpoint |
| 381 | + tx_bytes = base64.b64decode(signed_tx) |
| 382 | + send_result = await send_raw_transaction_with_priority( |
| 383 | + rpc_url=self._rpc_url, |
| 384 | + tx_bytes=tx_bytes, |
| 385 | + ) |
| 386 | + if not send_result.get("success"): |
| 387 | + return { |
| 388 | + "status": "error", |
| 389 | + "message": send_result.get( |
| 390 | + "error", "Failed to send transaction" |
| 391 | + ), |
| 392 | + } |
| 393 | + return {"status": "success", "signature": send_result.get("signature")} |
| 394 | + else: |
| 395 | + # Fallback to Jupiter execute if no RPC configured |
| 396 | + exec_result = await trigger.execute(signed_tx, request_id) |
| 397 | + if not exec_result.success: |
| 398 | + return {"status": "error", "message": exec_result.error} |
| 399 | + return {"status": "success", "signature": exec_result.signature} |
382 | 400 |
|
383 | 401 | except Exception as e: |
384 | 402 | logger.exception(f"Failed to sign and execute: {str(e)}") |
|
0 commit comments