Skip to content

Commit

Permalink
Merge pull request #302 from public-awesome/tasiov/reserve-auction-de…
Browse files Browse the repository at this point in the history
…ploy-script

Reserve Auction Mainnet
  • Loading branch information
shanev authored Jul 18, 2023
2 parents b49ceb1 + 24f409f commit 624d5e0
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 119 deletions.
29 changes: 27 additions & 2 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions contracts/marketplace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ exclude = [
[lib]
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "schema"
path = "src/bin/schema.rs"
doc = false

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
Expand Down
9 changes: 7 additions & 2 deletions 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.2.0"
version = "1.0.0"
authors = [
"Shane Vitarana <[email protected]>",
"Tasio Victoria <[email protected]>",
Expand All @@ -22,13 +22,19 @@ exclude = [
[lib]
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "schema"
path = "src/bin/schema.rs"
doc = false

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
sg-marketplace-common = { version = "1.1.0" }
stargaze-fair-burn = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
Expand All @@ -40,7 +46,6 @@ cw721 = { workspace = true }
cw721-base = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
sg-marketplace-common = { workspace = true }
sg-std = { workspace = true }
sg1 = { workspace = true }
sg721-base = { workspace = true }
Expand Down
117 changes: 10 additions & 107 deletions contracts/reserve-auction/README.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,21 @@
# Stargaze Reserve (Timed) Auctions
# Stargaze Reserve Auction (aka Live Auction)

Reserve auctions enable an NFT to receive bids of increasing value for a certain duration of time.

This contract honors royalties.

## State

### `Config`

These parameters will be set on contract instantiation. They can also be updated via Sudo.

```rs
pub struct Config {
pub create_auction_fee: Uint128,
pub min_reserve_price: Coin,
pub min_bid_increment: u64,
pub min_duration: u64,
pub extend_duration: u64,
pub trading_fee: Decimal,
}
```

### `Auction`

```rs
pub struct HighBid {
pub coin: Coin,
pub bidder: Addr,
}

pub struct Auction {
pub token_id: String,
pub collection: Addr,
pub seller: Addr,
pub reserve_price: Coin,
pub start_time: Timestamp,
pub end_time: Timestamp,
pub seller_funds_recipient: Option<Addr>,
pub high_bid: Option<HighBid>,
pub first_bid_time: Option<Timestamp>,
}
```
This CosmWasm smart contract implements a reserve auction on the Stargaze network. In a reserve auction, an item is not sold unless the highest bid is equal to or greater than a predetermined reserve price. The contract includes several key features such as auction creation, bid placement, auction settlement, and cancellation. The auction also provides the ability to update the reserve price.

## Messages

### `Instantiate`

```rs
pub struct InstantiateMsg {
pub create_auction_fee: Uint128,
pub min_reserve_price: Coin,
pub min_duration: u64,
pub min_bid_increment: u64,
pub extend_duration: u64,
pub trading_fee_bps: u64,
}
```

### `CreateAuction`

Creates an auction for the given NFT, the NFT is escrowed at the time of contract creation. The timer stars after `start_time`. The contract maintains custody of the NFT until the auction is finished. `Approval` must be given this contract so it can transfer the NFT to itself. `Approval` can be batched to run before `CreateAuction`.

```rs
CreateAuction {
collection: String,
token_id: String,
reserve_price: Coin,
start_time: Timestamp,
end_time: Timestamp,
seller_funds_recipient: Option<String>,
}
```

### `UpdateReservePrice`

Updated the reserve price of an existing auction. This only runs if the auction hasn't started yet.

```rs
UpdateReservePrice {
collection: String,
token_id: String,
reserve_price: Coin,
}
```

### `CancelAuction`

Cancels an existing auction. This only runs if the auction hasn't started yet.
The contract functionality is implemented in the following executable messages.

```rs
CancelAuction {
collection: String,
token_id: String,
}
```
**CreateAuction**: Allows the owner of an NFT to create an auction. The owner sets the reserve price, auction duration, and an optional recipient address for the auction proceeds. Upon creation, the contract verifies that the NFT owner has approved the auction contract to transfer the NFT. The function also handles the creation fee, which is sent to a fair-burn contract if applicable. The auction officially starts when the first bid has been placed.

### `PlaceBid`
**UpdateReservePrice**: Allows the seller to update the reserve price of an auction. This operation is only permissible if the auction has not yet started (i.e., no bids have been placed).

Places a bid on the given NFT. Each bid must be a fixed amount greater than the last. The amount for the bid is held in escrow by the contract until either the auction ends or a higher bid is placed. When a higher bid is placed, the previous bid is refunded. If a bid is placed within `extend_duration` of the auction ending, the auction is extended by `extend_duration` seconds.
**CancelAuction**: Allows the seller to cancel an auction. Like updating the reserve price, cancellation is only permissible if the auction has not yet started.

```rs
PlaceBid {
collection: String,
token_id: String,
}
```
**PlaceBid**: Allows a participant to place a bid on an NFT. If the participant is placing the first bid, then the bid must be higher than the reserve price. If it is not the first bid, then the bid must be higher than the previous highest bid. If a bid is placed near the end of an auction, the end time of the auction may be extended in order to allow for more bidding.

### `SettleAuction`
**SettleAuction**: Allows anyone to settle an auction after it has ended. The function distributes the winning bid to the seller, transfers the NFT to the winning bidder, and burns the platform fee. This message is also invoked within the CosmosSDK's EndBlocker to allow for timely settling of auctions.

Ends the auction for the given NFT. It sends it to the highest bidder, and transfers the funds from the bid to the seller. Royalties are paid to the creator. Anyone can call this function.
## Addresses

```rs
SettleAuction {
collection: String,
token_id: String,
}
```
- `elfagar-1: stars1dnadsd7tx0dmnpp26ms7d66zsp7tduygwjgfjzueh0lg9t5lq5vq9kn47c`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "stargaze-reserve-auction",
"contract_version": "1.2.0",
"contract_version": "1.0.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
18 changes: 14 additions & 4 deletions contracts/reserve-auction/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::msg::ExecuteMsg;
use crate::state::{auctions, Auction, HighBid};
use crate::state::{CONFIG, HALT_MANAGER};
use cosmwasm_std::{
coin, ensure, ensure_eq, has_coins, Addr, Coin, DepsMut, Env, Event, MessageInfo, Timestamp,
attr, coin, ensure, ensure_eq, has_coins, Addr, Coin, DepsMut, Env, Event, MessageInfo,
Timestamp,
};
use cw_utils::{maybe_addr, must_pay, nonpayable};
use sg_marketplace_common::{
Expand Down Expand Up @@ -300,14 +301,23 @@ pub fn execute_place_bid(
// If this is not the first bid, refund previous bidder and extend end_time if necessary
Some(_) => {
// Refund previous bidder
let high_bid = auction.high_bid.unwrap();
response =
response.add_submessage(checked_transfer_coin(high_bid.coin, &high_bid.bidder)?);
let previous_high_bid = auction.high_bid.unwrap();
response = response.add_submessage(checked_transfer_coin(
previous_high_bid.coin.clone(),
&previous_high_bid.bidder,
)?);

let time_remaining = auction.end_time.unwrap().seconds() - block_time.seconds();
if time_remaining < config.extend_duration {
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()),
attr("previous_bidder", previous_high_bid.bidder),
attr("previous_bid_amount", previous_high_bid.coin.to_string()),
]));
}
};

Expand Down
27 changes: 24 additions & 3 deletions contracts/reserve-auction/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
// pub mod contract;
//! # Stargaze Reserve Auction (aka Live Auction)
//!
//! This CosmWasm smart contract implements a reserve auction on the Stargaze network. In a reserve auction, an item is not sold unless the highest bid is equal to or greater than a predetermined reserve price. The contract includes several key features such as auction creation, bid placement, auction settlement, and cancellation. The auction also provides the ability to update the reserve price.
//!
//! ## Messages
//!
//! The contract functionality is implemented in the following executable messages.
//!
//! **CreateAuction**: Allows the owner of an NFT to create an auction. The owner sets the reserve price, auction duration, and an optional recipient address for the auction proceeds. Upon creation, the contract verifies that the NFT owner has approved the auction contract to transfer the NFT. The function also handles the creation fee, which is sent to a fair-burn contract if applicable. The auction officially starts when the first bid has been //! placed.
//!
//! **UpdateReservePrice**: Allows the seller to update the reserve price of an auction. This operation is only permissible if the auction has not yet //! started (i.e., no bids have been placed).
//!
//! **CancelAuction**: Allows the seller to cancel an auction. Like updating the reserve price, cancellation is only permissible if the auction has not yet //! started.
//!
//! **PlaceBid**: Allows a participant to place a bid on an NFT. If the participant is placing the first bid, then the bid must be higher than the reserve price. If it is not the first bid, then the bid must be higher than the previous highest bid. If a bid is placed near the end of an auction, the end //! time of the auction may be extended in order to allow for more bidding.
//!
//! **SettleAuction**: Allows anyone to settle an auction after it has ended. The function distributes the winning bid to the seller, transfers the NFT to //! the winning bidder, and burns the platform fee. This message is also invoked within the CosmosSDK's EndBlocker to allow for timely settling of auctions.
//!
//! ## Addresses
//!
//! - `elfagar-1: stars1dnadsd7tx0dmnpp26ms7d66zsp7tduygwjgfjzueh0lg9t5lq5vq9kn47c`
mod error;
pub mod execute;
pub mod helpers;
mod helpers;
pub mod instantiate;
pub mod migrate;
pub mod msg;
pub mod query;
pub mod state;
mod state;
pub mod sudo;
mod tests;

Expand Down
41 changes: 41 additions & 0 deletions scripts/markdown/stargaze_reserve_auction-v1.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Store WASM Code

This uploads the code for Stargaze Live Auction v1.0.0

The source code is available at https://github.com/public-awesome/core/releases/tag/stargaze_reserve_auction-v1.0.0

This CosmWasm smart contract implements a reserve auction on the Stargaze network. In a reserve auction, an item is not sold unless the highest bid is equal to or greater than a predetermined reserve price. The contract includes several key features such as auction creation, bid placement, auction settlement, and cancellation.

To integrate with the Stargaze Reserve Auction contract please refer to the following documentation https://crates.io/crates/stargaze-reserve-auction

### 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:

```
f7cdf509a1889e21399c33eee9e68ac328abd4a456142db080d760d15135fe56 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
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions scripts/reserve-auction/wasm_store.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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"
DESCRIPTION=$(cat "$MARKDOWN" | base64 | tr -d '\n')
SOURCE="https://github.com/public-awesome/core/releases/tag/stargaze_reserve_auction-v1.0.0"
BUILDER="cosmwasm/workspace-optimizer:0.12.13"
HASH="f7cdf509a1889e21399c33eee9e68ac328abd4a456142db080d760d15135fe56"

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

RUN_AS="stars19mmkdpvem2xvrddt8nukf5kfpjwfslrsu7ugt5"
ANY_OF_ADDRS="stars19mmkdpvem2xvrddt8nukf5kfpjwfslrsu7ugt5,stars1r5ecq7zn6hwh5e68e79ume8rp9ht7kjz352drk"

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

starsd tx gov submit-proposal wasm-store "$CONTRACT" \
--title "$TITLE" \
--description "$(echo "$DESCRIPTION" | base64 --decode)" \
--code-source-url "$SOURCE" \
--builder "$BUILDER" \
--code-hash "$HASH" \
--from "$FROM" \
--deposit "$DEPOSIT" \
--run-as "$RUN_AS" \
--instantiate-anyof-addresses "$ANY_OF_ADDRS" \
--chain-id "$CHAIN_ID" \
--node "$NODE" \
--gas-prices 1ustars \
--gas auto \
--gas-adjustment 1.5

0 comments on commit 624d5e0

Please sign in to comment.