A Decibel trading frontend for Aptos with live market data, wallet-signed execution, portfolio management, indicator automation, vault workflows, and direct CASH rewards for product usage.
Status: Mainnet deployed | Trading, portfolio, automation, and launchpad flows in active development
- Features
- Quick Start
- Architecture
- Decibel SDK
- Trading Strategies
- API Reference
- Database Setup
- Market Addresses
- Roadmap
- Automated Volume Generation - TWAP orders executing over 5-10 minutes
- Decibel Trading Frontend - Mainnet market selector, live chart, order book, positions, close orders, and account state
- Portfolio Management - Portfolio chart, Decibel positions, open orders, balances, and USDC withdrawal flow
- Multiple Trading Strategies - TWAP, Market Maker, Delta Neutral, High Risk
- Real-time Monitoring - Live balance, order progress, and trade history
- Secure Delegation Model - Bot can trade but never withdraw your funds
- Configurable Parameters - Capital, volume target, bias, speed
- Session Tracking - Each bot run tracked separately with unique session ID
- Multi-Wallet Support - Petra, Martian, Pontem, and 15+ Aptos wallets
- Mobile-Optimized UI - Clean, responsive interface with bottom navigation
- Direct CASH Rewards - Successful bot trade records can trigger live mainnet
$CASHtransfers from a funded rewards treasury
The app rewards confirmed bot trading activity with direct $CASH transfers. This is not an internal points balance: each reward is stored as an idempotent transfer attempt with status, amount, recipient, and Aptos transaction hash.
Mainnet CASH is a legacy Aptos Coin:
0x61ed8b048636516b4eaf4c74250fa4f9440d9c3e163d96aeb863fe658a4bdc67::CASH::CASH
decimals: 6
Required env:
CASH_REWARDS_ENABLED=true
CASH_REWARD_TREASURY_PRIVATE_KEY=ed25519-priv-0x...
CASH_REWARD_CASH_PER_USD_VOLUME=0.01
CASH_REWARD_NETWORK=mainnetSafety env:
CASH_REWARD_MIN_VOLUME_USD=1
CASH_REWARD_MAX_CASH_PER_TRADE=100
CASH_REWARD_DAILY_WALLET_CAP=1000
CASH_REWARD_DAILY_GLOBAL_CAP=100000Reward status API:
GET /api/cash/rewards?userWalletAddress=0x...&userSubaccount=0x...
POST /api/cash/rewards
Authorization: Bearer <CASH_REWARD_ADMIN_SECRET or CRON_SECRET>
- Node.js 18+ and pnpm
- Aptos wallet (Petra, Martian, etc.)
- Testnet APT for gas fees
- Testnet USDC from Decibel Faucet
# Clone the repository
git clone https://github.com/SeamMoney/cash.trading.git
cd cash.trading
# Install dependencies
pnpm install
# Set up environment variables
cp .env.example .env
# Edit .env and add your bot operator private key
# Run development server
pnpm devOpen http://localhost:3000 in your browser.
- Connect Wallet - Click the wallet button and connect your Aptos wallet
- Get USDC - Visit Decibel and mint testnet USDC (1000 USDC/day)
- Delegate Trading - Click "Authorize Bot" to delegate trading permissions
- Configure Bot - Set your capital allocation and trading parameters
- Start Trading - Click "Start Bot" to begin automated volume generation
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Next.js UI │────▶│ API Routes │────▶│ Bot Engine │
│ (Frontend) │ │ /api/bot/* │ │ (lib/) │
└─────────────────┘ └──────────────────┘ └────────┬────────┘
│
┌──────────────────┐ │
│ Neon PostgreSQL │◀─────────────┤
│ (Bot State) │ │
└──────────────────┘ │
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ User Wallet │────▶│ Decibel │◀────│ Aptos Testnet │
│ (Delegation) │ │ Smart Contracts │ │ (On-chain TX) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
| Component | Purpose | Location |
|---|---|---|
| Bot Engine | Core trading logic, builds & submits transactions | lib/bot-engine.ts |
| Decibel Client | Constants, market addresses, fee structures | lib/decibel-client.ts |
| Bot Manager | In-memory bot instance management | lib/bot-manager.ts |
| Wallet Integration | Multi-wallet support, balance fetching | components/wallet/ |
| Trading UI | Bot controls, configuration, status display | components/trading/ |
| API Routes | Bot lifecycle, status, delegation | app/api/bot/ |
| Database | Bot sessions, order history, state persistence | prisma/ |
- User → Connects wallet via Aptos Wallet Adapter
- Frontend → Fetches USDC balance from Decibel subaccount
- User → Delegates trading permissions to bot operator
- Frontend → Starts bot via
/api/bot/start - Bot Engine → Places TWAP orders to Decibel smart contracts
- Database → Tracks bot sessions and order history
- Frontend → Polls
/api/bot/statusfor real-time updates - Vercel Cron → Triggers
/api/cron/bot-tickevery minute for automated trading
Decibel's REST API is read-only - it's used for fetching market data, prices, positions, and order history. All trading operations (placing orders, canceling orders, delegation) must go through on-chain transactions to Decibel's Move smart contracts.
| Component | Purpose |
|---|---|
lib/bot-engine.ts |
Core trading engine - builds & submits transactions |
lib/decibel-client.ts |
Constants, market addresses, fee structures |
lib/bot-manager.ts |
In-memory bot instance management |
app/api/bot/delegate/ |
Delegation transaction generator |
// TWAP orders (time-weighted average price)
dex_accounts::place_twap_order_to_subaccount(
subaccount: address,
market: address,
size: u64,
is_long: bool,
reduce_only: bool,
min_duration_secs: u64,
max_duration_secs: u64,
builder_address: Option<address>,
max_builder_fee: Option<u64>
)
// Market orders (immediate execution)
dex_accounts::place_market_order_to_subaccount(...)
// Limit orders
dex_accounts::place_order_to_subaccount(...)
// Delegation
dex_accounts::delegate_trading_to_for_subaccount(
subaccount: address,
delegate: address,
expiration: u64 // 0 = unlimited
)
// Revoke delegation
dex_accounts::revoke_delegation_for_subaccount(...)The bot uses a delegation model for security:
- [+] Bot CAN: Place orders, execute strategies, generate volume
- [-] Bot CANNOT: Withdraw funds, transfer USDC, close subaccount
- [!] Funds ALWAYS stay in your Decibel subaccount
How it works:
- User connects wallet and delegates trading permissions to bot operator
- Bot operator can trade on behalf of user's subaccount
- User retains full control and can revoke delegation anytime
- Withdrawals require user's signature, not bot's
This app uses Decibel's TypeScript SDK where it is available and direct on-chain Aptos payloads for trading actions that must be signed by the connected wallet. The read paths use Decibel/Aptos market data plus Aptos fullnode views as a fallback, so trading actions do not need to depend on a browser-owned API key.
Key advantages:
- Type-safe API with full TypeScript definitions
- WebSocket subscriptions for real-time updates
- Gas price optimization and fee payer service
- TP/SL (take profit/stop loss) helpers where supported
- Vault operations for copy trading
- Built-in tick size rounding and price formatting
Migration Path: keep replacing local payload builders with official SDK helpers as Decibel exposes stable write helpers. See SDK_COMPARISON_MATRIX.md for detailed comparison.
- Places orders that execute over 5-10 minutes
- Minimizes market impact
- Best for volume generation
- Parameters:
twapFrequencySeconds(30s),twapDurationSeconds(5-10 min)
- Fast TWAP orders (same as TWAP currently)
- Planned: bid/ask spread management
- Places paired long/short limit orders
- Attempts to hedge positions
- Use case: Low-risk volume generation
- Uses larger position sizes (up to 10x multiplier)
- Maximum PNL volatility
- Use case: Aggressive volume generation
| Route | Method | Description |
|---|---|---|
/api/bot/start |
POST | Start a new bot instance |
/api/bot/stop |
POST | Stop a running bot |
/api/bot/status |
GET | Get bot status and order history |
/api/bot/tick |
POST | Execute one trade cycle (manual) |
/api/bot/delegate |
POST | Get delegation transaction payload |
/api/cron/bot-tick |
GET | Vercel Cron endpoint (automated trading) |
Base URL: https://api.netna.aptoslabs.com/decibel/api/v1
| Endpoint | Description |
|---|---|
GET /active_twaps?user={address} |
Active TWAP orders |
GET /positions?user={address} |
User positions |
GET /trades?user={address} |
Trade history |
GET /open_orders?user={address} |
Open orders |
GET /markets |
All available markets |
GET /market_prices |
All market prices |
GET /orderbook?market={symbol} |
Order book depth |
GET /candles?market={symbol}&interval={1m|5m|15m|1h|1d} |
Candlestick data |
Neon offers a generous free tier with serverless PostgreSQL:
# 1. Install Neon CLI
npm install -g neonctl
# 2. Authenticate
neonctl auth
# 3. Create project
neonctl projects create --name cash-trading
# 4. Get connection string
neonctl connection-string
# 5. Add to environment
vercel env add DATABASE_URL production
# Paste the connection string
# 6. Deploy
vercel deploy- Go to https://vercel.com/SeamMoney/cash.trading
- Click "Storage" tab
- Click "Create Database" → "Postgres"
- Check "Connect to project: cash.trading"
- Click "Create & Continue"
Vercel automatically:
- Creates the database
- Sets
DATABASE_URLenvironment variable - Runs migrations on next deployment
-- Bot Sessions
CREATE TABLE BotSession (
id TEXT PRIMARY KEY,
userId TEXT NOT NULL,
subaccount TEXT NOT NULL,
strategy TEXT NOT NULL,
capital REAL NOT NULL,
targetVolume REAL NOT NULL,
status TEXT NOT NULL,
createdAt TIMESTAMP DEFAULT NOW(),
updatedAt TIMESTAMP DEFAULT NOW()
);
-- Order History
CREATE TABLE OrderHistory (
id TEXT PRIMARY KEY,
sessionId TEXT REFERENCES BotSession(id),
orderId TEXT,
market TEXT NOT NULL,
side TEXT NOT NULL,
size REAL NOT NULL,
price REAL,
status TEXT NOT NULL,
createdAt TIMESTAMP DEFAULT NOW()
);# Generate migration
npx prisma migrate dev --name init
# Deploy to production
npx prisma migrate deploy
# Open Prisma Studio (DB GUI)
npx prisma studio| Market | Address | Max Leverage |
|---|---|---|
| BTC/USD | 0xf50add10e6982e3953d9d5bec945506c3ac049c79b375222131704d25251530e |
40x |
| ETH/USD | 0x5d4a373896cc46ce5bd27f795587c1d682e7f57a3de6149d19cc3f3cb6c6800d |
20x |
| SOL/USD | 0xef5eee5ae8ba5726efcd8af6ee89dffe2ca08d20631fff3bafe98d89137a58c4 |
20x |
| APT/USD | 0xfaade75b8302ef13835f40c66ee812c3c0c8218549c42c0aebe24d79c27498d2 |
10x |
| XRP/USD | 0x2b0858711c401b2ff1d22156241127c4500b9cc88aaab1e54aca88f29282a144 |
3x |
| LINK/USD | 0x7eda0461c46e464d7a155f77626be1d268b48f1c7b2e864c5dcf12aa5bf3159a |
3x |
| AAVE/USD | 0x7c6d96f972a4986030ec3012217621f117f6be8a9380ffa29a7941cd62ccd34d |
3x |
| ENA/USD | 0xbc6857d4255c58eb97643a6a3c9aed718322bf677b2556ce09097ab1bb3b47be |
3x |
| HYPE/USD | 0x5f848e543d8a3021e74282fd258ab1919bcfd934d730368fb04398b64cbef9cf |
3x |
Package Address: 0x1f513904b7568445e3c291a6c58cb272db017d8a72aea563d5664666221d5f75
Market addresses can change when Decibel redeploys contracts. To fetch current addresses:
# 1. Query Decibel's perp_engine::Global resource
curl -s "https://aptos.testnet.aptoslabs.com/v1/accounts/0x1f513904b7568445e3c291a6c58cb272db017d8a72aea563d5664666221d5f75/resources" \
| jq '.[] | select(.type | contains("perp_engine::Global")) | .data.market_refs'
# 2. For each market address, get the symbol:
curl -s "https://aptos.testnet.aptoslabs.com/v1/accounts/{MARKET_ADDRESS}/resources" \
| jq '.[] | select(.type | contains("PerpMarketConfig")) | .data.name'The bot operator address is the wallet that will execute trades on behalf of users who delegate permissions:
Bot Operator: 0x501f5aab249607751b53dcb84ed68c95ede4990208bd861c3374a9b8ac1426da
This is a public address (NOT a private key). Users delegate trading permissions to this address so the bot can place orders on their behalf.
Check if the bot operator is delegated for your subaccount:
curl -s "https://aptos.testnet.porto.movementlabs.xyz/v1/accounts/{YOUR_SUBACCOUNT_ADDRESS}/resources" | jq '.[] | select(.type | contains("Subaccount")) | .data.delegated_permissions'If delegated, you'll see the bot operator address in the output with "TradePerpsAllMarkets" permissions.
- Wallet integration & balance fetching
- Multi-wallet support (15+ wallets)
- Delegation system
- TWAP order placement
- Market and reduce-only position close payloads
- Order cancellation payloads
- Multiple trading strategies
- Real-time order monitoring
- SSE stream proxy with polling fallback
- Session-based trade tracking
- Mobile-responsive UI
- Database integration (Neon PostgreSQL)
- Vercel Cron jobs for automation
- PnL tracking and Decibel account overview
- Portfolio chart visualization
- USDC withdraw flow to owner wallet and optional recipient transfer
- Mainnet deployment on
cash.trading
- TP/SL (take profit/stop loss) automation
- Revoke delegation UI
- Dedicated real-time indexer service
- Copy trading and vault management polish
- Mobile trading UX polish
- Multi-market arbitrage
- Advanced bot guardrails UI for indicator-bound strategies
- Some mainnet accounts cannot create Decibel subaccounts unless Decibel allowlists/referrers permit it (
EACCOUNT_WITHOUT_REFERRER_OR_IN_ALLOW_LIST) - Authenticated Decibel/Aptos market streams require server-side API keys in deployment env
| Layer | Technology |
|---|---|
| Frontend | Next.js 16, React 19, TailwindCSS, shadcn/ui |
| Backend | Next.js API Routes, Prisma ORM |
| Database | Neon PostgreSQL (serverless) |
| Blockchain | Aptos TypeScript SDK (@aptos-labs/ts-sdk) |
| DEX | Decibel Protocol (custom SDK) |
| Wallet | Aptos Wallet Adapter (15+ wallets) |
| Hosting | Vercel (with Cron jobs) |
| Package Manager | pnpm |
# Required
BOT_OPERATOR_PRIVATE_KEY=ed25519-priv-0x... # Bot wallet private key
DATABASE_URL=postgresql://... # Neon PostgreSQL connection
# Optional
NEXT_PUBLIC_DECIBEL_PACKAGE=0x1f51... # Decibel contract address
APTOS_NODE_API_KEY=... # For higher rate limitsAll documentation is in the /docs folder:
- OFFICIAL_SDK_REFERENCE.md - Official
@decibel/sdkAPI reference (not yet public) - DECIBEL_SDK.md - Our custom SDK implementation details
- SDK_COMPARISON_MATRIX.md - Feature comparison & migration guide
- SDK_ANALYSIS_SUMMARY.md - Key findings from SDK review
- ARCHITECTURE_DIAGRAMS.md - 14 visual diagrams explaining the system
- COMPREHENSIVE_AUDIT.md - Complete feature inventory & roadmap
- DEVELOPMENT_NOTES.md - Technical deep dive & decisions
- DATABASE_SETUP.md - PostgreSQL/Neon setup guide
- SECURITY.md - Security best practices
Built for the Aptos ecosystem