Skip to content

Commit

Permalink
Merge pull request #3341 from Sifchain/mergeSmartContracts
Browse files Browse the repository at this point in the history
Merge Peggy2 Smart Contracts into master
  • Loading branch information
Brando753 authored Oct 23, 2022
2 parents 5fbcf6c + bfd393e commit 9c2d683
Show file tree
Hide file tree
Showing 205 changed files with 47,378 additions and 70,936 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/smart-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ jobs:
- name: Use Node.js
uses: actions/[email protected]
with:
node-version: '14.x'
node-version: '18.x'

- name: Install dependencies
run: npm install

- name: Install truffle
run: npm i -g truffle

- name: Test Setup
run: npm run test:setup

- name: Run truffle tests
run: npm run test
- name: Run hardhat tests
run: make tests
5 changes: 5 additions & 0 deletions smart-contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ venv
/artifacts/
/cache/
/.idea/
relayerdb/
witnessdb/
*.pyc
package-lock.json
.hardhat-compile
35 changes: 35 additions & 0 deletions smart-contracts/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": true,
"explicitTypes": "always"
}
},
{
"files": "*.js",
"options": {
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"singleQuote": false
}
},
{
"files": "*.ts",
"options": {
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"singleQuote": false,
"semi": true,
"trailingComma": es5
}
}
]
}
9 changes: 9 additions & 0 deletions smart-contracts/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
skipFiles: [
'BridgeRegistry.sol',
'Migrations.sol',
'Mocks/TrollToken.sol',
'MockUpgrade/MockCosmsosBridgeUpgrade.sol',
'SifchainTestToken.sol',
]
};
77 changes: 77 additions & 0 deletions smart-contracts/AddIbcTokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# How to: Add IBC ERC20 tokens

## Setup

For a mainnet deployment, modify the .env file to include:

```
MAINNET_URL=<mainnet_url>
MAINNET_PRIVATE_KEY=<private_key>
DEPLOYMENT_NAME=<deployment_name>
TOKEN_FILE=data/ibc_mainnet_tokens.json
TOKEN_ADDRESS_FILE=data/ibc_token_addresses.jsonl
```

Where:

| Item | Description |
| ---------------------- | ------------------------------------------------------------ |
| `<mainnet_url>` | Replace with the Infura Mainnet URL |
| `<private_key>` | Replace with the ETH Private Key for the BridgeBank operator |
| `<deployment_name>` | Replace with the deployment name like sifchain |
| `<token_file>` | File with information on new tokens to be deployed |
| `<token_address_file>` | File where new tokens that are created will be written to |

# Overview

There are two distinct steps to this script.

One is creating the new bridge tokens.
Two is attaching the bridge tokens to the bridgebank by calling addExistingBridgeToken on the bridgebank.

The script to attach bridge tokens will be run by a user with priviledged access to the bridgebank with the owner role.

## Mainnet Token Deployment

This does not require any special permissions. Tokens will be handed off to another user
before they're attached to the BridgeBank.

cd smart-contracts
npm install
npx hardhat run scripts/create_ibc_matching_token.ts --network mainnet | grep -v 'No need to generate' | tee data/ibc_token_addresses.jsonl

## Steps to Attach Tokens to BridgeBank

This requires the private key of the BridgeBank owner.

cd smart-contracts
npm install
npx hardhat run scripts/attach_ibc_matching_token.ts --network mainnet < data/ibc_token_addresses.jsonl

## Testing with forked mainnnet

Since you're running two scripts, you'll need a hardhat node running (otherwise the first script will run, execute transactions, then throw them away)

Start a hardhat node in a shell:

npx hardhat node --verbose

Then run the two scripts in a different shell:

npx hardhat run scripts/create_ibc_matching_token.ts --network localhost | grep -v 'No need to generate' | tee test_data/ibc_token_addresses.jsonl
npx hardhat run scripts/attach_ibc_matching_token.ts --network localhost < test_data/ibc_token_addresses.jsonl

or for ropsten

npx hardhat run scripts/create_ibc_matching_token.ts --network ropsten | grep -v 'No need to generate' | tee test_data/ibc_token_addresses.jsonl
npx hardhat run scripts/attach_ibc_matching_token.ts --network ropsten < test_data/ibc_token_addresses.jsonl

# Updating dev and test deployments

## Update symbol_translator.json

Modify https://github.com/Sifchain/chainOps/blob/main/.github/workflows/variableMapping/ebrelayer.yaml
with the new symbol_translation.json entries. It's a yaml file, so you need to escape json - you could
use something like ```jq -aRs``` to do the quoting.

To push that data out and restart the relayers, use https://github.com/Sifchain/chainOps/actions/workflows/peggy-ebrelayer-deployment.yml
50 changes: 32 additions & 18 deletions smart-contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,44 @@

SHELL:=/bin/bash

setup:
python3 -m venv venv ; source ./venv/bin/activate ; pip3 install -r requirements.txt
yarn
include Makefile.smartContracts
include Makefile.artifacts
gofiles=$(artifacts:.json=.go)

# Run slither over entire directory
# `make slither`
slither: setup
slither . || true
all: ${artifacts}

# Simple static analysis in a human-readable report over entire directory
# `make slither-pretty-summary`
slither-pretty-summary: setup
slither . --print human-summary
install: all

