Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions cairo_program/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ edition = "2025_12"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[lib]

[executable]

[cairo]
enable-gas = false

[dependencies]
cairo_execute = "2.18.0"


41 changes: 35 additions & 6 deletions cairo_program/src/integer.cairo
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
#[executable]
fn main() {
let result: u8 = add_num(5, 6);
let result: u32 = add_num(5, 6);
println!("the sum of x & y is: {}", result);
assert(result == 11, 'invalid sum logic');
assert!(result == 11, "invalid add logic");

let sub_result: u8 = sub_num(10, 5);
let sub_result: u32 = sub_num(3, 5);
println!("sub result is: {}", sub_result);
assert(sub_result == 5, 'invalid sub logic');
assert!(sub_result == 5, "invalid sub logic");

let mul_result: u8 = mul_num(5, 6);
println!("mul result is: {}", mul_result);
assert!(mul_result == 30, "invalid mul logic");

let div_result: u8 = div_num(10, 5);
println!("div result is: {}", div_result);
assert!(div_result == 2, "invalid div logic");
}

// addition logic
fn add_num(x: u8, y: u8) -> u8 {
pub fn add_num(x: u32, y: u32) -> u32 {
x + y
}

// subtraction logic
fn sub_num(x: u8, y: u8) -> u8 {
pub fn sub_num(x: u32, y: u32) -> u32 {
assert!(x >= y, "y should be less than or equal to x");
return x - y;
}

// multiplication logic
pub fn mul_num(x: u8, y: u8) -> u8 {
if (x == 0 || y == 0) {
assert!(y != 0 && x != 0, "x or y should not be zero");
}
x * y
}

// division logic
pub fn div_num(x: u8, y: u8) -> u8 {
if y == 0 || x == 0 {
assert!(y != 0 && x != 0, "x or y should not be zero");
}

if (y > x) {
assert!(y <= x, "y should be less than or equal to x");
}
x / y
}
6 changes: 4 additions & 2 deletions cairo_program/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// mod hello_world;
// mod short_string;
// mod integer;
pub mod integer;
// mod bool;
mod bytearray;
// mod bytearray;


5 changes: 5 additions & 0 deletions erc20/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.snfoundry_cache/
snfoundry_trace/
coverage/
profile/
24 changes: 24 additions & 0 deletions erc20/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "erc20"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.59.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:871fba677c03b66a1bf40815dac0ab1b385eb1b9be6e6c3cf2ad9788eeb2b6bb"

[[package]]
name = "snforge_std"
version = "0.59.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:3620924fa08bd2d740b2b5b01ef86c8dab3d4b9c2206387c8dbdc8d2ec15133e"
dependencies = [
"snforge_scarb_plugin",
]
52 changes: 52 additions & 0 deletions erc20/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "erc20"
version = "0.1.0"
edition = "2024_07"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.17.0"

[dev-dependencies]
snforge_std = "0.59.0"
assert_macros = "2.17.0"

[[target.starknet-contract]]
sierra = true

[scripts]
test = "snforge test"

[tool.scarb]
allow-prebuilt-plugins = ["snforge_std"]

# Visit https://foundry-rs.github.io/starknet-foundry/appendix/scarb-toml.html for more information

# [tool.snforge] # Define `snforge` tool section
# exit_first = true # Stop tests execution immediately upon the first failure
# fuzzer_runs = 1234 # Number of runs of the random fuzzer
# fuzzer_seed = 1111 # Seed for the random fuzzer

# [[tool.snforge.fork]] # Used for fork testing
# name = "SOME_NAME" # Fork name
# url = "http://your.rpc.url" # Url of the RPC provider
# block_id.tag = "latest" # Block to fork from (block tag)

# [[tool.snforge.fork]]
# name = "SOME_SECOND_NAME"
# url = "http://your.second.rpc.url"
# block_id.number = "123" # Block to fork from (block number)

# [[tool.snforge.fork]]
# name = "SOME_THIRD_NAME"
# url = "http://your.third.rpc.url"
# block_id.hash = "0x123" # Block to fork from (block hash)

# [profile.dev.cairo] # Configure Cairo compiler
# unstable-add-statements-code-locations-debug-info = true # Should be used if you want to use coverage
# unstable-add-statements-functions-debug-info = true # Should be used if you want to use coverage/profiler
# inlining-strategy = "avoid" # Should be used if you want to use coverage

# [features] # Used for conditional compilation
# enable_for_tests = [] # Feature name and list of other features that should be enabled with it
13 changes: 13 additions & 0 deletions erc20/snfoundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[sncast.default]
account = "erc-account"
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html
# and https://foundry-rs.github.io/starknet-foundry/projects/configuration.html for more information

# [sncast.default] # Define a profile name
# url = "https://api.zan.top/public/starknet-sepolia/rpc/v0_10" # Url of the RPC provider
# accounts-file = "../account-file" # Path to the file with the account data
# account = "mainuser" # Account from `accounts_file` or default account file that will be used for the transactions
# keystore = "~/keystore" # Path to the keystore file
# wait-params = { timeout = 300, retry-interval = 10 } # Wait for submitted transaction parameters
# block-explorer = "Voyager" # Block explorer service used to display links to transaction details
# show-explorer-links = true # Print links pointing to pages with transaction details in the chosen block explorer
22 changes: 22 additions & 0 deletions erc20/src/event.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use starknet::ContractAddress;

#[derive(Copy, Drop, Debug, PartialEq, starknet::Event)]
pub struct Transfer {
pub from: ContractAddress,
pub to: ContractAddress,
pub value: u256,
}

#[derive(Copy, Drop, Debug, PartialEq, starknet::Event)]
pub struct Approval {
pub owner: ContractAddress,
pub spender: ContractAddress,
pub value: u256,
}

#[derive(Copy, Drop, Debug, PartialEq, starknet::Event)]
pub struct Revoke {
pub owner: ContractAddress,
pub spender: ContractAddress,
pub value: u256,
}
22 changes: 22 additions & 0 deletions erc20/src/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use starknet::ContractAddress;

#[starknet::interface]
pub trait IERC20<TContractState> {
fn name(self: @TContractState) -> felt252;
fn symbol(self: @TContractState) -> felt252;
fn decimals(self: @TContractState) -> u8;
fn total_supply(self: @TContractState) -> u256;
fn balance_of(self: @TContractState, account: ContractAddress) -> u256;
fn allowance(self: @TContractState, owner: ContractAddress, spender: ContractAddress) -> u256;
fn transfer(ref self: TContractState, recipient: ContractAddress, amount: u256);
fn transfer_from(
ref self: TContractState, sender: ContractAddress, recipient: ContractAddress, amount: u256,
);
fn approve(ref self: TContractState, spender: ContractAddress, amount: u256);
fn revoke(ref self: TContractState, spender: ContractAddress);
fn increase_allowance(ref self: TContractState, spender: ContractAddress, added_value: u256);
fn decrease_allowance(
ref self: TContractState, spender: ContractAddress, subtracted_value: u256,
);
fn burn(ref self: TContractState, amount: u256);
}
Loading