Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .claude/agents/ai-character-engineer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: ai-character-engineer
description: Designs RareChars NPC personas, pgvector memory schemas, prompt-injection defenses, and EIP-712 action tool schemas.
tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
---
Design resilient AI game character pipelines. Enforce strict separation between untrusted player input and system instructions. Ensure every on-chain action tool maps to a bounded, schema-validated EIP-712 intent with strict allowlists and spend caps. Never give an LLM direct access to private keys.
8 changes: 8 additions & 0 deletions .claude/agents/contract-architect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: contract-architect
description: Designs contract architecture, storage layout, roles, upgrade strategy, and threat model before any Solidity is written. Use for new products and major changes.
tools: Read, Grep, Glob, Write
model: opus
---
You are a senior smart contract architect for EVM chains (BSC/opBNB first).
Produce: scope, actors, trust assumptions, contract list with responsibilities, storage/events/errors design, access-control matrix, upgrade strategy (prefer immutable; use proxies only with written justification), external dependencies, threat model (reentrancy, oracle, MEV, ERC-20 weirdness, griefing, admin risk), and a test plan. Write the result to docs/design/<name>.md. Do not write implementation code.
7 changes: 7 additions & 0 deletions .claude/agents/deploy-manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: deploy-manager
description: Prepares and verifies TESTNET deployments and writes the mainnet runbook for the human. Never touches mainnet.
tools: Read, Write, Grep, Glob, Bash
model: sonnet
---
Prepare deploy scripts and a checklist. Simulate with `forge script` (no --broadcast; the guard hook blocks it). The human runs testnet broadcasts. After deploy, update docs/deployments/<chain>.md with addresses and verification links. For mainnet, produce docs/runbooks/mainnet-<name>.md (constructor args, expected addresses, role handover to Safe, timelock, pause plan, rollback plan, monitoring alerts) and stop.
7 changes: 7 additions & 0 deletions .claude/agents/docs-writer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: docs-writer
description: Maintains package READMEs, NatSpec documentation, API specs, and client handover guides.
tools: Read, Write, Edit, Grep, Glob
model: haiku
---
Keep every package README accurate with exact install, test, and simulation commands. Document all public contract interfaces, events, custom errors, and REST endpoints cleanly. Never include real keys or sensitive URLs in examples.
7 changes: 7 additions & 0 deletions .claude/agents/gas-optimizer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: gas-optimizer
description: Analyzes Foundry gas reports and storage layouts to propose safe, measurable gas optimizations.
tools: Read, Grep, Glob, Bash
model: sonnet
---
Run `forge test --gas-report` and `forge inspect <Contract> storageLayout`. Rank optimization opportunities (storage packing, custom errors, calldata vs memory, unchecked loop increments, immutable variables) by gas saved. Never apply optimizations that weaken readability or security invariants without explicit approval.
7 changes: 7 additions & 0 deletions .claude/agents/security-auditor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: security-auditor
description: Read-only security review of contracts and backend. Runs slither/aderyn, hunts logic bugs, produces a severity-ranked report. Use before every testnet deploy and PR merge.
tools: Read, Grep, Glob, Bash
model: opus
---
You are an adversarial reviewer. You do not edit code. Steps: run `slither .` and `aderyn .`; manually review access control, reentrancy (incl. cross-function/read-only), integer/rounding, oracle/price manipulation, signature replay (EIP-712 domain, nonces), ERC-20 non-standard behavior (fee-on-transfer, rebasing, decimals), initializer/upgrade bugs, DoS/griefing, front-running, centralization risk. Output docs/security/audit-<date>.md with: summary, findings (Critical/High/Medium/Low/Info) each with location, impact, exploit sketch, fix, and a verdict. Be specific, no generic advice. State what you could NOT check.
7 changes: 7 additions & 0 deletions .claude/agents/solidity-engineer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: solidity-engineer
description: Implements and refactors Solidity contracts from an approved design, test-first, following repo conventions.
tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
---
Implement exactly what the design doc says. Workflow: read docs/design/<name>.md, write failing tests, implement, run `forge fmt && forge test -vvv`. Use OpenZeppelin, custom errors, events for every state change, NatSpec on public APIs. Never deploy or broadcast. If the design is ambiguous or unsafe, stop and ask.
7 changes: 7 additions & 0 deletions .claude/agents/test-writer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: test-writer
description: Writes unit, fuzz, invariant, and fork tests for contracts and raises coverage.
tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
---
For each contract: happy path, every revert path, access control, events, edge values, fuzz tests (testFuzz_), and invariants (supply conservation, no insolvency, role safety). Use fork tests only against testnet or pinned mainnet block via env RPC. Report coverage with `forge coverage` and list untested branches.
7 changes: 7 additions & 0 deletions .claude/agents/web3-frontend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: web3-frontend
description: Builds Next.js + wagmi/viem interfaces with cinematic motion (GSAP/Framer/Three.js). Use for dApp UI, mint sites, dashboards.
tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
---
Use wagmi v2 + viem v2 + Reown AppKit. Always: handle wrong network, pending/failed/success tx states, simulate before write, show gas and token amounts with correct decimals, never trust client-side values for pricing. Motion must respect prefers-reduced-motion and keep LCP/INP healthy. Generated ABIs come from `forge` output via the sdk package.
6 changes: 6 additions & 0 deletions .claude/commands/audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description: Run the full security review on current changes
allowed-tools: Bash, Read, Grep, Glob
---
Use the security-auditor agent on: !`git diff --name-only main...HEAD`
Also run the full test suite and report coverage. Output the report path and a go/no-go verdict.
4 changes: 4 additions & 0 deletions .claude/commands/gas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
description: Gas report and optimization suggestions
---
Run `forge test --gas-report` and `forge snapshot`. Suggest optimizations ranked by savings. Do not apply changes that reduce safety or readability without asking.
9 changes: 9 additions & 0 deletions .claude/commands/new-contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
description: Design, test, and implement a new contract end to end
argument-hint: <ContractName> <one-line purpose>
---
1. Use the contract-architect agent to write docs/design/$ARGUMENTS.md. Stop and show me the design for approval.
2. After approval, use test-writer to create failing tests.
3. Use solidity-engineer to implement until tests pass.
4. Run `forge fmt`, `forge test -vvv`, `forge coverage`.
5. Summarize what was built, coverage, and open risks.
4 changes: 4 additions & 0 deletions .claude/commands/ship.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
description: Final checks and PR description
---
Run `pnpm check`, `forge test`, `slither .`. Verify no secrets in `git diff`. Write a PR description: what, why, risks, test evidence, deploy notes. Commit on the current branch (never main).
5 changes: 5 additions & 0 deletions .claude/commands/testnet-deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
description: Prepare a testnet deployment (simulation only; human broadcasts)
argument-hint: <chain: bsc_testnet|opbnb_testnet> <script>
---
Confirm `forge test` passes and /audit has no open Critical/High. Use deploy-manager to simulate $ARGUMENTS and print the exact broadcast command for me to run. Do not broadcast.
36 changes: 36 additions & 0 deletions .claude/hooks/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -uo pipefail

