npm package: @silo-finance/adapter-common
Description: Abstract adapter interfaces for Silo Finance SDKs
Latest version: 0.0.1

# @silo-finance/adapter-common

<a href="https://www.npmjs.com/package/@silo-finance/adapter-common">
    <picture>
        <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/@silo-finance/adapter-common?colorA=21262d&colorB=21262d&style=flat">
        <img src="https://img.shields.io/npm/v/@silo-finance/adapter-common?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/adapter-common?colorA=21262d&colorB=21262d&style=flat">
        <img src="https://img.shields.io/npm/l/@silo-finance/adapter-common?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="MIT License">
    </picture>
</a>
<br />
<br />

Abstract adapter interfaces for Silo Finance SDKs. This package defines the contract that blockchain adapter implementations must fulfill.

## Purpose

This package provides TypeScript interfaces that enable:

- **Pluggable architecture**: Swap between viem, ethers.js, or custom implementations
- **Type safety**: Consistent types across all adapters
- **Future extensibility**: Easy to add new blockchain libraries

## Available Adapters

| Package | Status | Description |
|---------|--------|-------------|
| [`@silo-finance/adapter-viem`](../adapter-viem/) | Available | Viem implementation |
| `@silo-finance/adapter-ethers` | Coming soon | Ethers.js implementation |

## Installation

```bash
pnpm add @silo-finance/adapter-common
```

> **Note**: Most users should install [`@silo-finance/adapter-viem`](../adapter-viem/) or [`@silo-finance/silo-sdk`](../silo-sdk/) directly instead of this package.

## Interfaces

### Core Adapter Interfaces

```typescript
import type {
  ReadAdapter,
  WriteAdapter,
} from "@silo-finance/adapter-common";
```

**ReadAdapter** - Read-only blockchain operations:
- `readContract()` - Read from a contract
- `multicall()` - Batch multiple contract reads
- `getChainId()` - Get current chain ID
- `getBalance()` - Get native token balance
- `getBlockNumber()` - Get current block number

**WriteAdapter** - Write operations (extends ReadAdapter):
- `writeContract()` - Send a transaction
- `getAddress()` - Get connected wallet address
- `signMessage()` - Sign a message
- `waitForTransaction()` - Wait for tx confirmation

### Silo-Specific Interfaces

```typescript
import type {
  MarketReadOperations,
  PositionReadOperations,
  TokenReadOperations,
  SiloWriteOperations,
  SiloReadAdapter,
  SiloWriteAdapter,
} from "@silo-finance/adapter-common";
```

**MarketReadOperations**:
- `fetchMarket()` - Fetch market data
- `fetchSilo()` - Fetch silo data
- `fetchBorrowAPR()` / `fetchDepositAPR()` - Fetch APRs
- `fetchUtilization()` - Fetch utilization rate
- `fetchLiquidity()` - Fetch available liquidity

**PositionReadOperations**:
- `fetchPosition()` - Fetch user position
- `fetchUserLtv()` - Fetch user LTV
- `fetchIsSolvent()` - Check solvency

**TokenReadOperations**:
- `fetchTokenBalance()` - Get token balance
- `fetchAllowance()` - Get token allowance
- `fetchTokenMetadata()` - Get token info

**SiloWriteOperations**:
- `deposit()` / `withdraw()` - Deposit/withdraw collateral
- `borrow()` / `repay()` - Borrow/repay debt
- `approve()` - Approve token spending

### Combined Interfaces

```typescript
// Complete read adapter
interface SiloReadAdapter extends
  ReadAdapter,
  MarketReadOperations,
  PositionReadOperations,
  TokenReadOperations {
  readonly chainId: number;
}

// Full adapter with write capabilities
interface SiloWriteAdapter extends
  SiloReadAdapter,
  WriteAdapter,
  SiloWriteOperations {}
```

## Parameter Types

```typescript
import type {
  PositionData,
  TokenMetadata,
  DepositParams,
  WithdrawParams,
  BorrowParams,
  RepayParams,
  ApproveParams,
} from "@silo-finance/adapter-common";
```

## Creating a Custom Adapter

To create a custom adapter (e.g., for ethers.js):

```typescript
import type { SiloWriteAdapter, CreateWriteAdapterFn } from "@silo-finance/adapter-common";

const createEthersAdapter: CreateWriteAdapterFn<EthersConfig> = (config) => {
  return {
    chainId: config.chainId,

    async readContract(params) {
      // Implement using ethers.js
    },

    async writeContract(params) {
      // Implement using ethers.js
    },

    // ... implement all other methods
  };
};
```

## License

[MIT](/LICENSE)