Skip to content

Commit 1bc4361

Browse files
authored
Add Staking Tier Discount on Fees (#36)
* Add Fee rate change * Remove log statements * format * add validation tests and remove unwanted comments * update lints check and tier config * update types * update schema * remove unwanted comments * comment fixes * update fmt and add swap account tests * update account tests * add fee tier config query * add migration * fmt * fix migration tests * Fix PR Comments
1 parent e02f39c commit 1bc4361

File tree

90 files changed

+4884
-164
lines changed

Some content is hidden

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

90 files changed

+4884
-164
lines changed

Cargo.lock

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ members = [
2525
"contracts/mock-pyth",
2626
"contracts/mock-red-bank",
2727
"contracts/mock-vault",
28+
"contracts/mock-governance",
2829
"contracts/mock-lst-oracle",
2930

3031
# packages
@@ -153,6 +154,7 @@ mars-mock-red-bank = { path = "./contracts/mock-red-bank" }
153154
mars-mock-vault = { path = "./contracts/mock-vault" }
154155
mars-mock-lst-oracle = { path = "./contracts/mock-lst-oracle" }
155156
mars-mock-rover-health = { path = "./contracts/mock-health" }
157+
mars-mock-governance = { path = "./contracts/mock-governance" }
156158
mars-swapper-mock = { path = "./contracts/swapper/mock" }
157159
mars-zapper-mock = { path = "./contracts/v2-zapper/mock" }
158160

contracts/account-nft/tests/tests/helpers/mock_env_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl MockEnvBuilder {
161161
perps: "n/a".to_string(),
162162
keeper_fee_config: Default::default(),
163163
perps_liquidation_bonus_ratio: Decimal::percent(60),
164+
governance: "n/a".to_string(),
164165
},
165166
},
166167
&[],

contracts/address-provider/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mars-address-provider"
33
description = "A smart contract that holds addresses of Mars Red Bank contracts"
4-
version = "2.3.2"
4+
version = "2.4.0"
55
authors = { workspace = true }
66
edition = { workspace = true }
77
license = { workspace = true }

contracts/address-provider/src/contract.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,6 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
176176
match msg {
177177
MigrateMsg::V2_2_0ToV2_2_2 {} => migrations::v2_2_2::migrate(deps),
178178
MigrateMsg::V2_2_2ToV2_3_2 {} => migrations::v2_3_2::migrate(deps),
179+
MigrateMsg::V2_3_2ToV2_4_0 {} => migrations::v2_4_0::migrate(deps),
179180
}
180181
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod v2_2_2;
22
pub mod v2_3_2;
3+
pub mod v2_4_0;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use cosmwasm_std::{DepsMut, Response};
2+
use cw2::{assert_contract_version, set_contract_version};
3+
4+
use crate::{
5+
contract::{CONTRACT_NAME, CONTRACT_VERSION},
6+
error::ContractError,
7+
};
8+
9+
pub const FROM_VERSION: &str = "2.3.2";
10+
11+
pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
12+
// make sure we're migrating the correct contract and from the correct version
13+
assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?;
14+
15+
// this is a standard migration with no state changes
16+
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;
17+
18+
Ok(Response::new()
19+
.add_attribute("action", "migrate")
20+
.add_attribute("from_version", FROM_VERSION)
21+
.add_attribute("to_version", CONTRACT_VERSION))
22+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ mod test_addresses;
44
mod test_instantiate;
55
mod test_migration_v2;
66
mod test_migration_v2_3_2;
7+
mod test_migration_v2_4_0;
78
mod test_update_owner;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use cosmwasm_std::{attr, testing::mock_env, Event};
2+
use cw2::{ContractVersion, VersionError};
3+
use mars_address_provider::{
4+
contract::{migrate, CONTRACT_NAME, CONTRACT_VERSION},
5+
error::ContractError,
6+
migrations::v2_4_0::FROM_VERSION,
7+
};
8+
use mars_testing::mock_dependencies;
9+
use mars_types::address_provider::MigrateMsg;
10+
11+
#[test]
12+
fn wrong_contract_name() {
13+
let mut deps = mock_dependencies(&[]);
14+
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", FROM_VERSION).unwrap();
15+
16+
let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_3_2ToV2_4_0 {}).unwrap_err();
17+
18+
assert_eq!(
19+
err,
20+
ContractError::Version(VersionError::WrongContract {
21+
expected: format!("crates.io:{CONTRACT_NAME}"),
22+
found: "contract_xyz".to_string()
23+
})
24+
);
25+
}
26+
27+
#[test]
28+
fn wrong_contract_version() {
29+
let mut deps = mock_dependencies(&[]);
30+
cw2::set_contract_version(deps.as_mut().storage, format!("crates.io:{CONTRACT_NAME}"), "4.1.0")
31+
.unwrap();
32+
33+
let err = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_3_2ToV2_4_0 {}).unwrap_err();
34+
35+
assert_eq!(
36+
err,
37+
ContractError::Version(VersionError::WrongVersion {
38+
expected: FROM_VERSION.to_string(),
39+
found: "4.1.0".to_string()
40+
})
41+
);
42+
}
43+
44+
#[test]
45+
fn successful_migration() {
46+
let mut deps = mock_dependencies(&[]);
47+
cw2::set_contract_version(
48+
deps.as_mut().storage,
49+
format!("crates.io:{CONTRACT_NAME}"),
50+
FROM_VERSION,
51+
)
52+
.unwrap();
53+
54+
let res = migrate(deps.as_mut(), mock_env(), MigrateMsg::V2_3_2ToV2_4_0 {}).unwrap();
55+
56+
assert_eq!(res.messages, vec![]);
57+
assert_eq!(res.events, vec![] as Vec<Event>);
58+
assert!(res.data.is_none());
59+
assert_eq!(
60+
res.attributes,
61+
vec![
62+
attr("action", "migrate"),
63+
attr("from_version", FROM_VERSION),
64+
attr("to_version", CONTRACT_VERSION)
65+
]
66+
);
67+
68+
let new_contract_version = ContractVersion {
69+
contract: format!("crates.io:{CONTRACT_NAME}"),
70+
version: CONTRACT_VERSION.to_string(),
71+
};
72+
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version);
73+
}

contracts/credit-manager/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mars-credit-manager"
3-
version = "2.3.1"
3+
version = "2.4.0"
44
authors = { workspace = true }
55
license = { workspace = true }
66
edition = { workspace = true }

0 commit comments

Comments
 (0)