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

Commit

Permalink
chore: define usdc price resp
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-elys committed Dec 8, 2023
1 parent 846f676 commit 6ce643c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 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.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
8 changes: 6 additions & 2 deletions src/action/query/earn/get_usdc_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ 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<Decimal, ContractError> {
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();
Ok(usdc_usd_price)
let resp = GetUsdcPriceResp {
price: usdc_usd_price,
};
Ok(resp)
}
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;
}
}
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 6ce643c

Please sign in to comment.