Skip to content

Commit

Permalink
Revert "chore: implemented withrawal_function with erc20 token transfer"
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshioke-Salaki authored Nov 28, 2024
1 parent 8642142 commit 3e80f75
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
target
Scarb.lock
1 change: 0 additions & 1 deletion .snfoundry_cache/.prev_tests_failed

This file was deleted.

2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
starknet-foundry 0.31.0
scarb 2.8.2
scarb 2.8.3
26 changes: 26 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "openzeppelin"
version = "0.12.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.12.0#0697004db74502ce49900edef37331dd03531356"

[[package]]
name = "snforge_std"
version = "0.22.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.22.0#9b215944c6c5871c738381b4ded61bbf06e7ba35"

[[package]]
name = "token_bound_accounts"
version = "0.3.0"
source = "git+https://github.com/Starknet-Africa-Edu/TBA?tag=v0.3.0#1f8b5e3c45422fb188ef2cf874b46d02f642973b"

[[package]]
name = "tokengiver"
version = "0.1.0"
dependencies = [
"openzeppelin",
"snforge_std",
"token_bound_accounts",
]
1 change: 0 additions & 1 deletion src/base/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ pub mod Errors {
pub const INITIALIZED: felt252 = 'TGN: already initialized!';
pub const INVALID_OWNER: felt252 = 'TGN: caller is not owner!';
pub const INVALID_CAMPAIGN: felt252 = 'TGN: campaign is not owner!';
pub const INSUFFICIENT_BALANCE: felt252 = 'TGN: insufficient balance!';
}
22 changes: 3 additions & 19 deletions src/campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod TokengiverCampaign {
use tokengiver::interfaces::IERC721::{IERC721Dispatcher, IERC721DispatcherTrait};
use tokengiver::interfaces::ICampaign::ICampaign;
use tokengiver::base::types::Campaign;
use tokengiver::base::errors::Errors::{NOT_CAMPAIGN_OWNER, INSUFFICIENT_BALANCE};
use tokengiver::base::errors::Errors::NOT_CAMPAIGN_OWNER;
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};


Expand All @@ -43,7 +43,7 @@ mod TokengiverCampaign {
donations: Map<ContractAddress, u256>,
donation_count: Map<ContractAddress, u16>,
donation_details: Map<ContractAddress, DonationDetails>,
erc20_token: ContractAddress, // STRerc20 address
erc20_token: ContractAddress,
token_giver_nft_class_hash: ClassHash,
}

Expand Down Expand Up @@ -167,23 +167,6 @@ mod TokengiverCampaign {
self.withdrawal_balance.write(campaign_address, amount);
}

// withdraw function
fn withdraw(ref self: ContractState, campaign_address: ContractAddress, amount: u256) {
let campaign: Campaign = self.campaign.read(campaign_address);
let caller: ContractAddress = get_caller_address();

assert(caller == campaign.campaign_owner, NOT_CAMPAIGN_OWNER);

let available_balance: u256 = self.withdrawal_balance.read(campaign_address);
assert(amount <= available_balance, INSUFFICIENT_BALANCE);

let token_address = self.erc20_token.read();
let token_dispatcher = IERC20Dispatcher { contract_address: token_address };
let transfer_result = token_dispatcher.transfer(caller, amount);
assert!(transfer_result, "Transfer failed");
self.withdrawal_balance.write(campaign_address, available_balance - amount);
}

// *************************************************************************
// GETTERS
// *************************************************************************
Expand Down Expand Up @@ -211,6 +194,7 @@ mod TokengiverCampaign {
campaign.metadata_URI
}


fn get_campaigns(self: @ContractState) -> Array<ByteArray> {
let mut campaigns = ArrayTrait::new();
let count = self.count.read();
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ICampaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait ICampaign<TState> {
fn set_available_withdrawal(ref self: TState, campaign_address: ContractAddress, amount: u256);
fn set_donations(ref self: TState, campaign_address: ContractAddress, amount: u256);
fn donate(ref self: TState, campaign_address: ContractAddress, amount: u256, token_id: u256);
fn withdraw(ref self: TState, campaign_address: ContractAddress, amount: u256);


// Getters
fn get_campaign_metadata(self: @TState, campaign_address: ContractAddress) -> ByteArray;
Expand Down

0 comments on commit 3e80f75

Please sign in to comment.