Skip to content

Commit 300dfe1

Browse files
authored
Merge pull request #3341 from Sifchain/mergeSmartContracts
Merge Peggy2 Smart Contracts into master
2 parents 5cec22a + 4d8bae1 commit 300dfe1

File tree

205 files changed

+47378
-70936
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+47378
-70936
lines changed

.github/workflows/smart-contracts.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@ jobs:
1717
- name: Use Node.js
1818
uses: actions/[email protected]
1919
with:
20-
node-version: '14.x'
20+
node-version: '18.x'
2121

2222
- name: Install dependencies
2323
run: npm install
2424

25-
- name: Install truffle
26-
run: npm i -g truffle
27-
28-
- name: Test Setup
29-
run: npm run test:setup
30-
31-
- name: Run truffle tests
32-
run: npm run test
25+
- name: Run hardhat tests
26+
run: make tests

smart-contracts/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ venv
99
/artifacts/
1010
/cache/
1111
/.idea/
12+
relayerdb/
13+
witnessdb/
14+
*.pyc
15+
package-lock.json
16+
.hardhat-compile

smart-contracts/.prettierrc

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"overrides": [
3+
{
4+
"files": "*.sol",
5+
"options": {
6+
"printWidth": 100,
7+
"tabWidth": 2,
8+
"useTabs": false,
9+
"singleQuote": false,
10+
"bracketSpacing": true,
11+
"explicitTypes": "always"
12+
}
13+
},
14+
{
15+
"files": "*.js",
16+
"options": {
17+
"printWidth": 100,
18+
"tabWidth": 2,
19+
"useTabs": false,
20+
"singleQuote": false
21+
}
22+
},
23+
{
24+
"files": "*.ts",
25+
"options": {
26+
"printWidth": 100,
27+
"tabWidth": 2,
28+
"useTabs": false,
29+
"singleQuote": false,
30+
"semi": true,
31+
"trailingComma": es5
32+
}
33+
}
34+
]
35+
}

smart-contracts/.solcover.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
skipFiles: [
3+
'BridgeRegistry.sol',
4+
'Migrations.sol',
5+
'Mocks/TrollToken.sol',
6+
'MockUpgrade/MockCosmsosBridgeUpgrade.sol',
7+
'SifchainTestToken.sol',
8+
]
9+
};

