Skip to content

Commit

Permalink
Merge pull request #75 from briansinw3b/main
Browse files Browse the repository at this point in the history
staking pool
  • Loading branch information
0xandee authored Jul 12, 2024
2 parents 5e366a9 + 130dd6c commit f850e6f
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 9 deletions.
2 changes: 2 additions & 0 deletions flex_marketplace/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ mod marketplace {

mod interfaces {
mod nft_transfer_manager;
mod IFlexStakingPool;
}

mod openedition;
mod stakingpool;
mod contract_deployer;
mod currency_manager;
mod execution_manager;
Expand Down
10 changes: 10 additions & 0 deletions flex_marketplace/src/marketplace/interfaces/IFlexStakingPool.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use starknet::ContractAddress;

#[starknet::interface]
trait IFlexStakingPool<TContractState> {
fn stakeNFT(ref self: TContractState, collection: ContractAddress, tokenId: u256);
fn unstakeNFT(ref self: TContractState, collection: ContractAddress, tokenId: u256);
fn getUserPoint(
self: @TContractState, user: ContractAddress, nftCollection: ContractAddress, tokenId: u256
) -> u256;
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@ mod ERC721OpenEdition {
}
}

// return (number minted, current total supply)
fn get_mint_state(self: @ContractState, minter: ContractAddress) -> (u64, u64) {
fn get_mint_state(self: @ContractState, minter: ContractAddress) -> (u64, u64, u64) {
let total_minted = self.total_minted_per_wallet.read(minter);
let current_total_supply = self.get_total_minted();
(total_minted, current_total_supply)
(total_minted, current_total_supply, BoundedU64::max() - 1)
}

fn get_current_token_id(self: @ContractState) -> u256 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ mod ERC721OpenEditionMultiMetadata {
name: ByteArray,
symbol: ByteArray,
token_base_uri: ByteArray,
total_supply: u64,
allowed_flex_drop: Array::<ContractAddress>,
) {
self.ownable.initializer(creator);
self.erc721.initializer(name, symbol, creator, token_base_uri);
self.erc721.initializer(name, symbol, creator, total_supply, token_base_uri);
self.current_token_id.write(1);
self.current_phase_id.write(1);

Expand Down Expand Up @@ -290,10 +291,10 @@ mod ERC721OpenEditionMultiMetadata {
}

// return (number minted, current total supply)
fn get_mint_state(self: @ContractState, minter: ContractAddress) -> (u64, u64) {
fn get_mint_state(self: @ContractState, minter: ContractAddress) -> (u64, u64, u64) {
let total_minted = self.total_minted_per_wallet.read(minter);
let current_total_supply = self.get_total_minted();
(total_minted, current_total_supply)
(total_minted, current_total_supply, self.erc721.total_supply())
}

fn get_current_token_id(self: @ContractState) -> u256 {
Expand Down
4 changes: 3 additions & 1 deletion flex_marketplace/src/marketplace/openedition/FlexDrop.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,16 @@ mod FlexDrop {
) {
assert(quantity > 0, 'Only non zero quantity');

let (total_minted, _) = INonFungibleFlexDropTokenDispatcher {
let (total_minted, current_supply, total_supply) = INonFungibleFlexDropTokenDispatcher {
contract_address: *nft_address
}
.get_mint_state(*minter);

assert(
total_minted + quantity <= max_total_mint_per_wallet, 'Exceeds maximum total minted'
);

assert(current_supply + quantity <= total_supply, 'Exceeds maximum total supply');
}

fn assert_allowed_fee_recipient(self: @ContractState, fee_recipient: @ContractAddress,) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ mod ERC721Component {
self.ERC721_symbol.read()
}

/// Returns the NFT total supply
fn total_supply(self: @ComponentState<TContractState>) -> u64 {
BoundedU64::max() - 1
}

/// Returns the Uniform Resource Identifier (URI) for the `token_id` token.
/// If the URI is not set for the `token_id`, the return value will be `0`.
///
Expand Down Expand Up @@ -308,6 +313,10 @@ mod ERC721Component {
+SRC5Component::HasComponent<TContractState>,
+Drop<TContractState>
> of IERC721::IERC721MetadataCamelOnly<ComponentState<TContractState>> {
fn totalSupply(self: @ComponentState<TContractState>) -> u64 {
self.total_supply()
}

fn tokenURI(self: @ComponentState<TContractState>, tokenId: u256) -> ByteArray {
self.token_uri(tokenId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/// the IERC721Metadata interface and IFlexDropContractMetadata interface.
#[starknet::component]
mod ERC721MultiMetadataComponent {
use core::byte_array::ByteArrayTrait;
use openzeppelin::account;
use openzeppelin::introspection::dual_src5::{DualCaseSRC5, DualCaseSRC5Trait};
use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait;
Expand All @@ -23,6 +22,7 @@ mod ERC721MultiMetadataComponent {
struct Storage {
ERC721_name: ByteArray,
ERC721_symbol: ByteArray,
ERC721_total_supply: u64,
ERC721_owners: LegacyMap<u256, ContractAddress>,
ERC721_balances: LegacyMap<ContractAddress, u256>,
ERC721_token_approvals: LegacyMap<u256, ContractAddress>,
Expand Down Expand Up @@ -81,6 +81,7 @@ mod ERC721MultiMetadataComponent {
const SELF_APPROVAL: felt252 = 'ERC721: self approval';
const INVALID_RECEIVER: felt252 = 'ERC721: invalid receiver';
const ALREADY_MINTED: felt252 = 'ERC721: token already minted';
const REACH_MAXIMUM_SUPPLY: felt252 = 'ERC721: reach maximum supply';
const WRONG_SENDER: felt252 = 'ERC721: wrong sender';
const SAFE_MINT_FAILED: felt252 = 'ERC721: safe mint failed';
const SAFE_TRANSFER_FAILED: felt252 = 'ERC721: safe transfer failed';
Expand Down Expand Up @@ -231,6 +232,11 @@ mod ERC721MultiMetadataComponent {
self.ERC721_symbol.read()
}

/// Returns the NFT total supply
fn total_supply(self: @ComponentState<TContractState>) -> u64 {
self.ERC721_total_supply.read()
}

/// Returns the Uniform Resource Identifier (URI) for the `token_id` token.
/// If the URI is not set for the `token_id`, the return value will be `0`.
///
Expand Down Expand Up @@ -308,6 +314,10 @@ mod ERC721MultiMetadataComponent {
+SRC5Component::HasComponent<TContractState>,
+Drop<TContractState>
> of IERC721::IERC721MetadataCamelOnly<ComponentState<TContractState>> {
fn totalSupply(self: @ComponentState<TContractState>) -> u64 {
self.total_supply()
}

fn tokenURI(self: @ComponentState<TContractState>, tokenId: u256) -> ByteArray {
self.token_uri(tokenId)
}
Expand Down Expand Up @@ -357,11 +367,13 @@ mod ERC721MultiMetadataComponent {
name: ByteArray,
symbol: ByteArray,
creator: ContractAddress,
total_supply: u64,
token_base_uri: ByteArray
) {
self.ERC721_creator.write(creator);
self.ERC721_name.write(name);
self.ERC721_symbol.write(symbol);
self.ERC721_total_supply.write(total_supply);
self.ERC721_base_uri.write(token_base_uri);

let mut src5_component = get_dep_component_mut!(ref self, SRC5);
Expand All @@ -387,6 +399,11 @@ mod ERC721MultiMetadataComponent {
!self.ERC721_owners.read(token_id).is_zero()
}

/// Returns whether `token_id` greater than the total supply.
fn _reach_maximum_supply(self: @ComponentState<TContractState>, token_id: u256) -> bool {
token_id > self.ERC721_total_supply.read().into()
}

/// Returns whether `spender` is allowed to manage `token_id`.
///
/// Requirements:
Expand Down Expand Up @@ -449,6 +466,7 @@ mod ERC721MultiMetadataComponent {
fn _mint(ref self: ComponentState<TContractState>, to: ContractAddress, token_id: u256) {
assert(!to.is_zero(), Errors::INVALID_RECEIVER);
assert(!self._exists(token_id), Errors::ALREADY_MINTED);
assert(!self._reach_maximum_supply(token_id), Errors::REACH_MAXIMUM_SUPPLY);

self.ERC721_balances.write(to, self.ERC721_balances.read(to) + 1);
self.ERC721_owners.write(token_id, to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trait IERC721<TState> {
trait IERC721Metadata<TState> {
fn name(self: @TState) -> ByteArray;
fn symbol(self: @TState) -> ByteArray;
fn total_supply(self: @TState) -> u64;
fn token_uri(self: @TState, token_id: u256) -> ByteArray;
}

Expand All @@ -52,6 +53,7 @@ trait IERC721CamelOnly<TState> {

#[starknet::interface]
trait IERC721MetadataCamelOnly<TState> {
fn totalSupply(self: @TState) -> u64;
fn tokenURI(self: @TState, tokenId: u256) -> ByteArray;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait INonFungibleFlexDropToken<TContractState> {
);
fn multi_configure(ref self: TContractState, config: MultiConfigureStruct);
// return (number minted, current total supply, max supply)
fn get_mint_state(self: @TContractState, minter: ContractAddress) -> (u64, u64);
fn get_mint_state(self: @TContractState, minter: ContractAddress) -> (u64, u64, u64);
fn get_current_token_id(self: @TContractState) -> u256;
fn get_allowed_flex_drops(self: @TContractState) -> Span::<ContractAddress>;
}
1 change: 1 addition & 0 deletions flex_marketplace/src/marketplace/stakingpool.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod FlexStakingPool;
Loading

0 comments on commit f850e6f

Please sign in to comment.