Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
gshep committed Aug 29, 2024
1 parent 94d61e1 commit 67a13ce
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 5 deletions.
163 changes: 158 additions & 5 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 @@ -13,6 +13,8 @@ members = [
"gear-programs/vft-gateway/src/wasm",
"gear-programs/*",
"gear-programs/checkpoint-light-client/io",
"gear-programs/erc20-relay/app",
"gear-programs/erc20-relay/client",
"utils-prometheus",
]

Expand Down Expand Up @@ -41,6 +43,8 @@ gear_proof_storage = { path = "gear-programs/proof-storage" }
checkpoint_light_client-io = { path = "gear-programs/checkpoint-light-client/io", default-features = false }
utils-prometheus = { path = "utils-prometheus" }
checkpoint_light_client = { path = "gear-programs/checkpoint-light-client", default-features = false }
erc20-relay-app = { path = "gear-programs/erc20-relay/app" }
erc20-relay-client = { path = "gear-programs/erc20-relay/client" }

plonky2 = { git = "https://github.com/gear-tech/plonky2.git", rev = "4a620f4d79efe9233d0e7682df5a2fc625b5420e" }
plonky2_field = { git = "https://github.com/gear-tech/plonky2.git", rev = "4a620f4d79efe9233d0e7682df5a2fc625b5420e" }
Expand Down
15 changes: 15 additions & 0 deletions gear-programs/erc20-relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "erc20-relay"
version = "0.1.0"
edition = "2021"

[dependencies]
erc20-relay-app.workspace = true

[build-dependencies]
erc20-relay-app.workspace = true
sails-rs = { version = "0.4.0", features = ["wasm-builder"] }
sails-idl-gen = "0.4.0"

[features]
wasm-binary = []
8 changes: 8 additions & 0 deletions gear-programs/erc20-relay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## The **erc20-relay** program

The program workspace includes the following packages:
- `erc20-relay` is the package allowing to build WASM binary for the program and IDL file for it.
- `erc20-relay-app` is the package containing business logic for the program represented by the `Erc20RelayService` structure.
- `erc20-relay-client` is the package containing the client for the program allowing to interact with it from another program, tests, or
off-chain client.

12 changes: 12 additions & 0 deletions gear-programs/erc20-relay/app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "erc20-relay-app"
version = "0.1.0"
edition = "2021"

[dependencies]
sails-rs = "0.4.0"
ethereum-common.workspace = true

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", default-features = false, features = ["custom"] }
lazy_static = { version = "1.1", features = ["spin_no_std"] }
68 changes: 68 additions & 0 deletions gear-programs/erc20-relay/app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#![no_std]

use cell::RefCell;
use sails_rs::prelude::*;
use ethereum_common::
beacon::{
light::Block as LightBeaconBlock, BlockHeader as BeaconBlockHeader,
};

const CAPACITY: usize = 500_000;

#[derive(Clone, Debug, Decode, TypeInfo)]
#[codec(crate = sails_rs::scale_codec)]
#[scale_info(crate = sails_rs::scale_info)]
pub struct BlockInclusionProof {
pub block: LightBeaconBlock,
pub headers: Vec<BeaconBlockHeader>,
}

#[derive(Clone, Debug, Decode, TypeInfo)]
#[codec(crate = sails_rs::scale_codec)]
#[scale_info(crate = sails_rs::scale_info)]
pub struct EthToVaraEvent {
pub proof_block: BlockInclusionProof,
pub proof: Vec<Vec<u8>>,
pub transaction_index: u64,
pub receipt_rlp: Vec<u8>,
}

struct State {
checkpoints: ActorId,

Check failure on line 31 in gear-programs/erc20-relay/app/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

fields `checkpoints`, `vft`, and `transactions` are never read

Check failure on line 31 in gear-programs/erc20-relay/app/src/lib.rs

View workflow job for this annotation

GitHub Actions / lints

fields `checkpoints`, `vft`, and `transactions` are never read
vft: ActorId,
// (slot, transaction_index)
transactions: Vec<(u64, u64)>,
}

struct Erc20RelayService<'a>(&'a RefCell<State>);

Check failure on line 37 in gear-programs/erc20-relay/app/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

field `0` is never read

Check failure on line 37 in gear-programs/erc20-relay/app/src/lib.rs

View workflow job for this annotation

GitHub Actions / lints

field `0` is never read

#[sails_rs::service]
impl<'a> Erc20RelayService<'a> {
pub fn new(state: &'a RefCell<State>) -> Self {
Self(state)
}

pub fn relay(&mut self, message: EthToVaraEvent) -> String {

Check failure on line 45 in gear-programs/erc20-relay/app/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `message`

Check failure on line 45 in gear-programs/erc20-relay/app/src/lib.rs

View workflow job for this annotation

GitHub Actions / lints

unused variable: `message`
"Hello from Erc20Relay!".to_string()
}
}

pub struct Erc20RelayProgram(RefCell<State>);

#[sails_rs::program]
impl Erc20RelayProgram {
pub fn new(
checkpoints: ActorId,
vft: ActorId,
) -> Self {
Self(RefCell::new(State {
checkpoints,
vft,
transactions: Vec::with_capacity(CAPACITY),
}))
}

pub fn erc20_relay(&self) -> Erc20RelayService {
Erc20RelayService::new(&self.0)
}
}
Loading

0 comments on commit 67a13ce

Please sign in to comment.