Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add action to finalize-sale #330

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@

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,

Check warning on line 363 in contracts/stargaze-marketplace-v2/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/stargaze-marketplace-v2/src/execute.rs#L362-L363

Added lines #L362 - L363 were not covered by tests
&env,
&ask,
&config,
&matching_bid,
false,
"update-ask",
response,

Check warning on line 370 in contracts/stargaze-marketplace-v2/src/execute.rs

View check run for this annotation

Codecov / codecov/patch

contracts/stargaze-marketplace-v2/src/execute.rs#L370

Added line #L370 was not covered by tests
)?;
} else {
// If no match is found continue updating the ask
ask.save(deps.storage)?;
Expand Down Expand Up @@ -459,6 +477,7 @@
&config,
&MatchingBid::Bid(bid),
true,
"accept-ask",
Response::new(),
)?;

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

Expand Down Expand Up @@ -781,6 +803,7 @@
&config,
&MatchingBid::CollectionBid(collection_bid),
true,
"set-collection-bid",
response,
)?;
} else if buy_now {
Expand Down Expand Up @@ -882,6 +905,7 @@
&config,
&MatchingBid::CollectionBid(collection_bid),
true,
"update-collection-bid",
response,
)?;
} else {
Expand Down Expand Up @@ -1004,6 +1028,7 @@
&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
Loading