Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
krzkaczor committed Feb 15, 2021
0 parents commit 03d7ed3
Show file tree
Hide file tree
Showing 25 changed files with 9,657 additions and 0 deletions.
161 changes: 161 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"env": {
"es6": true
},
"extends": ["typestrict"],
"plugins": ["no-only-tests", "simple-import-sort", "unused-imports"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"rules": {
"unused-imports/no-unused-imports-ts": "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-useless-constructor": "error",
"accessor-pairs": "error",
"constructor-super": "error",
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"handle-callback-err": ["error", "^(err|error)$"],
"new-parens": "error",
"no-array-constructor": "error",
"no-async-promise-executor": "error",
"no-caller": "error",
"no-class-assign": "error",
"no-compare-neg-zero": "error",
"no-cond-assign": "error",
"no-const-assign": "error",
"no-constant-condition": [
"error",
{
"checkLoops": false
}
],
"no-control-regex": "error",
"no-debugger": "error",
"no-delete-var": "error",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty-character-class": "error",
"no-empty-pattern": "error",
"no-eval": "error",
"no-ex-assign": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-boolean-cast": "error",
"no-extra-parens": ["error", "functions"],
"no-floating-decimal": "error",
"no-func-assign": "error",
"no-global-assign": "error",
"no-implied-eval": "error",
"no-inner-declarations": ["error", "functions"],
"no-invalid-regexp": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": [
"error",
{
"allowLoop": false,
"allowSwitch": false
}
],
"no-lone-blocks": "error",
"no-misleading-character-class": "error",
"no-multi-str": "error",
"no-negated-in-lhs": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-symbol": "error",
"no-new-wrappers": "error",
"no-obj-calls": "error",
"no-octal": "error",
"no-octal-escape": "error",
"no-path-concat": "error",
"no-proto": "error",
"no-redeclare": [
"error",
{
"builtinGlobals": false
}
],
"no-regex-spaces": "error",
"no-return-assign": ["error", "except-parens"],
"no-self-assign": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow-restricted-names": "error",
"no-sparse-arrays": "error",
"no-tabs": "error",
"no-this-before-super": "error",
"no-throw-literal": "error",
"no-unexpected-multiline": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": [
"error",
{
"defaultAssignment": false
}
],
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"no-restricted-imports": ["error"],
"no-use-before-define": [
"error",
{
"classes": false,
"functions": false,
"variables": false
}
],
"no-useless-call": "error",
"no-useless-catch": "error",
"no-useless-computed-key": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-with": "error",
"one-var": [
"error",
{
"initialized": "never"
}
],
"prefer-const": [
"error",
{
"destructuring": "all"
}
],
"prefer-promise-reject-errors": "error",
"symbol-description": "error",
"use-isnan": "error",
"valid-typeof": [
"error",
{
"requireStringLiterals": true
}
],
"yoda": ["error", "never"],
"no-only-tests/no-only-tests": "error"
},
"overrides": [
{
"files": ["test/**/*.{js,ts,tsx}"],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
}
]
}
42 changes: 42 additions & 0 deletions .github/workflows/build-test-deposit-withdrawal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI - Deposit Withdrawal Example

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build-test-lint:
name: Run Deposit Withdrawal Test Suite on Node ${{matrix.node}}
runs-on: ubuntu-latest

strategy:
matrix:
node: [ '10' ]

steps:
- uses: actions/checkout@v2

- name: Setup node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

# START DEPENDENCY CACHING
- name: Cache root deps
uses: actions/cache@v1
id: cache_base
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('package.json') }}

# END DEPENDENCY CACHING

- name: Install Dependencies
run: yarn install

- name: Test
run: yarn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
artifacts/
cache/
artifacts-l2
24 changes: 24 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ensure NODE_ENV
process.env.NODE_ENV = 'test'

// if tsconfig.test.json exists in cwd prefer it
const { existsSync } = require('fs')
const { join } = require('path')
const testTsconfigPath = join(process.cwd(), 'tsconfig.test.json')
if (existsSync(testTsconfigPath)) {
process.env.TS_NODE_PROJECT = testTsconfigPath
}

// exit test runner on unhandled rejections
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection during test execution:', promise, 'reason:', reason)
process.exit(1)
})

module.exports = {
require: ['ts-node/register/transpile-only', 'earljs/mocha'],
extension: ['ts'],
watchExtensions: ['ts'],
spec: ['test/**/*.test.ts'],
timeout: 30000,
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.23
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.vscode
package.json
dist
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 120,
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "always"
}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Buidler-Deposit-Withdraw-Example
A simple ERC20 token project in Buidler to get started testing L1 <->L2 communication.
To get started:

```
yarn
yarn test
```

## Model

![Message Passing Diagram](./images/message-passing-diagram.png)
2 changes: 2 additions & 0 deletions buidler-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@nomiclabs/buidler-ethers/src/type-extensions" />
/// <reference types="@nomiclabs/buidler-waffle/src/type-extensions" />
49 changes: 49 additions & 0 deletions contracts-l2/L2ERC20Minter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pragma solidity ^0.5.0;

interface iOVM_BaseCrossDomainMessenger {
function xDomainMessageSender() external view returns (address);

function sendMessage(
address _target,
bytes calldata _message,
uint32 _gasLimit
) external;
}

interface Mintable {
function mint(address usr, uint256 wad) external;

function burn(address usr, uint256 wad) external;
}

contract L2ERC20Minter {
address l1ERC20DepositAddress;
iOVM_BaseCrossDomainMessenger internal messenger;
Mintable token;

constructor(address _token) public {
token = Mintable(_token);
}

function init(address _messenger, address _L1ERC20DepositAddress) public {
require(l1ERC20DepositAddress == address(0), 'L2ERC20 instance has already been initalized');
messenger = iOVM_BaseCrossDomainMessenger(_messenger);
l1ERC20DepositAddress = _L1ERC20DepositAddress;
}

function mint(address _depositor, uint256 _amount) public returns (bool success) {
require(messenger.xDomainMessageSender() == l1ERC20DepositAddress);
require(msg.sender == address(messenger), 'Only messages relayed by L2CrossDomainMessenger can mint');
token.mint(_depositor, _amount);
return true;
}

function withdraw(uint256 _amount) public {
token.burn(msg.sender, _amount);
// generate encoded calldata to be executed on L1
bytes memory message = abi.encodeWithSignature('withdraw(address,uint256)', msg.sender, _amount);

// send the message over to the L1CrossDomainMessenger!
messenger.sendMessage(l1ERC20DepositAddress, message, 1000000);
}
}
Loading

0 comments on commit 03d7ed3

Please sign in to comment.