Skip to content

Commit

Permalink
feat : added dockerisation and eth changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdbytes committed Apr 22, 2024
1 parent 3a50b82 commit b3ac61b
Show file tree
Hide file tree
Showing 19 changed files with 8,986 additions and 7,494 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
starkgate-contracts
starkgate-contracts-2-0-1
target
.github
18 changes: 9 additions & 9 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
run: |-
npx prettier --check .
markdown-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: avto-dev/markdown-lint@v1
with:
config: "./.markdownlint.json"
args: "."
ignore: "./target"
# markdown-lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: avto-dev/markdown-lint@v1
# with:
# config: "./.markdownlint.json"
# args: "."
# ignore: "./target"

toml-lint:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
.idea
.env
.env
addresses.json
21 changes: 11 additions & 10 deletions Cargo.lock

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

19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ sp-core = { git = "https://github.com/massalabs/polkadot-sdk", branch = "release
] }

# Zaun Deps
ethereum-instance = { git = "https://github.com/karnotxyz/zaun", package = "ethereum-instance", branch = "starkgate" }
starkgate-manager-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-manager-client", branch = "starkgate" }
starkgate-registry-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-registry-client", branch = "starkgate" }
starknet-core-contract-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-core-contract-client", branch = "starkgate" }
starknet-erc20-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-erc20-client", branch = "starkgate" }
starknet-eth-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-eth-bridge-client", branch = "starkgate" }
starknet-proxy-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-proxy-client", branch = "starkgate" }
starknet-token-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-token-bridge-client", branch = "starkgate" }
zaun-utils = { git = "https://github.com/karnotxyz/zaun", package = "utils", branch = "starkgate" }
ethereum-instance = { git = "https://github.com/karnotxyz/zaun", package = "ethereum-instance", branch = "main" }
starkgate-manager-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-manager-client", branch = "main" }
starkgate-registry-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-registry-client", branch = "main" }
starknet-core-contract-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-core-contract-client", branch = "main" }
starknet-erc20-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-erc20-client", branch = "main" }
starknet-eth-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-eth-bridge-client", branch = "main" }
starknet-proxy-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-proxy-client", branch = "main" }
starknet-token-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-token-bridge-client", branch = "main" }
zaun-utils = { git = "https://github.com/karnotxyz/zaun", package = "utils", branch = "main" }

# Starknet Deps
starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
Expand All @@ -62,6 +62,7 @@ clap = { version = "4.4.11", features = ["derive", "env"] }
dotenv = "0.15.0"
env_logger = "0.11.3"
log = "0.4.21"
num-bigint = "0.4"
parity-scale-codec = { version = "3.2.2", default-features = false, features = [
"std",
] }
Expand Down
65 changes: 65 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ==============================================
# Karnot Bridge Deploy
# ==============================================
FROM rustlang/rust:nightly-slim as builder
LABEL authors="karnot.xyz"

# Arguments :
ARG APP_CHAIN_ID
ARG ETH_CHAIN_ID
ARG ETH_PRIV_KEY
ARG ETH_RPC
ARG FEE_TOKEN_ADDRESS
ARG L1_DEPLOYER_ADDRESS
ARG L1_WAIT_TIME
ARG L2_DEPLOYER_ADDRESS
ARG ROLLUP_PRIV_KEY
ARG ROLLUP_SEQ_URL
ARG SN_OS_CONFIG_HASH_VERSION
ARG SN_OS_PROGRAM_HASH
ARG CROSS_CHAIN_WAIT_TIME

# Assigning the env vars
ENV APP_CHAIN_ID=${APP_CHAIN_ID} \
ETH_CHAIN_ID=${ETH_CHAIN_ID} \
ETH_PRIV_KEY=${ETH_PRIV_KEY} \
ETH_RPC=${ETH_RPC} \
FEE_TOKEN_ADDRESS=${FEE_TOKEN_ADDRESS} \
L1_DEPLOYER_ADDRESS=${L1_DEPLOYER_ADDRESS} \
L1_WAIT_TIME=${L1_WAIT_TIME} \
L2_DEPLOYER_ADDRESS=${L2_DEPLOYER_ADDRESS} \
ROLLUP_PRIV_KEY=${ROLLUP_PRIV_KEY} \
SN_OS_CONFIG_HASH_VERSION=${SN_OS_CONFIG_HASH_VERSION} \
SN_OS_PROGRAM_HASH=${SN_OS_PROGRAM_HASH} \
CROSS_CHAIN_WAIT_TIME=${CROSS_CHAIN_WAIT_TIME}

# adding musl (build failing fix)
ENV RUST_TARGET=x86_64-unknown-linux-musl
ENV PKG_CONFIG_ALLOW_CROSS=1
RUN apt-get update && apt-get install -y musl-tools
RUN rustup target add x86_64-unknown-linux-musl

RUN USER=root cargo new --bin karnot-bridge-deploy && chmod -R 777 /karnot-bridge-deploy

WORKDIR /karnot-bridge-deploy

# Copy your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

