Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(smart-contracts): use the correct proto definitions and paths #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions contracts/injective-auction-pool/src/executions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@
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 {
Expand Down Expand Up @@ -182,7 +180,7 @@

// 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()
&& env.block.time.seconds() < current_auction_round_response.auction_closing_time as u64
{
return Err(ContractError::PooledAuctionLocked);
}
Expand Down Expand Up @@ -230,9 +228,7 @@
}

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;

// prevents the contract from bidding on the wrong auction round
if auction_round != current_auction_round {
Expand All @@ -243,7 +239,7 @@
}

// prevents the contract from bidding if the contract is already the highest bidder
if current_auction_round_response.highest_bidder == Some(env.contract.address.to_string()) {
if current_auction_round_response.highest_bidder == env.contract.address.to_string() {
return Ok(Response::default()
.add_attribute("action", "did_not_bid")
.add_attribute("reason", "contract_is_already_the_highest_bidder"));
Expand All @@ -254,7 +250,6 @@
// 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())
.parse::<Decimal>()?
.checked_mul((Decimal::one().checked_add(config.min_next_bid_increment_rate))?)?
.to_uint_ceil()
Expand Down Expand Up @@ -319,9 +314,7 @@
}

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;

Check warning on line 317 in contracts/injective-auction-pool/src/executions.rs

View check run for this annotation

Codecov / codecov/patch

contracts/injective-auction-pool/src/executions.rs#L317

Added line #L317 was not covered by tests

// prevents the contract from settling the auction if the auction round has not finished
if current_auction_round == unsettled_auction.auction_round {
Expand Down
20 changes: 8 additions & 12 deletions contracts/injective-auction-pool/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
// 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()
Expand Down Expand Up @@ -181,9 +178,9 @@
deps.storage,
&Auction {
basket,
auction_round: current_auction_round_response.auction_round(),
auction_round: current_auction_round_response.auction_round,

Check warning on line 181 in contracts/injective-auction-pool/src/helpers.rs

View check run for this annotation

Codecov / codecov/patch

contracts/injective-auction-pool/src/helpers.rs#L181

Added line #L181 was not covered by tests
lp_subdenom: new_subdenom,
closing_time: current_auction_round_response.auction_closing_time(),
closing_time: current_auction_round_response.auction_closing_time as u64,

Check warning on line 183 in contracts/injective-auction-pool/src/helpers.rs

View check run for this annotation

Codecov / codecov/patch

contracts/injective-auction-pool/src/helpers.rs#L183

Added line #L183 was not covered by tests
},
)?;
attributes.push(attr(
Expand Down Expand Up @@ -212,9 +209,9 @@
denom: coin.denom.clone(),
})
.collect(),
auction_round: current_auction_round_response.auction_round(),
auction_round: current_auction_round_response.auction_round,

Check warning on line 212 in contracts/injective-auction-pool/src/helpers.rs

View check run for this annotation

Codecov / codecov/patch

contracts/injective-auction-pool/src/helpers.rs#L212

Added line #L212 was not covered by tests
lp_subdenom: unsettled_auction.lp_subdenom,
closing_time: current_auction_round_response.auction_closing_time(),
closing_time: current_auction_round_response.auction_closing_time as u64,

Check warning on line 214 in contracts/injective-auction-pool/src/helpers.rs

View check run for this annotation

Codecov / codecov/patch

contracts/injective-auction-pool/src/helpers.rs#L214

Added line #L214 was not covered by tests
},
)?;
attributes.push(attr(
Expand All @@ -231,9 +228,9 @@
deps.storage,
&Auction {
basket: current_basket,
auction_round: current_auction_round_response.auction_round(),
auction_round: current_auction_round_response.auction_round,
lp_subdenom: 0,
closing_time: current_auction_round_response.auction_closing_time(),
closing_time: current_auction_round_response.auction_closing_time as u64,
},
)?;

Expand Down Expand Up @@ -265,10 +262,9 @@
pub(crate) fn query_current_auction(
deps: Deps,
) -> Result<QueryCurrentAuctionBasketResponse, ContractError> {
// TODO: fix deserialization
let current_auction_basket_response: QueryCurrentAuctionBasketResponse =
deps.querier.query(&QueryRequest::Stargate {
path: "/injective.auction.v1beta1.QueryCurrentAuctionBasketRequest".to_string(),
path: "/injective.auction.v1beta1.Query/CurrentAuctionBasket".to_string(),
data: [].into(),
})?;

Expand Down
12 changes: 6 additions & 6 deletions contracts/injective-auction-pool/src/tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ impl Querier for AuctionQuerier {
path,
data: _,
} => match path.as_str() {
"/injective.auction.v1beta1.QueryCurrentAuctionBasketRequest" => {
"/injective.auction.v1beta1.Query/CurrentAuctionBasket" => {
Ok(CwContractResult::Ok(
to_json_binary(&QueryCurrentAuctionBasketResponse {
amount: vec![Coin {
denom: "uatom".to_string(),
amount: "10000".to_string(),
}],
auction_round: Some(1),
auction_round: 1,
// simulates now + 7 days in seconds
auction_closing_time: Some(1_571_797_419 + 7 * 86_400),
highest_bidder: Some("highest_bidder".to_string()),
highest_bid_amount: Some("20000".to_string()),
auction_closing_time: 1_571_797_419 + 7 * 86_400,
highest_bidder: "highest_bidder".to_string(),
highest_bid_amount: "20000".to_string(),
})
.unwrap(),
))
Expand Down Expand Up @@ -570,7 +570,7 @@ fn try_bid_works() {
assert_eq!(
res.messages[0].msg,
CosmosMsg::Stargate {
type_url: "/injective.auction.v1beta1.MsgBid".to_string(),
type_url: "/injective.auction.v1beta1.Msg/Bid".to_string(),
value: {
let msg = MsgBid {
sender: env.contract.address.to_string(),
Expand Down
90 changes: 36 additions & 54 deletions packages/injective_auction/src/auction.rs
Original file line number Diff line number Diff line change
@@ -1,93 +1,75 @@
use osmosis_std_derive::CosmwasmExt;

/// Coin defines a token with a denomination and an amount.
///
/// NOTE: The amount field is an Int which implements the custom method
/// signatures required by gogoproto.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/injective.base.v1beta1.Coin")]
#[proto_message(type_url = "/cosmos.base.v1beta1.CoinCoin")]
pub struct Coin {
#[prost(string, tag = "1")]
pub denom: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub amount: ::prost::alloc::string::String,
}

/// QueryCurrentAuctionBasketRequest is the request type for the
/// Query/CurrentAuctionBasket RPC method.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
Clone, PartialEq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize, CosmwasmExt,
)]
#[proto_message(type_url = "/injective.auction.v1beta1.QueryCurrentAuctionBasketRequest")]
#[proto_message(type_url = "/injective.auction.v1beta1.Query/CurrentAuctionBasket")]
pub struct QueryCurrentAuctionBasketRequest {}

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/injective.auction.v1beta1.QueryCurrentAuctionBasketResponse")]
/// QueryCurrentAuctionBasketResponse is the response type for the
/// Query/CurrentAuctionBasket RPC method.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize)]
pub struct QueryCurrentAuctionBasketResponse {
/// amount describes the amount put on auction
#[prost(message, repeated, tag = "1")]
pub amount: Vec<Coin>,
#[prost(uint64, optional, tag = "2")]
pub auction_round: ::core::option::Option<u64>,
#[prost(uint64, optional, tag = "3")]
pub auction_closing_time: ::core::option::Option<u64>,
#[prost(string, optional, tag = "4")]
pub highest_bidder: ::core::option::Option<String>,
#[prost(string, optional, tag = "5")]
pub highest_bid_amount: ::core::option::Option<String>,
pub amount: ::prost::alloc::vec::Vec<Coin>,
/// auctionRound describes current auction round
#[prost(uint64, tag = "2")]
pub auction_round: u64,
/// auctionClosingTime describes auction close time for the round
#[prost(int64, tag = "3")]
pub auction_closing_time: i64,
/// highestBidder describes highest bidder on current round
#[prost(string, tag = "4")]
pub highest_bidder: ::prost::alloc::string::String,
/// highestBidAmount describes highest bid amount on current round
#[prost(string, tag = "5")]
pub highest_bid_amount: ::prost::alloc::string::String,
}

/// Bid defines a SDK message for placing a bid for an auction
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
Clone, PartialEq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize, CosmwasmExt,
)]
#[proto_message(type_url = "/injective.auction.v1beta1.MsgBid")]
#[proto_message(type_url = "/injective.auction.v1beta1.Msg/Bid")]
pub struct MsgBid {
#[prost(string, tag = "1")]
pub sender: ::prost::alloc::string::String,
/// amount of the bid in INJ tokens
#[prost(message, optional, tag = "2")]
pub bid_amount: ::core::option::Option<Coin>,
/// the current auction round being bid on
#[prost(uint64, tag = "3")]
pub round: u64,
}

#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/injective.auction.v1beta1.MsgBidResponse")]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize)]
pub struct MsgBidResponse {}
4 changes: 2 additions & 2 deletions tarpaulin-report.html

Large diffs are not rendered by default.

Loading