Skip to main content
This reference provides authoritative documentation for all methods in the Main SDK, covering AMM trading, yield farming, and governance functionality for complete DeFi protocol development.

AMM Trading Methods

getSwapAmountSaros(connection, fromMint, toMint, fromAmount, slippage, poolParams): Promise<SwapEstimate>

Gets a swap quote from AMM pools using the actual Saros SDK functional API. Parameters:
  • connection (Connection) - Solana RPC connection
  • fromMint (string) - Source token mint address
  • toMint (string) - Destination token mint address
  • fromAmount (number) - Input amount in token decimals
  • slippage (number) - Slippage tolerance (0.5 = 0.5%)
  • poolParams (object) - Pool configuration parameters
Returns: Promise<SwapEstimate>
  • amountOut (number) - Expected output amount
  • priceImpact (number) - Price impact percentage (optional)
  • fee (number) - Transaction fees (optional)
Example:
import { getSwapAmountSaros } from '@saros-finance/sdk';

const swapEstimate = await getSwapAmountSaros(
  connection,
  "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
  "So11111111111111111111111111111111111111112",   // SOL
  1000000, // 1 USDC
  0.5,     // 0.5% slippage
  poolParams // Pool configuration object
);

console.log(`Expected output: ${swapEstimate.amountOut} lamports`);

swapSaros(connection, wallet, fromMint, toMint, fromAmount, minAmountOut, slippage): Promise<SwapResult>

Executes a swap transaction using the actual Saros SDK functional API. Parameters:
  • connection (Connection) - Solana RPC connection
  • wallet (Wallet) - User wallet for signing transactions
  • fromMint (string) - Source token mint address
  • toMint (string) - Destination token mint address
  • fromAmount (number) - Input amount in token decimals
  • minAmountOut (number) - Minimum acceptable output amount
  • slippage (number) - Slippage tolerance
Returns: Promise<SwapResult>
  • signature (string) - Transaction signature
  • Additional swap result data
Example:
import { swapSaros } from '@saros-finance/sdk';

const swapResult = await swapSaros(
  connection,
  userWallet,
  "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
  "So11111111111111111111111111111111111111112",   // SOL
  1000000,    // 1 USDC
  45000000,   // Min 0.045 SOL
  0.5         // 0.5% slippage
);

console.log(`Swap completed: ${swapResult.signature}`);

Yield Farming Methods

⚠️ Limited Farm API DocumentationThe Main SDK includes SarosFarmService but detailed method signatures require examining the actual implementation. The examples below show the available methods based on the SDK exports.

SarosFarmService.stakePool(...params): Promise<StakeResult>

Stakes tokens in a yield farming pool using the actual SDK API. Parameters:
  • connection (Connection) - Solana RPC connection
  • payerAccount - Payer account for transaction fees
  • farmAddress (PublicKey) - Farm pool address
  • amount (BN) - Amount to stake as BN
  • sarosFarmAddress (PublicKey) - Saros farm program address
  • rewardsArray (array) - Complex rewards configuration
  • lpTokenAddress (PublicKey) - LP token mint address
Example:
import sarosSdk from '@saros-finance/sdk';
import { PublicKey } from '@solana/web3.js';
import BN from 'bn.js';

const { SarosFarmService } = sarosSdk;

const farmResult = await SarosFarmService.stakePool(
  connection,
  payerAccount,
  new PublicKey("YourFarmAddress"),
  new BN(1000000), // Amount to stake
  new PublicKey("SFarmWM5wLFNEw1q5ofqL7CrwBMwdcqQgK6oQuoBGZJ"), // SAROS_FARM_ADDRESS
  rewardsArray, // Rewards configuration
  new PublicKey("LPTokenAddress")
);

SarosFarmService.unStakePool(...params): Promise<UnstakeResult>

Unstakes tokens from a yield farming pool using the actual SDK API. Parameters:
  • Similar to stakePool but for unstaking operations
  • Exact parameter structure requires examining SDK implementation
Example:
const { SarosFarmService } = sarosSdk;

// Unstaking requires similar parameters to staking
// Exact API structure needs to be determined from SDK source
const unstakeResult = await SarosFarmService.unStakePool(
  connection,
  payerAccount,
  // ... other required parameters
);

Staking Methods

SarosStakeServices Methods

The Main SDK provides staking functionality through the SarosStakeServices module. Example:
import sarosSdk from '@saros-finance/sdk';

const { SarosStakeServices } = sarosSdk;

// Staking services are available but require examining
// the actual SDK implementation for exact method signatures

Governance Methods

