Skip to content
Merged
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
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.

2 changes: 1 addition & 1 deletion contracts/address-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mars-address-provider"
description = "A smart contract that holds addresses of Mars Red Bank contracts"
version = "2.1.1"
version = "2.2.0"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion contracts/address-provider/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ fn query_all_addresses(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
migrations::v2_1_1::migrate(deps)
migrations::v2_2_0::migrate(deps)
}
1 change: 1 addition & 0 deletions contracts/address-provider/src/migrations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod v2_1_0;
pub mod v2_1_1;
pub mod v2_2_0;
35 changes: 35 additions & 0 deletions contracts/address-provider/src/migrations/v2_2_0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use cosmwasm_std::{DepsMut, Response};
use cw2::{get_contract_version, set_contract_version, VersionError};

use crate::{
contract::{CONTRACT_NAME, CONTRACT_VERSION},
error::ContractError,
};

const FROM_VERSION: &str = "2.1.0";

pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
let contract = format!("crates.io:{CONTRACT_NAME}");
let version = get_contract_version(deps.storage)?;

if version.contract != contract {
return Err(ContractError::Version(VersionError::WrongContract {
expected: contract,
found: version.contract,
}));
}

if version.version != FROM_VERSION {
return Err(ContractError::Version(VersionError::WrongVersion {
expected: FROM_VERSION.to_string(),
found: version.version,
}));
}

set_contract_version(deps.storage, contract, CONTRACT_VERSION)?;

Ok(Response::new()
.add_attribute("action", "migrate")
.add_attribute("from_version", FROM_VERSION)
.add_attribute("to_version", CONTRACT_VERSION))
}
6 changes: 3 additions & 3 deletions contracts/address-provider/tests/tests/test_migration_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn wrong_contract_version() {
}

#[test]
fn successful_migration() {
fn successful_migration_from_2_1_0() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-address-provider", "2.1.0")
.unwrap();
Expand All @@ -49,12 +49,12 @@ fn successful_migration() {
assert!(res.data.is_none());
assert_eq!(
res.attributes,
vec![attr("action", "migrate"), attr("from_version", "2.1.0"), attr("to_version", "2.1.1")]
vec![attr("action", "migrate"), attr("from_version", "2.1.0"), attr("to_version", "2.2.0")]
);

let new_contract_version = ContractVersion {
contract: "crates.io:mars-address-provider".to_string(),
version: "2.1.1".to_string(),
version: "2.2.0".to_string(),
};
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version);
}
68 changes: 43 additions & 25 deletions contracts/rewards-collector/osmosis/src/migrations/v2_2_0.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
use cosmwasm_std::{DepsMut, Response, Storage};
use cosmwasm_std::{Decimal, DepsMut, Response, Storage};
use cw2::{assert_contract_version, get_contract_version, set_contract_version, VersionError};
use mars_rewards_collector_base::ContractError;
use mars_types::rewards_collector::Config;
use mars_types::rewards_collector::{Config, RewardConfig, TransferType};

use crate::{
entry::{CONTRACT_NAME, CONTRACT_VERSION},
OsmosisCollector,
};

mod previous_state {
mod previous_state_v2_1_0 {
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Decimal};
use cosmwasm_std::{Addr, Coin, Decimal};
use cw_storage_plus::Item;
use mars_types::rewards_collector::RewardConfig;

#[cw_serde]
pub struct Config {
pub address_provider: Addr,
pub safety_tax_rate: Decimal,
pub revenue_share_tax_rate: Decimal,
pub slippage_tolerance: Decimal,
pub safety_fund_config: RewardConfig,
pub revenue_share_config: RewardConfig,
pub fee_collector_config: RewardConfig,
pub safety_fund_denom: String,
pub fee_collector_denom: String,
pub channel_id: String,
pub timeout_seconds: u64,
pub slippage_tolerance: Decimal,
pub neutron_ibc_config: Option<NeutronIbcConfig>,
}

#[cw_serde]
pub struct NeutronIbcConfig {
pub source_port: String,
pub acc_fee: Vec<Coin>,
pub timeout_fee: Vec<Coin>,
}

pub const CONFIG: Item<Config> = Item::new("config");
}

const FROM_VERSION: &str = "2.1.1";
const FROM_VERSION: &str = "2.1.0";

pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
let contract = format!("crates.io:{CONTRACT_NAME}");
Expand All @@ -52,23 +57,11 @@ pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {

assert_contract_version(deps.storage, &contract, FROM_VERSION)?;

let new_config = build_config_from_v2_1_0(deps.storage)?;

let storage: &mut dyn Storage = deps.storage;
let collector = OsmosisCollector::default();

let old_config = previous_state::CONFIG.load(storage)?;

let new_config = Config {
address_provider: old_config.address_provider,
safety_tax_rate: old_config.safety_tax_rate,
revenue_share_tax_rate: old_config.revenue_share_tax_rate,
safety_fund_config: old_config.safety_fund_config,
revenue_share_config: old_config.revenue_share_config,
fee_collector_config: old_config.fee_collector_config,
channel_id: old_config.channel_id,
timeout_seconds: old_config.timeout_seconds,
whitelisted_distributors: vec![],
};

new_config.validate()?;
collector.config.save(storage, &new_config)?;

Expand All @@ -79,3 +72,28 @@ pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
.add_attribute("from_version", FROM_VERSION)
.add_attribute("to_version", CONTRACT_VERSION))
}

