Skip to content

Create pirc_allocation_design2.js#2

Merged
Tsukimarf merged 3 commits intoTsukimarf-patch-1from
Tsukimarf-patch-2
Apr 17, 2026
Merged

Create pirc_allocation_design2.js#2
Tsukimarf merged 3 commits intoTsukimarf-patch-1from
Tsukimarf-patch-2

Conversation

@Tsukimarf
Copy link
Copy Markdown
Owner

@Tsukimarf Tsukimarf commented Apr 17, 2026

Summary by Sourcery

Add a new JavaScript module implementing the PiRC allocation period design option 2 with a static configuration and calculation engine for liquidity pool formation using deposits and swaps.

New Features:

  • Introduce a static in-code database describing allocation parameters, token and Pi splits, and process steps for PiRC allocation design option 2.
  • Provide a PiRCAllocationCalculator class to compute listing prices, AMM pool parameters, participant allocations, discounts, and effective price curves.
  • Add a runnable demo that logs pool summaries, effective price curves, participant allocation examples, and static configuration data.
  • Export the allocation database and calculator class for reuse in other Node or ES module contexts.

Summary by cubic

Implements Allocation Design Option 2 as an executable model for LP formation using deposits and swaps. Adds a calculation engine and reference data for prices, discounts, and participant allocations.

  • New Features
    • Added PIRC_ALLOCATION_DB with steps, token/Pi splits, LP fee, discount-to-lockup policy, and effective-price reference points.
    • Introduced PiRCAllocationCalculator for listing price, AMM invariant, swap price and normalized price, effective price, and discount (with input validation).
    • Exposed participantSummary, effectivePriceCurve, and poolSummary (includes min/max effective prices and discounts).
    • Included a runnable console demo and Node/ES module exports.

Written for commit 75d0287. Summary will update on new commits.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 17, 2026

Reviewer's Guide

Adds a self-contained JavaScript model and demo harness for PiRC Allocation Design Option 2, including a static data specification and a calculator class to compute pool parameters, swap pricing, participant-level allocations, and effective price curves for engagement-based LP swaps.

Sequence diagram for runDemo allocation calculation flow

sequenceDiagram
  actor Developer
  participant NodeProcess
  participant PiRCAllocationCalculator
  participant Console
  participant PIRC_ALLOCATION_DB

  Developer->>NodeProcess: execute script
  NodeProcess->>NodeProcess: runDemo()

  NodeProcess->>PiRCAllocationCalculator: new PiRCAllocationCalculator(1000000, 400000)
  PiRCAllocationCalculator-->>NodeProcess: instance

  NodeProcess->>PiRCAllocationCalculator: poolSummary()
  PiRCAllocationCalculator-->>NodeProcess: summaryObject
  NodeProcess->>Console: table(summaryObject)

  NodeProcess->>PiRCAllocationCalculator: effectivePriceCurve(11)
  PiRCAllocationCalculator-->>NodeProcess: curveData[]
  NodeProcess->>Console: table(curveData[])

  NodeProcess->>PiRCAllocationCalculator: participantSummary(1000, 0)
  PiRCAllocationCalculator-->>NodeProcess: mostEngagedSummary
  NodeProcess->>Console: table(mostEngagedSummary)

  NodeProcess->>PiRCAllocationCalculator: participantSummary(1000, 200000)
  PiRCAllocationCalculator-->>NodeProcess: leastEngagedSummary
  NodeProcess->>Console: table(leastEngagedSummary)

  NodeProcess->>PIRC_ALLOCATION_DB: access steps[0]
  PIRC_ALLOCATION_DB-->>NodeProcess: firstStepConfig
  NodeProcess->>Console: log(firstStepConfig)
Loading

Class diagram for PiRCAllocationCalculator and static allocation model

classDiagram
  class PIRC_ALLOCATION_DB {
    <<object>>
    document
    notation
    tokenSplit
    piSplit
    steps
    effectivePriceData
  }

  class PiRCAllocationCalculator {
    - number T
    - number C
    - number p_list
    - number k
    - number x0
    - number y0
    - number p_init
    + PiRCAllocationCalculator(number T, number C)
    + xAtS(number s) number
    + yAtS(number s) number
    + pSwap(number s) number
    + pSwapNorm(number s) number
    + pEff(number s) number
    + discountPercent(number s) number
    + participantSummary(number piCommitted, number s) object
    + effectivePriceCurve(number n) object[]
    + poolSummary() object
  }

  class RunDemoModule {
    <<module>>
    + runDemo() void
  }

  RunDemoModule ..> PiRCAllocationCalculator : creates
  RunDemoModule ..> PIRC_ALLOCATION_DB : reads
