Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metoken types and update contract to use metoken types #8

Merged
merged 7 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \
"""

[dependencies]
cw-umee-types = { version = "0.1.10", path = "./packages/cw-umee-types" }
cw-umee-types = { version = "0.1.11", path = "./packages/cw-umee-types" }
cosmwasm-std = { version = "1.2.5", features = ["stargate", "staking"] }
cosmwasm-storage = { version = "1.2.5" }
cw-storage-plus = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-umee-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-umee-types"
version = "0.1.10"
version = "0.1.11"
edition = "2021"
description = "Types for CustomMsg and CustomQuery for the Umee blockchain"
license = "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions packages/cw-umee-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod oracle_parameters;
pub mod query;
pub mod query_incentive;
pub mod query_leverage;
pub mod query_metoken;
pub mod query_oracle;
pub mod token;

Expand Down
56 changes: 56 additions & 0 deletions packages/cw-umee-types/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use crate::query_leverage::{
LiquidationTargetsParams, MarketSummaryParams, MaxWithdrawParams, RegisteredTokensParams,
UmeeQueryLeverage,
};
use crate::query_metoken::{
MetokenIndexPriceParams, MetokenIndexbalancesParams, MetokenIndexesParams,
MetokenParametersParams, MetokenRedeemfeeParams, MetokenSwapfeeParams, UmeeQueryMeToken,
};
use crate::query_oracle::{
ActiveExchangeRatesParams, AggregatePrevoteParams, AggregatePrevotesParams, AggregateVoteParams,
AggregateVotesParams, ExchangeRatesParams, FeederDelegationParams, MedianDeviationsParams,
Expand All @@ -33,6 +37,8 @@ pub enum UmeeQuery {
Oracle(UmeeQueryOracle),
// Incentive wraps all the query enums from the incentive module
Incentive(UmeeQueryIncentive),
// Metoken wraps all metoken queries
Metoken(UmeeQueryMeToken),
}

// StructUmeeQuery expected structure to query umee native modules
Expand Down Expand Up @@ -73,6 +79,13 @@ pub struct StructUmeeQuery {
current_rates: Option<CurrentRatesParams>,
actual_rates: Option<ActualRatesParams>,
last_reward_time: Option<LastRewardTimeParams>,
// metoken
metoken_parameters: Option<MetokenParametersParams>,
metoken_indexes: Option<MetokenIndexesParams>,
metoken_swapfee: Option<MetokenSwapfeeParams>,
metoken_redeemfee: Option<MetokenRedeemfeeParams>,
metoken_indexbalances: Option<MetokenIndexbalancesParams>,
metoken_indexprice: Option<MetokenIndexPriceParams>,
}

fn default_struct_umee_query() -> StructUmeeQuery {
Expand Down Expand Up @@ -110,6 +123,12 @@ fn default_struct_umee_query() -> StructUmeeQuery {
current_rates: None,
actual_rates: None,
last_reward_time: None,
metoken_parameters: None,
metoken_indexes: None,
metoken_swapfee: None,
metoken_redeemfee: None,
metoken_indexbalances: None,
metoken_indexprice: None,
}
}

Expand Down Expand Up @@ -332,4 +351,41 @@ impl StructUmeeQuery {
q.median_deviations_params = Some(median_deviations_params);
return q;
}

// metoken
pub fn metoken_parameters(metoken_parameter_params: MetokenParametersParams) -> StructUmeeQuery {
let mut q: StructUmeeQuery = default_struct_umee_query();
q.metoken_parameters = Some(metoken_parameter_params);
return q;
}

pub fn metoken_indexes(p: MetokenIndexesParams) -> StructUmeeQuery {
let mut q: StructUmeeQuery = default_struct_umee_query();
q.metoken_indexes = Some(p);
return q;
}

pub fn metoken_swapfee(p: MetokenSwapfeeParams) -> StructUmeeQuery {
let mut q: StructUmeeQuery = default_struct_umee_query();
q.metoken_swapfee = Some(p);
return q;
}

pub fn metoken_redeemfee(p: MetokenRedeemfeeParams) -> StructUmeeQuery {
let mut q: StructUmeeQuery = default_struct_umee_query();
q.metoken_redeemfee = Some(p);
return q;
}

pub fn metoken_indexbalances(p: MetokenIndexbalancesParams) -> StructUmeeQuery {
let mut q: StructUmeeQuery = default_struct_umee_query();
q.metoken_indexbalances = Some(p);
return q;
}

pub fn metoken_indexprice(p: MetokenIndexPriceParams) -> StructUmeeQuery {
let mut q: StructUmeeQuery = default_struct_umee_query();
q.metoken_indexprice = Some(p);
return q;
}
}
125 changes: 125 additions & 0 deletions packages/cw-umee-types/src/query_metoken.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
use cosmwasm_std::{Coin, Decimal};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum UmeeQueryMeToken {
MetokenParameters(MetokenParametersParams),
MetokenIndexes(MetokenIndexesParams),
MetokenSwapfee(MetokenSwapfeeParams),
MetokenRedeemfee(MetokenRedeemfeeParams),
MetokenIndexbalances(MetokenIndexbalancesParams),
MetokenIndexPrice(MetokenIndexPriceParams),
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenParametersParams {}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenParametersResponse {
pub params: MetokenParameters,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenParameters {
pub rebalancing_frequency: i64,
pub claiming_frequency: i64,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenIndexesParams {
pub metoken_denom: String,
RafilxTenfen marked this conversation as resolved.
Show resolved Hide resolved
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenIndexesResponse {
pub registry: Vec<Index>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Index {
pub denom: String,
pub max_supply: i64,
pub exponent: u32,
pub fee: Fee,
pub accepted_assets: Vec<AcceptedAsset>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Fee {
pub min_fee: Decimal,
pub balanced_fee: Decimal,
pub max_fee: Decimal,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct AcceptedAsset {
pub denom: String,
pub reserve_portion: Decimal,
pub target_allocation: Decimal,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenSwapfeeParams {
pub metoken_denom: String,
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
pub asset: Coin,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenSwapfeeResponse {
pub asset: Coin,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenRedeemfeeParams {
pub metoken: Coin,
pub asset_denom: String,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenRedeemfeeResponse {
pub asset: Coin,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenIndexbalancesParams {
pub metoken_denom: String,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenIndexbalancesResponse {
pub index_balances: Vec<IndexBalances>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct IndexBalances {
pub metoken_supply: Coin,
pub asset_balances: Vec<AssetBalance>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct AssetBalance {
pub denom: String,
pub leveraged: Decimal,
pub reserved: Decimal,
pub fees: Decimal,
pub interest: Decimal,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenIndexPriceParams {
pub metoken_denom: String,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenIndexPriceResponse {
pub price: Vec<Price>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Price {
pub denom: String,
pub price: Decimal,
pub exponent: u32,
}
Loading