Skip to content

Commit

Permalink
imp(contracts): Improve make command to compile smart contracts (#2487)
Browse files Browse the repository at this point in the history
* add hardhat setup and gitignore

* move contracts into subdirectory for hardhat compilation

* add hardhat compiled contract type and corresponding test - move contracts into testdata subfolder

* add WIP go embedding for hardhat contract

* add wip for python script to compile all contracts

* commit wip scanning the repo for Solidity files

* wip

* move compiled JSON files next to Solidity files

* add compilation step

* adjust import path on ERC20NoMetadata contract

* check input args to either compile or clean

* adjust contract name on ERC20NoMetadata

* some fixes for the script

* adjust Makefile targets for smart contract compilation

* remove print statements

* adjust contracts in precompiles dir to work with new approach

* improvements to script

* adjust ERC20 contracts

* add README and --add option

* remove todo

* add script readme

* run black formatter

* adjust more linters

* add changelog entry

* more linter adjustments

* fix changelog and improve check message

* linters

* move flash loan contract into contracts directory

* move flash loan contract into testdata directory

* rename contracts subdirectory to solidity

* fix failure on other script tests

* run black formatter

* adjust imports on ERC20 go files

* remove contracts from being initialized in init functions to dedicated methods to load them

* remove unused burnable contract

* run gofumpt

* address linters

* address JS linter

* address more JS linters

* remove unused contracts and move things into test packages and testdata folders to clean up the production code

* run make format

* move contracts to test data

* Apply suggestions from code review

Co-authored-by: Ramiro Carlucho <ramirocarlucho@gmail.com>
Co-authored-by: stepit <48993133+0xstepit@users.noreply.github.com>
Signed-off-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>

* update tool readme

* refactor contract loading into utility and remove unnecessary go:embed usage in test contracts

* add missing licenses

* address JS linter

* address linters

* refactor file reading

* fixes after merging

* Apply suggestions from code review

Signed-off-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>

* refactor unmarshalling compiled bytes and use embed for necessary file again

* fix changelog

---------

Signed-off-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
Co-authored-by: MalteHerrmann <MalteHerrmann@users.noreply.github.com>
Co-authored-by: Ramiro Carlucho <ramirocarlucho@gmail.com>
Co-authored-by: stepit <48993133+0xstepit@users.noreply.github.com>
  • Loading branch information
4 people committed May 1, 2024
1 parent fe249a0 commit 91319d2
Show file tree
Hide file tree
Showing 78 changed files with 9,606 additions and 672 deletions.
17 changes: 9 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (deps) [#2355](https://github.com/evmos/evmos/pull/2355) Bump Cosmos-SDK to v0.47.8-evmos.
- (revenue) [#2379](https://github.com/evmos/evmos/pull/2379) Remove `x/revenue` module.
- (evm) [#2380](https://github.com/evmos/evmos/pull/2380) Remove EVM hooks from app and EVM module.
- (evm) [#2501](https://github.com/evmos/evmos/pull/2501) Revert deletion from EVM hooks (#2380)
- (erc20) [#2502](https://github.com/evmos/evmos/pull/2502) Revert deletion from EVM hooks (#2154) (#2442)
- (evm) [#2501](https://github.com/evmos/evmos/pull/2501) Revert deletion of EVM hooks (#2380).
- (erc20) [#2502](https://github.com/evmos/evmos/pull/2502) Revert deletion of EVM hooks (#2154) (#2442).
- (vesting) [#2507](https://github.com/evmos/evmos/pull/2507) Consider locked-up vested delegated coins in `LockedCoins` calculation.
- (erc20) [#2508](https://github.com/evmos/evmos/pull/2508) Add bookkeping logic in preparation for STRV2 upgrade
- (erc20) [#2508](https://github.com/evmos/evmos/pull/2508) Add bookkeping logic in preparation for STRV2 upgrade.

### Bug Fixes

Expand Down Expand Up @@ -91,9 +91,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (docs) [#2472](https://github.com/evmos/evmos/pull/2472) Update security policy.
- (docs) [#2478](https://github.com/evmos/evmos/pull/2478) Change Evmos SDK with evmOS.
- (build) [#2484](https://github.com/evmos/evmos/pull/2484) Bump golang version to v1.22.
- (client) [#2481](https://github.com/evmos/evmos/pull/2481) Replace path.Join with filepath.Join.
- (cli) [#2503](https://github.com/evmos/evmos/pull/2503) Revert deletion of ConvertCoin for erc20 module (#2155).
- (cli) [#2503](https://github.com/evmos/evmos/pull/2503) Revert deletion of ConvertCoin for ERC-20 module (#2155).
- (ibc) [#2504](https://github.com/evmos/evmos/pull/2504) Refactor repeated unpacking of IBC packet data.
- (make) [#2487](https://github.com/evmos/evmos/pull/2487) Improve make command to compile all smart contracts in repository.

## [v18.0.0](https://github.com/evmos/evmos/releases/tag/v18.0.0) - 2024-04-22

Expand Down Expand Up @@ -121,11 +121,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [v16.0.3](https://github.com/evmos/evmos/releases/tag/v16.0.3) - 2024-02-02

## Bug Fixes
### Bug Fixes

- (evm) [#2302](https://github.com/evmos/evmos/pull/2302) Fix TraceTx KVGasConfig setup
- (evm) [#2302](https://github.com/evmos/evmos/pull/2302) Fix TraceTx KVGasConfig setup.

## [v16.0.2] - 2024-01-16
## [v16.0.2](https://github.com/evmos/evmos/releases/tag/v16.0.2) - 2024-01-16

### Bug Fixes

Expand Down Expand Up @@ -995,3 +995,4 @@ Ref: https://keepachangelog.com/en/1.0.0/

- (cli) [#26](https://github.com/evmos/evmos/pull/26) Use config on genesis accounts.
- (deps) [#28](https://github.com/evmos/evmos/pull/28) Bump Ethermint version to `v0.7.0`.

66 changes: 17 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -545,56 +545,24 @@ release:
### Compile Solidity Contracts ###
###############################################################################

CONTRACTS_DIR := contracts
COMPILED_DIR := $(CONTRACTS_DIR)/compiled_contracts
TMP := tmp
TMP_CONTRACTS := $(TMP)/contracts
TMP_COMPILED := $(TMP)/compiled.json
TMP_JSON := $(TMP)/tmp.json

# Compile and format solidity contracts for the erc20 module. Also install
# openzeppeling as the contracts are build on top of openzeppelin templates.
contracts-compile: contracts-clean openzeppelin create-contracts-json

# Install openzeppelin solidity contracts
openzeppelin:
@echo "Importing openzeppelin contracts..."
@cd $(CONTRACTS_DIR) && \
npm install && \
mv node_modules $(TMP) && \
mv $(TMP)/@openzeppelin . && \
rm -rf $(TMP)

# Clean tmp files
# Clean up the contracts directory, install the necessary dependencies
# and then compile the solidity contracts found in the Evmos repository.
contracts-all: contracts-clean contracts-compile

# Clean smart contract compilation artifacts, dependencies and cache files
contracts-clean:
@rm -rf $(CONTRACTS_DIR)/$(TMP)
@rm -rf $(CONTRACTS_DIR)/node_modules
@rm -rf $(COMPILED_DIR)
@rm -rf $(CONTRACTS_DIR)/@openzeppelin

# Compile, filter out and format contracts into the following format.
# {
# "abi": "[{\"inpu # JSON string
# "bin": "60806040
# "contractName": # filename without .sol
# }
create-contracts-json:
@for c in $(shell ls $(CONTRACTS_DIR) | grep '\.sol' | sed 's/.sol//g'); do \
command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed."; exit 1; } ;\
command -v solc > /dev/null 2>&1 || { echo >&2 "solc not installed."; exit 1; } ;\
mkdir -p $(COMPILED_DIR) ;\
mkdir -p $(TMP) ;\
echo "\nCompiling solidity contract $${c}..." ;\
solc --combined-json abi,bin $(CONTRACTS_DIR)/$${c}.sol > $(TMP_COMPILED) ;\
echo "Formatting JSON..." ;\
get_contract=$$(jq '.contracts["$(CONTRACTS_DIR)/'$$c'.sol:'$$c'"]' $(TMP_COMPILED)) ;\
add_contract_name=$$(echo $$get_contract | jq '. + { "contractName": "'$$c'" }') ;\
echo $$add_contract_name | jq > $(TMP_JSON) ;\
abi_string=$$(echo $$add_contract_name | jq -cr '.abi') ;\
echo $$add_contract_name | jq --arg newval "$$abi_string" '.abi = $$newval' > $(TMP_JSON) ;\
mv $(TMP_JSON) $(COMPILED_DIR)/$${c}.json ;\
done
@rm -rf $(TMP)
@echo "Cleaning up the contracts directory..."
@python3 ./scripts/compile_smart_contracts/compile_smart_contracts.py --clean

# Compile the solidity contracts found in the Evmos repository.
contracts-compile:
@echo "Compiling smart contracts..."
@python3 ./scripts/compile_smart_contracts/compile_smart_contracts.py --compile

# Add a new solidity contract to be compiled
contracts-add:
@echo "Adding a new smart contract to be compiled..."
@python3 ./scripts/compile_smart_contracts/compile_smart_contracts.py --add $(CONTRACT)

###############################################################################
### Miscellaneous Checks ###
Expand Down
8 changes: 8 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Compiled contracts
artifacts/

# Cached files
cache/

# Node modules
node_modules/
43 changes: 0 additions & 43 deletions contracts/ERC20Burnable.sol

This file was deleted.

5 changes: 0 additions & 5 deletions contracts/compiled_contracts/ERC20Burnable.json

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions contracts/compiled_contracts/ERC20MaliciousDelayed.json

This file was deleted.

0 comments on commit 91319d2

Please sign in to comment.