Loading

File-Level Changes

Change Details Files
Introduce a static allocation design database mirroring the Design Option 2 spec for tokens, Pi splits, process steps, and effective price samples.
  • Define PIRC_ALLOCATION_DB with document metadata, notation, token and Pi allocation splits, procedural steps, and precomputed effective price normalization data.
  • Encode key business parameters such as listing price formula, LP portion, fixed-price portion, Pi bucket fractions, and engagement-based swap configuration.
PiRC1/4-allocation/pirc_allocation_design2.js
Implement a PiRCAllocationCalculator engine that models LP behavior, swap pricing, participant allocation, and effective price curves based on total tokens T and committed Pi C.
  • Validate constructor inputs and derive core invariants such as listing price, constant-product k, initial LP reserves, and initial spot price.
  • Provide methods for reserve evolution over cumulative swaps, marginal swap price, normalized price, effective blended price (harmonic mean), discount percentage, and pool-level summary metrics.
  • Add participantSummary to compute per-user bucket A/B token allocations, effective acquisition price, and discount for a given Pi commitment and engagement rank.
  • Add effectivePriceCurve to generate a discretized curve of swap and effective prices over the 0..C/2 cumulative swap range.
PiRC1/4-allocation/pirc_allocation_design2.js
Add a demo harness that showcases calculator outputs and expose the module for Node/ES module consumption.
  • Create runDemo to instantiate the calculator with example T and C values, log pool summary, effective price curve, and sample participant summaries for most/least engaged cases.
  • Print a sample of the static DB to verify it matches the spec and wire up module.exports for PIRC_ALLOCATION_DB and PiRCAllocationCalculator when running under CommonJS.
PiRC1/4-allocation/pirc_allocation_design2.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues, and left some high level feedback:

  • Consider removing or guarding the top-level runDemo() call so that importing this module in other code (or tests) does not trigger console output and side effects by default.
  • participantSummary and discountPercent accept any s value without bounds checking; adding validation (e.g., 0 <= s <= C/2) would prevent nonsensical or out-of-range usage.
  • The constructor only checks that T and C are positive; adding type checks (e.g., ensuring they are finite numbers) would make the API more robust against invalid inputs.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider removing or guarding the top-level `runDemo()` call so that importing this module in other code (or tests) does not trigger console output and side effects by default.
- `participantSummary` and `discountPercent` accept any `s` value without bounds checking; adding validation (e.g., `0 <= s <= C/2`) would prevent nonsensical or out-of-range usage.
- The constructor only checks that `T` and `C` are positive; adding type checks (e.g., ensuring they are finite numbers) would make the API more robust against invalid inputs.

## Individual Comments

