diff --git a/emitter/src/contract.rs b/emitter/src/contract.rs index 60a09283..a49dad88 100644 --- a/emitter/src/contract.rs +++ b/emitter/src/contract.rs @@ -58,8 +58,6 @@ impl Emitter for EmitterContract { storage::set_backstop(&e, &backstop); storage::set_blend_id(&e, &blnd_token_id); storage::set_last_fork(&e, 0); // We set the block 45 days in the past to allow for an immediate initial drop - storage::set_drop_status(&e, false); - // TODO: Determine if setting the last distro time here is appropriate, since it means tokens immediately start being distributed storage::set_last_distro_time(&e, &(e.ledger().timestamp() - 7 * 24 * 60 * 60)); } diff --git a/emitter/src/emitter.rs b/emitter/src/emitter.rs index c8d78bb3..64e90415 100644 --- a/emitter/src/emitter.rs +++ b/emitter/src/emitter.rs @@ -27,7 +27,6 @@ pub fn execute_swap_backstop(e: &Env, new_backstop_id: Address) { let new_backstop_balance = backstop_token_client.balance(&new_backstop_id); if new_backstop_balance > backstop_balance { storage::set_backstop(e, &new_backstop_id); - storage::set_drop_status(e, false); storage::set_last_fork(e, e.ledger().sequence()); } else { panic_with_error!(e, EmitterError::InsufficientBackstopSize); @@ -36,7 +35,8 @@ pub fn execute_swap_backstop(e: &Env, new_backstop_id: Address) { /// Perform drop BLND distribution pub fn execute_drop(e: &Env) -> Map { - if storage::get_drop_status(e) { + let backstop = storage::get_backstop(e); + if storage::get_drop_status(e, &backstop) { panic_with_error!(e, EmitterError::BadDrop); } if storage::get_last_fork(e) + 777600 > e.ledger().sequence() { @@ -61,7 +61,7 @@ pub fn execute_drop(e: &Env) -> Map { for (addr, amt) in drop_list.iter() { blnd_client.mint(&addr, &amt); } - storage::set_drop_status(e, true); + storage::set_drop_status(e, &backstop); drop_list } @@ -152,11 +152,11 @@ mod tests { e.as_contract(&emitter, || { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); - storage::set_drop_status(&e, true); + storage::set_drop_status(&e, &backstop); execute_swap_backstop(&e, new_backstop.clone()); assert_eq!(storage::get_backstop(&e), new_backstop); - assert_eq!(storage::get_drop_status(&e), false); + assert_eq!(storage::get_drop_status(&e, &new_backstop), false); }); } @@ -246,11 +246,10 @@ mod tests { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); storage::set_blend_id(&e, &blnd_id); - storage::set_drop_status(&e, false); storage::set_last_fork(&e, 4000000); let list = execute_drop(&e); - assert_eq!(storage::get_drop_status(&e), true); + assert_eq!(storage::get_drop_status(&e, &backstop), true); assert_eq!(list.len(), 2); assert_eq!(blnd_client.balance(&frodo), 20_000_000 * SCALAR_7); assert_eq!(blnd_client.balance(&samwise), 30_000_000 * SCALAR_7); @@ -298,11 +297,11 @@ mod tests { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); storage::set_blend_id(&e, &blnd_id); - storage::set_drop_status(&e, true); + storage::set_drop_status(&e, &backstop); storage::set_last_fork(&e, 4000000); execute_drop(&e); - assert_eq!(storage::get_drop_status(&e), true); + assert_eq!(storage::get_drop_status(&e, &backstop), true); }); } @@ -347,11 +346,10 @@ mod tests { storage::set_last_distro_time(&e, &1000); storage::set_backstop(&e, &backstop); storage::set_blend_id(&e, &blnd_id); - storage::set_drop_status(&e, false); storage::set_last_fork(&e, 4000000); execute_drop(&e); - assert_eq!(storage::get_drop_status(&e), false); + assert_eq!(storage::get_drop_status(&e, &backstop), false); }); } @@ -398,7 +396,6 @@ mod tests { storage::set_backstop(&e, &backstop); storage::set_blend_id(&e, &blnd_id); storage::set_last_fork(&e, 5000000); - storage::set_drop_status(&e, false); execute_drop(&e); }); diff --git a/emitter/src/storage.rs b/emitter/src/storage.rs index 2d42c026..9b595bf6 100644 --- a/emitter/src/storage.rs +++ b/emitter/src/storage.rs @@ -19,8 +19,8 @@ pub enum EmitterDataKey { BlendLPId, // The last timestamp distribution was ran on LastDistro, - // The drop status for the current backstop - DropStatus, + // Stores the list of backstop addresses that have dropped + Dropped(Address), // The last block emissions were forked LastFork, } @@ -118,21 +118,21 @@ pub fn set_last_distro_time(e: &Env, last_distro: &u64) { /// Get whether the emitter has performed the drop distribution or not for the current backstop /// /// Returns true if the emitter has dropped -pub fn get_drop_status(e: &Env) -> bool { +pub fn get_drop_status(e: &Env, backstop: &Address) -> bool { e.storage() .instance() - .get(&EmitterDataKey::DropStatus) - .unwrap_optimized() + .get::(&EmitterDataKey::Dropped(backstop.clone())) + .unwrap_or(false) } /// Set whether the emitter has performed the drop distribution or not for the current backstop /// /// ### Arguments /// * `new_status` - new drop status -pub fn set_drop_status(e: &Env, new_status: bool) { +pub fn set_drop_status(e: &Env, backstop: &Address) { e.storage() .instance() - .set::(&EmitterDataKey::DropStatus, &new_status); + .set::(&EmitterDataKey::Dropped(backstop.clone()), &true); } /// Get the last block an emission fork was executed