Skip to main content
brokerCapability settles the payment, grants the capability, and pays out, in one transaction. It is the only state-changing function an integrator calls on the broker. For why the steps are ordered this way, see how a brokerage settles; this page is the surface.

Signature

function brokerCapability(
    Order calldata order,
    uint256 validAfter,
    uint256 validBefore,
    uint8 v,
    bytes32 r,
    bytes32 s
) external nonReentrant returns (bytes32 orderHash, bytes memory receipt);

Parameters

ParameterTypeDescription
orderOrderThe capability order. Its 8 fields are documented in the Order struct.
validAfteruint256EIP-3009 lower time bound of the consumer’s authorization (unix seconds; 0 for no lower bound).
validBeforeuint256EIP-3009 upper time bound (unix seconds).
vuint8Consumer signature recovery byte.
rbytes32Consumer signature r.
sbytes32Consumer signature s.

Returns

ReturnTypeDescription
orderHashbytes32keccak256(abi.encode(order)), the EIP-3009 nonce that was settled.
receiptbytesThe opaque adapter receipt for the grant (the adapter defines its shape).

The flow

The broker recomputes orderHash = keccak256(abi.encode(order)) from the order itself, then, in one transaction:
  1. Settle. It calls payToken.transferWithAuthorization(order.consumer, broker, order.amount, validAfter, validBefore, orderHash, v, r, s). The token verifies the consumer’s signature over the order hash and pulls amount to the broker.
  2. Grant. It calls adapter.grant(order.consumer, order.params). A revert here unwinds the settlement; the consumer is not charged.
  3. Pay out. fee = order.amount * order.feeBps / 10000. The provider (order.payee) receives order.amount - fee; the relayer (msg.sender) receives fee. Zero-value legs are skipped.
BPS_DENOMINATOR is 10000. The payout uses SafeERC20.

The Brokered event

Emitted once on success. The indexing matters for an indexer: orderHash, consumer, and adapter are indexed topics; the rest are in the data.
event Brokered(
    bytes32 indexed orderHash,
    address indexed consumer,
    address indexed adapter,
    address relayer,
    uint256 amount,
    uint256 fee,
    bytes receipt
);

Reverts

RevertWhen
FeeTooHigh()order.feeBps > 10000. Checked before settlement.
ReentrancyGuardReentrantCall()A reentrant call into the broker mid-settlement (nonReentrant).
SafeERC20FailedOperation(address token)A payout transfer failed.
Settlement also reverts on a tampered order (the token rejects the signature), an expired authorization, a used nonce, or any adapter revert (sold out, no lane control). The full catalog is in errors and reverts.

ABI

[
  {
    "type": "function",
    "name": "brokerCapability",
    "stateMutability": "nonpayable",
    "inputs": [
      { "name": "order", "type": "tuple", "components": [
        { "name": "consumer", "type": "address" },
        { "name": "adapter", "type": "address" },
        { "name": "params", "type": "bytes" },
        { "name": "payToken", "type": "address" },
        { "name": "amount", "type": "uint256" },
        { "name": "feeBps", "type": "uint16" },
        { "name": "payee", "type": "address" },
        { "name": "nonce", "type": "uint256" }
      ]},
      { "name": "validAfter", "type": "uint256" },
      { "name": "validBefore", "type": "uint256" },
      { "name": "v", "type": "uint8" },
      { "name": "r", "type": "bytes32" },
      { "name": "s", "type": "bytes32" }
    ],
    "outputs": [
      { "name": "orderHash", "type": "bytes32" },
      { "name": "receipt", "type": "bytes" }
    ]
  },
  {
    "type": "event",
    "name": "Brokered",
    "anonymous": false,
    "inputs": [
      { "name": "orderHash", "type": "bytes32", "indexed": true },
      { "name": "consumer", "type": "address", "indexed": true },
      { "name": "adapter", "type": "address", "indexed": true },
      { "name": "relayer", "type": "address", "indexed": false },
      { "name": "amount", "type": "uint256", "indexed": false },
      { "name": "fee", "type": "uint256", "indexed": false },
      { "name": "receipt", "type": "bytes", "indexed": false }
    ]
  },
  { "type": "error", "name": "FeeTooHigh", "inputs": [] }
]

See also