Skip to content

Commit

Permalink
feat(provider): modify provider traits for new types, impl alloy prov…
Browse files Browse the repository at this point in the history
…ider
  • Loading branch information
dancoombs committed Sep 19, 2024
1 parent f908cc2 commit 3ea1cfb
Show file tree
Hide file tree
Showing 20 changed files with 2,001 additions and 1,718 deletions.
151 changes: 145 additions & 6 deletions Cargo.lock

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

20 changes: 13 additions & 7 deletions crates/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ repository.workspace = true
publish = false

[dependencies]
rundler-contracts = { path = "../contracts" }
rundler-types = { path = "../types" }
rundler-utils = { path = "../utils" }

alloy-consensus.workspace = true
alloy-contract.workspace = true
alloy-json-rpc.workspace = true
alloy-primitives = { workspace = true, features = ["rand"] }
alloy-provider = { workspace = true, features = ["debug-api", "hyper"] }
alloy-rlp.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-rpc-types-trace.workspace = true
alloy-sol-types.workspace = true
alloy-transport.workspace = true

anyhow.workspace = true
async-trait.workspace = true
auto_impl = "1.2.0"
ethers.workspace = true
metrics.workspace = true
reqwest.workspace = true
serde.workspace = true
tokio.workspace = true
auto_impl.workspace = true
thiserror.workspace = true
tracing.workspace = true
parse-display.workspace = true

mockall = {workspace = true, optional = true }

Expand Down
55 changes: 55 additions & 0 deletions crates/provider/src/alloy/entry_point/arbitrum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This file is part of Rundler.
//
// Rundler is free software: you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later version.
//
// Rundler 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use alloy_primitives::{Address, Bytes};
use alloy_provider::Provider as AlloyProvider;
use alloy_sol_types::sol;
use alloy_transport::Transport;

use crate::ProviderResult;

// From https://github.com/OffchainLabs/nitro-contracts/blob/fbbcef09c95f69decabaced3da683f987902f3e2/src/node-interface/NodeInterface.sol#L112
sol! {
#[sol(rpc)]
interface NodeInterface {
function gasEstimateL1Component(
address to,
bool contractCreation,
bytes calldata data
)
external
payable
returns (
uint64 gasEstimateForL1,
uint256 baseFee,
uint256 l1BaseFeeEstimate
);
}
}

pub(crate) async fn estimate_l1_gas<AP: AlloyProvider<T>, T: Transport + Clone>(
provider: AP,
oracle_address: Address,
to_address: Address,
data: Bytes,
) -> ProviderResult<u128> {
let inst = NodeInterface::NodeInterfaceInstance::new(oracle_address, provider);

// assume contract creation
let ret = inst
.gasEstimateL1Component(to_address, true, data)
.call()
.await?;

Ok(ret.gasEstimateForL1 as u128)
}
Loading

0 comments on commit 3ea1cfb

Please sign in to comment.