mars_params/types/
vault.rs1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, Api, Coin, Decimal};
3use mars_utils::helpers::decimal_param_le_one;
4
5use crate::{
6 error::ContractResult,
7 execute::{assert_hls_lqt_gt_max_ltv, assert_lqt_gt_max_ltv},
8 types::hls::HlsParamsBase,
9};
10
11#[cw_serde]
12pub struct VaultConfigBase<T> {
13 pub addr: T,
14 pub deposit_cap: Coin,
15 pub max_loan_to_value: Decimal,
16 pub liquidation_threshold: Decimal,
17 pub whitelisted: bool,
18 pub hls: Option<HlsParamsBase<T>>,
19}
20
21pub type VaultConfigUnchecked = VaultConfigBase<String>;
22pub type VaultConfig = VaultConfigBase<Addr>;
23
24impl From<VaultConfig> for VaultConfigUnchecked {
25 fn from(v: VaultConfig) -> Self {
26 VaultConfigUnchecked {
27 addr: v.addr.to_string(),
28 deposit_cap: v.deposit_cap,
29 max_loan_to_value: v.max_loan_to_value,
30 liquidation_threshold: v.liquidation_threshold,
31 whitelisted: v.whitelisted,
32 hls: v.hls.map(Into::into),
33 }
34 }
35}
36
37impl VaultConfigUnchecked {
38 pub fn check(&self, api: &dyn Api) -> ContractResult<VaultConfig> {
39 decimal_param_le_one(self.max_loan_to_value, "max_loan_to_value")?;
40 decimal_param_le_one(self.liquidation_threshold, "liquidation_threshold")?;
41 assert_lqt_gt_max_ltv(self.max_loan_to_value, self.liquidation_threshold)?;
42
43 if let Some(hls) = self.hls.as_ref() {
45 decimal_param_le_one(hls.max_loan_to_value, "hls_max_loan_to_value")?;
46 decimal_param_le_one(hls.liquidation_threshold, "hls_liquidation_threshold")?;
47 assert_hls_lqt_gt_max_ltv(hls.max_loan_to_value, hls.liquidation_threshold)?;
48 }
49
50 Ok(VaultConfig {
51 addr: api.addr_validate(&self.addr)?,
52 deposit_cap: self.deposit_cap.clone(),
53 max_loan_to_value: self.max_loan_to_value,
54 liquidation_threshold: self.liquidation_threshold,
55 whitelisted: self.whitelisted,
56 hls: self.hls.as_ref().map(|hls| hls.check(api)).transpose()?,
57 })
58 }
59}