# Initialization

### Installation

```sh
npm install @yelay-lite/sdk
```

#### Required Dependencies

The Yelay Lite SDK requires a drift web3 adapter and the drift core library. Install both the core drift library and choose one adapter based on your web3 library:

**Core dependency (required for all setups):**

```sh
npm install @gud/drift
```

**For Viem:**

```sh
npm install @gud/drift-viem
```

**For Ethers v6:**

```sh
npm install @gud/drift-ethers
```

**For Ethers v5:**

```sh
npm install @gud/drift-ethers-v5
```

### Caching Configuration

The Yelay Lite SDK automatically disables drift's internal caching to ensure fresh data on every request.

When you call `sdk.init(drift)`, the SDK automatically replaces drift's default LRU cache with a no-op implementation, ensuring all contract calls fetch fresh data from the blockchain. The SDK will throw an error if you try to use custom caching.

### Initialization

The SDK uses a **drift adapter pattern** that works with any web3 library. The `init()` method is **mandatory** and must be called before using any SDK features.

#### With Viem

```ts
import { YelayLiteSdk } from '@yelay-lite/sdk';
import { viemAdapter } from '@gud/drift-viem';
import { createDrift } from '@gud/drift';
import { createPublicClient, createWalletClient, http } from 'viem';
import { base } from 'viem/chains';

// Set up your viem clients
const publicClient = createPublicClient({
	chain: base,
	transport: http(),
});

const walletClient = createWalletClient({
	chain: base,
	transport: http(),
});

// Create the adapter and drift instance
const adapter = viemAdapter({ publicClient, walletClient });
const drift = createDrift({ adapter });

// Initialize the SDK
const sdk = new YelayLiteSdk();
await sdk.init(drift);
```

#### With Ethers v6

```ts
import { YelayLiteSdk } from '@yelay-lite/sdk';
import { ethersAdapter } from '@gud/drift-ethers';
import { createDrift } from '@gud/drift';
import { ethers } from 'ethers';

// Set up your ethers provider and signer
const provider = new ethers.JsonRpcProvider('https://mainnet.base.org');
const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);

// Create the adapter and drift instance
const adapter = ethersAdapter({ provider, signer });
const drift = createDrift({ adapter });

// Initialize the SDK
const sdk = new YelayLiteSdk();
await sdk.init(drift);
```

#### With Ethers v5

```ts
import { YelayLiteSdk } from '@yelay-lite/sdk';
import { ethersV5Adapter } from '@gud/drift-ethers-v5';
import { createDrift } from '@gud/drift';
import { ethers } from 'ethers';

// Set up your ethers v5 provider and signer
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.base.org');
const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);

// Create the adapter and drift instance
const adapter = ethersV5Adapter({ provider, signer });
const drift = createDrift({ adapter });

// Initialize the SDK
const sdk = new YelayLiteSdk();
await sdk.init(drift);
```
