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

feat(contracts): payout strategy #353

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/contracts/contracts/interfaces/IPayoutStrategy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/// @title IPayoutStrategy
/// @notice Interface responsible for payout strategy
interface IPayoutStrategy {
/// @notice Strategy initialization params
struct StrategyInit {
/// @notice The cooldown duration for withdrawal extra funds
uint256 cooldownTime;
/// @notice The max contribution amount
uint256 maxContribution;
/// @notice The payout token
address payoutToken;
}

/// @notice Claim params
struct Claim {
/// @notice The index of the vote option to verify the correctness of the tally
uint256 index;
/// @notice The voice credit options received for recipient
uint256 voiceCreditsPerOption;
/// @notice Corresponding proof of the tally result
uint256[][] tallyResultProof;
/// @notice The respective salt in the results object in the tally.json
uint256 tallyResultSalt;
/// @notice Depth of the vote option tree
uint8 voteOptionTreeDepth;
/// @notice hashLeftRight(number of spent voice credits, spent salt)
uint256 spentVoiceCreditsHash;
/// @notice hashLeftRight(merkle root of the no spent voice
uint256 perVOSpentVoiceCreditsHash;
}

/// @notice Total deposited amount
function totalAmount() external view returns (uint256);

/// @notice The cooldown timeout
function cooldown() external view returns (uint256);

/// @notice Deposit amount
/// @param amount The amount
function deposit(uint256 amount) external;

/// @notice Withdraw extra amount
/// @param receivers The receivers addresses
/// @param amounts The amounts
function withdrawExtra(address[] calldata receivers, uint256[] calldata amounts) external;

/// @notice Claim funds for recipient
/// @param params The claim params
function claim(Claim calldata params) external;
}
7 changes: 6 additions & 1 deletion packages/contracts/contracts/interfaces/IPoll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ pragma solidity ^0.8.20;
import { IPoll as IPollBase } from "maci-contracts/contracts/interfaces/IPoll.sol";

import { IOwnable } from "./IOwnable.sol";
import { IRecipientRegistry } from "./IRecipientRegistry.sol";

/// @title IPollBase
/// @title IPoll
/// @notice Poll interface
interface IPoll is IPollBase, IOwnable {
/// @notice The initialization function.
Expand All @@ -14,4 +15,8 @@ interface IPoll is IPollBase, IOwnable {
/// @notice Set the poll registry.
/// @param registryAddress The registry address
function setRegistry(address registryAddress) external;

/// @notice Get the poll registry.
/// @return registry The poll registry
function getRegistry() external returns (IRecipientRegistry);
}
18 changes: 15 additions & 3 deletions packages/contracts/contracts/maci/Poll.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 { Poll as BasePoll } from "maci-contracts/contracts/Poll.sol";

import { ICommon } from "../interfaces/ICommon.sol";
import { IRecipientRegistry } from "../interfaces/IRecipientRegistry.sol";

/// @title Poll
/// @notice A Poll contract allows voters to submit encrypted messages
Expand All @@ -16,7 +17,7 @@ contract Poll is Ownable, BasePoll, ICommon {
address public registry;

/// @notice The timestamp of the block at which the Poll was deployed
uint256 internal initTime;
uint256 public initTime;

/// @notice events
event SetRegistry(address indexed registry);
Expand Down Expand Up @@ -90,8 +91,7 @@ contract Poll is Ownable, BasePoll, ICommon {
_;
}

/// @notice A modifier that causes the function to revert if the voting period is
/// over
/// @notice A modifier that causes the function to revert if the voting period is over
modifier isWithinVotingDeadline() override {
uint256 secondsPassed = block.timestamp - initTime;

Expand All @@ -110,6 +110,12 @@ contract Poll is Ownable, BasePoll, ICommon {
emit SetRegistry(registryAddress);
}

/// @notice Get the poll registry.
/// @return registry The poll registry
function getRegistry() public view returns (IRecipientRegistry) {
return IRecipientRegistry(registry);
}

/// @notice The initialization function.
function init() public override onlyOwner isRegistryInitialized {
initTime = block.timestamp;
Expand All @@ -118,6 +124,12 @@ contract Poll is Ownable, BasePoll, ICommon {
emit PollInit();
}

/// @inheritdoc BasePoll
function getDeployTimeAndDuration() public view override returns (uint256 pollDeployTime, uint256 pollDuration) {
pollDeployTime = initTime;
pollDuration = duration;
}

/// @inheritdoc BasePoll
function publishMessage(
Message memory message,
Expand Down
Loading
Loading