Skip to content

Commit

Permalink
feat: update doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnordelo committed Jan 10, 2025
1 parent 64f9f63 commit 1ba88f6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/ROOT/pages/access.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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};

Expand Down
8 changes: 3 additions & 5 deletions docs/modules/ROOT/pages/components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

(...)
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/erc20.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -164,7 +164,7 @@ impl ERC20MetadataImpl of interface::IERC20Metadata<ContractState> {

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]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/governance/votes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1ba88f6

Please sign in to comment.