Skip to content

Commit

Permalink
remove dependency on past version of same contract to prevent depende…
Browse files Browse the repository at this point in the history
…ncy name collisions when publishing
  • Loading branch information
NoahSaso committed Oct 31, 2024
1 parent 340b1e1 commit d453222
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions packages/dao-pre-propose-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,5 @@ serde = { workspace = true }
thiserror = { workspace = true }
semver = { workspace = true }

# v2.4.1 packages for state migration
cw-denom-v241 = { workspace = true }
dao-pre-propose-base-v241 = { workspace = true }
dao-voting-v241 = { workspace = true }

[dev-dependencies]
cw-multi-test = { workspace = true }
65 changes: 56 additions & 9 deletions packages/dao-pre-propose-base/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use cosmwasm_schema::schemars::JsonSchema;
use cosmwasm_schema::{cw_serde, schemars::JsonSchema};
use cosmwasm_std::{
to_json_binary, Addr, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdError,
StdResult, SubMsg, WasmMsg,
to_json_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult,
SubMsg, Uint128, WasmMsg,
};

use cw_storage_plus::Item;
use semver::{Version, VersionReq};

use cw2::{get_contract_version, set_contract_version, ContractVersion};
Expand All @@ -24,10 +25,6 @@ use crate::{
state::{Config, PreProposeContract},
};

use cw_denom_v241::CheckedDenom as CheckedDenomV241;
use dao_pre_propose_base_v241::state::PreProposeContract as PreProposeContractV241;
use dao_voting_v241::deposit::DepositRefundPolicy as DepositRefundPolicyV241;

const CONTRACT_NAME: &str = "crates.io::dao-pre-propose-base";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down Expand Up @@ -547,6 +544,57 @@ where
) -> Result<Response, PreProposeError> {
match msg {
MigrateMsg::FromUnderV250 { policy } => {
#[cw_serde]
struct ConfigV241 {
/// Information about the deposit required to create a
/// proposal. If `None`, no deposit is required.
pub deposit_info: Option<CheckedDepositInfoV241>,
/// If false, only members (addresses with voting power) may
/// create proposals in the DAO. Otherwise, any address may
/// create a proposal so long as they pay the deposit.
pub open_proposal_submission: bool,
}

/// Counterpart to the `DepositInfo` struct which has been
/// processed. This type should never be constructed literally
/// and should always by built by calling `into_checked` on a
/// `DepositInfo` instance.
#[cw_serde]
struct CheckedDepositInfoV241 {
/// The address of the cw20 token to be used for proposal
/// deposits.
pub denom: CheckedDenomV241,
/// The number of tokens that must be deposited to create a
/// proposal. This is validated to be non-zero if this
/// struct is constructed by converted via the
/// `into_checked` method on `DepositInfo`.
pub amount: Uint128,
/// The policy used for refunding proposal deposits.
pub refund_policy: DepositRefundPolicyV241,
}

#[cw_serde]
enum DepositRefundPolicyV241 {
/// Deposits should always be refunded.
Always,
/// Deposits should only be refunded for passed proposals.
OnlyPassed,
/// Deposits should never be refunded.
Never,
}

/// A denom that has been checked to point to a valid asset.
/// This enum should never be constructed literally and should
/// always be built by calling `into_checked` on an
/// `UncheckedDenom` instance.
#[cw_serde]
enum CheckedDenomV241 {
/// A native (bank module) asset.
Native(String),
/// A cw20 asset.
Cw20(Addr),
}

// all contracts >= v2.4.1 and < v2.5.0 have the same config
let required_str = ">=2.4.1, <2.5.0";

Expand All @@ -562,8 +610,7 @@ where
});
}

let old_contract = PreProposeContractV241::<Empty, Empty, Empty, Empty>::default();
let old_config = old_contract.config.load(deps.storage)?;
let old_config = Item::<ConfigV241>::new("config").load(deps.storage)?;

// if provided a policy to update with, use it
let submission_policy = if let Some(submission_policy) = policy {
Expand Down
4 changes: 2 additions & 2 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ cd packages/dao-dao-macros
cargo hack publish --no-dev-deps --allow-dirty
cd "$START_DIR"

cd packages/dao-pre-propose-base
cd packages/dao-voting
cargo publish
cd "$START_DIR"

cd packages/dao-voting
cd packages/dao-pre-propose-base
cargo publish
cd "$START_DIR"

Expand Down

1 comment on commit d453222

@NoahSaso
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit was retroactively inserted via force push. more info here on why this was necessary:
#894

Please sign in to comment.