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.4.0 to 0.5.0

18

dist/context.d.ts

@@ -1,5 +0,6 @@

import { PublicKey, Connection, ConfirmOptions } from "@solana/web3.js";
import { Provider, Program } from "@project-serum/anchor";
import { AnchorProvider, Program } from "@project-serum/anchor";
import { Wallet } from "@project-serum/anchor/dist/cjs/provider";
import { ConfirmOptions, Connection, PublicKey } from "@solana/web3.js";
import { Whirlpool } from "./artifacts/whirlpool";
import { Wallet } from "@project-serum/anchor/dist/cjs/provider";
import { AccountFetcher } from "./network/public";
/**

@@ -13,7 +14,8 @@ * @category Core

readonly program: Program<Whirlpool>;
readonly provider: Provider;
static from(connection: Connection, wallet: Wallet, programId: PublicKey, opts?: ConfirmOptions): WhirlpoolContext;
static fromWorkspace(provider: Provider, program: Program, opts?: ConfirmOptions): WhirlpoolContext;
static withProvider(provider: Provider, programId: PublicKey, opts?: ConfirmOptions): WhirlpoolContext;
constructor(provider: Provider, program: Program, opts: ConfirmOptions);
readonly provider: AnchorProvider;
readonly fetcher: AccountFetcher;
static from(connection: Connection, wallet: Wallet, programId: PublicKey, fetcher?: AccountFetcher, opts?: ConfirmOptions): WhirlpoolContext;
static fromWorkspace(provider: AnchorProvider, program: Program, fetcher?: AccountFetcher, opts?: ConfirmOptions): WhirlpoolContext;
static withProvider(provider: AnchorProvider, programId: PublicKey, fetcher?: AccountFetcher, opts?: ConfirmOptions): WhirlpoolContext;
constructor(provider: AnchorProvider, wallet: Wallet, program: Program, fetcher: AccountFetcher, opts: ConfirmOptions);
}

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

const whirlpool_json_1 = __importDefault(require("./artifacts/whirlpool.json"));
const public_1 = require("./network/public");
/**

@@ -14,5 +15,5 @@ * @category Core

class WhirlpoolContext {
constructor(provider, program, opts) {
constructor(provider, wallet, program, fetcher, opts) {
this.connection = provider.connection;
this.wallet = provider.wallet;
this.wallet = wallet;
this.opts = opts;

@@ -22,16 +23,17 @@ // It's a hack but it works on Anchor workspace *shrug*

this.provider = provider;
this.fetcher = fetcher;
}
static from(connection, wallet, programId, opts = anchor_1.Provider.defaultOptions()) {
const provider = new anchor_1.Provider(connection, wallet, opts);
const program = new anchor_1.Program(whirlpool_json_1.default, programId, provider);
return new WhirlpoolContext(provider, program, opts);
static from(connection, wallet, programId, fetcher = new public_1.AccountFetcher(connection), opts = anchor_1.AnchorProvider.defaultOptions()) {
const anchorProvider = new anchor_1.AnchorProvider(connection, wallet, opts);
const program = new anchor_1.Program(whirlpool_json_1.default, programId, anchorProvider);
return new WhirlpoolContext(anchorProvider, anchorProvider.wallet, program, fetcher, opts);
}
static fromWorkspace(provider, program, opts = anchor_1.Provider.defaultOptions()) {
return new WhirlpoolContext(provider, program, opts);
static fromWorkspace(provider, program, fetcher = new public_1.AccountFetcher(provider.connection), opts = anchor_1.AnchorProvider.defaultOptions()) {
return new WhirlpoolContext(provider, provider.wallet, program, fetcher, opts);
}
static withProvider(provider, programId, opts = anchor_1.Provider.defaultOptions()) {
static withProvider(provider, programId, fetcher = new public_1.AccountFetcher(provider.connection), opts = anchor_1.AnchorProvider.defaultOptions()) {
const program = new anchor_1.Program(whirlpool_json_1.default, programId, provider);
return new WhirlpoolContext(provider, program, opts);
return new WhirlpoolContext(provider, provider.wallet, program, fetcher, opts);
}
}
exports.WhirlpoolContext = WhirlpoolContext;

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

}
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
let tokenOwnerAccountA;

@@ -100,3 +100,3 @@ let tokenOwnerAccountB;

}
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
let tokenOwnerAccountA;

@@ -103,0 +103,0 @@ let tokenOwnerAccountB;

@@ -7,4 +7,4 @@ import { Address } from "@project-serum/anchor";

readonly ctx: WhirlpoolContext;
readonly fetcher: AccountFetcher;
constructor(ctx: WhirlpoolContext, fetcher: AccountFetcher);
constructor(ctx: WhirlpoolContext);
getContext(): WhirlpoolContext;
getFetcher(): AccountFetcher;

@@ -11,0 +11,0 @@ getPool(poolAddress: Address, refresh?: boolean): Promise<Whirlpool>;

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

class WhirlpoolClientImpl {
constructor(ctx, fetcher) {
constructor(ctx) {
this.ctx = ctx;
this.fetcher = fetcher;
}
getContext() {
return this.ctx;
}
getFetcher() {
return this.fetcher;
return this.ctx.fetcher;
}
getPool(poolAddress, refresh = false) {
return __awaiter(this, void 0, void 0, function* () {
const account = yield this.fetcher.getPool(poolAddress, refresh);
const account = yield this.ctx.fetcher.getPool(poolAddress, refresh);
if (!account) {
throw new Error(`Unable to fetch Whirlpool at address at ${poolAddress}`);
}
const tokenInfos = yield getTokenInfos(this.fetcher, account, false);
return new whirlpool_impl_1.WhirlpoolImpl(this.ctx, this.fetcher, common_sdk_1.AddressUtil.toPubKey(poolAddress), tokenInfos[0], tokenInfos[1], account);
const tokenInfos = yield getTokenInfos(this.ctx.fetcher, account, false);
return new whirlpool_impl_1.WhirlpoolImpl(this.ctx, this.ctx.fetcher, common_sdk_1.AddressUtil.toPubKey(poolAddress), tokenInfos[0], tokenInfos[1], account);
});

@@ -37,7 +39,7 @@ }

return __awaiter(this, void 0, void 0, function* () {
const account = yield this.fetcher.getPosition(positionAddress, refresh);
const account = yield this.ctx.fetcher.getPosition(positionAddress, refresh);
if (!account) {
throw new Error(`Unable to fetch Position at address at ${positionAddress}`);
}
return new position_impl_1.PositionImpl(this.ctx, this.fetcher, common_sdk_1.AddressUtil.toPubKey(positionAddress), account);
return new position_impl_1.PositionImpl(this.ctx, this.ctx.fetcher, common_sdk_1.AddressUtil.toPubKey(positionAddress), account);
});

@@ -44,0 +46,0 @@ }

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

}
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
initTickArrayStartPdas.forEach((initTickArrayInfo) => {

@@ -133,3 +133,3 @@ txBuilder.addInstruction((0, instructions_1.initTickArrayIx)(this.ctx.program, {

const positionTokenAccountAddress = yield (0, common_sdk_1.deriveATA)(wallet, positionMintKeypair.publicKey);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
const positionIx = (withMetadata ? instructions_1.openPositionWithMetadataIx : instructions_1.openPositionIx)(this.ctx.program, {

@@ -190,3 +190,3 @@ funder,

const positionTokenAccount = yield (0, common_sdk_1.deriveATA)(positionWallet, position.positionMint);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
const resolvedAssociatedTokenAddresses = {};

@@ -250,3 +250,3 @@ const [ataA, ataB] = yield (0, common_sdk_1.resolveOrCreateATAs)(this.ctx.connection, destinationWallet, [{ tokenMint: whirlpool.tokenMintA }, { tokenMint: whirlpool.tokenMintB }], () => this.fetcher.getAccountRentExempt(), payerKey);

const whirlpool = this.data;
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider);
const txBuilder = new common_sdk_1.TransactionBuilder(this.ctx.provider.connection, this.ctx.provider.wallet);
const [ataA, ataB] = yield (0, common_sdk_1.resolveOrCreateATAs)(this.ctx.connection, wallet, [

@@ -253,0 +253,0 @@ { tokenMint: whirlpool.tokenMintA, wrappedSolAmountIn: aToB ? amount : common_sdk_1.ZERO },

@@ -210,5 +210,5 @@ "use strict";

}
const WhirlpoolCoder = new anchor_1.Coder(WhirlpoolIDL);
const WhirlpoolCoder = new anchor_1.BorshAccountsCoder(WhirlpoolIDL);
function parseAnchorAccount(accountName, data) {
const discriminator = anchor_1.AccountsCoder.accountDiscriminator(accountName);
const discriminator = anchor_1.BorshAccountsCoder.accountDiscriminator(accountName);
if (discriminator.compare(data.slice(0, 8))) {

@@ -219,3 +219,3 @@ console.error("incorrect account name during parsing");

try {
return WhirlpoolCoder.accounts.decode(accountName, data);
return WhirlpoolCoder.decode(accountName, data);
}

@@ -222,0 +222,0 @@ catch (_e) {

@@ -6,4 +6,4 @@ "use strict";

function toTx(ctx, ix) {
return new common_sdk_1.TransactionBuilder(ctx.provider).addInstruction(ix);
return new common_sdk_1.TransactionBuilder(ctx.provider.connection, ctx.provider.wallet).addInstruction(ix);
}
exports.toTx = toTx;
import { Percentage, 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 { WhirlpoolData, PositionData, IncreaseLiquidityInput, DecreaseLiquidityInput } from "./types/public";
import { SwapQuote } from "./quotes/public";
import { DecreaseLiquidityInput, IncreaseLiquidityInput, PositionData, WhirlpoolData } from "./types/public";
import { TokenInfo } from "./types/public/client-types";
import { PublicKey } from "@solana/web3.js";
import { SwapQuote } from "./quotes/public";
/**

@@ -16,2 +16,7 @@ * Helper class to help interact with Whirlpool Accounts with a simpler interface.

/**
* Get this client's WhirlpoolContext object
* @return a WhirlpoolContext object
*/
getContext: () => WhirlpoolContext;
/**
* Get an AccountFetcher to fetch Whirlpool accounts

@@ -39,6 +44,5 @@ * @return an AccountFetcher instance

* @param ctx - WhirlpoolContext object
* @param fetcher - AccountFetcher instance to help fetch data with.
* @returns a WhirlpoolClient instance to help with interacting with Whirlpools accounts.
*/
export declare function buildWhirlpoolClient(ctx: WhirlpoolContext, fetcher: AccountFetcher): WhirlpoolClient;
export declare function buildWhirlpoolClient(ctx: WhirlpoolContext): WhirlpoolClient;
/**

@@ -45,0 +49,0 @@ * Helper class to interact with a Whirlpool account and build complex transactions.

@@ -10,8 +10,7 @@ "use strict";

* @param ctx - WhirlpoolContext object
* @param fetcher - AccountFetcher instance to help fetch data with.
* @returns a WhirlpoolClient instance to help with interacting with Whirlpools accounts.
*/
function buildWhirlpoolClient(ctx, fetcher) {
return new whirlpool_client_impl_1.WhirlpoolClientImpl(ctx, fetcher);
function buildWhirlpoolClient(ctx) {
return new whirlpool_client_impl_1.WhirlpoolClientImpl(ctx);
}
exports.buildWhirlpoolClient = buildWhirlpoolClient;
{
"name": "@orca-so/whirlpools-sdk",
"version": "0.4.0",
"version": "0.5.0",
"description": "Typescript SDK to interact with Orca's Whirlpool program.",

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

"@metaplex-foundation/mpl-token-metadata": "1.2.5",
"@orca-so/common-sdk": "^0.0.7",
"@project-serum/anchor": "^0.20.1",
"@orca-so/common-sdk": "~0.1.0",
"@project-serum/anchor": "~0.25.0",
"@solana/spl-token": "^0.1.8",

@@ -14,0 +14,0 @@ "decimal.js": "^10.3.1",

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