Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,302 changes: 1,090 additions & 212 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions 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/swapper/*",
"contracts/red-bank",
"contracts/rewards-collector/*",
"packages/chains/*",
Expand All @@ -19,6 +20,7 @@ authors = [
"Larry Engineer <larry@delphidigital.io>",
"Piotr Babel <piotr@delphilabs.io>",
"Spike Spiegel <spikeonmars@protonmail.com>",
"Brianna M. <brianna@delphilabs.io>",
"Ahmad Kaouk",
"Harry Scholes",
]
Expand All @@ -38,20 +40,22 @@ cw2 = { git = "https://github.com/mars-protocol/cw-plus", rev = "4
cw-multi-test = "0.16.1"
cw-storage-plus = "1.0.1"
cw-utils = "1.0.1"
mars-owner = "1.0.0"
mars-owner = { version = "1.0.0", features = ["emergency-owner"] }
osmosis-std = "0.14.0"
osmosis-test-tube = "14.1.1"
osmosis-test-tube = "15.1.0"
prost = { version = "0.11.5", default-features = false, features = ["prost-derive"] }
schemars = "0.8.11"
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
thiserror = "1.0.38"
cw-paginate = "0.2.1"

# packages
mars-health = { version = "1.0.0", path = "./packages/health" }
mars-osmosis = { version = "1.0.0", path = "./packages/chains/osmosis" }
mars-red-bank-types = { version = "1.0.0", path = "./packages/types" }
mars-testing = { version = "1.0.0", path = "./packages/testing" }
mars-utils = { version = "1.0.0", path = "./packages/utils" }
mars-swapper = { version = "1.0.0", path = "./packages/mars-swapper" }

# contracts
mars-address-provider = { version = "1.0.0", path = "./contracts/address-provider" }
Expand All @@ -61,6 +65,7 @@ mars-oracle-osmosis = { version = "1.0.0", path = "./contracts/oracle
mars-red-bank = { version = "1.0.0", path = "./contracts/red-bank" }
mars-rewards-collector-base = { version = "1.0.0", path = "./contracts/rewards-collector/base" }
mars-rewards-collector-osmosis = { version = "1.0.0", path = "./contracts/rewards-collector/osmosis" }
mars-swapper-base = { version = "1.0.0", path = "contracts/swapper/base" }

[profile.release]
codegen-units = 1
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ A bug bounty is currently open for these contracts. See details [here][2].

- Create the build folder:

```bash
yarn build
```
```bash
yarn build
```

- Compile all contracts:

```bash
cargo make rust-optimizer
```
```bash
cargo make rust-optimizer
```

- Formatting:

```bash
yarn format
yarn lint
```
```bash
yarn format
yarn lint
```

This compiles and optimizes all contracts, storing them in `/artifacts` directory along with `checksum.txt` which contains sha256 hashes of each of the `.wasm` files (The script just uses CosmWasm's [rust-optimizer][9]).

Expand Down
36 changes: 36 additions & 0 deletions contracts/params/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "mars-params"
description = "Contract storing the asset params for Rover and Red Bank."
version = { workspace = true }
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-red-bank-types = { 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 Permissions** Rover and Red Bank Permission Settings

Note: Rover 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,
}
}
91 changes: 91 additions & 0 deletions contracts/params/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use cosmwasm_std::{entry_point, 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_mcf, update_asset_params, update_max_close_factor, update_vault_config},
msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
query::{query_all_asset_params, query_all_vault_configs, query_vault_config},
state::{ASSET_PARAMS, MAX_CLOSE_FACTOR, OWNER},
types::{EmergencyUpdate, RedBankEmergencyUpdate, RoverEmergencyUpdate},
};

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

#[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_mcf(msg.max_close_factor)?;
MAX_CLOSE_FACTOR.save(deps.storage, &msg.max_close_factor)?;

Ok(Response::default())
}

#[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::UpdateMaxCloseFactor(mcf) => update_max_close_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::Rover(rv_u) => match rv_u {
RoverEmergencyUpdate::DisallowCoin(denom) => disallow_coin(deps, info, &denom),
RoverEmergencyUpdate::SetZeroMaxLtvOnVault(v) => set_zero_max_ltv(deps, info, &v),
RoverEmergencyUpdate::SetZeroDepositCapOnVault(v) => {
set_zero_deposit_cap(deps, info, &v)
}
},
},
}
}

#[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::MaxCloseFactor {} => to_binary(&MAX_CLOSE_FACTOR.load(deps.storage)?),
};
res.map_err(Into::into)
}
82 changes: 82 additions & 0 deletions contracts/params/src/emergency_powers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use cosmwasm_std::{Decimal, DepsMut, MessageInfo, Response, Uint128};

use crate::{
error::ContractError,
state::{ASSET_PARAMS, OWNER, VAULT_CONFIGS},
};

pub fn disable_borrowing(
deps: DepsMut,
info: MessageInfo,
denom: &str,
) -> Result<Response, ContractError> {
OWNER.assert_emergency_owner(deps.storage, &info.sender)?;

let mut params = ASSET_PARAMS.load(deps.storage, denom)?;
params.red_bank.borrow_enabled = false;
ASSET_PARAMS.save(deps.storage, denom, &params)?;

let response = Response::new()
.add_attribute("action", "emergency_disable_borrowing")
.add_attribute("denom", denom.to_string());

Ok(response)
}

pub fn disallow_coin(
deps: DepsMut,
info: MessageInfo,
denom: &str,
) -> Result<Response, ContractError> {
OWNER.assert_emergency_owner(deps.storage, &info.sender)?;

let mut params = ASSET_PARAMS.load(deps.storage, denom)?;
params.rover.whitelisted = false;
ASSET_PARAMS.save(deps.storage, denom, &params)?;

let response = Response::new()
.add_attribute("action", "emergency_disallow_coin")
.add_attribute("denom", denom.to_string());

Ok(response)
}

pub fn set_zero_max_ltv(
deps: DepsMut,
info: MessageInfo,
vault: &str,
) -> Result<Response, ContractError> {
OWNER.assert_emergency_owner(deps.storage, &info.sender)?;

let vault_addr = deps.api.addr_validate(vault)?;

let mut config = VAULT_CONFIGS.load(deps.storage, &vault_addr)?;
config.max_loan_to_value = Decimal::zero();
VAULT_CONFIGS.save(deps.storage, &vault_addr, &config)?;

let response = Response::new()
.add_attribute("action", "emergency_set_zero_max_ltv")
.add_attribute("vault", vault.to_string());

Ok(response)
}

pub fn set_zero_deposit_cap(
deps: DepsMut,
info: MessageInfo,
vault: &str,
) -> Result<Response, ContractError> {
OWNER.assert_emergency_owner(deps.storage, &info.sender)?;

let vault_addr = deps.api.addr_validate(vault)?;

let mut config = VAULT_CONFIGS.load(deps.storage, &vault_addr)?;
config.deposit_cap.amount = Uint128::zero();
VAULT_CONFIGS.save(deps.storage, &vault_addr, &config)?;

let response = Response::new()
.add_attribute("action", "emergency_set_zero_deposit_cap")
.add_attribute("vault", vault.to_string());

Ok(response)
}
18 changes: 18 additions & 0 deletions contracts/params/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use cosmwasm_std::StdError;
use mars_owner::OwnerError;
pub use mars_utils::error::ValidationError;
use thiserror::Error;

pub type ContractResult<T> = Result<T, ContractError>;

#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("{0}")]
Owner(#[from] OwnerError),

#[error("{0}")]
Validation(#[from] ValidationError),
}
Loading