Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions contracts/reserve-auction/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum ContractError {
#[error("InvalidReservePrice: {min}")]
InvalidReservePrice { min: Coin },

#[error("InvalidMinReservePriceManagerAddress")]
InvalidMinReservePriceManagerAddress {},

#[error("BidTooLow: {0}")]
BidTooLow(Uint128),

Expand Down
89 changes: 88 additions & 1 deletion contracts/reserve-auction/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::vec;
use crate::error::ContractError;
use crate::helpers::{only_no_auction, settle_auction, validate_reserve_price};
use crate::msg::ExecuteMsg;
use crate::state::{auctions, Auction, HighBid};
use crate::state::{auctions, Auction, HighBid, MIN_RESERVE_PRICES, MIN_RESERVE_PRICE_MANAGER};
use crate::state::{CONFIG, HALT_MANAGER};
use cosmwasm_std::{
attr, coin, ensure, ensure_eq, has_coins, Addr, Coin, DepsMut, Env, Event, MessageInfo,
Expand Down Expand Up @@ -76,6 +76,15 @@ pub fn execute(
api.addr_validate(&collection)?,
&token_id,
),
ExecuteMsg::SetMinReservePrices { min_reserve_prices } => {
execute_set_min_reserve_prices(deps, info, min_reserve_prices)
}
ExecuteMsg::UnsetMinReservePrices { denoms } => {
execute_unset_min_reserve_prices(deps, info, denoms)
}
ExecuteMsg::UpdateMinReservePriceManager { manager } => {
execute_update_min_reserve_price_manager(deps, info, manager)
}
}
}

Expand Down Expand Up @@ -372,3 +381,81 @@ pub fn execute_settle_auction(

settle_auction(deps, block_time, auction, &config, &halt_manager, response)
}

pub fn execute_set_min_reserve_prices(
deps: DepsMut,
info: MessageInfo,
min_reserve_prices: Vec<Coin>,
) -> Result<Response, ContractError> {
let min_reserve_price_manager = MIN_RESERVE_PRICE_MANAGER.load(deps.storage)?;
ensure_eq!(
info.sender,
min_reserve_price_manager,
ContractError::Unauthorized {}
);

let mut response = Response::new();

for min_reserve_price in min_reserve_prices {
ensure!(
!MIN_RESERVE_PRICES.has(deps.storage, min_reserve_price.denom.clone()),
ContractError::InvalidInput("found duplicate denom".to_string())
);

MIN_RESERVE_PRICES.save(
deps.storage,
min_reserve_price.denom.clone(),
&min_reserve_price.amount,
)?;
response = response.add_event(
Event::new("set-min-reserve-price")
.add_attribute("denom", min_reserve_price.denom)
.add_attribute("amount", min_reserve_price.amount),
);
}
Ok(response)
}

pub fn execute_unset_min_reserve_prices(
deps: DepsMut,
info: MessageInfo,
denoms: Vec<String>,
) -> Result<Response, ContractError> {
let min_reserve_price_manager = MIN_RESERVE_PRICE_MANAGER.load(deps.storage)?;
ensure_eq!(
info.sender,
min_reserve_price_manager,
ContractError::Unauthorized {}
);

let mut response = Response::new();

for denom in denoms {
ensure!(
MIN_RESERVE_PRICES.has(deps.storage, denom.clone()),
ContractError::InvalidInput("denom not found".to_string())
);

MIN_RESERVE_PRICES.remove(deps.storage, denom.clone());
response =
response.add_event(Event::new("unset-min-reserve-price").add_attribute("denom", denom));
}
Ok(response)
}

