Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions creator-keys/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ pub fn register_event_topics(creator: &Address) -> (Symbol, Address) {
(REGISTER_EVENT_NAME, creator.clone())
}

/// Event name for protocol fee recipient rotation.
pub const PROTO_FEE_ROTATE: Symbol = symbol_short!("pfr_upd");

/// Event name for creator fee recipient rotation.
pub const CREATOR_FEE_ROTATE: Symbol = symbol_short!("cfr_upd");

#[derive(Clone, Debug, Eq, PartialEq)]
#[contracttype]
pub struct ProtocolFeeRecipientUpdated {
pub old_recipient: Address,
pub new_recipient: Address,
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[contracttype]
pub struct CreatorFeeRecipientUpdated {
pub creator: Address,
pub old_recipient: Address,
pub new_recipient: Address,
}

/// Shared buy event topics tuple.
pub fn buy_event_topics(creator: &Address, buyer: &Address) -> (Symbol, Address, Address) {
(BUY_EVENT_NAME, creator.clone(), buyer.clone())
Expand Down
74 changes: 74 additions & 0 deletions creator-keys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub enum ContractError {
InvalidHandleCharacter = 14,
ZeroAddress = 15,
SlippageExceeded = 16,
Unauthorized = 17,
}

pub mod fee {
Expand Down Expand Up @@ -1262,6 +1263,79 @@ impl CreatorKeysContract {
Ok(())
}

pub fn update_protocol_fee_recipient(
env: Env,
admin: Address,
new_recipient: Address,
) -> Result<(), ContractError> {
admin.require_auth();

let stored_admin: Address = env
.storage()
.persistent()
.get(&constants::storage::ADMIN_ADDRESS)
.ok_or(ContractError::Unauthorized)?;
if admin != stored_admin {
return Err(ContractError::Unauthorized);
}

validate_non_zero_address(&env, &new_recipient)?;

let old_recipient: Address = env
.storage()
.persistent()
.get(&constants::storage::PROTOCOL_FEE_RECIPIENT)
.ok_or(ContractError::Unauthorized)?;

env.storage()
.persistent()
.set(&constants::storage::PROTOCOL_FEE_RECIPIENT, &new_recipient);

env.events().publish(
(events::PROTO_FEE_ROTATE,),
events::ProtocolFeeRecipientUpdated {
old_recipient,
new_recipient,
},
);

Ok(())
}

pub fn update_creator_fee_recipient(
env: Env,
creator: Address,
caller: Address,
new_recipient: Address,
) -> Result<(), ContractError> {
caller.require_auth();

let mut profile = read_registered_creator_profile(&env, &creator)?;

if caller != profile.fee_recipient {
return Err(ContractError::Unauthorized);
}

validate_non_zero_address(&env, &new_recipient)?;

let old_recipient = profile.fee_recipient.clone();

profile.fee_recipient = new_recipient.clone();
let key = constants::storage::creator(&creator);
env.storage().persistent().set(&key, &profile);

env.events().publish(
(events::CREATOR_FEE_ROTATE, creator.clone()),
events::CreatorFeeRecipientUpdated {
creator,
old_recipient,
new_recipient,
},
);

Ok(())
}

/// Read-only view: returns whether protocol configuration has been initialized.
///
/// Returns `true` once a protocol fee configuration has been stored and `false`
Expand Down
Loading
Loading