A Solana program that autonomously manages Raydium CPMM liquidity positions with automatic fee collection and distribution.
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
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
Creates a new position manager with specified team addresses.
pub fn initialize(
ctx: Context<Initialize>,
team_addresses: [Pubkey; 4],
) -> Result<()>
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<()>
Collects fees from the locked position and distributes them to team addresses.
pub fn collect_and_distribute_fees(
ctx: Context<CollectFees>
) -> Result<()>
Reinvests collected fees back into the LP position.
pub fn auto_compound(
ctx: Context<AutoCompound>
) -> Result<()>
- Install dependencies:
yarn install
- Build the program:
anchor build
- Deploy:
anchor deploy
Run the test suite:
anchor test
- Anchor Framework v0.29.0
- Raydium CPMM CPI
- Raydium Locking CPI
-
Time-based Checks
- Minimum 1-minute interval between fee collections
- Prevents excessive gas consumption
-
Safe Math
- All arithmetic operations use checked math
- Prevents overflows and underflows
-
Authority Checks
- Position manager authority required for critical operations
- Team addresses verified on initialization
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,
}
The program includes comprehensive error handling:
pub enum ErrorCode {
InvalidTeamAddress,
InvalidFeeSplit,
CollectionTooSoon,
Overflow,
}
MIT License