# Other Concepts

# Concurrency-Friendly Market Order Clearing Price Algorithm

We apply the split-apply-combine (opens new window) paradigm to leverage concurrency for efficient data processing.

  1. Match all matchable orders (see order matching for details) concurrently in all markets.
  • The intermediate result is a clearing price and a list of matched orders with their fill quantities.
  • The final result is a temporary cache of all new events and all changes to positions, orders, subaccount deposits, trading reward points and fees paid.
  1. Wait for execution on all markets and persist all data.

Note: beyond just executing settlement, the design must also take into account market data dissemination requirements for off-chain consumption.

# Trading Rewards

Governance approves a TradingRewardCampaignLaunchProposal which specifies:

  • The first campaign's starting timestamp
  • The TradingRewardCampaignInfo which specifies
    • The campaign duration in seconds
    • The accepted trading fee quote currency denoms
    • The optional market-specific boost info
    • The disqualified marketIDs for markets in which trades will not earn rewards
  • The CampaignRewardPools which specifies the maximum epoch rewards that constitute the trading rewards pool for each successive campaign

During a given campaign, the exchange will record each trader's cumulative trading reward points obtained from trading fees (with boosts applied, if applicable) from all eligible markets, i.e., markets with a matching quote currency that are not in the disqualified list. Note that by default, negative maker fees will make 0 contribution towards the rewards points. A market with a negative maker fee can however have a negative maker fee boost, which in turn would result in a positive reward point contribution.

At the end of each campaign, i.e., after the campaign starting timestamp + campaign duration has elapsed, each trader will receive a pro-rata percentage of the trading rewards pool based off their trading rewards points from that campaign epoch.

Campaigns will not auto-rollover. If there are no additional campaigns defined inside CampaignRewardPools, the trading reward campaigns will finish.

# Fee Discounts

Governance approves a FeeDiscountProposal which defines a fee discount schedule which specifies fee discount tiers which each specify the maker and taker discounts rates a trader will receive if they satisfy the specified minimum INJ staked amount AND have paid at least the specified trading fee amount (based on the specified quote denoms) over the specified time period (bucket count * bucket duration seconds, which should equal 30 days). The schedule also specifies a list of disqualified marketIDs for markets whose trading fees will not count towards the fee amount contribution.

  • Spot markets where the base and quote are both in the accepted quote currencies list will not be rewarded (e.g. the USDC/USDT spot market).
  • Maker fills in markets with negative maker fees will NOT give the trader any fee discounts, as well as NOT count against a trader's fee paid amount, i.e., a trader's fee paid amount is always non-negative.
  • If the fee discount proposal was passed less than 30 days ago, i.e. BucketCount * BucketDuration hasn't passed yet since the creation of the proposal, the fee paid requirement is ignored so we don't unfairly penalize market makers who onboard immediately.

Internally the fees paid are stored in buckets, typically 30 buckets each lasting 24 hours. When a bucket is older than 30 days, it gets removed. Additionally for performance reasons there is a cache for retrieving the fee discount tier for an account. The cache is updated every 24 hours.