Huge News!Announcing our $40M Series B led by Abstract Ventures.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.62 to 1.12.63

2

dist/cjs/calculator/price.js

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

// or at most, $1
const inputAmountNum = Math.max(10000, Math.min(Math.pow(10, reserve0.token.decimals), Math.floor(parseInt(reserve0.toU64().div(new bn_js_1.default(100)).toString()))));
const inputAmountNum = Math.max(10000, Math.min(10 ** reserve0.token.decimals, Math.floor(parseInt(reserve0.toU64().div(new bn_js_1.default(100)).toString()))));
const inputAmount = new token_utils_1.TokenAmount(reserve0.token, inputAmountNum);

@@ -23,0 +23,0 @@ const outputAmount = (0, __1.calculateEstimatedSwapOutputAmount)(exchangeInfo, inputAmount);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadExchangeInfoFromSwapAccount = exports.makeExchange = exports.loadExchangeInfo = exports.makeExchangeInfo = void 0;
const tslib_1 = require("tslib");
const token_utils_1 = require("@saberhq/token-utils");

@@ -45,9 +44,9 @@ const constants_1 = require("../constants");

*/
const loadExchangeInfo = (connection, exchange, swap) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const loadExchangeInfo = async (connection, exchange, swap) => {
if (!exchange.programID.equals(swap.config.swapProgramID)) {
throw new Error("Swap program id mismatch");
}
const reserveA = yield (0, account_1.loadProgramAccount)(connection, swap.state.tokenA.reserve, swap.config.tokenProgramID);
const reserveB = yield (0, account_1.loadProgramAccount)(connection, swap.state.tokenB.reserve, swap.config.tokenProgramID);
const poolMint = yield (0, account_1.loadProgramAccount)(connection, swap.state.poolTokenMint, swap.config.tokenProgramID);
const reserveA = await (0, account_1.loadProgramAccount)(connection, swap.state.tokenA.reserve, swap.config.tokenProgramID);
const reserveB = await (0, account_1.loadProgramAccount)(connection, swap.state.tokenB.reserve, swap.config.tokenProgramID);
const poolMint = await (0, account_1.loadProgramAccount)(connection, swap.state.poolTokenMint, swap.config.tokenProgramID);
return (0, exports.makeExchangeInfo)({

@@ -62,3 +61,3 @@ swap,

});
});
};
exports.loadExchangeInfo = loadExchangeInfo;

@@ -97,10 +96,10 @@ /**

*/
const loadExchangeInfoFromSwapAccount = (connection, swapAccount, tokenA = undefined, tokenB = undefined) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const loadExchangeInfoFromSwapAccount = async (connection, swapAccount, tokenA = undefined, tokenB = undefined) => {
var _a, _b;
const stableSwap = yield stable_swap_1.StableSwap.load(connection, swapAccount);
const theTokenA = tokenA !== null && tokenA !== void 0 ? tokenA : (_a = (yield token_utils_1.Token.load(connection, stableSwap.state.tokenA.mint))) === null || _a === void 0 ? void 0 : _a.info;
const stableSwap = await stable_swap_1.StableSwap.load(connection, swapAccount);
const theTokenA = tokenA !== null && tokenA !== void 0 ? tokenA : (_a = (await token_utils_1.Token.load(connection, stableSwap.state.tokenA.mint))) === null || _a === void 0 ? void 0 : _a.info;
if (!theTokenA) {
throw new Error(`Token ${stableSwap.state.tokenA.mint.toString()} not found`);
}
const theTokenB = tokenB !== null && tokenB !== void 0 ? tokenB : (_b = (yield token_utils_1.Token.load(connection, stableSwap.state.tokenB.mint))) === null || _b === void 0 ? void 0 : _b.info;
const theTokenB = tokenB !== null && tokenB !== void 0 ? tokenB : (_b = (await token_utils_1.Token.load(connection, stableSwap.state.tokenB.mint))) === null || _b === void 0 ? void 0 : _b.info;
if (!theTokenB) {

@@ -118,5 +117,5 @@ throw new Error(`Token ${stableSwap.state.tokenB.mint.toString()} not found`);

}
return yield (0, exports.loadExchangeInfo)(connection, exchange, stableSwap);
});
return await (0, exports.loadExchangeInfo)(connection, exchange, stableSwap);
};
exports.loadExchangeInfoFromSwapAccount = loadExchangeInfoFromSwapAccount;
//# sourceMappingURL=exchange.js.map

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

.filter(([, v]) => !!v)
.reduce((acc, [k, v]) => (Object.assign(Object.assign({}, acc), { [k]: v })), {});
.reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {});
};

