@nosana/kit
Version:
Nosana KIT
81 lines (80 loc) • 4.79 kB
TypeScript
import { createSolanaRpc, createSolanaRpcSubscriptions, Address, Signature, Instruction, TransactionMessageWithBlockhashLifetime, sendAndConfirmTransactionFactory, TransactionMessageWithFeePayer, TransactionMessage, SendableTransaction, Transaction, BaseTransactionMessage, TransactionSigner, TransactionWithBlockhashLifetime } from '@solana/kit';
import { estimateComputeUnitLimitFactory } from '@solana-program/compute-budget';
import { getCreateAssociatedTokenIdempotentInstructionAsync } from '@solana-program/token';
import { getTransferSolInstruction } from '@solana-program/system';
import { Logger } from '../../logger/Logger.js';
import { Wallet } from '../../types.js';
import { SolanaConfig } from '../../config/types.js';
/**
* Factory function to create an estimateAndSetComputeUnitLimit function
* that estimates compute units and adds the set compute unit limit instruction
*/
declare function estimateAndSetComputeUnitLimitFactory(...params: Parameters<typeof estimateComputeUnitLimitFactory>): <T extends BaseTransactionMessage & TransactionMessageWithFeePayer>(transactionMessage: T) => Promise<Omit<import("@solana/transaction-messages").ExcludeTransactionMessageWithinSizeLimit<T>, "instructions"> & {
readonly instructions: readonly [...T["instructions"], import("@solana-program/compute-budget").SetComputeUnitLimitInstruction<Address, []>];
}>;
/**
* Dependencies for SolanaService
*/
export interface SolanaServiceDeps {
logger: Logger;
getWallet: () => Wallet | undefined;
}
/**
* Solana service interface
*/
export interface SolanaService {
readonly config: SolanaConfig;
readonly rpc: ReturnType<typeof createSolanaRpc>;
readonly rpcSubscriptions: ReturnType<typeof createSolanaRpcSubscriptions>;
readonly sendAndConfirmTransaction: ReturnType<typeof sendAndConfirmTransactionFactory>;
readonly estimateAndSetComputeUnitLimit: ReturnType<typeof estimateAndSetComputeUnitLimitFactory>;
/**
* Optional fee payer for transactions. If set, will be used as fallback when no feePayer is provided in options.
* Set this property directly to configure the fee payer.
*/
feePayer: TransactionSigner | undefined;
pda(seeds: Array<Address | string>, programId: Address): Promise<Address>;
getBalance(addressStr?: string | Address): Promise<bigint>;
buildTransaction(instructions: Instruction | Instruction[], options?: {
feePayer?: TransactionSigner;
}): Promise<TransactionMessage & TransactionMessageWithFeePayer & TransactionMessageWithBlockhashLifetime>;
signTransaction(transactionMessage: TransactionMessage & TransactionMessageWithFeePayer & TransactionMessageWithBlockhashLifetime): Promise<SendableTransaction & Transaction & TransactionWithBlockhashLifetime>;
sendTransaction(transaction: SendableTransaction & Transaction & TransactionWithBlockhashLifetime, options?: {
commitment?: 'processed' | 'confirmed' | 'finalized';
}): Promise<Signature>;
buildSignAndSend(instructions: Instruction | Instruction[], options?: {
feePayer?: TransactionSigner;
commitment?: 'processed' | 'confirmed' | 'finalized';
}): Promise<Signature>;
/**
* Get an instruction to transfer SOL from one address to another.
*
* @param params Transfer parameters
* @param params.to Recipient address
* @param params.amount Amount in lamports (number or bigint)
* @param params.from Optional sender TransactionSigner. If not provided, uses wallet from client.
* @returns An instruction to transfer SOL
*/
transfer(params: {
to: Address | string;
amount: number | bigint;
from?: TransactionSigner;
}): Promise<ReturnType<typeof getTransferSolInstruction>>;
/**
* Get an instruction to create an associated token account if it doesn't exist.
* Checks if the ATA exists, and if not, returns an instruction to create it.
* Uses the idempotent version so it's safe to call even if the account already exists.
*
* @param ata The associated token account address
* @param mint The token mint address
* @param owner The owner of the associated token account
* @param payer Optional payer for the account creation. If not provided, uses the wallet or service feePayer.
* @returns An instruction to create the ATA if it doesn't exist, or null if it already exists
*/
getCreateATAInstructionIfNeeded(ata: Address, mint: Address, owner: Address, payer?: TransactionSigner): Promise<Awaited<ReturnType<typeof getCreateAssociatedTokenIdempotentInstructionAsync>> | null>;
}
/**
* Creates a Solana service instance.
*/
export declare function createSolanaService(deps: SolanaServiceDeps, config: SolanaConfig): SolanaService;
export {};