Skip to content

Commit 159b6ad

Browse files
committed
feat: add contract versioning
1 parent 1334665 commit 159b6ad

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/swap/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
2-
authors = [ "Antoni Mysliborski <antoni@injectivelabs.org>" ]
2+
authors = [ "Markus Waas <markus@injectivelabs.org>" ]
33
edition = "2021"
44
name = "injective-converter"
5-
version = "0.1.0"
5+
version = "1.0.0"
66

77
exclude = [
88
# 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.

contracts/swap/src/contract.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ use cosmwasm_std::entry_point;
33
use cosmwasm_std::{
44
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult,
55
};
6-
use cw2::set_contract_version;
6+
use cw2::{get_contract_version, set_contract_version};
77

88
use crate::admin::{delete_route, save_config, set_route, update_config, withdraw_support_funds};
9-
use crate::types::SwapQuantityMode;
9+
use crate::types::{ConfigResponse, SwapQuantityMode};
1010
use injective_cosmwasm::{InjectiveMsgWrapper, InjectiveQueryWrapper};
1111

1212
use crate::error::ContractError;
1313

1414
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
1515
use crate::queries::{estimate_swap_result, SwapQuantity};
16-
use crate::state::{get_all_swap_routes, read_swap_route};
16+
use crate::state::{get_all_swap_routes, get_config, read_swap_route};
1717
use crate::swap::{handle_atomic_order_reply, start_swap_flow};
1818

1919
// version info for migration info
@@ -141,5 +141,13 @@ pub fn query(deps: Deps<InjectiveQueryWrapper>, env: Env, msg: QueryMsg) -> StdR
141141
let routes = get_all_swap_routes(deps.storage)?;
142142
Ok(to_json_binary(&routes)?)
143143
}
144+
QueryMsg::GetConfig {} => {
145+
let config = get_config(deps.storage)?;
146+
let config_response = ConfigResponse {
147+
config,
148+
contract_version: get_contract_version(deps.storage)?.version,
149+
};
150+
Ok(to_json_binary(&config_response)?)
151+
}
144152
}
145153
}

contracts/swap/src/helpers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ impl Scaled for FPDecimal {
4747

4848
pub fn dec_scale_factor() -> FPDecimal {
4949
FPDecimal::ONE.scaled(18)
50-
// FPDecimal::from(1000000000000000000_i128)
5150
}
5251

5352
#[cfg(test)]

contracts/swap/src/msg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ pub enum QueryMsg {
6666
target_denom: String,
6767
},
6868
GetAllRoutes {},
69+
GetConfig {},
6970
}

contracts/swap/src/state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ pub fn read_swap_route(
2727
})
2828
}
2929

30+
pub fn get_config(storage: &dyn Storage) -> StdResult<Config> {
31+
let config = CONFIG.load(storage)?;
32+
Ok(config)
33+
}
34+
3035
pub fn get_all_swap_routes(storage: &dyn Storage) -> StdResult<Vec<SwapRoute>> {
3136
let routes = SWAP_ROUTES
3237
.range(storage, None, None, Order::Ascending)

contracts/swap/src/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ impl From<Coin> for FPCoin {
3232
}
3333
}
3434

35+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
36+
pub struct ConfigResponse {
37+
pub config: Config,
38+
pub contract_version: String,
39+
}
40+
3541
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
3642
pub enum SwapQuantityMode {
3743
MinOutputQuantity(FPDecimal),

0 commit comments

Comments
 (0)