From 9bec20ea5819d123ce0dd5a3473369fbfde38546 Mon Sep 17 00:00:00 2001 From: Jakub Date: Sun, 30 Jun 2024 16:13:24 +0200 Subject: [PATCH 1/2] Add prototypes of the interface --- contracts/auctions/Cargo.toml | 19 +++++++ contracts/auctions/Makefile | 20 ++++++++ contracts/auctions/src/lib.rs | 83 +++++++++++++++++++++++++++++++ contracts/collections/Cargo.toml | 19 +++++++ contracts/collections/Makefile | 20 ++++++++ contracts/collections/src/lib.rs | 50 +++++++++++++++++++ contracts/nft/src/lib.rs | 85 ++++++++++++++++++++++++++++---- 7 files changed, 287 insertions(+), 9 deletions(-) create mode 100644 contracts/auctions/Cargo.toml create mode 100644 contracts/auctions/Makefile create mode 100644 contracts/auctions/src/lib.rs create mode 100644 contracts/collections/Cargo.toml create mode 100644 contracts/collections/Makefile create mode 100644 contracts/collections/src/lib.rs diff --git a/contracts/auctions/Cargo.toml b/contracts/auctions/Cargo.toml new file mode 100644 index 00000000..226700e4 --- /dev/null +++ b/contracts/auctions/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "phoenix-nft" +version = { workspace = true } +authors = ["Jakub "] +repository = { workspace = true } +edition = { workspace = true } +license = { workspace = true } + +[lib] +crate-type = ["cdylib"] + +[features] +testutils = ["soroban-sdk/testutils"] + +[dependencies] +soroban-sdk = { workspace = true } + +[dev_dependencies] +soroban-sdk = { workspace = true, features = ["testutils"] } diff --git a/contracts/auctions/Makefile b/contracts/auctions/Makefile new file mode 100644 index 00000000..1e1e69be --- /dev/null +++ b/contracts/auctions/Makefile @@ -0,0 +1,20 @@ +default: all + +all: lint build test + +test: build # because of token dependency + cargo test + +build: + cargo build --target wasm32-unknown-unknown --release + +lint: fmt clippy + +fmt: + cargo fmt --all + +clippy: build + cargo clippy --all-targets -- -D warnings + +clean: + cargo clean diff --git a/contracts/auctions/src/lib.rs b/contracts/auctions/src/lib.rs new file mode 100644 index 00000000..65358418 --- /dev/null +++ b/contracts/auctions/src/lib.rs @@ -0,0 +1,83 @@ +#![no_std] + +use soroban_sdk::{contract, Address, BytesN, Env, Vec}; + +#[derive(Clone)] +pub struct Auction { + pub id: u64, + pub item_address: Address, // Can be an NFT contract address or a collection contract address + pub seller: Address, + pub highest_bid: u64, + pub highest_bidder: Address, + pub buy_now_price: u64, + pub end_time: u64, + pub status: AuctionStatus, +} + +#[derive(Clone, PartialEq)] +pub enum AuctionStatus { + Active, + Ended, + Cancelled, +} + + +#[contract] +pub struct MarketplaceContract; + +#[contractimpl] +impl MarketplaceContract { + fn generate_auction_id(env: &Env) -> u64 { + todo!() + } + + pub fn create_auction( + env: Env, + item_address: Address, + seller: Address, + buy_now_price: u64, + duration: u64, + ) -> Auction { + todo!() + } + + pub fn place_bid(env: Env, auction_id: u64, bidder: Address, bid_amount: u64) { + todo!() + } + + pub fn finalize_auction(env: Env, auction_id: u64) { + todo!() + } + + pub fn buy_now(env: Env, auction_id: u64, buyer: Address) { + todo!() + } + + fn distribute_funds(env: Env, auction: Auction) { + todo!() + } + + pub fn pause(env: Env) { + todo!() + } + + pub fn unpause(env: Env) { + todo!() + } + + pub fn get_auction(env: Env, auction_id: u64) -> Auction { + todo!() + } + + pub fn get_active_auctions(env: Env) -> Vec { + todo!() + } + + pub fn get_auctions_by_seller(env: Env, seller: Address) -> Vec { + todo!() + } + + pub fn get_highest_bid(env: Env, auction_id: u64) -> (u64, Address) { + todo!() + } +} diff --git a/contracts/collections/Cargo.toml b/contracts/collections/Cargo.toml new file mode 100644 index 00000000..226700e4 --- /dev/null +++ b/contracts/collections/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "phoenix-nft" +version = { workspace = true } +authors = ["Jakub "] +repository = { workspace = true } +edition = { workspace = true } +license = { workspace = true } + +[lib] +crate-type = ["cdylib"] + +[features] +testutils = ["soroban-sdk/testutils"] + +[dependencies] +soroban-sdk = { workspace = true } + +[dev_dependencies] +soroban-sdk = { workspace = true, features = ["testutils"] } diff --git a/contracts/collections/Makefile b/contracts/collections/Makefile new file mode 100644 index 00000000..1e1e69be --- /dev/null +++ b/contracts/collections/Makefile @@ -0,0 +1,20 @@ +default: all + +all: lint build test + +test: build # because of token dependency + cargo test + +build: + cargo build --target wasm32-unknown-unknown --release + +lint: fmt clippy + +fmt: + cargo fmt --all + +clippy: build + cargo clippy --all-targets -- -D warnings + +clean: + cargo clean diff --git a/contracts/collections/src/lib.rs b/contracts/collections/src/lib.rs new file mode 100644 index 00000000..48d92b64 --- /dev/null +++ b/contracts/collections/src/lib.rs @@ -0,0 +1,50 @@ +#![no_std] + +use soroban_sdk::{contract, Address, BytesN, Env, Vec}; + +use soroban_sdk::{contract, contractimpl, Env, Address, Symbol, Vec}; + +#[derive(Clone)] +pub struct Collection { + pub id: u64, + pub name: Symbol, + pub description: Symbol, + pub creator: Address, + pub nft_contracts: Vec
, // List of NFT contract addresses +} + +#[contract] +pub struct CollectionContract; + +#[contractimpl] +impl CollectionContract { + fn generate_id(env: &Env) -> u64 { + todo!() + } + + pub fn initialize( + env: Env, + name: Symbol, + description: Symbol, + creator: Address, + ) -> Collection { + todo!() + } + + pub fn add_nft(env: Env, collection_id: u64, nft_contract_address: Address) { + todo!() + } + + pub fn remove_nft(env: Env, collection_id: u64, nft_contract_address: Address) { + todo!() + } + + pub fn get_details(env: Env, collection_id: u64) -> Collection { + todo!() + } + + pub fn get_nfts(env: Env, collection_id: u64) -> Vec
{ + todo!() + } +} + diff --git a/contracts/nft/src/lib.rs b/contracts/nft/src/lib.rs index 5fc9f6d3..c9b4565e 100644 --- a/contracts/nft/src/lib.rs +++ b/contracts/nft/src/lib.rs @@ -1,11 +1,78 @@ #![no_std] -// mod admin; -// mod approval; -// mod balance; -mod contract; -// mod event; -mod interface; -// mod metadata; -// mod owner; -mod storage_types; +use soroban_sdk::{contract, Address, Bytes, Env, Symbol, Vec}; + +#[derive(Clone)] +pub enum ContentType { + Image, + Gif, + Video, + MP3, + Ticket, + Avatar(AvatarAttributes), +} + +#[derive(Clone)] +pub struct Trait { + pub trait_type: Symbol, + pub value: Symbol, + pub score: f64, +} + +#[derive(Clone)] +pub struct AvatarAttributes { + pub fur: Trait, + pub clothes: Trait, + pub eyes: Trait, + pub mouth: Trait, + pub background: Trait, + pub hat: Trait, + pub earring: Option, +} + +#[derive(Clone)] +pub struct NFT { + pub id: u64, + pub uri: Symbol, + pub creator: Address, + pub owner: Address, + pub royalties: u8, // Percentage of transaction + pub content_type: ContentType, + pub traits: Vec, // Optional traits for avatars or other NFTs +} + +use soroban_sdk::{contract, contractimpl, Env, Address, Symbol, Vec}; + +#[contract] +pub struct NftContract; + +#[contractimpl] +impl NftContract { + fn generate_id(env: &Env) -> u64 { + todo!() + } + + pub fn initialize( + env: Env, + uri: Symbol, + creator: Address, + royalties: u8, + content_type: ContentType, + traits: Option>, + ) -> NFT { + todo!() + } + + pub fn transfer_nft(env: Env, nft_id: u64, new_owner: Address) { + todo!() + } + + pub fn get_details(env: Env, nft_id: u64) -> NFT { + todo!() + } + + pub fn set_trait(env: Env, nft_id: u64, trait_type: Symbol, value: Symbol, score: f64) { + todo!() + } +} + From 6facb55d33be668b0aeb4f50ae0243219b7de694 Mon Sep 17 00:00:00 2001 From: Jakub Date: Mon, 1 Jul 2024 10:49:30 +0200 Subject: [PATCH 2/2] NFT collections: Fix imports --- Cargo.lock | 14 ++++++ contracts/auctions/Cargo.toml | 2 +- contracts/auctions/src/lib.rs | 1 - contracts/collections/Cargo.toml | 2 +- contracts/collections/src/lib.rs | 13 ++---- contracts/nft/src/lib.rs | 75 -------------------------------- 6 files changed, 19 insertions(+), 88 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44113772..cbf666b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -712,6 +712,20 @@ dependencies = [ "soroban-sdk", ] +[[package]] +name = "phoenix-nft-auctions" +version = "1.0.0" +dependencies = [ + "soroban-sdk", +] + +[[package]] +name = "phoenix-nft-collections" +version = "1.0.0" +dependencies = [ + "soroban-sdk", +] + [[package]] name = "pkcs8" version = "0.10.2" diff --git a/contracts/auctions/Cargo.toml b/contracts/auctions/Cargo.toml index 226700e4..8a08a19b 100644 --- a/contracts/auctions/Cargo.toml +++ b/contracts/auctions/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "phoenix-nft" +name = "phoenix-nft-auctions" version = { workspace = true } authors = ["Jakub "] repository = { workspace = true } diff --git a/contracts/auctions/src/lib.rs b/contracts/auctions/src/lib.rs index 65358418..8802cd3c 100644 --- a/contracts/auctions/src/lib.rs +++ b/contracts/auctions/src/lib.rs @@ -21,7 +21,6 @@ pub enum AuctionStatus { Cancelled, } - #[contract] pub struct MarketplaceContract; diff --git a/contracts/collections/Cargo.toml b/contracts/collections/Cargo.toml index 226700e4..f1f64bf5 100644 --- a/contracts/collections/Cargo.toml +++ b/contracts/collections/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "phoenix-nft" +name = "phoenix-nft-collections" version = { workspace = true } authors = ["Jakub "] repository = { workspace = true } diff --git a/contracts/collections/src/lib.rs b/contracts/collections/src/lib.rs index 48d92b64..85b33ae1 100644 --- a/contracts/collections/src/lib.rs +++ b/contracts/collections/src/lib.rs @@ -1,10 +1,9 @@ #![no_std] -use soroban_sdk::{contract, Address, BytesN, Env, Vec}; - -use soroban_sdk::{contract, contractimpl, Env, Address, Symbol, Vec}; +use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, Symbol, Vec}; #[derive(Clone)] +#[contracttype] pub struct Collection { pub id: u64, pub name: Symbol, @@ -22,12 +21,7 @@ impl CollectionContract { todo!() } - pub fn initialize( - env: Env, - name: Symbol, - description: Symbol, - creator: Address, - ) -> Collection { + pub fn initialize(env: Env, name: Symbol, description: Symbol, creator: Address) -> Collection { todo!() } @@ -47,4 +41,3 @@ impl CollectionContract { todo!() } } - diff --git a/contracts/nft/src/lib.rs b/contracts/nft/src/lib.rs index c9b4565e..63567659 100644 --- a/contracts/nft/src/lib.rs +++ b/contracts/nft/src/lib.rs @@ -1,78 +1,3 @@ #![no_std] use soroban_sdk::{contract, Address, Bytes, Env, Symbol, Vec}; - -#[derive(Clone)] -pub enum ContentType { - Image, - Gif, - Video, - MP3, - Ticket, - Avatar(AvatarAttributes), -} - -#[derive(Clone)] -pub struct Trait { - pub trait_type: Symbol, - pub value: Symbol, - pub score: f64, -} - -#[derive(Clone)] -pub struct AvatarAttributes { - pub fur: Trait, - pub clothes: Trait, - pub eyes: Trait, - pub mouth: Trait, - pub background: Trait, - pub hat: Trait, - pub earring: Option, -} - -#[derive(Clone)] -pub struct NFT { - pub id: u64, - pub uri: Symbol, - pub creator: Address, - pub owner: Address, - pub royalties: u8, // Percentage of transaction - pub content_type: ContentType, - pub traits: Vec, // Optional traits for avatars or other NFTs -} - -use soroban_sdk::{contract, contractimpl, Env, Address, Symbol, Vec}; - -#[contract] -pub struct NftContract; - -#[contractimpl] -impl NftContract { - fn generate_id(env: &Env) -> u64 { - todo!() - } - - pub fn initialize( - env: Env, - uri: Symbol, - creator: Address, - royalties: u8, - content_type: ContentType, - traits: Option>, - ) -> NFT { - todo!() - } - - pub fn transfer_nft(env: Env, nft_id: u64, new_owner: Address) { - todo!() - } - - pub fn get_details(env: Env, nft_id: u64) -> NFT { - todo!() - } - - pub fn set_trait(env: Env, nft_id: u64, trait_type: Symbol, value: Symbol, score: f64) { - todo!() - } -} -