Skip to content

Commit 7d2f507

Browse files
authored
Web3.js v2 -> Solana Kit (#788)
1 parent e62db2c commit 7d2f507

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+687
-673
lines changed

.changeset/long-wombats-hug.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@orca-so/whirlpools-example-ts-next": patch
3+
"@orca-so/tx-sender": patch
4+
"@orca-so/whirlpools": patch
5+
"@orca-so/whirlpools-docs": patch
6+
"@orca-so/whirlpools-client": patch
7+
"@orca-so/whirlpools-docs-ts": patch
8+
---
9+
10+
Switch from @solana/web3.js v2 to @solana/kit

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For specific use-cases you can opt for integrating with lower level packages suc
2424
* `@orca-so/whirlpools-client` & `orca_whirlpools_client` - auto-generated client for the Whirlpools program that contains account, instruction and error parsing.
2525
* `@orca-so/whirlpools-core` & `orca_whirlpools_core` - utility, math and quoting functions used by other packages.
2626

27-
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.
27+
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.
2828

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

docs/ts/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
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:
66

7-
### 1. High-Level SDK (Requires Solana Web3.js ≥v2.0)
7+
### 1. High-Level SDK (Requires Solana Kit)
88
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.
99

1010
### 2. Core SDK
1111
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.
1212

13-
### 3. Low-Level SDK (Requires Solana Web3.js SDK ≥v2.0)
14-
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.
13+
### 3. Low-Level SDK (Requires Solana Kit)
14+
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.

docs/whirlpool/docs/01-Welcome.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The Whirlpools SDKs are our primary set of SDKs designed to provide enhanced, mo
2929

3030
#### 1. High-Level SDK
3131
- **TypeScript**: [@orca-so/whirlpools](https://www.npmjs.com/package/@orca-so/whirlpools)
32-
- Compatible with Solana Web3.js SDK version `^2.0`
32+
- Compatible with Solana Kit
3333
- **Rust**: [orca_whirlpools](https://crates.io/crates/orca_whirlpools)
3434
- 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:
3535
```bash
@@ -45,7 +45,7 @@ The Whirlpools SDKs are our primary set of SDKs designed to provide enhanced, mo
4545

4646
#### 3. Low-Level SDK
4747
- **TypeScript**: [@orca-so/whirlpools-client](https://www.npmjs.com/package/@orca-so/whirlpools-client)
48-
- Compatible with Solana Web3.js SDK version `^2.0`
48+
- Compatible with Solana Kit
4949
- **Rust**: [orca_whirlpools_client](https://crates.io/crates/orca_whirlpools_client)
5050
- 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:
5151
```bash
@@ -59,13 +59,13 @@ The Whirlpools SDKs are our primary set of SDKs designed to provide enhanced, mo
5959
- **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.
6060

6161
### Legacy SDK
62-
- **TypeScript**: [@orca-so/whirlpools-sdk](https://www.npmjs.com/package/@orca-so/whirlpools-sdk) (Requires Solana Web3.js SDK `<v2.0`)
63-
- **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.
62+
- **TypeScript**: [@orca-so/whirlpools-sdk](https://www.npmjs.com/package/@orca-so/whirlpools-sdk) (Compatible with Solana Web3.js)
63+
- **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.
6464

6565
## How to use this documentation
6666

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

6969
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.
7070

71-
If you have any questions or need help, feel free to reach out to us on the [Discord](https://discord.orca.so).
71+
If you have any questions or need help, feel free to reach out to us on the [Discord](https://discord.orca.so).

docs/whirlpool/docs/03-Whirlpools SDKs/01-Whirlpools/02-Environment Setup.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This document covers the essential setup required to start building on Orca’s
3333
Install the necessary packages:
3434

3535
```bash
36-
npm install typescript @orca-so/whirlpools @solana/web3.js@2
36+
npm install typescript @orca-so/whirlpools @solana/kit
3737
```
3838

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

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

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

185185
## Next steps
186-
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.
186+
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.

docs/whirlpool/docs/03-Whirlpools SDKs/01-Whirlpools/03-Whirlpool Management/01-Create Pool.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Liquidity pools are a foundational concept in DeFi, enabling users to trade toke
1818

1919
- **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.
2020

21-
- **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.
21+
- **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.
2222

2323
## 2. Getting Started Guide
2424

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

4646
await setWhirlpoolsConfig('solanaDevnet');
4747
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
@@ -93,7 +93,7 @@ Splash Pools are the easiest way to get started:
9393
"Initialization Cost: {} lamports",
9494
result.initialization_cost
9595
);
96-
}
96+
}
9797
```
9898
</TabItem>
9999
</Tabs>
@@ -112,7 +112,7 @@ Concentrated Liquidity Pools offer more flexibility:
112112
<TabItem value="ts" label="Typescript" default>
113113
```tsx
114114
import { createConcentratedLiquidityPoolInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
115-
import { generateKeyPairSigner, createSolanaRpc, devnet, address } from '@solana/web3.js';
115+
import { generateKeyPairSigner, createSolanaRpc, devnet, address } from '@solana/kit';
116116

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

202202
## 4. Next Steps
203203

204-
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.
204+
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.

docs/whirlpool/docs/03-Whirlpools SDKs/01-Whirlpools/03-Whirlpool Management/02-Fetch Pools.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Similarly, when using Fetch Pools, which iterates through all possible tick spac
3030
<TabItem value="ts" label="Typescript" default>
3131
```tsx
3232
import { fetchSplashPool, setWhirlpoolsConfig } from '@orca-so/whirlpools';
33-
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
33+
import { createSolanaRpc, devnet, address } from '@solana/kit';
3434

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

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

150150
await setWhirlpoolsConfig('solanaDevnet');
151151
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));

docs/whirlpool/docs/03-Whirlpools SDKs/01-Whirlpools/04-Position Management/01-Open Position.mdx

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A position in a liquidity pool represents your contribution of liquidity, which
1717
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).
1818

1919
> ⚠️ **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.
20-
20+
2121
> ⚠️ Do not burn the position NFT, as burning it will result in the indefinite loss of your position and liquidity.
2222
2323
## 2. Getting Started Guide
@@ -41,7 +41,7 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
4141
<TabItem value="ts" label="Typescript" default>
4242
```tsx
4343
import { openFullRangePositionInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
44-
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
44+
import { createSolanaRpc, devnet, address } from '@solana/kit';
4545
import { loadWallet } from './utils';
4646

4747
await setWhirlpoolsConfig('solanaDevnet');
@@ -82,9 +82,9 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
8282
let wallet = load_wallet();
8383
let whirlpool_address = Pubkey::from_str("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt").unwrap();
8484
let param = IncreaseLiquidityParam::TokenA(10);
85-
85+
8686
let result = open_full_range_position_instructions(
87-
&rpc,
87+
&rpc,
8888
whirlpool_address,
8989
param,
9090
Some(100),
@@ -115,7 +115,7 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
115115
<TabItem value="ts" label="Typescript" default>
116116
```tsx
117117
import { openPositionInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
118-
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
118+
import { createSolanaRpc, devnet, address } from '@solana/kit';
119119
import { loadWallet } from './utils';
120120

121121
await setWhirlpoolsConfig('solanaDevnet');
@@ -158,9 +158,9 @@ For more details, refer to our [Environment Setup Guide](../02-Environment%20Set
158158
let wallet = load_wallet();
159159
let whirlpool_address = Pubkey::from_str("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt").unwrap();
160160
let param = IncreaseLiquidityParam::TokenA(10);
161-
161+
162162
let result = open_position_instructions(
163-
&rpc,
163+
&rpc,
164164
whirlpool_address,
165165
0.001,
166166
100.0,
@@ -192,4 +192,4 @@ After opening a position, you can:
192192
- [Add or Remove Liquidity](03-Adjust%20Liquidity.mdx): Adjust the amount of liquidity in your position based on market conditions.
193193
- [Harvest Rewards](04-Harvest.mdx): Collect rewards and fees without closing the position.
194194
- [Monitor Performance](02-Fetch%20Positions.mdx): Track your position's performance and earned fees.
195-
- [Close Position](05-Close%20Position.mdx): When you decide to exit, close the position and withdraw the provided tokens along with any earned fees.
195+
- [Close Position](05-Close%20Position.mdx): When you decide to exit, close the position and withdraw the provided tokens along with any earned fees.

docs/whirlpool/docs/03-Whirlpools SDKs/01-Whirlpools/04-Position Management/02-Fetch Positions.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Fetching positions is a straightforward process:
2727
<TabItem value="ts" label="Typescript" default>
2828
```tsx
2929
import { fetchPositionsForOwner, setWhirlpoolsConfig } from '@orca-so/whirlpools';
30-
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
30+
import { createSolanaRpc, devnet, address } from '@solana/kit';
3131

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

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

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

0 commit comments

Comments
 (0)