Skip to content

Commit

Permalink
major refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio committed May 23, 2022
1 parent a9ba742 commit ce98bf0
Show file tree
Hide file tree
Showing 17 changed files with 21,668 additions and 6,311 deletions.
8 changes: 7 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
node_modules
artifacts
lib
cache
artifacts
typechain-types
coverage
deployments
forge-artifacts
bin
out
50 changes: 44 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
"eslint:recommended",
"eslint-config-airbnb-base",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended",
],
env: {
browser: true,
es6: true,
jest: true,
},
parser: "@typescript-eslint/parser",
settings: {
"import/resolver": {
node: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
},
},
plugins: ["prettier"],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unused-vars": "off", // leave it to tsc
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-useless-constructor": "error",
"arrow-parens": ["error", "always"],
"class-methods-use-this": "off",
"import/extensions": ["error", "never"],
"import/no-extraneous-dependencies": [
"error",
{ devDependencies: ["**/*.test.{js,jsx,ts,tsx}"] },
],
"import/prefer-default-export": "off",
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
"no-shadow": "off", // leave it to @typescript-eslint
"no-use-before-define": "off", // leave it to @typescript-eslint
"no-useless-constructor": "off", // leave it to @typescript-eslint
},
overrides: [
{
files: "*.{js,jsx}",
rules: {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-var-requires": "off",
},
},
],
};
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
target-branch: "main"
labels:
- "dependencies"
45 changes: 45 additions & 0 deletions .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: 🕵️‍♂️ Test smart contracts

on: [push, pull_request]

concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

jobs:
unit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
node_version:
- 16

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}

- name: Install npm project with a clean slate
run: npm ci --prefer-offline

- name: Hardhat tests
run: npx hardhat test

- name: Slither static analyser
uses: crytic/slither-action@v0.1.1
continue-on-error: true
with:
node-version: ${{ matrix.node_version }}
70 changes: 68 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@
build
# Ignore all Visual Studio Code settings
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local history for Visual Studio Code
.history

# Built Visual Studio Code extensions
*.vsix

# Dependency directory
node_modules
.env

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Yarn integrity file
.yarn-integrity

# Optional npm cache directory
.npm

# Modern Yarn files
.pnp.*
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Hardhat files
cache
artifacts
.deps

# TypeScript bindings output directory
typechain-types

# solidity-coverage directory and output file
coverage
coverage.json

# xdeployer output directory
deployments

# Foundry output directory
forge-artifacts

# Ignore flattened files
flattened.sol

# Miscellaneous files
bin
out
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
node_modules
lib
cache
artifacts
typechain-types
coverage
deployments
forge-artifacts
bin
out
15 changes: 9 additions & 6 deletions contracts/Create.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract Create {
}

/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}.
* @dev Returns the address where a contract will be stored if deployed via `deploy`.
* For the specification of the Recursive Length Prefix (RLP) encoding scheme, please
* refer to p. 19 of the Ethereum Yellow Paper (https://ethereum.github.io/yellowpaper/paper.pdf)
* and the Ethereum Wiki (https://eth.wiki/fundamentals/rlp). For further insights also, see the
Expand All @@ -88,17 +88,15 @@ contract Create {
* Thus, the first contract address created by another contract is calculated with a non-zero nonce.
*/
// prettier-ignore
function computeAddress(address addr, uint256 nonce) internal pure returns (address) {
function computeAddress(address addr, uint256 nonce) public pure returns (address) {
bytes memory data;
bytes1 len = bytes1(0x94);

if (nonce == 0x00) data = abi.encodePacked(bytes1(0xd6), len, addr, bytes1(0x80));
else if (nonce <= 0x7f) data = abi.encodePacked(bytes1(0xd6), len, addr, uint8(nonce));
else if (nonce <= type(uint8).max) data = abi.encodePacked(bytes1(0xd7), len, addr, bytes1(0x81), uint8(nonce));
else if (nonce <= type(uint16).max)
data = abi.encodePacked(bytes1(0xd8), len, addr, bytes1(0x82), uint16(nonce));
else if (nonce <= type(uint24).max)
data = abi.encodePacked(bytes1(0xd9), len, addr, bytes1(0x83), uint24(nonce));
else if (nonce <= type(uint16).max) data = abi.encodePacked(bytes1(0xd8), len, addr, bytes1(0x82), uint16(nonce));
else if (nonce <= type(uint24).max) data = abi.encodePacked(bytes1(0xd9), len, addr, bytes1(0x83), uint24(nonce));

/**
* @dev In the case of `nonce > type(uint24).max`, we have the following encoding scheme:
Expand All @@ -110,4 +108,9 @@ contract Create {

return address(uint160(uint256(keccak256(data))));
}

/**
* @dev Receive function to enable deployments of `bytecode` with a `payable` constructor.
*/
receive() external payable {}
}
40 changes: 40 additions & 0 deletions contracts/mocks/ERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.14;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract ERC20Mock is ERC20 {
constructor(
string memory name,
string memory symbol,
address initialAccount,
uint256 initialBalance
) payable ERC20(name, symbol) {
_mint(initialAccount, initialBalance);
}

function mint(address account, uint256 amount) public {
_mint(account, amount);
}

function burn(address account, uint256 amount) public {
_burn(account, amount);
}

function transferInternal(
address from,
address to,
uint256 value
) public {
_transfer(from, to, value);
}

function approveInternal(
address owner,
address spender,
uint256 value
) public {
_approve(owner, spender, value);
}
}
16 changes: 16 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @type import('hardhat/config').HardhatUserConfig
*/
require("@nomiclabs/hardhat-truffle5");

module.exports = {
solidity: {
version: "0.8.14",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
};
4 changes: 2 additions & 2 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DeployBytecode = artifacts.require("DeployBytecode");
const Create = artifacts.require("Create");

module.exports = function (deployer) {
deployer.deploy(DeployBytecode);
deployer.deploy(Create);
};
Loading

0 comments on commit ce98bf0

Please sign in to comment.