Skip to content

Commit

Permalink
removed dequeue_withrawal function and unecessary casts
Browse files Browse the repository at this point in the history
  • Loading branch information
markuspluna committed Oct 24, 2023
1 parent bb7ced7 commit 26c9ab1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 110 deletions.
107 changes: 0 additions & 107 deletions backstop/src/backstop/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion backstop/src/backstop/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions backstop/src/emissions/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 26c9ab1

Please sign in to comment.