From 825de83d8e837e12ce962e318297aee9fdc1907b Mon Sep 17 00:00:00 2001 From: nahem Date: Tue, 30 Jul 2024 19:29:37 +0200 Subject: [PATCH] fix: add to the denom to mint --- .../injective-auction-pool/src/contract.rs | 4 +-- .../injective-auction-pool/src/executions.rs | 26 +++++++++---------- .../injective-auction-pool/src/helpers.rs | 25 ++++++++++-------- .../injective-auction-pool/src/queries.rs | 14 +++++++--- contracts/injective-auction-pool/src/state.rs | 2 +- .../src/tests/unit_tests.rs | 20 +++++++------- .../injective_auction/src/auction_pool.rs | 21 ++++++++++++--- 7 files changed, 68 insertions(+), 44 deletions(-) diff --git a/contracts/injective-auction-pool/src/contract.rs b/contracts/injective-auction-pool/src/contract.rs index fd4d62b..eacd88e 100644 --- a/contracts/injective-auction-pool/src/contract.rs +++ b/contracts/injective-auction-pool/src/contract.rs @@ -66,7 +66,6 @@ pub fn instantiate( Ok(Response::default() .add_messages(messages) .add_attribute("action", "instantiate") - .add_attributes(attributes)) } @@ -132,6 +131,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { } => queries::query_treasure_chest_contracts(deps, start_after, limit), QueryMsg::BiddingBalance {} => queries::query_bidding_balance(deps), QueryMsg::FundsLocked {} => to_json_binary(&FUNDS_LOCKED.load(deps.storage)?), - QueryMsg::QueryCurrentAuctionBasket { } => queries::query_current_auction_basket(deps) + QueryMsg::CurrentAuctionBasket {} => queries::query_current_auction_basket(deps), + QueryMsg::UnsettledAuction {} => queries::query_unsettled_auction(deps), } } diff --git a/contracts/injective-auction-pool/src/executions.rs b/contracts/injective-auction-pool/src/executions.rs index 92e4146..d29df0d 100644 --- a/contracts/injective-auction-pool/src/executions.rs +++ b/contracts/injective-auction-pool/src/executions.rs @@ -2,9 +2,9 @@ use cosmwasm_std::{ attr, coins, to_json_binary, BankMsg, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Response, Uint128, WasmMsg, }; +use injective_auction::auction_pool::ExecuteMsg::TryBid; use injective_std::types::cosmos::base::v1beta1::Coin; use injective_std::types::injective::auction::v1beta1::MsgBid; -use injective_auction::{ auction_pool::ExecuteMsg::TryBid}; use crate::{ helpers::{new_auction_round, query_current_auction, validate_percentage}, @@ -112,9 +112,7 @@ pub(crate) fn join_pool( let config = CONFIG.load(deps.storage)?; let amount = cw_utils::must_pay(&info, &config.native_denom)?; - let current_auction_round = query_current_auction(deps.as_ref())? - .auction_round; - // .ok_or(ContractError::CurrentAuctionQueryError)?; + let current_auction_round = query_current_auction(deps.as_ref())?.auction_round; // prevents the user from joining the pool if the auction round is over if auction_round != current_auction_round.u64() { @@ -130,7 +128,7 @@ pub(crate) fn join_pool( let lp_subdenom = UNSETTLED_AUCTION.load(deps.storage)?.lp_subdenom; messages.push(config.token_factory_type.mint( env.contract.address.clone(), - format!("auction.{}", lp_subdenom).as_str(), + format!("factory/{}/auction.{}", env.contract.address.clone(), lp_subdenom).as_str(), amount, )); @@ -184,7 +182,8 @@ pub(crate) fn exit_pool( // prevents the user from exiting the pool if the contract has already bid on the auction if FUNDS_LOCKED.load(deps.storage)? - && env.block.time.seconds() < current_auction_round_response.auction_closing_time.i64() as u64 + && env.block.time.seconds() + < current_auction_round_response.auction_closing_time.i64() as u64 { return Err(ContractError::PooledAuctionLocked); } @@ -232,9 +231,8 @@ pub(crate) fn try_bid( } let current_auction_round_response = query_current_auction(deps.as_ref())?; - let current_auction_round = current_auction_round_response - .auction_round; - //.ok_or(ContractError::CurrentAuctionQueryError)?; + let current_auction_round = current_auction_round_response.auction_round; + //.ok_or(ContractError::CurrentAuctionQueryError)?; // prevents the contract from bidding on the wrong auction round if auction_round != current_auction_round.u64() { @@ -255,8 +253,9 @@ pub(crate) fn try_bid( // minimum_allowed_bid = (highest_bid_amount * (1 + min_next_bid_increment_rate)) + 1 // the latest + 1 is to make sure the auction module accepts the bid all the times let minimum_allowed_bid = current_auction_round_response - .highest_bid_amount.to_string() - // .unwrap_or(0.to_string()) + .highest_bid_amount + .to_string() + // .unwrap_or(0.to_string()) .parse::()? .checked_mul((Decimal::one().checked_add(config.min_next_bid_increment_rate))?)? .to_uint_ceil() @@ -321,9 +320,8 @@ pub fn settle_auction( } let current_auction_round_response = query_current_auction(deps.as_ref())?; - let current_auction_round = current_auction_round_response - .auction_round; -// .ok_or(ContractError::CurrentAuctionQueryError)?; + let current_auction_round = current_auction_round_response.auction_round; + // .ok_or(ContractError::CurrentAuctionQueryError)?; // prevents the contract from settling the auction if the auction round has not finished if current_auction_round.u64() == unsettled_auction.auction_round { diff --git a/contracts/injective-auction-pool/src/helpers.rs b/contracts/injective-auction-pool/src/helpers.rs index 9363542..5fd968c 100644 --- a/contracts/injective-auction-pool/src/helpers.rs +++ b/contracts/injective-auction-pool/src/helpers.rs @@ -1,7 +1,10 @@ use std::str::FromStr; -use cosmwasm_std::{attr, instantiate2_address, to_json_binary, Addr, Attribute, BankMsg, Binary, CodeInfoResponse, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, OverflowError, Uint128, WasmMsg, StdResult, QueryRequest}; -use injective_std::types::injective::auction::v1beta1::{AuctionQuerier, QueryCurrentAuctionBasketResponse}; +use cosmwasm_std::{ + attr, instantiate2_address, to_json_binary, Addr, Attribute, BankMsg, Binary, CodeInfoResponse, + Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, OverflowError, QueryRequest, + StdResult, Uint128, WasmMsg, +}; use crate::{ state::{Auction, BIDDING_BALANCE, CONFIG, TREASURE_CHEST_CONTRACTS, UNSETTLED_AUCTION}, @@ -21,15 +24,14 @@ pub(crate) fn new_auction_round( // fetch current auction details and save them in the contract state let current_auction_round_response = query_current_auction(deps.as_ref())?; - let current_auction_round = current_auction_round_response - .auction_round; - // .ok_or(ContractError::CurrentAuctionQueryError)?; + let current_auction_round = current_auction_round_response.auction_round; let current_basket = current_auction_round_response .amount .iter() .map(|coin| Coin { - amount: Uint128::from_str(&coin.amount.to_string()).expect("Failed to parse coin amount"), + amount: Uint128::from_str(&coin.amount.to_string()) + .expect("Failed to parse coin amount"), denom: coin.denom.clone(), }) .collect(); @@ -179,7 +181,8 @@ pub(crate) fn new_auction_round( basket, auction_round: current_auction_round_response.auction_round.u64(), lp_subdenom: new_subdenom, - closing_time: current_auction_round_response.auction_closing_time.i64() as u64, + closing_time: current_auction_round_response.auction_closing_time.i64() + as u64, }, )?; attributes.push(attr( @@ -210,7 +213,8 @@ pub(crate) fn new_auction_round( .collect(), auction_round: current_auction_round_response.auction_round.u64(), lp_subdenom: unsettled_auction.lp_subdenom, - closing_time: current_auction_round_response.auction_closing_time .i64() as u64, + closing_time: current_auction_round_response.auction_closing_time.i64() + as u64, }, )?; attributes.push(attr( @@ -267,12 +271,11 @@ pub(crate) fn query_current_auction( Ok(current_auction_basket_response) */ - let current_auction_basket_response: crate::state:: QueryCurrentAuctionBasketResponse = + let current_auction_basket_response: crate::state::QueryCurrentAuctionBasketResponse = deps.querier.query(&QueryRequest::Stargate { path: "/injective.auction.v1beta1.Query/CurrentAuctionBasket".to_string(), data: [].into(), })?; - Ok(current_auction_basket_response) + Ok(current_auction_basket_response) } - diff --git a/contracts/injective-auction-pool/src/queries.rs b/contracts/injective-auction-pool/src/queries.rs index 68b804d..e055e80 100644 --- a/contracts/injective-auction-pool/src/queries.rs +++ b/contracts/injective-auction-pool/src/queries.rs @@ -1,11 +1,12 @@ +use crate::helpers::query_current_auction; +use crate::state::{ + BIDDING_BALANCE, CONFIG, TREASURE_CHEST_CONTRACTS, UNSETTLED_AUCTION, WHITELISTED_ADDRESSES, +}; use cosmwasm_std::{to_json_binary, Binary, Deps, StdResult}; -use injective_std::types::injective::auction::v1beta1::QueryCurrentAuctionBasketResponse; use injective_auction::auction_pool::{ BiddingBalanceResponse, ConfigResponse, TreasureChestContractsResponse, WhitelistedAddressesResponse, }; -use crate::helpers::query_current_auction; -use crate::state::{BIDDING_BALANCE, CONFIG, TREASURE_CHEST_CONTRACTS, WHITELISTED_ADDRESSES}; pub fn query_config(deps: Deps) -> StdResult { to_json_binary(&ConfigResponse { @@ -48,8 +49,15 @@ pub fn query_bidding_balance(deps: Deps) -> StdResult { bidding_balance, }) } + pub fn query_current_auction_basket(deps: Deps) -> StdResult { let current_auction_round_response = query_current_auction(deps)?; to_json_binary(¤t_auction_round_response) } + +pub fn query_unsettled_auction(deps: Deps) -> StdResult { + let unsettled_auction = UNSETTLED_AUCTION.load(deps.storage)?; + + to_json_binary(&unsettled_auction) +} diff --git a/contracts/injective-auction-pool/src/state.rs b/contracts/injective-auction-pool/src/state.rs index 16accde..b596879 100644 --- a/contracts/injective-auction-pool/src/state.rs +++ b/contracts/injective-auction-pool/src/state.rs @@ -25,7 +25,7 @@ pub const WHITELISTED_ADDRESSES: Map<&Addr, Whitelisted> = Map::new("whitelisted /// Stores the available balance that can be used for bidding pub const BIDDING_BALANCE: Item = Item::new("bidding_balance"); /// Stores the current auction details -pub const UNSETTLED_AUCTION: Item = Item::new("usnsettled_auction"); +pub const UNSETTLED_AUCTION: Item = Item::new("unsettled_auction"); /// Maps the auction round to the treasure chest contract address pub const TREASURE_CHEST_CONTRACTS: Map = Map::new("treasure_chest_contracts"); /// Stores whether the funds can be withdrawn or not from the contract diff --git a/contracts/injective-auction-pool/src/tests/unit_tests.rs b/contracts/injective-auction-pool/src/tests/unit_tests.rs index 23bead6..76a7d7c 100644 --- a/contracts/injective-auction-pool/src/tests/unit_tests.rs +++ b/contracts/injective-auction-pool/src/tests/unit_tests.rs @@ -1,15 +1,18 @@ use std::marker::PhantomData; -use cosmwasm_std::{attr, coin, coins, from_json, testing::{mock_env, mock_info, BankQuerier, MockApi, MockStorage, MOCK_CONTRACT_ADDR}, to_json_binary, Addr, BankMsg, Binary, CodeInfoResponse, ContractResult as CwContractResult, CosmosMsg, Decimal, Empty, Env, HexBinary, MemoryStorage, MessageInfo, OwnedDeps, Querier, QuerierResult, QueryRequest, Uint128, WasmMsg, WasmQuery, Int64, Uint64}; +use cosmwasm_std::{ + attr, coin, coins, from_json, + testing::{mock_env, mock_info, BankQuerier, MockApi, MockStorage, MOCK_CONTRACT_ADDR}, + to_json_binary, Addr, BankMsg, Binary, CodeInfoResponse, ContractResult as CwContractResult, + CosmosMsg, Decimal, Empty, Env, HexBinary, Int64, MemoryStorage, MessageInfo, OwnedDeps, + Querier, QuerierResult, QueryRequest, Uint128, Uint64, WasmMsg, WasmQuery, +}; use cw_ownable::Ownership; -use injective_std::types::cosmos::base::v1beta1::Coin; -use injective_std::types::injective::auction::v1beta1::{MsgBid};//, QueryCurrentAuctionBasketResponse}; -use injective_auction::{ - // auction::{Coin}, - auction_pool::{ - ConfigResponse, ExecuteMsg, InstantiateMsg, QueryMsg, WhitelistedAddressesResponse, - }, +use injective_auction::auction_pool::{ + ConfigResponse, ExecuteMsg, InstantiateMsg, QueryMsg, WhitelistedAddressesResponse, }; +use injective_std::types::cosmos::base::v1beta1::Coin; +use injective_std::types::injective::auction::v1beta1::MsgBid; use prost::Message; use treasurechest::tf::tokenfactory::TokenFactoryType; @@ -566,7 +569,6 @@ fn try_bid_works() { assert_eq!( res.messages[0].msg, - CosmosMsg::Stargate { type_url: "/injective.auction.v1beta1.MsgBid".to_string(), value: { diff --git a/packages/injective_auction/src/auction_pool.rs b/packages/injective_auction/src/auction_pool.rs index bd1c1ff..f52f4c9 100644 --- a/packages/injective_auction/src/auction_pool.rs +++ b/packages/injective_auction/src/auction_pool.rs @@ -1,10 +1,8 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Decimal, Uint128}; use cw_ownable::{cw_ownable_execute, cw_ownable_query}; -use treasurechest::tf::tokenfactory::TokenFactoryType; +use treasurechest::tf::{injective::denom::Coin, tokenfactory::TokenFactoryType}; -#[allow(unused_imports)] -use injective_std::types::injective::auction::v1beta1::{ QueryCurrentAuctionBasketResponse}; #[cw_serde] pub struct InstantiateMsg { pub owner: Option, @@ -86,7 +84,9 @@ pub enum QueryMsg { #[returns(FundsLockedResponse)] FundsLocked {}, #[returns(FundsLockedResponse)] - QueryCurrentAuctionBasket {}, + CurrentAuctionBasket {}, + #[returns(UnsettledAuction)] + UnsettledAuction {}, } #[cw_serde] @@ -135,3 +135,16 @@ pub struct Config { /// 95% of the basket value pub min_return: Decimal, } + +#[cw_serde] + +pub struct UnsettledAuction { + /// The coins in the basket being auctioned + pub basket: Vec, + /// The auction round number + pub auction_round: u64, + /// A unique number that is used to create new token factory denoms + pub lp_subdenom: u64, + /// The time when the auction will close + pub closing_time: u64, +}