allo-protocol / allo-v2

Core Allo V2 Contracts
GNU Affero General Public License v3.0
90 stars 73 forks source link

Add QFLibrary for Quadratic Funding #609

Closed 0xOneTony closed 4 months ago

0xOneTony commented 4 months ago

Problem

Basic mechanisms like Quadratic Voting/Funding should be abstracted into a trusted, optimized library. Provide helper functions for specific actions in different strategies.

Solution

Resources

Spec for QFLibrary

library QFHelper {
    using EnumerableSet for EnumerableSet.AddressSet;
    using SafeMath for uint256;

    /// Struct that defines a donation
    struct Donation {
        uint256 amount;
        address funder;
    }

    /// Struct that defines the state of the donations to recipients
    struct State {
        EnumerableSet.AddressSet recipients;
        mapping(address => Donation[]) donations;
        /// The square of total contributions for each recipient
        mapping(address => uint256) contributionsSquare;
    }

    /// Calculate the square root of a given number
    function _sqrt(uint256 x) internal pure returns (uint256 y) {}

    /// Donate to a recipient to allocate
    function fundRecipients(
        State storage _state,
        address[] memory _recipients,
        uint256[] memory _amounts
    ) internal {}

    function getPayOutForRecipient(State storage _state, address _recipient) internal view returns (uint256) {}

    function calculateDivisor(uint256 _matchingAmount, uint256 _totalContributions) internal view returns (uint256) {
        return _matchingAmount.div(_totalContributions);
    }

    /// Quadratic Formula
    function calculatePayout(State storage _state, address _recipient, uint256 _matchingAmount) internal view returns (uint256 _recipientPayout) {}
}