Skip to content

ExpertVagabond/parrot-twap

Repository files navigation

Solana TWAP Bot — Parrot Protocol Revival

Originally built by Parrot Protocol. Revived for the Solana Graveyard Hackathon with modern Jupiter DEX integration.

A time-weighted average price (TWAP) bot for Solana. Execute recurring buy or sell orders on any token pair at configurable intervals — dollar-cost averaging on autopilot.

What Changed (Revival)

The original Parrot TWAP bot was tightly coupled to Raydium AMM v4 and Serum DEX — both of which are now defunct (Serum was sunset after the FTX collapse in 2022). The bot was completely non-functional.

Our revival:

  • Replaced the dead Raydium/Serum swap backend with Jupiter Swap API — the dominant Solana DEX aggregator
  • Supports any Solana token pair (not just PRT), using Jupiter's optimal routing across all DEXes
  • Added well-known token symbol resolution (SOL, USDC, BONK, JUP, etc.) — no need to look up mint addresses
  • Added configurable slippage tolerance
  • Preserved the original architecture: scheduler, balance tracking, stop conditions, auto-transfers

Getting Started

Prerequisites

  • Go 1.17+
  • A Solana wallet with some SOL for fees
  • An RPC endpoint (e.g., from Helius, QuickNode, or the public endpoint)

Setup

Copy .env.example to .env and configure:

cp .env.example .env

Set your wallet private key and RPC endpoints:

RPCURL=https://api.mainnet-beta.solana.com
RPCWS=wss://api.mainnet-beta.solana.com
WALLETPK=your_base58_private_key

Usage

Buy USDC with 0.1 SOL every 5 minutes:

go run cmd/cli.go --pair SOL:USDC --amount 0.1 --interval 5m --side buy

Sell 1M BONK for SOL every hour:

go run cmd/cli.go --pair BONK:SOL --amount 1000000 --interval 1h --side sell --fromDecimals 5 --toDecimals 9

DCA into JUP with stop condition:

go run cmd/cli.go --pair SOL:JUP --amount 0.05 --interval 30m --side buy --stopAmount 1000

Use raw mint addresses:

go run cmd/cli.go --pair So11111111111111111111111111111111111111112:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v --amount 0.1 --interval 10m

Supported Token Symbols

Built-in symbol resolution for: SOL, USDC, USDT, BONK, JUP, RAY, ORCA, MSOL, JITOSOL, WIF, PYTH

Any other token can be specified by its mint address.

Options

Flag Description Default
--pair Token pair (e.g. SOL:USDC) required
--amount Amount per swap required
--interval Time between swaps (30s, 5m, 1h) required
--side buy or sell buy
--slippage Slippage in basis points 200 (2%)
--stopAmount Stop when to-token balance reaches this unlimited
--transferAddress Auto-transfer to-token to this address
--transferThreshold Transfer when balance exceeds this
--fromDecimals Decimals for the from-token 9
--toDecimals Decimals for the to-token 6

Stop Conditions

Specify --stopAmount to halt the bot when the target token balance reaches a threshold:

go run cmd/cli.go --pair SOL:USDC --amount 0.01 --interval 30s --stopAmount 100

Auto-Transfer

When the balance exceeds --transferThreshold, automatically transfer all accumulated tokens to --transferAddress:

go run cmd/cli.go --pair SOL:USDC --amount 0.5 --interval 10m --transferThreshold 500 --transferAddress YOUR_WALLET_ADDRESS

Production

Build a binary:

make
./build/twap --pair SOL:USDC --amount 0.1 --interval 5m

Or use Docker:

docker-compose build
docker run twap --pair SOL:USDC --amount 0.1 --interval 5m

Cross-compile for Linux:

env GOOS=linux GOARCH=amd64 go build -o ./twap ./cmd/cli.go

Architecture

cmd/cli.go          — CLI entry point, argument parsing, scheduler
swap/swap.go        — Core TWAP logic: balance checks, stop conditions, transfer
swap/jupiter.go     — Jupiter Swap API integration (quote + swap)
swap/raydium.go     — Original Raydium swap (preserved, non-functional)
swap/rpc.go         — Solana RPC helpers, transaction building
config/jupiter.go   — Token symbol resolution, pair parsing
config/tokens.go    — Token metadata (decimals)
config/pools.go     — Original Raydium pool configs (preserved)
price/coingeko.go   — CoinGecko price oracle for price thresholds
store/json.go       — Swap log persistence

Graveyard Hackathon Context

Track: Competing for overall prizes ($15K/$10K/$5K)

Original Protocol: Parrot Protocol — a Solana DeFi protocol that offered PAI stablecoin, staking, and this TWAP bot. The protocol shut down, and this bot became non-functional when Serum DEX was sunset.

Revival: We modernized the TWAP concept by replacing dead infrastructure (Serum + Raydium) with Jupiter — making it a universal DCA tool for any Solana token pair.

License

Apache-2.0 (preserved from original)

About

Solana TWAP/DCA bot revived from Parrot Protocol — now powered by Jupiter. Any token pair, configurable intervals, stop conditions.

- Creating gist parrot-twap-quickstart.md ✓ Created public gist parrot-twap-quickstart.md https://gist.github.com/ExpertVagabond/61ee36b9f910205c34d7c7a1a0a8713d

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages