Skip to content

Commit

Permalink
implemented patch feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
heytdep committed Jan 25, 2024
1 parent 7f7cfc3 commit 706e9d2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
15 changes: 0 additions & 15 deletions pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ impl Vault for Pool {
// shares to mint will always be the amount deposited, see https://github.com/xycloo/xycloans/issues/17
mint_shares(&env, from.clone(), amount);

// ensure that the pool's balance is >= total supply
check_balance_ge_supply(&env, &token_client)?;

events::deposited(&env, from, amount);
Ok(())
}
Expand All @@ -143,9 +140,6 @@ impl Vault for Pool {

update_rewards(&env, addr);

// ensure that the pool's balance is >= total supply
check_balance_ge_supply(&env, &get_token_client(&env))?;

Ok(())
}

Expand Down Expand Up @@ -175,9 +169,6 @@ impl Vault for Pool {
// burn the shares
burn_shares(&env, addr.clone(), amount);

// ensure that the pool's balance is >= total supply
check_balance_ge_supply(&env, &token_client)?;

events::withdrawn(&env, addr, amount);
Ok(())
}
Expand Down Expand Up @@ -213,9 +204,6 @@ impl FlashLoanModErc3156 for Pool {
// try `transfer_from()` of (`amount` + fees) from the receiver to the flash loan
try_repay(&env, &client, &receiver_id, amount, fee)?;

// ensure that the pool's balance is >= total supply
check_balance_ge_supply(&env, &client)?;

events::loan_successful(&env, receiver_id, amount);
Ok(())
}
Expand All @@ -242,9 +230,6 @@ impl FlashLoan for Pool {
// try `transfer_from()` of (`amount` + fees) from the receiver to the flash loan
try_repay(&env, &client, &receiver_id, amount, fee)?;

// ensure that the pool's balance is >= total supply
check_balance_ge_supply(&env, &client)?;

events::loan_successful(&env, receiver_id, amount);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion pool/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn compute_fee_per_share(
) -> I128WithDust {
let interest_by_supply = accrued_interest.fixed_div_floor(total_supply, STROOP.into()).unwrap();
let computed_floored = fee_per_share_universal.add(interest_by_supply);
let dust = accrued_interest - interest_by_supply.fixed_mul_floor(total_supply, STROOP.into()).unwrap();
let dust = accrued_interest - interest_by_supply.fixed_mul_ceil(total_supply, STROOP.into()).unwrap();

(computed_floored, dust)
}
Expand Down
5 changes: 2 additions & 3 deletions pool/src/rewards.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
events, math::{compute_fee_earned, compute_fee_per_share, I128WithDust}, storage::*, token_utility::{get_token_client, transfer}, types::Error
math::{compute_fee_earned, compute_fee_per_share, I128WithDust}, storage::*, token_utility::{get_token_client, transfer}, types::Error
};
use core::ops::AddAssign;
use soroban_sdk::{Address, Env};
Expand All @@ -17,8 +17,7 @@ pub(crate) fn update_rewards(e: &Env, addr: Address) {
let mut matured = read_matured_fees_particular(e, addr.clone());
matured.add_assign(lender_fees);

write_matured_fees_particular(e, addr.clone(), matured);
events::matured_updated(e, addr, matured);
write_matured_fees_particular(e, addr, matured);
}

pub(crate) fn update_fee_per_share_universal(e: &Env, collected: i128) {
Expand Down
7 changes: 4 additions & 3 deletions pool/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use soroban_sdk::{Address, Env};

use crate::{
types::{DataKey, Error},
INSTANCE_LEDGER_LIFE, PERSISTENT_LEDGER_LIFE, PERSISTENT_LEDGER_TTL_THRESHOLD, INSTANCE_LEDGER_TTL_THRESHOLD,
events, types::{DataKey, Error}, INSTANCE_LEDGER_LIFE, INSTANCE_LEDGER_TTL_THRESHOLD, PERSISTENT_LEDGER_LIFE, PERSISTENT_LEDGER_TTL_THRESHOLD
};

// User specific state.
Expand Down Expand Up @@ -48,9 +47,11 @@ pub(crate) fn read_fee_per_share_particular(e: &Env, addr: Address) -> i128 {
}

pub(crate) fn write_matured_fees_particular(e: &Env, addr: Address, amount: i128) {
let key = DataKey::MaturedFeesParticular(addr);
let key = DataKey::MaturedFeesParticular(addr.clone());
e.storage().persistent().set(&key, &amount);
bump_persistent(e, &key);

events::matured_updated(e, addr, amount);
}

pub(crate) fn read_matured_fees_particular(e: &Env, addr: Address) -> i128 {
Expand Down

0 comments on commit 706e9d2

Please sign in to comment.