npm package: @silo-finance/silo-sdk
Description: Complete SDK for Silo Finance - aggregates all packages
Latest version: 0.0.1

# @silo-finance/silo-sdk

<a href="https://www.npmjs.com/package/@silo-finance/silo-sdk">
    <picture>
        <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/@silo-finance/silo-sdk?colorA=21262d&colorB=21262d&style=flat">
        <img src="https://img.shields.io/npm/v/@silo-finance/silo-sdk?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="Version">
    </picture>
</a>
<a href="https://github.com/silo-finance/silo-sdk/blob/main/LICENSE">
    <picture>
        <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/l/@silo-finance/silo-sdk?colorA=21262d&colorB=21262d&style=flat">
        <img src="https://img.shields.io/npm/l/@silo-finance/silo-sdk?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="MIT License">
    </picture>
</a>
<br />
<br />

Complete SDK for Silo Finance - a unified package that re-exports all Silo SDK packages.

## Installation

```bash
pnpm add @silo-finance/silo-sdk viem
```

```bash
npm install @silo-finance/silo-sdk viem
```

## Quick Start

```typescript
import { createPublicClient, http } from "viem";
import { arbitrum } from "viem/chains";
import { SiloSdk, ViemAdapter, percentToDecimal } from "@silo-finance/silo-sdk";

// 1. Create viem client
const publicClient = createPublicClient({ chain: arbitrum, transport: http() });

// 2. Create adapter and SDK
const adapter = new ViemAdapter({ provider: publicClient });
const sdk = new SiloSdk({ chain: "arbitrum", adapter });

// 3. Use namespaced API
const siloAddress = "0x0696e6808ee11a5750733a3d821f9bb847e584fb";
const borrowApr = await sdk.markets.getBorrowAPR(siloAddress);
const borrowApy = sdk.calc.getApy({ apr: borrowApr, periods: 365n });

console.log(`Borrow APY: ${(percentToDecimal(borrowApy) * 100).toFixed(2)}%`);
```

## What's Included

This package re-exports functionality from all Silo SDK packages:

| Package | Description |
|---------|-------------|
| [`@silo-finance/primitives`](../primitives/) | Branded types (`Amount`, `Percent`, `USD`), math utilities, formatters |
| [`@silo-finance/address-book`](../address-book/) | Contract addresses and ABIs for all supported chains |
| [`@silo-finance/core`](../core/) | Pure calculation library - APR, LTV, health factors |
| [`@silo-finance/adapter-common`](../adapter-common/) | Abstract adapter interfaces |
| [`@silo-finance/adapter-viem`](../adapter-viem/) | Viem adapter for blockchain reads/writes |
| [`@silo-finance/indexer`](../indexer/) | GraphQL client for indexed data |

## Available Exports

### From adapter-viem (Blockchain Access)

```typescript
import {
  // SDK class (recommended)
  SiloSdk, ViemAdapter,
  // Write functions
  deposit, withdraw, borrow, repay, approve, approveMax,
  // Oracle utilities
  fetchQuote, fetchOracleQuotes, fetchQuoteToken,
  // Router utilities
  fetchRouterPaused,
  // Enums
  SiloCollateralType, RiskLevel,
} from "@silo-finance/silo-sdk";

// SiloSdk provides namespaced API:
// sdk.markets - getBorrowAPR(), getDepositAPR(), getUtilization(), getLiquidity(), etc.
// sdk.positions - get(), getLtv(), isSolvent(), getBalances(), getData()
// sdk.tokens - getBalance(), getBalances(), getAllowance(), getMetadata()
// sdk.actions - deposit(), withdraw(), borrow(), repay(), approve()
// sdk.calc - getApy(), calculateLtv(), getRiskLevel()
```

### From sdk (Pure Calculations)

```typescript
import {
  // APR/APY
  getApy, getCollateralBaseApr, calculateRewardsApr, calculateLeverageApr,
  // LTV analysis
  calculateLtv, getMaxBorrowWithBuffer, getMaxWithdrawWithBuffer, getRiskLevel,
} from "@silo-finance/silo-sdk";
```

### From primitives (Types & Utilities)

```typescript
import {
  // Type constructors
  makePercent, makeAmount, makeUSD, makeAddress,
  // Formatters
  formatPercent, formatAmount, formatUSD,
  // Constants
  PERCENT_FACTOR, PERCENT_ZERO, PERCENT_ONE,
  // Math utilities
  abs, min, max, clamp, mulDiv,
} from "@silo-finance/silo-sdk";
```

### From address-book (Contracts)

```typescript
import {
  // Contract addresses
  siloLensAddress, siloRouterV2Address, siloFactoryAddress,
  // Chain utilities
  chainKeys, chainIds, getChainKeyFromId,
  // ABIs
  siloAbi, siloLensAbi, erc20Abi,
} from "@silo-finance/silo-sdk";
```

### From indexer (GraphQL)

```typescript
import {
  SiloIndexerClient, createIndexerClient,
} from "@silo-finance/silo-sdk";
```

## When to Use Individual Packages

While this unified SDK is recommended for most applications, you may want to import individual packages when:

- **Bundle size matters**: Only import what you need
- **No blockchain access**: Use `@silo-finance/core` + `@silo-finance/primitives` for pure calculations
- **Custom adapter**: Build on `@silo-finance/adapter-common` for other blockchain libraries
- **Server-side only**: Use `@silo-finance/indexer` for GraphQL-only access

## Documentation

For detailed documentation of each module, see the individual package READMEs or visit our [documentation site](https://silo-finance.github.io/silo-sdks/).

## License

[MIT](/LICENSE)