Skip to content

Commit

Permalink
Continue implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Apr 13, 2024
1 parent a7a2200 commit 62bc108
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 126 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ lib
dist
tmp
node_modules
tsconfig.tsbuildinfo
tsconfig.tsbuildinfo
.turbo
51 changes: 18 additions & 33 deletions contracts/stargaze-marketplace-v2/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,12 @@ pub fn execute(
execute_update_ask(deps, env, info, id, details.str_to_addr(api)?)
}
ExecuteMsg::RemoveAsk { id } => execute_remove_ask(deps, env, info, id),
ExecuteMsg::AcceptAsk {
id,
asset_recipient,
finder,
} => execute_accept_ask(
ExecuteMsg::AcceptAsk { id, actor, finder } => execute_accept_ask(
deps,
env,
info,
id,
maybe_addr(api, asset_recipient)?,
maybe_addr(api, actor)?,
maybe_addr(api, finder)?,
),
ExecuteMsg::SetOffer {
Expand All @@ -82,16 +78,12 @@ pub fn execute(
execute_update_offer(deps, env, info, id, details.str_to_addr(api)?)
}
ExecuteMsg::RemoveOffer { id } => execute_remove_offer(deps, env, info, id),
ExecuteMsg::AcceptOffer {
id,
asset_recipient,
finder,
} => execute_accept_offer(
ExecuteMsg::AcceptOffer { id, actor, finder } => execute_accept_offer(
deps,
env,
info,
id,
maybe_addr(api, asset_recipient)?,
maybe_addr(api, actor)?,
maybe_addr(api, finder)?,
),
ExecuteMsg::SetCollectionOffer {
Expand All @@ -113,15 +105,15 @@ pub fn execute(
ExecuteMsg::AcceptCollectionOffer {
id,
token_id,
asset_recipient,
actor,
finder,
} => execute_accept_collection_offer(
deps,
env,
info,
id,
token_id,
maybe_addr(api, asset_recipient)?,
maybe_addr(api, actor)?,
maybe_addr(api, finder)?,
),
}
Expand Down Expand Up @@ -221,7 +213,7 @@ pub fn execute_set_ask(
"collection",
"token_id",
"price",
"asset_recipient",
"actor",
"finder",
],
}
Expand Down Expand Up @@ -283,7 +275,7 @@ pub fn execute_update_ask(
AskEvent {
ty: "update-ask",
ask: &ask,
attr_keys: vec!["id", "price", "asset_recipient", "finder"],
attr_keys: vec!["id", "price", "actor", "finder"],
}
.into(),
);
Expand Down Expand Up @@ -331,7 +323,7 @@ pub fn execute_accept_ask(
env: Env,
info: MessageInfo,
id: OrderId,
asset_recipient: Option<Addr>,
actor: Option<Addr>,
finder: Option<Addr>,
) -> Result<Response, ContractError> {
let mut funds = NativeBalance(info.funds.clone());
Expand All @@ -354,7 +346,7 @@ pub fn execute_accept_ask(
ask.token_id.clone(),
OrderDetails {
price: ask.details.price.clone(),
asset_recipient: asset_recipient.clone(),
actor: actor.clone(),
finder: finder.clone(),
},
env.block.height,
Expand Down Expand Up @@ -450,7 +442,7 @@ pub fn execute_set_offer(
"collection",
"token_id",
"price",
"asset_recipient",
"actor",
"finder",
],
}
Expand Down Expand Up @@ -538,7 +530,7 @@ pub fn execute_update_offer(
OfferEvent {
ty: "update-offer",
offer: &offer,
attr_keys: vec!["id", "price", "asset_recipient", "finder"],
attr_keys: vec!["id", "price", "actor", "finder"],
}
.into(),
);
Expand Down Expand Up @@ -588,7 +580,7 @@ pub fn execute_accept_offer(
env: Env,
info: MessageInfo,
id: OrderId,
asset_recipient: Option<Addr>,
actor: Option<Addr>,
finder: Option<Addr>,
) -> Result<Response, ContractError> {
let offer: Offer = offers()
Expand All @@ -614,7 +606,7 @@ pub fn execute_accept_offer(
offer.token_id.clone(),
OrderDetails {
price: offer.details.price.clone(),
asset_recipient: asset_recipient.clone(),
actor: actor.clone(),
finder: finder.clone(),
},
)
Expand Down Expand Up @@ -693,14 +685,7 @@ pub fn execute_set_collection_offer(
CollectionOfferEvent {
ty: "set-collection-offer",
collection_offer: &collection_offer,
attr_keys: vec![
"id",
"creator",
"collection",
"price",
"asset_recipient",
"finder",
],
attr_keys: vec!["id", "creator", "collection", "price", "actor", "finder"],
}
.into(),
);
Expand Down Expand Up @@ -788,7 +773,7 @@ pub fn execute_update_collection_offer(
CollectionOfferEvent {
ty: "update-collection-offer",
collection_offer: &collection_offer,
attr_keys: vec!["id", "price", "asset_recipient", "finder"],
attr_keys: vec!["id", "price", "actor", "finder"],
}
.into(),
);
Expand Down Expand Up @@ -840,7 +825,7 @@ pub fn execute_accept_collection_offer(
info: MessageInfo,
id: OrderId,
token_id: TokenId,
asset_recipient: Option<Addr>,
actor: Option<Addr>,
finder: Option<Addr>,
) -> Result<Response, ContractError> {
let collection_offer = collection_offers()
Expand Down Expand Up @@ -874,7 +859,7 @@ pub fn execute_accept_collection_offer(
token_id.clone(),
OrderDetails {
price: collection_offer.details.price.clone(),
asset_recipient: asset_recipient.clone(),
actor: actor.clone(),
finder: finder.clone(),
},
)
Expand Down
18 changes: 6 additions & 12 deletions contracts/stargaze-marketplace-v2/src/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cosmwasm_std::entry_point;
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
env: Env,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
Expand All @@ -26,20 +26,14 @@ pub fn instantiate(
config.save(deps.storage)?;

ALLOW_DENOMS.save(deps.storage, &msg.allow_denoms)?;

NONCE.save(deps.storage, &0)?;

let contract_info_response = deps
.querier
.query_wasm_contract_info(env.contract.address)?;

let instantiate_event = Event::new("instantiate".to_string())
.add_attribute("code_id", contract_info_response.code_id.to_string())
.add_attribute("contract_name", CONTRACT_NAME)
.add_attribute("contract_version", CONTRACT_VERSION);

let response = Response::new()
.add_event(instantiate_event)
.add_event(
Event::new("instantiate".to_string())
.add_attribute("contract_name", CONTRACT_NAME)
.add_attribute("contract_version", CONTRACT_VERSION),
)
.add_event(
ConfigEvent {
ty: "set-config",
Expand Down
6 changes: 3 additions & 3 deletions contracts/stargaze-marketplace-v2/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum ExecuteMsg {
},
AcceptAsk {
id: OrderId,
asset_recipient: Option<String>,
actor: Option<String>,
finder: Option<String>,
},
SetOffer {
Expand All @@ -56,7 +56,7 @@ pub enum ExecuteMsg {
},
AcceptOffer {
id: OrderId,
asset_recipient: Option<String>,
actor: Option<String>,
finder: Option<String>,
},
SetCollectionOffer {
Expand All @@ -73,7 +73,7 @@ pub enum ExecuteMsg {
AcceptCollectionOffer {
id: OrderId,
token_id: TokenId,
asset_recipient: Option<String>,
actor: Option<String>,
finder: Option<String>,
},
}
Expand Down
28 changes: 14 additions & 14 deletions contracts/stargaze-marketplace-v2/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ use sg_marketplace_common::address::address_or;
#[cw_serde]
pub struct OrderDetails<T: AddressLike> {
pub price: Coin,
pub asset_recipient: Option<T>,
pub actor: Option<T>,
pub finder: Option<T>,
}

impl OrderDetails<String> {
pub fn str_to_addr(self, api: &dyn Api) -> StdResult<OrderDetails<Addr>> {
Ok(OrderDetails {
price: self.price,
asset_recipient: maybe_addr(api, self.asset_recipient)?,
actor: maybe_addr(api, self.actor)?,
finder: maybe_addr(api, self.finder)?,
})
}
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Ask {
}

pub fn asset_recipient(&self) -> Addr {
address_or(self.details.asset_recipient.as_ref(), &self.creator)
address_or(self.details.actor.as_ref(), &self.creator)
}

pub fn save(&self, storage: &mut dyn Storage) -> Result<(), ContractError> {
Expand Down Expand Up @@ -138,11 +138,11 @@ impl Ask {
"collection" => Some(attr("collection", self.collection.to_string())),
"token_id" => Some(attr("token_id", self.token_id.to_string())),
"price" => Some(attr("price", self.details.price.to_string())),
"asset_recipient" => self
"actor" => self
.details
.asset_recipient
.actor
.as_ref()
.map(|asset_recipient| attr("asset_recipient", asset_recipient.to_string())),
.map(|actor| attr("actor", actor.to_string())),
"finder" => self
.details
.finder
Expand Down Expand Up @@ -193,7 +193,7 @@ impl Offer {
}

pub fn asset_recipient(&self) -> Addr {
address_or(self.details.asset_recipient.as_ref(), &self.creator)
address_or(self.details.actor.as_ref(), &self.creator)
}

pub fn save(&self, storage: &mut dyn Storage) -> Result<(), ContractError> {
Expand Down Expand Up @@ -229,11 +229,11 @@ impl Offer {
"collection" => Some(attr("collection", self.collection.to_string())),
"token_id" => Some(attr("token_id", self.token_id.to_string())),
"price" => Some(attr("price", self.details.price.to_string())),
"asset_recipient" => self
"actor" => self
.details
.asset_recipient
.actor
.as_ref()
.map(|asset_recipient| attr("asset_recipient", asset_recipient.to_string())),
.map(|actor| attr("actor", actor.to_string())),
"finder" => self
.details
.finder
Expand Down Expand Up @@ -280,7 +280,7 @@ impl CollectionOffer {
}

pub fn asset_recipient(&self) -> Addr {
address_or(self.details.asset_recipient.as_ref(), &self.creator)
address_or(self.details.actor.as_ref(), &self.creator)
}

pub fn save(&self, storage: &mut dyn Storage) -> Result<(), ContractError> {
Expand Down Expand Up @@ -321,11 +321,11 @@ impl CollectionOffer {
"creator" => Some(attr("creator", self.creator.to_string())),
"collection" => Some(attr("collection", self.collection.to_string())),
"price" => Some(attr("price", self.details.price.to_string())),
"asset_recipient" => self
"actor" => self
.details
.asset_recipient
.actor
.as_ref()
.map(|asset_recipient| attr("asset_recipient", asset_recipient.to_string())),
.map(|actor| attr("actor", actor.to_string())),
"finder" => self
.details
.finder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn try_query_asks_by_collection() {
&[],
OrderDetails {
price,
asset_recipient: None,
actor: None,
finder: None,
},
);
Expand Down Expand Up @@ -132,7 +132,7 @@ fn try_query_asks_by_creator() {
&[],
OrderDetails {
price,
asset_recipient: None,
actor: None,
finder: None,
},
);
Expand Down
Loading

0 comments on commit 62bc108

Please sign in to comment.