Skip to content

Commit

Permalink
docs: update readme and deployment guide
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1NotMe committed Oct 31, 2024
1 parent 357b0e4 commit b498dd9
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 76 deletions.
12 changes: 8 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Private key for deployment
PRIVATE_KEY=

# RPC URLs
RPC_POLYGON=https://polygon-mainnet.g.alchemy.com/v2/your-api-key
RPC_MUMBAI=https://polygon-mumbai.g.alchemy.com/v2/your-api-key
Expand All @@ -11,4 +8,11 @@ POLYGONSCAN_API_KEY=

# Contract addresses
ATLAS_POLYGON=
ATLAS_MUMBAI=
ATLAS_MUMBAI=

# Keystore configuration
KEYSTORE_NAME=deployer
KEYSTORE_PASSWORD=

# Optional: Override default keystore path
# KEYSTORE_PATH=/custom/path/to/keystores
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ docs/

# Other
.DS_Store

# Foundry
anvil.pid
anvil.log
76 changes: 76 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Deployment Guide

## Local Development

1. Start a local blockchain:
```bash
make anvil
```
This will start Anvil (local Ethereum node) in the background

2. Deploy to local network:
```bash
make deploy-local
```

3. Stop the local blockchain when done:
```bash
make stop-anvil
```

Note: Local deployment uses Anvil's default private key for convenience. Never use this key in production.

## Setting up Secure Deployment Keys

1. Generate a new wallet:

```bash
make new-wallet
```

2. Import the private key to an encrypted keystore:

```bash
make import-wallet
```

Follow the prompts to:
- Enter your private key
- Set a strong password (20+ characters)

3. List available keystores:

```bash
make list-wallets
```

4. Set up your environment:
- Copy `.env.example` to `.env`
- Fill in your RPC URLs and API keys
- Set your `KEYSTORE_NAME` and `KEYSTORE_PASSWORD`

## Deploying

1. To deploy to Mumbai testnet:

```bash
make deploy-mumbai
```

2. To deploy to Polygon mainnet:

```bash
make deploy-polygon
```

## Security Best Practices

1. **Keystore Password**:
- Use a strong password (20+ characters)
- Never store the password in plaintext
- Consider using a password manager

2. **Environment Security**:
- Never commit `.env` file
- Use different keys for testnet and mainnet
- Clear environment variables after use
54 changes: 52 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ WMATIC_MUMBAI := 0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889
ATLAS_POLYGON := 0x0
ATLAS_MUMBAI := 0x0

# Keystore configuration
KEYSTORE_PATH ?= ${HOME}/.foundry/keystores
KEYSTORE_NAME ?= deployer

# Build & Test
.PHONY: build test clean

Expand All @@ -30,33 +34,63 @@ test:
clean:
forge clean

# Keystore management
.PHONY: new-wallet import-wallet list-wallets

new-wallet:
@echo "Generating new wallet..."
@cast wallet new

import-wallet:
@echo "Importing wallet to keystore..."
@mkdir -p ${KEYSTORE_PATH}
@cast wallet import ${KEYSTORE_NAME} --interactive

list-wallets:
@echo "Available keystores:"
@ls -la ${KEYSTORE_PATH}

# Deployment commands
.PHONY: deploy-polygon deploy-mumbai deploy-local

deploy-polygon:
@if [ -z "${KEYSTORE_PASSWORD}" ]; then \
echo "Error: KEYSTORE_PASSWORD is required"; \
exit 1; \
fi
@echo "Deploying to Polygon Mainnet..."
forge script script/deploy.s.sol:DeployScript \
--rpc-url $(RPC_POLYGON) \
--broadcast \
--verify \
--etherscan-api-key ${POLYGONSCAN_API_KEY} \
--account ${KEYSTORE_NAME} \
--password ${KEYSTORE_PASSWORD} \
--with-gas-price $$(cast gas-price) \
-vvvv

deploy-mumbai:
@if [ -z "${KEYSTORE_PASSWORD}" ]; then \
echo "Error: KEYSTORE_PASSWORD is required"; \
exit 1; \
fi
@echo "Deploying to Mumbai Testnet..."
forge script script/deploy.s.sol:DeployScript \
--rpc-url $(RPC_MUMBAI) \
--broadcast \
--verify \
--etherscan-api-key ${POLYGONSCAN_API_KEY} \
--account ${KEYSTORE_NAME} \
--password ${KEYSTORE_PASSWORD} \
-vvvv

deploy-local:
deploy-local: anvil
@echo "Deploying to local network..."
@echo "Using default anvil private key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
forge script script/deploy.s.sol:DeployScript \
--rpc-url $(RPC_LOCAL) \
--broadcast \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
-vvvv

# Helper commands
Expand All @@ -73,4 +107,20 @@ update-deps:
# Environment setup
.PHONY: setup

setup: install-deps build
setup: install-deps build

# Local chain management
.PHONY: anvil stop-anvil

# Start local chain
anvil:
@echo "Starting local chain..."
@anvil --port 8545 > anvil.log 2>&1 & echo $$! > anvil.pid

# Stop local chain
stop-anvil:
@if [ -f anvil.pid ]; then \
echo "Stopping local chain..."; \
kill -9 `cat anvil.pid`; \
rm anvil.pid anvil.log; \
fi
Loading

0 comments on commit b498dd9

Please sign in to comment.