Skip to main content

Configuration

The SDK is configured through the BorrowSDKConfig object passed to the constructor.

Required Options

These options must be provided:
const sdk = new BorrowSDK({
  // Required
  apiKey: 'your-api-key',
  chain: ChainType.ARBITRUM,
  wallet: {
    address: 'bc1q...',
    signMessage: async (msg) => wallet.signMessage(msg)
  }
});

apiKey

Your SatsTerminal API key for authentication.
TypeRequired
stringYes

baseUrl

The SatsTerminal API endpoint.
TypeRequiredExample
stringYeshttps://api.satsterminal.com

chain

The EVM chain to use for borrowing.
TypeRequiredValues
ChainTypeYesARBITRUM, BASE, ETHEREUM
import { ChainType } from '@satsterminal-sdk/borrow';

// Options
ChainType.ARBITRUM  // 'arbitrum'
ChainType.BASE      // 'base'
ChainType.ETHEREUM  // 'ethereum'

wallet

The wallet provider for signing operations.
PropertyTypeRequiredDescription
addressstringYesBitcoin address
signMessage(msg: string) => Promise<string>YesMessage signing function
publicKeystringNoPublic key (hex)
sendBitcoin(to: string, sats: number) => Promise<string>NoBitcoin sending function
wallet: {
  address: 'bc1qxyz...',
  publicKey: '02abc...', // Optional
  signMessage: async (message) => {
    return await bitcoinWallet.signMessage(message);
  },
  sendBitcoin: async (toAddress, satoshis) => {
    return await bitcoinWallet.sendBitcoin(toAddress, satoshis);
  }
}

Optional Options

workflowPollInterval

Interval (in milliseconds) for polling workflow status.
TypeDefaultMin
number2000100
workflowPollInterval: 3000 // Poll every 3 seconds

sessionValiditySeconds

How long sessions remain valid (in seconds).
TypeDefaultMin
number259200 (3 days)60
sessionValiditySeconds: 86400 // 24 hours

autoTrackWorkflows

Automatically track workflow status after operations.
TypeDefault
booleantrue
autoTrackWorkflows: false // Disable auto-tracking

quoteSelector

Custom function to select a quote from available options.
TypeDefault
(quotes: Quote[]) => QuoteFirst quote
// Select the quote with lowest APY
quoteSelector: (quotes) => {
  return quotes.reduce((best, q) =>
    parseFloat(q.borrowApy.variable) < parseFloat(best.borrowApy.variable) ? q : best
  );
}

storage

Custom storage provider for persisting signatures.
TypeDefault
StorageProviderlocalStorage / MemoryStorage
// Custom storage implementation
storage: {
  getItem: (key) => myStorage.get(key),
  setItem: (key, value) => myStorage.set(key, value),
  removeItem: (key) => myStorage.delete(key),
  clear: () => myStorage.clear()
}

retryConfig

Configuration for automatic request retries.
PropertyTypeDefault
maxRetriesnumber3
retryDelaynumber1000
retryableStatusCodesnumber[][408, 429, 500, 502, 503, 504]
retryConfig: {
  maxRetries: 5,
  retryDelay: 2000,
  retryableStatusCodes: [429, 500, 502, 503, 504]
}

logger

Custom logger for debugging.
TypeDefault
Loggerconsole
logger: {
  debug: (msg) => myLogger.debug(msg),
  info: (msg) => myLogger.info(msg),
  warn: (msg) => myLogger.warn(msg),
  error: (msg) => myLogger.error(msg)
}

rpcUrl

Custom RPC URL for the selected chain.
TypeDefault
stringChain default
rpcUrl: 'https://arb-mainnet.g.alchemy.com/v2/your-key'

bundlerUrl

Custom bundler URL for ERC-4337 operations.
TypeDefault
stringPlatform default

Full Configuration Example

import { BorrowSDK, ChainType } from '@satsterminal-sdk/borrow';

const sdk = new BorrowSDK({
  // Required
  apiKey: process.env.API_KEY!,
  chain: ChainType.ARBITRUM,
  wallet: {
    address: userBtcAddress,
    publicKey: userPublicKey,
    signMessage: async (msg) => wallet.signMessage(msg),
    sendBitcoin: async (to, sats) => wallet.send(to, sats)
  },

  // Optional
  workflowPollInterval: 2000,
  sessionValiditySeconds: 259200,
  autoTrackWorkflows: true,

  quoteSelector: (quotes) => {
    // Select quote with best APY
    return quotes.sort((a, b) =>
      parseFloat(a.borrowApy.variable) - parseFloat(b.borrowApy.variable)
    )[0];
  },

  retryConfig: {
    maxRetries: 3,
    retryDelay: 1000
  },

  rpcUrl: process.env.RPC_URL,
  bundlerUrl: process.env.BUNDLER_URL
});

Environment-Based Configuration

const config: BorrowSDKConfig = {
  apiKey: process.env.SATSTERMINAL_API_KEY!,
  baseUrl: process.env.NODE_ENV === 'production'
    ? 'https://api.satsterminal.com'
    : 'https://api-staging.satsterminal.com',
  chain: ChainType.ARBITRUM,
  wallet: walletProvider,

  // More verbose logging in development
  logger: process.env.NODE_ENV === 'development'
    ? console
    : { debug: () => {}, info: () => {}, warn: console.warn, error: console.error }
};

Validation

The SDK validates configuration on initialization:
try {
  const sdk = new BorrowSDK(config);
} catch (error) {
  if (error instanceof ConfigValidationError) {
    console.error('Invalid config:', error.message);
    // e.g., "apiKey is required and must be a non-empty string"
  }
}

Validation Rules

OptionRule
apiKeyNon-empty string
baseUrlValid URL
chainOne of ChainType values
wallet.addressNon-empty string
wallet.signMessageFunction
workflowPollInterval>= 100
sessionValiditySeconds>= 60