⚠️ Governance Module Not Yet AvailableGovernance functionality is planned for future implementation but not currently available in the Saros Main SDK (v2.4.0).Current Status:
  • ❌ Governance voting system not implemented
  • ❌ Proposal creation and management not available
  • ⏳ Planned for future SDK releases
Available Now: Use the staking functionality for token-based rewards while governance features are developed.

Next: See Types Reference for complete type definitions.

getPoolInfo(connection, poolAddress): Promise<PoolInfo>

Retrieves information about an AMM pool using the actual SDK API. Parameters:
  • connection (Connection) - Solana RPC connection
  • poolAddress (string | PublicKey) - AMM pool address to query
Returns: Promise<PoolInfo>
  • Pool information structure (exact format determined by SDK implementation)
Example:
import { getPoolInfo } from '@saros-finance/sdk';

const poolInfo = await getPoolInfo(
  connection,
  "8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6"
);

console.log('Pool information:', poolInfo);

Liquidity Management Methods

depositAllTokenTypes(connection, wallet, poolAddress, amounts): Promise<DepositResult>

Deposits liquidity to an AMM pool. Parameters:
  • connection (Connection) - Solana RPC connection
  • wallet (Wallet) - User wallet
  • poolAddress - Pool address
  • amounts - Token amounts to deposit

withdrawAllTokenTypes(connection, wallet, poolAddress, lpAmount): Promise<WithdrawResult>

Withdraws liquidity from an AMM pool. Parameters:
  • connection (Connection) - Solana RPC connection
  • wallet (Wallet) - User wallet
  • poolAddress - Pool address
  • lpAmount - LP token amount to withdraw
Example:
import { depositAllTokenTypes, withdrawAllTokenTypes } from '@saros-finance/sdk';

// Deposit liquidity
const depositResult = await depositAllTokenTypes(
  connection,
  userWallet,
  poolAddress,
  tokenAmounts
);

// Withdraw liquidity
const withdrawResult = await withdrawAllTokenTypes(
  connection,
  userWallet, 
  poolAddress,
  lpTokenAmount
);

Governance Methods

getGovernanceInfo(): Promise<GovernanceInfo>

Retrieves overall governance system information. Returns: Promise<GovernanceInfo>
  • governanceToken (TokenInfo) - Token used for governance
  • totalSupply (string) - Total governance token supply
  • circulatingSupply (string) - Circulating governance tokens
  • totalStaked (string) - Total tokens staked in governance
  • activeProposals (number) - Number of active proposals
  • votingPower (string) - Total voting power in system
Example:
const govInfo = await mainSdk.getGovernanceInfo();

console.log(`Governance token: ${govInfo.governanceToken.symbol}`);
console.log(`Active proposals: ${govInfo.activeProposals}`);
console.log(`Total voting power: ${govInfo.votingPower}`);

getProposals(params?: GetProposalsParams): Promise<Proposal[]>

Retrieves governance proposals. Parameters:
  • params.status (ProposalStatus, optional) - Filter by proposal status
  • params.limit (number, optional) - Maximum proposals to return
  • params.offset (number, optional) - Pagination offset
Returns: Promise<Proposal[]>
  • Array of governance proposals
Example:
const proposals = await mainSdk.getProposals({
  status: 'active',
  limit: 10
});

proposals.forEach(proposal => {
  console.log(`Proposal: ${proposal.title}`);
  console.log(`Status: ${proposal.status}, Votes: ${proposal.totalVotes}`);
  console.log(`Ends: ${new Date(proposal.endTime * 1000)}`);
});

getProposalDetails(proposalId: string): Promise<ProposalDetails>

Gets detailed information about a specific proposal. Parameters:
  • proposalId (string) - Proposal identifier
Returns: Promise<ProposalDetails>
  • id (string) - Proposal ID
  • title (string) - Proposal title
  • description (string) - Detailed description
  • proposer (string) - Proposer wallet address
  • status (ProposalStatus) - Current status
  • votingOptions (VotingOption[]) - Available voting choices
  • votes (VoteBreakdown) - Current vote tallies
  • startTime (number) - Voting start timestamp
  • endTime (number) - Voting end timestamp
  • executionInfo (ExecutionInfo) - Execution details if passed
Example:
const proposal = await mainSdk.getProposalDetails("prop_12345");

console.log(`Title: ${proposal.title}`);
console.log(`Description: ${proposal.description}`);
console.log(`Current votes - Yes: ${proposal.votes.yes}, No: ${proposal.votes.no}`);

vote(params: VoteParams): Promise<VoteResult>

Casts a vote on a governance proposal. Parameters:
  • params.proposalId (string) - Proposal to vote on
  • params.choice (VoteChoice) - Voting choice (‘yes’, ‘no’, ‘abstain’)
  • params.votingPower (string) - Amount of voting power to use
  • params.wallet (Wallet) - Connected wallet
