Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3d98bc4
binary scaffolding
itamarreif Apr 19, 2024
312ac95
cleanup config vars
itamarreif Apr 19, 2024
dc13bb6
cleanup names
itamarreif Apr 19, 2024
b36a152
merge w main and make bridge compile and no warnings
noot May 20, 2024
badadd1
rename astria-bridge to astria-bridge-withdrawer
noot May 20, 2024
743f57d
lint toml
noot May 20, 2024
687f371
clippy
noot May 20, 2024
fade698
lint
noot May 21, 2024
6b3e883
implement AstriaWithdrawer contract and ethereum watcher (#1086)
noot May 22, 2024
9e860e2
Merge branch 'main' of github.com:astriaorg/astria into itamarreif/br…
noot May 22, 2024
4d8a8ad
update AstriaWithdrawer contract to have separate methods for sequenc…
noot May 23, 2024
75a1b29
feat(bridge-withdrawer): Bridge withdrawer transaction submission (#1…
itamarreif May 24, 2024
16ebcf6
Merge branch 'main' of github.com:astriaorg/astria into itamarreif/br…
noot May 24, 2024
397ddbb
cleanup
noot May 24, 2024
c41a562
ethereum scripts, deploy and call instructions
noot May 24, 2024
014c51f
add example .env
noot May 24, 2024
3ccc909
lint
noot May 24, 2024
ee8ceec
lint
noot May 24, 2024
631b090
attempt to fix ci
noot May 24, 2024
4e78e99
comment out ci changes
noot May 24, 2024
455d532
Merge branch 'main' of github.com:astriaorg/astria into itamarreif/br…
noot May 24, 2024
b78dfd8
clippy and lint
noot May 24, 2024
c61bd2e
ci??
noot May 24, 2024
fc0237d
ci??
noot May 24, 2024
80336fa
ci??
noot May 24, 2024
7b71c86
ci??
noot May 24, 2024
d22c387
env updates and log
noot May 24, 2024
1879617
install foundry in ci
noot May 24, 2024
1b3c1f7
put solc back
noot May 24, 2024
0e115f7
don't cache pip
noot May 24, 2024
10ad97a
Merge branch 'main' of github.com:astriaorg/astria into itamarreif/br…
noot May 28, 2024
4ee6fd1
address comments
noot May 28, 2024
6ce8d8e
Merge branch 'main' of github.com:astriaorg/astria into itamarreif/br…
noot May 28, 2024
f914103
Merge branch 'main' of github.com:astriaorg/astria into itamarreif/br…
noot May 30, 2024
bee7fb3
implement ASSET_WITHDRAWAL_DECIMALS in contract and asset_withdrawal_…
noot May 30, 2024
4a914f8
clippy
noot May 30, 2024
2dfd7c4
run tests using foundry into their own job
noot May 31, 2024
7271f75
Merge branch 'main' of github.com:astriaorg/astria into itamarreif/br…
noot May 31, 2024
7aba534
fix nextest
noot May 31, 2024
9029d02
address comments
noot May 31, 2024
6968898
clippy
noot May 31, 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
32 changes: 31 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,37 @@ jobs:
- name: Run tests
timeout-minutes: 20
run: |
cargo nextest run --archive-file=archive.tar.zst -- --include-ignored
cargo nextest run --archive-file=archive.tar.zst

rust-ethereum:
runs-on: buildjet-8vcpu-ubuntu-2204
needs: run_checker
if: needs.run_checker.outputs.run_tests == 'true'
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.76.0
- uses: Swatinem/rust-cache@v2.7.3
with:
cache-provider: "buildjet"
- name: Install nextest
uses: taiki-e/install-action@nextest
- uses: arduino/setup-protoc@v3
with:
version: "24.4"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install python and solc
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Run tests
timeout-minutes: 20
run: |
pip install solc-select
solc-select install 0.8.21
solc-select use 0.8.21
cargo nextest run --package astria-bridge-withdrawer -- --include-ignored

doctest:
runs-on: buildjet-8vcpu-ubuntu-2204
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "crates/astria-bridge-withdrawer/ethereum/lib/forge-std"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have the contracts outside of crates in the monorepo perhaps?

path = crates/astria-bridge-withdrawer/ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
33 changes: 33 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
exclude = ["tools/protobuf-compiler"]

members = [
"crates/astria-bridge-withdrawer",
"crates/astria-build-info",
"crates/astria-cli",
"crates/astria-composer",
Expand All @@ -24,6 +25,7 @@ members = [
# Specify default members so that cargo invocations in github actions will
# not act on lints
default-members = [
"crates/astria-bridge-withdrawer",
"crates/astria-build-info",
"crates/astria-cli",
"crates/astria-composer",
Expand Down Expand Up @@ -67,6 +69,7 @@ itertools = "0.12.1"
itoa = "1.0.10"
jsonrpsee = { version = "0.20" }
once_cell = "1.17.1"
pin-project-lite = "0.2.13"
sha2 = "0.10"
serde = "1"
serde_json = "1"
Expand Down
55 changes: 55 additions & 0 deletions crates/astria-bridge-withdrawer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[package]
name = "astria-bridge-withdrawer"
version = "0.1.0"
edition = "2021"
rust-version = "1.73"
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/astriaorg/astria"
homepage = "https://astria.org"

[[bin]]
name = "astria-bridge-withdrawer"

[dependencies]
http = "0.2.9"

axum = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
ethers = { workspace = true, features = ["ethers-solc", "ws"] }
hyper = { workspace = true }
humantime = { workspace = true }
ibc-types = { workspace = true }
metrics = { workspace = true }
pin-project-lite = { workspace = true }
prost = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sha2 = { workspace = true }
tendermint = { workspace = true }
tracing = { workspace = true }
tryhard = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
tokio-util = { workspace = true }

astria-build-info = { path = "../astria-build-info", features = ["runtime"] }
astria-core = { path = "../astria-core", features = ["serde", "server"] }
astria-eyre = { path = "../astria-eyre" }
config = { package = "astria-config", path = "../astria-config" }
sequencer-client = { package = "astria-sequencer-client", path = "../astria-sequencer-client", features = [
"http",
] }
telemetry = { package = "astria-telemetry", path = "../astria-telemetry", features = [
"display",
] }

[dev-dependencies]
astria-core = { path = "../astria-core", features = ["server", "test-utils"] }
astria-grpc-mock = { path = "../astria-grpc-mock" }
config = { package = "astria-config", path = "../astria-config", features = [
"tests",
] }

[build-dependencies]
astria-build-info = { path = "../astria-build-info", features = ["build"] }
4 changes: 4 additions & 0 deletions crates/astria-bridge-withdrawer/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
astria_build_info::emit("bridge-withdrawer-v")?;
Ok(())
}
14 changes: 14 additions & 0 deletions crates/astria-bridge-withdrawer/ethereum/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
38 changes: 38 additions & 0 deletions crates/astria-bridge-withdrawer/ethereum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# astria-bridge-withdrawer

Forge project for the bridge withdrawer contract.

Requirements:

- foundry

Build:

```sh
forge build
```

Copy the example .env: `cp local.example.env .env`

Put your private key in `.env` and `source .env`.

Deploy `AstriaWithdrawer.sol`:

```sh
forge script script/AstriaWithdrawer.s.sol:AstriaWithdrawerScript \
--rpc-url $RPC_URL --broadcast --sig "deploy()" -vvvv
```

Call `withdrawToSequencer` in `AstriaWithdrawer.sol`:

```sh
forge script script/AstriaWithdrawer.s.sol:AstriaWithdrawerScript \
--rpc-url $RPC_URL --broadcast --sig "withdrawToSequencer()" -vvvv
```

Call `withdrawToOriginChain` in `AstriaWithdrawer.sol`:

```sh
forge script script/AstriaWithdrawer.s.sol:AstriaWithdrawerScript \
--rpc-url $RPC_URL --broadcast --sig "withdrawToOriginChain()" -vvvv
```
6 changes: 6 additions & 0 deletions crates/astria-bridge-withdrawer/ethereum/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions crates/astria-bridge-withdrawer/ethereum/lib/forge-std
Submodule forge-std added at 978ac6
20 changes: 20 additions & 0 deletions crates/astria-bridge-withdrawer/ethereum/local.env.example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this file used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is used to deploy the ethereum contract and make calls to it - see the readme in this crate

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# private key to submit txs with
PRIVATE_KEY=0x

# default local rpc url
RPC_URL="http://localhost:8545"

# divide withdrawn values by 10^ASSET_WITHDRAWAL_DECIMALS
ASSET_WITHDRAWAL_DECIMALS=12

# contract address
ASTRIA_WITHDRAWER=0x5FbDB2315678afecb367f032d93F642f64180aa3

# destination chain address to withdraw to on the sequencer
SEQUENCER_DESTINATION_CHAIN_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

# destination chain address to withdraw to on the origin chain
ORIGIN_DESTINATION_CHAIN_ADDRESS="astring"

# amount to withdraw
AMOUNT=1000000000

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console} from "forge-std/Script.sol";
import {AstriaWithdrawer} from "../src/AstriaWithdrawer.sol";

contract AstriaWithdrawerScript is Script {
function setUp() public {}

function deploy() public {
uint32 assetWithdrawalDecimals = uint32(vm.envUint("ASSET_WITHDRAWAL_DECIMALS"));
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
AstriaWithdrawer astriaWithdrawer = new AstriaWithdrawer(assetWithdrawalDecimals);
console.logAddress(address(astriaWithdrawer));
vm.stopBroadcast();
}

function withdrawToSequencer() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

address contractAddress = vm.envAddress("ASTRIA_WITHDRAWER");
AstriaWithdrawer astriaWithdrawer = AstriaWithdrawer(contractAddress);

address destinationChainAddress = vm.envAddress("SEQUENCER_DESTINATION_CHAIN_ADDRESS");
uint256 amount = vm.envUint("AMOUNT");
astriaWithdrawer.withdrawToSequencer{value: amount}(destinationChainAddress);

vm.stopBroadcast();
}

function withdrawToOriginChain() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

address contractAddress = vm.envAddress("ASTRIA_WITHDRAWER");
AstriaWithdrawer astriaWithdrawer = AstriaWithdrawer(contractAddress);

string memory destinationChainAddress = vm.envString("ORIGIN_DESTINATION_CHAIN_ADDRESS");
uint256 amount = vm.envUint("AMOUNT");
astriaWithdrawer.withdrawToOriginChain{value: amount}(destinationChainAddress, "");

vm.stopBroadcast();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT or Apache-2.0
pragma solidity ^0.8.21;

// This contract facilitates withdrawals of the native asset from the rollup to the base chain.
//
// Funds can be withdrawn to either the sequencer or the origin chain via IBC.
contract AstriaWithdrawer {
// the number of decimal places more the asset has on the rollup versus the base chain.
//
// the amount transferred on the base chain will be divided by 10^ASSET_WITHDRAWAL_DECIMALS.
//
// for example, if the rollup specifies the asset has 18 decimal places and the base chain specifies 6,
// the ASSET_WITHDRAWAL_DECIMALS would be 12.
uint32 public immutable ASSET_WITHDRAWAL_DECIMALS;

constructor(uint32 assetWithdrawalDecimals) {
ASSET_WITHDRAWAL_DECIMALS = assetWithdrawalDecimals;
}

// emitted when a withdrawal to the sequencer is initiated
//
// the `sender` is the evm address that initiated the withdrawal
// the `destinationChainAddress` is the address on the sequencer the funds will be sent to
event SequencerWithdrawal(address indexed sender, uint256 indexed amount, address destinationChainAddress);

// emitted when a withdrawal to the origin chain is initiated.
// the withdrawal is sent to the origin chain via IBC from the sequencer using the denomination trace.
//
// the `sender` is the evm address that initiated the withdrawal
// the `destinationChainAddress` is the address on the origin chain the funds will be sent to
// the `memo` is an optional field that will be used as the ICS20 packet memo
event Ics20Withdrawal(address indexed sender, uint256 indexed amount, string destinationChainAddress, string memo);

function withdrawToSequencer(address destinationChainAddress) external payable {
emit SequencerWithdrawal(msg.sender, msg.value, destinationChainAddress);
}

function withdrawToOriginChain(string calldata destinationChainAddress, string calldata memo) external payable {
emit Ics20Withdrawal(msg.sender, msg.value, destinationChainAddress, memo);
}
}
Loading