Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Draft of the make templating #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ LEDGER_SENDER=
# Deployment via private key
PRIVATE_KEY=

# Test rpc_endpoints
# Configuration of rpc_endpoints
#Prod
RPC_MAINNET=https://rpc.flashbots.net
RPC_AVALANCHE=https://api.avax.network/ext/bc/C/rpc
RPC_OPTIMISM=https://mainnet.optimism.io
RPC_POLYGON=https://polygon-rpc.com
RPC_ARBITRUM=https://arb1.arbitrum.io/rpc
RPC_FANTOM=https://rpc.ftm.tools
RPC_HARMONY=https://api.harmony.one
#Testnet
RPC_TESTNET=https://rpc-goerli.flashbots.net
RPC_AVALANCHE_TESTNET=https://api.avax-test.network/ext/bc/C/rpc

# Etherscan api keys for verification & download utils
#Prod
ETHERSCAN_API_KEY_MAINNET=
ETHERSCAN_API_KEY_POLYGON=
ETHERSCAN_API_KEY_AVALANCHE=
ETHERSCAN_API_KEY_FANTOM=
ETHERSCAN_API_KEY_OPTIMISM=
ETHERSCAN_API_KEY_ARBITRUM=
#Testnet
ETHERSCAN_API_KEY_TESTNET=
ETHERSCAN_API_KEY_AVALANCHE_TESTNET=
45 changes: 42 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,51 @@
# deps
update:; forge update

# Build & test
build :; forge build --sizes --via-ir
test :; forge test -vvv

# Utilities
download :; cast etherscan-source --chain ${chain} -d src/etherscan/${chain}_${address} ${address}
git-diff :
@mkdir -p diffs
@printf '%s\n%s\n%s\n' "\`\`\`diff" "$$(git diff --no-index --diff-algorithm=patience --ignore-space-at-eol ${before} ${after})" "\`\`\`" > diffs/${out}.md


# Build & test
build :; forge build --sizes --via-ir
test :; forge test -vvv

# Base script configuration
BASE_LEDGER = --legacy --ledger --mnemonic-indexes $(MNEMONIC_INDEX) --sender $(LEDGER_SENDER)
BASE_KEY = --private-key ${PRIVATE_KEY}

custom_ethereum-testnet := --gas-estimate-multiplier 200

# params:
# 1 - path/file_name
# 2 - network name
# 3 - script to call if not the same as network name (optional)
# To define custom params per network add vars custom_network-name.
# To use ledger, set LEDGER=true to env.
# By default deploys to the chains specified in (3),
# if your contracts are testnet agnostic, set TESTNET=true to env, it will change network names to network_name-testnet
define deploy_single_fn
forge script \
scripts/$(1).s.sol:$(if $(3),$(3),$(shell UP=$(2); echo $${UP} | perl -nE 'say ucfirst')) \
--rpc-url $(if $(TESTNET),$(2)-testnet,$(2)) --broadcast --verify -vvvv \
$(if $(LEDGER),$(BASE_LEDGER),$(BASE_KEY)) \
$(custom_$(if $(TESTNET),$(2)-testnet,$(2)))

endef

define deploy_fn
$(foreach network,$(2),$(call deploy_single_fn,$(1),$(network),$(3)))
endef


# Deployment scripts

# Deploy Ghost on all networks
deploy-ghost-multi-chain:
$(call deploy_fn,Ghost,ethereum avalanche)

deploy-ghost-custom:
$(call deploy_fn,Ghost,ethereum,CustomDeploy)
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,40 @@ forge install
forge test
```

## Deploy templating via Makefile

### Multichain deployment

In case of the multichain deployment we recommend to name scripts with the same name as the network you deploy.

For example if you will define
```Makefile
deploy-ghost-multi-chain:
$(call deploy_fn,Ghost,ethereum avalanche)
```
And then execute
```sh
make deploy-ghost-multi-chain
```
It will execute `Mainnet` and `Avalanche` scripts located at `scripts/Ghost.s.sol`
which will deploy `Ghost` contract to `ethereum` and `avalanche` networks respectfully

### Custom deployment

If you want to put a custom name for your deployment script

```Makefile
deploy-ghost-custom:
$(call deploy_fn,Ghost,ethereum,CustomDeploy)
```
And then execute
```sh
make deploy-ghost-custom
```

It will execute `CustomDeploy` script located at `scripts/Ghost.s.sol`
which will deploy `Ghost` contract to `ethereum`network

## Advanced features

### Diffing
Expand Down
9 changes: 9 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ remappings = [
fs_permissions = [{access = "write", path = "./reports"}]

[rpc_endpoints]
# Prod
mainnet = "${RPC_MAINNET}"
optimism = "${RPC_OPTIMISM}"
avalanche = "${RPC_AVALANCHE}"
polygon = "${RPC_POLYGON}"
arbitrum = "${RPC_ARBITRUM}"
fantom = "${RPC_FANTOM}"
harmony = "${RPC_HARMONY}"
# Test
mainnet-testnet = "${RPC_TESTNET}"
avalanche-testnet = "${RPC_AVALANCHE_TESTNET}"

[etherscan]
# Prod
mainnet={key="${ETHERSCAN_API_KEY_MAINNET}",chainId=1}
optimism={key="${ETHERSCAN_API_KEY_OPTIMISM}",chainId=10}
avalanche={key="${ETHERSCAN_API_KEY_AVALANCHE}",chainId=43114}
polygon={key="${ETHERSCAN_API_KEY_POLYGON}",chainId=137}
arbitrum={key="${ETHERSCAN_API_KEY_ARBITRUM}",chainId=42161}
fantom={key="${ETHERSCAN_API_KEY_FANTOM}",chainId=250}
# Test
mainnet-testnet={key="${ETHERSCAN_API_KEY_TESTNET}",chainId=1}
avalanche-testnet={key="${ETHERSCAN_API_KEY_AVALANCHE_TESTNET}"}


# See more config options https://github.com/gakonst/foundry/tree/master/config
18 changes: 17 additions & 1 deletion scripts/Ghost.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ pragma solidity ^0.8.0;
import {Script} from 'forge-std/Script.sol';
import {Ghost} from '../src/contracts/Ghost.sol';

contract Deploy is Script {
contract Ethereum is Script {
function run() external {
vm.startBroadcast();
new Ghost();
vm.stopBroadcast();
}
}

contract Avalanche is Script {
function run() external {
vm.startBroadcast();
new Ghost();
vm.stopBroadcast();
}
}

contract CustomDeploy is Script {
function run() external {
vm.startBroadcast();
new Ghost();
Expand Down