# Cache dependencies
RUN cargo build --target x86_64-unknown-linux-musl --release
RUN rm src/*.rs

# Copy source tree
COPY ./src ./src

# Build for release
RUN rm -rf ./target/x86_64-unknown-linux-musl/release/deps/karnot_bridge_deploy*
RUN cargo build --target x86_64-unknown-linux-musl --release
RUN touch addresses.json

ENV RUST_LOG=debug

# Running the program
ENTRYPOINT ["cargo", "run"]
84 changes: 61 additions & 23 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# Karnot Bridge Deploy
# KBD 🌉

Karnot bridge deploy is a tool that helps to deploy the bridge
contract on settlement layer and on the rollup side.
Karnot bridge deploy (KBD) is a tool that helps to deploy
the bridge contract between a madara/katana appchain and
another L2 or L1 network.

```shell
ARGS / ENV:
//////////////////////////////////////////////////

eth_rpc
eth_priv_key
rollup_seq_url
rollup_priv_key
eth_chain_id
l1_deployer_address
l2_deployer_address
l1_wait_time
sn_os_program_hash
config_hash_version
app_chain_id
fee_token_address
```
**Currently Supported :**

- Madara App Chain <----> Ethereum / EVM based chains
- 👷🏼 more coming soon......

## Testing 🛠️

## To test
There are three test in the repository :

- bridge deployment e2e
- eth bridge deposit and claim
- erc20 token bridge deposit and claim

### IMP 🚨

- You need to comment/remove the #[ignore]
tags in [src/tests/mod.rs](src/tests/mod.rs) file
- Only one test can be run at one time as all
the tests are e2e tests.
- You also would need to restart
both the chains after running each test.
- While running the erc20 bridge deposit and withdraw
test you need to uncomment the lines 109-115 in file
[src/contract_clients/token_bridge.rs](src/contract_clients/token_bridge.rs)

```shell
# 1. Run madara instance with eth as settlement layer :
Expand All @@ -30,11 +36,43 @@ fee_token_address
~/.foundry/bin/anvil

# 3. Run tests
RUST_LOG=debug cargo test -- --no-capture
RUST_LOG=debug cargo test -- --nocapture
```

## To run and env setup
## Run 🚀

### Local 💻

You can provide the env variables as arguments also
,or you can also provide them in .env file.

Refer [.env.example](.env.example) file for setup

```shell
cp .env.example .env
cargo build --release
RUST_LOG=debug cargo run -- --help
```

### Docker 🐳

1. You need to set up the .env file first. Fill all
the variables in .env file

```shell
cp .env.example .env
```

2. You need to run docker compose command to build the image

```shell
docker compose build
```

3. Run the image
```shell
# If both the networks are running locally
docker run -it --net=host karnot-bridge-deploy-app
# If you are hosting on already deployed networks
docker run -it karnot-bridge-deploy-app
```
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.8"
services:
app:
build:
context: .
args:
APP_CHAIN_ID: ${APP_CHAIN_ID}
ETH_CHAIN_ID: ${ETH_CHAIN_ID}
ETH_PRIV_KEY: ${ETH_PRIV_KEY}
ETH_RPC: ${ETH_RPC}
FEE_TOKEN_ADDRESS: ${FEE_TOKEN_ADDRESS}
L1_DEPLOYER_ADDRESS: ${L1_DEPLOYER_ADDRESS}
L1_WAIT_TIME: ${L1_WAIT_TIME}
L2_DEPLOYER_ADDRESS: ${L2_DEPLOYER_ADDRESS}
ROLLUP_PRIV_KEY: ${ROLLUP_PRIV_KEY}
SN_OS_CONFIG_HASH_VERSION: ${SN_OS_CONFIG_HASH_VERSION}
SN_OS_PROGRAM_HASH: ${SN_OS_PROGRAM_HASH}
CROSS_CHAIN_WAIT_TIME: ${CROSS_CHAIN_WAIT_TIME}
volumes:
- ./addresses.json:/karnot-bridge-deploy/addresses.json:rw
7 changes: 7 additions & 0 deletions src/bridge/deploy_erc20_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::contract_clients::config::Config;
use crate::contract_clients::eth_bridge::BridgeDeployable;
use crate::contract_clients::starknet_sovereign::StarknetSovereignContract;
use crate::contract_clients::token_bridge::StarknetTokenBridge;
use crate::utils::{save_to_json, JsonValueType};
use crate::CliArgs;

pub async fn deploy_erc20_bridge(
Expand All @@ -26,6 +27,10 @@ pub async fn deploy_erc20_bridge(
log::debug!("Token Bridge Deployment Successful [✅]");
log::debug!("[🚀] Token Bridge Address : {:?}", token_bridge.bridge_address());
log::debug!("[🚀] ERC 20 Token Address : {:?}", token_bridge.address());
save_to_json("ERC20_l1_bridge_address", &JsonValueType::EthAddress(token_bridge.bridge_address()))?;
save_to_json("ERC20_l1_registry_address", &JsonValueType::EthAddress(token_bridge.registry_address()))?;
save_to_json("ERC20_l1_manager_address", &JsonValueType::EthAddress(token_bridge.manager_address()))?;
save_to_json("ERC20_l1_token_address", &JsonValueType::EthAddress(token_bridge.address()))?;

let l2_bridge_address = StarknetTokenBridge::deploy_l2_contracts(
clients.provider_l2(),
Expand All @@ -36,6 +41,7 @@ pub async fn deploy_erc20_bridge(

log::debug!("L2 Token Bridge Deployment Successful [✅]");
log::debug!("[🚀] L2 Token Bridge Address : {:?}", l2_bridge_address);
save_to_json("ERC20_l2_bridge_address", &JsonValueType::StringType(l2_bridge_address.to_string()))?;

token_bridge.initialize(core_contract.address()).await;
token_bridge
Expand All @@ -62,6 +68,7 @@ pub async fn deploy_erc20_bridge(
let l2_erc20_token_address =
get_l2_token_address(clients.provider_l2(), &l2_bridge_address, &token_bridge.address()).await;
log::debug!("[🚀] L2 ERC 20 Token Address : {:?}", l2_erc20_token_address);
save_to_json("ERC20_l2_token_address", &JsonValueType::StringType(l2_erc20_token_address.to_string()))?;

Ok((token_bridge, l2_bridge_address, l2_erc20_token_address))
}
Expand Down
Loading

0 comments on commit b3ac61b

Please sign in to comment.