Skip to content

d3f4ultt/ProfitMaxi

Repository files navigation

ProfitMaxi

Volume-Sensitive Limit Orders for AMM Liquidity Pools

License: MIT Solana

ProfitMaxi is a novel order type that enables large position exits with minimal price impact by matching sell execution proportionally to incoming buy volume.

πŸš€ Key Innovation

Traditional limit orders execute based on price or time. ProfitMaxi orders execute based on volume.

Traditional Market Sell (50 SOL position):
β”œβ”€β”€ Single transaction
β”œβ”€β”€ Price impact: -25%
└── Loss: 12.5 SOL

ProfitMaxi Exit (50 SOL position, r=1.0):
β”œβ”€β”€ Multiple shards matched to buys
β”œβ”€β”€ Price impact: -1%
└── Loss: 0.5 SOL
└── Savings: 12 SOL (96% reduction)

πŸ“– How It Works

The Delta Ratio (r)

Delta Ratio Behavior Use Case
r = 1.0 (100%) Price neutral Stealth exit, minimal chart impact
r = 0.8 (80%) +6% positive drift Balanced approach
r = 0.5 (50%) +22% positive drift Strong price support
r = 0.3 (30%) +53% positive drift Maximum pump while exiting

Execution Formula

For each qualifying buy of size B:

sell_amount = min(B Γ— r, remaining_order)

Where:

  • B = incoming buy volume
  • r = delta ratio (0.01 to 1.0)
  • remaining = unfilled order size

πŸ—οΈ Architecture

profitmaxi-sol/
β”œβ”€β”€ programs/profitmaxi/     # Anchor smart contract
β”‚   └── src/
β”‚       β”œβ”€β”€ lib.rs           # Program entry point
β”‚       β”œβ”€β”€ state.rs         # Account structures
β”‚       β”œβ”€β”€ instructions/    # Instruction handlers
β”‚       └── utils.rs         # Math utilities
β”œβ”€β”€ sdk/                     # TypeScript SDK
β”‚   └── src/
β”‚       β”œβ”€β”€ client.ts        # Main client
β”‚       β”œβ”€β”€ amm/             # Multi-DEX adapters
β”‚       β”‚   β”œβ”€β”€ raydium.ts   # Raydium V4/CPMM
β”‚       β”‚   β”œβ”€β”€ pumpswap.ts  # PumpSwap (pump.fun)
β”‚       β”‚   β”œβ”€β”€ meteora.ts   # Meteora DLMM
β”‚       β”‚   └── aggregator.ts # Pool discovery & ranking
β”‚       └── types.ts
└── keeper/                  # Keeper service
    └── src/
        └── multi-dex-keeper.ts

πŸ”§ Supported DEXes

ProfitMaxi monitors and executes across multiple AMMs:

Protocol Type Fee Status
Raydium V4 CPMM 0.25% βœ… Supported
Raydium CPMM CPMM 0.25% βœ… Supported
PumpSwap CPMM 1.0% βœ… Supported
Meteora DLMM DLMM Variable βœ… Supported
Orca Whirlpool CLMM Variable πŸ”œ Coming

Primary Pool Selection

For each token, ProfitMaxi automatically selects the primary pool based on:

  1. Liquidity (40% weight) - Higher liquidity = better execution
  2. Age (30% weight) - Older pools = more established
  3. Volume (20% weight) - Higher volume = more active
  4. Fees (10% weight) - Lower fees = better returns

πŸ“¦ Installation

Prerequisites

  • Rust 1.70+
  • Solana CLI 1.17+
  • Anchor 0.29+
  • Node.js 18+

Build

# Clone repository
git clone https://github.com/mezzanine-dao/profitmaxi-sol
cd profitmaxi-sol

# Build Anchor program
anchor build

# Install SDK dependencies
cd sdk && npm install && npm run build

# Install keeper dependencies
cd ../keeper && npm install && npm run build

Deploy

# Deploy to devnet
anchor deploy --provider.cluster devnet

# Deploy to mainnet
anchor deploy --provider.cluster mainnet

🎯 Usage

Create an Order (TypeScript)

import { ProfitMaxiClient } from '@profitmaxi/sdk';
import { Connection, Keypair } from '@solana/web3.js';
import BN from 'bn.js';

const connection = new Connection('https://api.mainnet-beta.solana.com');
const client = new ProfitMaxiClient({ connection });

// Create a volume-sensitive limit order
const tx = await client.createOrder({
  totalSize: new BN(50_000_000_000), // 50 SOL worth
  deltaRatioBps: 8000,               // 80% (r=0.8)
  minThreshold: new BN(100_000_000), // 0.1 SOL minimum buy
  tokenMint: TOKEN_MINT,
  quoteMint: WSOL_MINT,
  ammPool: POOL_ADDRESS,
  ammProgram: RAYDIUM_PROGRAM_ID,
});

Run the Keeper

# Set environment variables
export RPC_ENDPOINT="https://your-rpc-endpoint.com"
export KEEPER_PRIVATE_KEY="[your,keypair,bytes]"
export DRY_RUN="true"  # Set to false for live execution

# Start keeper
cd keeper && npm run start

Keeper Configuration

# .env
RPC_ENDPOINT=https://api.mainnet-beta.solana.com
KEEPER_PRIVATE_KEY=[...]
POLL_INTERVAL=1000
MIN_PROFIT=10000
DRY_RUN=true
MIN_POOL_LIQUIDITY=100000000000
JITO_ENDPOINT=https://mainnet.block-engine.jito.wtf

πŸ“Š Mathematical Foundation

Theorem 1: Price Preservation (r = 1.0)

For delta ratio r = 1.0, the net price impact approaches zero:

Ξ”P/Pβ‚€ = O(Ρ²)

Where Ξ΅ = B/yβ‚€ (trade size / pool depth).

Theorem 2: Positive Drift (r < 1.0)

For r = 1 - Ξ΄ where Ξ΄ > 0:

Ξ”P/Pβ‚€ β‰ˆ (1-r) Γ— B/yβ‚€ > 0

Lower delta ratios create sustained upward price pressure.

Theorem 3: Fill Guarantee

Given Poisson buy arrivals (rate Ξ» > 0, mean size BΜ„ > 0), order fills with probability 1:

E[t_fill] = T / (r Γ— Ξ» Γ— BΜ„_ΞΈ)

πŸ” Security

Audit Status

⚠️ UNAUDITED - This code is in development. Do not use in production without professional audit.

Known Considerations

  • MEV Protection: Use Jito bundles for execution
  • Slippage: Dynamic slippage based on pool depth
  • Oracle Risk: No oracle dependency (uses AMM reserves)

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development

# Run tests
anchor test

# Run SDK tests
cd sdk && npm test

# Lint
npm run lint

πŸ“œ License

MIT License - see LICENSE

πŸ“š Documentation

πŸ™ Acknowledgments


Author: Justin Liverman Twitter: @_d3f4ult Organization: @MezzanineDAO
Contact: d3f4ult@apolloalgo.ai

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors