From 3e80f755cda7939c9d3d36e6adfa3a3fd9bc0a16 Mon Sep 17 00:00:00 2001 From: Oshioke Salaki Date: Thu, 28 Nov 2024 16:13:57 +0100 Subject: [PATCH] Revert "chore: implemented withrawal_function with erc20 token transfer" --- .gitignore | 1 - .snfoundry_cache/.prev_tests_failed | 1 - .tool-versions | 2 +- Scarb.lock | 26 ++++++++++++++++++++++++++ src/base/errors.cairo | 1 - src/campaign.cairo | 22 +++------------------- src/interfaces/ICampaign.cairo | 2 +- 7 files changed, 31 insertions(+), 24 deletions(-) delete mode 100644 .snfoundry_cache/.prev_tests_failed create mode 100644 Scarb.lock diff --git a/.gitignore b/.gitignore index b1e298f..eb5a316 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ target -Scarb.lock diff --git a/.snfoundry_cache/.prev_tests_failed b/.snfoundry_cache/.prev_tests_failed deleted file mode 100644 index 1d7b2ef..0000000 --- a/.snfoundry_cache/.prev_tests_failed +++ /dev/null @@ -1 +0,0 @@ -tokengiver_integrationtest::test_withdraw::test_withdrawal_flow diff --git a/.tool-versions b/.tool-versions index 84a4307..d54b39c 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ starknet-foundry 0.31.0 -scarb 2.8.2 \ No newline at end of file +scarb 2.8.3 \ No newline at end of file diff --git a/Scarb.lock b/Scarb.lock new file mode 100644 index 0000000..4a8a52b --- /dev/null +++ b/Scarb.lock @@ -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", +] diff --git a/src/base/errors.cairo b/src/base/errors.cairo index ecee6fa..0d1bcf7 100644 --- a/src/base/errors.cairo +++ b/src/base/errors.cairo @@ -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!'; } diff --git a/src/campaign.cairo b/src/campaign.cairo index 0aa5dfe..0992110 100644 --- a/src/campaign.cairo +++ b/src/campaign.cairo @@ -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}; @@ -43,7 +43,7 @@ mod TokengiverCampaign { donations: Map, donation_count: Map, donation_details: Map, - erc20_token: ContractAddress, // STRerc20 address + erc20_token: ContractAddress, token_giver_nft_class_hash: ClassHash, } @@ -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 // ************************************************************************* @@ -211,6 +194,7 @@ mod TokengiverCampaign { campaign.metadata_URI } + fn get_campaigns(self: @ContractState) -> Array { let mut campaigns = ArrayTrait::new(); let count = self.count.read(); diff --git a/src/interfaces/ICampaign.cairo b/src/interfaces/ICampaign.cairo index fccafcf..d2c7c18 100644 --- a/src/interfaces/ICampaign.cairo +++ b/src/interfaces/ICampaign.cairo @@ -20,7 +20,7 @@ pub trait ICampaign { 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;