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

Document Class Hashes #832

Merged
merged 24 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
331844d
fix: link (#545)
ericnordelo Jan 20, 2023
2e7758e
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Oct 6, 2023
77cca2d
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Oct 10, 2023
8a19908
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Oct 18, 2023
2f3d020
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Oct 24, 2023
a2f062e
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Oct 25, 2023
1cbb5ed
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Nov 2, 2023
b4ee9c8
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Nov 10, 2023
fc522b6
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Nov 13, 2023
be442ab
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts
ericnordelo Nov 24, 2023
0415452
feat: add page
ericnordelo Nov 27, 2023
261cb7a
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Nov 27, 2023
bc12e61
feat: finish UI
ericnordelo Nov 27, 2023
257c6b2
Update docs/modules/ROOT/pages/api/erc721.adoc
ericnordelo Nov 29, 2023
e8b6bab
feat: apply review updates
ericnordelo Nov 29, 2023
e53088e
Merge branch 'feat/class-hashes-#555' of github.com:ericnordelo/cairo…
ericnordelo Nov 29, 2023
9327d7f
fix: remove trailing space
ericnordelo Nov 29, 2023
d01aca7
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Nov 29, 2023
1889cf7
feat: update CHANGELOG
ericnordelo Nov 29, 2023
5805d33
Update CHANGELOG.md
ericnordelo Dec 4, 2023
b82a84c
feat: apply review updates
ericnordelo Dec 4, 2023
57275f0
Merge branch 'feat/class-hashes-#555' of github.com:ericnordelo/cairo…
ericnordelo Dec 4, 2023
77a420e
feat: apply review updates
ericnordelo Dec 12, 2023
965214c
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Documentation for presets (#832)
2 changes: 2 additions & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
// * xref:udc.adoc[Universal Deployer Contract]
// * xref:utilities.adoc[Utilities]

* xref:/presets.adoc[Presets]

* xref:contracts::index.adoc[Contracts for Solidity]
8 changes: 8 additions & 0 deletions docs/modules/ROOT/pages/api/account.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ use openzeppelin::presets::Account;

Basic account contract leveraging xref:#AccountComponent[AccountComponent].

include::../utils/_class_hashes.adoc[]

[.contract-index]
.{class-hashes-page}
--
{account-class-hash}
--

[.contract-index]
.Constructor
--
Expand Down
11 changes: 9 additions & 2 deletions docs/modules/ROOT/pages/api/erc20.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ use openzeppelin::presets::ERC20;

Basic ERC20 contract leveraging xref:#ERC20Component[ERC20Component] with a fixed-supply mechanism for token distribution.

include::../utils/_class_hashes.adoc[]

[.contract-index]
.{class-hashes-page}
--
{erc20-class-hash}
--

[.contract-index]
.Constructor
--
Expand All @@ -509,5 +517,4 @@ Basic ERC20 contract leveraging xref:#ERC20Component[ERC20Component] with a fixe
[[ERC20-constructor]]
==== `[.contract-item-name]#++constructor++#++(ref self: ContractState, name: felt252, symbol: felt252, fixed_supply: u256, recipient: ContractAddress)++` [.item-kind]#constructor#

Sets the `name` and `symbol`.
Mints `fixed_supply` tokens to `recipient`.
Sets the `name` and `symbol` and mints `fixed_supply` tokens to `recipient`.
72 changes: 62 additions & 10 deletions docs/modules/ROOT/pages/api/erc721.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ Returns the owner address of `token_id`.

Transfer ownership of `token_id` from `from` to `to`, checking first that `to` is aware of the ERC721 protocol to prevent tokens being locked forever.
For information regarding how contracts communicate their awareness of the ERC721 protocol, see {receiving-tokens}.

Emits a <<IERC721-Transfer,Transfer>> event.

[.contract-item]
[[IERC721-transfer_from]]
==== `[.contract-item-name]#++transfer_from++#++(from: ContractAddress, to: ContractAddress, token_id: u256)++` [.item-kind]#external#

Transfer ownership of `token_id` from `from` to `to`.

Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 transfers or else they may be permanently lost.
Usage of <<IERC721-safe_transfer_from,IERC721::safe_transfer_from>> prevents loss, though the caller must understand this adds an external call which potentially creates a reentrancy vulnerability.

Emits a <<IERC721-Transfer,Transfer>> event.

[.contract-item]
Expand Down Expand Up @@ -190,8 +190,8 @@ ERC721 component implementing <<IERC721,IERC721>> and <<IERC721Metadata,IERC721M

NOTE: Implementing xref:api/introspection.adoc#SRC5Component[SRC5Component] is a requirement for this component to be implemented.

[.contract-index]
.External functions
[.contract-index#ERC721Component-Embeddable-Impls]
.Embeddable Implementations
--
.IERC721Impl
* xref:#IERC721-balance_of[`++balance_of(self, account)++`]
Expand All @@ -209,8 +209,8 @@ NOTE: Implementing xref:api/introspection.adoc#SRC5Component[SRC5Component] is a
* xref:#IERC721Metadata-token_uri[`++token_uri(self, token_id)++`]
--

[.contract-index]
.camelCase support
[.contract-index#ERC721Component-Embeddable-Impls-camelCase]
.Embeddable implementations (camelCase)
--
.ER721CamelOnlyImpl
* xref:#ERC721-balanceOf[`++balanceOf(self, account)++`]
Expand Down Expand Up @@ -550,19 +550,19 @@ Requirements:
==== Events

[.contract-item]
[[IERC721-Approval]]
[[ERC721-Approval]]
==== `[.contract-item-name]#++Approval++#++(owner: ContractAddress, approved: ContractAddress, token_id: u256)++` [.item-kind]#event#

See <<IERC721-Approval,Approval>>.

[.contract-item]
[[IERC721-ApprovalForAll]]
[[ERC721-ApprovalForAll]]
==== `[.contract-item-name]#++ApprovalForAll++#++(owner: ContractAddress, operator: ContractAddress, approved: bool)++` [.item-kind]#event#

See <<IERC721-ApprovalForAll,ApprovalForAll>>.

[.contract-item]
[[IERC721-Transfer]]
[[ERC721-Transfer]]
==== `[.contract-item-name]#++Transfer++#++(from: ContractAddress, to: ContractAddress, token_id: u256)++` [.item-kind]#event#

See <<IERC721-Transfer,Transfer>>.
Expand Down Expand Up @@ -597,3 +597,55 @@ Interface for contracts that support receiving `safe_transfer_from` transfers.
==== `[.contract-item-name]#++on_erc721_received++#++(operator: ContractAddress, from: ContractAddress, token_id: u256, data Span<felt252>) -> felt252++` [.item-kind]#external#

Whenever an IERC721 `token_id` token is transferred to this non-account contract via <<IERC721-safe_transfer_from,IERC721::safe_transfer_from>> by `operator` from `from`, this function is called.

== Presets

[.contract]
[[ERC721]]
=== `++ERC721++` link:https://github.com/OpenZeppelin/cairo-contracts/blob/release-v0.8.0/src/presets/erc721.cairo[{github-icon},role=heading-link]

```javascript
use openzeppelin::presets::ERC721;
```

Basic ERC721 contract leveraging xref:#ERC721Component[ERC721Component].

include::../utils/_class_hashes.adoc[]

[.contract-index]
.{class-hashes-page}
--
{erc721-class-hash}
--

[.contract-index]
.Constructor
--
* xref:#ERC721-constructor[`++constructor(self, name, symbol, recipient, token_ids, token_uris)++`]
--

[.contract-index]
.Embedded Implementations
--
.ERC721Component

* xref:#ERC721Component-Embeddable-Impls[`++ERC721Impl++`]
* xref:#ERC721Component-Embeddable-Impls[`++ERC721MetadataImpl++`]
* xref:#ERC721Component-Embeddable-Impls-camelCase[`++ERC721CamelOnly++`]
* xref:#ERC721Component-Embeddable-Impls-camelCase[`++ERC721MetadataCamelOnly++`]

.SRC5Component

* xref:api/introspection.adoc#SRC5Component-Embeddable-Impls[`++SRC5Impl++`]
--

[#ERC721-constructor-section]
==== Constructor

[.contract-item]
[[ERC721-constructor]]
==== `[.contract-item-name]#++constructor++#++(ref self: ContractState, name: felt252, symbol: felt252, recipient: ContractAddress, token_ids: Span<u256>, token_uris: Span<felt252>)++` [.item-kind]#constructor#

Sets the `name` and `symbol`.

Mints `token_ids` tokens with each corresponding URI from `token_uris` to `recipient`.
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/erc721.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ trait IERC721ABI {

:erc165-storage: https://docs.openzeppelin.com/contracts/4.x/api/utils#ERC165Storage[ERC165Storage]
:src5-api: xref:introspection.adoc#src5[SRC5]
:introspection: xref:introspection.adoc[Introspection]
:eip165: https://eips.ethereum.org/EIPS/eip-165[EIP165]

Although Starknet is not EVM compatible, this implementation aims to be as close as possible to the ERC721 standard by utilizing Cairo's short strings to simulate `name` and `symbol`.
Expand Down
36 changes: 36 additions & 0 deletions docs/modules/ROOT/pages/presets.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
:scarb: https://docs.swmansion.com/scarb[scarb]

= Presets

include::utils/_class_hashes.adoc[]

List of "ready-to-deploy" presets available and their corresponding class hashes.

:account: xref:/api/account.adoc#Account[Account.cairo]
:erc20: xref:/api/erc20.adoc#ERC20[ERC20.cairo]
:erc721: xref:/api/erc721.adoc#ERC721[ERC721.cairo]
:cairo-and-sierra: https://docs.starknet.io/documentation/architecture_and_concepts/Smart_Contracts/cairo-and-sierra/[Cairo and Sierra]

NOTE: Class hashes were computed using {class-hash-cairo-version}.

|===
| Name | Compiled Class Hash

| `{account}`
| `{account-class-hash}`

| `{erc20}`
| `{erc20-class-hash}`

| `{erc721}`
| `{erc721-class-hash}`
|===

:starkli: https://book.starkli.rs/introduction[starkli]

To understand the compiled class hash term, check {cairo-and-sierra}.

TIP: {starkli} class-hash command can be used to compute the class hash from a compiled artifact.

TIP: To obtain the artifact
using {scarb}, set the `casm = true` option under `\[[target.starknet-contract]]` in the `Scarb.toml` file.
10 changes: 10 additions & 0 deletions docs/modules/ROOT/pages/utils/_class_hashes.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Version
:class-hash-cairo-version: https://crates.io/crates/cairo-lang-compiler/2.3.1[cairo 2.3.1]

// Class Hashes
:account-class-hash: 0x016c6081eb34ad1e0c5513234ed0c025b3c7f305902d291bad534cd6474c85bc
:erc20-class-hash: 0x01d7085cee580ba542cdb5709bda80ebfe8bdede664261a3e6af92994d9a1de7
:erc721-class-hash: 0x04376782cbcd20a05f8e742e96150757383dab737ab3e791b8505ad856756907

// Presets page
:class-hashes-page: xref:presets.adoc[Compiled class hash]
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved