Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain Cache Manager Addr from ArbWasmCache Precompile + Informational Message About Cache on Deploy #59

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions check/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
use ethers::middleware::{Middleware, SignerMiddleware};
use ethers::signers::Signer;
use ethers::types::spoof::State;
use ethers::types::{Eip1559TransactionRequest, U256};
use ethers::types::transaction::eip2718::TypedTransaction;
use ethers::types::{Eip1559TransactionRequest, H160, U256};
use eyre::{bail, Context, Result};

use crate::check::{eth_call, EthCallError};
use crate::constants::ARB_WASM_CACHE_H160;
use crate::deploy::{format_gas, run_tx};
use crate::macros::greyln;
use crate::CacheConfig;

sol! {
interface ArbWasmCache {
function allCacheManagers() external view returns (address[] memory managers);
}
interface CacheManager {
function placeBid(address program) external payable;

Expand All @@ -39,10 +44,25 @@
let wallet = wallet.with_chain_id(chain_id.as_u64());
let client = SignerMiddleware::new(provider.clone(), wallet);

let data = ArbWasmCache::allCacheManagersCall {}.abi_encode();
let tx = Eip1559TransactionRequest::new()
.to(*ARB_WASM_CACHE_H160)
.data(data);
let tx = TypedTransaction::Eip1559(tx);
let result = client.call(&tx, None).await?;
let cache_managers_result =
ArbWasmCache::allCacheManagersCall::abi_decode_returns(&result, true)?;
let cache_manager_addrs = cache_managers_result.managers;
if cache_manager_addrs.is_empty() {
bail!("no cache managers found in ArbWasmCache, perhaps the Stylus cache is not yet enabled on this chain");
}
let cache_manager = cache_manager_addrs.last().unwrap().clone();

Check warning on line 59 in check/src/cache.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `Address` which implements the `Copy` trait

warning: using `clone` on type `Address` which implements the `Copy` trait --> check/src/cache.rs:59:25 | 59 | let cache_manager = cache_manager_addrs.last().unwrap().clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*cache_manager_addrs.last().unwrap()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `#[warn(clippy::clone_on_copy)]` on by default
let cache_manager = H160::from_slice(cache_manager.as_slice());

let program: Address = cfg.address.to_fixed_bytes().into();
let data = CacheManager::placeBidCall { program }.abi_encode();
let mut tx = Eip1559TransactionRequest::new()
.to(cfg.cache_manager_address)
.to(cache_manager)
.data(data);

// If a bid is set, specify it. Otherwise, a zero bid will be sent.
Expand Down
5 changes: 5 additions & 0 deletions check/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ pub const BROTLI_COMPRESSION_LEVEL: u32 = 11;
lazy_static! {
/// Address of the ArbWasm precompile.
pub static ref ARB_WASM_H160: H160 = H160(*ARB_WASM_ADDRESS.0);
/// Address of the ArbWasmCache precompile.
pub static ref ARB_WASM_CACHE_H160: H160 = H160(*ARB_WASM_CACHE_ADDRESS.0);
}

/// Address of the ArbWasm precompile.
pub const ARB_WASM_ADDRESS: Address = address!("0000000000000000000000000000000000000071");

/// Address of the ArbWasmCache precompile.
pub const ARB_WASM_CACHE_ADDRESS: Address = address!("0000000000000000000000000000000000000072");

/// Target for compiled WASM folder in a Rust project
pub const RUST_TARGET: &str = "wasm32-unknown-unknown";

Expand Down
6 changes: 6 additions & 0 deletions check/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ impl DeployConfig {
}
let tx_hash = receipt.transaction_hash.debug_lavender();
greyln!("Deployment tx hash: {tx_hash}");
println!(
r#"we recommend running cargo stylus cache --address={} to cache your activated program in ArbOS.
Cached programs benefit from cheaper calls. To read more about the Stylus program cache, see
https://docs.arbitrum.io/stylus/concepts/stylus-cache-manager"#,
hex::encode(contract)
);
Ok(contract)
}

Expand Down
3 changes: 0 additions & 3 deletions check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ pub struct CacheConfig {
/// Deployed and activated program address to cache.
#[arg(long)]
address: H160,
/// Address of the Stylus program cache manager on Arbitrum chains.
#[arg(long, default_value = "0c9043d042ab52cfa8d0207459260040cca54253")]
cache_manager_address: H160,
/// Bid, in wei, to place on the desired program to cache
#[arg(short, long, hide(true))]
bid: Option<u64>,
Expand Down
Loading