fn build_config_from_v2_1_0(storage: &mut dyn Storage) -> Result<Config, ContractError> {
let old_config = previous_state_v2_1_0::CONFIG.load(storage)?;

Ok(Config {
address_provider: old_config.address_provider,
safety_tax_rate: Decimal::percent(45),
revenue_share_tax_rate: Decimal::percent(10),
safety_fund_config: RewardConfig {
target_denom: old_config.safety_fund_denom.clone(),
transfer_type: TransferType::Bank,
},
revenue_share_config: RewardConfig {
target_denom: old_config.safety_fund_denom,
transfer_type: TransferType::Bank,
},
fee_collector_config: RewardConfig {
target_denom: old_config.fee_collector_denom,
transfer_type: TransferType::Ibc,
},
channel_id: "channel-874".to_string(),
timeout_seconds: old_config.timeout_seconds,
whitelisted_distributors: vec![],
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ use mars_types::rewards_collector::{Config, RewardConfig, TransferType};

const CONTRACT: &str = "crates.io:mars-rewards-collector-osmosis";

mod previous_state {
mod previous_state_v2_1_0 {
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Decimal};
use cosmwasm_std::{Addr, Coin, Decimal};
use cw_storage_plus::Item;
use mars_types::rewards_collector::RewardConfig;

#[cw_serde]
pub struct Config {
pub address_provider: Addr,
pub safety_tax_rate: Decimal,
pub revenue_share_tax_rate: Decimal,
pub slippage_tolerance: Decimal,
pub safety_fund_config: RewardConfig,
pub revenue_share_config: RewardConfig,
pub fee_collector_config: RewardConfig,
pub safety_fund_denom: String,
pub fee_collector_denom: String,
pub channel_id: String,
pub timeout_seconds: u64,
pub slippage_tolerance: Decimal,
pub neutron_ibc_config: Option<NeutronIbcConfig>,
}

#[cw_serde]
pub struct NeutronIbcConfig {
pub source_port: String,
pub acc_fee: Vec<Coin>,
pub timeout_fee: Vec<Coin>,
}

pub const CONFIG: Item<Config> = Item::new("config");
Expand All @@ -32,7 +37,7 @@ mod previous_state {
#[test]
fn wrong_contract_name() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.1.1").unwrap();
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.1.0").unwrap();

let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err();

Expand All @@ -58,38 +63,34 @@ fn wrong_contract_version() {
match err {
ContractError::Version(VersionError::WrongVersion {
found,
expected,
..
}) => {
assert_eq!(found, "4.1.0".to_string());
assert_eq!(expected, "2.1.0".to_string());
}
other => panic!("unexpected error: {other:?}"),
}
}

#[test]
fn successful_migration_from_2_1_1() {
fn successful_migration_from_2_1_0() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, CONTRACT, "2.1.1").unwrap();

let reward_cfg = |denom: &str| RewardConfig {
target_denom: denom.to_string(),
transfer_type: TransferType::Bank,
};
cw2::set_contract_version(deps.as_mut().storage, CONTRACT, "2.1.0").unwrap();

let addr_provider = deps.as_ref().api.addr_validate("addr_provider").unwrap();
let old_config = previous_state::Config {
let old_config = previous_state_v2_1_0::Config {
address_provider: addr_provider.clone(),
safety_tax_rate: Decimal::percent(5),
revenue_share_tax_rate: Decimal::percent(10),
slippage_tolerance: Decimal::percent(1),
safety_fund_config: reward_cfg("usdc"),
revenue_share_config: reward_cfg("usdc"),
fee_collector_config: reward_cfg("mars"),
channel_id: "channel-1".to_string(),
safety_tax_rate: Decimal::percent(60),
safety_fund_denom: "usdc".to_string(),
fee_collector_denom: "mars".to_string(),
channel_id: "channel-999".to_string(),
timeout_seconds: 600,
slippage_tolerance: Decimal::percent(1),
neutron_ibc_config: None,
};

previous_state::CONFIG.save(deps.as_mut().storage, &old_config).unwrap();
previous_state_v2_1_0::CONFIG.save(deps.as_mut().storage, &old_config).unwrap();

let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();

Expand All @@ -98,7 +99,7 @@ fn successful_migration_from_2_1_1() {
assert!(res.data.is_none());
assert_eq!(
res.attributes,
vec![attr("action", "migrate"), attr("from_version", "2.1.1"), attr("to_version", "2.2.0")]
vec![attr("action", "migrate"), attr("from_version", "2.1.0"), attr("to_version", "2.2.0")]
);

let new_contract_version = ContractVersion {
Expand All @@ -114,12 +115,21 @@ fn successful_migration_from_2_1_1() {
stored_config,
Config {
address_provider: addr_provider,
safety_tax_rate: Decimal::percent(5),
safety_tax_rate: Decimal::percent(45),
revenue_share_tax_rate: Decimal::percent(10),
safety_fund_config: reward_cfg("usdc"),
revenue_share_config: reward_cfg("usdc"),
fee_collector_config: reward_cfg("mars"),
channel_id: "channel-1".to_string(),
safety_fund_config: RewardConfig {
target_denom: "usdc".to_string(),
transfer_type: TransferType::Bank,
},
revenue_share_config: RewardConfig {
target_denom: "usdc".to_string(),
transfer_type: TransferType::Bank,
},
fee_collector_config: RewardConfig {
target_denom: "mars".to_string(),
transfer_type: TransferType::Ibc,
},
channel_id: "channel-874".to_string(),
timeout_seconds: 600,
whitelisted_distributors: vec![],
}
Expand Down
2 changes: 1 addition & 1 deletion schemas/mars-address-provider/mars-address-provider.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "mars-address-provider",
"contract_version": "2.1.1",
"contract_version": "2.2.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
Loading