Skip to content

Commit

Permalink
Merge branch 'master' into al/ethexe/libp2p-v0.54.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f authored Aug 21, 2024
2 parents 6d3236c + f7af27f commit b93e1c8
Show file tree
Hide file tree
Showing 34 changed files with 2,047 additions and 1,128 deletions.
1,072 changes: 722 additions & 350 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ serde = { version = "^1", default-features = false }
serde_json = "^1"
serde_yaml = "0.8.26"
sha-1 = "0.10.1"
subxt = "0.32.1"
subxt-metadata = "0.32.1"
subxt-codegen = "0.32.1"
subxt = "0.37.0"
subxt-metadata = "0.37.0"
subxt-codegen = "0.37.0"
syn = "2.0.71"
thiserror = "1.0.62"
tokio = { version = "1.38.0" }
Expand Down Expand Up @@ -303,9 +303,13 @@ ethexe-rpc = { path = "ethexe/rpc", default-features = false }
ethexe-common = { path = "ethexe/common" }

# Common executors between `sandbox-host` and `calc-stack-height`
sandbox-wasmer = { package = "wasmer", version = "4.3.4", features = ["singlepass"] }
sandbox-wasmer = { package = "wasmer", version = "4.3.4", features = [
"singlepass",
] }
sandbox-wasmer-types = { package = "wasmer-types", version = "4.3.4" }
sandbox-wasmi = { package = "wasmi", git = "https://github.com/gear-tech/wasmi", branch = "v0.13.2-sign-ext", features = ["virtual_memory"] }
sandbox-wasmi = { package = "wasmi", git = "https://github.com/gear-tech/wasmi", branch = "v0.13.2-sign-ext", features = [
"virtual_memory",
] }

