From 159b6ada1de978c1808f308a1c5860a876c34fa3 Mon Sep 17 00:00:00 2001 From: Markus Waas Date: Wed, 14 Feb 2024 17:46:34 -0600 Subject: [PATCH] feat: add contract versioning --- Cargo.lock | 2 +- contracts/swap/Cargo.toml | 4 ++-- contracts/swap/src/contract.rs | 14 +++++++++++--- contracts/swap/src/helpers.rs | 1 - contracts/swap/src/msg.rs | 1 + contracts/swap/src/state.rs | 5 +++++ contracts/swap/src/types.rs | 6 ++++++ 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 657810e..fdbec18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1313,7 +1313,7 @@ dependencies = [ [[package]] name = "injective-converter" -version = "0.1.0" +version = "1.0.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/contracts/swap/Cargo.toml b/contracts/swap/Cargo.toml index 5a0f402..d9d0327 100644 --- a/contracts/swap/Cargo.toml +++ b/contracts/swap/Cargo.toml @@ -1,8 +1,8 @@ [package] -authors = [ "Antoni Mysliborski " ] +authors = [ "Markus Waas " ] edition = "2021" name = "injective-converter" -version = "0.1.0" +version = "1.0.0" exclude = [ # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. diff --git a/contracts/swap/src/contract.rs b/contracts/swap/src/contract.rs index 4f9ad67..6592215 100644 --- a/contracts/swap/src/contract.rs +++ b/contracts/swap/src/contract.rs @@ -3,17 +3,17 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, }; -use cw2::set_contract_version; +use cw2::{get_contract_version, set_contract_version}; use crate::admin::{delete_route, save_config, set_route, update_config, withdraw_support_funds}; -use crate::types::SwapQuantityMode; +use crate::types::{ConfigResponse, SwapQuantityMode}; use injective_cosmwasm::{InjectiveMsgWrapper, InjectiveQueryWrapper}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; use crate::queries::{estimate_swap_result, SwapQuantity}; -use crate::state::{get_all_swap_routes, read_swap_route}; +use crate::state::{get_all_swap_routes, get_config, read_swap_route}; use crate::swap::{handle_atomic_order_reply, start_swap_flow}; // version info for migration info @@ -141,5 +141,13 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdR let routes = get_all_swap_routes(deps.storage)?; Ok(to_json_binary(&routes)?) } + QueryMsg::GetConfig {} => { + let config = get_config(deps.storage)?; + let config_response = ConfigResponse { + config, + contract_version: get_contract_version(deps.storage)?.version, + }; + Ok(to_json_binary(&config_response)?) + } } } diff --git a/contracts/swap/src/helpers.rs b/contracts/swap/src/helpers.rs index c0c7f36..27d8f17 100644 --- a/contracts/swap/src/helpers.rs +++ b/contracts/swap/src/helpers.rs @@ -47,7 +47,6 @@ impl Scaled for FPDecimal { pub fn dec_scale_factor() -> FPDecimal { FPDecimal::ONE.scaled(18) - // FPDecimal::from(1000000000000000000_i128) } #[cfg(test)] diff --git a/contracts/swap/src/msg.rs b/contracts/swap/src/msg.rs index 0f197b6..f0c841e 100644 --- a/contracts/swap/src/msg.rs +++ b/contracts/swap/src/msg.rs @@ -66,4 +66,5 @@ pub enum QueryMsg { target_denom: String, }, GetAllRoutes {}, + GetConfig {}, } diff --git a/contracts/swap/src/state.rs b/contracts/swap/src/state.rs index 5cde149..bc90154 100644 --- a/contracts/swap/src/state.rs +++ b/contracts/swap/src/state.rs @@ -27,6 +27,11 @@ pub fn read_swap_route( }) } +pub fn get_config(storage: &dyn Storage) -> StdResult { + let config = CONFIG.load(storage)?; + Ok(config) +} + pub fn get_all_swap_routes(storage: &dyn Storage) -> StdResult> { let routes = SWAP_ROUTES .range(storage, None, None, Order::Ascending) diff --git a/contracts/swap/src/types.rs b/contracts/swap/src/types.rs index ce993e4..911f861 100644 --- a/contracts/swap/src/types.rs +++ b/contracts/swap/src/types.rs @@ -32,6 +32,12 @@ impl From for FPCoin { } } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct ConfigResponse { + pub config: Config, + pub contract_version: String, +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub enum SwapQuantityMode { MinOutputQuantity(FPDecimal),