Skip to content

Commit b895db1

Browse files
authored
Merge pull request #448 from mars-protocol/latest-core-contracts
Move latest core-contracts changes to public
2 parents 430d796 + 983f772 commit b895db1

File tree

65 files changed

+2120
-487
lines changed

Some content is hidden

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

65 files changed

+2120
-487
lines changed

Cargo.lock

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

Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ARTIFACTS_DIR_PATH = "target/wasm32-unknown-unknown/release"
1313
RUST_OPTIMIZER_VERSION = "0.16.0"
1414
# Use rust version from rust-optimizer Dockerfile (see https://github.com/CosmWasm/optimizer/blob/v0.16.0/Dockerfile#L1)
1515
# to be sure that we compile / test against the same version
16-
RUST_VERSION = "1.78.0"
16+
RUST_VERSION = "1.81.0"
1717

1818
[tasks.install-stable]
1919
script = '''

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use mars_types::{
1818

1919
use super::MockEnvBuilder;
2020

21+
#[allow(dead_code)]
2122
pub struct MockEnv {
2223
pub app: BasicApp,
2324
pub minter: Addr,

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 = { workspace = true }
3+
version = "2.2.0"
44
authors = { workspace = true }
55
license = { workspace = true }
66
edition = { workspace = true }

contracts/credit-manager/src/contract.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use crate::{
1515
query::{
1616
query_accounts, query_all_coin_balances, query_all_debt_shares,
1717
query_all_total_debt_shares, query_all_vault_positions, query_all_vault_utilizations,
18-
query_config, query_positions, query_total_debt_shares, query_vault_bindings,
19-
query_vault_position_value, query_vault_utilization,
18+
query_config, query_positions, query_swap_fee, query_total_debt_shares,
19+
query_vault_bindings, query_vault_position_value, query_vault_utilization,
2020
},
2121
repay::repay_from_wallet,
2222
update_config::{update_config, update_nft_config, update_owner},
@@ -132,11 +132,12 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> ContractResult<Binary> {
132132
start_after,
133133
limit,
134134
} => to_json_binary(&query_vault_bindings(deps, start_after, limit)?),
135+
QueryMsg::SwapFeeRate {} => to_json_binary(&query_swap_fee(deps)?),
135136
};
136137
res.map_err(Into::into)
137138
}
138139

139140
#[cfg_attr(not(feature = "library"), entry_point)]
140141
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
141-
migrations::v2_1_0::migrate(deps)
142+
migrations::v2_2_0::migrate(deps)
142143
}

contracts/credit-manager/src/instantiate.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::{
66
error::ContractResult,
77
state::{
88
HEALTH_CONTRACT, INCENTIVES, MAX_SLIPPAGE, MAX_UNLOCKING_POSITIONS, ORACLE, OWNER, PARAMS,
9-
RED_BANK, SWAPPER, ZAPPER,
9+
RED_BANK, SWAPPER, SWAP_FEE, ZAPPER,
1010
},
11-
utils::assert_max_slippage,
11+
utils::{assert_max_slippage, assert_swap_fee},
1212
};
1313

1414
pub fn store_config(deps: DepsMut, env: Env, msg: &InstantiateMsg) -> ContractResult<()> {
@@ -32,6 +32,8 @@ pub fn store_config(deps: DepsMut, env: Env, msg: &InstantiateMsg) -> ContractRe
3232
HEALTH_CONTRACT.save(deps.storage, &msg.health_contract.check(deps.api)?)?;
3333
PARAMS.save(deps.storage, &msg.params.check(deps.api)?)?;
3434
INCENTIVES.save(deps.storage, &msg.incentives.check(deps.api, env.contract.address)?)?;
35+
assert_swap_fee(msg.swap_fee)?;
36+
SWAP_FEE.save(deps.storage, &msg.swap_fee)?;
3537

3638
Ok(())
3739
}

contracts/credit-manager/src/liquidate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
/// - Exceeds liquidatee's total debt for denom
1515
/// - Not enough liquidatee request coin balance to match
1616
/// - The value of the debt repaid exceeds the Maximum Debt Repayable (MDR)
17+
///
1718
/// Returns -> (Debt Coin, Liquidator Request Coin, Liquidatee Request Coin)
1819
/// Difference between Liquidator Request Coin and Liquidatee Request Coin goes to rewards-collector account as protocol fee.
1920
pub fn calculate_liquidation(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod v2_1_0;
2+
pub mod v2_2_0;
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
use cosmwasm_std::{DepsMut, Response};
22
use cw2::{assert_contract_version, set_contract_version};
33

4-
use crate::{
5-
contract::{CONTRACT_NAME, CONTRACT_VERSION},
6-
error::ContractError,
7-
};
4+
use crate::{contract::CONTRACT_NAME, error::ContractError};
85

96
const FROM_VERSION: &str = "2.0.3";
7+
const TO_VERSION: &str = "2.1.0";
108

119
pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
1210
// make sure we're migrating the correct contract and from the correct version
1311
assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?;
1412

15-
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;
13+
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), TO_VERSION)?;
1614

1715
Ok(Response::new()
1816
.add_attribute("action", "migrate")
1917
.add_attribute("from_version", FROM_VERSION)
20-
.add_attribute("to_version", CONTRACT_VERSION))
18+
.add_attribute("to_version", TO_VERSION))
2119
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use cosmwasm_std::{Decimal, DepsMut, Response};
2+
use cw2::{assert_contract_version, get_contract_version, set_contract_version, VersionError};
3+
4+
use crate::{
5+
contract::{CONTRACT_NAME, CONTRACT_VERSION},
6+
error::ContractError,
7+
state::SWAP_FEE,
8+
};
9+
10+
const FROM_VERSION: &str = "2.1.0";
11+
12+
pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
13+
let contract = format!("crates.io:{CONTRACT_NAME}");
14+
let version = get_contract_version(deps.storage)?;
15+
let from_version = version.version;
16+
17+
if version.contract != contract {
18+
return Err(ContractError::Version(VersionError::WrongContract {
19+
expected: contract,
20+
found: version.contract,
21+
}));
22+
}
23+
24+
if from_version != FROM_VERSION {
25+
return Err(ContractError::Version(VersionError::WrongVersion {
26+
expected: FROM_VERSION.to_string(),
27+
found: from_version,
28+
}));
29+
}
30+
31+
assert_contract_version(deps.storage, &contract, FROM_VERSION)?;
32+
33+
if SWAP_FEE.may_load(deps.storage)?.is_none() {
34+
SWAP_FEE.save(deps.storage, &Decimal::zero())?;
35+
}
36+
37+
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;
38+
39+
Ok(Response::new()
40+
.add_attribute("action", "migrate")
41+
.add_attribute("from_version", from_version)
42+
.add_attribute("to_version", CONTRACT_VERSION))
43+
}

0 commit comments

Comments
 (0)