Skip to content

Commit

Permalink
Merge pull request #305 from public-awesome/tasiov/fix-reserve-auctio…
Browse files Browse the repository at this point in the history
…n-funds-recipient

Reserve Auction v1.0.1
  • Loading branch information
jhernandezb authored Jul 27, 2023
2 parents 624d5e0 + 961d926 commit 878b287
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/reserve-auction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stargaze-reserve-auction"
version = "1.0.0"
version = "1.0.1"
authors = [
"Shane Vitarana <[email protected]>",
"Tasio Victoria <[email protected]>",
Expand Down
44 changes: 28 additions & 16 deletions contracts/reserve-auction/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions contracts/reserve-auction/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()),
);
Expand Down
5 changes: 5 additions & 0 deletions contracts/reserve-auction/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions contracts/reserve-auction/src/tests/unit_tests/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions scripts/markdown/migrateContractReserveAuctionV1.0.1.md
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 42 additions & 0 deletions scripts/markdown/storeWasmCodeReserveAuctionV1.0.1.md
Original file line number Diff line number Diff line change
@@ -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
```
39 changes: 23 additions & 16 deletions scripts/reserve-auction/migrate.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
RESERVE_AUCTION_ADDRESS=stars1pl77jpe2rrmtppv5tvs7d0g6xjq6smqxd879snksf2jwmuvxl6qs0jtvyt
# MSG=$(cat <<EOF
# {
# "fair_burn": "stars1mp4dg9mst3hxn5xvcd9zllyx6gguu5jsp5tyt9nsfrtghhwj2akqudhls8"
# }

# EOF
# )

# starsd tx wasm migrate $RESERVE_AUCTION_ADDRESS 2355 "$MSG" \
# --from testnet-1 --gas-prices 0.1ustars --gas-adjustment 1.7 --gas auto \
# -b block -o json | jq .

RESERVE_AUCTION="stars1dnadsd7tx0dmnpp26ms7d66zsp7tduygwjgfjzueh0lg9t5lq5vq9kn47c"
NEW_CODE_ID=123
MSG=$(cat <<EOF
{
"config": {}
}
}
EOF
)

starsd query wasm contract-state smart $RESERVE_AUCTION_ADDRESS "$MSG" -o json | jq .
TITLE="Stargaze Live Auction v1.0.1"
MARKDOWN="scripts/markdown/migrateContractReserveAuctionV1.0.1.md"
DESCRIPTION=$(cat "$MARKDOWN" | base64 | tr -d '\n')

FROM="hot-wallet"
DEPOSIT="10000000000ustars"

CHAIN_ID="stargaze-1"
NODE="https://rpc.stargaze-apis.com:443"

starsd tx gov submit-proposal migrate-contract "$RESERVE_AUCTION" $NEW_CODE_ID "$MSG" \
--title "$TITLE" \
--description "$(echo "$DESCRIPTION" | base64 --decode)" \
--from "$FROM" \
--deposit "$DEPOSIT" \
--chain-id "$CHAIN_ID" \
--node "$NODE" \
--gas-prices 1ustars \
--gas auto \
--gas-adjustment 1.5
8 changes: 4 additions & 4 deletions scripts/reserve-auction/wasm_store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ set -eux

CONTRACT=artifacts/stargaze_reserve_auction.wasm

TITLE="Stargaze Live Auction v1.0.0"
MARKDOWN="scripts/markdown/stargaze_reserve_auction-v1.0.0.md"
TITLE="Stargaze Live Auction v1.0.1"
MARKDOWN="scripts/markdown/storeWasmCodeReserveAuctionv1.0.1.md"
DESCRIPTION=$(cat "$MARKDOWN" | base64 | tr -d '\n')
SOURCE="https://github.com/public-awesome/core/releases/tag/stargaze_reserve_auction-v1.0.0"
SOURCE="https://github.com/public-awesome/marketplace/releases/tag/stargaze_reserve_auction-v1.0.1"
BUILDER="cosmwasm/workspace-optimizer:0.12.13"
HASH="f7cdf509a1889e21399c33eee9e68ac328abd4a456142db080d760d15135fe56"
HASH="4e77dfe1830d5a33058502d19ef990773f45acfee7862ebb5355626c75bd0eb1"

FROM="hot-wallet"
DEPOSIT="10000000000ustars"
Expand Down

0 comments on commit 878b287

Please sign in to comment.