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

Commit

Permalink
Feat/usdc price (#16)
Browse files Browse the repository at this point in the history
* chore: add usdc price query

* chore: fix endpoint url

* chore: define usdc price resp

* chore: update query_message return type

* chore: update contract version
  • Loading branch information
kenta-elys authored Dec 11, 2023
1 parent db522f2 commit 97bc3a1
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "financial_snapshot_contract"
version = "0.3.0"
version = "0.3.1"
edition = "2021"

[lib]
Expand All @@ -15,11 +15,11 @@ schemars = "0.8.1"
cosmwasm-schema = "1.1.4"
cw-utils = "0.13"
anyhow = "1"
elys-bindings = { version = "0.8.0", git = "https://github.com/elys-network/bindings", tag = "v0.8.0" }
elys-bindings = { version = "0.9.0", git = "https://github.com/elys-network/bindings", tag = "v0.9.0" }

[dev-dependencies]
cw-multi-test = "0.13.4"
elys-bindings = { version = "0.8.0", git = "https://github.com/elys-network/bindings", tag = "v0.8.0", features = [
elys-bindings = { version = "0.9.0", git = "https://github.com/elys-network/bindings", tag = "v0.9.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 @@ -30,6 +30,7 @@ pub mod query {
mod get_unbonding_delegations;
mod get_commitments;
mod get_pools;
mod get_usdc_price;

use cosmwasm_std::Deps;
use crate::ContractError;
Expand All @@ -43,5 +44,6 @@ pub mod query {
pub use get_unbonding_delegations::get_unbonding_delegations;
pub use get_commitments::get_commitments;
pub use get_pools::get_pools;
pub use get_usdc_price::get_usdc_price;
}
}
15 changes: 15 additions & 0 deletions src/action/query/earn/get_usdc_price.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::*;
use cosmwasm_std::{Decimal, Uint128};
use crate::bindings::{query::ElysQuery, querier::ElysQuerier};
use crate::types::ElysDenom;
use crate::msg::query_resp::earn::GetUsdcPriceResp;

pub fn get_usdc_price(deps: Deps<ElysQuery>) -> Result<GetUsdcPriceResp, ContractError> {
let querier = ElysQuerier::new(&deps.querier);
let usdc_oracle_price = querier.get_oracle_price(ElysDenom::USDC.as_str().to_string(), "".to_string(), 0)?;
let usdc_usd_price = usdc_oracle_price.price.price.checked_div(Decimal::from_atomics(Uint128::new(1000000), 0).unwrap()).unwrap();
let resp = GetUsdcPriceResp {
price: usdc_usd_price,
};
Ok(resp)
}
3 changes: 3 additions & 0 deletions src/entry_point/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ pub fn query(deps: Deps<ElysQuery>, _env: Env, msg: QueryMsg) -> Result<Binary,

// Liquidity Pools
GetLiquidityPools { pool_ids, filter_type, pagination} => Ok(to_json_binary(&earn::get_pools(deps, pool_ids, filter_type, pagination)?)?),

// Specific function for querying USDC oracle price
GetUsdcPrice { } => Ok(to_json_binary(&earn::get_usdc_price(deps)?)?),
}
}
2 changes: 2 additions & 0 deletions src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ pub mod query_resp {
pub use get_usdc_earn_details_resp::GetUsdcEarnProgramResp;
mod get_pool_resp;
pub use get_pool_resp::{QueryEarnPoolResponse, FilterType};
mod get_usdc_price_resp;
pub use get_usdc_price_resp::GetUsdcPriceResp;
}
}
2 changes: 2 additions & 0 deletions src/msg/query_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ pub enum QueryMsg {
GetCommitments { delegator_addr: String },
#[returns(QueryEarnPoolResponse)]
GetLiquidityPools { pool_ids: Option<Vec<u64>>, filter_type: FilterType, pagination: Option<PageRequest> },
#[returns(GetUsdcPriceResp)]
GetUsdcPrice{}
}
7 changes: 7 additions & 0 deletions src/msg/query_resp/earn/get_usdc_price_resp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Decimal;

#[cw_serde]
pub struct GetUsdcPriceResp {
pub price: Decimal,
}

0 comments on commit 97bc3a1

Please sign in to comment.