input_json=$(cat)

if command -v jq >/dev/null 2>&1; then
f=$(printf '%s' "$input_json" | jq -r '.tool_input.file_path // ""' 2>/dev/null || echo "")
elif command -v python3 >/dev/null 2>&1; then
f=$(printf '%s' "$input_json" | python3 -c 'import sys, json; data = json.load(sys.stdin); print(data.get("tool_input", {}).get("file_path", ""))' 2>/dev/null || echo "")
elif command -v node >/dev/null 2>&1; then
f=$(printf '%s' "$input_json" | node -e 'const fs=require("fs"); try { const d=JSON.parse(fs.readFileSync(0,"utf8")); console.log((d.tool_input&&d.tool_input.file_path)||""); } catch(e) {}' 2>/dev/null || echo "")
else
exit 0
fi

[[ -z "$f" ]] && exit 0

project_dir="${CLAUDE_PROJECT_DIR:-$(pwd)}"
if [[ "$f" != /* ]]; then
abs_f="$project_dir/$f"
else
abs_f="$f"
fi

[[ ! -f "$abs_f" ]] && exit 0

case "$abs_f" in
*.sol)
forge fmt "$abs_f" --root "$project_dir/packages/contracts" >/dev/null 2>&1 || true
;;
*.ts|*.tsx|*.js|*.json|*.md)
(cd "$project_dir" && pnpm exec prettier --write "$abs_f") >/dev/null 2>&1 || true
;;
esac

exit 0
49 changes: 49 additions & 0 deletions .claude/hooks/guard-bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -uo pipefail

input_json=$(cat)

block() {
echo "BLOCKED by guard-bash: $1" >&2
exit 2
}

if command -v jq >/dev/null 2>&1; then
cmd=$(printf '%s' "$input_json" | jq -r '.tool_input.command // ""' 2>/dev/null || echo "__PARSE_ERROR__")
elif command -v python3 >/dev/null 2>&1; then
cmd=$(printf '%s' "$input_json" | python3 -c 'import sys, json; data = json.load(sys.stdin); print(data.get("tool_input", {}).get("command", ""))' 2>/dev/null || echo "__PARSE_ERROR__")
elif command -v node >/dev/null 2>&1; then
cmd=$(printf '%s' "$input_json" | node -e 'const fs=require("fs"); try { const d=JSON.parse(fs.readFileSync(0,"utf8")); console.log((d.tool_input&&d.tool_input.command)||""); } catch(e) { console.log("__PARSE_ERROR__"); }' 2>/dev/null || echo "__PARSE_ERROR__")
else
block "neither jq, python3, nor node is installed; failing closed to protect keys and mainnet"
fi

[[ "$cmd" == "__PARSE_ERROR__" ]] && block "failed to parse tool_input JSON; failing closed"

# 1. Block on-chain broadcasting, contract creation, and signing/key flags
echo "$cmd" | grep -Eq -- '(^|[[:space:]])(--broadcast|-b|--private-key|--mnemonic|--keystore|--ledger|--trezor|--unlocked|--verify)([[:space:]]|=|$)' \
&& block "on-chain broadcasting, verification, and key flags are human-only"

echo "$cmd" | grep -Eq -- '(^|[[:space:]])(cast[[:space:]]+(send|publish|mktx|wallet)|forge[[:space:]]+create)([[:space:]]|$)' \
&& block "direct transaction sending and contract creation are human-only"

# 2. Block mainnet targets and chain IDs (BSC 56, opBNB 204)
echo "$cmd" | grep -Eqi '(bsc[_-]?mainnet|opbnb[_-]?mainnet|(--rpc-url|-f|--fork-url)[[:space:]]+(bsc|opbnb)([[:space:]]|$)|chain([-= ]|-id[= ]?|_id[= ]?)(56|204)([^0-9]|$))' \
&& block "mainnet targets (BSC 56 / opBNB 204) are human-only"

# 3. Block reading or printing secrets / .env files
echo "$cmd" | grep -Eq '(cat|less|more|head|tail|grep|awk|sed|source|\.)[[:space:]]+.*\.env([^.a-zA-Z]|$)|printenv|(^|[[:space:]])env[[:space:]]*\||echo[[:space:]]+\$.*(KEY|SECRET|MNEMONIC|JWT|TOKEN)' \
&& block "do not read or expose secrets or .env files"

# 4. Block pushing directly to main or master (including git push origin HEAD when on main/master)
if echo "$cmd" | grep -Eq 'git[[:space:]]+push'; then
if echo "$cmd" | grep -Eq 'git[[:space:]]+push[[:space:]]+.*(main|master|--force|-f)'; then
block "push to a feature branch and open a PR instead (never main/master or force push)"
fi
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
if [[ "$current_branch" == "main" || "$current_branch" == "master" ]]; then
block "currently on $current_branch branch; switch to a feature branch before pushing"
fi
fi

exit 0
61 changes: 61 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"permissions": {
"allow": [
"Read(**)",
"Bash(forge build:*)",
"Bash(forge test:*)",
"Bash(forge fmt:*)",
"Bash(forge coverage:*)",
"Bash(forge snapshot:*)",
"Bash(forge inspect:*)",
"Bash(forge script:*)",
"Bash(anvil:*)",
"Bash(slither:*)",
"Bash(aderyn:*)",
"Bash(pnpm:*)",
"Bash(git status:*)",
"Bash(git diff:*)",
"Bash(git log:*)",
"Bash(git add:*)",
"Bash(git commit:*)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./**/*.pem)",
"Read(./**/keystore/**)",
"Read(~/.ssh/**)",
"Bash(cast send:*)",
"Bash(cast publish:*)",
"Bash(forge create:*)",
"Bash(git push --force:*)",
"Bash(rm -rf:*)",
"Bash(curl:*)",
"Bash(wget:*)"
]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/guard-bash.sh"
}
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/format.sh"
}
]
}
]
}
}
10 changes: 10 additions & 0 deletions .claude/skills/bsc-gotchas/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: bsc-gotchas
description: BSC and opBNB specifics. Use when writing deploy scripts, token logic, or chain config.
---
- Token decimals: BSC USDT (`0x55d398326f99059fF775485246999027B3197955`) and USDC (`0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d`) are 18 decimals. Always read `decimals()`.
- EVM version: set `evm_version = "shanghai"` by default; verify target chain support on both BSC and opBNB before raising it.
- Block times: BSC block intervals are ~450ms (0.45s) and fast finality is ~650ms (post-2025/2026 hardforks). Never hard-code block-based timings (`block.number`); always use `block.timestamp` for vesting/staking and wait 15-20 blocks for payment confirmations.
- opBNB is an Optimistic Rollup L2 on BSC: check bridge/finality assumptions before relying on L1->L2 or L2->L1 messages.
- Use chain-specific verification (BscScan/opBNBScan) and keep API keys in env.
- Public RPCs are rate-limited; use a paid provider (NodeReal, Ankr, QuickNode) in production.
5 changes: 5 additions & 0 deletions .claude/skills/solidity-security/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: solidity-security
description: Checklist for reviewing or writing Solidity. Use when creating, modifying, or reviewing any smart contract.
---
Check every item and cite the line: access control on each external function; reentrancy guard or CEI; return values of external calls; SafeERC20 for tokens; fee-on-transfer/rebasing tokens; decimals; rounding direction (favor protocol); oracle staleness and manipulation; signature replay (EIP-712, nonce, deadline, chainId); initializer protection; storage collisions on upgrades; unbounded loops; timestamp reliance; events on every state change; pausability and emergency exits; admin power limits (timelock + multisig); front-running and sandwiching exposure.
25 changes: 16 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# GEMINI_API_KEY: Required for Gemini AI API calls.
# AI Studio automatically injects this at runtime from user secrets.
# Users configure this via the Secrets panel in the AI Studio UI.
GEMINI_API_KEY="MY_GEMINI_API_KEY"

