From de09699e3a5294aa239a27eb13dc0a4a0736e7e6 Mon Sep 17 00:00:00 2001 From: markuspluna <59978114+markuspluna@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:55:58 +0300 Subject: [PATCH] Backstop: lowered withdrawal queue - Emitter: Removed drop delay --- backstop/src/backstop/user.rs | 8 ++-- backstop/src/backstop/withdrawal.rs | 8 ++-- emitter/src/backstop_manager.rs | 14 ------- emitter/src/emitter.rs | 47 ----------------------- emitter/src/storage.rs | 21 ---------- test-suites/tests/test_backstop.rs | 2 +- test-suites/tests/test_wasm_happy_path.rs | 2 +- 7 files changed, 10 insertions(+), 92 deletions(-) diff --git a/backstop/src/backstop/user.rs b/backstop/src/backstop/user.rs index cf8b6e0c..b9e299dc 100644 --- a/backstop/src/backstop/user.rs +++ b/backstop/src/backstop/user.rs @@ -55,10 +55,10 @@ impl UserBalance { // user has enough tokens to withdrawal, add Q4W // TODO: Consider capping how many active Q4Ws a user can have - let thirty_days_in_sec = 30 * 24 * 60 * 60; + let twentyone_days_in_sec = 21 * 24 * 60 * 60; let new_q4w = Q4W { amount: to_q, - exp: e.ledger().timestamp() + thirty_days_in_sec, + exp: e.ledger().timestamp() + twentyone_days_in_sec, }; self.q4w.push_back(new_q4w.clone()); } @@ -168,7 +168,7 @@ mod tests { &e, Q4W { amount: to_queue, - exp: 10000 + 30 * 24 * 60 * 60, + exp: 10000 + 21 * 24 * 60 * 60, }, ], ); @@ -205,7 +205,7 @@ mod tests { user.queue_shares_for_withdrawal(&e, to_queue); cur_q4w.push_back(Q4W { amount: to_queue, - exp: 11000000 + 30 * 24 * 60 * 60, + exp: 11000000 + 21 * 24 * 60 * 60, }); assert_eq_vec_q4w(&user.q4w, &cur_q4w); } diff --git a/backstop/src/backstop/withdrawal.rs b/backstop/src/backstop/withdrawal.rs index 9d059e79..29e4ee4d 100644 --- a/backstop/src/backstop/withdrawal.rs +++ b/backstop/src/backstop/withdrawal.rs @@ -124,7 +124,7 @@ mod tests { &e, Q4W { amount: 42_0000000, - exp: 10000 + 30 * 24 * 60 * 60, + exp: 10000 + 21 * 24 * 60 * 60, }, ]; assert_eq_vec_q4w(&new_user_balance.q4w, &expected_q4w); @@ -235,7 +235,7 @@ mod tests { &e, Q4W { amount: 35_0000000, - exp: 10000 + 30 * 24 * 60 * 60, + exp: 10000 + 21 * 24 * 60 * 60, }, ]; assert_eq_vec_q4w(&new_user_balance.q4w, &expected_q4w); @@ -335,7 +335,7 @@ mod tests { e.ledger().set(LedgerInfo { protocol_version: 20, sequence_number: 200, - timestamp: 10000 + 30 * 24 * 60 * 60 + 1, + timestamp: 10000 + 21 * 24 * 60 * 60 + 1, network_id: Default::default(), base_reserve: 10, min_temp_entry_ttl: 10, @@ -401,7 +401,7 @@ mod tests { e.ledger().set(LedgerInfo { protocol_version: 20, sequence_number: 200, - timestamp: 10000 + 30 * 24 * 60 * 60 + 1, + timestamp: 10000 + 21 * 24 * 60 * 60 + 1, network_id: Default::default(), base_reserve: 10, min_temp_entry_ttl: 10, diff --git a/emitter/src/backstop_manager.rs b/emitter/src/backstop_manager.rs index 5fa51e45..a655c60d 100644 --- a/emitter/src/backstop_manager.rs +++ b/emitter/src/backstop_manager.rs @@ -80,7 +80,6 @@ pub fn execute_swap_backstop(e: &Env) -> Swap { emitter::execute_distribute(e, &backstop); // swap backstop and token - storage::set_last_fork(e, e.ledger().sequence()); storage::del_queued_swap(e); storage::set_backstop(e, &swap.new_backstop); storage::set_backstop_token(e, &swap.new_backstop_token); @@ -135,14 +134,12 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_backstop_token(&e, &backstop_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); execute_queue_swap_backstop(&e, &new_backstop, &new_backstop_token); // verify no swap occurred assert_eq!(storage::get_backstop(&e), backstop); assert_eq!(storage::get_backstop_token(&e), backstop_token); - assert_eq!(storage::get_last_fork(&e), 123); // verify swap is queued let swap = storage::get_queued_swap(&e); @@ -188,7 +185,6 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_backstop_token(&e, &backstop_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); execute_queue_swap_backstop(&e, &new_backstop, &new_backstop_token); assert!(false); // should panic @@ -235,7 +231,6 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_backstop_token(&e, &backstop_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); storage::set_queued_swap(&e, &swap); execute_queue_swap_backstop(&e, &new_backstop, &new_backstop_token); @@ -284,7 +279,6 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_backstop_token(&e, &backstop_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); storage::set_queued_swap(&e, &swap); execute_cancel_swap_backstop(&e); @@ -292,7 +286,6 @@ mod tests { // verify no swap occurred assert_eq!(storage::get_backstop(&e), backstop); assert_eq!(storage::get_backstop_token(&e), backstop_token); - assert_eq!(storage::get_last_fork(&e), 123); // verify swap is removed let swap = storage::get_queued_swap(&e); @@ -340,7 +333,6 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_backstop_token(&e, &backstop_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); storage::set_queued_swap(&e, &swap); execute_cancel_swap_backstop(&e); @@ -381,7 +373,6 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_backstop_token(&e, &backstop_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); execute_cancel_swap_backstop(&e); assert!(false); @@ -434,7 +425,6 @@ mod tests { storage::set_backstop_token(&e, &backstop_token); storage::set_blnd_token(&e, &blnd_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); storage::set_queued_swap(&e, &swap); execute_swap_backstop(&e); @@ -442,7 +432,6 @@ mod tests { // verify swap occurred assert_eq!(storage::get_backstop(&e), new_backstop); assert_eq!(storage::get_backstop_token(&e), new_backstop_token); - assert_eq!(storage::get_last_fork(&e), 500); // verify swap is removed let swap = storage::get_queued_swap(&e); @@ -499,7 +488,6 @@ mod tests { storage::set_backstop_token(&e, &backstop_token); storage::set_blnd_token(&e, &blnd_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); storage::set_queued_swap(&e, &swap); execute_swap_backstop(&e); @@ -543,7 +531,6 @@ mod tests { storage::set_backstop_token(&e, &backstop_token); storage::set_blnd_token(&e, &blnd_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); execute_swap_backstop(&e); assert!(false); @@ -593,7 +580,6 @@ mod tests { storage::set_backstop_token(&e, &backstop_token); storage::set_blnd_token(&e, &blnd_token); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 123); storage::set_queued_swap(&e, &swap); execute_swap_backstop(&e); diff --git a/emitter/src/emitter.rs b/emitter/src/emitter.rs index da6064d0..a5330dd6 100644 --- a/emitter/src/emitter.rs +++ b/emitter/src/emitter.rs @@ -25,10 +25,6 @@ pub fn execute_drop(e: &Env, list: &Map) { if storage::get_drop_status(e, &backstop) { panic_with_error!(e, EmitterError::BadDrop); } - if storage::get_last_fork(e) + 777600 > e.ledger().sequence() { - // Check that the last fork was at least 45 days ago - panic_with_error!(e, EmitterError::BadDrop); - } let mut drop_amount = 0; for (_, amt) in list.iter() { @@ -126,7 +122,6 @@ mod tests { storage::set_last_distro_time(&e, &backstop, 1000); storage::set_backstop(&e, &backstop); storage::set_blnd_token(&e, &blnd_id); - storage::set_last_fork(&e, 4000000); execute_drop(&e, &drop_list); assert_eq!(storage::get_drop_status(&e, &backstop), true); @@ -169,7 +164,6 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_blnd_token(&e, &blnd_id); storage::set_drop_status(&e, &backstop); - storage::set_last_fork(&e, 4000000); execute_drop(&e, &drop_list); assert_eq!(storage::get_drop_status(&e, &backstop), true); @@ -209,50 +203,9 @@ mod tests { storage::set_last_distro_time(&e, &backstop, 1000); storage::set_backstop(&e, &backstop); storage::set_blnd_token(&e, &blnd_id); - storage::set_last_fork(&e, 4000000); execute_drop(&e, &drop_list); assert_eq!(storage::get_drop_status(&e, &backstop), false); }); } - - #[test] - #[should_panic(expected = "Error(Contract, #1101)")] - fn test_drop_bad_block() { - let e = Env::default(); - e.mock_all_auths(); - - e.ledger().set(LedgerInfo { - timestamp: 12345, - protocol_version: 20, - sequence_number: 5000000, - network_id: Default::default(), - base_reserve: 10, - min_temp_entry_ttl: 10, - min_persistent_entry_ttl: 10, - max_entry_ttl: 2000000, - }); - - let bombadil = Address::generate(&e); - let frodo = Address::generate(&e); - let samwise = Address::generate(&e); - let emitter = create_emitter(&e); - let backstop = Address::generate(&e); - - let blnd_id = e.register_stellar_asset_contract(bombadil.clone()); - let drop_list = map![ - &e, - (frodo.clone(), 20_000_000 * SCALAR_7), - (samwise.clone(), 30_000_000 * SCALAR_7) - ]; - - e.as_contract(&emitter, || { - storage::set_last_distro_time(&e, &backstop, 1000); - storage::set_backstop(&e, &backstop); - storage::set_blnd_token(&e, &blnd_id); - storage::set_last_fork(&e, 5000000); - - execute_drop(&e, &drop_list); - }); - } } diff --git a/emitter/src/storage.rs b/emitter/src/storage.rs index 3111b2a2..a0e57ce8 100644 --- a/emitter/src/storage.rs +++ b/emitter/src/storage.rs @@ -11,7 +11,6 @@ const IS_INIT_KEY: &str = "IsInit"; const BACKSTOP_KEY: &str = "Backstop"; const BACKSTOP_TOKEN_KEY: &str = "BToken"; const BLND_TOKEN_KEY: &str = "BLNDTkn"; -const LAST_FORK_KEY: &str = "LastFork"; const SWAP_KEY: &str = "Swap"; // Emitter Data Keys @@ -193,23 +192,3 @@ pub fn set_drop_status(e: &Env, backstop: &Address) { .instance() .set::(&EmitterDataKey::Dropped(backstop.clone()), &true); } - -/// Get the last block an emission fork was executed -/// -/// Returns true if the emitter has dropped -pub fn get_last_fork(e: &Env) -> u32 { - e.storage() - .instance() - .get(&Symbol::new(e, LAST_FORK_KEY)) - .unwrap_optimized() -} - -/// Set whether the emitter has performed the drop distribution or not for the current backstop -/// -/// ### Arguments -/// * `new_status` - new drop status -pub fn set_last_fork(e: &Env, block: u32) { - e.storage() - .instance() - .set::(&Symbol::new(e, LAST_FORK_KEY), &block); -} diff --git a/test-suites/tests/test_backstop.rs b/test-suites/tests/test_backstop.rs index 427fa1c8..31b0e252 100644 --- a/test-suites/tests/test_backstop.rs +++ b/test-suites/tests/test_backstop.rs @@ -228,7 +228,7 @@ fn test_backstop() { assert_eq!(result.amount, amount); assert_eq!( result.exp, - fixture.env.ledger().timestamp() + 30 * 24 * 60 * 60 + fixture.env.ledger().timestamp() + 21 * 24 * 60 * 60 ); assert_eq!(bstop_token.balance(&sam), sam_bstop_token_balance); assert_eq!( diff --git a/test-suites/tests/test_wasm_happy_path.rs b/test-suites/tests/test_wasm_happy_path.rs index 3686f6ea..85820807 100644 --- a/test-suites/tests/test_wasm_happy_path.rs +++ b/test-suites/tests/test_wasm_happy_path.rs @@ -593,7 +593,7 @@ fn test_wasm_happy_path() { assert_eq!(result.amount, amount); assert_eq!( result.exp, - fixture.env.ledger().timestamp() + 60 * 60 * 24 * 30 + fixture.env.ledger().timestamp() + 60 * 60 * 24 * 21 ); assert_eq!(fixture.lp.balance(&frodo), frodo_bstop_token_balance); assert_eq!(