Skip to content

Commit

Permalink
add scaffold docs for contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenad committed Jun 10, 2024
1 parent fc7a99e commit 4c7cb7d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions listings/applications/advanced_factory/src/campaign.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ANCHOR: contract
use starknet::ClassHash;

#[starknet::interface]
Expand Down Expand Up @@ -175,3 +176,5 @@ pub mod Campaign {
}
}
}
// ANCHOR_END: contract

7 changes: 3 additions & 4 deletions listings/applications/advanced_factory/src/factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub use starknet::{ContractAddress, ClassHash};

#[starknet::interface]
pub trait ICrowdfundingFactory<TContractState> {
pub trait ICampaignFactory<TContractState> {
fn create_campaign(
ref self: TContractState,
title: ByteArray,
Expand All @@ -15,7 +15,7 @@ pub trait ICrowdfundingFactory<TContractState> {
}

#[starknet::contract]
pub mod CrowdfundingFactory {
pub mod CampaignFactory {
use core::num::traits::zero::Zero;
use starknet::{
ContractAddress, ClassHash, SyscallResultTrait, syscalls::deploy_syscall,
Expand Down Expand Up @@ -74,7 +74,7 @@ pub mod CrowdfundingFactory {


#[abi(embed_v0)]
impl CrowdfundingFactory of super::ICrowdfundingFactory<ContractState> {
impl CampaignFactory of super::ICampaignFactory<ContractState> {
// ANCHOR: deploy
fn create_campaign(
ref self: ContractState,
Expand Down Expand Up @@ -133,4 +133,3 @@ pub mod CrowdfundingFactory {
}
// ANCHOR_END: contract


18 changes: 9 additions & 9 deletions listings/applications/advanced_factory/src/tests/factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::<felt252> = @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)
}
Expand Down Expand Up @@ -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
}
)
Expand Down Expand Up @@ -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 }
)
)
]
Expand Down
3 changes: 3 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- advanced-concepts -->

Expand Down
7 changes: 7 additions & 0 deletions src/applications/crowdfunding/campaign.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Campaign Contract

This is the Campaign contract.

```rust
{{#include ../../../listings/applications/advanced_factory/src/campaign.cairo:contract}}
```
1 change: 1 addition & 0 deletions src/applications/crowdfunding/crowdfunding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Crowdfunding
7 changes: 7 additions & 0 deletions src/applications/crowdfunding/factory.md
Original file line number Diff line number Diff line change
@@ -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}}
```

0 comments on commit 4c7cb7d

Please sign in to comment.