Skip to content

Commit

Permalink
Merge pull request #121 from horuslabsio/feat/jolt
Browse files Browse the repository at this point in the history
Feat/jolt
  • Loading branch information
codeWhizperer authored Oct 4, 2024
2 parents 26c1a15 + 32daca0 commit 6d4ffab
Show file tree
Hide file tree
Showing 19 changed files with 1,562 additions and 57 deletions.
1 change: 0 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria.
[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.31.0" }


[sncast.default]
url= "https://starknet-sepolia.public.blastapi.io"

Expand Down
8 changes: 8 additions & 0 deletions src/base/constants/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ pub mod Errors {
pub const INVALID_PROFILE_ADDRESS: felt252 = 'Karst: invalid profile address!';
pub const SELF_FOLLOWING: felt252 = 'Karst: self follow is forbidden';
pub const ALREADY_REACTED: felt252 = 'Karst: already react to post!';
pub const SELF_TIPPING: felt252 = 'Karst: self-tip forbidden!';
pub const SELF_TRANSFER: felt252 = 'Karst: self-transfer forbidden!';
pub const SELF_REQUEST: felt252 = 'Karst: self-request forbidden!';
pub const INVALID_EXPIRATION_STAMP: felt252 = 'Karst: invalid expiration stamp';
pub const INSUFFICIENT_ALLOWANCE: felt252 = 'Karst: insufficient allowance!';
pub const AUTO_RENEW_DURATION_ENDED: felt252 = 'Karst: auto renew ended!';
pub const INVALID_JOLT: felt252 = 'Karst: invalid jolt!';
pub const INVALID_JOLT_RECIPIENT: felt252 = 'Karst: not request recipient!';
pub const TOKEN_DOES_NOT_EXIST: felt252 = 'Karst: token_id does not exist!';
}
111 changes: 91 additions & 20 deletions src/base/constants/types.cairo
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
// *************************************************************************
// TYPES
// *************************************************************************
use starknet::ContractAddress;

// /**
// * @notice A struct containing token follow-related data.
// *
// * @param followed_profile_address The ID of the profile being followed.
// * @param follower_profile_address The ID of the profile following.
// * @param followTimestamp The timestamp of the current follow, if a profile is using the token to
// follow.
// * @param block_status true if follower is blocked, false otherwise
// */
#[derive(Drop, Serde, starknet::Store)]
pub struct FollowData {
pub followed_profile_address: ContractAddress,
pub follower_profile_address: ContractAddress,
pub follow_timestamp: u64,
pub block_status: bool,
}

// *************************************************************************
// PROFILE
// *************************************************************************
// * @notice A struct containing profile data.
// * profile_address The profile ID of a karst profile
// * profile_owner The address that created the profile_address
Expand All @@ -36,6 +19,9 @@ pub struct Profile {
pub follow_nft: ContractAddress
}

// *************************************************************************
// PUBLICATION
// *************************************************************************
// /**
// * @notice A struct containing publication data.
// *
Expand Down Expand Up @@ -157,3 +143,88 @@ pub struct QuoteParams {
pub reference_pub_type: PublicationType
}

#[derive(Debug, Drop, Serde, starknet::Store, Clone)]
pub struct Upvote {
pub publication_id: u256,
pub transaction_executor: ContractAddress,
pub block_timestamp: u64,
}

#[derive(Debug, Drop, Serde, starknet::Store, Clone)]
pub struct Downvote {
pub publication_id: u256,
pub transaction_executor: ContractAddress,
pub block_timestamp: u64,
}

// *************************************************************************
// FOLLOW
// *************************************************************************
// /**
// * @notice A struct containing token follow-related data.
// *
// * @param followed_profile_address The ID of the profile being followed.
// * @param follower_profile_address The ID of the profile following.
// * @param followTimestamp The timestamp of the current follow, if a profile is using the token to
// follow.
// * @param block_status true if follower is blocked, false otherwise
// */
#[derive(Drop, Serde, starknet::Store)]
pub struct FollowData {
pub followed_profile_address: ContractAddress,
pub follower_profile_address: ContractAddress,
pub follow_timestamp: u64,
pub block_status: bool,
}

// *************************************************************************
// JOLT
// *************************************************************************
#[derive(Drop, Serde, starknet::Store)]
pub struct JoltData {
pub jolt_id: u256,
pub jolt_type: JoltType,
pub sender: ContractAddress,
pub recipient: ContractAddress,
pub memo: ByteArray,
pub amount: u256,
pub status: JoltStatus,
pub expiration_stamp: u64,
pub block_timestamp: u64,
pub erc20_contract_address: ContractAddress
}

#[derive(Drop, Serde)]
pub struct JoltParams {
pub jolt_type: JoltType,
pub recipient: ContractAddress,
pub memo: ByteArray,
pub amount: u256,
pub expiration_stamp: u64,
pub auto_renewal: (bool, u256),
pub erc20_contract_address: ContractAddress,
}

#[derive(Drop, Serde, starknet::Store)]
pub struct RenewalData {
pub renewal_duration: u256,
pub renewal_amount: u256,
pub erc20_contract_address: ContractAddress
}

#[derive(Drop, Serde, starknet::Store, PartialEq)]
pub enum JoltType {
Tip,
Transfer,
Subscription,
Request
}

#[derive(Drop, Serde, starknet::Store, PartialEq)]
pub enum JoltStatus {
PENDING,
SUCCESSFUL,
EXPIRED,
REJECTED,
FAILED
}
2 changes: 2 additions & 0 deletions src/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod IKarstNFT;
pub mod IERC721;
pub mod IERC20;
pub mod IRegistry;
pub mod IProfile;
pub mod IFollowNFT;
pub mod IPublication;
pub mod IHandle;
pub mod IHandleRegistry;
pub mod IHub;
pub mod IJolt;
pub mod ICollectNFT;
20 changes: 20 additions & 0 deletions src/interfaces/IERC20.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use starknet::ContractAddress;

// *************************************************************************
// IERC20
// *************************************************************************
#[starknet::interface]
pub trait IERC20<TState> {
fn total_supply(self: @TState) -> u256;
fn balance_of(self: @TState, account: ContractAddress) -> u256;
fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256;
fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool;
fn transfer_from(
ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256
) -> bool;
fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool;

fn name(self: @TState) -> ByteArray;
fn symbol(self: @TState) -> ByteArray;
fn decimals(self: @TState) -> u8;
}
18 changes: 18 additions & 0 deletions src/interfaces/IJolt.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use starknet::ContractAddress;
use karst::base::constants::types::{JoltParams, JoltData};

#[starknet::interface]
pub trait IJolt<TState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
fn jolt(ref self: TState, jolt_params: JoltParams) -> u256;
fn set_fee_address(ref self: TState, _fee_address: ContractAddress);
fn auto_renew(ref self: TState, profile: ContractAddress, renewal_id: u256) -> bool;
fn fulfill_request(ref self: TState, jolt_id: u256) -> bool;
// *************************************************************************
// GETTERS
// *************************************************************************
fn get_jolt(self: @TState, jolt_id: u256) -> JoltData;
fn get_fee_address(self: @TState) -> ContractAddress;
}
1 change: 1 addition & 0 deletions src/jolt.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod jolt;
Loading

0 comments on commit 6d4ffab

Please sign in to comment.