UNPKG

hypesdk

Version:

A powerful SDK for interacting with the Hype blockchain, featuring advanced routing and token swap capabilities

225 lines (224 loc) 10.5 kB
import { ethers } from "ethers"; import { WalletBalancesResponse, DeployedToken, TokenHoldersResponse, RawTransactionInfo } from "./types"; import { createWallet } from "./services/wallet"; export interface RouteAllocation { tokenIn: string; tokenOut: string; routerIndex: number; fee: number; amountIn: string; stable: boolean; routerName?: string; percentage?: number; } export interface RouteHop { tokenIn: string; tokenOut: string; hopAmountIn: string; allocations: RouteAllocation[]; } export interface TokenInfo { address: string; symbol: string; decimals: number; } export declare class HyperSDK { readonly provider: ethers.JsonRpcProvider; static readonly RPC_URL = "https://rpc.hyperliquid.xyz/evm"; static readonly NATIVE_TOKEN = "0x000000000000000000000000000000000000dEaD"; static readonly WRAPPED_TOKEN_ADDRESS = "0x5555555555555555555555555555555555555555"; static readonly ROUTER_ADDRESS = "0x744489ee3d540777a66f2cf297479745e0852f7a"; constructor(); /** * Creates a new wallet * @returns {object} Object containing the wallet's address and private key */ createWallet: typeof createWallet; /** * Transfers native tokens * @param privateKey The sender's private key * @param toAddress The recipient's address * @param amount Amount to send in ether * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Transaction hash */ transfer(privateKey: string, toAddress: string, amount: string, priorityFeeMultiplier?: number): Promise<string>; /** * Wraps native tokens into wrapped tokens * @param privateKey The sender's private key * @param amount Amount to wrap in ether * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Transaction hash */ wrap(privateKey: string, amount: string, priorityFeeMultiplier?: number): Promise<string>; /** * Unwraps tokens back to native tokens * @param privateKey The sender's private key * @param amount Amount to unwrap in ether * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Transaction hash */ unwrap(privateKey: string, amount: string, priorityFeeMultiplier?: number): Promise<string>; /** * Execute a token swap using the best available route * @param privateKey The sender's private key * @param tokenIn Address of the input token * @param tokenOut Address of the output token * @param amountIn Amount of input tokens in human readable format * @param slippageBps Slippage tolerance in basis points (1 bp = 0.01%) * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Transaction hash */ buyWithRoute(privateKey: string, tokenIn: string, tokenOut: string, amountIn: string | number, slippageBps?: number, priorityFeeMultiplier?: number): Promise<string>; /** * Execute a token sell using the best available route * @param privateKey The sender's private key * @param tokenToSell Address of the token to sell * @param amountIn Amount of input tokens in human readable format * @param slippageBps Slippage tolerance in basis points (1 bp = 0.01%) * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Transaction hash */ sellWithRoute(privateKey: string, tokenToSell: string, amountIn: string | number, slippageBps?: number, // Default 1% slippage priorityFeeMultiplier?: number): Promise<string>; /** * Get token balances for a specific wallet address * @param walletAddress The address to check balances for * @param limit Optional maximum number of tokens to return * @returns Wallet balances including native HYPE and tokens */ getWalletBalances(walletAddress: string, limit?: number): Promise<WalletBalancesResponse>; /** * Get balance of a specific token for a wallet address * @param tokenAddress The token contract address (use NATIVE_TOKEN for native HYPE) * @param walletAddress The wallet address to check balance for * @returns Token balance information including formatted balance and token details */ getTokenBalance(tokenAddress: string, walletAddress: string): Promise<{ balance: string; formattedBalance: string; symbol: string; decimals: number; name: string; }>; /** * Deploy a new token * @param privateKey The deployer's private key * @param name Token name * @param symbol Token symbol * @param initialSupply Initial token supply (in human readable format) * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Deployed token information */ deployToken(privateKey: string, name: string, symbol: string, initialSupply: string, priorityFeeMultiplier?: number): Promise<DeployedToken>; /** * Swap any token for any other token * @param privateKey The sender's private key * @param tokenIn Address of the input token * @param tokenOut Address of the output token * @param amountIn Amount of input tokens in human readable format * @param slippageBps Slippage tolerance in basis points (1 bp = 0.01%) * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Transaction hash */ swap(privateKey: string, tokenIn: string, tokenOut: string, amountIn: string | number, slippageBps?: number, priorityFeeMultiplier?: number): Promise<string>; /** * Get token holders for a specific token * @param tokenAddress The token contract address * @param limit Optional maximum number of holders to return (default: 100, max: 100) * @returns Token holders information with formatted balances */ getTokenHolders(tokenAddress: string, limit?: number): Promise<TokenHoldersResponse>; /** * Get detailed information about a transaction * @param txHash The transaction hash to look up * @returns Formatted transaction data from Hyperscan API */ getTransactionInfo(txHash: string): Promise<RawTransactionInfo>; /** * Airdrop tokens to multiple recipients in batches of 10 * @param privateKey The sender's private key * @param tokenAddress The token contract address to airdrop * @param recipients Array of recipient addresses * @param amounts Array of amounts to send (in human readable format) * @param priorityFeeMultiplier Optional multiplier for the priority fee * @returns Array of transaction hashes */ airdropToken(privateKey: string, tokenAddress: string, recipients: string[], amounts: string[], priorityFeeMultiplier?: number): Promise<string[]>; /** * Distribute native HYPE tokens to multiple recipients in batches of 100 * @param privateKey The sender's private key * @param recipients Array of recipient addresses * @param amounts Array of amounts to send (in human readable format) * @param priorityFeeMultiplier Optional multiplier for the priority fee (scales with batch size) * @returns Array of transaction hashes */ distributeHype(privateKey: string, recipients: string[], amounts: string[], priorityFeeMultiplier?: number): Promise<string[]>; /** * Get the current price of tokenB in terms of tokenA * @param tokenA The base token address * @param tokenB The quote token address * @returns Price information including the price of 1 tokenA in tokenB, and additional details */ getPrice(tokenA: string, tokenB: string): Promise<{ price: string; baseTokenSymbol: string; quoteTokenSymbol: string; baseTokenDecimals: number; quoteTokenDecimals: number; routeInfo: { path: string[]; priceImpact: string; routerNames: string[]; }; }>; /** * Create a buy limit order that executes when the token price falls to the target price * @param privateKey The private key of the wallet executing the trade * @param tokenAddress The address of the token to buy * @param amountIn Amount of HYPE to spend (in human readable format) * @param targetPrice Target price of token in terms of HYPE * @param options Additional options like slippage, check interval, timeout, etc. * @returns Object containing the order ID and a function to cancel the order */ createLimitOrderBuy(privateKey: string, tokenAddress: string, amountIn: string, targetPrice: string, options?: { slippageBps?: number; checkIntervalMs?: number; timeoutMs?: number; priorityFeeMultiplier?: number; }): Promise<{ orderId: string; cancel: () => void; }>; /** * Create a sell limit order that executes when the token price rises to the target price * @param privateKey The private key of the wallet executing the trade * @param tokenAddress The address of the token to sell * @param amountIn Amount of tokens to sell (in human readable format) * @param targetPrice Target price of token in terms of HYPE * @param options Additional options like slippage, check interval, timeout, etc. * @returns Object containing the order ID and a function to cancel the order */ createLimitOrderSell(privateKey: string, tokenAddress: string, amountIn: string, targetPrice: string, options?: { slippageBps?: number; checkIntervalMs?: number; timeoutMs?: number; priorityFeeMultiplier?: number; }): Promise<{ orderId: string; cancel: () => void; }>; /** * Create a limit order that executes when the target price is reached * @param privateKey The private key of the wallet executing the trade * @param tokenIn The input token address * @param tokenOut The output token address * @param amountIn Amount of input tokens (in human readable format) * @param targetPrice Target price of tokenOut in terms of tokenIn * @param orderType 'buy' or 'sell' * @param options Additional options like slippage, check interval, timeout, etc. * @returns Object containing the order ID and a function to cancel the order * @private This method is used internally by createLimitOrderBuy and createLimitOrderSell */ private createLimitOrder; }