Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Feat/move execution (#13)
Browse files Browse the repository at this point in the history
* chore: ad lockups

* chore: fix bonding period

* implement balance in all programs

* chore: price calculation in vesting details

* chore: handle pricing in elys program

* chore: handle USDC oracle price

* chore: change bonding pperiod

* chore: fix to use elys bindings

* choreL update elys binding version

* chore: remove execute

* chore: include discount in amm price query
  • Loading branch information
kenta-elys authored Dec 5, 2023
1 parent 9812a7b commit 87920cc
Show file tree
Hide file tree
Showing 25 changed files with 66 additions and 481 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ schemars = "0.8.1"
cosmwasm-schema = "1.1.4"
cw-utils = "0.13"
anyhow = "1"
elys-bindings = { version = "0.7.0", git = "https://github.com/elys-network/bindings", tag = "v0.7.0" }

[dev-dependencies]
cw-multi-test = "0.13.4"
elys-bindings = { version = "0.7.0", git = "https://github.com/elys-network/bindings", tag = "v0.7.0", features = [
"testing",
] }

[profile.release]
debug = true
20 changes: 0 additions & 20 deletions src/action/execute/claim_rewards_request.rs

This file was deleted.

20 changes: 0 additions & 20 deletions src/action/execute/claim_validator_commission_request.rs

This file was deleted.

20 changes: 0 additions & 20 deletions src/action/execute/eden_cancel_vest_request.rs

This file was deleted.

20 changes: 0 additions & 20 deletions src/action/execute/eden_vest_request.rs

This file was deleted.

23 changes: 0 additions & 23 deletions src/action/execute/elys_cancel_unstake_request.rs

This file was deleted.

28 changes: 0 additions & 28 deletions src/action/execute/elys_redelegation_request.rs

This file was deleted.

36 changes: 0 additions & 36 deletions src/action/execute/stake_request.rs

This file was deleted.

29 changes: 0 additions & 29 deletions src/action/execute/unstake_request.rs

This file was deleted.

28 changes: 0 additions & 28 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use cosmwasm_std::{DepsMut, MessageInfo, Response, Env, Int128, Coin};
use crate::bindings::msg::ElysMsg;
use crate::ContractError;

pub mod query {
pub mod pod {
mod get_pod_liquid_asset;
Expand Down Expand Up @@ -47,27 +43,3 @@ pub mod query {
pub use get_commitments::get_commitments;
}
}

pub mod execute {
mod stake_request;
mod unstake_request;

mod claim_rewards_request;
mod claim_validator_commission_request;
mod eden_cancel_vest_request;
mod eden_vest_request;
mod elys_cancel_unstake_request;
mod elys_redelegation_request;

use super::*;

pub use stake_request::stake_request;
pub use unstake_request::unstake_request;

pub use claim_rewards_request::claim_rewards_request;
pub use claim_validator_commission_request::claim_validator_commission_request;
pub use eden_cancel_vest_request::eden_cancel_vest_request;
pub use eden_vest_request::eden_vest_request;
pub use elys_cancel_unstake_request::elys_cancel_unstake_request;
pub use elys_redelegation_request::elys_redelegation_request;
}
8 changes: 5 additions & 3 deletions src/action/query/earn/get_eden_boost_earn_program_details.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;
use crate::{bindings::{query::ElysQuery, querier::ElysQuerier}, msg::query_resp::earn::GetEdenBoostEarnProgramResp};
use crate::types::{earn_program::eden_boost_earn::EdenBoostEarnProgram, ElysDenom, BalanceReward, AprUsdc, EarnType};
use crate::types::{earn_program::eden_boost_earn::EdenBoostEarnProgram, ElysDenom, BalanceReward, AprUsdc};
use cosmwasm_std::{coin, Decimal, Uint128};
use elys_bindings::types::EarnType;

pub fn get_eden_boost_earn_program_details(deps: Deps<ElysQuery>, address: Option<String>, asset: String) -> Result<GetEdenBoostEarnProgramResp, ContractError> {
let denom = ElysDenom::EdenBoost.as_str();
Expand All @@ -22,9 +23,10 @@ pub fn get_eden_boost_earn_program_details(deps: Deps<ElysQuery>, address: Optio
let available = querier.get_balance(addr.clone(), asset.clone())?;
let staked = querier.get_staked_balance(addr.clone(), asset.clone())?;

let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "".to_string(), 0)?;
let discount = Decimal::from_atomics(Uint128::new(1000000), 0).unwrap();
let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "elys".to_string(), 0)?;
let usdc_usd_price = usdc_oracle_price.price.price.checked_div(Decimal::from_atomics(Uint128::new(1000000), 0).unwrap()).unwrap();
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()))?;
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()), discount)?;

