Skip to main content
@caplane/shared is the order encoding, signing, and registry layer the consumer agent, the relayer, and the el-proxy share. It is the convenience layer; the encoding spec is the contract. You can reimplement the encoding in any language and still be correct. The groups below mirror the package’s index.ts exports. The @caplane/consumer-agent conveniences (the connect() on-ramp) are listed at the end.

Order and hashing

ExportSignaturePurpose
OrderinterfaceThe 8-field order. See the Order struct.
ORDER_TUPLEconstThe ABI tuple mirroring Order field order and types.
encodeOrder(order: Order) => Hexabi.encode(order) via viem’s encodeAbiParameters.
orderHash(order: Order) => Hexkeccak256(encodeOrder(order)), the EIP-3009 nonce.

Signing

ExportSignaturePurpose
TRANSFER_WITH_AUTHORIZATIONconstThe EIP-3009 typed-data schema (nonce is bytes32).
buildTransferAuthorization(domain, order, broker, validAfter, validBefore) => TransferAuthorizationThe unsigned authorization (pure; testable against a golden digest).
transferAuthDigest(auth: TransferAuthorization) => HexThe EIP-712 digest the token verifies.
signOrder(account, domain, order, broker, validAfter, validBefore) => Promise<SignedAuthorization>Sign the authorization with nonce = orderHash. Returns { v, r, s, validAfter, validBefore, orderHash }.
SignedAuthorizationinterfaceThe split signature plus the window and the bound orderHash.

Wire and relayer types

ExportSignaturePurpose
orderToJson(order: Order) => OrderJsonSerialize an order to its wire shape (uint256 as decimal strings).
orderFromJson(json: OrderJson) => OrderParse an order from its wire shape.
RELAY_ERROR_STATUSRecord<RelayErrorCode, number>The code to HTTP status map.
RelayRequestinterfaceThe POST /broker body.
RelaySuccessinterfaceThe 200 response (ok, txHash, orderHash, brokered, receipt, feeCollected).
RelayFailureinterfaceThe error response (ok: false, code, message). Carries no key material.
RelayResponsetypeThe union RelaySuccess or RelayFailure.
RelayErrorCodetypeThe seven settlement error codes. See errors.
RelayerInfointerfaceThe GET /info body (feeFloorBps, supportedChainIds, relayer).
OrderJsoninterfaceThe order’s JSON wire shape.

Registry and discovery

Addresses are never hard-coded. They are read from the registry, which is the single trust root.
ExportSignaturePurpose
loadRegistry(chainId, opts?) => RegistryLoad a chain’s registry (contracts, USDC domain, rpcUrl, explorer).
loadChain(chainId, opts?) => RegistryAlias used by connect().
resolveDeploymentsDir(opts?) => stringResolve the deployments directory.
resolveCapability(name, opts?) => ResolvedCapabilityResolve a capability to its chain and adapter address. Fails closed on an unknown capability.
listCapabilities(opts?) => string[]The capability names available.
loadCapabilities(opts?) => CapabilitiesFileParse capabilities.json.
domainFromRegistry(registry) => Eip712DomainBuild the USDC EIP-712 domain.
CHAIN_IDSconst{ arbitrumSepolia: 421614, robinhoodTestnet: 46630 }.
REGISTRY_FILESconstThe registry file names per chain.
Registry, RegistryUsdc, RegistryTimeboost, Eip712Domain, CapabilitySpec, ResolvedCapabilitytypesThe registry and capability shapes.

Attestation (for the AttestedAdapter)

The optional provider attestation surface, used by the AttestedAdapter. Exports: ATTESTATION_TYPES, ATTESTOR_DOMAIN_NAME, ATTESTOR_DOMAIN_VERSION, OFFCHAIN_VERIFYING_CONTRACT, buildAttestation, attestationDigest, signAttestation, recoverAttestor, verifyAttestation, encodeAttestedParams, paramsSubject, and the Attestation / AttestorDomain types. These build, sign, and verify the EIP-712 attestation an AttestedAdapter checks at grant time.

Consumer conveniences (@caplane/consumer-agent)

The on-ramp over the surface above. Documented end to end in broker a capability.
ExportSignaturePurpose
connect(opts: ConnectOptions) => Promise<CaplaneClient>Registry-bound, key-free client. Exposes buyAllocation and the generic broker.
discover(publicClient, adapter, params) => Promise<Quote>Read adapter.quote(params) for { price, payToken }.
buildOrder(args: BuildOrderArgs) => OrderAssemble an order; nonce defaults to a random salt.
randomNonce() => bigintA random 256-bit salt for order.nonce.
submit(relayerUrl, order, sig, chainId, opts?) => Promise<RelaySuccess>POST the signed order; throws SubmitError(code) on rejection.
SubmitErrorclassA typed submit failure carrying the RelayErrorCode.
encodeAllocationParams(vaultId: bigint) => Hexabi.encode(uint256 vaultId) for the Allocation adapter.
decodeAllocationReceipt(receipt: Hex) => bigintDecode an Allocation grant receipt to the minted slot id.

See also