Originally published on BotCookery, free build recipes for AI-built trading and prediction-market bots. Written with AI assistance. Every number below is from real read-only runs on Oct 25, 2026, against public wallets and accounts that aren't ours. Nothing was signed or sent, and we never held a funded bot wallet or sent a revoke. Nothing here is financial advice.
Most bot losses that aren't strategy losses are key losses: a private key committed to GitHub, a seed phrase pasted into a chat to "help debug", a forgotten unlimited approval on a wallet that also holds savings. Our Wallet-Key Safety Pack is a prompt you paste into your AI coding tool. It builds four small Python tools, each with unit tests:
-
secret_scan.py: a pre-commit scanner for private keys and seed phrases -
env_guard.py: an env loader that refuses unsafe key files -
kill_switch.py: a one-file kill switch every order path checks first -
wallet_audit.py: a read-only audit of a bot wallet's balance cap, approvals and API wallets, from its public address only
On Oct 25 we pasted the Oct 22 version of the prompt into a clean folder, built it, and pointed the tools at real data: the audit at 40 Polymarket wallets taken from the public trades feed and 60 random accounts from the Hyperliquid leaderboard, and the scanner at our own bot repos and logs.
The tools ran. They also missed real risks and buried the rest in noise. Here's what broke and how the prompt changed.
Bug 1: the audit missed an approval every active wallet had
All 40 wallets had an unlimited pUSD allowance and an outcome-token operator approval for the Neg Risk Adapter. The SDK's approval list leaves that contract out, and Polymarket's contracts page says the CLOB still checks it. Many wallets also still had unlimited USDC.e allowances to the exchanges from before pUSD. The old audit checked neither.
The fix: the approval list is now the union of three labelled sources: sdk (the SDK's list, 7 pUSD spenders and 10 operator approvals as of Oct 2026), docs (the Neg Risk Adapter) and legacy (USDC.e allowances and operator approvals for the two old exchanges). Every address is cross-checked against Polymarket's contracts page, and anything not on it is labelled "not on docs page" instead of skipped.
Bug 2: every working wallet failed
A trading bot needs its approvals. The old audit flagged each one, so all 40 wallets exited 1 with 17 flags. A normal approval looked the same as a leftover one.
The fix: by default, approvals are listed as "live" and the audit exits 0. A new --retiring flag turns every live approval and active API wallet into a FLAG (exit 1). Run that when you shut a bot down, not while it trades.
Bug 3: the revoke advice did nothing for smart wallets
All 40 wallets were smart wallets (Polymarket Deposit, Safe or Proxy). The old audit printed raw approve(spender, 0) calldata, which does nothing if you send it from your key: the approvals belong to the smart wallet.
The fix: the audit calls eth_getCode. For a smart wallet it says to revoke through the wallet's own flow (Polymarket's approve_erc20(..., amount=0) and approve_erc1155_for_all(..., approved=False), or the Safe app). It prints raw calldata only for a plain EOA.
Bug 4: the Hyperliquid cap ignored spot
The audit read only the perp account value. 42 of the 60 accounts held more in spot than in perps. 14 had under $100 in perps but between $129 and $2.05M in spot, so a $100 cap passed all 14.
The fix: total = perp accountValue + spot balances (USDC at $1, other tokens at markPx).
Our first rebuild from the fixed prompt then found three bugs of its own on the live Hyperliquid run:
- Spot prices were zipped against the pair list by position, but the API returns 1,164 price contexts for 347 pairs, in a different order. That priced HYPE at $0.08 instead of $77.06 and valued one account at $2.34 billion. Now contexts are joined by
ctx["coin"] == pair["name"], never by position. - Outcome-token balances (
+36001) have notokenfield and crashed one audit. Now it'sb.get("token"), and unpriced tokens are listed. - That crash exited 1, the same code as a normal flag. Now any RPC or API error exits 2, so a broken audit can't pass for a flagged or a clean one.
Bug 5: the scanner missed most real seed-phrase shapes
It caught a 12-word phrase on one lowercase line. It missed a JSON list, a Python list, a numbered list, Title Case, comma-separated words and one word per line, which is how seeds are usually stored.
The fix: tokenize the whole file into lowercased letter runs and flag 12+ consecutive BIP39 words when only spaces, newlines, commas, quotes, brackets or "1." numbering sit between them. A ":" or "=" breaks the run, so JSON logs full of common words don't trip it.
Bug 6: the scanner drowned in false alarms
It raised 100,331 hits on our Polymarket WebSocket logs, from tx hashes and condition IDs. It also flagged .env.example, API_SECRET=... placeholders, "Secrets:" prose, *_KEY_PATH variables and .pyc files.
The fix: don't flag a 64-hex value when a hash or ID label sits just before it (hash, tx, conditionId, order_id and so on). Assignments need a real literal of 8+ characters, names ending in _path, _file, _dir or _url are skipped, placeholders are skipped, binary files are skipped, and .env.example, .env.sample and .env.template are allowed.
Bug 7: the hook let a staged key through
The pre-commit hook scanned the working copy. In a scratch repo we staged a file with a key, then blanked the file without re-staging. The hook saw a clean file and the key was committed.
The fix: with no arguments, the scanner reads the staged content (git show :<path> for each file from git diff --cached --name-only --diff-filter=ACM). A new install_hook.py writes the hook with the current Python and refuses to overwrite an existing one.
Bug 8: the env guard accepted an empty key
It loaded PRIVATE_KEY= (empty) without complaint, and accepted a key file in a world-writable folder.
The fix: resolve symlinks first, reject a group- or other-writable parent directory, and treat an empty required value as missing.
What the rebuilt version showed
We ran the 40-wallet Polygon audit twice, at 2:53 and 2:57 PM ET, and got identical counts both times. All 40 are smart wallets, and 40 of 40 have the Neg Risk Adapter live. Across the 40 there are 42 unlimited legacy USDC.e allowances and 26 legacy operator approvals, and 23 wallets hold more than $100. By default every wallet exits 0. With --retiring, each shows 8 to 24 flags.
One wallet's output (wallet address removed):
wallet 0x...: smart wallet (Polymarket Deposit, Safe or Proxy) POL 0.0000 pUSD 6,374.39 USDC.e 0.00 FLAG $6,374.39 in stablecoins is above the $100.00 cap: move the excess out checking 24 approvals (17 sdk, 2 docs, 5 legacy) live pUSD allowance -> 0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296 [docs]: UNLIMITED live USDC.e allowance -> 0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E [legacy] (not on docs page): UNLIMITED live CTF operator 0xC5d563A36AE78145C45a50134d48A1215220f80a [legacy] (not on docs page): approved ... 23 live approvals, 1 not set This is a smart wallet: a plain transaction from your key will not touch these approvals. Revoke through the wallet itself: ... The addresses that remain are Polymarket's own contracts: the Neg Risk Adapter, the old CTF Exchange and the old Neg Risk CTF Exchange.
A fresh unfunded address showed "plain EOA", 0 live approvals out of 24 checked, and exit 0.
On Hyperliquid, with --cap 100, 32 of the 60 accounts were flagged and none errored. The 32 include all 14 that had been hiding money in spot. The audit listed 36 API wallets and found none expired. One account (API wallet address removed):
perp account value $0.00 spot $182,128.18 total $182,128.18 FLAG total $182,128.18 is above the $100.00 cap: move the excess out 1 API wallet(s) active 'Astro' 0x... valid until 2026-12-02 UTC The scanner now catches 11 of 11 secret shapes and gives 0 hits on our logs and repos: 69 files and 109,213 lines of WebSocket logs, the Hyperliquid starter, and the site's source. In the scratch repo, the hook blocked a key that was staged but deleted from the working file, and it let .env.example through. The 41 offline tests pass.
How to use it
Nothing in the pack trades, signs or sends. The audit takes a public address and refuses anything shaped like a private key. So it's safe to run on day one, before you build any bot:
- Paste the prompt into your AI coding tool in a new
wallet-guardfolder, then run the tests offline first. - Install the scanner as a pre-commit hook in every bot repo with
install_hook.py, then prove it: stage a throwaway 64-hex string and watch the commit get blocked. - Before you paste text into an AI tool, pipe it through
secret_scan.py --stdin. - Move the bot's key file to
~/.config/<bot>/.env,chmod 600, outside the repo, and load it withenv_guard.load_secrets(...). - Put
kill_switch.check()at the top of every order path. - Practise on a fresh throwaway address with no funds: audit it (expect zero balance and no approvals), turn the kill switch on and confirm your paper bot refuses orders.
When a bot retires, run the audit with --retiring, revoke everything it lists through your own wallet, and move the balance out. The audit prints what to revoke; it never does it for you. Exit 1 means a flag. Exit 2 means the audit couldn't finish, so don't read it as clean.
And the rule the tools can't enforce: never paste a seed phrase or private key into an AI chat, an issue or a screenshot. Your AI coding tool only needs the name of the environment variable your code reads.
What we tested, and what we didn't
The page's verified line, word for word: Verified working on live data in read-only mode, Oct 25, 2026. Audits ran live, read-only, against 40 active Polymarket wallets, 60 Hyperliquid leaderboard accounts and a fresh unfunded address. None of them is ours, and we never held a funded bot wallet or sent a revoke. The scanner and hook ran on our own repos and a scratch repo with throwaway keys.
So: the audit's reads were checked on live data, and the revoke paths were not exercised. Revoking is something you do yourself, in your own wallet.
The full recipe, with the complete prompt, a follow-up prompt for builds made before Oct 25, step-by-step setup, the safety checklist and links to the Polymarket and Hyperliquid docs behind it, is at botcookery.com/recipes/wallet-key-safety-pack.