Skip to content

Commit

Permalink
Merge pull request #330 from public-awesome/jhernandezb/add-action-fi…
Browse files Browse the repository at this point in the history
…nalize-sale

add action to finalize-sale
  • Loading branch information
jhernandezb authored Dec 12, 2024
2 parents cc7f729 + ce52e6e commit d26f1df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
29 changes: 27 additions & 2 deletions contracts/stargaze-marketplace-v2/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,16 @@ pub fn execute_set_ask(

if let Some(matching_bid) = match_result {
// If a match is found finalize the sale
response = finalize_sale(deps, &env, &ask, &config, &matching_bid, false, response)?;
response = finalize_sale(
deps,
&env,
&ask,
&config,
&matching_bid,
false,
"set-ask",
response,
)?;
} else if sell_now {
// If no match is found and sell_now is true, abort transaction
Err(ContractError::NoMatchFound)?;
Expand Down Expand Up @@ -350,7 +359,16 @@ pub fn execute_update_ask(

if let Some(matching_bid) = match_result {
// If a match is found finalize the sale
response = finalize_sale(deps, &env, &ask, &config, &matching_bid, false, response)?;
response = finalize_sale(
deps,
&env,
&ask,
&config,
&matching_bid,
false,
"update-ask",
response,
)?;
} else {
// If no match is found continue updating the ask
ask.save(deps.storage)?;
Expand Down Expand Up @@ -459,6 +477,7 @@ pub fn execute_accept_ask(
&config,
&MatchingBid::Bid(bid),
true,
"accept-ask",
Response::new(),
)?;

Expand Down Expand Up @@ -517,6 +536,7 @@ pub fn execute_set_bid(
&config,
&MatchingBid::Bid(bid),
true,
"set-bid",
response,
)?;
} else if buy_now {
Expand Down Expand Up @@ -611,6 +631,7 @@ pub fn execute_update_bid(
&config,
&MatchingBid::Bid(bid),
true,
"update-bid",
response,
)?;
} else {
Expand Down Expand Up @@ -730,6 +751,7 @@ pub fn execute_accept_bid(
&config,
&MatchingBid::Bid(bid),
false,
"accept-bid",
Response::new(),
)?;

Expand Down Expand Up @@ -781,6 +803,7 @@ pub fn execute_set_collection_bid(
&config,
&MatchingBid::CollectionBid(collection_bid),
true,
"set-collection-bid",
response,
)?;
} else if buy_now {
Expand Down Expand Up @@ -882,6 +905,7 @@ pub fn execute_update_collection_bid(
&config,
&MatchingBid::CollectionBid(collection_bid),
true,
"update-collection-bid",
response,
)?;
} else {
Expand Down Expand Up @@ -1004,6 +1028,7 @@ pub fn execute_accept_collection_bid(
&config,
&MatchingBid::CollectionBid(collection_bid),
false,
"accept-collection-bid",
Response::new(),
)?;

Expand Down
5 changes: 4 additions & 1 deletion contracts/stargaze-marketplace-v2/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ pub fn divide_protocol_fees(
Ok(protocol_fees)
}

#[allow(clippy::too_many_arguments)]
pub fn finalize_sale(
deps: DepsMut,
env: &Env,
ask: &Ask,
config: &Config<Addr>,
matching_bid: &MatchingBid,
ask_before_bid: bool,
action: &str,
response: Response,
) -> Result<Response, ContractError> {
let (nft_recipient, bid_details) = match &matching_bid {
Expand Down Expand Up @@ -204,7 +206,8 @@ pub fn finalize_sale(
.add_attribute("price", sale_price.amount.to_string())
.add_attribute("seller_recipient", seller_recipient.to_string())
.add_attribute("nft_recipient", nft_recipient.to_string())
.add_attribute("ask", ask.id.to_string());
.add_attribute("ask", ask.id.to_string())
.add_attribute("action", action.to_string());

match &matching_bid {
MatchingBid::Bid(bid) => {
Expand Down

0 comments on commit d26f1df

Please sign in to comment.