Skip to content

Commit 2b04b8f

Browse files
authored
Merge pull request #119 from Akshola00/mltpl-asset-type
Mltpl asset type
2 parents fc6d1d2 + a2b9a65 commit 2b04b8f

File tree

6 files changed

+172
-74
lines changed

6 files changed

+172
-74
lines changed

src/base/errors.cairo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ pub mod Errors {
133133
// Throw Error when Insufficient balance
134134
pub const INSUFFICIENT_BALANCE: felt252 = 'Error: Insufficient balance';
135135

136+
// Throw Error when donation token is invalid
137+
pub const INVALID_DONATION_TOKEN: felt252 = 'Error: Invalid donation token';
138+
136139
// Throw Error when Fee percent exceeds 100%
137140
pub const PROTOCOL_FEE_PERCENTAGE_EXCEED: felt252 = 'Error: Fee percent exceeds 100%';
141+
138142
}
139143

src/campaign_donation.cairo

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pub mod CampaignDonation {
2424
DOUBLE_WITHDRAWAL, INSUFFICIENT_ALLOWANCE, INSUFFICIENT_BALANCE, MORE_THAN_TARGET,
2525
NFT_NOT_CONFIGURED, OPERATION_OVERFLOW, PROTOCOL_FEE_ADDRESS_NOT_SET,
2626
PROTOCOL_FEE_PERCENTAGE_EXCEED, REFUND_ALREADY_CLAIMED, TARGET_NOT_REACHED, TARGET_REACHED,
27-
WITHDRAWAL_FAILED, ZERO_ALLOWANCE, ZERO_AMOUNT,
27+
WITHDRAWAL_FAILED, ZERO_ALLOWANCE, ZERO_AMOUNT, INVALID_DONATION_TOKEN,
28+
2829
};
2930
use crate::base::types::{Campaigns, DonationMetadata, Donations};
3031

@@ -164,13 +165,17 @@ pub mod CampaignDonation {
164165
#[abi(embed_v0)]
165166
impl CampaignDonationImpl of ICampaignDonation<ContractState> {
166167
fn create_campaign(
167-
ref self: ContractState, campaign_ref: felt252, target_amount: u256,
168+
ref self: ContractState,
169+
campaign_ref: felt252,
170+
target_amount: u256,
171+
donation_token: ContractAddress,
168172
) -> u256 {
169173
let caller = get_caller_address();
170174
let timestamp = get_block_timestamp();
171175
let ref_campaign = campaign_ref.clone();
172176
let campaign_target_amount = target_amount.clone();
173-
let campaign_id = self._create_campaign(ref_campaign, campaign_target_amount);
177+
let campaign_id = self
178+
._create_campaign(ref_campaign, campaign_target_amount, donation_token);
174179
self
175180
.emit(
176181
Event::Campaign(
@@ -463,11 +468,15 @@ pub mod CampaignDonation {
463468
#[generate_trait]
464469
impl InternalImpl of InternalTrait {
465470
fn _create_campaign(
466-
ref self: ContractState, campaign_ref: felt252, target_amount: u256,
471+
ref self: ContractState,
472+
campaign_ref: felt252,
473+
target_amount: u256,
474+
donation_token: ContractAddress,
467475
) -> u256 {
468476
assert(campaign_ref != '', CAMPAIGN_REF_EMPTY);
469477
assert(!self.campaign_refs.read(campaign_ref), CAMPAIGN_REF_EXISTS);
470478
assert(target_amount > 0, ZERO_AMOUNT);
479+
assert(!donation_token.is_zero(), INVALID_DONATION_TOKEN);
471480
let campaign_id: u256 = self.campaign_counts.read() + 1;
472481
let caller = get_caller_address();
473482
let current_balance: u256 = 0;
@@ -481,7 +490,7 @@ pub mod CampaignDonation {
481490
campaign_reference: campaign_ref,
482491
is_closed: false,
483492
is_goal_reached: false,
484-
donation_token: self.donation_token.read(),
493+
donation_token: donation_token,
485494
is_cancelled: false,
486495
};
487496

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

500-
let donation_token = self.donation_token.read();
509+
let donation_token = campaign.donation_token;
501510
// cannot send more than target amount
502511
assert!(amount <= campaign.target_amount, "More than Target");
503512

@@ -560,7 +569,7 @@ pub mod CampaignDonation {
560569

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

563-
let donation_token = self.donation_token.read();
572+
let donation_token = campaign.donation_token;
564573

565574
let token_dispatcher = IERC20Dispatcher { contract_address: donation_token };
566575

src/interfaces/ICampaignDonation.cairo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub trait ICampaignDonation<TContractState> {
1717
/// # Arguments
1818
/// * `campaign_ref` - A unique 5-character identifier for the campaign
1919
/// * `target_amount` - The fundraising goal amount in the donation token
20+
/// * `donation_token` - The address of the donation token
2021
///
2122
/// # Returns
2223
/// * `u256` - The newly created campaign's ID
@@ -26,7 +27,10 @@ pub trait ICampaignDonation<TContractState> {
2627
/// * If `campaign_ref` already exists
2728
/// * If `target_amount` is zero
2829
fn create_campaign(
29-
ref self: TContractState, campaign_ref: felt252, target_amount: u256,
30+
ref self: TContractState,
31+
campaign_ref: felt252,
32+
target_amount: u256,
33+
donation_token: ContractAddress,
3034
) -> u256;
3135

3236
/// Makes a donation to a specific campaign

src/payment_stream.cairo

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub mod PaymentStream {
2222
use crate::base::errors::Errors::{
2323
DECIMALS_TOO_HIGH, FEE_TOO_HIGH, INSUFFICIENT_ALLOWANCE, INSUFFICIENT_AMOUNT,
2424
INVALID_RECIPIENT, INVALID_TOKEN, NON_TRANSFERABLE_STREAM, ONLY_NFT_OWNER_CAN_DELEGATE,
25-
SAME_COLLECTOR_ADDRESS, SAME_OWNER, STREAM_CANCELED, STREAM_HAS_DELEGATE, STREAM_NOT_ACTIVE,
26-
STREAM_NOT_PAUSED, TOO_SHORT_DURATION, UNEXISTING_STREAM, WRONG_RECIPIENT,
27-
WRONG_RECIPIENT_OR_DELEGATE, WRONG_SENDER, ZERO_AMOUNT, OVERDEPOSIT
25+
OVERDEPOSIT, SAME_COLLECTOR_ADDRESS, SAME_OWNER, STREAM_CANCELED, STREAM_HAS_DELEGATE,
26+
STREAM_NOT_ACTIVE, STREAM_NOT_PAUSED, TOO_SHORT_DURATION, UNEXISTING_STREAM,
27+
WRONG_RECIPIENT, WRONG_RECIPIENT_OR_DELEGATE, WRONG_SENDER, ZERO_AMOUNT,
2828
};
2929
use crate::base::types::{ProtocolMetrics, Stream, StreamMetrics, StreamStatus};
3030

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

356-
357356
let token_address = stream.token;
358357

359358
// Effect: update the stream balance by adding the deposit amount
@@ -464,7 +463,7 @@ pub mod PaymentStream {
464463
} else {
465464
// For active streams, the withdrawable amount is the minimum of stream balance and
466465
// total debt
467-
total_debt - stream.withdrawn_amount
466+
total_debt - stream.withdrawn_amount
468467
}
469468
}
470469

@@ -673,7 +672,6 @@ pub mod PaymentStream {
673672

674673
#[abi(embed_v0)]
675674
impl PaymentStreamImpl of IPaymentStream<ContractState> {
676-
677675
/// @notice Creates a new stream and funds it with tokens in a single transaction
678676
/// @dev Combines the create_stream and deposit functions into one efficient operation
679677
fn create_stream(
@@ -806,7 +804,10 @@ pub mod PaymentStream {
806804

807805
self.accesscontrol.revoke_role(PROTOCOL_OWNER_ROLE, current_owner);
808806
self.accesscontrol._grant_role(PROTOCOL_OWNER_ROLE, new_protocol_owner);
809-
self.emit(ProtocolOwnerUpdated { new_protocol_owner, old_protocol_owner: current_owner });
807+
self
808+
.emit(
809+
ProtocolOwnerUpdated { new_protocol_owner, old_protocol_owner: current_owner },
810+
);
810811
}
811812

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

912913
// Pay the recipient the remaining balance
913914
let recipient = stream.recipient;
914-
915+
915916
// Update Stream in State
916917
self.streams.write(stream_id, stream);
917918
let amount_due = self._withdrawable_amount(stream_id);

0 commit comments

Comments
 (0)