Loading...
Loading...
Compare original and translation side by side
| Stylus | Solidity | |
|---|---|---|
| Proxy mechanism | Same — | |
| Storage layout | | Sequential slot allocation per Solidity rules |
| EIP standards | ERC-1967 storage slots, ERC-1822 proxiable UUID | Same |
| Context detection | | |
| Initialization | Two-step: constructor sets | Constructor + initializer via proxy |
| Reactivation | WASM contracts must be reactivated every 365 days or after a Stylus protocol upgrade | Not applicable |
#[storage]| 特性 | Stylus | Solidity |
|---|---|---|
| 代理机制 | 相同——通过 | 通过 |
| 存储布局 | | 按照Solidity规则顺序分配存储槽 |
| EIP标准 | ERC-1967存储槽、ERC-1822可代理UUID | 相同 |
| 上下文检测 | 在唯一存储槽中使用 | 将 |
| 初始化 | 两步流程:构造函数设置 | 构造函数 + 通过代理调用初始化方法 |
| 重新激活 | WASM合约必须每365天或在Stylus协议升级后重新激活 | 不适用 |
#[storage]| Pattern | Key types | Best for |
|---|---|---|
| UUPS | | Most projects — upgrade logic in the implementation, lighter proxy |
| Beacon | | Multiple proxies sharing one implementation — updating the beacon upgrades all proxies atomically |
| Basic Proxy | | Low-level building block for custom proxy patterns |
| 模式 | 核心类型 | 适用场景 |
|---|---|---|
| UUPS | | 大多数项目——升级逻辑在实现合约中,代理更轻量化 |
| Beacon | | 多个代理共享同一实现合约——更新Beacon可一次性升级所有代理 |
| 基础代理 | | 用于自定义代理模式的底层构建模块 |
UUPSUpgradeable#[storage]OwnableUUPSUpgradeable#[storage]self.uups.constructor()initializeself.uups.set_version()IUUPSUpgradeableupgrade_to_and_callupgrade_interface_versionself.uupsIErc1822Proxiableproxiable_uuidself.uupsErc1967Proxy#[fallback]set_versioncargo stylus deploysetVersionlet data = MyContractAbi::setVersionCall {}.abi_encode();
// Pass `data` as the proxy constructor's second argument at deployment time.#[storage]UUPSUpgradeableOwnable#[storage]UUPSUpgradeableself.uups.constructor()initializeself.uups.set_version()IUUPSUpgradeableupgrade_to_and_callupgrade_interface_versionself.uupsIErc1822Proxiableproxiable_uuidself.uupsErc1967Proxy#[fallback]set_versioncargo stylus deploysetVersionlet data = MyContractAbi::setVersionCall {}.abi_encode();
// Pass `data` as the proxy constructor's second argument at deployment time.BeaconProxyUpgradeableBeaconBeaconProxyUpgradeableBeaconimmutable__self = address(this)UUPSUpgradeablelogic_flaglogic_flag = truedelegatecallfalseonly_proxy()only_proxy()VERSION_NUMBERExamples: See thedirectory of the rust-contracts-stylus repository for full working integration examples of UUPS, Beacon, and related patterns.examples/
immutableUUPSUpgradeable__self = address(this)logic_flaglogic_flag = truedelegatecallfalseonly_proxy()only_proxy()VERSION_NUMBER示例: 可查看rust-contracts-stylus仓库的目录,获取UUPS、Beacon及相关模式的完整可运行集成示例。examples/
upgrade_to_and_callfn upgrade_to_and_call(&mut self, new_implementation: Address, data: Bytes) -> Result<(), Vec<u8>> {
self.ownable.only_owner()?; // or any access control check
self.uups.upgrade_to_and_call(new_implementation, data)?;
Ok(())
}upgrade_to_and_callfn upgrade_to_and_call(&mut self, new_implementation: Address, data: Bytes) -> Result<(), Vec<u8>> {
self.ownable.only_owner()?; // or any access control check
self.uups.upgrade_to_and_call(new_implementation, data)?;
Ok(())
}#[storage]#[storage]Erc20OwnableUUPSUpgradeable#[storage]#[storage]Erc20OwnableUUPSUpgradeablelogic_flagset_version()upgrade_to_and_callVERSION_NUMBERset_version()logic_flagset_version()upgrade_to_and_callVERSION_NUMBERset_version()upgrade_to_and_callself.ownable.only_owner()only_proxy()delegatecallproxiable_uuid()upgrade_to_and_callself.ownable.only_owner()delegatecallonly_proxy()proxiable_uuid()cargo-stylusArbWasmcargo-stylusArbWasmupgrade_to_and_callupgrade_to_and_callVERSION_NUMBERupgrade_to_and_callupgrade_to_and_callVERSION_NUMBER