@@ -3,9 +3,11 @@ import {
33 fetchAllMaybePosition ,
44 fetchAllMaybePositionBundle ,
55 fetchAllPosition ,
6+ fetchAllPositionWithFilter ,
67 getBundledPositionAddress ,
78 getPositionAddress ,
89 getPositionBundleAddress ,
10+ positionWhirlpoolFilter ,
911} from "@orca-so/whirlpools-client" ;
1012import { _POSITION_BUNDLE_SIZE } from "@orca-so/whirlpools-core" ;
1113import { getTokenDecoder , TOKEN_PROGRAM_ADDRESS } from "@solana-program/token" ;
@@ -14,6 +16,7 @@ import type {
1416 Account ,
1517 Address ,
1618 GetMultipleAccountsApi ,
19+ GetProgramAccountsApi ,
1720 GetTokenAccountsByOwnerApi ,
1821 Rpc ,
1922} from "@solana/web3.js" ;
@@ -178,3 +181,34 @@ export async function fetchPositionsForOwner(
178181
179182 return positionsOrBundles ;
180183}
184+
185+ /**
186+ * Fetches all positions for a given Whirlpool.
187+ *
188+ * @param {SolanaRpc } rpc - The Solana RPC client used to fetch positions.
189+ * @param {Address } whirlpool - The address of the Whirlpool.
190+ * @returns {Promise<HydratedPosition[]> } - A promise that resolves to an array of hydrated positions.
191+ *
192+ * @example
193+ * import { fetchPositionsInWhirlpool } from '@orca-so/whirlpools';
194+ * import { createSolanaRpc, devnet, address } from '@solana/web3.js';
195+ *
196+ * const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
197+ * await devnetRpc.requestAirdrop(wallet.address, lamports(1000000000n)).send();
198+ *
199+ * const whirlpool = address("Czfq3xZZDmsdGdUyrNLtRhGc47cXcZtLG4crryfu44zE");
200+ * const positions = await fetchPositionsInWhirlpool(devnetRpc, whirlpool);
201+ */
202+ export async function fetchPositionsInWhirlpool (
203+ rpc : Rpc < GetProgramAccountsApi > ,
204+ whirlpool : Address ,
205+ ) : Promise < HydratedPosition [ ] > {
206+ const positions = await fetchAllPositionWithFilter (
207+ rpc ,
208+ positionWhirlpoolFilter ( whirlpool ) ,
209+ ) ;
210+ return positions . map ( ( x ) => ( {
211+ ...x ,
212+ isPositionBundle : false ,
213+ } ) ) ;
214+ }
0 commit comments