# Substrate deps
binary-merkle-tree = { version = "4.0.0-dev", git = "https://github.com/gear-tech/polkadot-sdk.git", branch = "gear-v1.4.0", default-features = false }
Expand Down Expand Up @@ -526,11 +530,11 @@ wasm-opt = "0.116" # utils/wasm-builde
wasmprinter = "0.2" # utils/wasm-gen
whoami = "1.5.1" # gcli
fail = "0.5" # gear-common
scale-value = "^0.12" # gsdk
scale-value = "^0.16" # gsdk
heck = "0.5.0" # gsdk-api-gen
etc = "0.1.19" # gcli
toml_edit = "0.22.12" # crates-io
scale-decode = "0.9.0" # gsdk
scale-decode = "0.13.0" # gsdk
directories = "5.0.1" # utils/key-finder
num-traits = { version = "0.2", default-features = false } # gear-core
glob = "0.3.1" # cargo-gbuild
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ Refer to the **[Technical Paper](https://github.com/gear-tech/gear-technical/blo
1. Explore dApp examples in action and gain a deeper understanding of their functionalities. Write your own program or use one from the available templates. Adapt a template according to your business needs.
2. [Test](https://wiki.gear-tech.io/docs/developing-contracts/testing) your program off-chain and on-chain using a [local node](https://wiki.gear-tech.io/docs/node/setting-up).
3. Then upload it via Gear Idea to the [Vara Network](https://idea.gear-tech.io/programs?node=wss%3A%2F%2Frpc.vara.network).
3. :microscope: Dive into the documentation on Gear Protocol crates at https://docs.gear.rs.
3. :microscope: Dive into the documentation on Gear Protocol crates at [сrates.io](https://crates.io/teams/github:gear-tech:dev). Particular attention should be paid to - [sails_rs](https://crates.io/crates/sails_rs), [gstd](https://crates.io/crates/gstd), [gcore](https://crates.io/crates/gcore), [gtest](https://crates.io/crates/gtest), [gclient](https://crates.io/crates/gclient), [gsdk](https://crates.io/crates/gsdk). More details can be found in the Documentation section for each crate.

4. :iphone: Implement a frontend application that interacts with your program using the [JS API](https://github.com/gear-tech/gear-js/tree/main/api). React application examples are available [here](https://github.com/gear-foundation/dapps/tree/master/frontend/apps).

# Run Vara Node
Expand Down
12 changes: 7 additions & 5 deletions ethexe/cli/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ impl TestEnv {
Ethereum::deploy(&rpc_url, validators, signer.clone(), sender_address).await?
};

let router_address = ethereum.router().address();
let router = ethereum.router();
let router_query = router.query();

let router_query = RouterQuery::new(&rpc_url, router_address).await?;
let genesis_block_hash = router_query.genesis_block_hash().await?;

let blob_reader = blob_reader.unwrap_or_else(|| Arc::new(MockBlobReader::new(block_time)));

let router_address = router.address();

let query = Query::new(
Arc::new(db.clone()),
&rpc_url,
Expand Down Expand Up @@ -449,7 +451,7 @@ async fn ping() {

let program_address = ethexe_signer::Address::try_from(program_id).unwrap();

let wvara = env.ethereum.wvara();
let wvara = env.ethereum.router().wvara();

log::info!("📗 Approving WVara to mirror");
wvara.approve_all(program_address.0.into()).await.unwrap();
Expand Down Expand Up @@ -613,7 +615,7 @@ async fn ping_reorg() {

let program_address = ethexe_signer::Address::try_from(program_id).unwrap();

let wvara = env.ethereum.wvara();
let wvara = env.ethereum.router().wvara();

log::info!("📗 Approving WVara to mirror");
wvara.approve_all(program_address.0.into()).await.unwrap();
Expand Down Expand Up @@ -874,7 +876,7 @@ async fn ping_deep_sync() {
// Send message in between.
let program_address = ethexe_signer::Address::try_from(program_id).unwrap();

let wvara = env.ethereum.wvara();
let wvara = env.ethereum.router().wvara();

log::info!("📗 Approving WVara to mirror");
wvara.approve_all(program_address.0.into()).await.unwrap();
Expand Down
8 changes: 8 additions & 0 deletions ethexe/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use parity_scale_codec::{Decode, Encode};
pub mod db;
pub mod mirror;
pub mod router;
pub mod wvara;

#[derive(Clone, Debug, Encode, Decode)]
pub enum BlockEvent {
Expand All @@ -36,6 +37,7 @@ pub enum BlockEvent {
address: ActorId,
event: mirror::Event,
},
WVara(wvara::Event),
}

impl BlockEvent {
Expand All @@ -49,3 +51,9 @@ impl From<router::Event> for BlockEvent {
Self::Router(value)
}
}

impl From<wvara::Event> for BlockEvent {
fn from(value: wvara::Event) -> Self {
Self::WVara(value)
}
}
36 changes: 36 additions & 0 deletions ethexe/common/src/wvara.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of Gear.
//
// Copyright (C) 2024 Gear Technologies Inc.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use gprimitives::{ActorId, U256};
use parity_scale_codec::{Decode, Encode};

/* Events section */

#[derive(Clone, Debug, Encode, Decode)]
pub enum Event {
Transfer {
from: ActorId,
to: ActorId,
value: u128,
},
Approval {
owner: ActorId,
spender: ActorId,
value: U256,
},
}
31 changes: 29 additions & 2 deletions ethexe/ethereum/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use alloy::sol;
use ethexe_common::{mirror, router};
use alloy::{primitives::U256 as AlloyU256, sol};
use ethexe_common::{mirror, router, wvara};
use gear_core::message::ReplyDetails;
use gear_core_errors::ReplyCode;
use gprimitives::U256;

sol!(
#[sol(rpc)]
Expand Down Expand Up @@ -52,6 +53,12 @@ sol!(
"WrappedVara.json"
);

pub(crate) fn uint256_to_u128_lossy(value: AlloyU256) -> u128 {
let [.., high, low] = value.into_limbs();

((high as u128) << 64) | (low as u128)
}

/* From common types to alloy */

impl From<router::CodeCommitment> for IRouter::CodeCommitment {
Expand Down Expand Up @@ -294,3 +301,23 @@ impl From<IMirror::ValueClaimingRequested> for mirror::Event {
}
}
}

impl From<IWrappedVara::Transfer> for wvara::Event {
fn from(event: IWrappedVara::Transfer) -> Self {
wvara::Event::Transfer {
from: (*event.from.into_word()).into(),
to: (*event.to.into_word()).into(),
value: uint256_to_u128_lossy(event.value),
}
}
}

impl From<IWrappedVara::Approval> for wvara::Event {
fn from(event: IWrappedVara::Approval) -> Self {
wvara::Event::Approval {
owner: (*event.owner.into_word()).into(),
spender: (*event.spender.into_word()).into(),
value: U256(event.value.into_limbs()),
}
}
}
24 changes: 11 additions & 13 deletions ethexe/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use ethexe_signer::{Address as LocalAddress, PublicKey, Signer as LocalSigner};
use mirror::Mirror;
use router::{Router, RouterQuery};
use std::sync::Arc;
use wvara::WVara;

mod abi;
mod eip1167;
Expand All @@ -72,7 +71,7 @@ pub(crate) fn decode_log<E: SolEvent>(log: Log) -> Result<E> {

pub struct Ethereum {
router_address: Address,
wrapped_vara_address: Address,
wvara_address: Address,
provider: Arc<AlloyProvider>,
}

Expand All @@ -84,15 +83,15 @@ impl Ethereum {
sender_address: LocalAddress,
) -> Result<Self> {
let router_query = RouterQuery::new(rpc_url, router_address).await?;
let wrapped_vara_address = router_query.wrapped_vara_address().await?;
let wvara_address = router_query.wvara_address().await?;

let router_address = Address::new(router_address.0);

let provider = create_provider(rpc_url, signer, sender_address).await?;

Ok(Self {
router_address,
wrapped_vara_address,
wvara_address,
provider,
})
}
Expand Down Expand Up @@ -126,7 +125,7 @@ impl Ethereum {
)
.await?;
let wrapped_vara = IWrappedVara::new(*proxy.address(), provider.clone());
let wrapped_vara_address = *wrapped_vara.address();
let wvara_address = *wrapped_vara.address();

let nonce = provider.get_transaction_count(deployer_address).await?;
let mirror_address = deployer_address.create(
Expand All @@ -150,7 +149,7 @@ impl Ethereum {
initialOwner: deployer_address,
_mirror: mirror_address,
_mirrorProxy: mirror_proxy_address,
_wrappedVara: wrapped_vara_address,
_wrappedVara: wvara_address,
_validatorsKeys: validators,
}
.abi_encode(),
Expand All @@ -174,7 +173,7 @@ impl Ethereum {

Ok(Self {
router_address,
wrapped_vara_address,
wvara_address,
provider,
})
}
Expand All @@ -184,17 +183,16 @@ impl Ethereum {
}

pub fn router(&self) -> Router {
Router::new(self.router_address, self.provider.clone())
Router::new(
self.router_address,
self.wvara_address,
self.provider.clone(),
)
}

pub fn mirror(&self, address: LocalAddress) -> Mirror {
Mirror::new(address.0.into(), self.provider.clone())
}

// TODO (breathx): move in router.
pub fn wvara(&self) -> WVara {
WVara::new(self.wrapped_vara_address, self.provider.clone())
}
}

async fn create_provider(
Expand Down
9 changes: 8 additions & 1 deletion ethexe/ethereum/src/mirror/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{abi::IMirror, AlloyProvider, AlloyTransport};
use alloy::{
primitives::Address,
providers::{ProviderBuilder, RootProvider},
providers::{Provider, ProviderBuilder, RootProvider},
transports::BoxTransport,
};
use anyhow::{anyhow, Result};
Expand All @@ -46,6 +46,13 @@ impl Mirror {
LocalAddress(*self.0.address().0)
}

pub fn query(&self) -> MirrorQuery {
MirrorQuery(QueryInstance::new(
*self.0.address(),
Arc::new(self.0.provider().root().clone()),
))
}

pub async fn send_message(
&self,
payload: impl AsRef<[u8]>,
Expand Down
Loading

0 comments on commit b93e1c8

Please sign in to comment.