Skip to main content

Main SDK Types Reference

TypeScript types for the actual functional Saros Main SDK (@saros-finance/sdk)
This reference provides TypeScript type definitions that match the actual functional API exported by @saros-finance/sdk.
⚠️ API Pattern Reality CheckThe Main SDK uses functional programming patterns, not object-oriented classes. The types below reflect the actual SDK exports, not fictional OOP APIs.Actual Pattern:
import { getSwapAmountSaros, swapSaros } from '@saros-finance/sdk';
// Functional calls with individual parameters
NOT This (fictional OOP):
const sdk = new MainSDK(); // ❌ This class doesn't exist

Core Functional API Types

Swap Functions

getSwapAmountSaros Parameters

type GetSwapAmountSarosParams = [
  connection: Connection,
  fromMint: string,
  toMint: string,
  fromAmount: number,
  slippage: number,
  poolParams: PoolParams
];

interface PoolParams {
  // Pool configuration structure (exact format determined by SDK implementation)
  [key: string]: any;
}

swapSaros Parameters

type SwapSarosParams = [
  connection: Connection,
  wallet: Wallet,
  fromMint: string,
  toMint: string,
  fromAmount: number,
  minAmountOut: number,
  slippage: number
];

Swap Results

interface SwapEstimate {
  amountOut: number;
  priceImpact?: number;
  fee?: number;
}

interface SwapResult {
  signature: string;
  // Additional result data (structure determined by implementation)
  [key: string]: any;
}

Pool and Liquidity Types

getPoolInfo Parameters

type GetPoolInfoParams = [
  connection: Connection,
  poolAddress: string | PublicKey
];

interface PoolInfo {
  // Pool information structure (exact format determined by implementation)
  [key: string]: any;
}

Liquidity Functions

type DepositAllTokenTypesParams = [
  connection: Connection,
  wallet: Wallet,
  poolAddress: any,
  amounts: any
];

type WithdrawAllTokenTypesParams = [
  connection: Connection,
  wallet: Wallet,
  poolAddress: any,
  lpAmount: any
];

interface DepositResult {
  // Deposit result structure
  [key: string]: any;
}

interface WithdrawResult {
  // Withdraw result structure
  [key: string]: any;
}

Farm Service Types

SarosFarmService Methods

interface SarosFarmService {
  stakePool: (
    connection: Connection,
    payerAccount: any,
    farmAddress: PublicKey,
    amount: BN,
    sarosFarmAddress: PublicKey,
    rewardsArray: any[],
    lpTokenAddress: PublicKey
  ) => Promise<any>;
  
  unStakePool: (
    // Parameters similar to stakePool (exact structure TBD)
    ...params: any[]
  ) => Promise<any>;
}

SarosStakeServices

interface SarosStakeServices {
  // Staking service methods (exact structure determined by implementation)
  [key: string]: any;
}

SDK Default Export Types

Main SDK Object

interface SarosSdkDefault {
  SarosFarmService: SarosFarmService;
  SarosStakeServices: SarosStakeServices;
  // Additional service modules
  [key: string]: any;
}

// The default export from the SDK
declare const sarosSdk: SarosSdkDefault;
export default sarosSdk;

Governance Types

⚠️ Governance Not Yet AvailableGovernance functionality is planned but not currently implemented in the Main SDK (v2.4.0). Type definitions will be added when the module is released.Current Status:
  • ❌ No governance types available
  • ⏳ Planned for future releases
  • ✅ Staking available through SarosStakeServices

Utility Types

Solana Web3.js Types

The SDK relies on standard Solana Web3.js types:
import { Connection, PublicKey, Transaction, Wallet } from '@solana/web3.js';
import BN from 'bn.js';

interface Wallet {
  publicKey: PublicKey;
  signTransaction(transaction: Transaction): Promise<Transaction>;
  signAllTransactions?(transactions: Transaction[]): Promise<Transaction[]>;
}

Token Information

interface TokenInfo {
  mint: string;
  symbol: string;
  name: string;
  decimals: number;
  logoUri?: string;
}

Complete Import Pattern

Actual SDK Imports

// Default import for services
import sarosSdk from '@saros-finance/sdk';

// Named imports for functions
import { 
  getSwapAmountSaros,
  swapSaros,
  getPoolInfo,
  depositAllTokenTypes,
  withdrawAllTokenTypes
} from '@saros-finance/sdk';

// Solana dependencies
import { Connection, PublicKey } from '@solana/web3.js';
import BN from 'bn.js';

// Access services from default export
const { SarosFarmService, SarosStakeServices } = sarosSdk;

// Use functional API
const connection = new Connection('https://api.devnet.solana.com');
const quote = await getSwapAmountSaros(connection, fromMint, toMint, amount, slippage, poolParams);

Type Usage Examples

Swap Operation Types

import type { SwapEstimate, SwapResult } from './types';

// Function with typed parameters
async function performSwap(
  connection: Connection,
  wallet: Wallet,
  fromMint: string,
  toMint: string,
  amount: number,
  slippage: number = 0.5
): Promise<SwapResult> {
  // Get quote first
  const estimate: SwapEstimate = await getSwapAmountSaros(
    connection,
    fromMint,
    toMint,
    amount,
    slippage,
    poolParams
  );
  
  // Execute swap
  const result: SwapResult = await swapSaros(
    connection,
    wallet,
    fromMint,
    toMint,
    amount,
    estimate.amountOut,
    slippage
  );
  
  return result;
}

Farm Staking Types

// Typed farm staking
async function stakeFarm(
  connection: Connection,
  payerAccount: any,
  farmAddress: string,
  stakeAmount: number
): Promise<any> {
  const { SarosFarmService } = sarosSdk;
  
  const result = await SarosFarmService.stakePool(
    connection,
    payerAccount,
    new PublicKey(farmAddress),
    new BN(stakeAmount),
    new PublicKey("SFarmWM5wLFNEw1q5ofqL7CrwBMwdcqQgK6oQuoBGZJ"), // SAROS_FARM_ADDRESS
    [], // rewardsArray configuration
    new PublicKey("LPTokenAddress")
  );
  
  return result;
}

Version Information

Current SDK Version: @saros-finance/sdk@2.4.0 TypeScript Support:
  • ✅ Basic type inference from implementation
  • ⚠️ Explicit type definitions limited (functional API)
  • ❌ No official .d.ts files provided yet
Compatible With:
  • TypeScript 4.5.0+
  • Solana Web3.js ^1.31.0
  • @project-serum/anchor ^0.25.0-beta.1

Reference Documentation

Getting Started (Tutorials)

Solve Problems (How-To Guides)