From 591aafe3e08aad03edd16c530f801303e6c76715 Mon Sep 17 00:00:00 2001 From: Abigael Oniyilo <37497423-oniyiloboluwati@users.noreply.replit.com> Date: Thu, 31 Oct 2024 04:47:42 +0000 Subject: [PATCH 1/3] all errors resolved in contract --- README.md | 92 +++++++++++++++++++++++++++++++++++++++++++++ contracts/real.clar | 44 ++++++++++++++++------ 2 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..e05a3eb --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +GovStack is a decentralized governance platform built on Stacks blockchain that enables transparent, efficient, and secure decision-making for DAOs. The platform leverages Clarity smart contracts to facilitate proposal creation, voting, and execution. + +## Features + +- **Proposal Management**: Create and track governance proposals +- **Token-Based Voting**: Voting power proportional to token holdings +- **Secure Execution**: Automated proposal execution based on voting outcomes +- **Quorum Requirements**: Minimum participation thresholds for proposal validity +- **Time-Bound Voting**: Configurable voting periods for proposals + +## Smart Contract Overview + +### Key Functions + +1. `create-proposal` + - Creates a new governance proposal + - Requires minimum token threshold + - Parameters: title, description + +2. `cast-vote` + - Cast votes on active proposals + - Token-weighted voting system + - Parameters: proposal-id, vote (true/false), amount + +3. `execute-proposal` + - Executes successful proposals after voting period + - Requires quorum and majority approval + - Parameters: proposal-id + +### Constants + +- Minimum proposal threshold: 1,000,000 tokens +- Voting period: 144 blocks (~24 hours) +- Quorum requirement: 500,000 votes + +## Getting Started + +### Prerequisites + +- Stacks wallet +- Governance tokens +- Clarity CLI + +### Installation + +1. Clone the repository: +```bash +git clone https://github.com/your-username/govstack.git +cd govstack +``` + +2. Deploy the contract: +```bash +clarinet contract deploy govstack +``` + +### Usage Example + +```clarity +;; Create a new proposal +(contract-call? .govstack create-proposal "Update Protocol" "Proposal to upgrade protocol parameters") + +;; Cast a vote +(contract-call? .govstack cast-vote u1 true u5000) + +;; Execute proposal +(contract-call? .govstack execute-proposal u1) +``` + +## Testing + +Run the test suite: +```bash +clarinet test +``` + +## Security Considerations + +- Token-weighted voting system +- Time-locked execution +- Quorum requirements +- Access control mechanisms +- Proposal threshold requirements + +## Contributing + +1. Fork the repository +2. Create your feature branch: `git checkout -b feature/AmazingFeature` +3. Commit your changes: `git commit -m 'Add AmazingFeature'` +4. Push to the branch: `git push origin feature/AmazingFeature` +5. Open a Pull Request + diff --git a/contracts/real.clar b/contracts/real.clar index e44b19a..09220ff 100644 --- a/contracts/real.clar +++ b/contracts/real.clar @@ -1,15 +1,35 @@ +;; Define error codes +(define-constant ERR-INVALID-TOKEN (err u1)) +(define-constant ERR-VALIDATION-FAILED (err u2)) -;; real -;; +;; Token validation utility function with explicit response type +(define-private (comprehensive-token-validation (token principal)) + ;; For demonstration, validating if principal is not null + ;; In a real implementation, you would add more validation logic + (if (is-eq token tx-sender) ;; Example validation comparing with tx-sender + (ok token) + ERR-INVALID-TOKEN)) -;; constants -;; +;; First approach: Direct validation with match +(define-public (process-new-token (new-token principal)) + (let + ( + ;; Store the validation result + (validation-result (comprehensive-token-validation new-token)) + ) + ;; Check the validation result + (match validation-result + success (ok u1) + error ERR-VALIDATION-FAILED) + ) +) -;; data maps and vars -;; - -;; private functions -;; - -;; public functions -;; +;; Second approach: Alternative validation method +(define-public (process-new-token-alt (new-token principal)) + (begin + ;; Validate token with direct matching + (match (comprehensive-token-validation new-token) + success (ok u1) + error ERR-VALIDATION-FAILED) + ) +) \ No newline at end of file From 85342b61a47ac20f73e19512e912c5b0cd905933 Mon Sep 17 00:00:00 2001 From: Abigael Oniyilo <37497423-oniyiloboluwati@users.noreply.replit.com> Date: Thu, 31 Oct 2024 04:51:23 +0000 Subject: [PATCH 2/3] updated README content --- README.md | 169 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 111 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index e05a3eb..e19a704 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,145 @@ -GovStack is a decentralized governance platform built on Stacks blockchain that enables transparent, efficient, and secure decision-making for DAOs. The platform leverages Clarity smart contracts to facilitate proposal creation, voting, and execution. +# Token Validation Smart Contract + +## Overview +This smart contract implements a token validation system on the Stacks blockchain using Clarity. It provides a secure way to validate token principals with built-in error handling and response management. ## Features +- Principal-based token validation +- Comprehensive error handling +- Multiple validation approaches +- Transaction sender verification +- Configurable error responses -- **Proposal Management**: Create and track governance proposals -- **Token-Based Voting**: Voting power proportional to token holdings -- **Secure Execution**: Automated proposal execution based on voting outcomes -- **Quorum Requirements**: Minimum participation thresholds for proposal validity -- **Time-Bound Voting**: Configurable voting periods for proposals +## Contract Components -## Smart Contract Overview +### Error Constants +```clarity +ERR-INVALID-TOKEN (err u1) // Used when token validation fails +ERR-VALIDATION-FAILED (err u2) // Used for general validation failures +``` -### Key Functions +### Core Functions -1. `create-proposal` - - Creates a new governance proposal - - Requires minimum token threshold - - Parameters: title, description +#### `comprehensive-token-validation` +Private function that handles the core validation logic. +```clarity +(define-private (comprehensive-token-validation (token principal))) +``` +- **Parameters**: + - `token`: Principal to validate +- **Returns**: Response containing either: + - Success: Original token principal + - Error: ERR-INVALID-TOKEN + +#### `process-new-token` +Public function implementing the primary validation approach. +```clarity +(define-public (process-new-token (new-token principal))) +``` +- **Parameters**: + - `new-token`: Principal to process +- **Returns**: Response containing either: + - Success: u1 + - Error: ERR-VALIDATION-FAILED + +#### `process-new-token-alt` +Alternative public function with direct matching approach. +```clarity +(define-public (process-new-token-alt (new-token principal))) +``` +- **Parameters**: + - `new-token`: Principal to process +- **Returns**: Response containing either: + - Success: u1 + - Error: ERR-VALIDATION-FAILED + +## Usage + +### Basic Implementation +```clarity +;; Call the process-new-token function +(contract-call? .token-contract process-new-token tx-sender) +``` -2. `cast-vote` - - Cast votes on active proposals - - Token-weighted voting system - - Parameters: proposal-id, vote (true/false), amount +### Alternative Approach +```clarity +;; Call the alternative processing function +(contract-call? .token-contract process-new-token-alt tx-sender) +``` -3. `execute-proposal` - - Executes successful proposals after voting period - - Requires quorum and majority approval - - Parameters: proposal-id +## Security Considerations -### Constants +### Principal Validation +- The contract validates principals against the transaction sender +- Additional validation rules can be implemented in the `comprehensive-token-validation` function +- All error cases are explicitly handled -- Minimum proposal threshold: 1,000,000 tokens -- Voting period: 144 blocks (~24 hours) -- Quorum requirement: 500,000 votes +### Error Handling +- Uses explicit error codes for different failure scenarios +- Implements match expressions for proper error propagation +- Maintains type safety throughout the contract -## Getting Started +## Development ### Prerequisites - -- Stacks wallet -- Governance tokens - Clarity CLI +- Stacks blockchain node (for testing) +- Clarity VS Code extension (recommended) -### Installation +### Testing +1. Clone the repository +2. Deploy the contract to a local Stacks node +3. Run test cases against the deployed contract -1. Clone the repository: +### Deployment +1. Build the contract: ```bash -git clone https://github.com/your-username/govstack.git -cd govstack +clarinet build ``` -2. Deploy the contract: +2. Deploy to testnet: ```bash -clarinet contract deploy govstack +clarinet deploy --testnet ``` -### Usage Example +3. Deploy to mainnet: +```bash +clarinet deploy --mainnet +``` -```clarity -;; Create a new proposal -(contract-call? .govstack create-proposal "Update Protocol" "Proposal to upgrade protocol parameters") +## Customization -;; Cast a vote -(contract-call? .govstack cast-vote u1 true u5000) +### Adding Custom Validation Rules +Modify the `comprehensive-token-validation` function to add additional validation: -;; Execute proposal -(contract-call? .govstack execute-proposal u1) +```clarity +(define-private (comprehensive-token-validation (token principal)) + (if (and + (is-eq token tx-sender) + ;; Add additional validation here + (is-eq token contract-owner) + ) + (ok token) + ERR-INVALID-TOKEN)) ``` -## Testing - -Run the test suite: -```bash -clarinet test +### Modifying Error Codes +Add new error constants as needed: +```clarity +(define-constant ERR-CUSTOM-ERROR (err u3)) ``` -## Security Considerations +## Best Practices -- Token-weighted voting system -- Time-locked execution -- Quorum requirements -- Access control mechanisms -- Proposal threshold requirements +1. Always use explicit error handling +2. Validate all inputs thoroughly +3. Keep track of response types +4. Use meaningful error codes +5. Document function behavior ## Contributing - 1. Fork the repository -2. Create your feature branch: `git checkout -b feature/AmazingFeature` -3. Commit your changes: `git commit -m 'Add AmazingFeature'` -4. Push to the branch: `git push origin feature/AmazingFeature` -5. Open a Pull Request +2. Create a feature branch +3. Submit a pull request +4. Ensure all tests pass From cd365a813ad7735aa9e8ed2c9e1059757265a798 Mon Sep 17 00:00:00 2001 From: Abigael Oniyilo <37497423-oniyiloboluwati@users.noreply.replit.com> Date: Thu, 31 Oct 2024 09:27:31 +0000 Subject: [PATCH 3/3] contract updated --- contracts/real.clar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/real.clar b/contracts/real.clar index 09220ff..0fc7115 100644 --- a/contracts/real.clar +++ b/contracts/real.clar @@ -32,4 +32,4 @@ success (ok u1) error ERR-VALIDATION-FAILED) ) -) \ No newline at end of file +)git \ No newline at end of file