Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dssei committed Apr 8, 2024
1 parent c90add5 commit a2a5d4e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 49 deletions.
11 changes: 9 additions & 2 deletions contracts/sei-tester/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ use crate::{
state::{PARALLEL_VALS, USER_SUMS, VALUES},
types::{OrderData, PositionEffect},
};
use protobuf::Message;
use sei_cosmwasm::{BulkOrderPlacementsResponse, Cancellation, DenomAuthorityMetadataResponse, DenomUnit, DenomsFromCreatorResponse, DepositInfo, DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse, Metadata, MsgPlaceOrdersResponse, OracleTwapsResponse, Order, OrderSimulationResponse, OrderType, PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, SettlementEntry, SudoMsg, EvmAddressResponse, SeiAddressResponse};
use ethaddr::Address;
use protobuf::Message;
use sei_cosmwasm::{BulkOrderPlacementsResponse, Cancellation, DenomAuthorityMetadataResponse,
DenomUnit, DenomsFromCreatorResponse, DepositInfo, DexTwapsResponse,
EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse,
GetOrderByIdResponse, GetOrdersResponse, Metadata, MsgPlaceOrdersResponse,
OracleTwapsResponse, Order, OrderSimulationResponse, OrderType,
PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, SettlementEntry,
SudoMsg, EvmAddressResponse, SeiAddressResponse};


const PLACE_ORDER_REPLY_ID: u64 = 1;
// version info for migration info
Expand Down
13 changes: 10 additions & 3 deletions contracts/sei-tester/tests/sei_tester_integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use cosmwasm_std::{Addr, Api, BalanceResponse, coin, Coin, CosmosMsg, Decimal, Empty, from_json, GovMsg, IbcMsg, IbcQuery, QueryRequest, StdError, Storage, testing::{MockApi, MockStorage}, Uint128};
use cosmwasm_std::{Addr, Api, BalanceResponse, coin, Coin, CosmosMsg, Decimal, Empty, from_json,
GovMsg, IbcMsg, IbcQuery, QueryRequest, StdError, Storage,
testing::{MockApi, MockStorage}, Uint128};
use cosmwasm_std::{BlockInfo, Uint64};
use cw_multi_test::{
App, BankKeeper, ContractWrapper, DistributionKeeper, Executor, FailingModule, Router,
StakeKeeper, WasmKeeper,
};

use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleExchangeRate, OracleTwapsResponse, Order, OrderSimulationResponse, OrderStatus, OrderType, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute};
use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse,
EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse,
GetOrdersResponse, OracleExchangeRate, OracleTwapsResponse, Order,
OrderSimulationResponse, OrderStatus, OrderType, PositionDirection,
SeiAddressResponse, SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute};
use sei_integration_tests::{
helper::{get_balance, mock_app},
module::{SeiModule, EVM_ADDRESS, SEI_ADDRESS},
Expand Down Expand Up @@ -1003,5 +1009,6 @@ fn test_sei_address_query() {

let err = res.expect_err("Expected an error because the EVM address is invalid");
assert_eq!(err.to_string(),
"Generic error: Querier contract error: Generic error: Failed to parse Ethereum address");
"Generic error: Querier contract error: Generic error: Failed to parse Ethereum \
address");
}
22 changes: 15 additions & 7 deletions packages/sei-cosmwasm/src/querier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use cosmwasm_std::{Addr, QuerierWrapper, StdResult, Uint128};
use cw20::{BalanceResponse, TokenInfoResponse};

use crate::query::{DenomAuthorityMetadataResponse, DenomsFromCreatorResponse, DexTwapsResponse, EpochResponse, Erc20AllowanceResponse, Erc721ApprovedResponse, Erc721IsApprovedForAllResponse, Erc721NameSymbolResponse, Erc721OwnerResponse, Erc721UriResponse, ErcPayloadResponse, EvmAddressResponse, SeiAddressResponse, ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse, SeiQuery, SeiQueryWrapper, StaticCallResponse};
use crate::query::{DenomAuthorityMetadataResponse, DenomsFromCreatorResponse, DexTwapsResponse,
EpochResponse, Erc20AllowanceResponse, Erc721ApprovedResponse,
Erc721IsApprovedForAllResponse, Erc721NameSymbolResponse, Erc721OwnerResponse,
Erc721UriResponse, ErcPayloadResponse, EvmAddressResponse, SeiAddressResponse,
ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse,
GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse, SeiQuery,
SeiQueryWrapper, StaticCallResponse};
use crate::route::SeiRoute;
use crate::Order;

