Skip to content

Commit

Permalink
chore: update jolt
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Oct 30, 2024
1 parent e807bda commit d4118f6
Show file tree
Hide file tree
Showing 15 changed files with 385 additions and 150 deletions.
12 changes: 8 additions & 4 deletions src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,15 @@ pub mod CommunityComponent {
);
}

// create subscription item
// create subscription item
let mut sub_id = 0;
let (erc20_contract_address, amount) = paid_gating_details;
if(gate_keep_type == GateKeepType::PaidGating) {
if (gate_keep_type == GateKeepType::PaidGating) {
let mut jolt_comp = get_dep_component_mut!(ref self, Jolt);
sub_id = jolt_comp.create_subscription(self.fee_address.read(community_id), amount, erc20_contract_address);
sub_id = jolt_comp
.create_subscription(
self.fee_address.read(community_id), amount, erc20_contract_address
);
}

// update gatekeep details
Expand Down Expand Up @@ -761,7 +764,8 @@ pub mod CommunityComponent {
// enforce paid gatekeeping
GateKeepType::PaidGating => {
let fee_address = self.fee_address.read(community_id);
let (sub_id, erc20_contract_address, entry_fee) = gatekeep_details.paid_gating_details;
let (sub_id, erc20_contract_address, entry_fee) = gatekeep_details
.paid_gating_details;

let jolt_params = JoltParams {
jolt_type: JoltType::Transfer,
Expand Down
10 changes: 3 additions & 7 deletions src/hub/hub.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ use starknet::ContractAddress;
#[starknet::interface]
trait IColonizHub<TState> {
fn follow(
ref self: TState,
address_of_profiles_to_follow: Array<ContractAddress>
ref self: TState, address_of_profiles_to_follow: Array<ContractAddress>
) -> Array<u256>;
fn unfollow(ref self: TState, address_of_profiles_to_unfollow: Array<ContractAddress>);
fn set_block_status(
ref self: TState,
address_of_profiles_to_block: Array<ContractAddress>,
block_status: bool
ref self: TState, address_of_profiles_to_block: Array<ContractAddress>, block_status: bool
);
fn is_following(
self: @TState, followed_profile_address: ContractAddress, follower_address: ContractAddress
Expand Down Expand Up @@ -148,8 +145,7 @@ pub mod ColonizHub {
/// @notice follows a set of given addresses
/// @param address_of_profiles_to_follow addresses of profiles to follow
fn follow(
ref self: ContractState,
address_of_profiles_to_follow: Array<ContractAddress>
ref self: ContractState, address_of_profiles_to_follow: Array<ContractAddress>
) -> Array<u256> {
let follower_profile_address = get_caller_address();
let mut addresses_to_follow = address_of_profiles_to_follow.span();
Expand Down
7 changes: 2 additions & 5 deletions src/interfaces/IHub.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ pub trait IHub<TState> {
// FOLLOW INTERACTIONS
// *************************************************************************
fn follow(
ref self: TState,
address_of_profiles_to_follow: Array<ContractAddress>
ref self: TState, address_of_profiles_to_follow: Array<ContractAddress>
) -> Array<u256>;
fn unfollow(ref self: TState, address_of_profiles_to_unfollow: Array<ContractAddress>);
fn set_block_status(
ref self: TState,
address_of_profiles_to_block: Array<ContractAddress>,
block_status: bool
ref self: TState, address_of_profiles_to_block: Array<ContractAddress>, block_status: bool
);
fn is_following(
self: @TState, followed_profile_address: ContractAddress, follower_address: ContractAddress
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/IJolt.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ pub trait IJolt<TState> {
amount: u256,
erc20_contract_address: ContractAddress
) -> u256;
fn update_subscription(
ref self: TState,
sub_id: u256,
fee_address: ContractAddress,
amount: u256,
erc20_contract_address: ContractAddress
) -> u256;
fn set_fee_address(ref self: TState, _fee_address: ContractAddress);
fn set_whitelisted_renewers(ref self: TState, renewers: Array<ContractAddress>);
fn remove_whitelisted_renewers(ref self: TState, renewers: Array<ContractAddress>);
fn cancel_auto_renewal(ref self: TState, sub_id: u256);
// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down
6 changes: 1 addition & 5 deletions src/interfaces/IPublication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ pub trait IColonizPublications<TState> {
amount: u256,
erc20_contract_address: ContractAddress,
);
fn collect(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256
) -> u256;
fn collect(ref self: TState, profile_address: ContractAddress, pub_id: u256) -> u256;
// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down
99 changes: 98 additions & 1 deletion src/jolt/jolt.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub mod JoltComponent {
Jolted: Jolted,
JoltRequested: JoltRequested,
JoltRequestFullfilled: JoltRequestFullfilled,
SubscriptionCreated: SubscriptionCreated,
SubscriptionUpdated: SubscriptionUpdated,
AutoRenewalCancelled: AutoRenewalCancelled
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -74,6 +77,33 @@ pub mod JoltComponent {
pub block_timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct SubscriptionCreated {
pub sub_id: u256,
pub creator: ContractAddress,
pub fee_address: ContractAddress,
pub amount: u256,
pub erc20_contract_address: ContractAddress,
pub block_timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct SubscriptionUpdated {
pub sub_id: u256,
pub creator: ContractAddress,
pub fee_address: ContractAddress,
pub amount: u256,
pub erc20_contract_address: ContractAddress,
pub block_timestamp: u64,
}

#[derive(Drop, starknet::Event)]
pub struct AutoRenewalCancelled {
pub sub_id: u256,
pub subscriber: ContractAddress,
pub block_timestamp: u64
}

const MAX_TIP: u256 = 1000;

#[embeddable_as(Jolt)]
Expand All @@ -89,7 +119,6 @@ pub mod JoltComponent {

/// @notice multi-faceted transfer logic
/// @param jolt_params required jolting parameters
/// TODO: updating subscriptions, tracking auto renewals
fn jolt(ref self: ComponentState<TContractState>, jolt_params: JoltParams) -> u256 {
let sender = get_caller_address();
let tx_info = get_tx_info().unbox();
Expand Down Expand Up @@ -246,6 +275,61 @@ pub mod JoltComponent {
// update storage
self.subscriptions.write(sub_id, subscription_data);

// emit event
self
.emit(
SubscriptionCreated {
sub_id,
creator: caller,
fee_address: fee_address,
amount: amount,
erc20_contract_address: erc20_contract_address,
block_timestamp: get_block_timestamp(),
}
);

sub_id
}

/// @notice update an existing subscription item
/// @param sub_id id of subscription to be updated
/// @param fee_address address to send subscription fees to
/// @param amount amount to be paid for subscription
/// @param erc20_contract_addrress token to receive subscription in
/// @dev users subscribed to a subscription item should be alerted on update
fn update_subscription(
ref self: ComponentState<TContractState>,
sub_id: u256,
fee_address: ContractAddress,
amount: u256,
erc20_contract_address: ContractAddress
) -> u256 {
let subscription_creator = self.subscriptions.read(sub_id).creator;
assert(subscription_creator == get_caller_address(), Errors::UNAUTHORIZED);

let new_subscription_data = SubscriptionData {
creator: subscription_creator,
fee_address: fee_address,
amount: amount,
erc20_contract_address: erc20_contract_address
};

// update storage
self.subscriptions.write(sub_id, new_subscription_data);

// emit event
self
.emit(
SubscriptionUpdated {
sub_id,
creator: subscription_creator,
fee_address: fee_address,
amount: amount,
erc20_contract_address: erc20_contract_address,
block_timestamp: get_block_timestamp(),
}
);

sub_id
}

Expand Down Expand Up @@ -277,6 +361,19 @@ pub mod JoltComponent {
self._set_whitelisted_renewers_status(renewers, false);
}

fn cancel_auto_renewal(ref self: ComponentState<TContractState>, sub_id: u256) {
let caller = get_caller_address();
self.renewal_iterations.write((caller, sub_id), 0);

// emit event
self
.emit(
AutoRenewalCancelled {
sub_id, subscriber: caller, block_timestamp: get_block_timestamp()
}
);
}

// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down
6 changes: 1 addition & 5 deletions src/mocks/interfaces/IComposable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ pub trait IComposable<TState> {
amount: u256,
erc20_contract_address: ContractAddress,
);
fn collect(
ref self: TState,
profile_address: ContractAddress,
pub_id: u256
) -> u256;
fn collect(ref self: TState, profile_address: ContractAddress, pub_id: u256) -> u256;

// *************************************************************************
// GETTERS
Expand Down
4 changes: 1 addition & 3 deletions src/namespaces/handles.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ pub mod Handles {
/// @notice mints a handle to a profile address
/// @param address profile address to mint handle to
/// @param local_name username to be minted
fn mint_handle(
ref self: ContractState, local_name: felt252,
) -> u256 {
fn mint_handle(ref self: ContractState, local_name: felt252,) -> u256 {
let address = get_caller_address();
self._validate_local_name(local_name);
let token_id = self._mint_handle(address, local_name);
Expand Down
Loading

0 comments on commit d4118f6

Please sign in to comment.