New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@orca-so/whirlpools-sdk

Package Overview
Dependencies
Maintainers
5
Versions
95
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.11.0-beta-1 to 0.11.0-beta-2

8

dist/context.d.ts

@@ -5,3 +5,3 @@ import { AnchorProvider, Program } from "@coral-xyz/anchor";

import { Whirlpool } from "./artifacts/whirlpool";
import { WhirlpoolAccountFetcher, WhirlpoolAccountFetcherInterface } from "./network/public/account-fetcher";
import { WhirlpoolAccountFetcherInterface } from "./network/public/account-fetcher";
/**

@@ -29,6 +29,6 @@ * Default settings used when interacting with transactions.

readonly txBuilderOpts: TransactionBuilderOptions | undefined;
static from(connection: Connection, wallet: Wallet, programId: PublicKey, cache?: WhirlpoolAccountFetcher, lookupTableFetcher?: LookupTableFetcher, opts?: WhirlpoolContextOpts): WhirlpoolContext;
static fromWorkspace(provider: AnchorProvider, program: Program, fetcher?: WhirlpoolAccountFetcher, lookupTableFetcher?: LookupTableFetcher, opts?: WhirlpoolContextOpts): WhirlpoolContext;
static withProvider(provider: AnchorProvider, programId: PublicKey, fetcher?: WhirlpoolAccountFetcher, lookupTableFetcher?: LookupTableFetcher, opts?: WhirlpoolContextOpts): WhirlpoolContext;
static from(connection: Connection, wallet: Wallet, programId: PublicKey, fetcher?: WhirlpoolAccountFetcherInterface, lookupTableFetcher?: LookupTableFetcher, opts?: WhirlpoolContextOpts): WhirlpoolContext;
static fromWorkspace(provider: AnchorProvider, program: Program, fetcher?: WhirlpoolAccountFetcherInterface, lookupTableFetcher?: LookupTableFetcher, opts?: WhirlpoolContextOpts): WhirlpoolContext;
static withProvider(provider: AnchorProvider, programId: PublicKey, fetcher?: WhirlpoolAccountFetcherInterface, lookupTableFetcher?: LookupTableFetcher, opts?: WhirlpoolContextOpts): WhirlpoolContext;
constructor(provider: AnchorProvider, wallet: Wallet, program: Program, fetcher: WhirlpoolAccountFetcherInterface, lookupTableFetcher?: LookupTableFetcher, opts?: WhirlpoolContextOpts);
}

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

class WhirlpoolContext {
static from(connection, wallet, programId, cache = new account_fetcher_1.WhirlpoolAccountFetcher(connection, account_fetcher_1.DEFAULT_WHIRLPOOL_RETENTION_POLICY), lookupTableFetcher, opts = {}) {
static from(connection, wallet, programId, fetcher = new account_fetcher_1.WhirlpoolAccountFetcher(connection, account_fetcher_1.DEFAULT_WHIRLPOOL_RETENTION_POLICY), lookupTableFetcher, opts = {}) {
const anchorProvider = new anchor_1.AnchorProvider(connection, wallet, {

@@ -23,3 +23,3 @@ commitment: opts.userDefaultConfirmCommitment || "confirmed",

const program = new anchor_1.Program(whirlpool_json_1.default, programId, anchorProvider);
return new WhirlpoolContext(anchorProvider, anchorProvider.wallet, program, cache, lookupTableFetcher, opts);
return new WhirlpoolContext(anchorProvider, anchorProvider.wallet, program, fetcher, lookupTableFetcher, opts);
}

@@ -26,0 +26,0 @@ static fromWorkspace(provider, program, fetcher = new account_fetcher_1.WhirlpoolAccountFetcher(provider.connection, account_fetcher_1.DEFAULT_WHIRLPOOL_RETENTION_POLICY), lookupTableFetcher, opts = {}) {

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

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

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

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

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

}
async collectFees(updateFeesAndRewards = true, ownerTokenAccountMap, destinationWallet, positionWallet, ataPayer, opts = account_fetcher_1.AVOID_REFRESH) {
async collectFees(updateFeesAndRewards = true, ownerTokenAccountMap, destinationWallet, positionWallet, ataPayer, opts = account_fetcher_1.PREFER_CACHE) {
const [destinationWalletKey, positionWalletKey, ataPayerKey] = common_sdk_1.AddressUtil.toPubKeys([

@@ -189,3 +189,3 @@ destinationWallet ?? this.ctx.wallet.publicKey,

}
async collectRewards(rewardsToCollect, updateFeesAndRewards = true, ownerTokenAccountMap, destinationWallet, positionWallet, ataPayer, opts = account_fetcher_1.PREFER_REFRESH) {
async collectRewards(rewardsToCollect, updateFeesAndRewards = true, ownerTokenAccountMap, destinationWallet, positionWallet, ataPayer, opts = account_fetcher_1.IGNORE_CACHE) {
const [destinationWalletKey, positionWalletKey, ataPayerKey] = common_sdk_1.AddressUtil.toPubKeys([

@@ -248,11 +248,11 @@ destinationWallet ?? this.ctx.wallet.publicKey,

async refresh() {
const positionAccount = await this.ctx.fetcher.getPosition(this.address, account_fetcher_1.PREFER_REFRESH);
const positionAccount = await this.ctx.fetcher.getPosition(this.address, account_fetcher_1.IGNORE_CACHE);
if (!!positionAccount) {
this.data = positionAccount;
}
const whirlpoolAccount = await this.ctx.fetcher.getPool(this.data.whirlpool, account_fetcher_1.PREFER_REFRESH);
const whirlpoolAccount = await this.ctx.fetcher.getPool(this.data.whirlpool, account_fetcher_1.IGNORE_CACHE);
if (!!whirlpoolAccount) {
this.whirlpoolData = whirlpoolAccount;
}
const [lowerTickArray, upperTickArray] = await (0, position_builder_util_1.getTickArrayDataForPosition)(this.ctx, this.data, this.whirlpoolData, account_fetcher_1.PREFER_REFRESH);
const [lowerTickArray, upperTickArray] = await (0, position_builder_util_1.getTickArrayDataForPosition)(this.ctx, this.data, this.whirlpoolData, account_fetcher_1.IGNORE_CACHE);
if (lowerTickArray) {

@@ -259,0 +259,0 @@ this.lowerTickArrayData = lowerTickArray;

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

}
async getPool(poolAddress, opts = account_fetcher_1.AVOID_REFRESH) {
async getPool(poolAddress, opts = account_fetcher_1.PREFER_CACHE) {
const account = await this.ctx.fetcher.getPool(poolAddress, opts);

@@ -44,3 +44,3 @@ if (!account) {

}
async getPools(poolAddresses, opts = account_fetcher_1.AVOID_REFRESH) {
async getPools(poolAddresses, opts = account_fetcher_1.PREFER_CACHE) {
const accounts = Array.from((await this.ctx.fetcher.getPools(poolAddresses, opts)).values()).filter((account) => !!account);

@@ -69,5 +69,5 @@ if (accounts.length !== poolAddresses.length) {

const poolAddress = poolAddresses[i];
const tokenInfos = await (0, util_1.getTokenMintInfos)(this.ctx.fetcher, account, account_fetcher_1.AVOID_REFRESH);
const vaultInfos = await (0, util_1.getTokenVaultAccountInfos)(this.ctx.fetcher, account, account_fetcher_1.AVOID_REFRESH);
const rewardInfos = await (0, util_1.getRewardInfos)(this.ctx.fetcher, account, account_fetcher_1.AVOID_REFRESH);
const tokenInfos = await (0, util_1.getTokenMintInfos)(this.ctx.fetcher, account, account_fetcher_1.PREFER_CACHE);
const vaultInfos = await (0, util_1.getTokenVaultAccountInfos)(this.ctx.fetcher, account, account_fetcher_1.PREFER_CACHE);
const rewardInfos = await (0, util_1.getRewardInfos)(this.ctx.fetcher, account, account_fetcher_1.PREFER_CACHE);
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));

@@ -77,3 +77,3 @@ }

}
async getPosition(positionAddress, opts = account_fetcher_1.AVOID_REFRESH) {
async getPosition(positionAddress, opts = account_fetcher_1.PREFER_CACHE) {
const account = await this.ctx.fetcher.getPosition(positionAddress, opts);

@@ -93,3 +93,3 @@ if (!account) {

}
async getPositions(positionAddresses, opts = account_fetcher_1.AVOID_REFRESH) {
async getPositions(positionAddresses, opts = account_fetcher_1.PREFER_CACHE) {
// TODO: Prefetch and use fetcher as a cache - Think of a cleaner way to prefetch

@@ -104,3 +104,3 @@ const positions = Array.from((await this.ctx.fetcher.getPositions(positionAddresses, opts)).values());

if (pos) {
const pool = await this.ctx.fetcher.getPool(pos.whirlpool, account_fetcher_1.AVOID_REFRESH);
const pool = await this.ctx.fetcher.getPool(pos.whirlpool, account_fetcher_1.PREFER_CACHE);
if (pool) {

@@ -114,7 +114,7 @@ const lowerTickArrayPda = public_2.PDAUtil.getTickArrayFromTickIndex(pos.tickLowerIndex, pool.tickSpacing, pos.whirlpool, this.ctx.program.programId).publicKey;

}));
await this.ctx.fetcher.getTickArrays(Array.from(tickArrayAddresses), account_fetcher_1.PREFER_REFRESH);
await this.ctx.fetcher.getTickArrays(Array.from(tickArrayAddresses), account_fetcher_1.IGNORE_CACHE);
// Use getPosition and the prefetched values to generate the Positions
const results = await Promise.all(positionAddresses.map(async (pos) => {
try {
const position = await this.getPosition(pos, account_fetcher_1.AVOID_REFRESH);
const position = await this.getPosition(pos, account_fetcher_1.PREFER_CACHE);
return [pos, position];

@@ -128,3 +128,3 @@ }

}
async createPool(whirlpoolsConfig, tokenMintA, tokenMintB, tickSpacing, initialTick, funder, opts = account_fetcher_1.AVOID_REFRESH) {
async createPool(whirlpoolsConfig, tokenMintA, tokenMintB, tickSpacing, initialTick, funder, opts = account_fetcher_1.PREFER_CACHE) {
(0, tiny_invariant_1.default)(public_2.TickUtil.checkTickInBounds(initialTick), "initialTick is out of bounds.");

@@ -131,0 +131,0 @@ (0, tiny_invariant_1.default)(public_2.TickUtil.isTickInitializable(initialTick, tickSpacing), `initial tick ${initialTick} is not an initializable tick for tick-spacing ${tickSpacing}`);

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

}
async initTickArrayForTicks(ticks, funder, opts = account_fetcher_1.AVOID_REFRESH) {
async initTickArrayForTicks(ticks, funder, opts = account_fetcher_1.PREFER_CACHE) {
const initTickArrayStartPdas = await public_2.TickArrayUtil.getUninitializedArraysPDAs(ticks, this.ctx.program.programId, this.address, this.data.tickSpacing, this.ctx.fetcher, opts);

@@ -100,3 +100,3 @@ if (!initTickArrayStartPdas.length) {

wallet: sourceWalletKey,
}, account_fetcher_1.PREFER_REFRESH);
}, account_fetcher_1.IGNORE_CACHE);
}

@@ -115,3 +115,3 @@ async swapWithDevFees(quote, devFeeWallet, wallet, payer) {

wallet: sourceWalletKey,
}, account_fetcher_1.PREFER_REFRESH);
}, account_fetcher_1.IGNORE_CACHE);
txBuilder.addInstruction(swapTxBuilder.compressIx(true));

@@ -128,3 +128,3 @@ return txBuilder;

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

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

async getClosePositionIx(positionAddress, slippageTolerance, destinationWallet, positionWallet, payerKey) {
const positionData = await this.ctx.fetcher.getPosition(positionAddress, account_fetcher_1.PREFER_REFRESH);
const positionData = await this.ctx.fetcher.getPosition(positionAddress, account_fetcher_1.IGNORE_CACHE);
if (!positionData) {

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

const tickArrayUpper = public_2.PDAUtil.getTickArrayFromTickIndex(positionData.tickUpperIndex, whirlpool.tickSpacing, positionData.whirlpool, this.ctx.program.programId).publicKey;
const [tickArrayLowerData, tickArrayUpperData] = await (0, position_builder_util_1.getTickArrayDataForPosition)(this.ctx, positionData, whirlpool, account_fetcher_1.PREFER_REFRESH);
const [tickArrayLowerData, tickArrayUpperData] = await (0, position_builder_util_1.getTickArrayDataForPosition)(this.ctx, positionData, whirlpool, account_fetcher_1.IGNORE_CACHE);
(0, tiny_invariant_1.default)(!!tickArrayLowerData, `Tick array ${tickArrayLower} expected to be initialized for whirlpool ${this.address}`);

@@ -272,3 +272,3 @@ (0, tiny_invariant_1.default)(!!tickArrayUpperData, `Tick array ${tickArrayUpper} expected to be initialized for whirlpool ${this.address}`);

if (shouldCollectFees) {
const collectFeexTx = await position.collectFees(false, walletTokenAccountsByMint, destinationWallet, positionWallet, payerKey, account_fetcher_1.PREFER_REFRESH);
const collectFeexTx = await position.collectFees(false, walletTokenAccountsByMint, destinationWallet, positionWallet, payerKey, account_fetcher_1.IGNORE_CACHE);
txBuilder.addInstruction(collectFeexTx.compressIx(false));

@@ -297,6 +297,6 @@ }

async refresh() {
const account = await this.ctx.fetcher.getPool(this.address, account_fetcher_1.PREFER_REFRESH);
const account = await this.ctx.fetcher.getPool(this.address, account_fetcher_1.IGNORE_CACHE);
if (!!account) {
const rewardInfos = await (0, util_1.getRewardInfos)(this.ctx.fetcher, account, account_fetcher_1.PREFER_REFRESH);
const [tokenVaultAInfo, tokenVaultBInfo] = await (0, util_1.getTokenVaultAccountInfos)(this.ctx.fetcher, account, account_fetcher_1.PREFER_REFRESH);
const rewardInfos = await (0, util_1.getRewardInfos)(this.ctx.fetcher, account, account_fetcher_1.IGNORE_CACHE);
const [tokenVaultAInfo, tokenVaultBInfo] = await (0, util_1.getTokenVaultAccountInfos)(this.ctx.fetcher, account, account_fetcher_1.IGNORE_CACHE);
this.data = account;

@@ -303,0 +303,0 @@ this.tokenVaultAInfo = tokenVaultAInfo;

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

*/
async function collectAllForPositionAddressesTxns(ctx, params, opts = account_fetcher_1.AVOID_REFRESH) {
async function collectAllForPositionAddressesTxns(ctx, params, opts = account_fetcher_1.PREFER_CACHE) {
const { positions, ...rest } = params;

@@ -55,3 +55,3 @@ const fetchedPositions = await ctx.fetcher.getPositions(positions, opts);

const whirlpoolAddrs = positionList.map(([, pos]) => pos.whirlpool.toBase58());
const whirlpools = await ctx.fetcher.getPools(whirlpoolAddrs, account_fetcher_1.AVOID_REFRESH);
const whirlpools = await ctx.fetcher.getPools(whirlpoolAddrs, account_fetcher_1.PREFER_CACHE);
const allMints = (0, whirlpool_ata_utils_1.getTokenMintsFromWhirlpools)(Array.from(whirlpools.values()));

@@ -58,0 +58,0 @@ const accountExemption = await ctx.fetcher.getAccountRentExempt();

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

const payerKey = ctx.wallet.publicKey;
const whirlpoolDatas = Array.from((await ctx.fetcher.getPools(poolAddresses, account_fetcher_1.AVOID_REFRESH)).values());
const whirlpoolDatas = Array.from((await ctx.fetcher.getPools(poolAddresses, account_fetcher_1.PREFER_CACHE)).values());
const accountExemption = await ctx.fetcher.getAccountRentExempt();

@@ -16,0 +16,0 @@ const { ataTokenAddresses, resolveAtaIxs } = await (0, whirlpool_ata_utils_1.resolveAtaForMints)(ctx, {

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

const two_hop_swap_ix_1 = require("../two-hop-swap-ix");
async function getSwapFromRoute(ctx, params, opts = account_fetcher_1.AVOID_REFRESH, txBuilder = new common_sdk_1.TransactionBuilder(ctx.connection, ctx.wallet, (0, txn_utils_1.contextOptionsToBuilderOptions)(ctx.opts))) {
async function getSwapFromRoute(ctx, params, opts = account_fetcher_1.PREFER_CACHE, txBuilder = new common_sdk_1.TransactionBuilder(ctx.connection, ctx.wallet, (0, txn_utils_1.contextOptionsToBuilderOptions)(ctx.opts))) {
const { route, wallet, resolvedAtaAccounts, slippage } = params;

@@ -75,3 +75,3 @@ const requiredAtas = new Set();

else {
return ctx.fetcher.getTokenInfos(keys, opts).then(result => Array.from(result.values()));
return ctx.fetcher.getTokenInfos(keys, opts).then((result) => Array.from(result.values()));
}

@@ -78,0 +78,0 @@ });

@@ -5,26 +5,134 @@ import { AccountFetcher, Address, BasicSupportedTypes, ParsableEntity, RetentionPolicy, SimpleAccountFetchOptions, SimpleAccountFetcher } from "@orca-so/common-sdk";

import { FeeTierData, PositionBundleData, PositionData, TickArrayData, WhirlpoolData, WhirlpoolsConfigData } from "../../types/public";
/**
* Union type of all the {@link ParsableEntity} types that can be cached in the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
export type WhirlpoolSupportedTypes = WhirlpoolsConfigData | WhirlpoolData | PositionData | TickArrayData | FeeTierData | PositionBundleData | BasicSupportedTypes;
/**
* The default retention periods for each {@link ParsableEntity} type in the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
export declare const DEFAULT_WHIRLPOOL_RETENTION_POLICY: ReadonlyMap<ParsableEntity<WhirlpoolSupportedTypes>, number>;
/**
* Type to define fetch options for the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
export type WhirlpoolAccountFetchOptions = SimpleAccountFetchOptions;
export declare const PREFER_REFRESH: WhirlpoolAccountFetchOptions;
export declare const AVOID_REFRESH: WhirlpoolAccountFetchOptions;
/**
* Default fetch option for always fetching when making an account request to the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
export declare const IGNORE_CACHE: WhirlpoolAccountFetchOptions;
/**
* Default fetch option for always using the cached value for an account request to the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
export declare const PREFER_CACHE: WhirlpoolAccountFetchOptions;
/**
* Fetcher interface for fetching {@link WhirlpoolSupportedTypes} from the network
* @category Network
*/
export interface WhirlpoolAccountFetcherInterface extends AccountFetcher<WhirlpoolSupportedTypes, WhirlpoolAccountFetchOptions> {
/**
* Fetch and cache the rent exempt value
* @param refresh If true, will always fetch from the network
*/
getAccountRentExempt(refresh?: boolean): Promise<number>;
/**
* Fetch and cache the account for a given Whirlpool addresses
* @param address The mint address
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getPool(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<WhirlpoolData | null>;
/**
* Fetch and cache the accounts for a given array of Whirlpool addresses
* @param addresses The array of mint addresses
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getPools(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyMap<string, WhirlpoolData | null>>;
/**
* Fetch and cache the account for a given Position address
* @param address The address of the position account
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getPosition(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<PositionData | null>;
/**
* Fetch and cache the accounts for a given array of Position addresses
* @param addresses The array of position account addresses
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getPositions(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyMap<string, PositionData | null>>;
/**
* Fetch and cache the account for a given TickArray address.
* @param address The address of the tick array account
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getTickArray(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<TickArrayData | null>;
/**
* Fetch and cache the accounts for a given array of TickArray addresses
* @param addresses The array of tick array account addresses
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getTickArrays(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyArray<TickArrayData | null>>;
/**
* Fetch and cache the account for a given FeeTier address
* @param address The address of the fee tier account
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getFeeTier(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<FeeTierData | null>;
/**
* Fetch and cache the accounts for a given array of FeeTier addresses
* @param addresses The array of fee tier account addresses
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getFeeTiers(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyMap<string, FeeTierData | null>>;
/**
* Fetch and cache the account for a given TokenAccount address
* @param address The address of the token account
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getTokenInfo(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<TokenAccount | null>;
/**
* Fetch and cache the accounts for a given array of TokenAccount addresses
* @param addresses The array of token account addresses
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getTokenInfos(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyMap<string, TokenAccount | null>>;
/**
* Fetch and cache the account for a given Mint address
* @param address The address of the mint account
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getMintInfo(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<Mint | null>;
/**
* Fetch and cache the accounts for a given array of Mint addresses
* @param addresses The array of mint account addresses
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getMintInfos(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyMap<string, Mint | null>>;
/**
* Fetch and cache the account for a given WhirlpoolConfig address
* @param address The address of the WhirlpoolConfig account
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getConfig(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<WhirlpoolsConfigData | null>;
getConfigs(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyMap<string, WhirlpoolsConfigData | null>>;
/**
* Fetch and cache the account for a given PositionBundle address
* @param address The address of the position bundle account
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getPositionBundle(address: Address, opts?: WhirlpoolAccountFetchOptions): Promise<PositionBundleData | null>;
/**
* Fetch and cache the accounts for a given array of PositionBundle addresses
* @param addresses The array of position bundle account addresses
* @param opts {@link WhirlpoolAccountFetchOptions} instance to dictate fetch behavior
*/
getPositionBundles(addresses: Address[], opts?: WhirlpoolAccountFetchOptions): Promise<ReadonlyMap<string, PositionBundleData | null>>;
}
/**
* Fetcher and cache layer for fetching {@link WhirlpoolSupportedTypes} from the network
* Default implementation for {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
export declare class WhirlpoolAccountFetcher extends SimpleAccountFetcher<WhirlpoolSupportedTypes, WhirlpoolAccountFetchOptions> implements WhirlpoolAccountFetcherInterface {

@@ -31,0 +139,0 @@ readonly connection: Connection;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WhirlpoolAccountFetcher = exports.AVOID_REFRESH = exports.PREFER_REFRESH = exports.DEFAULT_WHIRLPOOL_RETENTION_POLICY = void 0;
exports.WhirlpoolAccountFetcher = exports.PREFER_CACHE = exports.IGNORE_CACHE = exports.DEFAULT_WHIRLPOOL_RETENTION_POLICY = void 0;
const common_sdk_1 = require("@orca-so/common-sdk");
const spl_token_1 = require("@solana/spl-token");
const __1 = require("../..");
/**
* The default retention periods for each {@link ParsableEntity} type in the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
exports.DEFAULT_WHIRLPOOL_RETENTION_POLICY = new Map([
[__1.ParsableWhirlpool, 8 * 1000],
[__1.ParsableTickArray, 8 * 1000]
[__1.ParsableTickArray, 8 * 1000],
]);
exports.PREFER_REFRESH = { maxAge: 0 };
exports.AVOID_REFRESH = { maxAge: Number.POSITIVE_INFINITY };
/**
* Default fetch option for always fetching when making an account request to the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
exports.IGNORE_CACHE = { maxAge: 0 };
/**
* Default fetch option for always using the cached value for an account request to the {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
exports.PREFER_CACHE = { maxAge: Number.POSITIVE_INFINITY };
/**
* Fetcher and cache layer for fetching {@link WhirlpoolSupportedTypes} from the network
* Default implementation for {@link WhirlpoolAccountFetcherInterface}
* @category Network
*/
class WhirlpoolAccountFetcher extends common_sdk_1.SimpleAccountFetcher {

@@ -14,0 +31,0 @@ constructor(connection, retentionPolicy) {

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

export * from "./account-fetcher";
export * from "./parsing";

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

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./account-fetcher"), exports);
__exportStar(require("./parsing"), exports);

@@ -5,3 +5,3 @@ /// <reference types="node" />

/**
* @category Parsables
* @category Network
*/

@@ -13,3 +13,3 @@ export declare class ParsableWhirlpoolsConfig {

/**
* @category Parsables
* @category Network
*/

@@ -21,3 +21,3 @@ export declare class ParsableWhirlpool {

/**
* @category Parsables
* @category Network
*/

@@ -29,3 +29,3 @@ export declare class ParsablePosition {

/**
* @category Parsables
* @category Network
*/

@@ -37,3 +37,3 @@ export declare class ParsableTickArray {

/**
* @category Parsables
* @category Network
*/

@@ -45,3 +45,3 @@ export declare class ParsableFeeTier {

/**
* @category Parsables
* @category Network
*/

@@ -48,0 +48,0 @@ export declare class ParsablePositionBundle {

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

/**
* @category Parsables
* @category Network
*/

@@ -61,3 +61,3 @@ let ParsableWhirlpoolsConfig = class ParsableWhirlpoolsConfig {

/**
* @category Parsables
* @category Network
*/

@@ -84,3 +84,3 @@ let ParsableWhirlpool = class ParsableWhirlpool {

/**
* @category Parsables
* @category Network
*/

@@ -107,3 +107,3 @@ let ParsablePosition = class ParsablePosition {

/**
* @category Parsables
* @category Network
*/

@@ -130,3 +130,3 @@ let ParsableTickArray = class ParsableTickArray {

/**
* @category Parsables
* @category Network
*/

@@ -153,3 +153,3 @@ let ParsableFeeTier = class ParsableFeeTier {

/**
* @category Parsables
* @category Network
*/

@@ -156,0 +156,0 @@ let ParsablePositionBundle = class ParsablePositionBundle {

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

*/
static async fetchTokenPricesByMints(ctx, mints, config = _1.defaultGetPricesConfig, thresholdConfig = _1.defaultGetPricesThresholdConfig, opts = account_fetcher_1.PREFER_REFRESH, availableData = {}) {
static async fetchTokenPricesByMints(ctx, mints, config = _1.defaultGetPricesConfig, thresholdConfig = _1.defaultGetPricesThresholdConfig, opts = account_fetcher_1.IGNORE_CACHE, availableData = {}) {
const poolMap = availableData?.poolMap

@@ -40,3 +40,3 @@ ? availableData?.poolMap

? availableData.decimalsMap
: await PriceModuleUtils.fetchDecimalsForMints(ctx, mints, account_fetcher_1.AVOID_REFRESH);
: await PriceModuleUtils.fetchDecimalsForMints(ctx, mints, account_fetcher_1.PREFER_CACHE);
return PriceModule.calculateTokenPrices(mints, {

@@ -58,3 +58,3 @@ poolMap,

*/
static async fetchTokenPricesByPools(ctx, pools, config = _1.defaultGetPricesConfig, thresholdConfig = _1.defaultGetPricesThresholdConfig, opts = account_fetcher_1.PREFER_REFRESH) {
static async fetchTokenPricesByPools(ctx, pools, config = _1.defaultGetPricesConfig, thresholdConfig = _1.defaultGetPricesThresholdConfig, opts = account_fetcher_1.IGNORE_CACHE) {
const poolDatas = Array.from((await ctx.fetcher.getPools(pools, opts)).values());

@@ -69,3 +69,3 @@ const [filteredPoolDatas, filteredPoolAddresses] = (0, txn_utils_1.filterNullObjects)(poolDatas, pools);

}, new Set()));
const decimalsMap = await PriceModuleUtils.fetchDecimalsForMints(ctx, mints, account_fetcher_1.AVOID_REFRESH);
const decimalsMap = await PriceModuleUtils.fetchDecimalsForMints(ctx, mints, account_fetcher_1.PREFER_CACHE);
return PriceModule.calculateTokenPrices(mints, {

@@ -159,3 +159,3 @@ poolMap,

*/
static async fetchPoolDataFromMints(ctx, mints, config = _1.defaultGetPricesConfig, opts = account_fetcher_1.PREFER_REFRESH) {
static async fetchPoolDataFromMints(ctx, mints, config = _1.defaultGetPricesConfig, opts = account_fetcher_1.IGNORE_CACHE) {
const { quoteTokens, tickSpacings, programId, whirlpoolsConfig } = config;

@@ -185,3 +185,3 @@ const poolAddresses = mints

*/
static async fetchTickArraysForPools(ctx, pools, config = _1.defaultGetPricesConfig, opts = account_fetcher_1.PREFER_REFRESH) {
static async fetchTickArraysForPools(ctx, pools, config = _1.defaultGetPricesConfig, opts = account_fetcher_1.IGNORE_CACHE) {
const { programId } = config;

@@ -219,3 +219,3 @@ const getQuoteTokenOrder = (mint) => {

*/
static async fetchDecimalsForMints(ctx, mints, opts = account_fetcher_1.PREFER_REFRESH) {
static async fetchDecimalsForMints(ctx, mints, opts = account_fetcher_1.IGNORE_CACHE) {
const mintInfos = Array.from((await ctx.fetcher.getMintInfos(mints, opts)).values());

@@ -222,0 +222,0 @@ return mintInfos.reduce((acc, mintInfo, index) => {

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

wallet: wallet.publicKey,
}, account_fetcher_1.AVOID_REFRESH);
}, account_fetcher_1.PREFER_CACHE);
if (!!opts.onRouteEvaluation) {

@@ -47,0 +47,0 @@ opts.onRouteEvaluation(route, tx);

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

const quoteUpdates = buildQuoteUpdateRequests(tokenIn, tokenOut, paths, percents, amounts, hop, amountSpecifiedIsInput, quoteMap);
const quoteParams = await (0, batch_swap_quote_1.batchBuildSwapQuoteParams)(quoteUpdates.map((update) => update.request), common_sdk_1.AddressUtil.toPubKey(programId), cache, account_fetcher_1.AVOID_REFRESH);
const quoteParams = await (0, batch_swap_quote_1.batchBuildSwapQuoteParams)(quoteUpdates.map((update) => update.request), common_sdk_1.AddressUtil.toPubKey(programId), cache, account_fetcher_1.PREFER_CACHE);
populateQuoteMap(quoteUpdates, quoteParams, quoteMap);

@@ -32,0 +32,0 @@ }

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

wallet: this.ctx.wallet.publicKey,
}, account_fetcher_1.PREFER_REFRESH);
}, account_fetcher_1.IGNORE_CACHE);
return txBuilder;

@@ -64,3 +64,3 @@ }

// Load all pool and tick-array data into the fetcher cache.
async function prefetchRoutes(paths, programId, cache, opts = account_fetcher_1.AVOID_REFRESH) {
async function prefetchRoutes(paths, programId, cache, opts = account_fetcher_1.PREFER_CACHE) {
const poolSet = new Set();

@@ -74,3 +74,3 @@ for (let i = 0; i < paths.length; i++) {

const ps = Array.from(poolSet);
const allWps = (await cache.getPools(ps, opts));
const allWps = await cache.getPools(ps, opts);
const tickArrayAddresses = [];

@@ -77,0 +77,0 @@ for (const [key, wp] of allWps) {

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

* Supported parasable account names from the Whirlpool contract.
* @category Parsables
* @category Network
*/

@@ -16,0 +16,0 @@ export declare enum AccountName {

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

* Supported parasable account names from the Whirlpool contract.
* @category Parsables
* @category Network
*/

@@ -21,0 +21,0 @@ var AccountName;

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

static async buildPoolGraphWithFetch(pools, cache) {
const poolAccounts = await cache.getPools(pools, account_fetcher_1.AVOID_REFRESH);
const poolAccounts = await cache.getPools(pools, account_fetcher_1.PREFER_CACHE);
const poolTokenPairs = Array.from(poolAccounts.entries())

@@ -24,0 +24,0 @@ .map(([addr, pool]) => {

@@ -95,5 +95,3 @@ "use strict";

static async getTickArrays(tickCurrentIndex, tickSpacing, aToB, programId, whirlpoolAddress, cache, opts) {
const data = await this.getBatchTickArrays(programId, cache, [
{ tickCurrentIndex, tickSpacing, aToB, whirlpoolAddress },
], opts);
const data = await this.getBatchTickArrays(programId, cache, [{ tickCurrentIndex, tickSpacing, aToB, whirlpoolAddress }], opts);
return data[0];

@@ -100,0 +98,0 @@ }

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

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

"@coral-xyz/anchor": "~0.27.0",
"@orca-so/common-sdk": "^0.3.0-beta-3",
"@orca-so/common-sdk": "^0.3.0",
"@solana/spl-token": "^0.3.8",

@@ -13,0 +13,0 @@ "@solana/web3.js": "^1.75.0",

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