How it actually works
Builder codes
Frontends that the owner approves as builders earn a fee on the PnL of the positions their users close, at a rate the trader signed off on.
What a builder code is
The session-key registration a trader signs (RegisterSessionKeyV2) names an address in its feeAddress field, the frontend’s builder code, and in maxBuilderFee the highest rate the trader agrees to pay it. While that address is an approved builder, every position the key closes pays it the lower of the builder’s own rate and that signed maximum. A key registered with the original RegisterSessionKey type carries no consent and earns a builder nothing. The app names no builder, and every trade, whichever frontend sends it, is submitted by the relayer.
What it costs
- Wins. The trader pays the builder its rate, at most 0.5% of the scaled gain, on top of the 2% win fee and the referral fee.
- Losses. The builder’s share of the loss comes out of what the LP gains, so the trader’s loss is unchanged. It is left out of the loss’s mint basis.
- Never on liquidations, and that includes a close at or past the bust price, which settles as one.
- Within the total. The base fee, the referral fee and the builder fee together never exceed 15% of the basis: a builder’s rate is clamped into whatever room the other two leave.
A builder is credited only while the payout queue is empty and the LP can fund the fee, the same rule as for the protocol’s own fees. When it cannot, a winner still pays the fee and it stays with the LP.
Approved builders only
- The owner approves each builder through the 2 days timelock.
- The governance Safe can remove a builder at once. A removal stops the fee on every key that names it; the keys keep working.
- Each builder sets its own rate, up to the owner’s ceiling of 0.5%. The owner can move the ceiling through the timelock, up to 15%; lowering it under a builder’s rate clamps what that builder earns.
- A registration that names an address that is not an approved builder is refused, by the relayer and by the contract; so is one that names a builder without a signed maximum, which would earn nothing.
For builders
- Name your builder address in
feeAddresswhen your users signRegisterSessionKeyV2, with the maximum rate they agree to inmaxBuilderFee; set your own rate on the registry withsetFeeRate, under the ceiling. - Earned fees accrue on the Exchange:
builderFees(address)shows yours. - Claim them with
claimBuilderFees()on the Exchange, sent from your builder address. The claim credits your exchange balance; any part the LP cannot cover at that moment joins the payout queue. Fees earned before a removal stay claimable. - Lost key: the owner can move your unclaimed fees to a new address through the timelock (
moveBuilderFees).
Until they are claimed, builder fees are owed by the LP: they stay inside LP cash and count against tracked LP value (see Solvency & queue). The BuilderRegistry’s address is on Contracts.