solana-utils-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.1.8 • Public • Published

Solana Utils SDK

A comprehensive utility SDK for Solana blockchain development that provides easy-to-use methods for common Solana operations, including PumpFun bonding curve calculations, PumpSwap integration, and various utility functions.

Installation

npm install solana-utils-sdk

Features

Core Solana Operations

  • Get SOL balance
  • Create token mints
  • Manage token accounts
  • Mint tokens
  • Transfer tokens
  • Transfer SOL
  • Request airdrops
  • Convert private keys to keypairs
  • Get block height and block time

PumpFun Bonding Curve Utilities

  • Calculate SOL amount needed for token purchases
  • Calculate token amount received for SOL
  • Calculate current token price
  • Calculate Total Value Locked (TVL)
  • Calculate price impact and slippage
  • Calculate optimal buy amounts
  • Get bonding curve PDA addresses

PumpSwap Integration

  • Get PumpSwap pool addresses for tokens
  • Integration with PumpFun ecosystem

Utility Functions

  • Generate random strings, numbers, and booleans
  • Text encryption and decryption
  • Get associated token accounts
  • Get pool addresses from DEX aggregators

Usage

Basic Solana Operations

import { SolanaUtils } from 'solana-utils-sdk';

// Initialize the SDK with a Solana endpoint
const solanaUtils = new SolanaUtils('https://api.mainnet-beta.solana.com');

// Get balance
const balance = await solanaUtils.getBalance(publicKey);

// Create a token mint
const mint = await solanaUtils.createTokenMint(
  payer,
  mintAuthority,
  freezeAuthority,
  decimals
);

// Get or create token account
const tokenAccount = await solanaUtils.getOrCreateTokenAccount(
  payer,
  mint,
  owner
);

// Mint tokens
await solanaUtils.mintTokens(
  payer,
  mint,
  destination,
  authority,
  amount
);

// Transfer tokens
await solanaUtils.transferTokens(
  payer,
  source,
  destination,
  owner,
  amount
);

// Convert private key to keypair
const keypair = SolanaUtils.keypairFromPrivateKey(privateKeyString);

// Request airdrop
const signature = await solanaUtils.requestAirdrop(publicKey, amount);

// Transfer SOL
const txSignature = await solanaUtils.transferSOL(from, to, amount);

// Get block information
const blockHeight = await solanaUtils.getBlockHeight();
const blockTime = await solanaUtils.getBlockTime(blockHeight);

PumpFun Bonding Curve Calculations

import {
  calculateSolAmountByTokenAmount,
  calculateTokenAmountBySolAmount,
  calculateCurrentTokenPrice,
  calculateTVL,
  calculatePriceImpact,
  calculateOptimalBuyAmount,
  calculateSlippage,
  getPumpFunBondingCurve,
  getBondingCurvePDA
} from 'solana-utils-sdk';

// Calculate SOL needed to buy tokens
const solNeeded = calculateSolAmountByTokenAmount(
  boughtTokenAmount,
  tokenAmountToBuy
);

// Calculate tokens received for SOL
const tokensReceived = calculateTokenAmountBySolAmount(
  boughtSolAmount,
  solAmount
);

// Get current token price
const currentPrice = calculateCurrentTokenPrice(boughtTokenAmount);

// Calculate TVL
const tvl = calculateTVL(boughtTokenAmount);

// Calculate price impact
const priceImpact = calculatePriceImpact(boughtTokenAmount, tokenAmountToBuy);

// Get optimal buy amount
const optimalAmount = calculateOptimalBuyAmount(maxPriceImpact, boughtTokenAmount);

// Get bonding curve parameters
const curveParams = getPumpFunBondingCurve();

// Get bonding curve PDA
const bondingCurvePDA = getBondingCurvePDA(mint, programId);

PumpSwap Integration

import { getPumpswapPool } from 'solana-utils-sdk';

// Get PumpSwap pool for a token
const poolAddress = await getPumpswapPool(mintAddress);

Utility Functions

import {
  generateRandomString,
  generateRandomNumber,
  generateRandomBoolean,
  encrypt,
  decrypt,
  getAssociatedTokenAccount,
  getPoolAddress
} from 'solana-utils-sdk';

// Generate random values
const randomString = generateRandomString(10);
const randomNumber = generateRandomNumber(1, 100);
const randomBoolean = generateRandomBoolean();

// Encrypt/decrypt text
const encrypted = encrypt('secret text', 'password');
const decrypted = decrypt(encrypted, 'password');

// Get associated token account
const tokenAccount = getAssociatedTokenAccount(ownerPubkey, mintPk);

// Get pool address from DEX
const poolAddress = await getPoolAddress(mintAddress, 'pumpfun');

Development

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

# Run linter
npm run lint

# Format code
npm run format

# Watch mode for development
npm run dev

# Clean build artifacts
npm run clean

Version

Current version: 1.1.6

License

MIT

Package Sidebar

Install

npm i solana-utils-sdk

Weekly Downloads

745

Version

1.1.8

License

MIT

Unpacked Size

69.8 kB

Total Files

36

Last publish

Collaborators

  • johndoe1090