openzeppelin_stylus/lib.rs
1/*!
2# OpenZeppelin Contracts for Stylus
3
4A library for secure smart contract development written in Rust for
5[Arbitrum Stylus](https://docs.arbitrum.io/stylus/gentle-introduction).
6This library offers common smart contract primitives and affordances that take
7advantage of the nature of Stylus.
8
9## Usage
10
11To start using it, add `openzeppelin-stylus` to your `Cargo.toml`, or simply run
12`cargo add openzeppelin-stylus`.
13
14```toml
15[dependencies]
16openzeppelin-stylus = "x.x.x"
17```
18
19We recommend pinning to a specific version -- expect rapid iteration.
20
21Once defined as a dependency, use one of our pre-defined implementations by
22importing them:
23
24```ignore
25use openzeppelin_stylus::token::erc20::{self, Erc20, IErc20};
26use stylus_sdk::{
27 alloy_primitives::{Address, U256},
28 prelude::*,
29};
30
31#[entrypoint]
32#[storage]
33struct MyContract {
34 pub erc20: Erc20,
35}
36
37#[public]
38#[implements(IErc20<Error = erc20::Error>)]
39impl MyContract {}
40
41#[public]
42impl IErc20 for MyContract {
43 type Error = erc20::Error;
44
45 fn total_supply(&self) -> U256 {
46 self.erc20.total_supply()
47 }
48
49 fn balance_of(&self, account: Address) -> U256 {
50 self.erc20.balance_of(account)
51 }
52
53 fn transfer(
54 &mut self,
55 to: Address,
56 value: U256,
57 ) -> Result<bool, Self::Error> {
58 self.erc20.transfer(to, value)
59 }
60
61 fn allowance(&self, owner: Address, spender: Address) -> U256 {
62 self.erc20.allowance(owner, spender)
63 }
64
65 fn approve(
66 &mut self,
67 spender: Address,
68 value: U256,
69 ) -> Result<bool, Self::Error> {
70 self.erc20.approve(spender, value)
71 }
72
73 fn transfer_from(
74 &mut self,
75 from: Address,
76 to: Address,
77 value: U256,
78 ) -> Result<bool, Self::Error> {
79 self.erc20.transfer_from(from, to, value)
80 }
81}
82```
83*/
84
85#![allow(
86 clippy::module_name_repetitions,
87 clippy::used_underscore_items,
88 clippy::unreadable_literal,
89 deprecated
90)]
91#![cfg_attr(not(any(test, feature = "export-abi")), no_std, no_main)]
92#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
93#![deny(rustdoc::broken_intra_doc_links)]
94extern crate alloc;
95
96pub mod access;
97pub mod finance;
98pub mod proxy;
99pub mod token;
100pub mod utils;