pub fn execute_update_min_reserve_price_manager(
deps: DepsMut,
info: MessageInfo,
manager: String,
) -> Result<Response, ContractError> {
let min_reserve_price_manager = MIN_RESERVE_PRICE_MANAGER.load(deps.storage)?;
ensure_eq!(
info.sender,
min_reserve_price_manager,
ContractError::Unauthorized {}
);

MIN_RESERVE_PRICE_MANAGER.save(deps.storage, &deps.api.addr_validate(&manager)?)?;

Ok(Response::new().add_attribute("action", "update-min-reserve-price-manager"))
}
8 changes: 7 additions & 1 deletion contracts/reserve-auction/src/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use cosmwasm_std::entry_point;

use crate::msg::InstantiateMsg;
use crate::state::{Config, HaltManager, HALT_MANAGER};
use crate::state::{Config, HaltManager, HALT_MANAGER, MIN_RESERVE_PRICE_MANAGER};
use crate::{error::ContractError, state::MIN_RESERVE_PRICES};
use cosmwasm_std::{DepsMut, Env, Event, MessageInfo};
use cw2::set_contract_version;
Expand All @@ -20,6 +20,12 @@ pub fn instantiate(
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

MIN_RESERVE_PRICE_MANAGER.save(
deps.storage,
&deps.api.addr_validate(&msg.min_reserve_price_manager)?,
)?;

let config = Config {
fair_burn: deps.api.addr_validate(&msg.fair_burn)?,
trading_fee_percent: msg.trading_fee_percent,
Expand Down
18 changes: 12 additions & 6 deletions contracts/reserve-auction/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct InstantiateMsg {
/// The minimum reserve prices for the various denoms. Denoms
/// no defined are not supported.
pub min_reserve_prices: Vec<Coin>,
pub min_reserve_price_manager: String,
}

#[cw_serde]
Expand Down Expand Up @@ -65,6 +66,15 @@ pub enum ExecuteMsg {
collection: String,
token_id: String,
},
SetMinReservePrices {
min_reserve_prices: Vec<Coin>,
},
UnsetMinReservePrices {
denoms: Vec<String>,
},
UpdateMinReservePriceManager {
manager: String,
},
}

#[cw_serde]
Expand Down Expand Up @@ -106,6 +116,8 @@ pub enum QueryMsg {
end_time: u64,
query_options: Option<QueryOptions<AuctionKeyOffset>>,
},
#[returns(String)]
MinReservePriceManager {},
}

#[allow(clippy::large_enum_variant)]
Expand All @@ -125,10 +137,4 @@ pub enum SudoMsg {
halt_buffer_duration: Option<u64>,
halt_postpone_duration: Option<u64>,
},
SetMinReservePrices {
min_reserve_prices: Vec<Coin>,
},
UnsetMinReservePrices {
denoms: Vec<String>,
},
}
12 changes: 11 additions & 1 deletion contracts/reserve-auction/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::msg::{AuctionKeyOffset, MinReservePriceOffset, QueryMsg};
use crate::state::{auctions, Auction, Config, HaltManager, HALT_MANAGER};
use crate::state::{
auctions, Auction, Config, HaltManager, HALT_MANAGER, MIN_RESERVE_PRICE_MANAGER,
};
use crate::state::{CONFIG, MIN_RESERVE_PRICES};

use cosmwasm_std::{coin, to_json_binary, Addr, Binary, Coin, Deps, Env, StdResult};
Expand Down Expand Up @@ -42,6 +44,9 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
end_time,
query_options.unwrap_or_default(),
)?),
QueryMsg::MinReservePriceManager {} => {
to_json_binary(&query_min_reserve_price_manager(deps)?)
}
}
}

Expand Down Expand Up @@ -75,6 +80,11 @@ pub fn query_min_reserve_prices(
Ok(coins)
}

pub fn query_min_reserve_price_manager(deps: Deps) -> StdResult<String> {
let manager = MIN_RESERVE_PRICE_MANAGER.load(deps.storage)?;
Ok(manager.to_string())
}

