Skip to content

Commit

Permalink
Merge pull request #29 from shapeshift/deployment-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Apr 17, 2024
2 parents 35dde7c + 1dc2114 commit 415780a
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 49 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1.2.0

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge clean
forge test -vvv
id: test
- name: Generate coverage report
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ node_modules

# misc
.DS_Store

# .env files
.env
.env.local
.env.mainnet
.env.sepolia
.env.arbitrum-one
.env.arbitrum-sepolia

# logs
npm-debug.log*
Expand Down
5 changes: 5 additions & 0 deletions foundry/.env.arbitrum-one.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ETHERSCAN_API_KEY="" # this must be an arbiscan api key
FOX_TOKEN_ADDRESS=""
PRIVATE_KEY=""
RPC_URL="https://arbitrum-mainnet.infura.io/v3/<INFURA_API_KEY>"
VERIFIER_URL="https://api.arbiscan.io/api"
5 changes: 5 additions & 0 deletions foundry/.env.arbitrum-sepolia.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ETHERSCAN_API_KEY="" # this must be an arbiscan api key
FOX_TOKEN_ADDRESS=""
PRIVATE_KEY=""
RPC_URL="https://arbitrum-sepolia.infura.io/v3/<INFURA_API_KEY>"
VERIFIER_URL="https://api-sepolia.arbiscan.io/api"
5 changes: 5 additions & 0 deletions foundry/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ETHERSCAN_API_KEY="not-required"
FOX_TOKEN_ADDRESS="0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d"
PRIVATE_KEY=""
RPC_URL="http://localhost:8545"
VERIFIER_URL="not-required"
5 changes: 5 additions & 0 deletions foundry/.env.mainnet.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ETHERSCAN_API_KEY=""
FOX_TOKEN_ADDRESS="0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d"
PRIVATE_KEY=""
RPC_URL="https://mainnet.infura.io/v3/<INFURA_API_KEY>"
VERIFIER_URL="https://api.etherscan.io/api"
5 changes: 5 additions & 0 deletions foundry/.env.sepolia.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ETHERSCAN_API_KEY=""
FOX_TOKEN_ADDRESS=""
PRIVATE_KEY=""
RPC_URL="https://sepolia.infura.io/v3/<INFURA_API_KEY>"
VERIFIER_URL="https://api-sepolia.etherscan.io/api"
6 changes: 2 additions & 4 deletions foundry/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
# Ignores broadcast logs
/broadcast

# Docs
docs/
Expand Down
86 changes: 47 additions & 39 deletions foundry/README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,74 @@
## Foundry
# rFOX

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
## Setup

Foundry consists of:
1. Install foundry https://book.getfoundry.sh/getting-started/installation
2. Install slither `brew install slither-analyzer`
3. Set up .env files:
1. Copy an example .env file for your chosen environment:
```shell
cp .env.<your-chosen-env>.example .env.<your-chosen-env>
```
2. Fill in the needed env vars there

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
### Private key

## Documentation

https://book.getfoundry.sh/

## Usage

### Build
To derive a private key 0 from your mnemonic:

```shell
$ forge build
cast wallet derive-private-key <YOUR_MNEMONIC> 0
```

### Test
### Faucets

```shell
$ forge test
```
**Arbitrum sepolia**

### Format
Grab some ETH:
https://www.l2faucet.com/arbitrum

```shell
$ forge fmt
```
Grab some USDC:
https://faucet.circle.com/

### Gas Snapshots
## Deploying

```shell
$ forge snapshot
```
### Local deployment
Deploying locally is different to deploying directly to a network for 2 reasons:
1. Its being deployed to a fork of another network (typically ethereum mainnet) rather than a real network.
2. There's no local instance of etherscan, so etherscan verification is skipped.
### Anvil
When deploying locally, it's necessary to start a local fork before deploying:

```shell
$ anvil
# RPC_URL for your env can be accessible with `source .env.<your-chosen-env`.
anvil --rpc-url $RPC_URL
```

### Deploy
### Deployment steps

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```
cd foundry
### Cast
# Install
forge install
```shell
$ cast <subcommand>
# Deploy
./deploy.sh --env <your-chosen-env>
# Test the proxy contract has been deployed with the correct version.
# RPC_URL for your env can be accessible with `source .env.<your-chosen-env`.
cast call <CONTRACT_PROXY_ADDRESS> "version()(uint256)" --rpc-url $RPC_URL
```

### Help
### Manually verifying

If contract verification fails for any reason, you can verify without re-deploying:

```shell
$ forge --help
$ anvil --help
$ cast --help
forge verify-contract \
--verifier etherscan \
--verifier-url https://api-sepolia.arbiscan.io/api \
--compiler-version "v0.8.25" \
--etherscan-api-key $ARBISCAN_API_KEY \
$CONTRACT_IMPLEMENTATION_ADDRESS \
src/FoxStakingV1.sol:FoxStakingV1
```
54 changes: 54 additions & 0 deletions foundry/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Load generic environment variables
source .env

# Parse command line options
while [[ "$#" -gt 0 ]]; do
case $1 in
--env) ENVIRONMENT="$2"; shift ;; # Shift past the value
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift # Shift past the current key or value
done

# Path to the environment file
ENV_FILE=".env.$ENVIRONMENT"

# Check if the environment file exists
if [ ! -f "$ENV_FILE" ]; then
echo "Environment file $ENV_FILE does not exist."
exit 1
fi

# Source environment variables
source $ENV_FILE

# Echo back the environment for verification
echo "Deploying to $ENVIRONMENT environment with settings from '$ENV_FILE'..."

# Deployment-related commands
echo "Running deployment tasks..."

# Clean the build directory
forge clean

if [ "$ENVIRONMENT" = "local" ]; then
# Local environment-specific commands (no etherscan verification)
FOX_TOKEN_ADDRESS="$FOX_TOKEN_ADDRESS" forge script script/DeployFoxStaking.s.sol:DeployFoxStaking \
--fork-url $RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
-vvvvv
else
# All other environments use etherscan verification (which automatically reroutes to arbiscan as needed)
FOX_TOKEN_ADDRESS="$FOX_TOKEN_ADDRESS" forge script script/DeployFoxStaking.s.sol:DeployFoxStaking \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
-vvvvv \
--verify \
--verifier etherscan \
--verifier-url $VERIFIER_URL \
--etherscan-api-key $ETHERSCAN_API_KEY
fi
25 changes: 25 additions & 0 deletions foundry/script/DeployFoxStaking.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25;

import "forge-std/Script.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {FoxStakingV1} from "../src/FoxStakingV1.sol";

contract DeployFoxStaking is Script {
address foxTokenAddress;

function setUp() public {
foxTokenAddress = vm.envAddress("FOX_TOKEN_ADDRESS");
}

function run() public {
vm.startBroadcast();
address foxStakingProxy = Upgrades.deployUUPSProxy(
"FoxStakingV1.sol",
abi.encodeCall(FoxStakingV1.initialize, (foxTokenAddress))
);
vm.stopBroadcast();
console.log("Contract deployed at:", foxStakingProxy);
}
}

0 comments on commit 415780a

Please sign in to comment.