goodrdotfun-sdk
Version:
SDK for interacting with goodr.fun and Sonic on Solana
386 lines (385 loc) • 15.4 kB
TypeScript
import * as anchor from '@coral-xyz/anchor';
import { IdlAccounts, IdlEvents } from '@coral-xyz/anchor';
import { GoodrFun } from './types/program';
import { PublicKey, Transaction, Keypair } from '@solana/web3.js';
import { BondingCurveAccount, GlobalAccount } from './states';
export declare const GLOBAL_SEED = "global";
export declare const BONDING_CURVE_SEED = "bonding_curve";
export declare const MPL_TOKEN_METADATA_PROGRAM_ID: anchor.web3.PublicKey;
export type GlobalState = IdlAccounts<GoodrFun>['global'];
export type BondingCurveState = IdlAccounts<GoodrFun>['bondingCurve'];
export type BondingCurveV2State = IdlAccounts<GoodrFun>['bondingCurveV2'];
export type CreateEvent = IdlEvents<GoodrFun>['createEvent'];
export type CompleteEvent = IdlEvents<GoodrFun>['completeEvent'];
export type SetParamsEvent = IdlEvents<GoodrFun>['setParamsEvent'];
export type TradeEvent = IdlEvents<GoodrFun>['tradeEvent'];
export declare class GoodrFunProgramBase {
readonly connection: anchor.web3.Connection;
private idl;
constructor(connection: anchor.web3.Connection);
get program(): anchor.Program<anchor.Idl>;
get accounts(): anchor.Program['account'];
/**
* Adds an event listener for the 'createEvent' event.
* @param handler - The function to handle the event.
*/
onCreateEvent(handler: (event: CreateEvent, slot: number, signature: string) => void): number;
/**
* Adds an event listener for the 'completeEvent' event.
* @param handler - The function to handle the event.
*/
onCompleteEvent(handler: (event: CompleteEvent, slot: number, signature: string) => void): number;
/**
* Adds an event listener for the 'tradeEvent' event.
* @param handler - The function to handle the event.
*/
onTradeEvent(handler: (event: TradeEvent, slot: number, signature: string) => void): number;
/**
* Adds an event listener for the 'setParamsEvent' event.
* @param handler - The function to handle the event.
*/
onSetParamsEvent(handler: (event: SetParamsEvent, slot: number, signature: string) => void): number;
/**
* Removes event listeners by their ids.
* @param eventIds - The ids of the event listeners to remove.
*/
removeListeners(eventIds: number[]): void;
/**
* Returns the metadata PDA for a given mint.
* @param mint - The mint to get the metadata PDA for.
* @returns The metadata PDA.
*/
metadataPDA({ mint }: {
mint: PublicKey;
}): PublicKey;
/**
* Returns the global PDA.
* @returns The global PDA.
*/
get globalPDA(): PublicKey;
/**
* Returns the bonding curve PDA for a given mint.
* @param mint - The mint to get the bonding curve PDA for.
* @returns The bonding curve PDA.
*/
bondingCurvePDA({ mint }: {
mint: PublicKey;
}): PublicKey;
/**
* Returns the bonding curve V2 PDA for a given mint (SONIC operations).
* @param mint - The mint to get the bonding curve V2 PDA for.
* @returns The bonding curve V2 PDA.
*/
bondingCurveV2PDA({ mint }: {
mint: PublicKey;
}): PublicKey;
/**
* Helper function to determine token program for a mint.
* @param mint - The mint to check
* @returns The appropriate token program ID
*/
getTokenProgramForMint(mint: PublicKey): Promise<PublicKey>;
/**
* Returns the global state.
* @returns The global state.
*/
getGlobalState(): Promise<GlobalState | null>;
/**
* Returns the global account.
* @returns The global account.
*/
getGlobalAccount(): Promise<GlobalAccount | null>;
/**
* Returns the bonding curve state for a given mint.
* @param mint - The mint to get the bonding curve state for.
* @returns The bonding curve state.
*/
getBondingCurveState({ mint, }: {
mint: PublicKey;
}): Promise<BondingCurveState | null>;
/**
* Returns the bonding curve V2 state for a given mint (SONIC operations).
* @param mint - The mint to get the bonding curve V2 state for.
* @returns The bonding curve V2 state.
*/
getBondingCurveV2State({ mint, }: {
mint: PublicKey;
}): Promise<BondingCurveV2State | null>;
/**
* Returns the bonding curve state for a given mint.
* @param mint - The mint to get the bonding curve state for.
* @returns The bonding curve state.
*/
getBondingCurveAccount({ mint, }: {
mint: PublicKey;
}): Promise<BondingCurveAccount | null>;
/**
* Initializes the global state.
* @param authority - The authority to initialize the global state.
* @returns The transaction.
*/
initialize({ authority, }: {
authority: PublicKey;
}): Promise<Transaction>;
/**
* Sets the parameters for the global state.
* @param authority - The authority to set the parameters.
* @returns The transaction.
*/
setParams({ authority, operatingWallet, initialVirtualTokenReserves, initialVirtualSolReserves, initialRealTokenReserves, tokenTotalSupply, operatingFeeBasisPoints, creatorFeeBasisPoints, }: {
authority: PublicKey;
operatingWallet: PublicKey;
initialVirtualTokenReserves: anchor.BN;
initialVirtualSolReserves: anchor.BN;
initialRealTokenReserves: anchor.BN;
tokenTotalSupply: anchor.BN;
operatingFeeBasisPoints: anchor.BN;
creatorFeeBasisPoints: anchor.BN;
}): Promise<Transaction>;
updateAuthority({ authority, newAuthority, }: {
authority: PublicKey;
newAuthority: PublicKey;
}): Promise<Transaction>;
/**
* Adds donation destinations to the global state.
* @param authority - The authority to add the donation destinations.
* @param donationDestinations - The donation destinations to add.
* @returns The transaction.
*/
addDonationDestinations({ authority, donationDestinations, }: {
authority: PublicKey;
donationDestinations: PublicKey[];
}): Promise<Transaction>;
/**
* Removes donation destinations from the global state.
* @param authority - The authority to remove the donation destinations.
* @param donationDestinations - The donation destinations to remove.
* @returns The transaction.
*/
removeDonationDestinations({ authority, donationDestinations, }: {
authority: PublicKey;
donationDestinations: PublicKey[];
}): Promise<Transaction>;
/**
* Creates a new bonding curve.
* @param user - The user to create the bonding curve.
* @param mint - The mint to create the bonding curve for.
* @param name - The name of the bonding curve.
* @param symbol - The symbol of the bonding curve.
* @param uri - The URI of the bonding curve.
* @param donationDestination - The donation destination for the bonding curve.
* @param donationAmount - The donation amount for the bonding curve.
* @returns The transaction.
*/
create({ user, mint, name, symbol, uri, donationDestination, donationAmount, }: {
user: PublicKey;
mint: Keypair;
name: string;
symbol: string;
uri: string;
donationDestination: PublicKey;
donationAmount: anchor.BN;
}): Promise<Transaction>;
/**
* Creates a new bonding curve with SPL token (SONIC) as base currency.
* @param user - The user to create the bonding curve.
* @param mint - The mint to create the bonding curve for.
* @param sonicMint - The SONIC mint address.
* @param name - The name of the bonding curve.
* @param symbol - The symbol of the bonding curve.
* @param uri - The URI of the bonding curve.
* @param donationDestination - The donation destination for the bonding curve.
* @param donationAmount - The donation amount for the bonding curve.
* @returns The transaction.
*/
createWithSpl({ user, mint, sonicMint, name, symbol, uri, donationDestination, donationAmount, }: {
user: PublicKey;
mint: Keypair;
sonicMint: PublicKey;
name: string;
symbol: string;
uri: string;
donationDestination: PublicKey;
donationAmount: anchor.BN;
}): Promise<Transaction>;
/**
* Buys tokens from the bonding curve by SOL amount.
* @param user - The user to buy the tokens.
* @param mint - The mint to buy the tokens for.
* @param buyAmountSol - The amount of SOL to buy.
* @param slippageBasisPoints - The slippage basic points.
* @returns The transaction.
*/
buyBySolAmount(user: PublicKey, mint: PublicKey, buyAmountSol: BigNumber, slippageBasisPoints?: number): Promise<Transaction>;
/**
* Buys tokens from the bonding curve.
* @param user - The user to buy the tokens.
* @param mint - The mint to buy the tokens for.
* @param amount - The amount of tokens to buy.
* @param maxCostSol - The maximum cost in SOL to buy the tokens.
* @returns The transaction.
*/
buy({ user, mint, amount, maxCostSol, creatorWallet, }: {
user: PublicKey;
mint: PublicKey;
amount: anchor.BN;
maxCostSol: anchor.BN;
creatorWallet: PublicKey;
}): Promise<Transaction>;
/**
* Sells tokens to the bonding curve by token amount.
* @param user - The user to sell the tokens.
* @param mint - The mint to sell the tokens for.
* @param sellTokenAmount - The amount of tokens to sell.
* @param slippageBasisPoints - The slippage basic points.
* @returns The transaction.
*/
sellByTokenAmount(user: PublicKey, mint: PublicKey, sellTokenAmount: BigNumber, slippageBasisPoints?: number): Promise<Transaction>;
/**
* Buys tokens from the bonding curve using SPL token (SONIC).
* @param user - The user to buy the tokens.
* @param mint - The mint to buy the tokens for.
* @param sonicMint - The SONIC mint address.
* @param amount - The amount of tokens to buy.
* @param maxCostSonic - The maximum cost in SONIC to buy the tokens.
* @param creatorWallet - The creator wallet to receive fees.
* @returns The transaction.
*/
buyWithSpl({ user, mint, sonicMint, amount, maxCostSonic, creatorWallet, }: {
user: PublicKey;
mint: PublicKey;
sonicMint: PublicKey;
amount: anchor.BN;
maxCostSonic: anchor.BN;
creatorWallet: PublicKey;
}): Promise<Transaction>;
/**
* Sells tokens to the bonding curve for SPL token (SONIC).
* @param user - The user to sell the tokens.
* @param mint - The mint to sell the tokens for.
* @param sonicMint - The SONIC mint address.
* @param amount - The amount of tokens to sell.
* @param minSonicReceived - The minimum amount of SONIC to receive.
* @param creatorWallet - The creator wallet to receive fees.
* @returns The transaction.
*/
sellWithSpl({ user, mint, sonicMint, amount, minSonicReceived, creatorWallet, }: {
user: PublicKey;
mint: PublicKey;
sonicMint: PublicKey;
amount: anchor.BN;
minSonicReceived: anchor.BN;
creatorWallet: PublicKey;
}): Promise<Transaction>;
/**
* Withdraws tokens from the bonding curve.
* @param user - The user to withdraw the tokens.
* @param mint - The mint to withdraw the tokens for.
* @returns The transaction.
*/
withdraw({ user, mint, }: {
user: PublicKey;
mint: PublicKey;
}): Promise<Transaction>;
/**
* Withdraws tokens and SONIC from a completed bonding curve V2.
* @param user - The user (authority) to withdraw the tokens.
* @param mint - The token mint to withdraw.
* @param sonicMint - The SONIC mint address.
* @returns The transaction.
*/
withdrawSpl({ user, mint, sonicMint, }: {
user: PublicKey;
mint: PublicKey;
sonicMint: PublicKey;
}): Promise<Transaction>;
/**
* Calculates the amount of tokens to buy with improved slippage protection.
* @param mint - The mint to buy the tokens for.
* @param amountSol - The amount of SOL to buy the tokens with.
* @param slippage - The slippage percentage (e.g., 5 = 5%, capped at 20% for safety).
* @returns The amount of tokens to buy and the maximum cost in SOL.
*/
calculateBuyTokenAmount({ mint, amountSol, slippage, }: {
mint: PublicKey;
amountSol: anchor.BN;
slippage: number;
}): Promise<{
amountToken: anchor.BN;
maxCostSol: anchor.BN;
}>;
/**
* Calculates the amount of tokens to sell to the bonding curve.
* @param mint - The mint to sell the tokens for.
* @param amountToken - The amount of tokens to sell.
* @param slippage - The slippage percentage.
* @returns The amount of tokens to sell and the minimum amount of SOL to receive.
*/
calculateSellTokenAmount({ mint, amountToken, slippage, }: {
mint: PublicKey;
amountToken: anchor.BN;
slippage: number;
}): Promise<{
amountToken: anchor.BN;
minSolReceived: anchor.BN;
}>;
getPriceAndMarketcap(mint: PublicKey): Promise<{
price: number;
marketcap: number;
}>;
getBondingCurveProgress(mint: PublicKey): Promise<number>;
getPriceAndMarketcapV2(mint: PublicKey): Promise<{
price: number;
marketcap: number;
}>;
getBondingCurveProgressV2(mint: PublicKey): Promise<number>;
/**
* Calculates the amount of tokens to buy from the bonding curve using SPL token (SONIC).
* @param mint - The mint to buy the tokens for.
* @param sonicMint - The SONIC mint address.
* @param amountSonic - The amount of SONIC to buy the tokens with.
* @param slippage - The slippage percentage.
* @returns The amount of tokens to buy and the maximum cost in SONIC.
*/
calculateBuyTokenAmountWithSpl({ mint, sonicMint: _sonicMint, amountSonic, slippage, }: {
mint: PublicKey;
sonicMint: PublicKey;
amountSonic: anchor.BN;
slippage: number;
}): Promise<{
amountToken: anchor.BN;
maxCostSonic: anchor.BN;
}>;
/**
* Calculates the amount of tokens to sell to the bonding curve for SPL token (SONIC).
* @param mint - The mint to sell the tokens for.
* @param sonicMint - The SONIC mint address.
* @param amountToken - The amount of tokens to sell.
* @param slippage - The slippage percentage.
* @returns The amount of tokens to sell and the minimum amount of SONIC to receive.
*/
calculateSellTokenAmountWithSpl({ mint, sonicMint: _sonicMint, amountToken, slippage, }: {
mint: PublicKey;
sonicMint: PublicKey;
amountToken: anchor.BN;
slippage: number;
}): Promise<{
amountToken: anchor.BN;
minSonicReceived: anchor.BN;
}>;
/**
* Helper method to calculate tokens for given SONIC amount
* @private
*/
private calculateTokensForSonic;
/**
* Helper method to calculate SONIC needed for specific token amount
* @private
*/
private calculateSonicForTokens;
/**
* Helper method to calculate fees
* @private
*/
private calculateFees;
}