-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from MAGICGrants/scripts
Scripts
- Loading branch information
Showing
16 changed files
with
1,331 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
ELECTRUM_SERVER_ADDRESS="" | ||
MONERO_DAEMON_ADDRESS="" | ||
ELECTRUM_RPC_PASSWORD="" | ||
MONERO_RPC_PASSWORD="" | ||
BITCOIN_WALLET_SEED="" | ||
MONERO_WALLET_SEED="" | ||
MONERO_WALLET_PASSWORD="" | ||
MONERO_WALLET_HEIGHT="" | ||
KRAKEN_API_KEY="" | ||
KRAKEN_API_SECRET="" | ||
MAX_BITCOIN_FEE_PERCENT="10" | ||
MAX_SLIPPAGE_PERCENT="1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Deploy autoforward and autoconvert programs | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
- name: Deploy | ||
run: | | ||
ssh -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_IP }} << 'EOF' | ||
export HISTFILE=/dev/null | ||
cd autoforward-autoconvert | ||
git checkout main | ||
echo "Pulling changes..." | ||
git pull | ||
echo "Starting..." | ||
ELECTRS_DAEMON_RPC_ADDR=${{ secrets.ELECTRS_DAEMON_RPC_ADDR }} \ | ||
ELECTRS_DAEMON_P2P_ADDR=${{ secrets.ELECTRS_DAEMON_P2P_ADDR }} \ | ||
ELECTRUM_RPC_URL=${{ secrets.ELECTRUM_RPC_URL }} \ | ||
ELECTRUM_RPC_PASSWORD=${{ secrets.ELECTRUM_RPC_PASSWORD }} \ | ||
BITCOIN_WALLET_SEED=${{ secrets.BITCOIN_WALLET_SEED }} \ | ||
MONERO_RPC_URL=${{ secrets.MONERO_RPC_URL }} \ | ||
MONERO_RPC_USERNAME=${{ secrets.MONERO_RPC_USERNAME }} \ | ||
MONERO_RPC_PASSWORD=${{ secrets.MONERO_RPC_PASSWORD }} \ | ||
MONERO_WALLET_SEED=${{ secrets.MONERO_WALLET_SEED }} \ | ||
MONERO_WALLET_PASSWORD=${{ secrets.MONERO_WALLET_PASSWORD }} \ | ||
MONERO_WALLET_HEIGHT=${{ secrets.MONERO_WALLET_HEIGHT }} \ | ||
KRAKEN_API_KEY=${{ secrets.KRAKEN_API_KEY }} \ | ||
KRAKEN_API_SECRET=${{ secrets.KRAKEN_API_SECRET }} \ | ||
docker compose up -d --build | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.venv | ||
.env | ||
.electrs-cookie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM python:3.12-alpine AS builder | ||
|
||
RUN pip install poetry==1.8.3 --user | ||
RUN apk add build-base musl-dev gcc | ||
|
||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache \ | ||
PATH=/root/.local/bin/:$PATH | ||
|
||
WORKDIR /app | ||
|
||
COPY pyproject.toml poetry.lock ./ | ||
|
||
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root | ||
|
||
FROM python:3.12-alpine AS runtime | ||
|
||
WORKDIR /app | ||
|
||
ENV VIRTUAL_ENV=/app/.venv \ | ||
PATH="/app/.venv/bin:$PATH" | ||
|
||
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} | ||
|
||
COPY src src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,61 @@ | ||
# autoforward-autoconvert | ||
Programs to auto-forward BTC and XMR wallets to Kraken, and then auto-convert to USD | ||
|
||
Programs to auto-forward BTC and XMR wallets to Kraken, and then auto-convert to USD. | ||
|
||
## Requirements | ||
|
||
- Docker | ||
- Docker Compose | ||
|
||
## Configuration | ||
|
||
Create a `.env` file as a copy of `.env.example` and set the values for the empty variables. | ||
|
||
### Environment variables | ||
|
||
| Variable name | Required | Default | Description | | ||
| - | - | - | - | | ||
| `BITCOIN_WALLET_SEED` | Yes | - | Your BIP39 Bitcoin mnemonic seed. | | ||
| `MONERO_WALLET_SEED` | Yes | - | Your 25 word Monero mnemonic seed. | | ||
| `MONERO_WALLET_HEIGHT` | Yes | - | The restore height of your Monero wallet. | | ||
| `ELECTRUM_RPC_PASSWORD` | Yes | - | A new strong password for your Electrum RPC. | | ||
| `MONERO_RPC_PASSWORD` | Yes | - | A new strong password for your Monero RPC. | | ||
| `MONERO_WALLET_PASSWORD` | Yes | - | A new strong password for your Monero Wallet. | | ||
| `KRAKEN_API_KEY` | Yes | - | Your API key from Kraken. | | ||
| `KRAKEN_API_SECRET` | Yes | - | Your API secret from Kraken. | | ||
| `MONERO_DAEMON_ADDRESS` | Yes | - | The address of a Monero daemon you own or trust. | | ||
| `ELECTRUM_SERVER_ADDRESS` | **No** | - | The address of an Electrum server you own or trust. E.g.: `localhost:50001:t` (no SSL) or `my.electrum.server:50001:s` (SSL). By leaving this blank you're letting Electrum select a random server for you, which may be a privacy concern. | | ||
| `MAX_BITCOIN_FEE_PERCENT` | **No** | `10` | The maximum accepted bitcoin miner's fee percent when auto-forwarding. | | ||
| `MAX_SLIPPAGE_PERCENT` | **No** | `1` | The maximum accepted slippage percent when auto-converting. | | ||
|
||
|
||
## Running | ||
|
||
After setting the required environment variable values, you can run the containers: | ||
|
||
```bash | ||
$ docker-compose --env-file .env up -d | ||
``` | ||
|
||
## Changing seeds | ||
|
||
If you wish to change any of the wallet seeds in the future, first you have to take down all Docker Compose services and delete the volumes: | ||
|
||
```bash | ||
$ docker-compose down -v | ||
``` | ||
|
||
Change the seeds in the `.env` file and start all services again: | ||
|
||
```bash | ||
$ docker-compose --env-file .env up -d | ||
``` | ||
|
||
# Contributing | ||
|
||
Pull requests welcome! | ||
Thanks for supporting MAGIC Grants. | ||
|
||
# License | ||
|
||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
services: | ||
electrum-client: | ||
build: | ||
context: ./electrum-client | ||
args: | ||
VERSION: "4.5.5" | ||
CHECKSUM_SHA512: "3bdfce2187466fff20fd67736bdf257bf95d3517de47043be411ccda558a442b8fd81d6a8da094a39a1db39a7339dcd4282e73a7f00cf6bbd70473d7ce456b0b" | ||
container_name: electrum-client | ||
restart: unless-stopped | ||
environment: | ||
- ELECTRUM_USER=${ELECTRUM_RPC_USERNAME} | ||
- ELECTRUM_PASSWORD=${ELECTRUM_RPC_PASSWORD} | ||
- ELECTRUM_SERVER_ADDRESS=${ELECTRUM_SERVER_ADDRESS} | ||
|
||
monero-wallet-rpc: | ||
image: ghcr.io/sethforprivacy/simple-monero-wallet-rpc:latest | ||
restart: unless-stopped | ||
container_name: monero-wallet-rpc | ||
volumes: | ||
- monero-wallet-rpc-data:/home/monero | ||
command: | ||
- "--trusted-daemon" | ||
- "--rpc-bind-port=18082" | ||
- "--rpc-login=${MONERO_RPC_USERNAME}:${MONERO_RPC_PASSWORD}" | ||
- "--daemon-address=${MONERO_DAEMON_ADDRESS}" | ||
- "--wallet-dir=/home/monero/wallet" | ||
- "--log-level=4" | ||
|
||
seed-importer: | ||
build: | ||
context: . | ||
container_name: seed-importer | ||
environment: | ||
- PYTHONUNBUFFERED=1 | ||
- ELECTRUM_RPC_URL=http://electrum-client:7000 | ||
- ELECTRUM_RPC_USERNAME=${ELECTRUM_RPC_USERNAME} | ||
- ELECTRUM_RPC_PASSWORD=${ELECTRUM_RPC_PASSWORD} | ||
- BITCOIN_WALLET_SEED=${BITCOIN_WALLET_SEED} | ||
- MONERO_RPC_URL=http://monero-wallet-rpc:18082/json_rpc | ||
- MONERO_RPC_USERNAME=${MONERO_RPC_USERNAME} | ||
- MONERO_RPC_PASSWORD=${MONERO_RPC_PASSWORD} | ||
- MONERO_WALLET_SEED=${MONERO_WALLET_SEED} | ||
- MONERO_WALLET_PASSWORD=${MONERO_WALLET_PASSWORD} | ||
- MONERO_WALLET_HEIGHT=${MONERO_WALLET_HEIGHT} | ||
command: python ./src/seed-importer.py | ||
depends_on: | ||
- electrum-client | ||
- monero-wallet-rpc | ||
|
||
autoforward: | ||
build: | ||
context: . | ||
container_name: autoforward | ||
restart: unless-stopped | ||
environment: | ||
- PYTHONUNBUFFERED=1 | ||
- ELECTRUM_RPC_URL=http://electrum-client:7000 | ||
- ELECTRUM_RPC_USERNAME=${ELECTRUM_RPC_USERNAME} | ||
- ELECTRUM_RPC_PASSWORD=${ELECTRUM_RPC_PASSWORD} | ||
- BITCOIN_WALLET_SEED=${BITCOIN_WALLET_SEED} | ||
- MONERO_RPC_URL=http://monero-wallet-rpc:18082/json_rpc | ||
- MONERO_RPC_USERNAME=${MONERO_RPC_USERNAME} | ||
- MONERO_RPC_PASSWORD=${MONERO_RPC_PASSWORD} | ||
- MONERO_WALLET_SEED=${MONERO_WALLET_SEED} | ||
- MONERO_WALLET_PASSWORD=${MONERO_WALLET_PASSWORD} | ||
- MONERO_WALLET_HEIGHT=${MONERO_WALLET_HEIGHT} | ||
- KRAKEN_API_KEY=${KRAKEN_API_KEY} | ||
- KRAKEN_API_SECRET=${KRAKEN_API_SECRET} | ||
command: python ./src/autoforward.py | ||
depends_on: | ||
- seed-importer | ||
|
||
autoconvert: | ||
build: | ||
context: . | ||
container_name: autoconvert | ||
restart: unless-stopped | ||
environment: | ||
- PYTHONUNBUFFERED=1 | ||
- KRAKEN_API_KEY=${KRAKEN_API_KEY} | ||
- KRAKEN_API_SECRET=${KRAKEN_API_SECRET} | ||
command: python ./src/autoconvert.py | ||
depends_on: | ||
- seed-importer | ||
|
||
volumes: | ||
monero-wallet-rpc-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM python:3.12-alpine | ||
|
||
ARG VERSION | ||
ARG CHECKSUM_SHA512 | ||
|
||
ENV ELECTRUM_VERSION=$VERSION | ||
ENV ELECTRUM_USER=electrum | ||
ENV ELECTRUM_HOME=/home/$ELECTRUM_USER | ||
ENV ELECTRUM_NETWORK=mainnet | ||
|
||
RUN adduser -D $ELECTRUM_USER | ||
|
||
RUN mkdir -p /data ${ELECTRUM_HOME} && \ | ||
ln -sf /data ${ELECTRUM_HOME}/.electrum && \ | ||
chown ${ELECTRUM_USER} ${ELECTRUM_HOME}/.electrum /data | ||
|
||
# IMPORTANT: always verify gpg signature before changing a hash here! | ||
ENV ELECTRUM_CHECKSUM_SHA512 $CHECKSUM_SHA512 | ||
|
||
RUN apk --no-cache add --virtual build-dependencies gcc musl-dev libsecp256k1 libsecp256k1-dev libressl-dev | ||
RUN wget https://download.electrum.org/${ELECTRUM_VERSION}/Electrum-${ELECTRUM_VERSION}.tar.gz | ||
RUN [ "${ELECTRUM_CHECKSUM_SHA512} Electrum-${ELECTRUM_VERSION}.tar.gz" = "$(sha512sum Electrum-${ELECTRUM_VERSION}.tar.gz)" ] | ||
RUN echo -e "**************************\n SHA 512 Checksum OK\n**************************" | ||
RUN pip3 install cryptography Electrum-${ELECTRUM_VERSION}.tar.gz | ||
RUN rm -f Electrum-${ELECTRUM_VERSION}.tar.gz | ||
|
||
RUN mkdir -p /data \ | ||
${ELECTRUM_HOME}/.electrum/wallets/ \ | ||
${ELECTRUM_HOME}/.electrum/testnet/wallets/ \ | ||
${ELECTRUM_HOME}/.electrum/regtest/wallets/ \ | ||
${ELECTRUM_HOME}/.electrum/simnet/wallets/ && \ | ||
ln -sf ${ELECTRUM_HOME}/.electrum/ /data && \ | ||
chown -R ${ELECTRUM_USER} ${ELECTRUM_HOME}/.electrum /data | ||
|
||
USER $ELECTRUM_USER | ||
WORKDIR $ELECTRUM_HOME | ||
VOLUME /data | ||
EXPOSE 7000 | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
ENTRYPOINT ["docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env sh | ||
set -ex | ||
|
||
trap 'pkill -TERM -P1; electrum stop; exit 0' SIGTERM | ||
|
||
rm -f .electrum/daemon | ||
electrum --offline setconfig rpcuser ${ELECTRUM_USER} | ||
electrum --offline setconfig rpcpassword ${ELECTRUM_PASSWORD} | ||
electrum --offline setconfig rpchost 0.0.0.0 | ||
electrum --offline setconfig rpcport 7000 | ||
|
||
if [ -n "${ELECTRUM_SERVER_ADDRESS}" ]; then | ||
electrum daemon -1 -s "${ELECTRUM_SERVER_ADDRESS}" "$@" | ||
else | ||
electrum daemon "$@" | ||
fi | ||
|
Oops, something went wrong.