Skip to content

Commit

Permalink
Update and fix documentation (#458)
Browse files Browse the repository at this point in the history
* Update wallet management. Fix code examples

* Fix typedocs

* Fix header

* Resolve comments

---------

Co-authored-by: calintje <csimon@orca.so>
  • Loading branch information
calintje and calintje authored Nov 5, 2024
1 parent 6d93632 commit ed6ad5b
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 48 deletions.
13 changes: 2 additions & 11 deletions docs/whirlpool/docs/03-Whirlpools SDK/01-Environment Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,15 @@ Initialize the project as a TypeScript project:
npx tsc --init
```

## 2. Wallet Creation
## 2. Wallet Management

You can create a wallet using `generateKeyPairSigner()` from the Solana SDK.

```tsx
import { generateKeyPairSigner } from '@solana/web3.js';

const wallet = await generateKeyPairSigner();
```

Alternatively, if you have your wallet stored as a 64-byte private key in a `wallet.json` file, you can load it using `createKeyPairSignerFromBytes`.
You can [generate a file system wallet using the Solana CLI](https://docs.solanalabs.com/cli/wallets/file-system) and load it using `createKeyPairSignerFromBytes`.

```tsx
import { createKeyPairSignerFromBytes } from '@solana/web3.js';
import fs from 'fs';

const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));

const wallet = await createKeyPairSignerFromBytes(keyPairBytes);
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Splash Pools are the easiest way to get started:
```tsx
import { createSplashPoolInstructions } from '@orca-so/whirlpools'

const { poolAddress, instructions, initializationCost } = await createSplashPoolInstructions(
const { poolAddress, instructions, estInitializationCost } = await createSplashPoolInstructions(
rpc,
tokenMintOne,
tokenMintTwo,
Expand All @@ -60,7 +60,7 @@ Concentrated Liquidity Pools offer more flexibility:
```tsx
import { createConcentratedLiquidityPool } from '@orca-so/whirlpools'

