How fees work
- Two fee modes. Percent of the trade’s collateral (
fee_percent,1 = 1%) or a fixed USDC amount per trade (fixed_fee_usdc). - Paid by the trader, in USDC, to your
fee_collector. Charged on-chain at execution time; every charge emits aBuilderFeesChargedevent. - Live config. The fee parameters are read from the registry at trade time, so
modify_builder_code(...)takes effect immediately for all future trades. - Protocol caps. Registration and updates revert above the protocol maximums, currently 1% of collateral and 10 USDC per trade. Read them (and a code’s current config) with
builder_code(...).
Fee-eligible actions
Fees are charged on the actions that open or add exposure. Closes, cancels, margin updates, and TP/SL changes never charge a builder fee.Check a code
Look a code up before registering:registered: False means it’s free to claim. The response also carries the protocol caps:
bytes32 on-chain; pass a plain string of 1-31 characters (right-padded, like referral codes) or a 32-byte 0x hex value.
Register a code
BUILDER_CODE_ALREADY_REGISTERED if the code is taken, and with FEE_PERCENT_TOO_HIGH / FIXED_FEE_TOO_HIGH above the caps.
Update a code
modify_builder_code(...) takes the same parameters and is owner-only. Changes apply to all future trades immediately:
Attach your code to your users’ trades
Fees are charged by the Avantis EIP-7702 delegation template that executes a trade: a builder-specific template carries your code and verifies it against the registry on every fee-eligible call. Wiring your registered code into a template for your order flow is coordinated with the Avantis team, so reach out once your code is registered. Independently of fees, setbuilder_code in the configuration to tag your order flow: the SDK appends the 32-byte value as a calldata suffix to every EIP-7702 transaction it builds (market opens/closes/increases and all relayer-passthrough actions), which Avantis uses for order-flow attribution:
- The suffix rides on every transaction the SDK signs and relays itself (the EIP-7702 route). Intent-only paths that Avantis executes server-side (TWAP intents, the market-maker fast path, and global TP/SL triggers) carry no SDK-built calldata.
- In direct mode the SDK broadcasts plain transactions from the trader’s wallet, which bypasses the delegation template, so no builder fee is charged on those trades.
Track your revenue
Every charge emitsBuilderFeesCharged(trader, feeCollector, builderCode, fee). Like all EIP-7702 activity, the event is emitted from the trader’s EOA, so filter logs by topic across all addresses rather than by a fixed contract address (see events for indexers). RegisteredBuilderCode and ModifiedBuilderCode fire on registry changes.
API endpoints
If you integrate against the HTTP API directly instead of the SDK, the tx-builder exposes a Builder Codes group in the API reference:
The registry contract address is in
GET /addresses under builderCode.
Runnable script: examples/20_builder_code.py.