Skip to content

Commit

Permalink
feat: add incentive query types and update the umee sample contract (#7)
Browse files Browse the repository at this point in the history
* add incentive query types and update the umee sample contract

* update the schema
  • Loading branch information
gsk967 authored Jul 5, 2023
1 parent a92d949 commit 8afd039
Show file tree
Hide file tree
Showing 8 changed files with 979 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

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

Expand Down Expand Up @@ -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"
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.9"
version = "0.1.10"
edition = "2021"
description = "Types for CustomMsg and CustomQuery for the Umee blockchain"
license = "Apache-2.0"
Expand Down
2 changes: 2 additions & 0 deletions packages/cw-umee-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};

Expand Down
112 changes: 112 additions & 0 deletions packages/cw-umee-types/src/query.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -52,6 +60,19 @@ pub struct StructUmeeQuery {
max_borrow_params: Option<MaxBorrowParams>,
medians_params: Option<MediansParams>,
median_deviations_params: Option<MedianDeviationsParams>,
// incentive
incentive_parameters: Option<IncentiveParametersParams>,
total_bonded: Option<TotalBondedParams>,
total_unbonding: Option<TotalUnbondingParams>,
account_bonds: Option<AccountBondsParams>,
pending_rewards: Option<PendingRewardsParams>,
completed_incentive_programs: Option<CompletedIncentiveProgramsParams>,
ongoing_incentive_programs: Option<OngoingIncentiveProgramsParams>,
upcoming_incentive_programs: Option<UpcomingIncentiveProgramsParams>,
incentive_program: Option<IncentiveProgramParams>,
current_rates: Option<CurrentRatesParams>,
actual_rates: Option<ActualRatesParams>,
last_reward_time: Option<LastRewardTimeParams>,
}

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

Expand All @@ -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();
Expand Down
158 changes: 158 additions & 0 deletions packages/cw-umee-types/src/query_incentive.rs
Original file line number Diff line number Diff line change
@@ -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<Coin>,
}

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

#[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<Coin>,
pub unbonding: Vec<Coin>,
pub unbondings: Vec<Unbonding>,
}

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

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

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct CompletedIncentiveProgramsResponse {
pub programs: Vec<IncentiveProgram>,
}

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

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct OngoingIncentiveProgramsResponse {
pub programs: Vec<IncentiveProgram>,
}

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

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct UpcomingIncentiveProgramsResponse {
pub programs: Vec<IncentiveProgram>,
}

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

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

0 comments on commit 8afd039

Please sign in to comment.