Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@orca-so/whirlpools-sdk

Package Overview
Dependencies
Maintainers
4
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orca-so/whirlpools-sdk - npm Package Compare versions

Comparing version 0.5.3 to 0.6.0

dist/instructions/composites/collect-all-txn.d.ts

2

dist/artifacts/whirlpool.d.ts

@@ -1,2 +0,2 @@

export declare type Whirlpool = {
export type Whirlpool = {
"version": "0.1.0";

@@ -3,0 +3,0 @@ "name": "whirlpool";

@@ -14,11 +14,2 @@ "use strict";

class WhirlpoolContext {
constructor(provider, wallet, program, fetcher, opts) {
this.connection = provider.connection;
this.wallet = wallet;
this.opts = opts;
// It's a hack but it works on Anchor workspace *shrug*
this.program = program;
this.provider = provider;
this.fetcher = fetcher;
}
static from(connection, wallet, programId, fetcher = new public_1.AccountFetcher(connection), opts = anchor_1.AnchorProvider.defaultOptions()) {

@@ -36,3 +27,12 @@ const anchorProvider = new anchor_1.AnchorProvider(connection, wallet, opts);

}
constructor(provider, wallet, program, fetcher, opts) {
this.connection = provider.connection;
this.wallet = wallet;
this.opts = opts;
// It's a hack but it works on Anchor workspace *shrug*
this.program = program;
this.provider = provider;
this.fetcher = fetcher;
}
}
exports.WhirlpoolContext = WhirlpoolContext;

@@ -22,3 +22,3 @@ export declare enum MathErrorCode {

}
export declare type WhirlpoolsErrorCode = TokenErrorCode | SwapErrorCode | MathErrorCode;
export type WhirlpoolsErrorCode = TokenErrorCode | SwapErrorCode | MathErrorCode;
export declare class WhirlpoolsError extends Error {

@@ -25,0 +25,0 @@ message: string;

import { TransactionBuilder } from "@orca-so/common-sdk";
import { Address } from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import { WhirlpoolContext } from "../context";
import { IncreaseLiquidityInput, DecreaseLiquidityInput } from "../instructions";
import { DecreaseLiquidityInput, IncreaseLiquidityInput } from "../instructions";
import { PositionData } from "../types/public";
import { Position } from "../whirlpool-client";
import { PublicKey } from "@solana/web3.js";
import { AccountFetcher } from "../network/public";
export declare class PositionImpl implements Position {
readonly ctx: WhirlpoolContext;
readonly fetcher: AccountFetcher;
readonly address: PublicKey;
private data;
constructor(ctx: WhirlpoolContext, fetcher: AccountFetcher, address: PublicKey, data: PositionData);
constructor(ctx: WhirlpoolContext, address: PublicKey, data: PositionData);
getAddress(): PublicKey;

@@ -16,0 +14,0 @@ getData(): PositionData;

@@ -28,5 +28,4 @@ "use strict";

class PositionImpl {
constructor(ctx, fetcher, address, data) {
constructor(ctx, address, data) {
this.ctx = ctx;
this.fetcher = fetcher;
this.address = address;

@@ -56,3 +55,3 @@ this.data = data;

const ataPayerKey = ataPayer ? common_sdk_1.AddressUtil.toPubKey(ataPayer) : this.ctx.wallet.publicKey;
const whirlpool = yield this.fetcher.getPool(this.data.whirlpool, true);
const whirlpool = yield this.ctx.fetcher.getPool(this.data.whirlpool, true);
if (!whirlpool) {

@@ -68,3 +67,3 @@ throw new Error("Unable to fetch whirlpool for this position.");

{ tokenMint: whirlpool.tokenMintB, wrappedSolAmountIn: liquidityInput.tokenMaxB },
], () => this.fetcher.getAccountRentExempt(), ataPayerKey);
], () => this.ctx.fetcher.getAccountRentExempt(), ataPayerKey);
const _a = ataA, { address: ataAddrA } = _a, tokenOwnerAccountAIx = __rest(_a, ["address"]);

@@ -98,3 +97,3 @@ const _b = ataB, { address: ataAddrB } = _b, tokenOwnerAccountBIx = __rest(_b, ["address"]);

const ataPayerKey = ataPayer ? common_sdk_1.AddressUtil.toPubKey(ataPayer) : this.ctx.wallet.publicKey;
const whirlpool = yield this.fetcher.getPool(this.data.whirlpool, true);
const whirlpool = yield this.ctx.fetcher.getPool(this.data.whirlpool, true);
if (!whirlpool) {

@@ -107,3 +106,3 @@ throw new Error("Unable to fetch whirlpool for this position.");

if (resolveATA) {
const [ataA, ataB] = yield (0, common_sdk_1.resolveOrCreateATAs)(this.ctx.connection, sourceWalletKey, [{ tokenMint: whirlpool.tokenMintA }, { tokenMint: whirlpool.tokenMintB }], () => this.fetcher.getAccountRentExempt(), ataPayerKey);
const [ataA, ataB] = yield (0, common_sdk_1.resolveOrCreateATAs)(this.ctx.connection, sourceWalletKey, [{ tokenMint: whirlpool.tokenMintA }, { tokenMint: whirlpool.tokenMintB }], () => this.ctx.fetcher.getAccountRentExempt(), ataPayerKey);
const _a = ataA, { address: ataAddrA } = _a, tokenOwnerAccountAIx = __rest(_a, ["address"]);

@@ -128,3 +127,3 @@ const _b = ataB, { address: ataAddrB } = _b, tokenOwnerAccountBIx = __rest(_b, ["address"]);

return __awaiter(this, void 0, void 0, function* () {
const account = yield this.fetcher.getPosition(this.address, true);
const account = yield this.ctx.fetcher.getPosition(this.address, true);
if (!!account) {

@@ -131,0 +130,0 @@ this.data = account;

@@ -0,5 +1,7 @@

import { TransactionBuilder } from "@orca-so/common-sdk";
import { Address } from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import { WhirlpoolContext } from "../context";
import { AccountFetcher } from "../network/public";
import { WhirlpoolClient, Whirlpool, Position } from "../whirlpool-client";
import { Position, Whirlpool, WhirlpoolClient } from "../whirlpool-client";
export declare class WhirlpoolClientImpl implements WhirlpoolClient {

@@ -13,2 +15,8 @@ readonly ctx: WhirlpoolContext;

getPosition(positionAddress: Address, refresh?: boolean): Promise<Position>;
getPositions(positionAddresses: Address[], refresh?: boolean): Promise<Record<string, Position | null>>;
createPool(whirlpoolsConfig: Address, tokenMintA: Address, tokenMintB: Address, tickSpacing: number, initialTick: number, funder: Address, refresh?: boolean): Promise<{
poolKey: PublicKey;
tx: TransactionBuilder;
}>;
collectFeesAndRewardsForPositions(positionAddresses: Address[], refresh?: boolean | undefined): Promise<TransactionBuilder[]>;
}

@@ -11,5 +11,13 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WhirlpoolClientImpl = void 0;
const common_sdk_1 = require("@orca-so/common-sdk");
const web3_js_1 = require("@solana/web3.js");
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
const instructions_1 = require("../instructions");
const composites_1 = require("../instructions/composites");
const ix_1 = require("../ix");
const public_1 = require("../utils/public");

@@ -38,3 +46,3 @@ const position_impl_1 = require("./position-impl");

const rewardInfos = yield (0, util_1.getRewardInfos)(this.ctx.fetcher, account, refresh);
return new whirlpool_impl_1.WhirlpoolImpl(this.ctx, this.ctx.fetcher, common_sdk_1.AddressUtil.toPubKey(poolAddress), tokenInfos[0], tokenInfos[1], vaultInfos[0], vaultInfos[1], rewardInfos, account);
return new whirlpool_impl_1.WhirlpoolImpl(this.ctx, common_sdk_1.AddressUtil.toPubKey(poolAddress), tokenInfos[0], tokenInfos[1], vaultInfos[0], vaultInfos[1], rewardInfos, account);
});

@@ -70,3 +78,3 @@ }

const rewardInfos = yield (0, util_1.getRewardInfos)(this.ctx.fetcher, account, false);
whirlpools.push(new whirlpool_impl_1.WhirlpoolImpl(this.ctx, this.ctx.fetcher, common_sdk_1.AddressUtil.toPubKey(poolAddress), tokenInfos[0], tokenInfos[1], vaultInfos[0], vaultInfos[1], rewardInfos, account));
whirlpools.push(new whirlpool_impl_1.WhirlpoolImpl(this.ctx, common_sdk_1.AddressUtil.toPubKey(poolAddress), tokenInfos[0], tokenInfos[1], vaultInfos[0], vaultInfos[1], rewardInfos, account));
}

@@ -82,6 +90,73 @@ return whirlpools;

}
return new position_impl_1.PositionImpl(this.ctx, this.ctx.fetcher, common_sdk_1.AddressUtil.toPubKey(positionAddress), account);
return new position_impl_1.PositionImpl(this.ctx, common_sdk_1.AddressUtil.toPubKey(positionAddress), account);
});
}
getPositions(positionAddresses, refresh = false) {
return __awaiter(this, void 0, void 0, function* () {
const accounts = yield this.ctx.fetcher.listPositions(positionAddresses, refresh);
const results = accounts.map((positionAccount, index) => {
const address = positionAddresses[index];
if (!positionAccount) {
return [address, null];
}
return [address, new position_impl_1.PositionImpl(this.ctx, common_sdk_1.AddressUtil.toPubKey(address), positionAccount)];
});
return Object.fromEntries(results);
});
}
createPool(whirlpoolsConfig, tokenMintA, tokenMintB, tickSpacing, initialTick, funder, refresh = false) {
return __awaiter(this, void 0, void 0, function* () {
(0, tiny_invariant_1.default)(public_1.TickUtil.checkTickInBounds(initialTick), "initialTick is out of bounds.");
(0, tiny_invariant_1.default)(public_1.TickUtil.isTickInitializable(initialTick, tickSpacing), `initial tick ${initialTick} is not an initializable tick for tick-spacing ${tickSpacing}`);
const correctTokenOrder = public_1.PoolUtil.orderMints(tokenMintA, tokenMintB).map((addr) => addr.toString());
(0, tiny_invariant_1.default)(correctTokenOrder[0] === tokenMintA.toString(), "Token order needs to be flipped to match the canonical ordering (i.e. sorted on the byte repr. of the mint pubkeys)");
whirlpoolsConfig = common_sdk_1.AddressUtil.toPubKey(whirlpoolsConfig);
const feeTierKey = public_1.PDAUtil.getFeeTier(this.ctx.program.programId, whirlpoolsConfig, tickSpacing).publicKey;
const initSqrtPrice = public_1.PriceMath.tickIndexToSqrtPriceX64(initialTick);
const tokenVaultAKeypair = web3_js_1.Keypair.generate();
const tokenVaultBKeypair = web3_js_1.Keypair.generate();
const whirlpoolPda = public_1.PDAUtil.getWhirlpool(this.ctx.program.programId, whirlpoolsConfig, new web3_js_1.PublicKey(tokenMintA), new web3_js_1.PublicKey(tokenMintB), tickSpacing);
const feeTier = yield this.ctx.fetcher.getFeeTier(feeTierKey, refresh);
(0, tiny_invariant_1.default)(!!feeTier, `Fee tier for ${tickSpacing} doesn't exist`);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
const initPoolIx = ix_1.WhirlpoolIx.initializePoolIx(this.ctx.program, {
initSqrtPrice,
whirlpoolsConfig,
whirlpoolPda,
tokenMintA: new web3_js_1.PublicKey(tokenMintA),
tokenMintB: new web3_js_1.PublicKey(tokenMintB),
tokenVaultAKeypair,
tokenVaultBKeypair,
feeTierKey,
tickSpacing,
funder: new web3_js_1.PublicKey(funder),
});
const initialTickArrayStartTick = public_1.TickUtil.getStartTickIndex(initialTick, tickSpacing);
const initialTickArrayPda = public_1.PDAUtil.getTickArray(this.ctx.program.programId, whirlpoolPda.publicKey, initialTickArrayStartTick);
txBuilder.addInstruction(initPoolIx);
txBuilder.addInstruction((0, instructions_1.initTickArrayIx)(this.ctx.program, {
startTick: initialTickArrayStartTick,
tickArrayPda: initialTickArrayPda,
whirlpool: whirlpoolPda.publicKey,
funder: common_sdk_1.AddressUtil.toPubKey(funder),
}));
return {
poolKey: whirlpoolPda.publicKey,
tx: txBuilder,
};
});
}
collectFeesAndRewardsForPositions(positionAddresses, refresh) {
return __awaiter(this, void 0, void 0, function* () {
const walletKey = this.ctx.wallet.publicKey;
return (0, composites_1.collectAllForPositionAddressesTxns)(this.ctx, {
positions: positionAddresses,
receiver: walletKey,
positionAuthority: walletKey,
positionOwner: walletKey,
payer: walletKey,
}, refresh);
});
}
}
exports.WhirlpoolClientImpl = WhirlpoolClientImpl;

