goodrdotfun-sdk
Version:
SDK for interacting with goodr.fun and Sonic on Solana
258 lines (257 loc) • 10.9 kB
TypeScript
import { Keypair, PublicKey, Signer, Transaction } from '@solana/web3.js';
import { CreateEvent, TradeEvent, CompleteEvent, SetParamsEvent, TransactionResult, CreateAndBuyParams, BuyParams, SellParams, CreateAndBuyWithSonicParams, BuyWithSonicParams, SellWithSonicParams, PriceData, TokenState, GlobalAccount, BondingCurveAccount, ChainType } from './types';
import * as anchor from '@coral-xyz/anchor';
import { Idl } from '@coral-xyz/anchor';
/**
* SDK for interacting with the GoodrFun program on Solana and Sonic
*/
export declare class GoodrFunSDK {
private chainType;
private program;
/**
* Creates a new instance of GoodrFunSDK
* @param rpcEndpoint - The Solana RPC endpoint URL
*/
constructor(chainType: ChainType, rpcEndpoint: string);
/**
* Gets the program ID
* @returns The program ID
*/
get programId(): PublicKey;
/**
* Calculate buy token amount with slippage for SOL (public method for testing)
* @param params - Calculation parameters
* @returns Token amount and max cost
*/
calculateBuyTokenAmountWithSlippage(params: {
mint: PublicKey;
amountSol: anchor.BN;
slippage: number;
}): Promise<{
amountToken: anchor.BN;
maxCostSol: anchor.BN;
}>;
/**
* Calculate buy token amount with slippage for SONIC (public method for testing)
* @param params - Calculation parameters
* @returns Token amount and max cost
*/
calculateBuyTokenAmountWithSplSlippage(params: {
mint: PublicKey;
sonicMint: PublicKey;
amountSonic: anchor.BN;
slippage: number;
}): Promise<{
amountToken: anchor.BN;
maxCostSonic: anchor.BN;
}>;
/**
* Gets the IDL
* @returns The IDL of the program
*/
get idl(): Idl;
/**
* Gets the global account
* @returns The global account
*/
getGlobalAccount(): Promise<GlobalAccount | null>;
/**
* Gets the bonding curve account
* @returns The bonding curve account
*/
getBondingCurveAccount(mint: PublicKey): Promise<BondingCurveAccount | null>;
/**
* Adds a callback for the Create event
* @param callback - Function to be called when a Create event occurs
* @returns Event listener ID that can be used to remove the listener
*/
addOnCreateEvent(callback: (event: CreateEvent, slot: number, signature: string) => void): number;
/**
* Adds a callback for the Trade event
* @param callback - Function to be called when a Trade event occurs
* @returns Event listener ID that can be used to remove the listener
*/
addOnTradeEvent(callback: (event: TradeEvent, slot: number, signature: string) => void): number;
/**
* Adds a callback for the Complete event
* @param callback - Function to be called when a Complete event occurs
* @returns Event listener ID that can be used to remove the listener
*/
addOnCompleteEvent(callback: (event: CompleteEvent, slot: number, signature: string) => void): number;
/**
* Adds a callback for the SetParams event
* @param callback - Function to be called when a SetParams event occurs
* @returns Event listener ID that can be used to remove the listener
*/
addOnSetParamsEvent(callback: (event: SetParamsEvent, slot: number, signature: string) => void): number;
/**
* Removes one or more event listeners
* @param eventIds - List of event listener IDs to remove
*/
removeEventListener(...eventIds: number[]): void;
/**
* Creates a new token and buys tokens in a single transaction
* @param creator - The keypair of the creator
* @param params - Parameters for creating and buying tokens
* @returns Transaction result containing signature and slot
*/
createAndBuy(creator: Keypair, params: CreateAndBuyParams): Promise<TransactionResult>;
/**
* Creates a transaction for creating a new token and buying tokens
* @param creator - The public key of the creator
* @param params - Parameters for creating and buying tokens
* @returns Transaction object ready to be signed and sent
*/
createAndBuyTx(creator: PublicKey, params: CreateAndBuyParams): Promise<Transaction>;
/**
* Buys tokens for a given amount of SOL
* @param creator - The keypair of the buyer
* @param params - Parameters for buying tokens
* @returns Transaction result containing signature and slot
*/
buy(creator: Keypair, params: BuyParams): Promise<TransactionResult>;
/**
* Creates a transaction for buying tokens
* @param creator - The public key of the buyer
* @param params - Parameters for buying tokens
* @returns Transaction object ready to be signed and sent
*/
buyTx(creator: PublicKey, params: BuyParams): Promise<Transaction>;
/**
* Sells tokens for SOL
* @param creator - The keypair of the seller
* @param params - Parameters for selling tokens
* @returns Transaction result containing signature and slot
*/
sell(creator: Keypair, params: SellParams): Promise<TransactionResult>;
/**
* Creates a transaction for selling tokens
* @param creator - The public key of the seller
* @param params - Parameters for selling tokens
* @returns Transaction object ready to be signed and sent
*/
sellTx(creator: PublicKey, params: SellParams): Promise<Transaction>;
/**
* Creates a new token with SONIC and buys tokens in a single transaction
* @param creator - The keypair of the creator
* @param params - Parameters for creating and buying tokens with SONIC
* @returns Transaction result containing signature and slot
*/
createAndBuyWithSonic(creator: Keypair, params: CreateAndBuyWithSonicParams): Promise<TransactionResult>;
/**
* Creates a transaction for creating a new token with SONIC and buying tokens
* @param creator - The public key of the creator
* @param params - Parameters for creating and buying tokens with SONIC
* @returns Transaction object ready to be signed and sent
*/
createAndBuyWithSonicTx(creator: PublicKey, params: CreateAndBuyWithSonicParams): Promise<Transaction>;
/**
* Buys tokens for a given amount of SONIC
* @param creator - The keypair of the buyer
* @param params - Parameters for buying tokens with SONIC
* @returns Transaction result containing signature and slot
*/
buyWithSonic(creator: Keypair, params: BuyWithSonicParams): Promise<TransactionResult>;
/**
* Creates a transaction for buying tokens with SONIC
* @param creator - The public key of the buyer
* @param params - Parameters for buying tokens with SONIC
* @returns Transaction object ready to be signed and sent
*/
buyWithSonicTx(creator: PublicKey, params: BuyWithSonicParams): Promise<Transaction>;
/**
* Sells tokens for SONIC
* @param creator - The keypair of the seller
* @param params - Parameters for selling tokens for SONIC
* @returns Transaction result containing signature and slot
*/
sellWithSonic(creator: Keypair, params: SellWithSonicParams): Promise<TransactionResult>;
/**
* Creates a transaction for selling tokens for SONIC
* @param creator - The public key of the seller
* @param params - Parameters for selling tokens for SONIC
* @returns Transaction object ready to be signed and sent
*/
sellWithSonicTx(creator: PublicKey, params: SellWithSonicParams): Promise<Transaction>;
withdraw({ authority, mint }: {
authority: Signer;
mint: PublicKey;
}): Promise<string>;
/**
* Withdraws tokens and SONIC from a completed bonding curve V2
* @param authority - The authority (signer) to withdraw the tokens
* @param mint - The token mint address to withdraw
* @param sonicMint - The SONIC token mint address
* @returns Transaction hash of the withdrawal
*/
withdrawSpl({ authority, mint, sonicMint, }: {
authority: Signer;
mint: PublicKey;
sonicMint: PublicKey;
}): Promise<string>;
/**
* Gets the token account balance for a given mint and authority
* @param mint - The token mint address
* @param authority - The authority's public key
* @returns The token balance as a BigNumber
*/
getTokenAccountBalance(mint: PublicKey, authority: PublicKey): Promise<BigNumber>;
/**
* Calculates the amount of tokens that can be bought for a given amount of SOL
* @param params - Parameters containing mint and SOL amount
* @returns Object containing the calculated token amount
*/
calculateBuyTokenAmount({ mint, amountSol, }: {
mint: PublicKey;
amountSol: BigNumber;
}): Promise<{
amountToken: BigNumber;
}>;
/**
* Calculates the amount of SOL that can be received for a given amount of tokens
* @param params - Parameters containing mint and token amount
* @returns Object containing the calculated SOL amount
*/
calculateSellTokenAmount({ mint, amountToken, }: {
mint: PublicKey;
amountToken: BigNumber;
}): Promise<{
amountSol: BigNumber;
}>;
/**
* Calculates the amount of tokens that can be bought for a given amount of SONIC
* @param params - Parameters containing mint, base currency mint and SONIC amount
* @returns Object containing the calculated token amount
*/
calculateBuyTokenAmountWithSonic({ mint, baseCurrencyMint, amountSonic, }: {
mint: PublicKey;
baseCurrencyMint: PublicKey;
amountSonic: BigNumber;
}): Promise<{
amountToken: BigNumber;
}>;
/**
* Calculates the amount of SONIC that can be received for a given amount of tokens
* @param params - Parameters containing mint, base currency mint and token amount
* @returns Object containing the calculated SONIC amount
*/
calculateSellTokenAmountWithSonic({ mint, baseCurrencyMint, amountToken, }: {
mint: PublicKey;
baseCurrencyMint: PublicKey;
amountToken: BigNumber;
}): Promise<{
amountSonic: BigNumber;
}>;
/**
* Gets the current price and market cap data for a token
* @param mint - The token mint address
* @returns Price data including current price and market cap
*/
getPriceAndMarketcapData(mint: PublicKey): Promise<PriceData>;
/**
* Gets the current state of a token including price data and bonding curve progress
* @param mint - The token mint address
* @returns Token state including price data, bonding curve progress, and total supply
*/
getCurrentState(mint: PublicKey): Promise<TokenState>;
}