diff --git a/Cargo.lock b/Cargo.lock index f821573c9..b1e7d67d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2222,6 +2222,7 @@ dependencies = [ "dao-voting-cw4 2.5.0", "dao-voting-cw721-staked", "dao-voting-token-staked", + "semver", "thiserror", ] diff --git a/contracts/distribution/dao-rewards-distributor/Cargo.toml b/contracts/distribution/dao-rewards-distributor/Cargo.toml index 0df6ef1d5..4d38cbc3b 100644 --- a/contracts/distribution/dao-rewards-distributor/Cargo.toml +++ b/contracts/distribution/dao-rewards-distributor/Cargo.toml @@ -29,6 +29,7 @@ cw-utils = { workspace = true } dao-hooks = { workspace = true } dao-interface = { workspace = true } dao-voting = { workspace = true } +semver = { workspace = true } thiserror = { workspace = true } [dev-dependencies] diff --git a/contracts/distribution/dao-rewards-distributor/src/contract.rs b/contracts/distribution/dao-rewards-distributor/src/contract.rs index 3a6e3c6e0..b0ae7b7a6 100644 --- a/contracts/distribution/dao-rewards-distributor/src/contract.rs +++ b/contracts/distribution/dao-rewards-distributor/src/contract.rs @@ -9,6 +9,7 @@ use cw20::{Cw20ReceiveMsg, Denom}; use cw_storage_plus::Bound; use cw_utils::{must_pay, nonpayable, Duration, Expiration}; use dao_interface::voting::InfoResponse; +use semver::Version; use std::ops::Add; @@ -592,6 +593,12 @@ fn query_distributions( #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + let version: Version = CONTRACT_VERSION.parse()?; + let storage_version: Version = get_contract_version(deps.storage)?.version.parse()?; + + if storage_version < version { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + } + Ok(Response::default()) } diff --git a/contracts/distribution/dao-rewards-distributor/src/error.rs b/contracts/distribution/dao-rewards-distributor/src/error.rs index 94d7bbb85..e28bd4b17 100644 --- a/contracts/distribution/dao-rewards-distributor/src/error.rs +++ b/contracts/distribution/dao-rewards-distributor/src/error.rs @@ -22,6 +22,9 @@ pub enum ContractError { #[error(transparent)] Payment(#[from] PaymentError), + #[error("semver parsing error: {0}")] + SemVer(String), + #[error("Invalid CW20")] InvalidCw20 {}, @@ -55,3 +58,9 @@ pub enum ContractError { #[error("Cannot update emission rate because this distribution has accumulated the maximum rewards. Start a new distribution with the new emission rate instead. (Overflow: {err})")] DistributionHistoryTooLarge { err: String }, } + +impl From for ContractError { + fn from(err: semver::Error) -> Self { + Self::SemVer(err.to_string()) + } +}