Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release query #490

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions platform/contracts/admin/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult<Binary>
.and_then(|ref protocol| {
cosmwasm_std::to_json_binary::<ProtocolQueryResponse>(protocol).map_err(Into::into)
}),
QueryMsg::PlatformPackageRelease {} => {
cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into)
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion platform/contracts/admin/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ where
Uint64: Into<CodeId>,
CodeId: Into<Uint64>,
{
InstantiateAddress { code_id: Uint64, protocol: String },
InstantiateAddress {
code_id: Uint64,
protocol: String,
},
Protocols {},
Platform {},
Protocol(String),
/// Implementation of [versioning::query::PlatformPackage::Release]
PlatformPackageRelease {},
}

pub type ProtocolsQueryResponse = Vec<String>;
Expand Down
3 changes: 3 additions & 0 deletions platform/contracts/timealarms/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult<Binary>
QueryMsg::AlarmsStatus {} => Ok(to_json_binary(
&TimeAlarms::new(deps.storage).try_any_alarm(env.block.time)?,
)?),
QueryMsg::PlatformPackageRelease {} => {
cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into)
}
}
.inspect_err(platform_error::log(deps.api))
}
Expand Down
2 changes: 2 additions & 0 deletions platform/contracts/timealarms/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum SudoMsg {}
pub enum QueryMsg {
ContractVersion {},
AlarmsStatus {},
/// Implementation of [versioning::query::PlatformPackage::Release]
PlatformPackageRelease {},
}

#[derive(Serialize, Deserialize, Clone, Copy, Eq, PartialEq, JsonSchema)]
Expand Down
3 changes: 3 additions & 0 deletions platform/contracts/treasury/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult<Binary>
}
QueryMsg::CalculateRewards {} => query_reward_apr(deps.storage, deps.querier, &env)
.and_then(|ref apr| to_json_binary(apr).map_err(ContractError::Serialize)),
QueryMsg::PlatformPackageRelease {} => {
cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into)
}
}
.inspect_err(platform_error::log(deps.api))
}
Expand Down
2 changes: 2 additions & 0 deletions platform/contracts/treasury/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum SudoMsg {
pub enum QueryMsg {
Config {},
CalculateRewards {},
/// Implementation of [versioning::query::PlatformPackage::Release]
PlatformPackageRelease {},
}

// We define a custom struct for each query response
Expand Down
4 changes: 2 additions & 2 deletions platform/packages/versioning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub use crate::{
error::Error,
protocol::Release as ProtocolRelease,
release::{
Id as ReleaseId, PlatformPackageRelease, ProtocolPackageRelease, ProtocolPackageReleaseId,
UpdatablePackage,
query, Id as ReleaseId, PlatformPackageRelease, ProtocolPackageRelease,
ProtocolPackageReleaseId, UpdatablePackage,
},
software::{PackageRelease as SoftwarePackageRelease, VersionSegment},
};
Expand Down
4 changes: 4 additions & 0 deletions platform/packages/versioning/src/release/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use self::id::Id;
#[cfg(feature = "protocol_contract")]
mod current;
mod id;
pub mod query;

pub trait UpdatablePackage
where
Expand All @@ -26,12 +27,15 @@ where
}

pub type PlatformPackageRelease = SoftwarePackageRelease;
#[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct ProtocolPackageRelease {
software: SoftwarePackageRelease,
protocol: ProtocolRelease,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct ProtocolPackageReleaseId {
software: Id,
protocol: Id,
Expand Down
52 changes: 52 additions & 0 deletions platform/packages/versioning/src/release/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use serde::Serialize;
use thiserror::Error;

use sdk::cosmwasm_std::{Addr, QuerierWrapper, StdError};

use super::{PlatformPackageRelease, ProtocolPackageRelease};

/// A common versioning API of each platform package
#[derive(Serialize)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum PlatformPackage {
/// Query the platform package for its release.
///
/// The result is [versioning::PlatformPackageRelease]
#[serde(rename = "platform_package_release")]
Release {},
}

/// A common versioning API of each protocol package
#[derive(Serialize)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum ProtocolPackage {
/// Query the protocol package for its release.
///
/// The result is [versioning::ProtocolPackageRelease]
#[serde(rename = "protocol_package_release")]
Release {},
}
gmanev7 marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Error, Debug, PartialEq)]
pub enum Error {
#[error("[Versioning][Query] {0}")]
Transmission(StdError),
}

pub fn platform_release(
contract: Addr,
querier: QuerierWrapper<'_>,
) -> Result<PlatformPackageRelease, Error> {
querier
.query_wasm_smart(contract, &PlatformPackage::Release {})
.map_err(Error::Transmission)
}

pub fn protocol_release(
contract: Addr,
querier: QuerierWrapper<'_>,
) -> Result<ProtocolPackageRelease, Error> {
querier
.query_wasm_smart(contract, &ProtocolPackage::Release {})
.map_err(Error::Transmission)
}
4 changes: 2 additions & 2 deletions protocol/contracts/lease/examples/lease_schema.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use lease::api::{open::NewLeaseForm, query::StateQuery, ExecuteMsg};
use lease::api::{open::NewLeaseForm, query::QueryMsg, ExecuteMsg};
use sdk::cosmwasm_schema::{export_schema, schema_for};

fn main() {
let out_dir = schema::prep_out_dir().expect("The output directory should be valid");
export_schema(&schema_for!(NewLeaseForm), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(StateQuery), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
}
12 changes: 9 additions & 3 deletions protocol/contracts/lease/src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ pub use opened::ClosePolicy;
#[derive(Deserialize, JsonSchema)]
#[cfg_attr(any(test, feature = "testing"), derive(Clone, Debug, Serialize))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct StateQuery {
pub enum QueryMsg {
/// Ask for estimation of the due and overdue amounts and periods in that point of time
///
/// Return a [StateResponse]
///
/// The value is meaningfull only if the lease is in Opened state.
#[serde(default, rename = "due_projection_secs")]
pub due_projection: Seconds,
State {
#[serde(default, rename = "due_projection_secs")]
due_projection: Seconds,
},
KirilMihaylov marked this conversation as resolved.
Show resolved Hide resolved
/// Implementation of [versioning::query::ProtocolPackage::Release]
ProtocolPackageRelease {},
}

#[derive(Serialize)]
Expand Down
27 changes: 15 additions & 12 deletions protocol/contracts/lease/src/contract/endpoins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use versioning::{
};

use crate::{
api::{open::NewLeaseContract, query::StateQuery, ExecuteMsg, MigrateMsg},
api::{open::NewLeaseContract, query::QueryMsg, ExecuteMsg, MigrateMsg},
contract::api::Contract,
error::{ContractError, ContractResult},
};
Expand Down Expand Up @@ -93,17 +93,20 @@ pub fn sudo(deps: DepsMut<'_>, env: Env, msg: SudoMsg) -> ContractResult<CwRespo
}

#[entry_point]
pub fn query(deps: Deps<'_>, env: Env, msg: StateQuery) -> ContractResult<Binary> {
state::load(deps.storage)
.and_then(|state| {
state.state(
env.block.time,
Duration::from_secs(msg.due_projection),
deps.querier,
)
})
.and_then(|resp| to_json_binary(&resp).map_err(Into::into))
.inspect_err(platform_error::log(deps.api))
pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult<Binary> {
match msg {
QueryMsg::State { due_projection } => state::load(deps.storage)
.and_then(|state| {
state.state(
env.block.time,
Duration::from_secs(due_projection),
deps.querier,
)
})
.and_then(|resp| to_json_binary(&resp).map_err(Into::into)),
QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE).map_err(Into::into),
}
.inspect_err(platform_error::log(deps.api))
}

fn process_lease<ProcFn>(
Expand Down
1 change: 1 addition & 0 deletions protocol/contracts/leaser/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub fn sudo(deps: DepsMut<'_>, _env: Env, msg: SudoMsg) -> ContractResult<Respon
pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
match msg {
QueryMsg::Config {} => to_json_binary(&Leaser::new(deps).config()?),
QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE),
QueryMsg::Quote {
downpayment,
lease_asset,
Expand Down
2 changes: 2 additions & 0 deletions protocol/contracts/leaser/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum ForceClose {
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum QueryMsg {
Config {},
/// Implementation of [versioning::query::ProtocolPackage::Release]
ProtocolPackageRelease {},
Quote {
downpayment: DownpaymentCoin,
lease_asset: CurrencyDTO<LeaseCurrencies>,
Expand Down
1 change: 1 addition & 0 deletions protocol/contracts/lpp/src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub fn sudo(deps: DepsMut<'_>, _env: Env, msg: SudoMsg) -> Result<CwResponse> {
pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg<LpnCurrencies>) -> Result<Binary> {
match msg {
QueryMsg::Config() => Config::load(deps.storage).and_then(|ref resp| to_json_binary(resp)),
QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE),
QueryMsg::Lpn() => to_json_binary(LpnCurrency::definition().dto()),
QueryMsg::Balance { address } => {
lender::query_balance(deps.storage, address).and_then(|ref resp| to_json_binary(resp))
Expand Down
2 changes: 2 additions & 0 deletions protocol/contracts/lpp/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ where
Lpns: Group,
{
Config(),
/// Implementation of [versioning::query::ProtocolPackage::Release]
ProtocolPackageRelease {},
/// Report the Lpn currency as [CurrencyDTO<Lpns>]
Lpn(),
Quote {
Expand Down
3 changes: 3 additions & 0 deletions protocol/contracts/oracle/src/api/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ where
// Returns contract's semantic version as a package, which is set in `Cargo.toml`.
ContractVersion {},

/// Implementation of [versioning::query::ProtocolPackage::Release]
ProtocolPackageRelease {},

// returns the contract configuration
Config {},

Expand Down
1 change: 1 addition & 0 deletions protocol/contracts/oracle/src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn migrate(
pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg<PriceCurrencies>) -> ContractResult<Binary> {
match msg {
QueryMsg::ContractVersion {} => to_json_binary(CURRENT_VERSION),
QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE),
QueryMsg::Config {} => to_json_binary(&query_config(deps.storage)?),
QueryMsg::Feeders {} => Feeders::get(deps.storage)
.map_err(ContractError::LoadFeeders)
Expand Down
1 change: 1 addition & 0 deletions protocol/contracts/profit/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> ContractResult<Binary>
env.block.time,
deps.querier,
)?),
QueryMsg::ProtocolPackageRelease {} => to_json_binary(&CURRENT_RELEASE),
}
.map_err(Into::into)
}
2 changes: 2 additions & 0 deletions protocol/contracts/profit/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum ExecuteMsg {
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum QueryMsg {
Config {},
/// Implementation of [versioning::query::ProtocolPackage::Release]
ProtocolPackageRelease {},
}

// We define a custom struct for each query response
Expand Down
2 changes: 2 additions & 0 deletions protocol/contracts/reserve/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub enum QueryMsg {
ReserveLpn(), // the name contains the contract name to help distinguish from simmilar queries to other contracts
/// Return a [ConfigResponse]
Config(),
/// Implementation of [versioning::query::ProtocolPackage::Release]
ProtocolPackageRelease {},
}

#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)]
Expand Down
10 changes: 6 additions & 4 deletions protocol/contracts/reserve/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ pub fn execute(
#[entry_point]
pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> Result<Binary> {
match msg {
QueryMsg::Config() => Config::load(deps.storage)
.map(ConfigResponse::from)
.and_then(|config| cosmwasm_std::to_json_binary(&config).map_err(Into::into)),
QueryMsg::ReserveLpn() => cosmwasm_std::to_json_binary(
&currency::to_string::<LpnCurrency>(LpnCurrency::definition()),
)
.map_err(Into::into),
QueryMsg::Config() => Config::load(deps.storage)
.map(ConfigResponse::from)
.and_then(|config| cosmwasm_std::to_json_binary(&config).map_err(Into::into)),
QueryMsg::ProtocolPackageRelease {} => {
cosmwasm_std::to_json_binary(&CURRENT_RELEASE).map_err(Into::into)
}
}
.map_err(Into::into)
.inspect_err(platform_error::log(deps.api))
}

Expand Down
1 change: 1 addition & 0 deletions scripts/check/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ append_lint_flags() {
--deny "rust-2021-compatibility" \
--deny "rust-2024-compatibility" \
--allow "impl-trait-overcaptures" \
--forbid "unfulfilled_lint_expectations" \
--deny "unused" \
--deny "warnings"
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/common/lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lease::{
ConnectionParams, Ics20Channel, LoanForm, NewLeaseContract, NewLeaseForm,
PositionSpecDTO,
},
query::{StateQuery, StateResponse},
query::{QueryMsg, StateResponse},
},
contract::{execute, instantiate, query, reply, sudo},
};
Expand Down Expand Up @@ -351,7 +351,7 @@ pub(crate) fn fetch_state(app: &App, lease: Addr) -> StateResponse {
app.query()
.query_wasm_smart(
lease,
&StateQuery {
&QueryMsg::State {
due_projection: Seconds::default(),
},
)
Expand Down