FORGE Header

Plugins

DeFi Plugin

Access Solana DeFi protocols through a unified interface

Overview

The DeFi Plugin provides seamless integration with major Solana DeFi protocols including Jupiter, Raydium, Orca, and more. Execute swaps, provide liquidity, and manage yield farming positions.

Installation

npm install @solana-agent-kit/plugin-defi

Jupiter Integration

swapJupiter()

Execute token swaps using Jupiter's aggregation engine.

import { swapJupiter } from '@solana-agent-kit/plugin-defi'; const result = await swapJupiter({ inputMint: 'SOL_MINT_ADDRESS', outputMint: 'USDC_MINT_ADDRESS', amount: 1000000000, // 1 SOL slippageBps: 100 // 1% slippage }); console.log(`Swapped to ${result.outputAmount} tokens`);

getJupiterQuote()

Get the best swap quote without executing.

import { getJupiterQuote } from '@solana-agent-kit/plugin-defi'; const quote = await getJupiterQuote({ inputMint: 'SOL_MINT_ADDRESS', outputMint: 'USDC_MINT_ADDRESS', amount: 1000000000 }); console.log(`Expected output: ${quote.outAmount}`); console.log(`Price impact: ${quote.priceImpactPct}%`);

Raydium Integration

addLiquidity()

Add liquidity to a Raydium pool and receive LP tokens.

import { addLiquidity } from '@solana-agent-kit/plugin-defi'; const lpTokens = await addLiquidity({ poolAddress: 'POOL_ADDRESS', tokenAAmount: 1000000, // Amount of token A tokenBAmount: 5000000, // Amount of token B slippage: 100 // 1% slippage tolerance });

removeLiquidity()

Remove liquidity from a pool and get your tokens back.

import { removeLiquidity } from '@solana-agent-kit/plugin-defi'; const tokens = await removeLiquidity({ poolAddress: 'POOL_ADDRESS', lpTokenAmount: 1000000, slippage: 100 });

stakeLPTokens()

Stake LP tokens in a farm to earn additional rewards.

import { stakeLPTokens } from '@solana-agent-kit/plugin-defi'; await stakeLPTokens({ farmAddress: 'FARM_ADDRESS', lpTokenAmount: 1000000 });

Orca Integration

swapOrca()

Execute swaps on Orca's Whirlpools.

import { swapOrca } from '@solana-agent-kit/plugin-defi'; await swapOrca({ inputMint: 'TOKEN_A_MINT', outputMint: 'TOKEN_B_MINT', amount: 1000000, slippage: 100 });

createWhirlpoolPosition()

Create a concentrated liquidity position in an Orca Whirlpool.

import { createWhirlpoolPosition } from '@solana-agent-kit/plugin-defi'; const position = await createWhirlpoolPosition({ whirlpoolAddress: 'WHIRLPOOL_ADDRESS', tickLowerIndex: -1000, tickUpperIndex: 1000, liquidityAmount: 1000000 });

Price Data

getTokenPrice()

Get real-time token prices from various sources.

import { getTokenPrice } from '@solana-agent-kit/plugin-defi'; const price = await getTokenPrice({ tokenMint: 'TOKEN_MINT_ADDRESS', vsToken: 'USDC' // Price in USDC }); console.log(`Current price: $${price}`);

Staking

stakeSOL()

Stake SOL with validators or liquid staking protocols.

import { stakeSOL } from '@solana-agent-kit/plugin-defi'; await stakeSOL({ amount: 10000000000, // 10 SOL validatorVote: 'VALIDATOR_VOTE_ADDRESS' });

liquidStake()

Stake SOL and receive liquid staking tokens (mSOL, stSOL, etc.).

import { liquidStake } from '@solana-agent-kit/plugin-defi'; const mSOL = await liquidStake({ amount: 10000000000, // 10 SOL protocol: 'marinade' // or 'lido' });

Advanced Features

Flash Loans

Execute flash loan arbitrage strategies:

import { executeFlashLoan } from '@solana-agent-kit/plugin-defi'; await executeFlashLoan({ amount: 1000000000, operations: [/* arbitrage operations */] });

Yield Aggregation

Find the best yields across all protocols:

import { getBestYields } from '@solana-agent-kit/plugin-defi'; const yields = await getBestYields({ tokenMint: 'USDC_MINT', minAPY: 5.0 });

Risk Management

  • • Always set appropriate slippage tolerance
  • • Understand impermanent loss before providing liquidity
  • • Check pool TVL and volume before adding liquidity
  • • Monitor your positions regularly
  • • Be cautious with leverage and flash loans
  • • Verify contract addresses before interacting
  • • Start with small amounts to test strategies
  • • Keep emergency SOL for gas fees