Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ jobs:
toolchain: nightly-2021-03-25
override: true
components: clippy
- run: make etc/eth-contracts/res/EvmErc20.bin
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --no-default-features --features=contract -- -D warnings
contracts:
name: eth-contracts
runs-on: ubuntu-latest
steps:
- name: Clone the repository
uses: actions/checkout@v2
- name: Run yarn lint
working-directory: etc/eth-contracts
run: yarn && yarn lint
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
# Rust artifacts
/*.wasm
/target/

# Solidity artifacts
artifacts/
cache/
node_modules/
res/
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ release: release.wasm
release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm
ln -sf $< $@

target/wasm32-unknown-unknown/release/aurora_engine.wasm: Cargo.toml Cargo.lock $(wildcard src/*.rs)
target/wasm32-unknown-unknown/release/aurora_engine.wasm: Cargo.toml Cargo.lock $(wildcard src/*.rs) etc/eth-contracts/res/EvmErc20.bin
RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=$(FEATURES) -Z avoid-dev-deps

etc/eth-contracts/res/EvmErc20.bin: $(wildcard etc/eth-contracts/contracts/*.sol) etc/eth-contracts/package.json
cd etc/eth-contracts && yarn && yarn build

debug: debug.wasm

debug.wasm: target/wasm32-unknown-unknown/debug/aurora_engine.wasm
Expand Down
1 change: 1 addition & 0 deletions etc/eth-contracts/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
52 changes: 52 additions & 0 deletions etc/eth-contracts/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"extends" : [
"standard",
"plugin:promise/recommended"
],
"plugins": [
"promise"
],
"env": {
"browser" : true,
"node": true,
"mocha": true,
"jest": true
},
"globals" : {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {

// Strict mode
"strict": [2, "global"],

// Code style
"indent": [2, 4],
"quotes": [2, "single"],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"no-use-before-define": 0,
"no-unused-expressions": "off",
"eqeqeq": [2, "smart"],
"dot-notation": [2, {"allowKeywords": true, "allowPattern": ""}],
"no-redeclare": [2, {"builtinGlobals": true}],
"no-trailing-spaces": [2, { "skipBlankLines": true }],
"eol-last": 1,
"comma-spacing": [2, {"before": false, "after": true}],
"camelcase": [2, {"properties": "always"}],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"comma-dangle": [1, "always-multiline"],
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-debugger": 0,
"no-undef": 2,
"object-curly-spacing": [2, "always"],
"max-len": [2, 200, 2],
"generator-star-spacing": ["error", "before"],
"promise/avoid-new": 0,
"promise/always-return": 0
}
}
1 change: 1 addition & 0 deletions etc/eth-contracts/.soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
23 changes: 23 additions & 0 deletions etc/eth-contracts/.soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"mixedcase": "off",
"error-reason": "off",
"indentation": ["error", 4],
"lbrace": "off",
"linebreak-style": ["error", "unix"],
"max-len": ["error", 139],
"no-constant": ["error"],
"no-empty-blocks": "off",
"quotes": ["error", "double"],
"uppercase": "off",
"visibility-first": "error",
"arg-overflow": ["error", 5],
"function-order": "off",

"security/enforce-explicit-visibility": ["error"],
"security/no-block-members": ["off"],
"security/no-inline-assembly": ["warning"]
}
}
46 changes: 46 additions & 0 deletions etc/eth-contracts/contracts/AdminControlled.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pragma solidity ^0.8.0;


contract AdminControlled {
address public admin;
uint public paused;

constructor(address _admin, uint flags) {
admin = _admin;

// Add the possibility to set pause flags on the initialization
paused = flags;
}

modifier onlyAdmin {
require(msg.sender == admin);
_;
}

modifier pausable(uint flag) {
require((paused & flag) == 0 || msg.sender == admin);
_;
}

function adminPause(uint flags) public onlyAdmin {
paused = flags;
}

function adminSstore(uint key, uint value) public onlyAdmin {
assembly {
sstore(key, value)
}
}

function adminSendEth(address payable destination, uint amount) public onlyAdmin {
destination.transfer(amount);
}

function adminReceiveEth() public payable onlyAdmin {}

function adminDelegatecall(address target, bytes memory data) public payable onlyAdmin returns (bytes memory) {
(bool success, bytes memory rdata) = target.delegatecall(data);
require(success);
return rdata;
}
}
28 changes: 28 additions & 0 deletions etc/eth-contracts/contracts/EvmErc20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./AdminControlled.sol";


/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `ERC20` functions.
*/
contract EvmErc20 is Context, ERC20, AdminControlled {
uint8 private _decimals;

constructor (string memory name, string memory symbol, uint8 decimal) ERC20(name, symbol) AdminControlled(address(0), 0) {
_decimals = decimal;
}

function decimals() public view override returns (uint8) {
return _decimals;
}

function mint(address account, uint256 amount) public onlyAdmin {
_mint(account, amount);
}
}
17 changes: 17 additions & 0 deletions etc/eth-contracts/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require('@nomiclabs/hardhat-ethers');
require('solidity-coverage');

/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
version: '0.8.3',
settings: {
optimizer: {
enabled: true,
runs: 1000,
},
},
},
};
7 changes: 7 additions & 0 deletions etc/eth-contracts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fs = require('fs');
const path = require('path');
const artifact = require(process.argv[2]);
if (!fs.existsSync('res')) {
fs.mkdirSync('res');
}
fs.writeFileSync(path.join('res', 'EvmErc20.bin'), artifact.bytecode.substring(2));
37 changes: 37 additions & 0 deletions etc/eth-contracts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "vanilla-erc20-token",
"version": "0.1.0",
"description": "ERC20 token implementation on EVM mapped from Native NEP-141",
"dependencies": {
"@openzeppelin/contracts": "^4.1.0"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.1",
"chai": "^4.3.3",
"eslint": "^6.3.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"eth-gas-reporter": "^0.2.11",
"ethers": "^5.0.31",
"hardhat": "^2.1.1",
"rainbow-bridge-lib": "^2.0.0",
"solc": "0.8.3",
"solidity-coverage": "^0.7.16",
"solium": "^1.2.5"
},
"scripts": {
"compile": "hardhat compile",
"build": "yarn compile && node main.js ./artifacts/contracts/EvmErc20.sol/EvmErc20.json",
"test": "hardhat test",
"coverage": "hardhat coverage",
"lint:js": "eslint .",
"lint:js:fix": "eslint . --fix",
"lint:sol": "solium -d .",
"lint:sol:fix": "solium -d . --fix",
"lint": "yarn lint:js && yarn lint:sol",
"lint:fix": "yarn lint:js:fix && yarn lint:sol:fix"
}
}
Loading