Skip to content

Commit 5bf8e63

Browse files
committed
feat: injective cosmwasm 0.3.5-1
1 parent 5df2142 commit 5bf8e63

5 files changed

Lines changed: 23 additions & 62 deletions

File tree

packages/injective-cosmwasm/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ license = "Apache-2.0"
66
name = "injective-cosmwasm"
77
readme = "README.md"
88
repository = "https://github.com/InjectiveLabs/cw-injective/tree/dev/packages/injective-cosmwasm"
9-
version = "0.3.4-1"
9+
version = "0.3.5-1"
1010

1111
[dependencies]
12-
cosmwasm-std = { version = "2.2.2", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "iterator", "stargate" ] }
13-
cw-storage-plus = { version = "2.0.0" }
12+
cosmwasm-std = { version = "3.0.2", features = ["cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "cosmwasm_2_0", "iterator", "stargate" ] }
13+
cw-storage-plus = { version = "3.0.1" }
1414
ethereum-types = { version = "0.5.2" }
1515
hex = { version = "0.4.3", features = [ "serde" ] }
16-
injective-math = { version = "0.3.4-1" }
16+
injective-math = { version = "0.3.5-1", path="../injective-math" }
1717
schemars = { version = "0.8.16" }
1818
serde = { version = "1.0.196", default-features = false, features = [ "derive" ] }
1919
serde_repr = { version = "0.1.17" }
2020
subtle-encoding = { version = "0.5.1", features = [ "bech32-preview" ] }
2121
tiny-keccak = { version = "1.2.1" }
22-
ed25519-zebra = { version = "4.1.0", features = ["alloc"] }
2322

2423

2524
[dev-dependencies]

packages/injective-cosmwasm/src/exchange/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ impl MarketId {
106106
let market_id = market_id_s.into();
107107

108108
if !market_id.starts_with("0x") {
109-
return Err(StdError::generic_err("Invalid prefix: market_id must start with 0x"));
109+
return Err(StdError::msg("Invalid prefix: market_id must start with 0x"));
110110
}
111111

112112
if market_id.len() != 66 {
113-
return Err(StdError::generic_err("Invalid length: market_id must be exactly 66 characters"));
113+
return Err(StdError::msg("Invalid length: market_id must be exactly 66 characters"));
114114
}
115115

116116
Ok(Self(market_id.to_lowercase()))
@@ -191,11 +191,11 @@ impl SubaccountId {
191191
let subaccount_id = subaccount_id_s.into();
192192

193193
if !subaccount_id.starts_with("0x") {
194-
return Err(StdError::generic_err("Invalid prefix: subaccount_id must start with 0x"));
194+
return Err(StdError::msg("Invalid prefix: subaccount_id must start with 0x"));
195195
}
196196

197197
if subaccount_id.len() != 66 {
198-
return Err(StdError::generic_err("Invalid length: subaccount_id must be exactly 66 characters"));
198+
return Err(StdError::msg("Invalid length: subaccount_id must be exactly 66 characters"));
199199
}
200200

201201
Ok(Self(subaccount_id.to_lowercase()))
@@ -283,15 +283,15 @@ impl ShortSubaccountId {
283283
pub fn validate(&self) -> StdResult<Self> {
284284
let as_decimal = match u32::from_str_radix(self.as_str(), 16) {
285285
Ok(dec) => Ok(dec),
286-
Err(_) => Err(StdError::generic_err(format!(
286+
Err(_) => Err(StdError::msg(format!(
287287
"Invalid value: ShortSubaccountId was not a hexadecimal number: {}",
288288
&self.0
289289
))),
290290
};
291291

292292
match as_decimal?.to_string().parse::<u16>() {
293293
Ok(value) if value <= MAX_SHORT_SUBACCOUNT_NONCE => Ok(self.clone()),
294-
_ => Err(StdError::generic_err(format!(
294+
_ => Err(StdError::msg(format!(
295295
"Invalid value: ShortSubaccountId must be a number between 0-999, but {} was received",
296296
&self.0
297297
))),
@@ -430,7 +430,7 @@ impl Hash {
430430

431431
pub fn from_hex<T: AsRef<[u8]>>(s: T) -> StdResult<Hash> {
432432
let mut bytes = [0u8; 32];
433-
hex::decode_to_slice(s, &mut bytes).map_err(|e| StdError::generic_err(e.to_string()))?;
433+
hex::decode_to_slice(s, &mut bytes).map_err(|e| StdError::msg(e.to_string()))?;
434434
Ok(Hash::new(bytes))
435435
}
436436
}

packages/injective-cosmwasm/src/exchange_mock_querier.rs

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use std::marker::PhantomData;
22
use std::str::FromStr;
33

44
use cosmwasm_std::testing::{MockApi, MockStorage};
5-
use cosmwasm_std::{
6-
from_json, to_json_binary, Addr, AllBalanceResponse, BalanceResponse, BankQuery, Binary, Coin, ContractResult, OwnedDeps, Querier, QuerierResult,
7-
QueryRequest, SupplyResponse, SystemError, SystemResult, Uint128, WasmQuery,
8-
};
5+
use cosmwasm_std::{from_json, to_json_binary, Addr, BalanceResponse, BankQuery, Binary, Coin, ContractResult, OwnedDeps, Querier, QuerierResult, QueryRequest, SupplyResponse, SystemError, SystemResult, Uint128, Uint256, WasmQuery};
96

107
use injective_math::FPDecimal;
118

@@ -248,7 +245,7 @@ fn default_token_factory_denom_total_supply_handler() -> QuerierResult {
248245
fn default_bank_total_supply_handler() -> QuerierResult {
249246
let response = SupplyResponse::new(Coin {
250247
denom: "inj".to_string(),
251-
amount: Uint128::from(1000u128),
248+
amount: Uint256::from(1000u128),
252249
});
253250
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
254251
}
@@ -270,11 +267,6 @@ fn default_balance_bank_query_handler(denom: impl Into<String>) -> QuerierResult
270267
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
271268
}
272269

273-
fn default_all_balances_bank_query_handler() -> QuerierResult {
274-
let response = AllBalanceResponse::new(vec![Coin::new(1000000000000000u128, "inj")]);
275-
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
276-
}
277-
278270
fn default_exchange_params_response_handler() -> QuerierResult {
279271
let denom = "inj";
280272

@@ -434,9 +426,6 @@ pub trait HandlesBankBalanceQuery {
434426
fn handle(&self, address: String, denom: String) -> QuerierResult;
435427
}
436428

437-
pub trait HandlesBankAllBalancesQuery {
438-
fn handle(&self, address: String) -> QuerierResult;
439-
}
440429

441430
pub trait HandlesByAddressQuery {
442431
fn handle(&self, address: String) -> QuerierResult;
@@ -504,7 +493,6 @@ pub struct WasmMockQuerier {
504493
pub token_factory_denom_total_supply_handler: Option<Box<dyn HandlesDenomSupplyQuery>>,
505494
pub token_factory_denom_creation_fee_handler: Option<Box<dyn HandlesFeeQuery>>,
506495
pub balance_query_handler: Option<Box<dyn HandlesBankBalanceQuery>>,
507-
pub all_balances_query_handler: Option<Box<dyn HandlesBankAllBalancesQuery>>,
508496
pub total_supply_handler: Option<Box<dyn HandlesDenomSupplyQuery>>,
509497
pub registered_contract_info_query_handler: Option<Box<dyn HandlesByAddressQuery>>,
510498
pub spot_market_orderbook_response_handler: Option<Box<dyn HandlesPriceLevelsQuery>>,
@@ -555,11 +543,6 @@ impl WasmMockQuerier {
555543
Some(handler) => handler.handle(address.to_string(), denom.to_string()),
556544
None => default_balance_bank_query_handler(denom),
557545
},
558-
#[allow(deprecated)]
559-
BankQuery::AllBalances { address } => match &self.all_balances_query_handler {
560-
Some(handler) => handler.handle(address.to_string()),
561-
None => default_all_balances_bank_query_handler(),
562-
},
563546
BankQuery::Supply { denom } => match &self.total_supply_handler {
564547
Some(handler) => handler.handle(denom.to_string()),
565548
None => default_bank_total_supply_handler(),
@@ -767,7 +750,6 @@ impl WasmMockQuerier {
767750
token_factory_denom_total_supply_handler: None,
768751
token_factory_denom_creation_fee_handler: None,
769752
balance_query_handler: None,
770-
all_balances_query_handler: None,
771753
registered_contract_info_query_handler: None,
772754
denom_decimals_handler: None,
773755
spot_market_orderbook_response_handler: None,
@@ -801,10 +783,7 @@ impl TestDeposit {
801783
}
802784

803785
pub mod handlers {
804-
use cosmwasm_std::{
805-
to_json_binary, Addr, AllBalanceResponse, BalanceResponse, Binary, Checksum, CodeInfoResponse, Coin, ContractInfoResponse, ContractResult,
806-
QuerierResult, StdResult, SupplyResponse, SystemError, SystemResult, Uint128,
807-
};
786+
use cosmwasm_std::{to_json_binary, Addr, BalanceResponse, Binary, Checksum, CodeInfoResponse, Coin, ContractInfoResponse, ContractResult, QuerierResult, SupplyResponse, SystemError, SystemResult, Uint128, Uint256};
808787
use std::collections::HashMap;
809788

810789
use injective_math::FPDecimal;
@@ -824,7 +803,7 @@ pub mod handlers {
824803
TrimmedSpotLimitOrder,
825804
};
826805
use crate::{
827-
HandlesBankAllBalancesQuery, HandlesBankBalanceQuery, HandlesCodeInfo, HandlesContractInfo,
806+
HandlesBankBalanceQuery, HandlesCodeInfo, HandlesContractInfo,
828807
HandlesTraderDerivativeOrdersToCancelUpToAmountQuery, MarketMidPriceAndTOBResponse, OracleType,
829808
};
830809

@@ -1202,9 +1181,9 @@ pub mod handlers {
12021181
}))
12031182
}
12041183

1205-
pub fn create_bank_supply_handler(supply: Uint128) -> Option<Box<dyn HandlesDenomSupplyQuery>> {
1184+
pub fn create_bank_supply_handler(supply: Uint256) -> Option<Box<dyn HandlesDenomSupplyQuery>> {
12061185
struct Temp {
1207-
supply: Uint128,
1186+
supply: Uint256,
12081187
}
12091188
impl HandlesDenomSupplyQuery for Temp {
12101189
fn handle(&self, denom: String) -> QuerierResult {
@@ -1273,20 +1252,6 @@ pub mod handlers {
12731252
Some(Box::new(Temp { balances }))
12741253
}
12751254

1276-
pub fn create_simple_all_balances_bank_query_handler(balances: Vec<Coin>) -> Option<Box<dyn HandlesBankAllBalancesQuery>> {
1277-
struct Temp {
1278-
balances: Vec<Coin>,
1279-
}
1280-
impl HandlesBankAllBalancesQuery for Temp {
1281-
fn handle(&self, _: String) -> QuerierResult {
1282-
let res = AllBalanceResponse::new(self.balances.to_owned());
1283-
1284-
SystemResult::Ok(ContractResult::from(to_json_binary(&res)))
1285-
}
1286-
}
1287-
Some(Box::new(Temp { balances }))
1288-
}
1289-
12901255
pub fn create_atomic_order_fee_multiplier_handler(multiplier: FPDecimal) -> Option<Box<dyn HandlesMarketIdQuery>> {
12911256
struct Temp {
12921257
multiplier: FPDecimal,
@@ -1307,7 +1272,7 @@ pub mod handlers {
13071272
impl HandlesSmartQuery for Temp {
13081273
fn handle(&self, _contract_addr: &str, _msg: &Binary) -> QuerierResult {
13091274
match self.result.clone() {
1310-
Ok(resp) => SystemResult::Ok(ContractResult::from(StdResult::Ok(resp))),
1275+
Ok(resp) => SystemResult::Ok(ContractResult::from(Ok::<Binary, cosmwasm_std::StdError>(resp))),
13111276
Err(err) => SystemResult::Err(err),
13121277
}
13131278
}
@@ -1322,7 +1287,7 @@ pub mod handlers {
13221287
impl HandlesRawQuery for Temp {
13231288
fn handle(&self, _contract_addr: &str, _key: &Binary) -> QuerierResult {
13241289
match self.result.clone() {
1325-
Ok(resp) => SystemResult::Ok(ContractResult::from(StdResult::Ok(resp))),
1290+
Ok(resp) => SystemResult::Ok(ContractResult::from(Ok::<Binary, cosmwasm_std::StdError>(resp))),
13261291
Err(err) => SystemResult::Err(err),
13271292
}
13281293
}
@@ -1338,8 +1303,7 @@ pub mod handlers {
13381303

13391304
impl HandlesContractInfo for Temp {
13401305
fn handle(&self, _contract_addr: &str) -> QuerierResult {
1341-
let response = ContractInfoResponse::new(self.code_id, self.creator.to_owned(), None, false, None);
1342-
1306+
let response = ContractInfoResponse::new(self.code_id, self.creator.to_owned(), None, false, None, None);
13431307
SystemResult::Ok(ContractResult::from(to_json_binary(&response)))
13441308
}
13451309
}

packages/injective-cosmwasm/src/msg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn create_external_transfer_msg(
234234
}
235235

236236
if is_default_subaccount(source_subaccount_id) {
237-
return Err(StdError::generic_err("Cannot send from default subaccount to external subaccount"));
237+
return Err(StdError::msg("Cannot send from default subaccount to external subaccount"));
238238
}
239239

240240
Ok(vec![InjectiveMsgWrapper {

packages/injective-cosmwasm/src/test_helpers.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ pub(crate) mod testing_helpers {
66
use std::string::ToString;
77

88
use cosmwasm_std::testing::{MockApi, MockStorage};
9-
use cosmwasm_std::{
10-
Addr, Api, BlockInfo, ContractInfo, CustomQuery, DepsMut, Env, OwnedDeps, Querier, QuerierWrapper, Storage, Timestamp, TransactionInfo,
11-
};
9+
use cosmwasm_std::{Addr, Api, BlockInfo, ContractInfo, CustomQuery, DepsMut, Env, OwnedDeps, Querier, QuerierWrapper, Storage, Timestamp};
1210

1311
use injective_math::FPDecimal;
1412

@@ -53,7 +51,7 @@ pub(crate) mod testing_helpers {
5351
time: Timestamp::from_nanos(1_571_797_419_879_305_533),
5452
chain_id: "cosmos-testnet-14002".to_string(),
5553
},
56-
transaction: Some(TransactionInfo { index: 3 }),
54+
transaction: None,
5755
contract: ContractInfo {
5856
address: Addr::unchecked(TEST_CONTRACT_ADDR),
5957
},

0 commit comments

Comments
 (0)