From 46125bf10006f7be183dd951dd580d3136ae9e72 Mon Sep 17 00:00:00 2001 From: morelucks Date: Fri, 28 Mar 2025 12:43:43 +0100 Subject: [PATCH 1/3] escrow_factory interface implementation --- .tool-versions | 9 --------- src/escrow/escrow_contract.cairo | 8 ++++---- src/escrow/escrow_factory.cairo | 20 +++----------------- src/escrownet/escrownet.cairo | 2 +- src/interface.cairo | 1 + src/interface/iescrow.cairo | 6 ++---- src/interface/iescrowfactory.cairo | 17 +++++++++++++++++ 7 files changed, 28 insertions(+), 35 deletions(-) create mode 100644 src/interface/iescrowfactory.cairo diff --git a/.tool-versions b/.tool-versions index 87039f6..114df33 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,11 +1,2 @@ scarb 2.8.2 starknet-foundry - - - - - - - - - diff --git a/src/escrow/escrow_contract.cairo b/src/escrow/escrow_contract.cairo index 9c4eb44..b4c793d 100644 --- a/src/escrow/escrow_contract.cairo +++ b/src/escrow/escrow_contract.cairo @@ -164,8 +164,8 @@ mod EscrowContract { Event::EscrowRefunded( EscrowRefunded { escrow_id, depositor, amount, timestamp: get_block_timestamp(), - } - ) + }, + ), ); } @@ -301,14 +301,14 @@ mod EscrowContract { isCompleted: false, isApprovedDepositor: false, isApprovedBeneficiary: false, - isPaid: false + isPaid: false, }; self.milestones.write(milestone_id, milestone) } fn request_milestone_payment( - ref self: ContractState, id: u64, token_address: ContractAddress + ref self: ContractState, id: u64, token_address: ContractAddress, ) -> bool { let mut milestone: Milestone = self.milestones.read(id); diff --git a/src/escrow/escrow_factory.cairo b/src/escrow/escrow_factory.cairo index 78a3ec7..9883e55 100644 --- a/src/escrow/escrow_factory.cairo +++ b/src/escrow/escrow_factory.cairo @@ -3,22 +3,7 @@ pub use starknet::{ ContractAddress, class_hash::ClassHash, syscalls::deploy_syscall, SyscallResultTrait, }; use escrownet_contract::interface::iescrow::{IEscrowDispatcher, IEscrowDispatcherTrait}; - -#[starknet::interface] -pub trait IEscrowFactory { - fn deploy_escrow( - ref self: TContractState, - beneficiary: ContractAddress, - depositor: ContractAddress, - arbiter: ContractAddress, - salt: felt252, - milestone_description: ByteArray, - milestone_amount: u256, - milestone_dueDate: u256, - ) -> ContractAddress; - - fn get_escrow_contracts(self: @TContractState) -> Array; -} +use escrownet_contract::interface::iescrowfactory; #[starknet::component] pub mod EscrowFactory { @@ -29,6 +14,7 @@ pub mod EscrowFactory { ContractAddress, class_hash::ClassHash, syscalls::deploy_syscall, SyscallResultTrait, storage::{Map}, }; + use core::traits::{TryInto, Into}; const ESCROW_CONTRACT_CLASS_HASH: felt252 = @@ -43,7 +29,7 @@ pub mod EscrowFactory { #[embeddable_as(Escrows)] impl EscrowFactoryImpl< TContractState, +HasComponent, - > of IEscrowFactory> { + > of IEscrowFactory> { fn deploy_escrow( ref self: ComponentState, beneficiary: ContractAddress, diff --git a/src/escrownet/escrownet.cairo b/src/escrownet/escrownet.cairo index 08ccf67..7dc2b21 100644 --- a/src/escrownet/escrownet.cairo +++ b/src/escrownet/escrownet.cairo @@ -13,7 +13,7 @@ pub mod Escrownet { #[event] #[derive(Drop, starknet::Event)] enum Event { - EscrowFactoryEvent: EscrowFactory::Event + EscrowFactoryEvent: EscrowFactory::Event, } #[storage] diff --git a/src/interface.cairo b/src/interface.cairo index 1f03bf5..ee2be8a 100644 --- a/src/interface.cairo +++ b/src/interface.cairo @@ -1,2 +1,3 @@ pub mod iescrow; pub mod ierc20; +pub mod IEscrowFactory; diff --git a/src/interface/iescrow.cairo b/src/interface/iescrow.cairo index dfca26a..ced524a 100644 --- a/src/interface/iescrow.cairo +++ b/src/interface/iescrow.cairo @@ -10,11 +10,9 @@ pub trait IEscrow { provider_address: ContractAddress, amount: u256, ); - fn add_milestone( - ref self: TContractState, description: ByteArray, amount: u256, dueDate: u256, - ); + fn add_milestone(ref self: TContractState, description: ByteArray, amount: u256, dueDate: u256); fn request_milestone_payment( - ref self: TContractState, id: u64, token_address: ContractAddress + ref self: TContractState, id: u64, token_address: ContractAddress, ) -> bool; fn get_escrow_details(ref self: TContractState, escrow_id: u64) -> Escrow; fn get_depositor(self: @TContractState) -> ContractAddress; diff --git a/src/interface/iescrowfactory.cairo b/src/interface/iescrowfactory.cairo new file mode 100644 index 0000000..9837d55 --- /dev/null +++ b/src/interface/iescrowfactory.cairo @@ -0,0 +1,17 @@ +use starknet::ContractAddress; + +#[starknet::interface] +pub trait IEscrowFactory { + fn deploy_escrow( + ref self: TContractState, + beneficiary: ContractAddress, + depositor: ContractAddress, + arbiter: ContractAddress, + salt: felt252, + milestone_description: ByteArray, + milestone_amount: u256, + milestone_dueDate: u256, + ) -> ContractAddress; + + fn get_escrow_contracts(self: @TContractState) -> Array; +} From 7e1c1912964840da65f7bf4ef27b996da62b4349 Mon Sep 17 00:00:00 2001 From: morelucks Date: Fri, 28 Mar 2025 14:05:05 +0100 Subject: [PATCH 2/3] UPDATE: fix import and appending iescrowfactory to the interface.cario --- src/escrow/escrow_factory.cairo | 2 +- src/interface.cairo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/escrow/escrow_factory.cairo b/src/escrow/escrow_factory.cairo index 9883e55..c47c255 100644 --- a/src/escrow/escrow_factory.cairo +++ b/src/escrow/escrow_factory.cairo @@ -3,7 +3,7 @@ pub use starknet::{ ContractAddress, class_hash::ClassHash, syscalls::deploy_syscall, SyscallResultTrait, }; use escrownet_contract::interface::iescrow::{IEscrowDispatcher, IEscrowDispatcherTrait}; -use escrownet_contract::interface::iescrowfactory; +use escrownet_contract::interface::iescrowfactory::{IEscrowFactory}; #[starknet::component] pub mod EscrowFactory { diff --git a/src/interface.cairo b/src/interface.cairo index ee2be8a..f4bb609 100644 --- a/src/interface.cairo +++ b/src/interface.cairo @@ -1,3 +1,3 @@ pub mod iescrow; pub mod ierc20; -pub mod IEscrowFactory; +pub mod iescrowfactory; From d1ef42f9151ec52fee2a3d504f18f0624ff1aa66 Mon Sep 17 00:00:00 2001 From: morelucks Date: Fri, 28 Mar 2025 14:12:17 +0100 Subject: [PATCH 3/3] fix: improve formatting in EscrowFactory implementation --- src/escrow/escrow_factory.cairo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/escrow/escrow_factory.cairo b/src/escrow/escrow_factory.cairo index c47c255..5cad684 100644 --- a/src/escrow/escrow_factory.cairo +++ b/src/escrow/escrow_factory.cairo @@ -14,7 +14,7 @@ pub mod EscrowFactory { ContractAddress, class_hash::ClassHash, syscalls::deploy_syscall, SyscallResultTrait, storage::{Map}, }; - + use core::traits::{TryInto, Into}; const ESCROW_CONTRACT_CLASS_HASH: felt252 = @@ -29,7 +29,7 @@ pub mod EscrowFactory { #[embeddable_as(Escrows)] impl EscrowFactoryImpl< TContractState, +HasComponent, - > of IEscrowFactory> { + > of IEscrowFactory> { fn deploy_escrow( ref self: ComponentState, beneficiary: ContractAddress,