Skip to content

Commit

Permalink
feat(contracts): payout strategy
Browse files Browse the repository at this point in the history
- [x] Use tally as payout strategy
- [x] Add deposit/claim/withdraw functions
- [x] Add tests
- [x] Add pause for tally in poll deploy script
- [x] Update deploy config
- [x] Add tally initialization
- [x] Add batch method for rewards calculation
  • Loading branch information
0xmad committed Oct 24, 2024
1 parent 3b95975 commit a646b7d
Show file tree
Hide file tree
Showing 18 changed files with 1,685 additions and 272 deletions.
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

0 comments on commit a646b7d

Please sign in to comment.