const { poolAddress, instructions, initializationCost } = await createConcentratedLiquidityPool(
const { poolAddress, instructions, estInitializationCost } = await createConcentratedLiquidityPool(
rpc,
tokenMintOne,
tokenMintTwo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ For more details, refer to our [Environment Setup Guide](../01-Environment%20Set
4. **Funder**: This can be your wallet, which will fund the pool initialization. If the funder is not specified, the default wallet will be used. You can configure the default wallet through the SDK.
5. **Create Instructions**: Use the appropriate function to generate the necessary instructions.
```tsx
const { quote, instructions, initializationCost } = await openPositionInstructions(
const { quote, instructions, initializationCost, positionMint } = await openPositionInstructions(
rpc,
poolAddress,
param,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ Adjusting liquidity in an existing position can be done as follows:
5. **Funder**: This can be your wallet, which will fund the pool initialization. If a funder is not specified, the default wallet will be used. You can configure the default wallet through the SDK.
6. **Create Instructions**: Use the appropriate function to generate the necessary instructions.
```tsx
const {quote, instructions, initializationCost} = await increaseLiquidityInstructions(
const { quote, instructions, initializationCost, positionMint } = await increaseLiquidityInstructions(
rpc,
positionMint,
param,
slippageTolerance,
wallet
)

const { quote, instructions } = await decreaseLiquidityInstructions(
rpc,
positionMint,
param,
Expand Down
14 changes: 8 additions & 6 deletions ts-sdk/whirlpool/src/createPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,18 @@ export type CreatePoolInstructions = {
*
* @example
* import { createSplashPoolInstructions } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { generateKeyPairSigner, createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await generateKeyPairSigner(); // CAUTION: This wallet is not persistent.
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const tokenMintOne = "TOKEN_MINT_ADDRESS_1";
* const tokenMintTwo = "TOKEN_MINT_ADDRESS_2";
* const initialPrice = 0.01;
*
* const { poolAddress, instructions, initializationCost } = await createSplashPoolInstructions(
* const { poolAddress, instructions, estInitializationCost } = await createSplashPoolInstructions(
* devnetRpc,
* tokenMintOne,
* tokenMintTwo,
Expand Down Expand Up @@ -110,18 +111,19 @@ export function createSplashPoolInstructions(
*
* @example
* import { createConcentratedLiquidityPool } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { generateKeyPairSigner, createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await generateKeyPairSigner(); // CAUTION: This wallet is not persistent.
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const tokenMintOne = "TOKEN_MINT_ADDRESS_1";
* const tokenMintTwo = "TOKEN_MINT_ADDRESS_2";
* const tickSpacing = 64;
* const initialPrice = 0.01;
*
* const { poolAddress, instructions, initializationCost } = await createConcentratedLiquidityPool(
* const { poolAddress, instructions, estInitializationCost } = await createConcentratedLiquidityPool(
* devnetRpc,
* tokenMintOne,
* tokenMintTwo,
Expand Down
10 changes: 6 additions & 4 deletions ts-sdk/whirlpool/src/decreaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ function getDecreaseLiquidityQuote(
*
* @example
* import { decreaseLiquidityInstructions } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { generateKeyPairSigner, createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await generateKeyPairSigner(); // CAUTION: This wallet is not persistent.
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const positionMint = "POSITION_MINT";
Expand Down Expand Up @@ -287,10 +288,11 @@ export type ClosePositionInstructions = DecreaseLiquidityInstructions & {
*
* @example
* import { closePositionInstructions } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { generateKeyPairSigner, createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await generateKeyPairSigner(); // CAUTION: This wallet is not persistent.
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const positionMint = "POSITION_MINT";
Expand Down
5 changes: 3 additions & 2 deletions ts-sdk/whirlpool/src/harvest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ export type HarvestPositionInstructions = {
* A promise that resolves to an object containing the instructions, fees, and rewards quotes.
* @example
* import { harvestPositionInstructions } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { createKeyPairSignerFromBytes , createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await createKeyPairSignerFromBytes(keyPairBytes);
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const positionMint = "POSITION_MINT";
Expand Down
22 changes: 12 additions & 10 deletions ts-sdk/whirlpool/src/increaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,22 @@ function getIncreaseLiquidityQuote(
* @param {IncreaseLiquidityQuoteParam} param - The parameters for adding liquidity. Can specify liquidity, Token A, or Token B amounts.
* @param {number} [slippageToleranceBps=SLIPPAGE_TOLERANCE_BPS] - The maximum acceptable slippage, in basis points (BPS).
* @param {TransactionSigner} [authority=FUNDER] - The account that authorizes the transaction.
* @returns {Promise<IncreaseLiquidityInstructions>} - Instructions and quote for increasing liquidity.
* @returns {Promise<IncreaseLiquidityInstructions>} A promise that resolves to an object containing instructions, quote, position mint address, and initialization costs for increasing liquidity.
*
* @example
* import { increaseLiquidityInstructions } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { generateKeyPairSigner, createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await generateKeyPairSigner(); // CAUTION: This wallet is not persistent.
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const positionMint = "POSITION_MINT";
*
* const param = { tokenA: 1_000_000n };
*
* const { quote, instructions, initializationCost } = await increaseLiquidityInstructions(
* const { quote, instructions, initializationCost, positionMint } = await increaseLiquidityInstructions(
* devnetRpc,
* positionMint,
* param,
Expand Down Expand Up @@ -464,21 +465,22 @@ async function internalOpenPositionInstructions(
* @param {IncreaseLiquidityQuoteParam} param - The parameters for adding liquidity, where one of `liquidity`, `tokenA`, or `tokenB` must be specified. The SDK will compute the others.
* @param {number} [slippageToleranceBps=SLIPPAGE_TOLERANCE_BPS] - The maximum acceptable slippage, in basis points (BPS).
* @param {TransactionSigner} [funder=FUNDER] - The account funding the transaction.
* @returns {Promise<IncreaseLiquidityInstructions>} - Instructions and quote for opening a full-range position.
* @returns {Promise<IncreaseLiquidityInstructions>} A promise that resolves to an object containing the instructions, quote, position mint address, and initialization costs for increasing liquidity.
*
* @example
* import { openFullRangePositionInstructions } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { generateKeyPairSigner, createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await generateKeyPairSigner(); // CAUTION: This wallet is not persistent.
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const poolAddress = "POOL_ADDRESS";
*
* const param = { tokenA: 1_000_000n };
*
* const { quote, instructions, initializationCost } = await openFullRangePositionInstructions(
* const { quote, instructions, initializationCost, positionMint } = await openFullRangePositionInstructions(
* devnetRpc,
* poolAddress,
* param,
Expand Down Expand Up @@ -530,7 +532,7 @@ export async function openFullRangePositionInstructions(
* @param {number} [slippageToleranceBps=SLIPPAGE_TOLERANCE_BPS] - The slippage tolerance for adding liquidity, in basis points (BPS).
* @param {TransactionSigner} [funder=FUNDER] - The account funding the transaction.
*
* @returns {Promise<IncreaseLiquidityInstructions>} A promise that resolves to an object containing liquidity information and the list of instructions needed to open the position.
* @returns {Promise<IncreaseLiquidityInstructions>} A promise that resolves to an object containing instructions, quote, position mint address, and initialization costs for increasing liquidity.
*
* @example
* import { openPositionInstructions } from '@orca-so/whirlpools';
Expand All @@ -546,7 +548,7 @@ export async function openFullRangePositionInstructions(
* const lowerPrice = 0.00005;
* const upperPrice = 0.00015;
*
* const { quote, instructions, initializationCost } = await openPositionInstructions(
* const { quote, instructions, initializationCost, positionMint } = await openPositionInstructions(
* devnetRpc,
* poolAddress,
* param,
Expand Down
12 changes: 3 additions & 9 deletions ts-sdk/whirlpool/src/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ export type PoolInfo = (InitializablePool | InitializedPool) & {
*
* @example
* import { fetchSplashPool } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { createSolanaRpc, devnet } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const tokenMintOne = "TOKEN_MINT_ONE";
* const tokenMintTwo = "TOKEN_MINT_TWO";
Expand Down Expand Up @@ -101,11 +99,9 @@ export async function fetchSplashPool(
*
* @example
* import { fetchPool } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { createSolanaRpc, devnet } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const tokenMintOne = "TOKEN_MINT_ONE";
* const tokenMintTwo = "TOKEN_MINT_TWO";
Expand Down Expand Up @@ -174,11 +170,9 @@ export async function fetchConcentratedLiquidityPool(
*
* @example
* import { fetchWhirlpoolsByTokenPair } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { createSolanaRpc, devnet } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const tokenMintOne = "TOKEN_MINT_ONE";
* const tokenMintTwo = "TOKEN_MINT_TWO";
Expand Down
5 changes: 3 additions & 2 deletions ts-sdk/whirlpool/src/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ function getSwapQuote<T extends SwapParams>(
*
* @example
* import { swapInstructions } from '@orca-so/whirlpools';
* import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';
* import { generateKeyPairSigner, createSolanaRpc, devnet, lamports } from '@solana/web3.js';
*
* const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
* const wallet = await generateKeyPairSigner();
* const keyPairBytes = new Uint8Array(JSON.parse(fs.readFileSync('path/to/solana-keypair.json', 'utf8')));
* const wallet = await generateKeyPairSigner(); // CAUTION: This wallet is not persistent.
* await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
*
* const poolAddress = "POOL_ADDRESS";
Expand Down

0 comments on commit ed6ad5b

Please sign in to comment.