# @layerzerolabs/lz-solana-sdk-v2

The LayerZero Solana SDK V2 package provides a set of essential utilities and modules to facilitate the development and integration of applications with the Solana blockchain. It includes functions for managing deployments, handling wallets, interacting with contracts, and more.

## Features

- **Deployment Management**: Functions for reading, writing, and managing deployments.
- **Wallet Management**: Functions for handling Solana wallets.
- **Contract Interaction**: Functions for interacting with deployed contracts.
- **Event Extraction**: Functions for extracting events from transactions.
- **Price Feed Management**: Functions for managing price feeds.
- **Utility Functions**: Various utility functions for Solana development.

## Installation

To install the LayerZero Solana SDK V2 package, you can use npm or yarn:

```sh
npm install @layerzerolabs/lz-solana-sdk-v2
```

or

```sh
yarn add @layerzerolabs/lz-solana-sdk-v2
```

## Usage

### Deployment Management

#### getProgramKeypair

Gets the program keypair for a specified network and program.

```typescript
import { getProgramKeypair } from "@layerzerolabs/lz-solana-sdk-v2";

const network = "solana-sandbox-local";
const program = "endpoint";

const programKeypair = getProgramKeypair(network, program);
console.log(`Program Keypair: ${programKeypair.toBase58()}`);
```

### Wallet Management

#### getChainWallet

Retrieves a chain wallet for a specified stage and name.

```typescript
import { getChainWallet } from "@layerzerolabs/lz-solana-sdk-v2";

const stage = "production";
const name = "oracle";

const wallet = getChainWallet(stage, name);
console.log(`Wallet Address: ${wallet.publicKey.toBase58()}`);
```

### Contract Interaction

#### initEndpoint

Initializes the endpoint settings, including eid and admin, and registers the blocked message library.

```typescript
import { Endpoint } from "@layerzerolabs/lz-solana-sdk-v2";

const endpointProgram = new Endpoint(programPublicKey);
const endpointId = 1;
const payer = new PublicKey("payerPublicKey");
const admin = new PublicKey("adminPublicKey");

const instruction = endpointProgram.initEndpoint(endpointId, payer, admin);
console.log(`Transaction Instruction: ${instruction}`);
```

### Event Extraction

#### extractSentPacketEventByTxHash

Extracts the sent packet event by transaction hash.

```typescript
import { extractSentPacketEventByTxHash } from "@layerzerolabs/lz-solana-sdk-v2";

const connection = new Connection("https://api.mainnet-beta.solana.com");
const program = new PublicKey("programPublicKey");
const signature = "transactionSignature";

extractSentPacketEventByTxHash(connection, program, signature).then(
  (events) => {
    console.log(`Sent Packet Events: ${events}`);
  },
);
```

### Price Feed Management

#### initPriceFeed

Initializes the price feed.

```typescript
import { PriceFeed } from "@layerzerolabs/lz-solana-sdk-v2";

const priceFeedProgram = new PriceFeed(programPublicKey);
const connection = new Connection("https://api.mainnet-beta.solana.com");
const payer = new PublicKey("payerPublicKey");
const admin = new PublicKey("adminPublicKey");
const updaters = [new PublicKey("updaterPublicKey")];

priceFeedProgram
  .initPriceFeed(connection, payer, admin, updaters)
  .then((instruction) => {
    console.log(`Transaction Instruction: ${instruction}`);
  });
```

### Utility Functions

#### deriveLzReceiveTypesAccountsPDA

Derives the LZ receive types accounts PDA.

```typescript
import { deriveLzReceiveTypesAccountsPDA } from "@layerzerolabs/lz-solana-sdk-v2";

const program = new PublicKey("programPublicKey");
const oappId = new PublicKey("oappId");

const [pda, bump] = deriveLzReceiveTypesAccountsPDA(program, oappId);
console.log(`PDA: ${pda.toBase58()}, Bump: ${bump}`);
```
