Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/sei-protocol/sei-cosmwasm i…
Browse files Browse the repository at this point in the history
…nto DexUpdateSeiCosmwasm
  • Loading branch information
Kartik Bhat committed Aug 24, 2023
2 parents f740a49 + e7f9082 commit d7e1074
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 14 deletions.
71 changes: 67 additions & 4 deletions contracts/sei-tester/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ use crate::{
};
use protobuf::Message;
use sei_cosmwasm::{
BulkOrderPlacementsResponse, Cancellation, DepositInfo, DexTwapsResponse, EpochResponse,
ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
MsgPlaceOrdersResponse, OracleTwapsResponse, Order, OrderSimulationResponse, OrderType,
PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper, SettlementEntry, SudoMsg,
BulkOrderPlacementsResponse, Cancellation, DenomAuthorityMetadataResponse, DenomUnit,
DenomsFromCreatorResponse, DepositInfo, DexTwapsResponse, EpochResponse, ExchangeRatesResponse,
GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
Metadata, MsgPlaceOrdersResponse, OracleTwapsResponse, Order,
OrderSimulationResponse, OrderType, PositionDirection, SeiMsg, SeiQuerier, SeiQueryWrapper,
SettlementEntry, SudoMsg,
};

const PLACE_ORDER_REPLY_ID: u64 = 1;
Expand Down Expand Up @@ -61,6 +63,7 @@ pub fn execute(
ExecuteMsg::Mint {} => mint(deps, env, info),
ExecuteMsg::Burn {} => burn(deps, env, info),
ExecuteMsg::ChangeAdmin {} => change_admin(deps, env, info),
ExecuteMsg::SetMetadata {} => set_metadata(deps, env, info),
}
}

Expand Down Expand Up @@ -189,6 +192,39 @@ pub fn change_admin(
Ok(Response::new().add_message(test_change_admin))
}

// set coin metadata for a tokenfactory denom.
pub fn set_metadata(
_deps: DepsMut<SeiQueryWrapper>,
env: Env,
_info: MessageInfo,
) -> Result<Response<SeiMsg>, StdError> {
let tokenfactory_denom =
"factory/".to_string() + env.contract.address.to_string().as_ref() + "/subdenom";
let test_metadata = Metadata {
description: "Token Metadata".to_string(),
base: tokenfactory_denom.clone(),
display: "SUBDENOM".to_string(),
name: "subdenom".to_string(),
symbol: "SUB".to_string(),
denom_units: vec![
DenomUnit {
denom: tokenfactory_denom.clone(),
exponent: 0 as u32,
aliases: vec!["usubdenom".to_string()],
},
DenomUnit {
denom: "SUBDENOM".to_string(),
exponent: 6 as u32,
aliases: vec!["subdenom".to_string()],
},
],
};
let test_set_metadata = sei_cosmwasm::SeiMsg::SetMetadata {
metadata: test_metadata,
};
Ok(Response::new().add_message(test_set_metadata))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn sudo(
deps: DepsMut<SeiQueryWrapper>,
Expand Down Expand Up @@ -327,6 +363,12 @@ pub fn query(deps: Deps<SeiQueryWrapper>, _env: Env, msg: QueryMsg) -> StdResult
price_denom,
asset_denom,
)?),
QueryMsg::GetDenomAuthorityMetadata { denom } => {
to_binary(&query_denom_authority_metadata(deps, denom)?)
}
QueryMsg::GetDenomsFromCreator { creator } => {
to_binary(&query_denoms_from_creator(deps, creator)?)
}
}
}

Expand Down Expand Up @@ -419,3 +461,24 @@ pub fn query_get_latest_price(

Ok(res)
}

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

Ok(res)
}

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

Ok(res)
}
7 changes: 7 additions & 0 deletions contracts/sei-tester/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum ExecuteMsg {
Mint {},
Burn {},
ChangeAdmin {},
SetMetadata {},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down Expand Up @@ -47,4 +48,10 @@ pub enum QueryMsg {
price_denom: String,
asset_denom: String,
},
GetDenomAuthorityMetadata {
denom: String,
},
GetDenomsFromCreator {
creator: String,
},
}
7 changes: 7 additions & 0 deletions packages/sei-cosmwasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Currently, Sei Bindings support query and message support for the sei custom mod
- Epoch
- Get current epoch information
- TokenFactory
- Query
- DenomAuthorityMetadata
- Gets the denom authority metadata for a tokenfactory denom
- DenomsFromCreator
- Gets all the tokenfactory denoms from a creator
- Message
- CreateDenom
- Creates a denom of type `factory/{creator address}/{subdenom}` given a `subdenom`.
Expand All @@ -50,6 +55,8 @@ Currently, Sei Bindings support query and message support for the sei custom mod
- Burns an amount of a factory denom. Only the creater of the denom (admin) can mint.
- ChangeAdmin
- Change the Admin of the Denom. Only the current admin can change the admin.
- SetMetadata
- Set the denom metadata of a factory denom. Only the current admin can set metadata.

## Usage

