This project is a Solana Market Maker Bot designed to automate trading strategies on the Solana blockchain using the Jupiter swap protocol.
Solana Market Maker Bot
This project is a Solana Market Maker Bot designed to automate trading strategies on the Solana blockchain using the Jupiter swap protocol. It implements a portfolio rebalancing strategy between SOL and SPL tokens (50/50 by default), automatically executing trades to restore the target balance when price fluctuations create imbalances.
โ ๏ธ No official token. This project has no associated cryptocurrency, coin, or token, and is not affiliated with any pump.fun / memecoin launch. Any coin claiming to represent, fund, or be "official" for this project is a scam โ do not buy it and do not connect your wallet to it. The maintainer will never ask you to sign a transaction or connect a wallet in relation to this repository.
Features
- Automatic Portfolio Rebalancing: Maintains a configurable value balance between token pairs (default 50/50)
- Jupiter Integration: Uses Jupiter Aggregator for optimal swap execution
- Price Tolerance: Rebalances only when the imbalance exceeds a configurable share of the portfolio (default 2%)
- Slippage Protection: Default 0.5% (50 bps) maximum slippage
- Priority Fees: Includes 200,000 lamport priority fees for faster transaction confirmation
- BIP39 Wallet Support: Load keypairs from a file or derive them from a mnemonic
- Robust Transaction Handling: Re-broadcasts transactions until confirmed, with expiry tracking and timeouts
- Fault Tolerance: A failed RPC/API call skips the cycle instead of crashing the bot; Jupiter requests retry with exponential backoff on rate-limits/5xx
- Graceful Shutdown:
SIGINT/SIGTERMstop the bot after the current cycle - Simulation Mode: Test strategies without executing actual trades (
ENABLE_TRADING=false)
Project Structure
.
โโโ package.json
โโโ package-lock.json
โโโ tsconfig.json
โโโ eslint.config.mjs
โโโ .env.example # Template for environment configuration
โโโ .github
โ โโโ workflows/ci.yml # CI: build, lint, test, audit (Node 20 & 22)
โโโ src
โ โโโ api
โ โ โโโ jupiter.ts # Jupiter API client with quote and swap functionality
โ โ โโโ solana.ts # Solana RPC client (@solana/kit) and mint helpers
โ โโโ constants
โ โ โโโ constants.ts # Token mint addresses
โ โโโ main.ts # Entry point and setup
โ โโโ strategies
โ โ โโโ basicMM.ts # Rebalancing market-making strategy implementation
โ โโโ utils
โ โ โโโ convert.ts # Token unit conversion utilities (Decimal-based)
โ โ โโโ transactionSender.ts # Robust transaction submission with retry logic
โ โ โโโ sleep.ts # Asynchronous sleep utility
โ โโโ wallet.ts # Signer loading (@solana/kit) from file or mnemonic
โโโ tests # Vitest unit tests
โโโ basicMM.test.ts
โโโ convert.test.ts
Requirements
- Node.js (version 20.x or later; the
@solana/kitsigner relies on WebCrypto Ed25519) - A funded Solana wallet with SOL and SPL tokens
Setup
- Install Node.js: Ensure that you have Node.js installed on your machine. You can download it from here
- Clone the Repository: Clone the repository to your local machine:
git clone https://github.com/gianlucamazza/solana-mmaker.git
cd solana-mmaker
- Install Dependencies:
npm install
- Environment Variables: Copy
.env.exampleto.envand fill in your values:
cp .env.example .env
Environment Variables
| Variable | Required | Description | | ---------------------------- | -------- | ------------------------------------------------------------------------------ | | SOLANARPCENDPOINT | yes | Solana RPC endpoint URL | | USER_KEYPAIR | no\* | Path to a JSON secret-key file (solana-keygen format) | | SOLANA_MNEMONIC | no\* | BIP39 mnemonic to derive the keypair from | | ENABLE_TRADING | no | true to execute real swaps; anything else runs in simulation mode | | JUPITERAPIBASE_URL | no | Override the Jupiter API base URL (default: https://lite-api.jup.ag/swap/v1) | | MMWAITTIME_MS | no | Milliseconds between rebalance checks (default: 60000) | | MMSLIPPAGEBPS | no | Maximum slippage in basis points (default: 50) | | MMPRICETOLERANCE | no | Portfolio imbalance fraction required to trigger a rebalance (default: 0.02) | | MMREBALANCEPERCENTAGE | no | Target share of total value held in the first token (default: 0.5) | | MMMINIMUMTRADEVALUEUSD | no | Minimum trade value in USD for a rebalance to be executed (default: 1) | | MMPRIORITYFEE_LAMPORTS | no | Priority fee in lamports attached to swaps (default: 200000) | | MMSKIPPREFLIGHT | no | true to skip RPC preflight simulation when sending swaps (default: false) |
\* Keypair resolution order: USERKEYPAIR file โ SOLANAMNEMONIC โ ~/.config/solana/id.json. Set at most one of the two variables.
Running the Bot
To start the market maker bot in development mode:
npm run dev
For production after building:
npm run build
npm start
Testing and Linting
npm test # Vitest unit tests
npm run lint # ESLint over src and tests
Configuration Options
The strategy parameters can be set through the MM_* environment variables above, or programmatically via the MarketMaker constructor:
const marketMaker = new MarketMaker({
waitTime: 60000, // ms between rebalance checks
slippageBps: 50, // max slippage in basis points
priceTolerance: 0.02, // imbalance fraction that triggers a rebalance
rebalancePercentage: 0.5, // target share of value in the first token
minimumTradeValueUsd: 1, // minimum trade value in USD worth executing
});
Customizing Trading Pairs
To change the traded pair:
- Add your token mint addresses to
src/constants/constants.ts - Update the token configuration in the
MarketMakerconstructor (src/strategies/basicMM.ts); SPL token decimals are verified on-chain at startup - Ensure you have balances of both tokens in your wallet
Safety and Security
- Always review the strategy and start with small amounts for testing
- Use a dedicated wallet with only the tokens you intend to trade
- The bot uses priority fees to ensure transactions confirm quickly
- All sensitive information is stored in environment variables; keys and mnemonics are never logged
- Transaction timeout protection prevents hanging on failed transactions
Contribution
Contributions are welcome! Please feel free to fork the repository, make changes, and submit pull requests.
Disclaimer
This project is for educational and experimental purposes only. Use it at your own risk. The authors are not responsible for any financial losses or damages.
There is no official token associated with this project (see the notice at the top).