Returns: Promise<VoteResult>
  • signature (string) - Transaction signature
  • proposalId (string) - Proposal voted on
  • choice (VoteChoice) - Vote cast
  • votingPower (string) - Voting power used
  • totalVotes (VoteBreakdown) - Updated vote tallies
Example:
const result = await mainSdk.vote({
  proposalId: "prop_12345",
  choice: 'yes',
  votingPower: "1000000000", // 1000 tokens worth of voting power
  wallet: connectedWallet
});

console.log(`Voted ${result.choice} on proposal ${result.proposalId}`);
console.log(`Used ${result.votingPower} voting power`);

createProposal(params: CreateProposalParams): Promise<CreateProposalResult>

Creates a new governance proposal. Parameters:
  • params.title (string) - Proposal title
  • params.description (string) - Detailed description
  • params.actions (ProposalAction[]) - Actions to execute if passed
  • params.votingPeriod (number) - Voting duration in hours
  • params.wallet (Wallet) - Connected wallet (must meet requirements)
Returns: Promise<CreateProposalResult>
  • signature (string) - Transaction signature
  • proposalId (string) - Generated proposal ID
  • startTime (number) - Voting start time
  • endTime (number) - Voting end time
Example:
const result = await mainSdk.createProposal({
  title: "Increase Staking Rewards",
  description: "Proposal to increase staking rewards by 2% across all pools",
  actions: [
    {
      target: "StakingController",
      method: "updateRewardRate",
      params: ["0.12"] // 12% APY
    }
  ],
  votingPeriod: 168, // 7 days
  wallet: connectedWallet
});

console.log(`Created proposal ${result.proposalId}`);

delegateVotes(params: DelegateParams): Promise<DelegateResult>

Delegates voting power to another address. Parameters:
  • params.delegate (string) - Address to delegate to
  • params.amount (string) - Amount of tokens to delegate
  • params.wallet (Wallet) - Connected wallet
Returns: Promise<DelegateResult>
  • signature (string) - Transaction signature
  • delegatedAmount (string) - Amount delegated
  • delegate (string) - Delegate address
  • newVotingPower (string) - Remaining voting power
Example:
const result = await mainSdk.delegateVotes({
  delegate: "DelegateWalletAddress...",
  amount: "500000000", // 500 tokens
  wallet: connectedWallet
});

console.log(`Delegated ${result.delegatedAmount} tokens to ${result.delegate}`);

getUserGovernanceInfo(walletAddress: string): Promise<UserGovernanceInfo>

Gets governance information for a specific user. Parameters:
  • walletAddress (string) - User wallet address
Returns: Promise<UserGovernanceInfo>
  • tokenBalance (string) - Governance token balance
  • stakedAmount (string) - Amount staked in governance
  • votingPower (string) - Current voting power
  • delegatedTo (string) - Address votes are delegated to (if any)
  • delegatedFrom (DelegationInfo[]) - Delegations received
  • proposalsVoted (number) - Number of proposals voted on
  • activeVotes (ActiveVote[]) - Current active votes
Example:
const userGov = await mainSdk.getUserGovernanceInfo("UserWalletAddress...");

console.log(`Voting power: ${userGov.votingPower}`);
console.log(`Proposals voted: ${userGov.proposalsVoted}`);
console.log(`Active votes: ${userGov.activeVotes.length}`);

Available SDK Functions Summary

The Main SDK (@saros-finance/sdk) exports the following actual functions:

Core AMM Functions

  • getSwapAmountSaros() - Get swap quotes
  • swapSaros() - Execute swaps
  • getPoolInfo() - Get pool information
  • depositAllTokenTypes() - Add liquidity
  • withdrawAllTokenTypes() - Remove liquidity

Service Modules

  • SarosFarmService.stakePool() - Stake in farms
  • SarosFarmService.unStakePool() - Unstake from farms
  • SarosStakeServices - Staking functionality

API Pattern

The SDK uses functional programming patterns, not object-oriented classes. All functions require a Connection parameter and use individual arguments rather than config objects. Example Integration:
import sarosSdk, { 
  getSwapAmountSaros, 
  swapSaros,
  getPoolInfo,
  depositAllTokenTypes 
} from '@saros-finance/sdk';
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://api.devnet.solana.com');
const { SarosFarmService, SarosStakeServices } = sarosSdk;

// All functions use this functional pattern
const quote = await getSwapAmountSaros(connection, fromMint, toMint, amount, slippage, poolParams);

Reference Documentation

Getting Started (Tutorials)

Solve Problems (How-To Guides)

Understanding Concepts (Explanation)