Skip to content
Merged
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
1 change: 1 addition & 0 deletions ci-trigger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy file to trigger CI run
13 changes: 13 additions & 0 deletions creator-keys/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ pub const ADDRESS_WHITELISTED_EVENT_NAME: Symbol = symbol_short!("wl_add");
pub const ADDRESS_REMOVED_EVENT_NAME: Symbol = symbol_short!("wl_rem");
pub const HOLDING_CAP_UPDATED_EVENT_NAME: Symbol = symbol_short!("hold_cap");
pub const WHITELIST_UPDATED_EVENT_NAME: Symbol = symbol_short!("wl_upd");
pub const EARLY_ACCESS_MODE_CHANGED_EVENT_NAME: Symbol = symbol_short!("ea_mode");
pub const REFERRAL_REGISTERED_EVENT_NAME: Symbol = symbol_short!("ref_reg");
pub const REFERRAL_REWARD_ALLOCATED_EVENT_NAME: Symbol = symbol_short!("ref_rwd");
pub const REFERRAL_REWARDS_CLAIMED_EVENT_NAME: Symbol = symbol_short!("ref_clm");
Expand Down Expand Up @@ -1187,6 +1188,18 @@ pub fn whitelist_updated_topics(creator: &Address) -> (Symbol, Address) {
(WHITELIST_UPDATED_EVENT_NAME, creator.clone())
}

/// Emitted when a creator toggles early-access mode.
#[derive(Clone, Debug, Eq, PartialEq)]
#[contracttype]
pub struct EarlyAccessModeChangedEvent {
pub creator: Address,
pub enabled: bool,
}

pub fn early_access_mode_changed_topics(creator: &Address) -> (Symbol, Address) {
(EARLY_ACCESS_MODE_CHANGED_EVENT_NAME, creator.clone())
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[contracttype]
pub struct ReferralRegisteredEvent {
Expand Down
11 changes: 9 additions & 2 deletions creator-keys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12334,7 +12334,7 @@ impl CreatorKeysContract {
.get(&constants::storage::max_keys_per_wallet(&creator))
}

/// Creator or admin toggles early-access mode. While on, only whitelisted
/// Creator toggles early-access mode. While on, only whitelisted
/// wallets may buy; turning it off opens trading to everyone. Shares the
/// flag used by `enable_whitelist` / `disable_whitelist`.
pub fn set_early_access_mode(
Expand All @@ -12344,13 +12344,20 @@ impl CreatorKeysContract {
enabled: bool,
) -> Result<(), ContractError> {
caller.require_auth();
assert_creator_or_admin(&env, &caller, &creator)?;
read_registered_creator_profile(&env, &creator)?;
if caller != creator {
return Err(ContractError::Unauthorized);
}
if enabled && is_whitelist_permanently_disabled(&env, &creator) {
return Err(ContractError::WhitelistPermanentlyDisabled);
}
let mode_key = constants::storage::whitelist_mode(&creator);
env.storage().persistent().set(&mode_key, &enabled);
extend_key_ttl_to_full_window(&env, &mode_key);
env.events().publish(
events::early_access_mode_changed_topics(&creator),
events::EarlyAccessModeChangedEvent { creator, enabled },
);
Ok(())
}

Expand Down
18 changes: 16 additions & 2 deletions creator-keys/src/test_new_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
METADATA_NAME_MAX_LEN,
};
use soroban_sdk::{
testutils::{Address as _, Events},
testutils::{Address as _, Events as _},
Address, Env, IntoVal, String, Symbol,
};

Expand Down Expand Up @@ -518,10 +518,24 @@ fn test_early_access_mode_whitelist_and_permissions() {
client.try_buy_key(&creator, &wallet, &1000i128, &None),
Err(Ok(ContractError::NotWhitelisted))
);
client.set_early_access_mode(&admin, &creator, &false);
assert_eq!(
client.try_set_early_access_mode(&admin, &creator, &false),
Err(Ok(ContractError::Unauthorized))
);
client.set_early_access_mode(&creator, &creator, &false);
assert_eq!(client.buy_key(&creator, &wallet, &1000i128, &None), 2);
}

#[test]
fn test_early_access_mode_toggle_emits_event() {
let (env, client, _admin, _treasury) = setup_test();
let creator = Address::generate(&env);
register_creator(&env, &client, &creator);

client.set_early_access_mode(&creator, &creator, &true);
assert_eq!(env.events().all().len(), 1);
}

#[test]
fn test_registered_referral_first_trade_fee_and_claim() {
let (env, client, admin, _treasury) = setup_test();
Expand Down
Loading