delegate-framework
Version:
A TypeScript framework for building robust, production-ready blockchain workflows with comprehensive error handling, logging, and testing. Maintained by delegate.fun
89 lines • 2.4 kB
TypeScript
/**
* Framework-ized Swapper for executing token swaps with fallback between protocols
*
* Usage Example:
* ```typescript
* const swapper = new Swapper(
* privateKey,
* 'https://mainnet.helius-rpc.com',
* 'your-api-key',
* {
* jupiter: {
* tokenListUrl: 'https://token.jup.ag/all',
* fallbackDecimals: 6
* }
* }
* );
*
* const result = await swapper.executeSwap({
* fromAsset: 'So11111111111111111111111111111111111111112', // SOL
* toAssets: ['EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'], // USDC
* numTokens: 0.1, // Optional: specific amount, otherwise uses available balance
* slippage: 0.5 // Optional: default 0.5%
* });
*
* if (result.success) {
* console.log(`Swap successful using ${result.protocol}: ${result.signature}`);
* } else {
* console.log(`Swap failed: ${result.error}`);
* }
* ```
*/
import { JupiterSwapConfig } from './swap/jupiter';
import { RaydiumSwapConfig } from './swap/raydium';
import { BaseDelegate } from './base-delegate';
export interface SwapTask {
fromAsset: string;
toAssets: string[];
numTokens?: number;
slippage?: number;
}
export interface SwapResult {
success: boolean;
signature?: string;
protocol?: string;
error?: string;
}
export declare class Swapper extends BaseDelegate {
private heliusClient;
private jupiterSwap;
private raydiumSwap;
constructor(privateKey: string, rpcUrl: string, apiKey: string, config?: {
jupiter?: JupiterSwapConfig;
raydium?: RaydiumSwapConfig;
});
/**
* Execute a swap task with fallback between protocols
*/
executeSwap(task: SwapTask): Promise<SwapResult>;
/**
* Get the appropriate swap amount based on asset type and balance
*/
private getSwapAmount;
/**
* Execute swap with fallback between protocols
*/
private swapWithFallback;
/**
* Execute Jupiter swap
*/
private executeJupiterSwap;
/**
* Execute Raydium swap
*/
private executeRaydiumSwap;
/**
* Get current balances for all assets
*/
getBalances(): Promise<{
sol: number;
tokens: Array<{
mint: string;
balance: number;
decimals: number;
}>;
}>;
executeDelegate(): Promise<any>;
validateOptions(): void;
}
//# sourceMappingURL=swapper.d.ts.map