From 5c1d3f6b7818cc2cd3291056d1a1b51ed26b7fb2 Mon Sep 17 00:00:00 2001 From: Alex Metelli Date: Fri, 16 Aug 2024 21:26:30 +0800 Subject: [PATCH] + hyp_erc721 + fixes --- .../components/hyp_erc721_component.cairo | 2 +- .../token/components/token_router.cairo | 2 +- cairo/src/contracts/token/hyp_erc721.cairo | 94 ++++++++++++++++--- 3 files changed, 84 insertions(+), 14 deletions(-) diff --git a/cairo/src/contracts/token/components/hyp_erc721_component.cairo b/cairo/src/contracts/token/components/hyp_erc721_component.cairo index 0a6ca01..84a26b9 100644 --- a/cairo/src/contracts/token/components/hyp_erc721_component.cairo +++ b/cairo/src/contracts/token/components/hyp_erc721_component.cairo @@ -14,7 +14,7 @@ pub trait IHypErc721 { } #[starknet::component] -pub mod HypErc721 { +pub mod HypErc721Component { use openzeppelin::access::ownable::{ OwnableComponent, OwnableComponent::InternalImpl as OwnableInternalImpl }; diff --git a/cairo/src/contracts/token/components/token_router.cairo b/cairo/src/contracts/token/components/token_router.cairo index 1f04893..8013cf5 100644 --- a/cairo/src/contracts/token/components/token_router.cairo +++ b/cairo/src/contracts/token/components/token_router.cairo @@ -38,7 +38,7 @@ pub mod TokenRouterComponent { #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { SentTransferRemote: SentTransferRemote, ReceivedTransferRemote: ReceivedTransferRemote, } diff --git a/cairo/src/contracts/token/hyp_erc721.cairo b/cairo/src/contracts/token/hyp_erc721.cairo index cdc3636..1ad3d99 100644 --- a/cairo/src/contracts/token/hyp_erc721.cairo +++ b/cairo/src/contracts/token/hyp_erc721.cairo @@ -6,24 +6,94 @@ pub trait IHypErc721 { #[starknet::contract] pub mod HypErc721 { - #[storage] - struct Storage {} + use hyperlane_starknet::contracts::client::gas_router_component::GasRouterComponent; + use hyperlane_starknet::contracts::client::mailboxclient_component::MailboxclientComponent; + use hyperlane_starknet::contracts::client::router_component::RouterComponent; + use hyperlane_starknet::contracts::token::components::hyp_erc721_component::HypErc721Component; + use hyperlane_starknet::contracts::token::components::token_router::TokenRouterComponent; + use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use openzeppelin::upgrades::upgradeable::UpgradeableComponent; + use starknet::ContractAddress; + + component!(path: ERC721Component, storage: erc721, event: ERC721Event); + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); + component!(path: HypErc721Component, storage: hyp_erc721, event: HypErc721Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); + component!(path: TokenRouterComponent, storage: token_router, event: TokenRouterEvent); + component!(path: MailboxclientComponent, storage: mailboxclient, event: MailboxclientEvent); + component!(path: RouterComponent, storage: router, event: RouterEvent); + component!(path: GasRouterComponent, storage: gas_router, event: GasRouterEvent); + // Ownable + impl OwnableInternalImpl = OwnableComponent::InternalImpl; + + // ERC721 Mixin + #[abi(embed_v0)] + impl ERC721MixinImpl = ERC721Component::ERC721MixinImpl; + impl ERC721InternalImpl = ERC721Component::InternalImpl; + + // Upgradeable + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; - fn constructor() {} + // HypERC721 + #[abi(embed_v0)] + impl HypErc721Impl = HypErc721Component::HypErc721Impl; - impl HypErc721Impl of super::IHypErc721 { - fn initialize(ref self: ContractState) {} + // TokenRouter + #[abi(embed_v0)] + impl TokenRouterImpl = TokenRouterComponent::TokenRouterImpl; + impl TokenRouterInternalImpl = TokenRouterComponent::TokenRouterInternalImpl; - fn balance_of(self: @ContractState) -> u256 { - 0 - } + + #[storage] + struct Storage { + #[substorage(v0)] + erc721: ERC721Component::Storage, + #[substorage(v0)] + upgradeable: UpgradeableComponent::Storage, + #[substorage(v0)] + hyp_erc721: HypErc721Component::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage, + #[substorage(v0)] + ownable: OwnableComponent::Storage, + #[substorage(v0)] + token_router: TokenRouterComponent::Storage, + #[substorage(v0)] + mailboxclient: MailboxclientComponent::Storage, + #[substorage(v0)] + router: RouterComponent::Storage, + #[substorage(v0)] + gas_router: GasRouterComponent::Storage } - #[generate_trait] - impl InternalImpl of InternalTrait { - fn transfer_from_sender(ref self: ContractState, token_id: u256) {} + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC721Event: ERC721Component::Event, + #[flat] + UpgradeableEvent: UpgradeableComponent::Event, + #[flat] + HypErc721Event: HypErc721Component::Event, + #[flat] + SRC5Event: SRC5Component::Event, + #[flat] + OwnableEvent: OwnableComponent::Event, + #[flat] + TokenRouterEvent: TokenRouterComponent::Event, + #[flat] + MailboxclientEvent: MailboxclientComponent::Event, + #[flat] + RouterEvent: RouterComponent::Event, + #[flat] + GasRouterEvent: GasRouterComponent::Event + } - fn transfer_to_recipient(ref self: ContractState, recipient: u256, token_id: u256) {} + fn constructor(ref self: ContractState, mailbox: ContractAddress) { + self.token_router.initialize(mailbox); } }