Skip to content

Commit b4a7194

Browse files
authored
Merge pull request #123 from Fundable-Protocol/refactor_distribute
Add unique_ref to distribute function and Distribution event
2 parents 6c9278d + 116d32d commit b4a7194

4 files changed

Lines changed: 93 additions & 33 deletions

File tree

src/base/types.cairo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct Distribution {
2828
#[key]
2929
pub amount: u256,
3030
#[key]
31+
pub unique_ref: felt252,
32+
#[key]
3133
pub recipients_count: u32,
3234
}
3335

@@ -41,6 +43,8 @@ pub struct WeightedDistribution {
4143
pub recipient: ContractAddress,
4244
#[key]
4345
pub amount: u256,
46+
#[key]
47+
pub unique_ref: felt252,
4448
}
4549

4650
/// @notice Enum representing the possible states of a stream
@@ -77,6 +81,7 @@ pub struct DistributionHistory {
7781
pub token: ContractAddress,
7882
pub amount: u256,
7983
pub recipients_count: u32,
84+
pub unique_ref: felt252,
8085
pub timestamp: u64,
8186
}
8287

src/distribute.cairo

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ mod Distributor {
131131
amount: u256,
132132
recipients: Array<ContractAddress>,
133133
token: ContractAddress,
134+
unique_ref: felt252,
134135
) {
135136
// Validate inputs
136137
assert(!recipients.is_empty(), EMPTY_RECIPIENTS);
@@ -160,7 +161,7 @@ mod Distributor {
160161
let recipients_list = recipients.span();
161162
for recipient in recipients {
162163
token_dispatcher.transfer_from(caller, recipient, amount);
163-
self.emit(WeightedDistribution { caller, token, recipient, amount });
164+
self.emit(WeightedDistribution { caller, token, recipient, amount, unique_ref });
164165
}
165166

166167
// Update global statistics
@@ -176,6 +177,7 @@ mod Distributor {
176177
token,
177178
amount: amount_to_distribute,
178179
recipients_count: recipients_list.len(),
180+
unique_ref,
179181
timestamp,
180182
},
181183
);
@@ -189,6 +191,7 @@ mod Distributor {
189191
token,
190192
amount: amount_to_distribute,
191193
recipients_count: recipients_list.len(),
194+
unique_ref,
192195
},
193196
),
194197
);
@@ -199,6 +202,7 @@ mod Distributor {
199202
amounts: Array<u256>,
200203
recipients: Array<ContractAddress>,
201204
token: ContractAddress,
205+
unique_ref: felt252,
202206
) {
203207
// Validate inputs
204208
assert(!recipients.is_empty(), EMPTY_RECIPIENTS);
@@ -241,7 +245,7 @@ mod Distributor {
241245
token_dispatcher.transfer_from(caller, recipient, amount);
242246

243247
// Emit event for each distribution
244-
self.emit(WeightedDistribution { caller, token, recipient, amount });
248+
self.emit(WeightedDistribution { caller, token, recipient, amount, unique_ref });
245249

246250
i += 1;
247251
}
@@ -259,6 +263,7 @@ mod Distributor {
259263
token,
260264
amount: amount_to_distribute,
261265
recipients_count: recipients.len(),
266+
unique_ref,
262267
timestamp,
263268
},
264269
);
@@ -272,6 +277,7 @@ mod Distributor {
272277
token,
273278
amount: amount_to_distribute,
274279
recipients_count: recipients.len(),
280+
unique_ref,
275281
},
276282
),
277283
);

src/interfaces/IDistributor.cairo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ pub trait IDistributor<TContractState> {
88
/// @param amount The total amount to distribute
99
/// @param recipients Array of recipient addresses to distribute to
1010
/// @param token The ERC20 token to distribute
11+
// @param unique_ref uniquely identify the distrubtion
1112
fn distribute(
1213
ref self: TContractState,
1314
amount: u256,
1415
recipients: Array<ContractAddress>,
1516
token: ContractAddress,
17+
unique_ref: felt252,
1618
);
1719

1820
/// @notice Distributes tokens to recipients with custom amounts
@@ -24,6 +26,7 @@ pub trait IDistributor<TContractState> {
2426
amounts: Array<u256>,
2527
recipients: Array<ContractAddress>,
2628
token: ContractAddress,
29+
unique_ref: felt252,
2730
);
2831

2932
/// @notice Gets the current protocol fee percentage

0 commit comments

Comments
 (0)