8000 [1.0.rc-1] Crowdfund & Auction Adjustments by joemonem · Pull Request #386 · andromedaprotocol/andromeda-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[1.0.rc-1] Crowdfund & Auction Adjustments #386

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

Merged
merged 3 commits into from
Apr 2, 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
42 changes: 19 additions & 23 deletions contracts/non-fungible-tokens/andromeda-auction/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Respon
token_id,
token_address,
start_time,
duration,
end_time,
coin_denom,
whitelist,
min_bid,
Expand All @@ -136,7 +136,7 @@ pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Respon
token_id,
token_address,
start_time,
duration,
end_time,
coin_denom,
whitelist,
min_bid,
Expand Down Expand Up @@ -180,7 +180,7 @@ fn handle_receive_cw721(
match from_json(&msg.msg)? {
Cw721HookMsg::StartAuction {
start_time,
duration,
end_time,
coin_denom,
whitelist,
min_bid,
Expand All @@ -189,7 +189,7 @@ fn handle_receive_cw721(
msg.sender,
msg.token_id,
start_time,
duration,
10000 end_time,
coin_denom,
whitelist,
min_bid,
Expand All @@ -216,25 +216,24 @@ fn execute_start_auction(
sender: String,
token_id: String,
start_time: Option<Milliseconds>,
duration: Milliseconds,
end_time: Milliseconds,
coin_denom: String,
whitelist: Option<Vec<Addr>>,
min_bid: Option<Uint128>,
) -> Result<Response, ContractError> {
validate_denom(&ctx.deps.querier, coin_denom.clone())?;
ensure!(!duration.is_zero(), ContractError::InvalidExpiration {});
let ExecuteContext {
deps, info, env, ..
} = ctx;

// If start time wasn't provided, it will be set as the current_time
let (start_expiration, current_time) = get_and_validate_start_time(&env, start_time)?;
let (start_expiration, _current_time) = get_and_validate_start_time(&env, start_time)?;
let end_expiration = expiration_from_milliseconds(end_time)?;

let end_expiration = expiration_from_milliseconds(
start_time
.unwrap_or(current_time)
.plus_milliseconds(duration),
)?;
ensure!(
end_expiration > start_expiration,
ContractError::StartTimeAfterEndTime {}
);

let token_address = info.sender.to_string();

Expand Down Expand Up @@ -277,7 +276,7 @@ fn execute_update_auction(
token_id: String,
token_address: String,
start_time: Option<Milliseconds>,
duration: Milliseconds,
end_time: Milliseconds,
coin_denom: String,
whitelist: Option<Vec<Addr>>,
min_bid: Option<Uint128>,
Expand All @@ -297,19 +296,16 @@ fn execute_update_auction(
!token_auction_state.start_time.is_expired(&env.block),
ContractError::AuctionAlreadyStarted {}
);
ensure!(
duration > Milliseconds::zero(),
ContractError::InvalidExpiration {}
);
ensure!(!end_time.is_zero(), ContractError::InvalidExpiration {});

// If start time wasn't provided, it will be set as the current_time
let (start_expiration, current_time) = get_and_validate_start_time(&env, start_time)?;
let (start_expiration, _current_time) = get_and_validate_start_time(&env, start_time)?;
let end_expiration = expiration_from_milliseconds(end_time)?;

let end_expiration = expiration_from_milliseconds(
start_time
.unwrap_or(current_time)
.plus_milliseconds(duration),
)?;
ensure!(
end_expiration > start_expiration,
ContractError::StartTimeAfterEndTime {}
);

token_auction_state.start_time = start_expiration;
token_auction_state.end_time = end_expiration;
Expand Down
4 changes: 2 additions & 2 deletions contracts/non-fungible-tokens/andromeda-auction/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ pub fn mock_auction_instantiate_msg(

pub fn mock_start_auction(
start_time: Option<Milliseconds>,
duration: Milliseconds,
end_time: Milliseconds,
coin_denom: String,
min_bid: Option<Uint128>,
whitelist: Option<Vec<Addr>>,
) -> Cw721HookMsg {
Cw721HookMsg::StartAuction {
start_time,
duration,
end_time,
coin_denom,
min_bid,
whitelist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ fn query_latest_auction_state_helper(deps: Deps, env: Env) -> AuctionStateRespon
from_json(query(deps, env, query_msg).unwrap()).unwrap()
}

fn current_time() -> u64 {
mock_env().block.time.nanos() / MILLISECONDS_TO_NANOSECONDS_RATIO
}

fn start_auction(deps: DepsMut, whitelist: Option<Vec<Addr>>, min_bid: Option<Uint128>) {
let hook_msg = Cw721HookMsg::StartAuction {
start_time: None,
duration: Milliseconds(10_000),
end_time: Milliseconds::from_nanos((current_time() + 20_000_000) * 1_000_000),
coin_denom: "uusd".to_string(),
whitelist,
min_bid,
Expand All @@ -73,7 +77,7 @@ fn start_auction(deps: DepsMut, whitelist: Option<Vec<Addr>>, min_bid: Option<Ui

fn assert_auction_created(deps: Deps, whitelist: Option<Vec<Addr>>, min_bid: Option<Uint128>) {
let current_time = mock_env().block.time.nanos() / MILLISECONDS_TO_NANOSECONDS_RATIO;
let duration = 10_000;
let duration = 20_000_000;
assert_eq!(
TokenAuctionState {
start_time: Expiration::AtTime(Timestamp::from_nanos((current_time + 1) * 1_000_000)),
Expand Down Expand Up @@ -350,7 +354,7 @@ fn execute_place_bid_multiple_bids() {
);
let mut expected_response = AuctionStateResponse {
start_time: Expiration::AtTime(Timestamp::from_nanos(1571797419880000000)),
end_time: Expiration::AtTime(Timestamp::from_nanos(1571797429879000000)),
end_time: Expiration::AtTime(Timestamp::from_nanos(1571817419879000000)),
high_bidder_addr: "sender".to_string(),
high_bidder_amount: Uint128::from(100u128),
auction_id: Uint128::from(1u128),
Expand Down Expand Up @@ -550,7 +554,7 @@ fn execute_start_auction_start_time_in_past() {

let hook_msg = Cw721HookMsg::StartAuction {
start_time: Some(Milliseconds(100000)),
duration: Milliseconds(100000),
end_time: Milliseconds(100000),
coin_denom: "uusd".to_string(),
whitelist: None,
min_bid: None,
Expand Down Expand Up @@ -581,7 +585,7 @@ fn execute_start_auction_zero_start_time() {

let hook_msg = Cw721HookMsg::StartAuction {
start_time: Some(Milliseconds::zero()),
duration: Milliseconds(1),
end_time: Milliseconds(1),
coin_denom: "uusd".to_string(),
whitelist: None,
min_bid: None,
Expand Down Expand Up @@ -611,7 +615,7 @@ fn execute_start_auction_start_time_not_provided() {

let hook_msg = Cw721HookMsg::StartAuction {
start_time: None,
duration: Milliseconds(1),
end_time: Milliseconds::from_nanos((current_time() + 20_000_000) * 1_000_000),
coin_denom: "uusd".to_string(),
whitelist: None,
min_bid: None,
Expand All @@ -634,7 +638,7 @@ fn execute_start_auction_zero_duration() {

let hook_msg = Cw721HookMsg::StartAuction {
start_time: Some(Milliseconds(100)),
duration: Milliseconds::zero(),
end_time: Milliseconds::zero(),
coin_denom: "uusd".to_string(),
< 292D span class='blob-code-inner blob-code-marker ' data-code-marker=" "> whitelist: None,
min_bid: None,
Expand All @@ -650,7 +654,7 @@ fn execute_start_auction_zero_duration() {
let info = mock_info(MOCK_TOKEN_ADDR, &[]);
let res = execute(deps.as_mut(), env, info, msg);

assert_eq!(ContractError::InvalidExpiration {}, res.unwrap_err());
assert_eq!(ContractError::StartTimeAfterEndTime {}, res.unwrap_err());
}

// #[test]
Expand Down Expand Up @@ -693,7 +697,7 @@ fn execute_update_auction_zero_start() {
token_id: MOCK_UNCLAIMED_TOKEN.to_owned(),
token_address: MOCK_TOKEN_ADDR.to_string(),
start_time: Some(Milliseconds::zero()),
duration: Milliseconds(1),
end_time: Milliseconds(1),
coin_denom: "uusd".to_string(),
whitelist: None,
min_bid: None,
Expand Down Expand Up @@ -724,7 +728,7 @@ fn execute_update_auction_zero_duration() {
token_id: MOCK_UNCLAIMED_TOKEN.to_owned(),
token_address: MOCK_TOKEN_ADDR.to_string(),
start_time: Some(Milliseconds(100000)),
duration: Milliseconds::zero(),
end_time: Milliseconds::zero(),
coin_denom: "uusd".to_string(),
whitelist: None,
min_bid: None,
Expand All @@ -749,7 +753,7 @@ fn execute_update_auction_unauthorized() {
token_id: MOCK_UNCLAIMED_TOKEN.to_owned(),
token_address: MOCK_TOKEN_ADDR.to_string(),
start_time: Some(Milliseconds(100000)),
duration: Milliseconds(100),
end_time: Milliseconds(100),
coin_denom: "uluna".to_string(),
whitelist: Some(vec![Addr::unchecked("user")]),
min_bid: None,
Expand All @@ -772,7 +776,7 @@ fn execute_update_auction_auction_started() {
token_id: MOCK_UNCLAIMED_TOKEN.to_owned(),
token_address: MOCK_TOKEN_ADDR.to_string(),
start_time: Some(Milliseconds(100000)),
duration: Milliseconds(100),
end_time: Milliseconds(100),
coin_denom: "uluna".to_string(),
whitelist: Some(vec![Addr::unchecked("user")]),
min_bid: None,
Expand All @@ -797,7 +801,7 @@ fn execute_update_auction() {
token_id: MOCK_UNCLAIMED_TOKEN.to_owned(),
token_address: MOCK_TOKEN_ADDR.to_string(),
start_time: Some(Milliseconds(1571711019879 + 1)),
duration: Milliseconds(100000),
end_time: Milliseconds(1571711019879 + 2),
coin_denom: "uluna".to_string(),
whitelist: Some(vec![Addr::unchecked("user")]),
min_bid: None,
Expand All @@ -811,7 +815,7 @@ fn execute_update_auction() {
assert_eq!(
TokenAuctionState {
start_time: Expiration::AtTime(Timestamp::from_nanos(1571711019880000000)),
end_time: Expiration::AtTime(Timestamp::from_nanos(1571711119880000000)),
end_time: Expiration::AtTime(Timestamp::from_nanos(1571711019881000000)),
high_bidder_addr: Addr::unchecked(""),
high_bidder_amount: Uint128::zero(),
coin_denom: "uluna".to_string(),
Expand Down Expand Up @@ -839,7 +843,7 @@ fn execute_start_auction_after_previous_finished() {

let hook_msg = Cw721HookMsg::StartAuction {
start_time: None,
duration: Milliseconds(100000),
end_time: Milliseconds::from_nanos((current_time() + 20_000_000) * 1_000_000),
coin_denom: "uusd".to_string(),
whitelist: None,
min_bid: None,
Expand All @@ -851,16 +855,16 @@ fn execute_start_auction_after_previous_finished() {
});
let mut env = mock_env();
// Auction ended by that time
env.block.time = env.block.time.plus_days(1);
env.block.time = env.block.time.plus_hours(1);

let info = mock_info(MOCK_TOKEN_ADDR, &[]);
let res = execute(deps.as_mut(), env, info, msg).unwrap();
assert_eq!(
Response::new()
.add_attributes(vec![
attr("action", "start_auction"),
attr("start_time", "expiration time: 1571883819.880000000"),
attr("end_time", "expiration time: 1571883919.879000000"),
attr("start_time", "expiration time: 1571801019.880000000"),
attr("end_time", "expiration time: 1571817419.879000000"),
attr("coin_denom", "uusd"),
attr("auction_id", "2"),
attr("whitelist", "None"),
Expand Down Expand Up @@ -1034,7 +1038,7 @@ fn execute_claim_auction_already_claimed() {

let hook_msg = Cw721HookMsg::StartAuction {
start_time: None,
duration: Milliseconds(100000),
end_time: Milliseconds::from_nanos((current_time() + 20_000_000) * 1_000_000),
coin_denom: "uusd".to_string(),
whitelist: None,
min_bid: None,
Expand Down
22 changes: 12 additions & 10 deletions contracts/non-fungible-tokens/andromeda-crowdfund/src/contract.rs
10956
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use andromeda_non_fungible_tokens::{
use andromeda_std::{
ado_base::ownership::OwnershipMessage,
amp::{messages::AMPPkt, recipient::Recipient, AndrAddr},
common::{actions::call_action, expiration::get_and_validate_start_time, Milliseconds},
common::{
actions::call_action,
expiration::{expiration_from_milliseconds, get_and_validate_start_time},
Milliseconds,
},
};
use andromeda_std::{ado_contract::ADOContract, common::context::ExecuteContext};

Expand All @@ -30,7 +34,7 @@ use cosmwasm_std::{
Order, QuerierWrapper, QueryRequest, Reply, Response, StdError, Storage, SubMsg, Uint128,
WasmMsg, WasmQuery,
};
use cw721::{ContractInfoResponse, Expiration, TokensResponse};
use cw721::{ContractInfoResponse, TokensResponse};
use cw_utils::nonpayable;
use std::cmp;

Expand Down Expand Up @@ -286,7 +290,7 @@ fn execute_update_token_contract(
fn execute_start_sale(
ctx: ExecuteContext,
start_time: Option<Milliseconds>,
end_time: Expiration,
end_time: Milliseconds,
price: Coin,
min_tokens_sold: Uint128,
max_amount_per_wallet: Option<u32>,
Expand All @@ -307,14 +311,12 @@ fn execute_start_sale(
// If start time wasn't provided, it will be set as the current_time
let (start_expiration, _current_time) = get_and_validate_start_time(&env, start_time)?;

let end_expiration = expiration_from_milliseconds(end_time)?;

ensure!(
end_time > start_expiration,
end_expiration > start_expiration,
ContractError::StartTimeAfterEndTime {}
);
ensure!(
!matches!(end_time, Expiration::Never {}),
ContractError::ExpirationMustNotBeNever {}
);

SALE_CONDUCTED.save(deps.storage, &true)?;
let state = STATE.may_load(deps.storage)?;
Expand All @@ -326,7 +328,7 @@ fn execute_start_sale(
STATE.save(
deps.storage,
&State {
end_time,
end_time: end_expiration,
price,
min_tokens_sold,
max_amount_per_wallet,
Expand All @@ -342,7 +344,7 @@ fn execute_start_sale(
Ok(Response::new()
.add_attribute("action", "start_sale")
.add_attribute("start_time", start_expiration.to_string())
.add_attribute("end_time", end_time.to_string())
.add_attribute("end_time", end_expiration.to_string())
.add_attribute("price", price_str)
.add_attribute("min_tokens_sold", min_tokens_sold)
.add_attribute("max_amount_per_wallet", max_amount_per_wallet.to_string()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use andromeda_non_fungible_tokens::{
use andromeda_std::{ado_base::modules::Module, amp::AndrAddr};
use andromeda_std::{amp::Recipient, common::Milliseconds};
use cosmwasm_std::{Coin, Empty, Uint128};
use cw721::Expiration;
use cw_multi_test::{Contract, ContractWrapper};

pub fn mock_andromeda_crowdfund() -> Box<dyn Contract<Empty>> {
Expand All @@ -34,7 +33,7 @@ pub fn mock_crowdfund_instantiate_msg(

pub fn mock_start_crowdfund_msg(
start_time: Option<Milliseconds>,
end_time: Expiration,
end_time: Milliseconds,
price: Coin,
min_tokens_sold: Uint128,
max_amount_per_wallet: Option<u32>,
Expand Down
Loading
0