Skip to content

Commit

Permalink
add metoken types and update contract to use metoken types (#8)
Browse files Browse the repository at this point in the history
* add metoken types and update contract to use metoken types

* update the schema and fix the lint

* lint fix

* add missing field on MetokenSwapfeeParams

* update the schema and fix the lint

* updating the metoken params

* fix the lint
gsk967 authored Nov 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8afd039 commit 5c398ad
Showing 10 changed files with 1,105 additions and 319 deletions.
396 changes: 273 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "umee-cosmwasm"
version = "0.1.10"
version = "0.1.11"
authors = ["Umee (umee.cc)"]
edition = "2018"

@@ -40,8 +40,8 @@ optimize = """docker run --rm -v "$(pwd)":/code \
"""

[dependencies]
cw-umee-types = { version = "0.1.10", path = "./packages/cw-umee-types" }
cosmwasm-std = { version = "1.2.5", features = ["stargate", "staking"] }
cw-umee-types = { version = "0.1.12", path = "./packages/cw-umee-types" }
cosmwasm-std = { version = "1.3.3", features = ["stargate", "staking","cosmwasm_1_1","cosmwasm_1_2"] }
cosmwasm-storage = { version = "1.2.5" }
cw-storage-plus = "1.0"
cw2 = "1.0"
236 changes: 119 additions & 117 deletions packages/cw-umee-types/Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 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.12"
edition = "2021"
description = "Types for CustomMsg and CustomQuery for the Umee blockchain"
license = "Apache-2.0"
@@ -30,7 +30,7 @@ library = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cosmwasm-std = { version = "1.2.5", features = ["stargate", "staking"] }
cosmwasm-std = { version = "1.3.3", features = ["stargate", "staking","cosmwasm_1_1","cosmwasm_1_2"] }
cosmwasm-storage = { version = "1.2.5" }
cw-storage-plus = "1.0"
cw2 = "1.0"
1 change: 1 addition & 0 deletions packages/cw-umee-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

56 changes: 56 additions & 0 deletions packages/cw-umee-types/src/query.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@ use crate::query_leverage::{
LiquidationTargetsParams, MarketSummaryParams, MaxWithdrawParams, RegisteredTokensParams,
UmeeQueryLeverage,
};
use crate::query_metoken::{
MetokenIndexPricesParams, MetokenIndexbalancesParams, MetokenIndexesParams,
MetokenParametersParams, MetokenRedeemfeeParams, MetokenSwapfeeParams, UmeeQueryMeToken,
};
use crate::query_oracle::{
ActiveExchangeRatesParams, AggregatePrevoteParams, AggregatePrevotesParams, AggregateVoteParams,
AggregateVotesParams, ExchangeRatesParams, FeederDelegationParams, MedianDeviationsParams,
@@ -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
@@ -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<MetokenIndexPricesParams>,
}

fn default_struct_umee_query() -> StructUmeeQuery {
@@ -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,
}
}

@@ -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: MetokenIndexPricesParams) -> StructUmeeQuery {
let mut q: StructUmeeQuery = default_struct_umee_query();
q.metoken_indexprice = Some(p);
return q;
}
}
137 changes: 137 additions & 0 deletions packages/cw-umee-types/src/query_metoken.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
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),
MetokenIndexPrices(MetokenIndexPricesParams),
}

#[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,
}

#[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,
pub asset: String,
}

#[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: String,
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>,
pub index_prices: Vec<IndexPrices>,
}

#[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 IndexPrices {
pub denom: String,
pub price: String,
pub exponent: u32,
pub assets: Vec<AssetPrice>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct AssetPrice {
pub base_denom: String,
pub symbol_denom: String,
pub price: String,
pub exponent: u32,
pub swap_rate: String,
pub redeem_rate: String,
}

#[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 MetokenIndexPricesParams {
pub metoken_denom: String,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MetokenIndexPricesResponse {
pub prices: Vec<IndexPrices>,
}
2 changes: 1 addition & 1 deletion rust_optimizer.sh
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ set -eo pipefail

CWD="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
BASENAME="$(basename $CWD)"
OPTIMIZER_VERSION="0.12.8"
OPTIMIZER_VERSION="0.14.0"
architecture=$(uname -m)

