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

Feat: token erc721 uristorage #109

2 changes: 1 addition & 1 deletion cairo/src/contracts/client/router_component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub mod RouterComponent {
}

#[embeddable_as(RouterImpl)]
impl Router<
pub impl Router<
TContractState,
+HasComponent<TContractState>,
+MailboxclientComponent::HasComponent<TContractState>,
Expand Down
21 changes: 18 additions & 3 deletions cairo/src/contracts/token/components/erc721_uri_storage.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#[starknet::interface]
pub trait IERC721URIStorage<TContractState> {
fn name(self: @TContractState) -> ByteArray;
fn symbol(self: @TContractState) -> ByteArray;
fn token_uri(self: @TContractState, token_id: u256) -> ByteArray;
}

#[starknet::component]
pub mod ERC721URIStorageComponent {
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc721::interface::IERC721Metadata;
use openzeppelin::token::erc721::{
ERC721Component, ERC721Component::InternalTrait as ERC721InternalTrait,
ERC721Component::ERC721HooksTrait, ERC721Component::ERC721MetadataImpl
Expand All @@ -18,7 +21,7 @@ pub mod ERC721URIStorageComponent {

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
pub enum Event {
MetadataUpdate: MetadataUpdate,
}

Expand All @@ -28,14 +31,26 @@ pub mod ERC721URIStorageComponent {
}

#[embeddable_as(ERC721URIStorageImpl)]
impl ERC721URIStorage<
pub impl ERC721URIStorage<
TContractState,
+HasComponent<TContractState>,
+Drop<TContractState>,
+SRC5Component::HasComponent<TContractState>,
+ERC721HooksTrait<TContractState>,
impl ERC721: ERC721Component::HasComponent<TContractState>,
> of super::IERC721URIStorage<ComponentState<TContractState>> {
// returns the NFT name
fn name(self: @ComponentState<TContractState>) -> ByteArray {
let erc721_component = get_dep_component!(self, ERC721);
erc721_component.name()
}

// returns the NFT symbol
fn symbol(self: @ComponentState<TContractState>) -> ByteArray {
let erc721_component = get_dep_component!(self, ERC721);
erc721_component.symbol()
}

/// Returns the URI associated with a given `token_id`.
///
/// This function retrieves the URI for an ERC721 token based on its `token_id`.
Expand Down Expand Up @@ -71,7 +86,7 @@ pub mod ERC721URIStorageComponent {
}

#[generate_trait]
impl ERC721URIStorageInternalImpl<
pub impl ERC721URIStorageInternalImpl<
TContractState,
+HasComponent<TContractState>,
+Drop<TContractState>,
Expand Down
63 changes: 5 additions & 58 deletions cairo/src/contracts/token/components/hyp_erc721_component.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use starknet::{ContractAddress, ClassHash};

#[starknet::interface]
pub trait IHypErc721<TState> {
fn initialize(ref self: TState, mint_amount: u256, name: ByteArray, symbol: ByteArray,);
fn initialize(ref self: TState, mint_amount: u256, name: ByteArray, symbol: ByteArray);
}

#[starknet::component]
Expand All @@ -22,23 +20,21 @@ pub mod HypErc721Component {
ERC721Component::InternalTrait as ERC721InternalTrait, ERC721Component::ERC721HooksTrait,
};

use starknet::{ContractAddress, ClassHash};


#[storage]
struct Storage {}

#[embeddable_as(HypErc721Impl)]
impl HypErc721<
#[generate_trait]
pub impl HypErc721InternalImpl<
TContractState,
+HasComponent<TContractState>,
+Drop<TContractState>,
+OwnableComponent::HasComponent<TContractState>,
+SRC5Component::HasComponent<TContractState>,
+ERC721Component::ERC721HooksTrait<TContractState>,
+ERC721HooksTrait<TContractState>,
impl Mailboxclient: MailboxclientComponent::HasComponent<TContractState>,
impl ERC721: ERC721Component::HasComponent<TContractState>,
> of super::IHypErc721<ComponentState<TContractState>> {
> of HypErc721InternalTrait<TContractState> {
/// Initializes the ERC721 token contract with a specified mint amount, name, and symbol.
///
/// This function sets the name and symbol for the ERC721 token contract and mints the specified number
Expand Down Expand Up @@ -68,53 +64,4 @@ pub mod HypErc721Component {
};
}
}

#[generate_trait]
impl HypErc721InternalImpl<
TContractState,
+HasComponent<TContractState>,
+Drop<TContractState>,
+SRC5Component::HasComponent<TContractState>,
+ERC721Component::ERC721HooksTrait<TContractState>,
impl ERC721: ERC721Component::HasComponent<TContractState>,
> of InternalTrait<TContractState> {
/// Burns a token owned by the sender.
///
/// This function ensures that the sender is the owner of the specified token before burning it.
/// The token is permanently removed from the sender's balance.
///
/// # Arguments
///
/// * `token_id` - A `u256` representing the ID of the token to be burned.
///
/// # Panics
///
/// Panics if the caller is not the owner of the token.
fn transfer_from_sender(ref self: ComponentState<TContractState>, token_id: u256) {
let erc721_comp_read = get_dep_component!(@self, ERC721);
assert!(
erc721_comp_read.owner_of(token_id) == starknet::get_caller_address(),
"Caller is not owner of token"
);

let mut erc721_comp_write = get_dep_component_mut!(ref self, ERC721);
erc721_comp_write.burn(token_id);
}

/// Mints a token to a specified recipient.
///
/// This function mints the specified token to the given recipient's address. The newly minted token
/// will be transferred to the recipient.
///
/// # Arguments
///
/// * `recipient` - A `ContractAddress` representing the recipient's address.
/// * `token_id` - A `u256` representing the ID of the token to be minted.
fn transfer_to(
ref self: ComponentState<TContractState>, recipient: ContractAddress, token_id: u256
) {
let mut erc721_comp_write = get_dep_component_mut!(ref self, ERC721);
erc721_comp_write.mint(recipient, token_id);
}
}
}
2 changes: 1 addition & 1 deletion cairo/src/contracts/token/components/token_router.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub mod TokenRouterComponent {
}

#[embeddable_as(TokenRouterImpl)]
impl TokenRouter<
pub impl TokenRouter<
TContractState,
+HasComponent<TContractState>,
+Drop<TContractState>,
Expand Down
Loading
Loading