Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eth/ERC20 Bridge related contracts #9

Merged
merged 32 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
48a6425
add:starkgate contracts
anshalshukla Mar 1, 2024
66d626d
update: add traits to bridge and legacy bridge
anshalshukla Mar 3, 2024
b35e52e
test:eth
anshalshukla Mar 3, 2024
26bf6a2
add proxxy
anshalshukla Mar 3, 2024
a615c7b
update
anshalshukla Mar 3, 2024
d75d001
update
anshalshukla Mar 3, 2024
f2e1eb0
add: methods to eth bridge
anshalshukla Mar 6, 2024
64a466c
add: add fees to eth bridge payable function
anshalshukla Mar 6, 2024
90c36ee
add: add fees to eth bridge payable function
anshalshukla Mar 6, 2024
d646677
add: methods to token bridge
anshalshukla Mar 7, 2024
f9a10a8
refactor
anshalshukla Mar 7, 2024
bd3f2ad
update: abi compiles
anshalshukla Mar 7, 2024
8921057
add: methods to token bridge
anshalshukla Mar 8, 2024
c104f23
fix
anshalshukla Mar 8, 2024
7278ace
tesr
anshalshukla Mar 9, 2024
60bd142
add
anshalshukla Mar 11, 2024
1585303
add
anshalshukla Mar 11, 2024
5fd421a
add
anshalshukla Mar 11, 2024
b23c6b4
test
anshalshukla Mar 11, 2024
53a2443
remove proxy support from erc20
anshalshukla Mar 12, 2024
845ec4b
minor: refactoring
anshalshukla Mar 12, 2024
5426c46
add: withdraw function
anshalshukla Mar 12, 2024
4b4e6e0
fix
anshalshukla Mar 12, 2024
59234b8
remove .idea
anshalshukla Mar 13, 2024
452e5f8
zaun module updates (#2)
Apr 2, 2024
2a84dbb
fix : fixed unwrap and clone changes
Apr 8, 2024
b37bae7
fix : added fixes for unwrap and makefile updated
Apr 9, 2024
6d289ed
feat : updated ethereum client and added no arg type
Apr 10, 2024
e4f6689
update readme for bridge contract sources
apoorvsadana Apr 10, 2024
3b43f2c
pushed changes
Apr 10, 2024
657b026
Merge branch 'starkgate' of https://github.com/anshalshukla/zaun into…
Apr 10, 2024
06d35f4
fix : updated the vars
Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 107 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resolver = "2"
members = [
"crates/starknet-core-contract-client",
"crates/sandbox",
"crates/ethereum-instance", "crates/starknet-eth-bridge-client", "crates/starknet-token-bridge-client", "crates/starkgate-manager-client", "crates/utils", "crates/starknet-erc20-client", "crates/starkgate-registry-client", "crates/starknet-proxy-client",
]

[workspace.package]
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
# Zaun
A development environment for Starknet Solidity contracts.

### Setup:
This repository contains interfaces and functions to interact with starknet solidity contracts.

## Setup

```bash
curl -L https://foundry.paradigm.xyz | bash
foundryup
```

### Testing:
## Testing

Unit

```bash
forge test -vv
```

### Devnet

Start Avnvil as background process w/ Core Contracts and STARK token:
Start Anvil as background process w/ Core Contracts and STARK token:

```bash
./script/sn-base-dev.sh
```

Kill Anvil deployment:

```bash
./script/sn-base-kill.sh
```

### Artifacts
## Artifacts

Zaun sandbox crate can be used as dev dependency in external projects for integration testing.
If any changes made to the Solidity contracts, one has to re-generate Ethers bindings (this won't be done automatically).
Zaun sandbox crate can be used as dev dependency in external projects. If any changes made to the Solidity contracts, one has to re-generate Ethers bindings (this won't be done automatically).

```bash
make artifacts
```
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved

### StarkNet Consensus Protocol Contracts
## StarkNet Consensus Protocol Contracts

PoC solidity implementation of the following Starknet Decentralized Protocol proposal:

- [I - Introduction](https://community.starknet.io/t/starknet-decentralized-protocol-i-introduction/2671/1)
- [II - Candidate for Leader Elections](https://community.starknet.io/t/starknet-decentralized-protocol-ii-candidate-for-leader-elections/4751)
- [III - Consensus](https://community.starknet.io/t/starknet-decentralized-protocol-iii-consensus/5386)
- [IV - Proofs in the Protocol](https://community.starknet.io/t/starknet-decentralized-protocol-iv-proofs-in-the-protocol/6030)
- [V - Checkpoints for Fast Finality](https://community.starknet.io/t/starknet-decentralized-protocol-v-checkpoints-for-fast-finality/6032)
- [VI - The Buffer Problem](https://community.starknet.io/t/starknet-decentralized-protocol-vi-the-buffer-problem/7098)
- [VII - Chained Proof Protocols & Braiding](https://community.starknet.io/t/starknet-decentralized-protocol-vii-chained-proof-protocols-braiding/18831)
- [VII - Chained Proof Protocols & Braiding](https://community.starknet.io/t/starknet-decentralized-protocol-vii-chained-proof-protocols-braiding/18831)
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "sandbox"
name = "ethereum-instance"
edition.workspace = true
version.workspace = true
authors.workspace = true

[dependencies]
starknet-core-contract-client = { path = "../starknet-core-contract-client" }
ethers = { workspace = true }
dirs = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
hex = { workspace = true }
utils = { path = "../utils" }

[dev-dependencies]
tokio = { version = "1.29.1", features = ["rt", "macros", "parking_lot"] }
54 changes: 34 additions & 20 deletions crates/sandbox/src/lib.rs → crates/ethereum-instance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
use ethers::abi::Tokenize;
use ethers::contract::ContractError;
use ethers::contract::{ContractError, ContractFactory, ContractInstance};
use ethers::prelude::SignerMiddleware;
use ethers::prelude::{ContractFactory, ContractInstance};
use ethers::providers::{Http, Provider, ProviderError};
use ethers::signers::{LocalWallet, Signer};
use ethers::types::Bytes;
use ethers::utils::hex::FromHex;
use ethers::utils::{Anvil, AnvilInstance};
use ethers::types::Bytes;
use hex::FromHex;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;

/// Unsafe proxy is a straightforward implementation of the delegate proxy contract
/// that is used to make Starknet core contract upgradeable.
/// This implementation DOES NOT restrict who can invoke the core contract.
/// For more information see https://l2beat.com/scaling/projects/starknet#contracts
pub mod unsafe_proxy;

/// Ethers library allows multiple signer backends and transports.
/// For simplicity we use local wallet (basically private key) and
/// HTTP transport in this crate.
pub use starknet_core_contract_client::LocalWalletSignerMiddleware;
pub use utils::LocalWalletSignerMiddleware;

/// Sandbox is typically used for E2E scenarios so we need to speed things up
const POLLING_INTERVAL_MS: u64 = 10;
Expand All @@ -47,15 +41,15 @@ pub enum Error {
ContractBuildArtifacts(&'static str),
}

/// A convenient wrapper over an already running or spawned Anvil local devnet
pub struct EthereumSandbox {
/// A convenient wrapper over an already running or spawned Anvil local devnet or ethereum
pub struct EthereumClient {
/// If initialized keeps an Anvil instance to properly shutdown it at the end
_anvil: Option<AnvilInstance>,
/// Pre-configured local signer
client: Arc<LocalWalletSignerMiddleware>,
signer: Arc<LocalWalletSignerMiddleware>,
}

impl EthereumSandbox {
impl EthereumClient {
/// Creates a new sandbox instance.
/// Will try to attach to already running Anvil instance using one
/// of the following endpoints:
Expand Down Expand Up @@ -85,7 +79,7 @@ impl EthereumSandbox {

Ok(Self {
_anvil: None,
client: Arc::new(client),
signer: Arc::new(client),
})
}

Expand Down Expand Up @@ -115,19 +109,39 @@ impl EthereumSandbox {

Self {
_anvil: Some(anvil),
client: Arc::new(client),
signer: Arc::new(client),
}
}

/// Returns local client configured for the running Anvil instance
pub fn signer(&self) -> Arc<LocalWalletSignerMiddleware> {
self.signer.clone()
}
}


/// Wrapper For Spawning a ethereum instance using the provider
/// Used for deploying on the main network purposes
pub struct EthereumInstance {
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved
client: Arc<LocalWalletSignerMiddleware>
}

impl EthereumInstance {
pub fn spawn(rpc_url: String, priv_key: String, chain_id: u64) -> Self {

let provider = Provider::<Http>::try_from(rpc_url).expect("Failed to connect to the given rpc url");
EvolveArt marked this conversation as resolved.
Show resolved Hide resolved
let wallet: LocalWallet = priv_key.parse::<LocalWallet>().expect("Error in initializing local wallet");

let client = SignerMiddleware::new(provider, wallet.with_chain_id(chain_id));

Self { client: Arc::new(client) }
}

pub fn client(&self) -> Arc<LocalWalletSignerMiddleware> {
self.client.clone()
}
}

/// Deploys new smart contract using:
/// - Forge build artifacts (JSON file contents)
/// - Constructor args (use () if no args expected)
pub async fn deploy_contract<T: Tokenize>(
client: Arc<LocalWalletSignerMiddleware>,
contract_build_artifacts: &str,
Expand Down Expand Up @@ -160,4 +174,4 @@ pub async fn deploy_contract<T: Tokenize>(
.send()
.await
.map_err(Into::<ContractError<LocalWalletSignerMiddleware>>::into)?)
}
}
Loading