diff --git a/creator-keys/src/lib.rs b/creator-keys/src/lib.rs
index 46cf9baa..dd08aeb5 100644
--- a/creator-keys/src/lib.rs
+++ b/creator-keys/src/lib.rs
@@ -2385,18 +2385,29 @@ impl CreatorKeysContract {
admin.require_auth();
validate_non_zero_address(&env, &recipient)?;
- if env
+ let old_recipient: Option
= env
.storage()
.persistent()
- .get::(&constants::storage::PROTOCOL_FEE_RECIPIENT)
- .as_ref()
- == Some(&recipient)
- {
+ .get(&constants::storage::PROTOCOL_FEE_RECIPIENT);
+
+ if old_recipient.as_ref() == Some(&recipient) {
return Ok(());
}
+
env.storage()
.persistent()
.set(&constants::storage::PROTOCOL_FEE_RECIPIENT, &recipient);
+
+ if let Some(old) = old_recipient {
+ env.events().publish(
+ (events::PROTOCOL_FEE_RECIPIENT_UPDATED_EVENT_NAME, admin),
+ events::ProtocolFeeRecipientUpdatedEvent {
+ old_recipient: old,
+ new_recipient: recipient,
+ },
+ );
+ }
+
Ok(())
}
diff --git a/creator-keys/tests/set_protocol_fee_recipient.rs b/creator-keys/tests/set_protocol_fee_recipient.rs
index e0be18e5..7dfcd489 100644
--- a/creator-keys/tests/set_protocol_fee_recipient.rs
+++ b/creator-keys/tests/set_protocol_fee_recipient.rs
@@ -73,3 +73,45 @@ fn test_set_protocol_fee_recipient_idempotent() {
"recipient unchanged after idempotent set"
);
}
+
+#[test]
+fn test_set_protocol_fee_recipient_emits_event_on_update() {
+ use creator_keys::events;
+ use soroban_sdk::{testutils::Events, IntoVal};
+
+ let env = test_env_with_auths();
+ let (client, _) = register_creator_keys(&env);
+
+ let admin = Address::generate(&env);
+ let old_recipient = Address::generate(&env);
+ let new_recipient = Address::generate(&env);
+
+ client.set_protocol_fee_recipient(&admin, &old_recipient);
+ client.set_protocol_fee_recipient(&admin, &new_recipient);
+
+ let all_events = env.events().all();
+ let update_events: Vec<_> = all_events
+ .iter()
+ .filter(|(_, topics, _)| {
+ topics
+ .get(events::TOPIC_EVENT_NAME_INDEX)
+ .map(|v| {
+ let sym: soroban_sdk::Symbol = v.into_val(&env);
+ sym == events::PROTOCOL_FEE_RECIPIENT_UPDATED_EVENT_NAME
+ })
+ .unwrap_or(false)
+ })
+ .collect();
+
+ assert_eq!(
+ update_events.len(),
+ 1,
+ "updating fee recipient via set_protocol_fee_recipient must emit exactly one event"
+ );
+
+ let (_, _, data) = update_events.last().unwrap();
+ let payload: events::ProtocolFeeRecipientUpdatedEvent = data.into_val(&env);
+
+ assert_eq!(payload.old_recipient, old_recipient);
+ assert_eq!(payload.new_recipient, new_recipient);
+}