Whirlpool Essentials
Whirlpool Essentials is a core library to interacting with Orca Whirlpool Program in Python.
Documentation
Dependencies
This library have been tested in the following environment.
- Python: 3.10.6
- solders: 0.21.0
- solana: 0.35.1
- anchorpy: 0.20.1
Installation
pip install solana solders anchorpy
pip install whirlpool-essentials
Important Notes
V2 instructions and TokenExtensions
Whirlpool Essentials can handle v2 instructions with WhirlpoolIx.
HOWEVER the quote functions cannot handle TransferFee extension yet.
So please ensure that input and output token don't use TransferFee extension.
If its fee rate is zero, it can be ignored. (e.g. PYUSD)
General topics
- Whirlpool Essentials is NOT included in Orca's official SDK list, so the update may be delayed.
- Please use this package at your own risk.
Sample
Get SOL/USDC Whirlpool Price
import asyncio
from solana.rpc.async_api import AsyncClient
from solders.pubkey import Pubkey
from solders.keypair import Keypair
from orca_whirlpool.constants import ORCA_WHIRLPOOL_PROGRAM_ID
from orca_whirlpool.context import WhirlpoolContext
from orca_whirlpool.utils import PriceMath, DecimalUtil
SOL_USDC_8_WHIRLPOOL_PUBKEY = Pubkey.from_string("7qbRF6YsyGuLUVs6Y1q64bdVrfe4ZcUUz1JRdoVNUJnm")
async def main():
connection = AsyncClient(RPC_ENDPOINT_URL)
ctx = WhirlpoolContext(ORCA_WHIRLPOOL_PROGRAM_ID, connection, Keypair())
# get SOL/USDC(ts=8) whirlpool
whirlpool_pubkey = SOL_USDC_8_WHIRLPOOL_PUBKEY
whirlpool = await ctx.fetcher.get_whirlpool(whirlpool_pubkey)
decimals_a = (await ctx.fetcher.get_token_mint(whirlpool.token_mint_a)).decimals # SOL_DECIMAL
decimals_b = (await ctx.fetcher.get_token_mint(whirlpool.token_mint_b)).decimals # USDC_DECIMAL
print("whirlpool token_mint_a", whirlpool.token_mint_a)
print("whirlpool token_mint_b", whirlpool.token_mint_b)
print("whirlpool tick_spacing", whirlpool.tick_spacing)
print("whirlpool tick_current_index", whirlpool.tick_current_index)
print("whirlpool sqrt_price", whirlpool.sqrt_price)
price = PriceMath.sqrt_price_x64_to_price(whirlpool.sqrt_price, decimals_a, decimals_b)
print("whirlpool price", DecimalUtil.to_fixed(price, decimals_b))
asyncio.run(main())
Get Liquidity Distribution of SOL/USDC Whirlpool
import asyncio
import os
from dotenv import load_dotenv
from solders.pubkey import Pubkey
from solana.rpc.async_api import AsyncClient
from orca_whirlpool.accounts import AccountFinder, AccountFetcher
from orca_whirlpool.constants import ORCA_WHIRLPOOL_PROGRAM_ID
from orca_whirlpool.utils import PoolUtil
async def main():
connection = AsyncClient(RPC_ENDPOINT_URL)
whirlpool_pubkey = Pubkey.from_string("HJPjoWUrhoZzkNfRpHuieeFk9WcZWjwy6PBjZ81ngndJ")
# get liquidity distribution
fetcher = AccountFetcher(connection)
whirlpool = await fetcher.get_whirlpool(whirlpool_pubkey)
finder = AccountFinder(connection)
tick_arrays = await finder.find_tick_arrays_by_whirlpool(
ORCA_WHIRLPOOL_PROGRAM_ID,
whirlpool_pubkey,
)
liquidity_distribution = PoolUtil.get_liquidity_distribution(whirlpool, tick_arrays)
for ld in liquidity_distribution:
print(ld.tick_lower_index, ld.tick_upper_index, ld.liquidity)
asyncio.run(main())
Release files for whirlpool-essentials 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| whirlpool_essentials-0.1.0.tar.gz | 61.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| whirlpool_essentials-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 190.0 kB
Release files / whirlpool_essentials-0.1.0.tar.gz
| Download URL | whirlpool_essentials-0.1.0.tar.gz |
|---|---|
| Size | 61.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c197e195b4a32daa9c985ce08ac56a03c0215a8b8248975742b6d294a6a5533b
|
|
BLAKE2b-256 checksum How to use checksums |
fa98907d55f322017f79f0caf5b8bce3b9f34aa69e24496641f21336af61dfdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.6
|
Release files / whirlpool_essentials-0.1.0-py3-none-any.whl
| Download URL | whirlpool_essentials-0.1.0-py3-none-any.whl |
|---|---|
| Size | 128.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c62962098dc3424f27a9fbccf69b63b3e0dd04d17931e1141a434149f5eae12
|
|
BLAKE2b-256 checksum How to use checksums |
9c6de2fe476523ae6226055d072871b72ca90007fb649f65a6562b51149dfa48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.6
|