Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constants #179

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion backstop/src/backstop/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn require_pool_above_threshold(pool_backstop_data: &PoolBackstopData) -> bo
.saturating_mul(bal_blnd)
.saturating_mul(bal_usdc)
.saturating_mul(SCALAR_7); // 10^7 * 10^7
saturating_pool_pc / threshold_pc >= 1_0000000
saturating_pool_pc / threshold_pc >= SCALAR_7
}

/// The pool's backstop balances
Expand Down
4 changes: 3 additions & 1 deletion pool-factory/src/pool_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use soroban_sdk::{
Symbol, Val, Vec,
};

const SCALAR_9: u64 = 1_000_000_000;

#[contract]
pub struct PoolFactoryContract;

Expand Down Expand Up @@ -69,7 +71,7 @@ impl PoolFactory for PoolFactoryContract {
let pool_init_meta = storage::get_pool_init_meta(&e);

// verify backstop take rate is within [0,1) with 9 decimals
if backstop_take_rate >= 1_000_000_000 {
if backstop_take_rate >= SCALAR_9 {
panic_with_error!(&e, PoolFactoryError::InvalidPoolInitArgs);
}

Expand Down
8 changes: 4 additions & 4 deletions pool/src/auctions/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pub enum AuctionType {
}

impl AuctionType {
pub fn from_u32(value: u32) -> Self {
pub fn from_u32(e: &Env, value: u32) -> Self {
match value {
0 => AuctionType::UserLiquidation,
1 => AuctionType::BadDebtAuction,
2 => AuctionType::InterestAuction,
_ => panic!("internal error"),
_ => panic_with_error!(e, PoolError::BadRequest),
}
}
}
Expand All @@ -54,7 +54,7 @@ pub struct AuctionData {
/// If the auction is unable to be created
pub fn create(e: &Env, auction_type: u32) -> AuctionData {
let backstop = storage::get_backstop(e);
let auction_data = match AuctionType::from_u32(auction_type) {
let auction_data = match AuctionType::from_u32(e, auction_type) {
AuctionType::UserLiquidation => {
panic_with_error!(e, PoolError::BadRequest);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn fill(
) {
let auction_data = storage::get_auction(e, &auction_type, user);
let (to_fill_auction, remaining_auction) = scale_auction(e, &auction_data, percent_filled);
match AuctionType::from_u32(auction_type) {
match AuctionType::from_u32(e, auction_type) {
AuctionType::UserLiquidation => {
fill_user_liq_auction(e, pool, &to_fill_auction, user, filler_state)
}
Expand Down
6 changes: 3 additions & 3 deletions pool/src/auctions/user_liquidation_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn create_user_liq_auction_data(
.fixed_div_floor(position_data.liability_raw, oracle_scalar)
.unwrap_optimized();
let est_incentive = (SCALAR_7 - avg_cf.fixed_div_ceil(avg_lf, SCALAR_7).unwrap_optimized())
.fixed_div_ceil(2_0000000, SCALAR_7)
.fixed_div_ceil(2 * SCALAR_7, SCALAR_7)
.unwrap_optimized()
+ SCALAR_7;

Expand All @@ -65,8 +65,8 @@ pub fn create_user_liq_auction_data(
let mut est_withdrawn_collateral_pct = est_withdrawn_collateral
.fixed_div_ceil(position_data.collateral_raw, oracle_scalar)
.unwrap_optimized();
if est_withdrawn_collateral_pct > 1_0000000 {
est_withdrawn_collateral_pct = 1_0000000;
if est_withdrawn_collateral_pct > SCALAR_7 {
est_withdrawn_collateral_pct = SCALAR_7;
}

for (asset, amount) in user_state.positions.collateral.iter() {
Expand Down
2 changes: 1 addition & 1 deletion pool/src/emissions/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn set_pool_emissions(e: &Env, res_emission_metadata: Vec<ReserveEmissionMet
total_share += metadata.share;
}

if total_share > 1_0000000 {
if total_share > SCALAR_7 as u64 {
panic_with_error!(e, PoolError::BadRequest);
}

Expand Down
2 changes: 1 addition & 1 deletion pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use auctions::{AuctionData, AuctionType};
pub use contract::*;
pub use emissions::ReserveEmissionMetadata;
pub use errors::PoolError;
pub use pool::{Positions, Request};
pub use pool::{Positions, Request, RequestType};
pub use storage::{
AuctionKey, PoolConfig, PoolDataKey, PoolEmissionConfig, ReserveConfig, ReserveData,
ReserveEmissionsConfig, ReserveEmissionsData, UserEmissionData, UserReserveKey,
Expand Down
Loading