-
Notifications
You must be signed in to change notification settings - Fork 0
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
emmanuelist
wants to merge
40
commits into
main
Choose a base branch
from
feature/oracle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…, and pausing the contract
- 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Constants and Data Variables:
contract-owner
: Authorized to make updates.error-codes
: Used for invalid price, unauthorized access, and invalid interval.update-interval
: Default interval between price updates.stx-price
: Stores the current STX price.last-update-time
: Stores the timestamp of the last update.update-interval
: Stores the configurable update interval.Public Function:
set-stx-price
:Public Function:
set-update-interval
: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:
@stacks/clarity-cli
.Commits Included:
Define Constants and Data Variables
Implement
set-stx-price
FunctionImplement Read-only Functions
get-stx-price
andget-last-update
read-only functions.Implement
set-update-interval
FunctionChecklist:
set-stx-price
andset-update-interval
implemented.get-stx-price
andget-last-update
added.