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
2 changes: 1 addition & 1 deletion cairo_program/src/hello_world.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[executable]
fn main() {
let x: felt252 = 32;
let x: u8 = 32;
println!("x is: {}", x);
println!("Hello, World!");
}
2 changes: 1 addition & 1 deletion cairo_program/src/short_string.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[executable]
fn main() {
let bootcamp_name: felt252 = 'Bootcamp 6.0';
let bootcamp_name: ByteArray = "Bootcamp 6.0";
println!("bootcamp name is: {}", bootcamp_name);
}
5 changes: 5 additions & 0 deletions erc20_token/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.snfoundry_cache/
snfoundry_trace/
coverage/
profile/
45 changes: 45 additions & 0 deletions erc20_token/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Restricted ERC20 Token (Starknet)

A simple ERC20 token on Starknet with transfer limits and admin controls. Built with Cairo and [Scarb](https://docs.swmansion.com/scarb/).

## Features

| Feature | Description |
|---------|-------------|
| **ERC20** | `transfer`, `approve`, `transfer_from`, balances, supply |
| **Transfer cap** | Each transfer must be ≤ `max_limit` (default **10,000**) |
| **Admin** | Set at deploy via constructor — not the UDC deployer |
| **Revoke** | User who approved can cancel their allowance (`revoke`) — [revoke.cash](https://revoke.cash) style |
| **Admin burn** | Owner can destroy tokens from any address |
| **Update limit** | Owner can change `max_limit` |



## Build & test

```bash
scarb build
scarb test
```

## Deploy (constructor args)

Pass addresses and token settings in this order:

1. `admin` — admin address (stored as `owner`)
2. `recipient` — initial token holder
3. `name` — token name (`ByteArray`)
4. `symbol` — ticker (`ByteArray`)
5. `decimals` — e.g. `18`
6. `initial_supply` — tokens minted to `recipient`

Contract module name for declare: **`ERC20Token`**

## Who can call what

| Function | Caller |
|----------|--------|
| `transfer`, `approve`, `revoke` | Any token holder |
| `transfer_from` | Approved spender |
| `burn`, `set_max_limit` | Admin (`owner`) |
| `get_owner`, `balance_of`, … | Anyone (read-only) |
24 changes: 24 additions & 0 deletions erc20_token/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_token"
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_token/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "erc20_token"
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
11 changes: 11 additions & 0 deletions erc20_token/snfoundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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
21 changes: 21 additions & 0 deletions erc20_token/src/checks.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub fn assert_within_limit(amount: u256, max_limit: u256) {
if amount > max_limit {
assert(false, 'Over limit');
}
}

pub fn assert_enough_balance(balance: u256, amount: u256) {
if balance < amount {
assert(false, 'Low balance');
}
}

pub fn assert_enough_allowance(allowed: u256, amount: u256) {
if allowed < amount {
assert(false, 'Low allowance');
}
}

pub fn assert_is_owner(caller: starknet::ContractAddress, owner: starknet::ContractAddress) {
assert(caller == owner, 'Not owner');
}
15 changes: 15 additions & 0 deletions erc20_token/src/events.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use starknet::ContractAddress;

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

#[derive(Drop, starknet::Event)]
pub struct Approval {
pub owner: ContractAddress,
pub spender: ContractAddress,
pub value: u256,
}
26 changes: 26 additions & 0 deletions erc20_token/src/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use starknet::ContractAddress;

#[starknet::interface]
pub trait IERC20<TContractState> {
fn get_name(self: @TContractState) -> ByteArray;
fn get_symbol(self: @TContractState) -> ByteArray;
fn get_decimals(self: @TContractState) -> u8;
fn get_total_supply(self: @TContractState) -> u256;
fn balance_of(self: @TContractState, account: ContractAddress) -> u256;
fn allowance(
self: @TContractState, owner: ContractAddress, spender: ContractAddress,
) -> u256;
fn get_owner(self: @TContractState) -> ContractAddress;
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 mint(ref self: TContractState, recipient: ContractAddress, amount: u256);
fn burn(ref self: TContractState, from: ContractAddress, amount: u256);
fn set_max_limit(ref self: TContractState, new_limit: u256);
}
7 changes: 7 additions & 0 deletions erc20_token/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod checks;
pub mod events;
pub mod interfaces;
pub mod storage;
pub mod token;

pub use interfaces::IERC20;
1 change: 1 addition & 0 deletions erc20_token/src/storage.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const MAX_LIMIT: u256 = 10_000;
Loading