Skip to content
4 changes: 4 additions & 0 deletions src/base/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ pub mod Errors {
// Throw Error when Insufficient balance
pub const INSUFFICIENT_BALANCE: felt252 = 'Error: Insufficient balance';

// Throw Error when donation token is invalid
pub const INVALID_DONATION_TOKEN: felt252 = 'Error: Invalid donation token';

// Throw Error when Fee percent exceeds 100%
pub const PROTOCOL_FEE_PERCENTAGE_EXCEED: felt252 = 'Error: Fee percent exceeds 100%';

}

23 changes: 16 additions & 7 deletions src/campaign_donation.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub mod CampaignDonation {
DOUBLE_WITHDRAWAL, INSUFFICIENT_ALLOWANCE, INSUFFICIENT_BALANCE, MORE_THAN_TARGET,
NFT_NOT_CONFIGURED, OPERATION_OVERFLOW, PROTOCOL_FEE_ADDRESS_NOT_SET,
PROTOCOL_FEE_PERCENTAGE_EXCEED, REFUND_ALREADY_CLAIMED, TARGET_NOT_REACHED, TARGET_REACHED,
WITHDRAWAL_FAILED, ZERO_ALLOWANCE, ZERO_AMOUNT,
WITHDRAWAL_FAILED, ZERO_ALLOWANCE, ZERO_AMOUNT, INVALID_DONATION_TOKEN,

};
use crate::base::types::{Campaigns, DonationMetadata, Donations};

