kujira_ghost/
math.rs

1use cosmwasm_std::{Decimal, Uint128};
2
3/// Utility to handle the math of adding debt shares (maximize debt)
4pub fn calculate_added_debt(borrow_amount: Uint128, debt_share_price: Decimal) -> Uint128 {
5    borrow_amount.div_ceil(debt_share_price)
6}
7
8/// Utility to handle the math of removing debt shares (maximize debt)
9pub fn calculate_removed_debt(repay_amount: Uint128, debt_share_price: Decimal) -> Uint128 {
10    repay_amount.div_floor(debt_share_price)
11}
12
13/// Utility to convert debt shares to value of debt (maximize debt)
14pub fn debt_to_liability(shares: Uint128, rate: Decimal) -> Uint128 {
15    shares.mul_ceil(rate)
16}
17
18/// Utility to convert receipt tokens to value of deposit (minimize redemption amount)
19pub fn rcpt_tokens_to_owed(tokens: Uint128, rate: Decimal) -> Uint128 {
20    tokens.mul_floor(rate)
21}
22
23/// Utility to convert deposit value to receipt tokens (minimize receipt tokens received)
24pub fn amt_to_rcpt_tokens(amt: Uint128, rate: Decimal) -> Uint128 {
25    amt.div_floor(rate)
26}