Skip to content

Commit

Permalink
Merge branch 'develop' into feat/mnemonic-env-var
Browse files Browse the repository at this point in the history
  • Loading branch information
pacmanifold authored Jun 21, 2023
2 parents 4cc842a + 56cfee5 commit cfae5e6
Show file tree
Hide file tree
Showing 46 changed files with 4,769 additions and 46 deletions.
51 changes: 28 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"contracts/address-provider",
"contracts/incentives",
"contracts/oracle/*",
"contracts/params",
"contracts/swapper/*",
"contracts/red-bank",
"contracts/rewards-collector",
Expand Down Expand Up @@ -42,7 +43,7 @@ anyhow = "1.0.71"
bech32 = "0.9.1"
cosmwasm-schema = "1.2.6"
cosmwasm-std = "1.2.6"
cw2 = { git = "https://github.com/CosmWasm/cw-plus", rev = "de1fb0b" }
cw2 = "1.1.0"
cw-multi-test = "0.16.5"
cw-storage-plus = "1.0.1"
cw-utils = "1.0.1"
Expand Down
4 changes: 2 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ args = ["test", "--locked"]
[tasks.unit-test]
toolchain = "stable"
command = "cargo"
args = ["test", "--locked", "--workspace", "--exclude", "mars-integration-tests"]
args = ["test", "--locked", "--workspace", "--exclude", "mars-integration-tests", "--exclude", "mars-swapper-astroport", "--exclude", "mars-oracle-wasm", "--exclude", "mars-swapper-osmosis"]

[tasks.integration-test]
toolchain = "stable"
command = "cargo"
args = ["test", "--locked", "--package", "mars-integration-tests"]
args = ["test", "--locked", "-p", "mars-integration-tests", "-p", "mars-swapper-astroport", "-p", "mars-oracle-wasm", "-p", "mars-swapper-osmosis", "--test", "*"]

[tasks.fmt]
toolchain = "nightly"
Expand Down
1 change: 0 additions & 1 deletion contracts/incentives/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub const USER_UNCLAIMED_REWARDS: Map<(&Addr, &str, &str), Uint128> = Map::new("
pub const DEFAULT_LIMIT: u32 = 5;

/// The maximum limit for pagination
/// TODO: Remove MAX_LIMIT? What is the purpose? Surely better to have the limit be whatever is the max gas limit?
pub const MAX_LIMIT: u32 = 10;

/// Helper function to update unclaimed rewards for a given user, collateral denom and incentive
Expand Down
2 changes: 0 additions & 2 deletions contracts/oracle/wasm/src/price_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ impl PriceSourceUnchecked<WasmPriceSourceChecked, Empty> for WasmPriceSourceUnch
&route_assets,
)?;

//TODO: Validate window_size and tolerance?

Ok(WasmPriceSourceChecked::AstroportTwap {
pair_address: deps.api.addr_validate(&pair_address)?,
window_size,
Expand Down
35 changes: 35 additions & 0 deletions contracts/params/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "mars-params"
description = "Contract storing the asset params for Credit Manager and Red Bank."
version = "1.0.7"
authors = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
documentation = { workspace = true }
keywords = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
mars-owner = { workspace = true }
mars-utils = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
cw-multi-test = { workspace = true }
16 changes: 16 additions & 0 deletions contracts/params/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Mars Params Contract

The Mars Params Contract is published to [Crates.io](https://crates.io/crates/mars-params)

This contract holds the following values for all the assets in Mars Protocol:

- **Max Loan To Value:** Max percentage of collateral that can be borrowed
- **Liquidation Threshold:** LTV at which the loan is defined as under collateralized and can be liquidated
- **Liquidation Bonus:** Percentage of extra collateral the liquidator gets as a bonus
- **Deposit Enabled:** Is the asset able to be deposited into the Red Bank
- **Borrow Enabled:** Is the asset able to be borrowed from the Red Bank
- **Deposit Cap:** Max amount that can be deposited into the Red Bank
- **Asset Settings:** Credit Manager and Red Bank Permission Settings

Note: Credit Manager Vaults only utilize max loan to value, liquidation threshold, and deposit cap parameters, while Red Bank Markets utilize all of the above parameters.

10 changes: 10 additions & 0 deletions contracts/params/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::write_api;
use mars_params::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
95 changes: 95 additions & 0 deletions contracts/params/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response};
use cw2::set_contract_version;
use mars_owner::OwnerInit::SetInitialOwner;

use crate::{
emergency_powers::{disable_borrowing, disallow_coin, set_zero_deposit_cap, set_zero_max_ltv},
error::ContractResult,
execute::{assert_thf, update_asset_params, update_target_health_factor, update_vault_config},
msg::{
CmEmergencyUpdate, EmergencyUpdate, ExecuteMsg, InstantiateMsg, QueryMsg,
RedBankEmergencyUpdate,
},
query::{query_all_asset_params, query_all_vault_configs, query_vault_config},
state::{ASSET_PARAMS, OWNER, TARGET_HEALTH_FACTOR},
};

const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_: Env,
_: MessageInfo,
msg: InstantiateMsg,
) -> ContractResult<Response> {
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;

OWNER.initialize(
deps.storage,
deps.api,
SetInitialOwner {
owner: msg.owner,
},
)?;

assert_thf(msg.target_health_factor)?;
TARGET_HEALTH_FACTOR.save(deps.storage, &msg.target_health_factor)?;

Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
_: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> ContractResult<Response> {
match msg {
ExecuteMsg::UpdateOwner(update) => Ok(OWNER.update(deps, info, update)?),
ExecuteMsg::UpdateAssetParams(update) => update_asset_params(deps, info, update),
ExecuteMsg::UpdateTargetHealthFactor(mcf) => update_target_health_factor(deps, info, mcf),
ExecuteMsg::UpdateVaultConfig(update) => update_vault_config(deps, info, update),
ExecuteMsg::EmergencyUpdate(update) => match update {
EmergencyUpdate::RedBank(rb_u) => match rb_u {
RedBankEmergencyUpdate::DisableBorrowing(denom) => {
disable_borrowing(deps, info, &denom)
}
},
EmergencyUpdate::CreditManager(rv_u) => match rv_u {
CmEmergencyUpdate::DisallowCoin(denom) => disallow_coin(deps, info, &denom),
CmEmergencyUpdate::SetZeroMaxLtvOnVault(v) => set_zero_max_ltv(deps, info, &v),
CmEmergencyUpdate::SetZeroDepositCapOnVault(v) => {
set_zero_deposit_cap(deps, info, &v)
}
},
},
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _: Env, msg: QueryMsg) -> ContractResult<Binary> {
let res = match msg {
QueryMsg::Owner {} => to_binary(&OWNER.query(deps.storage)?),
QueryMsg::AssetParams {
denom,
} => to_binary(&ASSET_PARAMS.load(deps.storage, &denom)?),
QueryMsg::AllAssetParams {
start_after,
limit,
} => to_binary(&query_all_asset_params(deps, start_after, limit)?),
QueryMsg::VaultConfig {
address,
} => to_binary(&query_vault_config(deps, &address)?),
QueryMsg::AllVaultConfigs {
start_after,
limit,
} => to_binary(&query_all_vault_configs(deps, start_after, limit)?),
QueryMsg::TargetHealthFactor {} => to_binary(&TARGET_HEALTH_FACTOR.load(deps.storage)?),
};
res.map_err(Into::into)
}
Loading

0 comments on commit cfae5e6

Please sign in to comment.