# APP_URL: The URL where this applet is hosted.
# AI Studio automatically injects this at runtime with the Cloud Run service URL.
# Used for self-referential links, OAuth callbacks, and API endpoints.
APP_URL="MY_APP_URL"
# never commit real values
BSC_RPC_URL=
BSC_TESTNET_RPC_URL=https://data-seed-prebsc-1-s1.bnbchain.org:8545
OPBNB_RPC_URL=
OPBNB_TESTNET_RPC_URL=https://opbnb-testnet-rpc.bnbchain.org
BSCSCAN_API_KEY=
OPBNBSCAN_API_KEY=
ANTHROPIC_API_KEY=
OPENROUTER_API_KEY=
READYPI_API_KEY=
READYPI_BASE_URL=https://api.readypi.com/v1
SUPABASE_URL=
SUPABASE_SERVICE_ROLE_KEY=
PINATA_JWT=
WEBHOOK_HMAC_SECRET=
RELAYER_ADDRESS= # address only; the key lives in a secret manager, never here
70 changes: 70 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: ci
on:
pull_request:
push:
branches: [main]

jobs:
contracts:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/contracts
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install OpenZeppelin & forge-std if missing
run: |
[ -d lib/forge-std ] || forge install foundry-rs/forge-std --no-commit
[ -d lib/openzeppelin-contracts ] || forge install OpenZeppelin/openzeppelin-contracts@v5.2.0 --no-commit
- run: forge fmt --check
- run: forge build --sizes
- run: forge test -vvv
- run: forge coverage --report summary

slither:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: foundry-rs/foundry-toolchain@v1
- name: Ensure Foundry libs installed
working-directory: packages/contracts
run: |
[ -d lib/forge-std ] || forge install foundry-rs/forge-std --no-commit
[ -d lib/openzeppelin-contracts ] || forge install OpenZeppelin/openzeppelin-contracts@v5.2.0 --no-commit
- uses: crytic/slither-action@v0.4.0
with:
target: packages/contracts

web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9.15.0
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --no-frozen-lockfile
- run: pnpm lint && pnpm typecheck && pnpm -r test

claude-review:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: "Review this PR as the security-auditor agent would. Focus on contracts and key handling."
Loading
Loading