From 8afd039db0b7a61c8e5dbd4aa391f016e5819536 Mon Sep 17 00:00:00 2001 From: Sai Kumar <17549398+gsk967@users.noreply.github.com> Date: Thu, 6 Jul 2023 01:55:55 +0530 Subject: [PATCH] feat: add incentive query types and update the umee sample contract (#7) * add incentive query types and update the umee sample contract * update the schema --- Cargo.lock | 4 +- Cargo.toml | 4 +- packages/cw-umee-types/Cargo.toml | 2 +- packages/cw-umee-types/src/lib.rs | 2 + packages/cw-umee-types/src/query.rs | 112 ++++++ packages/cw-umee-types/src/query_incentive.rs | 158 ++++++++ schema/query_msg.json | 374 ++++++++++++++++++ src/contract.rs | 329 ++++++++++++++- 8 files changed, 979 insertions(+), 6 deletions(-) create mode 100644 packages/cw-umee-types/src/query_incentive.rs diff --git a/Cargo.lock b/Cargo.lock index db1d653..6890404 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,7 +237,7 @@ dependencies = [ [[package]] name = "cw-umee-types" -version = "0.1.9" +version = "0.1.10" dependencies = [ "cosmwasm-std", "cosmwasm-storage", @@ -789,7 +789,7 @@ dependencies = [ [[package]] name = "umee-cosmwasm" -version = "0.1.4" +version = "0.1.10" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/Cargo.toml b/Cargo.toml index 2342f96..dea60a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "umee-cosmwasm" -version = "0.1.9" +version = "0.1.10" authors = ["Umee (umee.cc)"] edition = "2018" @@ -40,7 +40,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ """ [dependencies] -cw-umee-types = { version = "0.1.9", path = "./packages/cw-umee-types" } +cw-umee-types = { version = "0.1.10", 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" diff --git a/packages/cw-umee-types/Cargo.toml b/packages/cw-umee-types/Cargo.toml index ba3327b..40d2f16 100644 --- a/packages/cw-umee-types/Cargo.toml +++ b/packages/cw-umee-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cw-umee-types" -version = "0.1.9" +version = "0.1.10" edition = "2021" description = "Types for CustomMsg and CustomQuery for the Umee blockchain" license = "Apache-2.0" diff --git a/packages/cw-umee-types/src/lib.rs b/packages/cw-umee-types/src/lib.rs index 297f19d..32c2afd 100644 --- a/packages/cw-umee-types/src/lib.rs +++ b/packages/cw-umee-types/src/lib.rs @@ -7,6 +7,7 @@ pub mod msg; pub mod msg_leverage; pub mod oracle_parameters; pub mod query; +pub mod query_incentive; pub mod query_leverage; pub mod query_oracle; pub mod token; @@ -43,6 +44,7 @@ pub use msg_leverage::{ MsgMaxWithdrawParams, MsgTypes, RepayParams, SupplyCollateralParams, SupplyParams, UmeeMsgLeverage, WithdrawParams, }; +pub use query_incentive::UmeeQueryIncentive; pub use msg::{StructUmeeMsg, UmeeMsg}; diff --git a/packages/cw-umee-types/src/query.rs b/packages/cw-umee-types/src/query.rs index 39eb860..59b2ac6 100644 --- a/packages/cw-umee-types/src/query.rs +++ b/packages/cw-umee-types/src/query.rs @@ -1,3 +1,9 @@ +use crate::query_incentive::{ + AccountBondsParams, ActualRatesParams, CompletedIncentiveProgramsParams, CurrentRatesParams, + IncentiveParametersParams, IncentiveProgramParams, LastRewardTimeParams, + OngoingIncentiveProgramsParams, PendingRewardsParams, TotalBondedParams, TotalUnbondingParams, + UmeeQueryIncentive, UpcomingIncentiveProgramsParams, +}; use crate::query_leverage::{ AccountBalancesParams, AccountSummaryParams, BadDebtsParams, LeverageParametersParams, LiquidationTargetsParams, MarketSummaryParams, MaxWithdrawParams, RegisteredTokensParams, @@ -25,6 +31,8 @@ pub enum UmeeQuery { Leverage(UmeeQueryLeverage), // Oracle wraps all the query enums from the oracle module Oracle(UmeeQueryOracle), + // Incentive wraps all the query enums from the incentive module + Incentive(UmeeQueryIncentive), } // StructUmeeQuery expected structure to query umee native modules @@ -52,6 +60,19 @@ pub struct StructUmeeQuery { max_borrow_params: Option, medians_params: Option, median_deviations_params: Option, + // incentive + incentive_parameters: Option, + total_bonded: Option, + total_unbonding: Option, + account_bonds: Option, + pending_rewards: Option, + completed_incentive_programs: Option, + ongoing_incentive_programs: Option, + upcoming_incentive_programs: Option, + incentive_program: Option, + current_rates: Option, + actual_rates: Option, + last_reward_time: Option, } fn default_struct_umee_query() -> StructUmeeQuery { @@ -77,6 +98,18 @@ fn default_struct_umee_query() -> StructUmeeQuery { max_borrow_params: None, medians_params: None, median_deviations_params: None, + incentive_parameters: None, + total_bonded: None, + total_unbonding: None, + account_bonds: None, + pending_rewards: None, + completed_incentive_programs: None, + ongoing_incentive_programs: None, + upcoming_incentive_programs: None, + incentive_program: None, + current_rates: None, + actual_rates: None, + last_reward_time: None, } } @@ -85,6 +118,85 @@ fn default_struct_umee_query() -> StructUmeeQuery { // the fields inside the struct are private, to avoid missmatching // the query property with the assigned_query field impl StructUmeeQuery { + pub fn incentive_params( + incentive_parameter_params: IncentiveParametersParams, + ) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.incentive_parameters = Some(incentive_parameter_params); + return q; + } + pub fn total_bonded(total_bonded_params: TotalBondedParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.total_bonded = Some(total_bonded_params); + return q; + } + + pub fn total_unbonding(total_unbonding_params: TotalUnbondingParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.total_unbonding = Some(total_unbonding_params); + return q; + } + + pub fn account_bonds(account_bonds_params: AccountBondsParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.account_bonds = Some(account_bonds_params); + return q; + } + + pub fn pending_rewards(pending_rewards_params: PendingRewardsParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.pending_rewards = Some(pending_rewards_params); + return q; + } + + pub fn completed_incentive_programs( + completed_incentive_programs_params: CompletedIncentiveProgramsParams, + ) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.completed_incentive_programs = Some(completed_incentive_programs_params); + return q; + } + + pub fn ongoing_incentive_programs( + ongoing_incentive_programs_params: OngoingIncentiveProgramsParams, + ) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.ongoing_incentive_programs = Some(ongoing_incentive_programs_params); + return q; + } + + pub fn upcoming_incentive_programs( + upcoming_incentive_programs_params: UpcomingIncentiveProgramsParams, + ) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.upcoming_incentive_programs = Some(upcoming_incentive_programs_params); + return q; + } + + pub fn incentive_program(incentive_program_params: IncentiveProgramParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.incentive_program = Some(incentive_program_params); + return q; + } + + pub fn current_rates(current_rates_params: CurrentRatesParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.current_rates = Some(current_rates_params); + return q; + } + + pub fn actual_rates(actual_rates_params: ActualRatesParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.actual_rates = Some(actual_rates_params); + return q; + } + + pub fn last_reward_time(last_reward_time_params: LastRewardTimeParams) -> StructUmeeQuery { + let mut q = default_struct_umee_query(); + q.last_reward_time = Some(last_reward_time_params); + return q; + } + // creates a new exchange_rates query. pub fn exchange_rates(exchange_rates_params: ExchangeRatesParams) -> StructUmeeQuery { let mut q = default_struct_umee_query(); diff --git a/packages/cw-umee-types/src/query_incentive.rs b/packages/cw-umee-types/src/query_incentive.rs new file mode 100644 index 0000000..353f0ce --- /dev/null +++ b/packages/cw-umee-types/src/query_incentive.rs @@ -0,0 +1,158 @@ +use cosmwasm_std::{Coin, Decimal, Decimal256}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +#[serde(rename_all = "snake_case")] +pub enum UmeeQueryIncentive { + IncentiveParameters(IncentiveParametersParams), + TotalBonded(TotalBondedParams), + TotalUnbonding(TotalUnbondingParams), + AccountBonds(AccountBondsParams), + PendingRewards(PendingRewardsParams), + CompletedIncentivePrograms(CompletedIncentiveProgramsParams), + OngoingIncentivePrograms(OngoingIncentiveProgramsParams), + UpcomingIncentivePrograms(UpcomingIncentiveProgramsParams), + IncentiveProgram(IncentiveProgramParams), + CurrentRates(CurrentRatesParams), + ActualRates(ActualRatesParams), + LastRewardTime(LastRewardTimeParams), +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct IncentiveParametersParams {} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct IncentiveParametersResponse { + pub params: IncentiveParameters, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct IncentiveParameters { + pub max_unbondings: u32, + pub unbonding_duration: i64, + pub emergency_unbond_fee: Decimal256, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct TotalBondedParams { + pub denom: String, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct TotalBondedResponse { + pub bonded: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct TotalUnbondingParams { + pub denom: String, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct TotalUnbondingResponse { + pub unbonding: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct AccountBondsParams { + pub address: String, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct AccountBondsResponse { + pub bonded: Vec, + pub unbonding: Vec, + pub unbondings: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct Unbonding { + pub start: i64, + pub end: i64, + pub u_token: Coin, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct PendingRewardsParams { + pub address: String, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct PendingRewardsResponse { + pub rewards: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct CompletedIncentiveProgramsParams {} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct CompletedIncentiveProgramsResponse { + pub programs: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct OngoingIncentiveProgramsParams {} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct OngoingIncentiveProgramsResponse { + pub programs: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct UpcomingIncentiveProgramsParams {} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct UpcomingIncentiveProgramsResponse { + pub programs: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct IncentiveProgramParams { + pub id: u32, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct IncentiveProgramResponse { + pub program: IncentiveProgram, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct CurrentRatesParams { + pub u_token: String, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct CurrentRatesResponse { + pub reference_bond: Coin, + pub rewards: Vec, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct ActualRatesParams { + pub u_token: String, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct ActualRatesResponse { + pub APY: Decimal, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct LastRewardTimeParams {} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct LastRewardTimeResponse { + pub time: i64, +} + +#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] +pub struct IncentiveProgram { + pub ID: u32, + pub start_time: i64, + pub duration: i64, + pub u_token: String, + pub funded: bool, + pub total_rewards: Coin, + pub remaining_rewards: Coin, +} diff --git a/schema/query_msg.json b/schema/query_msg.json index 4d2a800..7b9b8b9 100644 --- a/schema/query_msg.json +++ b/schema/query_msg.json @@ -87,6 +87,17 @@ } } }, + "AccountBondsParams": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + } + } + }, "AccountSummaryParams": { "type": "object", "required": [ @@ -101,6 +112,17 @@ "ActiveExchangeRatesParams": { "type": "object" }, + "ActualRatesParams": { + "type": "object", + "required": [ + "u_token" + ], + "properties": { + "u_token": { + "type": "string" + } + } + }, "Addr": { "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", "type": "string" @@ -190,6 +212,20 @@ "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", "type": "string" }, + "CompletedIncentiveProgramsParams": { + "type": "object" + }, + "CurrentRatesParams": { + "type": "object", + "required": [ + "u_token" + ], + "properties": { + "u_token": { + "type": "string" + } + } + }, "ExchangeRatesParams": { "type": "object", "required": [ @@ -278,6 +314,25 @@ } ] }, + "IncentiveParametersParams": { + "type": "object" + }, + "IncentiveProgramParams": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "uint32", + "minimum": 0.0 + } + } + }, + "LastRewardTimeParams": { + "type": "object" + }, "LeverageParametersParams": { "type": "object" }, @@ -358,9 +413,23 @@ } } }, + "OngoingIncentiveProgramsParams": { + "type": "object" + }, "OracleParametersParams": { "type": "object" }, + "PendingRewardsParams": { + "type": "object", + "required": [ + "address" + ], + "properties": { + "address": { + "type": "string" + } + } + }, "QueryRequest_for_StructUmeeQuery": { "oneOf": [ { @@ -573,6 +642,16 @@ } ] }, + "account_bonds": { + "anyOf": [ + { + "$ref": "#/definitions/AccountBondsParams" + }, + { + "type": "null" + } + ] + }, "account_summary": { "anyOf": [ { @@ -593,6 +672,16 @@ } ] }, + "actual_rates": { + "anyOf": [ + { + "$ref": "#/definitions/ActualRatesParams" + }, + { + "type": "null" + } + ] + }, "aggregate_prevote": { "anyOf": [ { @@ -643,6 +732,26 @@ } ] }, + "completed_incentive_programs": { + "anyOf": [ + { + "$ref": "#/definitions/CompletedIncentiveProgramsParams" + }, + { + "type": "null" + } + ] + }, + "current_rates": { + "anyOf": [ + { + "$ref": "#/definitions/CurrentRatesParams" + }, + { + "type": "null" + } + ] + }, "exchange_rates": { "anyOf": [ { @@ -663,6 +772,36 @@ } ] }, + "incentive_parameters": { + "anyOf": [ + { + "$ref": "#/definitions/IncentiveParametersParams" + }, + { + "type": "null" + } + ] + }, + "incentive_program": { + "anyOf": [ + { + "$ref": "#/definitions/IncentiveProgramParams" + }, + { + "type": "null" + } + ] + }, + "last_reward_time": { + "anyOf": [ + { + "$ref": "#/definitions/LastRewardTimeParams" + }, + { + "type": "null" + } + ] + }, "leverage_parameters": { "anyOf": [ { @@ -743,6 +882,16 @@ } ] }, + "ongoing_incentive_programs": { + "anyOf": [ + { + "$ref": "#/definitions/OngoingIncentiveProgramsParams" + }, + { + "type": "null" + } + ] + }, "oracle_params": { "anyOf": [ { @@ -753,6 +902,16 @@ } ] }, + "pending_rewards": { + "anyOf": [ + { + "$ref": "#/definitions/PendingRewardsParams" + }, + { + "type": "null" + } + ] + }, "registered_tokens": { "anyOf": [ { @@ -772,6 +931,58 @@ "type": "null" } ] + }, + "total_bonded": { + "anyOf": [ + { + "$ref": "#/definitions/TotalBondedParams" + }, + { + "type": "null" + } + ] + }, + "total_unbonding": { + "anyOf": [ + { + "$ref": "#/definitions/TotalUnbondingParams" + }, + { + "type": "null" + } + ] + }, + "upcoming_incentive_programs": { + "anyOf": [ + { + "$ref": "#/definitions/UpcomingIncentiveProgramsParams" + }, + { + "type": "null" + } + ] + } + } + }, + "TotalBondedParams": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" + } + } + }, + "TotalUnbondingParams": { + "type": "object", + "required": [ + "denom" + ], + "properties": { + "denom": { + "type": "string" } } }, @@ -800,6 +1011,166 @@ } }, "additionalProperties": false + }, + { + "type": "object", + "required": [ + "incentive" + ], + "properties": { + "incentive": { + "$ref": "#/definitions/UmeeQueryIncentive" + } + }, + "additionalProperties": false + } + ] + }, + "UmeeQueryIncentive": { + "oneOf": [ + { + "type": "object", + "required": [ + "incentive_parameters" + ], + "properties": { + "incentive_parameters": { + "$ref": "#/definitions/IncentiveParametersParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "total_bonded" + ], + "properties": { + "total_bonded": { + "$ref": "#/definitions/TotalBondedParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "total_unbonding" + ], + "properties": { + "total_unbonding": { + "$ref": "#/definitions/TotalUnbondingParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account_bonds" + ], + "properties": { + "account_bonds": { + "$ref": "#/definitions/AccountBondsParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "pending_rewards" + ], + "properties": { + "pending_rewards": { + "$ref": "#/definitions/PendingRewardsParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "completed_incentive_programs" + ], + "properties": { + "completed_incentive_programs": { + "$ref": "#/definitions/CompletedIncentiveProgramsParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ongoing_incentive_programs" + ], + "properties": { + "ongoing_incentive_programs": { + "$ref": "#/definitions/OngoingIncentiveProgramsParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "upcoming_incentive_programs" + ], + "properties": { + "upcoming_incentive_programs": { + "$ref": "#/definitions/UpcomingIncentiveProgramsParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "incentive_program" + ], + "properties": { + "incentive_program": { + "$ref": "#/definitions/IncentiveProgramParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "current_rates" + ], + "properties": { + "current_rates": { + "$ref": "#/definitions/CurrentRatesParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "actual_rates" + ], + "properties": { + "actual_rates": { + "$ref": "#/definitions/ActualRatesParams" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "last_reward_time" + ], + "properties": { + "last_reward_time": { + "$ref": "#/definitions/LastRewardTimeParams" + } + }, + "additionalProperties": false } ] }, @@ -1063,6 +1434,9 @@ } ] }, + "UpcomingIncentiveProgramsParams": { + "type": "object" + }, "WasmQuery": { "oneOf": [ { diff --git a/src/contract.rs b/src/contract.rs index 3069ce2..c9274a8 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -5,6 +5,15 @@ use cosmwasm_std::{ }; use cw2::set_contract_version; use cw_umee_types::error::ContractError; +use cw_umee_types::query_incentive::{ + AccountBondsParams, AccountBondsResponse, ActualRatesParams, ActualRatesResponse, + CompletedIncentiveProgramsParams, CompletedIncentiveProgramsResponse, CurrentRatesParams, + CurrentRatesResponse, IncentiveParametersParams, IncentiveParametersResponse, + IncentiveProgramParams, IncentiveProgramResponse, LastRewardTimeParams, LastRewardTimeResponse, + OngoingIncentiveProgramsParams, OngoingIncentiveProgramsResponse, PendingRewardsParams, + PendingRewardsResponse, TotalBondedParams, TotalBondedResponse, TotalUnbondingParams, + TotalUnbondingResponse, UpcomingIncentiveProgramsParams, UpcomingIncentiveProgramsResponse, +}; use cw_umee_types::query_leverage::{ BadDebtsParams, BadDebtsResponse, MaxBorrowParams, MaxBorrowResponse, MaxWithdrawParams, MaxWithdrawResponse, @@ -22,7 +31,7 @@ use cw_umee_types::{ MarketSummaryParams, MarketSummaryResponse, MissCounterParams, MissCounterResponse, OracleParametersParams, OracleParametersResponse, RegisteredTokensParams, RegisteredTokensResponse, SlashWindowParams, SlashWindowResponse, StructUmeeMsg, StructUmeeQuery, - UmeeMsg, UmeeMsgLeverage, UmeeQuery, UmeeQueryLeverage, UmeeQueryOracle, + UmeeMsg, UmeeMsgLeverage, UmeeQuery, UmeeQueryIncentive, UmeeQueryLeverage, UmeeQueryOracle, }; use crate::msg::{ExecuteMsg, InstantiateMsg, OwnerResponse, QueryMsg}; @@ -233,6 +242,8 @@ fn query_umee(deps: Deps, _env: Env, umee_msg: UmeeQuery) -> StdResult { // } // } UmeeQuery::Oracle(oracle) => query_oracle(deps, _env, oracle), + // incentive + UmeeQuery::Incentive(incentive) => query_incentive(deps, _env, incentive), } } @@ -293,6 +304,322 @@ fn query_leverage(deps: Deps, _env: Env, msg: UmeeQueryLeverage) -> StdResult StdResult { + match msg { + UmeeQueryIncentive::IncentiveParameters(incentive_params) => { + to_binary(&query_incentive_params(deps, incentive_params)?) + } + UmeeQueryIncentive::TotalBonded(params) => to_binary(&query_total_bonded(deps, params)?), + UmeeQueryIncentive::TotalUnbonding(params) => to_binary(&query_total_unbonding(deps, params)?), + UmeeQueryIncentive::AccountBonds(params) => to_binary(&query_account_bonds(deps, params)?), + UmeeQueryIncentive::PendingRewards(params) => to_binary(&query_pending_rewards(deps, params)?), + UmeeQueryIncentive::CompletedIncentivePrograms(params) => { + to_binary(&query_completed_incentive_programs(deps, params)?) + } + UmeeQueryIncentive::OngoingIncentivePrograms(params) => { + to_binary(&query_ongoing_incentive_programs(deps, params)?) + } + UmeeQueryIncentive::UpcomingIncentivePrograms(params) => { + to_binary(&query_upcoming_incentive_programs(deps, params)?) + } + UmeeQueryIncentive::IncentiveProgram(params) => { + to_binary(&query_incentive_program(deps, params)?) + } + UmeeQueryIncentive::CurrentRates(params) => to_binary(&query_current_rates(deps, params)?), + UmeeQueryIncentive::ActualRates(params) => to_binary(&query_actutal_rates(deps, params)?), + UmeeQueryIncentive::LastRewardTime(params) => to_binary(&query_last_reward_time(deps, params)?), + } +} + +// query_last_reward_time +fn query_last_reward_time( + deps: Deps, + params: LastRewardTimeParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::last_reward_time(params)); + + let response: LastRewardTimeResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_actutal_rates +fn query_actutal_rates(deps: Deps, params: ActualRatesParams) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::actual_rates(params)); + + let response: ActualRatesResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_current_rates +fn query_current_rates(deps: Deps, params: CurrentRatesParams) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::current_rates(params)); + + let response: CurrentRatesResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_incentive_program +fn query_incentive_program( + deps: Deps, + params: IncentiveProgramParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::incentive_program(params)); + + let response: IncentiveProgramResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_upcoming_incentive_programs +fn query_upcoming_incentive_programs( + deps: Deps, + params: UpcomingIncentiveProgramsParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::upcoming_incentive_programs(params)); + + let response: UpcomingIncentiveProgramsResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_ongoing_incentive_programs +fn query_ongoing_incentive_programs( + deps: Deps, + params: OngoingIncentiveProgramsParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::ongoing_incentive_programs(params)); + + let response: OngoingIncentiveProgramsResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_completed_incentive_programs +fn query_completed_incentive_programs( + deps: Deps, + params: CompletedIncentiveProgramsParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::completed_incentive_programs(params)); + + let response: CompletedIncentiveProgramsResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_account_bonds +fn query_pending_rewards( + deps: Deps, + params: PendingRewardsParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::pending_rewards(params)); + + let response: PendingRewardsResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_account_bonds +fn query_account_bonds(deps: Deps, params: AccountBondsParams) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::account_bonds(params)); + + let response: AccountBondsResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_total_unbonding +fn query_total_unbonding( + deps: Deps, + params: TotalUnbondingParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::total_unbonding(params)); + + let response: TotalUnbondingResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_total_bonded +fn query_total_bonded(deps: Deps, params: TotalBondedParams) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::total_bonded(params)); + + let response: TotalBondedResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(resp) => response = resp, + }; + } + } + + Ok(response) +} + +// query_incentive_params +fn query_incentive_params( + deps: Deps, + incentive_params: IncentiveParametersParams, +) -> StdResult { + let request = QueryRequest::Custom(StructUmeeQuery::incentive_params(incentive_params)); + + let incentive_params_response: IncentiveParametersResponse; + match query_chain(deps, &request) { + Err(err) => { + return Err(err); + } + Ok(binary) => { + match from_binary::(&binary) { + Err(err) => { + return Err(err); + } + Ok(response) => incentive_params_response = response, + }; + } + } + + Ok(incentive_params_response) +} + // query_oracle contains the umee oracle available queries fn query_oracle(deps: Deps, _env: Env, msg: UmeeQueryOracle) -> StdResult { match msg {