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
48 changes: 48 additions & 0 deletions .github/workflows/build_push_filwizard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build & Push FilWizard (Smart contract deployment tool).

on:
workflow_dispatch:
inputs:
filwizard_tag:
type: string
required: true
default: 'latest'
description: A filwizard tag

jobs:
antithesis:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Antithesis Google Artifact Registry
uses: docker/login-action@v3
with:
registry: us-central1-docker.pkg.dev
username: _json_key
password: ${{ secrets.ANTITHESIS_GAR_KEY }}

- name: Extract metadata (tags) for Docker filwizard
id: meta-filwizard
uses: docker/metadata-action@v5
with:
images: us-central1-docker.pkg.dev/molten-verve-216720/filecoin-repository/filwizard
tags: |
type=sha
${{ github.event.inputs.filwizard_tag }}
- name: Build and push filwizard
uses: docker/build-push-action@v5
with:
context: ./filwizard
file: ./filwizard/Dockerfile
push: true
tags: ${{ steps.meta-filwizard.outputs.tags }}, ${{ env.GITHUB_REF_NAME }}
labels: ${{ steps.meta-filwizard.outputs.labels }}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM scratch

COPY docker-compose.yaml /docker-compose.yaml
COPY docker-compose2.yaml /docker-compose2.yaml

COPY ./.env /.env
COPY ../data /data
COPY ./drand /drand
COPY ./lotus /lotus
COPY ./forest /forest
COPY ./curio /curio
COPY ./yugabyte /yugabyte
COPY ./yugabyte /yugabyte
COPY ./filwizard /filwizard
COPY ./workload /workload
59 changes: 59 additions & 0 deletions filwizard/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Stage 1: Clone and build the filwizard binary
FROM golang:latest AS builder

# Clone FilWizard repo (for contract deployment only)
RUN git clone https://github.com/parthshah1/FilWizard /build
WORKDIR /build
RUN git checkout main
RUN git pull

# Build filwizard binary
RUN go mod download
RUN CGO_ENABLED=1 go build -o filwizard .

# Install abigen (go-ethereum ABI binding generator)
RUN go install github.com/ethereum/go-ethereum/cmd/abigen@latest

# Stage 2: Runtime image with all tools needed for contract deployment
FROM ubuntu:24.04