Expand Down Expand Up @@ -430,19 +436,21 @@ impl<'a> SeiQuerier<'a> {

/// Queries the EVM (Ethereum Virtual Machine) address associated with a given Sei address.
///
/// This function takes a `sei_address` as a parameter, which is a `String` representing the SEI address.
/// It returns a `StdResult<EvmAddressResponse>`, which is a standard result type in the `cosmwasm_std` library.
/// The `EvmAddressResponse` struct contains the EVM address and a boolean indicating whether the EVM address is associated.
/// This function takes a `sei_address` as a parameter, which is a `String` representing the
/// SEI address. It returns a `StdResult<EvmAddressResponse>`, which is a standard result type
/// in the `cosmwasm_std` library. The `EvmAddressResponse` struct contains the EVM address and
/// a boolean indicating whether the EVM address is associated.
///
/// # Arguments
///
/// * `sei_address` - A `String` that represents the Sei address.
///
/// # Returns
///
/// * `StdResult<EvmAddressResponse>` - A standard result that wraps the `EvmAddressResponse` struct.
/// `EvmAddressResponse` contains the EVM address and a boolean indicating whether the EVM address is associated.
/// If the Sei address is not associated with any EVM address, the EVM address will be an empty string.
/// * `StdResult<EvmAddressResponse>` - A standard result that wraps the `EvmAddressResponse`
/// struct. `EvmAddressResponse` contains the EVM address and a boolean indicating whether the
/// EVM address is associated. If the Sei address is not associated with any EVM address,
/// the EVM address will be an empty string.
///
///
/// # Errors
Expand Down
3 changes: 2 additions & 1 deletion packages/sei-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ pub struct EvmAddressResponse {

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct SeiAddressResponse {
/// The SEI address associated to EVM address. Empty if the EVM address is not associated with any SEI address.
/// The SEI address associated to EVM address. Empty if the EVM address is not associated with
/// any SEI address.
pub sei_address: String,

/// A boolean value indicating whether the SEI address is associated to EVM address.
Expand Down
35 changes: 20 additions & 15 deletions packages/sei-integration-tests/src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use cosmwasm_std::{testing::{MockApi, MockQuerier, MockStorage}, Api, BalanceResponse, BankQuery, BlockInfo, Empty, GovMsg, IbcMsg, IbcQuery, MemoryStorage, Storage, Timestamp, from_json};
use cosmwasm_std::{
from_json,
testing::{MockApi, MockQuerier, MockStorage},
Api, BalanceResponse, BankQuery, BlockInfo, Empty, GovMsg, IbcMsg, IbcQuery, MemoryStorage,
Storage, Timestamp,
};
use cw_multi_test::{
App, AppBuilder, BankKeeper, DistributionKeeper, FailingModule, Module, Router, StakeKeeper,
WasmKeeper,
Expand Down Expand Up @@ -47,20 +52,20 @@ pub fn mock_app<F>(
FailingModule<IbcMsg, IbcQuery, Empty>,
FailingModule<GovMsg, Empty, Empty>,
>
where
F: FnOnce(
&mut Router<
BankKeeper,
SeiModule,
WasmKeeper<SeiMsg, SeiQueryWrapper>,
StakeKeeper,
DistributionKeeper,
FailingModule<IbcMsg, IbcQuery, Empty>,
FailingModule<GovMsg, Empty, Empty>,
>,
&dyn Api,
&mut dyn Storage,
),
where
F: FnOnce(
&mut Router<
BankKeeper,
SeiModule,
WasmKeeper<SeiMsg, SeiQueryWrapper>,
StakeKeeper,
DistributionKeeper,
FailingModule<IbcMsg, IbcQuery, Empty>,
FailingModule<GovMsg, Empty, Empty>,
>,
&dyn Api,
&mut dyn Storage,
),
{
let appbuilder: AppBuilder<
BankKeeper,
Expand Down
53 changes: 32 additions & 21 deletions packages/sei-integration-tests/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
use anyhow::Result as AnyResult;
use cosmwasm_std::{Addr, Api, BankMsg, Binary, BlockInfo, Coin, CosmosMsg, CustomQuery, Decimal, Querier, Storage, Uint128, Uint64, to_json_binary, from_json};
use cosmwasm_std::{
from_json,
to_json_binary,
Addr, Api, BankMsg, Binary, BlockInfo, Coin, CosmosMsg, CustomQuery, Decimal, Querier, Storage,
Uint128, Uint64,
};
use cw_multi_test::{AppResponse, BankSudo, CosmosRouter, Module, SudoMsg};
use schemars::JsonSchema;
use sei_cosmwasm::{Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, Epoch, EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleTwap, OracleTwapsResponse, Order, OrderResponse, OrderSimulationResponse, OrderStatus, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuery, SeiQueryWrapper, SudoMsg as SeiSudoMsg};
use sei_cosmwasm::{
Cancellation, DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, Epoch,
EpochResponse, EvmAddressResponse, ExchangeRatesResponse, GetOrderByIdResponse,
GetOrdersResponse, OracleTwap, OracleTwapsResponse, Order, OrderResponse,
OrderSimulationResponse, OrderStatus, PositionDirection, SeiAddressResponse, SeiMsg, SeiQuery,
SeiQueryWrapper, SudoMsg as SeiSudoMsg
};
use serde::de::DeserializeOwned;
use std::{
collections::HashMap,
Expand Down Expand Up @@ -81,14 +92,14 @@ impl Module for SeiModule {
&self,
api: &dyn Api,
storage: &mut dyn Storage,
router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
router: &dyn CosmosRouter<ExecC=ExecC, QueryC=QueryC>,
block: &BlockInfo,
sender: Addr,
msg: Self::ExecT,
) -> AnyResult<AppResponse>
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
{
match msg {
SeiMsg::PlaceOrders {
Expand Down Expand Up @@ -204,13 +215,13 @@ impl Module for SeiModule {
&self,
_api: &dyn Api,
_storage: &mut dyn Storage,
_router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
_router: &dyn CosmosRouter<ExecC=ExecC, QueryC=QueryC>,
_block: &BlockInfo,
msg: Self::SudoT,
) -> AnyResult<AppResponse>
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
{
match msg {
SeiSudoMsg::Settlement {
Expand Down Expand Up @@ -484,7 +495,7 @@ fn get_dex_twaps(
let order_response: GetOrdersResponse = from_json(
&query_get_orders_helper(storage, contract_address, Addr::unchecked("")).unwrap(),
)
.unwrap();
.unwrap();

let mut orders = order_response.orders.clone();
orders.sort_by(|a, b| b.id.cmp(&a.id));
Expand Down Expand Up @@ -555,7 +566,7 @@ fn get_order_simulation(
let orders: GetOrdersResponse = from_json(
&query_get_orders_helper(storage, contract_address, Addr::unchecked("")).unwrap(),
)
.unwrap();
.unwrap();

let valid_orders = if order.position_direction == PositionDirection::Long {
PositionDirection::Short
Expand All @@ -568,7 +579,7 @@ fn get_order_simulation(
if (order_response.position_direction == PositionDirection::Long
&& order.price <= order_response.price)
|| (order_response.position_direction == PositionDirection::Short
&& order.price >= order_response.price)
&& order.price >= order_response.price)
{
executed_quantity += order_response.quantity;
}
Expand Down Expand Up @@ -698,14 +709,14 @@ fn execute_create_denom_helper(
fn execute_mint_tokens_helper<ExecC, QueryC>(
api: &dyn Api,
storage: &mut dyn Storage,
router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
router: &dyn CosmosRouter<ExecC=ExecC, QueryC=QueryC>,
block: &BlockInfo,
sender: Addr,
amount: Coin,
) -> AnyResult<AppResponse>
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
{
let owner = storage.get(amount.denom.as_bytes());
if owner.is_none() || owner.unwrap() != sender.to_string().as_bytes() {
Expand All @@ -728,14 +739,14 @@ where
fn execute_burn_tokens_helper<ExecC, QueryC>(
api: &dyn Api,
storage: &mut dyn Storage,
router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
router: &dyn CosmosRouter<ExecC=ExecC, QueryC=QueryC>,
block: &BlockInfo,
sender: Addr,
amount: Coin,
) -> AnyResult<AppResponse>
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
where
ExecC: Debug + Clone + PartialEq + JsonSchema + DeserializeOwned + 'static,
QueryC: CustomQuery + DeserializeOwned + 'static,
{
let owner = storage.get(amount.denom.as_bytes());
if owner.is_none() || owner.unwrap() != sender.to_string().as_bytes() {
Expand Down

0 comments on commit a2a5d4e

Please sign in to comment.