Expand Down
10 changes: 5 additions & 5 deletions packages/sei-cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub use proto_structs::{
};
pub use querier::SeiQuerier;
pub use query::{
DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse,
GetOrderByIdResponse, GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse,
PriceResponse, SeiQuery, SeiQueryWrapper,
DenomAuthorityMetadataResponse, DenomsFromCreatorResponse, DexTwapsResponse, EpochResponse,
ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
OracleTwapsResponse, OrderSimulationResponse, PriceResponse, SeiQuery, SeiQueryWrapper,
};
pub use route::SeiRoute;
pub use sei_types::{
BulkOrderPlacementsResponse, Cancellation, DepositInfo, Order, OrderResponse, OrderStatus,
OrderType, PositionDirection, SettlementEntry,
BulkOrderPlacementsResponse, Cancellation, DenomUnit, DepositInfo,
Metadata, Order, OrderResponse, OrderStatus, OrderType, PositionDirection, SettlementEntry,
};
pub use tx::MsgPlaceOrdersResponse;

Expand Down
7 changes: 6 additions & 1 deletion packages/sei-cosmwasm/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::sei_types::{Cancellation, DepositInfo, Order, SettlementEntry};
use crate::sei_types::{
Cancellation, DepositInfo, Metadata, Order, SettlementEntry,
};
use cosmwasm_std::{Addr, Coin, CosmosMsg, CustomMsg};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -38,6 +40,9 @@ pub enum SeiMsg {
denom: String,
new_admin_address: String,
},
SetMetadata {
metadata: Metadata,
},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
Expand Down
30 changes: 27 additions & 3 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::{
DexTwapsResponse, EpochResponse, ExchangeRatesResponse, GetLatestPriceResponse,
GetOrderByIdResponse, GetOrdersResponse, OracleTwapsResponse, OrderSimulationResponse,
SeiQuery, SeiQueryWrapper,
DenomAuthorityMetadataResponse, DenomsFromCreatorResponse, DexTwapsResponse, EpochResponse,
ExchangeRatesResponse, GetLatestPriceResponse, GetOrderByIdResponse, GetOrdersResponse,
OracleTwapsResponse, OrderSimulationResponse, SeiQuery, SeiQueryWrapper,
};
use crate::route::SeiRoute;
use crate::Order;
Expand Down Expand Up @@ -143,4 +143,28 @@ impl<'a> SeiQuerier<'a> {
.into();
self.querier.query(&request)
}

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

pub fn query_denoms_from_creator(&self, creator: Addr) -> StdResult<DenomsFromCreatorResponse> {
let request = SeiQueryWrapper {
route: SeiRoute::Tokenfactory,
query_data: SeiQuery::DenomsFromCreator { creator },
}
.into();
self.querier.query(&request)
}
}
20 changes: 19 additions & 1 deletion packages/sei-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

use crate::proto_structs::{DenomOracleExchangeRatePair, DexPair, DexTwap, Epoch, OracleTwap};
use crate::route::SeiRoute;
use crate::sei_types::OrderResponse;
use crate::sei_types::{DenomAuthorityMetadata, OrderResponse};
use crate::Order;

/// SeiQueryWrapper is an override of QueryRequest::Custom to access Sei-specific modules
Expand Down Expand Up @@ -50,6 +50,12 @@ pub enum SeiQuery {
contract_address: Addr,
order: Order,
},
DenomAuthorityMetadata {
denom: String,
},
DenomsFromCreator {
creator: Addr,
},
}

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

/// DenomAuthorityMetadataResponse is data format returned from DenomAuthorityMetadata query
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct DenomAuthorityMetadataResponse {
pub authority_metadata: DenomAuthorityMetadata,
}

/// DenomsFromCreatorResponse is data format returned from DenomsFromCreator query
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct DenomsFromCreatorResponse {
pub denoms: Vec<String>,
}
25 changes: 25 additions & 0 deletions packages/sei-cosmwasm/src/sei_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

/// Replicates the cosmos-sdk bank module Metadata type
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
pub struct Metadata {
pub description: String,
pub denom_units: Vec<DenomUnit>,
pub base: String,
pub display: String,
pub name: String,
pub symbol: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct DenomAuthorityMetadata {
pub admin: String,
}

/// Replicates the cosmos-sdk bank module DenomUnit type
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
pub struct DenomUnit {
pub denom: String,
pub exponent: u32,
pub aliases: Vec<String>,
}

#[derive(Serialize_repr, Deserialize_repr, Copy, Clone, Debug, PartialEq, Eq, Hash, JsonSchema)]
#[repr(i32)]
pub enum PositionDirection {
Expand Down
8 changes: 8 additions & 0 deletions packages/sei-integration-tests/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ impl Module for SeiModule {
id,
);
}
// TODO: Implement get denom authority metadata in integration tests
SeiQuery::DenomAuthorityMetadata { .. } => {
panic!("Denom Authority Metadata not implemented")
}
// TODO: Implement get denom from creator in integration tests
SeiQuery::DenomsFromCreator { .. } => {
panic!("Denoms From Creator not implemented")
}
}
}

Expand Down

0 comments on commit d7e1074

Please sign in to comment.