From 97bc3a1e24230a9e6bc340a263fe278cbe7d36ad Mon Sep 17 00:00:00 2001 From: kenta-elys <130330089+kenta-elys@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:53:05 +0900 Subject: [PATCH] Feat/usdc price (#16) * chore: add usdc price query * chore: fix endpoint url * chore: define usdc price resp * chore: update query_message return type * chore: update contract version --- Cargo.lock | 30 +++++++++---------- Cargo.toml | 6 ++-- src/action/mod.rs | 2 ++ src/action/query/earn/get_usdc_price.rs | 15 ++++++++++ src/entry_point/query.rs | 3 ++ src/msg/mod.rs | 2 ++ src/msg/query_msg.rs | 2 ++ .../query_resp/earn/get_usdc_price_resp.rs | 7 +++++ 8 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 src/action/query/earn/get_usdc_price.rs create mode 100644 src/msg/query_resp/earn/get_usdc_price_resp.rs diff --git a/Cargo.lock b/Cargo.lock index 1b81a9b..155297e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,8 +371,8 @@ dependencies = [ [[package]] name = "elys-bindings" -version = "0.8.0" -source = "git+https://github.com/elys-network/bindings?tag=v0.8.0#6e3eba16496f7ea9ded374099c6ad6e51331708f" +version = "0.9.0" +source = "git+https://github.com/elys-network/bindings?tag=v0.9.0#7665defad591d08530b4a247dcb6cbb3d66584c9" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -391,7 +391,7 @@ dependencies = [ [[package]] name = "financial_snapshot_contract" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "cosmwasm-schema", @@ -479,9 +479,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "k256" @@ -499,15 +499,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.150" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" @@ -593,9 +593,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "schemars" @@ -661,7 +661,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] @@ -755,9 +755,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "13fa70a4ee923979ffb522cacce59d34421ebdea5625e1073c4326ef9d2dd42e" dependencies = [ "proc-macro2", "quote", @@ -781,7 +781,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.40", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 11ea9b0..0b7660d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "financial_snapshot_contract" -version = "0.3.0" +version = "0.3.1" edition = "2021" [lib] @@ -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", ] } diff --git a/src/action/mod.rs b/src/action/mod.rs index 40b8833..c6958f7 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -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; @@ -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; } } diff --git a/src/action/query/earn/get_usdc_price.rs b/src/action/query/earn/get_usdc_price.rs new file mode 100644 index 0000000..eed47bb --- /dev/null +++ b/src/action/query/earn/get_usdc_price.rs @@ -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) -> Result { + 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) +} \ No newline at end of file diff --git a/src/entry_point/query.rs b/src/entry_point/query.rs index 132cc62..7a4de95 100644 --- a/src/entry_point/query.rs +++ b/src/entry_point/query.rs @@ -31,5 +31,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result 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)?)?), } } diff --git a/src/msg/mod.rs b/src/msg/mod.rs index 348021f..7fd1b0d 100644 --- a/src/msg/mod.rs +++ b/src/msg/mod.rs @@ -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; } } \ No newline at end of file diff --git a/src/msg/query_msg.rs b/src/msg/query_msg.rs index 8f3c709..2f63a47 100644 --- a/src/msg/query_msg.rs +++ b/src/msg/query_msg.rs @@ -48,4 +48,6 @@ pub enum QueryMsg { GetCommitments { delegator_addr: String }, #[returns(QueryEarnPoolResponse)] GetLiquidityPools { pool_ids: Option>, filter_type: FilterType, pagination: Option }, + #[returns(GetUsdcPriceResp)] + GetUsdcPrice{} } diff --git a/src/msg/query_resp/earn/get_usdc_price_resp.rs b/src/msg/query_resp/earn/get_usdc_price_resp.rs new file mode 100644 index 0000000..097987f --- /dev/null +++ b/src/msg/query_resp/earn/get_usdc_price_resp.rs @@ -0,0 +1,7 @@ +use cosmwasm_schema::cw_serde; +use cosmwasm_std::Decimal; + +#[cw_serde] +pub struct GetUsdcPriceResp { + pub price: Decimal, +}