Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add STX Price Management Functions with Authorization and Validation #3

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

emmanuelist
Copy link
Owner

Description

This pull request implements key features to manage the STX price in the smart contract, including functions for updating the price and interval with authorization checks, data validation, and event logging. It also provides read-only functions for retrieving the current price and last update time.

Key Features Implemented:

  1. Constants and Data Variables:

    • Defined constants for:
      • contract-owner: Authorized to make updates.
      • error-codes: Used for invalid price, unauthorized access, and invalid interval.
      • update-interval: Default interval between price updates.
    • Defined data variables:
      • stx-price: Stores the current STX price.
      • last-update-time: Stores the timestamp of the last update.
      • update-interval: Stores the configurable update interval.
  2. Public Function: set-stx-price:

    • Authorization: Only the contract owner can update the STX price.
    • Validation:
      • Price must be greater than zero.
      • Ensure the update interval has passed since the last update.
    • Update Process: Updates the STX price and last update time.
    • Event: Prints a log event indicating the STX price has been successfully updated.
  3. Public Function: set-update-interval:

    • Authorization: Only the contract owner can update the interval.
    • Validation: New interval must be within a valid range.
    • Update: Modifies the update interval data variable.
  4. Read-only Functions:

    • get-stx-price: Returns the current STX price.
    • get-last-update: Returns the timestamp of the last STX price update.

Additional Notes:

  • Added tests for all new functions using @stacks/clarity-cli.
  • Function documentation is included within the contract.
  • Error handling is implemented using predefined error codes.

Commits Included:

  1. Define Constants and Data Variables

    • Added constants for contract owner, error codes, and update interval.
    • Added data variables for STX price, last update time, and update interval.
  2. Implement set-stx-price Function

    • Implemented public function for updating the STX price with authorization, validation, and event logging.
  3. Implement Read-only Functions

    • Implemented get-stx-price and get-last-update read-only functions.
  4. Implement set-update-interval Function

    • Implemented the public function for updating the interval with authorization and validation.

Checklist:

  • Constants and data variables defined.
  • Public functions set-stx-price and set-update-interval implemented.
  • Read-only functions get-stx-price and get-last-update added.
  • Tests added for all functions.
  • Function comments and event logs included.

- Add constants and error codes for governance contract
- Adds constant values for contract owner and error codes such as `ERR_UNAUTHORIZED, ERR_INVALID_PROPOSAL,` and more.
- Define data variables for proposal count, stake, and voting period
- Initializes proposal-count, min-proposal-stake, and voting-period.
- Define maps for proposals and user votes tracking
- Defines proposals and user-votes data structures.
- Implement SIP-010 token trait for fungible token interactions
- Adds the trait ft-trait with functions like transfer and get-balance to interact with tokens.
- Add private helper function for token transfers
- Defines a private function transfer-tokens to manage token transfers between principals.
- Add function to create a proposal with staking mechanism
- Implements the logic for creating a proposal, ensuring the proposer has enough stake and transferring tokens.
- Add function to cast votes on proposals
- Allows users to vote either for or against a proposal and ensures they haven't voted before.
- Add function to end a proposal and determine result
- Adds the logic for concluding a proposal and refunding tokens based on the outcome (pass or reject).
- Add read-only functions for proposal and vote status"
Implements functions `get-proposal`, `get-user-vote`, and `get-proposal-count` for querying the state.
- Add admin function to update the minimum proposal stake
- Allows the contract owner to modify the minimum stake required for creating proposals.
- Add admin function to update the voting period
- Allows the contract owner to modify the voting period duration.
- Define constants for contract owner, error codes, and update intervals.
- Define data variables for storing STX price, last update time, and update interval.
- Add public function to update the STX price.
- Include authorization checks to ensure only the contract owner can update the price.
- Validate the price to ensure it is greater than zero.
- Ensure the update interval has passed before allowing a new update.
- Update the last update time and STX price.
- Print an event indicating the price has been updated.
- Add get-stx-price function to return the current STX price.
- Add get-last-update function to return the last update time.
- Add public function to allow the contract owner to update the interval.
- Include authorization checks to ensure only the contract owner can update the interval.
- Validate the new interval to ensure it is within the allowed range.
- Update the update interval.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant