Skip to content

Commit

Permalink
Remove denom creation fee whitelist from sei-cosmwasm (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbhat1 authored Nov 17, 2022
1 parent 0816454 commit 76fa363
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 177 deletions.
30 changes: 2 additions & 28 deletions contracts/sei-tester/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use crate::{
};
use protobuf::Message;
use sei_cosmwasm::{
BulkOrderPlacementsResponse, ContractOrderResult, CreatorInDenomFeeWhitelistResponse,
DepositInfo, DexTwapsResponse, EpochResponse, ExchangeRatesResponse,
GetDenomFeeWhitelistResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
BulkOrderPlacementsResponse, ContractOrderResult, DepositInfo, DexTwapsResponse, EpochResponse,
ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
LiquidationRequest, LiquidationResponse, MsgPlaceOrdersResponse, OracleTwapsResponse, Order,
OrderSimulationResponse, OrderType, PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper,
SettlementEntry, SudoMsg,
Expand Down Expand Up @@ -381,10 +380,6 @@ pub fn query(deps: Deps<SeiQueryWrapper>, _env: Env, msg: QueryMsg) -> StdResult
asset_denom,
id,
)?),
QueryMsg::GetDenomFeeWhitelist {} => to_binary(&query_get_denom_fee_whitelist(deps)?),
QueryMsg::CreatorInDenomFeeWhitelist { creator } => {
to_binary(&query_creator_in_denom_fee_whitelist(deps, creator)?)
}
QueryMsg::GetLatestPrice {
contract_address,
price_denom,
Expand Down Expand Up @@ -487,24 +482,3 @@ pub fn query_get_latest_price(

Ok(res)
}

pub fn query_get_denom_fee_whitelist(
deps: Deps<SeiQueryWrapper>,
) -> StdResult<GetDenomFeeWhitelistResponse> {
let querier = SeiQuerier::new(&deps.querier);
let res: GetDenomFeeWhitelistResponse = querier.query_get_denom_fee_whitelist()?;

Ok(res)
}

pub fn query_creator_in_denom_fee_whitelist(
deps: Deps<SeiQueryWrapper>,
creator: String,
) -> StdResult<CreatorInDenomFeeWhitelistResponse> {
let valid_addr = deps.api.addr_validate(&creator)?;
let querier = SeiQuerier::new(&deps.querier);
let res: CreatorInDenomFeeWhitelistResponse =
querier.query_creator_in_denom_fee_whitelist(valid_addr)?;

Ok(res)
}
4 changes: 0 additions & 4 deletions contracts/sei-tester/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ pub enum QueryMsg {
asset_denom: String,
id: u64,
},
GetDenomFeeWhitelist {},
GetLatestPrice {
contract_address: String,
price_denom: String,
asset_denom: String,
},
CreatorInDenomFeeWhitelist {
creator: String,
},
}
53 changes: 4 additions & 49 deletions contracts/sei-tester/tests/sei_tester_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use cw_multi_test::{
WasmKeeper,
};
use sei_cosmwasm::{
CreatorInDenomFeeWhitelistResponse, DenomOracleExchangeRatePair, DexPair, DexTwap,
DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetDenomFeeWhitelistResponse,
GetOrderByIdResponse, GetOrdersResponse, OracleExchangeRate, OracleTwapsResponse, Order,
OrderSimulationResponse, OrderStatus, OrderType, PositionDirection, SeiMsg, SeiQuery,
SeiQueryWrapper, SeiRoute, SudoMsg as SeiSudoMsg,
DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, EpochResponse,
ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleExchangeRate,
OracleTwapsResponse, Order, OrderSimulationResponse, OrderStatus, OrderType, PositionDirection,
SeiMsg, SeiQuery, SeiQueryWrapper, SeiRoute, SudoMsg as SeiSudoMsg,
};
use sei_integration_tests::{
helper::{get_balance, mock_app},
Expand Down Expand Up @@ -726,50 +725,6 @@ fn test_oracle_module_query_exchange_rate() {
}
}

/// Denom fee whitelist
#[test]
fn test_denom_fee_whitelist_query() {
let mut app = mock_app(init_default_balances, vec![]);
let sei_tester_addr = setup_test(&mut app);

// Query denom fee whitelist
let res: GetDenomFeeWhitelistResponse = app
.wrap()
.query_wasm_smart(sei_tester_addr.clone(), &QueryMsg::GetDenomFeeWhitelist {})
.unwrap();

assert_eq!(
res.creators,
["whitelist1", "whitelist2", "whitelist3"]
.map(String::from)
.to_vec()
);

// Query example creator within whitelist
let res: CreatorInDenomFeeWhitelistResponse = app
.wrap()
.query_wasm_smart(
sei_tester_addr.clone(),
&QueryMsg::CreatorInDenomFeeWhitelist {
creator: "whitelist1".to_string(),
},
)
.unwrap();
assert_eq!(res.whitelisted, true);

// Query example creator not within whitelist
let res: CreatorInDenomFeeWhitelistResponse = app
.wrap()
.query_wasm_smart(
sei_tester_addr.clone(),
&QueryMsg::CreatorInDenomFeeWhitelist {
creator: "non-whitelist1".to_string(),
},
)
.unwrap();
assert_eq!(res.whitelisted, false);
}

/// Oracle Module - query TWAP rates
#[test]
fn test_oracle_module_query_twaps() {
Expand Down
6 changes: 3 additions & 3 deletions packages/sei-cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub use proto_structs::{
};
pub use querier::SeiQuerier;
pub use query::{
CreatorInDenomFeeWhitelistResponse, DexTwapsResponse, EpochResponse, ExchangeRatesResponse,
GetDenomFeeWhitelistResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
OracleTwapsResponse, OrderSimulationResponse, PriceResponse, SeiQuery, SeiQueryWrapper,
DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse,
GetOrderByIdResponse, GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse,
PriceResponse, SeiQuery, SeiQueryWrapper,
};
pub use route::SeiRoute;
pub use sei_types::{
Expand Down
30 changes: 3 additions & 27 deletions packages/sei-cosmwasm/src/querier.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cosmwasm_std::{Addr, QuerierWrapper, StdResult};

use crate::query::{
CreatorInDenomFeeWhitelistResponse, DexTwapsResponse, EpochResponse, ExchangeRatesResponse,
GetDenomFeeWhitelistResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
OracleTwapsResponse, OrderSimulationResponse, SeiQuery, SeiQueryWrapper,
DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse,
GetOrderByIdResponse, GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse,
SeiQuery, SeiQueryWrapper,
};
use crate::route::SeiRoute;
use crate::Order;
Expand Down Expand Up @@ -126,30 +126,6 @@ impl<'a> SeiQuerier<'a> {
self.querier.query(&request)
}

/*
query tokenfactory module
*/
pub fn query_get_denom_fee_whitelist(&self) -> StdResult<GetDenomFeeWhitelistResponse> {
let request = SeiQueryWrapper {
route: SeiRoute::Tokenfactory,
query_data: SeiQuery::GetDenomFeeWhitelist {},
}
.into();
self.querier.query(&request)
}

pub fn query_creator_in_denom_fee_whitelist(
&self,
creator: Addr,
) -> StdResult<CreatorInDenomFeeWhitelistResponse> {
let request = SeiQueryWrapper {
route: SeiRoute::Tokenfactory,
query_data: SeiQuery::CreatorInDenomFeeWhitelist { creator },
}
.into();
self.querier.query(&request)
}

pub fn query_get_latest_price(
&self,
contract_address: Addr,
Expand Down
16 changes: 0 additions & 16 deletions packages/sei-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ pub enum SeiQuery {
contract_address: Addr,
order: Order,
},
GetDenomFeeWhitelist {},
CreatorInDenomFeeWhitelist {
creator: Addr,
},
}

/// ExchangeRatesResponse is data format returned from OracleRequest::ExchangeRates query
Expand Down Expand Up @@ -112,15 +108,3 @@ pub struct GetLatestPriceResponse {
pub struct OrderSimulationResponse {
pub executed_quantity: Decimal,
}

/// GetDenomFeeWhitelistResponse is data format returned from GetDenomFeeWhitelist query
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct GetDenomFeeWhitelistResponse {
pub creators: Vec<String>,
}

/// CreatorInDenomFeeWhitelistResponse is data format returned from CreatorInDenomFeeWhitelist query
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct CreatorInDenomFeeWhitelistResponse {
pub whitelisted: bool,
}
54 changes: 4 additions & 50 deletions packages/sei-integration-tests/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use cosmwasm_std::{
use cw_multi_test::{AppResponse, BankSudo, CosmosRouter, Module, SudoMsg};
use schemars::JsonSchema;
use sei_cosmwasm::{
CreatorInDenomFeeWhitelistResponse, DenomOracleExchangeRatePair, DexPair, DexTwap,
DexTwapsResponse, Epoch, EpochResponse, ExchangeRatesResponse, GetDenomFeeWhitelistResponse,
GetOrderByIdResponse, GetOrdersResponse, OracleTwap, OracleTwapsResponse, Order, OrderResponse,
OrderSimulationResponse, OrderStatus, PositionDirection, SeiMsg, SeiQuery, SeiQueryWrapper,
SudoMsg as SeiSudoMsg,
DenomOracleExchangeRatePair, DexPair, DexTwap, DexTwapsResponse, Epoch, EpochResponse,
ExchangeRatesResponse, GetOrderByIdResponse, GetOrdersResponse, OracleTwap,
OracleTwapsResponse, Order, OrderResponse, OrderSimulationResponse, OrderStatus,
PositionDirection, SeiMsg, SeiQuery, SeiQueryWrapper, SudoMsg as SeiSudoMsg,
};
use serde::de::DeserializeOwned;
use std::{
Expand All @@ -22,7 +21,6 @@ use std::{
pub struct SeiModule {
epoch: Epoch,
exchange_rates: HashMap<String, Vec<DenomOracleExchangeRatePair>>,
denom_fee_whitelist: Vec<String>,
}

const GENESIS_EPOCH: Epoch = Epoch {
Expand All @@ -38,9 +36,6 @@ impl SeiModule {
SeiModule {
epoch: GENESIS_EPOCH,
exchange_rates: HashMap::new(),
denom_fee_whitelist: ["whitelist1", "whitelist2", "whitelist3"]
.map(String::from)
.to_vec(),
}
}

Expand All @@ -65,19 +60,13 @@ impl SeiModule {
SeiModule {
epoch: GENESIS_EPOCH,
exchange_rates: exchange_rates,
denom_fee_whitelist: ["whitelist1", "whitelist2", "whitelist3"]
.map(String::from)
.to_vec(),
}
}

pub fn set_epoch(&self, new_epoch: Epoch) -> Self {
SeiModule {
epoch: new_epoch,
exchange_rates: (&self.exchange_rates).clone(),
denom_fee_whitelist: ["whitelist1", "whitelist2", "whitelist3"]
.map(String::from)
.to_vec(),
}
}
}
Expand Down Expand Up @@ -198,15 +187,6 @@ impl Module for SeiModule {
id,
);
}
SeiQuery::GetDenomFeeWhitelist {} => {
return query_get_denom_fee_whitelist_helper(self.denom_fee_whitelist.clone())
}
SeiQuery::CreatorInDenomFeeWhitelist { creator } => {
return query_get_creator_in_denom_fee_whitelist_helper(
creator,
self.denom_fee_whitelist.clone(),
)
}
}
}

Expand Down Expand Up @@ -680,32 +660,6 @@ fn query_get_epoch_helper(epoch: Epoch) -> AnyResult<Binary> {
return Ok(to_binary(&get_epoch(epoch))?);
}

fn get_denom_fee_whitelist(denom_fee_whitelist: Vec<String>) -> GetDenomFeeWhitelistResponse {
GetDenomFeeWhitelistResponse {
creators: denom_fee_whitelist,
}
}

// Query: GetDenomFeeWhitelist()
fn query_get_denom_fee_whitelist_helper(denom_fee_whitelist: Vec<String>) -> AnyResult<Binary> {
return Ok(to_binary(&get_denom_fee_whitelist(denom_fee_whitelist))?);
}

fn get_creator_in_denom_fee_whitelist(whitelisted: bool) -> CreatorInDenomFeeWhitelistResponse {
CreatorInDenomFeeWhitelistResponse {
whitelisted: whitelisted,
}
}

// Query: CreatorInDenomFeeWhitelistResponse()
fn query_get_creator_in_denom_fee_whitelist_helper(
creator: Addr,
denom_fee_whitelist: Vec<String>,
) -> AnyResult<Binary> {
let whitelisted: bool = denom_fee_whitelist.contains(&creator.to_string());
return Ok(to_binary(&get_creator_in_denom_fee_whitelist(whitelisted))?);
}

// TokenFactory Msg

// Execute: CreateDenom()
Expand Down

0 comments on commit 76fa363

Please sign in to comment.