pub fn query_auction(
deps: Deps,
collection: String,
Expand Down
1 change: 1 addition & 0 deletions contracts/reserve-auction/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub const CONFIG: Item<Config> = Item::new("cfg");
// A map of acceptable denoms to their minimum reserve price.
// Denoms not found in the Map are not accepted.
pub const MIN_RESERVE_PRICES: Map<String, Uint128> = Map::new("mrp");
pub const MIN_RESERVE_PRICE_MANAGER: Item<Addr> = Item::new("mrpm");

#[cw_serde]
pub struct HighBid {
Expand Down
49 changes: 1 addition & 48 deletions contracts/reserve-auction/src/sudo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::ContractError;
use crate::helpers::settle_auction;
use crate::msg::SudoMsg;
use crate::state::{auctions, Auction, HaltWindow, CONFIG, HALT_MANAGER, MIN_RESERVE_PRICES};
use crate::state::{auctions, Auction, HaltWindow, CONFIG, HALT_MANAGER};

use cosmwasm_std::{Addr, Coin, Decimal, DepsMut, Env, Event, Order, StdResult};
use cw_storage_plus::Bound;
Expand Down Expand Up @@ -40,10 +40,6 @@ pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response, ContractE
halt_buffer_duration,
halt_postpone_duration,
),
SudoMsg::SetMinReservePrices { min_reserve_prices } => {
sudo_set_min_reserve_prices(deps, min_reserve_prices)
}
SudoMsg::UnsetMinReservePrices { denoms } => sudo_unset_min_reserve_prices(deps, denoms),
}
}

Expand Down Expand Up @@ -205,46 +201,3 @@ pub fn sudo_update_params(

Ok(Response::new().add_event(event))
}

pub fn sudo_set_min_reserve_prices(
deps: DepsMut,
min_reserve_prices: Vec<Coin>,
) -> Result<Response, ContractError> {
let mut response = Response::new();

for min_reserve_price in min_reserve_prices {
if MIN_RESERVE_PRICES.has(deps.storage, min_reserve_price.denom.clone()) {
return Err(ContractError::InvalidInput(
"found duplicate denom".to_string(),
));
}
MIN_RESERVE_PRICES.save(
deps.storage,
min_reserve_price.denom.clone(),
&min_reserve_price.amount,
)?;
response = response.add_event(
Event::new("set-min-reserve-price")
.add_attribute("denom", min_reserve_price.denom)
.add_attribute("amount", min_reserve_price.amount),
);
}
Ok(response)
}

pub fn sudo_unset_min_reserve_prices(
deps: DepsMut,
denoms: Vec<String>,
) -> Result<Response, ContractError> {
let mut response = Response::new();

for denom in denoms {
if !MIN_RESERVE_PRICES.has(deps.storage, denom.clone()) {
return Err(ContractError::InvalidInput("denom not found".to_string()));
}
MIN_RESERVE_PRICES.remove(deps.storage, denom.clone());
response =
response.add_event(Event::new("unset-min-reserve-price").add_attribute("denom", denom));
}
Ok(response)
}
2 changes: 2 additions & 0 deletions contracts/reserve-auction/src/tests/setup/setup_auctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use super::setup_contracts::*;

pub const DUMMY_DENOM: &str =
"ibc/773B5B5E24EC48005205A2EB35E6C0743EE47C9147E94BD5A4E0CBB63082314D";
pub const DUMMY_MIN_RESERVE_PRICE_MANAGER: &str = "min-reserve-price-manager";

pub fn setup_reserve_auction(
router: &mut StargazeApp,
Expand All @@ -39,6 +40,7 @@ pub fn setup_reserve_auction(
coin(MIN_RESERVE_PRICE, NATIVE_DENOM),
coin(MIN_RESERVE_PRICE, DUMMY_DENOM),
],
min_reserve_price_manager: DUMMY_MIN_RESERVE_PRICE_MANAGER.to_string(),
};
let auction = router
.instantiate_contract(
Expand Down
Loading
Loading