Skip to content

This is a robust, blockchain-based system built in Clarity for decentralized management of gaming guilds and equitable profit distribution among members. It enables guild owners to create collaborative gaming organizations, manage member participation, track profits, and automate fair earnings distribution based on predetermined share percentages.

Notifications You must be signed in to change notification settings

johndamson/Gaming-Guild-Profit-Sharing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Gaming Guild Profit Sharing Smart Contract

A robust, production-ready Clarity smart contract for decentralized gaming guild management with automated profit sharing and member earnings distribution on the Stacks blockchain.

Overview

The Gaming Guild Profit Sharing contract enables gaming communities to organize as decentralized guilds with transparent, automated profit distribution. Guild owners manage membership and earnings, while members receive fair compensation based on their assigned share percentages.

Features

  • Guild Management - Create and manage multiple gaming guilds with unique identities and ownership
  • Member Management - Add/remove members with customizable profit share percentages (1-100%)
  • Profit Tracking - Track guild profitability and member earnings with precision
  • Automated Distribution - Distribute profits fairly based on member share percentages
  • Earnings Claims - Members can claim their earned amounts at any time
  • Security - Owner-only authorization, input validation, and comprehensive error handling
  • Data Integrity - Maintains detailed records of all transactions and member activity

Contract Functions

Public Functions

create-guild

Creates a new gaming guild and registers the creator as the first member. ``` (create-guild (name (string-ascii 64)) (initial-share uint)) ```

  • Parameters:
    • name: Guild name (1-64 ASCII characters)
    • initial-share: Creator's profit share (1-100)
  • Returns: Guild ID on success
  • Errors: Invalid input, invalid share percentage

add-member

Adds a new member to an existing guild (owner only). ``` (add-member (guild-id uint) (new-member principal) (share uint)) ```

  • Parameters:
    • guild-id: Target guild ID
    • new-member: Member principal address
    • share: Profit share percentage (1-100)
  • Returns: ok true on success
  • Errors: Guild not found, unauthorized, member exists, invalid share

remove-member

Removes a member from a guild (owner only). ``` (remove-member (guild-id uint) (member principal)) ```

  • Parameters:
    • guild-id: Target guild ID
    • member: Member principal to remove
  • Returns: ok true on success
  • Errors: Guild not found, unauthorized, member not found

deposit-profit

Deposits profit into a guild (owner only). ``` (deposit-profit (guild-id uint) (amount uint)) ```

  • Parameters:
    • guild-id: Target guild ID
    • amount: Profit amount to deposit
  • Returns: Deposited amount on success
  • Errors: Guild not found, unauthorized, invalid input

distribute-profits

Distributes profits to active members based on share percentages (owner only). ``` (distribute-profits (guild-id uint) (profit-amount uint)) ```

  • Parameters:
    • guild-id: Target guild ID
    • profit-amount: Amount to distribute
  • Returns: Distributed amount on success
  • Errors: Guild not found, unauthorized, no profits

claim-earnings

Allows members to claim their earned amounts. ``` (claim-earnings (guild-id uint) (amount uint)) ```

  • Parameters:
    • guild-id: Guild ID
    • amount: Amount to claim
  • Returns: Claimed amount on success
  • Errors: Guild not found, member not found, insufficient balance

update-member-share

Updates a member's profit share percentage (owner only). ``` (update-member-share (guild-id uint) (member principal) (new-share uint)) ```

  • Parameters:
    • guild-id: Target guild ID
    • member: Member principal
    • new-share: New share percentage (1-100)
  • Returns: ok true on success
  • Errors: Guild not found, unauthorized, member not found, invalid share

Read-Only Functions

get-guild-info

Retrieves guild information. ``` (get-guild-info (guild-id uint)) ``` Returns: { name, owner, created-at, total-profit, active-members } or none

get-member-info

Retrieves member information. ``` (get-member-info (guild-id uint) (member principal)) ``` Returns: { share-percentage, joined-at, total-earned, pending-withdrawal, active } or none

get-guild-balance

Gets the current balance of a guild. ``` (get-guild-balance (guild-id uint)) ``` Returns: Balance amount (uint)

get-contract-balance

Gets the total contract balance. ``` (get-contract-balance) ``` Returns: Total balance (uint)

get-total-guilds

Gets the total number of guilds created. ``` (get-total-guilds) ``` Returns: Total guilds count (uint)

Error Codes

Code Error Description
400 ERR-INVALID-INPUT Invalid input parameters
401 ERR-UNAUTHORIZED Caller is not authorized
402 ERR-INSUFFICIENT-BALANCE Insufficient balance for operation
404 ERR-GUILD-NOT-FOUND Guild does not exist
405 ERR-MEMBER-NOT-FOUND Member does not exist
406 ERR-MEMBER-EXISTS Member already exists in guild
407 ERR-NO-PROFITS No profits to distribute
408 ERR-INVALID-SHARE Share percentage outside valid range (1-100)

Deployment

Prerequisites

  • Clarinet (Stacks development environment)
  • STX tokens for network fees

Steps

  1. Install Clarinet ```bash npm install -g @hirosystems/clarinet ```

  2. Clone the repository ```bash git clone cd gaming-guild ```

  3. Deploy to testnet ```bash clarinet deployments generate --testnet ```

  4. Deploy to mainnet ```bash clarinet deployments generate --mainnet ```

Usage Example

;; 1. Create a new guild
(contract-call? .gaming-guild create-guild "Legends Guild" u25)
;; Returns: u1 (guild ID)

;; 2. Add members to the guild
(contract-call? .gaming-guild add-member u1 'SP2X2JC3WGMQ9N38JFNM2K8G2J1F2H4N5K6P7Q8R u20)

;; 3. Deposit profits
(contract-call? .gaming-guild deposit-profit u1 u1000)

;; 4. Distribute profits to members
(contract-call? .gaming-guild distribute-profits u1 u1000)

;; 5. Members claim earnings
(contract-call? .gaming-guild claim-earnings u1 u250)

;; 6. Query guild info
(contract-call? .gaming-guild get-guild-info u1)

About

This is a robust, blockchain-based system built in Clarity for decentralized management of gaming guilds and equitable profit distribution among members. It enables guild owners to create collaborative gaming organizations, manage member participation, track profits, and automate fair earnings distribution based on predetermined share percentages.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published