helius_execute_jupiter_swap
Swap tokens on Solana using Jupiter. Specify input and output token mints, amount, and signer.
Instructions
Execute a token swap using Jupiter
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputMint | Yes | The mint address of the input token | |
| outputMint | Yes | The mint address of the output token | |
| amount | Yes | The amount of input tokens to swap | |
| maxDynamicSlippageBps | No | Maximum slippage in basis points (optional) | |
| signer | Yes | The signer public key |
Implementation Reference
- src/handlers/helius.ts:519-541 (handler)Handler function that executes a Jupiter swap. Validates the signer public key, constructs params with inputMint/outputMint/amount/maxDynamicSlippageBps, then calls helius.rpc.executeJupiterSwap and returns the result.
export const executeJupiterSwapHandler = async (input: ExecuteJupiterSwapInput): Promise<ToolResultSchema> => { try { // Validate the signer is a valid public key format const signerPublicKey = validatePublicKey(input.signer); if (!(signerPublicKey instanceof PublicKey)) { return signerPublicKey; } const params = { inputMint: input.inputMint, outputMint: input.outputMint, amount: input.amount, maxDynamicSlippageBps: input.maxDynamicSlippageBps }; // The actual implementation expects a Signer object, but our mock likely accepts a string // We'll use the string and let the type casting handle it const result = await (helius as any as Helius).rpc.executeJupiterSwap(params, input.signer as any); return createSuccessResponse(`Jupiter swap executed: ${JSON.stringify(result, null, 2)}`); } catch (error) { return createErrorResponse(`Error executing Jupiter swap: ${error instanceof Error ? error.message : String(error)}`); } } - src/handlers/helius.types.ts:275-281 (schema)Type definition for ExecuteJupiterSwapInput containing inputMint, outputMint, amount, optional maxDynamicSlippageBps, and signer fields.
export type ExecuteJupiterSwapInput = { inputMint: string; outputMint: string; amount: number; maxDynamicSlippageBps?: number; signer: string; } - src/tools.ts:516-530 (schema)Tool registration entry defining name 'helius_execute_jupiter_swap', description, and inputSchema with inputMint, outputMint, amount, maxDynamicSlippageBps, signer properties.
{ name: 'helius_execute_jupiter_swap', description: 'Execute a token swap using Jupiter', inputSchema: { type: 'object', properties: { inputMint: { type: 'string', description: 'The mint address of the input token' }, outputMint: { type: 'string', description: 'The mint address of the output token' }, amount: { type: 'number', description: 'The amount of input tokens to swap' }, maxDynamicSlippageBps: { type: 'number', description: 'Maximum slippage in basis points (optional)' }, signer: { type: 'string', description: 'The signer public key' } }, required: ['inputMint', 'outputMint', 'amount', 'signer'] } } - src/tools.ts:549-591 (registration)Handler dictionary mapping tool name 'helius_execute_jupiter_swap' to executeJupiterSwapHandler function.
export const handlers: handlerDictionary = { "helius_get_balance": getBalanceHandler, "helius_get_block_height": getBlockHeightHandler, "helius_get_token_accounts_by_owner": getTokenAccountsByOwnerHandler, "helius_get_token_supply": getTokenSupplyHandler, "helius_get_token_largest_accounts": getTokenLargestAccountsHandler, "helius_get_latest_blockhash": getLatestBlockhashHandler, "helius_get_token_account_balance": getTokenAccountBalanceHandler, "helius_get_slot": getSlotHandler, "helius_get_transaction": getTransactionHandler, // New handlers "helius_get_account_info": getAccountInfoHandler, "helius_get_program_accounts": getProgramAccountsHandler, "helius_get_signatures_for_address": getSignaturesForAddressHandler, "helius_get_minimum_balance_for_rent_exemption": getMinimumBalanceForRentExemptionHandler, "helius_get_multiple_accounts": getMultipleAccountsHandler, "helius_get_inflation_reward": getInflationRewardHandler, "helius_get_epoch_info": getEpochInfoHandler, "helius_get_epoch_schedule": getEpochScheduleHandler, "helius_get_leader_schedule": getLeaderScheduleHandler, "helius_get_recent_performance_samples": getRecentPerformanceSamplesHandler, "helius_get_version": getVersionHandler, // DAS Methods "helius_get_asset": helius.getAssetHandler, "helius_get_rwa_asset": helius.getRwaAssetHandler, "helius_get_asset_batch": helius.getAssetBatchHandler, "helius_get_asset_proof": helius.getAssetProofHandler, "helius_get_assets_by_group": helius.getAssetsByGroupHandler, "helius_get_assets_by_owner": helius.getAssetsByOwnerHandler, "helius_get_assets_by_creator": helius.getAssetsByCreatorHandler, "helius_get_assets_by_authority": helius.getAssetsByAuthorityHandler, "helius_search_assets": helius.searchAssetsHandler, "helius_get_signatures_for_asset": helius.getSignaturesForAssetHandler, "helius_get_nft_editions": helius.getNftEditionsHandler, "helius_get_token_accounts": helius.getTokenAccountsHandler, // Transaction and Fee Methods "helius_get_priority_fee_estimate": helius.getPriorityFeeEstimateHandler, "helius_poll_transaction_confirmation": helius.pollTransactionConfirmationHandler, "helius_send_jito_bundle": helius.sendJitoBundleHandler, "helius_get_bundle_statuses": helius.getBundleStatusesHandler, "helius_get_fee_for_message": getFeeForMessageHandler, "helius_execute_jupiter_swap": executeJupiterSwapHandler // "print_environment": printEnvironmentHandler, - src/handlers/utils.ts:53-59 (helper)Utility function validatePublicKey used by the handler to validate the signer public key before executing the swap.
export const validatePublicKey = (publicKeyString: string): PublicKey | ToolResultSchema => { const { publicKey, error } = createPublicKey(publicKeyString); if (error) { return createErrorResponse(error); } return publicKey!; };