npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@orca-so/whirlpools

v1.0.1

Published

Orca's high-level typescript sdk to interact with Orca's on-chain Whirlpool program.

Downloads

840

Readme

Orca Whirlpools SDK

Orca Whirlpools is an open-source concentrated liquidity AMM contract on the Solana and Eclipse blockchain. This SDK allows developers to interact with the Whirlpools program on both chains, enabling the creation and management of liquidity pools and positions, as well as performing swaps.

Overview

The Orca Whirlpools SDK provides a comprehensive set of tools to interact with the Whirlpools program on Solana and Eclipse.

Note: This SDK uses Solana Web3.js SDK v2. It is not compatible with the widely used v1.x.x version.

Installation

To install the SDK, use the following command:

npm install @orca-so/whirlpools

Basic Usage

1. Wallet Creation

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

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

const wallet = await generateKeyPairSigner();

2. Configure the Whirlpools SDK for Your Network

Orca's Whirlpools SDK supports several networks: Solana Mainnet, Solana Devnet, Eclipse Mainnet, and Eclipse Testnet. To select a network, use the setWhirlpoolsConfig function. This ensures compatibility with the network you’re deploying on.

Example: Setting the SDK Configuration to Solana Devnet.

import { setWhirlpoolsConfig } from '@orca-so/whirlpools';

await setWhirlpoolsConfig('solanaDevnet');

Available networks are:

  • solanaMainnet
  • solanaDevnet
  • eclipseMainnet
  • eclipseTestnet

ℹ️ The setWhirlpoolsConfig function accepts either one of Orca's default network keys or a custom Address. This allows you to specify a custom configuration if needed.

3. Create the Swap Instructions

After configuring the SDK, you can perform a swap. Here is an example of how to perform a token swap using the Whirlpools SDK:

import { swapInstructions } from '@orca-so/whirlpools';
const poolAddress = "POOL_ADDRESS";
const mintAddress = "TOKEN_MINT";
const amount = 1_000_000n;
const slippageTolerance = 100; // 1bps

const { instructions, quote } = await swapInstructions(
    devnetRpc,
    {
        inputAmount: amount,
        mint: mintAddress
    },
    poolAddress,
    slippageTolerance,
    wallet
);

4. Putting it all together

import { swapInstructions, setWhirlpoolsConfig } from '@orca-so/whirlpools';
import { generateKeyPairSigner, createSolanaRpc, devnet } from '@solana/web3.js';

const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
await setWhirlpoolsConfig('solanaDevnet');
const wallet = await generateKeyPairSigner();
await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();

/* Example Devnet Addresses:
 * -------------------------
 * SOL/devUSDC Whirlpool: 3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt
 * SOL Token Address: So11111111111111111111111111111111111111112
 * devUSDC Token Address: 3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt
 */

const poolAddress = "3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt";
const mintAddress = "So11111111111111111111111111111111111111112";
const amount = 1_000_000n;
const slippageTolerance = 100; // 1bps

const { instructions, quote } = await swapInstructions(
    devnetRpc,
    {
        inputAmount: amount,
        mint: mintAddress
    },
    poolAddress,
    slippageTolerance,
    wallet
);