Skip to content
Merged
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
120 changes: 120 additions & 0 deletions cloakpay/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,129 @@ version = 1
name = "cloakpay"
version = "0.1.0"
dependencies = [
"openzeppelin",
"snforge_std",
]

[[package]]
name = "openzeppelin"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:320185f3e17cf9fafda88b1ce490f5eaed0bfcc273036b56cd22ce4fb8de628f"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_merkle_tree",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:a39a4ea1582916c637bf7e3aee0832c3fe1ea3a3e39191955e8dc39d08327f9b"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:7e943a2de32ddca4d48e467e52790e380ab1f49c4daddbbbc4634dd930d0243f"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_finance"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:9fa9e91d39b6ccdfa31eef32fdc087cd06c0269cc9c6b86e32d57f5a6997d98b"
dependencies = [
"openzeppelin_access",
"openzeppelin_token",
]

[[package]]
name = "openzeppelin_governance"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:c05add2974b3193c3a5c022b9586a84cf98c5970cdb884dcf201c77dbe359f55"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_introspection"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:34e088ecf19e0b3012481a29f1fbb20e600540cb9a5db1c3002a97ebb7f5a32a"

[[package]]
name = "openzeppelin_merkle_tree"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:a5341705514a3d9beeeb39cf11464111f7355be621639740d2c5006786aa63dc"

[[package]]
name = "openzeppelin_presets"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:4eb098e2ee3ac0e67b6828115a7de62f781418beab767d4e80b54e176808369d"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_security"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:1deb811a239c4f9cc28fc302039e2ffcb19911698a8c612487207448d70d2e6e"

[[package]]
name = "openzeppelin_token"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:33fcb84a1a76d2d3fff9302094ff564f78d45b743548fd7568c130b272473f66"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_upgrades"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:36f7a03e7e7111577916aacf31f88ad0053de20f33ee10b0ab3804849c3aa373"

[[package]]
name = "openzeppelin_utils"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:fd348b31c4a4407add33adc3c2b8f26dca71dbd7431faaf726168f37a91db0c1"

[[package]]
name = "snforge_scarb_plugin"
version = "0.40.0"
Expand Down
1 change: 1 addition & 0 deletions cloakpay/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2024_07"

[dependencies]
starknet = "2.11.2"
openzeppelin = "1.0.0"

[dev-dependencies]
snforge_std = "0.40.0"
Expand Down
10 changes: 9 additions & 1 deletion cloakpay/src/base/errors.cairo
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
pub mod Errors {}
pub mod CloakPayErrors {
pub const UNSUPPORTED_TOKEN: felt252 = 'UNSUPPORTED TOKEN';
pub const COMMITMENT_ALREADY_USED: felt252 = 'COMMITMENT ALREADY USED';
}

pub mod payment_errors {
pub const INSUFFICIENT_ALLOWANCE: felt252 = 'Insufficient token allowance';
pub const INSUFFICIENT_BALANCE: felt252 = 'Insufficient token balance';
}
12 changes: 11 additions & 1 deletion cloakpay/src/base/events.cairo
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
pub mod Events {}
use crate::base::types::DepositDetails;

pub mod Events {
use super::*;
#[derive(Drop, starknet::Event)]
pub struct DepositEvent {
#[key]
pub deposit_id: u256,
pub details: DepositDetails,
}
}
113 changes: 113 additions & 0 deletions cloakpay/src/base/token.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-License-Identifier: MIT

/// @title STRK.cairo
/// @notice This file defines the STARKTOKEN contract, which implements the ERC20 token standard.
/// @dev The contract uses OpenZeppelin components for access control and ERC20 functionality.

use starknet::ContractAddress;

#[starknet::interface]
pub trait IExternal<ContractState> {
/// @notice Mints new tokens to a specified recipient.
/// @param self The contract state.
/// @param recipient The address of the recipient who will receive the minted tokens.
/// @param amount The amount of tokens to mint.
fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256);
}

#[starknet::contract]
pub mod token {
use core::byte_array::ByteArray;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::token::erc20::interface::IERC20Metadata;
use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use starknet::ContractAddress;
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};

component!(path: ERC20Component, storage: erc20, event: ERC20Event);
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);

#[storage]
/// @notice Storage struct for the Predifi contract.
/// @dev Holds all pools, user stakes, odds, roles, and protocol parameters.
pub struct Storage {
#[substorage(v0)]
pub erc20: ERC20Component::Storage,
#[substorage(v0)]
pub ownable: OwnableComponent::Storage,
custom_decimals: u8,
token_name: ByteArray,
token_symbol: ByteArray,
}

#[event]
#[derive(Drop, starknet::Event)]
/// @notice Events emitted by the Predifi contract.
enum Event {
#[flat]
ERC20Event: ERC20Component::Event,
#[flat]
OwnableEvent: OwnableComponent::Event,
}

/// @notice Contract constructor. Initializes the ERC20 and Ownable components.
/// @param self The contract state.
/// @param recipient The address to receive the initial supply.
/// @param owner The address to be set as the contract owner.
/// @param decimals The number of decimals for the token.
#[constructor]
fn constructor(
ref self: ContractState, recipient: ContractAddress, owner: ContractAddress, decimals: u8,
) {
let name: ByteArray = "STRK";
let symbol: ByteArray = "STRK";
// Initialize the ERC20 component
self.erc20.initializer(name, symbol);
self.ownable.initializer(owner);
self.custom_decimals.write(decimals);
self.erc20.mint(recipient, 200_000_000_000_000_000_000_000);
}

#[abi(embed_v0)]
impl CustomERC20MetadataImpl of IERC20Metadata<ContractState> {
/// @notice Returns the name of the token.
/// @param self The contract state.
/// @return The name of the token.
fn name(self: @ContractState) -> ByteArray {
self.token_name.read()
}

/// @notice Returns the symbol of the token.
/// @param self The contract state.
/// @return The symbol of the token.
fn symbol(self: @ContractState) -> ByteArray {
self.token_symbol.read()
}

/// @notice Returns the number of decimals used to get its user representation.
/// @param self The contract state.
/// @return The number of decimals.
fn decimals(self: @ContractState) -> u8 {
self.custom_decimals.read() // Return custom value
}
}

// Keep existing implementations
#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl InternalImpl = ERC20Component::InternalImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

#[abi(embed_v0)]
impl ExternalImpl of super::IExternal<ContractState> {
/// @notice Mints new tokens to a specified recipient.
/// @param self The contract state.
/// @param recipient The address of the recipient who will receive the minted tokens.
/// @param amount The amount of tokens to mint.
fn mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
self.erc20.mint(recipient, amount);
}
}
}
16 changes: 14 additions & 2 deletions cloakpay/src/base/types.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/// Common types used across the contract.

use starknet::ContractAddress;
/// @notice enum of supported tokens
#[derive(Copy, Drop, Serde, PartialEq, starknet::Store, Debug)]
pub enum SupportedToken {
#[default]
STRK,
}

#[derive(Copy, Drop, Serde, PartialEq, starknet::Store, Debug)]
pub struct DepositDetails {
pub supported_token: ContractAddress,
pub amount: u256,
pub commitment: felt252,
pub time_sent: u64,
}
Loading
Loading