SDK Reference
Function-level API map for the Collateral Rail SDK.
Purpose
@steerprotocol/collateral-rail-sdk is designed around two guarantees:
- Typed runtime paths for browser and Node.js.
- No hidden transaction signing assumptions (clients are explicit inputs).
This page is a practical lookup for what to use in production code.
Public exports
The package root exports:
clienthelpers (src/client.ts)swaphelpers (src/swap.ts)contractshelpers (src/contracts.ts)onboardinghelpers (src/onboarding.ts)eventsparsing (src/events.ts)errorsdecoding (src/errors.ts)generatedtyped wagmi actions (src/generated/contracts.ts)protocolTypesfor all major payload shapes
Client construction
| Helper | Category | What it returns |
|---|---|---|
createProtocolPublicClient | core | PublicClient |
createProtocolWalletClient | core | WalletClient |
createProtocolClients | core | { publicClient, walletClient } |
clientsFromWagmiConfig | browser | { publicClient, walletClient } |
customProviderTransport | integration | viem Transport |
Example
import { createProtocolClients } from "@steerprotocol/collateral-rail-sdk";
import { optimismSepolia } from "viem/chains";
const { publicClient, walletClient } = createProtocolClients({
chain: optimismSepolia,
rpcUrl: "https://rpc.example",
});Swap utilities
| Helper | Input | Output |
|---|---|---|
inferSwapDirection | SwapParams | { direction, absoluteAmount } |
resolveHookData | hookData? | raw hookData or empty bytes |
previewCollateralSwapFromParams | SwapParams | { intent, shouldSettle, hookData } |
buildSwapIntent | SwapParams, hookData?, signedSwapQuote? | { intent, shouldSettle, hookData } |
buildSwapCallDescriptor | SwapExecutionInput | viem call descriptor |
buildExactInputSignedQuoteCallDescriptor | ExactInputSignedQuoteExecutionInput | executor call descriptor |
buildExactOutputSignedQuoteCallDescriptor | ExactOutputSignedQuoteExecutionInput | executor call descriptor |
buildTargetOutputSignedQuoteCallDescriptor | TargetOutputSignedQuoteExecutionInput | executor call descriptor |
buildSignedSwapQuotePayload | (walletClient, collateralManager, chainId, quote, account) | signed quote payload Hex |
buildSignedSwapQuoteDigest | (collateralManager, chainId, quote) | signed quote digest Hex |
simulateSwap | PublicClient, SwapExecutionInput | simulation result |
executeSwap | WalletClient, SwapExecutionInput (+ optional account) | tx hash |
defaultSwapDeadline | offset (seconds) | unix epoch bigint |
isSignedSwapQuoteData | Hex payload | boolean |
encodeSignedSwapQuotePayload | SignedSwapQuote | Hex |
splitSignature | ECDSA signature Hex | { v, r, s } |
signSignedSwapQuote | (walletClient, collateralManager, chainId, quote, account) | SignedSwapQuote |
Signing controls vault settlement
buildSwapIntent and buildSwapCallDescriptor support empty or explicit hook data. Quote-price-only legacy metadata is intentionally not generated by the SDK. If signedSwapQuote is supplied, its encoded payload is used directly as hookData for signed quote vault settlement.
Signed quote execution
Production signed quote vault swaps should use the SignedCollateralSwapRouter helpers with signed quote hook data. They expose sqrtPriceLimitX96 as a first-class native v4 price boundary; 0n means the executor will apply the direction-based unbounded default. Final slippage remains amountOutMin or amountInMax, and non-signed hookData remains pure AMM metadata only.
Signed quote types
signedQuote.ts exports:
SignedSwapQuote(fully signed quote payload)SignedSwapQuoteBase(unsigned quote values)SignedSwapQuoteSignature(v,r,s)SIGNED_SWAP_QUOTE_ENCODED_LENGTH_BYTES
Signed quote schema (normative)
| Field | Type | Unit / format | Notes |
|---|---|---|---|
poolId | bytes32 | exact on-chain pool id | Must match the pool for this swap |
trader | address | EIP-55 address | Must match swap sender/trader binding |
maxAbsAmount | uint256 | token base units | Must be >= abs(amountSpecified) |
quotedPriceE18 | uint256 | 1e18 fixed-point | Checked against oracle policy envelope |
expiry | uint64 | Unix timestamp (seconds) | Expired quotes revert |
v | uint8 | 27 or 28 | Signature recovery id |
r | bytes32 | hex | Signature component |
s | bytes32 | hex | Signature component |
Encoding notes:
- SDK payload version is
1. - Encoded signed quote payload length is
288bytes (SIGNED_SWAP_QUOTE_ENCODED_LENGTH_BYTES). - Replay keys are derived on-chain from the signed envelope, recovered signer, chain id, and collateral manager address.
EIP-712 domain and typed data
Signed quote helpers (signSignedSwapQuote, buildSignedSwapQuoteDigest) use:
domain.name = "CollateralManager"domain.version = "1"domain.chainId = <target chain id>domain.verifyingContract = <collateral manager address>primaryType = "SignedSwapQuote"
SignedSwapQuote typed fields:
poolId: bytes32trader: addressmaxAbsAmount: uint256quotedPrice: uint256expiry: uint64
Core collateral flow
| Helper | Function |
|---|---|
getCollateralManagerMaxMintable | Read max mint for account |
getCollateralManagerBalance | Read collateral or debt balance |
totalDebt | Read protocol debt denominator |
getCollateralManagerConfig | Read config bundle from manager |
depositCollateral | Write collateral in |
withdrawCollateral | Write collateral out |
mintStableForAccount | Mint stable on behalf of user |
redeemStableForAccount | Redeem stable to collateral |
previewCollateralManagerSwap | Read settlement intent |
settleCollateralManagerSwap | Write post-swap settlement |
Helper safety classification
| Helper group | Intended audience | Notes |
|---|---|---|
client + signed quote swap builders (create*Client, buildExactInputSignedQuoteCallDescriptor, buildExactOutputSignedQuoteCallDescriptor, buildTargetOutputSignedQuoteCallDescriptor) | app integrators | Standard production integration path |
read helpers (get*, previewCollateralManagerSwap) | app integrators, operators | Safe for read-only planning and monitoring |
admin writers (set*, guardian helpers) | operators/governance | Require privileged roles |
settleCollateralManagerSwap | hook-authorized contexts only | For protocol callback flows, simulations, and specialized operator tooling; not normal end-user app execution |
Settlement preview vs. settle
- Use
previewCollateralManagerSwapto get deterministic settlement direction. - Use
settleCollateralManagerSwapwith the actual callbackpoolDeltafrom the swap execution. - Any preview and settlement mismatches should be treated as runtime observability events, not hidden failures.
Risk and governance
RiskConfig
getRiskConfigCollateral,setRiskConfigCollateralgetRiskConfigGlobal,setRiskConfigGlobal,setRiskConfigSafeModeguardianSetSafeMode
Hook controls
getHookPoolRiskConfig,setHookPoolRiskConfigsetHookOracleAdaptersetHookGlobalSafeMode
CollateralManager controls
setCollateralManagerOracleAdaptersetCollateralManagerSettlementHooksetCollateralManagerDegradedHaircut
Oracle controls
getOracleCollateralConfig,setOracleCollateralConfiggetOracleEffectivePricesetOracleGlobalPaused
Stablecoin controls
setStablecoinMinter,getStablecoinIsMinter
Launch automation
The launch helpers compose and validate the operational sequence before you broadcast:
withDefaultsCollateralConfigwithDefaultsGlobalConfigwithDefaultsPoolRiskConfigwithDefaultsOracleConfigvalidateLaunchInputbuildLaunchStepsbuildLaunchCallDescriptors
Use these with a multisig flow and a pre-transaction dry-run checklist.
Events and errors
| Helper | Purpose |
|---|---|
parseHookRiskEvaluatedLogs | Decode risk gating events from a list of logs |
parseHookSettlementLogs | Decode settlement callback outcomes |
parseAfterSwapSettlementLogs | Decode post-settlement AMM reconciliation |
parseEventsFromReceipt | Group all protocol events from tx receipt |
parseError | Decode reverted protocol error reason |
getErrorMessage | Return compact {source}.{name} string |
Generated wagmi actions
The generated namespace contains optional typed read/write/simulate/watch helpers for all contracts.
Use it for:
- React apps already on wagmi action typing
- Explicit generated contracts in schema-heavy codebases
Use plain viem-first helpers when you need transport-level control or non-wagmi runtimes.
Type references
Commonly-used protocol shapes:
SwapParamsSwapIntentSwapExecutionInputCallDescriptorContractAddressesCollateralConfigGlobalConfigPoolRiskConfigOracleCollateralConfigHookRiskLogHookSettlementLogSettlementEventLaunchConfig/LaunchPlanRiskMode,OracleModeValue,OracleReasonCodeSignedSwapQuoteSignedSwapQuoteBaseSignedSwapQuoteSignature
Recommended docs path
- Start from this SDK Integration page.
- Then step into Swap lifecycle walkthrough.
- For deployment prep, follow New Market Onboarding.
Explicit risk mode changes
setRiskConfigGlobal retains the current mode and reverts if its supplied mode
is stale. Use setRiskConfigSafeMode(walletClient, riskConfig, expectedMode, nextMode, account?) for an explicit admin mode transition without rewriting
limits. Refresh and review a mode mismatch before retrying. Guardian emergency
changes continue to use guardianSetSafeMode. The new helper requires a registry
that implements the new entrypoint; older deployments retain their existing API.