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

@project-serum/serum

Package Overview
Dependencies
Maintainers
5
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@project-serum/serum - npm Package Compare versions

Comparing version 0.13.64 to 0.13.65

20

lib/instructions.d.ts

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

export function encodeInstruction(instruction: any): Buffer;
export function encodeInstruction(instruction: any, maxLength?: number): Buffer;
export function encodeInstructionV2(instruction: any): Buffer;

@@ -50,3 +50,3 @@ export function decodeInstruction(message: any): any;

}): TransactionInstruction;
static newOrderV3({ market, openOrders, payer, owner, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, side, limitPrice, maxBaseQuantity, maxQuoteQuantity, orderType, clientId, programId, selfTradeBehavior, feeDiscountPubkey, maxTs, }: {
static newOrderV3({ market, openOrders, payer, owner, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, side, limitPrice, maxBaseQuantity, maxQuoteQuantity, orderType, clientId, programId, selfTradeBehavior, feeDiscountPubkey, maxTs, replaceIfExists, }: {
market: any;

@@ -72,3 +72,19 @@ openOrders: any;

maxTs?: any;
replaceIfExists?: boolean | undefined;
}): TransactionInstruction;
static replaceOrdersByClientIds({ market, openOrders, payer, owner, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, feeDiscountPubkey, programId, orders }: {
market: any;
openOrders: any;
payer: any;
owner: any;
requestQueue: any;
eventQueue: any;
bids: any;
asks: any;
baseVault: any;
quoteVault: any;
feeDiscountPubkey?: any;
programId: any;
orders: any;
}): TransactionInstruction;
static matchOrders({ market, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, limit, programId, }: {

@@ -75,0 +91,0 @@ market: any;

80

lib/instructions.js

@@ -62,14 +62,4 @@ "use strict";

exports.INSTRUCTION_LAYOUT.inner.addVariant(17, buffer_layout_1.struct([buffer_layout_1.u16('limit')]), 'consumeEventsPermissioned');
exports.INSTRUCTION_LAYOUT.inner.addVariant(18, buffer_layout_1.struct([
layout_1.u64('clientId0'),
layout_1.u64('clientId1'),
layout_1.u64('clientId2'),
layout_1.u64('clientId3'),
layout_1.u64('clientId4'),
layout_1.u64('clientId5'),
layout_1.u64('clientId6'),
layout_1.u64('clientId7')
]), 'cancelOrdersByClientIds');
exports.INSTRUCTION_LAYOUT_V2 = new layout_1.VersionedLayout(0, buffer_layout_1.union(buffer_layout_1.u32('instruction')));
exports.INSTRUCTION_LAYOUT_V2.inner.addVariant(10, buffer_layout_1.struct([
exports.INSTRUCTION_LAYOUT.inner.addVariant(18, buffer_layout_1.struct([buffer_layout_1.seq(layout_1.u64(), 8, 'clientIds')]), 'cancelOrdersByClientIds');
const orderStruct = () => buffer_layout_1.struct([
layout_1.sideLayout('side'),

@@ -84,5 +74,9 @@ layout_1.u64('limitPrice'),

layout_1.i64('maxTs'),
]), 'newOrderV3');
function encodeInstruction(instruction) {
const b = Buffer.alloc(100);
]);
exports.INSTRUCTION_LAYOUT.inner.addVariant(19, orderStruct(), 'replaceOrderByClientId');
exports.INSTRUCTION_LAYOUT.inner.addVariant(20, buffer_layout_1.struct([layout_1.u64('orderAmount'), buffer_layout_1.seq(orderStruct(), 8, 'orders')]), 'replaceOrdersByClientIds');
exports.INSTRUCTION_LAYOUT_V2 = new layout_1.VersionedLayout(0, buffer_layout_1.union(buffer_layout_1.u32('instruction')));
exports.INSTRUCTION_LAYOUT_V2.inner.addVariant(10, orderStruct(), 'newOrderV3');
function encodeInstruction(instruction, maxLength = 100) {
const b = Buffer.alloc(maxLength);
return b.slice(0, exports.INSTRUCTION_LAYOUT.encode(instruction, b));

@@ -175,3 +169,3 @@ }

}
static newOrderV3({ market, openOrders, payer, owner, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, side, limitPrice, maxBaseQuantity, maxQuoteQuantity, orderType, clientId, programId, selfTradeBehavior, feeDiscountPubkey = null, maxTs = null, }) {
static newOrderV3({ market, openOrders, payer, owner, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, side, limitPrice, maxBaseQuantity, maxQuoteQuantity, orderType, clientId, programId, selfTradeBehavior, feeDiscountPubkey = null, maxTs = null, replaceIfExists = false, }) {
const keys = [

@@ -198,3 +192,11 @@ { pubkey: market, isSigner: false, isWritable: true },

}
const encoder = maxTs ? encodeInstructionV2 : encodeInstruction;
let instructionName, encoder;
if (replaceIfExists) {
instructionName = 'replaceOrderByClientId';
encoder = encodeInstruction;
}
else {
instructionName = 'newOrderV3';
encoder = maxTs ? encodeInstructionV2 : encodeInstruction;
}
return new web3_js_1.TransactionInstruction({

@@ -204,3 +206,3 @@ keys,

data: encoder({
newOrderV3: {
[instructionName]: {
side,

@@ -219,2 +221,42 @@ limitPrice,

}
static replaceOrdersByClientIds({ market, openOrders, payer, owner, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, feeDiscountPubkey = null, programId, orders }) {
const keys = [
{ pubkey: market, isSigner: false, isWritable: true },
{ pubkey: openOrders, isSigner: false, isWritable: true },
{ pubkey: requestQueue, isSigner: false, isWritable: true },
{ pubkey: eventQueue, isSigner: false, isWritable: true },
{ pubkey: bids, isSigner: false, isWritable: true },
{ pubkey: asks, isSigner: false, isWritable: true },
{ pubkey: payer, isSigner: false, isWritable: true },
{ pubkey: owner, isSigner: true, isWritable: false },
{ pubkey: baseVault, isSigner: false, isWritable: true },
{ pubkey: quoteVault, isSigner: false, isWritable: true },
{ pubkey: token_instructions_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
{ pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
];
if (feeDiscountPubkey) {
keys.push({
pubkey: feeDiscountPubkey,
isSigner: false,
isWritable: false,
});
}
return new web3_js_1.TransactionInstruction({
keys,
programId,
data: encodeInstruction({
replaceOrdersByClientIds: {
orderAmount: new bn_js_1.default(orders.length),
orders: orders.map(order => {
var _a;
return ({
...order,
maxTs: new bn_js_1.default((_a = order.maxTs) !== null && _a !== void 0 ? _a : '9223372036854775807'),
limit: 65535,
});
})
}
}, 15 + orders.length * 60).slice(0, 13 + orders.length * 54)
});
}
static matchOrders({ market, requestQueue, eventQueue, bids, asks, baseVault, quoteVault, limit, programId, }) {

@@ -347,3 +389,3 @@ return new web3_js_1.TransactionInstruction({

data: encodeInstruction({
cancelOrdersByClientIds: Object.fromEntries(clientIds.map((clientId, i) => [`clientId${i}`, clientId])),
cancelOrdersByClientIds: { clientIds },
}),

@@ -350,0 +392,0 @@ });

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

findOpenOrdersAccountsForOwner(connection: Connection, ownerAddress: PublicKey, cacheDurationMs?: number): Promise<OpenOrders[]>;
placeOrder(connection: Connection, { owner, payer, side, price, size, orderType, clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey, maxTs, }: OrderParams): Promise<string>;
replaceOrders(connection: Connection, accounts: OrderParamsAccounts, orders: OrderParamsBase[], cacheDurationMs?: number): Promise<string>;
placeOrder(connection: Connection, { owner, payer, side, price, size, orderType, clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey, maxTs, replaceIfExists, }: OrderParams): Promise<string>;
getSplTokenBalanceFromAccountInfo(accountInfo: AccountInfo<Buffer>, decimals: number): number;

@@ -66,3 +67,3 @@ get supportsSrmFeeDiscounts(): boolean;

}>;
makePlaceOrderTransaction<T extends PublicKey | Account>(connection: Connection, { owner, payer, side, price, size, orderType, clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey, selfTradeBehavior, maxTs, }: OrderParams<T>, cacheDurationMs?: number, feeDiscountPubkeyCacheDurationMs?: number): Promise<{
makePlaceOrderTransaction<T extends PublicKey | Account>(connection: Connection, { owner, payer, side, price, size, orderType, clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey, selfTradeBehavior, maxTs, replaceIfExists, }: OrderParams<T>, cacheDurationMs?: number, feeDiscountPubkeyCacheDurationMs?: number): Promise<{
transaction: Transaction;

@@ -74,2 +75,3 @@ signers: Account[];

makeNewOrderV3Instruction<T extends PublicKey | Account>(params: OrderParams<T>): TransactionInstruction;
makeReplaceOrdersByClientIdsInstruction<T extends PublicKey | Account>(accounts: OrderParamsAccounts<T>, orders: OrderParamsBase<T>[]): TransactionInstruction;
private _sendTransaction;

@@ -114,5 +116,3 @@ cancelOrderByClientId(connection: Connection, owner: Account, openOrders: PublicKey, clientId: BN): Promise<string>;

}
export interface OrderParams<T = Account> {
owner: T;
payer: PublicKey;
export interface OrderParamsBase<T = Account> {
side: 'buy' | 'sell';

@@ -123,9 +123,16 @@ price: number;

clientId?: BN;
selfTradeBehavior?: 'decrementTake' | 'cancelProvide' | 'abortTransaction' | undefined;
maxTs?: number | null;
}
export interface OrderParamsAccounts<T = Account> {
owner: T;
payer: PublicKey;
openOrdersAddressKey?: PublicKey;
openOrdersAccount?: Account;
feeDiscountPubkey?: PublicKey | null;
selfTradeBehavior?: 'decrementTake' | 'cancelProvide' | 'abortTransaction' | undefined;
programId?: PublicKey;
maxTs?: number | null;
}
export interface OrderParams<T = Account> extends OrderParamsBase<T>, OrderParamsAccounts<T> {
replaceIfExists?: boolean;
}
export declare const _OPEN_ORDERS_LAYOUT_V1: any;

@@ -132,0 +139,0 @@ export declare const _OPEN_ORDERS_LAYOUT_V2: any;

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

}
async placeOrder(connection, { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey, maxTs, }) {
async replaceOrders(connection, accounts, orders, cacheDurationMs = 0) {
var _a;
if (!accounts.openOrdersAccount && !accounts.openOrdersAddressKey) {
const ownerAddress = (_a = accounts.owner.publicKey) !== null && _a !== void 0 ? _a : accounts.owner;
const openOrdersAccounts = await this.findOpenOrdersAccountsForOwner(connection, ownerAddress, cacheDurationMs);
accounts.openOrdersAddressKey = openOrdersAccounts[0].address;
}
const transaction = new web3_js_1.Transaction();
transaction.add(this.makeReplaceOrdersByClientIdsInstruction(accounts, orders));
return await this._sendTransaction(connection, transaction, [
accounts.owner,
]);
}
async placeOrder(connection, { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey, maxTs, replaceIfExists = false, }) {
const { transaction, signers } = await this.makePlaceOrderTransaction(connection, {

@@ -251,2 +264,3 @@ owner,

maxTs,
replaceIfExists,
});

@@ -337,3 +351,3 @@ return await this._sendTransaction(connection, transaction, [

}
async makePlaceOrderTransaction(connection, { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey = undefined, selfTradeBehavior = 'decrementTake', maxTs, }, cacheDurationMs = 0, feeDiscountPubkeyCacheDurationMs = 0) {
async makePlaceOrderTransaction(connection, { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey = undefined, selfTradeBehavior = 'decrementTake', maxTs, replaceIfExists = false, }, cacheDurationMs = 0, feeDiscountPubkeyCacheDurationMs = 0) {
var _a, _b;

@@ -430,2 +444,3 @@ // @ts-ignore

maxTs,
replaceIfExists,
});

@@ -444,3 +459,3 @@ transaction.add(placeOrderInstruction);

var _a;
const { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey = null, maxTs, } = params;
const { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey = null, } = params;
// @ts-ignore

@@ -471,2 +486,3 @@ const ownerAddress = (_a = owner.publicKey) !== null && _a !== void 0 ? _a : owner;

programId: this._programId,
// @ts-ignore
feeDiscountPubkey: this.supportsSrmFeeDiscounts

@@ -483,3 +499,3 @@ ? feeDiscountPubkey

var _a;
const { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey = null, selfTradeBehavior = 'decrementTake', programId, maxTs, } = params;
const { owner, payer, side, price, size, orderType = 'limit', clientId, openOrdersAddressKey, openOrdersAccount, feeDiscountPubkey = null, selfTradeBehavior = 'decrementTake', programId, maxTs, replaceIfExists, } = params;
// @ts-ignore

@@ -514,4 +530,44 @@ const ownerAddress = (_a = owner.publicKey) !== null && _a !== void 0 ? _a : owner;

maxTs,
replaceIfExists,
});
}
makeReplaceOrdersByClientIdsInstruction(accounts, orders) {
var _a, _b;
// @ts-ignore
const ownerAddress = (_a = accounts.owner.publicKey) !== null && _a !== void 0 ? _a : accounts.owner;
return instructions_1.DexInstructions.replaceOrdersByClientIds({
market: this.address,
bids: this._decoded.bids,
asks: this._decoded.asks,
requestQueue: this._decoded.requestQueue,
eventQueue: this._decoded.eventQueue,
baseVault: this._decoded.baseVault,
quoteVault: this._decoded.quoteVault,
openOrders: accounts.openOrdersAccount
? accounts.openOrdersAccount.publicKey
: accounts.openOrdersAddressKey,
owner: ownerAddress,
payer: accounts.payer,
programId: (_b = accounts.programId) !== null && _b !== void 0 ? _b : this._programId,
// @ts-ignore
feeDiscountPubkey: this.supportsSrmFeeDiscounts
? accounts.feeDiscountPubkey
: null,
orders: orders.map(order => {
var _a;
return ({
side: order.side,
limitPrice: this.priceNumberToLots(order.price),
maxBaseQuantity: this.baseSizeNumberToLots(order.size),
maxQuoteQuantity: new bn_js_1.default(this._decoded.quoteLotSize.toNumber()).mul(this.baseSizeNumberToLots(order.size).mul(this.priceNumberToLots(order.price))),
orderType: order.orderType,
clientId: order.clientId,
programId: (_a = accounts.programId) !== null && _a !== void 0 ? _a : this._programId,
selfTradeBehavior: order.selfTradeBehavior,
// @ts-ignore
maxTs: order.maxTs,
});
})
});
}
async _sendTransaction(connection, transaction, signers) {

@@ -518,0 +574,0 @@ const signature = await connection.sendTransaction(transaction, signers, {

{
"name": "@project-serum/serum",
"version": "0.13.64",
"version": "0.13.65",
"description": "Library for interacting with the serum dex",

@@ -61,2 +61,2 @@ "license": "MIT",

]
}
}

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