### Comment 1
<location path="PiRC1/4-allocation/pirc_allocation_design2.js" line_range="105-108" />
<code_context>
+   * @param {number} T - Total token launch allocation
+   * @param {number} C - Total Pi committed by all participants
+   */
+  constructor(T, C) {
+    if (T <= 0 || C <= 0) throw new Error("T and C must be positive numbers.");
+    this.T = T;
+    this.C = C;
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider validating that T and C are finite numbers, not just positive values.

Non-finite or non-numeric values (e.g. strings, `NaN`, `Infinity`) currently pass this check and can later produce `NaN` or infinite pricing/pool parameters. Using `Number.isFinite(T)` / `Number.isFinite(C)` (or explicitly coercing then validating) would fail fast and keep downstream calculations well-defined.

```suggestion
  constructor(T, C) {
    if (!Number.isFinite(T) || !Number.isFinite(C) || T <= 0 || C <= 0) {
      throw new Error("T and C must be finite positive numbers.");
    }
    this.T = T;
    this.C = C;
```
</issue_to_address>

### Comment 2
<location path="PiRC1/4-allocation/pirc_allocation_design2.js" line_range="155-156" />
<code_context>
+   * @param {number} s           - Cumulative Pi swapped into LP at this participant's rank
+   * @returns {object}
+   */
+  participantSummary(piCommitted, s) {
+    const halfPi        = piCommitted / 2;
+
+    // Bucket A: fixed-price tokens
</code_context>
<issue_to_address>
**issue:** Add guardrails for `piCommitted` and `s` to avoid invalid or out-of-range inputs.

If `piCommitted` is non‑positive or `s` falls outside the intended `[0, C/2]` range, this can yield invalid allocations (e.g., negative discounts or unbounded prices) without any error. Please validate `piCommitted > 0` and either clamp or reject `s` outside the supported range so downstream consumers can trust the summary values.
</issue_to_address>

### Comment 3
<location path="PiRC1/4-allocation/pirc_allocation_design2.js" line_range="184-198" />
<code_context>
+    const halfC = this.C / 2;
+    return Array.from({ length: n }, (_, i) => {
+      const s = (i / (n - 1)) * halfC;
+      return {
+        s,
+        sFraction:    s / halfC,
+        pSwap:        this.pSwap(s),
+        pSwapNorm:    this.pSwapNorm(s),
+        pEff:         this.pEff(s),
+        pEffNorm:     this.pEff(s) / this.p_list,
+        discount:     this.discountPercent(s),
</code_context>
<issue_to_address>
**suggestion:** Avoid recomputing `pEff(s)` to keep the curve output self-consistent and slightly more efficient.

In `effectivePriceCurve`, you call `this.pEff(s)` twice (for `pEff` and `pEffNorm`). Store it once in a local `const pEff = this.pEff(s);` and use that for both fields to avoid duplicate work and guarantee they always stay in sync if `pEff` changes later.

```suggestion
  effectivePriceCurve(n = 11) {
    const halfC = this.C / 2;
    return Array.from({ length: n }, (_, i) => {
      const s = (i / (n - 1)) * halfC;
      const pEff = this.pEff(s);
      return {
        s,
        sFraction:    s / halfC,
        pSwap:        this.pSwap(s),
        pSwapNorm:    this.pSwapNorm(s),
        pEff:         pEff,
        pEffNorm:     pEff / this.p_list,
        discount:     this.discountPercent(s),
      };
    });
  }
```
</issue_to_address>

### Comment 4
<location path="PiRC1/4-allocation/pirc_allocation_design2.js" line_range="242" />
<code_context>
+  console.log(JSON.stringify(PIRC_ALLOCATION_DB.steps[0], null, 2));
+}
+
+runDemo();
+
+// ─────────────────────────────────────────────
</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid executing the demo automatically on import to prevent side effects in consumers.

Unconditional `runDemo()` causes console output and side effects whenever this module is imported, which is problematic for library consumers. Please gate this behind an entry-point check (e.g., `if (require.main === module)` in CommonJS or a separate CLI) so the demo only runs when executed directly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread PiRC1/4-allocation/pirc_allocation_design2.js
Comment thread PiRC1/4-allocation/pirc_allocation_design2.js
Comment thread PiRC1/4-allocation/pirc_allocation_design2.js
Comment thread PiRC1/4-allocation/pirc_allocation_design2.js
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="PiRC1/4-allocation/pirc_allocation_design2.js">

<violation number="1" location="PiRC1/4-allocation/pirc_allocation_design2.js:106">
P2: This guard does not reject `NaN`, `Infinity`, or non-numeric inputs. In JavaScript, `NaN <= 0` is `false`, so `NaN` silently passes through and contaminates every derived value (`p_list`, `k`, reserves, prices). Use `Number.isFinite()` to fail fast on non-finite inputs.</violation>

<violation number="2" location="PiRC1/4-allocation/pirc_allocation_design2.js:242">
P2: Avoid unconditional `runDemo()` execution on import; gate it so demo code only runs when this file is executed directly.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread PiRC1/4-allocation/pirc_allocation_design2.js
Comment thread PiRC1/4-allocation/pirc_allocation_design2.js Outdated
Tsukimarf and others added 2 commits April 18, 2026 06:12
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@Tsukimarf Tsukimarf merged commit 0e4709a into Tsukimarf-patch-1 Apr 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant