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

Feat/earn liquidity #14

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 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
Expand Up @@ -15,11 +15,11 @@ 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" }
cosmic-vagabond marked this conversation as resolved.
Show resolved Hide resolved
elys-bindings = { version = "0.8.0", git = "https://github.com/elys-network/bindings", tag = "v0.8.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 = [
elys-bindings = { version = "0.8.0", git = "https://github.com/elys-network/bindings", tag = "v0.8.0", features = [
"testing",
] }

Expand Down
2 changes: 2 additions & 0 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod query {
mod get_delegations;
mod get_unbonding_delegations;
mod get_commitments;
mod get_pools;

use cosmwasm_std::Deps;
use crate::ContractError;
Expand All @@ -41,5 +42,6 @@ pub mod query {
pub use get_delegations::get_delegations;
pub use get_unbonding_delegations::get_unbonding_delegations;
pub use get_commitments::get_commitments;
pub use get_pools::get_pools;
}
}
9 changes: 9 additions & 0 deletions src/action/query/earn/get_pools.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use super::*;
use crate::{bindings::{querier::ElysQuerier, query::ElysQuery}, msg::query_resp::earn::{FilterType, QueryEarnPoolResponse}};
use crate::types::PageRequest;

pub fn get_pools(deps: Deps<ElysQuery>, pool_ids: Option<Vec<u64>>, filter_type: FilterType, pagination: Option<PageRequest>) -> Result<QueryEarnPoolResponse, ContractError> {
let querier = ElysQuerier::new(&deps.querier);
let resp = querier.get_all_pools(pool_ids, filter_type as i32, pagination)?;
Ok(resp)
}
11 changes: 10 additions & 1 deletion src/bindings/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use super::{
QueryGetPriceResponse},
};

use crate::types::{BalanceBorrowed, QueryAprResponse};
use crate::msg::query_resp::earn::QueryEarnPoolResponse;
use crate::types::{BalanceBorrowed, QueryAprResponse, PageRequest};
use elys_bindings::types::BalanceAvailable;

#[allow(dead_code)]
Expand Down Expand Up @@ -179,4 +180,12 @@ impl<'a> ElysQuerier<'a> {
let resp: QueryGetPriceResponse = self.querier.query(&request)?;
Ok(resp)
}

pub fn get_all_pools(&self, pool_ids: Option<Vec<u64>>, filter_type: i32, pagination: Option<PageRequest>) -> StdResult<QueryEarnPoolResponse> {
let pools_query = ElysQuery::get_all_pools(pool_ids, filter_type, pagination);
let request: QueryRequest<ElysQuery> = QueryRequest::Custom(pools_query);

let resp: QueryEarnPoolResponse = self.querier.query(&request)?;
Ok(resp)
}
}
12 changes: 10 additions & 2 deletions src/bindings/query.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[allow(unused_imports)]
use super::query_resp::*;
#[allow(unused_imports)]
use crate::types::{BalanceBorrowed, QueryAprResponse};
use crate::types::{BalanceBorrowed, QueryAprResponse, PageRequest};
#[allow(unused_imports)]
use elys_bindings::types::BalanceAvailable;

Expand All @@ -10,6 +10,9 @@ use cosmwasm_schema::{cw_serde, QueryResponses};
#[allow(unused_imports)]
use cosmwasm_std::{CustomQuery, Decimal, Coin};

#[allow(unused_imports)]
use crate::msg::query_resp::earn::QueryEarnPoolResponse;

#[cw_serde]
#[derive(QueryResponses)]
pub enum ElysQuery {
Expand Down Expand Up @@ -44,7 +47,9 @@ pub enum ElysQuery {
#[returns(Decimal)]
AmmPriceByDenom{token_in: Coin, discount: Decimal},
#[returns(QueryGetPriceResponse)]
OraclePrice{asset: String, source: String, timestamp: u64}
OraclePrice{asset: String, source: String, timestamp: u64},
#[returns(QueryEarnPoolResponse)]
AmmEarnMiningPoolAll{pool_ids: Option<Vec<u64>>, filter_type: i32, pagination: Option<PageRequest>}
}

impl CustomQuery for ElysQuery {}
Expand Down Expand Up @@ -97,4 +102,7 @@ impl ElysQuery {
pub fn get_oracle_price(asset: String, source: String, timestamp: u64) -> Self {
ElysQuery::OraclePrice{ asset, source, timestamp }
}
pub fn get_all_pools(pool_ids: Option<Vec<u64>>, filter_type: i32, pagination: Option<PageRequest>) -> Self {
ElysQuery::AmmEarnMiningPoolAll{ pool_ids, filter_type, pagination }
}
}
2 changes: 1 addition & 1 deletion src/bindings/query_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ pub struct Price {
#[cw_serde]
pub struct QueryGetPriceResponse {
pub price: Price,
}
}
3 changes: 3 additions & 0 deletions src/entry_point/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ pub fn query(deps: Deps<ElysQuery>, _env: Env, msg: QueryMsg) -> Result<Binary,
GetDelegations { delegator_addr } => Ok(to_json_binary(&earn::get_delegations(deps, delegator_addr)?)?),
GetUnbondingDelegations { delegator_addr } => Ok(to_json_binary(&earn::get_unbonding_delegations(deps, delegator_addr)?)?),
GetCommitments { delegator_addr } => Ok(to_json_binary(&earn::get_commitments(deps, delegator_addr)?)?),

// Liquidity Pools
GetLiquidityPools { pool_ids, filter_type, pagination} => Ok(to_json_binary(&earn::get_pools(deps, pool_ids, filter_type, pagination)?)?),
}
}
2 changes: 2 additions & 0 deletions src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ pub mod query_resp {
pub use get_elys_earn_details_resp::GetElysEarnProgramResp;
mod get_usdc_earn_details_resp;
pub use get_usdc_earn_details_resp::GetUsdcEarnProgramResp;
mod get_pool_resp;
pub use get_pool_resp::{QueryEarnPoolResponse, FilterType};
}
}
4 changes: 4 additions & 0 deletions src/msg/query_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use super::query_resp::earn::*;
use cosmwasm_schema::{cw_serde, QueryResponses};
#[allow(unused_imports)]
use crate::bindings::query_resp::*;
#[allow(unused_imports)]
use crate::types::PageRequest;

#[cw_serde]
#[derive(QueryResponses)]
Expand Down Expand Up @@ -44,4 +46,6 @@ pub enum QueryMsg {
GetUnbondingDelegations { delegator_addr: String },
#[returns(QueryShowCommitmentsResponse)]
GetCommitments { delegator_addr: String },
#[returns(QueryEarnPoolResponse)]
GetLiquidityPools { pool_ids: Option<Vec<u64>>, filter_type: FilterType, pagination: Option<PageRequest> },
}
34 changes: 34 additions & 0 deletions src/msg/query_resp/earn/get_pool_resp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

use cosmwasm_std::{Decimal, Uint128, Coin};
use cosmwasm_schema::cw_serde;

#[cw_serde]
pub enum FilterType {
FilterAll = 0,
FilterPerpetual = 1,
FilterFixedWeight = 2,
FilterDynamicWeight = 3,
}

#[cw_serde]
pub struct PoolAsset {
pub token: Coin,
pub weight: Uint128,
}

#[cw_serde]
pub struct PoolResp {
pub assets: Vec<PoolAsset>, // eg : [{{"denom":"uatom", "amount":"1000"}, "weight":"10"}, {{"denom":"uusdc", "amount":"100"}, "weight":"1"}, ...]
pub pool_ratio: Decimal,
pub dex_apr: Decimal,
pub eden_apr: Decimal,
pub leverage_lp: Decimal,
pub perpetual: Decimal,
pub tvl: Decimal,
pub rewards: Decimal,
}

#[cw_serde]
pub struct QueryEarnPoolResponse {
pub pools: Option<Vec<PoolResp>>,
}
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ pub use page_response::PageResponse;
pub mod denom;
pub use denom::ElysDenom;

use elys_bindings::types::BalanceAvailable;
use elys_bindings::types::BalanceAvailable;
Loading