Skip to content

Commit

Permalink
chore(smart-contracts): small changes to comply with cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed Mar 12, 2024
1 parent 3755138 commit 9ee36b8
Show file tree
Hide file tree
Showing 5 changed files with 710 additions and 28 deletions.
61 changes: 37 additions & 24 deletions contracts/injective-auction-pool/src/executions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use cosmwasm_std::{
};
use injective_auction::auction::MsgBid;
use injective_auction::auction_pool::ExecuteMsg::TryBid;
use prost::Message;

const DAY_IN_SECONDS: u64 = 86400;

Expand Down Expand Up @@ -45,7 +44,7 @@ pub fn update_config(
if let Some(whitelist_addresses) = whitelist_addresses {
config.whitelisted_addresses = whitelist_addresses
.iter()
.map(|addr| deps.api.addr_validate(&addr))
.map(|addr| deps.api.addr_validate(addr))
.collect::<Result<Vec<Addr>, _>>()?;
}

Expand Down Expand Up @@ -182,14 +181,13 @@ pub(crate) fn exit_pool(

let config = CONFIG.load(deps.storage)?;

let mut messages = vec![];

// burn the LP token and send the inj back to the user
messages.push(config.token_factory_type.burn(
let mut messages = vec![config.token_factory_type.burn(
env.contract.address.clone(),
lp_denom.as_str(),
amount,
));
)];

messages.push(
BankMsg::Send {
to_address: info.sender.to_string(),
Expand Down Expand Up @@ -239,6 +237,7 @@ pub(crate) fn try_bid(

// calculate the minimum allowed bid to not be rejected by the auction module
// 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
.unwrap_or(0.to_string())
Expand All @@ -262,24 +261,17 @@ pub(crate) fn try_bid(
.add_attribute("reason", "basket_value_is_not_worth_bidding_for"));
}

// TODO: need to send some funds here?
let message: CosmosMsg = CosmosMsg::Stargate {
type_url: "/injective.auction.v1beta1.MsgBid".to_string(),
value: {
let msg = MsgBid {
sender: env.contract.address.to_string(),
bid_amount: Some(injective_auction::auction::Coin {
denom: config.native_denom,
amount: minimum_allowed_bid.to_string(),
}),
round: auction_round,
};
Binary(msg.encode_to_vec())
},
};
let msg = <MsgBid as Into<CosmosMsg>>::into(MsgBid {
sender: env.contract.address.to_string(),
bid_amount: Some(injective_auction::auction::Coin {
denom: config.native_denom,
amount: minimum_allowed_bid.to_string(),
}),
round: auction_round,
});

Ok(Response::default()
.add_message(message)
.add_message(msg)
.add_attribute("action", "try_bid".to_string())
.add_attribute("amount", minimum_allowed_bid.to_string()))
}
Expand Down Expand Up @@ -321,7 +313,9 @@ pub fn settle_auction(
}

// the contract won the auction
if auction_winner == env.contract.address.to_string() {
// NOTE: this is assuming the bot is sending the correct data about the winner of the previous auction
// currently there's no way to query the auction module directly to get this information
if deps.api.addr_validate(&auction_winner)? == env.contract.address {
// update LP subdenom for the next auction round (increment by 1)
let new_subdenom = unsettled_auction.lp_subdenom.checked_add(1).ok_or(
ContractError::OverflowError(OverflowError {
Expand Down Expand Up @@ -391,7 +385,7 @@ pub fn settle_auction(
let salt = Binary::from(seed.as_bytes());

let treasure_chest_address =
Addr::unchecked(&instantiate2_address(&checksum, &creator, &salt)?.to_string());
Addr::unchecked(instantiate2_address(&checksum, &creator, &salt)?.to_string());

let denom = format!("factory/{}/{}", env.contract.address, unsettled_auction.lp_subdenom);

Expand Down Expand Up @@ -430,6 +424,25 @@ pub fn settle_auction(
.create_denom(env.contract.address, new_subdenom.to_string().as_str()),
);

let basket = current_auction_round_response
.amount
.iter()
.map(|coin| Coin {
amount: Uint128::from_str(&coin.amount).expect("Failed to parse coin amount"),
denom: coin.denom.clone(),
})
.collect();

UNSETTLED_AUCTION.save(
deps.storage,
&Auction {
basket,
auction_round,
lp_subdenom: new_subdenom,
closing_time: current_auction_round_response.auction_closing_time(),
},
)?;

Ok(Response::default()
.add_messages(messages)
.add_attribute("action", "settle_auction".to_string())
Expand Down
1 change: 0 additions & 1 deletion contracts/injective-auction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod contract;
mod error;
pub mod executions;
pub mod helpers;
pub mod msg;
pub mod queries;
pub mod state;

Expand Down
1 change: 0 additions & 1 deletion contracts/injective-auction-pool/src/msg.rs

This file was deleted.

4 changes: 2 additions & 2 deletions contracts/injective-auction-pool/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::marker::PhantomData;
use treasurechest::tf::tokenfactory::TokenFactoryType;

use crate::contract::{execute, instantiate, query};
use crate::state::{BIDDING_BALANCE, TREASURE_CHEST_CONTRACTS, UNSETTLED_AUCTION};
use crate::state::BIDDING_BALANCE;
use crate::ContractError;

pub struct AuctionQuerier {
Expand Down Expand Up @@ -512,7 +512,7 @@ fn try_bid_fails() {
}

// TODO: to test settle auction, need to comment the line that checks if the auction round is valid on executions.rs
//
// use crate::state::{TREASURE_CHEST_CONTRACTS, UNSETTLED_AUCTION};
// #[test]
// fn settle_auction_as_loser_works() {
// let (mut deps, mut env) = init();
Expand Down
671 changes: 671 additions & 0 deletions tarpaulin-report.html

Large diffs are not rendered by default.

0 comments on commit 9ee36b8

Please sign in to comment.