Skip to content

Commit 06a510b

Browse files
authored
MP-2702. Migration for Osmo contracts (#439)
* Update migration for address-provider. * Update migration for account-nft. * Update migration for credit-manager. * Update migration for health. * Update migration for incentives. * Update migration for oracle-osmosis. * Update migration for params. * Update migration for red-bank. * Update migration for rewards-collector. * Update migration for swapper-osmosis. * Update migration for zapper-osmosis. * MP-2562. Add missing connection between RC addr and acc id. * Generate schema. * Update changelog. * Add one more point to Changelog.
1 parent b99696d commit 06a510b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+941
-1613
lines changed

CHANGELOG.md

+60
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,66 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## v2.1.0 - Osmosis Release
6+
7+
### Credit Manager Contract
8+
- Introduced abstract account creation via `update_credit_account` message
9+
- Added new account type: FundManager for Managed Vaults
10+
- Updated `SwapExactIn` action:
11+
```diff
12+
SwapExactIn {
13+
coin_in: ActionCoin,
14+
denom_out: String,
15+
- slippage: Decimal,
16+
+ min_receive: Uint128,
17+
route: Option<SwapperRoute>,
18+
}
19+
```
20+
- Integrated Astro support:
21+
- Added actions for staking, unstaking, and claiming rewards
22+
- Introduced `staked_astro_lps` positions
23+
- Updated deposit cap mechanism (see https://github.com/mars-protocol/contracts/pull/425)
24+
- Trade any asset (https://github.com/mars-protocol/contracts/pull/381)
25+
26+
### Incentives Contract
27+
- Added support for Astro ecosystem interactions:
28+
- Introduced staking and unstaking functionality
29+
- Added reward claiming mechanisms
30+
31+
### Params Contract
32+
- Added new paginated queries:
33+
- `QueryMsg::AllVaultConfigsV2`
34+
- `QueryMsg::AllTotalDepositsV2`
35+
36+
### Red Bank Contract
37+
- Removed UncollateralizedLoanLimit logic
38+
- Added `QueryMsg::MarketsV2`
39+
40+
### Rewards Collector
41+
- Updated `SwapAsset` execute message to support minimum receive amounts:
42+
```diff
43+
SwapAsset {
44+
denom: String,
45+
amount: Option<Uint128>,
46+
safety_fund_route: Option<SwapperRoute>,
47+
fee_collector_route: Option<SwapperRoute>,
48+
+ safety_fund_min_receive: Option<Uint128>,
49+
+ fee_collector_min_receive: Option<Uint128>,
50+
}
51+
```
52+
53+
### Swapper Contract
54+
- Updated `SwapExactIn` to use minimum receive instead of slippage:
55+
```diff
56+
SwapExactIn {
57+
coin_in: Coin,
58+
denom_out: String,
59+
- slippage: Decimal,
60+
+ min_receive: Uint128,
61+
route: Option<SwapperRoute>,
62+
}
63+
```
64+
565
## v1.2.0
666

767
- Allow Credit account to lend/reclaim to the Red Bank (calls Deposit/Withdraw in Red Bank), claim incentive rewards from lending to the Red Bank (pass account_id to track Credit Manager users in `red-bank` and `incentives` contract).

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/account-nft/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ cw-multi-test = { workspace = true }
3535
mars-mock-credit-manager = { workspace = true }
3636
mars-mock-rover-health = { workspace = true }
3737
mars-owner = { workspace = true }
38+
mars-testing = { workspace = true }
3839
serde_json = { workspace = true }

contracts/account-nft/src/contract.rs

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use mars_types::account_nft::{ExecuteMsg, InstantiateMsg, NftConfig, QueryMsg};
1010
use crate::{
1111
error::ContractError,
1212
execute::{burn, mint, update_config},
13+
migrations,
1314
query::{query_config, query_next_id},
1415
state::{CONFIG, NEXT_ID},
1516
};
@@ -79,3 +80,8 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
7980
_ => Parent::default().query(deps, env, msg.try_into()?),
8081
}
8182
}
83+
84+
#[cfg_attr(not(feature = "library"), entry_point)]
85+
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
86+
migrations::v2_1_0::migrate(deps)
87+
}

