-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Getting Started" docs for TS SDK (#378)
* Base docs organization * Update welcome * Update Getting Started docs. Add environment setup, create pool, open position. * Finalize draft for ts-sdk docs * Fix spelling. Fix linter issue. Fix linking. * Resolve comments * Rename files. Remove 'Monitor' category. Fix links, fix build. * Streamline content for conceptual and usage-focused guides. Move detailed function explanation to Typedocs. * Fix typos * Fix links * Resolve comments * Update explainer on divergence loss --------- Co-authored-by: calintje <[email protected]>
- Loading branch information
Showing
21 changed files
with
760 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
sidebar_position: 1 | ||
slug: / | ||
--- | ||
import DocCard from '@theme/DocCard'; | ||
|
||
# Welcome | ||
|
||
Whirlpools is an open-sourced concentrated liquidity automated market maker (CLAMM) program built for the Solana ecosystem. | ||
|
||
<DocCard item={{ | ||
type: 'link', | ||
href: 'https://github.com/orca-so/whirlpools', | ||
label: 'Whirlpools Program', | ||
description: 'https://github.com/orca-so/whirlpools' | ||
}} /> | ||
|
||
## Introduction to Solana. | ||
|
||
On Solana, all data is stored in what is referred to as accounts. The way accounts are organized on Solana is similar to a key-value store, where each entry in the database is called an account. The key is the account's address, and the value is the data stored in the account. | ||
|
||
Some accounts only store data, such as a token account for your favorite token. Other accounts store programs. For example, there is a Token Program responsible for managing token accounts and transfers. Every time you send a token, you're sending a transaction to the Token Program, which updates the balances of the accounts involved. | ||
|
||
The Whirlpools Program is also a program. It can create new data accounts if you instruct it to, and even set you as the owner of those accounts. Accounts that you can own include Splash Pools, Concentrated Liquidity Pools, and liquidity positions. For these accounts, you'll pay rent. But here's the good part: this is no ordinary rent—you get the full rent back if you decide to close the account! You only pay the transaction costs on the Solana network, which, as you may know, are very low. You can also instruct the program to swap tokens against one of the many liquidity pools that hold the tokens you'd like to trade. | ||
|
||
You interact with the Solana network by sending transactions to interact with accounts. Transactions are a sequence of instructions that are executed atomically on the network. The execution logic for these instructions is stored in programs (smart contracts) that run on the network. | ||
|
||
Interacting with the Solana network and its many existing programs is easier than you might think. There are several SDKs available to simplify the process. | ||
|
||
## Whirlpools SDK | ||
|
||
The Whirlpools SDK is an open-source library that allows developers to interact with the Whirlpools Program and is intended to be used in conjunction with the Solana SDK. Simply put, you use the Whirlpools SDK to create instructions, and the Solana SDK to send them to the network. | ||
|
||
Some of the main features are: | ||
- Create instructions to set up a new pool, open positions, add or remove liquidity, and swap tokens. | ||
- Get quotes for swaps. | ||
- Query the state of pools to retrieve information about asset prices, liquidity, and fees. | ||
|
||
## How to use this documentation | ||
|
||
In the next section you will find information about the Whirlpools Program and its architecture. | ||
|
||
In the following sections you will find information about the Whirlpools SDK and how to use it to interact with the program. | ||
|
||
We also provide start-to-end tutorials for specific use cases combining the Whirlpools SDK with the Solana SDK. | ||
|
||
If you have any questions or need help, feel free to reach out to us on the [Discord](https://discord.orca.so). |
3 changes: 3 additions & 0 deletions
3
docs/whirlpool/docs/02-Whirlpools Overview/01-Account Architecture.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Account Architecture | ||
|
||
Coming soon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Coming soon |
1 change: 1 addition & 0 deletions
1
docs/whirlpool/docs/02-Whirlpools Overview/03-Understanding Tick Arrays.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Coming soon |
1 change: 1 addition & 0 deletions
1
docs/whirlpool/docs/02-Whirlpools Overview/04-Tokenized Positions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Coming soon |
1 change: 1 addition & 0 deletions
1
docs/whirlpool/docs/02-Whirlpools Overview/05-Whirlpool Fees.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Coming soon |
Binary file added
BIN
+7.08 KB
docs/whirlpool/docs/02-Whirlpools Overview/img/architecture-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions
73
docs/whirlpool/docs/03-Whirlpools SDK/01-Environment Setup.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Environment setup | ||
|
||
This document covers the essential setup required to start building on Orca’s SDK using the Whirlpools protocol. It includes wallet setup, RPC client configuration, airdropping tokens for testing, and the basics of interacting with the Solana ecosystem. | ||
|
||
## Prerequisites | ||
|
||
Before you start, ensure you have Node.js version 20 or higher installed on your machine. Download it from the official website: https://nodejs.org/. | ||
|
||
## 1. Initialize a new project | ||
Create a new project directory: | ||
|
||
```bash | ||
mkdir whirlpools | ||
cd whirlpools | ||
``` | ||
|
||
Initialize a new Node.js project: | ||
|
||
```bash | ||
npm init -y | ||
``` | ||
|
||
Install the necessary packages: | ||
|
||
```bash | ||
npm install typescript @orca-so/whirlpools @solana/web3.js@rc | ||
``` | ||
|
||
Initialize the project as a TypeScript project: | ||
|
||
```bash | ||
npx tsc --init | ||
``` | ||
|
||
## 3. Wallet Creation | ||
|
||
You can create a wallet using `generateKeyPairSigner()` from the Solana SDK. | ||
|
||
```tsx | ||
import { generateKeyPairSigner } from '@solana/web3.js'; | ||
|
||
const wallet = await generateKeyPairSigner(); | ||
``` | ||
|
||
> ⚠️ Important: Never share your private key publicly. | ||
## 4. Airdrop SOL to Your Wallet | ||
|
||
Once your wallet is created, you will need some SOL to pay for transactions. You can request an airdrop of SOL from the network, but this is only available on **Devnet** and **Testnet**. | ||
|
||
```tsx | ||
import { generateKeyPair, createSolanaRpc, devnet, getAddressFromPublicKey } from '@solana/web3.js'; | ||
|
||
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com')); | ||
const wallet = await generateKeyPairSigner(); | ||
devnetRpc.requestAirdrop( | ||
wallet.address, | ||
lamports(1000000000n) | ||
).send() | ||
``` | ||
|
||
## 5. Set the FUNDER for Transactions | ||
|
||
After funding your wallet, you can set the wallet as the **FUNDER** for future transactions within the SDK. The funder is the account that will cover the transaction costs for initializing pools, providing liquidity, etc. | ||
```tsx | ||
import { setDefaultFunder } from '@orca-so/whirlpools'; | ||
|
||
setDefaultFunder(wallet); | ||
``` | ||
|
||
## 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. |
94 changes: 94 additions & 0 deletions
94
docs/whirlpool/docs/03-Whirlpools SDK/02-Whirlpool Management/01-Create Pool.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
sidebar_label: Create Liquidity Pools | ||
--- | ||
|
||
# Creating Liquidity Pools on Orca | ||
|
||
Creating liquidity pools on Orca is an essential step for launching your token and enabling trading. In this guide, we'll explore two types of liquidity pools available in the Orca ecosystem, **Splash Pools** and **Concentrated Liquidity Pools**, and help you understand how to create them, their differences, and which one best suits your needs. | ||
|
||
## 1. Introduction to Pool Types | ||
|
||
### Overview | ||
|
||
Liquidity pools are a foundational concept in DeFi, enabling users to trade tokens without relying on traditional order books. On Orca, liquidity pools provide the means for traders to swap between two tokens, while liquidity providers earn fees by supplying the tokens to the pool. | ||
|
||
### Splash Pools vs. Concentrated Liquidity Pools | ||
|
||
- **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. | ||
|
||
## 2. Getting Started Guide | ||
|
||
Before creating a Splash Pool or a Concentrated Liquidity Pool, ensure you have completed the environment setup: | ||
- **RPC Setup**: Use a Solana RPC client to communicate with the blockchain. | ||
- **Wallet Creation**: Create a wallet to interact with the Solana network. | ||
- **Devnet Airdrop**: Fund your wallet with a Solana devnet airdrop to cover transaction fees. | ||
|
||
For more details, refer to our [Environment Setup Guide](../01-Environment%20Setup.md) | ||
|
||
### Creating Splash Pools | ||
|
||
Splash Pools are the easiest way to get started: | ||
|
||
1. **Token Mint Addresses**: Provide the mint addresses of the two tokens that will make up the liquidity pool. The order of the tokens is important: the first token will be priced in terms of the second token. This means that the price you set will reflect how many units of the second token are needed to equal one unit of the first token. For example, if you set the price to 0.0001 SOL, this means that one unit of the first token is worth 0.0001 units of the second token (SOL). Make sure to verify the order of your tokens. | ||
2. **Initial Price**: Set the initial price of token 1 in terms of token 2. | ||
3. **Funder**: This will be your wallet, which will fund the initialization process. | ||
4. **Create Instructions**: Use the appropriate function to generate the required pool creation instructions. | ||
```tsx | ||
import { createSplashPoolInstructions } from '@orca-so/whirlpools' | ||
|
||
const { poolAddress, instructions, initializationCost } = await createSplashPoolInstructions( | ||
rpc, | ||
tokenMintOne, | ||
tokenMintTwo, | ||
initialPrice, | ||
wallet | ||
); | ||
``` | ||
5. Submit Transaction: Include the generated pool creation instructions in a Solana transaction and send it to the network using the Solana SDK. | ||
|
||
### Creating Concentrated Liquidity Pools | ||
|
||
Concentrated Liquidity Pools offer more flexibility: | ||
|
||
1. **Token Mint Addresses**: Provide the two token mints. | ||
2. **Tick Spacing**: Set the tick spacing, which defines the intervals for price ticks. Visit [this link](https://orca-so.gitbook.io/orca-developer-portal/whirlpools/interacting-with-the-protocol/orca-whirlpools-parameters#initialized-feetier-and-tickspacing) to learn more about the available values of tick spacing and their corresponding fee rates. | ||
3. **Initial Price**: Specify the initial price of token 1 in terms of token 2. | ||
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 create the pool. | ||
```tsx | ||
import { createConcentratedLiquidityPool } from '@orca-so/whirlpools' | ||
|
||
const { poolAddress, instructions, initializationCost } = await createConcentratedLiquidityPool( | ||
rpc, | ||
tokenMintOne, | ||
tokenMintTwo, | ||
tickSpacing, | ||
initialPrice, | ||
wallet | ||
); | ||
``` | ||
6. **Submit Transaction**: Include the generated pool creation instructions in a Solana transaction and send it to the network using the Solana SDK. | ||
### Comparison | ||
| Feature | Splash Pools | Concentrated Liquidity Pools | | ||
| ------------------ | ------------------ | -------------------------------- | | ||
| Complexity | Low | High | | ||
| Initial Parameters | Token mints, price | Token mints, tick spacing, price | | ||
| Capital Efficiency | Moderate | High | | ||
| Ideal For | Beginners | Advanced Users | | ||
## 3. Usage Examples | ||
### Launching a Token Pair with a Splash Pool | ||
Suppose you want to launch a new memecoin and pair it with USDC. You can leverage the simplicity of Splash Pools to quickly set up the pool with an initial price. This is ideal if you want to keep things simple and start earning trading fees with minimal configuration. For example, if a development team is building a launchpad for memecoins, Splash Pools are an ideal solution. | ||
### Creating a Concentrated Liquidity Pool for Efficiency | ||
If you want to maximize capital efficiency, you can use the flexibility of Concentrated Liquidity Pools to define specific price ranges for your liquidity. This approach is beneficial when you expect price movements within certain bounds and want to concentrate liquidity accordingly. For example, a DeFi protocol might use a Concentrated Liquidity Pool to facilitate a stablecoin-stablecoin pair, where the price is expected to remain within a tight range. By concentrating liquidity in this range, the protocol can maximize returns for liquidity providers and reduce slippage for traders. | ||
## 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. |
66 changes: 66 additions & 0 deletions
66
docs/whirlpool/docs/03-Whirlpools SDK/02-Whirlpool Management/02-Fetch Pools.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
sidebar_label: Fetch Liquidity Pools | ||
--- | ||
|
||
# Fetching Liquidity Pools on Orca | ||
|
||
Monitoring and fetching details about liquidity pools on Orca is crucial for understanding their current state, whether you want to gather insights in a Splash Pool, a Concentrated Liquidity Pool, or all pools between specific token pairs. This guide will explain how to interact with the available functions to retrieve these details. | ||
|
||
## 1. Overview of Pool Fetching | ||
|
||
Fetching liquidity pool details helps developers gain insight into the current state of the pool, whether it is initialized or uninitialized, and retrieve relevant metrics like liquidity, price, and fee rates. | ||
|
||
The SDKs offer three main functions to help developers monitor the pools: | ||
- **Fetch Splash Pool**: Fetches the details of a specific Splash Pool. | ||
- **Fetch Concentrated Liquidity Pool**: Fetches the details of a specific Concentrated Liquidity Pool. | ||
- **Fetch Pools**: Fetches all possible liquidity pools between two token mints, with various tick spacings. | ||
|
||
### Initialized vs. Uninitialized Pools | ||
> Skip this section if you're using Splash Pools. | ||
Each token pair can have multiple pools based on different tick spacings, corresponding to various fee tiers. When using the Fetch Concentrated Liquidity Pool function, it’s possible to request a pool with a tick spacing that hasn't been used to create a pool for the given token pair. In this case, you’ll receive a pool object with default parameters and an additional field `initialized = false`, indicating that the pool has not been set up. | ||
|
||
Similarly, when using Fetch Pools, which iterates through all possible tick spacings for a given token pair, uninitialized pools can also be returned in this manner. The function will return both initialized and uninitialized pools, allowing you to identify pools that have not yet been created. | ||
|
||
## 2. Getting Started Guide | ||
|
||
### Fetching a Splash Pool | ||
|
||
1. **Token Mint Addresses**: Provide the mint addresses of the two tokens that make up the liquidity pool. | ||
2. **Fetch Pool Details**: Use the appropriate function to fetch the details of the specified Splash Pool. | ||
|
||
```tsx | ||
const poolInfo = await fetchSplashPool( | ||
rpc, | ||
tokenMintOne, | ||
tokenMintTwo | ||
); | ||
``` | ||
|
||
### Fetching a Concentrated Liquidity Pool | ||
|
||
1. **Token Mint Addresses**: Provide the mint addresses of the two tokens that make up the liquidity pool. | ||
2. **Tick Spacing**: Specify the tick spacing, which defines the intervals for price ticks. | ||
3. **Fetch Pool Details**: Use the appropriate function to fetch the details of the specified Concentrated Liquidity Pool. | ||
|
||
```tsx | ||
const poolInfo = await fetchConcentratedLiquidityPool( | ||
rpc, | ||
tokenMintOne, | ||
tokenMintTwo, | ||
tickSpacing | ||
); | ||
``` | ||
|
||
### Fetching Pools by Token Pairs | ||
|
||
1. **Token Mint Addresses**: Provide the mint addresses of the two tokens that make up the liquidity pool. | ||
2. **Fetch Pool Details**: Use the appropriate function to fetch the details of the specified pools. | ||
|
||
```tsx | ||
const pools = await fetchWhirlPools( | ||
rpc, | ||
tokenMintOne, | ||
tokenMintTwo | ||
); | ||
``` |
Oops, something went wrong.