# Check for ERC 20|223|777|721|165|1820 conformance
# `make conformance CONTRACT=./contracts/ContractFile.sol CONTRACT_NAME=ContractName`
erc-conformance: setup
slither-check-erc ${CONTRACT} ${CONTRACT_NAME}
artifacts/%.go: artifacts/%.json
bash scripts/do_abigen.sh $< ../cmd/ebrelayer/contract/generated

.PHONY: clean clean-smartcontracts clean-node
clean: clean-node clean-smartcontracts
${artifacts}: .hardhat-compile

all: ${gofiles}

.hardhat-compile: node_modules
npx hardhat compile --force
touch $@

node_modules: package.json
npm install

.PHONY: clean clean-smartcontracts clean-node clean-hardhat-artifact
clean: clean-hardhat-artifact clean-node clean-smartcontracts
rm -f .hardhat-compile

clean-smartcontracts:
rm -rf build .openzepplin

clean-node:
rm -rf node_modules
rm -rf node_modules

clean-hardhat-artifact:
git clean -fdx artifacts
git clean -fdx cache

type:
npx hardhat typechain

tests: type
npx hardhat test test/*.js test/*.ts
1 change: 1 addition & 0 deletions smart-contracts/Makefile.artifacts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
artifacts=artifacts/contracts/Blocklist.sol/Blocklist.json artifacts/contracts/Valset.sol/Valset.json artifacts/contracts/ValsetStorage.sol/ValsetStorage.json artifacts/contracts/CosmosBridgeStorage.sol/CosmosBridgeStorage.json artifacts/contracts/BridgeBank/CosmosWhiteList.sol/CosmosWhiteList.json artifacts/contracts/BridgeBank/CosmosWhiteListStorage.sol/CosmosWhiteListStorage.json artifacts/contracts/BridgeBank/BankStorage.sol/BankStorage.json artifacts/contracts/BridgeBank/CosmosBank.sol/CosmosBank.json artifacts/contracts/BridgeBank/Rowan.sol/Rowan.json artifacts/contracts/BridgeBank/BridgeToken.sol/BridgeToken.json artifacts/contracts/BridgeBank/EthereumWhitelist.sol/EthereumWhiteList.json artifacts/contracts/BridgeBank/BridgeBank.sol/BridgeBank.json artifacts/contracts/BridgeBank/Pausable.sol/Pausable.json artifacts/contracts/BridgeBank/EthereumBankStorage.sol/EthereumBankStorage.json artifacts/contracts/BridgeBank/PauserRole.sol/PauserRole.json artifacts/contracts/BridgeBank/CosmosBankStorage.sol/CosmosBankStorage.json artifacts/contracts/OracleStorage.sol/OracleStorage.json artifacts/contracts/interfaces/IBlocklist.sol/IBlocklist.json artifacts/contracts/Oracle.sol/Oracle.json artifacts/contracts/CosmosBridge.sol/CosmosBridge.json artifacts/contracts/Mocks/FailHardToken.sol/FailHardToken.json artifacts/contracts/Mocks/Erowan.sol/Erowan.json artifacts/contracts/Mocks/ReentrancyToken.sol/ReentrancyToken.json artifacts/contracts/Mocks/FakeERC20.sol/FakeERC20.json artifacts/contracts/Mocks/ManyDecimalsToken.sol/ManyDecimalsToken.json artifacts/contracts/Mocks/TrollToken.sol/TrollToken.json artifacts/contracts/BridgeRegistry.sol/BridgeRegistry.json
1 change: 1 addition & 0 deletions smart-contracts/Makefile.smartContracts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smartContracts=contracts/Blocklist.sol contracts/Valset.sol contracts/ValsetStorage.sol contracts/CosmosBridgeStorage.sol contracts/BridgeBank/CosmosWhiteList.sol contracts/BridgeBank/CosmosWhiteListStorage.sol contracts/BridgeBank/BankStorage.sol contracts/BridgeBank/CosmosBank.sol contracts/BridgeBank/Rowan.sol contracts/BridgeBank/BridgeToken.sol contracts/BridgeBank/EthereumWhitelist.sol contracts/BridgeBank/BridgeBank.sol contracts/BridgeBank/Pausable.sol contracts/BridgeBank/EthereumBankStorage.sol contracts/BridgeBank/PauserRole.sol contracts/BridgeBank/CosmosBankStorage.sol contracts/OracleStorage.sol contracts/interfaces/IBlocklist.sol contracts/Oracle.sol contracts/CosmosBridge.sol contracts/Mocks/FailHardToken.sol contracts/Mocks/Erowan.sol contracts/Mocks/ReentrancyToken.sol contracts/Mocks/FakeERC20.sol contracts/Mocks/ManyDecimalsToken.sol contracts/Mocks/TrollToken.sol contracts/BridgeRegistry.sol
91 changes: 0 additions & 91 deletions smart-contracts/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions smart-contracts/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
All documentation related to smart contracts and peggy2 can be found in /docs/peggy/docs/ in this repo or online
at https://peggy.sifchain.finance.
13 changes: 13 additions & 0 deletions smart-contracts/TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
To run unit tests that rely on devenv, start devenv in a terminal:

npx hardhat run scripts/devenv.ts

And then run the tests in another terminal:

npx hardhat test test/devenv/test_lockburn.ts --network localhost

The VERBOSE environment variable can be set to:

* summary - only print summary lines
* (not set) - no verbose output
* any string other than summary - full json output
Loading

0 comments on commit 9c2d683

Please sign in to comment.