Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/deep-hornets-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@orca-so/whirlpools-example-ts-next": minor
"@orca-so/tx-sender": minor
"@orca-so/whirlpools": minor
"@orca-so/whirlpools-client": minor
---

Update solana ts dependencies, migrate from tests from bankrun to litesvm
4 changes: 2 additions & 2 deletions examples/ts-sdk/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"dependencies": {
"@orca-so/tx-sender": "*",
"@orca-so/whirlpools": "*",
"@solana/kit": "^3.0.3",
"@solana/react": "^3.0.3",
"@solana/kit": "^5.0.0",
"@solana/react": "^5.0.0",
"@wallet-standard/react": "^1.0.1",
"next": "^15.5.6",
"react": "^19.2.0",
Expand Down
4 changes: 2 additions & 2 deletions ts-sdk/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"clean": "rimraf dist src/generated"
},
"peerDependencies": {
"@solana/kit": "^2.1.0"
"@solana/kit": "^5.0.0"
},
"devDependencies": {
"@codama/nodes-from-anchor": "^1.2.9",
"@codama/renderers-js": "^1.4.2",
"@orca-so/whirlpools-program": "*",
"@solana/kit": "^2.3.0",
"@solana/kit": "^5.0.0",
"codama": "^1.3.7",
"tsup": "^8.4.0",
"typescript": "^5.9.3",
Expand Down
10 changes: 5 additions & 5 deletions ts-sdk/tx-sender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
"clean": "rimraf dist"
},
"dependencies": {
"@solana-program/address-lookup-table": "^0.8.0",
"@solana-program/compute-budget": "^0.9.0",
"@solana-program/system": "^0.8.0"
"@solana-program/address-lookup-table": "^0.10.0",
"@solana-program/compute-budget": "^0.11.0",
"@solana-program/system": "^0.10.0"
},
"peerDependencies": {
"@solana/kit": "^3.0.3"
"@solana/kit": "^5.0.0"
},
"devDependencies": {
"@solana/kit": "^3.0.3",
"@solana/kit": "^5.0.0",
"tsup": "^8.4.0",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
Expand Down
14 changes: 7 additions & 7 deletions ts-sdk/whirlpool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
"@orca-so/tx-sender": "*",
"@orca-so/whirlpools-client": "*",
"@orca-so/whirlpools-core": "*",
"@solana-program/memo": "^0.8.0",
"@solana-program/system": "^0.8.0",
"@solana-program/token": "^0.6.0",
"@solana-program/memo": "^0.10.0",
"@solana-program/system": "^0.10.0",
"@solana-program/token": "^0.8.0",
"@solana-program/token-2022": "^0.5.0",
"@solana/sysvars": "^3.0.3"
"@solana/sysvars": "^5.0.0"
},
"peerDependencies": {
"@solana/kit": "^3.0.3"
"@solana/kit": "^5.0.0"
},
"devDependencies": {
"@solana/kit": "^3.0.3",
"solana-bankrun": "^0.4.0",
"@solana/kit": "^5.0.0",
"litesvm": "^0.3.3",
"tsup": "^8.4.0",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
Expand Down
6 changes: 3 additions & 3 deletions ts-sdk/whirlpool/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ export const SPLASH_POOL_TICK_SPACING = 32896;
/**
* The default funder for transactions. No explicit funder specified.
*/
export const DEFAULT_FUNDER: TransactionSigner =
export const DEFAULT_FUNDER: TransactionSigner<string> =
createNoopSigner(DEFAULT_ADDRESS);

/**
* The currently selected funder for transactions.
*/
export let FUNDER: TransactionSigner = DEFAULT_FUNDER;
export let FUNDER: TransactionSigner<string> = DEFAULT_FUNDER;

/**
* Sets the default funder for transactions.
*
* @param {TransactionSigner | Address | null} funder - The funder to be set as default, either as an address or a transaction signer.
*/
export function setDefaultFunder(
funder: TransactionSigner | Address | null,
funder: TransactionSigner<string> | Address | null,
): void {
if (typeof funder === "string") {
FUNDER = createNoopSigner(funder);
Expand Down
5 changes: 3 additions & 2 deletions ts-sdk/whirlpool/src/createPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function createSplashPoolInstructions(
tokenMintA: Address,
tokenMintB: Address,
initialPrice: number = 1,
funder: TransactionSigner = FUNDER,
funder: TransactionSigner<string> = FUNDER,
): Promise<CreatePoolInstructions> {
return createConcentratedLiquidityPoolInstructions(
rpc,
Expand Down Expand Up @@ -145,7 +145,7 @@ export async function createConcentratedLiquidityPoolInstructions(
tokenMintB: Address,
tickSpacing: number,
initialPrice: number = 1,
funder: TransactionSigner = FUNDER,
funder: TransactionSigner<string> = FUNDER,
): Promise<CreatePoolInstructions> {
assert(
funder.address !== DEFAULT_ADDRESS,
Expand All @@ -157,6 +157,7 @@ export async function createConcentratedLiquidityPoolInstructions(
);
const instructions: Instruction[] = [];

// as Parameters<typeof fetchSysvarRent>[0],
const rent = await fetchSysvarRent(rpc);
let nonRefundableRent: bigint = 0n;

Expand Down
4 changes: 2 additions & 2 deletions ts-sdk/whirlpool/src/decreaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export async function decreaseLiquidityInstructions(
positionMintAddress: Address,
param: DecreaseLiquidityQuoteParam,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
authority: TransactionSigner = FUNDER,
authority: TransactionSigner<string> = FUNDER,
): Promise<DecreaseLiquidityInstructions> {
assert(
authority.address !== DEFAULT_ADDRESS,
Expand Down Expand Up @@ -316,7 +316,7 @@ export async function closePositionInstructions(
>,
positionMintAddress: Address,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
authority: TransactionSigner = FUNDER,
authority: TransactionSigner<string> = FUNDER,
): Promise<ClosePositionInstructions> {
assert(
authority.address !== DEFAULT_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion ts-sdk/whirlpool/src/harvest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function harvestPositionInstructions(
GetEpochInfoApi
>,
positionMintAddress: Address,
authority: TransactionSigner = FUNDER,
authority: TransactionSigner<string> = FUNDER,
): Promise<HarvestPositionInstructions> {
assert(
authority.address !== DEFAULT_ADDRESS,
Expand Down
9 changes: 5 additions & 4 deletions ts-sdk/whirlpool/src/increaseLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function increaseLiquidityInstructions(
positionMintAddress: Address,
param: IncreaseLiquidityQuoteParam,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
authority: TransactionSigner = FUNDER,
authority: TransactionSigner<string> = FUNDER,
): Promise<IncreaseLiquidityInstructions> {
assert(
authority.address !== DEFAULT_ADDRESS,
Expand Down Expand Up @@ -302,14 +302,15 @@ async function internalOpenPositionInstructions(
mintA: Account<Mint>,
mintB: Account<Mint>,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
funder: TransactionSigner = FUNDER,
funder: TransactionSigner<string> = FUNDER,
): Promise<OpenPositionInstructions> {
assert(
funder.address !== DEFAULT_ADDRESS,
"Either supply a funder or set the default funder",
);
const instructions: Instruction[] = [];

// rpc as Parameters<typeof fetchSysvarRent>[0],
const rent = await fetchSysvarRent(rpc);
let nonRefundableRent: bigint = 0n;

Expand Down Expand Up @@ -509,7 +510,7 @@ export async function openFullRangePositionInstructions(
poolAddress: Address,
param: IncreaseLiquidityQuoteParam,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
funder: TransactionSigner = FUNDER,
funder: TransactionSigner<string> = FUNDER,
): Promise<OpenPositionInstructions> {
const whirlpool = await fetchWhirlpool(rpc, poolAddress);
const tickRange = getFullRangeTickIndexes(whirlpool.data.tickSpacing);
Expand Down Expand Up @@ -582,7 +583,7 @@ export async function openPositionInstructions(
lowerPrice: number,
upperPrice: number,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
funder: TransactionSigner = FUNDER,
funder: TransactionSigner<string> = FUNDER,
): Promise<OpenPositionInstructions> {
const whirlpool = await fetchWhirlpool(rpc, poolAddress);
assert(
Expand Down
2 changes: 1 addition & 1 deletion ts-sdk/whirlpool/src/resetPositionRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function resetPositionRangeInstructions(
positionMintAddress: Address,
newLowerPrice: number,
newUpperPrice: number,
authority: TransactionSigner = FUNDER,
authority: TransactionSigner<string> = FUNDER,
): Promise<ResetPositionRageInstructions> {
assert(
authority.address !== DEFAULT_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion ts-sdk/whirlpool/src/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export async function swapInstructions<T extends SwapParams>(
params: T,
poolAddress: Address,
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPS,
signer: TransactionSigner = FUNDER,
signer: TransactionSigner<string> = FUNDER,
): Promise<SwapInstructions<T>> {
const whirlpool = await fetchWhirlpool(rpc, poolAddress);
const [tokenA, tokenB] = await fetchAllMint(rpc, [
Expand Down
2 changes: 1 addition & 1 deletion ts-sdk/whirlpool/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export async function prepareTokenAccountsInstructions(
: 0n;
if (ENFORCE_TOKEN_BALANCE_CHECK) {
assert(
BigInt(spec[mint.address]) <= existingBalance,
BigInt(spec[mint.address]) < existingBalance,
`Token account for ${mint.address} does not have the required balance`,
);
}
Expand Down
20 changes: 13 additions & 7 deletions ts-sdk/whirlpool/tests/increaseLiquidity.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { describe, it, beforeAll } from "vitest";
import { increaseLiquidityInstructions } from "../src/increaseLiquidity";
import { rpc, signer, sendTransaction } from "./utils/mockRpc";
import { setupMint, setupAta } from "./utils/token";
import { fetchPosition, getPositionAddress } from "@orca-so/whirlpools-client";
import { fetchToken } from "@solana-program/token-2022";
import type { Address } from "@solana/kit";
import assert from "assert";
import { beforeAll, describe, it } from "vitest";
import {
DEFAULT_FUNDER,
setDefaultFunder,
setEnforceTokenBalanceCheck,
} from "../src/config";
import { increaseLiquidityInstructions } from "../src/increaseLiquidity";
import { rpc, sendTransaction, signer } from "./utils/mockRpc";
import {
setupPosition,
setupTEPosition,
setupWhirlpool,
} from "./utils/program";
import { DEFAULT_FUNDER, setDefaultFunder } from "../src/config";
import { setupAta, setupMint } from "./utils/token";
import {
setupAtaTE,
setupMintTE,
Expand Down Expand Up @@ -132,7 +136,7 @@ describe("Increase Liquidity Instructions", () => {
const liquidity = 100_000n;
setDefaultFunder(DEFAULT_FUNDER);
await assert.rejects(
increaseLiquidityInstructions(rpc, positions.entries().next().value, {
increaseLiquidityInstructions(rpc, positions.entries().next().value![1], {
liquidity,
}),
);
Expand All @@ -141,10 +145,12 @@ describe("Increase Liquidity Instructions", () => {

it("Should throw error increase liquidity amount by token is equal or greater than the token balance", async () => {
const tokenAAmount = 1_000_000n;
setEnforceTokenBalanceCheck(true);
await assert.rejects(
increaseLiquidityInstructions(rpc, positions.entries().next().value, {
increaseLiquidityInstructions(rpc, positions.entries().next().value![1], {
tokenA: tokenAAmount,
}),
);
setEnforceTokenBalanceCheck(false);
});
});
22 changes: 14 additions & 8 deletions ts-sdk/whirlpool/tests/pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,21 @@ describe("Fetch Pool", () => {
assert.strictEqual(pool.whirlpoolsConfig, WHIRLPOOLS_CONFIG_ADDRESS);
});

// TODO: Enable this test once solana-bankrun exposes getProgramAccounts
it.skip("Should be able to fetch all pools for a pair", async () => {
it("Should be able to fetch all pools for a pair", async () => {
const pools = await fetchWhirlpoolsByTokenPair(rpc, mintA, mintB);
assert.strictEqual(pools.length, 3);
assert.strictEqual(pools[0].initialized, true);
assert.strictEqual(pools[0].tickSpacing, 64);
assert.strictEqual(pools[1].initialized, true);
assert.strictEqual(pools[1].tickSpacing, SPLASH_POOL_TICK_SPACING);
assert.strictEqual(pools[2].initialized, false);
assert.strictEqual(pools[2].tickSpacing, 128);

// Check that we have all expected tick spacings
const tickSpacings = pools.map((p) => p.tickSpacing);
assert.ok(tickSpacings.includes(64));
assert.ok(tickSpacings.includes(SPLASH_POOL_TICK_SPACING));
assert.ok(tickSpacings.includes(128));

// Check initialized states
const initializedPools = pools.filter((p) => p.initialized);
const uninitializedPools = pools.filter((p) => !p.initialized);
assert.strictEqual(initializedPools.length, 2);
assert.strictEqual(uninitializedPools.length, 1);
assert.strictEqual(uninitializedPools[0].tickSpacing, 128);
});
});
41 changes: 31 additions & 10 deletions ts-sdk/whirlpool/tests/position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
fetchPositionsInWhirlpool,
} from "../src/position";
import { rpc, signer } from "./utils/mockRpc";
import { getFullRangeTickIndexes } from "@orca-so/whirlpools-core";

describe("Fetch Position", () => {
let mintA: Address;
Expand All @@ -29,28 +30,48 @@ describe("Fetch Position", () => {
pool = await setupWhirlpool(mintA, mintB, 128);
splashPool = await setupWhirlpool(mintA, mintB, SPLASH_POOL_TICK_SPACING);
await setupPosition(pool);
await setupPosition(splashPool);
const splashFullRange = getFullRangeTickIndexes(SPLASH_POOL_TICK_SPACING);
await setupPosition(splashPool, {
tickLower: splashFullRange.tickLowerIndex,
tickUpper: splashFullRange.tickUpperIndex,
});
await setupTEPosition(pool);
await setupPositionBundle(pool);
await setupPositionBundle(splashPool, [{}, {}]);

// bundle with 1 position, 2 positions
await setupPositionBundle(pool, [{ tickLower: -100, tickUpper: 100 }]);
await setupPositionBundle(splashPool, [
{
tickLower: splashFullRange.tickLowerIndex,
tickUpper: splashFullRange.tickUpperIndex,
},
{
tickLower: splashFullRange.tickLowerIndex,
tickUpper: splashFullRange.tickUpperIndex,
},
]);
});

// TODO: enable this when solana-bankrun supports gpa
it.skip("Should fetch all positions for an address", async () => {
it("Should fetch all positions for an address", async () => {
const positions = await fetchPositionsForOwner(rpc, signer.address);
assert.strictEqual(positions.length, 5);

// 3 positions: 1 regular on pool, 1 full-range on splashPool, 1 TE on pool
const standalone = positions.filter((p) => !p.isPositionBundle);
assert.strictEqual(standalone.length, 3);

const bundles = positions.filter((p) => p.isPositionBundle);
assert.strictEqual(bundles.length, 2);
assert.deepEqual(bundles.map((b) => b.positions.length).sort(), [1, 2]);
});

// TODO: enable this when solana-bankrun supports gpa
it.skip("Should fetch no positions for a different address", async () => {
it("Should fetch no positions for a different address", async () => {
const other = await generateKeyPairSigner();
const positions = await fetchPositionsForOwner(rpc, other.address);
assert.strictEqual(positions.length, 0);
});

// TODO: enable this when solana-bankrun supports gpa
it.skip("Should fetch positions for a whirlpool", async () => {
it("Should fetch positions for a whirlpool", async () => {
const positions = await fetchPositionsInWhirlpool(rpc, pool);
// 3 positions in pool: 1 regular + 1 TE + 1 bundled
assert.strictEqual(positions.length, 3);
});
});
Loading