contracts/account-nft/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod contract;
22
pub mod error;
33
pub mod execute;
4+
pub mod migrations;
45
pub mod query;
56
pub mod state;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod v2_1_0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use cosmwasm_std::{Addr, DepsMut, Empty, MessageInfo, Response};
2+
use cw2::{assert_contract_version, set_contract_version};
3+
4+
use crate::{
5+
contract::{Parent, CONTRACT_NAME, CONTRACT_VERSION},
6+
error::ContractError,
7+
};
8+
9+
const FROM_VERSION: &str = "2.0.0";
10+
11+
const CREDIT_MANAGER_CONTRACT_ADDR: &str =
12+
"osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf";
13+
14+
/// Check Credit-Manager `config` query response:
15+
/// {
16+
/// ...
17+
/// "rewards_collector": {
18+
/// "address": "osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy",
19+
/// "account_id": "2321"
20+
/// }
21+
/// }
22+
/// }
23+
const REWARDS_COLLECTOR_CONTRACT_ADDR: &str =
24+
"osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy";
25+
const REWARDS_COLLECTOR_ACC_ID: &str = "2321";
26+
27+
pub fn migrate(mut deps: DepsMut) -> Result<Response, ContractError> {
28+
// Make sure we're migrating the correct contract and from the correct version
29+
assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?;
30+
31+
// Create missing connection between Reward-Collector contract addr and acc id
32+
Parent::default().mint(
33+
deps.branch(),
34+
MessageInfo {
35+
sender: Addr::unchecked(CREDIT_MANAGER_CONTRACT_ADDR.to_string()),
36+
funds: vec![],
37+
},
38+
REWARDS_COLLECTOR_ACC_ID.to_string(),
39+
REWARDS_COLLECTOR_CONTRACT_ADDR.to_string(),
40+
None,
41+
Empty {},
42+
)?;
43+
44+
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;
45+
46+
Ok(Response::new()
47+
.add_attribute("action", "migrate")
48+
.add_attribute("from_version", FROM_VERSION)
49+
.add_attribute("to_version", CONTRACT_VERSION))
50+
}

contracts/account-nft/tests/tests/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod helpers;
22

33
mod test_burn_allowance;
44
mod test_instantiate;
5+
mod test_migration_v2;
56
mod test_mint;
67
mod test_proposed_minter;
78
mod test_update_config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
use cosmwasm_std::{
2+
attr, from_json,
3+
testing::{mock_env, mock_info},
4+
Empty, Event,
5+
};
6+
use cw2::{ContractVersion, VersionError};
7+
use cw721_base::InstantiateMsg;
8+
use mars_account_nft::{
9+
contract::{execute, migrate, query, Parent},
10+
error::ContractError,
11+
state::NEXT_ID,
12+
};
13+
use mars_testing::mock_dependencies;
14+
15+
#[test]
16+
fn wrong_contract_name() {
17+
let mut deps = mock_dependencies(&[]);
18+
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.0.0").unwrap();
19+
20+
let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err();
21+
22+
assert_eq!(
23+
err,
24+
ContractError::Version(VersionError::WrongContract {
25+
expected: "crates.io:mars-account-nft".to_string(),
26+
found: "contract_xyz".to_string()
27+
})
28+
);
29+
}
30+
31+
#[test]
32+
fn wrong_contract_version() {
33+
let mut deps = mock_dependencies(&[]);
34+
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-account-nft", "4.1.0")
35+
.unwrap();
36+
37+
let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err();
38+
39+
assert_eq!(
40+
err,
41+
ContractError::Version(VersionError::WrongVersion {
42+
expected: "2.0.0".to_string(),
43+
found: "4.1.0".to_string()
44+
})
45+
);
46+
}
47+
48+
#[test]
49+
fn successful_migration() {
50+
let mut deps = mock_dependencies(&[]);
51+
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-account-nft", "2.0.0")
52+
.unwrap();
53+
54+
let env = mock_env();
55+
// Credit-Manager contract address
56+
let owner = "osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf";
57+
let owner_info = mock_info(owner, &[]);
58+
59+
// Init counter with 1
60+
NEXT_ID.save(deps.as_mut().storage, &1).unwrap();
61+
62+
// Instantiate the contract
63+
Parent::default()
64+
.instantiate(
65+
deps.as_mut(),
66+
env.clone(),
67+
owner_info.clone(),
68+
InstantiateMsg {
69+
name: "mock_nft".to_string(),
70+
symbol: "MOCK".to_string(),
71+
minter: owner.to_string(),
72+
},
73+
)
74+
.unwrap();
75+
76+
// Mint a random token
77+
execute(
78+
deps.as_mut(),
79+
env.clone(),
80+
owner_info.clone(),
81+
mars_types::account_nft::ExecuteMsg::Mint {
82+
user: "user_1".to_string(),
83+
},
84+
)
85+
.unwrap();
86+
87+
// Move counter to 3000
88+
NEXT_ID.save(deps.as_mut().storage, &3000).unwrap();
89+
90+
// Mint a random token
91+
execute(
92+
deps.as_mut(),
93+
env.clone(),
94+
owner_info.clone(),
95+
mars_types::account_nft::ExecuteMsg::Mint {
96+
user: "user_2".to_string(),
97+
},
98+
)
99+
.unwrap();
100+
101+
// Check if counter is moved to 3001
102+
let next_id = NEXT_ID.load(deps.as_ref().storage).unwrap();
103+
assert_eq!(next_id, 3001);
104+
105+
// Query should fail because token_id 2321 is not minted yet
106+
query(
107+
deps.as_ref(),
108+
env.clone(),
109+
mars_types::account_nft::QueryMsg::OwnerOf {
110+
token_id: "2321".to_string(),
111+
include_expired: None,
112+
},
113+
)
114+
.unwrap_err();
115+
116+
let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();
117+
118+
// Query should now return the owner of token_id 2321, which is Rewards-Collector contract address
119+
let owner_of_res_binary = query(
120+
deps.as_ref(),
121+
env.clone(),
122+
mars_types::account_nft::QueryMsg::OwnerOf {
123+
token_id: "2321".to_string(),
124+
include_expired: None,
125+
},
126+
)
127+
.unwrap();
128+
let owner_of_res: cw721::OwnerOfResponse = from_json(owner_of_res_binary).unwrap();
129+
assert_eq!(
130+
owner_of_res.owner,
131+
"osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy".to_string()
132+
);
133+
134+
assert_eq!(res.messages, vec![]);
135+
assert_eq!(res.events, vec![] as Vec<Event>);
136+
assert!(res.data.is_none());
137+
assert_eq!(
138+
res.attributes,
139+
vec![attr("action", "migrate"), attr("from_version", "2.0.0"), attr("to_version", "2.1.0")]
140+
);
141+
142+
let new_contract_version = ContractVersion {
143+
contract: "crates.io:mars-account-nft".to_string(),
144+
version: "2.1.0".to_string(),
145+
};
146+
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version);
147+
}

