diff --git a/Cargo.lock b/Cargo.lock index e9f539c1..eda860e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1641,7 +1641,7 @@ dependencies = [ [[package]] name = "stargaze-reserve-auction" -version = "1.0.0" +version = "1.0.1" dependencies = [ "anyhow", "cosmwasm-schema", diff --git a/contracts/reserve-auction/Cargo.toml b/contracts/reserve-auction/Cargo.toml index 843df5d1..83a02381 100644 --- a/contracts/reserve-auction/Cargo.toml +++ b/contracts/reserve-auction/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stargaze-reserve-auction" -version = "1.0.0" +version = "1.0.1" authors = [ "Shane Vitarana ", "Tasio Victoria ", diff --git a/contracts/reserve-auction/src/execute.rs b/contracts/reserve-auction/src/execute.rs index d301874e..42847097 100644 --- a/contracts/reserve-auction/src/execute.rs +++ b/contracts/reserve-auction/src/execute.rs @@ -292,11 +292,31 @@ pub fn execute_place_bid( ContractError::AuctionEnded {} ); + let next_bid = HighBid { + bidder: info.sender, + coin: coin(bid_amount.u128(), auction_denom), + }; + + let mut event = Event::new("place-bid") + .add_attribute("collection", auction.collection.to_string()) + .add_attribute("token_id", auction.token_id.clone()) + .add_attribute("seller", auction.seller.to_string()) + .add_attribute("bidder", next_bid.bidder.to_string()) + .add_attribute("bid_amount", next_bid.coin.to_string()); + match auction.first_bid_time { // If this is the first bid, set the first_bid_time and end_time None => { auction.first_bid_time = Some(block_time); auction.end_time = Some(block_time.plus_seconds(auction.duration)); + + event = event.add_attributes(vec![ + attr("first_bid", true.to_string()), + attr( + "auction_end_time", + auction.end_time.as_ref().unwrap().to_string(), + ), + ]); } // If this is not the first bid, refund previous bidder and extend end_time if necessary Some(_) => { @@ -312,33 +332,25 @@ pub fn execute_place_bid( auction.end_time = Some(block_time.plus_seconds(config.extend_duration)); } - response = response.add_event(Event::new("remove-bid").add_attributes(vec![ - attr("collection", auction.collection.to_string()), - attr("token_id", auction.token_id.clone()), + event = event.add_attributes(vec![ + attr("first_bid", false.to_string()), + attr( + "auction_end_time", + auction.end_time.as_ref().unwrap().to_string(), + ), attr("previous_bidder", previous_high_bid.bidder), attr("previous_bid_amount", previous_high_bid.coin.to_string()), - ])); + ]); } }; - auction.high_bid = Some(HighBid { - bidder: info.sender, - coin: coin(bid_amount.u128(), auction_denom), - }); - + auction.high_bid = Some(next_bid); auctions().save( deps.storage, (auction.collection.clone(), auction.token_id.clone()), &auction, )?; - let high_bid = &auction.high_bid.unwrap(); - let event = Event::new("place-bid") - .add_attribute("collection", auction.collection.to_string()) - .add_attribute("token_id", auction.token_id) - .add_attribute("bidder", high_bid.bidder.to_string()) - .add_attribute("bid_amount", high_bid.coin.to_string()) - .add_attribute("auction_end_time", auction.end_time.unwrap().to_string()); response = response.add_event(event); Ok(response) diff --git a/contracts/reserve-auction/src/helpers.rs b/contracts/reserve-auction/src/helpers.rs index f39e2df7..68954efe 100644 --- a/contracts/reserve-auction/src/helpers.rs +++ b/contracts/reserve-auction/src/helpers.rs @@ -85,13 +85,13 @@ pub fn settle_auction( )?; // High bid must exist if end time exists - let high_bid = auction.high_bid.unwrap(); + let high_bid = auction.high_bid.as_ref().unwrap(); let royalty_info = load_collection_royalties(&deps.querier, deps.api, &auction.collection)?; (_, response) = payout_nft_sale_fees( &high_bid.coin, - &auction.seller, + &auction.funds_recipient(), &config.fair_burn, None, None, @@ -112,6 +112,7 @@ pub fn settle_auction( Event::new("settle-auction") .add_attribute("collection", auction.collection.to_string()) .add_attribute("token_id", auction.token_id) + .add_attribute("seller", auction.seller) .add_attribute("bidder", high_bid.bidder.to_string()) .add_attribute("bid_amount", high_bid.coin.amount.to_string()), ); diff --git a/contracts/reserve-auction/src/state.rs b/contracts/reserve-auction/src/state.rs index 3fbeab05..98862960 100644 --- a/contracts/reserve-auction/src/state.rs +++ b/contracts/reserve-auction/src/state.rs @@ -2,6 +2,7 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::{coin, ensure, Addr, Coin, Decimal, Storage, Timestamp, Uint128}; use cw_storage_macro::index_list; use cw_storage_plus::{IndexedMap, Item, Map, MultiIndex}; +use sg_marketplace_common::address::address_or; use crate::ContractError; @@ -82,6 +83,10 @@ impl Auction { self.reserve_price.denom.clone() } + pub fn funds_recipient(&self) -> Addr { + address_or(self.seller_funds_recipient.as_ref(), &self.seller) + } + pub fn min_bid_coin(&self, min_bid_increment_percent: Decimal) -> Coin { let amount = match &self.high_bid { Some(high_bid) => high_bid diff --git a/contracts/reserve-auction/src/tests/unit_tests/auction.rs b/contracts/reserve-auction/src/tests/unit_tests/auction.rs index 2f40d617..2edb2a13 100644 --- a/contracts/reserve-auction/src/tests/unit_tests/auction.rs +++ b/contracts/reserve-auction/src/tests/unit_tests/auction.rs @@ -23,7 +23,7 @@ use crate::tests::{ }; use crate::ContractError; -use cosmwasm_std::{coin, Decimal, StdError, Uint128}; +use cosmwasm_std::{coin, Addr, Decimal, StdError, Uint128}; use cw_multi_test::Executor; use sg721_base::msg::{CollectionInfoResponse, QueryMsg as Sg721QueryMsg}; use sg_multi_test::StargazeApp; @@ -717,6 +717,7 @@ fn try_settle_auction_with_bids() { let auction_creator = setup_addtl_account(&mut router, "auction_creator", INITIAL_BALANCE).unwrap(); let second_bidder = setup_addtl_account(&mut router, "second_bidder", INITIAL_BALANCE).unwrap(); + let seller_funds_recipient = Addr::unchecked("seller_funds_recipient"); // mint nft for creator mint(&mut router, &minter, &creator, &auction_creator); @@ -737,7 +738,7 @@ fn try_settle_auction_with_bids() { &token_id.to_string(), coin(MIN_RESERVE_PRICE, NATIVE_DENOM), DEFAULT_DURATION, - None, + Some(seller_funds_recipient.to_string()), coin(CREATE_AUCTION_FEE.u128(), NATIVE_DENOM), ); assert!(res.is_ok()); @@ -843,7 +844,7 @@ fn try_settle_auction_with_bids() { Uint128::from(INITIAL_BALANCE) + royalty_fee ); - // check that seller was paid + // check that seller funds recipient was paid let seller_payment = Uint128::from(high_bid_amount) - protocol_fee - royalty_fee; let new_auction_creator_balance = router .wrap() @@ -852,9 +853,16 @@ fn try_settle_auction_with_bids() { .amount; assert_eq!( new_auction_creator_balance, - Uint128::from(INITIAL_BALANCE) - CREATE_AUCTION_FEE + seller_payment + Uint128::from(INITIAL_BALANCE) - CREATE_AUCTION_FEE ); + let new_seller_funds_recipient_balance = router + .wrap() + .query_balance(&seller_funds_recipient, NATIVE_DENOM) + .unwrap() + .amount; + assert_eq!(new_seller_funds_recipient_balance, seller_payment); + // check that first bidder was fully refunded let first_bidder_balance = router .wrap() diff --git a/scripts/markdown/migrateContractReserveAuctionV1.0.1.md b/scripts/markdown/migrateContractReserveAuctionV1.0.1.md new file mode 100644 index 00000000..49e798cc --- /dev/null +++ b/scripts/markdown/migrateContractReserveAuctionV1.0.1.md @@ -0,0 +1,3 @@ +## Migrate Contract + +By voting YES on this proposal, you agree to migrate the Stargaze Reserve Auction contract from V1.0.0 to V1.0.1. The migrate code ID of the contract uploaded in proposal #185. diff --git a/scripts/markdown/stargaze_reserve_auction-v1.0.0.md b/scripts/markdown/storeWasmCodeReserveAuctionV1.0.0.md similarity index 100% rename from scripts/markdown/stargaze_reserve_auction-v1.0.0.md rename to scripts/markdown/storeWasmCodeReserveAuctionV1.0.0.md diff --git a/scripts/markdown/storeWasmCodeReserveAuctionV1.0.1.md b/scripts/markdown/storeWasmCodeReserveAuctionV1.0.1.md new file mode 100644 index 00000000..dffeef22 --- /dev/null +++ b/scripts/markdown/storeWasmCodeReserveAuctionV1.0.1.md @@ -0,0 +1,42 @@ +## Store WASM Code + +This uploads the code for Stargaze Live Auction v1.0.1 + +The source code is available at https://github.com/public-awesome/marketplace/releases/tag/stargaze_reserve_auction-v1.0.1 + +This patch follows the release of Reserve Auctions on mainnet to fix a few items outlined below: + +- fix usage of seller_funds_recipient address +- add more attributes to certain contract events + +### Compile Instructions + +```sh +docker run --rm -v "$(pwd)":/code --platform linux/amd64 \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/workspace-optimizer:0.12.13 +``` + +This results in the following SHA256 checksum: + +``` +4e77dfe1830d5a33058502d19ef990773f45acfee7862ebb5355626c75bd0eb1 stargaze_reserve_auction.wasm +``` + +### Verify On-chain Contract + +```sh +starsd q gov proposal $id --output json \ +| jq -r '.content.wasm_byte_code' \ +| base64 -d \ +| gzip -dc \ +| sha256sum + +``` + +### Verify Local Contract + +``` +sha256sum artifacts/stargaze_reserve_auction.wasm +``` diff --git a/scripts/reserve-auction/migrate.sh b/scripts/reserve-auction/migrate.sh index 645ac960..7d0029bd 100755 --- a/scripts/reserve-auction/migrate.sh +++ b/scripts/reserve-auction/migrate.sh @@ -1,22 +1,29 @@ -RESERVE_AUCTION_ADDRESS=stars1pl77jpe2rrmtppv5tvs7d0g6xjq6smqxd879snksf2jwmuvxl6qs0jtvyt -# MSG=$(cat <