@blend-money/sdk-core
v0.1.11
Published
Core utilities for Blend SDK.
Downloads
334
Readme
@blend-money/sdk-core
Type-safe SDK for interacting with the Blend API. Provides precise decimal arithmetic using Decimal.js and comprehensive type safety for all API operations.
Features
- Type-safe API client with full TypeScript support
- Precise decimal arithmetic using Decimal.js for financial calculations
- Automatic retry logic with exponential backoff for failed requests
- Safe address caching to minimize API calls
- Comprehensive error handling with detailed error types
- Isomorphic - works in both browser and Node.js environments
Install
pnpm add @blend-money/sdk-coreQuick Start
import { BlendClient } from "@blend-money/sdk-core";
const client = new BlendClient({
baseUrl: "https://api.blend.money",
userAddress: "0x742d35Cc6634C0532925a3b8D",
integratorId: "my-app-v1.0",
});
// Resolve Safe address
const safeResolution = await client.safe.resolveSafeAddress(
"0x742d35Cc6634C0532925a3b8D",
8453,
);
// Get available strategies
const strategies = await client.strategy.getAvailableStrategies();
// Get yield information
const yieldSummary = await client.strategy.getAllYieldsFromVault(strategies[0]);Configuration
import { BlendClient } from "@blend-money/sdk-core";
const client = new BlendClient({
baseUrl: "https://api.blend.money", // Required: API base URL
userAddress: "0x742d35Cc6634C0532925a3b8D", // Required: User's EOA address
integratorId: "my-app-v1.0", // Required: Integrator identifier
timeoutMs: 30000, // Optional: Request timeout (default: 15000)
retries: 5, // Optional: Retry attempts (default: 3)
alchemyApiKey: "your-key", // Optional: For balance queries
});Decimal Arithmetic
The SDK uses Decimal.js for precise financial calculations:
import { Decimal } from "decimal.js";
const price = new Decimal("1.5"); // new Decimal(1.5)
const quantity = new Decimal("1000"); // new Decimal(1000)
const total = price.mul(quantity); // new Decimal(1500)
// Convert back to number if needed
const totalNumber = total.toNumber(); // 1500Error Handling
import { BlendClient, SdkError } from "@blend-money/sdk-core";
try {
const result = await client.safe.resolveSafeAddress(address, chainId);
} catch (error) {
if (error instanceof SdkError) {
console.error(`API Error ${error.status}: ${error.message}`);
console.error(`User-friendly: ${error.getUserMessage()}`);
}
}API Reference
BlendClient
Main client class providing access to all SDK functionality.
Constructor
new BlendClient(config: BlendClientConfig)
Modules
client.safe- Safe address resolution and deploymentclient.strategy- Yield and balance informationclient.actions- Deposit, withdraw, and rebalance operations
Strategy Methods
client.strategy.getAvailableIntegrations()→string[]- Lists supported integrations (e.g.,
"MESA_CAPITAL").
- Lists supported integrations (e.g.,
Types
Percent- Percentage values using Decimal.js (1 = 100%)Usd- USD values using Decimal.jsPrice- Token prices using Decimal.jsToken- Token configuration with address, symbol, decimals, chainIdTokenAmount- Token amount with native decimal scalingVaultConfig- Vault configuration and metadataYieldSummary- Comprehensive yield informationBalanceSummary- Balance information across all positions
Utilities
parseAmount(amountStr, decimals)- Parse string to BigInt with decimalsformatAmount(amount, decimals, precision?)- Format BigInt to stringtokenAmountToDecimal(amount)- Convert TokenAmount to DecimaldecimalToTokenAmount(decimal, decimals)- Convert Decimal to TokenAmountvalidateAddress(address)- Validate Ethereum addressvalidateChainId(chainId)- Validate chain ID format
License
MIT
