How to Automagically Drain Your Whirlpool Positions

Jarett Dunn
2 min readJan 31, 2023

I’ve been playing an awful lot with Orca Whirlpools of late, trying to perfect a non-custodial system wherein people can ‘set and forget’ their preferences and have my Whirlie Wonka program close unprofitable positions and open new ones that are within the range of profitability.

They are not just ‘in range,’ but also so incredibly well-monitoried by the smart contract that they can be just to the left and right of the current price — maximizing returns.

Anywho, last night I was left with hundreds of open positions and the thing isn’t quite working ideally yet (and I wanted some rare and lovely sleep) so I set up a little script to close all of my whirlpool positions.

  1. install nodejs (google it)
  2. npm i -g ts-node

Now, there are a few requirements here to get started. We need the whirlpool and solana dependencies, for one.

I forgot bs58 :) so

npm i bs58

First, we need a connection and a wallet/keypair to use. We’re going to use a private key that you have in your environment, well call it SOLANA_KEY. You can set this in linux/mac by going

or windows

now:

Now, we need to loop through all of our tokens in our wallet — this used to be quite an endeavour, until the bigwigs at Solana Labs included getParsedTokenAccounts in the JSON RPC schema :) afterwards, we attempt loading them as Positions and see if it succeeds or fails. If it succeeds, we can move forward with decreasing liquidity.

also, unrelated: prettier be damned :)

This guide is designed for the average degen who doesn’t care if they hold all the leftover nfts, and unfortunately we cannot close a whirlpool position until also draining the rewards and fees — so I leave it to your eager imagination and Googling skills, hopefully having whetted your interest enough to figure out how to do the rest ;) For the degens: Make sure to hit the button to claim all your rewards and fees on the whirlpool interface!

--

--