Skip to content

Commit

Permalink
Merge pull request #85 from skalenetwork/release
Browse files Browse the repository at this point in the history
First release
  • Loading branch information
DimaStebaev authored Mar 21, 2022
2 parents d52ccdc + 96da545 commit 4d5578e
Show file tree
Hide file tree
Showing 24 changed files with 1,196 additions and 695 deletions.
29 changes: 29 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"node": true,
"mocha": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"tsconfigRootDir": "."
},
"plugins": ["@typescript-eslint"],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"]
},
"ignorePatterns": [
"coverage/**",
"docs/**",
"typechain-types/**"
]
}
19 changes: 18 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install NODE JS
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: 16

- name: Set up Python 3.9
uses: actions/setup-python@v2
Expand Down Expand Up @@ -71,6 +71,14 @@ jobs:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: predeployed/scripts/publish_package.sh

- name: Generate ABI
env:
VERSION: ${{ env.VERSION }}
run: |
pip install predeployed/dist/*.whl
./predeployed/scripts/generate_abi.py > data/marionette-$VERSION-abi.json
ls data
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -90,3 +98,12 @@ jobs:
with:
release_id: ${{ steps.create_release.outputs.id }}
assets_path: predeployed/dist/

- name: Upload ABI
id: upload-abi
uses: dwenegar/upload-release-assets@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
assets_path: data/*.json
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ jobs:
- name: Lint
run: yarn fullCheck

# - name: Test deploy
# run: ./scripts/test_deploy.sh
- name: Test deploy
run: ./scripts/test_deploy.sh

- name: Run tests
run: npx hardhat coverage
Expand Down
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"comprehensive-interface": "error",
"contract-name-camelcase": "error",
"code-complexity": "error",
"compiler-version": ["error","0.8.9"],
"compiler-version": ["error","0.8.11"],
"func-name-mixedcase": "error",
"func-visibility": ["warn",{"ignoreConstructors":true}],
"function-max-lines": "error",
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
1.0.0
8 changes: 4 additions & 4 deletions contracts/Marionette.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.9;
pragma solidity 0.8.11;

import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
Expand Down Expand Up @@ -62,10 +62,10 @@ contract Marionette is IMarionette, AccessControlEnumerableUpgradeable {

function initialize(address owner, address ima) external override initializer {
AccessControlEnumerableUpgradeable.__AccessControlEnumerable_init();
AccessControlEnumerableUpgradeable._setupRole(DEFAULT_ADMIN_ROLE, address(this));
AccessControlEnumerableUpgradeable._setupRole(PUPPETEER_ROLE, owner);
AccessControlUpgradeable._setupRole(DEFAULT_ADMIN_ROLE, address(this));
AccessControlUpgradeable._setupRole(PUPPETEER_ROLE, owner);
if (ima != address(0)) {
AccessControlEnumerableUpgradeable._setupRole(IMA_ROLE, ima);
AccessControlUpgradeable._setupRole(IMA_ROLE, ima);
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IMarionette.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.9;
pragma solidity 0.8.11;

import "@skalenetwork/ima-interfaces/IMessageReceiver.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ImaMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.9;
pragma solidity 0.8.11;

import "@skalenetwork/ima-interfaces/IMessageReceiver.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/Target.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity 0.8.9;
pragma solidity 0.8.11;

import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "@skalenetwork/ima-interfaces/IMessageReceiver.sol";
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function getGasPrice(gasPrice: string | undefined) {
const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
solidity: {
version: '0.8.9',
version: '0.8.11',
settings: {
optimizer:{
enabled: true,
Expand Down
65 changes: 65 additions & 0 deletions migrations/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// tslint:disable:no-console

import { promises as fs } from 'fs';
import { ethers, upgrades, network } from "hardhat";
import { getAbi } from './tools/abi';
import { verifyProxy } from './tools/verification';
import { getVersion } from './tools/version';


export function getContractKeyInAbiFile(contract: string) {
return contract.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase();
}

async function main() {
const [ deployer,] = await ethers.getSigners();

const version = await getVersion();

// Usage information:
//
// Optional variables:
// IMA_ADDRESS
//
// For custom network do not forget to set:
// ENDPOINT - rpc endpoint
// PRIVATE_KEY - deployer private key
// GASPRICE - optional - desired gas price
//
// Usage example:
// IMA_ADDRESS=0xd2AAa00100000000000000000000000000000000 npx hardhat run migrations/deploy.ts --network custom

const ownerAddress = deployer.address;
const imaAddress = process.env.IMA_ADDRESS ? process.env.IMA_ADDRESS : ethers.constants.AddressZero;
if (imaAddress === ethers.constants.AddressZero) {
console.log("IMA MessageProxy was not passed. Zero address will be used.");
}

console.log("Deploy Marionette");
const marionetteUpgradeableFactory = await ethers.getContractFactory("Marionette");
const marionette = (await upgrades.deployProxy(marionetteUpgradeableFactory, [ownerAddress, imaAddress]));
await marionette.deployTransaction.wait();
const marionetteAddress = marionette.address;
const marionetteInterface = marionette.interface;
await verifyProxy("Marionette", marionette.address, []);


console.log("Store ABIs");

const abiAndAddresses: {[key: string]: string | []} = {};
abiAndAddresses[getContractKeyInAbiFile("Marionette") + "_address"] = marionetteAddress;
abiAndAddresses[getContractKeyInAbiFile("Marionette") + "_abi"] = getAbi(marionetteInterface);

await fs.writeFile(`data/marionette-${version}-${network.name}-abi-and-addresses.json`, JSON.stringify(abiAndAddresses, null, 4));

console.log("Done");
}

if (require.main === module) {
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
}
2 changes: 1 addition & 1 deletion migrations/tools/abi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Interface } from "ethers/lib/utils";

export function getAbi(contractInterface: Interface) {
const abi = JSON.parse(contractInterface.format("json") as string);
const abi = JSON.parse(contractInterface.format("json") as string) as [];

abi.forEach((obj: {type: string}) => {
if (obj.type === "function") {
Expand Down
45 changes: 23 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marionette",
"version": "0.0.1",
"version": "1.0.0",
"description": "Predeployed smart contract on skale chain that is controlled by external entity.",
"main": "index.js",
"repository": "[email protected]:skalenetwork/marionette.git",
Expand All @@ -14,44 +14,45 @@
"cspell": "npx cspell \"**/*\"",
"slither": "slither .",
"tsc": "npx tsc --noEmit",
"tslint": "npx tslint --project .",
"eslint": "npx eslint --cache --ext .js,.jsx,.ts,.tsx .",
"test": "yarn tsc && npx hardhat test",
"fullCheck": "yarn lint && yarn cspell && yarn slither && yarn tsc && yarn tslint",
"fullCheck": "yarn lint && yarn cspell && yarn slither && yarn tsc && yarn eslint",
"hooks": "git config core.hooksPath .githooks || true",
"no-hooks": "git config core.hooksPath .git/hooks"
},
"devDependencies": {
"@ethersproject/abi": "^5.5.0",
"@ethersproject/bytes": "^5.5.0",
"@ethersproject/providers": "^5.5.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.1.7",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/hardhat-upgrades": "^1.12.0",
"@typechain/ethers-v5": "^8.0.1",
"@typechain/hardhat": "^3.0.0",
"@types/chai": "^4.2.22",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.2",
"@openzeppelin/hardhat-upgrades": "^1.13.0",
"@typechain/ethers-v5": "^9.0.0",
"@typechain/hardhat": "^4.0.0",
"@types/chai": "^4.3.0",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.6",
"chai": "^4.3.4",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.13",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"cspell": "^5.12.6",
"cspell": "^5.17.0",
"eslint": "^8.7.0",
"ethereum-waffle": "^3.0.0",
"ethers": "^5.5.1",
"hardhat": "^2.6.8",
"ethers": "^5.5.3",
"hardhat": "^2.8.3",
"kill-port": "^1.6.1",
"lodash": "^4.17.21",
"solhint": "^3.3.6",
"solidity-coverage": "^0.7.17",
"solidity-coverage": "^0.7.18",
"ts-node": "^10.4.0",
"tslint": "^6.1.3",
"tslint-no-unused-expression-chai": "^0.1.4",
"typechain": "^6.0.2",
"typescript": "^4.4.4"
"typechain": "^7.0.0",
"typescript": "^4.5.5"
},
"dependencies": {
"@openzeppelin/contracts-upgradeable": "^4.3.2",
"@openzeppelin/contracts-upgradeable": "^4.4.2",
"@skalenetwork/ima-interfaces": "^0.0.1"
}
}
15 changes: 10 additions & 5 deletions predeployed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pip install marionette-predeployed
```python
from marionette_predeployed import UpgradeableMarionetteGenerator, MARIONETTE_ADDRESS, MARIONETTE_IMPLEMENTATION_ADDRESS

OWNER_ADDRESS = '0xd200000000000000000000000000000000000000'
PROXY_ADMIN_ADDRESS = '0xd200000000000000000000000000000000000001'
PROXY_ADMIN_ADDRESS = '0xd200000000000000000000000000000000000000'
MAINNET_OWNER_ADDRESS = '0xd200000000000000000000000000000000000001'
SCHAIN_OWNER_ADDRESS = '0xD200000000000000000000000000000000000002'
MESSAGE_PROXY_FOR_SCHAIN_ADDRESS = '0xd200000000000000000000000000000000000003'

marionette_generator = UpgradeableMarionetteGenerator()

Expand All @@ -25,9 +27,12 @@ genesis = {
'alloc': {
**marionette_generator.generate_allocation(
contract_address=MARIONETTE_ADDRESS,
implementation_address=MARIONETTE_IMPLEMENTATION_ADDRESS,
schain_owner=OWNER_ADDRESS,
proxy_admin_address=PROXY_ADMIN_ADDRESS
implementation_address=MARIONETTE_IMPLEMENTATION_ADDRESS,
proxy_admin_address=PROXY_ADMIN_ADDRESS,
schain_owner=MAINNET_OWNER_ADDRESS,
marionette=MARIONETTE_ADDRESS,
owner=SCHAIN_OWNER_ADDRESS,
ima=MESSAGE_PROXY_FOR_SCHAIN_ADDRESS,
)
}
}
Expand Down
11 changes: 11 additions & 0 deletions predeployed/scripts/generate_abi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
from marionette_predeployed.marionette_generator import MarionetteGenerator
import json


def main():
print(json.dumps(MarionetteGenerator().get_abi(), sort_keys=True, indent=4))


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self):
dirname(__file__),
'artifacts',
self.ARTIFACT_FILENAME))
super().__init__(bytecode=generator.bytecode)
super().__init__(bytecode=generator.bytecode, abi=generator.abi)

@classmethod
def generate_storage(cls, **kwargs) -> Dict[str, str]:
Expand Down
3 changes: 3 additions & 0 deletions predeployed/test/test_upgradeable_marionette_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def prepare_genesis(self):
})

def test_default_admin_role(self, tmpdir):
self.datadir = tmpdir
genesis = self.prepare_genesis()

with self.run_geth(tmpdir, genesis):
Expand All @@ -44,6 +45,7 @@ def test_default_admin_role(self, tmpdir):
assert marionette.functions.hasRole(MarionetteGenerator.DEFAULT_ADMIN_ROLE, MARIONETTE_ADDRESS).call()

def test_ima_role(self, tmpdir):
self.datadir = tmpdir
genesis = self.prepare_genesis()

with self.run_geth(tmpdir, genesis):
Expand All @@ -55,6 +57,7 @@ def test_ima_role(self, tmpdir):
assert marionette.functions.hasRole(MarionetteGenerator.IMA_ROLE, self.IMA_ADDRESS).call()

def test_PUPPETEER_ROLE(self, tmpdir):
self.datadir = tmpdir
genesis = self.prepare_genesis()

with self.run_geth(tmpdir, genesis):
Expand Down
6 changes: 5 additions & 1 deletion predeployed/test/tools/base_genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"berlinBlock": 0,
"londonBlock": 0
"londonBlock": 0,
"clique": {
"period": 5,
"epoch": 30000
}
},
"nonce": "0x33",
"timestamp": "0x0",
Expand Down
Loading

0 comments on commit 4d5578e

Please sign in to comment.