Skip to content

paradigm-shifter/raydium-lp-manager

Repository files navigation

Autonomous Position Manager for Raydium CPMM

A Solana program that autonomously manages Raydium CPMM liquidity positions with automatic fee collection and distribution.

Overview

This program provides autonomous management of Raydium CPMM liquidity positions with the following features:

  • Automated LP position creation and locking
  • Continuous fee collection (minimum 1-minute intervals)
  • Automatic fee distribution to team addresses (50% split)
  • Auto-compounding of remaining fees (50% reinvestment)
  • Team-based governance structure

Architecture

graph TD
    subgraph Core[Core System]
        PM[Position Manager]
        LP[Raydium CPMM Pool]
        Fees[Fee Collection]
        Team[Team Distribution]
        Comp[Auto-Compound]
        
        LP -->|Generate| Fees
        Fees -->|50%| Comp
        Fees -->|50%| Team
        Comp -->|Reinvest| LP
    end
    
    subgraph Distribution[Team Distribution]
        Team -->|12.5%| Addr1[Team Member 1]
        Team -->|12.5%| Addr2[Team Member 2]
        Team -->|12.5%| Addr3[Team Member 3]
        Team -->|12.5%| Addr4[Team Member 4]
    end
Loading

Instructions

1. Initialize

Creates a new position manager with specified team addresses.

pub fn initialize(
    ctx: Context<Initialize>,
    team_addresses: [Pubkey; 4],
) -> Result<()>

2. Create Position

Creates and locks an LP position in a Raydium CPMM pool.

pub fn create_position(
    ctx: Context<CreatePosition>,
    amount_a: u64,
    amount_b: u64,
) -> Result<()>

3. Collect and Distribute Fees

Collects fees from the locked position and distributes them to team addresses.

pub fn collect_and_distribute_fees(
    ctx: Context<CollectFees>
) -> Result<()>

4. Auto-compound

Reinvests collected fees back into the LP position.

pub fn auto_compound(
    ctx: Context<AutoCompound>
) -> Result<()>

Setup

  1. Install dependencies:
yarn install
  1. Build the program:
anchor build
  1. Deploy:
anchor deploy

Testing

Run the test suite:

anchor test

Dependencies

  • Anchor Framework v0.29.0
  • Raydium CPMM CPI
  • Raydium Locking CPI

Security Features

  1. Time-based Checks

    • Minimum 1-minute interval between fee collections
    • Prevents excessive gas consumption
  2. Safe Math

    • All arithmetic operations use checked math
    • Prevents overflows and underflows
  3. Authority Checks

    • Position manager authority required for critical operations
    • Team addresses verified on initialization

State Management

The PositionManager account tracks:

pub struct PositionManager {
    pub authority: Pubkey,
    pub team_addresses: [Pubkey; 4],
    pub lp_position: Option<Pubkey>,
    pub last_collection_time: i64,
    pub total_fees_collected: u64,
    pub total_reinvested: u64,
}

Error Handling

The program includes comprehensive error handling:

pub enum ErrorCode {
    InvalidTeamAddress,
    InvalidFeeSplit,
    CollectionTooSoon,
    Overflow,
}

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published