stylus_sdk/lib.rs
1// Copyright 2022-2024, Offchain Labs, Inc.
2// For licensing, see https://github.com/OffchainLabs/stylus-sdk-rs/blob/main/licenses/COPYRIGHT.md
3
4//! The Stylus SDK.
5//!
6//! The Stylus SDK makes it easy to develop Solidity ABI-equivalent Stylus contracts in Rust.
7//! Included is a full suite of types and shortcuts that abstract away the details of Solidity's storage layout,
8//! method selectors, affordances, and more, making it easy to *just write Rust*.
9//! For a guided exploration of the features, please see the comprehensive [Feature Overview][overview].
10//!
11//! Some of the features available in the SDK include:
12//! - **Generic**, storage-backed Rust types for programming **Solidity-equivalent** smart contracts with optimal
13//! storage caching.
14//! - Simple macros for writing **language-agnostic** methods and entrypoints.
15//! - Automatic export of Solidity interfaces for interoperability across programming languages.
16//! - Powerful **primitive types** backed by the feature-rich [Alloy][alloy].
17//!
18//! Rust programs written with the Stylus SDK can **call and be called** by Solidity smart contracts
19//! due to ABI equivalence with Ethereum programming languages. In fact, existing Solidity DEXs can list Rust
20//! tokens without modification, and vice versa.
21//!
22//! [overview]: https://docs.arbitrum.io/stylus/reference/rust-sdk-guide
23//! [alloy]: https://docs.rs/alloy-primitives/latest/alloy_primitives/
24
25#![doc(html_favicon_url = "https://arbitrum.io/assets/stylus/Arbitrum_Stylus-Logomark.png")]
26#![doc(html_logo_url = "https://arbitrum.io/assets/stylus/Arbitrum_Stylus-Logomark.png")]
27#![warn(missing_docs)]
28// Only allow the standard library in tests and for exports
29#![cfg_attr(not(any(test, feature = "export-abi")), no_std)]
30
31/// Use an efficient WASM allocator.
32///
33/// If a different custom allocator is desired, disable the `mini-alloc` feature.
34#[cfg(all(target_arch = "wasm32", feature = "mini-alloc"))]
35#[global_allocator]
36static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT;
37
38extern crate alloc;
39
40pub use alloy_primitives;
41pub use alloy_sol_types;
42pub use hex;
43pub use keccak_const;
44pub use stylus_core;
45pub use stylus_proc;
46
47#[cfg(all(feature = "stylus-test", target_arch = "wasm32"))]
48compile_error!("The `stylus-test` feature should not be enabled for wasm32 targets");
49
50// If the target is a testing environment, we export the stylus test module as the `testing` crate
51// for Stylus SDK consumers, to be used as a test framework.
52#[cfg(feature = "stylus-test")]
53pub use rclite as rc;
54#[cfg(feature = "stylus-test")]
55pub use stylus_test as testing;
56
57#[macro_use]
58pub mod abi;
59
60#[macro_use]
61pub mod debug;
62
63pub mod block;
64pub mod call;
65pub mod contract;
66pub mod crypto;
67pub mod deploy;
68pub mod evm;
69pub mod host;
70pub mod methods;
71pub mod msg;
72pub mod prelude;
73pub mod storage;
74pub mod tx;
75pub mod types;
76
77mod util;
78
79#[cfg(feature = "hostio")]
80pub mod hostio;
81
82#[cfg(not(feature = "hostio"))]
83mod hostio;
84
85use alloc::vec::Vec;
86
87/// Represents a contract invocation outcome.
88pub type ArbResult = Result<Vec<u8>, Vec<u8>>;