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
185 changes: 170 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,177 @@
# Cairo Bootcamp 6.0
# StarkNet Restricted ERC-20 Token

Welcome to **Cairo Bootcamp 6** — a hands-on, developer-focused program designed to help you learn Cairo from first principles and build real-world applications. This repository contains learning materials, examples, and exercises used throughout the bootcamp.
A secure ERC-20 token implementation on StarkNet with administrative controls, transfer restrictions, and burn functionality.

---
* **File-path:** `yahia008/blockheader_test`
* **File-path:** `yahia008/assignment_1`
* **File-path:** `yahia008/assignment_2`
* **File-path:** `yahia008/av2_pro`

## Overview

## About the Bootcamp
This contract extends standard ERC-20 behavior with admin-managed safeguards. It is designed for cases where token movement must follow configurable rules, while still supporting the usual transfer and allowance flows.

This Cairo Bootcamp is designed to:
- Introduce developers to Cairo
- Teach provable computation fundamentals**
- Explore Starknet and smart contract development
- Encourage hands-on building and experimentation
## Features

### Core ERC-20 Functionality

---
- Standard token operations: `transfer`, `approve`, and `transfer_from`
- Balance tracking and allowance management
- Token metadata: `name`, `symbol`, `decimals`, and `total_supply`

## 📁 Repository Structure
.
├── cairo_programs/ # Pure Cairo programs (stateless logic)
├── starknet_contracts/ # Smart contracts (stateful logic)
└── README.md
### Admin Controls

- Transfer limit management: the admin can update the maximum transfer amount
- Global transfer toggle: the admin can disable or re-enable all transfers
- Burn mechanism: the admin can burn tokens from any address
- Spender revocation: the admin can revoke specific spenders from using allowances

### Security Features

- Maximum transfer limit enforcement
- Zero-address validation
- Insufficient balance checks
- Allowance validation
- Revoked spender tracking
- Admin-only privileged functions

## Contract Architecture

### Interfaces

#### `IERC20`

Standard ERC-20 interface with the required functions:

- `get_name()`
- `get_symbol()`
- `get_decimals()`
- `get_total_supply()`
- `balance_of()`
- `allowance()`
- `transfer()`
- `transfer_from()`
- `approve()`
- `increase_allowance()`
- `decrease_allowance()`

#### `IAdminRestricted`

Admin-specific functions:

- `set_transfer_limit()` - Updates the maximum transfer amount
- `burn()` - Burns tokens from any account
- `revoke_transfers()` - Disables all transfers
- `enable_transfers()` - Re-enables transfers
- `admin_revoke_spender()` - Revokes a specific spender

### Storage Variables

```rust
name: felt252
symbol: felt252
decimals: u8
total_supply: u256
balances: Map<ContractAddress, u256>
allowances: Map<(ContractAddress, ContractAddress), u256>
revoked_user: Map<ContractAddress, bool>
admin: ContractAddress
transfer_limit: u256
transfers_enabled: bool
```

### Events

- `Transfer` - Emitted on token transfers
- `Approval` - Emitted on allowance changes
- `TransferLimitUpdated` - Emitted when the admin updates the transfer limit
- `TransfersRevoked` / `TransfersEnabled` - Emitted when global transfer status changes
- `Burn` - Emitted when tokens are burned

## Deployment

### Constructor Parameters

```rust
fn constructor(
recipient: ContractAddress,
name: felt252,
decimals: u8,
initial_supply: u256,
symbol: felt252,
admin: ContractAddress
)
```

Parameter summary:

- `recipient` - Initial token recipient
- `name` - Token name
- `decimals` - Token decimals
- `initial_supply` - Initial amount to mint
- `symbol` - Token symbol
- `admin` - Admin address

### Example Deployment

```cairo
let token = erc20::constructor(
recipient: 0x123...,
name: 'Restricted Token',
decimals: 18,
initial_supply: 1000000_u256,
symbol: 'RST',
admin: 0x456...
);
```

## Usage Examples

### Transfer Validation

The following transfer will fail if:

- The amount exceeds `transfer_limit`
- The sender has insufficient balance
- Global transfers are disabled
- A zero address is used

```cairo
token.transfer(recipient, 5000_u256); // Works
token.transfer(recipient, 15000_u256); // Fails: exceeds limit
```

### Admin Operations

```cairo
// Update transfer limit
token.set_transfer_limit(20000_u256);

// Burn tokens from any address
token.burn(account_address, 1000_u256);

// Emergency stop all transfers
token.revoke_transfers();
token.transfer(recipient, 1000_u256); // Fails: transfers disabled

// Re-enable transfers
token.enable_transfers();

// Revoke a specific spender
token.admin_revoke_spender(owner, spender);
```

## Error Codes