smart-contracts/AddIbcTokens.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# How to: Add IBC ERC20 tokens
2+
3+
## Setup
4+
5+
For a mainnet deployment, modify the .env file to include:
6+
7+
```
8+
MAINNET_URL=<mainnet_url>
9+
MAINNET_PRIVATE_KEY=<private_key>
10+
DEPLOYMENT_NAME=<deployment_name>
11+
TOKEN_FILE=data/ibc_mainnet_tokens.json
12+
TOKEN_ADDRESS_FILE=data/ibc_token_addresses.jsonl
13+
```
14+
15+
Where:
16+
17+
| Item | Description |
18+
| ---------------------- | ------------------------------------------------------------ |
19+
| `<mainnet_url>` | Replace with the Infura Mainnet URL |
20+
| `<private_key>` | Replace with the ETH Private Key for the BridgeBank operator |
21+
| `<deployment_name>` | Replace with the deployment name like sifchain |
22+
| `<token_file>` | File with information on new tokens to be deployed |
23+
| `<token_address_file>` | File where new tokens that are created will be written to |
24+
25+
# Overview
26+
27+
There are two distinct steps to this script.
28+
29+
One is creating the new bridge tokens.
30+
Two is attaching the bridge tokens to the bridgebank by calling addExistingBridgeToken on the bridgebank.
31+
32+
The script to attach bridge tokens will be run by a user with priviledged access to the bridgebank with the owner role.
33+
34+
## Mainnet Token Deployment
35+
36+
This does not require any special permissions. Tokens will be handed off to another user
37+
before they're attached to the BridgeBank.
38+
39+
cd smart-contracts
40+
npm install
41+
npx hardhat run scripts/create_ibc_matching_token.ts --network mainnet | grep -v 'No need to generate' | tee data/ibc_token_addresses.jsonl
42+
43+
## Steps to Attach Tokens to BridgeBank
44+
45+
This requires the private key of the BridgeBank owner.
46+
47+
cd smart-contracts
48+
npm install
49+
npx hardhat run scripts/attach_ibc_matching_token.ts --network mainnet < data/ibc_token_addresses.jsonl
50+
51+
## Testing with forked mainnnet
52+
53+
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)
54+
55+
Start a hardhat node in a shell:
56+
57+
npx hardhat node --verbose
58+
59+
Then run the two scripts in a different shell:
60+
61+
npx hardhat run scripts/create_ibc_matching_token.ts --network localhost | grep -v 'No need to generate' | tee test_data/ibc_token_addresses.jsonl
62+
npx hardhat run scripts/attach_ibc_matching_token.ts --network localhost < test_data/ibc_token_addresses.jsonl
63+
64+
or for ropsten
65+
66+
npx hardhat run scripts/create_ibc_matching_token.ts --network ropsten | grep -v 'No need to generate' | tee test_data/ibc_token_addresses.jsonl
67+
npx hardhat run scripts/attach_ibc_matching_token.ts --network ropsten < test_data/ibc_token_addresses.jsonl
68+
69+
# Updating dev and test deployments
70+
71+
## Update symbol_translator.json
72+
73+
Modify https://github.com/Sifchain/chainOps/blob/main/.github/workflows/variableMapping/ebrelayer.yaml
74+
with the new symbol_translation.json entries. It's a yaml file, so you need to escape json - you could
75+
use something like ```jq -aRs``` to do the quoting.
76+
77+
To push that data out and restart the relayers, use https://github.com/Sifchain/chainOps/actions/workflows/peggy-ebrelayer-deployment.yml

smart-contracts/Makefile

+32-18
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,44 @@
22

33
SHELL:=/bin/bash
44

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

9-
# Run slither over entire directory
10-
# `make slither`
11-
slither: setup
12-
slither . || true
9+
all: ${artifacts}
1310

14-
# Simple static analysis in a human-readable report over entire directory
15-
# `make slither-pretty-summary`
16-
slither-pretty-summary: setup
17-
slither . --print human-summary
11+
install: all
1812

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

24-
.PHONY: clean clean-smartcontracts clean-node
25-
clean: clean-node clean-smartcontracts
16+
${artifacts}: .hardhat-compile
17+
18+
all: ${gofiles}
19+
20+
.hardhat-compile: node_modules
21+
npx hardhat compile --force
22+
touch $@
23+
24+
node_modules: package.json
25+
npm install
26+
27+
.PHONY: clean clean-smartcontracts clean-node clean-hardhat-artifact
28+
clean: clean-hardhat-artifact clean-node clean-smartcontracts
29+
rm -f .hardhat-compile
2630

2731
clean-smartcontracts:
2832
rm -rf build .openzepplin
2933

3034
clean-node:
31-
rm -rf node_modules
35+
rm -rf node_modules
36+
37+
clean-hardhat-artifact:
38+
git clean -fdx artifacts
39+
git clean -fdx cache
40+
41+
type:
42+
npx hardhat typechain
43+
44+
tests: type
45+
npx hardhat test test/*.js test/*.ts

smart-contracts/Makefile.artifacts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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

smart-contracts/README.md

-91
This file was deleted.

smart-contracts/README.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
All documentation related to smart contracts and peggy2 can be found in /docs/peggy/docs/ in this repo or online
2+
at https://peggy.sifchain.finance.

smart-contracts/TEST.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
To run unit tests that rely on devenv, start devenv in a terminal:
2+
3+
npx hardhat run scripts/devenv.ts
4+
5+
And then run the tests in another terminal:
6+
7+
npx hardhat test test/devenv/test_lockburn.ts --network localhost
8+
9+
The VERBOSE environment variable can be set to:
10+
11+
* summary - only print summary lines
12+
* (not set) - no verbose output
13+
* any string other than summary - full json output

0 commit comments

Comments
 (0)