@@ -19,0 +19,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withdrawOneInstruction = exports.withdrawInstruction = exports.depositInstruction = exports.swapInstruction = exports.initializeSwapInstruction = exports.initializeSwapInstructionRaw = exports.StableSwapInstruction = void 0;
const tslib_1 = require("tslib");
const state_1 = require("../state");

@@ -48,5 +47,4 @@ const common_1 = require("./common");

exports.initializeSwapInstructionRaw = initializeSwapInstructionRaw;
const initializeSwapInstruction = (_a) => {
var { fees = state_1.ZERO_FEES } = _a, args = tslib_1.__rest(_a, ["fees"]);
return (0, exports.initializeSwapInstructionRaw)(Object.assign(Object.assign({}, args), { fees: (0, state_1.encodeFees)(fees) }));
const initializeSwapInstruction = ({ fees = state_1.ZERO_FEES, ...args }) => {
return (0, exports.initializeSwapInstructionRaw)({ ...args, fees: (0, state_1.encodeFees)(fees) });
};

@@ -53,0 +51,0 @@ exports.initializeSwapInstruction = initializeSwapInstruction;

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

*/
static getMinBalanceRentForExemptStableSwap(connection) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return yield connection.getMinimumBalanceForRentExemption(layout_1.StableSwapLayout.span);
});
static async getMinBalanceRentForExemptStableSwap(connection) {
return await connection.getMinimumBalanceForRentExemption(layout_1.StableSwapLayout.span);
}

@@ -41,8 +39,6 @@ /**

*/
static load(connection, swapAccount, programID = constants_1.SWAP_PROGRAM_ID) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const data = yield (0, account_1.loadProgramAccount)(connection, swapAccount, programID);
const [authority] = yield (0, exports.findSwapAuthorityKey)(swapAccount, programID);
return StableSwap.loadWithData(swapAccount, data, authority, programID);
});
static async load(connection, swapAccount, programID = constants_1.SWAP_PROGRAM_ID) {
const data = await (0, account_1.loadProgramAccount)(connection, swapAccount, programID);
const [authority] = await (0, exports.findSwapAuthorityKey)(swapAccount, programID);
return StableSwap.loadWithData(swapAccount, data, authority, programID);
}

@@ -56,6 +52,4 @@ /**

*/
static loadFromExchange(connection, exchange) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return StableSwap.load(connection, exchange.swapAccount, exchange.programID);
});
static async loadFromExchange(connection, exchange) {
return StableSwap.load(connection, exchange.swapAccount, exchange.programID);
}

@@ -101,3 +95,7 @@ /**

: this.state.tokenB.adminFeeAccount;
return instructions.swapInstruction(Object.assign(Object.assign({ config: this.config }, args), { adminDestination }));
return instructions.swapInstruction({
config: this.config,
...args,
adminDestination,
});
}

@@ -108,3 +106,9 @@ /**

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

@@ -115,3 +119,11 @@ /**

withdraw(args) {
return instructions.withdrawInstruction(Object.assign({ 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 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,
});
}

@@ -125,4 +137,9 @@ /**

: [this.state.tokenA.reserve, this.state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction(Object.assign({ config: this.config, poolMint: this.state.poolTokenMint, quoteTokenAccount,
adminDestinationAccount }, args));
return instructions.withdrawOneInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
}

@@ -129,0 +146,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadProgramAccount = void 0;
const tslib_1 = require("tslib");
/**

@@ -12,4 +11,4 @@ * Loads the account info of an account owned by a program.

*/
const loadProgramAccount = (connection, address, programId) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const accountInfo = yield connection.getAccountInfo(address);
const loadProgramAccount = async (connection, address, programId) => {
const accountInfo = await connection.getAccountInfo(address);
if (accountInfo === null) {

@@ -22,4 +21,4 @@ throw new Error("Failed to find account");

return Buffer.from(accountInfo.data);
});
};
exports.loadProgramAccount = loadProgramAccount;
//# sourceMappingURL=account.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createInitializeNewSwapTx = exports.deployNewSwap = exports.createInitializeStableSwapInstructionsRaw = exports.createInitializeStableSwapInstructions = exports.loadSwapFromInitializeArgs = exports.initializeStableSwap = void 0;
const tslib_1 = require("tslib");
const solana_contrib_1 = require("@saberhq/solana-contrib");

@@ -21,7 +20,7 @@ const token_utils_1 = require("@saberhq/token-utils");

