11 MARKETSUSDG10 S GRIDNEXT FILL 00:10
//09_ Docs

REWARDS

//01_ WHERE REWARDS COME FROM

SOURCEWHENTO PAPER HOLDERSTO TREASURY
Win feea win paid in full from cash50%50%
Loss feea losing close, queue empty50%50%
Liquidation feea liquidation, queue empty50%50%
Excess sweepcash above $75,000, queue empty100%0%

Every fee actually charged is split in two: half to paper holders, half to the treasury. The paper share rounds down and the treasury receives the remainder. The 50% share is a constant of the contract.

The excess sweep is not split. When nobody is queued and the house's cash is above $75,000, pushExcess() sends everything above $75,000 to paper holders. Any address can call it, and the keeper does so about once an hour.

//02_ HOW THEY ARE SHARED

Rewards are paid in proportion to paper held at the moment of each distribution. The contract does this with a single accumulator, without looping over holders:

ACCUMULATOR
distribution of x:
    if totalPaper == 0:   unallocated += x
    else:                 accPerPaper += (x + unallocated) x 1e36 / totalPaper
                          unallocated  = 0

your claimable = rewardsOwed + paper x accPerPaper / 1e36 - rewardDebt

When new paper is minted to you, the rewards earned by the paper you already hold are first set aside in rewardsOwed, then your rewardDebt is reset. New paper earns only from distributions made after it was minted. The fee of a loss is distributed before the loser's paper is minted, so nobody earns on their own fee.

A distribution made while no paper exists yet is held as unallocated and added to the next distribution. Divisions round down; the remainder, a fraction of a base unit per distribution, stays in the contract.

//03_ AN EXAMPLE

Total paper is 50,000 and you hold 5,000, a tenth of it. Then:

EVENTTO PAPER HOLDERSYOUR SHARE
Another trader closes at a $1,000 loss (fee $20)$10.00$1.00
A win of $500 adjusted is paid from cash (fee $10)$5.00$0.50
The keeper sweeps $2,000 of excess$2,000.00$200.00

The trader who lost $1,000 then receives paper on a basis of $980, which dilutes everyone from that point on, you included. Paper total grows with every loss; your share of each future distribution is your paper divided by the total at that moment.

//04_ CLAIMING

claimRewards() moves everything you have earned into your available balance, from where you can withdraw it or use it as margin. Rewards do not expire and can be claimed at any time. Only the wallet can claim: a one-click trading key cannot.

Credits: hands from Michelangelo, The Creation of Adam (detail), public domain, via Wikimedia Commons. Marks of the markets and integrations belong to their owners (sources, credits).