npm package: @1delta/initializer-sdk
Description: Deterministic initializer for lending protocol data across the stack
Latest version: 0.0.10

# @1delta/initializer-sdk

Fetches lending protocol deployment metadata from GitHub and populates the global registries used by `@1delta/data-sdk`.

## Installation

```bash
pnpm add @1delta/initializer-sdk
```

## How It Works

```
GitHub (lender-metadata repo)  ──fetch──►  initializer-sdk  ──populate──►  data-sdk global registry
                                                                                    │
                                                                           aavePools(), morphoPools(), ...
```

The initializer fetches JSON files from `1delta-DAO/lender-metadata` (pool configs, reserves, oracles, tokens) and `1delta-DAO/chains` (chain metadata), then calls `initializeLenderData()` / `initializeChainData()` from `@1delta/data-sdk` to populate the global registry. After initialization, all data is accessible via the data-sdk getter functions.

---

## Quick Start

### Initialize everything

```ts
import { fetchLenderMetaFromDirAndInitializeAll } from '@1delta/initializer-sdk'

await fetchLenderMetaFromDirAndInitializeAll()

// Now data-sdk getters work:
import { aavePools, compoundV2Pools, morphoPools, chains } from '@1delta/data-sdk'
console.log(Object.keys(aavePools()))   // ['AAVE_V3', 'SPARK', 'LENDLE', ...]
console.log(Object.keys(chains()))      // ['1', '56', '42161', ...]
```

### Initialize selectively

Only load what you need — reduces fetch time and memory:

```ts
import { fetchLenderMetaFromDirAndInitialize } from '@1delta/initializer-sdk'

await fetchLenderMetaFromDirAndInitialize({
  aavePools: true,
  aaveReserves: true,
  compoundV2Pools: true,
  compoundV2TokenArray: true,
  chains: true,
})
```

---

## API

### `fetchLenderMetaFromDirAndInitializeAll()`

Fetches **all** metadata files and initializes the global registry. Equivalent to calling `fetchLenderMetaFromDirAndInitialize` with every flag set to `true`.

```ts
await fetchLenderMetaFromDirAndInitializeAll()
```

### `fetchLenderMetaFromDirAndInitialize(flags)`

Fetches only the metadata specified by `flags` and initializes the registry.

```ts
await fetchLenderMetaFromDirAndInitialize({
  aavePools: true,       // fetch aave pool configs
  aaveReserves: true,    // fetch aave reserve lists
  morphoPools: true,     // fetch morpho singleton addresses
  chains: true,          // fetch chain metadata
  // all other flags default to false
})
```

### `fetchLenderMetaFromDir(flags)`

Fetches metadata without initializing. Returns an object of overrides you can pass to `inititalizeAllData()` manually.

```ts
const params = await fetchLenderMetaFromDir({ aavePools: true, aaveReserves: true })
// params.aavePoolsOverride = { AAVE_V3: { '1': { pool, protocolDataProvider } }, ... }
// params.aaveReservesOverride = { AAVE_V3: { '1': ['0x...', ...] }, ... }
```

### `inititalizeAllData(params)`

Populates the global registry from a params object (as returned by `fetchLenderMetaFromDir`).

```ts
const params = await fetchLenderMetaFromDir({ aavePools: true })
inititalizeAllData(params)
```

### `getDeltaTokenList(chainId)`

Fetches the token list for a chain from the `1delta-DAO/token-lists` repo.

```ts
import { getDeltaTokenList } from '@1delta/initializer-sdk'

const tokens = await getDeltaTokenList('1')
// {
//   '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': {
//     chainId: '1', name: 'Wrapped Ether', symbol: 'WETH',
//     address: '0xc02a...', decimals: 18, logoURI: '...',
//   },
//   ...
// }
```

---

## Fetch Flags

All flags default to `false`. Set to `true` to fetch the corresponding data.

### Aave (V2 / V3 / all forks)

| Flag | Remote file | data-sdk getter |
|------|------------|-----------------|
| `aavePools` | `config/aave-pools.json` | `aavePools()` |
| `aaveReserves` | `data/aave-reserves.json` | `aaveReserves()` |
| `aaveTokens` | `data/aave-tokens.json` | `aaveTokens()` |
| `aaveOracles` | `data/aave-oracles.json` | `aaveOracles()` |
| `aaveWethGateway` | `config/aave-weth-gateway.json` | `aaveWethGateway()` |

