npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

funsdk

v0.4.1

Published

A strong-typed pumpfun SDK

Downloads

626

Readme

funsdk

A package for interacting with pumpfun fully typed.

[!CAUTION] THIS PACKAGE IS NOT PRODUCTION READY
expect breaking changes in the future

Instalation

npm i funsdk # any package manager should work

How to use

Initiate

import { Fun } from 'funsdk';
import { Connection, clusterApiUrl } from '@solana/web3.js';

const connection = new Connection(clusterApiUrl("mainnet-beta"));
const fun = new Fun(connection);

[!WARNING] RENT EXEMPTION CHECK IS INCLUDED IN THIS FUNCTION
Please ensure that the creator account has enough SOL for rent exemption before executing any transaction.

Get Create Token Instruction

import { Fun, type TokenMeta } from 'funsdk';
import fs from 'fs';
import { Connection, clusterApiUrl, Keypair } from '@solana/web3.js';

// ... previous init code

const creator = Keypair.generate();
const token = Keypair.generate();

const imagePath = fs.readFileSync("./image.jpg", {encoding: "base64"});
const image = new File([imagePath], "image.jpg");

const tokenData: TokenMeta = {
    name: "ABC",
    symbol: "DEF",
    description: "GHI",
    image,
    keypair: token
    // socials if any...
};

/** 
 * If insufficient SOL is provided, the function will throw an error
 * 
 * This will return a TransactionInstruction instance
 * so you can freely assign the instruction to any type
 * of transaction that you like.
 * 
 * ex. Transaction | VersionedTransaction
 * **/
const createInstruct = await fun.compileCreateTokenInstruction({
    creator: creator.publicKey,
    tokenData
});

[!WARNING] RENT EXEMPTION CHECK IS INCLUDED IN THIS FUNCTION
Please ensure that the creator account has enough SOL for rent exemption before executing any transaction.

Get token buy instruction

import { Fun } from 'funsdk';
import fs from 'fs';
import { Connection, clusterApiUrl, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js';

// ... previous init code
// ... previous create code

const buyAmount = Bigint(1 * LAMPORTS_PER_SOL);

/** 
 * If insufficient SOL is provided, the function will throw an error
 * If the token bonding curve account is not found, the function will throw an error
 * 
 * Same return value as before 
 * **/
const buyInstruct = await fun.compileBuyInstruction({
    trader: creator.publicKey,
    token: token.publicKey,
    solAmount: buyAmount
}, true); // set to true if this is the initial token buy, else empty

// If true was passed, function will include createAssociatedTokenAccount along with
// the buy instruction [createATA, buyInstruct]
     
// with type annotation. Same return as above
// fun.compileBuyInstruction<true>({
//     solAmount: BigInt(1 * LAMPORTS_PER_SOL),
//     token: token.publicKey,
//     trader: creator.publicKey
// })

Get token sell instruction

import { Fun } from 'funsdk';
import fs from 'fs';
import { Connection, clusterApiUrl, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js';

// ... previous init code
// ... previous create code

// Preferably build a function that fetches your token balance
// and do some calculations for the sell amount
const sellAmount = 1000000n;

/** 
 * Same return value as before
 * 
 * this will return Error if the token bonding curve account
 * is not found
 *  **/
const sellInstruct = await fun.compileSellInstruction({
    trader: creator.publicKey,
    token: token.publicKey,
    tokenAmount: sellAmount
}, true);

Get token data

const tokenData = await fun.getTokenDataAPI(token.publicKey);

console.log(tokenData);
// name, symbol, description, image_uri, metadata_uri, etc.

Get bonding curve data

const bondingCurveData = await fun.getBondingCurveData(token.publicKey);

console.log(bondingCurveData);
// virtualTokenReserves, virtualSolReserves, realTokenReserves, realSolReserves, tokenTotalSupply, complete

Listen to events

// ... previous init code

const removeListener = fun.listen("createEvent", (event) => {
    console.log(event);
});

// ... some codes

await removeListener();

API

.compileCreateTokenInstruction Use to compile a create token instruction for pumpfun program

  • async
  • Params [object]
    • creator: [PublicKey]
    • tokenMeta: [object]
      • name: [string]
      • symbol: [string]
      • description: [string]
      • image: [File]
      • twitter?: [string]
      • telegram?: [string]
      • website?: [string]

.compileBuyInstruction Use to compile a buy token instruction for pumpfun program

  • async
  • Params [object]
    • solAmount [bigint] - Buy value in sol amount
    • trader [PublicKey] - The assign trader public key
    • token [PublicKey] - The assign token public key
  • isInitial [boolean] - is initial token buy
    • default false

.compileSellInstruction Use to compile a sell token instruction for pumpfun program

  • async
  • Params [object]
    • tokenAmount [bigint] - Sell value in token amount
    • trader [PublicKey] - The assign trader public key
    • token [PublicKey] - The assign token public key

.getTokenDataAPI Use to get token data from pumpfun API

  • async
  • Params [PublicKey] - The assign token public key

.getBondingCurveData Use to get bonding curve data from pumpfun program useful for calculating token price, mcap, etc.

  • async
  • Params [PublicKey] - The assign bonding curve public key

.listen Use to listen to pumpfun events

  • Params [object]
    • event [Events] - Event type
      • createEvent
      • tradeEvent
      • completeEvent
      • setParamsEvent
    • callback [function] - Event callback

Types

interface CreateEvent {
    name: string;
    symbol: string;
    uri: string;
    mint: PublicKey;
    bondingCurve: PublicKey;
    user: PublicKey;
}

interface TradeEvent {
    mint: PublicKey;
    solAmount: BN;
    tokenAmount: BN;
    isBuy: boolean;
    user: PublicKey;
    timestamp: BN;
    virtualSolReserves: BN;
    virtualTokenReserves: BN;
    realSolReserves: BN;
    realTokenReserves: BN;
}

interface CompleteEvent {
    user: PublicKey;
    mint: PublicKey;
    bondingCurve: PublicKey;
    timestamp: BN;
}

interface SetParamsEvent {
    feeRecipient: PublicKey;
    initialVirtualTokenReserves: BN;
    initialVirtualSolReserves: BN;
    initialRealTokenReserves: BN;
    tokenTotalSupply: BN;
    feeBasisPoints: BN;
}

type Events = "createEvent" | "tradeEvent" | "completeEvent" | "setParamsEvent";

interface EventCallback<E extends Events> {
    (event: E extends "createEvent" ? CreateEvent : never): void;
    (event: E extends "tradeEvent" ? TradeEvent : never): void;
    (event: E extends "completeEvent" ? CompleteEvent : never): void;
    (event: E extends "setParamsEvent" ? SetParamsEvent : never): void;
}

interface TokenMetadataResponse {
    metadata: {
        name: string
        symbol: string
        description: string
        image: string
        showName: boolean
        createdOn: string
    }
    metadataUri: string
}

interface TokenMeta {
    keypair: Keypair;
    name: string;
    symbol: string;
    image: File;
    description: string;
    telegram?: string;
    twitter?: string;
    website?: string;
}

interface CreateTokenInstructionParam {
    creator: PublicKey;
    tokenMeta: TokenMeta;
}

interface TradeInstructionParam {
    trader: PublicKey;
    token: PublicKey;
    amount: bigint;
    slippageCut: bigint;
}

interface BuyInstructionParam {
    trader: PublicKey;
    token: PublicKey;
    solAmount: bigint;
}

interface SellInstructionParam {
    trader: PublicKey;
    token: PublicKey;
    tokenAmount: bigint;
};

Author

on1force

License

MIT