OpenZeppelin Contracts for Stylus

一个安全的、模块化的智能合约库,适用于 Stylus,用 Rust 编写。

OpenZeppelin Contracts for Stylus 将经过时间考验的智能合约模式引入到 Arbitrum 基于 WASM 的执行环境。该库提供了与 no_std 兼容的模块,用于在 Stylus 中构建安全、可重用的合约。

特性

  • ✨ 从 openzeppelin-contracts 移植的安全至上的合约。

  • 📦 用 Rust 编写,完全支持 no_std

  • 🧪 通过单元测试和集成测试进行测试。

  • 🚧 积极开发中。

快速开始

将依赖项添加到您的 Cargo.toml 中:

[dependencies]
openzeppelin-stylus = "=0.2.0"

启用 ABI 导出特性:

[features]
export-abi = ["openzeppelin-stylus/export-abi"]

使用示例

使用该库的最小 ERC-20 实现:

use openzeppelin_stylus::token::erc20::{self, Erc20, IErc20};
use stylus_sdk::{
    alloy_primitives::{Address, U256},
    prelude::*,
};

#[entrypoint]
#[storage]
struct Erc20Example {
    erc20: Erc20,
}

#[public]
#[implements(IErc20<Error = erc20::Error>)]
impl Erc20Example {}

#[public]
impl IErc20 for Erc20Example {
    // ERC-20 逻辑实现...
}

examples 目录中探索更多示例。

兼容性

该库旨在与 no_std 一起使用。为了保持您的合约兼容,请禁用拉取标准库的任何依赖项的默认特性:

[dependencies]
alloy-primitives = { version = "=0.8.20", default-features = false }
stylus-sdk = "=0.9.0"

路线图 & 贡献

在我们的 路线图中查看计划中或正在开发的内容。

有兴趣贡献吗?阅读 贡献指南

安全

虽然该库正在积极开发中,但安全仍然是重中之重。有关过去的审计和安全报告,请参见 audits 目录

许可证

MIT 许可证下发布。