Skip to content

Commit 97e9477

Browse files
authored
chore(mpp): add built-in rpc url mapping (foundry-rs#14353)
add built-in rpc url mapping
1 parent 82557ee commit 97e9477

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

crates/cheatcodes/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ impl CheatsConfig {
186186
pub fn rpc_endpoint(&self, url_or_alias: &str) -> Result<ResolvedRpcEndpoint> {
187187
if let Some(endpoint) = self.rpc_endpoints.get(url_or_alias) {
188188
Ok(endpoint.clone().try_resolve())
189+
} else if let Some(builtin_url) = foundry_config::builtin_rpc_url(url_or_alias) {
190+
let url = RpcEndpointUrl::Url(builtin_url.to_string());
191+
Ok(RpcEndpoint::new(url).resolve())
189192
} else {
190193
// check if it's a URL or a path to an existing file to an ipc socket
191194
if url_or_alias.starts_with("http") ||

crates/config/src/endpoints.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,18 @@ impl DerefMut for ResolvedRpcEndpoints {
453453
}
454454
}
455455

456+
/// Returns the URL for a built-in RPC alias, if one exists.
457+
///
458+
/// Built-in aliases act as fallbacks: they are only used when the alias has **not** been
459+
/// defined by the user in `[rpc_endpoints]` or resolved via MESC.
460+
pub fn builtin_rpc_url(alias: &str) -> Option<&'static str> {
461+
match alias {
462+
"tempo" => Some("https://rpc.mpp.tempo.xyz"),
463+
"moderato" => Some("https://rpc.mpp.moderato.tempo.xyz"),
464+
_ => None,
465+
}
466+
}
467+
456468
#[cfg(test)]
457469
mod tests {
458470
use super::*;

crates/config/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub use utils::*;
5959
mod endpoints;
6060
pub use endpoints::{
6161
ResolvedRpcEndpoint, ResolvedRpcEndpoints, RpcEndpoint, RpcEndpointUrl, RpcEndpoints,
62+
builtin_rpc_url,
6263
};
6364

6465
mod etherscan;
@@ -1529,6 +1530,10 @@ impl Config {
15291530
return Some(Ok(Cow::Owned(mesc_url)));
15301531
}
15311532

1533+
if let Some(builtin) = crate::endpoints::builtin_rpc_url(maybe_alias) {
1534+
return Some(Ok(Cow::Borrowed(builtin)));
1535+
}
1536+
15321537
None
15331538
}
15341539

0 commit comments

Comments
 (0)