// have value in usd
let mut eden_rewards_in_usd = elys_price_in_usd.checked_mul(Decimal::from_atomics(eden_rewards.amount, 0).unwrap()).unwrap();
Expand Down
13 changes: 8 additions & 5 deletions src/action/query/earn/get_eden_earn_program_details.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;
use crate::{bindings::{query::ElysQuery, querier::ElysQuerier}, msg::query_resp::earn::GetEdenEarnProgramResp};
use crate::types::{earn_program::eden_earn::EdenEarnProgram, ElysDenom, BalanceReward, AprElys, EarnType, VestingDetail};
use crate::types::{earn_program::eden_earn::EdenEarnProgram, ElysDenom, BalanceReward, AprElys, VestingDetail};
use cosmwasm_std::{coin, Decimal, Uint128};
use elys_bindings::types::EarnType;

pub fn get_eden_earn_program_details(deps: Deps<ElysQuery>, address: Option<String>, asset: String) -> Result<GetEdenEarnProgramResp, ContractError> {
let denom = ElysDenom::Eden.as_str();
Expand All @@ -23,13 +24,15 @@ pub fn get_eden_earn_program_details(deps: Deps<ElysQuery>, address: Option<Stri
let mut available = querier.get_balance(addr.clone(), asset.clone())?;
let mut staked = querier.get_staked_balance(addr.clone(), asset.clone())?;
let mut vesting_info = querier.get_vesting_info(addr.clone())?;

let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "".to_string(), 0)?;

let discount = Decimal::from_atomics(Uint128::new(1000000), 0).unwrap();

let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "elys".to_string(), 0)?;
let usdc_usd_price = usdc_oracle_price.price.price.checked_div(Decimal::from_atomics(Uint128::new(1000000), 0).unwrap()).unwrap();

// have value in usd
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()))?;
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()), discount)?;

let mut staked_in_usd = elys_price_in_usd.checked_mul(Decimal::from_atomics(staked.amount, 0).unwrap()).unwrap();
staked_in_usd = staked_in_usd.checked_mul(usdc_usd_price).unwrap();
staked.usd_amount = staked_in_usd;
Expand Down
8 changes: 5 additions & 3 deletions src/action/query/earn/get_elys_earn_program_details.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;
use crate::{bindings::{query::ElysQuery, querier::ElysQuerier}, msg::query_resp::earn::GetElysEarnProgramResp};
use crate::types::{earn_program::elys_earn::ElysEarnProgram, ElysDenom, BalanceReward, AprElys, EarnType, StakedPosition, UnstakedPosition};
use crate::types::{earn_program::elys_earn::ElysEarnProgram, ElysDenom, BalanceReward, AprElys, StakedPosition, UnstakedPosition};
use cosmwasm_std::{coin, Decimal, Uint128};
use elys_bindings::types::EarnType;

pub fn get_elys_earn_program_details(deps: Deps<ElysQuery>, address: Option<String>, asset: String) -> Result<GetElysEarnProgramResp, ContractError> {
let denom = ElysDenom::Elys.as_str();
Expand All @@ -27,11 +28,12 @@ pub fn get_elys_earn_program_details(deps: Deps<ElysQuery>, address: Option<Stri
let mut staked_positions = querier.get_staked_positions(addr.clone())?;
let mut unstaked_positions = querier.get_unstaked_positions(addr.clone())?;

let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "".to_string(), 0)?;
let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "elys".to_string(), 0)?;
let usdc_usd_price = usdc_oracle_price.price.price.checked_div(Decimal::from_atomics(Uint128::new(1000000), 0).unwrap()).unwrap();

