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
5 changes: 5 additions & 0 deletions src/base/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct Distribution {
#[key]
pub amount: u256,
#[key]
pub unique_ref: felt252,
#[key]
pub recipients_count: u32,
}

Expand All @@ -41,6 +43,8 @@ pub struct WeightedDistribution {
pub recipient: ContractAddress,
#[key]
pub amount: u256,
#[key]
pub unique_ref: felt252,
}

/// @notice Enum representing the possible states of a stream
Expand Down Expand Up @@ -77,6 +81,7 @@ pub struct DistributionHistory {
pub token: ContractAddress,
pub amount: u256,
pub recipients_count: u32,
pub unique_ref: felt252,
pub timestamp: u64,
}

Expand Down
10 changes: 8 additions & 2 deletions src/distribute.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ mod Distributor {
amount: u256,
recipients: Array<ContractAddress>,
token: ContractAddress,
unique_ref: felt252,
) {
// Validate inputs
assert(!recipients.is_empty(), EMPTY_RECIPIENTS);
Expand Down Expand Up @@ -160,7 +161,7 @@ mod Distributor {
let recipients_list = recipients.span();
for recipient in recipients {
token_dispatcher.transfer_from(caller, recipient, amount);
self.emit(WeightedDistribution { caller, token, recipient, amount });
self.emit(WeightedDistribution { caller, token, recipient, amount, unique_ref });
}

// Update global statistics
Expand All @@ -176,6 +177,7 @@ mod Distributor {
token,
amount: amount_to_distribute,
recipients_count: recipients_list.len(),
unique_ref,
timestamp,
},
);
Expand All @@ -189,6 +191,7 @@ mod Distributor {
token,
amount: amount_to_distribute,
recipients_count: recipients_list.len(),
unique_ref,
},
),
);
Expand All @@ -199,6 +202,7 @@ mod Distributor {
amounts: Array<u256>,
recipients: Array<ContractAddress>,
token: ContractAddress,
unique_ref: felt252,
) {
// Validate inputs
assert(!recipients.is_empty(), EMPTY_RECIPIENTS);
Expand Down Expand Up @@ -241,7 +245,7 @@ mod Distributor {
token_dispatcher.transfer_from(caller, recipient, amount);

// Emit event for each distribution
self.emit(WeightedDistribution { caller, token, recipient, amount });
self.emit(WeightedDistribution { caller, token, recipient, amount, unique_ref });

i += 1;
}
Expand All @@ -259,6 +263,7 @@ mod Distributor {
token,
amount: amount_to_distribute,
recipients_count: recipients.len(),
unique_ref,
timestamp,
},
);
Expand All @@ -272,6 +277,7 @@ mod Distributor {
token,
amount: amount_to_distribute,
recipients_count: recipients.len(),
unique_ref,
},
),
);
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IDistributor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ pub trait IDistributor<TContractState> {
/// @param amount The total amount to distribute
/// @param recipients Array of recipient addresses to distribute to
/// @param token The ERC20 token to distribute
// @param unique_ref uniquely identify the distrubtion
fn distribute(
ref self: TContractState,
amount: u256,
recipients: Array<ContractAddress>,
token: ContractAddress,
unique_ref: felt252,
);

/// @notice Distributes tokens to recipients with custom amounts
Expand All @@ -24,6 +26,7 @@ pub trait IDistributor<TContractState> {
amounts: Array<u256>,
recipients: Array<ContractAddress>,
token: ContractAddress,
unique_ref: felt252,
);

/// @notice Gets the current protocol fee percentage
Expand Down
Loading
Loading