Skip to content

Commit

Permalink
feat(questions): tags, rename folder
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Nov 1, 2024
1 parent 9efac8f commit 6d73593
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 56 deletions.
126 changes: 76 additions & 50 deletions script/deploy/DeployPoC.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,75 @@ import { FollowerSinceStamp } from "../../src/stamps/FollowerSinceStamp.sol";
import { FollowerSincePoints } from "../../src/points/FollowerSincePoints.sol";
import { MultipleFollowerSincePoints } from "../../src/points/MultipleFollowerSincePoints.sol";
import { Plasa } from "../../src/plasa/Plasa.sol";
import { FixedQuestion } from "../../src/voting/FixedQuestion.sol";
import { FixedQuestion } from "../../src/questions/FixedQuestion.sol";

contract DeployPoC is Script {
function deploySpace1(
DeployPoCArgs.CommonArgs memory common,
DeployPoCArgs.Space1Args memory args
) private returns (Space, FollowerSincePoints, FollowerSinceStamp) {
FollowerSinceStamp stamp = new FollowerSinceStamp(common.stampSigner, args.stampPlatform, args.stampFollowed);
FollowerSincePoints points = new FollowerSincePoints(address(stamp), args.pointsName, args.pointsSymbol);
Space space = new Space(
common.initialSuperAdmins,
args.name,
args.description,
args.imageUrl,
address(points),
common.minPointsToAddOpenQuestionOption
);
return (space, points, stamp);
}

function deploySpace2(
DeployPoCArgs.CommonArgs memory common,
DeployPoCArgs.Space2Args memory args
) private returns (Space, MultipleFollowerSincePoints, FollowerSinceStamp[] memory) {
FollowerSinceStamp[] memory stamps = new FollowerSinceStamp[](args.stampPlatforms.length);
address[] memory stampAddresses = new address[](args.stampPlatforms.length);

for (uint256 i = 0; i < args.stampPlatforms.length; i++) {
stamps[i] = new FollowerSinceStamp(common.stampSigner, args.stampPlatforms[i], args.stampFollowed[i]);
stampAddresses[i] = address(stamps[i]);
}

MultipleFollowerSincePoints points = new MultipleFollowerSincePoints(
stampAddresses,
args.stampMultipliers,
args.pointsName,
args.pointsSymbol
);

Space space = new Space(
common.initialSuperAdmins,
args.name,
args.description,
args.imageUrl,
address(points),
common.minPointsToAddOpenQuestionOption
);

return (space, points, stamps);
}

function deployQuestion(
address spaceAddress,
address pointsAddress,
DeployPoCArgs.QuestionArgs memory args
) private returns (FixedQuestion) {
return
new FixedQuestion(
spaceAddress,
pointsAddress,
args.title,
args.description,
args.tags,
args.deadline,
args.optionTitles,
args.optionDescriptions
);
}

function run() public {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
uint256 superAdminPrivateKey = vm.envUint("SUPER_ADMIN_PRIVATE_KEY");
Expand All @@ -32,59 +98,19 @@ contract DeployPoC is Script {
// Deploy Plasa
Plasa plasa = new Plasa(superAdmin);

// Deploy Space 1 with FollowerSincePoints
FollowerSinceStamp stamp1 = new FollowerSinceStamp(args.stampSigner, args.stamp1Platform, args.stamp1Followed);
FollowerSincePoints points1 = new FollowerSincePoints(address(stamp1), args.points1Name, args.points1Symbol);
Space space1 = new Space(
args.initialSuperAdmins,
args.space1Name,
args.space1Description,
args.space1ImageUrl,
address(points1),
args.minPointsToAddOpenQuestionOption
);
// Deploy Space 1
(Space space1, FollowerSincePoints points1, FollowerSinceStamp stamp1) = deploySpace1(args.common, args.space1);

// Deploy Space 2 with MultipleFollowerSincePoints
FollowerSinceStamp[] memory stamps2 = new FollowerSinceStamp[](args.stamp2Platforms.length);
address[] memory stampAddresses2 = new address[](args.stamp2Platforms.length);
for (uint256 i = 0; i < args.stamp2Platforms.length; i++) {
stamps2[i] = new FollowerSinceStamp(args.stampSigner, args.stamp2Platforms[i], args.stamp2Followed[i]);
stampAddresses2[i] = address(stamps2[i]);
}
MultipleFollowerSincePoints points2 = new MultipleFollowerSincePoints(
stampAddresses2,
args.stamp2Multipliers,
args.points2Name,
args.points2Symbol
);
Space space2 = new Space(
args.initialSuperAdmins,
args.space2Name,
args.space2Description,
args.space2ImageUrl,
address(points2),
args.minPointsToAddOpenQuestionOption
// Deploy Space 2
(Space space2, MultipleFollowerSincePoints points2, FollowerSinceStamp[] memory stamps2) = deploySpace2(
args.common,
args.space2
);

// Deploy question for Space 1
FixedQuestion question1 = new FixedQuestion(
address(space1),
args.question1Title,
args.question1Description,
args.question1Deadline,
args.question1OptionTitles,
args.question1OptionDescriptions
);
// Deploy questions
FixedQuestion question1 = deployQuestion(address(space1), address(points1), args.question1);

// Deploy question for Space 2
FixedQuestion question2 = new FixedQuestion(
address(space2),
args.question2Title,
args.question2Description,
args.question2Deadline,
args.question2OptionTitles,
args.question2OptionDescriptions
);
FixedQuestion question2 = deployQuestion(address(space2), address(points2), args.question2);

vm.stopBroadcast();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ contract FixedQuestion is Question, IFixedQuestion {
/// @param _initialOptionDescriptions An array of descriptions for the initial voting options
constructor(
address _space,
address _points,
string memory _title,
string memory _description,
string[] memory _tags,
uint256 _deadline,
string[] memory _initialOptionTitles,
string[] memory _initialOptionDescriptions
) Question(_space, _title, _description, _deadline) {
) Question(_space, _points, _title, _description, _deadline, _tags) {
questionType = QuestionType.Fixed;

if (_initialOptionTitles.length != _initialOptionDescriptions.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ contract OpenQuestion is Question, IOpenQuestion {
/// @param _title The title of the question
/// @param _description The description of the question
/// @param _deadline The deadline for voting on the question
/// @param _tags The array of tags associated with this question
constructor(
address _space,
address _points,
string memory _title,
string memory _description,
string[] memory _tags,
uint256 _deadline
) Question(_space, _title, _description, _deadline) {
) Question(_space, _points, _title, _description, _deadline, _tags) {
questionType = QuestionType.Open;
}

Expand Down
26 changes: 25 additions & 1 deletion src/voting/Question.sol → src/questions/Question.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IQuestion } from "./interfaces/IQuestion.sol";
import { ISpace } from "../spaces/interfaces/ISpace.sol";
import { IQuestionView } from "./interfaces/IQuestionView.sol";
import { IPoints } from "../points/interfaces/IPoints.sol";

/// @title Abstract Question Contract for Decentralized Voting System
/// @dev Implements base functionality for a voting question, inheriting from Ownable and IQuestion
Expand All @@ -31,9 +32,15 @@ abstract contract Question is Ownable, IQuestion {
/// @notice The Space contract associated with this question
ISpace public space;

/// @notice The Points contract associated with this question
IPoints public points;

/// @notice The address of the user who created this question
address public creator;

/// @notice Array of tags associated with this question
string[] public tags;

/// @dev Modifier to check if the voting is still active
/// @notice Reverts if the voting period has ended
modifier whileActive() {
Expand All @@ -47,18 +54,28 @@ abstract contract Question is Ownable, IQuestion {
/// @param _title The title of the question
/// @param _description The description of the question
/// @param _deadline The deadline for voting
/// @param _tags The array of tags associated with this question
constructor(
address _space,
address _points,
string memory _title,
string memory _description,
uint256 _deadline
uint256 _deadline,
string[] memory _tags
) Ownable(msg.sender) {
creator = msg.sender;
space = ISpace(_space);
kickoff = block.timestamp;
title = _title;
description = _description;
deadline = _deadline;
tags = _tags;

if (_points == address(0)) {
points = space.defaultPoints();
} else {
points = IPoints(_points);
}

// Add an empty option at index 0
_options.push(OptionData("", "", address(0), 0, 0));
Expand Down Expand Up @@ -107,6 +124,12 @@ abstract contract Question is Ownable, IQuestion {
return _options[optionId];
}

/// @notice Updates the tags of the question
/// @param _tags The new array of tags
function updateTags(string[] memory _tags) external onlyOwner {
tags = _tags;
}

// Internal functions

/// @dev Processes a vote for a specific option
Expand Down Expand Up @@ -179,6 +202,7 @@ abstract contract Question is Ownable, IQuestion {
questionType,
title,
description,
tags,
creator,
kickoff,
deadline,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface IQuestionView {
QuestionType questionType;
string title;
string description;
string[] tags;
address creator;
uint256 kickoff;
uint256 deadline;
Expand Down
2 changes: 1 addition & 1 deletion src/spaces/Space.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.20;

import { ISpace } from "./interfaces/ISpace.sol";
import { ISpaceView } from "./interfaces/ISpaceView.sol";
import { IQuestion, IQuestionView } from "../voting/interfaces/IQuestion.sol";
import { IQuestion, IQuestionView } from "../questions/interfaces/IQuestion.sol";
import { SpaceAccessControl } from "./SpaceAccessControl.sol";
import { IPoints } from "../points/interfaces/IPoints.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/spaces/interfaces/ISpace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
import { ISpaceAccessControl } from "./ISpaceAccessControl.sol";
import { ISpaceView } from "./ISpaceView.sol";
import { IPoints } from "../../points/interfaces/IPoints.sol";
import { IQuestion } from "../../voting/interfaces/IQuestion.sol";
import { IQuestion } from "../../questions/interfaces/IQuestion.sol";

/// @title ISpace - Interface for managing community spaces in Plasa
/// @dev Implement this interface to create a space contract that represents a community or organization
Expand Down
2 changes: 1 addition & 1 deletion src/spaces/interfaces/ISpaceView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import { IPointsView } from "../../points/interfaces/IPointsView.sol";
import { IQuestionView } from "../../voting/interfaces/IQuestionView.sol";
import { IQuestionView } from "../../questions/interfaces/IQuestionView.sol";

/// @title Interface for viewing Space data and user permissions
/// @dev This interface defines structures and functions for retrieving Space information
Expand Down

0 comments on commit 6d73593

Please sign in to comment.