From 828076f175dd237becc5122e6608d68e47b6dccc Mon Sep 17 00:00:00 2001 From: dancreee Date: Sat, 3 Aug 2024 17:58:24 +0800 Subject: [PATCH 1/5] Remove sending of rewards, burn rewards for fee collector denom instead --- .../rewards-collector/base/src/contract.rs | 68 ++++++------- .../tests/tests/test_distribute_rewards.rs | 12 +-- .../tests/test_rewards_collector.rs | 97 +++++++++++++------ packages/types/src/address_provider.rs | 13 +-- 4 files changed, 113 insertions(+), 77 deletions(-) diff --git a/contracts/rewards-collector/base/src/contract.rs b/contracts/rewards-collector/base/src/contract.rs index cf787a4a..172b3ed3 100644 --- a/contracts/rewards-collector/base/src/contract.rs +++ b/contracts/rewards-collector/base/src/contract.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ - coin, to_json_binary, Addr, Binary, Coin, CosmosMsg, CustomMsg, Deps, DepsMut, Empty, Env, - MessageInfo, Response, StdResult, Uint128, WasmMsg, + coin, coins, to_json_binary, Addr, BankMsg, Binary, Coin, CosmosMsg, CustomMsg, Deps, DepsMut, + Empty, Env, MessageInfo, Response, StdResult, Uint128, WasmMsg, }; use cw_storage_plus::Item; use mars_owner::{Owner, OwnerInit::SetInitialOwner, OwnerUpdate}; @@ -352,43 +352,45 @@ where ) -> ContractResult> { let cfg = self.config.load(deps.storage)?; - let to_address = if denom == cfg.safety_fund_denom { - address_provider::helpers::query_module_addr( + let amount_to_distribute = + unwrap_option_amount(&deps.querier, &env.contract.address, &denom, amount)?; + + let response = Response::new() + .add_attribute("denom", &denom) + .add_attribute("amount", amount_to_distribute); + + if denom == cfg.safety_fund_denom { + let to_address = address_provider::helpers::query_module_addr( deps.as_ref(), &cfg.address_provider, MarsAddressType::SafetyFund, - )? + )?; + + let transfer_msg = I::ibc_transfer_msg( + env, + to_address.clone(), + Coin { + denom: denom.clone(), + amount: amount_to_distribute, + }, + cfg, + )?; + + Ok(response + .add_attribute("action", "distribute_rewards") + .add_attribute("to", to_address) + .add_message(transfer_msg)) } else if denom == cfg.fee_collector_denom { - address_provider::helpers::query_module_addr( - deps.as_ref(), - &cfg.address_provider, - MarsAddressType::FeeCollector, - )? + Ok(response.add_attribute("action", "burn_rewards").add_message(CosmosMsg::Bank( + BankMsg::Burn { + amount: coins(amount_to_distribute.u128(), denom), + }, + ))) } else { - return Err(ContractError::AssetNotEnabledForDistribution { + Err(ContractError::AssetNotEnabledForDistribution { denom, - }); - }; - - let amount_to_distribute = - unwrap_option_amount(&deps.querier, &env.contract.address, &denom, amount)?; - - let transfer_msg = I::ibc_transfer_msg( - env, - to_address.clone(), - Coin { - denom: denom.clone(), - amount: amount_to_distribute, - }, - cfg, - )?; - - Ok(Response::new() - .add_message(transfer_msg) - .add_attribute("action", "distribute_rewards") - .add_attribute("denom", denom) - .add_attribute("amount", amount_to_distribute) - .add_attribute("to", to_address)) + }) + } } pub fn query_config(&self, deps: Deps) -> StdResult { diff --git a/contracts/rewards-collector/osmosis/tests/tests/test_distribute_rewards.rs b/contracts/rewards-collector/osmosis/tests/tests/test_distribute_rewards.rs index b5f52d9a..7f733c00 100644 --- a/contracts/rewards-collector/osmosis/tests/tests/test_distribute_rewards.rs +++ b/contracts/rewards-collector/osmosis/tests/tests/test_distribute_rewards.rs @@ -1,5 +1,6 @@ use cosmwasm_std::{ - coin, testing::mock_env, CosmosMsg, IbcMsg, IbcTimeout, SubMsg, Timestamp, Uint128, + coin, coins, testing::mock_env, BankMsg, CosmosMsg, IbcMsg, IbcTimeout, SubMsg, Timestamp, + Uint128, }; use mars_rewards_collector_base::ContractError; use mars_rewards_collector_osmosis::entry::execute; @@ -39,7 +40,7 @@ fn distributing_rewards() { })) ); - // distribute umars to fee collector + // burn umars as fee collector denom let res = execute( deps.as_mut(), env, @@ -53,11 +54,8 @@ fn distributing_rewards() { assert_eq!(res.messages.len(), 1); assert_eq!( res.messages[0], - SubMsg::new(CosmosMsg::Ibc(IbcMsg::Transfer { - channel_id: "channel-69".to_string(), - to_address: "fee_collector".to_string(), - amount: coin(8964, "umars"), - timeout: IbcTimeout::with_timestamp(Timestamp::from_seconds(17000300)) + SubMsg::new(CosmosMsg::Bank(BankMsg::Burn { + amount: coins(8964, "umars") })) ); diff --git a/integration-tests/tests/test_rewards_collector.rs b/integration-tests/tests/test_rewards_collector.rs index cbb3be55..4c3f4efe 100644 --- a/integration-tests/tests/test_rewards_collector.rs +++ b/integration-tests/tests/test_rewards_collector.rs @@ -234,7 +234,6 @@ fn distribute_rewards_if_ibc_channel_invalid() { .init_accounts( &[ coin(1_000_000_000_000, "uusdc"), - coin(1_000_000_000_000, "umars"), coin(1_000_000_000_000, "uosmo"), // for gas ], 2, @@ -253,16 +252,6 @@ fn distribute_rewards_if_ibc_channel_invalid() { prefix: "osmo".to_string(), }, ); - wasm.execute( - &addr_provider_addr, - &ExecuteMsgAddr::SetAddress { - address_type: MarsAddressType::FeeCollector, - address: "mars17xpfvakm2amg962yls6f84z3kell8c5ldy6e7x".to_string(), - }, - &[], - signer, - ) - .unwrap(); wasm.execute( &addr_provider_addr, &ExecuteMsgAddr::SetAddress { @@ -297,13 +286,9 @@ fn distribute_rewards_if_ibc_channel_invalid() { // fund rewards-collector contract let bank = Bank::new(&app); let usdc_funded = 800_000_000u128; - let mars_funded = 50_000_000u128; bank.send(user, &rewards_addr, &[coin(usdc_funded, "uusdc")]).unwrap(); - bank.send(user, &rewards_addr, &[coin(mars_funded, "umars")]).unwrap(); let usdc_balance = bank.query_balance(&rewards_addr, "uusdc"); assert_eq!(usdc_balance, usdc_funded); - let mars_balance = bank.query_balance(&rewards_addr, "umars"); - assert_eq!(mars_balance, mars_balance); // distribute usdc let res = wasm @@ -338,18 +323,76 @@ fn distribute_rewards_if_ibc_channel_invalid() { signer, ) .unwrap(); +} - // distribute mars - let res = wasm - .execute( - &rewards_addr, - &ExecuteMsg::DistributeRewards { - denom: "umars".to_string(), - amount: None, - }, - &[], - signer, +#[test] +fn burn_rewards() { + let app = OsmosisTestApp::new(); + let wasm = Wasm::new(&app); + + let accs = app + .init_accounts( + &[ + coin(1_000_000_000_000, "umars"), + coin(1_000_000_000_000, "uosmo"), // for gas + ], + 2, ) - .unwrap_err(); - assert_err(res, "port ID (transfer) channel ID (channel-1): channel not found"); + .unwrap(); + let signer = &accs[0]; + let user = &accs[1]; + + // setup address-provider contract + let addr_provider_addr = instantiate_contract( + &wasm, + signer, + OSMOSIS_ADDR_PROVIDER_CONTRACT_NAME, + &InstantiateAddr { + owner: signer.address(), + prefix: "osmo".to_string(), + }, + ); + + // setup rewards-collector contract + let safety_fund_denom = "uusdc"; + let fee_collector_denom = "umars"; + let rewards_addr = instantiate_contract( + &wasm, + signer, + OSMOSIS_REWARDS_CONTRACT_NAME, + &InstantiateRewards { + owner: signer.address(), + address_provider: addr_provider_addr, + safety_tax_rate: Decimal::percent(50), + safety_fund_denom: safety_fund_denom.to_string(), + fee_collector_denom: fee_collector_denom.to_string(), + channel_id: "".to_string(), + timeout_seconds: 60, + slippage_tolerance: Decimal::percent(1), + neutron_ibc_config: None, + }, + ); + + // fund rewards-collector contract + let bank = Bank::new(&app); + let mars_funded = 50_000_000u128; + bank.send(user, &rewards_addr, &[coin(mars_funded, "umars")]).unwrap(); + let mars_balance = bank.query_balance(&rewards_addr, "umars"); + assert_eq!(mars_balance, mars_funded); + + // since umars is the fee denom, the umars should be burnt + wasm.execute( + &rewards_addr, + &ExecuteMsg::DistributeRewards { + denom: "umars".to_string(), + amount: None, + }, + &[], + signer, + ) + .unwrap(); + + // assert the rewards collector balance of umars is 0 to confirm umars has been burnt + let mars_balance = bank.query_balance(&rewards_addr, "umars"); + assert_eq!(mars_balance, 0); } diff --git a/packages/types/src/address_provider.rs b/packages/types/src/address_provider.rs index c212ec89..6a2702e8 100644 --- a/packages/types/src/address_provider.rs +++ b/packages/types/src/address_provider.rs @@ -14,19 +14,14 @@ pub enum MarsAddressType { RewardsCollector, Params, CreditManager, - /// Protocol admin is an ICS-27 interchain account controlled by Mars Hub's x/gov module. - /// This account will take the owner and admin roles of red-bank contracts. + /// Protocol admin is a Mars Hubs governance smart contract instance, + /// or ICS-27 interchain account controlled by Mars Hubs governance instance. + /// This account will take the owner and admin roles of Mars Protocol contracts. /// /// Owner means the account who can invoke certain priviliged execute methods on a contract, /// such as updating the config. /// Admin means the account who can migrate a contract. ProtocolAdmin, - /// The `fee_collector` module account controlled by Mars Hub's x/distribution module. - /// Funds sent to this account will be distributed as staking rewards. - /// - /// NOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized - /// by the `api.addr_validate` method. - FeeCollector, /// The module account controlled by the by Mars Hub's x/safety module. /// Funds sent to this account will be deposited into the safety fund. /// @@ -41,7 +36,6 @@ impl fmt::Display for MarsAddressType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match self { MarsAddressType::CreditManager => "credit_manager", - MarsAddressType::FeeCollector => "fee_collector", MarsAddressType::Incentives => "incentives", MarsAddressType::Oracle => "oracle", MarsAddressType::Params => "params", @@ -61,7 +55,6 @@ impl FromStr for MarsAddressType { fn from_str(s: &str) -> Result { match s { "credit_manager" => Ok(MarsAddressType::CreditManager), - "fee_collector" => Ok(MarsAddressType::FeeCollector), "incentives" => Ok(MarsAddressType::Incentives), "oracle" => Ok(MarsAddressType::Oracle), "params" => Ok(MarsAddressType::Params), From 7937154137f1b32a76a85177636e7aa81dc30a7d Mon Sep 17 00:00:00 2001 From: dancreee Date: Sat, 3 Aug 2024 20:47:54 +0800 Subject: [PATCH 2/5] migration --- Cargo.lock | 2 +- .../rewards-collector/neutron/Cargo.toml | 2 +- .../rewards-collector/neutron/src/lib.rs | 22 ++++++++++++------- .../neutron/src/migrations/mod.rs | 1 + .../neutron/src/migrations/v2_0_2.rs | 19 ++++++++++++++++ .../rewards-collector/osmosis/src/lib.rs | 12 ++++++---- .../osmosis/tests/tests/test_migration_v2.rs | 12 +++++----- packages/types/src/rewards_collector.rs | 7 +++++- 8 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 contracts/rewards-collector/neutron/src/migrations/mod.rs create mode 100644 contracts/rewards-collector/neutron/src/migrations/v2_0_2.rs diff --git a/Cargo.lock b/Cargo.lock index a75d2759..3027a5ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2477,7 +2477,7 @@ dependencies = [ [[package]] name = "mars-rewards-collector-neutron" -version = "2.0.0" +version = "2.0.2" dependencies = [ "cosmwasm-std", "cw2 1.1.2", diff --git a/contracts/rewards-collector/neutron/Cargo.toml b/contracts/rewards-collector/neutron/Cargo.toml index 109bab47..1e47c092 100644 --- a/contracts/rewards-collector/neutron/Cargo.toml +++ b/contracts/rewards-collector/neutron/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mars-rewards-collector-neutron" -version = { workspace = true } +version = "2.0.2" authors = { workspace = true } edition = { workspace = true } license = { workspace = true } diff --git a/contracts/rewards-collector/neutron/src/lib.rs b/contracts/rewards-collector/neutron/src/lib.rs index bdb98bf5..e1e33165 100644 --- a/contracts/rewards-collector/neutron/src/lib.rs +++ b/contracts/rewards-collector/neutron/src/lib.rs @@ -1,3 +1,5 @@ +mod migrations; + use std::vec; use cosmwasm_std::{coin, Coin, CosmosMsg, Env, StdError}; @@ -47,15 +49,13 @@ pub type NeutronCollector<'a> = Collector<'a, NeutronMsg, NeutronIbcMsgFactory>; #[cfg(not(feature = "library"))] pub mod entry { - use cosmwasm_std::{ - entry_point, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult, - }; + use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::set_contract_version; - use mars_rewards_collector_base::ContractResult; - use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, QueryMsg}; + use mars_rewards_collector_base::{ContractError, ContractResult}; + use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, NeutronMigrateMsg, QueryMsg}; use neutron_sdk::bindings::msg::NeutronMsg; - use crate::NeutronCollector; + use crate::{migrations, NeutronCollector}; pub const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -90,7 +90,13 @@ pub mod entry { } #[entry_point] - pub fn migrate(_deps: DepsMut, _env: Env, _msg: Empty) -> StdResult { - Ok(Response::default()) + pub fn migrate( + deps: DepsMut, + _env: Env, + msg: NeutronMigrateMsg, + ) -> Result { + match msg { + NeutronMigrateMsg::V1_2_0ToV2_0_2 {} => migrations::v2_0_2::migrate(deps), + } } } diff --git a/contracts/rewards-collector/neutron/src/migrations/mod.rs b/contracts/rewards-collector/neutron/src/migrations/mod.rs new file mode 100644 index 00000000..edbf9895 --- /dev/null +++ b/contracts/rewards-collector/neutron/src/migrations/mod.rs @@ -0,0 +1 @@ +pub mod v2_0_2; diff --git a/contracts/rewards-collector/neutron/src/migrations/v2_0_2.rs b/contracts/rewards-collector/neutron/src/migrations/v2_0_2.rs new file mode 100644 index 00000000..4a46ded6 --- /dev/null +++ b/contracts/rewards-collector/neutron/src/migrations/v2_0_2.rs @@ -0,0 +1,19 @@ +use cosmwasm_std::{DepsMut, Response}; +use cw2::{assert_contract_version, set_contract_version}; +use mars_rewards_collector_base::ContractError; + +use crate::entry::{CONTRACT_NAME, CONTRACT_VERSION}; + +const FROM_VERSION: &str = "1.2.0"; + +pub fn migrate(deps: DepsMut) -> Result { + // make sure we're migrating the correct contract and from the correct version + assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; + + set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; + + Ok(Response::new() + .add_attribute("action", "migrate") + .add_attribute("from_version", FROM_VERSION) + .add_attribute("to_version", CONTRACT_VERSION)) +} diff --git a/contracts/rewards-collector/osmosis/src/lib.rs b/contracts/rewards-collector/osmosis/src/lib.rs index 9e3c09f5..86a0a021 100644 --- a/contracts/rewards-collector/osmosis/src/lib.rs +++ b/contracts/rewards-collector/osmosis/src/lib.rs @@ -7,7 +7,7 @@ pub mod entry { }; use cw2::set_contract_version; use mars_rewards_collector_base::{contract::Collector, ContractError, ContractResult}; - use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; + use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, OsmosisMigrateMsg, QueryMsg}; use crate::migrations; @@ -46,10 +46,14 @@ pub mod entry { } #[entry_point] - pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result { + pub fn migrate( + deps: DepsMut, + _env: Env, + msg: OsmosisMigrateMsg, + ) -> Result { match msg { - MigrateMsg::V1_0_0ToV2_0_0 {} => migrations::v2_0_0::migrate(deps), - MigrateMsg::V2_0_0ToV2_0_1 {} => migrations::v2_0_1::migrate(deps), + OsmosisMigrateMsg::V1_0_0ToV2_0_0 {} => migrations::v2_0_0::migrate(deps), + OsmosisMigrateMsg::V2_0_0ToV2_0_1 {} => migrations::v2_0_1::migrate(deps), } } } diff --git a/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs b/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs index d473afe2..edc0c21b 100644 --- a/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs +++ b/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs @@ -6,14 +6,14 @@ use mars_rewards_collector_osmosis::{ migrations::v2_0_0::v1_state::{self, OwnerSetNoneProposed}, }; use mars_testing::mock_dependencies; -use mars_types::rewards_collector::MigrateMsg; +use mars_types::rewards_collector::OsmosisMigrateMsg; #[test] fn wrong_contract_name() { let mut deps = mock_dependencies(&[]); cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "1.0.0").unwrap(); - let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); + let err = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); assert_eq!( err, @@ -34,7 +34,7 @@ fn wrong_contract_version() { ) .unwrap(); - let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); + let err = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); assert_eq!( err, @@ -78,7 +78,7 @@ fn successful_migration() { }; v1_state::CONFIG.save(deps.as_mut().storage, &v1_config).unwrap(); - let res = migrate(deps.as_mut(), mock_env(), MigrateMsg::V1_0_0ToV2_0_0 {}).unwrap(); + let res = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V1_0_0ToV2_0_0 {}).unwrap(); assert_eq!(res.messages, vec![]); assert_eq!(res.events, vec![] as Vec); @@ -114,7 +114,7 @@ fn successful_migration() { } #[test] -fn successful_migration_to_v2_0_2() { +fn successful_migration_to_v2_0_1() { let mut deps = mock_dependencies(&[]); cw2::set_contract_version( deps.as_mut().storage, @@ -123,7 +123,7 @@ fn successful_migration_to_v2_0_2() { ) .unwrap(); - let res = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_0_0ToV2_0_1 {}).unwrap(); + let res = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V2_0_0ToV2_0_1 {}).unwrap(); assert_eq!(res.messages, vec![]); assert_eq!(res.events, vec![] as Vec); diff --git a/packages/types/src/rewards_collector.rs b/packages/types/src/rewards_collector.rs index 4a7ba2c8..205c95c6 100644 --- a/packages/types/src/rewards_collector.rs +++ b/packages/types/src/rewards_collector.rs @@ -203,7 +203,12 @@ pub enum QueryMsg { } #[cw_serde] -pub enum MigrateMsg { +pub enum OsmosisMigrateMsg { V1_0_0ToV2_0_0 {}, V2_0_0ToV2_0_1 {}, } + +#[cw_serde] +pub enum NeutronMigrateMsg { + V1_2_0ToV2_0_2 {}, +} From 87f176964bb7f4df9ac5151c0d66b63dd40bf72b Mon Sep 17 00:00:00 2001 From: piobab Date: Wed, 7 Aug 2024 16:27:10 +0200 Subject: [PATCH 3/5] Update schema. --- .../mars-address-provider.json | 45 +++---------------- .../MarsAddressProvider.types.ts | 1 - 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/schemas/mars-address-provider/mars-address-provider.json b/schemas/mars-address-provider/mars-address-provider.json index 9cf4cd37..86db232e 100644 --- a/schemas/mars-address-provider/mars-address-provider.json +++ b/schemas/mars-address-provider/mars-address-provider.json @@ -82,19 +82,12 @@ ] }, { - "description": "Protocol admin is an ICS-27 interchain account controlled by Mars Hub's x/gov module. This account will take the owner and admin roles of red-bank contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", + "description": "Protocol admin is a Mars Hubs governance smart contract instance, or ICS-27 interchain account controlled by Mars Hubs governance instance. This account will take the owner and admin roles of Mars Protocol contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", "type": "string", "enum": [ "protocol_admin" ] }, - { - "description": "The `fee_collector` module account controlled by Mars Hub's x/distribution module. Funds sent to this account will be distributed as staking rewards.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", - "type": "string", - "enum": [ - "fee_collector" - ] - }, { "description": "The module account controlled by the by Mars Hub's x/safety module. Funds sent to this account will be deposited into the safety fund.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", "type": "string", @@ -293,19 +286,12 @@ ] }, { - "description": "Protocol admin is an ICS-27 interchain account controlled by Mars Hub's x/gov module. This account will take the owner and admin roles of red-bank contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", + "description": "Protocol admin is a Mars Hubs governance smart contract instance, or ICS-27 interchain account controlled by Mars Hubs governance instance. This account will take the owner and admin roles of Mars Protocol contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", "type": "string", "enum": [ "protocol_admin" ] }, - { - "description": "The `fee_collector` module account controlled by Mars Hub's x/distribution module. Funds sent to this account will be distributed as staking rewards.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", - "type": "string", - "enum": [ - "fee_collector" - ] - }, { "description": "The module account controlled by the by Mars Hub's x/safety module. Funds sent to this account will be deposited into the safety fund.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", "type": "string", @@ -372,19 +358,12 @@ ] }, { - "description": "Protocol admin is an ICS-27 interchain account controlled by Mars Hub's x/gov module. This account will take the owner and admin roles of red-bank contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", + "description": "Protocol admin is a Mars Hubs governance smart contract instance, or ICS-27 interchain account controlled by Mars Hubs governance instance. This account will take the owner and admin roles of Mars Protocol contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", "type": "string", "enum": [ "protocol_admin" ] }, - { - "description": "The `fee_collector` module account controlled by Mars Hub's x/distribution module. Funds sent to this account will be distributed as staking rewards.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", - "type": "string", - "enum": [ - "fee_collector" - ] - }, { "description": "The module account controlled by the by Mars Hub's x/safety module. Funds sent to this account will be deposited into the safety fund.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", "type": "string", @@ -454,19 +433,12 @@ ] }, { - "description": "Protocol admin is an ICS-27 interchain account controlled by Mars Hub's x/gov module. This account will take the owner and admin roles of red-bank contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", + "description": "Protocol admin is a Mars Hubs governance smart contract instance, or ICS-27 interchain account controlled by Mars Hubs governance instance. This account will take the owner and admin roles of Mars Protocol contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", "type": "string", "enum": [ "protocol_admin" ] }, - { - "description": "The `fee_collector` module account controlled by Mars Hub's x/distribution module. Funds sent to this account will be distributed as staking rewards.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", - "type": "string", - "enum": [ - "fee_collector" - ] - }, { "description": "The module account controlled by the by Mars Hub's x/safety module. Funds sent to this account will be deposited into the safety fund.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", "type": "string", @@ -536,19 +508,12 @@ ] }, { - "description": "Protocol admin is an ICS-27 interchain account controlled by Mars Hub's x/gov module. This account will take the owner and admin roles of red-bank contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", + "description": "Protocol admin is a Mars Hubs governance smart contract instance, or ICS-27 interchain account controlled by Mars Hubs governance instance. This account will take the owner and admin roles of Mars Protocol contracts.\n\nOwner means the account who can invoke certain priviliged execute methods on a contract, such as updating the config. Admin means the account who can migrate a contract.", "type": "string", "enum": [ "protocol_admin" ] }, - { - "description": "The `fee_collector` module account controlled by Mars Hub's x/distribution module. Funds sent to this account will be distributed as staking rewards.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", - "type": "string", - "enum": [ - "fee_collector" - ] - }, { "description": "The module account controlled by the by Mars Hub's x/safety module. Funds sent to this account will be deposited into the safety fund.\n\nNOTE: This is a Mars Hub address with the `mars` bech32 prefix, which may not be recognized by the `api.addr_validate` method.", "type": "string", diff --git a/scripts/types/generated/mars-address-provider/MarsAddressProvider.types.ts b/scripts/types/generated/mars-address-provider/MarsAddressProvider.types.ts index a2545bd3..dc6e2f4f 100644 --- a/scripts/types/generated/mars-address-provider/MarsAddressProvider.types.ts +++ b/scripts/types/generated/mars-address-provider/MarsAddressProvider.types.ts @@ -22,7 +22,6 @@ export type ExecuteMsg = export type MarsAddressType = | ('incentives' | 'oracle' | 'red_bank' | 'rewards_collector' | 'params' | 'credit_manager') | 'protocol_admin' - | 'fee_collector' | 'safety_fund' | 'swapper' | 'astroport_incentives' From 16386c779746af35e68374a21a7e43739b524d4a Mon Sep 17 00:00:00 2001 From: piobab Date: Wed, 7 Aug 2024 17:04:54 +0200 Subject: [PATCH 4/5] Update build. --- scripts/deploy/base/deployer.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/deploy/base/deployer.ts b/scripts/deploy/base/deployer.ts index 93ffcc96..46a750cf 100644 --- a/scripts/deploy/base/deployer.ts +++ b/scripts/deploy/base/deployer.ts @@ -595,10 +595,6 @@ export class Deployer { address: this.storage.addresses['redBank']!, address_type: 'red_bank', }, - { - address: this.config.feeCollectorAddr, - address_type: 'fee_collector', - }, { address: this.config.safetyFundAddr, address_type: 'safety_fund', From 647418601c0c7d552c0dbf78ef3b5acf7aab5275 Mon Sep 17 00:00:00 2001 From: dancreee Date: Wed, 28 Aug 2024 12:54:10 +0800 Subject: [PATCH 5/5] revert migration changes based on feedback --- Cargo.lock | 2 +- contracts/rewards-collector/neutron/Cargo.toml | 2 +- contracts/rewards-collector/neutron/src/lib.rs | 18 +++++++----------- contracts/rewards-collector/osmosis/src/lib.rs | 12 ++++-------- .../osmosis/tests/tests/test_migration_v2.rs | 10 +++++----- packages/types/src/rewards_collector.rs | 7 +------ 6 files changed, 19 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f990cdd0..4d28073f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2551,7 +2551,7 @@ dependencies = [ [[package]] name = "mars-rewards-collector-neutron" -version = "2.0.2" +version = "2.1.0" dependencies = [ "cosmwasm-std", "cw2 1.1.2", diff --git a/contracts/rewards-collector/neutron/Cargo.toml b/contracts/rewards-collector/neutron/Cargo.toml index 7279acac..5f773f79 100644 --- a/contracts/rewards-collector/neutron/Cargo.toml +++ b/contracts/rewards-collector/neutron/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mars-rewards-collector-neutron" -version = "2.0.2" +version = { workspace = true } authors = { workspace = true } edition = { workspace = true } license = { workspace = true } diff --git a/contracts/rewards-collector/neutron/src/lib.rs b/contracts/rewards-collector/neutron/src/lib.rs index 0c418ab3..fb9766e5 100644 --- a/contracts/rewards-collector/neutron/src/lib.rs +++ b/contracts/rewards-collector/neutron/src/lib.rs @@ -49,10 +49,12 @@ pub type NeutronCollector<'a> = Collector<'a, NeutronMsg, NeutronIbcMsgFactory>; #[cfg(not(feature = "library"))] pub mod entry { - use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; + use cosmwasm_std::{ + entry_point, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult, + }; use cw2::set_contract_version; - use mars_rewards_collector_base::{ContractError, ContractResult}; - use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, NeutronMigrateMsg, QueryMsg}; + use mars_rewards_collector_base::ContractResult; + use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, QueryMsg}; use neutron_sdk::bindings::msg::NeutronMsg; use crate::{migrations, NeutronCollector}; @@ -90,13 +92,7 @@ pub mod entry { } #[entry_point] - pub fn migrate( - deps: DepsMut, - _env: Env, - msg: NeutronMigrateMsg, - ) -> Result { - match msg { - NeutronMigrateMsg::V1_2_0ToV2_0_2 {} => migrations::v2_0_2::migrate(deps), - } + pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> ContractResult { + migrations::v2_0_2::migrate(deps) } } diff --git a/contracts/rewards-collector/osmosis/src/lib.rs b/contracts/rewards-collector/osmosis/src/lib.rs index 86a0a021..9e3c09f5 100644 --- a/contracts/rewards-collector/osmosis/src/lib.rs +++ b/contracts/rewards-collector/osmosis/src/lib.rs @@ -7,7 +7,7 @@ pub mod entry { }; use cw2::set_contract_version; use mars_rewards_collector_base::{contract::Collector, ContractError, ContractResult}; - use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, OsmosisMigrateMsg, QueryMsg}; + use mars_types::rewards_collector::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use crate::migrations; @@ -46,14 +46,10 @@ pub mod entry { } #[entry_point] - pub fn migrate( - deps: DepsMut, - _env: Env, - msg: OsmosisMigrateMsg, - ) -> Result { + pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result { match msg { - OsmosisMigrateMsg::V1_0_0ToV2_0_0 {} => migrations::v2_0_0::migrate(deps), - OsmosisMigrateMsg::V2_0_0ToV2_0_1 {} => migrations::v2_0_1::migrate(deps), + MigrateMsg::V1_0_0ToV2_0_0 {} => migrations::v2_0_0::migrate(deps), + MigrateMsg::V2_0_0ToV2_0_1 {} => migrations::v2_0_1::migrate(deps), } } } diff --git a/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs b/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs index 59f10107..3f0db857 100644 --- a/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs +++ b/contracts/rewards-collector/osmosis/tests/tests/test_migration_v2.rs @@ -6,14 +6,14 @@ use mars_rewards_collector_osmosis::{ migrations::v2_0_0::v1_state::{self, OwnerSetNoneProposed}, }; use mars_testing::mock_dependencies; -use mars_types::rewards_collector::OsmosisMigrateMsg; +use mars_types::rewards_collector::MigrateMsg; #[test] fn wrong_contract_name() { let mut deps = mock_dependencies(&[]); cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "1.0.0").unwrap(); - let err = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); + let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); assert_eq!( err, @@ -34,7 +34,7 @@ fn wrong_contract_version() { ) .unwrap(); - let err = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); + let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V1_0_0ToV2_0_0 {}).unwrap_err(); assert_eq!( err, @@ -78,7 +78,7 @@ fn successful_migration() { }; v1_state::CONFIG.save(deps.as_mut().storage, &v1_config).unwrap(); - let res = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V1_0_0ToV2_0_0 {}).unwrap(); + let res = migrate(deps.as_mut(), mock_env(), MigrateMsg::V1_0_0ToV2_0_0 {}).unwrap(); assert_eq!(res.messages, vec![]); assert_eq!(res.events, vec![] as Vec); @@ -123,7 +123,7 @@ fn successful_migration_to_v2_1_0() { ) .unwrap(); - let res = migrate(deps.as_mut(), mock_env(), OsmosisMigrateMsg::V2_0_0ToV2_0_1 {}).unwrap(); + let res = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_0_0ToV2_0_1 {}).unwrap(); assert_eq!(res.messages, vec![]); assert_eq!(res.events, vec![] as Vec); diff --git a/packages/types/src/rewards_collector.rs b/packages/types/src/rewards_collector.rs index d3d51d07..6748da6a 100644 --- a/packages/types/src/rewards_collector.rs +++ b/packages/types/src/rewards_collector.rs @@ -205,12 +205,7 @@ pub enum QueryMsg { } #[cw_serde] -pub enum OsmosisMigrateMsg { +pub enum MigrateMsg { V1_0_0ToV2_0_0 {}, V2_0_0ToV2_0_1 {}, } - -#[cw_serde] -pub enum NeutronMigrateMsg { - V1_2_0ToV2_0_2 {}, -}