Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SRC107 to ERC20 (simpler customizable decimals) #1294

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: update doc examples
ericnordelo committed Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1ba88f6766ced344453829dcfa2d22e0ce0fd03f
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 3 additions & 3 deletions docs/modules/ROOT/pages/access.adoc
Original file line number Diff line number Diff line change
@@ -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};

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