Skip to content

Commit

Permalink
feat: add contract versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
gorgos committed Feb 14, 2024
1 parent 1334665 commit 159b6ad
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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 contracts/swap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
authors = [ "Antoni Mysliborski <antoni@injectivelabs.org>" ]
authors = [ "Markus Waas <markus@injectivelabs.org>" ]
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.
Expand Down
14 changes: 11 additions & 3 deletions contracts/swap/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -141,5 +141,13 @@ pub fn query(deps: Deps<InjectiveQueryWrapper>, 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)?)
}
}
}
1 change: 0 additions & 1 deletion contracts/swap/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ impl Scaled for FPDecimal {

pub fn dec_scale_factor() -> FPDecimal {
FPDecimal::ONE.scaled(18)
// FPDecimal::from(1000000000000000000_i128)
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions contracts/swap/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ pub enum QueryMsg {
target_denom: String,
},
GetAllRoutes {},
GetConfig {},
}
5 changes: 5 additions & 0 deletions contracts/swap/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ pub fn read_swap_route(
})
}

pub fn get_config(storage: &dyn Storage) -> StdResult<Config> {
let config = CONFIG.load(storage)?;
Ok(config)
}

pub fn get_all_swap_routes(storage: &dyn Storage) -> StdResult<Vec<SwapRoute>> {
let routes = SWAP_ROUTES
.range(storage, None, None, Order::Ascending)
Expand Down
6 changes: 6 additions & 0 deletions contracts/swap/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ impl From<Coin> 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),
Expand Down

0 comments on commit 159b6ad

Please sign in to comment.