Skip to content

Commit

Permalink
Merge pull request #140 from neutron-org/feat/sdk-50
Browse files Browse the repository at this point in the history
Feat/sdk 50
  • Loading branch information
pr0n00gler authored Jun 11, 2024
2 parents ed3d135 + 092c478 commit f45c35d
Show file tree
Hide file tree
Showing 20 changed files with 399 additions and 14 deletions.
5 changes: 5 additions & 0 deletions packages/neutron-sdk/schema/neutron_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@
"type": "object",
"required": [
"amount_in",
"limit_sell_price",
"order_type",
"receiver",
"tick_index_in_to_out",
Expand All @@ -1064,6 +1065,10 @@
"format": "uint64",
"minimum": 0.0
},
"limit_sell_price": {
"description": "Accepts standard decimals and decimals with scientific notation (ie. 1234.23E-7)",
"type": "string"
},
"max_amount_out": {
"description": "Maximum amount of TokenB can be bought. For everything except JUST_IN_TIME OrderType",
"anyOf": [
Expand Down
2 changes: 2 additions & 0 deletions packages/neutron-sdk/src/bindings/dex/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub enum DexMsg {
expiration_time: Option<u64>,
/// Maximum amount of TokenB can be bought. For everything except JUST_IN_TIME OrderType
max_amount_out: Option<Uint128>,
/// Accepts standard decimals and decimals with scientific notation (ie. 1234.23E-7)
limit_sell_price: String,
},
/// WithdrawFilledLimitOrder. Once a limit order has been filled – either partially or in
/// its entirety, it can be withdrawn at any time. Withdrawing from a limit order credits
Expand Down
4 changes: 3 additions & 1 deletion packages/neutron-sdk/src/bindings/dex/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ pub struct MultiHopRoute {
#[serde(rename_all = "snake_case")]
pub struct Params {
pub fee_tiers: Vec<u64>,
pub max_true_taker_spread: Option<PrecDec>,
pub paused: bool,
pub max_jits_per_block: u64,
pub good_til_purge_allowance: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, Default)]
Expand Down
2 changes: 2 additions & 0 deletions packages/neutron-sdk/src/bindings/marketmap/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod query;
pub mod types;
48 changes: 48 additions & 0 deletions packages/neutron-sdk/src/bindings/marketmap/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::bindings::marketmap::types::{Market, MarketMap, Params};
use crate::bindings::oracle::types::CurrencyPair;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum MarketMapQuery {
/// Parameters queries the parameters of the module.
Params {},
LastUpdated {},
MarketMap {},
Market {
currency_pair: CurrencyPair,
},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct ParamsResponse {
pub params: Params,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct LastUpdatedResponse {
pub last_updated: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MarketMapResponse {
/// **market_map** defines the global set of market configurations for all providers
/// and markets.
pub market_map: MarketMap,
/// **last_updated** is the last block height that the market map was updated.
/// This field can be used as an optimization for clients checking if there
/// is a new update to the map.
pub last_updated: u64,
/// **chain_id** is the chain identifier for the market map.
pub chain_id: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MarketResponse {
pub market: Market,
}
78 changes: 78 additions & 0 deletions packages/neutron-sdk/src/bindings/marketmap/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use schemars::{JsonSchema, Map};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct Params {
pub admin: String,
pub market_authorities: Vec<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct MarketMap {
pub markets: Map<String, Market>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct Market {
/// **ticker** is the full list of tickers and their associated configurations
/// to be stored on-chain.
pub ticker: Ticker,
pub provider_configs: Vec<ProviderConfig>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct ProviderConfig {
/// **name** corresponds to the name of the provider for which the configuration is
/// being set.
pub name: String,
/// **off_chain_ticker** is the off-chain representation of the ticker i.e. BTC/USD.
/// The off-chain ticker is unique to a given provider and is used to fetch the
/// price of the ticker from the provider.
pub off_chain_ticker: String,
/// **normalize_by_pair** is the currency pair for this ticker to be normalized by.
/// For example, if the desired Ticker is BTC/USD, this market could be reached
/// using: OffChainTicker = BTC/USDT NormalizeByPair = USDT/USD This field is
/// optional and nullable.
pub normalize_by_pair: Option<CurrencyPair>,
/// **invert** is a boolean indicating if the BASE and QUOTE of the market should
/// be inverted. i.e. BASE -> QUOTE, QUOTE -> BASE
#[serde(default)]
pub invert: bool,
/// **metadata_json** is a string of JSON that encodes any extra configuration
/// for the given provider config.
#[serde(rename(serialize = "metadata_JSON", deserialize = "metadata_JSON"))]
pub metadata_json: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct CurrencyPair {
#[serde(rename(serialize = "Base", deserialize = "Base"))]
pub base: String,
#[serde(rename(serialize = "Quote", deserialize = "Quote"))]
pub quote: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct Ticker {
/// **currency_pair** is the currency pair for this ticker.
pub currency_pair: CurrencyPair,
/// **decimals** is the number of decimal places for the ticker. The number of
/// decimal places is used to convert the price to a human-readable format.
pub decimals: u64,
/// **min_provider_count** is the minimum number of providers required to consider
/// the ticker valid.
pub min_provider_count: u64,
/// **enabled** is the flag that denotes if the Ticker is enabled for price
/// fetching by an oracle.
#[serde(default)]
pub enabled: bool,
/// **metadata_json** is a string of JSON that encodes any extra configuration
/// for the given ticker. ,
#[serde(rename(serialize = "metadata_JSON", deserialize = "metadata_JSON"))]
pub metadata_json: String,
}
2 changes: 2 additions & 0 deletions packages/neutron-sdk/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod dex;
pub mod marketmap;
#[allow(deprecated)]
pub mod msg;
pub mod oracle;
pub mod query;
pub mod types;
40 changes: 37 additions & 3 deletions packages/neutron-sdk/src/bindings/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ impl NeutronMsg {
}
}

#[deprecated(
since = "0.11.0",
note = "Used only for querying old proposals. Will fail if executed in a new proposal. Use submit_proposal_execute_message instead"
)]
/// Basic helper to define an ibc upgrade proposal passed to AdminModule:
/// * **proposal** is struct which contains proposal that upgrades network.
pub fn submit_upgrade_proposal(proposal: UpgradeProposal) -> Self {
Expand All @@ -368,6 +372,10 @@ impl NeutronMsg {
}
}

#[deprecated(
since = "0.11.0",
note = "Used only for querying old proposals. Will fail if executed in a new proposal. Use submit_proposal_execute_message instead"
)]
/// Basic helper to define an ibc update client change proposal passed to AdminModule:
/// * **proposal** is struct which contains proposal updates cliient.
pub fn submit_client_update_proposal(proposal: ClientUpdateProposal) -> Self {
Expand Down Expand Up @@ -534,6 +542,16 @@ pub struct MsgRegisterInterchainQueryResponse {
pub id: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
/// MsgRegisterInterchainAccountResponse defines the Msg/RegisterInterchainAccount response type.
pub struct MsgRegisterInterchainAccountResponse {
/// **channel_id** is a ...
pub channel_id: String,
/// **port_id** is a ...
pub port_id: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
/// MsgSubmitTxResponse defines the response for Msg/SubmitTx.
Expand All @@ -546,7 +564,7 @@ pub struct MsgSubmitTxResponse {

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
/// MsgSubmitTxResponse defines the response for Msg/IbcTransfer.
/// MsgIbcTransferResponse defines the response for Msg/IbcTransfer.
pub struct MsgIbcTransferResponse {
/// **sequence_id** is a channel's sequence_id for outgoing ibc packet. Unique per a channel.
pub sequence_id: u64,
Expand All @@ -562,10 +580,18 @@ pub enum AdminProposal {
/// New params has their own `MsgUpdateParams` msgs that can be supplied to `ProposalExecuteMessage`
ParamChangeProposal(ParamChangeProposal),

/// Proposal to upgrade IBC client
#[deprecated(
since = "0.11.0",
note = "Used only for querying old proposals. Will fail if executed in a new proposal. Use ProposalExecuteMessage instead"
)]
/// Depreacteed Proposal to upgrade IBC client
UpgradeProposal(UpgradeProposal),

/// Proposal to update IBC client
#[deprecated(
since = "0.11.0",
note = "Used only for querying old proposals. Will fail if executed in a new proposal. Use ProposalExecuteMessage instead"
)]
/// Deprecated. Proposal to update IBC client
ClientUpdateProposal(ClientUpdateProposal),

/// Proposal to execute CosmosMsg.
Expand Down Expand Up @@ -660,6 +686,10 @@ pub struct Plan {

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[deprecated(
since = "0.11.0",
note = "Used only for querying old proposals. Will fail if executed in a new proposal. Use ProposalExecuteMessage instead"
)]
/// UpgradeProposal defines the struct for IBC upgrade proposal.
pub struct UpgradeProposal {
/// **title** is a text title of proposal.
Expand All @@ -674,6 +704,10 @@ pub struct UpgradeProposal {

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
#[deprecated(
since = "0.11.0",
note = "Used only for querying old proposals. Will fail if executed in a new proposal. Use ProposalExecuteMessage instead"
)]
/// ClientUpdateProposal defines the struct for client update proposal.
pub struct ClientUpdateProposal {
/// **title** is a text title of proposal.
Expand Down
2 changes: 2 additions & 0 deletions packages/neutron-sdk/src/bindings/oracle/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod query;
pub mod types;
40 changes: 40 additions & 0 deletions packages/neutron-sdk/src/bindings/oracle/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::bindings::oracle::types::{CurrencyPair, QuotePrice};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum OracleQuery {
GetAllCurrencyPairs {},
GetPrice { currency_pair: CurrencyPair },
GetPrices { currency_pair_ids: Vec<String> },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct GetPriceResponse {
/// **price** represents the quote-price for the CurrencyPair given in
/// GetPriceRequest (possibly nil if no update has been made)
pub price: QuotePrice,
/// **nonce** represents the nonce for the CurrencyPair if it exists in state
pub nonce: u64,
/// **decimals* represents the number of decimals that the quote-price is
/// represented in. For Pairs where ETHEREUM is the quote this will be 18,
/// otherwise it will be 8.
pub decimals: u64,
/// *id** represents the identifier for the CurrencyPair.
#[serde(default)]
pub id: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct GetPricesResponse {
pub prices: Vec<GetPriceResponse>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct GetAllCurrencyPairsResponse {
pub currency_pairs: Vec<CurrencyPair>,
}
23 changes: 23 additions & 0 deletions packages/neutron-sdk/src/bindings/oracle/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use cosmwasm_std::Int128;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct CurrencyPair {
#[serde(rename(serialize = "Base", deserialize = "Base"))]
pub base: String,
#[serde(rename(serialize = "Quote", deserialize = "Quote"))]
pub quote: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct QuotePrice {
pub price: Int128,
/// **block_timestamp** tracks the block height associated with this price update.
/// We include block timestamp alongside the price to ensure that smart
/// contracts and applications are not utilizing stale oracle prices
pub block_timestamp: String,
/// **block_height** is height of block mentioned above
pub block_height: Option<u64>,
}
18 changes: 18 additions & 0 deletions packages/neutron-sdk/src/bindings/query.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::bindings::marketmap::query::MarketMapQuery;
use crate::bindings::oracle::query::OracleQuery;
use crate::bindings::types::{Failure, InterchainQueryResult, RegisteredQuery};
use cosmwasm_std::{Binary, CustomQuery, QueryRequest};
use schemars::JsonSchema;
Expand Down Expand Up @@ -73,6 +75,10 @@ pub enum NeutronQuery {
},

Dex(DexQuery),

MarketMap(MarketMapQuery),

Oracle(OracleQuery),
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down Expand Up @@ -151,3 +157,15 @@ impl From<DexQuery> for QueryRequest<NeutronQuery> {
QueryRequest::Custom(NeutronQuery::Dex(msg))
}
}

impl From<MarketMapQuery> for QueryRequest<NeutronQuery> {
fn from(msg: MarketMapQuery) -> Self {
QueryRequest::Custom(NeutronQuery::MarketMap(msg))
}
}

impl From<OracleQuery> for QueryRequest<NeutronQuery> {
fn from(msg: OracleQuery) -> Self {
QueryRequest::Custom(NeutronQuery::Oracle(msg))
}
}
2 changes: 1 addition & 1 deletion packages/neutron-sdk/src/proto_types/NEUTRON_COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.0.3
3357d418e391c14e1a4800ab640932896ed93fe8
Loading

0 comments on commit f45c35d

Please sign in to comment.