-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
11 deletions.
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
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
112 changes: 112 additions & 0 deletions
112
cairo/src/contracts/token/components/hyp_erc721_component.cairo
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,112 @@ | ||
use starknet::{ContractAddress, ClassHash}; | ||
|
||
#[starknet::interface] | ||
pub trait IHypErc721<TState> { | ||
fn initialize( | ||
ref self: TState, | ||
mint_amount: u256, | ||
name: ByteArray, | ||
symbol: ByteArray, | ||
hook: ContractAddress, | ||
interchain_security_module: ContractAddress, | ||
owner: ContractAddress | ||
); | ||
} | ||
|
||
#[starknet::component] | ||
pub mod HypErc721 { | ||
use hyperlane_starknet::contracts::client::gas_router_component::{ | ||
GasRouterComponent, GasRouterComponent::GasRouterInternalImpl | ||
}; | ||
use hyperlane_starknet::contracts::client::mailboxclient_component::{ | ||
MailboxclientComponent, MailboxclientComponent::MailboxClientInternalImpl, | ||
MailboxclientComponent::MailboxClient | ||
}; | ||
use hyperlane_starknet::contracts::client::router_component::{ | ||
RouterComponent, RouterComponent::RouterComponentInternalImpl, IRouter, | ||
}; | ||
use hyperlane_starknet::contracts::token::components::token_message::TokenMessageTrait; | ||
use hyperlane_starknet::contracts::token::components::token_router::TokenRouterComponent; | ||
use openzeppelin::access::ownable::{ | ||
OwnableComponent, OwnableComponent::InternalImpl as OwnableInternalImpl | ||
}; | ||
use openzeppelin::introspection::src5::{ | ||
SRC5Component, SRC5Component::SRC5Impl, SRC5Component::InternalTrait as SRC5InternalTrait | ||
}; | ||
use openzeppelin::token::erc721::{ | ||
ERC721Component, ERC721Component::ERC721, | ||
ERC721Component::InternalImpl as ERC721InternalImpl, | ||
ERC721Component::InternalTrait as ERC721InternalTrait, | ||
ERC721Component::ERC721HooksTrait, | ||
}; | ||
|
||
use starknet::{ContractAddress, ClassHash}; | ||
|
||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[embeddable_as(HypErc721Impl)] | ||
impl HypErc721< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
+Drop<TContractState>, | ||
+OwnableComponent::HasComponent<TContractState>, | ||
+SRC5Component::HasComponent<TContractState>, | ||
+ERC721Component::ERC721HooksTrait<TContractState>, | ||
impl MailBoxClient: MailboxclientComponent::HasComponent<TContractState>, | ||
impl ERC721: ERC721Component::HasComponent<TContractState>, | ||
> of super::IHypErc721<ComponentState<TContractState>> { | ||
fn initialize( | ||
ref self: ComponentState<TContractState>, | ||
mint_amount: u256, | ||
name: ByteArray, | ||
symbol: ByteArray, | ||
hook: ContractAddress, | ||
interchain_security_module: ContractAddress, | ||
owner: ContractAddress | ||
) { | ||
let mut mailbox_comp = get_dep_component_mut!(ref self, MailBoxClient); | ||
mailbox_comp._MailboxClient_initialize(hook, interchain_security_module, owner); | ||
|
||
let mut erc721_comp = get_dep_component_mut!(ref self, ERC721); | ||
erc721_comp.initializer(name, symbol, ""); | ||
|
||
let caller = starknet::get_caller_address(); | ||
|
||
let mut i = 0; | ||
while i < mint_amount { | ||
erc721_comp.mint(caller, i.into()); | ||
i += 1; | ||
}; | ||
} | ||
} | ||
|
||
#[generate_trait] | ||
impl HypErc721InternalImpl< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
+Drop<TContractState>, | ||
+SRC5Component::HasComponent<TContractState>, | ||
impl ERC721: ERC721Component::HasComponent<TContractState>, | ||
+ERC721Component::ERC721HooksTrait<TContractState>, | ||
|
||
> of InternalTrait<TContractState> { | ||
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); | ||
} | ||
|
||
fn transfer_to(ref self: ComponentState<TContractState>, recipient: u256, token_id: u256) { | ||
let mut erc721_comp_write = get_dep_component_mut!(ref self, ERC721); | ||
erc721_comp_write.mint(recipient, token_id); | ||
} | ||
} | ||
} | ||
|
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
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
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