Skip to content

Fabo/migrate #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ regex = "1.10.2"
prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]}
enum-repr = "0.2.6"
prost-derive = "0.12.3"
semver = "1.0.20"

[dev-dependencies]
cw-multi-test = "0.17.0"
37 changes: 32 additions & 5 deletions contracts/staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ use crate::{
msg::{ExecuteMsg, IBCLifecycleComplete, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg},
};
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult,
Uint128,
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError,
StdResult, Uint128,
};
use cosmwasm_std::{CosmosMsg, Timestamp};
use cw2::set_contract_version;
use cw_utils::must_pay;
use milky_way::staking::Batch;
use osmosis_std::types::osmosis::tokenfactory::v1beta1::MsgCreateDenom;
use semver::Version;

// Version information for migration
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
Expand Down Expand Up @@ -232,9 +233,35 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
/// MIGRATE ///
///////////////

#[entry_point]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
// TODO: note implement yet
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
let current_version = cw2::get_contract_version(deps.storage)?;
if &CONTRACT_NAME != &current_version.contract.as_str() {
return Err(StdError::generic_err("Cannot upgrade to a different contract").into());
}

let version: Version = current_version
.version
.parse()
.map_err(|_| StdError::generic_err("Invalid contract version"))?;
let new_version: Version = CONTRACT_VERSION
.parse()
.map_err(|_| StdError::generic_err("Invalid contract version"))?;

// current version not launchpad v2
if version > new_version {
return Err(StdError::generic_err("Cannot upgrade to a previous contract version").into());
}
// if same version return
if version == new_version {
return Ok(Response::new());
}
Comment on lines +255 to +258
Copy link
Member

Choose a reason for hiding this comment

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

Is it intended that we just return Ok if new version is the same version?


// migrate data
// NONE currently

// set new contract version
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::new())
}

Expand Down
33 changes: 0 additions & 33 deletions deploy/migrate_stake_contract.sh

This file was deleted.

14 changes: 14 additions & 0 deletions scripts/deploy/migrate_stake_contract_testnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer-arm64:0.14.0

# double check contract address https://decento-labs.slack.com/canvas/C04R92P76L9
CONTRACT="osmo1h3s40qhqztppucdfggzwykz7xgwhcnps952y86xc73eupqfu9jmqcaghze"
RES=$(osmosisd tx wasm store ./artifacts/staking-aarch64.wasm --from test_master --output json -y -b block --gas-prices 0.025stake --gas-adjustment 1.7 --gas auto --chain-id osmosis-dev-1)
CODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[-1].value')
osmosisd tx wasm migrate $CONTRACT $CODE_ID '{}' \
--from test_master -y \
-b block --node https://rpc.testnet.osmosis.zone:443 \
--gas-prices 0.025uosmo --gas-adjustment 1.7 --gas auto \
--chain-id osmo-test-5