Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Add reward calculation example#9

Open
erdinc333 wants to merge 3 commits into
Polymarket:mainfrom
erdinc333:main
Open

Add reward calculation example#9
erdinc333 wants to merge 3 commits into
Polymarket:mainfrom
erdinc333:main

Conversation

@erdinc333

@erdinc333 erdinc333 commented Nov 23, 2025

Copy link
Copy Markdown

Added a standalone TypeScript example for calculating liquidity rewards using additive spread logic.


Note

Adds a standalone TypeScript script and README to fetch market/order book data, sort bids/asks, compute additive-spread depth, and estimate daily rewards per outcome.

  • Example Script (reward-calculation/calculate-rewards.ts):
    • Fetches event/market data from Gamma API and order books from CLOB API.
    • Parses clobTokenIds/outcomes, iterates outcomes, and computes mid-price from best bid/ask.
    • Correctly sorts order books (bids desc, asks asc).
    • Calculates depth within additive spreads (±$0.01/0.02/0.03) and estimates daily rewards using rewardsDailyRate, investment amount, and mid-price weighting.
    • Logs per-outcome mid-price, depth breakdown, and estimated daily rewards.
  • Docs (reward-calculation/README.md):
    • Describes features, usage (via ts-node), and logic overview (sorting, additive spread, depth calculation).

Written by Cursor Bugbot for commit 6ed7731. This will update automatically on new commits. Configure here.

Comment thread reward-calculation/calculate-rewards.ts
// In reality, rewards are split by outcome probability.
const userShare = INVESTMENT_AMOUNT / (totalDepth + INVESTMENT_AMOUNT);
// Adjust reward by probability (approximate using price)
const outcomeRewardPool = dailyRewardPool * midPrice;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Reward pool allocation can exceed 100%

The calculation multiplies dailyRewardPool by midPrice for each outcome independently. Since midPrices across outcomes don't necessarily sum to 1.0 due to bid-ask spreads, the total allocated rewards across all outcomes can exceed the actual daily reward pool, making the reward estimates inaccurate.

Fix in Cursor Fix in Web

Comment thread reward-calculation/calculate-rewards.ts
Comment thread reward-calculation/calculate-rewards.ts
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant