Skip to content

Commit 9c18f4b

Browse files
committed
feat: initial commit
0 parents  commit 9c18f4b

File tree

17 files changed

+3667
-0
lines changed

17 files changed

+3667
-0
lines changed

.claude/CLAUDE.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Dutch Taker Bot
2+
3+
A Silverback bot that automatically takes (executes) flex dutch auctions on the blockchain.
4+
5+
## Tech Stack
6+
7+
- **Framework**: [Silverback SDK](https://docs.apeworx.io/silverback/stable)
8+
- **Blockchain**: [Ape Framework](https://docs.apeworx.io/ape/stable)
9+
- **Python**: 3.12+
10+
- **Package Manager**: uv
11+
12+
## Project Structure
13+
14+
```
15+
dutch-taker/
16+
├── bot/
17+
│ ├── __init__.py
18+
│ ├── bot.py # Main bot logic
19+
│ ├── config.py # Network config, addresses
20+
│ └── tg.py # Telegram notifications
21+
├── .claude/
22+
│ ├── CLAUDE.md
23+
│ └── skills/
24+
├── pyproject.toml
25+
└── README.md
26+
```
27+
28+
## Development Guidelines
29+
30+
### Principles
31+
32+
- **DRY** - Don't Repeat Yourself
33+
- **KISS** - Keep It Simple, Stupid
34+
- **Clean Code** - Self-documenting, minimal comments
35+
- **Single Responsibility** - Each function does one thing well
36+
- **Fail Fast** - Validate early, raise exceptions clearly
37+
38+
### Code Style
39+
40+
- Super clean and minimalistic
41+
- Format: `ruff format .`
42+
- Lint: `ruff check .`
43+
- Type check: `mypy bot`
44+
- Line length: 120 characters
45+
- No unnecessary abstractions
46+
- No premature optimization
47+
48+
### Risk Management
49+
50+
- Never hardcode secrets - use environment variables
51+
- Implement configurable limits
52+
- Use `CircuitBreaker` for emergency stops
53+
- Test with print debugging before enabling transactions
54+
55+
## Running
56+
57+
```bash
58+
silverback run --network ethereum:mainnet
59+
```

.claude/skills/writing-bots.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
name: writing-bots
3+
description: Write a bot to continuously listen and respond to events on a public blockchain network.
4+
compatibility: Requires uv installed
5+
---
6+
7+
This skill describes when and how to a bot using the Silverback SDK.
8+
9+
The user provides operational requirements such as which blockchain network they want it to run on,
10+
which smart contracts they want to interact with, what types of actions they want to take.
11+
They may provide additional context about technical constraints, or scenarios it must avoid.
12+
13+
## Using This Skill
14+
15+
**CRITICAL**: Before writing any Silverback bot code, you MUST:
16+
1. Use `web_fetch` to retrieve the latest documentation from https://docs.apeworx.io/silverback/stable
17+
2. Specifically fetch relevant pages like:
18+
- Development guide: https://docs.apeworx.io/silverback/stable/userguides/development
19+
- API reference: https://docs.apeworx.io/silverback/stable/methoddocs
20+
21+
**DO NOT** rely on general knowledge about Silverback - always fetch the current documentation first to ensure accuracy.
22+
23+
## Designing a Bot
24+
25+
Before writing the bot, understand the types of actions you want to perform,
26+
and which on-chain or off-chain events you might want to monitor in order to trigger them
27+
- **New Block**: Do you want to perform an action on every block?
28+
- **Event Log**: Do you want to perform an action when a smart contract emits a particular event?
29+
- **Cron Job**: Do you want to perform an action on a time-based interval?
30+
- **Metrics**: Do you want to perform an action when a [metric](#defining-metrics) meets certain conditions?
31+
32+
**CRITICAL**: Have a good understanding of the requirements first before proceeding to write any code.
33+
34+
Then implement event handlers, which are callbacks implemented that trigger logic which might:
35+
- send a message on Telegram or Discord to a group or channel
36+
- send a social media post on X or Farcaster
37+
- send a POST request to another backend service
38+
- sign and broadcast a transaction on the listening chain and/or other blockchain(s)
39+
- measure a simple or derived [Metric](#defining-metrics)
40+
- provision a product or service
41+
42+
### Defining Metrics
43+
44+
In order to have visibility into the operation of the bot,
45+
it is often useful to define key "Metrics" or signal values that you can monitor over time to understand the real-world operation of the bot.
46+
This can also be very useful for monitoring purposes, but Silverback also lets you define event triggers based on the value of the metric.
47+
For example, if you've defined a complex metric based on the amount of trading volume occuring on a particular decentralized exchange pool in the latest block,
48+
you might want to trigger an action to occur when that volume signal is above or below a certain threshold.
49+
This can create more complex, reactive behaviors beyond what basic blockchain events can tell you.
50+
51+
## Maintaining State
52+
53+
Sometimes the actions you want to take in a bot depends on the results of other actions,
54+
so it is useful to maintain some internal state to track those results.
55+
Use internal state sparingly, and try to rely as much as you can on the blockchain state,
56+
or the state of other external services you've integrated the bot with in order to make correct decisions.
57+
58+
## Managing Risk
59+
60+
Overall, bots can do potentially risky actions and may end up being a part of critical user infrastructure.
61+
It is best to advise them on proceeding slowly and verifying the correctness of their implementation in stages,
62+
before more drastic steps like adding a signer to submit transactions or giving it access to a critical communications channel.
63+
You can easily do this through `print` debugging at first,
64+
or build-in operational modes based on the presence of a specific environment variable such as the availability of an API key,
65+
whether the `bot.signer` is configured, or based on other on-chain information like account balances.
66+
67+
Also, you should suggest things like adding configurable limits (using environment variables via `os.environ`),
68+
emergency stop conditions (raising the `silverback.CircuitBreaker` exception), or others ways to effectively manage risk.
69+
70+
## Running the Bot
71+
72+
Only after the user thinks that the bot seems well-written and ready for testing should you install silverback and run it.
73+
74+
To install silverback, run the following command with `uv` installed:
75+
76+
```bash
77+
$ uv tool install silverback
78+
```
79+
80+
This will make the `silverback` cli command available.
81+
You can then run the bot on the `ecosystem` and `network` they want (such as "ethereum:mainnet") using:
82+
83+
```bash
84+
$ silverback run --network <ecosystem>:<network>
85+
```
86+
87+
You can make the bot shutdown manually via ctrl+C, or sending the SHUTDOWN or KILL signal to the process.
88+
89+
Monitor the bot's operations via it's logs and try to resolve errors until they rarely happen.
90+
Silverback can handle the occasional error, so you can't figure out exactly why something is failing,
91+
it could be okay to continue testing with.
92+
93+
Ask the user to monitor their bot as well via the logs, and then ask if they like how the bot is working.

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
TAKER_PRIVATE_KEY=""
2+
BOT_ACCESS_TOKEN=""
3+
GROUP_CHAT_ID=""
4+
ERROR_GROUP_CHAT_ID=""
5+
ETHERSCAN_API_KEY=""
6+
ETH_RPC_URL=""
7+
ETH_WS_URL=""

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
check-code:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: "3.12"
21+
22+
- name: Install uv
23+
run: |
24+
curl -Ls https://astral.sh/uv/install.sh | sh
25+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
26+
27+
- name: Set up project
28+
run: |
29+
uv venv
30+
source .venv/bin/activate
31+
uv sync
32+
33+
- name: Run Ruff format check
34+
run: |
35+
source .venv/bin/activate
36+
ruff format . --check
37+
38+
- name: Run Ruff linter
39+
run: |
40+
source .venv/bin/activate
41+
ruff check .
42+
43+
- name: Run mypy
44+
run: |
45+
source .venv/bin/activate
46+
mypy bot

.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Python cache files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution/packaging
7+
dist/
8+
build/
9+
*.egg-info/
10+
11+
# Virtual environments
12+
venv/
13+
env/
14+
.env/
15+
.venv/
16+
17+
# IDE settings
18+
.vscode/
19+
.idea/
20+
*.swp
21+
*.swo
22+
23+
# Testing
24+
.pytest_cache/
25+
.coverage
26+
htmlcov/
27+
28+
# Local development settings
29+
.env
30+
.env.local
31+
32+
# Jupyter Notebook
33+
.ipynb_checkpoints
34+
35+
# Logs
36+
*.log
37+
38+
# Type checking
39+
.mypy_cache/
40+
41+
# Editor configs
42+
.cursorrules
43+
44+
# Cache files
45+
cache-id.txt
46+
*.cache
47+
.uv/
48+
.ruff_cache
49+
.DS_Store
50+
51+
# Ape stuff
52+
.build/
53+
.silverback-images/
54+
.silverback-sessions/
55+
56+
# Local storage
57+
bot_state.json

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.12
2+
3+
WORKDIR /app
4+
5+
# Copy source
6+
COPY . .
7+
8+
# Install deps
9+
RUN pip install uv && uv sync --no-dev --no-cache
10+
11+
# Fix shebang
12+
RUN sed -i '1 s|^#!.*python3$|#!/app/.venv/bin/python3|' /app/.venv/bin/silverback
13+
14+
# Ensure the project venv is on PATH so 'silverback' is found
15+
ENV PATH="/app/.venv/bin:${PATH}"
16+
17+
# Default entrypoint, compose will pass rest of the args
18+
ENTRYPOINT ["silverback"]

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# dutch-taker
2+
3+
<p align="center">
4+
<img src="assets/pfp.jpg" alt="Flex Silverback" width="700" height="500"/>
5+
</p>
6+
7+
## Installation
8+
9+
1. **Clone the repository**
10+
```bash
11+
git clone https://github.com/flexmeow/dutch-taker.git
12+
cd dutch-taker
13+
```
14+
15+
2. **Set up virtual environment**
16+
```bash
17+
uv venv
18+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
19+
```
20+
21+
3. **Install dependencies**
22+
```bash
23+
# Install all dependencies
24+
uv sync
25+
```
26+
27+
> Note: This project uses [uv](https://github.com/astral-sh/uv) for faster dependency installation. If you don't have uv installed, you can install it with `pip install uv` or follow the [installation instructions](https://github.com/astral-sh/uv#installation).
28+
29+
4. **Environment setup**
30+
```bash
31+
cp .env.example .env
32+
# Edit .env with your API keys and configuration
33+
34+
# Load environment variables into your shell session
35+
export $(grep -v '^#' .env | xargs)
36+
```
37+
38+
## Usage
39+
40+
Run:
41+
```shell
42+
silverback run --network :mainnet
43+
```
44+
45+
Run using docker compose:
46+
```shell
47+
docker compose up --build
48+
```
49+
50+
Stop docker compose:
51+
```shell
52+
docker compose down
53+
```
54+
55+
## Code Style
56+
57+
Format and lint code with ruff:
58+
```bash
59+
# Format code
60+
ruff format .
61+
62+
# Lint code
63+
ruff check .
64+
65+
# Fix fixable lint issues
66+
ruff check --fix .
67+
```
68+
69+
Type checking with mypy:
70+
```bash
71+
mypy bot
72+
```

ape-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node:
2+
ethereum:
3+
mainnet:
4+
uri: "${ETH_RPC_URL}"
5+
ws_uri: "${ETH_WS_URL}"

assets/pfp.jpg

144 KB
Loading

bot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .bot import bot as bot

0 commit comments

Comments
 (0)