Skip to content

Commit

Permalink
Implement the ETH connector. (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD authored May 28, 2021
1 parent b09b530 commit 5144281
Show file tree
Hide file tree
Showing 24 changed files with 3,490 additions and 191 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ jobs:
profile: minimal
toolchain: nightly-2021-03-25
override: true
- run: make release
- run: ls -lH release.wasm
- run: make test-build
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ wee_alloc = { version = "0.4.5", default-features = false }
lunarity-lexer = { git = "https://github.com/ilblackdragon/lunarity", rev = "5201d9a76f7e491082b7f74af7e64049271e387f", default-features = false }
ethabi = { git = "https://github.com/darwinia-network/ethabi", branch = "xavier-no-std", default-features = false }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
byte-slice-cast = { version = "1.0", default-features = false }
rjson = { version = "0.3.1", default-features = false }

[dev-dependencies]
Expand All @@ -77,3 +78,6 @@ testnet = []
engine = []
contract = ["engine"]
evm_bully = []
log = []
exit-precompiles = ["contract"]
integration-test = ["log"]
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CARGO = cargo
NEAR = near
FEATURES = contract
FEATURES = contract,log

ifeq ($(evm-bully),yes)
FEATURES := $(FEATURES),evm_bully
Expand All @@ -15,6 +15,7 @@ release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm

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

debug: debug.wasm

Expand All @@ -24,6 +25,11 @@ debug.wasm: target/wasm32-unknown-unknown/debug/aurora_engine.wasm
target/wasm32-unknown-unknown/debug/aurora_engine.wasm: Cargo.toml Cargo.lock $(wildcard src/*.rs)
$(CARGO) build --target wasm32-unknown-unknown --no-default-features --features=$(FEATURES) -Z avoid-dev-deps

test-build:
RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=contract,integration-test -Z avoid-dev-deps
ln -sf target/wasm32-unknown-unknown/release/aurora_engine.wasm release.wasm
ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm

.PHONY: all release debug

deploy: release.wasm
Expand All @@ -35,10 +41,10 @@ check-format:
$(CARGO) fmt -- --check

check-clippy:
$(CARGO) +nightly clippy --no-default-features --features=$(FEATURES) -- -D warnings
$(CARGO) clippy --no-default-features --features=$(FEATURES) -- -D warnings

# test depends on release since `tests/test_upgrade.rs` includes `release.wasm`
test: release
test: test-build
$(CARGO) test

format:
Expand Down
42 changes: 42 additions & 0 deletions doc/eth-connector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ETH connector

## Build
1. For production set in the Makefile
```
FEATURES = contract
```
1.1. For **development and testing** set in the Makefile
```
FEATURES = contract,integration-test
```
2. Build release: `$ make release`
3. Run tests: `$ cargo test`
4. Deploying process is common for Aurora itself. Please reference [README.md](../README.md)
## Initialize eth-conenctor
With `near-cli` run:
```
$ near call <NEAR_ACC> new_eth_connector '{"prover_account": "<PROVER_NEAR_ACCOUNT>", "eth_custodian_address": "<ETH_ADDRESS>"}' --account-id <NEAR_ACC>

```
## ETH connector specific methods
* new_eth_connector (call once)
* deposit (mutable)
* withdraw (mutable, payable)
* finish_deposit_near (private, mutable)
* ft_total_supply (view)
* ft_total_supply_near (view)
* ft_total_supply_eth (view)
* ft_balance_of (view)
* ft_balance_of_eth (view)
* ft_transfer (mutable, payable)
* ft_resolve_transfer (private, mutable)
* ft_transfer_call (mutable, payable)
* ft_on_transfer (private, mutable)
* storage_deposit (mutable)
* storage_withdraw (mutable, payable)
* storage_balance_of (view)
## Ethereum specific flow
Follow by [this instruction](https://github.com/aurora-is-near/eth-connector/blob/master/README.md).
39 changes: 23 additions & 16 deletions etc/state-migration-test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/admin_controlled.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::sdk;

pub type PausedMask = u8;

pub trait AdminControlled {
/// Returns true if the current account is owner
fn is_owner(&self) -> bool {
sdk::current_account_id() == sdk::predecessor_account_id()
}

/// Return the current mask representing all paused events.
fn get_paused(&self) -> PausedMask;

/// Update mask with all paused events.
/// Implementor is responsible for guaranteeing that this function can only be
/// called by owner of the contract.
fn set_paused(&mut self, paused: PausedMask);

/// Return if the contract is paused for the current flag and user
fn is_paused(&self, flag: PausedMask) -> bool {
(self.get_paused() & flag) != 0 && !self.is_owner()
}

/// Asserts the passed paused flag is not set. Panics with "ERR_PAUSED" if the flag is set.
fn assert_not_paused(&self, flag: PausedMask) {
assert!(!self.is_paused(flag), "ERR_PAUSED");
}
}
Loading

0 comments on commit 5144281

Please sign in to comment.