Skip to content

Commit

Permalink
Renamed function
Browse files Browse the repository at this point in the history
  • Loading branch information
maneva3 authored and Gancho Manev committed Jun 2, 2023
1 parent 7eb4b73 commit 4e6ddce
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions contracts/lease/src/lease/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::Serialize;
use finance::{
coin::Coin,
currency::Currency,
liability::{check_liability, Status},
liability::{self, Status},
price::{self, Price},
zero::Zero,
};
Expand Down Expand Up @@ -38,7 +38,7 @@ where
Coin::ZERO
};

let status = check_liability(
let status = liability::inspect(
&self.liability,
self.amount,
price::total(total_due, price_in_asset),
Expand Down
86 changes: 43 additions & 43 deletions packages/finance/src/liability/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
}
}

pub fn check_liability<Asset>(
pub fn inspect_liability<Asset>(
spec: &Liability,
asset: Coin<Asset>,
total_due: Coin<Asset>,
Expand Down Expand Up @@ -162,14 +162,14 @@ where
mod tests {
use crate::{coin::Amount, duration::Duration, percent::Percent, test::currency::Nls};

use super::{check_liability, Cause, Liability, Status, Zone};
use super::{inspect_liability, Cause, Liability, Status, Zone};

#[test]
fn no_debt() {
let warn_ltv = Percent::from_permille(11);
let spec = liability_with_first(warn_ltv);
assert_eq!(
check_liability::<Nls>(&spec, 100.into(), 0.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 100.into(), 0.into(), 0.into(), 0.into()),
Status::NoDebt,
);
}
Expand All @@ -179,31 +179,31 @@ mod tests {
let warn_ltv = Percent::from_percent(51);
let spec = liability_with_first(warn_ltv);
assert_eq!(
check_liability::<Nls>(&spec, 100.into(), 1.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 100.into(), 1.into(), 0.into(), 0.into()),
Status::No(Zone::no_warnings(spec.first_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 100.into(), 49.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 100.into(), 49.into(), 0.into(), 0.into()),
Status::No(Zone::no_warnings(spec.first_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 100.into(), 50.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 100.into(), 50.into(), 0.into(), 0.into()),
Status::No(Zone::no_warnings(spec.first_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 505.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 505.into(), 1.into(), 0.into()),
Status::partial(1.into(), Cause::Overdue()),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 509.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 509.into(), 0.into(), 0.into()),
Status::No(Zone::no_warnings(spec.first_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 510.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 510.into(), 0.into(), 0.into()),
Status::No(Zone::first(spec.first_liq_warn(), spec.second_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 510.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 510.into(), 1.into(), 0.into()),
Status::partial(1.into(), Cause::Overdue()),
);
}
Expand All @@ -213,27 +213,27 @@ mod tests {
let spec = liability_with_first(Percent::from_permille(712));

assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 711.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 711.into(), 0.into(), 0.into()),
Status::No(Zone::no_warnings(spec.first_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 712.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 712.into(), 0.into(), 0.into()),
Status::No(Zone::first(spec.first_liq_warn(), spec.second_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 712.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 712.into(), 1.into(), 0.into()),
Status::partial(1.into(), Cause::Overdue())
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 715.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 715.into(), 0.into(), 0.into()),
Status::No(Zone::first(spec.first_liq_warn(), spec.second_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 721.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 721.into(), 0.into(), 0.into()),
Status::No(Zone::first(spec.first_liq_warn(), spec.second_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 722.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 722.into(), 0.into(), 0.into()),
Status::No(Zone::second(spec.second_liq_warn(), spec.third_liq_warn())),
);
}
Expand All @@ -243,27 +243,27 @@ mod tests {
let spec = liability_with_second(Percent::from_permille(123));

assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 122.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 122.into(), 0.into(), 0.into()),
Status::No(Zone::first(spec.first_liq_warn(), spec.second_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 123.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 123.into(), 0.into(), 0.into()),
Status::No(Zone::second(spec.second_liq_warn(), spec.third_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 124.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 124.into(), 0.into(), 0.into()),
Status::No(Zone::second(spec.second_liq_warn(), spec.third_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 128.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 128.into(), 1.into(), 0.into()),
Status::partial(1.into(), Cause::Overdue())
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 132.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 132.into(), 0.into(), 0.into()),
Status::No(Zone::second(spec.second_liq_warn(), spec.third_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 133.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 133.into(), 0.into(), 0.into()),
Status::No(Zone::third(spec.third_liq_warn(), spec.max())),
);
}
Expand All @@ -275,27 +275,27 @@ mod tests {
let spec = liability_with_third(warn_third_ltv);

assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 380.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 380.into(), 0.into(), 0.into()),
Status::No(Zone::second(spec.second_liq_warn(), spec.third_liq_warn())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 381.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 381.into(), 1.into(), 0.into()),
Status::partial(1.into(), Cause::Overdue())
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 381.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 381.into(), 0.into(), 0.into()),
Status::No(Zone::third(spec.third_liq_warn(), spec.max())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 382.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 382.into(), 0.into(), 0.into()),
Status::No(Zone::third(spec.third_liq_warn(), spec.max())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 390.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 390.into(), 0.into(), 0.into()),
Status::No(Zone::third(spec.third_liq_warn(), spec.max())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 391.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 391.into(), 0.into(), 0.into()),
Status::partial(
384.into(),
Cause::Liability {
Expand All @@ -312,15 +312,15 @@ mod tests {
let spec = liability_with_max(max_ltv);

assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 880.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 880.into(), 0.into(), 0.into()),
Status::No(Zone::third(spec.third_liq_warn(), spec.max())),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 880.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 880.into(), 1.into(), 0.into()),
Status::partial(1.into(), Cause::Overdue()),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 881.into(), 0.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 881.into(), 0.into(), 0.into()),
Status::partial(
879.into(),
Cause::Liability {
Expand All @@ -330,7 +330,7 @@ mod tests {
),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 881.into(), 878.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 881.into(), 878.into(), 0.into()),
Status::partial(
879.into(),
Cause::Liability {
Expand All @@ -340,7 +340,7 @@ mod tests {
),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 881.into(), 879.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 881.into(), 879.into(), 0.into()),
Status::partial(
879.into(),
Cause::Liability {
Expand All @@ -350,11 +350,11 @@ mod tests {
),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 881.into(), 880.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 881.into(), 880.into(), 0.into()),
Status::partial(880.into(), Cause::Overdue()),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 999.into(), 997.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 999.into(), 997.into(), 0.into()),
Status::partial(
998.into(),
Cause::Liability {
Expand All @@ -364,7 +364,7 @@ mod tests {
),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 1000.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 1000.into(), 1.into(), 0.into()),
Status::full(Cause::Liability {
ltv: max_ltv,
healthy_ltv: STEP
Expand All @@ -378,7 +378,7 @@ mod tests {
let spec = liability_with_max(max_ltv);

assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 768.into(), 765.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 768.into(), 765.into(), 0.into()),
Status::partial(
765.into(),
Cause::Liability {
Expand All @@ -388,19 +388,19 @@ mod tests {
),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 768.into(), 766.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 768.into(), 766.into(), 0.into()),
Status::partial(766.into(), Cause::Overdue()),
);
assert_eq!(
check_liability::<Nls>(&spec, 1000.into(), 1000.into(), 1.into(), 0.into()),
inspect_liability::<Nls>(&spec, 1000.into(), 1000.into(), 1.into(), 0.into()),
Status::full(Cause::Liability {
ltv: max_ltv,
healthy_ltv: STEP
}),
);
let back_to_healthy: Amount = spec.amount_to_liquidate(1000, 900);
assert_eq!(
check_liability::<Nls>(
inspect_liability::<Nls>(
&spec,
1000.into(),
900.into(),
Expand All @@ -416,7 +416,7 @@ mod tests {
),
);
assert_eq!(
check_liability::<Nls>(
inspect_liability::<Nls>(
&spec,
1000.into(),
900.into(),
Expand All @@ -426,7 +426,7 @@ mod tests {
Status::partial((back_to_healthy + 1).into(), Cause::Overdue()),
);
assert_eq!(
check_liability::<Nls>(
inspect_liability::<Nls>(
&spec,
1000.into(),
900.into(),
Expand All @@ -439,7 +439,7 @@ mod tests {
}),
);
assert_eq!(
check_liability::<Nls>(
inspect_liability::<Nls>(
&spec,
1000.into(),
900.into(),
Expand Down
2 changes: 1 addition & 1 deletion packages/finance/src/liability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};

pub use self::level::Level;
pub use self::liquidation::check_liability;
pub use self::liquidation::inspect_liability as inspect;
pub use self::liquidation::Cause;
pub use self::liquidation::Liquidation;
pub use self::liquidation::Status;
Expand Down

0 comments on commit 4e6ddce

Please sign in to comment.