| Error | Description |
| --- | --- |
| `ERC20: not admin` | Caller is not the contract admin |
| `ERC20: transfers disabled` | Global transfers are currently disabled |
| `ERC20: exceeds max limit` | Transfer amount exceeds the current limit |
| `ERC20: insufficient balance` | Sender has insufficient tokens |
| `ERC20: insufficient allowance` | Insufficient allowance for `transfer_from` |
| `ERC20: spender revoked` | Spender has been revoked by the admin |
| `ERC20: limit must be >0` | Transfer limit must be positive |
| `ERC20: zero address` | Zero address is not allowed for the operation |
| `ERC20: approve to 0` | Cannot approve the zero address |
| `ERC20: burn amount >0` | Burn amount must be positive |
1 change: 1 addition & 0 deletions starknet-agentic
Submodule starknet-agentic added at 79d018
48 changes: 48 additions & 0 deletions starknet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# StarkNet MCP Transfer Agent

An autonomous multi-step agent workflow built on StarkNet-agentic for intelligent, condition-based token transfers with monitoring and alerting.

## Objective

Build a composable autonomous transfer agent using an MCP (Model Context Protocol) server architecture that can:

- Fetch wallet balances
- Validate transfer conditions
- Execute conditional transfers
- Chain multiple agent calls
- Log execution results
- Trigger alerts on low balance

## Architecture

The workflow follows this sequence:

1. Fetch balance
2. Validate transfer conditions
3. Execute transfer
4. Call another agent if needed
5. Log the result
6. Trigger an alert when balances are low

## Components

### MCP Server Structure

```typescript
const server = new McpServer({
name: "starknet-transfer-agent",
version: "1.0.0"
});
```

### Available Tools

| Tool | Description | Parameters |
| --- | --- | --- |
| `fetch_balance` | Get wallet balance | `wallet_address` |
| `validate_transfer` | Check transfer conditions | `amount`, `balance`, `threshold` |
| `execute_transfer` | Perform token transfer | `to`, `amount`, `token_address` |
| `call_agent` | Invoke another agent | `agent_name`, `params` |
| `log_result` | Record execution results | `status`, `details`, `timestamp` |
| `check_threshold` | Monitor balance threshold | `balance`, `threshold` |
| `trigger_alert` | Send a low-balance notification | `wallet`, `current_balance` |
1 change: 1 addition & 0 deletions yahia008/assignment_1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
6 changes: 6 additions & 0 deletions yahia008/assignment_1/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "assignment_1"
version = "0.1.0"
14 changes: 14 additions & 0 deletions yahia008/assignment_1/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "assignment_1"
version = "0.1.0"
edition = "2025_12"

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

[executable]

[cairo]
enable-gas = false

[dependencies]
cairo_execute = "2.17.0"
74 changes: 74 additions & 0 deletions yahia008/assignment_1/src/assignment1.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use core::num::traits::CheckedMul;
use core::num::traits::CheckedAdd;
use core::num::traits::CheckedSub;

#[derive(Drop)]
enum MathError {
Overflow,
DivisionByZero,
Underflow,
}


#[executable]
fn main() {
let add_result = add_number(0, 0);
match add_result {
Result::Ok(v) => {
assert!(v==0, "assertion failed")
println!("add value {}", v)
},
Result::Err(_) => println!("add error ", ),
};

let mul_result = multiply_number(10, 5);
match mul_result {
Result::Ok(v) => {
assert!(v==50, "assertion failed")
println!("mul value {}", v)
},
Result::Err(_) => println!("mul error"),
};


let div_result = divide(10, 2);
match div_result {
Result::Ok(v) => {
assert!(v==5, "assertion failed")
println!("div value {}", v)
},
Result::Err(_) => println!("div error", ),
};

let sub_result = sub_num(10, 7);
match sub_result {
Result::Ok(v) => {
assert!(v==3, "assertion failed")
println!("sub value {}", v)
},
Result::Err(_) => println!("sub error"),
};
}



fn add_number(x: u128, y: u128) -> Result<u128, MathError> {
x.checked_add(y).ok_or(MathError::Overflow)
}

fn multiply_number(x:u128, y:u128) -> Result<u128, MathError> {
x.checked_mul(y).ok_or(MathError::Overflow)
}

fn divide(x: u128, y: u128) -> Result<u128, MathError>{
if y == 0 {
return Result::Err(MathError::DivisionByZero);
}

Result::Ok(x / y)
}

fn sub_num(x:u128, y:u128) -> Result<u128, MathError>{
x.checked_sub(y).ok_or(MathError::Underflow)
}

1 change: 1 addition & 0 deletions yahia008/assignment_1/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod assignment1;
5 changes: 5 additions & 0 deletions yahia008/assignment_2/.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 yahia008/assignment_2/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 = "assignment_2"
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",
]
Loading