### Compound V2 (all forks)

| Flag | Remote file | data-sdk getter |
|------|------------|-----------------|
| `compoundV2Pools` | `config/compound-v2-pools.json` | `compoundV2Pools()` |
| `compoundV2Reserves` | `data/compound-v2-reserves.json` | `compoundV2Reserves()` |
| `compoundV2Tokens` | `data/compound-v2-c-tokens.json` | `compoundV2Tokens()` |
| `compoundV2TokenArray` | `data/compound-v2-tokens.json` | `compoundV2TokenArray()` |
| `compoundV2Oracles` | `data/compound-v2-oracles.json` | `compoundV2Oracles()` |

### Compound V3

| Flag | Remote file | data-sdk getter |
|------|------------|-----------------|
| `compoundV3Pools` | `config/compound-v3-pools.json` | `compoundV3Pools()` |
| `compoundV3Reserves` | `data/compound-v3-reserves.json` | `compoundV3Reserves()` |
| `compoundV3BaseData` | `data/compound-v3-base-data.json` | `compoundV3BaseData()` |
| `compoundV3OraclesData` | `data/compound-v3-oracles-data.json` | `compoundV3OraclesData()` |
| `compoundV3Bulker` | `data/compound-v3-bulkers.json` | `compoundV3Bulker()` |

### Morpho

| Flag | Remote file | data-sdk getter |
|------|------------|-----------------|
| `morphoPools` | `config/morpho-pools.json` | `morphoPools()` |
| `morphoOracles` | `data/morpho-oracles.json` | `morphoOracles()` |
| `morphoTypeOracles` | `data/morpho-type-oracles.json` | `morphoTypeOracles()` |
| `morphoTypeMarkets` | `data/morpho-type-markets.json` | `morphoTypeMarkets()` |
| `morphoBundler3` | `data/morpho-bundler3.json` | `morphoBundler3()` |

### Euler

| Flag | Remote file | data-sdk getter |
|------|------------|-----------------|
| `eulerConfigs` | `config/euler-configs.json` | `eulerConfigs()` |
| `eulerVaults` | `data/euler-vaults.json` | `eulerVaults()` |

### Other

| Flag | Remote file | data-sdk getter |
|------|------------|-----------------|
| `initPools` | `config/init-pools.json` | `initConfig()` |
| `initConfig` | `data/init-config.json` | `initConfig()` |
| `listaNativeProvider` | `data/lista-providers.json` | `listaNativeProvider()` |
| `chains` | `data.json` (from chains repo) | `chains()` |

---

## Data Sources

| Repository | Content |
|-----------|---------|
| `github.com/1delta-DAO/lender-metadata` | Pool configs, reserves, oracles, tokens for all protocols |
| `github.com/1delta-DAO/chains` | Chain metadata (RPC, explorers, native currency) |
| `github.com/1delta-DAO/token-lists` | Per-chain token lists |

---

## Usage with irm-sdk

The typical flow for fetching IRM data across all protocols:

```ts
import { fetchLenderMetaFromDirAndInitialize } from '@1delta/initializer-sdk'
import { aavePools, compoundV2Pools, compoundV3Pools, morphoPools, eulerConfigs } from '@1delta/data-sdk'
import { prepareFetch, batchPrepared } from '@1delta/irm-sdk'
import { multicallRetryUniversal } from '@1delta/providers'

// 1. Initialize the registry (only pool + reserve data needed for IRM)
await fetchLenderMetaFromDirAndInitialize({
  aavePools: true,
  aaveReserves: true,
  compoundV2Pools: true,
  compoundV2TokenArray: true,
  compoundV3Pools: true,
  compoundV3BaseData: true,
  morphoPools: true,
  morphoTypeMarkets: true,
  eulerConfigs: true,
  eulerVaults: true,
})

// 2. Enumerate all deployments
const targets = []
for (const [lender, chains] of Object.entries(aavePools() ?? {}))
  for (const chainId of Object.keys(chains))
    targets.push({ lender, chainId })
// ... repeat for compoundV2Pools, compoundV3Pools, morphoPools, eulerConfigs

// 3. Fetch IRM data per chain
for (const [chainId, lenders] of Object.entries(groupByChain(targets))) {
  const prepared = lenders
    .map(({ lender }) => prepareFetch({ chainId, lender }))
    .filter(Boolean)
  const results = await batchPrepared(chainId, prepared, multicallRetryUniversal)
}
```