Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mohit/currency manager #20

Closed
Closed
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

flex_marketplace/target/
.snfoundry_cache


flex_marketplace/.snfoundry_cache/

2 changes: 2 additions & 0 deletions flex_marketplace/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
starknet-foundry 0.13.0
scarb 2.4.0
14 changes: 13 additions & 1 deletion flex_marketplace/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,17 @@ starknet = "2.4.0"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.13.0" }
openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag = "v0.8.0" }

[[target.starknet-contract]]
sierra = true
casm = true
allowed-libfuncs-list.name = "experimental"

[cairo]
sierra-replace-ids = true

[tool.fmt]
sort-module-level-items = true

[scripts]
test = "snforge test"
test = "snforge test"

2 changes: 1 addition & 1 deletion flex_marketplace/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ mod marketplace {
mod transfer_manager_ERC721;
mod transfer_manager_ERC1155;
mod transfer_selector_NFT;
}
}
69 changes: 49 additions & 20 deletions flex_marketplace/src/marketplace/currency_manager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@ trait ICurrencyManager<TState> {
fn initializer(ref self: TState, owner: ContractAddress, proxy_admin: ContractAddress);
fn add_currency(ref self: TState, currency: ContractAddress);
fn remove_currency(ref self: TState, currency: ContractAddress);
fn transfer_ownership(ref self: TState, new_owner: ContractAddress);
fn owner(self: @TState) -> ContractAddress;
fn is_currency_whitelisted(self: @TState, currency: ContractAddress) -> bool;
fn whitelisted_currency_count(self: @TState) -> usize;
fn whitelisted_currency(self: @TState, index: usize) -> ContractAddress;
}

#[starknet::interface]
trait ICurrencyManage<TState> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ICurruncyManager

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be same as the interface just above, we can't have that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see what is the issue, you can remove completely the interface with Ownable functions, we will use IOwnable interface for testing. after that LGTM let's just wait for the workflow to be approved (not sure why it does still need approval). Also if you have problem with assert! formatting ContractAddress my last PR will fix that once merged you'll just have to import flex::{Debug, Display}; in your contract

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's failing because of the assert! formatting, I will pull and merge those changes, once they are merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR that fixes your issue is merged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mohiiit Hey man, any updates on this PR!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @and1vo, Yes I will update this branch, with the latest changes in place. was away for sometime, will do it asap

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Mohiiit just checkin in!

fn owner(self: @TState) -> ContractAddress;
fn transfer_ownership(ref self: TState, new_owner: ContractAddress);
}

#[starknet::contract]
mod CurrencyManager {
use starknet::{ContractAddress, contract_address_const};
use openzeppelin::access::ownable::interface::IOwnable;
use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait as OwnableInternalTrait;
use openzeppelin::access::ownable::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const, get_block_timestamp};

use openzeppelin::access::ownable::OwnableComponent;
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;

// impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