@@ -6,3 +6,2 @@ import { Percentage, TransactionBuilder } from "@orca-so/common-sdk";

import { DevFeeSwapInput, IncreaseLiquidityInput, SwapInput } from "../instructions";
import { AccountFetcher } from "../network/public";
import { TokenAccountInfo, TokenInfo, WhirlpoolData, WhirlpoolRewardInfo } from "../types/public";

@@ -12,3 +11,2 @@ import { Whirlpool } from "../whirlpool-client";

readonly ctx: WhirlpoolContext;
readonly fetcher: AccountFetcher;
readonly address: PublicKey;

@@ -21,3 +19,3 @@ readonly tokenAInfo: TokenInfo;

private data;
constructor(ctx: WhirlpoolContext, fetcher: AccountFetcher, address: PublicKey, tokenAInfo: TokenInfo, tokenBInfo: TokenInfo, tokenVaultAInfo: TokenAccountInfo, tokenVaultBInfo: TokenAccountInfo, rewardInfos: WhirlpoolRewardInfo[], data: WhirlpoolData);
constructor(ctx: WhirlpoolContext, address: PublicKey, tokenAInfo: TokenInfo, tokenBInfo: TokenInfo, tokenVaultAInfo: TokenAccountInfo, tokenVaultBInfo: TokenAccountInfo, rewardInfos: WhirlpoolRewardInfo[], data: WhirlpoolData);
getAddress(): PublicKey;

