From beb4e8b7655acf7889506d631419e8613f2a10e4 Mon Sep 17 00:00:00 2001 From: Darlington02 Date: Mon, 30 Sep 2024 02:21:16 +0100 Subject: [PATCH] chore: upgrade contracts to v2.8.2 --- .tool-versions | 4 +- Scarb.lock | 113 ++++++++++++++++++- Scarb.toml | 8 +- src/base/constants.cairo | 4 +- src/base/constants/types.cairo | 91 +++++++-------- src/base/token_uris.cairo | 8 +- src/base/token_uris/follow_token_uri.cairo | 1 - src/base/token_uris/handle_token_uri.cairo | 1 - src/base/token_uris/profile_token_uri.cairo | 2 - src/base/token_uris/traits.cairo | 18 +-- src/base/token_uris/traits/background.cairo | 4 +- src/base/token_uris/traits/beard.cairo | 4 +- src/base/token_uris/traits/cloth.cairo | 4 +- src/base/token_uris/traits/color.cairo | 2 +- src/base/token_uris/traits/eyeacessory.cairo | 2 +- src/base/token_uris/traits/follow.cairo | 2 +- src/base/token_uris/traits/glass.cairo | 4 +- src/base/token_uris/traits/handle.cairo | 2 +- src/base/token_uris/traits/head.cairo | 4 +- src/base/token_uris/traits/profile.cairo | 3 +- src/base/utils.cairo | 6 +- src/base/utils/base64_extended.cairo | 1 - src/base/utils/byte_array_extra.cairo | 8 +- src/follownft/follownft.cairo | 58 +++------- src/hub.cairo | 2 +- src/hub/hub.cairo | 11 +- src/interfaces/IHub.cairo | 2 +- src/interfaces/IPublication.cairo | 2 +- src/karstnft/karstnft.cairo | 63 +++-------- src/mocks/interfaces/IComposable.cairo | 2 +- src/mocks/registry.cairo | 6 +- src/namespaces.cairo | 4 +- src/namespaces/handle_registry.cairo | 18 +-- src/namespaces/handles.cairo | 64 +++-------- src/presets.cairo | 4 +- src/presets/profile.cairo | 4 +- src/presets/publication.cairo | 3 +- src/profile/profile.cairo | 23 ++-- src/publication/publication.cairo | 18 +-- 39 files changed, 287 insertions(+), 293 deletions(-) diff --git a/.tool-versions b/.tool-versions index 37875a5..992abf3 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.6.3 -starknet-foundry 0.22.0 \ No newline at end of file +scarb 2.8.3 +starknet-foundry 0.31.0 \ No newline at end of file diff --git a/Scarb.lock b/Scarb.lock index 00f591b..133b44a 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -65,13 +65,118 @@ dependencies = [ [[package]] name = "openzeppelin" -version = "0.11.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.11.0#a83f36b23f1af6e160288962be4a2701c3ecbcda" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_finance", + "openzeppelin_governance", + "openzeppelin_introspection", + "openzeppelin_merkle_tree", + "openzeppelin_presets", + "openzeppelin_security", + "openzeppelin_token", + "openzeppelin_upgrades", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_access" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +dependencies = [ + "openzeppelin_introspection", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_account" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +dependencies = [ + "openzeppelin_introspection", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_finance" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +dependencies = [ + "openzeppelin_access", + "openzeppelin_token", +] + +[[package]] +name = "openzeppelin_governance" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +dependencies = [ + "openzeppelin_access", + "openzeppelin_introspection", +] + +[[package]] +name = "openzeppelin_introspection" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" + +[[package]] +name = "openzeppelin_merkle_tree" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" + +[[package]] +name = "openzeppelin_presets" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_finance", + "openzeppelin_introspection", + "openzeppelin_token", + "openzeppelin_upgrades", +] + +[[package]] +name = "openzeppelin_security" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" + +[[package]] +name = "openzeppelin_token" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +dependencies = [ + "openzeppelin_account", + "openzeppelin_governance", + "openzeppelin_introspection", +] + +[[package]] +name = "openzeppelin_upgrades" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" + +[[package]] +name = "openzeppelin_utils" +version = "0.17.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" + +[[package]] +name = "snforge_scarb_plugin" +version = "0.31.0" +source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67" [[package]] name = "snforge_std" -version = "0.22.0" -source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.22.0#9b215944c6c5871c738381b4ded61bbf06e7ba35" +version = "0.31.0" +source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.31.0#72ea785ca354e9e506de3e5d687da9fb2c1b3c67" +dependencies = [ + "snforge_scarb_plugin", +] [[package]] name = "token_bound_accounts" diff --git a/Scarb.toml b/Scarb.toml index afb490e..f00def2 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,7 +1,7 @@ [package] name = "karst" version = "0.1.0" -edition = "2023_10" +edition = "2024_07" authors = ["Horus Labs "] description = "Decentralized Social Graph on Starknet" repository = "https://github.com/horuslabsio/karst-core" @@ -10,13 +10,13 @@ keywords = ["Karst", "SocialFi", "tokenbound", "cairo", "contracts", "starknet"] # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -starknet = "2.6.3" -openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.11.0" } +starknet = "2.8.2" +openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.17.0" } token_bound_accounts= { git = "https://github.com/Starknet-Africa-Edu/TBA", tag = "v0.3.0" } alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria.git" } [dev-dependencies] -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.22.0" } +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.31.0" } [sncast.default] url= "https://starknet-sepolia.public.blastapi.io" diff --git a/src/base/constants.cairo b/src/base/constants.cairo index 318d175..422d669 100644 --- a/src/base/constants.cairo +++ b/src/base/constants.cairo @@ -1,2 +1,2 @@ -mod errors; -mod types; +pub mod errors; +pub mod types; diff --git a/src/base/constants/types.cairo b/src/base/constants/types.cairo index 118307e..5b404d7 100644 --- a/src/base/constants/types.cairo +++ b/src/base/constants/types.cairo @@ -1,4 +1,3 @@ -use core::option::OptionTrait; // ************************************************************************* // TYPES // ************************************************************************* @@ -14,10 +13,10 @@ use starknet::ContractAddress; // */ #[derive(Drop, Serde, starknet::Store)] pub struct FollowData { - followed_profile_address: ContractAddress, - follower_profile_address: ContractAddress, - follow_timestamp: u64, - block_status: bool, + pub followed_profile_address: ContractAddress, + pub follower_profile_address: ContractAddress, + pub follow_timestamp: u64, + pub block_status: bool, } // * @notice A struct containing profile data. @@ -28,11 +27,11 @@ pub struct FollowData { // * @param follow_nft profile follow nft token contract #[derive(Drop, Serde, starknet::Store)] pub struct Profile { - profile_address: ContractAddress, - profile_owner: ContractAddress, - pub_count: u256, - metadata_URI: ByteArray, - follow_nft: ContractAddress + pub profile_address: ContractAddress, + pub profile_owner: ContractAddress, + pub pub_count: u256, + pub metadata_URI: ByteArray, + pub follow_nft: ContractAddress } // /** @@ -51,14 +50,14 @@ pub struct Profile { // */ #[derive(Debug, Drop, Serde, starknet::Store)] pub struct Publication { - pointed_profile_address: ContractAddress, - pointed_pub_id: u256, - content_URI: ByteArray, - pub_Type: PublicationType, - root_profile_address: ContractAddress, - root_pub_id: u256, - upvote: u256, - downvote: u256, + pub pointed_profile_address: ContractAddress, + pub pointed_pub_id: u256, + pub content_URI: ByteArray, + pub pub_Type: PublicationType, + pub root_profile_address: ContractAddress, + pub root_pub_id: u256, + pub upvote: u256, + pub downvote: u256, } // /** @@ -70,7 +69,7 @@ pub struct Publication { // * @param Mirror A mirror, having a pointer to another publication, but no URI. // */ #[derive(Debug, Drop, Serde, starknet::Store, Clone, PartialEq)] -enum PublicationType { +pub enum PublicationType { Nonexistent, Post, Comment, @@ -85,8 +84,8 @@ enum PublicationType { // */ #[derive(Drop, Serde, starknet::Store, Clone)] pub struct PostParams { - content_URI: ByteArray, - profile_address: ContractAddress, + pub content_URI: ByteArray, + pub profile_address: ContractAddress, } // /** @@ -98,21 +97,21 @@ pub struct PostParams { // * @param pointed_pub_id ID of the pointed publication // */ #[derive(Drop, Serde, starknet::Store, Clone)] -struct CommentParams { - profile_address: ContractAddress, - content_URI: ByteArray, - pointed_profile_address: ContractAddress, - pointed_pub_id: u256, - reference_pub_type: PublicationType, +pub struct CommentParams { + pub profile_address: ContractAddress, + pub content_URI: ByteArray, + pub pointed_profile_address: ContractAddress, + pub pointed_pub_id: u256, + pub reference_pub_type: PublicationType, } #[derive(Drop, Serde, starknet::Store)] pub struct ReferencePubParams { - profile_address: ContractAddress, - content_URI: ByteArray, - pointed_profile_address: ContractAddress, - pointed_pub_id: u256 + pub profile_address: ContractAddress, + pub content_URI: ByteArray, + pub pointed_profile_address: ContractAddress, + pub pointed_pub_id: u256 } // /** @@ -125,9 +124,9 @@ pub struct ReferencePubParams { // */ #[derive(Drop, Serde, starknet::Store, Clone)] pub struct RepostParams { - profile_address: ContractAddress, - pointed_profile_address: ContractAddress, - pointed_pub_id: u256, + pub profile_address: ContractAddress, + pub pointed_profile_address: ContractAddress, + pub pointed_pub_id: u256, } // /** @@ -140,21 +139,23 @@ pub struct RepostParams { // */ #[derive(Drop, Serde, starknet::Store, Clone)] pub struct QuoteParams { - profile_address: ContractAddress, - content_URI: ByteArray, - pointed_profile_address: ContractAddress, - pointed_pub_id: u256, - reference_pub_type: PublicationType + pub profile_address: ContractAddress, + pub content_URI: ByteArray, + pub pointed_profile_address: ContractAddress, + pub pointed_pub_id: u256, + pub reference_pub_type: PublicationType } + #[derive(Debug, Drop, Serde, starknet::Store, Clone)] pub struct Upvote { - publication_id: u256, - transaction_executor: ContractAddress, - block_timestamp: u64, + pub publication_id: u256, + pub transaction_executor: ContractAddress, + pub block_timestamp: u64, } + #[derive(Debug, Drop, Serde, starknet::Store, Clone)] pub struct Downvote { - publication_id: u256, - transaction_executor: ContractAddress, - block_timestamp: u64, + pub publication_id: u256, + pub transaction_executor: ContractAddress, + pub block_timestamp: u64, } diff --git a/src/base/token_uris.cairo b/src/base/token_uris.cairo index 8fe6de3..316ac8d 100644 --- a/src/base/token_uris.cairo +++ b/src/base/token_uris.cairo @@ -1,4 +1,4 @@ -mod follow_token_uri; -mod handle_token_uri; -mod profile_token_uri; -mod traits; +pub mod follow_token_uri; +pub mod handle_token_uri; +pub mod profile_token_uri; +pub mod traits; diff --git a/src/base/token_uris/follow_token_uri.cairo b/src/base/token_uris/follow_token_uri.cairo index 6150145..c655311 100644 --- a/src/base/token_uris/follow_token_uri.cairo +++ b/src/base/token_uris/follow_token_uri.cairo @@ -2,7 +2,6 @@ pub mod FollowTokenUri { use starknet::ContractAddress; - use alexandria_bytes::{Bytes, BytesTrait}; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; use karst::base::utils::base64_extended::{convert_into_byteArray, get_base64_encode}; use karst::base::token_uris::traits::follow::follow::get_svg_follow; diff --git a/src/base/token_uris/handle_token_uri.cairo b/src/base/token_uris/handle_token_uri.cairo index 4b3266a..a4ba36b 100644 --- a/src/base/token_uris/handle_token_uri.cairo +++ b/src/base/token_uris/handle_token_uri.cairo @@ -2,7 +2,6 @@ pub mod HandleTokenUri { use core::array::ArrayTrait; - use alexandria_bytes::{Bytes, BytesTrait}; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; use karst::base::utils::base64_extended::{convert_into_byteArray, get_base64_encode}; use karst::base::token_uris::traits::handle::handle::get_svg_handle; diff --git a/src/base/token_uris/profile_token_uri.cairo b/src/base/token_uris/profile_token_uri.cairo index a337351..86b2dbe 100644 --- a/src/base/token_uris/profile_token_uri.cairo +++ b/src/base/token_uris/profile_token_uri.cairo @@ -2,10 +2,8 @@ pub mod ProfileTokenUri { use core::array::ArrayTrait; - use alexandria_bytes::{Bytes, BytesTrait}; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; use karst::base::utils::base64_extended::{get_base64_encode, convert_into_byteArray}; - use karst::base::token_uris::traits::profile::ProfileSvg::gen_profile_svg; fn get_svg(token_id: u256, mint_timestamp: u64) -> Array { let mut svg = ArrayTrait::::new(); diff --git a/src/base/token_uris/traits.cairo b/src/base/token_uris/traits.cairo index 3ae4bce..1b1b821 100644 --- a/src/base/token_uris/traits.cairo +++ b/src/base/token_uris/traits.cairo @@ -1,9 +1,9 @@ -mod head; -mod glass; -mod color; -mod beard; -mod background; -mod cloth; -mod profile; -mod handle; -mod follow; +pub mod head; +pub mod glass; +pub mod color; +pub mod beard; +pub mod background; +pub mod cloth; +pub mod profile; +pub mod handle; +pub mod follow; diff --git a/src/base/token_uris/traits/background.cairo b/src/base/token_uris/traits/background.cairo index 0c174f7..032b97a 100644 --- a/src/base/token_uris/traits/background.cairo +++ b/src/base/token_uris/traits/background.cairo @@ -1,8 +1,6 @@ // let make the face of the profile svg -mod background { - use core::traits::TryInto; - use karst::base::token_uris::traits::color::karstColors; +pub mod background { use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; #[derive(Drop)] diff --git a/src/base/token_uris/traits/beard.cairo b/src/base/token_uris/traits/beard.cairo index d9af2b7..3c1fcb3 100644 --- a/src/base/token_uris/traits/beard.cairo +++ b/src/base/token_uris/traits/beard.cairo @@ -1,8 +1,6 @@ // let make the face of the profile svg -mod beard { - use core::traits::TryInto; - use karst::base::token_uris::traits::color::karstColors; +pub mod beard { use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; #[derive(Drop)] diff --git a/src/base/token_uris/traits/cloth.cairo b/src/base/token_uris/traits/cloth.cairo index ca29800..f1a48c5 100644 --- a/src/base/token_uris/traits/cloth.cairo +++ b/src/base/token_uris/traits/cloth.cairo @@ -1,8 +1,6 @@ // let make the face of the profile svg -mod cloth { - use core::traits::TryInto; - use karst::base::token_uris::traits::color::karstColors; +pub mod cloth { use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; #[derive(Drop)] diff --git a/src/base/token_uris/traits/color.cairo b/src/base/token_uris/traits/color.cairo index 10fa2b9..9dfc5b2 100644 --- a/src/base/token_uris/traits/color.cairo +++ b/src/base/token_uris/traits/color.cairo @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -mod karstColors { +pub mod karstColors { pub const baseGreen: felt252 = '#A0D170'; pub const basePink: felt252 = '#FFD2DD'; pub const basePurple: felt252 = '#EAD7FF'; diff --git a/src/base/token_uris/traits/eyeacessory.cairo b/src/base/token_uris/traits/eyeacessory.cairo index 53c9ef9..152c168 100644 --- a/src/base/token_uris/traits/eyeacessory.cairo +++ b/src/base/token_uris/traits/eyeacessory.cairo @@ -1,6 +1,6 @@ // let make the face of the profile svg -mod eyeacessory { +pub mod eyeacessory { use core::traits::TryInto; use karst::base::token_uris::traits::color::karstColors; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; diff --git a/src/base/token_uris/traits/follow.cairo b/src/base/token_uris/traits/follow.cairo index 46bbc81..0dc8001 100644 --- a/src/base/token_uris/traits/follow.cairo +++ b/src/base/token_uris/traits/follow.cairo @@ -1,4 +1,4 @@ -mod follow { +pub mod follow { use core::array::ArrayTrait; use karst::base::utils::base64_extended::convert_into_byteArray; use karst::base::token_uris::traits::color::karstColors; diff --git a/src/base/token_uris/traits/glass.cairo b/src/base/token_uris/traits/glass.cairo index 8ae34c8..5e70e38 100644 --- a/src/base/token_uris/traits/glass.cairo +++ b/src/base/token_uris/traits/glass.cairo @@ -1,8 +1,6 @@ // let make the face of the profile svg -mod glass { - use core::traits::TryInto; - use karst::base::token_uris::traits::color::karstColors; +pub mod glass { use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; #[derive(Drop)] diff --git a/src/base/token_uris/traits/handle.cairo b/src/base/token_uris/traits/handle.cairo index 6946fbc..89e01a3 100644 --- a/src/base/token_uris/traits/handle.cairo +++ b/src/base/token_uris/traits/handle.cairo @@ -1,4 +1,4 @@ -mod handle { +pub mod handle { use core::array::ArrayTrait; use karst::base::utils::base64_extended::convert_into_byteArray; use karst::base::token_uris::traits::color::karstColors; diff --git a/src/base/token_uris/traits/head.cairo b/src/base/token_uris/traits/head.cairo index 147630a..1b70dff 100644 --- a/src/base/token_uris/traits/head.cairo +++ b/src/base/token_uris/traits/head.cairo @@ -1,8 +1,6 @@ // let make the face of the profile svg -mod head { - use core::traits::TryInto; - use karst::base::token_uris::traits::color::karstColors; +pub mod head { use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; #[derive(Drop)] diff --git a/src/base/token_uris/traits/profile.cairo b/src/base/token_uris/traits/profile.cairo index 3bff74a..8f0c286 100644 --- a/src/base/token_uris/traits/profile.cairo +++ b/src/base/token_uris/traits/profile.cairo @@ -1,5 +1,4 @@ -mod ProfileSvg { - use karst::base::token_uris::traits::color::karstColors; +pub mod ProfileSvg { use karst::base::token_uris::traits::head::head::faceSvgStart; use karst::base::token_uris::traits::glass::glass::glassSvgStart; use karst::base::token_uris::traits::beard::beard::beardSvgStart; diff --git a/src/base/utils.cairo b/src/base/utils.cairo index 5145ad3..c83ec0b 100644 --- a/src/base/utils.cairo +++ b/src/base/utils.cairo @@ -1,3 +1,3 @@ -mod byte_array_extra; -mod hubrestricted; -mod base64_extended; +pub mod byte_array_extra; +pub mod hubrestricted; +pub mod base64_extended; diff --git a/src/base/utils/base64_extended.cairo b/src/base/utils/base64_extended.cairo index 05acc08..3237105 100644 --- a/src/base/utils/base64_extended.cairo +++ b/src/base/utils/base64_extended.cairo @@ -1,4 +1,3 @@ -use core::serde::Serde; use core::array::ArrayTrait; use karst::base::utils::byte_array_extra::FeltTryIntoByteArray; use alexandria_encoding::base64::{Base64UrlEncoder}; diff --git a/src/base/utils/byte_array_extra.cairo b/src/base/utils/byte_array_extra.cairo index b24976e..861e075 100644 --- a/src/base/utils/byte_array_extra.cairo +++ b/src/base/utils/byte_array_extra.cairo @@ -1,9 +1,7 @@ -use core::serde::Serde; - -impl FeltTryIntoByteArray of TryInto { +pub impl FeltTryIntoByteArray of TryInto { fn try_into(self: felt252) -> Option { let mut res: ByteArray = Default::default(); - res.pending_word = self; + // res.pending_word = self; let mut length = 0; let mut data: u256 = self.into(); loop { @@ -13,7 +11,7 @@ impl FeltTryIntoByteArray of TryInto { data /= 0x100; length += 1; }; - res.pending_word_len = length; + // res.pending_word_len = length; Option::Some(res) } } diff --git a/src/follownft/follownft.cairo b/src/follownft/follownft.cairo index f0b5cf9..5dee2c3 100644 --- a/src/follownft/follownft.cairo +++ b/src/follownft/follownft.cairo @@ -1,55 +1,22 @@ -// ************************************************************************* -// OZ ERC721 -// ************************************************************************* -use openzeppelin::{ - token::erc721::{ERC721Component::{ERC721Metadata, ERC721Mixin, HasComponent}}, - introspection::src5::SRC5Component, -}; - - -#[starknet::interface] -trait IERC721Metadata { - fn name(self: @TState) -> ByteArray; - fn symbol(self: @TState) -> ByteArray; -} - -#[starknet::embeddable] -impl IERC721MetadataImpl< - TContractState, - +HasComponent, - +SRC5Component::HasComponent, - +Drop -> of IERC721Metadata { - fn name(self: @TContractState) -> ByteArray { - let component = HasComponent::get_component(self); - ERC721Metadata::name(component) - } - - fn symbol(self: @TContractState) -> ByteArray { - let component = HasComponent::get_component(self); - ERC721Metadata::symbol(component) - } -} - #[starknet::contract] -mod Follow { +pub mod Follow { // ************************************************************************* // IMPORT // ************************************************************************* - use core::traits::TryInto; - use starknet::{ContractAddress, get_caller_address, get_block_timestamp}; + use starknet::{ + ContractAddress, + get_block_timestamp, + storage::{ StoragePointerWriteAccess, StoragePointerReadAccess, Map, StorageMapReadAccess, StorageMapWriteAccess } + }; use core::num::traits::zero::Zero; use karst::interfaces::{IFollowNFT::IFollowNFT}; use karst::base::{ constants::{errors::Errors, types::FollowData}, utils::hubrestricted::HubRestricted::hub_only, token_uris::follow_token_uri::FollowTokenUri, }; - use openzeppelin::{ - account, access::ownable::OwnableComponent, - token::erc721::{ - ERC721Component, erc721::ERC721Component::InternalTrait as ERC721InternalTrait - }, + access::ownable::OwnableComponent, + token::erc721::{ERC721Component, ERC721HooksEmptyImpl}, introspection::{src5::SRC5Component} }; @@ -66,6 +33,7 @@ mod Follow { impl ERC721Impl = ERC721Component::ERC721Impl; #[abi(embed_v0)] impl ERC721CamelOnlyImpl = ERC721Component::ERC721CamelOnlyImpl; + impl ERC721InternalImpl = ERC721Component::InternalImpl; // add an owner #[abi(embed_v0)] @@ -86,8 +54,8 @@ mod Follow { admin: ContractAddress, followed_profile_address: ContractAddress, follower_count: u256, - follow_id_by_follower_profile_address: LegacyMap, - follow_data_by_follow_id: LegacyMap, + follow_id_by_follower_profile_address: Map, + follow_data_by_follow_id: Map, karst_hub: ContractAddress, } @@ -334,7 +302,7 @@ mod Follow { /// @param follower_profile_address address of profile performing the follow action fn _follow(ref self: ContractState, follower_profile_address: ContractAddress) -> u256 { let new_follower_id = self.follower_count.read() + 1; - self.erc721._mint(follower_profile_address, new_follower_id); + self.erc721.mint(follower_profile_address, new_follower_id); let follow_timestamp: u64 = get_block_timestamp(); let follow_data = FollowData { @@ -365,7 +333,7 @@ mod Follow { /// @param unfollower address of user performing the unfollow action /// @param follow_id ID of the initial follow action fn _unfollow(ref self: ContractState, unfollower: ContractAddress, follow_id: u256) { - self.erc721._burn(follow_id); + self.erc721.burn(follow_id); self.follow_id_by_follower_profile_address.write(unfollower, 0); self .follow_data_by_follow_id diff --git a/src/hub.cairo b/src/hub.cairo index 72ecbfa..2dbca3b 100644 --- a/src/hub.cairo +++ b/src/hub.cairo @@ -1 +1 @@ -mod hub; +pub mod hub; diff --git a/src/hub/hub.cairo b/src/hub/hub.cairo index 79b6158..5c3e555 100644 --- a/src/hub/hub.cairo +++ b/src/hub/hub.cairo @@ -25,11 +25,14 @@ trait IKarstHub { } #[starknet::contract] -mod KarstHub { +pub mod KarstHub { use core::array::SpanTrait; - use starknet::{ContractAddress, get_caller_address, get_contract_address}; - use core::num::traits::zero::Zero; - use core::traits::TryInto; + use starknet::{ + ContractAddress, + get_caller_address, + get_contract_address, + storage::{ StoragePointerWriteAccess, StoragePointerReadAccess } + }; use karst::profile::profile::ProfileComponent; use karst::publication::publication::PublicationComponent; use karst::interfaces::IFollowNFT::{IFollowNFTDispatcher, IFollowNFTDispatcherTrait}; diff --git a/src/interfaces/IHub.cairo b/src/interfaces/IHub.cairo index 01f6670..79164e5 100644 --- a/src/interfaces/IHub.cairo +++ b/src/interfaces/IHub.cairo @@ -1,6 +1,6 @@ use starknet::ContractAddress; use karst::base::constants::types::{ - Profile, PostParams, RepostParams, CommentParams, PublicationType, Publication, QuoteParams + Profile, PostParams, RepostParams, CommentParams, PublicationType, Publication }; // ************************************************************************* diff --git a/src/interfaces/IPublication.cairo b/src/interfaces/IPublication.cairo index 3b6e33e..d730ac5 100644 --- a/src/interfaces/IPublication.cairo +++ b/src/interfaces/IPublication.cairo @@ -3,7 +3,7 @@ // ************************************************************************* use starknet::ContractAddress; use karst::base::constants::types::{ - PostParams, RepostParams, CommentParams, PublicationType, Publication, QuoteParams + PostParams, RepostParams, CommentParams, PublicationType, Publication }; #[starknet::interface] diff --git a/src/karstnft/karstnft.cairo b/src/karstnft/karstnft.cairo index 4ff694d..0a66c3c 100644 --- a/src/karstnft/karstnft.cairo +++ b/src/karstnft/karstnft.cairo @@ -1,54 +1,23 @@ -use starknet::ContractAddress; - -// ************************************************************************* -// OZ IMPORTS -// ************************************************************************* -use openzeppelin::{ - token::erc721::{ERC721Component::{ERC721Metadata, HasComponent}}, - introspection::src5::SRC5Component, -}; - -#[starknet::interface] -trait IERC721Metadata { - fn name(self: @TState) -> ByteArray; - fn symbol(self: @TState) -> ByteArray; -} - -#[starknet::embeddable] -impl IERC721MetadataImpl< - TContractState, - +HasComponent, - +SRC5Component::HasComponent, - +Drop -> of IERC721Metadata { - fn name(self: @TContractState) -> ByteArray { - let component = HasComponent::get_component(self); - ERC721Metadata::name(component) - } - - fn symbol(self: @TContractState) -> ByteArray { - let component = HasComponent::get_component(self); - ERC721Metadata::symbol(component) - } -} - #[starknet::contract] pub mod KarstNFT { // ************************************************************************* // IMPORTS // ************************************************************************* - use openzeppelin::token::erc721::interface::IERC721Metadata; - use starknet::{ContractAddress, get_caller_address, get_block_timestamp}; + use starknet::{ + ContractAddress, + get_block_timestamp, + storage::{ StoragePointerWriteAccess, StoragePointerReadAccess, Map, StorageMapReadAccess, StorageMapWriteAccess } + }; use core::num::traits::zero::Zero; use karst::interfaces::IKarstNFT; use karst::base::{ - utils::hubrestricted::HubRestricted::hub_only, constants::errors::Errors::ALREADY_MINTED, + constants::errors::Errors::ALREADY_MINTED, token_uris::profile_token_uri::ProfileTokenUri, }; use openzeppelin::{ - account, access::ownable::OwnableComponent, + access::ownable::OwnableComponent, token::erc721::{ - ERC721Component, erc721::ERC721Component::InternalTrait as ERC721InternalTrait + ERC721Component, ERC721HooksEmptyImpl }, introspection::{src5::SRC5Component} }; @@ -66,6 +35,7 @@ pub mod KarstNFT { impl ERC721Impl = ERC721Component::ERC721Impl; #[abi(embed_v0)] impl ERC721CamelOnlyImpl = ERC721Component::ERC721CamelOnlyImpl; + impl ERC721InternalImpl = ERC721Component::InternalImpl; // add an owner #[abi(embed_v0)] @@ -86,8 +56,8 @@ pub mod KarstNFT { ownable: OwnableComponent::Storage, admin: ContractAddress, last_minted_id: u256, - mint_timestamp: LegacyMap, - user_token_id: LegacyMap, + mint_timestamp: Map, + user_token_id: Map, } // ************************************************************************* @@ -111,12 +81,9 @@ pub mod KarstNFT { fn constructor( ref self: ContractState, admin: ContractAddress, - name: ByteArray, - symbol: ByteArray, - base_uri: ByteArray, ) { self.admin.write(admin); - self.erc721.initializer(name, symbol, base_uri); + self.erc721.initializer("Karst", "KST", ""); } #[abi(embed_v0)] @@ -131,7 +98,7 @@ pub mod KarstNFT { assert(balance.is_zero(), ALREADY_MINTED); let mut token_id = self.last_minted_id.read() + 1; - self.erc721._mint(address, token_id); + self.erc721.mint(address, token_id); let timestamp: u64 = get_block_timestamp(); self.user_token_id.write(address, token_id); @@ -162,12 +129,12 @@ pub mod KarstNFT { // ************************************************************************* /// @notice returns the collection name fn name(self: @ContractState) -> ByteArray { - self.erc721.name() + return "Karst Handles"; } /// @notice returns the collection symbol fn symbol(self: @ContractState) -> ByteArray { - self.erc721.symbol() + return "KARST"; } /// @notice returns the token_uri for a particular token_id diff --git a/src/mocks/interfaces/IComposable.cairo b/src/mocks/interfaces/IComposable.cairo index 8b78469..af8ec4d 100644 --- a/src/mocks/interfaces/IComposable.cairo +++ b/src/mocks/interfaces/IComposable.cairo @@ -1,6 +1,6 @@ use starknet::ContractAddress; use karst::base::constants::types::{ - Profile, PublicationType, Publication, RepostParams, QuoteParams, PostParams, CommentParams + Profile, PublicationType, Publication, RepostParams, PostParams, CommentParams }; // ************************************************************************* // INTERFACE of KARST PROFILE diff --git a/src/mocks/registry.cairo b/src/mocks/registry.cairo index b743016..dff6976 100644 --- a/src/mocks/registry.cairo +++ b/src/mocks/registry.cairo @@ -8,14 +8,14 @@ pub mod Registry { use core::pedersen::PedersenTrait; use starknet::{ ContractAddress, get_caller_address, syscalls::call_contract_syscall, class_hash::ClassHash, - syscalls::deploy_syscall, SyscallResultTrait + syscalls::deploy_syscall, SyscallResultTrait, + storage::{ Map, StorageMapReadAccess, StorageMapWriteAccess } }; - use token_bound_accounts::interfaces::IERC721::{IERC721DispatcherTrait, IERC721Dispatcher}; use token_bound_accounts::interfaces::IRegistry::IRegistry; #[storage] struct Storage { - registry_deployed_accounts: LegacyMap< + registry_deployed_accounts: Map< (ContractAddress, u256), u8 >, // tracks no. of deployed accounts by registry for an NFT } diff --git a/src/namespaces.cairo b/src/namespaces.cairo index f3d58ad..cddb7d5 100644 --- a/src/namespaces.cairo +++ b/src/namespaces.cairo @@ -1,2 +1,2 @@ -mod handles; -mod handle_registry; +pub mod handles; +pub mod handle_registry; diff --git a/src/namespaces/handle_registry.cairo b/src/namespaces/handle_registry.cairo index 0b383e3..ae92c1a 100644 --- a/src/namespaces/handle_registry.cairo +++ b/src/namespaces/handle_registry.cairo @@ -1,12 +1,12 @@ #[starknet::contract] -mod HandleRegistry { +pub mod HandleRegistry { // ************************************************************************* // IMPORT // ************************************************************************* - use core::traits::TryInto; use core::num::traits::zero::Zero; use starknet::{ - ContractAddress, get_caller_address, get_block_timestamp, contract_address_const + ContractAddress, get_caller_address, get_block_timestamp, contract_address_const, + storage::{ StoragePointerWriteAccess, StoragePointerReadAccess, Map, StorageMapReadAccess, StorageMapWriteAccess } }; use karst::interfaces::IHandleRegistry::IHandleRegistry; use karst::interfaces::IERC721::{IERC721Dispatcher, IERC721DispatcherTrait}; @@ -17,10 +17,10 @@ mod HandleRegistry { // STORAGE // ************************************************************************* #[storage] - struct Storage { + pub struct Storage { handle_address: ContractAddress, - handle_to_profile_address: LegacyMap::, - profile_address_to_handle: LegacyMap::, + handle_to_profile_address: Map::, + profile_address_to_handle: Map::, } // ************************************************************************* @@ -28,13 +28,13 @@ mod HandleRegistry { // ************************************************************************* #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { Linked: HandleLinked, Unlinked: HandleUnlinked, } #[derive(Drop, starknet::Event)] - struct HandleLinked { + pub struct HandleLinked { handle_id: u256, profile_address: ContractAddress, caller: ContractAddress, @@ -42,7 +42,7 @@ mod HandleRegistry { } #[derive(Drop, starknet::Event)] - struct HandleUnlinked { + pub struct HandleUnlinked { handle_id: u256, profile_address: ContractAddress, caller: ContractAddress, diff --git a/src/namespaces/handles.cairo b/src/namespaces/handles.cairo index 2b4cdb5..31414b7 100644 --- a/src/namespaces/handles.cairo +++ b/src/namespaces/handles.cairo @@ -1,39 +1,5 @@ -// ************************************************************************* -// OZ ERC721 -// ************************************************************************* -use openzeppelin::{ - token::erc721::{ERC721Component::{ERC721Metadata, ERC721Mixin, HasComponent}}, - introspection::src5::SRC5Component, -}; - - -#[starknet::interface] -trait IERC721Metadata { - fn name(self: @TState) -> ByteArray; - fn symbol(self: @TState) -> ByteArray; -} - -#[starknet::embeddable] -impl IERC721MetadataImpl< - TContractState, - +HasComponent, - +SRC5Component::HasComponent, - +Drop -> of IERC721Metadata { - fn name(self: @TContractState) -> ByteArray { - let component = HasComponent::get_component(self); - ERC721Metadata::name(component) - } - - fn symbol(self: @TContractState) -> ByteArray { - let component = HasComponent::get_component(self); - ERC721Metadata::symbol(component) - } -} - - #[starknet::contract] -mod Handles { +pub mod Handles { // ************************************************************************* // IMPORT // ************************************************************************* @@ -41,21 +7,22 @@ mod Handles { use core::traits::TryInto; use core::poseidon::PoseidonTrait; use core::hash::{HashStateTrait, HashStateExTrait}; - use starknet::{ContractAddress, get_caller_address, get_block_timestamp}; + use starknet::{ + ContractAddress, + get_caller_address, + get_block_timestamp, + storage::{ StoragePointerWriteAccess, StoragePointerReadAccess, Map, StorageMapReadAccess, StorageMapWriteAccess } + }; use openzeppelin::{ - account, access::ownable::OwnableComponent, - token::erc721::{ - ERC721Component, erc721::ERC721Component::InternalTrait as ERC721InternalTrait - }, + access::ownable::OwnableComponent, + token::erc721::{ERC721Component, ERC721HooksEmptyImpl}, introspection::{src5::SRC5Component} }; use karst::base::{ constants::errors::Errors, utils::byte_array_extra::FeltTryIntoByteArray, token_uris::handle_token_uri::HandleTokenUri, }; - use karst::interfaces::{ - IKarstNFT::{IKarstNFTDispatcher, IKarstNFTDispatcherTrait}, IHandle::IHandle - }; + use karst::interfaces::{ IHandle::IHandle }; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); @@ -70,6 +37,7 @@ mod Handles { impl ERC721Impl = ERC721Component::ERC721Impl; #[abi(embed_v0)] impl ERC721CamelOnlyImpl = ERC721Component::ERC721CamelOnlyImpl; + impl ERC721InternalImpl = ERC721Component::InternalImpl; // add an owner #[abi(embed_v0)] @@ -80,7 +48,7 @@ mod Handles { // STORAGE // ************************************************************************* #[storage] - struct Storage { + pub struct Storage { #[substorage(v0)] erc721: ERC721Component::Storage, #[substorage(v0)] @@ -89,7 +57,7 @@ mod Handles { ownable: OwnableComponent::Storage, admin: ContractAddress, total_supply: u256, - local_names: LegacyMap::, + local_names: Map::, } // ************************************************************************* @@ -166,7 +134,7 @@ mod Handles { assert(get_caller_address() == self.erc721.owner_of(token_id), Errors::INVALID_OWNER); let current_supply = self.total_supply.read(); let local_name = self.local_names.read(token_id); - self.erc721._burn(token_id); + self.erc721.burn(token_id); self.total_supply.write(current_supply - 1); self.local_names.write(token_id, 0); self @@ -208,7 +176,7 @@ mod Handles { /// @notice checks if a handle exists /// @param token_id ID of handle to be queried fn exists(self: @ContractState, token_id: u256) -> bool { - self.erc721._exists(token_id) + self.erc721.exists(token_id) } /// @notice returns no. of handles minted @@ -264,7 +232,7 @@ mod Handles { current_total_supply += 1; self.total_supply.write(current_total_supply); - self.erc721._mint(address, token_id); + self.erc721.mint(address, token_id); self.local_names.write(token_id, local_name); self diff --git a/src/presets.cairo b/src/presets.cairo index 25247b8..46ac7a7 100644 --- a/src/presets.cairo +++ b/src/presets.cairo @@ -1,2 +1,2 @@ -mod profile; -mod publication; +pub mod profile; +pub mod publication; diff --git a/src/presets/profile.cairo b/src/presets/profile.cairo index 6143b8c..1dc8c55 100644 --- a/src/presets/profile.cairo +++ b/src/presets/profile.cairo @@ -1,6 +1,6 @@ #[starknet::contract] -mod KarstProfile { - use starknet::{ContractAddress, get_caller_address}; +pub mod KarstProfile { + use starknet::ContractAddress; use karst::profile::profile::ProfileComponent; component!(path: ProfileComponent, storage: profile, event: ProfileEvent); diff --git a/src/presets/publication.cairo b/src/presets/publication.cairo index b50ca55..5c0bad6 100644 --- a/src/presets/publication.cairo +++ b/src/presets/publication.cairo @@ -1,6 +1,5 @@ #[starknet::contract] -mod KarstPublication { - use starknet::{ContractAddress}; +pub mod KarstPublication { use karst::publication::publication::PublicationComponent; use karst::profile::profile::ProfileComponent; diff --git a/src/profile/profile.cairo b/src/profile/profile.cairo index fd3e824..30859d2 100644 --- a/src/profile/profile.cairo +++ b/src/profile/profile.cairo @@ -1,33 +1,30 @@ -use starknet::ContractAddress; - #[starknet::component] -mod ProfileComponent { +pub mod ProfileComponent { // ************************************************************************* // IMPORT // ************************************************************************* - use core::{traits::TryInto, result::ResultTrait}; + use core::{traits::TryInto}; use starknet::{ ContractAddress, get_caller_address, get_block_timestamp, ClassHash, - syscalls::deploy_syscall, SyscallResultTrait + syscalls::deploy_syscall, SyscallResultTrait, + storage::{ StoragePointerWriteAccess, StoragePointerReadAccess, Map, StorageMapReadAccess, StorageMapWriteAccess } }; use karst::interfaces::IKarstNFT::{IKarstNFTDispatcher, IKarstNFTDispatcherTrait}; use karst::interfaces::IRegistry::{ - IRegistryDispatcher, IRegistryDispatcherTrait, IRegistryLibraryDispatcher + IRegistryDispatcherTrait, IRegistryLibraryDispatcher }; use karst::interfaces::IERC721::{IERC721Dispatcher, IERC721DispatcherTrait}; use karst::interfaces::IProfile::IProfile; - use karst::interfaces::{IFollowNFT::IFollowNFT}; use karst::base::{ constants::types::Profile, constants::errors::Errors::NOT_PROFILE_OWNER, - utils::hubrestricted::HubRestricted::hub_only }; // ************************************************************************* // STORAGE // ************************************************************************* #[storage] - struct Storage { - profile: LegacyMap, + pub struct Storage { + profile: Map, karst_nft_address: ContractAddress, hub_address: ContractAddress, follow_nft_classhash: ClassHash @@ -38,12 +35,12 @@ mod ProfileComponent { // ************************************************************************* #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { CreatedProfile: CreatedProfile } #[derive(Drop, starknet::Event)] - struct CreatedProfile { + pub struct CreatedProfile { #[key] owner: ContractAddress, #[key] @@ -181,7 +178,7 @@ mod ProfileComponent { } #[generate_trait] - impl Private> of PrivateTrait { + pub impl Private> of PrivateTrait { /// @notice increments user's publication count /// @params profile_address the targeted profile address fn increment_publication_count( diff --git a/src/publication/publication.cairo b/src/publication/publication.cairo index b89f295..9036094 100644 --- a/src/publication/publication.cairo +++ b/src/publication/publication.cairo @@ -6,14 +6,18 @@ pub mod PublicationComponent { use core::traits::TryInto; use karst::interfaces::IProfile::IProfile; use core::option::OptionTrait; - use starknet::{ContractAddress, get_contract_address, get_caller_address, get_block_timestamp}; + use starknet::{ + ContractAddress, + get_caller_address, + get_block_timestamp, + storage::{ Map, StorageMapReadAccess, StorageMapWriteAccess } + }; use karst::interfaces::IPublication::IKarstPublications; use karst::base::{ constants::errors::Errors::{NOT_PROFILE_OWNER, UNSUPPORTED_PUB_TYPE, ALREADY_REACTED}, - utils::hubrestricted::HubRestricted::hub_only, constants::types::{ - PostParams, Publication, PublicationType, ReferencePubParams, CommentParams, - RepostParams, Upvote, Downvote + PostParams, Publication, PublicationType, CommentParams, + RepostParams } }; @@ -25,9 +29,9 @@ pub mod PublicationComponent { // STORAGE // ************************************************************************* #[storage] - struct Storage { - publication: LegacyMap<(ContractAddress, u256), Publication>, - vote_status: LegacyMap<(ContractAddress, u256), bool>, + pub struct Storage { + publication: Map<(ContractAddress, u256), Publication>, + vote_status: Map<(ContractAddress, u256), bool>, } // *************************************************************************