mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
Test the Deployer contract
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use alloy_core::primitives::{hex::FromHex, Address, U256, Bytes, TxKind};
|
||||
use alloy_core::primitives::{hex, Address, U256, Bytes, TxKind};
|
||||
use alloy_consensus::{Signed, TxLegacy};
|
||||
|
||||
use alloy_sol_types::SolCall;
|
||||
@@ -14,6 +14,9 @@ use alloy_transport::{TransportErrorKind, RpcError};
|
||||
use alloy_simple_request_transport::SimpleRequest;
|
||||
use alloy_provider::{Provider, RootProvider};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[expect(warnings)]
|
||||
#[expect(needless_pass_by_value)]
|
||||
@@ -24,6 +27,17 @@ mod abi {
|
||||
alloy_sol_macro::sol!("contracts/Deployer.sol");
|
||||
}
|
||||
|
||||
const BYTECODE: &[u8] = {
|
||||
const BYTECODE_HEX: &[u8] =
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/serai-processor-ethereum-deployer/Deployer.bin"));
|
||||
const BYTECODE: [u8; BYTECODE_HEX.len() / 2] =
|
||||
match hex::const_decode_to_array::<{ BYTECODE_HEX.len() / 2 }>(BYTECODE_HEX) {
|
||||
Ok(bytecode) => bytecode,
|
||||
Err(_) => panic!("Deployer.bin did not contain valid hex"),
|
||||
};
|
||||
&BYTECODE
|
||||
};
|
||||
|
||||
/// The Deployer contract for the Serai Router contract.
|
||||
///
|
||||
/// This Deployer has a deterministic address, letting it be immediately identified on any instance
|
||||
@@ -38,21 +52,39 @@ 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> {
|
||||
pub const BYTECODE: &[u8] =
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/serai-processor-ethereum-deployer/Deployer.bin"));
|
||||
let bytecode =
|
||||
Bytes::from_hex(BYTECODE).expect("compiled-in Deployer bytecode wasn't valid hex");
|
||||
let bytecode = Bytes::from(BYTECODE);
|
||||
|
||||
// Legacy transactions are used to ensure the widest possible degree of support across EVMs
|
||||
let tx = TxLegacy {
|
||||
chain_id: None,
|
||||
nonce: 0,
|
||||
// This uses a fixed gas price as necessary to achieve a deterministic address
|
||||
// The gas price is fixed to 100 gwei, which should be incredibly generous, in order to make
|
||||
// this getting stuck unlikely. While expensive, this only has to occur once
|
||||
/*
|
||||
This needs to use a fixed gas price to achieve a deterministic address. The gas price is
|
||||
fixed to 100 gwei, which should be generous, in order to make this unlikely to get stuck.
|
||||
While potentially expensive, this only has to occur per chain this is deployed on.
|
||||
|
||||
If this is too low of a gas price, private mempools can be used, with other transactions in
|
||||
the bundle raising the gas price to acceptable levels. While this strategy could be
|
||||
entirely relied upon, allowing the gas price paid to reflect the network's actual gas
|
||||
price, that wouldn't work for EVM networks without private mempools.
|
||||
|
||||
That leaves this as failing only if it violates a protocol constant, or if the gas price is
|
||||
too low on a network without private mempools to publish via. In that case, this code
|
||||
should to be forked to accept an enum of which network the deployment is for (with the gas
|
||||
price derivative of that, as common as possible across networks to minimize the amount of
|
||||
addresses representing the Deployer).
|
||||
*/
|
||||
gas_price: 100_000_000_000u128,
|
||||
// TODO: Use a more accurate gas limit
|
||||
gas_limit: 1_000_000u64,
|
||||
/*
|
||||
This is twice the cost of deployment as of Ethereum's Cancun upgrade. The wide margin is to
|
||||
increase the likelihood of surviving changes to the cost of contract deployment (notably
|
||||
the gas cost of calldata). While wasteful, this only has to be done once per chain and is
|
||||
accepted accordingly.
|
||||
|
||||
If this is ever unacceptable, the parameterization suggested in case the `gas_price` is
|
||||
unacceptable should be implemented.
|
||||
*/
|
||||
gas_limit: 300_698,
|
||||
to: TxKind::Create,
|
||||
value: U256::ZERO,
|
||||
input: bytecode,
|
||||
|
||||
Reference in New Issue
Block a user