Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Polymarket/ctf-exchange/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The CalculatorHelper library provides utility functions for calculating amounts, prices, fees, and determining whether orders can be matched. All functions are pure and do not modify state.Constants
Precision constant used for price calculations (18 decimals)
Divisor for basis points conversions (10,000 bps = 100%)
Functions
calculateTakingAmount
Calculates the taker amount based on the maker amount being filled.Parameters
The amount of maker tokens being filled in this transaction
The total maker amount from the order
The total taker amount from the order
Returns
The proportional taker amount:
makingAmount * takerAmount / makerAmountReturns 0 if makerAmount is 0Example
calculateFee
Calculates the fee for an order based on outcome tokens and fee rate.Parameters
Fee rate in basis points (100 bps = 1%)
The number of outcome tokens involved in the transaction
The maker amount of the order
The taker amount of the order
The side of the order (
BUY or SELL)Returns
The calculated fee amount
- For BUY orders: Fee charged on token proceeds
- Formula:
feeRateBps * min(price, 1-price) * (outcomeTokens/price) / BPS_DIVISOR
- Formula:
- For SELL orders: Fee charged on collateral proceeds
- Formula:
feeRateBps * min(price, 1-price) * outcomeTokens / (BPS_DIVISOR * ONE)
- Formula:
feeRateBps is 0 or price is invalid (≤ 0 or > 1)Example
calculatePrice
Calculates the price for an order.Parameters
The order to calculate the price for
Returns
The price as an 18-decimal fixed-point number
- For BUY orders:
makerAmount * ONE / takerAmount(price maker is willing to pay) - For SELL orders:
takerAmount * ONE / makerAmount(price maker wants to receive)
_calculatePrice
Internal price calculation function.Parameters
The maker amount
The taker amount
The side of the order
Returns
The calculated price
- If
side == BUY: ReturnsmakerAmount * ONE / takerAmount(or 0 iftakerAmount == 0) - If
side == SELL: ReturnstakerAmount * ONE / makerAmount(or 0 ifmakerAmount == 0)
isCrossing
Determines if two orders can be matched (i.e., their prices cross).Parameters
First order
Second order
Returns
Whether the orders cross and can be matchedReturns
true if either order has zero takerAmount, or if the prices satisfy the crossing condition_isCrossing
Internal crossing calculation function.Parameters
Price of the first order
Price of the second order
Side of the first order
Side of the second order
Returns
Whether the prices cross based on order sidesCrossing conditions:
- Both BUY:
priceA + priceB >= ONE(bid prices sum to ≥ 1) - BUY vs SELL:
priceA >= priceB(bid price ≥ ask price) - SELL vs BUY:
priceB >= priceA(bid price ≥ ask price) - Both SELL:
priceA + priceB <= ONE(ask prices sum to ≤ 1)
min
Returns the minimum of two values.Parameters
First value
Second value
Returns
The smaller of the two values