Skip to content

Commit

Permalink
feat: send base fee back to treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
allnil committed Oct 3, 2024
1 parent 0943366 commit eddaf8d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions crates/revm/src/handler/mainnet/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
},
Context, FrameResult,
};
use crate::primitives::{address};

/// Mainnet end handle does not change the output.
#[inline]
Expand Down Expand Up @@ -40,6 +41,9 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
effective_gas_price
};

// WVM: send base fee back to treasury
wvm_add_base_fee_to_treasury(context, gas)?;

let coinbase_account = context
.evm
.inner
Expand All @@ -56,6 +60,28 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
Ok(())
}

/// WVM: send base fee back to treasury
fn wvm_add_base_fee_to_treasury<SPEC: Spec, EXT, DB: Database>(
context: &mut Context<EXT, DB>,
gas: &Gas,
) -> Result<(), EVMError<DB::Error>> {
let treasury_address = address!("a2A0D977847805fE224B789D8C4d3D711ab251e7")?; // e.g treasury account
let treasury_account = context
.evm
.inner
.journaled_state
.load_account(treasury_address, &mut context.evm.inner.db)?;

treasury_account.data.mark_touch();
treasury_account.data.info.balance = treasury_account
.data
.info
.balance
.saturating_add(context.evm.env.block.basefee);

Ok(())
}

pub fn refund<SPEC: Spec, EXT, DB: Database>(
_context: &mut Context<EXT, DB>,
gas: &mut Gas,
Expand Down
1 change: 1 addition & 0 deletions documentation/src/crates/revm/handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Is a list of functions that are called after the execution. They are called in t

* `reward_beneficiary`:
Reward the beneficiary with the fee that was paid for the transaction.
WVM fork sends basefee back to treasury.

* `output`:
Returns the state changes and the result of the execution.
Expand Down

0 comments on commit eddaf8d

Please sign in to comment.