RUN apt-get update && apt-get install -y \
curl jq git ca-certificates nodejs npm \
&& rm -rf /var/lib/apt/lists/*

# Install pnpm
RUN npm install -g pnpm@latest

# Install Foundry
RUN curl -L https://foundry.paradigm.xyz | bash
ENV PATH="/root/.foundry/bin:${PATH}"
RUN foundryup

# Copy filwizard binary
COPY --from=builder /build/filwizard /usr/local/bin/filwizard

# Copy abigen binary
COPY --from=builder /go/bin/abigen /usr/local/bin/abigen

# Pre-clone and compile FOC contracts (air-gapped operation)
WORKDIR /opt/filwizard
COPY --from=builder /build/config/filecoin-synapse.json /opt/filwizard/config/filecoin-synapse.json

RUN filwizard contract clone-config \
--config /opt/filwizard/config/filecoin-synapse.json \
--workspace /opt/filwizard/workspace


# Copy scripts
COPY scripts/register-service-provider.js /opt/filwizard/scripts/register-service-provider.js
COPY scripts/warm-add.js /opt/filwizard/scripts/warm-add.js
COPY scripts/package.json /opt/filwizard/scripts/package.json
COPY scripts/export-environment.sh /opt/filwizard/scripts/export-environment.sh
RUN chmod +x /opt/filwizard/scripts/register-service-provider.js /opt/filwizard/scripts/warm-add.js /opt/filwizard/scripts/export-environment.sh
# Install script dependencies locally (ethers.js)
RUN cd /opt/filwizard/scripts && npm install

WORKDIR /opt/filwizard

# Default entrypoint — will be overridden by compose
ENTRYPOINT ["filwizard"]
173 changes: 173 additions & 0 deletions filwizard/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/bin/bash
set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

log_info() { echo -e "${GREEN}[FILWIZARD]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[FILWIZARD]${NC} $1"; }
log_error() { echo -e "${RED}[FILWIZARD]${NC} $1" >&2; }

wait_for_file() {
local file="$1" desc="$2"
log_info "Waiting for $desc..."
while [ ! -f "$file" ] || [ ! -s "$file" ]; do sleep 2; done
log_info "$desc found"
}

# ── Config ──
FILECOIN_RPC="http://lotus0:1234/rpc/v1"
ETH_RPC_URL="http://lotus0:1234/rpc/v1"
RPC_WS_URL="ws://lotus0:1234/rpc/v1"
RPC_LOTUS="${RPC_LOTUS:-http://lotus0:1234/rpc/v0}"
CHAIN_ID="31415926"
INIT_BLOCK_HEIGHT=5

WORKSPACE_PATH="/opt/filwizard/workspace"
CONFIG_PATH="/opt/filwizard/config/filecoin-synapse.json"
ENV_OUTPUT="/shared/environment.env"
CURIO_SHARED_DIR="/shared/curio"
CURIO_ENV_FILE="${CURIO_SHARED_DIR}/.env.curio"
ACCOUNTS_FILE="${WORKSPACE_PATH}/accounts.json"

SP_SERVICE_URL="${SP_SERVICE_URL:-http://curio:80}"
SP_NAME="${SP_NAME:-My Devnet Provider}"
SP_DESCRIPTION="${SP_DESCRIPTION:-Devnet provider for Warm Storage}"

# ── 1. Wait for chain ──
log_info "Waiting for block height ${INIT_BLOCK_HEIGHT}..."
BLOCK_HEIGHT_REACHED=0
while [ "${INIT_BLOCK_HEIGHT}" -gt "${BLOCK_HEIGHT_REACHED}" ]; do
RESPONSE=$(curl -s --max-time 5 -X POST "$RPC_LOTUS" \
-H 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","id":1,"method":"Filecoin.ChainHead","params":[]}' 2>/dev/null || echo '{}')
BLOCK_HEIGHT_REACHED=$(echo "$RESPONSE" | jq -r '.result.Height // 0' 2>/dev/null)
[ -z "$BLOCK_HEIGHT_REACHED" ] || [ "$BLOCK_HEIGHT_REACHED" = "null" ] && BLOCK_HEIGHT_REACHED=0
[ "${INIT_BLOCK_HEIGHT}" -le "${BLOCK_HEIGHT_REACHED}" ] && break
log_info "Height: ${BLOCK_HEIGHT_REACHED}, waiting..."
sleep 5
done
log_info "Chain ready at height ${BLOCK_HEIGHT_REACHED}"

# ── 2. Setup Filecoin env ──
JWT_FILE="/shared/lotus0/lotus0-jwt"
wait_for_file "$JWT_FILE" "Lotus JWT"
export FILECOIN_RPC ETH_RPC_URL
export FILECOIN_TOKEN=$(cat "$JWT_FILE")

# ── 3. Deploy FOC contracts ──
log_info "Deploying contracts via FilWizard..."
cd /opt/filwizard

filwizard contract deploy-local \
--config "$CONFIG_PATH" \
--workspace "$WORKSPACE_PATH" \
--rpc-url "$FILECOIN_RPC" \
--create-deployer \
--bindings \
|| log_warn "Deployment completed with warnings, continuing..."

wait_for_file "${WORKSPACE_PATH}/deployments.json" "deployments.json"

# ── 4. Export environment (simple bash + jq) ──
log_info "Exporting environment..."
bash /opt/filwizard/scripts/export-environment.sh \
"$WORKSPACE_PATH" \
"$ENV_OUTPUT" \
"$CHAIN_ID" \
"$FILECOIN_RPC" \
"$RPC_WS_URL"

log_info "environment.env written to $ENV_OUTPUT"

# ── 5. Create Curio .env (subset with CURIO_ prefix) ──
log_info "Creating Curio environment file..."
mkdir -p "$CURIO_SHARED_DIR"

# Source the exported env to get address variables
set -a
source "$ENV_OUTPUT"
set +a

cat > "$CURIO_ENV_FILE" << EOF
# Curio Devnet Contract Addresses
# Generated by filwizard entrypoint

CURIO_DEVNET_PDP_VERIFIER_ADDRESS=${PDP_VERIFIER_PROXY_ADDRESS}
CURIO_DEVNET_FWSS_ADDRESS=${FWSS_PROXY_ADDRESS}
CURIO_DEVNET_SERVICE_REGISTRY_ADDRESS=${SERVICE_PROVIDER_REGISTRY_PROXY_ADDRESS}
CURIO_DEVNET_PAYMENTS_ADDRESS=${FILECOIN_PAY_ADDRESS}
CURIO_DEVNET_USDFC_ADDRESS=${USDFC_ADDRESS}
CURIO_DEVNET_MULTICALL_ADDRESS=${MULTICALL3_ADDRESS}
EOF

log_info "Curio env created: $CURIO_ENV_FILE"

# ── 6. Create client wallet ──
log_info "Creating client wallet..."
filwizard wallet create \
--type ethereum \
--count 1 \
--fund 5 \
--show-private-key \
--key-output "$ACCOUNTS_FILE" \
--name "client"

CLIENT_PRIVATE_KEY=$(jq -r '.accounts.client.privateKey' "$ACCOUNTS_FILE")
DEPLOYER_PRIVATE_KEY=$(jq -r '.accounts.deployer.privateKey' "$ACCOUNTS_FILE")

# ── 7. Wait for Curio SP private key ──
SP_PRIVATE_KEY_FILE="/shared/curio/private_key"
wait_for_file "$SP_PRIVATE_KEY_FILE" "SP private key from Curio"
SP_PRIVATE_KEY=$(cat "$SP_PRIVATE_KEY_FILE" | tr -d '[:space:]')

# ── 8. Mint tokens ──
log_info "Minting tokens..."

filwizard payments mint-private-key --workspace "$WORKSPACE_PATH" \
--private-key "$CLIENT_PRIVATE_KEY" --amount 1000000000000000000000 --fil 0

filwizard payments mint-private-key --workspace "$WORKSPACE_PATH" \
--private-key "$CLIENT_PRIVATE_KEY" --amount 0 --fil 10

filwizard payments mint-private-key --workspace "$WORKSPACE_PATH" \
--private-key "$SP_PRIVATE_KEY" --amount 10000000000000000000000 --fil 0

filwizard payments mint-private-key --workspace "$WORKSPACE_PATH" \
--private-key "$SP_PRIVATE_KEY" --amount 0 --fil 10

log_info "Tokens minted"

# ── 9. Register service provider ──
log_info "Registering service provider..."

export DEPLOYER_PRIVATE_KEY SP_PRIVATE_KEY CLIENT_PRIVATE_KEY
export SP_SERVICE_URL SP_NAME SP_DESCRIPTION

node /opt/filwizard/scripts/register-service-provider.js \
--rpc-url "$FILECOIN_RPC" \
--warm-storage "$FWSS_PROXY_ADDRESS" \
--sp-registry "$SERVICE_PROVIDER_REGISTRY_PROXY_ADDRESS"

log_info "Service provider registered"

# ── 10. Add approved provider to warm storage ──
log_info "Adding service provider to warm storage global whitelist..."

export DEPLOYER_PRIVATE_KEY SP_PRIVATE_KEY

node /opt/filwizard/scripts/warm-add.js \
--rpc-url "$FILECOIN_RPC" \
--warm-storage "$FWSS_PROXY_ADDRESS" \
--sp-registry "$SERVICE_PROVIDER_REGISTRY_PROXY_ADDRESS"

log_info "Service provider added to global whitelist (ready for dapps)"

# ── 11. Signal healthy ──
log_info "FilWizard setup complete. Signaling healthy."
touch /tmp/healthy

# Keep container alive (compose healthcheck will gate dependents)
sleep infinity
73 changes: 73 additions & 0 deletions filwizard/scripts/export-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
set -e

# Simple environment export using bash + jq
# Replaces the FilWizard env export command

WORKSPACE="${1:-/opt/filwizard/workspace}"
OUTPUT="${2:-/shared/environment.env}"
CHAIN_ID="${3:-31415926}"
RPC_URL="${4:-http://lotus0:1234/rpc/v1}"
RPC_WS_URL="${5:-ws://lotus0:1234/rpc/v1}"

# Use service contracts from workspace deployment (already deployed)
SERVICE_CONTRACTS_JSON="$WORKSPACE/filecoinwarmstorage/service_contracts/deployments.json"
WORKSPACE_DEPLOYMENTS_JSON="$WORKSPACE/deployments.json"
ACCOUNTS_JSON="$WORKSPACE/accounts.json"

# Write to file instead of stdout
{
echo "# Generated by filwizard environment export"
echo "# Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo ""
echo "# Network"
echo "CHAIN_ID=$CHAIN_ID"
echo "RPC_URL=$RPC_URL"
echo "ETH_RPC_URL=$RPC_URL"
echo "RPC_WS_URL=$RPC_WS_URL"
echo ""

# Service contract addresses (from workspace deployment)
echo "# Service Contract Addresses"
if [ -f "$SERVICE_CONTRACTS_JSON" ]; then
jq -r --arg chain "$CHAIN_ID" '
.[$chain] // {} |
to_entries |
map(select(.key != "metadata")) |
sort_by(.key) |
.[] |
"\(.key)=\(.value)"
' "$SERVICE_CONTRACTS_JSON"
else
echo "# Note: Service contracts will be loaded after deployment"
fi

# USDFC and Multicall3 from workspace
if [ -f "$WORKSPACE_DEPLOYMENTS_JSON" ]; then
jq -r '
.[] |
select(.name == "USDFC" or .name == "Multicall3") |
"\(.name | ascii_upcase)_ADDRESS=\(.address)"
' "$WORKSPACE_DEPLOYMENTS_JSON"
fi
echo ""

# Accounts
echo "# Accounts"
if [ -f "$ACCOUNTS_JSON" ]; then
# Deployer private key
DEPLOYER_KEY=$(jq -r '.accounts.deployer.privateKey // empty' "$ACCOUNTS_JSON")
if [ -n "$DEPLOYER_KEY" ]; then
echo "DEPLOYER_PRIVATE_KEY=$DEPLOYER_KEY"
fi

# Deployer ETH address
DEPLOYER_ETH=$(jq -r '.accounts.deployer.ethAddress // empty' "$ACCOUNTS_JSON")
if [ -n "$DEPLOYER_ETH" ]; then
echo "DEPLOYER_ETH_ADDRESS=$DEPLOYER_ETH"
fi
fi
echo ""
} > "$OUTPUT"

echo "✓ Environment exported to $OUTPUT"
9 changes: 9 additions & 0 deletions filwizard/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "filwizard-scripts",
"version": "1.0.0",
"type": "module",
"description": "Service provider registration and contract deployment scripts",
"dependencies": {
"ethers": "^6.0.0"
}
}
Loading