Skip to content

Commit

Permalink
fix: add to the denom to mint
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed Jul 30, 2024
1 parent 76f7c70 commit 825de83
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 44 deletions.
4 changes: 2 additions & 2 deletions contracts/injective-auction-pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pub fn instantiate(
Ok(Response::default()
.add_messages(messages)
.add_attribute("action", "instantiate")

.add_attributes(attributes))
}

Expand Down Expand Up @@ -132,6 +131,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
} => 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),
}
}
26 changes: 12 additions & 14 deletions contracts/injective-auction-pool/src/executions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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() {
Expand All @@ -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,
));

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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::<Decimal>()?
.checked_mul((Decimal::one().checked_add(config.min_next_bid_increment_rate))?)?
.to_uint_ceil()
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 14 additions & 11 deletions contracts/injective-auction-pool/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}

14 changes: 11 additions & 3 deletions contracts/injective-auction-pool/src/queries.rs
Original file line number Diff line number Diff line change
@@ -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<Binary> {
to_json_binary(&ConfigResponse {
Expand Down Expand Up @@ -48,8 +49,15 @@ pub fn query_bidding_balance(deps: Deps) -> StdResult<Binary> {
bidding_balance,
})
}

pub fn query_current_auction_basket(deps: Deps) -> StdResult<Binary> {
let current_auction_round_response = query_current_auction(deps)?;

to_json_binary(&current_auction_round_response)
}

pub fn query_unsettled_auction(deps: Deps) -> StdResult<Binary> {
let unsettled_auction = UNSETTLED_AUCTION.load(deps.storage)?;

to_json_binary(&unsettled_auction)
}
2 changes: 1 addition & 1 deletion contracts/injective-auction-pool/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint128> = Item::new("bidding_balance");
/// Stores the current auction details
pub const UNSETTLED_AUCTION: Item<Auction> = Item::new("usnsettled_auction");
pub const UNSETTLED_AUCTION: Item<Auction> = Item::new("unsettled_auction");
/// Maps the auction round to the treasure chest contract address
pub const TREASURE_CHEST_CONTRACTS: Map<u64, Addr> = Map::new("treasure_chest_contracts");
/// Stores whether the funds can be withdrawn or not from the contract
Expand Down
20 changes: 11 additions & 9 deletions contracts/injective-auction-pool/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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: {
Expand Down
21 changes: 17 additions & 4 deletions packages/injective_auction/src/auction_pool.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
Expand Down Expand Up @@ -86,7 +84,9 @@ pub enum QueryMsg {
#[returns(FundsLockedResponse)]
FundsLocked {},
#[returns(FundsLockedResponse)]
QueryCurrentAuctionBasket {},
CurrentAuctionBasket {},
#[returns(UnsettledAuction)]
UnsettledAuction {},
}

#[cw_serde]
Expand Down Expand Up @@ -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<Coin>,
/// 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,
}

0 comments on commit 825de83

Please sign in to comment.