@@ -24,0 +22,0 @@ getData(): WhirlpoolData;

@@ -36,5 +36,4 @@ "use strict";

class WhirlpoolImpl {
constructor(ctx, fetcher, address, tokenAInfo, tokenBInfo, tokenVaultAInfo, tokenVaultBInfo, rewardInfos, data) {
constructor(ctx, address, tokenAInfo, tokenBInfo, tokenVaultAInfo, tokenVaultBInfo, rewardInfos, data) {
this.ctx = ctx;
this.fetcher = fetcher;
this.address = address;

@@ -89,3 +88,3 @@ this.tokenAInfo = tokenAInfo;

return __awaiter(this, void 0, void 0, function* () {
const initTickArrayStartPdas = yield public_2.TickArrayUtil.getUninitializedArraysPDAs(ticks, this.ctx.program.programId, this.address, this.data.tickSpacing, this.fetcher, refresh);
const initTickArrayStartPdas = yield public_2.TickArrayUtil.getUninitializedArraysPDAs(ticks, this.ctx.program.programId, this.address, this.data.tickSpacing, this.ctx.fetcher, refresh);
if (!initTickArrayStartPdas.length) {

@@ -148,3 +147,3 @@ return null;

(0, tiny_invariant_1.default)(liquidity.gt(new anchor_1.BN(0)), "liquidity must be greater than zero");
const whirlpool = yield this.fetcher.getPool(this.address, false);
const whirlpool = yield this.ctx.fetcher.getPool(this.address, false);
if (!whirlpool) {

@@ -175,3 +174,3 @@ throw new Error(`Whirlpool not found: ${(0, anchor_1.translateAddress)(this.address).toBase58()}`);

{ tokenMint: whirlpool.tokenMintB, wrappedSolAmountIn: tokenMaxB },
], () => this.fetcher.getAccountRentExempt(), funder);
], () => this.ctx.fetcher.getAccountRentExempt(), funder);
const { address: tokenOwnerAccountA } = ataA, tokenOwnerAccountAIx = __rest(ataA, ["address"]);

@@ -207,3 +206,3 @@ const { address: tokenOwnerAccountB } = ataB, tokenOwnerAccountBIx = __rest(ataB, ["address"]);

return __awaiter(this, void 0, void 0, function* () {
const position = yield this.fetcher.getPosition(positionAddress, true);
const position = yield this.ctx.fetcher.getPosition(positionAddress, true);
if (!position) {

@@ -219,3 +218,3 @@ throw new Error(`Position not found: ${positionAddress.toBase58()}`);

const resolvedAssociatedTokenAddresses = {};
const [ataA, ataB] = yield (0, common_sdk_1.resolveOrCreateATAs)(this.ctx.connection, destinationWallet, [{ tokenMint: whirlpool.tokenMintA }, { tokenMint: whirlpool.tokenMintB }], () => this.fetcher.getAccountRentExempt(), payerKey);
const [ataA, ataB] = yield (0, common_sdk_1.resolveOrCreateATAs)(this.ctx.connection, destinationWallet, [{ tokenMint: whirlpool.tokenMintA }, { tokenMint: whirlpool.tokenMintB }], () => this.ctx.fetcher.getAccountRentExempt(), payerKey);
const { address: tokenOwnerAccountA } = ataA, createTokenOwnerAccountAIx = __rest(ataA, ["address"]);

@@ -276,2 +275,12 @@ const { address: tokenOwnerAccountB } = ataB, createTokenOwnerAccountBIx = __rest(ataB, ["address"]);

(0, tiny_invariant_1.default)(input.amount.gt(common_sdk_1.ZERO), "swap amount must be more than zero.");
// Check if all the tick arrays have been initialized.
const tickArrayAddresses = [input.tickArray0, input.tickArray1, input.tickArray2];
const tickArrays = yield this.ctx.fetcher.listTickArrays(tickArrayAddresses, true);
const uninitializedIndices = public_2.TickArrayUtil.getUninitializedArrays(tickArrays);
if (uninitializedIndices.length > 0) {
const uninitializedArrays = uninitializedIndices
.map((index) => tickArrayAddresses[index].toBase58())
.join(", ");
throw new Error(`TickArray addresses - [${uninitializedArrays}] need to be initialized.`);
}
const { amount, aToB } = input;

@@ -283,3 +292,3 @@ const whirlpool = this.data;

{ tokenMint: whirlpool.tokenMintB, wrappedSolAmountIn: !aToB ? amount : common_sdk_1.ZERO },
], () => this.fetcher.getAccountRentExempt());
], () => this.ctx.fetcher.getAccountRentExempt());
const { address: tokenOwnerAccountA } = ataA, tokenOwnerAccountAIx = __rest(ataA, ["address"]);

@@ -296,6 +305,6 @@ const { address: tokenOwnerAccountB } = ataB, tokenOwnerAccountBIx = __rest(ataB, ["address"]);

return __awaiter(this, void 0, void 0, function* () {
const account = yield this.fetcher.getPool(this.address, true);
const account = yield this.ctx.fetcher.getPool(this.address, true);
if (!!account) {
const rewardInfos = yield (0, util_1.getRewardInfos)(this.fetcher, account, true);
const [tokenVaultAInfo, tokenVaultBInfo] = yield (0, util_1.getTokenVaultAccountInfos)(this.fetcher, account, true);
const rewardInfos = yield (0, util_1.getRewardInfos)(this.ctx.fetcher, account, true);
const [tokenVaultAInfo, tokenVaultBInfo] = yield (0, util_1.getTokenVaultAccountInfos)(this.ctx.fetcher, account, true);
this.data = account;

@@ -302,0 +311,0 @@ this.tokenVaultAInfo = tokenVaultAInfo;

export * from "./context";
export * from "./impl/position-impl";
export * from "./ix";
export * from "./network/public";
export * from "./quotes/public";
export * from "./types/public";
export * from "./types/public/anchor-types";
export * from "./utils/public";
export * from "./network/public";
export * from "./quotes/public";
export * from "./ix";
export * from "./whirlpool-client";
export * from "./types/public/anchor-types";

@@ -22,9 +22,10 @@ "use strict";

__exportStar(require("./context"), exports);
__exportStar(require("./impl/position-impl"), exports);
__exportStar(require("./ix"), exports);
__exportStar(require("./network/public"), exports);
__exportStar(require("./quotes/public"), exports);
__exportStar(require("./types/public"), exports);
__exportStar(require("./types/public/anchor-types"), exports);
__exportStar(require("./utils/public"), exports);
__exportStar(require("./network/public"), exports);
__exportStar(require("./quotes/public"), exports);
__exportStar(require("./ix"), exports);
__exportStar(require("./whirlpool-client"), exports);
__exportStar(require("./types/public/anchor-types"), exports);
// Global rules for Decimals

@@ -31,0 +32,0 @@ // - 40 digits of precision for the largest number

@@ -15,3 +15,3 @@ import { Instruction } from "@orca-so/common-sdk";

*/
export declare type ClosePositionParams = {
export type ClosePositionParams = {
receiver: PublicKey;

@@ -18,0 +18,0 @@ position: PublicKey;

@@ -18,3 +18,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type CollectFeesParams = {
export type CollectFeesParams = {
whirlpool: PublicKey;

@@ -21,0 +21,0 @@ position: PublicKey;

@@ -17,3 +17,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type CollectProtocolFeesParams = {
export type CollectProtocolFeesParams = {
whirlpoolsConfig: PublicKey;

@@ -20,0 +20,0 @@ whirlpool: PublicKey;

@@ -17,3 +17,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type CollectRewardParams = {
export type CollectRewardParams = {
whirlpool: PublicKey;

@@ -20,0 +20,0 @@ position: PublicKey;

@@ -25,3 +25,3 @@ /// <reference types="bn.js" />

*/
export declare type DecreaseLiquidityParams = {
export type DecreaseLiquidityParams = {
whirlpool: PublicKey;

@@ -41,3 +41,3 @@ position: PublicKey;

*/
export declare type DecreaseLiquidityInput = {
export type DecreaseLiquidityInput = {
tokenMinA: BN;

@@ -44,0 +44,0 @@ tokenMinB: BN;

@@ -25,3 +25,3 @@ /// <reference types="bn.js" />

*/
export declare type IncreaseLiquidityParams = {
export type IncreaseLiquidityParams = {
whirlpool: PublicKey;

@@ -49,3 +49,3 @@ position: PublicKey;

*/
export declare type IncreaseLiquidityInput = {
export type IncreaseLiquidityInput = {
tokenMaxA: u64;

@@ -52,0 +52,0 @@ tokenMaxB: u64;

@@ -5,2 +5,3 @@ export * from "./close-position-ix";

export * from "./collect-reward-ix";
export * from "./composites";
export * from "./decrease-liquidity-ix";

@@ -7,0 +8,0 @@ export * from "./increase-liquidity-ix";

@@ -21,2 +21,3 @@ "use strict";

__exportStar(require("./collect-reward-ix"), exports);
__exportStar(require("./composites"), exports);
__exportStar(require("./decrease-liquidity-ix"), exports);

@@ -23,0 +24,0 @@ __exportStar(require("./increase-liquidity-ix"), exports);

@@ -16,3 +16,3 @@ import { Keypair, PublicKey } from "@solana/web3.js";

*/
export declare type InitConfigParams = {
export type InitConfigParams = {
whirlpoolsConfigKeypair: Keypair;

@@ -19,0 +19,0 @@ feeAuthority: PublicKey;

@@ -17,3 +17,3 @@ import { PublicKey } from "@solana/web3.js";

*/
export declare type InitFeeTierParams = {
export type InitFeeTierParams = {
whirlpoolsConfig: PublicKey;

@@ -20,0 +20,0 @@ feeTierPda: PDA;

@@ -23,3 +23,3 @@ /// <reference types="bn.js" />

*/
export declare type InitPoolParams = {
export type InitPoolParams = {
initSqrtPrice: BN;

@@ -26,0 +26,0 @@ whirlpoolsConfig: PublicKey;

@@ -16,3 +16,3 @@ import { Keypair, PublicKey } from "@solana/web3.js";

*/
export declare type InitializeRewardParams = {
export type InitializeRewardParams = {
whirlpool: PublicKey;

@@ -19,0 +19,0 @@ rewardIndex: number;

@@ -15,3 +15,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type InitTickArrayParams = {
export type InitTickArrayParams = {
whirlpool: PublicKey;

@@ -18,0 +18,0 @@ tickArrayPda: PDA;

@@ -18,3 +18,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type OpenPositionParams = {
export type OpenPositionParams = {
whirlpool: PublicKey;

@@ -21,0 +21,0 @@ owner: PublicKey;

@@ -13,3 +13,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetCollectProtocolFeesAuthorityParams = {
export type SetCollectProtocolFeesAuthorityParams = {
whirlpoolsConfig: PublicKey;

@@ -16,0 +16,0 @@ collectProtocolFeesAuthority: PublicKey;

@@ -14,3 +14,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetDefaultFeeRateParams = {
export type SetDefaultFeeRateParams = {
whirlpoolsConfig: PublicKey;

@@ -17,0 +17,0 @@ feeAuthority: PublicKey;

@@ -13,3 +13,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetDefaultProtocolFeeRateParams = {
export type SetDefaultProtocolFeeRateParams = {
whirlpoolsConfig: PublicKey;

@@ -16,0 +16,0 @@ feeAuthority: PublicKey;

@@ -13,3 +13,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetFeeAuthorityParams = {
export type SetFeeAuthorityParams = {
whirlpoolsConfig: PublicKey;

@@ -16,0 +16,0 @@ feeAuthority: PublicKey;

@@ -14,3 +14,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetFeeRateParams = {
export type SetFeeRateParams = {
whirlpool: PublicKey;

@@ -17,0 +17,0 @@ whirlpoolsConfig: PublicKey;

@@ -14,3 +14,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetProtocolFeeRateParams = {
export type SetProtocolFeeRateParams = {
whirlpool: PublicKey;

@@ -17,0 +17,0 @@ whirlpoolsConfig: PublicKey;

@@ -15,3 +15,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetRewardAuthorityBySuperAuthorityParams = {
export type SetRewardAuthorityBySuperAuthorityParams = {
whirlpool: PublicKey;

@@ -18,0 +18,0 @@ whirlpoolsConfig: PublicKey;

@@ -14,3 +14,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetRewardAuthorityParams = {
export type SetRewardAuthorityParams = {
whirlpool: PublicKey;

@@ -17,0 +17,0 @@ rewardIndex: number;

@@ -17,3 +17,3 @@ /// <reference types="bn.js" />

*/
export declare type SetRewardEmissionsParams = {
export type SetRewardEmissionsParams = {
whirlpool: PublicKey;

@@ -20,0 +20,0 @@ rewardIndex: number;

@@ -13,3 +13,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type SetRewardEmissionsSuperAuthorityParams = {
export type SetRewardEmissionsSuperAuthorityParams = {
whirlpoolsConfig: PublicKey;

@@ -16,0 +16,0 @@ rewardEmissionsSuperAuthority: PublicKey;

@@ -28,3 +28,3 @@ /// <reference types="bn.js" />

*/
export declare type SwapParams = SwapInput & {
export type SwapParams = SwapInput & {
whirlpool: PublicKey;

@@ -52,3 +52,3 @@ tokenOwnerAccountA: PublicKey;

*/
export declare type SwapInput = {
export type SwapInput = {
amount: u64;

@@ -78,3 +78,3 @@ otherAmountThreshold: u64;

*/
export declare type DevFeeSwapInput = SwapInput & {
export type DevFeeSwapInput = SwapInput & {
devFeeAmount: u64;

@@ -81,0 +81,0 @@ };

@@ -14,3 +14,3 @@ import { Program } from "@project-serum/anchor";

*/
export declare type UpdateFeesAndRewardsParams = {
export type UpdateFeesAndRewardsParams = {
whirlpool: PublicKey;

@@ -17,0 +17,0 @@ position: PublicKey;

import { PDA } from "@orca-so/common-sdk";
import { Program } from "@project-serum/anchor";
import { WhirlpoolContext } from ".";
import { Whirlpool } from "./artifacts/whirlpool";

@@ -306,2 +307,11 @@ import * as ix from "./instructions";

static setRewardEmissionsSuperAuthorityIx(program: Program<Whirlpool>, params: ix.SetRewardEmissionsSuperAuthorityParams): import("@orca-so/common-sdk").Instruction;
/**
* A set of transactions to collect all fees and rewards from a list of positions.
*
* @param ctx - WhirlpoolContext object for the current environment.
* @param params - CollectAllPositionAddressParams object.
* @param refresh - if true, will always fetch for the latest values on chain to compute.
* @returns
*/
static collectAllForPositionsTxns(ctx: WhirlpoolContext, params: ix.CollectAllPositionAddressParams, refresh: boolean): Promise<import("@orca-so/common-sdk").TransactionBuilder[]>;
}

@@ -377,3 +377,14 @@ "use strict";

}
/**
* A set of transactions to collect all fees and rewards from a list of positions.
*
* @param ctx - WhirlpoolContext object for the current environment.
* @param params - CollectAllPositionAddressParams object.
* @param refresh - if true, will always fetch for the latest values on chain to compute.
* @returns
*/
static collectAllForPositionsTxns(ctx, params, refresh) {
return ix.collectAllForPositionAddressesTxns(ctx, params, refresh);
}
}
exports.WhirlpoolIx = WhirlpoolIx;

@@ -10,3 +10,3 @@ import { Connection } from "@solana/web3.js";

*/
declare type CachedValue = WhirlpoolsConfigData | WhirlpoolData | PositionData | TickArrayData | FeeTierData | AccountInfo | MintInfo;
type CachedValue = WhirlpoolsConfigData | WhirlpoolData | PositionData | TickArrayData | FeeTierData | AccountInfo | MintInfo;
/**

@@ -13,0 +13,0 @@ * Include both the entity (i.e. type) of the stored value, and the value itself

@@ -7,3 +7,3 @@ /// <reference types="bn.js" />

*/
export declare type CollectFeesQuoteParam = {
export type CollectFeesQuoteParam = {
whirlpool: WhirlpoolData;

@@ -17,3 +17,3 @@ position: PositionData;

*/
export declare type CollectFeesQuote = {
export type CollectFeesQuote = {
feeOwedA: BN;

@@ -20,0 +20,0 @@ feeOwedB: BN;

@@ -7,3 +7,3 @@ /// <reference types="bn.js" />

*/
export declare type CollectRewardsQuoteParam = {
export type CollectRewardsQuoteParam = {
whirlpool: WhirlpoolData;

@@ -17,3 +17,3 @@ position: PositionData;

*/
export declare type CollectRewardsQuote = [BN | undefined, BN | undefined, BN | undefined];
export type CollectRewardsQuote = [BN | undefined, BN | undefined, BN | undefined];
/**

@@ -20,0 +20,0 @@ * Get a quote on the outstanding rewards owed to a position.

@@ -15,3 +15,3 @@ /// <reference types="bn.js" />

*/
export declare type DecreaseLiquidityQuoteParam = {
export type DecreaseLiquidityQuoteParam = {
liquidity: BN;

@@ -28,3 +28,3 @@ tickCurrentIndex: number;

*/
export declare type DecreaseLiquidityQuote = DecreaseLiquidityInput & {
export type DecreaseLiquidityQuote = DecreaseLiquidityInput & {
tokenEstA: BN;

@@ -43,3 +43,3 @@ tokenEstB: BN;

*/
export declare function decreaseLiquidityQuoteByLiquidity(liquidity: BN, slippageTolerance: Percentage, position: Position, whirlpool: Whirlpool): Promise<DecreaseLiquidityQuote>;
export declare function decreaseLiquidityQuoteByLiquidity(liquidity: BN, slippageTolerance: Percentage, position: Position, whirlpool: Whirlpool): DecreaseLiquidityQuote;
/**

@@ -46,0 +46,0 @@ * Get an estimated quote on the minimum tokens receivable based on the desired withdraw liquidity value.

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -31,14 +22,12 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

function decreaseLiquidityQuoteByLiquidity(liquidity, slippageTolerance, position, whirlpool) {
return __awaiter(this, void 0, void 0, function* () {
const positionData = position.getData();
const whirlpoolData = whirlpool.getData();
(0, tiny_invariant_1.default)(liquidity.lte(positionData.liquidity), "Quote liquidity is more than the position liquidity.");
return decreaseLiquidityQuoteByLiquidityWithParams({
liquidity,
slippageTolerance,
tickLowerIndex: positionData.tickLowerIndex,
tickUpperIndex: positionData.tickUpperIndex,
sqrtPrice: whirlpoolData.sqrtPrice,
tickCurrentIndex: whirlpoolData.tickCurrentIndex,
});
const positionData = position.getData();
const whirlpoolData = whirlpool.getData();
(0, tiny_invariant_1.default)(liquidity.lte(positionData.liquidity), "Quote liquidity is more than the position liquidity.");
return decreaseLiquidityQuoteByLiquidityWithParams({
liquidity,
slippageTolerance,
tickLowerIndex: positionData.tickLowerIndex,
tickUpperIndex: positionData.tickUpperIndex,
sqrtPrice: whirlpoolData.sqrtPrice,
tickCurrentIndex: whirlpoolData.tickCurrentIndex,
});

@@ -45,0 +34,0 @@ }

@@ -18,3 +18,3 @@ import { Percentage } from "@orca-so/common-sdk";

*/
export declare type DevFeeSwapQuote = NormalSwapQuote & {
export type DevFeeSwapQuote = NormalSwapQuote & {
amountSpecifiedIsInput: true;

@@ -21,0 +21,0 @@ estimatedSwapFeeAmount: u64;

@@ -21,3 +21,3 @@ /// <reference types="bn.js" />

*/
export declare type IncreaseLiquidityQuoteParam = {
export type IncreaseLiquidityQuoteParam = {
inputTokenAmount: u64;

@@ -37,3 +37,3 @@ inputTokenMint: PublicKey;

*/
export declare type IncreaseLiquidityQuote = IncreaseLiquidityInput & {
export type IncreaseLiquidityQuote = IncreaseLiquidityInput & {
tokenEstA: u64;

@@ -40,0 +40,0 @@ tokenEstB: u64;

@@ -21,3 +21,3 @@ /// <reference types="bn.js" />

*/
export declare type SwapQuoteParam = {
export type SwapQuoteParam = {
whirlpoolData: WhirlpoolData;

@@ -37,3 +37,3 @@ tokenAmount: u64;

*/
export declare type SwapQuote = NormalSwapQuote | DevFeeSwapQuote;
export type SwapQuote = NormalSwapQuote | DevFeeSwapQuote;
/**

@@ -48,3 +48,3 @@ * A collection of estimated values from quoting a swap.

*/
export declare type NormalSwapQuote = {
export type NormalSwapQuote = {
estimatedAmountIn: u64;

@@ -51,0 +51,0 @@ estimatedAmountOut: u64;

@@ -21,3 +21,2 @@ "use strict";

const swap_quote_impl_1 = require("../swap/swap-quote-impl");
const swap_quote_utils_1 = require("../swap/swap-quote-utils");
/**

@@ -75,3 +74,2 @@ * Get an estimated swap quote using input token amount.

function swapQuoteWithParams(params, slippageTolerance) {
(0, swap_quote_utils_1.checkIfAllTickArraysInitialized)(params.tickArrays);
const quote = (0, swap_quote_impl_1.simulateSwap)(params);

@@ -78,0 +76,0 @@ const slippageAdjustedQuote = Object.assign(Object.assign({}, quote), swap_utils_1.SwapUtils.calculateSwapAmountsFromQuote(quote.amount, quote.estimatedAmountIn, quote.estimatedAmountOut, slippageTolerance, quote.amountSpecifiedIsInput));

@@ -5,3 +5,3 @@ import { u64 } from "@solana/spl-token";

import { TickArraySequence } from "./tick-array-sequence";
export declare type SwapResult = {
export type SwapResult = {
amountA: BN;

@@ -8,0 +8,0 @@ amountB: BN;

@@ -18,3 +18,3 @@ "use strict";

const { aToB, whirlpoolData, tickArrays, tokenAmount, sqrtPriceLimit, otherAmountThreshold, amountSpecifiedIsInput, } = params;
if (sqrtPriceLimit.gt(new anchor_1.BN(public_1.MAX_SQRT_PRICE) || sqrtPriceLimit.lt(new anchor_1.BN(public_1.MIN_SQRT_PRICE)))) {
if (sqrtPriceLimit.gt(new anchor_1.BN(public_1.MAX_SQRT_PRICE)) || sqrtPriceLimit.lt(new anchor_1.BN(public_1.MIN_SQRT_PRICE))) {
throw new errors_1.WhirlpoolsError("Provided SqrtPriceLimit is out of bounds.", errors_1.SwapErrorCode.SqrtPriceOutOfBounds);

@@ -21,0 +21,0 @@ }

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkIfAllTickArraysInitialized = void 0;
const __1 = require("../..");
function checkIfAllTickArraysInitialized(tickArrays) {
import { TickArrayUtil } from "../..";
export function checkIfAllTickArraysInitialized(tickArrays) {
// Check if all the tick arrays have been initialized.
const uninitializedIndices = __1.TickArrayUtil.getUninitializedArrays(tickArrays.map((array) => array.data));
const uninitializedIndices = TickArrayUtil.getUninitializedArrays(tickArrays.map((array) => array.data));
if (uninitializedIndices.length > 0) {

@@ -15,2 +12,1 @@ const uninitializedArrays = uninitializedIndices

}
exports.checkIfAllTickArraysInitialized = checkIfAllTickArraysInitialized;

@@ -6,2 +6,10 @@ "use strict";

class TickArrayIndex {
static fromTickIndex(index, tickSpacing) {
const arrayIndex = Math.floor(Math.floor(index / tickSpacing) / public_1.TICK_ARRAY_SIZE);
let offsetIndex = Math.floor((index % (tickSpacing * public_1.TICK_ARRAY_SIZE)) / tickSpacing);
if (offsetIndex < 0) {
offsetIndex = public_1.TICK_ARRAY_SIZE + offsetIndex;
}
return new TickArrayIndex(arrayIndex, offsetIndex, tickSpacing);
}
constructor(arrayIndex, offsetIndex, tickSpacing) {

@@ -21,10 +29,2 @@ this.arrayIndex = arrayIndex;

}
static fromTickIndex(index, tickSpacing) {
const arrayIndex = Math.floor(Math.floor(index / tickSpacing) / public_1.TICK_ARRAY_SIZE);
let offsetIndex = Math.floor((index % (tickSpacing * public_1.TICK_ARRAY_SIZE)) / tickSpacing);
if (offsetIndex < 0) {
offsetIndex = public_1.TICK_ARRAY_SIZE + offsetIndex;
}
return new TickArrayIndex(arrayIndex, offsetIndex, tickSpacing);
}
toTickIndex() {

@@ -31,0 +31,0 @@ return (this.arrayIndex * public_1.TICK_ARRAY_SIZE * this.tickSpacing + this.offsetIndex * this.tickSpacing);

@@ -8,8 +8,8 @@ import { TickArray, TickData } from "../../types/public";

export declare class TickArraySequence {
readonly tickArrays: TickArray[];
readonly tickSpacing: number;
readonly aToB: boolean;
private sequence;
private touchedArrays;
private startArrayIndex;
constructor(tickArrays: TickArray[], tickSpacing: number, aToB: boolean);
constructor(tickArrays: Readonly<TickArray[]>, tickSpacing: number, aToB: boolean);
checkArrayContainsTickIndex(sequenceIndex: number, tickIndex: number): boolean;

@@ -16,0 +16,0 @@ getNumOfTouchedArrays(): number;

@@ -13,3 +13,2 @@ "use strict";

constructor(tickArrays, tickSpacing, aToB) {
this.tickArrays = tickArrays;
this.tickSpacing = tickSpacing;

@@ -20,8 +19,19 @@ this.aToB = aToB;

}
this.touchedArrays = [...Array(tickArrays.length).fill(false)];
this.startArrayIndex = tick_array_index_1.TickArrayIndex.fromTickIndex(tickArrays[0].data.startTickIndex, this.tickSpacing).arrayIndex;
// If an uninitialized TickArray appears, truncate all TickArrays after it (inclusive).
this.sequence = [];
for (const tickArray of tickArrays) {
if (!tickArray || !tickArray.data) {
break;
}
this.sequence.push({
address: tickArray.address,
data: tickArray.data
});
}
this.touchedArrays = [...Array(this.sequence.length).fill(false)];
this.startArrayIndex = tick_array_index_1.TickArrayIndex.fromTickIndex(this.sequence[0].data.startTickIndex, this.tickSpacing).arrayIndex;
}
checkArrayContainsTickIndex(sequenceIndex, tickIndex) {
var _a;
const tickArray = (_a = this.tickArrays[sequenceIndex]) === null || _a === void 0 ? void 0 : _a.data;
const tickArray = (_a = this.sequence[sequenceIndex]) === null || _a === void 0 ? void 0 : _a.data;
if (!tickArray) {

@@ -38,3 +48,3 @@ return false;

if (curr) {
prev.push(this.tickArrays[index].address);
prev.push(this.sequence[index].address);
}

@@ -62,3 +72,3 @@ return prev;

const localArrayIndex = this.getLocalArrayIndex(targetTaIndex.arrayIndex, this.aToB);
const tickArray = this.tickArrays[localArrayIndex].data;
const tickArray = this.sequence[localArrayIndex].data;
this.touchedArrays[localArrayIndex] = true;

@@ -109,3 +119,3 @@ if (!tickArray) {

const localArrayIndex = this.getLocalArrayIndex(index.arrayIndex, aToB);
const seqLength = this.tickArrays.length;
const seqLength = this.sequence.length;
return localArrayIndex >= 0 && localArrayIndex < seqLength;

@@ -112,0 +122,0 @@ }

@@ -25,3 +25,3 @@ /// <reference types="bn.js" />

*/
export declare type WhirlpoolsConfigData = {
export type WhirlpoolsConfigData = {
feeAuthority: PublicKey;

@@ -36,3 +36,3 @@ collectProtocolFeesAuthority: PublicKey;

*/
export declare type WhirlpoolRewardInfoData = {
export type WhirlpoolRewardInfoData = {
mint: PublicKey;

@@ -47,3 +47,3 @@ vault: PublicKey;

*/
export declare type WhirlpoolBumpsData = {
export type WhirlpoolBumpsData = {
whirlpoolBump: number;

@@ -54,3 +54,3 @@ };

*/
export declare type WhirlpoolData = {
export type WhirlpoolData = {
whirlpoolsConfig: PublicKey;

@@ -78,3 +78,3 @@ whirlpoolBump: number[];

*/
export declare type TickArrayData = {
export type TickArrayData = {
whirlpool: PublicKey;

@@ -87,3 +87,3 @@ startTickIndex: number;

*/
export declare type TickData = {
export type TickData = {
initialized: boolean;

@@ -99,3 +99,3 @@ liquidityNet: BN;

*/
export declare type PositionRewardInfoData = {
export type PositionRewardInfoData = {
growthInsideCheckpoint: BN;

@@ -107,3 +107,3 @@ amountOwed: BN;

*/
export declare type OpenPositionBumpsData = {
export type OpenPositionBumpsData = {
positionBump: number;

@@ -114,3 +114,3 @@ };

*/
export declare type OpenPositionWithMetadataBumpsData = {
export type OpenPositionWithMetadataBumpsData = {
positionBump: number;

@@ -122,3 +122,3 @@ metadataBump: number;

*/
export declare type PositionData = {
export type PositionData = {
whirlpool: PublicKey;

@@ -138,3 +138,3 @@ positionMint: PublicKey;

*/
export declare type FeeTierData = {
export type FeeTierData = {
whirlpoolsConfig: PublicKey;

@@ -141,0 +141,0 @@ tickSpacing: number;

@@ -8,7 +8,7 @@ import { PublicKey } from "@solana/web3.js";

*/
export declare type TokenInfo = MintInfo & {
export type TokenInfo = MintInfo & {
mint: PublicKey;
};
export declare type TokenAccountInfo = AccountInfo;
export declare type WhirlpoolRewardInfo = WhirlpoolRewardInfoData & {
export type TokenAccountInfo = AccountInfo;
export type WhirlpoolRewardInfo = WhirlpoolRewardInfoData & {
initialized: boolean;

@@ -21,5 +21,5 @@ vaultAmount: u64;

*/
export declare type TickArray = {
export type TickArray = {
address: PublicKey;
data: TickArrayData | null;
};
/// <reference types="bn.js" />
import { u64 } from "@solana/spl-token";
import { BN } from "@project-serum/anchor";
export declare type SwapStep = {
export type SwapStep = {
amountIn: BN;

@@ -6,0 +6,0 @@ amountOut: BN;

@@ -0,7 +1,7 @@

export * from "./ix-utils";
export * from "./pda-utils";
export * from "./pool-utils";
export * from "./price-math";
export * from "./swap-utils";
export * from "./tick-utils";
export * from "./pool-utils";
export * from "./ix-utils";
export * from "./types";
export * from "./swap-utils";

@@ -17,8 +17,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ix-utils"), exports);
__exportStar(require("./pda-utils"), exports);
__exportStar(require("./pool-utils"), exports);
__exportStar(require("./price-math"), exports);
__exportStar(require("./swap-utils"), exports);
__exportStar(require("./tick-utils"), exports);
__exportStar(require("./pool-utils"), exports);
__exportStar(require("./ix-utils"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./swap-utils"), exports);

@@ -63,3 +63,3 @@ /// <reference types="bn.js" />

*/
export declare type TokenAmounts = {
export type TokenAmounts = {
tokenA: u64;

@@ -66,0 +66,0 @@ tokenB: u64;

@@ -26,2 +26,16 @@ /// <reference types="bn.js" />

static priceToInitializableTickIndex(price: Decimal, decimalsA: number, decimalsB: number, tickSpacing: number): number;
/**
* Utility to invert the price Pb/Pa to Pa/Pb
* @param price Pb / Pa
* @param decimalsA Decimals of original token A (i.e. token A in the given Pb / Pa price)
* @param decimalsB Decimals of original token B (i.e. token B in the given Pb / Pa price)
* @returns inverted price, i.e. Pa / Pb
*/
static invertPrice(price: Decimal, decimalsA: number, decimalsB: number): Decimal;
/**
* Utility to invert the sqrtPriceX64 from X64 repr. of sqrt(Pb/Pa) to X64 repr. of sqrt(Pa/Pb)
* @param sqrtPriceX64 X64 representation of sqrt(Pb / Pa)
* @returns inverted sqrtPriceX64, i.e. X64 representation of sqrt(Pa / Pb)
*/
static invertSqrtPriceX64(sqrtPriceX64: BN): BN;
}

@@ -93,2 +93,24 @@ "use strict";

}
/**
* Utility to invert the price Pb/Pa to Pa/Pb
* @param price Pb / Pa
* @param decimalsA Decimals of original token A (i.e. token A in the given Pb / Pa price)
* @param decimalsB Decimals of original token B (i.e. token B in the given Pb / Pa price)
* @returns inverted price, i.e. Pa / Pb
*/
static invertPrice(price, decimalsA, decimalsB) {
const tick = PriceMath.priceToTickIndex(price, decimalsA, decimalsB);
const invTick = tick_utils_1.TickUtil.invertTick(tick);
return PriceMath.tickIndexToPrice(invTick, decimalsB, decimalsA);
}
/**
* Utility to invert the sqrtPriceX64 from X64 repr. of sqrt(Pb/Pa) to X64 repr. of sqrt(Pa/Pb)
* @param sqrtPriceX64 X64 representation of sqrt(Pb / Pa)
* @returns inverted sqrtPriceX64, i.e. X64 representation of sqrt(Pa / Pb)
*/
static invertSqrtPriceX64(sqrtPriceX64) {
const tick = PriceMath.sqrtPriceX64ToTickIndex(sqrtPriceX64);
const invTick = tick_utils_1.TickUtil.invertTick(tick);
return PriceMath.tickIndexToSqrtPriceX64(invTick);
}
}

@@ -95,0 +117,0 @@ exports.PriceMath = PriceMath;

@@ -46,2 +46,11 @@ import { PublicKey } from "@solana/web3.js";

static isTickInitializable(tick: number, tickSpacing: number): boolean;
/**
*
* Returns the tick for the inverse of the price that this tick represents.
* Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
* inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
* @param tick The tick to invert
* @returns
*/
static invertTick(tick: number): number;
}

@@ -48,0 +57,0 @@ /**

@@ -103,2 +103,13 @@ "use strict";

}
/**
*
* Returns the tick for the inverse of the price that this tick represents.
* Eg: Consider tick i where Pb/Pa = 1.0001 ^ i
* inverse of this, i.e. Pa/Pb = 1 / (1.0001 ^ i) = 1.0001^-i
* @param tick The tick to invert
* @returns
*/
static invertTick(tick) {
return -tick;
}
}

@@ -105,0 +116,0 @@ exports.TickUtil = TickUtil;

@@ -28,2 +28,3 @@ import { Percentage, TransactionBuilder } from "@orca-so/common-sdk";

* @param poolAddress the address of the Whirlpool account
* @param refresh true to always request newest data from chain with this request
* @return a Whirlpool object to interact with

@@ -35,2 +36,3 @@ */

* @param poolAddresses the addresses of the Whirlpool accounts
* @param refresh true to always request newest data from chain with this request
* @return a list of Whirlpool objects to interact with

@@ -42,5 +44,38 @@ */

* @param positionAddress the address of the Position account
* @return a Position object to interact with
* @param refresh true to always request newest data from chain with this request
* @return a Position object to interact with.
* @throws error when address does not return a Position account.
*/
getPosition: (positionAddress: Address, refresh?: boolean) => Promise<Position>;
/**
* Get a list of Position objects to interact with the Position account at the given addresses.
* @param positionAddress the addresses of the Position accounts
* @param refresh true to always request newest data from chain with this request
* @return a Record object between account address and Position. If an address is not a Position account, it will be null.
*/
getPositions: (positionAddresses: Address[], refresh?: boolean) => Promise<Record<string, Position | null>>;
/**
* Collect all fees and rewards from a list of positions.
* @experimental
* @param positionAddress the addresses of the Position accounts to collect fee & rewards from.
* @param refresh true to always request newest data from chain with this request
* @returns A set of transaction-builders to resolve ATA for affliated tokens, collect fee & rewards for all positions.
* The first transaction should always be processed as it contains all the resolve ATA instructions to receive tokens.
*/
collectFeesAndRewardsForPositions: (positionAddresses: Address[], refresh?: boolean) => Promise<TransactionBuilder[]>;
/**
* Create a Whirlpool account for a group of token A, token B and tick spacing
* @param whirlpoolConfig the address of the whirlpool config
* @param tokenMintA the address of the token A
* @param tokenMintB the address of the token B
* @param tickSpacing the space between two ticks in the tick array
* @param initialTick the initial tick that the pool is set to (derived from initial price)
* @param funder the account to debit SOL from to fund the creation of the account(s)
* @return `poolKey`: The public key of the newly created whirlpool account. `tx`: The transaction containing instructions for the on-chain operations.
* @throws error when the tokens are not in the canonical byte-based ordering. To resolve this, invert the token order and the initialTick (see `TickUtil.invertTick()`, `PriceMath.invertSqrtPriceX64()`, or `PriceMath.invertPrice()`).
*/
createPool: (whirlpoolsConfig: Address, tokenMintA: Address, tokenMintB: Address, tickSpacing: number, initialTick: number, funder: Address) => Promise<{
poolKey: PublicKey;
tx: TransactionBuilder;
}>;
}

@@ -47,0 +82,0 @@ /**

{
"name": "@orca-so/whirlpools-sdk",
"version": "0.5.3",
"version": "0.6.0",
"description": "Typescript SDK to interact with Orca's Whirlpool program.",

@@ -10,3 +10,4 @@ "license": "Apache-2.0",

"@metaplex-foundation/mpl-token-metadata": "1.2.5",
"@orca-so/common-sdk": "~0.1.1",
"@solana/web3.js": "1.66.0",
"@orca-so/common-sdk": "^0.1.4",
"@project-serum/anchor": "~0.25.0",

@@ -19,3 +20,2 @@ "@solana/spl-token": "^0.1.8",

"@types/bn.js": "~5.1.0",
"@types/decimal.js": "^7.4.0",
"@types/jest": "^26.0.24",

@@ -30,2 +30,3 @@ "@types/mocha": "^9.0.0",

"prettier": "^2.3.2",
"process": "^0.11.10",
"ts-jest": "^27.0.3",

@@ -32,0 +33,0 @@ "typescript": "^4.5.5"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc