From 4c7cb7de7c4bc6f9d2eea1958f05f84761193915 Mon Sep 17 00:00:00 2001 From: Nenad Date: Mon, 10 Jun 2024 18:25:51 +0200 Subject: [PATCH] add scaffold docs for contracts --- .../advanced_factory/src/campaign.cairo | 3 +++ .../advanced_factory/src/factory.cairo | 7 +++---- .../advanced_factory/src/tests/factory.cairo | 18 +++++++++--------- src/SUMMARY.md | 3 +++ src/applications/crowdfunding/campaign.md | 7 +++++++ src/applications/crowdfunding/crowdfunding.md | 1 + src/applications/crowdfunding/factory.md | 7 +++++++ 7 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 src/applications/crowdfunding/campaign.md create mode 100644 src/applications/crowdfunding/crowdfunding.md create mode 100644 src/applications/crowdfunding/factory.md diff --git a/listings/applications/advanced_factory/src/campaign.cairo b/listings/applications/advanced_factory/src/campaign.cairo index 91be1788..e77dcd0d 100644 --- a/listings/applications/advanced_factory/src/campaign.cairo +++ b/listings/applications/advanced_factory/src/campaign.cairo @@ -1,3 +1,4 @@ +// ANCHOR: contract use starknet::ClassHash; #[starknet::interface] @@ -175,3 +176,5 @@ pub mod Campaign { } } } +// ANCHOR_END: contract + diff --git a/listings/applications/advanced_factory/src/factory.cairo b/listings/applications/advanced_factory/src/factory.cairo index 2af7ea77..088d871f 100644 --- a/listings/applications/advanced_factory/src/factory.cairo +++ b/listings/applications/advanced_factory/src/factory.cairo @@ -2,7 +2,7 @@ pub use starknet::{ContractAddress, ClassHash}; #[starknet::interface] -pub trait ICrowdfundingFactory { +pub trait ICampaignFactory { fn create_campaign( ref self: TContractState, title: ByteArray, @@ -15,7 +15,7 @@ pub trait ICrowdfundingFactory { } #[starknet::contract] -pub mod CrowdfundingFactory { +pub mod CampaignFactory { use core::num::traits::zero::Zero; use starknet::{ ContractAddress, ClassHash, SyscallResultTrait, syscalls::deploy_syscall, @@ -74,7 +74,7 @@ pub mod CrowdfundingFactory { #[abi(embed_v0)] - impl CrowdfundingFactory of super::ICrowdfundingFactory { + impl CampaignFactory of super::ICampaignFactory { // ANCHOR: deploy fn create_campaign( ref self: ContractState, @@ -133,4 +133,3 @@ pub mod CrowdfundingFactory { } // ANCHOR_END: contract - diff --git a/listings/applications/advanced_factory/src/tests/factory.cairo b/listings/applications/advanced_factory/src/tests/factory.cairo index ee00d2a7..d1297416 100644 --- a/listings/applications/advanced_factory/src/tests/factory.cairo +++ b/listings/applications/advanced_factory/src/tests/factory.cairo @@ -2,7 +2,7 @@ use core::traits::TryInto; use core::clone::Clone; use core::result::ResultTrait; use advanced_factory::factory::{ - CrowdfundingFactory, ICrowdfundingFactoryDispatcher, ICrowdfundingFactoryDispatcherTrait + CampaignFactory, ICampaignFactoryDispatcher, ICampaignFactoryDispatcherTrait }; use starknet::{ ContractAddress, ClassHash, get_block_timestamp, contract_address_const, get_caller_address @@ -18,21 +18,21 @@ use components::ownable::{IOwnableDispatcher, IOwnableDispatcherTrait}; /// Deploy a campaign factory contract with the provided campaign class hash -fn deploy_factory_with(campaign_class_hash: ClassHash) -> ICrowdfundingFactoryDispatcher { +fn deploy_factory_with(campaign_class_hash: ClassHash) -> ICampaignFactoryDispatcher { let mut constructor_calldata: @Array:: = @array![campaign_class_hash.into()]; - let contract = declare("CrowdfundingFactory").unwrap(); + let contract = declare("CampaignFactory").unwrap(); let contract_address = contract.precalculate_address(constructor_calldata); let factory_owner: ContractAddress = contract_address_const::<'factory_owner'>(); start_cheat_caller_address(contract_address, factory_owner); contract.deploy(constructor_calldata).unwrap(); - ICrowdfundingFactoryDispatcher { contract_address } + ICampaignFactoryDispatcher { contract_address } } /// Deploy a campaign factory contract with default campaign class hash -fn deploy_factory() -> ICrowdfundingFactoryDispatcher { +fn deploy_factory() -> ICampaignFactoryDispatcher { let campaign_class_hash = declare("Campaign").unwrap().class_hash; deploy_factory_with(campaign_class_hash) } @@ -80,8 +80,8 @@ fn test_deploy_campaign() { @array![ ( factory.contract_address, - CrowdfundingFactory::Event::CampaignCreated( - CrowdfundingFactory::CampaignCreated { + CampaignFactory::Event::CampaignCreated( + CampaignFactory::CampaignCreated { caller: campaign_owner, contract_address: campaign_address } ) @@ -117,8 +117,8 @@ fn test_update_campaign_class_hash() { @array![ ( factory.contract_address, - CrowdfundingFactory::Event::ClassHashUpdated( - CrowdfundingFactory::ClassHashUpdated { new_class_hash } + CampaignFactory::Event::ClassHashUpdated( + CampaignFactory::ClassHashUpdated { new_class_hash } ) ) ] diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 10436298..a0939c53 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -58,6 +58,9 @@ Summary - [Constant Product AMM](./applications/constant-product-amm.md) - [TimeLock](./applications/timelock.md) - [Staking](./applications/staking.md) +- [Crowdfunding](./applications/crowdfunding/crowdfunding.md) + - [Campaign Contract](./applications/crowdfunding/campaign.md) + - [CampaignFactory Contract](./applications/crowdfunding/factory.md) diff --git a/src/applications/crowdfunding/campaign.md b/src/applications/crowdfunding/campaign.md new file mode 100644 index 00000000..024e3a47 --- /dev/null +++ b/src/applications/crowdfunding/campaign.md @@ -0,0 +1,7 @@ +# Campaign Contract + +This is the Campaign contract. + +```rust +{{#include ../../../listings/applications/advanced_factory/src/campaign.cairo:contract}} +``` diff --git a/src/applications/crowdfunding/crowdfunding.md b/src/applications/crowdfunding/crowdfunding.md new file mode 100644 index 00000000..f7d424c0 --- /dev/null +++ b/src/applications/crowdfunding/crowdfunding.md @@ -0,0 +1 @@ +# Crowdfunding \ No newline at end of file diff --git a/src/applications/crowdfunding/factory.md b/src/applications/crowdfunding/factory.md new file mode 100644 index 00000000..60b052eb --- /dev/null +++ b/src/applications/crowdfunding/factory.md @@ -0,0 +1,7 @@ +# CampaignFactory Contract + +This is the CampaignFactory contract that creates new Campaign contract instances. + +```rust +{{#include ../../../listings/applications/advanced_factory/src/factory.cairo:contract}} +```