> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inkwell.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting Started with the SDK

> Install and start using @leviathan/sdk to interact with the Leviathan protocol from TypeScript.

> **CONFIDENTIAL & PROPRIETARY © 2026 Inkwell Finance, Inc. All Rights Reserved.**
>
> This document is for informational purposes only and does not constitute legal, tax, or investment advice, nor an offer to sell or a solicitation to buy any security or other financial instrument. Any examples, structures, or flows described here are design intent only and may change.

## Installation

Install the SDK with your preferred package manager:

```bash theme={null}
pnpm add @leviathan/sdk
```

The SDK requires `@solana/web3.js` as a peer dependency:

```bash theme={null}
pnpm add @solana/web3.js
```

## Basic Setup

Import from the subpath that matches your needs:

```typescript theme={null}
// Full SVM integration
import { findLoanPda, findPoolPda } from "@leviathan/sdk/svm/pda";
import { buildDepositTx, buildWithdrawTx } from "@leviathan/sdk/svm/transactions";

// Low-level instruction builders
import { depositInstruction, withdrawInstruction } from "@leviathan/sdk/svm/instructions";

// Account types
import type { LoanAccount, PoolAccount } from "@leviathan/sdk/svm/accounts";
```

## Connecting to the Network

Set up a Solana connection and reference the program IDs:

```typescript theme={null}
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://api.mainnet-beta.solana.com");
```

The SDK exports default program IDs for each Leviathan program. You can override these if deploying to a custom environment.

## PDA Derivation

Leviathan accounts are stored at program-derived addresses (PDAs). The SDK provides helpers to derive these deterministically:

```typescript theme={null}
import { findLoanPda, findPolicyPda, loanIdBuffer } from "@leviathan/sdk/svm/pda";
import { findPoolPda } from "@leviathan/sdk/svm/pda";

// Derive a loan PDA from the borrower's public key
const borrower = new PublicKey("...");
const [loanPda, loanBump] = findLoanPda(borrower, loanIdBuffer(0));

// Derive the associated policy PDA
const [policyPda, policyBump] = findPolicyPda(loanPda);

// Derive a pool PDA
const admin = new PublicKey("...");
const [poolPda, poolBump] = findPoolPda(admin);
```

PDA helpers accept optional `programId` overrides for testing against custom deployments.

## Querying Pool State

Fetch and inspect a lending pool's on-chain state:

```typescript theme={null}
import { Connection, PublicKey } from "@solana/web3.js";
import { findPoolPda } from "@leviathan/sdk/svm/pda";

const connection = new Connection("https://api.mainnet-beta.solana.com");

const admin = new PublicKey("...");
const [poolPda] = findPoolPda(admin);

// Fetch the raw account data
const accountInfo = await connection.getAccountInfo(poolPda);

if (accountInfo) {
  // Deserialize using SDK account types
  console.log("Pool account found:", poolPda.toBase58());
  console.log("Data length:", accountInfo.data.length);
}
```

## Building Transactions

The SDK provides high-level transaction builders that handle account lookups and instruction composition:

### Depositing into a Pool

```typescript theme={null}
import { Connection, PublicKey } from "@solana/web3.js";
import { buildDepositTx } from "@leviathan/sdk/svm/transactions";

const connection = new Connection("https://api.mainnet-beta.solana.com");
const depositor = new PublicKey("...");
const poolPda = new PublicKey("...");

// Build a deposit transaction
const depositAmount = 1_000_000; // in smallest units (e.g., lamports or token base units)
const tx = await buildDepositTx(connection, depositor, poolPda, depositAmount);

// Sign and send (using your wallet adapter or keypair)
// tx is a ready-to-sign Transaction object
```

### Withdrawing from a Pool

```typescript theme={null}
import { buildWithdrawTx } from "@leviathan/sdk/svm/transactions";

const withdrawAmount = 500_000;
const tx = await buildWithdrawTx(connection, depositor, poolPda, withdrawAmount);
```

## Querying Credit Scores

Look up a borrower's on-chain credit score:

```typescript theme={null}
import { findScoreEntryPda } from "@leviathan/sdk/svm/pda";

const borrower = new PublicKey("...");
const [scoreEntryPda] = findScoreEntryPda(borrower);

const scoreAccount = await connection.getAccountInfo(scoreEntryPda);

if (scoreAccount) {
  console.log("Score entry found for:", borrower.toBase58());
}
```

## Using Low-Level Instructions

For custom transaction flows, use instruction builders directly:

```typescript theme={null}
import { depositInstruction } from "@leviathan/sdk/svm/instructions";
import { Transaction } from "@solana/web3.js";

// Build individual instructions
const depositIx = depositInstruction(depositor, poolPda, amount, /* ...accounts */);

// Compose into a custom transaction
const tx = new Transaction();
tx.add(depositIx);
tx.feePayer = depositor;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
```

## Sui Bindings

Sui bindings for policy and dWallet operations are available through the SDK's codegen pipeline:

* Policy-gated dWallet capabilities
* Destination registry queries
* Cross-chain signing operations

Sui types are generated from Move contract summaries and provide typed interfaces for all policy enforcement operations.

## Next Steps

<CardGroup cols={2}>
  <Card title="SDK Reference" icon="book" href="/leviathan/credit-line/sdk-overview">
    Full overview of all SDK exports and capabilities
  </Card>

  <Card title="Protocol Overview" icon="layer-group" href="/leviathan/credit-line/overview">
    Understand the on-chain programs the SDK interacts with
  </Card>
</CardGroup>
