Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ typechain-types
.idea
.DS_Store
*.log
.env*
*.tgz
90 changes: 90 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
## CONTRACTS DEPLOYMENT

For automatic deployment, we use `make` and Makefiles. The Makefile manages the deployment and configuration of various smart contracts and helpers, including targets for installing dependencies, deploying contracts, and managing environment variables.

## QUICK START

1. Run `make install`
2. Create `.env` file with the following variables:
- Set OPS_NETWORK (e.g., mainnet, goerli, unichain)
- Set OPS_CHAIN_ID (use `make show-chain-config` to find the chain ID for your network)
- Set OPS_REG_TYPE if using custom networks
- Set other optional variables as needed
3. Run `make run`

## ENVIRONMENT VARIABLES

The Makefile supports loading environment variables from either `.env` or `.env.automation` based on the `OPS_LAUNCH_MODE` environment variable:
- If `OPS_LAUNCH_MODE=auto`, it loads `.env.automation`
- Otherwise, it loads `.env`

| Variable | Description |
|----------------------------|-----------------------------------------------------|
| OPS_REG_TYPE | Registration type (e.g., custom) |
| OPS_NETWORK | Network name (e.g., mainnet, goerli) - REQUIRED |
| OPS_CHAIN_ID | Chain ID for the network - REQUIRED |
| OPS_ETHERSCAN_NETWORK_NAME | (Optional) Etherscan network name (e.g., mainnet) |
| OPS_API_URL | (Optional) Custom API URL for the network |
| OPS_BROWSER_URL | (Optional) Custom browser URL for the network |
| OPS_HARDFORK | (Optional) Hardfork to use (e.g., london) |
| OPS_L1_NETWORK | (Optional) L1 network name |

### Example of .env file for custom network config:

```env
OPS_REG_TYPE=custom
OPS_NETWORK=unichain
OPS_CHAIN_ID=130
OPS_ETHERSCAN_NETWORK_NAME=
OPS_API_URL=https://api.uniscan.xyz/api
OPS_BROWSER_URL=https://uniscan.xyz/
OPS_HARDFORK=shanghai
OPS_L1_NETWORK=
```

### Example of .env file for mainnet:

```env
OPS_REG_TYPE=
OPS_NETWORK=mainnet
OPS_CHAIN_ID=1
OPS_ETHERSCAN_NETWORK_NAME=mainnet
OPS_API_URL=
OPS_BROWSER_URL=
OPS_HARDFORK=
OPS_L1_NETWORK=
```

## MAKEFILE TARGETS

Here is a list of Makefile targets you can use by running `make <target-name>` in the terminal:

- `install` - Installs utilities and project dependencies (runs install-utils and install-dependencies).
- `install-utils` - Installs required system utilities (yarn, wget) using Homebrew.
- `install-dependencies` - Installs project dependencies using yarn.
- `run` - Runs the setup for the specified network. Validates that OPS_NETWORK and OPS_CHAIN_ID are set, then updates network configuration and increments version.
- `show-chain-config` - Downloads chain configuration from Hardhat and ChainList to help find the chain ID for your network.
- `update-networks` - Adds the specified network configuration to hardhat-setup/networks.ts if it doesn't already exist.
- `update-ver` - Increments the minor version in package.json using npm version minor.
- `help` - Shows all available make targets with descriptions.

## NETWORK CONFIGURATION

The Makefile automatically generates network registration code based on your environment variables:

For standard networks:
```typescript
this.register("networkName", chainId, process.env.NETWORKNAME_RPC_URL, process.env.NETWORKNAME_PRIVATE_KEY || privateKey, process.env.NETWORKNAME_ETHERSCAN_KEY);
```

For custom networks:
```typescript
this.registerCustom("networkName", chainId, process.env.NETWORKNAME_RPC_URL, process.env.NETWORKNAME_PRIVATE_KEY || privateKey, process.env.NETWORKNAME_ETHERSCAN_KEY, "apiUrl", "browserUrl");
```

The environment variable names are automatically generated from the network name by converting to uppercase and replacing camelCase with underscores (e.g., `unichain` becomes `UNICHAIN_`, `baseMainnet` becomes `BASE_MAINNET_`).

## TODO

- logging
- error handling
137 changes: 137 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Conditionally include .env or .env.automation based on OPS_LAUNCH_MODE
ifeq ($(OPS_LAUNCH_MODE),auto)
-include .env.automation
else
-include .env
endif
export

