Skip to content

Commit

Permalink
Deployment Script (storyprotocol#15)
Browse files Browse the repository at this point in the history
* feat: foundry deploy script w/ hardhat wip

* feat: fix foundry deploy script

* feat: makefile abi & typechain

* feat: hardhat scripts

* fix: delete ignore folder

* feat: script deployments and mocks

* fix: package deps

* fix: ignore folders

* feat: deploy & revert scripts
  • Loading branch information
jdubpark authored Jan 23, 2024
1 parent 285dbbb commit ca16637
Show file tree
Hide file tree
Showing 33 changed files with 1,171 additions and 83 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ forge-cache/

# Ignores development broadcast logs
!/broadcast
# ignore 1 for now, it's tenderly fork
/broadcast/*/1/
/broadcast/*/31337/
/broadcast/**/dry-run/

Expand All @@ -24,3 +26,11 @@ node_modules/
pnpm-lock.yaml

coverage

# contracts
abi
typechain
!./script/out

# hardhat-tenderly plugin
deployments
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
"tabWidth": 4,
"semi": false,
"singleQuote": false,
"bracketSpacing": true
"bracketSpacing": true,
"overrides": [
{
"files": ["*.ts", "*.js"],
"options": {
"tabWidth": 2
}
}
]
}
41 changes: 37 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
-include .env

.PHONY: all test clean coverage
.PHONY: all test clean coverage typechain deploy-main

all: clean install build

# function: generate abi for given contract name (key)
# requires contract name to match the file name
define generate_abi
$(eval $@_CONTRACT_NAME = $(1))
$(eval $@_CONTRACT_PATH = $(2))
forge inspect --optimize --optimizer-runs 2000 contracts/${$@_CONTRACT_PATH}/${$@_CONTRACT_NAME}.sol:${$@_CONTRACT_NAME} abi > abi/${$@_CONTRACT_NAME}.json
endef

# Clean the repo
forge-clean :; forge clean
forge-clean :; forge clean
clean :; npx hardhat clean