let discount = Decimal::from_atomics(Uint128::new(1000000), 0).unwrap();
let usdc_rewards_in_usd = usdc_rewards.usd_amount.checked_mul(usdc_usd_price).unwrap();
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()))?;
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()), discount)?;

// have value in usd
let mut eden_rewards_in_usd = elys_price_in_usd.checked_mul(Decimal::from_atomics(eden_rewards.amount, 0).unwrap()).unwrap();
Expand Down
27 changes: 22 additions & 5 deletions src/action/query/earn/get_usdc_earn_program_details.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::*;
use crate::{bindings::{query::ElysQuery, querier::ElysQuerier}, msg::query_resp::earn::GetUsdcEarnProgramResp};
use crate::{bindings::{query::ElysQuery, querier::ElysQuerier, query_resp::Lockup}, msg::query_resp::earn::GetUsdcEarnProgramResp};
use crate::types::{earn_program::usdc_earn::UsdcEarnProgram, ElysDenom};
use crate::types::{BalanceReward, AprUsdc, EarnType};
use crate::types::{BalanceReward, AprUsdc};
use cosmwasm_std::{coin, Decimal, Uint128};
use elys_bindings::types::EarnType;

pub fn get_usdc_earn_program_details(deps: Deps<ElysQuery>, address: Option<String>, asset: String) -> Result<GetUsdcEarnProgramResp, ContractError> {
let denom = ElysDenom::Usdc.as_str();
Expand All @@ -19,10 +20,11 @@ pub fn get_usdc_earn_program_details(deps: Deps<ElysQuery>, address: Option<Stri
Some(addr) => {
let usdc_rewards = querier.get_sub_bucket_rewards_balance(addr.clone(), ElysDenom::Usdc.as_str().to_string(), EarnType::UsdcProgram as i32)?;
let eden_rewards = querier.get_sub_bucket_rewards_balance(addr.clone(), ElysDenom::Eden.as_str().to_string(), EarnType::UsdcProgram as i32)?;
let discount = Decimal::from_atomics(Uint128::new(1000000), 0).unwrap();

let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "".to_string(), 0)?;
let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "elys".to_string(), 0)?;
let usdc_usd_price = usdc_oracle_price.price.price.checked_div(Decimal::from_atomics(Uint128::new(1000000), 0).unwrap()).unwrap();
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()))?;
let elys_price_in_usd = querier.get_amm_price_by_denom(coin(Uint128::new(1000000).u128(), ElysDenom::Elys.as_str().to_string()), discount)?;

let mut available = querier.get_balance(addr.clone(), asset.clone())?;
available.usd_amount = available.usd_amount.checked_mul(usdc_usd_price).unwrap();
Expand All @@ -39,8 +41,23 @@ pub fn get_usdc_earn_program_details(deps: Deps<ElysQuery>, address: Option<Stri

let usdc_rewards_in_usd = usdc_rewards.usd_amount.checked_mul(usdc_usd_price).unwrap();

let new_lockups = match staked.lockups {
Some(lockups) => {
let mut new_lockups: Vec<Lockup> = Vec::new();
for mut lockup in lockups {
lockup.unlock_timestamp = lockup.unlock_timestamp*1000;
new_lockups.push(lockup)
}

new_lockups
},
None => vec![],
};

staked.lockups = Some(new_lockups);

UsdcEarnProgram {
bonding_period: 1,
bonding_period: 0,
apr: AprUsdc {
uusdc: usdc_apr.apr.to_owned(),
ueden: eden_apr.apr.to_owned(),
Expand Down
Loading

0 comments on commit 87920cc

Please sign in to comment.