Skip to content

Commit

Permalink
Merge pull request #251 from rodrigoherrerai/payment-proposer
Browse files Browse the repository at this point in the history
support eth transfer to proposers with code
  • Loading branch information
ralexstokes authored May 8, 2024
2 parents ab15837 + 5a55ede commit f1af6d4
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions mev-build-rs/src/payload/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ pub enum Error {

pub const BASE_TX_GAS_LIMIT: u64 = 21000;

pub const PAYMENT_TO_CONTRACT_GAS_LIMIT: u64 = 100_000;

fn make_payment_transaction(
signer: &LocalWallet,
config: &PayloadFinalizerConfig,
chain_id: ChainId,
nonce: u64,
gas_limit: u64,
max_fee_per_gas: u128,
value: U256,
) -> Result<TransactionSignedEcRecovered, PayloadBuilderError> {
let tx = Transaction::Eip1559(TxEip1559 {
chain_id,
nonce,
gas_limit: BASE_TX_GAS_LIMIT,
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas: 0,
to: TxKind::Call(config.proposer_fee_recipient),
Expand Down Expand Up @@ -94,11 +97,30 @@ fn append_payment<Client: StateProviderFactory>(
.build();

let signer_account = db.load_cache_account(signer.address())?;
let nonce = signer_account.account_info().map(|info| info.nonce).unwrap_or_default();
let nonce = signer_account.account_info().map(|account| account.nonce).unwrap_or_default();

let proposer_fee_recipient_account = db.load_cache_account(config.proposer_fee_recipient)?;
let is_empty_code_hash = proposer_fee_recipient_account
.account_info()
.map(|account| account.is_empty_code_hash())
.unwrap_or_default();

// Use a fixed gas limit for the payment transaction reflecting the recipient's status
// as smart contract or EOA.
let gas_limit =
if is_empty_code_hash { BASE_TX_GAS_LIMIT } else { PAYMENT_TO_CONTRACT_GAS_LIMIT };

// SAFETY: cast to bigger type always succeeds
let max_fee_per_gas = block.header().base_fee_per_gas.unwrap_or_default() as u128;
let payment_tx =
make_payment_transaction(signer, config, chain_id, nonce, max_fee_per_gas, value)?;
let payment_tx = make_payment_transaction(
signer,
config,
chain_id,
nonce,
gas_limit,
max_fee_per_gas,
value,
)?;

// TODO: skip clones here
let mut env: EnvWithHandlerCfg = EnvWithHandlerCfg::new_with_cfg_env(
Expand Down

0 comments on commit f1af6d4

Please sign in to comment.