Configuration
The SDK is configured through theBorrowSDKConfig object passed to the constructor.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
BorrowSDKConfig object passed to the constructor.
const sdk = new BorrowSDK({
// Required
apiKey: 'your-api-key',
wallet: {
address: 'bc1q...',
signMessage: async (msg) => wallet.signMessage(msg)
}
});
apiKey| Type | Required |
|---|---|
string | Yes |
wallet| Property | Type | Required | Description |
|---|---|---|---|
address | string | Yes | Bitcoin address |
signMessage | (msg: string) => Promise<string> | Yes | Message signing function |
publicKey | string | No | Public key (hex) |
sendBitcoin | (to: string, sats: number) => Promise<string> | No | Bitcoin 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);
}
}
workflowPollInterval| Type | Default | Min |
|---|---|---|
number | 2000 | 100 |
workflowPollInterval: 3000 // Poll every 3 seconds
sessionValiditySeconds| Type | Default | Min |
|---|---|---|
number | 259200 (3 days) | 60 |
sessionValiditySeconds: 86400 // 24 hours
autoTrackWorkflows| Type | Default |
|---|---|
boolean | true |
autoTrackWorkflows: false // Disable auto-tracking
quoteSelector| Type | Default |
|---|---|
(quotes: Quote[]) => Quote | First 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| Type | Default |
|---|---|
StorageProvider | localStorage / 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| Property | Type | Default |
|---|---|---|
maxRetries | number | 3 |
retryDelay | number | 1000 |
retryableStatusCodes | number[] | [408, 429, 500, 502, 503, 504] |
retryConfig: {
maxRetries: 5,
retryDelay: 2000,
retryableStatusCodes: [429, 500, 502, 503, 504]
}
logger| Type | Default |
|---|---|
Logger | console |
logger: {
debug: (msg) => myLogger.debug(msg),
info: (msg) => myLogger.info(msg),
warn: (msg) => myLogger.warn(msg),
error: (msg) => myLogger.error(msg)
}
rpcUrl| Type | Default |
|---|---|
string | Chain default |
rpcUrl: 'https://arb-mainnet.g.alchemy.com/v2/your-key'
bundlerUrl| Type | Default |
|---|---|
string | Platform default |
import { BorrowSDK } from '@satsterminal-sdk/borrow';
const sdk = new BorrowSDK({
// Required
apiKey: process.env.API_KEY!,
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
});
const config: BorrowSDKConfig = {
apiKey: process.env.SATSTERMINAL_API_KEY!,
wallet: walletProvider,
// More verbose logging in development
logger: process.env.NODE_ENV === 'development'
? console
: { debug: () => {}, info: () => {}, warn: console.warn, error: console.error }
};
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"
}
}
| Option | Rule |
|---|---|
apiKey | Non-empty string |
baseUrl | Valid URL |
chain | One of ChainType values |
wallet.address | Non-empty string |
wallet.signMessage | Function |
workflowPollInterval | >= 100 |
sessionValiditySeconds | >= 60 |