diff --git a/contracts/revenue/auction/src/auction.rs b/contracts/revenue/auction/src/auction.rs index f1613bf..fce765d 100644 --- a/contracts/revenue/auction/src/auction.rs +++ b/contracts/revenue/auction/src/auction.rs @@ -73,21 +73,21 @@ pub fn create_auction( } let auction = Auction { - auction_id: auction_id.clone(), + auction_id, nft_contract: nft_contract.clone(), token_id: token_id.clone(), seller: seller.clone(), - duration: duration, + duration, min_duration: config.min_duration, denom: denom.clone(), - reserve_price: reserve_price, + reserve_price, end_time: 0, auction_type: auction_type.clone(), bidder: None, amount: reserve_price, - creator_address: creator_address, - royalty_fee: royalty_fee, - protocol_fee: config.protocol_fee.clone(), + creator_address, + royalty_fee, + protocol_fee: config.protocol_fee, is_settled: false, }; // save auction @@ -130,7 +130,7 @@ pub fn set_royalty_fee( let nft_contract_addr = deps.api.addr_validate(&contract_addr)?; let creator_addr = deps.api.addr_validate(&creator)?; let royalty = Royalty { - royalty_fee: royalty_fee, + royalty_fee, creator: creator_addr, }; ROYALTIES.save(deps.storage, &nft_contract_addr, &royalty)?; @@ -234,8 +234,8 @@ pub fn place_bid( .funds .iter() .find(|c| c.denom == auction.denom) - .map(|c| Uint128::from(c.amount)) - .unwrap_or_else(|| Uint128::zero()); + .map(|c| c.amount) + .unwrap_or_else(Uint128::zero); //check time let block_time = env.block.time.seconds(); let mut messages: Vec = vec![]; @@ -340,7 +340,7 @@ pub fn place_bid( }; let min_bid_amount = - calculate_min_bid_amount(config.min_increment.clone(), auction.amount.clone())?; + calculate_min_bid_amount(config.min_increment, auction.amount)?; if bid_amount < min_bid_amount { return Err(ContractError::InvalidAmount( "bid amount too low".to_string(), @@ -732,7 +732,7 @@ pub fn only_owner(deps: Deps, _env: &Env, info: MessageInfo) -> Result St include_expired: None, })?, }))?; - Ok(deps.api.addr_validate(&owner_response.owner)?) + deps.api.addr_validate(&owner_response.owner) } pub fn query_auction(deps: Deps, auction_id: Uint128) -> StdResult { @@ -61,14 +61,8 @@ pub fn query_auction(deps: Deps, auction_id: Uint128) -> StdResult StdResult { - let creator_address = match auction.creator_address { - Some(v) => Some(v.to_string()), - None => None, - }; - let bidder = match auction.bidder { - Some(v) => Some(v.to_string()), - None => None, - }; + let creator_address = auction.creator_address.map(|v| v.to_string()); + let bidder = auction.bidder.map(|v| v.to_string()); Ok(AuctionResponse { auction_id: auction.auction_id, auction_type: auction.auction_type, @@ -80,10 +74,10 @@ fn _query_auction(auction: Auction) -> StdResult { denom: auction.denom, reserve_price: auction.reserve_price, end_time: auction.end_time, - bidder: bidder, + bidder, amount: auction.amount, is_settled: auction.is_settled, - creator_address: creator_address, + creator_address, royalty_fee: auction.royalty_fee, }) } @@ -130,7 +124,7 @@ pub fn query_auction_by_nft( auction_id }) .collect::>(); - return Ok(auction_ids); + Ok(auction_ids) } pub fn query_auction_by_seller( @@ -150,7 +144,7 @@ pub fn query_auction_by_seller( }) .collect::>(); - return Ok(auction_ids); + Ok(auction_ids) } pub fn query_auction_by_end_time( @@ -181,7 +175,7 @@ pub fn query_auction_by_end_time( }) .collect::>(); - return Ok(auction_ids); + Ok(auction_ids) } pub fn query_not_started_auctions( @@ -212,7 +206,7 @@ pub fn query_not_started_auctions( auction_id }) .collect::>(); - return Ok(auction_ids); + Ok(auction_ids) } pub fn query_auction_by_bidder( @@ -238,7 +232,7 @@ pub fn query_auction_by_bidder( auction_id }) .collect::>(); - return Ok(auction_ids); + Ok(auction_ids) } pub fn query_auction_by_amount( @@ -264,7 +258,7 @@ pub fn query_auction_by_amount( }) .collect::>(); - return Ok(auction_ids); + Ok(auction_ids) } pub fn query_calculate_price( @@ -312,7 +306,7 @@ pub fn query_bid_history_by_auction_id( pub fn query_bid_number(deps: Deps, auction_id: Uint128) -> StdResult { let count = BID_COUNT_BY_AUCTION_ID.load(deps.storage, auction_id.u128())?; - Ok(BidsCountResponse { count: count }) + Ok(BidsCountResponse { count }) } pub fn query_all_royalty( @@ -338,14 +332,11 @@ pub fn query_royalty_admin(deps: Deps, address: String) -> StdResult v, - None => false, - }; + let enable = admin.unwrap_or(false); Ok(RoyaltyAdminResponse { - address: address, - enable: enable, + address, + enable, }) } @@ -363,7 +354,7 @@ pub fn construct_action_response( Err(_) => (), }; } - Ok(AuctionListResponse { auctions: auctions }) + Ok(AuctionListResponse { auctions }) } fn parse_royalty(item: StdResult<(Addr, Royalty)>) -> StdResult { diff --git a/contracts/revenue/auction/src/state.rs b/contracts/revenue/auction/src/state.rs index 6568a64..62082cd 100644 --- a/contracts/revenue/auction/src/state.rs +++ b/contracts/revenue/auction/src/state.rs @@ -1,6 +1,6 @@ use cosmwasm_schema::cw_serde; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; + + use cosmwasm_std::{Addr, Decimal, Uint128}; use cw_storage_plus::{Item, Map}; diff --git a/contracts/revenue/auction/src/testing.rs b/contracts/revenue/auction/src/testing.rs index 7cdcc89..4dd05cb 100644 --- a/contracts/revenue/auction/src/testing.rs +++ b/contracts/revenue/auction/src/testing.rs @@ -10,8 +10,8 @@ use marketplace::auction::{ }; use std::str::FromStr; -use crate::auction::{calculate_fee, calculate_min_bid_amount}; -use crate::contract::{execute, instantiate, query}; + +use crate::contract::{execute, instantiate}; use crate::error::ContractError; use crate::mock_querier::mock_dependencies; use crate::querier::{ @@ -26,7 +26,7 @@ fn setup_contract(deps: DepsMut, accepted_denom: Vec) { min_increment: Decimal::from_str("0.1").unwrap(), duration: 86400, min_duration: 900, - accepted_denom: accepted_denom, + accepted_denom, protocol_addr: "collector".to_string(), max_royalty_fee: Decimal::percent(20), // 20% }; @@ -365,11 +365,11 @@ fn settle_buynow() { auction_id: Uint128::zero(), }; env.block.time = Timestamp::from_seconds(120); - let info = mock_info("random", &vec![]); + let info = mock_info("random", &[]); let res = execute(deps.as_mut(), env.clone(), info, settle_msg.clone()).unwrap(); assert_eq!(4, res.messages.len()); - let send_fund_collector_msg = res.messages.get(0).expect("no message"); + let send_fund_collector_msg = res.messages.first().expect("no message"); assert_eq!( &send_fund_collector_msg.msg, &CosmosMsg::Bank(BankMsg::Send { @@ -560,11 +560,11 @@ fn settle_buynow_with_royalty() { auction_id: Uint128::zero(), }; env.block.time = Timestamp::from_seconds(120); - let info = mock_info("random", &vec![]); + let info = mock_info("random", &[]); let res = execute(deps.as_mut(), env.clone(), info, settle_msg.clone()).unwrap(); assert_eq!(5, res.messages.len()); - let send_fund_collector_msg = res.messages.get(0).expect("no message"); + let send_fund_collector_msg = res.messages.first().expect("no message"); assert_eq!( &send_fund_collector_msg.msg, &CosmosMsg::Bank(BankMsg::Send { @@ -752,7 +752,7 @@ fn settle_auction() { let info = mock_info("fliper", &[Coin::new(1_100000, "uluna")]); let res = execute(deps.as_mut(), env.clone(), info, place_bid_msg.clone()).unwrap(); assert_eq!(1, res.messages.len()); - let send_fund_buyer_msg = res.messages.get(0).expect("no message"); + let send_fund_buyer_msg = res.messages.first().expect("no message"); assert_eq!( &send_fund_buyer_msg.msg, &CosmosMsg::Bank(BankMsg::Send { @@ -786,7 +786,7 @@ fn settle_auction() { let info = mock_info("buyer", &[Coin::new(1_210000, "uluna")]); let res = execute(deps.as_mut(), env.clone(), info, place_bid_msg.clone()).unwrap(); assert_eq!(1, res.messages.len()); - let send_fund_fliper_msg = res.messages.get(0).expect("no message"); + let send_fund_fliper_msg = res.messages.first().expect("no message"); assert_eq!( &send_fund_fliper_msg.msg, &CosmosMsg::Bank(BankMsg::Send { @@ -819,7 +819,7 @@ fn settle_auction() { let settle_msg = ExecuteMsg::Settle { auction_id: Uint128::zero(), }; - let info = mock_info("random", &vec![]); + let info = mock_info("random", &[]); let err = execute(deps.as_mut(), env.clone(), info, settle_msg.clone()).unwrap_err(); match err { ContractError::InvalidAuction { .. } => {} @@ -828,11 +828,11 @@ fn settle_auction() { // settle env.block.time = Timestamp::from_seconds(86900); - let info = mock_info("random", &vec![]); + let info = mock_info("random", &[]); let res = execute(deps.as_mut(), env.clone(), info, settle_msg.clone()).unwrap(); assert_eq!(4, res.messages.len()); - let send_fund_collector_msg = res.messages.get(0).expect("no message"); + let send_fund_collector_msg = res.messages.first().expect("no message"); assert_eq!( &send_fund_collector_msg.msg, &CosmosMsg::Bank(BankMsg::Send { @@ -1024,7 +1024,7 @@ fn check_freeze_and_cancel_auction() { let res = execute(deps.as_mut(), env, info, cancel_msg).unwrap(); assert_eq!(2, res.messages.len()); - let send_nft_msg = res.messages.get(0).expect("no message"); + let send_nft_msg = res.messages.first().expect("no message"); assert_eq!( &send_nft_msg.msg, &CosmosMsg::Wasm(WasmMsg::Execute { @@ -1116,7 +1116,7 @@ fn admin_cancel() { }; let res = execute(deps.as_mut(), env, info, admin_cancel_msg).unwrap(); assert_eq!(1, res.messages.len()); - let send_nft_msg = res.messages.get(0).expect("no message"); + let send_nft_msg = res.messages.first().expect("no message"); assert_eq!( &send_nft_msg.msg, &CosmosMsg::Wasm(WasmMsg::Execute { @@ -1172,7 +1172,7 @@ fn admin_cancel() { let res = execute(deps.as_mut(), env, info, admin_cancel_msg).unwrap(); assert_eq!(2, res.messages.len()); - let send_fund_bidder_msg = res.messages.get(0).expect("no message"); + let send_fund_bidder_msg = res.messages.first().expect("no message"); assert_eq!( &send_fund_bidder_msg.msg, &CosmosMsg::Bank(BankMsg::Send { diff --git a/contracts/revenue/fair-burn/src/contract.rs b/contracts/revenue/fair-burn/src/contract.rs index 26ead8c..f6c3a05 100644 --- a/contracts/revenue/fair-burn/src/contract.rs +++ b/contracts/revenue/fair-burn/src/contract.rs @@ -94,7 +94,7 @@ pub fn execute_fair_burn( Some(recipient) => { payout_map .entry(recipient.to_string()) - .or_insert(vec![]) + .or_default() .push(dist_coin.clone()); } None => { @@ -114,14 +114,14 @@ pub fn execute_fair_burn( payout_map .entry(fair_burn_pool_key.clone()) - .or_insert(vec![]) + .or_default() .push(fee_coin.clone()); if let Some(dist_coin) = dist_coin { let recipient = recipient.as_ref().unwrap().to_string(); payout_map .entry(recipient) - .or_insert(vec![]) + .or_default() .push(dist_coin.clone()); } } diff --git a/packages/actions/mint-hooks/derive/src/lib.rs b/packages/actions/mint-hooks/derive/src/lib.rs index 2b91bb0..ba610b1 100644 --- a/packages/actions/mint-hooks/derive/src/lib.rs +++ b/packages/actions/mint-hooks/derive/src/lib.rs @@ -40,7 +40,7 @@ fn merge_variants(metadata: TokenStream, left: TokenStream, right: TokenStream) }; // insert variants from the right to the left - variants.extend(to_add.into_iter()); + variants.extend(to_add); quote! { #left }.into() }