Expand Down Expand Up @@ -164,13 +165,17 @@ pub mod CampaignDonation {
#[abi(embed_v0)]
impl CampaignDonationImpl of ICampaignDonation<ContractState> {
fn create_campaign(
ref self: ContractState, campaign_ref: felt252, target_amount: u256,
ref self: ContractState,
campaign_ref: felt252,
target_amount: u256,
donation_token: ContractAddress,
) -> u256 {
let caller = get_caller_address();
let timestamp = get_block_timestamp();
let ref_campaign = campaign_ref.clone();
let campaign_target_amount = target_amount.clone();
let campaign_id = self._create_campaign(ref_campaign, campaign_target_amount);
let campaign_id = self
._create_campaign(ref_campaign, campaign_target_amount, donation_token);
self
.emit(
Event::Campaign(
Expand Down Expand Up @@ -463,11 +468,15 @@ pub mod CampaignDonation {
#[generate_trait]
impl InternalImpl of InternalTrait {
fn _create_campaign(
ref self: ContractState, campaign_ref: felt252, target_amount: u256,
ref self: ContractState,
campaign_ref: felt252,
target_amount: u256,
donation_token: ContractAddress,
) -> u256 {
assert(campaign_ref != '', CAMPAIGN_REF_EMPTY);
assert(!self.campaign_refs.read(campaign_ref), CAMPAIGN_REF_EXISTS);
assert(target_amount > 0, ZERO_AMOUNT);
assert(!donation_token.is_zero(), INVALID_DONATION_TOKEN);
let campaign_id: u256 = self.campaign_counts.read() + 1;
let caller = get_caller_address();
let current_balance: u256 = 0;
Expand All @@ -481,7 +490,7 @@ pub mod CampaignDonation {
campaign_reference: campaign_ref,
is_closed: false,
is_goal_reached: false,
donation_token: self.donation_token.read(),
donation_token: donation_token,
is_cancelled: false,
};

Expand All @@ -497,7 +506,7 @@ pub mod CampaignDonation {
let mut campaign = self.get_campaign(campaign_id);
let contract_address = get_contract_address();

let donation_token = self.donation_token.read();
let donation_token = campaign.donation_token;
// cannot send more than target amount
assert!(amount <= campaign.target_amount, "More than Target");

Expand Down Expand Up @@ -560,7 +569,7 @@ pub mod CampaignDonation {

assert(!self.campaign_withdrawn.read(campaign_id), DOUBLE_WITHDRAWAL);

let donation_token = self.donation_token.read();
let donation_token = campaign.donation_token;

let token_dispatcher = IERC20Dispatcher { contract_address: donation_token };

Expand Down
6 changes: 5 additions & 1 deletion src/interfaces/ICampaignDonation.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub trait ICampaignDonation<TContractState> {
/// # Arguments
/// * `campaign_ref` - A unique 5-character identifier for the campaign
/// * `target_amount` - The fundraising goal amount in the donation token
/// * `donation_token` - The address of the donation token
///
/// # Returns
/// * `u256` - The newly created campaign's ID
Expand All @@ -26,7 +27,10 @@ pub trait ICampaignDonation<TContractState> {
/// * If `campaign_ref` already exists
/// * If `target_amount` is zero
fn create_campaign(
ref self: TContractState, campaign_ref: felt252, target_amount: u256,
ref self: TContractState,
campaign_ref: felt252,
target_amount: u256,
donation_token: ContractAddress,
) -> u256;

/// Makes a donation to a specific campaign
Expand Down
17 changes: 9 additions & 8 deletions src/payment_stream.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub mod PaymentStream {
use crate::base::errors::Errors::{
DECIMALS_TOO_HIGH, FEE_TOO_HIGH, INSUFFICIENT_ALLOWANCE, INSUFFICIENT_AMOUNT,
INVALID_RECIPIENT, INVALID_TOKEN, NON_TRANSFERABLE_STREAM, ONLY_NFT_OWNER_CAN_DELEGATE,
SAME_COLLECTOR_ADDRESS, SAME_OWNER, STREAM_CANCELED, STREAM_HAS_DELEGATE, STREAM_NOT_ACTIVE,
STREAM_NOT_PAUSED, TOO_SHORT_DURATION, UNEXISTING_STREAM, WRONG_RECIPIENT,
WRONG_RECIPIENT_OR_DELEGATE, WRONG_SENDER, ZERO_AMOUNT, OVERDEPOSIT
OVERDEPOSIT, SAME_COLLECTOR_ADDRESS, SAME_OWNER, STREAM_CANCELED, STREAM_HAS_DELEGATE,
STREAM_NOT_ACTIVE, STREAM_NOT_PAUSED, TOO_SHORT_DURATION, UNEXISTING_STREAM,
WRONG_RECIPIENT, WRONG_RECIPIENT_OR_DELEGATE, WRONG_SENDER, ZERO_AMOUNT,
};
use crate::base::types::{ProtocolMetrics, Stream, StreamMetrics, StreamStatus};

Expand Down Expand Up @@ -353,7 +353,6 @@ pub mod PaymentStream {
// Check: stream is not canceled
assert(stream.status != StreamStatus::Canceled, STREAM_CANCELED);


let token_address = stream.token;

// Effect: update the stream balance by adding the deposit amount
Expand Down Expand Up @@ -464,7 +463,7 @@ pub mod PaymentStream {
} else {
// For active streams, the withdrawable amount is the minimum of stream balance and
// total debt
total_debt - stream.withdrawn_amount
total_debt - stream.withdrawn_amount
}
}

Expand Down Expand Up @@ -673,7 +672,6 @@ pub mod PaymentStream {

#[abi(embed_v0)]
impl PaymentStreamImpl of IPaymentStream<ContractState> {

/// @notice Creates a new stream and funds it with tokens in a single transaction
/// @dev Combines the create_stream and deposit functions into one efficient operation
fn create_stream(
Expand Down Expand Up @@ -806,7 +804,10 @@ pub mod PaymentStream {

self.accesscontrol.revoke_role(PROTOCOL_OWNER_ROLE, current_owner);
self.accesscontrol._grant_role(PROTOCOL_OWNER_ROLE, new_protocol_owner);
self.emit(ProtocolOwnerUpdated { new_protocol_owner, old_protocol_owner: current_owner });
self
.emit(
ProtocolOwnerUpdated { new_protocol_owner, old_protocol_owner: current_owner },
);
}

fn get_fee_collector(self: @ContractState) -> ContractAddress {
Expand Down Expand Up @@ -911,7 +912,7 @@ pub mod PaymentStream {

// Pay the recipient the remaining balance
let recipient = stream.recipient;

// Update Stream in State
self.streams.write(stream_id, stream);
let amount_due = self._withdrawable_amount(stream_id);
Expand Down
Loading
Loading