From 1ba88f6766ced344453829dcfa2d22e0ce0fd03f Mon Sep 17 00:00:00 2001 From: Eric Nordelo Date: Fri, 10 Jan 2025 14:04:33 +0100 Subject: [PATCH] feat: update doc examples --- README.md | 2 +- docs/modules/ROOT/pages/access.adoc | 6 +++--- docs/modules/ROOT/pages/components.adoc | 8 +++----- docs/modules/ROOT/pages/erc20.adoc | 4 ++-- docs/modules/ROOT/pages/governance/votes.adoc | 2 +- docs/modules/ROOT/pages/index.adoc | 14 ++++++++++++-- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4bbab1e00..c41b76482 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ For example, this is how to write an ERC20-compliant contract: ```cairo #[starknet::contract] mod MyToken { - use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl, DefaultConfig}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); diff --git a/docs/modules/ROOT/pages/access.adoc b/docs/modules/ROOT/pages/access.adoc index 752c7ffc9..aa6d07efa 100644 --- a/docs/modules/ROOT/pages/access.adoc +++ b/docs/modules/ROOT/pages/access.adoc @@ -176,7 +176,7 @@ const MINTER_ROLE: felt252 = selector!("MINTER_ROLE"); mod MyContract { use openzeppelin_access::accesscontrol::AccessControlComponent; use openzeppelin_introspection::src5::SRC5Component; - use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl, DefaultConfig}; use starknet::ContractAddress; use super::MINTER_ROLE; @@ -267,7 +267,7 @@ const BURNER_ROLE: felt252 = selector!("BURNER_ROLE"); mod MyContract { use openzeppelin_access::accesscontrol::AccessControlComponent; use openzeppelin_introspection::src5::SRC5Component; - use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl, DefaultConfig}; use starknet::ContractAddress; use super::{MINTER_ROLE, BURNER_ROLE}; @@ -390,7 +390,7 @@ mod MyContract { use openzeppelin_access::accesscontrol::AccessControlComponent; use openzeppelin_access::accesscontrol::DEFAULT_ADMIN_ROLE; use openzeppelin_introspection::src5::SRC5Component; - use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl, DefaultConfig}; use starknet::ContractAddress; use super::{MINTER_ROLE, BURNER_ROLE}; diff --git a/docs/modules/ROOT/pages/components.adoc b/docs/modules/ROOT/pages/components.adoc index 7d6ad92e1..e90dd2c8e 100644 --- a/docs/modules/ROOT/pages/components.adoc +++ b/docs/modules/ROOT/pages/components.adoc @@ -483,7 +483,7 @@ The following snippet leverages the `before_update` hook to include this behavio mod MyToken { use openzeppelin_security::pausable::PausableComponent::InternalTrait; use openzeppelin_security::pausable::PausableComponent; - use openzeppelin_token::erc20::ERC20Component; + use openzeppelin_token::erc20::{ERC20Component, DefaultConfig}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); @@ -535,7 +535,7 @@ The using contract just needs to bring the implementation into scope like this: ---- #[starknet::contract] mod MyToken { - use openzeppelin_token::erc20::ERC20Component; + use openzeppelin_token::erc20::{ERC20Component, DefaultConfig}; use openzeppelin_token::erc20::ERC20HooksEmptyImpl; (...) @@ -559,7 +559,7 @@ Here's the setup: #[starknet::contract] mod ERC20Pausable { use openzeppelin_security::pausable::PausableComponent; - use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl, DefaultConfig}; // Import the ERC20 interfaces to create custom implementations use openzeppelin_token::erc20::interface::{IERC20, IERC20CamelOnly}; use starknet::ContractAddress; @@ -651,8 +651,6 @@ This is why the contract defined the `ERC20Impl` from the component in the previ Creating a custom implementation of an interface must define *all* methods from that interface. This is true even if the behavior of a method does not change from the component implementation (as `total_supply` exemplifies in this example). -TIP: The ERC20 documentation provides another custom implementation guide for {custom-decimals}. - === Accessing component storage There may be cases where the contract must read or write to an integrated component's storage. diff --git a/docs/modules/ROOT/pages/erc20.adoc b/docs/modules/ROOT/pages/erc20.adoc index b73124f12..3a4ac4e2c 100644 --- a/docs/modules/ROOT/pages/erc20.adoc +++ b/docs/modules/ROOT/pages/erc20.adoc @@ -23,7 +23,7 @@ Here's what that looks like: ---- #[starknet::contract] mod MyToken { - use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl, DefaultConfig}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event); @@ -164,7 +164,7 @@ impl ERC20MetadataImpl of interface::IERC20Metadata { For more complex scenarios, such as a factory deploying multiple tokens with differing values for decimals, a flexible solution might be appropriate. -TIP: Note that we are not using the MixinImpl in this case, since we need to customize the IERC20Metadata implementation. +TIP: Note that we are not using the MixinImpl or the DefaultConfig in this case, since we need to customize the IERC20Metadata implementation. [,cairo] ---- diff --git a/docs/modules/ROOT/pages/governance/votes.adoc b/docs/modules/ROOT/pages/governance/votes.adoc index 67df15525..9445673f7 100644 --- a/docs/modules/ROOT/pages/governance/votes.adoc +++ b/docs/modules/ROOT/pages/governance/votes.adoc @@ -33,7 +33,7 @@ Here's an example of how to structure a simple ERC20Votes contract: #[starknet::contract] mod ERC20VotesContract { use openzeppelin_governance::votes::VotesComponent; - use openzeppelin_token::erc20::ERC20Component; + use openzeppelin_token::erc20::{ERC20Component, DefaultConfig}; use openzeppelin_utils::cryptography::nonces::NoncesComponent; use openzeppelin_utils::cryptography::snip12::SNIP12Metadata; use starknet::ContractAddress; diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 9db691184..8e2255f32 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -61,18 +61,28 @@ Install the library by declaring it as a dependency in the project's `Scarb.toml openzeppelin = "0.20.0" ---- -WARNING: Make sure the tag matches the target release. +The previous example would import the entire library. We can also add each package as a separate dependency to +improve the building time by not including modules that won't be used: + +[,text] +---- +[dependencies] +openzeppelin_access = "0.20.0" +openzeppelin_token = "0.20.0" +---- == Basic usage This is how it looks to build an ERC20 contract using the xref:erc20.adoc[ERC20 component]. Copy the code into `src/lib.cairo`. +TIP: If you added the entire library as a dependency, use `openzeppelin::token` instead of `openzeppelin_token` for the imports. + [,cairo] ---- #[starknet::contract] mod MyERC20Token { - use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl, DefaultConfig}; use starknet::ContractAddress; component!(path: ERC20Component, storage: erc20, event: ERC20Event);