Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3.js v2 -> Solana Kit #788

Merged
merged 9 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/long-wombats-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@orca-so/whirlpools-example-ts-next": patch
"@orca-so/tx-sender": patch
"@orca-so/whirlpools": patch
"@orca-so/whirlpools-docs": patch
"@orca-so/whirlpools-client": patch
"@orca-so/whirlpools-docs-ts": patch
---

Switch from @solana/web3.js v2 to @solana/kit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For specific use-cases you can opt for integrating with lower level packages suc
* `@orca-so/whirlpools-client` & `orca_whirlpools_client` - auto-generated client for the Whirlpools program that contains account, instruction and error parsing.
* `@orca-so/whirlpools-core` & `orca_whirlpools_core` - utility, math and quoting functions used by other packages.

The legacy Typescript SDK (`@orca-so/whirlpools-sdk`) remains a solid choice, and it’s currently the only option if your project uses Solana Web3.js versions below v2.
The legacy Typescript SDK (`@orca-so/whirlpools-sdk`) remains a solid choice, and it’s currently the only option if your project uses Solana Web3.js.

For a more detailed overview of our SDK suite and usage examples, visit our [developer documentation](https://dev.orca.so/) site.

Expand Down
6 changes: 3 additions & 3 deletions docs/ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

The Whirlpools SDKs are Orca's primary set of SDKs designed to provide enhanced, modular interaction with the Whirlpool Program on Solana and Eclipse. Whether you are managing liquidity, building applications that require pool infrastructure, or building automation tools that interact with the program, our SDKs cover a spectrum of functionality from low-level granular control to high-level abstractions. This offering is divided into three main components:

### 1. High-Level SDK (Requires Solana Web3.js ≥v2.0)
### 1. High-Level SDK (Requires Solana Kit)
The High-Level SDK is our top recommendation for anyone who wants to integrate with the Whirlpool Program. It builds upon the Low-Level and Core SDKs to provide an easy-to-use interface for interacting with the Whirlpool Program. This SDK abstracts many of the underlying complexities, such as tick array management, and makes managing pools and positions, and executing swaps much simpler. It is suitable for developers who need efficient, high-level functionalities and want to minimize manual configuration and management.

### 2. Core SDK
The Core SDK provides essential utilities for math operations and quotes, required for working with liquidity pools. This library focuses on calculations such as determining position status, price conversions, and computing quotes on adjusting liquidity and swaps. It is written in Rust but has been compiled to WebAssembly (Wasm) for easy integration into TypeScript projects.

### 3. Low-Level SDK (Requires Solana Web3.js SDK ≥v2.0)
The Low-Level SDK is autogenerated from our Interface Description Language (IDL) using Codama. This SDK provides direct program interactions and is designed for developers who need complete, low-level control over Whirlpool operations. It covers direct access to Solana accounts, instructions, and transactions.
### 3. Low-Level SDK (Requires Solana Kit)
The Low-Level SDK is autogenerated from our Interface Description Language (IDL) using Codama. This SDK provides direct program interactions and is designed for developers who need complete, low-level control over Whirlpool operations. It covers direct access to Solana accounts, instructions, and transactions.
10 changes: 5 additions & 5 deletions docs/whirlpool/docs/01-Welcome.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The Whirlpools SDKs are our primary set of SDKs designed to provide enhanced, mo

#### 1. High-Level SDK
- **TypeScript**: [@orca-so/whirlpools](https://www.npmjs.com/package/@orca-so/whirlpools)
- Compatible with Solana Web3.js SDK version `^2.0`
- Compatible with Solana Kit
- **Rust**: [orca_whirlpools](https://crates.io/crates/orca_whirlpools)
- Compatible with Solana SDK versions `^1.18.0` but `<3.0.0`. By default, Cargo will install the latest version of Solana SDK `^v2`. This can cause dependcy issues when using older versions. To solve this you can apply a lockfile patch with the following command:
```bash
Expand All @@ -45,7 +45,7 @@ The Whirlpools SDKs are our primary set of SDKs designed to provide enhanced, mo

#### 3. Low-Level SDK
- **TypeScript**: [@orca-so/whirlpools-client](https://www.npmjs.com/package/@orca-so/whirlpools-client)
- Compatible with Solana Web3.js SDK version `^2.0`
- Compatible with Solana Kit
- **Rust**: [orca_whirlpools_client](https://crates.io/crates/orca_whirlpools_client)
- Compatible with `anchor` versions `^0.26` but `<0.30`. If you enable the `anchor` feature of `orca_whirlpools_client` in `cargo.toml` while using a version of anchor that's `^0.30` in your project, you may need to apply a lockfile patch to switch to a lower version:
```bash
Expand All @@ -59,13 +59,13 @@ The Whirlpools SDKs are our primary set of SDKs designed to provide enhanced, mo
- **Description**: The Low-Level SDK is autogenerated from the Whirlpool Program's Interface Description Language (IDL) using Codama. This SDK provides direct program interactions and is designed for developers who need complete, low-level control over Whirlpool operations. It covers direct access to Solana accounts, instructions, and transactions.

### Legacy SDK
- **TypeScript**: [@orca-so/whirlpools-sdk](https://www.npmjs.com/package/@orca-so/whirlpools-sdk) (Requires Solana Web3.js SDK `<v2.0`)
- **Description**: Despite being called "Legacy", this SDK remains a reliable choice for integrating with projects that use Solana Web3.js versions older than v2.0. It offers foundational tools for interacting with Orca's Whirlpool Program and includes utilities from @orca-so/common-sdk.
- **TypeScript**: [@orca-so/whirlpools-sdk](https://www.npmjs.com/package/@orca-so/whirlpools-sdk) (Compatible with Solana Web3.js)
- **Description**: Despite being called "Legacy", this SDK remains a reliable choice for integrating with projects that use Solana Web3.js. It offers foundational tools for interacting with Orca's Whirlpool Program and includes utilities from @orca-so/common-sdk.

## How to use this documentation

In the next section you will find information about the Whirlpool Program and its architecture.

In the following sections you will find documentation on the Whirlpools SDKs and the Legacy SDK and how to use it to interact with the program.

If you have any questions or need help, feel free to reach out to us on the [Discord](https://discord.orca.so).
If you have any questions or need help, feel free to reach out to us on the [Discord](https://discord.orca.so).
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This document covers the essential setup required to start building on Orca’s
Install the necessary packages:

```bash
npm install typescript @orca-so/whirlpools @solana/web3.js@2
npm install typescript @orca-so/whirlpools @solana/kit
```

Initialize the project as a TypeScript project:
Expand Down Expand Up @@ -69,7 +69,7 @@ You can [generate a file system wallet using the Solana CLI](https://docs.solana
<Tabs groupId="programming-languages">
<TabItem value="ts" label="Typescript" default>
```tsx
import { createKeyPairSignerFromBytes } from '@solana/web3.js';
import { createKeyPairSignerFromBytes } from '@solana/kit';
import fs from 'fs';

const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
Expand Down Expand Up @@ -132,7 +132,7 @@ Once your wallet is created, you will need some SOL to pay for transactions. You
<Tabs groupId="programming-languages">
<TabItem value="ts" label="Typescript" default>
```tsx
import { generateKeyPair, createSolanaRpc, devnet, getAddressFromPublicKey } from '@solana/web3.js';
import { generateKeyPair, createSolanaRpc, devnet, getAddressFromPublicKey } from '@solana/kit';

const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
const wallet = await generateKeyPairSigner();
Expand Down Expand Up @@ -183,4 +183,4 @@ After funding your wallet, you can set the wallet as the **FUNDER** for future t
</Tabs>

## Next steps
Once you’ve completed the setup, you can move on to building more complex functionalities using the Orca SDK, such as creating and managing pools, providing liquidity, etc. Refer to individual function documentation to use this wallet setup in action.
Once you’ve completed the setup, you can move on to building more complex functionalities using the Orca SDK, such as creating and managing pools, providing liquidity, etc. Refer to individual function documentation to use this wallet setup in action.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Liquidity pools are a foundational concept in DeFi, enabling users to trade toke

- **Splash Pools**: Splash Pools are the simplest type of liquidity pool. They are ideal for those looking to launch a new token with minimal parameters. You only need to provide the mint addresses of the two tokens and set the initial price. Splash Pools offer an easy entry point into liquidity provision, making them especially appealing for community-driven projects like memecoins. These projects often prioritize community engagement over technical complexity, and Splash Pools provide a straightforward way to get started.

- **Concentrated Liquidity Pools:** Concentrated Liquidity Pools are more advanced and allow liquidity providers to concentrate their liquidity within specific price ranges. This results in higher capital efficiency but requires a deeper understanding of how to manage liquidity. Concentrated Liquidity Pools are better suited for experienced users who want greater control over their liquidity.
- **Concentrated Liquidity Pools:** Concentrated Liquidity Pools are more advanced and allow liquidity providers to concentrate their liquidity within specific price ranges. This results in higher capital efficiency but requires a deeper understanding of how to manage liquidity. Concentrated Liquidity Pools are better suited for experienced users who want greater control over their liquidity.

## 2. Getting Started Guide

Expand All @@ -41,7 +41,7 @@ Splash Pools are the easiest way to get started:
<TabItem value="ts" label="Typescript" default>
```tsx
import { createSplashPoolInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { generateKeyPairSigner, createSolanaRpc, devnet, address } from '@solana/web3.js';
import { generateKeyPairSigner, createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
Expand Down Expand Up @@ -93,7 +93,7 @@ Splash Pools are the easiest way to get started:
"Initialization Cost: {} lamports",
result.initialization_cost
);
}
}
```
</TabItem>
</Tabs>
Expand All @@ -112,7 +112,7 @@ Concentrated Liquidity Pools offer more flexibility:
<TabItem value="ts" label="Typescript" default>
```tsx
import { createConcentratedLiquidityPoolInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { generateKeyPairSigner, createSolanaRpc, devnet, address } from '@solana/web3.js';
import { generateKeyPairSigner, createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
Expand Down Expand Up @@ -201,4 +201,4 @@ If you want to maximize capital efficiency, you can use the flexibility of Conce

## 4. Next Steps

After creating a liquidity pool, the pool is still empty and requires liquidity for people to trade against. To make the pool functional, open a position and add liquidity. This enables traders to swap between tokens and helps you start earning fees.
After creating a liquidity pool, the pool is still empty and requires liquidity for people to trade against. To make the pool functional, open a position and add liquidity. This enables traders to swap between tokens and helps you start earning fees.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Similarly, when using Fetch Pools, which iterates through all possible tick spac
<TabItem value="ts" label="Typescript" default>
```tsx
import { fetchSplashPool, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
Expand Down Expand Up @@ -85,7 +85,7 @@ Similarly, when using Fetch Pools, which iterates through all possible tick spac
<TabItem value="ts" label="Typescript" default>
```tsx
import { fetchConcentratedLiquidityPool, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
Expand Down Expand Up @@ -145,7 +145,7 @@ Similarly, when using Fetch Pools, which iterates through all possible tick spac
<TabItem value="ts" label="Typescript" default>
```tsx
import { fetchWhirlpoolsByTokenPair, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A position in a liquidity pool represents your contribution of liquidity, which
Upon creation of the position, an NFT will be minted to represent ownership of the position. This NFT is used by the program to verify your ownership when adjusting liquidity, harvesting rewards, or closing the position. For more information, refer to [Tokenized Positions](../../../02-Architecture%20Overview/04-Tokenized%20Positions.md).

> ⚠️ **Risk of Divergence loss**: The ratio of Token A to Token B that you deposit as liquidity is determined by several factors, including the current price. As trades occur against the pool, the amounts of Token A and Token B in the pool — and in your position — will change, which affects the price of the tokens relative to each other. This can work to your advantage, but it may also result in the combined value of your tokens (including any earned fees and rewards) being lower than when you initially provided liquidity.

> ⚠️ Do not burn the position NFT, as burning it will result in the indefinite loss of your position and liquidity.

## 2. Getting Started Guide
Expand All @@ -41,7 +41,7 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
<TabItem value="ts" label="Typescript" default>
```tsx
import { openFullRangePositionInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { createSolanaRpc, devnet, address } from '@solana/kit';
import { loadWallet } from './utils';

await setWhirlpoolsConfig('solanaDevnet');
Expand Down Expand Up @@ -82,9 +82,9 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
let wallet = load_wallet();
let whirlpool_address = Pubkey::from_str("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt").unwrap();
let param = IncreaseLiquidityParam::TokenA(10);

let result = open_full_range_position_instructions(
&rpc,
&rpc,
whirlpool_address,
param,
Some(100),
Expand Down Expand Up @@ -115,7 +115,7 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
<TabItem value="ts" label="Typescript" default>
```tsx
import { openPositionInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { createSolanaRpc, devnet, address } from '@solana/kit';
import { loadWallet } from './utils';

await setWhirlpoolsConfig('solanaDevnet');
Expand Down Expand Up @@ -158,9 +158,9 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
let wallet = load_wallet();
let whirlpool_address = Pubkey::from_str("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt").unwrap();
let param = IncreaseLiquidityParam::TokenA(10);

let result = open_position_instructions(
&rpc,
&rpc,
whirlpool_address,
0.001,
100.0,
Expand Down Expand Up @@ -192,4 +192,4 @@ After opening a position, you can:
- [Add or Remove Liquidity](03-Adjust%20Liquidity.mdx): Adjust the amount of liquidity in your position based on market conditions.
- [Harvest Rewards](04-Harvest.mdx): Collect rewards and fees without closing the position.
- [Monitor Performance](02-Fetch%20Positions.mdx): Track your position's performance and earned fees.
- [Close Position](05-Close%20Position.mdx): When you decide to exit, close the position and withdraw the provided tokens along with any earned fees.
- [Close Position](05-Close%20Position.mdx): When you decide to exit, close the position and withdraw the provided tokens along with any earned fees.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Fetching positions is a straightforward process:
<TabItem value="ts" label="Typescript" default>
```tsx
import { fetchPositionsForOwner, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
Expand Down Expand Up @@ -75,7 +75,7 @@ Fetching all positions in a Whirlpool is a straightforward process:
<TabItem value="ts" label="Typescript" default>
```tsx
import { fetchPositionsInWhirlpool, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { createSolanaRpc, devnet, address } from '@solana/kit';

await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
Expand Down Expand Up @@ -122,4 +122,4 @@ After fetching positions, you could:
- [Harvest Rewards](04-Harvest.mdx): Collect rewards and fees without closing the position.
- [Close Position](05-Close%20Position.mdx): When you decide to exit, close the position and withdraw the provided tokens along with any earned fees.

By fetching the positions, you gain visibility into your liquidity positions and can take necessary actions to optimize returns.
By fetching the positions, you gain visibility into your liquidity positions and can take necessary actions to optimize returns.
Loading
Loading