contracts/address-provider/src/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,5 @@ fn query_all_addresses(
171171

172172
#[cfg_attr(not(feature = "library"), entry_point)]
173173
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
174-
migrations::v2_0_0::migrate(deps)
174+
migrations::v2_1_0::migrate(deps)
175175
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod v2_0_0;
1+
pub mod v2_1_0;

contracts/address-provider/src/migrations/v2_0_0.rs contracts/address-provider/src/migrations/v2_1_0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
error::ContractError,
77
};
88

9-
const FROM_VERSION: &str = "1.2.0";
9+
const FROM_VERSION: &str = "2.0.0";
1010

1111
pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
1212
// make sure we're migrating the correct contract and from the correct version

contracts/address-provider/tests/tests/test_migration_v2.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use mars_testing::mock_dependencies;
66
#[test]
77
fn wrong_contract_name() {
88
let mut deps = mock_dependencies(&[]);
9-
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "1.2.0").unwrap();
9+
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.0.0").unwrap();
1010

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

@@ -30,7 +30,7 @@ fn wrong_contract_version() {
3030
assert_eq!(
3131
err,
3232
ContractError::Version(VersionError::WrongVersion {
33-
expected: "1.2.0".to_string(),
33+
expected: "2.0.0".to_string(),
3434
found: "4.1.0".to_string()
3535
})
3636
);
@@ -39,7 +39,7 @@ fn wrong_contract_version() {
3939
#[test]
4040
fn successful_migration() {
4141
let mut deps = mock_dependencies(&[]);
42-
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-address-provider", "1.2.0")
42+
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-address-provider", "2.0.0")
4343
.unwrap();
4444

4545
let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();
@@ -49,7 +49,7 @@ fn successful_migration() {
4949
assert!(res.data.is_none());
5050
assert_eq!(
5151
res.attributes,
52-
vec![attr("action", "migrate"), attr("from_version", "1.2.0"), attr("to_version", "2.1.0")]
52+
vec![attr("action", "migrate"), attr("from_version", "2.0.0"), attr("to_version", "2.1.0")]
5353
);
5454

5555
let new_contract_version = ContractVersion {

0 commit comments

Comments
 (0)