Skip to content

Commit

Permalink
confs
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Jul 26, 2024
2 parents 8a8190c + 0b9a0b3 commit 18dc6e8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
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 cargo_stylus_util::sys;
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 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> {
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 @@ -140,6 +140,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 @@ -93,9 +93,6 @@ pub struct CacheConfig {
/// Deployed and activated program address to cache.
#[arg(long)]
address: H160,
/// Address of the Stylus program cache manager on Arbitrum Sepolia testnet.
#[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

0 comments on commit 18dc6e8

Please sign in to comment.