A comprehensive Automated Market Maker (AMM) aggregation and analytics platform for the Stellar/Soroban ecosystem. Lobster integrates with multiple DEX protocols (Phoenix, Soroswap, Aquarius) to provide unified liquidity management, analytics, and automated decision-making.
- Overview
- Architecture
- Repository Structure
- Quick Start
- Components
- Development
- Deployment
- API Documentation
- Contributing
Lobster Protocol is a multi-protocol AMM aggregator that:
- Aggregates Liquidity across Phoenix, Soroswap, and Aquarius DEXs
- Indexes On-Chain Events using SubQuery for real-time data access
- Computes Analytics including prices, volumes, fees, TVL, PnL, APR, and risk metrics
- Automates Decisions for optimal pool selection and liquidity migration
- Provides APIs for accessing processed metrics and triggering analyses
βββββββββββββββββββ
β Stellar/Soroban β
β (Phoenix, β
β Soroswap, β
β Aquarius) β
ββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββ
β Query β β SubQuery Indexer
β (Event Indexing)β
ββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββ
β DataProcess β β Analytics & Metrics
β (Computations) β
ββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββ
β DecisionTaker β β Pool Analysis & Migration
β (Automation) β
βββββββββββββββββββ
Lobster/
βββ SmartContract/ # Soroban smart contracts (Rust)
βββ Query/ # SubQuery indexer (TypeScript)
βββ DataProcess/ # Analytics & metrics computation (TypeScript)
βββ DecisionTaker/ # Pool analysis & migration automation (TypeScript)
βββ core/ # Core Soroswap contracts & utilities
βββ phoenix-contracts/ # Phoenix AMM contracts reference
βββ soroban-amm/ # AMM contracts reference implementation
βββ Bindings/ # TypeScript bindings for contracts
βββ BindingsFac/ # Factory contract bindings
βββ BindingsTokens/ # Token contract bindings
βββ Api/ # API utilities
- Node.js 20+ and npm/yarn
- Rust 1.87.0+ with
wasm32v1-nonetarget - Docker and Docker Compose
- Soroban CLI:
cargo install soroban-cli --locked - SubQuery CLI:
npm install -g @subql/cli
-
Clone the repository
git clone <repository-url> cd Lobster
-
Set up environment variables
# Copy example env files in each component directory cp Query/.env.example Query/.env cp DataProcess/.env.example DataProcess/.env cp DecisionTaker/.env.example DecisionTaker/.env -
Install dependencies
# Query indexer cd Query && npm install && cd .. # Data processing cd DataProcess && npm install && cd .. # Decision automation cd DecisionTaker && npm install && cd ..
-
Generate pool repositories (see Pool Repository section)
Soroban smart contracts for the Lobster protocol, including factory, pool management, and token contracts.
Location: SmartContract/
Key Features:
- Factory contract for pool creation
- Pool management contracts
- Token contracts
- Pool repository generation scripts
Quick Start:
cd SmartContract
make build # Build all contracts
make test # Run testsPool Repository Scripts:
generate_pools_phoenix.sh- Generate Phoenix pool listgenerate_pools_soroswap.sh- Generate Soroswap pool listgenerate_pools_aquarius.sh- Generate Aquarius pool list
See Pool Repository for details.
Documentation: See SmartContract/README.md
SubQuery-based indexer that indexes on-chain events from Phoenix, Soroswap, and Aquarius DEXs.
Location: Query/
Key Features:
- Real-time event indexing from multiple DEX protocols
- GraphQL API for querying indexed data
- Pool repository fallback for missing pool data
- WebSocket support for real-time updates
Quick Start:
cd Query
npm install
npm run dev # Start with Docker (Postgres + indexer + GraphQL)Access:
- GraphQL Playground:
http://localhost:3000 - Health check:
http://localhost:3000/health
Configuration:
- Network settings in
project.ts - Event handlers in
src/mappings/mappingHandlers.ts - Schema in
schema.graphql
Pool Repository Integration:
The indexer uses pool repository files (pool_repertory/*.ts) as fallback when pool data is not found in the database. Set NETWORK=testnet or NETWORK=mainnet to use the correct pool lists.
Documentation: See Query/README.md
Analytics service that computes AMM metrics from SubQuery data and stores results in S3-compatible storage.
Location: DataProcess/
Key Features:
- Fetches swap/pool data from SubQuery
- Computes analytical metrics (prices, volumes, fees, TVL, PnL, APR, Sharpe ratio)
- Stores results as compressed JSON in S3
- REST API for accessing metrics
Quick Start:
cd DataProcess
npm install
npm run api # Start Express API on :8085Or with Docker:
docker compose up -d
# API β http://localhost:8085
# MinIO Console β http://localhost:9001API Endpoints:
GET /health- Health checkPOST /process- Trigger processing for a token pairGET /data- Get full metrics snapshotGET /data/last- Get latest metric values only
Example:
# Process a pair
curl -X POST http://localhost:8085/process \
-H 'content-type: application/json' \
-d '{"token0":"CCWHNL...","token1":"CDF3IU...","protocol":"soroswap"}'
# Get results
curl 'http://localhost:8085/data?token0=...&token1=...&protocol=soroswap'Documentation: See DataProcess/README.md
Automated pool analysis and migration service that compares APRs across pools and can trigger multisig migrations.
Location: DecisionTaker/
Key Features:
- Pool analysis comparing APRs across protocols
- Automated liquidity migration decisions
- Multisig support (single, local, external)
- REST API for triggering analyses
Quick Start:
cd DecisionTaker
cp .env.example .env # Configure your environment
npm install
npm run dev # Start API on :3334API Endpoints:
GET /- StatusGET /health- Health checkGET /api/run/all- Analyze all poolsGET /api/run/user/:address- Analyze user's poolsGET /api/run/pool/:poolId- Analyze specific pool
Multisig Modes:
single- Single signermultisig-local- Local multisig with multiple secretsmultisig-external- External signer APIs
Docker:
# Build
docker build -t decisiontaker-server --target server .
docker build -t decisiontaker-signer --target signer .
# Run
docker run --rm -p 3334:3000 --env-file .env decisiontaker-serverDocumentation: See DecisionTaker/README.md
Generated TypeScript files containing pool addresses and token pairs for Phoenix, Soroswap, and Aquarius protocols.
Location: Query/src/pool_repertory/ and SmartContract/
Files:
phoenix_pools.ts/phoenix_pools_testnet.tssoroswap_pools.ts/soroswap_pools_testnet.tsaquarius_pools.ts/aquarius_pools_testnet.ts
Generation Scripts (in SmartContract/):
-
Phoenix Pools:
cd SmartContract ./generate_pools_phoenix.sh- Configurable via
PHOENIX_FACTORY_ID,NETWORK,SOURCE_ACCOUNT - Outputs:
phoenix_pools.tsorphoenix_pools_testnet.ts
- Configurable via
-
Soroswap Pools:
./generate_pools_soroswap.sh
- Queries factory for pool count
- Fetches each pool address
- Gets
token_0andtoken_1for each pool - Outputs:
soroswap_pools.tsorsoroswap_pools_testnet.ts
-
Aquarius Pools:
./generate_pools_aquarius.sh
- Queries token sets count
- Fetches pools in batches
- Outputs:
aquarius_pools.tsoraquarius_pools_testnet.ts
Usage in Code:
import { phoenixPools } from '../pool_repertory/phoenix_pools';
import { soroswapPools } from '../pool_repertory/soroswap_pools';
import { aquariusPools } from '../pool_repertory/aquarius_pools';
// Find pool by address
const pool = phoenixPools.find(p => p.pool_address === address);
if (pool) {
console.log(`Token A: ${pool.token_a}, Token B: ${pool.token_b}`);
}Network Selection:
Set NETWORK=testnet or NETWORK=mainnet environment variable before running scripts or in your application.
-
Generate Pool Repositories
cd SmartContract NETWORK=testnet ./generate_pools_phoenix.sh NETWORK=testnet ./generate_pools_soroswap.sh NETWORK=testnet ./generate_pools_aquarius.sh -
Start Query Indexer
cd Query NETWORK=testnet npm run dev -
Start Data Processing
cd DataProcess npm run api -
Start Decision Service
cd DecisionTaker npm run dev
# Smart contracts
cd SmartContract
make test
# Query indexer
cd Query
npm test
# Data processing
cd DataProcess
npm test# Smart contracts
cd SmartContract
make build
# TypeScript projects
cd Query && npm run build
cd DataProcess && npm run build
cd DecisionTaker && npm run build-
Configure network and identity:
soroban config network add testnet \ --rpc-url https://soroban-testnet.stellar.org \ --network-passphrase "Test SDF Network ; September 2015" soroban config identity generate lobster-dev -
Deploy contracts:
cd SmartContract make deploy # Or use specific deployment scripts
Deploy to SubQuery hosted service or self-host:
cd Query
npm run build
# Follow SubQuery deployment docsDeploy as Docker containers or Node.js services:
# Build images
docker build -t lobster-dataprocess -f DataProcess/Dockerfile .
docker build -t lobster-decisiontaker -f DecisionTaker/Dockerfile .
# Run with environment variables
docker run --env-file .env lobster-dataprocess
docker run --env-file .env lobster-decisiontakerRecommended baseline VPS sizes for each component. Adjust upward if you expect full-history indexing, heavier analytics workloads, or large traffic spikes.
-
Query (
Query/)
4 vCPU / 8β―GB RAM / 80β―GB SSDsupports the SubQuery indexer, GraphQL API, and Postgres without contention. -
DataProcess (
DataProcess/)
4 vCPU / 8β―GB RAM / 60β―GB SSDprovides enough CPU for analytics batches and room for Docker layers plus cache. -
DecisionTaker (
DecisionTaker/)
2 vCPU / 4β―GB RAM / 40β―GB SSDeasily runs the automation API and multisig signer. -
All-in-one staging stack
8 vCPU / 16β―GB RAM / 150β―GB SSDhosts every service (Query + DataProcess + DecisionTaker + Postgres) comfortably on a single VPS.
Access at http://localhost:3000 (GraphQL Playground)
Example Query:
query {
swapAquariusEntities(first: 5) {
nodes {
id
contract
amount0
amount1
sender
block
timestamp
}
}
}Base URL: http://localhost:8085
GET /health- Health checkPOST /process- Process token pairGET /data?token0=...&token1=...&protocol=...- Get metricsGET /data/last?token0=...&token1=...&protocol=...- Get latest values
Base URL: http://localhost:3334
GET /health- Health checkGET /api/run/all- Analyze all poolsGET /api/run/user/:address- Analyze user poolsGET /api/run/pool/:poolId- Analyze specific pool
Query:
NETWORK-testnetormainnetCHAIN_ID- Network passphraseHORIZON_ENDPOINT- Horizon RPC URLSOROBAN_ENDPOINT- Soroban RPC URL
DataProcess:
PORT- API port (default: 8085)SUBQUERY_URL- SubQuery GraphQL endpointS3_ENDPOINT- S3 endpointS3_ACCESS_KEY- S3 access keyS3_SECRET_KEY- S3 secret keyS3_BUCKET- S3 bucket name
DecisionTaker:
HOST- Bind address (default: 0.0.0.0)PORT- API port (default: 3334)NETWORK-testnetormainnetRPC_URL- Soroban RPC endpointNETWORK_PASSPHRASE- Network passphraseSECRET- Stellar secret keyFACTORY_ID- Factory contract IDMULTISIG_MODE-single,multisig-local, ormultisig-external
SmartContract:
SOURCE_ACCOUNT- Stellar account name (default: alice2)NETWORK-testnetormainnetPHOENIX_FACTORY_ID- Phoenix factory addressSOROSWAP_FACTORY_ID- Soroswap factory addressAQUARIUS_ROUTER_ID- Aquarius router address
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
- Rust: Follow
cargo fmtandcargo clippystandards - TypeScript: Use ESLint and Prettier configurations
- Commits: Use conventional commit messages
See individual component directories for license information.
For issues, questions, or contributions, please open an issue on the repository.