Add crate for the Ethereum contracts

This commit is contained in:
Luke Parker
2024-09-14 22:12:32 -04:00
parent d9543bee40
commit 239127aae5
24 changed files with 121 additions and 48 deletions

View File

@@ -0,0 +1,20 @@
[package]
name = "serai-processor-ethereum-contracts"
version = "0.1.0"
description = "Ethereum contracts for the Serai processor"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/processor/ethereum/contracts"
authors = ["Luke Parker <lukeparker5132@gmail.com>", "Elizabeth Binks <elizabethjbinks@gmail.com>"]
edition = "2021"
publish = false
rust-version = "1.79"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[lints]
workspace = true
[dependencies]
alloy-sol-types = { version = "0.8", default-features = false }

View File

@@ -0,0 +1,15 @@
AGPL-3.0-only license
Copyright (c) 2022-2024 Luke Parker
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License Version 3 as
published by the Free Software Foundation.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@@ -0,0 +1,7 @@
# Serai Processor Ethereum Contracts
The Ethereum contracts used for (and for testing) the Serai processor. This is
its own crate for organizational and build-time reasons. It is not intended to
be publicly used.
This crate will fail to build if `solc` is not installed and available.

View File

@@ -28,14 +28,18 @@ fn main() {
"./contracts/Sandbox.sol",
"./contracts/Router.sol",
"./src/tests/contracts/Schnorr.sol",
"./src/tests/contracts/ERC20.sol",
"./contracts/tests/Schnorr.sol",
"./contracts/tests/ERC20.sol",
"--no-color",
];
let solc = Command::new("solc").args(args).output().unwrap();
assert!(solc.status.success());
for line in String::from_utf8(solc.stderr).unwrap().lines() {
assert!(!line.starts_with("Error:"));
let stderr = String::from_utf8(solc.stderr).unwrap();
for line in stderr.lines() {
if line.contains("Error:") {
println!("{stderr}");
panic!()
}
}
}

View File

@@ -0,0 +1,48 @@
use alloy_sol_types::sol;
#[rustfmt::skip]
#[expect(warnings)]
#[expect(needless_pass_by_value)]
#[expect(clippy::all)]
#[expect(clippy::ignored_unit_patterns)]
#[expect(clippy::redundant_closure_for_method_calls)]
mod erc20_container {
use super::*;
sol!("contracts/IERC20.sol");
}
pub mod erc20 {
pub const BYTECODE: &str = include_str!("../artifacts/Deployer.bin");
pub use super::erc20_container::IERC20::*;
}
#[rustfmt::skip]
#[expect(warnings)]
#[expect(needless_pass_by_value)]
#[expect(clippy::all)]
#[expect(clippy::ignored_unit_patterns)]
#[expect(clippy::redundant_closure_for_method_calls)]
mod deployer_container {
use super::*;
sol!("contracts/Deployer.sol");
}
pub mod deployer {
pub const BYTECODE: &str = include_str!("../artifacts/Deployer.bin");
pub use super::deployer_container::Deployer::*;
}
#[rustfmt::skip]
#[expect(warnings)]
#[expect(needless_pass_by_value)]
#[expect(clippy::all)]
#[expect(clippy::ignored_unit_patterns)]
#[expect(clippy::redundant_closure_for_method_calls)]
mod router_container {
use super::*;
sol!(Router, "artifacts/Router.abi");
}
pub mod router {
pub const BYTECODE: &str = include_str!("../artifacts/Router.bin");
pub use super::router_container::Router::*;
}
pub mod tests;

View File

@@ -8,6 +8,6 @@ use alloy_sol_types::sol;
#[allow(clippy::redundant_closure_for_method_calls)]
mod schnorr_container {
use super::*;
sol!("src/tests/contracts/Schnorr.sol");
sol!("contracts/tests/Schnorr.sol");
}
pub(crate) use schnorr_container::TestSchnorr as schnorr;
pub use schnorr_container::TestSchnorr as schnorr;

View File

@@ -38,6 +38,8 @@ alloy-provider = { version = "0.3", default-features = false }
alloy-node-bindings = { version = "0.3", default-features = false, optional = true }
contracts = { package = "serai-processor-ethereum-contracts", path = "../contracts" }
[dev-dependencies]
frost = { package = "modular-frost", path = "../../../crypto/frost", default-features = false, features = ["tests"] }

View File

@@ -1,37 +0,0 @@
use alloy_sol_types::sol;
#[rustfmt::skip]
#[allow(warnings)]
#[allow(needless_pass_by_value)]
#[allow(clippy::all)]
#[allow(clippy::ignored_unit_patterns)]
#[allow(clippy::redundant_closure_for_method_calls)]
mod erc20_container {
use super::*;
sol!("contracts/IERC20.sol");
}
pub use erc20_container::IERC20 as erc20;
#[rustfmt::skip]
#[allow(warnings)]
#[allow(needless_pass_by_value)]
#[allow(clippy::all)]
#[allow(clippy::ignored_unit_patterns)]
#[allow(clippy::redundant_closure_for_method_calls)]
mod deployer_container {
use super::*;
sol!("contracts/Deployer.sol");
}
pub use deployer_container::Deployer as deployer;
#[rustfmt::skip]
#[allow(warnings)]
#[allow(needless_pass_by_value)]
#[allow(clippy::all)]
#[allow(clippy::ignored_unit_patterns)]
#[allow(clippy::redundant_closure_for_method_calls)]
mod router_container {
use super::*;
sol!(Router, "artifacts/Router.abi");
}
pub use router_container::Router as router;

View File

@@ -30,7 +30,7 @@ impl Deployer {
/// funded for this transaction to be submitted. This account has no known private key to anyone,
/// so ETH sent can be neither misappropriated nor returned.
pub fn deployment_tx() -> Signed<TxLegacy> {
let bytecode = include_str!("../artifacts/Deployer.bin");
let bytecode = contracts::deployer::BYTECODE;
let bytecode =
Bytes::from_hex(bytecode).expect("compiled-in Deployer bytecode wasn't valid hex");

View File

@@ -15,7 +15,11 @@ pub mod alloy {
pub mod crypto;
pub(crate) mod abi;
pub(crate) mod abi {
pub use contracts::erc20;
pub use contracts::deployer;
pub use contracts::router;
}
pub mod erc20;
pub mod deployer;

View File

@@ -135,7 +135,7 @@ pub struct Executed {
pub struct Router(Arc<RootProvider<SimpleRequest>>, Address);
impl Router {
pub(crate) fn code() -> Vec<u8> {
let bytecode = include_str!("../artifacts/Router.bin");
let bytecode = contracts::router::BYTECODE;
Bytes::from_hex(bytecode).expect("compiled-in Router bytecode wasn't valid hex").to_vec()
}

View File

@@ -21,7 +21,7 @@ use crate::crypto::{address, deterministically_sign, PublicKey};
mod crypto;
#[cfg(test)]
mod abi;
use contracts::tests as abi;
#[cfg(test)]
mod schnorr;
#[cfg(test)]