#[storage]
struct Storage {
whitelisted_currency_count: usize,
whitelisted_currencies: LegacyMap::<usize, ContractAddress>,
whitelisted_currency_index: LegacyMap::<ContractAddress, usize>,
initialized: bool,
#[substorage(v0)]
ownable: OwnableComponent::Storage
}
Expand All @@ -38,6 +46,7 @@ mod CurrencyManager {
enum Event {
CurrencyRemoved: CurrencyRemoved,
CurrencyWhitelisted: CurrencyWhitelisted,
#[flat]
OwnableEvent: OwnableComponent::Event,
}

Expand All @@ -57,36 +66,56 @@ mod CurrencyManager {
impl CurrencyManagerImpl of super::ICurrencyManager<ContractState> {
fn initializer(
ref self: ContractState, owner: ContractAddress, proxy_admin: ContractAddress
) { // TODO
}

fn add_currency(ref self: ContractState, currency: ContractAddress) { // TODO
}

fn remove_currency(ref self: ContractState, currency: ContractAddress) { // TODO
) {
assert!(!self.initialized.read(), "CurrencyManager: already initialized");
self.initialized.write(true);
self.ownable.initializer(owner);
}

fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { // TODO
fn add_currency(ref self: ContractState, currency: ContractAddress) {
self.ownable.assert_only_owner();
let index = self.whitelisted_currency_index.read(currency);
assert!(index.is_zero(), "CurrencyManager: currency {} already whitelisted", currency);
let new_count = self.whitelisted_currency_count.read() + 1;
self.whitelisted_currency_index.write(currency, new_count);
self.whitelisted_currencies.write(new_count, currency);
self.whitelisted_currency_count.write(new_count);
let timestamp = get_block_timestamp();
self.emit(CurrencyWhitelisted { currency, timestamp });
}

fn owner(self: @ContractState) -> ContractAddress {
// TODO
contract_address_const::<0>()
fn remove_currency(ref self: ContractState, currency: ContractAddress) {
self.ownable.assert_only_owner();
let index = self.whitelisted_currency_index.read(currency);
assert!(!index.is_zero(), "CurrencyManager: currency {} not whitelisted", currency);
let count = self.whitelisted_currency_count.read();

let currency_at_last_index = self.whitelisted_currencies.read(count);
self.whitelisted_currencies.write(index, currency_at_last_index);
self.whitelisted_currencies.write(count, contract_address_const::<0>());
self.whitelisted_currency_index.write(currency, 0);
if (count != 1) {
self.whitelisted_currency_index.write(currency_at_last_index, index);
}
self.whitelisted_currency_count.write(count - 1);
let timestamp = get_block_timestamp();
self.emit(CurrencyRemoved { currency, timestamp });
}

fn is_currency_whitelisted(self: @ContractState, currency: ContractAddress) -> bool {
// TODO
let index = self.whitelisted_currency_index.read(currency);
if (index == 0) {
return false;
}
true
}

fn whitelisted_currency_count(self: @ContractState) -> usize {
// TODO
0
self.whitelisted_currency_count.read()
}

fn whitelisted_currency(self: @ContractState, index: usize) -> ContractAddress {
// TODO
contract_address_const::<0>()
self.whitelisted_currencies.read(index)
}
}
}
3 changes: 1 addition & 2 deletions flex_marketplace/src/marketplace/execution_manager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ trait IExecutionManager<TState> {

#[starknet::contract]
mod ExecutionManager {
use starknet::{ContractAddress, contract_address_const};

use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
Expand Down
6 changes: 2 additions & 4 deletions flex_marketplace/src/marketplace/market_place.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use starknet::ContractAddress;

use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};
use starknet::ContractAddress;

trait IMarketPlace<TState> {
fn cancel_all_orders_for_sender(ref self: TState, min_nonce: u128);
Expand Down Expand Up @@ -50,11 +49,10 @@ trait IMarketPlace<TState> {

#[starknet::contract]
mod MarketPlace {
use starknet::{ContractAddress, contract_address_const};

use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};

use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
Expand Down
1 change: 1 addition & 0 deletions flex_marketplace/src/marketplace/royalty_fee_manager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ trait IERC2981<TContractState> {

#[starknet::contract]
mod RoyaltyFeeManager {

use openzeppelin::upgrades::upgradeable::UpgradeableComponent::InternalTrait;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::upgrades::UpgradeableComponent;
Expand Down
3 changes: 1 addition & 2 deletions flex_marketplace/src/marketplace/royalty_fee_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ trait IRoyaltyFeeRegistry<TState> {

#[starknet::contract]
mod RoyaltyFeeRegistry {
use starknet::{ContractAddress, contract_address_const};

use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
Expand Down
6 changes: 2 additions & 4 deletions flex_marketplace/src/marketplace/signature_checker2.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use starknet::ContractAddress;

use flex::marketplace::utils::order_types::MakerOrder;
use starknet::ContractAddress;

trait ISignatureChecker2<TState> {
fn initializer(ref self: TState, proxy_admin: ContractAddress);
Expand All @@ -12,9 +11,8 @@ trait ISignatureChecker2<TState> {

#[starknet::contract]
mod SignatureChecker2 {
use starknet::ContractAddress;

use flex::marketplace::utils::order_types::MakerOrder;
use starknet::ContractAddress;

#[storage]
struct Storage {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use starknet::ContractAddress;

use flex::marketplace::utils::order_types::{TakerOrder, MakerOrder};
use starknet::ContractAddress;

#[starknet::interface]
trait IStrategyStandardSaleForFixedPrice<TState> {
Expand All @@ -21,18 +20,17 @@ trait IStrategyStandardSaleForFixedPrice<TState> {

#[starknet::contract]
mod StrategyStandardSaleForFixedPrice {
use starknet::{ContractAddress, contract_address_const};
use flex::marketplace::utils::order_types::{TakerOrder, MakerOrder};

use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;

impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

use flex::marketplace::utils::order_types::{TakerOrder, MakerOrder};

#[storage]
struct Storage {
protocol_fee: u128,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ trait IERC1155<TState> {

#[starknet::contract]
mod ERC1155 {
use starknet::{ContractAddress, contract_address_const};

use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};

use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ trait IERC721<TState> {

#[starknet::contract]
mod ERC721 {
use starknet::{ContractAddress, contract_address_const};

use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};

use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
Expand Down
3 changes: 1 addition & 2 deletions flex_marketplace/src/marketplace/transfer_selector_NFT.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ trait ITransferSelectorNFT<TState> {

#[starknet::contract]
mod TransferSelectorNFT {
use starknet::{ContractAddress, contract_address_const};

use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};

use openzeppelin::access::ownable::OwnableComponent;
use starknet::{ContractAddress, contract_address_const};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[abi(embed_v0)]
Expand Down
Loading