#quadratic #contributions #calculations #random #matching #cap #funding

bin+lib pluralistic-rs

A Rust crate for Quadratic Funding calculations

2 unstable releases

0.2.0 Feb 5, 2024
0.1.0 Jan 23, 2024

#13 in #quadratic

MIT license

13KB
220 lines

pluralistic-rs

Overview

The pluralistic-rs library is a Rust crate providing functionality to calculate quadratic funding distributions based on a set of contributions. The library includes a robust implementation for generating random contributions, managing contributions, and applying quadratic funding formulas to distribute a matching pot of funds.

Features

  • Quadratic Funding Calculation: Calculate funding distributions using the calculate_linear_qf function.
  • Matching Upscale: Upscale matching to saturate a round.
  • Matching Cap Strategies: Apply different cap strategies (Cap and Redistribute) using MatchingCapStrategy.
  • Random Contribution Generation: Generate random contributions with the Random trait implemented for Contribution.

Installation

Add pluralistic-rs to your Cargo.toml dependencies:

[dependencies]
pluralistic-rs = "0.1.0"

Usage

  1. Defining Contributions: Contributions are represented by the Contribution struct, which includes sender, recipient, and amount details.

  2. Calculating Distributions: Use calculate_linear_qf to calculate the quadratic funding distribution based on the contributions, matching pot, and options provided.

  3. Applying Cap Strategies: Utilize the MatchingCapStrategy to define how contributions are capped or redistributed when necessary.

  4. Generating Random Contributions: Use the Random trait to generate random contributions for testing and simulation purposes.

Example

use pluralistic_rs::{Contribution, calculate_linear_qf, LinearQfOptions, Random};

fn main() {
    // Generate random contributions
    let contributions = vec![Contribution::rnd(), Contribution::rnd(), ...];

    // Define options for quadratic funding calculation
    let options = LinearQfOptions {
        matching_cap_amount: Some(1000.0),
        matching_cap_strategy: MatchingCapStrategy::Cap,
        ..Default::default()
    };

    // Calculate distributions
    let distributions = calculate_linear_qf(contributions, 5000.0, options);

    // Process distributions...
}

Testing

The library includes a tests module with test cases to ensure the functionality works as expected.

Dependencies

  • rand: Used for generating random contributions and other randomness-related functionalities.

License

MIT

Dependencies

~9–19MB
~275K SLoC