# Remove modules
Expand All @@ -14,9 +22,9 @@ forge-remove :; rm -rf .gitmodules && rm -rf .git/modules/* && rm -rf lib && tou
install :; npm install

# Update Dependencies
forge-update:; forge update
forge-update :; forge update

forge-build:; forge build
forge-build :; forge build
build :; npx hardhat compile

test :; forge test
Expand All @@ -33,6 +41,24 @@ coverage:
lcov --remove lcov.info -o lcov.info 'test/*'
genhtml lcov.info --output-dir coverage

abi:
mkdir -p abi
@$(call generate_abi,"AccessController",".")
@$(call generate_abi,"DisputeModule","./modules/dispute-module")
@$(call generate_abi,"RoyaltyModule","./modules/royalty-module")
@$(call generate_abi,"TaggingModule","./modules/tagging")
@$(call generate_abi,"IPAccountRegistry","./registries")
@$(call generate_abi,"IPRecordRegistry","./registries")
@$(call generate_abi,"LicenseRegistry","./registries")
@$(call generate_abi,"ModuleRegistry","./registries")
@$(call generate_abi,"IPMetadataResolver","./resolvers")

# typechain:
# make abi
# rm -rf ./types-typechain
# npx typechain --target ethers-v6 ./abi/*.json --out-dir ./types-typechain
typechain :; npx hardhat typechain

# solhint should be installed globally
lint :; npx solhint contracts/**/*.sol && npx solhint contracts/*.sol

Expand All @@ -41,3 +67,10 @@ verify-goerli :; npx hardhat verify --network goerli ${contract}

anvil :; anvil -m 'test test test test test test test test test test test junk'

# run: RPC_URL=https://rpc.url make deploy-main
deploy-main :; forge script script/foundry/deployment/Main.s.sol:Main --rpc-url ${RPC_URL} --broadcast --verify -vvvv

deploy-main-hh:
rm -rf deployments/hardhat/*.json
npx hardhat run script/hardhat/post-deployment/99-revert-chain.ts --network tenderly
npx hardhat run script/hardhat/deployment/00-deploy-main.ts --network tenderly
16 changes: 16 additions & 0 deletions contracts/mocks/MockERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockERC20 is ERC20 {
constructor() ERC20("MockERC20", "MERC20") {}

function mint(address to, uint256 amount) external {
_mint(to, amount);
}

function burn(address from, uint256 amount) external {
_burn(from, amount);
}
}
31 changes: 31 additions & 0 deletions contracts/mocks/MockERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MockERC721 is ERC721 {
uint256 private _counter;

constructor() ERC721("MockERC721", "M721") {
_counter = 0;
}

function mint(address to) public returns (uint256 tokenId) {
tokenId = ++_counter;
_safeMint(to, tokenId);
return tokenId;
}

function mintId(address to, uint256 tokenId) public returns (uint256) {
_safeMint(to, tokenId);
return tokenId;
}

function burn(uint256 tokenId) public {
_burn(tokenId);
}

function transferFrom(address from, address to, uint256 tokenId) public override {
_transfer(from, to, tokenId);
}
}
10 changes: 10 additions & 0 deletions deploy-out/deployment-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"main": {
"AccessController": "0xE2307e3710d108ceC7a4722a020a050681c835b3",
"ERC6551Registry": "0xD28F3246f047Efd4059B24FA1fa587eD9fa3e77F",
"IPAccountImpl": "0x15F2ea83eB97ede71d84Bd04fFF29444f6b7cd52",
"IPAccountRegistry": "0x519b05b3655F4b89731B677d64CEcf761f4076f6",
"LicenseRegistry": "0x057cD3082EfED32d5C907801BF3628B27D88fD80",
"ModuleRegistry": "0x0B32a3F8f5b7E5d315b9E52E640a49A89d89c820"
}
}
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ optimizer = true
optimizer_runs = 20000
test = 'test'
solc = '0.8.23'
fs_permissions = [{ access = 'read-write', path = './deployments' }]

[rpc_endpoints]
# Comment out for local development (testing requires 0xSplit forks — will add Mock soon)
Expand Down
73 changes: 0 additions & 73 deletions hardhat.config.js

This file was deleted.

109 changes: 109 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import "@nomicfoundation/hardhat-foundry"
import "@nomiclabs/hardhat-waffle"
import "@nomiclabs/hardhat-ethers"
import "@nomicfoundation/hardhat-verify"
import "@tenderly/hardhat-tenderly"
import * as tdly from "@tenderly/hardhat-tenderly" // also import tdly for setup, in addition to global import above
import "@typechain/hardhat"
// import "@openzeppelin/hardhat-upgrades"
import "hardhat-gas-reporter"
import "solidity-coverage"
import "hardhat-deploy"
import { HardhatConfig, HardhatUserConfig } from "hardhat/types"
import "hardhat-contract-sizer" // npx hardhat size-contracts

require("dotenv").config()

tdly.setup({
automaticVerifications: true,
})

//
// NOTE:
// To load the correct .env, you must run this at the root folder (where hardhat.config is located)
//
const MAINNET_URL = process.env.MAINNET_URL || "https://eth-mainnet"
const MAINNET_PRIVATEKEY = process.env.MAINNET_PRIVATEKEY || "0xkey"
const GOERLI_URL = process.env.GOERLI_URL || "https://eth-goerli"
const GOERLI_PRIVATEKEY = process.env.GOERLI_PRIVATEKEY || "0xkey"

const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "key"

const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "key"

/** @type import('hardhat/config').HardhatUserConfig */
const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: "0.8.18",
},
{
version: "0.8.23",
},
],
settings: {
optimizer: {
enabled: true,
runs: 2000,
},
},
},
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts",
},
defaultNetwork: "tenderly",
networks: {
hardhat: {
chainId: 31337,
},
localhost: {
chainId: 31337,
url: "http://127.0.0.1:8545/",
},
tenderly: {
url: MAINNET_URL || "",
chainId: 1,
accounts: [MAINNET_PRIVATEKEY],
},
goerli: {
chainId: 5,
url: GOERLI_URL || "",
accounts: [GOERLI_PRIVATEKEY],
},
},
// @ts-ignore
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
outputFile: "gas-report.txt",
noColors: true,
currency: "USD",
coinmarketcap: COINMARKETCAP_API_KEY,
},
mocha: {
timeout: 20_000,
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
tenderly: {
project: process.env.TENDERLY_PROJECT_SLUG || "",
username: process.env.TENDERLY_USERNAME || "",
forkNetwork: 1, // fork mainnet
privateVerification: process.env.TENDERLY_PRIVATE_VERIFICATION === "true",
},
typechain: {
outDir: "typechain",
target: "ethers-v6",
},
}

export default config
22 changes: 22 additions & 0 deletions helper-hardhat-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ethers } from "ethers"

export interface networkConfigItem {
name?: string
blockConfirmations?: number
}

export interface networkConfigInfo {
[key: number]: networkConfigItem
}

export const networkConfig: networkConfigInfo = {
5: {
name: "goerli",
blockConfirmations: 6,
},
31337: {
name: "hardhat",
},
}

export const developmentChains = ["hardhat", "localhost"]
Loading

0 comments on commit ca16637

Please sign in to comment.