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

@saberhq/stableswap-sdk

Package Overview
Dependencies
Maintainers
2
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saberhq/stableswap-sdk - npm Package Compare versions

Comparing version 1.12.69 to 1.12.70

44

dist/cjs/stable-swap.d.ts
/// <reference types="node" />
import type { ProgramAccount } from "@saberhq/token-utils";
import type { Connection, TransactionInstruction } from "@solana/web3.js";

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

import type { StableSwapState } from "./state";
export declare class StableSwap {
export interface StableSwapInfo {
config: StableSwapConfig;
state: StableSwapState;
}
/**
* Swap token A for token B
* @param userSource
* @param poolSource
* @param poolDestination
* @param userDestination
* @param amountIn
* @param minimumAmountOut
*/
export declare function createSaberSwapInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.SwapInstruction, "userAuthority" | "userSource" | "userDestination" | "poolSource" | "poolDestination" | "amountIn" | "minimumAmountOut">): TransactionInstruction;
/**
* Deposit tokens into the pool.
*/
export declare function createSaberDepositInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.DepositInstruction, "userAuthority" | "sourceA" | "sourceB" | "poolTokenAccount" | "tokenAmountA" | "tokenAmountB" | "minimumPoolTokenAmount">): TransactionInstruction;
/**
* Withdraw tokens from the pool
*/
export declare function createSaberWithdrawInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.WithdrawInstruction, "userAuthority" | "userAccountA" | "userAccountB" | "sourceAccount" | "poolTokenAmount" | "minimumTokenA" | "minimumTokenB">): TransactionInstruction;
/**
* Withdraw tokens from the pool
*/
export declare function createSaberWithdrawOneInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.WithdrawOneInstruction, "userAuthority" | "baseTokenAccount" | "destinationAccount" | "sourceAccount" | "poolTokenAmount" | "minimumTokenAmount">): TransactionInstruction;
export declare class StableSwap implements StableSwapInfo {
readonly config: StableSwapConfig;
readonly state: StableSwapState;
/**
* Constructor for new StableSwap client object
* @param connection
* Constructor for new StableSwap client object.
* @param config

@@ -42,2 +68,14 @@ * @param state

/**
* Loads the swap object from a program account.
* @param data
* @returns
*/
static fromProgramAccount(data: ProgramAccount<StableSwapState>): Promise<StableSwap>;
/**
* Loads the swap object from a program account, with the swap authority loaded.
* @param data
* @returns
*/
static fromProgramAccountWithAuthority(data: ProgramAccount<StableSwapState>, authority: PublicKey): StableSwap;
/**
* Loads a StableSwap instance with data.

@@ -44,0 +82,0 @@ *

129

dist/cjs/stable-swap.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findSwapAuthorityKey = exports.StableSwap = void 0;
exports.findSwapAuthorityKey = exports.StableSwap = exports.createSaberWithdrawOneInstruction = exports.createSaberWithdrawInstruction = exports.createSaberDepositInstruction = exports.createSaberSwapInstruction = void 0;
const tslib_1 = require("tslib");

@@ -12,6 +12,69 @@ const token_utils_1 = require("@saberhq/token-utils");

const account_1 = require("./util/account");
/**
* Swap token A for token B
* @param userSource
* @param poolSource
* @param poolDestination
* @param userDestination
* @param amountIn
* @param minimumAmountOut
*/
function createSaberSwapInstruction({ config, state }, args) {
const adminDestination = args.poolDestination.equals(state.tokenA.reserve)
? state.tokenA.adminFeeAccount
: state.tokenB.adminFeeAccount;
return instructions.swapInstruction({
config: config,
...args,
adminDestination,
});
}
exports.createSaberSwapInstruction = createSaberSwapInstruction;
/**
* Deposit tokens into the pool.
*/
function createSaberDepositInstruction({ config, state }, args) {
return instructions.depositInstruction({
config: config,
tokenAccountA: state.tokenA.reserve,
tokenAccountB: state.tokenB.reserve,
poolTokenMint: state.poolTokenMint,
...args,
});
}
exports.createSaberDepositInstruction = createSaberDepositInstruction;
/**
* Withdraw tokens from the pool
*/
function createSaberWithdrawInstruction({ config, state }, args) {
return instructions.withdrawInstruction({
config: config,
poolMint: state.poolTokenMint,
tokenAccountA: state.tokenA.reserve,
tokenAccountB: state.tokenB.reserve,
adminFeeAccountA: state.tokenA.adminFeeAccount,
adminFeeAccountB: state.tokenB.adminFeeAccount,
...args,
});
}
exports.createSaberWithdrawInstruction = createSaberWithdrawInstruction;
/**
* Withdraw tokens from the pool
*/
function createSaberWithdrawOneInstruction({ config, state }, args) {
const [quoteTokenAccount, adminDestinationAccount] = args.baseTokenAccount.equals(state.tokenA.reserve)
? [state.tokenB.reserve, state.tokenA.adminFeeAccount]
: [state.tokenA.reserve, state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction({
config: config,
poolMint: state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
}
exports.createSaberWithdrawOneInstruction = createSaberWithdrawOneInstruction;
class StableSwap {
/**
* Constructor for new StableSwap client object
* @param connection
* Constructor for new StableSwap client object.
* @param config

@@ -55,2 +118,24 @@ * @param state

/**
* Loads the swap object from a program account.
* @param data
* @returns
*/
static async fromProgramAccount(data) {
const [authority] = await (0, exports.findSwapAuthorityKey)(data.publicKey);
return StableSwap.fromProgramAccountWithAuthority(data, authority);
}
/**
* Loads the swap object from a program account, with the swap authority loaded.
* @param data
* @returns
*/
static fromProgramAccountWithAuthority(data, authority) {
return new StableSwap({
swapAccount: data.publicKey,
swapProgramID: constants_1.SWAP_PROGRAM_ID,
tokenProgramID: token_utils_1.TOKEN_PROGRAM_ID,
authority,
}, data.account);
}
/**
* Loads a StableSwap instance with data.

@@ -91,10 +176,3 @@ *

swap(args) {
const adminDestination = args.poolDestination.equals(this.state.tokenA.reserve)
? this.state.tokenA.adminFeeAccount
: this.state.tokenB.adminFeeAccount;
return instructions.swapInstruction({
config: this.config,
...args,
adminDestination,
});
return createSaberSwapInstruction(this, args);
}

@@ -105,9 +183,3 @@ /**

deposit(args) {
return instructions.depositInstruction({
config: this.config,
tokenAccountA: this.state.tokenA.reserve,
tokenAccountB: this.state.tokenB.reserve,
poolTokenMint: this.state.poolTokenMint,
...args,
});
return createSaberDepositInstruction(this, args);
}

@@ -118,11 +190,3 @@ /**

withdraw(args) {
return instructions.withdrawInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
tokenAccountA: this.state.tokenA.reserve,
tokenAccountB: this.state.tokenB.reserve,
adminFeeAccountA: this.state.tokenA.adminFeeAccount,
adminFeeAccountB: this.state.tokenB.adminFeeAccount,
...args,
});
return createSaberWithdrawInstruction(this, args);
}

@@ -133,12 +197,3 @@ /**

withdrawOne(args) {
const [quoteTokenAccount, adminDestinationAccount] = args.baseTokenAccount.equals(this.state.tokenA.reserve)
? [this.state.tokenB.reserve, this.state.tokenA.adminFeeAccount]
: [this.state.tokenA.reserve, this.state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
return createSaberWithdrawOneInstruction(this, args);
}

@@ -145,0 +200,0 @@ }

/// <reference types="node" />
import type { ProgramAccount } from "@saberhq/token-utils";
import type { Connection, TransactionInstruction } from "@solana/web3.js";

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

import type { StableSwapState } from "./state";
export declare class StableSwap {
export interface StableSwapInfo {
config: StableSwapConfig;
state: StableSwapState;
}
/**
* Swap token A for token B
* @param userSource
* @param poolSource
* @param poolDestination
* @param userDestination
* @param amountIn
* @param minimumAmountOut
*/
export declare function createSaberSwapInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.SwapInstruction, "userAuthority" | "userSource" | "userDestination" | "poolSource" | "poolDestination" | "amountIn" | "minimumAmountOut">): TransactionInstruction;
/**
* Deposit tokens into the pool.
*/
export declare function createSaberDepositInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.DepositInstruction, "userAuthority" | "sourceA" | "sourceB" | "poolTokenAccount" | "tokenAmountA" | "tokenAmountB" | "minimumPoolTokenAmount">): TransactionInstruction;
/**
* Withdraw tokens from the pool
*/
export declare function createSaberWithdrawInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.WithdrawInstruction, "userAuthority" | "userAccountA" | "userAccountB" | "sourceAccount" | "poolTokenAmount" | "minimumTokenA" | "minimumTokenB">): TransactionInstruction;
/**
* Withdraw tokens from the pool
*/
export declare function createSaberWithdrawOneInstruction({ config, state }: StableSwapInfo, args: Pick<instructions.WithdrawOneInstruction, "userAuthority" | "baseTokenAccount" | "destinationAccount" | "sourceAccount" | "poolTokenAmount" | "minimumTokenAmount">): TransactionInstruction;
export declare class StableSwap implements StableSwapInfo {
readonly config: StableSwapConfig;
readonly state: StableSwapState;
/**
* Constructor for new StableSwap client object
* @param connection
* Constructor for new StableSwap client object.
* @param config

@@ -42,2 +68,14 @@ * @param state

/**
* Loads the swap object from a program account.
* @param data
* @returns
*/
static fromProgramAccount(data: ProgramAccount<StableSwapState>): Promise<StableSwap>;
/**
* Loads the swap object from a program account, with the swap authority loaded.
* @param data
* @returns
*/
static fromProgramAccountWithAuthority(data: ProgramAccount<StableSwapState>, authority: PublicKey): StableSwap;
/**
* Loads a StableSwap instance with data.

@@ -44,0 +82,0 @@ *

@@ -8,6 +8,65 @@ import { TOKEN_PROGRAM_ID } from "@saberhq/token-utils";

import { loadProgramAccount } from "./util/account";
/**
* Swap token A for token B
* @param userSource
* @param poolSource
* @param poolDestination
* @param userDestination
* @param amountIn
* @param minimumAmountOut
*/
export function createSaberSwapInstruction({ config, state }, args) {
const adminDestination = args.poolDestination.equals(state.tokenA.reserve)
? state.tokenA.adminFeeAccount
: state.tokenB.adminFeeAccount;
return instructions.swapInstruction({
config: config,
...args,
adminDestination,
});
}
/**
* Deposit tokens into the pool.
*/
export function createSaberDepositInstruction({ config, state }, args) {
return instructions.depositInstruction({
config: config,
tokenAccountA: state.tokenA.reserve,
tokenAccountB: state.tokenB.reserve,
poolTokenMint: state.poolTokenMint,
...args,
});
}
/**
* Withdraw tokens from the pool
*/
export function createSaberWithdrawInstruction({ config, state }, args) {
return instructions.withdrawInstruction({
config: config,
poolMint: state.poolTokenMint,
tokenAccountA: state.tokenA.reserve,
tokenAccountB: state.tokenB.reserve,
adminFeeAccountA: state.tokenA.adminFeeAccount,
adminFeeAccountB: state.tokenB.adminFeeAccount,
...args,
});
}
/**
* Withdraw tokens from the pool
*/
export function createSaberWithdrawOneInstruction({ config, state }, args) {
const [quoteTokenAccount, adminDestinationAccount] = args.baseTokenAccount.equals(state.tokenA.reserve)
? [state.tokenB.reserve, state.tokenA.adminFeeAccount]
: [state.tokenA.reserve, state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction({
config: config,
poolMint: state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
}
export class StableSwap {
/**
* Constructor for new StableSwap client object
* @param connection
* Constructor for new StableSwap client object.
* @param config

@@ -51,2 +110,24 @@ * @param state

/**
* Loads the swap object from a program account.
* @param data
* @returns
*/
static async fromProgramAccount(data) {
const [authority] = await findSwapAuthorityKey(data.publicKey);
return StableSwap.fromProgramAccountWithAuthority(data, authority);
}
/**
* Loads the swap object from a program account, with the swap authority loaded.
* @param data
* @returns
*/
static fromProgramAccountWithAuthority(data, authority) {
return new StableSwap({
swapAccount: data.publicKey,
swapProgramID: SWAP_PROGRAM_ID,
tokenProgramID: TOKEN_PROGRAM_ID,
authority,
}, data.account);
}
/**
* Loads a StableSwap instance with data.

@@ -87,10 +168,3 @@ *

swap(args) {
const adminDestination = args.poolDestination.equals(this.state.tokenA.reserve)
? this.state.tokenA.adminFeeAccount
: this.state.tokenB.adminFeeAccount;
return instructions.swapInstruction({
config: this.config,
...args,
adminDestination,
});
return createSaberSwapInstruction(this, args);
}

@@ -101,9 +175,3 @@ /**

deposit(args) {
return instructions.depositInstruction({
config: this.config,
tokenAccountA: this.state.tokenA.reserve,
tokenAccountB: this.state.tokenB.reserve,
poolTokenMint: this.state.poolTokenMint,
...args,
});
return createSaberDepositInstruction(this, args);
}

@@ -114,11 +182,3 @@ /**

withdraw(args) {
return instructions.withdrawInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
tokenAccountA: this.state.tokenA.reserve,
tokenAccountB: this.state.tokenB.reserve,
adminFeeAccountA: this.state.tokenA.adminFeeAccount,
adminFeeAccountB: this.state.tokenB.adminFeeAccount,
...args,
});
return createSaberWithdrawInstruction(this, args);
}

@@ -129,12 +189,3 @@ /**

withdrawOne(args) {
const [quoteTokenAccount, adminDestinationAccount] = args.baseTokenAccount.equals(this.state.tokenA.reserve)
? [this.state.tokenB.reserve, this.state.tokenA.adminFeeAccount]
: [this.state.tokenA.reserve, this.state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
return createSaberWithdrawOneInstruction(this, args);
}

@@ -141,0 +192,0 @@ }

@@ -13,3 +13,3 @@ {

"author": "Saber Team <team@saber.so>",
"version": "1.12.69",
"version": "1.12.70",
"main": "dist/cjs/index.js",

@@ -27,6 +27,6 @@ "module": "dist/esm/index.js",

"devDependencies": {
"@solana/web3.js": "^1.41.1",
"@solana/web3.js": "^1.41.3",
"@types/bn.js": "^5.1.0",
"@types/lodash.mapvalues": "^4.6.7",
"@types/node": "^17.0.29",
"@types/node": "^17.0.30",
"bn.js": "^5.2.0",

@@ -41,4 +41,4 @@ "jsbi": "^4.3.0"

"dependencies": {
"@saberhq/solana-contrib": "^1.12.69",
"@saberhq/token-utils": "^1.12.69",
"@saberhq/solana-contrib": "^1.12.70",
"@saberhq/token-utils": "^1.12.70",
"@solana/buffer-layout": "^4.0.0",

@@ -56,3 +56,3 @@ "lodash.mapvalues": "^4.6.0",

},
"gitHead": "46d93812ce37f38c1ceb217dd7ec8eb462d17007"
"gitHead": "576566ae9814f24e994ac19e2aaa522ebf98f099"
}

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

import type { ProgramAccount } from "@saberhq/token-utils";
import { TOKEN_PROGRAM_ID } from "@saberhq/token-utils";

@@ -14,6 +15,123 @@ import type { Connection, TransactionInstruction } from "@solana/web3.js";

export class StableSwap {
export interface StableSwapInfo {
config: StableSwapConfig;
state: StableSwapState;
}
/**
* Swap token A for token B
* @param userSource
* @param poolSource
* @param poolDestination
* @param userDestination
* @param amountIn
* @param minimumAmountOut
*/
export function createSaberSwapInstruction(
{ config, state }: StableSwapInfo,
args: Pick<
instructions.SwapInstruction,
| "userAuthority"
| "userSource"
| "userDestination"
| "poolSource"
| "poolDestination"
| "amountIn"
| "minimumAmountOut"
>
): TransactionInstruction {
const adminDestination = args.poolDestination.equals(state.tokenA.reserve)
? state.tokenA.adminFeeAccount
: state.tokenB.adminFeeAccount;
return instructions.swapInstruction({
config: config,
...args,
adminDestination,
});
}
/**
* Deposit tokens into the pool.
*/
export function createSaberDepositInstruction(
{ config, state }: StableSwapInfo,
args: Pick<
instructions.DepositInstruction,
| "userAuthority"
| "sourceA"
| "sourceB"
| "poolTokenAccount"
| "tokenAmountA"
| "tokenAmountB"
| "minimumPoolTokenAmount"
>
): TransactionInstruction {
return instructions.depositInstruction({
config: config,
tokenAccountA: state.tokenA.reserve,
tokenAccountB: state.tokenB.reserve,
poolTokenMint: state.poolTokenMint,
...args,
});
}
/**
* Withdraw tokens from the pool
*/
export function createSaberWithdrawInstruction(
{ config, state }: StableSwapInfo,
args: Pick<
instructions.WithdrawInstruction,
| "userAuthority"
| "userAccountA"
| "userAccountB"
| "sourceAccount"
| "poolTokenAmount"
| "minimumTokenA"
| "minimumTokenB"
>
): TransactionInstruction {
return instructions.withdrawInstruction({
config: config,
poolMint: state.poolTokenMint,
tokenAccountA: state.tokenA.reserve,
tokenAccountB: state.tokenB.reserve,
adminFeeAccountA: state.tokenA.adminFeeAccount,
adminFeeAccountB: state.tokenB.adminFeeAccount,
...args,
});
}
/**
* Withdraw tokens from the pool
*/
export function createSaberWithdrawOneInstruction(
{ config, state }: StableSwapInfo,
args: Pick<
instructions.WithdrawOneInstruction,
| "userAuthority"
| "baseTokenAccount"
| "destinationAccount"
| "sourceAccount"
| "poolTokenAmount"
| "minimumTokenAmount"
>
): TransactionInstruction {
const [quoteTokenAccount, adminDestinationAccount] =
args.baseTokenAccount.equals(state.tokenA.reserve)
? [state.tokenB.reserve, state.tokenA.adminFeeAccount]
: [state.tokenA.reserve, state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction({
config: config,
poolMint: state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
}
export class StableSwap implements StableSwapInfo {
/**
* Constructor for new StableSwap client object
* @param connection
* Constructor for new StableSwap client object.
* @param config

@@ -76,2 +194,34 @@ * @param state

/**
* Loads the swap object from a program account.
* @param data
* @returns
*/
static async fromProgramAccount(
data: ProgramAccount<StableSwapState>
): Promise<StableSwap> {
const [authority] = await findSwapAuthorityKey(data.publicKey);
return StableSwap.fromProgramAccountWithAuthority(data, authority);
}
/**
* Loads the swap object from a program account, with the swap authority loaded.
* @param data
* @returns
*/
static fromProgramAccountWithAuthority(
data: ProgramAccount<StableSwapState>,
authority: PublicKey
): StableSwap {
return new StableSwap(
{
swapAccount: data.publicKey,
swapProgramID: SWAP_PROGRAM_ID,
tokenProgramID: TOKEN_PROGRAM_ID,
authority,
},
data.account
);
}
/**
* Loads a StableSwap instance with data.

@@ -131,12 +281,3 @@ *

): TransactionInstruction {
const adminDestination = args.poolDestination.equals(
this.state.tokenA.reserve
)
? this.state.tokenA.adminFeeAccount
: this.state.tokenB.adminFeeAccount;
return instructions.swapInstruction({
config: this.config,
...args,
adminDestination,
});
return createSaberSwapInstruction(this, args);
}

@@ -159,9 +300,3 @@

): TransactionInstruction {
return instructions.depositInstruction({
config: this.config,
tokenAccountA: this.state.tokenA.reserve,
tokenAccountB: this.state.tokenB.reserve,
poolTokenMint: this.state.poolTokenMint,
...args,
});
return createSaberDepositInstruction(this, args);
}

@@ -184,11 +319,3 @@

): TransactionInstruction {
return instructions.withdrawInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
tokenAccountA: this.state.tokenA.reserve,
tokenAccountB: this.state.tokenB.reserve,
adminFeeAccountA: this.state.tokenA.adminFeeAccount,
adminFeeAccountB: this.state.tokenB.adminFeeAccount,
...args,
});
return createSaberWithdrawInstruction(this, args);
}

@@ -210,14 +337,3 @@

): TransactionInstruction {
const [quoteTokenAccount, adminDestinationAccount] =
args.baseTokenAccount.equals(this.state.tokenA.reserve)
? [this.state.tokenB.reserve, this.state.tokenA.adminFeeAccount]
: [this.state.tokenA.reserve, this.state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
return createSaberWithdrawOneInstruction(this, args);
}

@@ -224,0 +340,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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