From 26c9ab1d145b1365e49981a5911738213afee29b Mon Sep 17 00:00:00 2001 From: markuspluna <59978114+markuspluna@users.noreply.github.com> Date: Tue, 24 Oct 2023 13:36:26 -0400 Subject: [PATCH] removed dequeue_withrawal function and unecessary casts --- backstop/src/backstop/user.rs | 107 ---------------------------- backstop/src/backstop/withdrawal.rs | 3 +- backstop/src/emissions/manager.rs | 4 +- 3 files changed, 4 insertions(+), 110 deletions(-) diff --git a/backstop/src/backstop/user.rs b/backstop/src/backstop/user.rs index 4f001fe3..123cd3ff 100644 --- a/backstop/src/backstop/user.rs +++ b/backstop/src/backstop/user.rs @@ -109,19 +109,6 @@ impl UserBalance { panic_with_error!(e, BackstopError::InvalidBalance); } } - - /// Withdraw shares from the user - /// - /// ### Arguments - /// * `to_dequeue` - The amount of shares to dequeue from withdraw - /// - /// ### Errors - /// If the amount to queue is greater than the available shares - pub fn dequeue_withdrawal(&mut self, e: &Env, to_dequeue: i128) { - self.dequeue_shares_for_withdrawal(e, to_dequeue, false); - - self.shares += to_dequeue; - } } #[cfg(test)] @@ -448,60 +435,6 @@ mod tests { user.dequeue_shares_for_withdrawal(&e, to_wd, true); } - #[test] - fn test_dequeue_shares() { - let e = Env::default(); - - let cur_q4w = vec![ - &e, - Q4W { - amount: 125, - exp: 10000000, - }, - Q4W { - amount: 200, - exp: 12592000, - }, - Q4W { - amount: 50, - exp: 19592000, - }, - ]; - let mut user = UserBalance { - shares: 1000, - q4w: cur_q4w.clone(), - }; - - e.ledger().set(LedgerInfo { - protocol_version: 20, - sequence_number: 1, - timestamp: 11192000, - network_id: Default::default(), - base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, - }); - let to_dequeue = 300; - - // verify exp is ignored if only dequeueing - user.dequeue_withdrawal(&e, to_dequeue); - - let expected_q4w = vec![ - &e, - Q4W { - amount: 25, - exp: 12592000, - }, - Q4W { - amount: 50, - exp: 19592000, - }, - ]; - assert_eq_vec_q4w(&user.q4w, &expected_q4w); - assert_eq!(user.shares, 1300); - } - #[test] #[should_panic(expected = "Error(Contract, #3)")] fn test_try_dequeue_shares_require_expired_expect_panic() { @@ -541,44 +474,4 @@ mod tests { // verify exp is respected when specified user.dequeue_shares_for_withdrawal(&e, to_dequeue, true); } - - #[test] - #[should_panic(expected = "Error(Contract, #2)")] - fn test_try_dequeue_shares_over_total() { - let e = Env::default(); - - let cur_q4w = vec![ - &e, - Q4W { - amount: 125, - exp: 10000000, - }, - Q4W { - amount: 200, - exp: 12592000, - }, - Q4W { - amount: 50, - exp: 19592000, - }, - ]; - let mut user = UserBalance { - shares: 1000, - q4w: cur_q4w.clone(), - }; - - e.ledger().set(LedgerInfo { - protocol_version: 20, - sequence_number: 1, - timestamp: 11192000, - network_id: Default::default(), - base_reserve: 10, - min_temp_entry_expiration: 10, - min_persistent_entry_expiration: 10, - max_entry_expiration: 2000000, - }); - - let to_dequeue = 376; - user.dequeue_withdrawal(&e, to_dequeue); - } } diff --git a/backstop/src/backstop/withdrawal.rs b/backstop/src/backstop/withdrawal.rs index 5bf278e3..bddf32f0 100644 --- a/backstop/src/backstop/withdrawal.rs +++ b/backstop/src/backstop/withdrawal.rs @@ -42,7 +42,8 @@ pub fn execute_dequeue_withdrawal(e: &Env, from: &Address, pool_address: &Addres // update emissions emissions::update_emissions(e, pool_address, &pool_balance, from, &user_balance, false); - user_balance.dequeue_withdrawal(e, amount); + user_balance.dequeue_shares_for_withdrawal(e, amount, false); + user_balance.add_shares(amount); pool_balance.dequeue_q4w(e, amount); storage::set_user_balance(e, pool_address, from, &user_balance); diff --git a/backstop/src/emissions/manager.rs b/backstop/src/emissions/manager.rs index 8e8011d4..6a58d019 100644 --- a/backstop/src/emissions/manager.rs +++ b/backstop/src/emissions/manager.rs @@ -79,14 +79,14 @@ pub fn update_emission_cycle(e: &Env) { let net_deposits = pool_balance.tokens.clone() - pool_balance.convert_to_tokens(pool_balance.q4w.clone()); rz_tokens.push_back(net_deposits); - total_tokens += i128(net_deposits); + total_tokens += net_deposits; } let blnd_token_client = TokenClient::new(e, &storage::get_blnd_token(e)); // store pools EPS and distribute emissions to backstop depositors for rz_pool_index in 0..rz_len { let rz_pool = reward_zone.get(rz_pool_index).unwrap_optimized(); - let cur_pool_tokens = i128(rz_tokens.pop_front_unchecked()); + let cur_pool_tokens = rz_tokens.pop_front_unchecked(); let share = cur_pool_tokens .fixed_div_floor(total_tokens, SCALAR_7) .unwrap_optimized();