diff --git a/Cargo.lock b/Cargo.lock index 5bafd67..dea8ad0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -875,7 +875,7 @@ dependencies = [ [[package]] name = "infinity-global" -version = "0.1.0" +version = "0.1.1" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -929,7 +929,7 @@ dependencies = [ [[package]] name = "infinity-router" -version = "0.1.0" +version = "0.1.1" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/contracts/infinity-global/Cargo.toml b/contracts/infinity-global/Cargo.toml index 6e3a02b..8eab107 100644 --- a/contracts/infinity-global/Cargo.toml +++ b/contracts/infinity-global/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "infinity-global" -version = "0.1.0" +version = "0.1.1" edition = { workspace = true } repository = { workspace = true } license = { workspace = true } diff --git a/contracts/infinity-global/schema/infinity-global.json b/contracts/infinity-global/schema/infinity-global.json index ec36565..d704592 100644 --- a/contracts/infinity-global/schema/infinity-global.json +++ b/contracts/infinity-global/schema/infinity-global.json @@ -1,6 +1,6 @@ { "contract_name": "infinity-global", - "contract_version": "0.1.0", + "contract_version": "0.1.1", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/contracts/infinity-global/src/lib.rs b/contracts/infinity-global/src/lib.rs index c141f9d..ef99cbc 100644 --- a/contracts/infinity-global/src/lib.rs +++ b/contracts/infinity-global/src/lib.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ - coin, to_binary, Addr, Binary, Deps, DepsMut, Empty, Env, Event, MessageInfo, QuerierWrapper, - StdError, StdResult, Uint128, + coin, ensure, to_binary, Addr, Binary, Deps, DepsMut, Empty, Env, Event, MessageInfo, + QuerierWrapper, StdError, StdResult, Uint128, }; use cosmwasm_std::{Api, Coin, Decimal}; use cw2::set_contract_version; @@ -305,3 +305,34 @@ pub fn sudo_remove_min_prices(deps: DepsMut, denoms: Vec) -> Result Result { + let prev_contract_version = cw2::get_contract_version(deps.storage)?; + + let valid_contract_names = vec![CONTRACT_NAME.to_string()]; + ensure!( + valid_contract_names.contains(&prev_contract_version.contract), + StdError::generic_err("Invalid contract name for migration") + ); + + ensure!( + prev_contract_version.version < CONTRACT_VERSION.to_string(), + StdError::generic_err("Must upgrade contract version") + ); + + sudo(deps.branch(), env, msg)?; + + cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + let response = Response::new().add_event( + Event::new("migrate") + .add_attribute("from_name", prev_contract_version.contract) + .add_attribute("from_version", prev_contract_version.version) + .add_attribute("to_name", CONTRACT_NAME) + .add_attribute("to_version", CONTRACT_VERSION), + ); + + Ok(response) +} diff --git a/contracts/infinity-router/Cargo.toml b/contracts/infinity-router/Cargo.toml index 059e178..c65d7e9 100644 --- a/contracts/infinity-router/Cargo.toml +++ b/contracts/infinity-router/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "infinity-router" -version = "0.1.0" +version = "0.1.1" edition = { workspace = true } repository = { workspace = true } license = { workspace = true } diff --git a/contracts/infinity-router/schema/infinity-router.json b/contracts/infinity-router/schema/infinity-router.json index da78ed8..67f8903 100644 --- a/contracts/infinity-router/schema/infinity-router.json +++ b/contracts/infinity-router/schema/infinity-router.json @@ -1,6 +1,6 @@ { "contract_name": "infinity-router", - "contract_version": "0.1.0", + "contract_version": "0.1.1", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/contracts/infinity-router/src/lib.rs b/contracts/infinity-router/src/lib.rs index 59a7a5f..c6de7ef 100644 --- a/contracts/infinity-router/src/lib.rs +++ b/contracts/infinity-router/src/lib.rs @@ -1,6 +1,7 @@ pub mod execute; pub mod helpers; pub mod instantiate; +pub mod migrate; pub mod msg; pub mod nfts_for_tokens_iterators; pub mod query; diff --git a/contracts/infinity-router/src/migrate.rs b/contracts/infinity-router/src/migrate.rs new file mode 100644 index 0000000..4f6f869 --- /dev/null +++ b/contracts/infinity-router/src/migrate.rs @@ -0,0 +1,39 @@ +use crate::{ + error::ContractError, + instantiate::{CONTRACT_NAME, CONTRACT_VERSION}, +}; + +use cosmwasm_std::{ensure, DepsMut, Empty, Env, Event, StdError}; +use sg_std::Response; + +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; + +#[cfg_attr(not(feature = "library"), entry_point)] +#[allow(clippy::cmp_owned)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result { + let prev_contract_version = cw2::get_contract_version(deps.storage)?; + + let valid_contract_names = vec![CONTRACT_NAME.to_string()]; + ensure!( + valid_contract_names.contains(&prev_contract_version.contract), + StdError::generic_err("Invalid contract name for migration") + ); + + ensure!( + prev_contract_version.version < CONTRACT_VERSION.to_string(), + StdError::generic_err("Must upgrade contract version") + ); + + cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + let response = Response::new().add_event( + Event::new("migrate") + .add_attribute("from_name", prev_contract_version.contract) + .add_attribute("from_version", prev_contract_version.version) + .add_attribute("to_name", CONTRACT_NAME) + .add_attribute("to_version", CONTRACT_VERSION), + ); + + Ok(response) +}