From a760b309679b0f63062a9607b677a71f99787571 Mon Sep 17 00:00:00 2001 From: Tasio Victoria Date: Sat, 13 Jul 2024 11:08:50 -0400 Subject: [PATCH] Marketplace v2 rename offers to bid, add collection and token id attr to remove and update events --- contracts/stargaze-marketplace-v2/README.md | 2 +- .../stargaze-marketplace-v2/src/events.rs | 22 +- .../stargaze-marketplace-v2/src/execute.rs | 303 ++++++++++-------- .../stargaze-marketplace-v2/src/helpers.rs | 52 ++- contracts/stargaze-marketplace-v2/src/msg.rs | 50 +-- .../stargaze-marketplace-v2/src/orders.rs | 49 ++- .../stargaze-marketplace-v2/src/query.rs | 78 ++--- .../stargaze-marketplace-v2/src/state.rs | 55 ++-- .../{offer_queries.rs => bid_queries.rs} | 186 +++++------ .../tests/unit_tests/{offers.rs => bids.rs} | 128 ++++---- ...r_queries.rs => collection_bid_queries.rs} | 158 ++++----- ...ollection_offers.rs => collection_bids.rs} | 130 ++++---- .../src/tests/unit_tests/mod.rs | 8 +- .../src/tests/unit_tests/sales.rs | 112 +++---- 14 files changed, 673 insertions(+), 660 deletions(-) rename contracts/stargaze-marketplace-v2/src/tests/unit_tests/{offer_queries.rs => bid_queries.rs} (56%) rename contracts/stargaze-marketplace-v2/src/tests/unit_tests/{offers.rs => bids.rs} (66%) rename contracts/stargaze-marketplace-v2/src/tests/unit_tests/{collection_offer_queries.rs => collection_bid_queries.rs} (53%) rename contracts/stargaze-marketplace-v2/src/tests/unit_tests/{collection_offers.rs => collection_bids.rs} (61%) diff --git a/contracts/stargaze-marketplace-v2/README.md b/contracts/stargaze-marketplace-v2/README.md index 2ff7cd68..b9a4c313 100644 --- a/contracts/stargaze-marketplace-v2/README.md +++ b/contracts/stargaze-marketplace-v2/README.md @@ -2,7 +2,7 @@ The Stargaze NFT auction happens as a perpetual auction. Asks and bids have time limits set by governance. -Anyone can call the `SetBid` method and make an offer on any listed NFT. The funds are sent to the marketplace contract which serves as an escrow. +Anyone can call the `SetBid` method and make an bid on any listed NFT. The funds are sent to the marketplace contract which serves as an escrow. Bidders can remove their bids and reclaim their funds with `RemoveBid`. When a bid is removed, its deposit is refunded. New bids automatically remove and refund previous bids. diff --git a/contracts/stargaze-marketplace-v2/src/events.rs b/contracts/stargaze-marketplace-v2/src/events.rs index b4283ff4..65091090 100644 --- a/contracts/stargaze-marketplace-v2/src/events.rs +++ b/contracts/stargaze-marketplace-v2/src/events.rs @@ -1,5 +1,5 @@ use crate::{ - orders::{Ask, CollectionOffer, Offer}, + orders::{Ask, CollectionBid, Bid}, state::{AllowDenoms, Config}, }; @@ -71,27 +71,27 @@ impl<'a> From> for Event { } } -pub struct OfferEvent<'a> { +pub struct BidEvent<'a> { pub ty: &'a str, - pub offer: &'a Offer, + pub bid: &'a Bid, pub attr_keys: Vec<&'a str>, } -impl<'a> From> for Event { - fn from(oe: OfferEvent) -> Self { - Event::new(oe.ty.to_string()).add_attributes(oe.offer.get_event_attrs(oe.attr_keys)) +impl<'a> From> for Event { + fn from(oe: BidEvent) -> Self { + Event::new(oe.ty.to_string()).add_attributes(oe.bid.get_event_attrs(oe.attr_keys)) } } -pub struct CollectionOfferEvent<'a> { +pub struct CollectionBidEvent<'a> { pub ty: &'a str, - pub collection_offer: &'a CollectionOffer, + pub collection_bid: &'a CollectionBid, pub attr_keys: Vec<&'a str>, } -impl<'a> From> for Event { - fn from(coe: CollectionOfferEvent) -> Self { +impl<'a> From> for Event { + fn from(coe: CollectionBidEvent) -> Self { Event::new(coe.ty.to_string()) - .add_attributes(coe.collection_offer.get_event_attrs(coe.attr_keys)) + .add_attributes(coe.collection_bid.get_event_attrs(coe.attr_keys)) } } diff --git a/contracts/stargaze-marketplace-v2/src/execute.rs b/contracts/stargaze-marketplace-v2/src/execute.rs index 16380231..b6a8162d 100644 --- a/contracts/stargaze-marketplace-v2/src/execute.rs +++ b/contracts/stargaze-marketplace-v2/src/execute.rs @@ -1,12 +1,12 @@ use crate::{ error::ContractError, - events::{AllowDenomsEvent, AskEvent, CollectionOfferEvent, ConfigEvent, OfferEvent}, + events::{AllowDenomsEvent, AskEvent, BidEvent, CollectionBidEvent, ConfigEvent}, helpers::{finalize_sale, generate_id, only_contract_admin}, msg::ExecuteMsg, - orders::{Ask, CollectionOffer, MatchingOffer, Offer, OrderDetails}, + orders::{Ask, Bid, CollectionBid, MatchingBid, OrderDetails}, state::{ - asks, collection_offers, offers, AllowDenoms, Config, OrderId, TokenId, ALLOW_DENOMS, - CONFIG, NONCE, + asks, bids, collection_bids, AllowDenoms, Config, OrderId, TokenId, ALLOW_DENOMS, CONFIG, + NONCE, }, }; @@ -71,11 +71,11 @@ pub fn execute( maybe_addr(api, recipient)?, maybe_addr(api, finder)?, ), - ExecuteMsg::SetOffer { + ExecuteMsg::SetBid { collection, token_id, details, - } => execute_set_offer( + } => execute_set_bid( deps, env, info, @@ -84,16 +84,16 @@ pub fn execute( details.str_to_addr(api)?, false, ), - ExecuteMsg::UpdateOffer { id, details } => { - execute_update_offer(deps, env, info, id, details.str_to_addr(api)?) + ExecuteMsg::UpdateBid { id, details } => { + execute_update_bid(deps, env, info, id, details.str_to_addr(api)?) } - ExecuteMsg::RemoveOffer { id } => execute_remove_offer(deps, env, info, id), - ExecuteMsg::AcceptOffer { + ExecuteMsg::RemoveBid { id } => execute_remove_bid(deps, env, info, id), + ExecuteMsg::AcceptBid { id, min_output, recipient, finder, - } => execute_accept_offer( + } => execute_accept_bid( deps, env, info, @@ -102,10 +102,10 @@ pub fn execute( maybe_addr(api, recipient)?, maybe_addr(api, finder)?, ), - ExecuteMsg::SetCollectionOffer { + ExecuteMsg::SetCollectionBid { collection, details, - } => execute_set_collection_offer( + } => execute_set_collection_bid( deps, env, info, @@ -113,19 +113,19 @@ pub fn execute( details.str_to_addr(api)?, false, ), - ExecuteMsg::UpdateCollectionOffer { id, details } => { - execute_update_collection_offer(deps, env, info, id, details.str_to_addr(api)?) + ExecuteMsg::UpdateCollectionBid { id, details } => { + execute_update_collection_bid(deps, env, info, id, details.str_to_addr(api)?) } - ExecuteMsg::RemoveCollectionOffer { id } => { - execute_remove_collection_offer(deps, env, info, id) + ExecuteMsg::RemoveCollectionBid { id } => { + execute_remove_collection_bid(deps, env, info, id) } - ExecuteMsg::AcceptCollectionOffer { + ExecuteMsg::AcceptCollectionBid { id, token_id, min_output, recipient, finder, - } => execute_accept_collection_offer( + } => execute_accept_collection_bid( deps, env, info, @@ -160,7 +160,7 @@ pub fn execute( max_input, recipient, finder, - } => execute_set_offer( + } => execute_set_bid( deps, env, info, @@ -178,7 +178,7 @@ pub fn execute( max_input, recipient, finder, - } => execute_set_collection_offer( + } => execute_set_collection_bid( deps, env, info, @@ -260,11 +260,11 @@ pub fn execute_set_ask( let mut response = Response::new(); - let match_result = ask.match_with_offer(deps.as_ref())?; + let match_result = ask.match_with_bid(deps.as_ref())?; - if let Some(matching_offer) = match_result { + if let Some(matching_bid) = match_result { // If a match is found finalize the sale - response = finalize_sale(deps, &env, &ask, &config, &matching_offer, false, response)?; + response = finalize_sale(deps, &env, &ask, &config, &matching_bid, false, response)?; } else if sell_now { // If no match is found and sell_now is true, abort transaction Err(ContractError::NoMatchFound)?; @@ -340,11 +340,11 @@ pub fn execute_update_ask( let mut response = Response::new(); - let match_result = ask.match_with_offer(deps.as_ref())?; + let match_result = ask.match_with_bid(deps.as_ref())?; - if let Some(matching_offer) = match_result { + if let Some(matching_bid) = match_result { // If a match is found finalize the sale - response = finalize_sale(deps, &env, &ask, &config, &matching_offer, false, response)?; + response = finalize_sale(deps, &env, &ask, &config, &matching_bid, false, response)?; } else { // If no match is found continue updating the ask ask.save(deps.storage)?; @@ -353,7 +353,14 @@ pub fn execute_update_ask( AskEvent { ty: "update-ask", ask: &ask, - attr_keys: vec!["id", "price", "recipient", "finder"], + attr_keys: vec![ + "id", + "collection", + "token_id", + "price", + "recipient", + "finder", + ], } .into(), ); @@ -391,7 +398,14 @@ pub fn execute_remove_ask( ask.remove(deps.storage)?; - response = response.add_event(Event::new("remove-ask".to_string()).add_attribute("id", id)); + response = response.add_event( + AskEvent { + ty: "remove-ask", + ask: &ask, + attr_keys: vec!["id", "collection", "token_id"], + } + .into(), + ); Ok(response) } @@ -424,7 +438,7 @@ pub fn execute_accept_ask( let nonce = NONCE.load(deps.storage)?.wrapping_add(1); NONCE.save(deps.storage, &nonce)?; - let offer = Offer::new( + let bid = Bid::new( info.sender.clone(), ask.collection.clone(), ask.token_id.clone(), @@ -443,7 +457,7 @@ pub fn execute_accept_ask( &env, &ask, &config, - &MatchingOffer::Offer(offer), + &MatchingBid::Bid(bid), true, Response::new(), )?; @@ -456,7 +470,7 @@ pub fn execute_accept_ask( Ok(response) } -pub fn execute_set_offer( +pub fn execute_set_bid( deps: DepsMut, env: Env, info: MessageInfo, @@ -479,7 +493,7 @@ pub fn execute_set_offer( let nonce = NONCE.load(deps.storage)?.wrapping_add(1); NONCE.save(deps.storage, &nonce)?; - let offer = Offer::new( + let bid = Bid::new( info.sender.clone(), collection, token_id, @@ -488,7 +502,7 @@ pub fn execute_set_offer( nonce, ); - let matching_ask = offer.match_with_ask(deps.as_ref())?; + let matching_ask = bid.match_with_ask(deps.as_ref())?; let mut response = Response::new(); @@ -504,7 +518,7 @@ pub fn execute_set_offer( &env, &ask, &config, - &MatchingOffer::Offer(offer), + &MatchingBid::Bid(bid), true, response, )?; @@ -512,18 +526,18 @@ pub fn execute_set_offer( // If no match is found and buy_now is true, abort transaction Err(ContractError::NoMatchFound)?; } else { - // If no match is found. Offer creation should: - // * store the offer + // If no match is found. Bid creation should: + // * store the bid // * emit event funds = funds - .sub(offer.details.price.clone()) + .sub(bid.details.price.clone()) .map_err(|_| ContractError::InsufficientFunds)?; response = response.add_event( - OfferEvent { - ty: "set-offer", - offer: &offer, + BidEvent { + ty: "set-bid", + bid: &bid, attr_keys: vec![ "id", "creator", @@ -537,11 +551,9 @@ pub fn execute_set_offer( .into(), ); - offers().update(deps.storage, offer.id.clone(), |existing| match existing { - Some(_) => Err(ContractError::InternalError( - "offer id collision".to_string(), - )), - None => Ok(offer), + bids().update(deps.storage, bid.id.clone(), |existing| match existing { + Some(_) => Err(ContractError::InternalError("bid id collision".to_string())), + None => Ok(bid), })?; } @@ -553,7 +565,7 @@ pub fn execute_set_offer( Ok(response) } -pub fn execute_update_offer( +pub fn execute_update_bid( deps: DepsMut, env: Env, info: MessageInfo, @@ -566,15 +578,15 @@ pub fn execute_update_offer( ContractError::InvalidInput("invalid denom".to_string()) ); - let mut offer = offers() + let mut bid = bids() .load(deps.storage, id.clone()) - .map_err(|_| ContractError::InvalidInput(format!("offer not found [{}]", id)))?; + .map_err(|_| ContractError::InvalidInput(format!("bid not found [{}]", id)))?; ensure_eq!( info.sender, - offer.creator, + bid.creator, MarketplaceStdError::Unauthorized( - "only the creator of offer can perform this action".to_string() + "only the creator of bid can perform this action".to_string() ) ); @@ -582,13 +594,13 @@ pub fn execute_update_offer( funds.normalize(); // Add the previous price to the funds in context - funds = funds.add(offer.details.price.clone()); + funds = funds.add(bid.details.price.clone()); - offer.details = details; + bid.details = details; let mut response = Response::new(); - let match_result = offer.match_with_ask(deps.as_ref())?; + let match_result = bid.match_with_ask(deps.as_ref())?; if let Some(ask) = match_result { // If a match is found finalize the sale @@ -602,23 +614,30 @@ pub fn execute_update_offer( &env, &ask, &config, - &MatchingOffer::Offer(offer), + &MatchingBid::Bid(bid), true, response, )?; } else { - // If no match is found update the offer + // If no match is found update the bid funds = funds - .sub(offer.details.price.clone()) + .sub(bid.details.price.clone()) .map_err(|_| ContractError::InsufficientFunds)?; - offer.save(deps.storage)?; + bid.save(deps.storage)?; response = response.add_event( - OfferEvent { - ty: "update-offer", - offer: &offer, - attr_keys: vec!["id", "price", "recipient", "finder"], + BidEvent { + ty: "update-bid", + bid: &bid, + attr_keys: vec![ + "id", + "collection", + "token_id", + "price", + "recipient", + "finder", + ], } .into(), ); @@ -632,7 +651,7 @@ pub fn execute_update_offer( Ok(response) } -pub fn execute_remove_offer( +pub fn execute_remove_bid( deps: DepsMut, _env: Env, info: MessageInfo, @@ -640,30 +659,37 @@ pub fn execute_remove_offer( ) -> Result { nonpayable(&info)?; - let offer = offers() + let bid = bids() .load(deps.storage, id.clone()) - .map_err(|_| ContractError::InvalidInput(format!("offer not found [{}]", id)))?; + .map_err(|_| ContractError::InvalidInput(format!("bid not found [{}]", id)))?; ensure_eq!( info.sender, - offer.creator, + bid.creator, MarketplaceStdError::Unauthorized( - "only the creator of offer can perform this action".to_string() + "only the creator of bid can perform this action".to_string() ) ); - let refund = offer.details.price.clone(); + let refund = bid.details.price.clone(); - offer.remove(deps.storage)?; + bid.remove(deps.storage)?; let mut response = transfer_coin(refund, &info.sender, Response::new()); - response = response.add_event(Event::new("remove-offer".to_string()).add_attribute("id", id)); + response = response.add_event( + BidEvent { + ty: "remove-bid", + bid: &bid, + attr_keys: vec!["id", "collection", "token_id"], + } + .into(), + ); Ok(response) } -pub fn execute_accept_offer( +pub fn execute_accept_bid( deps: DepsMut, env: Env, info: MessageInfo, @@ -672,16 +698,16 @@ pub fn execute_accept_offer( recipient: Option, finder: Option, ) -> Result { - let offer: Offer = offers() + let bid: Bid = bids() .load(deps.storage, id.clone()) - .map_err(|_| ContractError::InvalidInput(format!("offer not found [{}]", id)))?; + .map_err(|_| ContractError::InvalidInput(format!("bid not found [{}]", id)))?; ensure!( - has_coins(&[offer.details.price.clone()], &min_output), - ContractError::InvalidInput("min output is greater than offer price".to_string()) + has_coins(&[bid.details.price.clone()], &min_output), + ContractError::InvalidInput("min output is greater than bid price".to_string()) ); - let ask_id = generate_id(vec![offer.collection.as_bytes(), offer.token_id.as_bytes()]); + let ask_id = generate_id(vec![bid.collection.as_bytes(), bid.token_id.as_bytes()]); let ask_option = asks().may_load(deps.storage, ask_id.clone())?; // Check if the sender is the owner of the NFT, or if the creator of a valid ask @@ -693,13 +719,13 @@ pub fn execute_accept_offer( } ask } else { - only_owner(&deps.querier, &info, &offer.collection, &offer.token_id)?; + only_owner(&deps.querier, &info, &bid.collection, &bid.token_id)?; Ask::new( info.sender.clone(), - offer.collection.clone(), - offer.token_id.clone(), + bid.collection.clone(), + bid.token_id.clone(), OrderDetails { - price: offer.details.price.clone(), + price: bid.details.price.clone(), recipient: recipient.clone(), finder: finder.clone(), }, @@ -712,7 +738,7 @@ pub fn execute_accept_offer( &env, &ask, &config, - &MatchingOffer::Offer(offer), + &MatchingBid::Bid(bid), false, Response::new(), )?; @@ -720,7 +746,7 @@ pub fn execute_accept_offer( Ok(response) } -pub fn execute_set_collection_offer( +pub fn execute_set_collection_bid( deps: DepsMut, env: Env, info: MessageInfo, @@ -742,7 +768,7 @@ pub fn execute_set_collection_offer( let nonce = NONCE.load(deps.storage)?.wrapping_add(1); NONCE.save(deps.storage, &nonce)?; - let collection_offer = CollectionOffer::new( + let collection_bid = CollectionBid::new( info.sender.clone(), collection, details, @@ -750,7 +776,7 @@ pub fn execute_set_collection_offer( nonce, ); - let matching_ask = collection_offer.match_with_ask(deps.as_ref())?; + let matching_ask = collection_bid.match_with_ask(deps.as_ref())?; let mut response = Response::new(); @@ -766,7 +792,7 @@ pub fn execute_set_collection_offer( &env, &ask, &config, - &MatchingOffer::CollectionOffer(collection_offer), + &MatchingBid::CollectionBid(collection_bid), true, response, )?; @@ -774,15 +800,15 @@ pub fn execute_set_collection_offer( // If no match is found and buy_now is true, abort transaction Err(ContractError::NoMatchFound)?; } else { - // If no match is found. Offer creation should store the offer + // If no match is found. Bid creation should store the bid funds = funds - .sub(collection_offer.details.price.clone()) + .sub(collection_bid.details.price.clone()) .map_err(|_| ContractError::InsufficientFunds)?; response = response.add_event( - CollectionOfferEvent { - ty: "set-collection-offer", - collection_offer: &collection_offer, + CollectionBidEvent { + ty: "set-collection-bid", + collection_bid: &collection_bid, attr_keys: vec![ "id", "creator", @@ -795,14 +821,16 @@ pub fn execute_set_collection_offer( .into(), ); - collection_offers().update(deps.storage, collection_offer.id.clone(), |existing| { - match existing { + collection_bids().update( + deps.storage, + collection_bid.id.clone(), + |existing| match existing { Some(_) => Err(ContractError::InternalError( - "collection offer id collision".to_string(), + "collection bid id collision".to_string(), )), - None => Ok(collection_offer), - } - })?; + None => Ok(collection_bid), + }, + )?; } // Transfer remaining funds back to user @@ -813,7 +841,7 @@ pub fn execute_set_collection_offer( Ok(response) } -pub fn execute_update_collection_offer( +pub fn execute_update_collection_bid( deps: DepsMut, env: Env, info: MessageInfo, @@ -826,15 +854,15 @@ pub fn execute_update_collection_offer( ContractError::InvalidInput("invalid denom".to_string()) ); - let mut collection_offer = collection_offers() + let mut collection_bid = collection_bids() .load(deps.storage, id.clone()) - .map_err(|_| ContractError::InvalidInput(format!("collection offer not found [{}]", id)))?; + .map_err(|_| ContractError::InvalidInput(format!("collection bid not found [{}]", id)))?; ensure_eq!( info.sender, - collection_offer.creator, + collection_bid.creator, MarketplaceStdError::Unauthorized( - "only the creator of collection offer can perform this action".to_string() + "only the creator of collection bid can perform this action".to_string() ) ); @@ -842,13 +870,13 @@ pub fn execute_update_collection_offer( funds.normalize(); // Add the previous price to the funds in context - funds = funds.add(collection_offer.details.price.clone()); + funds = funds.add(collection_bid.details.price.clone()); - collection_offer.details = details; + collection_bid.details = details; let mut response = Response::new(); - let match_result = collection_offer.match_with_ask(deps.as_ref())?; + let match_result = collection_bid.match_with_ask(deps.as_ref())?; if let Some(ask) = match_result { // If a match is found finalize the sale @@ -862,23 +890,23 @@ pub fn execute_update_collection_offer( &env, &ask, &config, - &MatchingOffer::CollectionOffer(collection_offer), + &MatchingBid::CollectionBid(collection_bid), true, response, )?; } else { - // If no match is found update the offer + // If no match is found update the bid funds = funds - .sub(collection_offer.details.price.clone()) + .sub(collection_bid.details.price.clone()) .map_err(|_| ContractError::InsufficientFunds)?; - collection_offer.save(deps.storage)?; + collection_bid.save(deps.storage)?; response = response.add_event( - CollectionOfferEvent { - ty: "update-collection-offer", - collection_offer: &collection_offer, - attr_keys: vec!["id", "price", "recipient", "finder"], + CollectionBidEvent { + ty: "update-collection-bid", + collection_bid: &collection_bid, + attr_keys: vec!["id", "collection", "price", "recipient", "finder"], } .into(), ); @@ -892,7 +920,7 @@ pub fn execute_update_collection_offer( Ok(response) } -pub fn execute_remove_collection_offer( +pub fn execute_remove_collection_bid( deps: DepsMut, _env: Env, info: MessageInfo, @@ -900,31 +928,37 @@ pub fn execute_remove_collection_offer( ) -> Result { nonpayable(&info)?; - let collection_offer = collection_offers() + let collection_bid = collection_bids() .load(deps.storage, id.clone()) - .map_err(|_| ContractError::InvalidInput(format!("collection offer not found [{}]", id)))?; + .map_err(|_| ContractError::InvalidInput(format!("collection bid not found [{}]", id)))?; ensure_eq!( info.sender, - collection_offer.creator, + collection_bid.creator, MarketplaceStdError::Unauthorized( - "only the creator of collection offer can perform this action".to_string() + "only the creator of collection bid can perform this action".to_string() ) ); - let refund = collection_offer.details.price.clone(); + let refund = collection_bid.details.price.clone(); - collection_offer.remove(deps.storage)?; + collection_bid.remove(deps.storage)?; let mut response = transfer_coin(refund, &info.sender, Response::new()); - response = response - .add_event(Event::new("remove-collection-offer".to_string()).add_attribute("id", id)); + response = response.add_event( + CollectionBidEvent { + ty: "remove-collection-bid", + collection_bid: &collection_bid, + attr_keys: vec!["id", "collection"], + } + .into(), + ); Ok(response) } -pub fn execute_accept_collection_offer( +pub fn execute_accept_collection_bid( deps: DepsMut, env: Env, info: MessageInfo, @@ -934,19 +968,17 @@ pub fn execute_accept_collection_offer( recipient: Option, finder: Option, ) -> Result { - let collection_offer = collection_offers() + let collection_bid = collection_bids() .load(deps.storage, id.clone()) - .map_err(|_| ContractError::InvalidInput(format!("collection offer not found [{}]", id)))?; + .map_err(|_| ContractError::InvalidInput(format!("collection bid not found [{}]", id)))?; ensure!( - has_coins(&[collection_offer.details.price.clone()], &min_output), - ContractError::InvalidInput( - "min output is greater than collection offer price".to_string() - ) + has_coins(&[collection_bid.details.price.clone()], &min_output), + ContractError::InvalidInput("min output is greater than collection bid price".to_string()) ); let ask_id = generate_id(vec![ - collection_offer.collection.as_bytes(), + collection_bid.collection.as_bytes(), token_id.as_bytes(), ]); let ask_option = asks().may_load(deps.storage, ask_id.clone())?; @@ -960,18 +992,13 @@ pub fn execute_accept_collection_offer( } ask } else { - only_owner( - &deps.querier, - &info, - &collection_offer.collection, - &token_id, - )?; + only_owner(&deps.querier, &info, &collection_bid.collection, &token_id)?; Ask::new( info.sender.clone(), - collection_offer.collection.clone(), + collection_bid.collection.clone(), token_id.clone(), OrderDetails { - price: collection_offer.details.price.clone(), + price: collection_bid.details.price.clone(), recipient: recipient.clone(), finder: finder.clone(), }, @@ -984,7 +1011,7 @@ pub fn execute_accept_collection_offer( &env, &ask, &config, - &MatchingOffer::CollectionOffer(collection_offer), + &MatchingBid::CollectionBid(collection_bid), false, Response::new(), )?; diff --git a/contracts/stargaze-marketplace-v2/src/helpers.rs b/contracts/stargaze-marketplace-v2/src/helpers.rs index dfb9b147..3dd30486 100644 --- a/contracts/stargaze-marketplace-v2/src/helpers.rs +++ b/contracts/stargaze-marketplace-v2/src/helpers.rs @@ -1,5 +1,5 @@ use crate::{ - orders::{Ask, MatchingOffer}, + orders::{Ask, MatchingBid}, state::{Config, TokenId}, ContractError, }; @@ -93,30 +93,21 @@ pub fn finalize_sale( env: &Env, ask: &Ask, config: &Config, - matching_offer: &MatchingOffer, - ask_before_offer: bool, + matching_bid: &MatchingBid, + ask_before_bid: bool, response: Response, ) -> Result { - let (nft_recipient, offer_details) = match &matching_offer { - MatchingOffer::Offer(offer) => (offer.asset_recipient(), &offer.details), - MatchingOffer::CollectionOffer(collection_offer) => ( - collection_offer.asset_recipient(), - &collection_offer.details, - ), + let (nft_recipient, bid_details) = match &matching_bid { + MatchingBid::Bid(bid) => (bid.asset_recipient(), &bid.details), + MatchingBid::CollectionBid(collection_bid) => { + (collection_bid.asset_recipient(), &collection_bid.details) + } }; - let (sale_price, maker, taker) = if ask_before_offer { - ( - &ask.details.price, - &ask.details.finder, - &offer_details.finder, - ) + let (sale_price, maker, taker) = if ask_before_bid { + (&ask.details.price, &ask.details.finder, &bid_details.finder) } else { - ( - &offer_details.price, - &offer_details.finder, - &ask.details.finder, - ) + (&bid_details.price, &bid_details.finder, &ask.details.finder) }; let seller_recipient = ask.asset_recipient(); @@ -174,12 +165,12 @@ pub fn finalize_sale( // Remove orders ask.remove(deps.storage)?; - match &matching_offer { - MatchingOffer::Offer(offer) => { - offer.remove(deps.storage)?; + match &matching_bid { + MatchingBid::Bid(bid) => { + bid.remove(deps.storage)?; } - MatchingOffer::CollectionOffer(collection_offer) => { - collection_offer.remove(deps.storage)?; + MatchingBid::CollectionBid(collection_bid) => { + collection_bid.remove(deps.storage)?; } } @@ -192,13 +183,12 @@ pub fn finalize_sale( .add_attribute("nft_recipient", nft_recipient.to_string()) .add_attribute("ask", ask.id.to_string()); - match &matching_offer { - MatchingOffer::Offer(offer) => { - sale_event = sale_event.add_attribute("offer", offer.id.to_string()); + match &matching_bid { + MatchingBid::Bid(bid) => { + sale_event = sale_event.add_attribute("bid", bid.id.to_string()); } - MatchingOffer::CollectionOffer(collection_offer) => { - sale_event = - sale_event.add_attribute("collection_offer", collection_offer.id.to_string()); + MatchingBid::CollectionBid(collection_bid) => { + sale_event = sale_event.add_attribute("collection_bid", collection_bid.id.to_string()); } } diff --git a/contracts/stargaze-marketplace-v2/src/msg.rs b/contracts/stargaze-marketplace-v2/src/msg.rs index 1458e56b..52375082 100644 --- a/contracts/stargaze-marketplace-v2/src/msg.rs +++ b/contracts/stargaze-marketplace-v2/src/msg.rs @@ -1,5 +1,5 @@ use crate::{ - orders::{Ask, CollectionOffer, Offer, OrderDetails}, + orders::{Ask, Bid, CollectionBid, OrderDetails}, state::{AllowDenoms, Config, Denom, OrderId, TokenId}, }; @@ -43,36 +43,36 @@ pub enum ExecuteMsg { recipient: Option, finder: Option, }, - SetOffer { + SetBid { collection: String, token_id: TokenId, details: OrderDetails, }, - RemoveOffer { + RemoveBid { id: OrderId, }, - UpdateOffer { + UpdateBid { id: OrderId, details: OrderDetails, }, - AcceptOffer { + AcceptBid { id: OrderId, min_output: Coin, recipient: Option, finder: Option, }, - SetCollectionOffer { + SetCollectionBid { collection: String, details: OrderDetails, }, - RemoveCollectionOffer { + RemoveCollectionBid { id: OrderId, }, - UpdateCollectionOffer { + UpdateCollectionBid { id: OrderId, details: OrderDetails, }, - AcceptCollectionOffer { + AcceptCollectionBid { id: OrderId, token_id: TokenId, min_output: Coin, @@ -124,35 +124,35 @@ pub enum QueryMsg { collection: String, query_options: Option>, }, - #[returns(Option)] - Offer(String), - #[returns(Vec)] - Offers(Vec), - #[returns(Vec)] - OffersByTokenPrice { + #[returns(Option)] + Bid(String), + #[returns(Vec)] + Bids(Vec), + #[returns(Vec)] + BidsByTokenPrice { collection: String, token_id: TokenId, denom: Denom, query_options: Option>, }, - #[returns(Vec)] - OffersByCreatorCollection { + #[returns(Vec)] + BidsByCreatorCollection { creator: String, collection: String, query_options: Option>, }, - #[returns(Option)] - CollectionOffer(String), - #[returns(Vec)] - CollectionOffers(Vec), - #[returns(Vec)] - CollectionOffersByPrice { + #[returns(Option)] + CollectionBid(String), + #[returns(Vec)] + CollectionBids(Vec), + #[returns(Vec)] + CollectionBidsByPrice { collection: String, denom: Denom, query_options: Option>, }, - #[returns(Vec)] - CollectionOffersByCreatorCollection { + #[returns(Vec)] + CollectionBidsByCreatorCollection { creator: String, collection: String, query_options: Option>, diff --git a/contracts/stargaze-marketplace-v2/src/orders.rs b/contracts/stargaze-marketplace-v2/src/orders.rs index 186f7dc5..f6edd4ae 100644 --- a/contracts/stargaze-marketplace-v2/src/orders.rs +++ b/contracts/stargaze-marketplace-v2/src/orders.rs @@ -2,10 +2,9 @@ use crate::{ helpers::generate_id, msg::PriceOffset, query::{ - query_asks_by_collection_denom, query_collection_offers_by_price, - query_offers_by_token_price, + query_asks_by_collection_denom, query_bids_by_token_price, query_collection_bids_by_price, }, - state::{asks, collection_offers, offers, TokenId}, + state::{asks, bids, collection_bids, TokenId}, ContractError, }; @@ -33,9 +32,9 @@ impl OrderDetails { } } -pub enum MatchingOffer { - Offer(Offer), - CollectionOffer(CollectionOffer), +pub enum MatchingBid { + Bid(Bid), + CollectionBid(CollectionBid), } #[cw_serde] @@ -77,8 +76,8 @@ impl Ask { Ok(()) } - pub fn match_with_offer(&self, deps: Deps) -> Result, ContractError> { - let top_offer = query_offers_by_token_price( + pub fn match_with_bid(&self, deps: Deps) -> Result, ContractError> { + let top_bid = query_bids_by_token_price( deps, self.collection.clone(), self.token_id.clone(), @@ -95,7 +94,7 @@ impl Ask { )? .pop(); - let top_collection_offer = query_collection_offers_by_price( + let top_collection_bid = query_collection_bids_by_price( deps, self.collection.clone(), self.details.price.denom.clone(), @@ -111,18 +110,16 @@ impl Ask { )? .pop(); - let result = match (top_offer, top_collection_offer) { - (Some(offer), Some(collection_offer)) => { - if offer.details.price.amount >= collection_offer.details.price.amount { - Some(MatchingOffer::Offer(offer)) + let result = match (top_bid, top_collection_bid) { + (Some(bid), Some(collection_bid)) => { + if bid.details.price.amount >= collection_bid.details.price.amount { + Some(MatchingBid::Bid(bid)) } else { - Some(MatchingOffer::CollectionOffer(collection_offer)) + Some(MatchingBid::CollectionBid(collection_bid)) } } - (Some(offer), None) => Some(MatchingOffer::Offer(offer)), - (None, Some(collection_offer)) => { - Some(MatchingOffer::CollectionOffer(collection_offer)) - } + (Some(bid), None) => Some(MatchingBid::Bid(bid)), + (None, Some(collection_bid)) => Some(MatchingBid::CollectionBid(collection_bid)), (None, None) => None, }; @@ -161,7 +158,7 @@ impl Ask { } #[cw_serde] -pub struct Offer { +pub struct Bid { pub id: String, pub creator: Addr, pub collection: Addr, @@ -169,7 +166,7 @@ pub struct Offer { pub details: OrderDetails, } -impl Offer { +impl Bid { pub fn new( creator: Addr, collection: Addr, @@ -197,12 +194,12 @@ impl Offer { } pub fn save(&self, storage: &mut dyn Storage) -> Result<(), ContractError> { - offers().save(storage, self.id.clone(), self)?; + bids().save(storage, self.id.clone(), self)?; Ok(()) } pub fn remove(&self, storage: &mut dyn Storage) -> Result<(), ContractError> { - offers().remove(storage, self.id.clone())?; + bids().remove(storage, self.id.clone())?; Ok(()) } @@ -252,14 +249,14 @@ impl Offer { } #[cw_serde] -pub struct CollectionOffer { +pub struct CollectionBid { pub id: String, pub creator: Addr, pub collection: Addr, pub details: OrderDetails, } -impl CollectionOffer { +impl CollectionBid { pub fn new( creator: Addr, collection: Addr, @@ -284,12 +281,12 @@ impl CollectionOffer { } pub fn save(&self, storage: &mut dyn Storage) -> Result<(), ContractError> { - collection_offers().save(storage, self.id.clone(), self)?; + collection_bids().save(storage, self.id.clone(), self)?; Ok(()) } pub fn remove(&self, storage: &mut dyn Storage) -> Result<(), ContractError> { - collection_offers().remove(storage, self.id.clone())?; + collection_bids().remove(storage, self.id.clone())?; Ok(()) } diff --git a/contracts/stargaze-marketplace-v2/src/query.rs b/contracts/stargaze-marketplace-v2/src/query.rs index 1e5266a0..ea3382da 100644 --- a/contracts/stargaze-marketplace-v2/src/query.rs +++ b/contracts/stargaze-marketplace-v2/src/query.rs @@ -1,9 +1,9 @@ use crate::{ helpers::build_collection_token_index_str, msg::{PriceOffset, QueryMsg}, - orders::{Ask, CollectionOffer, Offer}, + orders::{Ask, CollectionBid, Bid}, state::{ - asks, collection_offers, offers, AllowDenoms, Config, Denom, OrderId, ALLOW_DENOMS, CONFIG, + asks, bids, collection_bids, AllowDenoms, Config, Denom, OrderId, ALLOW_DENOMS, CONFIG, }, }; @@ -42,49 +42,49 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { api.addr_validate(&collection)?, query_options.unwrap_or(QueryOptions::default()), )?), - QueryMsg::Offer(id) => to_json_binary(&query_offers(deps, vec![id])?.pop()), - QueryMsg::Offers(ids) => to_json_binary(&query_offers(deps, ids)?), - QueryMsg::OffersByTokenPrice { + QueryMsg::Bid(id) => to_json_binary(&query_bids(deps, vec![id])?.pop()), + QueryMsg::Bids(ids) => to_json_binary(&query_bids(deps, ids)?), + QueryMsg::BidsByTokenPrice { collection, token_id, denom, query_options, - } => to_json_binary(&query_offers_by_token_price( + } => to_json_binary(&query_bids_by_token_price( deps, api.addr_validate(&collection)?, token_id, denom, query_options.unwrap_or(QueryOptions::default()), )?), - QueryMsg::OffersByCreatorCollection { + QueryMsg::BidsByCreatorCollection { creator, collection, query_options, - } => to_json_binary(&query_offers_by_creator_collection( + } => to_json_binary(&query_bids_by_creator_collection( deps, api.addr_validate(&creator)?, api.addr_validate(&collection)?, query_options.unwrap_or(QueryOptions::default()), )?), - QueryMsg::CollectionOffer(id) => { - to_json_binary(&query_collection_offers(deps, vec![id])?.pop()) + QueryMsg::CollectionBid(id) => { + to_json_binary(&query_collection_bids(deps, vec![id])?.pop()) } - QueryMsg::CollectionOffers(ids) => to_json_binary(&query_collection_offers(deps, ids)?), - QueryMsg::CollectionOffersByPrice { + QueryMsg::CollectionBids(ids) => to_json_binary(&query_collection_bids(deps, ids)?), + QueryMsg::CollectionBidsByPrice { collection, denom, query_options, - } => to_json_binary(&query_collection_offers_by_price( + } => to_json_binary(&query_collection_bids_by_price( deps, api.addr_validate(&collection)?, denom, query_options.unwrap_or(QueryOptions::default()), )?), - QueryMsg::CollectionOffersByCreatorCollection { + QueryMsg::CollectionBidsByCreatorCollection { creator, collection, query_options, - } => to_json_binary(&query_collection_offers_by_creator_collection( + } => to_json_binary(&query_collection_bids_by_creator_collection( deps, api.addr_validate(&creator)?, api.addr_validate(&collection)?, @@ -164,26 +164,26 @@ pub fn query_asks_by_creator_collection( Ok(results) } -pub fn query_offers(deps: Deps, ids: Vec) -> StdResult> { +pub fn query_bids(deps: Deps, ids: Vec) -> StdResult> { let mut retval = vec![]; for id in ids { - let offer = offers().may_load(deps.storage, id)?; - if let Some(offer) = offer { - retval.push(offer); + let bid = bids().may_load(deps.storage, id)?; + if let Some(bid) = bid { + retval.push(bid); } } Ok(retval) } -pub fn query_offers_by_token_price( +pub fn query_bids_by_token_price( deps: Deps, collection: Addr, token_id: String, denom: Denom, query_options: QueryOptions, -) -> StdResult> { +) -> StdResult> { let QueryOptionsInternal { limit, order, @@ -191,7 +191,7 @@ pub fn query_offers_by_token_price( max, } = query_options.unpack(&(|offset| (offset.amount, offset.id.clone())), None, None); - let results = offers() + let results = bids() .idx .token_denom_price .sub_prefix(( @@ -200,18 +200,18 @@ pub fn query_offers_by_token_price( )) .range(deps.storage, min, max, order) .take(limit) - .map(|res| res.map(|(_, offer)| offer)) + .map(|res| res.map(|(_, bid)| bid)) .collect::>>()?; Ok(results) } -pub fn query_offers_by_creator_collection( +pub fn query_bids_by_creator_collection( deps: Deps, creator: Addr, collection: Addr, query_options: QueryOptions, -) -> StdResult> { +) -> StdResult> { let QueryOptionsInternal { limit, order, @@ -219,37 +219,37 @@ pub fn query_offers_by_creator_collection( max, } = query_options.unpack(&(|offset| offset.clone()), None, None); - let results = offers() + let results = bids() .idx .creator_collection .prefix((creator, collection)) .range(deps.storage, min, max, order) .take(limit) - .map(|res| res.map(|(_, offer)| offer)) + .map(|res| res.map(|(_, bid)| bid)) .collect::>>()?; Ok(results) } -pub fn query_collection_offers(deps: Deps, ids: Vec) -> StdResult> { +pub fn query_collection_bids(deps: Deps, ids: Vec) -> StdResult> { let mut retval = vec![]; for id in ids { - let collection_offer = collection_offers().may_load(deps.storage, id)?; - if let Some(collection_offer) = collection_offer { - retval.push(collection_offer); + let collection_bid = collection_bids().may_load(deps.storage, id)?; + if let Some(collection_bid) = collection_bid { + retval.push(collection_bid); } } Ok(retval) } -pub fn query_collection_offers_by_price( +pub fn query_collection_bids_by_price( deps: Deps, collection: Addr, denom: Denom, query_options: QueryOptions, -) -> StdResult> { +) -> StdResult> { let QueryOptionsInternal { limit, order, @@ -257,24 +257,24 @@ pub fn query_collection_offers_by_price( max, } = query_options.unpack(&(|offset| (offset.amount, offset.id.clone())), None, None); - let results = collection_offers() + let results = collection_bids() .idx .collection_denom_price .sub_prefix((collection, denom)) .range(deps.storage, min, max, order) .take(limit) - .map(|res| res.map(|(_, collection_offer)| collection_offer)) + .map(|res| res.map(|(_, collection_bid)| collection_bid)) .collect::>>()?; Ok(results) } -pub fn query_collection_offers_by_creator_collection( +pub fn query_collection_bids_by_creator_collection( deps: Deps, creator: Addr, collection: Addr, query_options: QueryOptions, -) -> StdResult> { +) -> StdResult> { let QueryOptionsInternal { limit, order, @@ -282,13 +282,13 @@ pub fn query_collection_offers_by_creator_collection( max, } = query_options.unpack(&(|offset| offset.clone()), None, None); - let results = collection_offers() + let results = collection_bids() .idx .creator_collection .prefix((creator, collection)) .range(deps.storage, min, max, order) .take(limit) - .map(|res| res.map(|(_, collection_offer)| collection_offer)) + .map(|res| res.map(|(_, collection_bid)| collection_bid)) .collect::>>()?; Ok(results) diff --git a/contracts/stargaze-marketplace-v2/src/state.rs b/contracts/stargaze-marketplace-v2/src/state.rs index 7f57795d..373d53ad 100644 --- a/contracts/stargaze-marketplace-v2/src/state.rs +++ b/contracts/stargaze-marketplace-v2/src/state.rs @@ -1,5 +1,5 @@ use crate::helpers::build_collection_token_index_str; -use crate::orders::{CollectionOffer, Offer}; +use crate::orders::{Bid, CollectionBid}; use crate::ContractError; use crate::{constants::MAX_BASIS_POINTS, orders::Ask}; @@ -118,25 +118,25 @@ pub fn asks<'a>() -> IndexedMap<'a, OrderId, Ask, AskIndices<'a>> { IndexedMap::new("a", indexes) } -/// Defines incides for accessing offers -pub struct OfferIndices<'a> { - // Index offers for a token id, sorted by denom price (infinity router dependency) - pub token_denom_price: MultiIndex<'a, (TokenId, Denom, u128), Offer, OrderId>, - // Index offers by creator and collection - pub creator_collection: MultiIndex<'a, (Addr, Addr), Offer, OrderId>, +/// Defines incides for accessing bids +pub struct BidIndices<'a> { + // Index bids for a token id, sorted by denom price (infinity router dependency) + pub token_denom_price: MultiIndex<'a, (TokenId, Denom, u128), Bid, OrderId>, + // Index bids by creator and collection + pub creator_collection: MultiIndex<'a, (Addr, Addr), Bid, OrderId>, } -impl<'a> IndexList for OfferIndices<'a> { - fn get_indexes(&'_ self) -> Box> + '_> { - let v: Vec<&dyn Index> = vec![&self.token_denom_price, &self.creator_collection]; +impl<'a> IndexList for BidIndices<'a> { + fn get_indexes(&'_ self) -> Box> + '_> { + let v: Vec<&dyn Index> = vec![&self.token_denom_price, &self.creator_collection]; Box::new(v.into_iter()) } } -pub fn offers<'a>() -> IndexedMap<'a, OrderId, Offer, OfferIndices<'a>> { - let indexes = OfferIndices { +pub fn bids<'a>() -> IndexedMap<'a, OrderId, Bid, BidIndices<'a>> { + let indexes = BidIndices { token_denom_price: MultiIndex::new( - |_pk: &[u8], o: &Offer| { + |_pk: &[u8], o: &Bid| { ( build_collection_token_index_str(o.collection.as_ref(), &o.token_id), o.details.price.denom.clone(), @@ -147,7 +147,7 @@ pub fn offers<'a>() -> IndexedMap<'a, OrderId, Offer, OfferIndices<'a>> { "o_p", ), creator_collection: MultiIndex::new( - |_pk: &[u8], o: &Offer| (o.creator.clone(), o.collection.clone()), + |_pk: &[u8], o: &Bid| (o.creator.clone(), o.collection.clone()), "o", "o_c", ), @@ -155,27 +155,26 @@ pub fn offers<'a>() -> IndexedMap<'a, OrderId, Offer, OfferIndices<'a>> { IndexedMap::new("o", indexes) } -/// Defines incides for accessing collection offers -pub struct CollectionOfferIndices<'a> { - // Index collection offers by collection and price - pub collection_denom_price: MultiIndex<'a, (Addr, Denom, u128), CollectionOffer, OrderId>, - // Index collection offers by creator - pub creator_collection: MultiIndex<'a, (Addr, Addr), CollectionOffer, OrderId>, +/// Defines incides for accessing collection bids +pub struct CollectionBidIndices<'a> { + // Index collection bids by collection and price + pub collection_denom_price: MultiIndex<'a, (Addr, Denom, u128), CollectionBid, OrderId>, + // Index collection bids by creator + pub creator_collection: MultiIndex<'a, (Addr, Addr), CollectionBid, OrderId>, } -impl<'a> IndexList for CollectionOfferIndices<'a> { - fn get_indexes(&'_ self) -> Box> + '_> { - let v: Vec<&dyn Index> = +impl<'a> IndexList for CollectionBidIndices<'a> { + fn get_indexes(&'_ self) -> Box> + '_> { + let v: Vec<&dyn Index> = vec![&self.collection_denom_price, &self.creator_collection]; Box::new(v.into_iter()) } } -pub fn collection_offers<'a>( -) -> IndexedMap<'a, OrderId, CollectionOffer, CollectionOfferIndices<'a>> { - let indexes = CollectionOfferIndices { +pub fn collection_bids<'a>() -> IndexedMap<'a, OrderId, CollectionBid, CollectionBidIndices<'a>> { + let indexes = CollectionBidIndices { collection_denom_price: MultiIndex::new( - |_pk: &[u8], co: &CollectionOffer| { + |_pk: &[u8], co: &CollectionBid| { ( co.collection.clone(), co.details.price.denom.clone(), @@ -186,7 +185,7 @@ pub fn collection_offers<'a>( "c_p", ), creator_collection: MultiIndex::new( - |_pk: &[u8], co: &CollectionOffer| (co.creator.clone(), co.collection.clone()), + |_pk: &[u8], co: &CollectionBid| (co.creator.clone(), co.collection.clone()), "c", "c_c", ), diff --git a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/offer_queries.rs b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/bid_queries.rs similarity index 56% rename from contracts/stargaze-marketplace-v2/src/tests/unit_tests/offer_queries.rs rename to contracts/stargaze-marketplace-v2/src/tests/unit_tests/bid_queries.rs index f3eee92d..14509e6f 100644 --- a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/offer_queries.rs +++ b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/bid_queries.rs @@ -1,6 +1,6 @@ use crate::{ msg::{ExecuteMsg, PriceOffset, QueryMsg}, - orders::{Offer, OrderDetails}, + orders::{Bid, OrderDetails}, tests::{ helpers::utils::find_attrs, setup::{ @@ -17,7 +17,7 @@ use cw_multi_test::Executor; use sg_index_query::{QueryBound, QueryOptions}; #[test] -fn try_query_offers() { +fn try_query_bids() { let TestContext { mut app, contracts: @@ -29,16 +29,16 @@ fn try_query_offers() { accounts: TestAccounts { bidder, .. }, } = test_context(); - let num_offers: u8 = 4; + let num_bids: u8 = 4; let token_id = "1".to_string(); - let mut offer_ids: Vec = vec![]; - for idx in 1..(num_offers + 1) { - let offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + let mut bid_ids: Vec = vec![]; + for idx in 1..(num_bids + 1) { + let bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -46,30 +46,30 @@ fn try_query_offers() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price], + &set_bid, + &[bid_price], ); assert!(response.is_ok()); - let offer_id = find_attrs(response.unwrap(), "wasm-set-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-bid", "id") .pop() .unwrap(); - offer_ids.push(offer_id); + bid_ids.push(bid_id); } - let offers = app + let bids = app .wrap() - .query_wasm_smart::>(&marketplace, &QueryMsg::Offers(offer_ids.clone())) + .query_wasm_smart::>(&marketplace, &QueryMsg::Bids(bid_ids.clone())) .unwrap(); - assert_eq!(offers.len(), num_offers as usize); + assert_eq!(bids.len(), num_bids as usize); - for (idx, offer) in offers.iter().enumerate() { - assert_eq!(offer.id, offer_ids[idx]); + for (idx, bid) in bids.iter().enumerate() { + assert_eq!(bid.id, bid_ids[idx]); } } #[test] -fn try_query_offers_by_token_price() { +fn try_query_bids_by_token_price() { let TestContext { mut app, contracts: @@ -81,16 +81,16 @@ fn try_query_offers_by_token_price() { accounts: TestAccounts { bidder, .. }, } = test_context(); - let num_offers: u8 = 4; + let num_bids: u8 = 4; let token_id = "1".to_string(); - let mut offer_ids: Vec = vec![]; - for idx in 1..(num_offers + 1) { - let offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + let mut bid_ids: Vec = vec![]; + for idx in 1..(num_bids + 1) { + let bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -98,24 +98,24 @@ fn try_query_offers_by_token_price() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price], + &set_bid, + &[bid_price], ); assert!(response.is_ok()); - let offer_id = find_attrs(response.unwrap(), "wasm-set-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-bid", "id") .pop() .unwrap(); - offer_ids.push(offer_id); + bid_ids.push(bid_id); } - // Other collection returns no offers + // Other collection returns no bids let dummy_collection = Addr::unchecked("dummy_collection"); - let offers = app + let bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByTokenPrice { + &QueryMsg::BidsByTokenPrice { collection: dummy_collection.to_string(), token_id: "1".to_string(), denom: NATIVE_DENOM.to_string(), @@ -123,14 +123,14 @@ fn try_query_offers_by_token_price() { }, ) .unwrap(); - assert_eq!(offers.len(), 0); + assert_eq!(bids.len(), 0); - // Other token id returns no offers - let offers = app + // Other token id returns no bids + let bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByTokenPrice { + &QueryMsg::BidsByTokenPrice { collection: collection.to_string(), token_id: "2".to_string(), denom: NATIVE_DENOM.to_string(), @@ -138,14 +138,14 @@ fn try_query_offers_by_token_price() { }, ) .unwrap(); - assert_eq!(offers.len(), 0); + assert_eq!(bids.len(), 0); - // Other denoms returns no offers - let offers = app + // Other denoms returns no bids + let bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByTokenPrice { + &QueryMsg::BidsByTokenPrice { collection: collection.to_string(), token_id: "1".to_string(), denom: JUNO_DENOM.to_string(), @@ -153,14 +153,14 @@ fn try_query_offers_by_token_price() { }, ) .unwrap(); - assert_eq!(offers.len(), 0); + assert_eq!(bids.len(), 0); - // Correct number of offers returned for correct token_id and denom - let offers = app + // Correct number of bids returned for correct token_id and denom + let bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByTokenPrice { + &QueryMsg::BidsByTokenPrice { collection: collection.to_string(), token_id: "1".to_string(), denom: NATIVE_DENOM.to_string(), @@ -168,14 +168,14 @@ fn try_query_offers_by_token_price() { }, ) .unwrap(); - assert_eq!(offers.len(), num_offers as usize); + assert_eq!(bids.len(), num_bids as usize); // Query Options work - let qo_offers = app + let qo_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByTokenPrice { + &QueryMsg::BidsByTokenPrice { collection: collection.to_string(), token_id: "1".to_string(), denom: NATIVE_DENOM.to_string(), @@ -183,32 +183,32 @@ fn try_query_offers_by_token_price() { descending: Some(true), limit: None, min: Some(QueryBound::Exclusive(PriceOffset { - id: offers[0].id.clone(), - amount: offers[0].details.price.amount.u128(), + id: bids[0].id.clone(), + amount: bids[0].details.price.amount.u128(), })), max: Some(QueryBound::Exclusive(PriceOffset { - id: offers[3].id.clone(), - amount: offers[3].details.price.amount.u128(), + id: bids[3].id.clone(), + amount: bids[3].details.price.amount.u128(), })), }), }, ) .unwrap(); - assert_eq!(qo_offers.len(), 2); + assert_eq!(qo_bids.len(), 2); - for (idx, offer) in qo_offers.iter().enumerate() { - let offer_idx = 2 - idx; - assert_eq!(offer.id, offers[offer_idx].id); + for (idx, bid) in qo_bids.iter().enumerate() { + let bid_idx = 2 - idx; + assert_eq!(bid.id, bids[bid_idx].id); assert_eq!( - offer.details.price.amount.u128(), - offers[offer_idx].details.price.amount.u128() + bid.details.price.amount.u128(), + bids[bid_idx].details.price.amount.u128() ); } } #[test] -fn try_query_offers_by_creator() { +fn try_query_bids_by_creator() { let TestContext { mut app, contracts: @@ -220,16 +220,16 @@ fn try_query_offers_by_creator() { accounts: TestAccounts { owner, bidder, .. }, } = test_context(); - let num_offers: u8 = 4; + let num_bids: u8 = 4; let token_id = "1".to_string(); - let mut offer_ids: Vec = vec![]; - for idx in 1..(num_offers + 1) { - let offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + let mut bid_ids: Vec = vec![]; + for idx in 1..(num_bids + 1) { + let bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -237,71 +237,71 @@ fn try_query_offers_by_creator() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price], + &set_bid, + &[bid_price], ); assert!(response.is_ok()); - let offer_id = find_attrs(response.unwrap(), "wasm-set-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-bid", "id") .pop() .unwrap(); - offer_ids.push(offer_id); + bid_ids.push(bid_id); } - // Other creator address returns no offers - let offers = app + // Other creator address returns no bids + let bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByCreatorCollection { + &QueryMsg::BidsByCreatorCollection { creator: owner.to_string(), collection: collection.to_string(), query_options: None, }, ) .unwrap(); - assert_eq!(offers.len(), 0); + assert_eq!(bids.len(), 0); - // Correct number of offers returned for correct creator - let offers = app + // Correct number of bids returned for correct creator + let bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByCreatorCollection { + &QueryMsg::BidsByCreatorCollection { creator: bidder.to_string(), collection: collection.to_string(), query_options: None, }, ) .unwrap(); - assert_eq!(offers.len(), num_offers as usize); + assert_eq!(bids.len(), num_bids as usize); // Query Options work - let qo_offers = app + let qo_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::OffersByCreatorCollection { + &QueryMsg::BidsByCreatorCollection { creator: bidder.to_string(), collection: collection.to_string(), query_options: Some(QueryOptions { descending: Some(true), limit: Some(2), - min: Some(QueryBound::Exclusive(offers[0].id.clone())), - max: Some(QueryBound::Exclusive(offers[3].id.clone())), + min: Some(QueryBound::Exclusive(bids[0].id.clone())), + max: Some(QueryBound::Exclusive(bids[3].id.clone())), }), }, ) .unwrap(); - assert_eq!(qo_offers.len(), 2); + assert_eq!(qo_bids.len(), 2); - for (idx, offer) in qo_offers.iter().enumerate() { - let offer_idx = 2 - idx; - assert_eq!(offer.id, offers[offer_idx].id); + for (idx, bid) in qo_bids.iter().enumerate() { + let bid_idx = 2 - idx; + assert_eq!(bid.id, bids[bid_idx].id); assert_eq!( - offer.details.price.amount.u128(), - offers[offer_idx].details.price.amount.u128() + bid.details.price.amount.u128(), + bids[bid_idx].details.price.amount.u128() ); } } diff --git a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/offers.rs b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/bids.rs similarity index 66% rename from contracts/stargaze-marketplace-v2/src/tests/unit_tests/offers.rs rename to contracts/stargaze-marketplace-v2/src/tests/unit_tests/bids.rs index 1f8ba7e7..314d09b5 100644 --- a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/offers.rs +++ b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/bids.rs @@ -1,6 +1,6 @@ use crate::{ msg::{ExecuteMsg, QueryMsg}, - orders::{Offer, OrderDetails}, + orders::{Bid, OrderDetails}, tests::{ helpers::utils::{assert_error, find_attrs}, setup::{ @@ -20,7 +20,7 @@ use sg_marketplace_common::MarketplaceStdError; use std::ops::{Add, Sub}; #[test] -fn try_set_offer() { +fn try_set_bid() { let TestContext { mut app, contracts: @@ -34,13 +34,13 @@ fn try_set_offer() { let token_id = "1"; - // Create offer without sufficient offer funds fails - let offer_price = coin(1_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + // Create bid without sufficient bid funds fails + let bid_price = coin(1_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -48,18 +48,18 @@ fn try_set_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[coin(offer_price.amount.u128() - 1u128, NATIVE_DENOM)], + &set_bid, + &[coin(bid_price.amount.u128() - 1u128, NATIVE_DENOM)], ); assert_error(response, ContractError::InsufficientFunds.to_string()); - // Create offer with invalid denom fails - let offer_price = coin(1_000_000, JUNO_DENOM); - let set_offer = ExecuteMsg::SetOffer { + // Create bid with invalid denom fails + let bid_price = coin(1_000_000, JUNO_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -67,23 +67,23 @@ fn try_set_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[coin(offer_price.amount.u128() - 1u128, JUNO_DENOM)], + &set_bid, + &[coin(bid_price.amount.u128() - 1u128, JUNO_DENOM)], ); assert_error( response, ContractError::InvalidInput("invalid denom".to_string()).to_string(), ); - // Create offer succeeds, even when overpaid + // Create bid succeeds, even when overpaid let recipient = Addr::unchecked("recipient".to_string()); let finder = Addr::unchecked("finder".to_string()); - let offer_price = coin(1_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + let bid_price = coin(1_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: Some(recipient.to_string()), finder: Some(finder.to_string()), }, @@ -93,8 +93,8 @@ fn try_set_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[coin(offer_price.amount.u128() * 2u128, NATIVE_DENOM)], + &set_bid, + &[coin(bid_price.amount.u128() * 2u128, NATIVE_DENOM)], ); assert!(response.is_ok()); @@ -102,32 +102,32 @@ fn try_set_offer() { NativeBalance(app.wrap().query_all_balances(bidder.clone()).unwrap()); assert_eq!( bidder_native_balances_before - .sub(offer_price.clone()) + .sub(bid_price.clone()) .unwrap(), bidder_native_balances_after ); - let offer_id = find_attrs(response.unwrap(), "wasm-set-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-bid", "id") .pop() .unwrap(); - let offer = app + let bid = app .wrap() - .query_wasm_smart::>(&marketplace, &QueryMsg::Offer(offer_id.clone())) + .query_wasm_smart::>(&marketplace, &QueryMsg::Bid(bid_id.clone())) .unwrap() .unwrap(); - assert_eq!(offer.id, offer_id); - assert_eq!(offer.creator, bidder); - assert_eq!(offer.collection, collection); - assert_eq!(offer.token_id, token_id); - assert_eq!(offer.details.price, offer_price); - assert_eq!(offer.details.recipient, Some(recipient)); - assert_eq!(offer.details.finder, Some(finder)); + assert_eq!(bid.id, bid_id); + assert_eq!(bid.creator, bidder); + assert_eq!(bid.collection, collection); + assert_eq!(bid.token_id, token_id); + assert_eq!(bid.details.price, bid_price); + assert_eq!(bid.details.recipient, Some(recipient)); + assert_eq!(bid.details.finder, Some(finder)); } #[test] -pub fn try_update_offer() { +pub fn try_update_bid() { let TestContext { mut app, contracts: @@ -142,16 +142,16 @@ pub fn try_update_offer() { let recipient = setup_additional_account(&mut app, "recipient").unwrap(); let finder = setup_additional_account(&mut app, "finder").unwrap(); - let num_offers: u8 = 4; + let num_bids: u8 = 4; let token_id = "1".to_string(); - let mut offer_ids: Vec = vec![]; - for idx in 1..(num_offers + 1) { - let offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + let mut bid_ids: Vec = vec![]; + for idx in 1..(num_bids + 1) { + let bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -159,39 +159,39 @@ pub fn try_update_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price], + &set_bid, + &[bid_price], ); assert!(response.is_ok()); - let offer_id = find_attrs(response.unwrap(), "wasm-set-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-bid", "id") .pop() .unwrap(); - offer_ids.push(offer_id); + bid_ids.push(bid_id); } - // Non creator updating offer fails - let update_offer = ExecuteMsg::UpdateOffer { - id: offer_ids[0].clone(), + // Non creator updating bid fails + let update_bid = ExecuteMsg::UpdateBid { + id: bid_ids[0].clone(), details: OrderDetails { price: coin(1000000u128, NATIVE_DENOM), recipient: Some(recipient.to_string()), finder: Some(finder.to_string()), }, }; - let response = app.execute_contract(owner.clone(), marketplace.clone(), &update_offer, &[]); + let response = app.execute_contract(owner.clone(), marketplace.clone(), &update_bid, &[]); assert_error( response, MarketplaceStdError::Unauthorized( - "only the creator of offer can perform this action".to_string(), + "only the creator of bid can perform this action".to_string(), ) .to_string(), ); - // Updating offer succeeds, wallet is refunded + // Updating bid succeeds, wallet is refunded let new_price = coin(1000000u128, NATIVE_DENOM); - let update_offer = ExecuteMsg::UpdateOffer { - id: offer_ids[0].clone(), + let update_bid = ExecuteMsg::UpdateBid { + id: bid_ids[0].clone(), details: OrderDetails { price: new_price.clone(), recipient: None, @@ -204,7 +204,7 @@ pub fn try_update_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &update_offer, + &update_bid, &[new_price], ); assert!(response.is_ok()); @@ -218,7 +218,7 @@ pub fn try_update_offer() { } #[test] -pub fn try_remove_offer() { +pub fn try_remove_bid() { let TestContext { mut app, contracts: @@ -237,7 +237,7 @@ pub fn try_remove_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &ExecuteMsg::SetOffer { + &ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { @@ -249,30 +249,30 @@ pub fn try_remove_offer() { &[price], ); - let offer_id = find_attrs(response.unwrap(), "wasm-set-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-bid", "id") .pop() .unwrap(); - // Removing offer as non creator fails - let remove_offer = ExecuteMsg::RemoveOffer { - id: offer_id.clone(), + // Removing bid as non creator fails + let remove_bid = ExecuteMsg::RemoveBid { + id: bid_id.clone(), }; - let response = app.execute_contract(bidder2.clone(), marketplace.clone(), &remove_offer, &[]); + let response = app.execute_contract(bidder2.clone(), marketplace.clone(), &remove_bid, &[]); assert_error( response, MarketplaceStdError::Unauthorized( - "only the creator of offer can perform this action".to_string(), + "only the creator of bid can perform this action".to_string(), ) .to_string(), ); - // Removing offer as creator succeeds - let response = app.execute_contract(bidder.clone(), marketplace.clone(), &remove_offer, &[]); + // Removing bid as creator succeeds + let response = app.execute_contract(bidder.clone(), marketplace.clone(), &remove_bid, &[]); assert!(response.is_ok()); - let offer = app + let bid = app .wrap() - .query_wasm_smart::>(&marketplace, &QueryMsg::Offer(offer_id)) + .query_wasm_smart::>(&marketplace, &QueryMsg::Bid(bid_id)) .unwrap(); - assert!(offer.is_none()); + assert!(bid.is_none()); } diff --git a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_offer_queries.rs b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_bid_queries.rs similarity index 53% rename from contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_offer_queries.rs rename to contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_bid_queries.rs index f66f4563..d3aef38b 100644 --- a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_offer_queries.rs +++ b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_bid_queries.rs @@ -1,6 +1,6 @@ use crate::{ msg::{ExecuteMsg, PriceOffset, QueryMsg}, - orders::{CollectionOffer, OrderDetails}, + orders::{CollectionBid, OrderDetails}, tests::{ helpers::utils::find_attrs, setup::{ @@ -17,7 +17,7 @@ use cw_multi_test::Executor; use sg_index_query::{QueryBound, QueryOptions}; #[test] -fn try_query_collection_offers_by_collection() { +fn try_query_collection_bids_by_collection() { let TestContext { mut app, contracts: @@ -29,17 +29,17 @@ fn try_query_collection_offers_by_collection() { accounts: TestAccounts { .. }, } = test_context(); - let num_collection_offers: u8 = 4; - let mut collection_offer_ids: Vec = vec![]; - for idx in 1..(num_collection_offers + 1) { + let num_collection_bids: u8 = 4; + let mut collection_bid_ids: Vec = vec![]; + for idx in 1..(num_collection_bids + 1) { let collection_bidder = setup_additional_account(&mut app, &format!("collection-bidder-{}", idx)).unwrap(); - let collection_offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_collection_offer = ExecuteMsg::SetCollectionOffer { + let collection_bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_collection_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: collection_offer_price.clone(), + price: collection_bid_price.clone(), recipient: None, finder: None, }, @@ -47,32 +47,32 @@ fn try_query_collection_offers_by_collection() { let response = app.execute_contract( collection_bidder.clone(), marketplace.clone(), - &set_collection_offer, - &[collection_offer_price.clone()], + &set_collection_bid, + &[collection_bid_price.clone()], ); assert!(response.is_ok()); - let offer_id = find_attrs(response.unwrap(), "wasm-set-collection-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-collection-bid", "id") .pop() .unwrap(); - collection_offer_ids.push(offer_id); + collection_bid_ids.push(bid_id); } - let collection_offers = app + let collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffers(collection_offer_ids.clone()), + &QueryMsg::CollectionBids(collection_bid_ids.clone()), ) .unwrap(); - assert_eq!(collection_offers.len(), num_collection_offers as usize); + assert_eq!(collection_bids.len(), num_collection_bids as usize); - for (idx, offer) in collection_offers.iter().enumerate() { - assert_eq!(offer.id, collection_offer_ids[idx]); + for (idx, bid) in collection_bids.iter().enumerate() { + assert_eq!(bid.id, collection_bid_ids[idx]); } } #[test] -fn try_query_collection_offers_by_token_price() { +fn try_query_collection_bids_by_token_price() { let TestContext { mut app, contracts: @@ -84,15 +84,15 @@ fn try_query_collection_offers_by_token_price() { accounts: TestAccounts { .. }, } = test_context(); - let num_collection_offers: u8 = 4; - for idx in 1..(num_collection_offers + 1) { + let num_collection_bids: u8 = 4; + for idx in 1..(num_collection_bids + 1) { let collection_bidder = setup_additional_account(&mut app, &format!("collection-bidder-{}", idx)).unwrap(); - let collection_offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_collection_offer = ExecuteMsg::SetCollectionOffer { + let collection_bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_collection_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: collection_offer_price.clone(), + price: collection_bid_price.clone(), recipient: None, finder: None, }, @@ -100,93 +100,93 @@ fn try_query_collection_offers_by_token_price() { let response = app.execute_contract( collection_bidder.clone(), marketplace.clone(), - &set_collection_offer, - &[collection_offer_price.clone()], + &set_collection_bid, + &[collection_bid_price.clone()], ); assert!(response.is_ok()); } - // Other collection address returns no collection offers + // Other collection address returns no collection bids let dummy_collection = Addr::unchecked("dummy_collection"); - let collection_offers = app + let collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffersByPrice { + &QueryMsg::CollectionBidsByPrice { collection: dummy_collection.to_string(), denom: NATIVE_DENOM.to_string(), query_options: None, }, ) .unwrap(); - assert_eq!(collection_offers.len(), 0); + assert_eq!(collection_bids.len(), 0); - // Other denoms returns no collection offers - let collection_offers = app + // Other denoms returns no collection bids + let collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffersByPrice { + &QueryMsg::CollectionBidsByPrice { collection: collection.to_string(), denom: ATOM_DENOM.to_string(), query_options: None, }, ) .unwrap(); - assert_eq!(collection_offers.len(), 0); + assert_eq!(collection_bids.len(), 0); - // Correct number of collection offers returned for correct collection and denom - let collection_offers = app + // Correct number of collection bids returned for correct collection and denom + let collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffersByPrice { + &QueryMsg::CollectionBidsByPrice { collection: collection.to_string(), denom: NATIVE_DENOM.to_string(), query_options: None, }, ) .unwrap(); - assert_eq!(collection_offers.len(), num_collection_offers as usize); + assert_eq!(collection_bids.len(), num_collection_bids as usize); // Query Options work - let qo_collection_offers = app + let qo_collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffersByPrice { + &QueryMsg::CollectionBidsByPrice { collection: collection.to_string(), denom: NATIVE_DENOM.to_string(), query_options: Some(QueryOptions { descending: Some(true), limit: None, min: Some(QueryBound::Exclusive(PriceOffset { - id: collection_offers[0].id.clone(), - amount: collection_offers[0].details.price.amount.u128(), + id: collection_bids[0].id.clone(), + amount: collection_bids[0].details.price.amount.u128(), })), max: Some(QueryBound::Exclusive(PriceOffset { - id: collection_offers[3].id.clone(), - amount: collection_offers[3].details.price.amount.u128(), + id: collection_bids[3].id.clone(), + amount: collection_bids[3].details.price.amount.u128(), })), }), }, ) .unwrap(); - assert_eq!(qo_collection_offers.len(), 2); + assert_eq!(qo_collection_bids.len(), 2); - for (idx, offer) in qo_collection_offers.iter().enumerate() { - let offer_idx = 2 - idx; - assert_eq!(offer.id, collection_offers[offer_idx].id); + for (idx, bid) in qo_collection_bids.iter().enumerate() { + let bid_idx = 2 - idx; + assert_eq!(bid.id, collection_bids[bid_idx].id); assert_eq!( - offer.details.price.amount.u128(), - collection_offers[offer_idx].details.price.amount.u128() + bid.details.price.amount.u128(), + collection_bids[bid_idx].details.price.amount.u128() ); } } #[test] -fn try_query_collection_offers_by_creator() { +fn try_query_collection_bids_by_creator() { let TestContext { mut app, contracts: @@ -198,13 +198,13 @@ fn try_query_collection_offers_by_creator() { accounts: TestAccounts { bidder, .. }, } = test_context(); - let num_collection_offers: u8 = 4; - for idx in 1..(num_collection_offers + 1) { - let collection_offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_collection_offer = ExecuteMsg::SetCollectionOffer { + let num_collection_bids: u8 = 4; + for idx in 1..(num_collection_bids + 1) { + let collection_bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_collection_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: collection_offer_price.clone(), + price: collection_bid_price.clone(), recipient: None, finder: None, }, @@ -212,62 +212,62 @@ fn try_query_collection_offers_by_creator() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_collection_offer, - &[collection_offer_price.clone()], + &set_collection_bid, + &[collection_bid_price.clone()], ); assert!(response.is_ok()); } - // Other creator address returns no collection_offers + // Other creator address returns no collection_bids let dummy_creator = Addr::unchecked("dummy_creator"); - let collection_offers = app + let collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffersByCreatorCollection { + &QueryMsg::CollectionBidsByCreatorCollection { creator: dummy_creator.to_string(), collection: collection.to_string(), query_options: None, }, ) .unwrap(); - assert_eq!(collection_offers.len(), 0); + assert_eq!(collection_bids.len(), 0); // Correct number of asks returned for correct creator - let collection_offers = app + let collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffersByCreatorCollection { + &QueryMsg::CollectionBidsByCreatorCollection { creator: bidder.to_string(), collection: collection.to_string(), query_options: None, }, ) .unwrap(); - assert_eq!(collection_offers.len(), num_collection_offers as usize); + assert_eq!(collection_bids.len(), num_collection_bids as usize); // Query Options work - let qo_collection_offers = app + let qo_collection_bids = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffersByCreatorCollection { + &QueryMsg::CollectionBidsByCreatorCollection { creator: bidder.to_string(), collection: collection.to_string(), query_options: Some(QueryOptions { descending: Some(true), limit: Some(2), - min: Some(QueryBound::Exclusive(collection_offers[0].id.clone())), - max: Some(QueryBound::Exclusive(collection_offers[3].id.clone())), + min: Some(QueryBound::Exclusive(collection_bids[0].id.clone())), + max: Some(QueryBound::Exclusive(collection_bids[3].id.clone())), }), }, ) .unwrap(); - assert_eq!(qo_collection_offers.len(), 2); + assert_eq!(qo_collection_bids.len(), 2); assert_eq!( - qo_collection_offers[0].creator, + qo_collection_bids[0].creator, Addr::unchecked(bidder.to_string()) ); - assert_eq!(qo_collection_offers[0].collection, collection); + assert_eq!(qo_collection_bids[0].collection, collection); } diff --git a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_offers.rs b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_bids.rs similarity index 61% rename from contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_offers.rs rename to contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_bids.rs index 7e0a72cb..1c02e2f6 100644 --- a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_offers.rs +++ b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/collection_bids.rs @@ -1,6 +1,6 @@ use crate::{ msg::{ExecuteMsg, QueryMsg}, - orders::{CollectionOffer, OrderDetails}, + orders::{CollectionBid, OrderDetails}, tests::{ helpers::utils::{assert_error, find_attrs}, setup::{ @@ -20,7 +20,7 @@ use sg_marketplace_common::MarketplaceStdError; use std::ops::{Add, Sub}; #[test] -fn try_set_collection_offer() { +fn try_set_collection_bid() { let TestContext { mut app, contracts: @@ -32,12 +32,12 @@ fn try_set_collection_offer() { accounts: TestAccounts { bidder, .. }, } = test_context(); - // Create offer without sufficient offer funds fails - let collection_offer_price = coin(1_000_000, NATIVE_DENOM); - let set_collection_offer = ExecuteMsg::SetCollectionOffer { + // Create bid without sufficient bid funds fails + let collection_bid_price = coin(1_000_000, NATIVE_DENOM); + let set_collection_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: collection_offer_price.clone(), + price: collection_bid_price.clone(), recipient: None, finder: None, }, @@ -45,20 +45,20 @@ fn try_set_collection_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_collection_offer, + &set_collection_bid, &[coin( - collection_offer_price.amount.u128() - 1u128, + collection_bid_price.amount.u128() - 1u128, NATIVE_DENOM, )], ); assert_error(response, ContractError::InsufficientFunds.to_string()); - // Create collection_offer with invalid denom fails - let collection_offer_price = coin(1_000_000, JUNO_DENOM); - let set_collection_offer = ExecuteMsg::SetCollectionOffer { + // Create collection_bid with invalid denom fails + let collection_bid_price = coin(1_000_000, JUNO_DENOM); + let set_collection_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: collection_offer_price.clone(), + price: collection_bid_price.clone(), recipient: None, finder: None, }, @@ -66,9 +66,9 @@ fn try_set_collection_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_collection_offer, + &set_collection_bid, &[coin( - collection_offer_price.amount.u128() - 1u128, + collection_bid_price.amount.u128() - 1u128, JUNO_DENOM, )], ); @@ -77,14 +77,14 @@ fn try_set_collection_offer() { ContractError::InvalidInput("invalid denom".to_string()).to_string(), ); - // Create collection_offer succeeds, even when overpaid + // Create collection_bid succeeds, even when overpaid let recipient = Addr::unchecked("recipient".to_string()); let finder = Addr::unchecked("finder".to_string()); - let collection_offer_price = coin(1_000_000, NATIVE_DENOM); - let set_collection_offer = ExecuteMsg::SetCollectionOffer { + let collection_bid_price = coin(1_000_000, NATIVE_DENOM); + let set_collection_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: collection_offer_price.clone(), + price: collection_bid_price.clone(), recipient: Some(recipient.to_string()), finder: Some(finder.to_string()), }, @@ -94,9 +94,9 @@ fn try_set_collection_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_collection_offer, + &set_collection_bid, &[coin( - collection_offer_price.amount.u128() * 2u128, + collection_bid_price.amount.u128() * 2u128, NATIVE_DENOM, )], ); @@ -106,34 +106,34 @@ fn try_set_collection_offer() { NativeBalance(app.wrap().query_all_balances(bidder.clone()).unwrap()); assert_eq!( bidder_native_balances_before - .sub(collection_offer_price.clone()) + .sub(collection_bid_price.clone()) .unwrap(), bidder_native_balances_after ); - let collection_offer_id = find_attrs(response.unwrap(), "wasm-set-collection-offer", "id") + let collection_bid_id = find_attrs(response.unwrap(), "wasm-set-collection-bid", "id") .pop() .unwrap(); - let collection_offer = app + let collection_bid = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffer(collection_offer_id.clone()), + &QueryMsg::CollectionBid(collection_bid_id.clone()), ) .unwrap() .unwrap(); - assert_eq!(collection_offer.id, collection_offer_id); - assert_eq!(collection_offer.creator, bidder); - assert_eq!(collection_offer.collection, collection); - assert_eq!(collection_offer.details.price, collection_offer_price); - assert_eq!(collection_offer.details.recipient, Some(recipient)); - assert_eq!(collection_offer.details.finder, Some(finder)); + assert_eq!(collection_bid.id, collection_bid_id); + assert_eq!(collection_bid.creator, bidder); + assert_eq!(collection_bid.collection, collection); + assert_eq!(collection_bid.details.price, collection_bid_price); + assert_eq!(collection_bid.details.recipient, Some(recipient)); + assert_eq!(collection_bid.details.finder, Some(finder)); } #[test] -pub fn try_update_collection_offer() { +pub fn try_update_collection_bid() { let TestContext { mut app, contracts: @@ -148,14 +148,14 @@ pub fn try_update_collection_offer() { let recipient = setup_additional_account(&mut app, "recipient").unwrap(); let finder = setup_additional_account(&mut app, "finder").unwrap(); - let num_collection_offers: u8 = 4; - let mut collection_offer_ids: Vec = vec![]; - for idx in 1..(num_collection_offers + 1) { - let collection_offer_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); - let set_collection_offer = ExecuteMsg::SetCollectionOffer { + let num_collection_bids: u8 = 4; + let mut collection_bid_ids: Vec = vec![]; + for idx in 1..(num_collection_bids + 1) { + let collection_bid_price = coin(1000000u128 + idx as u128, NATIVE_DENOM); + let set_collection_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: collection_offer_price.clone(), + price: collection_bid_price.clone(), recipient: None, finder: None, }, @@ -163,20 +163,20 @@ pub fn try_update_collection_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_collection_offer, - &[collection_offer_price], + &set_collection_bid, + &[collection_bid_price], ); assert!(response.is_ok()); - let collection_offer_id = find_attrs(response.unwrap(), "wasm-set-collection-offer", "id") + let collection_bid_id = find_attrs(response.unwrap(), "wasm-set-collection-bid", "id") .pop() .unwrap(); - collection_offer_ids.push(collection_offer_id); + collection_bid_ids.push(collection_bid_id); } - // Non creator updating collection_offer fails - let update_collection_offer = ExecuteMsg::UpdateCollectionOffer { - id: collection_offer_ids[0].clone(), + // Non creator updating collection_bid fails + let update_collection_bid = ExecuteMsg::UpdateCollectionBid { + id: collection_bid_ids[0].clone(), details: OrderDetails { price: coin(1000000u128, NATIVE_DENOM), recipient: Some(recipient.to_string()), @@ -186,21 +186,21 @@ pub fn try_update_collection_offer() { let response = app.execute_contract( owner.clone(), marketplace.clone(), - &update_collection_offer, + &update_collection_bid, &[], ); assert_error( response, MarketplaceStdError::Unauthorized( - "only the creator of collection offer can perform this action".to_string(), + "only the creator of collection bid can perform this action".to_string(), ) .to_string(), ); - // Updating collection_offer succeeds, wallet is refunded + // Updating collection_bid succeeds, wallet is refunded let new_price = coin(1000000u128, NATIVE_DENOM); - let update_collection_offer = ExecuteMsg::UpdateCollectionOffer { - id: collection_offer_ids[0].clone(), + let update_collection_bid = ExecuteMsg::UpdateCollectionBid { + id: collection_bid_ids[0].clone(), details: OrderDetails { price: new_price.clone(), recipient: None, @@ -213,7 +213,7 @@ pub fn try_update_collection_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &update_collection_offer, + &update_collection_bid, &[new_price], ); assert!(response.is_ok()); @@ -227,7 +227,7 @@ pub fn try_update_collection_offer() { } #[test] -pub fn try_remove_offer() { +pub fn try_remove_bid() { let TestContext { mut app, contracts: @@ -243,7 +243,7 @@ pub fn try_remove_offer() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &ExecuteMsg::SetCollectionOffer { + &ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { price: price.clone(), @@ -254,43 +254,43 @@ pub fn try_remove_offer() { &[price], ); - let collection_offer_id = find_attrs(response.unwrap(), "wasm-set-collection-offer", "id") + let collection_bid_id = find_attrs(response.unwrap(), "wasm-set-collection-bid", "id") .pop() .unwrap(); - // Removing collection_offer as non creator fails - let remove_collection_offer = ExecuteMsg::RemoveCollectionOffer { - id: collection_offer_id.clone(), + // Removing collection_bid as non creator fails + let remove_collection_bid = ExecuteMsg::RemoveCollectionBid { + id: collection_bid_id.clone(), }; let response = app.execute_contract( owner.clone(), marketplace.clone(), - &remove_collection_offer, + &remove_collection_bid, &[], ); assert_error( response, MarketplaceStdError::Unauthorized( - "only the creator of collection offer can perform this action".to_string(), + "only the creator of collection bid can perform this action".to_string(), ) .to_string(), ); - // Removing collection_offer as creator succeeds + // Removing collection_bid as creator succeeds let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &remove_collection_offer, + &remove_collection_bid, &[], ); assert!(response.is_ok()); - let collection_offer = app + let collection_bid = app .wrap() - .query_wasm_smart::>( + .query_wasm_smart::>( &marketplace, - &QueryMsg::CollectionOffer(collection_offer_id), + &QueryMsg::CollectionBid(collection_bid_id), ) .unwrap(); - assert!(collection_offer.is_none()); + assert!(collection_bid.is_none()); } diff --git a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/mod.rs b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/mod.rs index bbb4d2de..5ec08996 100644 --- a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/mod.rs +++ b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/mod.rs @@ -5,12 +5,12 @@ mod ask_queries; #[cfg(test)] mod asks; #[cfg(test)] -mod collection_offer_queries; +mod bid_queries; #[cfg(test)] -mod collection_offers; +mod bids; #[cfg(test)] -mod offer_queries; +mod collection_bid_queries; #[cfg(test)] -mod offers; +mod collection_bids; #[cfg(test)] mod sales; diff --git a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/sales.rs b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/sales.rs index 2d68ea16..8ca4ef11 100644 --- a/contracts/stargaze-marketplace-v2/src/tests/unit_tests/sales.rs +++ b/contracts/stargaze-marketplace-v2/src/tests/unit_tests/sales.rs @@ -53,29 +53,29 @@ fn try_set_ask_sale() { let token_id = "1"; - // Create ask with matching offer produces a valid sale + // Create ask with matching bid produces a valid sale - // * Offer 1 - 10_000_000 native denom (should not match) - let offer_price_1 = coin(10_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + // * Bid 1 - 10_000_000 native denom (should not match) + let bid_price_1 = coin(10_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price_1.clone(), + price: bid_price_1.clone(), recipient: None, finder: None, }, }; - let response = app.execute_contract(bidder, marketplace.clone(), &set_offer, &[offer_price_1]); + let response = app.execute_contract(bidder, marketplace.clone(), &set_bid, &[bid_price_1]); assert!(response.is_ok()); - // * Offer 2 - 15_000_000 native denom (should_match) - let offer_price_2 = coin(15_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + // * Bid 2 - 15_000_000 native denom (should_match) + let bid_price_2 = coin(15_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price_2.clone(), + price: bid_price_2.clone(), recipient: None, finder: None, }, @@ -83,8 +83,8 @@ fn try_set_ask_sale() { let response = app.execute_contract( bidder2.clone(), marketplace.clone(), - &set_offer, - &[offer_price_2.clone()], + &set_bid, + &[bid_price_2.clone()], ); assert!(response.is_ok()); @@ -106,7 +106,7 @@ fn try_set_ask_sale() { let owner_balances_after = NativeBalance(app.wrap().query_all_balances(owner.clone()).unwrap()); let bidder2_balances_after = NativeBalance(app.wrap().query_all_balances(bidder2).unwrap()); - let sale_coin = offer_price_2; + let sale_coin = bid_price_2; let fair_burn_amount = sale_coin .amount .mul_ceil(Decimal::bps(config.protocol_fee_bps)); @@ -151,7 +151,7 @@ fn try_accept_ask_sale() { let bidder_balances_before = NativeBalance(app.wrap().query_all_balances(bidder.clone()).unwrap()); - // Create ask with no matching offer + // Create ask with no matching bid let token_id = "1"; mint(&mut app, &creator, &owner, &collection, token_id); approve(&mut app, &owner, &collection, &marketplace, token_id); @@ -207,7 +207,7 @@ fn try_accept_ask_sale() { } #[test] -fn try_set_offer_sale() { +fn try_set_bid_sale() { let TestContext { mut app, contracts: @@ -235,7 +235,7 @@ fn try_set_offer_sale() { let bidder_balances_before = NativeBalance(app.wrap().query_all_balances(bidder.clone()).unwrap()); - // Create ask with no matching offer + // Create ask with no matching bid let token_id = "1"; mint(&mut app, &creator, &owner, &collection, token_id); approve(&mut app, &owner, &collection, &marketplace, token_id); @@ -253,13 +253,13 @@ fn try_set_offer_sale() { let response = app.execute_contract(owner.clone(), marketplace.clone(), &set_ask, &[]); assert!(response.is_ok()); - // Create offer that matches ask - let offer_price = coin(10_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + // Create bid that matches ask + let bid_price = coin(10_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -267,8 +267,8 @@ fn try_set_offer_sale() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price], + &set_bid, + &[bid_price], ); assert!(response.is_ok()); @@ -292,7 +292,7 @@ fn try_set_offer_sale() { } #[test] -fn try_accept_offer_sale() { +fn try_accept_bid_sale() { let TestContext { mut app, contracts: @@ -322,13 +322,13 @@ fn try_accept_offer_sale() { let token_id = "1"; - // Create ask with matching offer produces a valid sale - let offer_price = coin(10_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetOffer { + // Create ask with matching bid produces a valid sale + let bid_price = coin(10_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetBid { collection: collection.to_string(), token_id: token_id.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -336,30 +336,30 @@ fn try_accept_offer_sale() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price.clone()], + &set_bid, + &[bid_price.clone()], ); assert!(response.is_ok()); - let offer_id = find_attrs(response.unwrap(), "wasm-set-offer", "id") + let bid_id = find_attrs(response.unwrap(), "wasm-set-bid", "id") .pop() .unwrap(); mint(&mut app, &creator, &owner, &collection, token_id); approve(&mut app, &owner, &collection, &marketplace, token_id); - let accept_offer = ExecuteMsg::AcceptOffer { - id: offer_id, - min_output: offer_price.clone(), + let accept_bid = ExecuteMsg::AcceptBid { + id: bid_id, + min_output: bid_price.clone(), recipient: None, finder: None, }; - let response = app.execute_contract(owner.clone(), marketplace.clone(), &accept_offer, &[]); + let response = app.execute_contract(owner.clone(), marketplace.clone(), &accept_bid, &[]); assert!(response.is_ok()); let owner_balances_after = NativeBalance(app.wrap().query_all_balances(owner.clone()).unwrap()); let bidder_balances_after = NativeBalance(app.wrap().query_all_balances(bidder).unwrap()); - let sale_coin = offer_price; + let sale_coin = bid_price; let fair_burn_amount = sale_coin .amount .mul_ceil(Decimal::bps(config.protocol_fee_bps)); @@ -376,7 +376,7 @@ fn try_accept_offer_sale() { } #[test] -fn try_set_collection_offer_sale() { +fn try_set_collection_bid_sale() { let TestContext { mut app, contracts: @@ -404,7 +404,7 @@ fn try_set_collection_offer_sale() { let bidder_balances_before = NativeBalance(app.wrap().query_all_balances(bidder.clone()).unwrap()); - // Create ask with no matching offer + // Create ask with no matching bid let token_id = "1"; mint(&mut app, &creator, &owner, &collection, token_id); approve(&mut app, &owner, &collection, &marketplace, token_id); @@ -422,9 +422,9 @@ fn try_set_collection_offer_sale() { let response = app.execute_contract(owner.clone(), marketplace.clone(), &set_ask, &[]); assert!(response.is_ok()); - // Create offer that matches ask - let offer_price = coin(10_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetCollectionOffer { + // Create bid that matches ask + let bid_price = coin(10_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { price: ask_price.clone(), @@ -435,8 +435,8 @@ fn try_set_collection_offer_sale() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price], + &set_bid, + &[bid_price], ); assert!(response.is_ok()); @@ -460,7 +460,7 @@ fn try_set_collection_offer_sale() { } #[test] -fn try_accept_collection_offer_sale() { +fn try_accept_collection_bid_sale() { let TestContext { mut app, contracts: @@ -490,12 +490,12 @@ fn try_accept_collection_offer_sale() { let token_id = "1"; - // Create ask with matching offer produces a valid sale - let offer_price = coin(10_000_000, NATIVE_DENOM); - let set_offer = ExecuteMsg::SetCollectionOffer { + // Create ask with matching bid produces a valid sale + let bid_price = coin(10_000_000, NATIVE_DENOM); + let set_bid = ExecuteMsg::SetCollectionBid { collection: collection.to_string(), details: OrderDetails { - price: offer_price.clone(), + price: bid_price.clone(), recipient: None, finder: None, }, @@ -503,18 +503,18 @@ fn try_accept_collection_offer_sale() { let response = app.execute_contract( bidder.clone(), marketplace.clone(), - &set_offer, - &[offer_price.clone()], + &set_bid, + &[bid_price.clone()], ); assert!(response.is_ok()); - let collection_offer_id = find_attrs(response.unwrap(), "wasm-set-collection-offer", "id") + let collection_bid_id = find_attrs(response.unwrap(), "wasm-set-collection-bid", "id") .pop() .unwrap(); mint(&mut app, &creator, &owner, &collection, token_id); approve(&mut app, &owner, &collection, &marketplace, token_id); - // Create an Ask to test accepting an offer while the NFT is escrowed + // Create an Ask to test accepting an bid while the NFT is escrowed let set_ask = ExecuteMsg::SetAsk { collection: collection.to_string(), token_id: token_id.to_string(), @@ -527,17 +527,17 @@ fn try_accept_collection_offer_sale() { let response = app.execute_contract(owner.clone(), marketplace.clone(), &set_ask, &[]); assert!(response.is_ok()); - let accept_collection_offer = ExecuteMsg::AcceptCollectionOffer { - id: collection_offer_id, + let accept_collection_bid = ExecuteMsg::AcceptCollectionBid { + id: collection_bid_id, token_id: token_id.to_string(), - min_output: offer_price.clone(), + min_output: bid_price.clone(), recipient: None, finder: None, }; let response = app.execute_contract( owner.clone(), marketplace.clone(), - &accept_collection_offer, + &accept_collection_bid, &[], ); assert!(response.is_ok()); @@ -545,7 +545,7 @@ fn try_accept_collection_offer_sale() { let owner_balances_after = NativeBalance(app.wrap().query_all_balances(owner.clone()).unwrap()); let bidder_balances_after = NativeBalance(app.wrap().query_all_balances(bidder).unwrap()); - let sale_coin = offer_price; + let sale_coin = bid_price; let fair_burn_amount = sale_coin .amount .mul_ceil(Decimal::bps(config.protocol_fee_bps));