0.1.0-22 • Published 10 months ago
@lit-protocol/aw-tool-jupiter-swap v0.1.0-22
AW-Tool Jupiter Swap Documentation
The aw-tool-jupiter-swap package contains utilities for performing token swaps on Solana using Jupiter Exchange via Lit Protocol.
Files Overview (in src/lib)
1. lit-actions/tool.ts
Contains the main logic for executing a Lit Action to perform a Jupiter swap.
Key Features:
- PKP Info Retrieval: Fetches PKP details and validates the tool policy.
- Policy Validation: Checks if a policy exists and executes it if present.
- Swap Execution: Handles the complete swap flow including:
- Getting token decimals
- Converting amounts to atomic units
- Fetching Jupiter quotes
- Creating and signing transactions
- Broadcasting the swap transaction
2. lit-actions/policy.ts
Defines and validates the Jupiter swap policy.
Key Features:
- Policy Validation: Validates policy parameters including:
- Maximum swap amount
- Allowed token addresses
- Token Address Validation: Ensures tokens are valid Solana public keys
- Amount Validation: Checks if swap amount is within policy limits
3. lit-actions/utils/
Collection of utility functions for the swap process:
Key Components:
solana-keypair.ts: Handles Solana keypair creation and managementsolana-connection.ts: Manages Solana RPC connectionstoken-decimals.ts: Retrieves token decimal informationatomic-conversion.ts: Converts between human-readable and atomic amountsquote.ts: Interfaces with Jupiter's quote APIswap.ts: Handles swap transaction creationtransaction.ts: Manages transaction signing and sending
Usage
The tool requires the following parameters:
{
pkpEthAddress: string; // PKP's Ethereum address
tokenIn: string; // Input token's Solana address
tokenOut: string; // Output token's Solana address
amountIn: string; // Amount to swap (in human-readable format)
ciphertext: string; // Encrypted private key data
dataToEncryptHash: string; // Hash of the encrypted data
}Policy Parameters
The tool supports policy restrictions on:
- Maximum swap amount
- Allowed token addresses
Response Format
Success Response:
{
status: 'success',
message: 'Swap transaction sent successfully',
txid: string // Solana transaction ID
}Error Response:
{
status: 'error',
error: string,
details: {
message: string,
type: string,
stack?: string
}
}Security Features
- Policy Enforcement: Validates all swaps against defined policies
- Access Control: Uses Lit Protocol's access control conditions
- Secure Key Management: Handles private keys securely through encryption
- Input Validation: Validates all input parameters before execution
Dependencies
@solana/web3.js: Solana blockchain interaction@lit-protocol/aw-tool: Core Agent Wallet tooling- Jupiter Exchange SDK: For swap functionality