OPS_NETWORK:=$(subst ",,$(OPS_NETWORK))
OPS_CHAIN_ID:=$(subst ",,$(OPS_CHAIN_ID))
OPS_REG_TYPE:=$(subst ",,$(OPS_REG_TYPE))
OPS_ETHERSCAN_NETWORK_NAME:=$(subst ",,$(OPS_ETHERSCAN_NETWORK_NAME))
OPS_API_URL:=$(subst ",,$(OPS_API_URL))
OPS_BROWSER_URL:=$(subst ",,$(OPS_BROWSER_URL))
OPS_HARDFORK:=$(subst ",,$(OPS_HARDFORK))
OPS_L1_NETWORK:=$(subst ",,$(OPS_L1_NETWORK))

CURRENT_DIR=$(shell pwd)
ENV_FILE=$(CURRENT_DIR)/.env
NETWORKS_FILE=$(CURRENT_DIR)/hardhat-setup/networks.ts
PACKAGE_FILE=$(CURRENT_DIR)/package.json
PREFIX=$(shell echo "$(OPS_NETWORK)" | sed -r 's/([a-z0-9])([A-Z])/\1_\2/g' | tr '[:lower:]' '[:upper:]')
REGOP_PREFIX=$(shell printf ' ')this.register

ifeq ($(OPS_REG_TYPE),custom)
REGOP_TYPE=Custom

ifneq ($(OPS_API_URL),)
REGOP_API_URL=, \"$(OPS_API_URL)\"
endif

ifneq ($(OPS_BROWSER_URL),)
REGOP_BROWSER_URL=, \"$(OPS_BROWSER_URL)\"
endif
else
ifneq ($(OPS_ETHERSCAN_NETWORK_NAME),)
REGOP_ETHERSCAN_NETWORK_NAME=, \"$(OPS_ETHERSCAN_NETWORK_NAME)\"
endif

ifneq ($(OPS_L1_NETWORK),)
REGOP_L1_NETWORK=, \"$(OPS_L1_NETWORK)\"
endif
endif

ifneq ($(OPS_HARDFORK),)
REGOP_HARDFORK=, \"$(OPS_HARDFORK)\"
endif

REGOP_ENV_PREFIX=process.env.
REGOP_ENV_RPC_URL=$(PREFIX)_RPC_URL
REGOP_ENV_PK=$(PREFIX)_PRIVATE_KEY
REGOP_ENV_ETHERSCAN_KEY=etherscanApiKey

REGOP=$(REGOP_PREFIX)$(REGOP_TYPE)(\"$(OPS_NETWORK)\", $(OPS_CHAIN_ID), $(REGOP_ENV_PREFIX)$(REGOP_ENV_RPC_URL), $(REGOP_ENV_PREFIX)$(REGOP_ENV_PK) || privateKey$(REGOP_ETHERSCAN_NETWORK_NAME), $(REGOP_ENV_ETHERSCAN_KEY)$(REGOP_API_URL)$(REGOP_BROWSER_URL)$(REGOP_HARDFORK)$(REGOP_L1_NETWORK));

install: install-utils install-dependencies

install-utils:
brew install yarn wget

install-dependencies:
yarn

run:
@{ \
if [ -z "$(OPS_NETWORK)" ]; then \
echo "Please set OPS_NETWORK environment variable!"; \
exit 1; \
fi; \
if [ -z "$(OPS_CHAIN_ID)" ]; then \
echo "Please set OPS_CHAIN_ID environment variable!"; \
exit 1; \
fi; \
echo "Running setup for network: $(OPS_NETWORK) with chain ID: $(OPS_CHAIN_ID):"; \
make update-networks; \
echo "Setup completed successfully!"; \
}

URL_CHAIN_CONFIG=https://raw.githubusercontent.com/NomicFoundation/hardhat/refs/heads/main/packages/hardhat-verify/src/internal/chain-config.ts
URL_CHAIN_LIST=https://chainlist.org/rpcs.json

show-chain-config:
@wget -q -O chain-config.ts $(URL_CHAIN_CONFIG)
@echo "Getting chain ID for network: $(OPS_NETWORK) from $(URL_CHAIN_CONFIG)"
@if grep -q "network: \"$(OPS_NETWORK)\"" chain-config.ts; then \
echo "Use OPS_CHAIN_ID=$$(grep -A 1 "network: \"$(OPS_NETWORK)\"" chain-config.ts | sed -nE 's/ chainId: ([0-9]*),/\1/p') in your .env file"; \
else \
echo "Network $(OPS_NETWORK) not found in chain-config.ts"; \
fi
@rm -f chain-config.ts
@wget -q -O rpcs.json $(URL_CHAIN_LIST)
@echo "Getting chain ID for network: $(OPS_NETWORK) from $(URL_CHAIN_LIST)"
@if grep -q "\"shortName\": \"$(OPS_NETWORK)\"" rpcs.json; then \
echo "Use OPS_CHAIN_ID=$$(grep -A 1 "\"shortName\": \"$(OPS_NETWORK)\"" rpcs.json | sed -nE 's/.*"chainId": ([0-9]*),/\1/p') in your .env file"; \
else \
echo "Network $(OPS_NETWORK) not found in rpcs.json"; \
fi
@rm -f rpcs.json

update-networks:
@{ \
if [ -z "$(OPS_NETWORK)" ]; then \
echo "Please set OPS_NETWORK environment variable!"; \
exit 1; \
fi; \
if [ -z "$(OPS_CHAIN_ID)" ]; then \
echo "Please set OPS_CHAIN_ID environment variable!"; \
exit 1; \
fi; \
if grep -q "this.register('$(OPS_NETWORK)'" $(NETWORKS_FILE) || grep -q "this.registerCustom('$(OPS_NETWORK)'" $(NETWORKS_FILE); then \
echo "Network already exists!"; \
else \
echo "Adding network $(OPS_NETWORK) with chain ID $(OPS_CHAIN_ID) to $(NETWORKS_FILE)"; \
echo "The next network configuration will be added to $(NETWORKS_FILE): $(REGOP)"; \
tmpfile=$$(mktemp); \
awk '1;/\[\[AUTOMATION\]\]/{print "$(REGOP)"}' $(NETWORKS_FILE) > $$tmpfile; \
sed -i '' 's/"/'\''/g' $$tmpfile; \
mv $$tmpfile $(NETWORKS_FILE); \
npm version minor --force; \
fi; \
}

update-ver:
@npm version minor --force; \

help:
@echo "Available targets:"
@echo " install Install utilities and dependencies"
@echo " install-utils Install required utilities (yarn, wget)"
@echo " install-dependencies Install project dependencies with yarn"
@echo " run Run setup for the specified network"
@echo " show-chain-config Show chain ID for the specified network"
@echo " update-networks Add network configuration to networks.ts"
@echo " update-ver Update version in package.json"
@echo " help Show this help message"

.PHONY: install install-utils install-dependencies run show-chain-config update-networks update-ver help
3 changes: 3 additions & 0 deletions hardhat-setup/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export class Networks {
// For 'zksyncFork' network you should use zksync fork node: https://github.com/matter-labs/era-test-node
this.register('zksyncFork', 260, process.env.ZKSYNC_FORK_RPC_URL, process.env.ZKSYNC_FORK_PRIVATE_KEY || privateKey, 'zksyncfork', 'none', 'paris', process.env.ZKSYNC_LOCAL_ETH_NETWORK || 'mainnet');
this.register('zksyncLocal', 270, process.env.ZKSYNC_LOCAL_RPC_URL, process.env.ZKSYNC_PRIVATE_KEY || privateKey, 'zksynclocal', 'none', 'paris', process.env.ZKSYNC_LOCAL_ETH_NETWORK);

// [[AUTOMATION]]

/* eslint-enable max-len */
return { networks: this.networks, etherscan: this.etherscan };
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/solidity-utils",
"version": "6.7.1",
"version": "6.7.2",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"exports": {
Expand Down Expand Up @@ -49,7 +49,6 @@
"dotenv": "16.4.5",
"ethereumjs-util": "7.1.5",
"ethers": "6.13.4",
"hardhat": "2.23.0",
"hardhat-deploy": "0.14.0",
"mocha-chai-jest-snapshot": "1.1.6",
"node-fetch": "2.7.0"
Expand All @@ -72,6 +71,7 @@
"eslint-plugin-import": "2.31.0",
"eslint-plugin-n": "17.12.0",
"eslint-plugin-promise": "7.1.0",
"hardhat": "2.23.0",
"hardhat-gas-reporter": "2.2.1",
"prettier": "3.3.3",
"prettier-plugin-solidity": "1.4.1",
Expand Down
Loading