diff --git a/contracts/marketplace/src/execute.rs b/contracts/marketplace/src/execute.rs index e5a1251f..663d5453 100644 --- a/contracts/marketplace/src/execute.rs +++ b/contracts/marketplace/src/execute.rs @@ -586,8 +586,6 @@ pub fn execute_process_renewals( .querier .query_wasm_smart::(name_minter, &SgNameMinterQueryMsg::Params {})?; - let name_collection = NAME_COLLECTION.load(deps.storage)?; - let mut response = Response::new(); for renewable_ask in renewable_asks { @@ -596,7 +594,6 @@ pub fn execute_process_renewals( &env, &sudo_params, &name_minter_params, - &name_collection, renewable_ask, response, )?; diff --git a/contracts/marketplace/src/helpers.rs b/contracts/marketplace/src/helpers.rs index 7c04667d..3953542f 100644 --- a/contracts/marketplace/src/helpers.rs +++ b/contracts/marketplace/src/helpers.rs @@ -3,7 +3,7 @@ use std::cmp::max; use crate::{ execute::{finalize_sale, store_ask}, msg::{ExecuteMsg, QueryMsg}, - state::{ask_key, asks, bid_key, bids, Ask, Bid, SudoParams, RENEWAL_QUEUE}, + state::{bid_key, bids, Ask, Bid, SudoParams, RENEWAL_QUEUE}, ContractError, }; use cosmwasm_schema::cw_serde; @@ -11,7 +11,6 @@ use cosmwasm_std::{ coins, ensure, to_json_binary, Addr, BankMsg, Deps, DepsMut, Env, Event, Order, QuerierWrapper, QueryRequest, StdError, StdResult, Timestamp, Uint128, WasmMsg, WasmQuery, }; -use cw721::Cw721ExecuteMsg; use cw_storage_plus::Bound; use sg_name_common::{charge_fees, SECONDS_PER_YEAR}; use sg_name_minter::SudoParams as NameMinterParams; @@ -155,13 +154,15 @@ pub fn renew_name( renewal_price: Uint128, mut response: Response, ) -> Result { - // Take renewal payment - ask.renewal_fund -= renewal_price; - charge_fees( - &mut response, - sudo_params.trading_fee_percent, - renewal_price, - ); + if !renewal_price.is_zero() { + // Take renewal payment + ask.renewal_fund -= renewal_price; + charge_fees( + &mut response, + sudo_params.trading_fee_percent, + renewal_price, + ); + } // Update renewal time RENEWAL_QUEUE.remove(deps.storage, (ask.renewal_time.seconds(), ask.id)); @@ -217,33 +218,11 @@ fn sell_name( Ok(response) } -fn burn_name( - deps: DepsMut, - collection: &Addr, - ask: Ask, - mut response: Response, -) -> Result { - response = response.add_message(WasmMsg::Execute { - contract_addr: collection.to_string(), - msg: to_json_binary(&Cw721ExecuteMsg::Burn { - token_id: ask.token_id.to_string(), - })?, - funds: vec![], - }); - - // Delete ask - RENEWAL_QUEUE.remove(deps.storage, (ask.renewal_time.seconds(), ask.id)); - asks().remove(deps.storage, ask_key(&ask.token_id))?; - - Ok(response) -} - pub fn process_renewal( deps: DepsMut, env: &Env, sudo_params: &SudoParams, name_minter_params: &NameMinterParams, - collection: &Addr, mut ask: Ask, mut response: Response, ) -> Result { @@ -264,34 +243,33 @@ pub fn process_renewal( name_minter_params.base_price.u128(), )?; - // If the renewal fund is sufficient, renew it - if ask.renewal_fund >= renewal_price { - process_renewal_event = process_renewal_event.add_attribute("action", "renew"); - response = response.add_event(process_renewal_event); - - return renew_name(deps, env, sudo_params, ask, renewal_price, response); - } - - // Renewal fund is insufficient, send it back to the owner - if !ask.renewal_fund.is_zero() { - response = response.add_message(BankMsg::Send { - to_address: ask.seller.to_string(), - amount: coins(ask.renewal_fund.u128(), NATIVE_DENOM), - }); - ask.renewal_fund = Uint128::zero(); - } - if let Some(bid) = valid_bid { - // The renewal fund is insufficient, sell to the highest bidder - process_renewal_event = process_renewal_event.add_attribute("action", "sell"); - response = response.add_event(process_renewal_event); - - sell_name(deps, env, ask, bid, response) + // If the renewal fund is sufficient, renew it + if ask.renewal_fund >= renewal_price { + process_renewal_event = process_renewal_event.add_attribute("action", "renew"); + response = response.add_event(process_renewal_event); + + renew_name(deps, env, sudo_params, ask, renewal_price, response) + } else { + // Renewal fund is insufficient, send it back to the owner + if !ask.renewal_fund.is_zero() { + response = response.add_message(BankMsg::Send { + to_address: ask.seller.to_string(), + amount: coins(ask.renewal_fund.u128(), NATIVE_DENOM), + }); + ask.renewal_fund = Uint128::zero(); + } + + // The renewal fund is insufficient, sell to the highest bidder + process_renewal_event = process_renewal_event.add_attribute("action", "sell"); + response = response.add_event(process_renewal_event); + + sell_name(deps, env, ask, bid, response) + } } else { - // The renewal fund is insufficient, and there is no valid bid, burn it - process_renewal_event = process_renewal_event.add_attribute("action", "burn"); + process_renewal_event = process_renewal_event.add_attribute("action", "renew"); response = response.add_event(process_renewal_event); - burn_name(deps, collection, ask, response) + renew_name(deps, env, sudo_params, ask, Uint128::zero(), response) } } diff --git a/contracts/marketplace/src/sudo.rs b/contracts/marketplace/src/sudo.rs index 5836f847..508b10f7 100644 --- a/contracts/marketplace/src/sudo.rs +++ b/contracts/marketplace/src/sudo.rs @@ -182,15 +182,12 @@ pub fn sudo_end_block(mut deps: DepsMut, env: Env) -> Result(name_minter, &SgNameMinterQueryMsg::Params {})?; - let name_collection = NAME_COLLECTION.load(deps.storage)?; - for renewable_ask in renewable_asks { response = process_renewal( deps.branch(), &env, &sudo_params, &name_minter_params, - &name_collection, renewable_ask, response, )?; diff --git a/contracts/name-minter/src/integration_tests.rs b/contracts/name-minter/src/integration_tests.rs index 050baf20..0fe30cd5 100644 --- a/contracts/name-minter/src/integration_tests.rs +++ b/contracts/name-minter/src/integration_tests.rs @@ -1332,7 +1332,7 @@ mod query { let ask = result.unwrap().unwrap(); assert_eq!(ask.seller, USER.to_string()); - assert_eq!(ask.renewal_fund, Uint128::zero()); + assert_eq!(ask.renewal_fund, renewal_price.amount); let expected_renewal_time = app.block_info().time.plus_seconds(SECONDS_PER_YEAR); assert_eq!(ask.renewal_time, expected_renewal_time); @@ -1444,7 +1444,7 @@ mod query { } #[test] - fn process_renewals_burn() { + fn process_renewals_renew_free() { let mut app = instantiate_contracts(None, None, None); mint_and_list(&mut app, NAME, USER, None).unwrap(); @@ -1497,7 +1497,7 @@ mod query { }, ); assert!(result.is_ok()); - assert!(result.unwrap().is_none()); + assert!(result.unwrap().is_some()); } #[test] diff --git a/scripts/migrate_mkt.sh b/scripts/migrate_mkt.sh old mode 100644 new mode 100755 index 9ca742c4..1bfdd05f --- a/scripts/migrate_mkt.sh +++ b/scripts/migrate_mkt.sh @@ -9,7 +9,7 @@ MSG=$(cat <