*/
const initializeStableSwap = (provider, stableSwapAccount, initializeSwapInstruction) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const initializeStableSwap = async (provider, stableSwapAccount, initializeSwapInstruction) => {
if (!stableSwapAccount.publicKey.equals(initializeSwapInstruction.config.swapAccount)) {
throw new Error("stable swap public key");
}
const { instructions } = yield (0, exports.createInitializeStableSwapInstructionsRaw)({
const { instructions } = await (0, exports.createInitializeStableSwapInstructionsRaw)({
provider,

@@ -32,6 +31,6 @@ initializeSwapInstruction,

console.log("createAccount and InitializeSwap");
const txSig = (yield tx.confirm()).signature;
const txSig = (await tx.confirm()).signature;
console.log(`TxSig: ${txSig}`);
return (0, exports.loadSwapFromInitializeArgs)(initializeSwapInstruction);
});
};
exports.initializeStableSwap = initializeStableSwap;

@@ -72,3 +71,3 @@ /**

*/
const createInitializeStableSwapInstructions = ({ provider, swapProgramID = constants_1.SWAP_PROGRAM_ID, adminAccount, tokenAMint, tokenBMint, ampFactor, fees, initialLiquidityProvider = adminAccount, useAssociatedAccountForInitialLP, swapAccountSigner = web3_js_1.Keypair.generate(), poolTokenMintSigner = web3_js_1.Keypair.generate(), seedPoolAccounts, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const createInitializeStableSwapInstructions = async ({ provider, swapProgramID = constants_1.SWAP_PROGRAM_ID, adminAccount, tokenAMint, tokenBMint, ampFactor, fees, initialLiquidityProvider = adminAccount, useAssociatedAccountForInitialLP, swapAccountSigner = web3_js_1.Keypair.generate(), poolTokenMintSigner = web3_js_1.Keypair.generate(), seedPoolAccounts, }) => {
const instructions = {

@@ -86,7 +85,7 @@ createLPTokenMint: new solana_contrib_1.TransactionEnvelope(provider, []),

// Create authority and nonce
const [authority, nonce] = yield (0, stable_swap_1.findSwapAuthorityKey)(swapAccount, swapProgramID);
const [authority, nonce] = await (0, stable_swap_1.findSwapAuthorityKey)(swapAccount, swapProgramID);
// Create LP token mint
const { decimals } = yield new token_utils_1.SPLToken(provider.connection, tokenAMint, token_utils_1.TOKEN_PROGRAM_ID, web3_js_1.Keypair.generate()).getMintInfo();
const mintBalanceNeeded = yield token_utils_1.SPLToken.getMinBalanceRentForExemptMint(provider.connection);
instructions.createLPTokenMint = yield (0, token_utils_1.createInitMintInstructions)({
const { decimals } = await new token_utils_1.SPLToken(provider.connection, tokenAMint, token_utils_1.TOKEN_PROGRAM_ID, web3_js_1.Keypair.generate()).getMintInfo();
const mintBalanceNeeded = await token_utils_1.SPLToken.getMinBalanceRentForExemptMint(provider.connection);
instructions.createLPTokenMint = await (0, token_utils_1.createInitMintInstructions)({
provider,

@@ -101,3 +100,3 @@ mintKP: poolTokenMintSigner,

if (useAssociatedAccountForInitialLP) {
const lpAccount = yield (0, token_utils_1.getOrCreateATA)({
const lpAccount = await (0, token_utils_1.getOrCreateATA)({
provider,

@@ -114,3 +113,3 @@ mint: poolTokenMint,

else {
const { key: unassociatedInitialLPAccount, tx: initialLPInstructions } = yield (0, token_utils_1.createTokenAccount)({
const { key: unassociatedInitialLPAccount, tx: initialLPInstructions } = await (0, token_utils_1.createTokenAccount)({
provider,

@@ -125,3 +124,3 @@ mint: poolTokenMint,

// Create Swap Token A account
const { info: tokenA, instructions: tokenAInstructions } = yield initializeSwapTokenInfo({
const { info: tokenA, instructions: tokenAInstructions } = await initializeSwapTokenInfo({
provider,

@@ -134,3 +133,3 @@ mint: tokenAMint,

// Create Swap Token B account
const { info: tokenB, instructions: tokenBInstructions } = yield initializeSwapTokenInfo({
const { info: tokenB, instructions: tokenBInstructions } = await initializeSwapTokenInfo({
provider,

@@ -166,3 +165,3 @@ mint: tokenBMint,

};
const { balanceNeeded: swapBalanceNeeded, instructions: initializeStableSwapInstructions, } = yield (0, exports.createInitializeStableSwapInstructionsRaw)({
const { balanceNeeded: swapBalanceNeeded, instructions: initializeStableSwapInstructions, } = await (0, exports.createInitializeStableSwapInstructionsRaw)({
provider,

@@ -180,7 +179,7 @@ initializeSwapInstruction,

};
});
};
exports.createInitializeStableSwapInstructions = createInitializeStableSwapInstructions;
const initializeSwapTokenInfo = ({ provider, mint, authority, admin, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const initializeSwapTokenInfo = async ({ provider, mint, authority, admin, }) => {
// Create Swap Token Account
const { key: tokenAccount, tx: createSwapTokenAccountInstructions } = yield (0, token_utils_1.createTokenAccount)({
const { key: tokenAccount, tx: createSwapTokenAccountInstructions } = await (0, token_utils_1.createTokenAccount)({
provider,

@@ -192,3 +191,3 @@ mint,

// Create Admin Fee Account
const { key: adminFeeAccount, tx: createAdminFeeAccountInstructions } = yield (0, token_utils_1.createTokenAccount)({
const { key: adminFeeAccount, tx: createAdminFeeAccountInstructions } = await (0, token_utils_1.createTokenAccount)({
provider,

@@ -207,3 +206,3 @@ mint,

};
});
};
/**

@@ -216,5 +215,5 @@ * Creates an unsigned InitializeSwap transaction.

*/
const createInitializeStableSwapInstructionsRaw = ({ provider, initializeSwapInstruction, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const createInitializeStableSwapInstructionsRaw = async ({ provider, initializeSwapInstruction, }) => {
// Allocate memory for the account
const balanceNeeded = yield stable_swap_1.StableSwap.getMinBalanceRentForExemptStableSwap(provider.connection);
const balanceNeeded = await stable_swap_1.StableSwap.getMinBalanceRentForExemptStableSwap(provider.connection);
return {

@@ -233,3 +232,3 @@ balanceNeeded,

};
});
};
exports.createInitializeStableSwapInstructionsRaw = createInitializeStableSwapInstructionsRaw;

@@ -239,24 +238,26 @@ /**

*/
const deployNewSwap = (_a) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var { enableLogging = false } = _a, args = tslib_1.__rest(_a, ["enableLogging"]);
const result = yield (0, exports.createInitializeNewSwapTx)(args);
const deployNewSwap = async ({ enableLogging = false, ...args }) => {
const result = await (0, exports.createInitializeNewSwapTx)(args);
const { txs } = result;
const { signature: setupAccounts1 } = yield txs.setupAccounts1.confirm();
const { signature: setupAccounts1 } = await txs.setupAccounts1.confirm();
if (enableLogging) {
console.log(`Set up accounts pt 1: ${setupAccounts1}`);
}
const { signature: setupAccounts2 } = yield txs.setupAccounts2.confirm();
const { signature: setupAccounts2 } = await txs.setupAccounts2.confirm();
if (enableLogging) {
console.log(`Set up accounts pt 2: ${setupAccounts2}`);
}
const { signature: initializeSwap } = yield txs.initializeSwap.confirm();
const { signature: initializeSwap } = await txs.initializeSwap.confirm();
if (enableLogging) {
console.log(`Initialize swap: ${initializeSwap}`);
}
return Object.assign(Object.assign({}, result), { txSigs: {
return {
...result,
txSigs: {
setupAccounts1,
setupAccounts2,
initializeSwap,
} });
});
},
};
};
exports.deployNewSwap = deployNewSwap;

@@ -268,5 +269,7 @@ /**

*/
const createInitializeNewSwapTx = (args) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const createInitializeNewSwapTx = async (args) => {
const { provider } = args;
const { instructions, initializeArgs } = yield (0, exports.createInitializeStableSwapInstructions)(Object.assign({}, args));
const { instructions, initializeArgs } = await (0, exports.createInitializeStableSwapInstructions)({
...args,
});
const setupAccounts1 = [

@@ -297,4 +300,4 @@ "createLPTokenMint",

};
});
};
exports.createInitializeNewSwapTx = createInitializeNewSwapTx;
//# sourceMappingURL=initialize.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeInstructions = exports.executeTxInstructions = exports.createMutableTransactionInstructions = void 0;
const tslib_1 = require("tslib");
const solana_contrib_1 = require("@saberhq/solana-contrib");

@@ -18,3 +17,3 @@ const createMutableTransactionInstructions = () => ({

*/
const executeTxInstructions = (title, { instructions, signers }, { provider, payerSigner, options, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const executeTxInstructions = async (title, { instructions, signers }, { provider, payerSigner, options, }) => {
console.log(`Running tx ${title}`);

@@ -27,6 +26,6 @@ const txEnv = new solana_contrib_1.TransactionEnvelope(provider, instructions.slice(), [

]);
const sig = yield txEnv.confirm(options);
const sig = await txEnv.confirm(options);
console.log(`${title} done at tx: ${sig.signature}`);
return sig.signature;
});
};
exports.executeTxInstructions = executeTxInstructions;

@@ -33,0 +32,0 @@ const mergeInstructions = (mut, inst) => {

@@ -16,3 +16,3 @@ import { Price, TokenAmount } from "@saberhq/token-utils";

// or at most, $1
const inputAmountNum = Math.max(10000, Math.min(Math.pow(10, reserve0.token.decimals), Math.floor(parseInt(reserve0.toU64().div(new BN(100)).toString()))));
const inputAmountNum = Math.max(10000, Math.min(10 ** reserve0.token.decimals, Math.floor(parseInt(reserve0.toU64().div(new BN(100)).toString()))));
const inputAmount = new TokenAmount(reserve0.token, inputAmountNum);

@@ -19,0 +19,0 @@ const outputAmount = calculateEstimatedSwapOutputAmount(exchangeInfo, inputAmount);

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

import { __awaiter } from "tslib";
import { deserializeAccount, deserializeMint, parseBigintIsh, Token, TokenAmount, } from "@saberhq/token-utils";

@@ -41,9 +40,9 @@ import { SWAP_PROGRAM_ID } from "../constants";

*/
export const loadExchangeInfo = (connection, exchange, swap) => __awaiter(void 0, void 0, void 0, function* () {
export const loadExchangeInfo = async (connection, exchange, swap) => {
if (!exchange.programID.equals(swap.config.swapProgramID)) {
throw new Error("Swap program id mismatch");
}
const reserveA = yield loadProgramAccount(connection, swap.state.tokenA.reserve, swap.config.tokenProgramID);
const reserveB = yield loadProgramAccount(connection, swap.state.tokenB.reserve, swap.config.tokenProgramID);
const poolMint = yield loadProgramAccount(connection, swap.state.poolTokenMint, swap.config.tokenProgramID);
const reserveA = await loadProgramAccount(connection, swap.state.tokenA.reserve, swap.config.tokenProgramID);
const reserveB = await loadProgramAccount(connection, swap.state.tokenB.reserve, swap.config.tokenProgramID);
const poolMint = await loadProgramAccount(connection, swap.state.poolTokenMint, swap.config.tokenProgramID);
return makeExchangeInfo({

@@ -58,3 +57,3 @@ swap,

});
});
};
/**

@@ -91,10 +90,10 @@ * Creates an IExchange from an ExchangeBasic.

*/
export const loadExchangeInfoFromSwapAccount = (connection, swapAccount, tokenA = undefined, tokenB = undefined) => __awaiter(void 0, void 0, void 0, function* () {
export const loadExchangeInfoFromSwapAccount = async (connection, swapAccount, tokenA = undefined, tokenB = undefined) => {
var _a, _b;
const stableSwap = yield StableSwap.load(connection, swapAccount);
const theTokenA = tokenA !== null && tokenA !== void 0 ? tokenA : (_a = (yield Token.load(connection, stableSwap.state.tokenA.mint))) === null || _a === void 0 ? void 0 : _a.info;
const stableSwap = await StableSwap.load(connection, swapAccount);
const theTokenA = tokenA !== null && tokenA !== void 0 ? tokenA : (_a = (await Token.load(connection, stableSwap.state.tokenA.mint))) === null || _a === void 0 ? void 0 : _a.info;
if (!theTokenA) {
throw new Error(`Token ${stableSwap.state.tokenA.mint.toString()} not found`);
}
const theTokenB = tokenB !== null && tokenB !== void 0 ? tokenB : (_b = (yield Token.load(connection, stableSwap.state.tokenB.mint))) === null || _b === void 0 ? void 0 : _b.info;
const theTokenB = tokenB !== null && tokenB !== void 0 ? tokenB : (_b = (await Token.load(connection, stableSwap.state.tokenB.mint))) === null || _b === void 0 ? void 0 : _b.info;
if (!theTokenB) {

@@ -112,4 +111,4 @@ throw new Error(`Token ${stableSwap.state.tokenB.mint.toString()} not found`);

}
return yield loadExchangeInfo(connection, exchange, stableSwap);
});
return await loadExchangeInfo(connection, exchange, stableSwap);
};
//# sourceMappingURL=exchange.js.map

@@ -13,3 +13,3 @@ import { u64 } from "@saberhq/token-utils";

.filter(([, v]) => !!v)
.reduce((acc, [k, v]) => (Object.assign(Object.assign({}, acc), { [k]: v })), {});
.reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {});
};

@@ -16,0 +16,0 @@ /**

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

import { __rest } from "tslib";
import { encodeFees, ZERO_FEES } from "../state";

@@ -44,5 +43,4 @@ import { buildInstruction } from "./common";

};
export const initializeSwapInstruction = (_a) => {
var { fees = ZERO_FEES } = _a, args = __rest(_a, ["fees"]);
return initializeSwapInstructionRaw(Object.assign(Object.assign({}, args), { fees: encodeFees(fees) }));
export const initializeSwapInstruction = ({ fees = ZERO_FEES, ...args }) => {
return initializeSwapInstructionRaw({ ...args, fees: encodeFees(fees) });
};

@@ -49,0 +47,0 @@ export const swapInstruction = ({ config, userAuthority, userSource, poolSource, poolDestination, userDestination, adminDestination, amountIn, minimumAmountOut, }) => {

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

import { __awaiter } from "tslib";
import { TOKEN_PROGRAM_ID } from "@saberhq/token-utils";

@@ -25,6 +24,4 @@ import { PublicKey } from "@solana/web3.js";

*/
static getMinBalanceRentForExemptStableSwap(connection) {
return __awaiter(this, void 0, void 0, function* () {
return yield connection.getMinimumBalanceForRentExemption(StableSwapLayout.span);
});
static async getMinBalanceRentForExemptStableSwap(connection) {
return await connection.getMinimumBalanceForRentExemption(StableSwapLayout.span);
}

@@ -38,8 +35,6 @@ /**

*/
static load(connection, swapAccount, programID = SWAP_PROGRAM_ID) {
return __awaiter(this, void 0, void 0, function* () {
const data = yield loadProgramAccount(connection, swapAccount, programID);
const [authority] = yield findSwapAuthorityKey(swapAccount, programID);
return StableSwap.loadWithData(swapAccount, data, authority, programID);
});
static async load(connection, swapAccount, programID = SWAP_PROGRAM_ID) {
const data = await loadProgramAccount(connection, swapAccount, programID);
const [authority] = await findSwapAuthorityKey(swapAccount, programID);
return StableSwap.loadWithData(swapAccount, data, authority, programID);
}

@@ -53,6 +48,4 @@ /**

*/
static loadFromExchange(connection, exchange) {
return __awaiter(this, void 0, void 0, function* () {
return StableSwap.load(connection, exchange.swapAccount, exchange.programID);
});
static async loadFromExchange(connection, exchange) {
return StableSwap.load(connection, exchange.swapAccount, exchange.programID);
}

@@ -98,3 +91,7 @@ /**

: this.state.tokenB.adminFeeAccount;
return instructions.swapInstruction(Object.assign(Object.assign({ config: this.config }, args), { adminDestination }));
return instructions.swapInstruction({
config: this.config,
...args,
adminDestination,
});
}

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

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

@@ -112,3 +115,11 @@ /**

withdraw(args) {
return instructions.withdrawInstruction(Object.assign({ 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 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,
});
}

@@ -122,4 +133,9 @@ /**

: [this.state.tokenA.reserve, this.state.tokenB.adminFeeAccount];
return instructions.withdrawOneInstruction(Object.assign({ config: this.config, poolMint: this.state.poolTokenMint, quoteTokenAccount,
adminDestinationAccount }, args));
return instructions.withdrawOneInstruction({
config: this.config,
poolMint: this.state.poolTokenMint,
quoteTokenAccount,
adminDestinationAccount,
...args,
});
}

@@ -126,0 +142,0 @@ }

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

import { __awaiter } from "tslib";
/**

@@ -9,4 +8,4 @@ * Loads the account info of an account owned by a program.

*/
export const loadProgramAccount = (connection, address, programId) => __awaiter(void 0, void 0, void 0, function* () {
const accountInfo = yield connection.getAccountInfo(address);
export const loadProgramAccount = async (connection, address, programId) => {
const accountInfo = await connection.getAccountInfo(address);
if (accountInfo === null) {

@@ -19,3 +18,3 @@ throw new Error("Failed to find account");

return Buffer.from(accountInfo.data);
});
};
//# sourceMappingURL=account.js.map

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

import { __awaiter, __rest } from "tslib";
import { TransactionEnvelope } from "@saberhq/solana-contrib";

@@ -18,7 +17,7 @@ import { createInitMintInstructions, createTokenAccount, getOrCreateATA, SPLToken, TOKEN_PROGRAM_ID, u64, } from "@saberhq/token-utils";

*/
export const initializeStableSwap = (provider, stableSwapAccount, initializeSwapInstruction) => __awaiter(void 0, void 0, void 0, function* () {
export const initializeStableSwap = async (provider, stableSwapAccount, initializeSwapInstruction) => {
if (!stableSwapAccount.publicKey.equals(initializeSwapInstruction.config.swapAccount)) {
throw new Error("stable swap public key");
}
const { instructions } = yield createInitializeStableSwapInstructionsRaw({
const { instructions } = await createInitializeStableSwapInstructionsRaw({
provider,

@@ -29,6 +28,6 @@ initializeSwapInstruction,

console.log("createAccount and InitializeSwap");
const txSig = (yield tx.confirm()).signature;
const txSig = (await tx.confirm()).signature;
console.log(`TxSig: ${txSig}`);
return loadSwapFromInitializeArgs(initializeSwapInstruction);
});
};
/**

@@ -67,3 +66,3 @@ * Creates a new instance of StableSwap from create args.

*/
export const createInitializeStableSwapInstructions = ({ provider, swapProgramID = SWAP_PROGRAM_ID, adminAccount, tokenAMint, tokenBMint, ampFactor, fees, initialLiquidityProvider = adminAccount, useAssociatedAccountForInitialLP, swapAccountSigner = Keypair.generate(), poolTokenMintSigner = Keypair.generate(), seedPoolAccounts, }) => __awaiter(void 0, void 0, void 0, function* () {
export const createInitializeStableSwapInstructions = async ({ provider, swapProgramID = SWAP_PROGRAM_ID, adminAccount, tokenAMint, tokenBMint, ampFactor, fees, initialLiquidityProvider = adminAccount, useAssociatedAccountForInitialLP, swapAccountSigner = Keypair.generate(), poolTokenMintSigner = Keypair.generate(), seedPoolAccounts, }) => {
const instructions = {

@@ -81,7 +80,7 @@ createLPTokenMint: new TransactionEnvelope(provider, []),

// Create authority and nonce
const [authority, nonce] = yield findSwapAuthorityKey(swapAccount, swapProgramID);
const [authority, nonce] = await findSwapAuthorityKey(swapAccount, swapProgramID);
// Create LP token mint
const { decimals } = yield new SPLToken(provider.connection, tokenAMint, TOKEN_PROGRAM_ID, Keypair.generate()).getMintInfo();
const mintBalanceNeeded = yield SPLToken.getMinBalanceRentForExemptMint(provider.connection);
instructions.createLPTokenMint = yield createInitMintInstructions({
const { decimals } = await new SPLToken(provider.connection, tokenAMint, TOKEN_PROGRAM_ID, Keypair.generate()).getMintInfo();
const mintBalanceNeeded = await SPLToken.getMinBalanceRentForExemptMint(provider.connection);
instructions.createLPTokenMint = await createInitMintInstructions({
provider,

@@ -96,3 +95,3 @@ mintKP: poolTokenMintSigner,

if (useAssociatedAccountForInitialLP) {
const lpAccount = yield getOrCreateATA({
const lpAccount = await getOrCreateATA({
provider,

@@ -109,3 +108,3 @@ mint: poolTokenMint,

else {
const { key: unassociatedInitialLPAccount, tx: initialLPInstructions } = yield createTokenAccount({
const { key: unassociatedInitialLPAccount, tx: initialLPInstructions } = await createTokenAccount({
provider,

@@ -120,3 +119,3 @@ mint: poolTokenMint,

// Create Swap Token A account
const { info: tokenA, instructions: tokenAInstructions } = yield initializeSwapTokenInfo({
const { info: tokenA, instructions: tokenAInstructions } = await initializeSwapTokenInfo({
provider,

@@ -129,3 +128,3 @@ mint: tokenAMint,

// Create Swap Token B account
const { info: tokenB, instructions: tokenBInstructions } = yield initializeSwapTokenInfo({
const { info: tokenB, instructions: tokenBInstructions } = await initializeSwapTokenInfo({
provider,

@@ -161,3 +160,3 @@ mint: tokenBMint,

};
const { balanceNeeded: swapBalanceNeeded, instructions: initializeStableSwapInstructions, } = yield createInitializeStableSwapInstructionsRaw({
const { balanceNeeded: swapBalanceNeeded, instructions: initializeStableSwapInstructions, } = await createInitializeStableSwapInstructionsRaw({
provider,

@@ -175,6 +174,6 @@ initializeSwapInstruction,

};
});
const initializeSwapTokenInfo = ({ provider, mint, authority, admin, }) => __awaiter(void 0, void 0, void 0, function* () {
};
const initializeSwapTokenInfo = async ({ provider, mint, authority, admin, }) => {
// Create Swap Token Account
const { key: tokenAccount, tx: createSwapTokenAccountInstructions } = yield createTokenAccount({
const { key: tokenAccount, tx: createSwapTokenAccountInstructions } = await createTokenAccount({
provider,

@@ -186,3 +185,3 @@ mint,

// Create Admin Fee Account
const { key: adminFeeAccount, tx: createAdminFeeAccountInstructions } = yield createTokenAccount({
const { key: adminFeeAccount, tx: createAdminFeeAccountInstructions } = await createTokenAccount({
provider,

@@ -201,3 +200,3 @@ mint,

};
});
};
/**

@@ -210,5 +209,5 @@ * Creates an unsigned InitializeSwap transaction.

*/
export const createInitializeStableSwapInstructionsRaw = ({ provider, initializeSwapInstruction, }) => __awaiter(void 0, void 0, void 0, function* () {
export const createInitializeStableSwapInstructionsRaw = async ({ provider, initializeSwapInstruction, }) => {
// Allocate memory for the account
const balanceNeeded = yield StableSwap.getMinBalanceRentForExemptStableSwap(provider.connection);
const balanceNeeded = await StableSwap.getMinBalanceRentForExemptStableSwap(provider.connection);
return {

@@ -227,28 +226,30 @@ balanceNeeded,

};
});
};
/**
* Deploys a new StableSwap pool.
*/
export const deployNewSwap = (_a) => __awaiter(void 0, void 0, void 0, function* () {
var { enableLogging = false } = _a, args = __rest(_a, ["enableLogging"]);
const result = yield createInitializeNewSwapTx(args);
export const deployNewSwap = async ({ enableLogging = false, ...args }) => {
const result = await createInitializeNewSwapTx(args);
const { txs } = result;
const { signature: setupAccounts1 } = yield txs.setupAccounts1.confirm();
const { signature: setupAccounts1 } = await txs.setupAccounts1.confirm();
if (enableLogging) {
console.log(`Set up accounts pt 1: ${setupAccounts1}`);
}
const { signature: setupAccounts2 } = yield txs.setupAccounts2.confirm();
const { signature: setupAccounts2 } = await txs.setupAccounts2.confirm();
if (enableLogging) {
console.log(`Set up accounts pt 2: ${setupAccounts2}`);
}
const { signature: initializeSwap } = yield txs.initializeSwap.confirm();
const { signature: initializeSwap } = await txs.initializeSwap.confirm();
if (enableLogging) {
console.log(`Initialize swap: ${initializeSwap}`);
}
return Object.assign(Object.assign({}, result), { txSigs: {
return {
...result,
txSigs: {
setupAccounts1,
setupAccounts2,
initializeSwap,
} });
});
},
};
};
/**

@@ -259,5 +260,7 @@ * Creates the transactions for creating a new swap.

*/
export const createInitializeNewSwapTx = (args) => __awaiter(void 0, void 0, void 0, function* () {
export const createInitializeNewSwapTx = async (args) => {
const { provider } = args;
const { instructions, initializeArgs } = yield createInitializeStableSwapInstructions(Object.assign({}, args));
const { instructions, initializeArgs } = await createInitializeStableSwapInstructions({
...args,
});
const setupAccounts1 = [

@@ -288,3 +291,3 @@ "createLPTokenMint",

};
});
};
//# sourceMappingURL=initialize.js.map

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

import { __awaiter } from "tslib";
import { TransactionEnvelope } from "@saberhq/solana-contrib";

@@ -14,3 +13,3 @@ export const createMutableTransactionInstructions = () => ({

*/
export const executeTxInstructions = (title, { instructions, signers }, { provider, payerSigner, options, }) => __awaiter(void 0, void 0, void 0, function* () {
export const executeTxInstructions = async (title, { instructions, signers }, { provider, payerSigner, options, }) => {
console.log(`Running tx ${title}`);

@@ -23,6 +22,6 @@ const txEnv = new TransactionEnvelope(provider, instructions.slice(), [

]);
const sig = yield txEnv.confirm(options);
const sig = await txEnv.confirm(options);
console.log(`${title} done at tx: ${sig.signature}`);
return sig.signature;
});
};
export const mergeInstructions = (mut, inst) => {

@@ -29,0 +28,0 @@ mut.instructions.push(...inst.instructions);

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

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

@@ -40,4 +40,4 @@ "module": "dist/esm/index.js",

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

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

},
"gitHead": "02ba28d061f06bdb3ff4672cced985c9f853e9ba"
"gitHead": "458b20ec0afb87644f172538e2ce5a0c728c3a4f"
}

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

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

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

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