Personal Telegram bot for TibetSwap swaps and automatic DCA on Chia.
Warning
This is experimental, unaudited software that can instruct a wallet to sign and submit real transactions. Use a dedicated low-value wallet, review every configuration value, and expect swaps or DCA runs to lose funds through bugs, market movement, slippage, fees, or external service failures. This project provides no financial advice or guarantee of recovery.
Security reports and contribution requirements are documented in
SECURITY.md and CONTRIBUTING.md.
npm install
Copy-Item .env.example .envFill .env. Sage is the default wallet provider:
TELEGRAM_BOT_TOKEN=...
ALLOWED_TELEGRAM_USER_IDS=123456789
WALLET_PROVIDER=sage
SAGE_RPC_URL=https://127.0.0.1:9257
SAGE_RPC_CERT=C:\Users\<username>\AppData\Roaming\com.rigidnetwork.sage\ssl\wallet.crt
SAGE_RPC_KEY=C:\Users\<username>\AppData\Roaming\com.rigidnetwork.sage\ssl\wallet.key
SAGE_RPC_REJECT_UNAUTHORIZED=trueThe Sage RPC Server must be enabled and running while the bot is in use.
Without it, the bot cannot read wallet balances, create or cancel offers, run
swaps, or execute DCA purchases. The default Sage RPC endpoint is
https://127.0.0.1:9257.
In Sage, enable the RPC Server and its automatic startup option. Keep Sage running and unlocked when using transaction features. Verify that the default RPC port is listening before starting the bot:
Test-NetConnection 127.0.0.1 -Port 9257TcpTestSucceeded must be True. Then start the bot:
npm run devTLS verification is enabled by default. For loopback RPC URLs, the bot pins the
exact wallet certificate configured by SAGE_RPC_CERT or
CHIA_WALLET_RPC_CERT, which supports the wallet's local certificate even when
its hostname does not match 127.0.0.1. For a remote RPC endpoint, provide its
CA certificate through SAGE_RPC_CA or CHIA_WALLET_RPC_CA; normal CA and
hostname verification remains mandatory.
Setting *_REJECT_UNAUTHORIZED=false is allowed only for loopback URLs and
prints a security warning. The bot refuses insecure TLS for remote hosts.
/start
/help
/wallet
/balance
/cats [search]
/pairs [search]
/quote XCH BEPE 0.1
/quote BEPE XCH 0.075
/swap XCH BEPE 0.1
/swap BEPE XCH 0.075
/confirm <id>
/status <id>
/history
/dca_create BEPE 0.001 20m 0.1
/dca_confirm <id>
/dca_list
/dca_status <id>
/dca_pause <id>
/dca_resume <id>
/dca_stop <id>
/dca_history [id]
Swaps execute through TibetSwap. The bot gets a fresh quote, creates a Chia
offer through the configured local wallet, and submits that offer to TibetSwap.
Manual swaps always require a preview and /confirm.
Examples:
/quote XCH BEPE 0.1
/swap XCH BEPE 0.1
/confirm <id from preview>
/quote BEPE XCH 0.075
/swap BEPE XCH 0.075
/confirm <id from preview>
Guardrails include quote expiry, slippage, maximum price impact, maximum XCH trade size, Telegram user allowlisting, and fresh quote validation immediately before execution.
Token symbols and names are accepted only when they resolve to one verified
pair. Ambiguous symbols are rejected. Unverified tokens require the exact full
asset ID shown by /pairs, and every swap/DCA preview displays both the full
asset ID and pair ID before confirmation.
Create and confirm an automatic XCH-to-token schedule:
/dca_create BEPE 0.001 20m 0.1
/dca_confirm <id>
This buys 0.001 XCH of BEPE immediately, then every 20 minutes, until the
0.1 XCH budget is spent. Transaction fees are outside the budget. The final
run uses the remaining budget when it is smaller than the normal run amount.
Intervals accept positive values ending in s, m, h, or d. Missed runs
while the bot is offline are skipped rather than replayed.
Use /dca_pause <id> for a temporary pause, /dca_resume <id> to continue on
the next interval, or /dca_stop <id> to permanently stop future purchases.
An already submitted swap may still complete. Schedules automatically pause
after three consecutive failures or an uncertain restart recovery.
If a wallet offer is created but Tibet submission fails, the bot records the
wallet offer ID, submits a secure cancellation when supported, and pauses the
DCA schedule. Check /status <swap-id> and verify the cancellation in the
wallet before resuming or creating a replacement schedule.
TIBET_API_BASE=https://api.v2.tibetswap.io
REQUEST_TIMEOUT_MS=30000
WALLET_PROVIDER=sage
DEFAULT_SLIPPAGE_BPS=100
MAX_PRICE_IMPACT_BPS=500
QUOTE_TTL_SECONDS=45
DEFAULT_TX_FEE_MOJOS=10000000
MAX_XCH_TRADE_MOJOS=1000000000000
DB_PATH=./bot.sqliteREQUEST_TIMEOUT_MS applies to TibetSwap HTTP calls and Sage/Chia wallet RPC
calls. A timed-out request is aborted; the next command or DCA interval creates
a fresh connection. If timeout happens after wallet offer creation, the bot
uses the secure cancellation and manual-review flow described above.
Important units:
1 XCH = 1_000_000_000_000mojos.- The bot currently assumes
1 CAT = 1000token mojos. 100basis points means1%.
Sage is the default provider. To use Chia Wallet RPC instead:
WALLET_PROVIDER=chia
CHIA_WALLET_RPC_CERT=C:\Users\<username>\.chia\mainnet\config\ssl\wallet\private_wallet.crt
CHIA_WALLET_RPC_KEY=C:\Users\<username>\.chia\mainnet\config\ssl\wallet\private_wallet.key
CHIA_WALLET_RPC_REJECT_UNAUTHORIZED=trueThis project is available under the MIT License. Upstream projects
used as research references are not vendored into this repository; their source
URLs, pinned research commits, and licenses are recorded in
THIRD_PARTY.md.