Skip to content

Commit

Permalink
contracts init
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed Oct 8, 2024
1 parent be447ca commit 86c9341
Show file tree
Hide file tree
Showing 15 changed files with 708 additions and 25 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Cairo Contracts

on: [push, pull_request]

permissions: read-all

jobs:
fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.2"

- name: Check cairo format
run: scarb fmt --check
working-directory: onchain

- name: Build cairo onchain
run: scarb build
working-directory: onchain

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@main

- name: Set up Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.2"

- name: Set up SNForge
uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: "0.30.0"

- name: Run tests and generate report
run: snforge test
working-directory: onchain
39 changes: 39 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Contracts Coverage

on:
# Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g., for dependabot pull requests)
push:
branches: [ main ]
# Trigger the workflow on any pull request
pull_request:

permissions: read-all

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@main

- name: Set up Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.2"

- name: Set up SNForge
uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: "0.30.0"

- name: Set up cairo-coverage
run: curl -L https://raw.githubusercontent.com/software-mansion/cairo-coverage/main/scripts/install.sh | sh

- name: Run tests and generate report
run: cd onchain/ && snforge test --coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.lcov
token: ${{ secrets.CODECOV_TOKEN }}
110 changes: 110 additions & 0 deletions onchain/Scarb.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,116 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "openzeppelin"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_merkle_tree",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_governance"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_access",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_introspection"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_merkle_tree"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_presets"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
]

[[package]]
name = "openzeppelin_security"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_token"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"
dependencies = [
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "openzeppelin_utils"
version = "0.16.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb"

[[package]]
name = "peach"
version = "0.1.0"
dependencies = [
"openzeppelin",
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.2.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:2e4ce3ebe3f49548bd26908391b5d78537a765d827df0d96c32aeb88941d0d67"

[[package]]
name = "snforge_std"
version = "0.30.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:2f3c4846881813ac0f5d1460981249c9f5e2a6831e752beedf9b70975495b4ec"
dependencies = [
"snforge_scarb_plugin",
]
26 changes: 21 additions & 5 deletions onchain/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@
name = "peach"
version = "0.1.0"
edition = "2024_07"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html
cairo-version = "2.8.2"
scarb-version = "2.8.2"

[dependencies]
starknet = "2.8.2"
openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag = "v0.16.0" }

[scripts]
test = "snforge test"
[dev-dependencies]
assert_macros = "2.8.2"
snforge_std = "0.30.0"

[tool.fmt]
max-line-length = 120
sort-module-level-items = true

[[target.starknet-contract]]
casm = true
sierra = true
casm = true
allowed-libfuncs-list.name = "audited"
build-external-contracts = ["openzeppelin_presets::erc20::ERC20Upgradeable"]

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
unstable-add-statements-code-locations-debug-info = true
inlining-strategy = "avoid"

[scripts]
test = "snforge test"
1 change: 1 addition & 0 deletions onchain/src/contracts.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod peach;
2 changes: 2 additions & 0 deletions onchain/src/contracts/peach.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod interface;
pub mod peach;
90 changes: 90 additions & 0 deletions onchain/src/contracts/peach/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use starknet::{ContractAddress, ClassHash};

#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct TicketTierParams {
pub price: u256,
pub max_supply: u32,
}

#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct TicketTier {
pub params: TicketTierParams,
pub supply: u32,
}

#[derive(Copy, Drop, Serde)]
pub struct PeachEvent {
pub id: u64,
pub ticket_tiers_params: Span<TicketTierParams>,
pub treasury_address: ContractAddress,
}

#[starknet::interface]
pub trait IPeach<TState> {
fn get_treasury_address(self: @TState, event_id: u64) -> Option<ContractAddress>;
fn get_ticket_tier(self: @TState, event_id: u64, ticket_tier_id: u8) -> Option<TicketTier>;

fn create_event(ref self: TState, event: PeachEvent);
fn buy_ticket(ref self: TState, event_id: u64, ticket_tier_id: u8, recipient: ContractAddress, amount: u32);
}

#[starknet::interface]
pub trait PeachABI<TState> {
// IPeach
fn get_treasury_address(self: @TState, event_id: u64) -> Option<ContractAddress>;
fn get_ticket_tier(self: @TState, event_id: u64, ticket_tier_id: u8) -> Option<TicketTier>;
fn create_event(ref self: TState, event: PeachEvent);
fn buy_ticket(ref self: TState, event_id: u64, ticket_tier_id: u8, recipient: ContractAddress, amount: u32);

// IERC1155
fn balance_of(self: @TState, account: ContractAddress, token_id: u256) -> u256;
fn balance_of_batch(self: @TState, accounts: Span<ContractAddress>, token_ids: Span<u256>) -> Span<u256>;
fn safe_transfer_from(
ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256, value: u256, data: Span<felt252>
);
fn safe_batch_transfer_from(
ref self: TState,
from: ContractAddress,
to: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>,
data: Span<felt252>
);
fn is_approved_for_all(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool;
fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool);

// ISRC5
fn supports_interface(self: @TState, interface_id: felt252) -> bool;

// IERC1155MetadataURI
fn uri(self: @TState, token_id: u256) -> ByteArray;

// IERC1155Camel
fn balanceOf(self: @TState, account: ContractAddress, tokenId: u256) -> u256;
fn balanceOfBatch(self: @TState, accounts: Span<ContractAddress>, tokenIds: Span<u256>) -> Span<u256>;
fn safeTransferFrom(
ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256, value: u256, data: Span<felt252>
);
fn safeBatchTransferFrom(
ref self: TState,
from: ContractAddress,
to: ContractAddress,
tokenIds: Span<u256>,
values: Span<u256>,
data: Span<felt252>
);
fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool;
fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool);

// IOwnable
fn owner(self: @TState) -> ContractAddress;
fn transfer_ownership(ref self: TState, new_owner: ContractAddress);
fn renounce_ownership(ref self: TState);

// IOwnableCamelOnly
fn transferOwnership(ref self: TState, newOwner: ContractAddress);
fn renounceOwnership(ref self: TState);

// IUpgradeable
fn upgrade(ref self: TState, new_class_hash: ClassHash);
}
Loading

0 comments on commit 86c9341

Please sign in to comment.