-
Notifications
You must be signed in to change notification settings - Fork 359
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 ERC721 preset #811
Merged
martriay
merged 76 commits into
OpenZeppelin:main
from
andrew-fleming:add-erc721-preset
Nov 25, 2023
Merged
Add ERC721 preset #811
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
103375f
consolidate mocks
andrew-fleming 7968708
add erc721abi
andrew-fleming 4e09fb6
migrate to component
andrew-fleming 8da4c00
use abi dispatcher
andrew-fleming 5cc8a6d
start updating tests
andrew-fleming 1f29ac1
add pop_log_comp_indexed
andrew-fleming 8d14e0f
update tests
andrew-fleming 18f5f23
fix formatting
andrew-fleming 3b2259b
add erc721camelabi
andrew-fleming 4396dcc
remove unnecessary trait
andrew-fleming c820965
add code comments
andrew-fleming b42744b
change import style
andrew-fleming aac3940
fix conflicts
andrew-fleming 816a28a
Update src/token/erc721/erc721.cairo
andrew-fleming 682887c
remove unnecessary fn
andrew-fleming 4499d24
change back to pop_log
andrew-fleming 0c9427b
flatten event in mock
andrew-fleming 4e58863
flatten events in mocks
andrew-fleming e8b696a
Merge branch 'main' into component-erc721
andrew-fleming 4e459f9
change receiver to component
andrew-fleming c01445f
fix formatting
andrew-fleming 04be9e9
simplify camel return id
andrew-fleming d89af43
fix imports
andrew-fleming 3f5c77a
fix imports
andrew-fleming ab72343
fix tokenURI
andrew-fleming 2a853c4
add Component suffix
andrew-fleming 4893df9
add Component suffix to receiver
andrew-fleming 3cf4940
fix formatting
andrew-fleming 74ce94e
fix formatting
andrew-fleming 1c106a6
add receiver tests
andrew-fleming 0941a61
fix formatting and test
andrew-fleming cf7b7d6
remove import
andrew-fleming d5feed7
add code comments
andrew-fleming 0cc9420
fix conflicts
andrew-fleming 35f144c
fix conflicts
andrew-fleming e8f6a3a
simplify with get_dep_component_mut
andrew-fleming 50e7f26
add recipient to constructor
andrew-fleming cd86147
remove unused mocks
andrew-fleming 9ee7511
simplify mocks
andrew-fleming 8d0cd9c
fix formatting
andrew-fleming 974c942
add erc721 preset
andrew-fleming 65ef95e
add erc721 preset
andrew-fleming eb9c55c
start preset tests
andrew-fleming f0d7a0f
fix formatting
andrew-fleming 9baca0d
fix test
andrew-fleming 53c5ac5
finish tests
andrew-fleming dbe5f61
fix formatting
andrew-fleming 81d7971
remove import
andrew-fleming d518fcf
Update src/tests/token/test_erc721.cairo
andrew-fleming 8094a96
fix impl order
andrew-fleming 8efe05e
Merge branch 'component-erc721' into add-erc721-preset
andrew-fleming 0f5ae41
Apply suggestions from code review
andrew-fleming aa24838
change param to span
andrew-fleming 1f13281
add constructor tests
andrew-fleming 2905387
fix formatting
andrew-fleming 263defe
add in-code comments
andrew-fleming f917443
fix fn order
andrew-fleming a048b8a
fix title
andrew-fleming b4591ab
Apply suggestions from code review
andrew-fleming baff1e8
fix formatting
andrew-fleming dffc3b9
fix impl order
andrew-fleming 24460d0
fix src5 comment
andrew-fleming 5b65a6e
add info in comments
andrew-fleming 00eaad7
fix component impl order
andrew-fleming d5d5592
change back import style
andrew-fleming 76ba674
Merge branch 'component-erc721' into add-erc721-preset
andrew-fleming 6238c1e
fix conflicts
andrew-fleming b838c61
fix component order
andrew-fleming bad7662
remove extra line
andrew-fleming 403cc85
remove unused imports
andrew-fleming 9dc86dc
fix comment
andrew-fleming 314ba29
add drop_events
andrew-fleming 3f3e237
reorder preset components
andrew-fleming cde00a4
fix conflicts
andrew-fleming b13e02e
fix tests
andrew-fleming bc45dec
set owner as caller in setup
andrew-fleming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod account; | ||
mod erc20; | ||
mod erc721; | ||
|
||
use account::Account; | ||
use erc20::ERC20; | ||
use erc721::ERC721; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts for Cairo v0.8.0-beta.0 (presets/erc721.cairo) | ||
|
||
/// # ERC721 Preset | ||
/// | ||
/// The ERC721 contract offers a batch-mint mechanism that | ||
/// can only be executed once upon contract construction. | ||
#[starknet::contract] | ||
mod ERC721 { | ||
use openzeppelin::introspection::src5::SRC5Component; | ||
use openzeppelin::token::erc721::ERC721Component; | ||
use starknet::ContractAddress; | ||
|
||
component!(path: ERC721Component, storage: erc721, event: ERC721Event); | ||
component!(path: SRC5Component, storage: src5, event: SRC5Event); | ||
|
||
// ERC721 | ||
#[abi(embed_v0)] | ||
impl ERC721Impl = ERC721Component::ERC721Impl<ContractState>; | ||
#[abi(embed_v0)] | ||
impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl<ContractState>; | ||
#[abi(embed_v0)] | ||
impl ERC721CamelOnly = ERC721Component::ERC721CamelOnlyImpl<ContractState>; | ||
#[abi(embed_v0)] | ||
impl ERC721MetadataCamelOnly = | ||
ERC721Component::ERC721MetadataCamelOnlyImpl<ContractState>; | ||
impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>; | ||
|
||
// SRC5 | ||
#[abi(embed_v0)] | ||
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>; | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
erc721: ERC721Component::Storage, | ||
#[substorage(v0)] | ||
src5: SRC5Component::Storage | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
#[flat] | ||
ERC721Event: ERC721Component::Event, | ||
#[flat] | ||
SRC5Event: SRC5Component::Event | ||
} | ||
|
||
mod Errors { | ||
const UNEQUAL_ARRAYS: felt252 = 'Array lengths do not match'; | ||
} | ||
|
||
/// Sets the token `name` and `symbol`. | ||
/// Mints the `token_ids` tokens to `recipient` and sets | ||
/// each token's URI. | ||
#[constructor] | ||
fn constructor( | ||
ref self: ContractState, | ||
name: felt252, | ||
symbol: felt252, | ||
recipient: ContractAddress, | ||
token_ids: Span<u256>, | ||
token_uris: Span<felt252> | ||
) { | ||
self.erc721.initializer(name, symbol); | ||
self._mint_assets(recipient, token_ids, token_uris); | ||
} | ||
|
||
/// Mints `token_ids` to `recipient`. | ||
/// Sets the token URI from `token_uris` to the corresponding | ||
/// token ID of `token_ids`. | ||
/// | ||
/// Requirements: | ||
/// | ||
/// - `token_ids` must be equal in length to `token_uris`. | ||
#[generate_trait] | ||
impl InternalImpl of InternalTrait { | ||
fn _mint_assets( | ||
ref self: ContractState, | ||
recipient: ContractAddress, | ||
mut token_ids: Span<u256>, | ||
mut token_uris: Span<felt252> | ||
) { | ||
assert(token_ids.len() == token_uris.len(), Errors::UNEQUAL_ARRAYS); | ||
|
||
loop { | ||
if token_ids.len() == 0 { | ||
break; | ||
} | ||
let id = *token_ids.pop_front().unwrap(); | ||
let uri = *token_uris.pop_front().unwrap(); | ||
|
||
self.erc721._mint(recipient, id); | ||
self.erc721._set_token_uri(id, uri); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod test_account; | ||
mod test_erc20; | ||
mod test_erc721; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that it may be easier to add the license with X.Y.Z version, because before releasing it would be easier to find these new files with a quick search, instead of having to implement other mechanisms for not forgetting some. what do you think cc @martriay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we care about new files only? we want to update them all even if they're
v0.7.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean adding the XYZ instead of removing the license line, because files without the license line are harder to find with Ctrl+Shift+F
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why do we want to identify new files specifically?