if [[ "$architecture" == "arm64" ]];then
258 changes: 258 additions & 0 deletions schema/query_msg.json
Original file line number Diff line number Diff line change
@@ -160,6 +160,27 @@
},
"BankQuery": {
"oneOf": [
{
"description": "This calls into the native bank module for querying the total supply of one denomination. It does the same as the SupplyOf call in Cosmos SDK's RPC API. Return value is of type SupplyResponse.",
"type": "object",
"required": [
"supply"
],
"properties": {
"supply": {
"type": "object",
"required": [
"denom"
],
"properties": {
"denom": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "This calls into the native bank module for one denomination Return value is BalanceResponse",
"type": "object",
@@ -402,6 +423,72 @@
}
}
},
"MetokenIndexPricesParams": {
"type": "object",
"required": [
"metoken_denom"
],
"properties": {
"metoken_denom": {
"type": "string"
}
}
},
"MetokenIndexbalancesParams": {
"type": "object",
"required": [
"metoken_denom"
],
"properties": {
"metoken_denom": {
"type": "string"
}
}
},
"MetokenIndexesParams": {
"type": "object",
"required": [
"metoken_denom"
],
"properties": {
"metoken_denom": {
"type": "string"
}
}
},
"MetokenParametersParams": {
"type": "object"
},
"MetokenRedeemfeeParams": {
"type": "object",
"required": [
"asset_denom",
"metoken"
],
"properties": {
"asset_denom": {
"type": "string"
},
"metoken": {
"type": "string"
}
}
},
"MetokenSwapfeeParams": {
"type": "object",
"required": [
"asset",
"metoken_denom"
],
"properties": {
"asset": {
"type": "string"
},
"metoken_denom": {
"type": "string"
}
}
},
"MissCounterParams": {
"type": "object",
"required": [
@@ -872,6 +959,66 @@
}
]
},
"metoken_indexbalances": {
"anyOf": [
{
"$ref": "#/definitions/MetokenIndexbalancesParams"
},
{
"type": "null"
}
]
},
"metoken_indexes": {
"anyOf": [
{
"$ref": "#/definitions/MetokenIndexesParams"
},
{
"type": "null"
}
]
},
"metoken_indexprice": {
"anyOf": [
{
"$ref": "#/definitions/MetokenIndexPricesParams"
},
{
"type": "null"
}
]
},
"metoken_parameters": {
"anyOf": [
{
"$ref": "#/definitions/MetokenParametersParams"
},
{
"type": "null"
}
]
},
"metoken_redeemfee": {
"anyOf": [
{
"$ref": "#/definitions/MetokenRedeemfeeParams"
},
{
"type": "null"
}
]
},
"metoken_swapfee": {
"anyOf": [
{
"$ref": "#/definitions/MetokenSwapfeeParams"
},
{
"type": "null"
}
]
},
"miss_counter": {
"anyOf": [
{
@@ -1023,6 +1170,18 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"metoken"
],
"properties": {
"metoken": {
"$ref": "#/definitions/UmeeQueryMeToken"
}
},
"additionalProperties": false
}
]
},
@@ -1286,6 +1445,82 @@
}
]
},
"UmeeQueryMeToken": {
"oneOf": [
{
"type": "object",
"required": [
"metoken_parameters"
],
"properties": {
"metoken_parameters": {
"$ref": "#/definitions/MetokenParametersParams"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"metoken_indexes"
],
"properties": {
"metoken_indexes": {
"$ref": "#/definitions/MetokenIndexesParams"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"metoken_swapfee"
],
"properties": {
"metoken_swapfee": {
"$ref": "#/definitions/MetokenSwapfeeParams"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"metoken_redeemfee"
],
"properties": {
"metoken_redeemfee": {
"$ref": "#/definitions/MetokenRedeemfeeParams"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"metoken_indexbalances"
],
"properties": {
"metoken_indexbalances": {
"$ref": "#/definitions/MetokenIndexbalancesParams"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"metoken_index_prices"
],
"properties": {
"metoken_index_prices": {
"$ref": "#/definitions/MetokenIndexPricesParams"
}
},
"additionalProperties": false
}
]
},
"UmeeQueryOracle": {
"oneOf": [
{
@@ -1519,6 +1754,29 @@
}
},
"additionalProperties": false
},
{
"description": "Returns a [`CodeInfoResponse`] with metadata of the code",
"type": "object",
"required": [
"code_info"
],
"properties": {
"code_info": {
"type": "object",
"required": [
"code_id"
],
"properties": {
"code_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
},
"additionalProperties": false
}
]
}
328 changes: 255 additions & 73 deletions src/contract.rs

Large diffs are not rendered by default.

0 comments on commit 5c398ad

Please sign in to comment.