From f4488b6f2fa4681a1e0d5bac3430c38769f07d25 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:25:38 +0100 Subject: [PATCH 01/16] Add initial constants and data variables for Governance DAO Smart Contract - Defined constants for contract owner and various error codes. - Added data variables to track total members, total proposals, and treasury balance. --- contracts/gov-dao.clar | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 contracts/gov-dao.clar diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar new file mode 100644 index 0000000..fb88d0e --- /dev/null +++ b/contracts/gov-dao.clar @@ -0,0 +1,32 @@ +;; Title: Governance DAO Smart Contract + +;; Summary: +;; This smart contract implements a decentralized autonomous organization (DAO) for governance purposes. +;; It allows stakeholders to propose, vote on, and execute decisions in a transparent and decentralized manner. + +;; Description: +;; The Governance DAO Smart Contract is designed to facilitate decentralized decision-making within a community or organization. +;; It includes functionalities for proposing new initiatives, voting on proposals, and executing approved decisions. +;; The contract ensures that all actions are transparent and verifiable on the blockchain, promoting trust and +;; accountability among participants. Key features include: +;; - Proposal creation and management +;; - Voting mechanisms with configurable parameters +;; - Execution of approved proposals +;; - Role-based access control for administrative functions +;; - Event logging for transparency and auditability + +;; Constants +(define-constant CONTRACT-OWNER tx-sender) +(define-constant ERR-NOT-AUTHORIZED (err u100)) +(define-constant ERR-ALREADY-MEMBER (err u101)) +(define-constant ERR-NOT-MEMBER (err u102)) +(define-constant ERR-INVALID-PROPOSAL (err u103)) +(define-constant ERR-PROPOSAL-EXPIRED (err u104)) +(define-constant ERR-ALREADY-VOTED (err u105)) +(define-constant ERR-INSUFFICIENT-FUNDS (err u106)) +(define-constant ERR-INVALID-AMOUNT (err u107)) + +;; Data variables +(define-data-var total-members uint u0) +(define-data-var total-proposals uint u0) +(define-data-var treasury-balance uint u0) \ No newline at end of file From c9bb49c21ecefeb0def6f22b57d3609b86743ec0 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:26:37 +0100 Subject: [PATCH 02/16] Add data maps for members, proposals, and votes in Governance DAO Smart Contract - Defined `members` map to store member details including reputation, stake, and last interaction. - Defined `proposals` map to store proposal details including creator, title, description, amount, votes, status, and timestamps. - Defined `votes` map to track votes by proposal ID and voter. --- contracts/gov-dao.clar | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index fb88d0e..1d93b28 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -29,4 +29,29 @@ ;; Data variables (define-data-var total-members uint u0) (define-data-var total-proposals uint u0) -(define-data-var treasury-balance uint u0) \ No newline at end of file +(define-data-var treasury-balance uint u0) + +;; Data maps +(define-map members principal + { + reputation: uint, + stake: uint, + last-interaction: uint + } +) + +(define-map proposals uint + { + creator: principal, + title: (string-ascii 50), + description: (string-utf8 500), + amount: uint, + yes-votes: uint, + no-votes: uint, + status: (string-ascii 10), + created-at: uint, + expires-at: uint + } +) + +(define-map votes {proposal-id: uint, voter: principal} bool) \ No newline at end of file From 4c481de59637012708bb20f99fbf5c6ed12c3b16 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:28:03 +0100 Subject: [PATCH 03/16] Add collaborations map and private utility functions in Governance DAO Smart Contract - Defined `collaborations` map to store details of collaborations with partner DAOs including partner DAO, proposal ID, and status. - Added private function `is-member` to check if a user is a member. - Added private function `is-active-proposal` to check if a proposal is active based on its expiration and status. --- contracts/gov-dao.clar | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index 1d93b28..13d58c0 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -54,4 +54,31 @@ } ) -(define-map votes {proposal-id: uint, voter: principal} bool) \ No newline at end of file +(define-map votes {proposal-id: uint, voter: principal} bool) + +(define-map collaborations uint + { + partner-dao: principal, + proposal-id: uint, + status: (string-ascii 10) + } +) + +;; Private functions + +(define-private (is-member (user principal)) + (match (map-get? members user) + member-data true + false + ) +) + +(define-private (is-active-proposal (proposal-id uint)) + (match (map-get? proposals proposal-id) + proposal (and + (< block-height (get expires-at proposal)) + (is-eq (get status proposal) "active") + ) + false + ) +) \ No newline at end of file From db6166b9173a75e5b656f72fe29efcb73cecb480 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:30:23 +0100 Subject: [PATCH 04/16] Add private utility functions for proposal and collaboration validation, and voting power calculation - Added `is-valid-proposal-id` function to check if a proposal ID is valid. - Added `is-valid-collaboration-id` function to check if a collaboration ID is valid. - Added `calculate-voting-power` function to compute a user's voting power based on their reputation and stake. --- contracts/gov-dao.clar | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index 13d58c0..ace121b 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -81,4 +81,28 @@ ) false ) +) + +(define-private (is-valid-proposal-id (proposal-id uint)) + (match (map-get? proposals proposal-id) + proposal true + false + ) +) + +(define-private (is-valid-collaboration-id (collaboration-id uint)) + (match (map-get? collaborations collaboration-id) + collaboration true + false + ) +) + +(define-private (calculate-voting-power (user principal)) + (let ( + (member-data (unwrap! (map-get? members user) u0)) + (reputation (get reputation member-data)) + (stake (get stake member-data)) + ) + (+ (* reputation u10) stake) + ) ) \ No newline at end of file From 97b6c5773244e83a4a860466a6c23ac291e7057c Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:31:04 +0100 Subject: [PATCH 05/16] Add private function to update member reputation in Governance DAO Smart Contract - Added `update-member-reputation` function to adjust a member's reputation by a specified change and update their last interaction timestamp. --- contracts/gov-dao.clar | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index ace121b..d1bea69 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -105,4 +105,18 @@ ) (+ (* reputation u10) stake) ) +) + +(define-private (update-member-reputation (user principal) (change int)) + (match (map-get? members user) + member-data + (let ( + (new-reputation (to-uint (+ (to-int (get reputation member-data)) change))) + (updated-data (merge member-data {reputation: new-reputation, last-interaction: block-height})) + ) + (map-set members user updated-data) + (ok new-reputation) + ) + ERR-NOT-MEMBER + ) ) \ No newline at end of file From 28584a1d12b743c70ef4ef8f39876900353bb13d Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:31:48 +0100 Subject: [PATCH 06/16] Add public functions for joining and leaving the DAO in Governance DAO Smart Contract - Added `join-dao` function to allow users to join the DAO, initializing their membership data and incrementing the total members count. - Added `leave-dao` function to allow users to leave the DAO, removing their membership data and decrementing the total members count. --- contracts/gov-dao.clar | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index d1bea69..44198dd 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -119,4 +119,30 @@ ) ERR-NOT-MEMBER ) +) + +;; Public functions + +;; Membership management + +(define-public (join-dao) + (let ( + (caller tx-sender) + ) + (asserts! (not (is-member caller)) ERR-ALREADY-MEMBER) + (map-set members caller {reputation: u1, stake: u0, last-interaction: block-height}) + (var-set total-members (+ (var-get total-members) u1)) + (ok true) + ) +) + +(define-public (leave-dao) + (let ( + (caller tx-sender) + ) + (asserts! (is-member caller) ERR-NOT-MEMBER) + (map-delete members caller) + (var-set total-members (- (var-get total-members) u1)) + (ok true) + ) ) \ No newline at end of file From 418f07982cc9e91c1bf41405a55ec58d3c1548f1 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:32:59 +0100 Subject: [PATCH 07/16] Add public functions for staking and unstaking tokens in Governance DAO Smart Contract - Added `stake-tokens` function to allow members to stake tokens, updating their stake and the treasury balance. - Added `unstake-tokens` function to allow members to unstake tokens, ensuring sufficient funds and updating their stake and the treasury balance. --- contracts/gov-dao.clar | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index 44198dd..aa9d818 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -145,4 +145,53 @@ (var-set total-members (- (var-get total-members) u1)) (ok true) ) +) + +(define-public (stake-tokens (amount uint)) + (let ( + (caller tx-sender) + ) + (asserts! (is-member caller) ERR-NOT-MEMBER) + (asserts! (> amount u0) ERR-INVALID-AMOUNT) + (try! (stx-transfer? amount caller (as-contract tx-sender))) + (match (map-get? members caller) + member-data + (let ( + (new-stake (+ (get stake member-data) amount)) + (updated-data (merge member-data {stake: new-stake, last-interaction: block-height})) + ) + (map-set members caller updated-data) + (var-set treasury-balance (+ (var-get treasury-balance) amount)) + (ok new-stake) + ) + ERR-NOT-MEMBER + ) + ) +) + +(define-public (unstake-tokens (amount uint)) + (let ( + (caller tx-sender) + ) + (asserts! (is-member caller) ERR-NOT-MEMBER) + (asserts! (> amount u0) ERR-INVALID-AMOUNT) + (match (map-get? members caller) + member-data + (let ( + (current-stake (get stake member-data)) + ) + (asserts! (>= current-stake amount) ERR-INSUFFICIENT-FUNDS) + (try! (as-contract (stx-transfer? amount tx-sender caller))) + (let ( + (new-stake (- current-stake amount)) + (updated-data (merge member-data {stake: new-stake, last-interaction: block-height})) + ) + (map-set members caller updated-data) + (var-set treasury-balance (- (var-get treasury-balance) amount)) + (ok new-stake) + ) + ) + ERR-NOT-MEMBER + ) + ) ) \ No newline at end of file From e0580091aee730147c8d3b3a5d159c395e3087e0 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:33:45 +0100 Subject: [PATCH 08/16] Add public functions for proposal creation and voting in Governance DAO Smart Contract - Added `create-proposal` function to allow members to create proposals, ensuring sufficient treasury balance and valid proposal details. - Added `vote-on-proposal` function to allow members to vote on proposals, updating the proposal's vote counts and the member's reputation. --- contracts/gov-dao.clar | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index aa9d818..67d27eb 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -194,4 +194,57 @@ ERR-NOT-MEMBER ) ) +) + +;; Proposal management + +(define-public (create-proposal (title (string-ascii 50)) (description (string-utf8 500)) (amount uint)) + (let ( + (caller tx-sender) + (proposal-id (+ (var-get total-proposals) u1)) + ) + (asserts! (is-member caller) ERR-NOT-MEMBER) + (asserts! (>= (var-get treasury-balance) amount) ERR-INSUFFICIENT-FUNDS) + (asserts! (> (len title) u0) ERR-INVALID-PROPOSAL) + (asserts! (> (len description) u0) ERR-INVALID-PROPOSAL) + (map-set proposals proposal-id + { + creator: caller, + title: title, + description: description, + amount: amount, + yes-votes: u0, + no-votes: u0, + status: "active", + created-at: block-height, + expires-at: (+ block-height u1440) ;; Proposal expires after 1440 blocks (approx. 10 days) + } + ) + (var-set total-proposals proposal-id) + (try! (update-member-reputation caller 1)) ;; Increase reputation for creating a proposal + (ok proposal-id) + ) +) + +(define-public (vote-on-proposal (proposal-id uint) (vote bool)) + (let ( + (caller tx-sender) + ) + (asserts! (is-member caller) ERR-NOT-MEMBER) + (asserts! (is-active-proposal proposal-id) ERR-INVALID-PROPOSAL) + (asserts! (not (default-to false (map-get? votes {proposal-id: proposal-id, voter: caller}))) ERR-ALREADY-VOTED) + + (let ( + (voting-power (calculate-voting-power caller)) + (proposal (unwrap! (map-get? proposals proposal-id) ERR-INVALID-PROPOSAL)) + ) + (if vote + (map-set proposals proposal-id (merge proposal {yes-votes: (+ (get yes-votes proposal) voting-power)})) + (map-set proposals proposal-id (merge proposal {no-votes: (+ (get no-votes proposal) voting-power)})) + ) + (map-set votes {proposal-id: proposal-id, voter: caller} true) + (try! (update-member-reputation caller 1)) ;; Increase reputation for voting + (ok true) + ) + ) ) \ No newline at end of file From da400f876be57f0cb25528b6ca099855919786e8 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:34:45 +0100 Subject: [PATCH 09/16] Add public function to execute proposals in Governance DAO Smart Contract - Added `execute-proposal` function to allow members to execute proposals after their expiration, transferring funds if approved and updating the proposal status. --- contracts/gov-dao.clar | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index 67d27eb..f4a71fe 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -247,4 +247,44 @@ (ok true) ) ) +) + +(define-public (execute-proposal (proposal-id uint)) + (let ( + (caller tx-sender) + ) + (asserts! (is-member caller) ERR-NOT-MEMBER) + (asserts! (is-valid-proposal-id proposal-id) ERR-INVALID-PROPOSAL) + (match (map-get? proposals proposal-id) + proposal + (begin + (asserts! (>= block-height (get expires-at proposal)) ERR-PROPOSAL-EXPIRED) + (asserts! (is-eq (get status proposal) "active") ERR-INVALID-PROPOSAL) + (let ( + (yes-votes (get yes-votes proposal)) + (no-votes (get no-votes proposal)) + (amount (get amount proposal)) + ) + (if (> yes-votes no-votes) + (begin + (try! (as-contract (stx-transfer? amount tx-sender (get creator proposal)))) + (var-set treasury-balance (- (var-get treasury-balance) amount)) + ;; Add additional validation before setting status + (asserts! (is-valid-proposal-id proposal-id) ERR-INVALID-PROPOSAL) + (map-set proposals proposal-id (merge proposal {status: "executed"})) + (try! (update-member-reputation (get creator proposal) 5)) + (ok true) + ) + (begin + ;; Add additional validation before setting status + (asserts! (is-valid-proposal-id proposal-id) ERR-INVALID-PROPOSAL) + (map-set proposals proposal-id (merge proposal {status: "rejected"})) + (ok false) + ) + ) + ) + ) + ERR-INVALID-PROPOSAL + ) + ) ) \ No newline at end of file From 56416b82c3e977460d708b0a3f1aef6b70e71428 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:35:23 +0100 Subject: [PATCH 10/16] Add public functions for treasury management in Governance DAO Smart Contract - Added `get-treasury-balance` read-only function to retrieve the current balance of the treasury. - Added `donate-to-treasury` function to allow users to donate to the treasury, updating the balance and increasing the reputation of members who donate. --- contracts/gov-dao.clar | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index f4a71fe..ee9a3a2 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -287,4 +287,27 @@ ERR-INVALID-PROPOSAL ) ) +) + +;; Treasury management + +(define-read-only (get-treasury-balance) + (ok (var-get treasury-balance)) +) + +(define-public (donate-to-treasury (amount uint)) + (let ( + (caller tx-sender) + ) + (asserts! (> amount u0) ERR-INVALID-AMOUNT) + (try! (stx-transfer? amount caller (as-contract tx-sender))) + (var-set treasury-balance (+ (var-get treasury-balance) amount)) + (if (is-member caller) + (begin + (try! (update-member-reputation caller 2)) ;; Increase reputation for donating + (ok true) + ) + (ok true) + ) + ) ) \ No newline at end of file From d3f598b0474c7089cf1f5402073de51e8804ac9d Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:36:20 +0100 Subject: [PATCH 11/16] Add reputation system functions in Governance DAO Smart Contract - Added `get-member-reputation` read-only function to retrieve the reputation of a specific member. - Added `decay-inactive-members` function to halve the reputation of members inactive for approximately 30 days, callable only by the contract owner. --- contracts/gov-dao.clar | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index ee9a3a2..468afe3 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -310,4 +310,33 @@ (ok true) ) ) +) + +;; Reputation system + +(define-read-only (get-member-reputation (user principal)) + (match (map-get? members user) + member-data (ok (get reputation member-data)) + ERR-NOT-MEMBER + ) +) + +(define-public (decay-inactive-members) + (let ( + (caller tx-sender) + (current-block block-height) + ) + (asserts! (is-eq caller CONTRACT-OWNER) ERR-NOT-AUTHORIZED) + (map-set members caller + (match (map-get? members caller) + member-data + (if (> (- current-block (get last-interaction member-data)) u4320) ;; Approx. 30 days of inactivity + (merge member-data {reputation: (/ (get reputation member-data) u2)}) ;; Halve the reputation + member-data + ) + { reputation: u0, stake: u0, last-interaction: current-block } + ) + ) + (ok true) + ) ) \ No newline at end of file From 170f57724c32c690885ae7cdb7851a4a2ba3f217 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:37:06 +0100 Subject: [PATCH 12/16] Add public function for proposing cross-DAO collaborations in Governance DAO Smart Contract - Added `propose-collaboration` function to allow members to propose collaborations with partner DAOs, linking to an active proposal and ensuring the partner DAO is not the caller. --- contracts/gov-dao.clar | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index 468afe3..1cfea68 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -339,4 +339,26 @@ ) (ok true) ) +) + +;; Cross-DAO collaboration + +(define-public (propose-collaboration (partner-dao principal) (proposal-id uint)) + (let ( + (caller tx-sender) + (collaboration-id (+ (var-get total-proposals) u1)) + ) + (asserts! (is-member caller) ERR-NOT-MEMBER) + (asserts! (is-active-proposal proposal-id) ERR-INVALID-PROPOSAL) + (asserts! (not (is-eq partner-dao caller)) ERR-INVALID-PROPOSAL) + (map-set collaborations collaboration-id + { + partner-dao: partner-dao, + proposal-id: proposal-id, + status: "proposed" + } + ) + (var-set total-proposals collaboration-id) + (ok collaboration-id) + ) ) \ No newline at end of file From 46085d1336cd0811b489b74d506823fb5c2ff35e Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:38:02 +0100 Subject: [PATCH 13/16] Add public function to accept cross-DAO collaborations in Governance DAO Smart Contract - Added `accept-collaboration` function to allow partner DAOs to accept proposed collaborations, updating the collaboration status to "accepted". --- contracts/gov-dao.clar | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index 1cfea68..f2e9816 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -361,4 +361,24 @@ (var-set total-proposals collaboration-id) (ok collaboration-id) ) +) + +(define-public (accept-collaboration (collaboration-id uint)) + (let ( + (caller tx-sender) + ) + (asserts! (is-valid-collaboration-id collaboration-id) ERR-INVALID-PROPOSAL) + (match (map-get? collaborations collaboration-id) + collaboration + (begin + (asserts! (is-eq caller (get partner-dao collaboration)) ERR-NOT-AUTHORIZED) + (asserts! (is-eq (get status collaboration) "proposed") ERR-INVALID-PROPOSAL) + ;; Add additional validation before setting status + (asserts! (is-valid-collaboration-id collaboration-id) ERR-INVALID-PROPOSAL) + (map-set collaborations collaboration-id (merge collaboration {status: "accepted"})) + (ok true) + ) + ERR-INVALID-PROPOSAL + ) + ) ) \ No newline at end of file From 5cf52141da24339aaceeaaf428fc907ab2795629 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:38:38 +0100 Subject: [PATCH 14/16] Add getter functions in Governance DAO Smart Contract - Added `get-proposal` function to retrieve details of a specific proposal. - Added `get-member` function to retrieve details of a specific member. - Added `get-total-members` function to get the total number of members. - Added `get-total-proposals` function to get the total number of proposals. --- contracts/gov-dao.clar | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index f2e9816..9d3402a 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -381,4 +381,22 @@ ERR-INVALID-PROPOSAL ) ) +) + +;; Getter functions + +(define-read-only (get-proposal (proposal-id uint)) + (ok (unwrap! (map-get? proposals proposal-id) ERR-INVALID-PROPOSAL)) +) + +(define-read-only (get-member (user principal)) + (ok (unwrap! (map-get? members user) ERR-NOT-MEMBER)) +) + +(define-read-only (get-total-members) + (ok (var-get total-members)) +) + +(define-read-only (get-total-proposals) + (ok (var-get total-proposals)) ) \ No newline at end of file From 13ba0df60512ea213c90b4c67bce2bc76983e1ec Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:39:59 +0100 Subject: [PATCH 15/16] Add contract initialization block in Governance DAO Smart Contract - Added initialization block to set initial values for total members, total proposals, and treasury balance. --- contracts/gov-dao.clar | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contracts/gov-dao.clar b/contracts/gov-dao.clar index 9d3402a..9e2d963 100644 --- a/contracts/gov-dao.clar +++ b/contracts/gov-dao.clar @@ -15,7 +15,7 @@ ;; - Role-based access control for administrative functions ;; - Event logging for transparency and auditability -;; Constants +;; Constants;; Constants (define-constant CONTRACT-OWNER tx-sender) (define-constant ERR-NOT-AUTHORIZED (err u100)) (define-constant ERR-ALREADY-MEMBER (err u101)) @@ -399,4 +399,11 @@ (define-read-only (get-total-proposals) (ok (var-get total-proposals)) +) + +;; Initialize contract +(begin + (var-set total-members u0) + (var-set total-proposals u0) + (var-set treasury-balance u0) ) \ No newline at end of file From 6085c6de4b4aa791404d03e90ccca17eb2c341b1 Mon Sep 17 00:00:00 2001 From: esthercodez1 Date: Sun, 22 Dec 2024 05:54:23 +0100 Subject: [PATCH 16/16] Add initial project documentation - Added `CODE_OF_CONDUCT.md` to outline the expected behavior and enforcement policies for contributors. - Added `CONTRIBUTING.md` to provide guidelines for contributing to the project. - Added `LICENSE` file to specify the project's licensing terms. - Added `README.md` to provide an overview of the project, installation instructions, usage, and other relevant information. --- CODE_OF_CONDUCT.md | 52 +++++++++++++++ CONTRIBUTING.md | 70 ++++++++++++++++++++ Clarinet.toml | 22 ++++--- LICENSE | 18 +++++ README.md | 148 ++++++++++++++++++++++++++++++++++++++++++ tests/gov-dao_test.ts | 26 ++++++++ 6 files changed, 326 insertions(+), 10 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 tests/gov-dao_test.ts diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..19a3d1a --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,52 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +## Our Standards + +Examples of behavior that contributes to a positive environment: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes +- Focusing on what is best for the overall community + +Examples of unacceptable behavior: + +- The use of sexualized language or imagery, and sexual attention or advances +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information without explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement through the project's issue tracker. +All complaints will be reviewed and investigated promptly and fairly. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c9b1420 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,70 @@ +# Contributing to Governance DAO Smart Contract + +We love your input! We want to make contributing to the Governance DAO Smart Contract as easy and transparent as possible, whether it's: + +- Reporting a bug +- Discussing the current state of the code +- Submitting a fix +- Proposing new features +- Becoming a maintainer + +## We Develop with Github + +We use Github to host code, to track issues and feature requests, as well as accept pull requests. + +## We Use [Github Flow](https://github.com/github/docs/blob/main/content/get-started/using-github/github-flow.md) + +Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests: + +1. Fork the repo and create your branch from `main`. +2. If you've added code that should be tested, add tests. +3. If you've changed APIs, update the documentation. +4. Ensure the test suite passes. +5. Make sure your code lints. +6. Issue that pull request! + +## Smart Contract Development Guidelines + +1. **Security First** + + - Always prioritize security in your changes + - Follow established security patterns + - Add appropriate checks and validations + +2. **Code Style** + + - Follow Clarity best practices + - Use meaningful variable and function names + - Add comments for complex logic + - Keep functions focused and modular + +3. **Testing** + + - Add tests for new functionality + - Ensure existing tests pass + - Test edge cases and failure scenarios + +4. **Documentation** + - Update documentation for any changes + - Add inline comments for complex logic + - Update error code documentation + +## Any contributions you make will be under the MIT Software License + +In short, when you submit code changes, your submissions are understood to be under the same [MIT License](LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern. + +## Write bug reports with detail, background, and sample code + +**Great Bug Reports** tend to have: + +- A quick summary and/or background +- Steps to reproduce + - Be specific! + - Give sample code if you can. +- What you expected would happen +- What actually happens +- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) + +## License + +By contributing, you agree that your contributions will be licensed under its MIT License. diff --git a/Clarinet.toml b/Clarinet.toml index 6f52597..d4d9a1f 100644 --- a/Clarinet.toml +++ b/Clarinet.toml @@ -1,20 +1,22 @@ - [project] name = "GovDAO" authors = [] +description = "" telemetry = true +requirements = [] +[contracts.gov-dao] +path = "contracts/gov-dao.clar" +depends_on = [] + +[repl] +costs_version = 2 +parser_version = 2 + [repl.analysis] passes = ["check_checker"] + [repl.analysis.check_checker] -# If true, inputs are trusted after tx_sender has been checked. +strict = false trusted_sender = false -# If true, inputs are trusted after contract-caller has been checked. trusted_caller = false -# If true, untrusted data may be passed into a private function without a -# warning, if it gets checked inside. This check will also propagate up to the -# caller. callee_filter = false - -# [contracts.counter] -# path = "contracts/counter.clar" -# depends_on = [] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4a01b9d --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +MIT License + +Copyright (c) 2024 Esther Sunday + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAM \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0cf465 --- /dev/null +++ b/README.md @@ -0,0 +1,148 @@ +# Governance DAO Smart Contract + +A decentralized autonomous organization (DAO) smart contract built on Stacks blockchain for transparent and decentralized governance. + +## Overview + +This smart contract implements a comprehensive DAO system that enables: + +- Decentralized decision-making through proposals and voting +- Member management with reputation and staking mechanisms +- Treasury management with secure fund handling +- Cross-DAO collaboration capabilities +- Reputation system with activity-based adjustments + +## Features + +- **Membership Management** + + - Join/leave DAO functionality + - Token staking and unstaking + - Reputation-based system + - Activity tracking + +- **Proposal System** + + - Create and vote on proposals + - Automatic proposal expiration + - Weighted voting based on reputation and stake + - Transparent execution of approved proposals + +- **Treasury Management** + + - Secure fund handling + - Donation capabilities + - Balance tracking + - Controlled fund distribution + +- **Reputation System** + + - Dynamic reputation scoring + - Activity-based reputation gains + - Inactivity decay mechanism + - Weighted voting power + +- **Cross-DAO Collaboration** + - Propose collaborations with other DAOs + - Accept/reject collaboration proposals + - Track collaboration status + +## Getting Started + +### Prerequisites + +- Stacks blockchain environment +- Clarity smart contract development tools +- STX tokens for testing and deployment + +### Installation + +1. Clone the repository +2. Deploy the contract to the Stacks blockchain +3. Initialize the contract + +### Usage + +#### Joining the DAO + +```clarity +(contract-call? .governance-dao join-dao) +``` + +#### Creating a Proposal + +```clarity +(contract-call? .governance-dao create-proposal + "Proposal Title" + "Proposal Description" + u1000) +``` + +#### Voting on a Proposal + +```clarity +(contract-call? .governance-dao vote-on-proposal u1 true) +``` + +#### Staking Tokens + +```clarity +(contract-call? .governance-dao stake-tokens u1000) +``` + +## Contract Functions + +### Member Management + +- `join-dao`: Join the DAO as a new member +- `leave-dao`: Leave the DAO +- `stake-tokens`: Stake STX tokens +- `unstake-tokens`: Unstake previously staked tokens + +### Proposal Management + +- `create-proposal`: Create a new proposal +- `vote-on-proposal`: Vote on an active proposal +- `execute-proposal`: Execute an approved proposal + +### Treasury Management + +- `get-treasury-balance`: Get current treasury balance +- `donate-to-treasury`: Make a donation to the treasury + +### Reputation System + +- `get-member-reputation`: Get a member's reputation +- `decay-inactive-members`: Apply reputation decay to inactive members + +### Cross-DAO Collaboration + +- `propose-collaboration`: Propose collaboration with another DAO +- `accept-collaboration`: Accept a collaboration proposal + +## Error Codes + +- `ERR-NOT-AUTHORIZED (u100)`: Unauthorized access +- `ERR-ALREADY-MEMBER (u101)`: User is already a member +- `ERR-NOT-MEMBER (u102)`: User is not a member +- `ERR-INVALID-PROPOSAL (u103)`: Invalid proposal +- `ERR-PROPOSAL-EXPIRED (u104)`: Proposal has expired +- `ERR-ALREADY-VOTED (u105)`: Member has already voted +- `ERR-INSUFFICIENT-FUNDS (u106)`: Insufficient funds +- `ERR-INVALID-AMOUNT (u107)`: Invalid amount specified + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests. + +## Security + +For security concerns, please refer to our [SECURITY.md](SECURITY.md) file. + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +## Support + +For support and questions, please open an issue in the repository. diff --git a/tests/gov-dao_test.ts b/tests/gov-dao_test.ts new file mode 100644 index 0000000..9a18ae0 --- /dev/null +++ b/tests/gov-dao_test.ts @@ -0,0 +1,26 @@ + +import { Clarinet, Tx, Chain, Account, types } from 'https://deno.land/x/clarinet@v0.14.0/index.ts'; +import { assertEquals } from 'https://deno.land/std@0.90.0/testing/asserts.ts'; + +Clarinet.test({ + name: "Ensure that <...>", + async fn(chain: Chain, accounts: Map) { + let block = chain.mineBlock([ + /* + * Add transactions with: + * Tx.contractCall(...) + */ + ]); + assertEquals(block.receipts.length, 0); + assertEquals(block.height, 2); + + block = chain.mineBlock([ + /* + * Add transactions with: + * Tx.contractCall(...) + */ + ]); + assertEquals(block.receipts.length, 0); + assertEquals(block.height, 3); + }, +});