Socket
Socket
Sign inDemoInstall

@project-serum/serum

Package Overview
Dependencies
3
Maintainers
3
Versions
135
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.5 to 0.10.0

6

lib/market.d.ts

@@ -46,4 +46,6 @@ /// <reference types="node" />

settleFunds(connection: Connection, owner: Account, openOrders: OpenOrders, baseWallet: PublicKey, quoteWallet: PublicKey): Promise<string>;
makeSettleFundsTransaction(connection: Connection, openOrders: OpenOrders, baseWallet: PublicKey, quoteWallet: PublicKey): Promise<Transaction>;
makeSettleInstruction(openOrders: OpenOrders, baseWallet: PublicKey, quoteWallet: PublicKey, vaultSigner: any): TransactionInstruction;
makeSettleFundsTransaction(connection: Connection, openOrders: OpenOrders, baseWallet: PublicKey, quoteWallet: PublicKey): Promise<{
transaction: Transaction;
signers: [PublicKey | Account];
}>;
loadRequestQueue(connection: Connection): Promise<any[]>;

@@ -50,0 +52,0 @@ loadEventQueue(connection: Connection): Promise<import("./queue").Event[]>;

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

const buffer_1 = require("buffer");
const token_instructions_1 = require("./token-instructions");
exports.MARKET_STATE_LAYOUT = buffer_layout_1.struct([

@@ -129,3 +130,3 @@ buffer_layout_1.blob(5),

async makePlaceOrderTransaction(connection, { owner, payer, side, price, size, orderType = 'limit', clientId, }) {
var _a;
var _a, _b;
// @ts-ignore

@@ -146,5 +147,30 @@ const ownerAddress = (_a = owner.publicKey) !== null && _a !== void 0 ? _a : owner;

}
let wrappedSolAccount = null;
if (payer.equals(ownerAddress)) {
if ((side === 'buy' && this.quoteMintAddress.equals(token_instructions_1.WRAPPED_SOL_MINT)) ||
(side === 'sell' && this.baseMintAddress.equals(token_instructions_1.WRAPPED_SOL_MINT))) {
wrappedSolAccount = new web3_js_1.Account();
transaction.add(web3_js_1.SystemProgram.createAccount({
fromPubkey: ownerAddress,
newAccountPubkey: wrappedSolAccount.publicKey,
lamports:
// TODO: calculate the amount we need and use that instead
(await connection.getBalance(ownerAddress, 'recent')) - 100000,
space: 165,
programId: token_instructions_1.TOKEN_PROGRAM_ID,
}));
transaction.add(token_instructions_1.initializeAccount({
account: wrappedSolAccount.publicKey,
mint: token_instructions_1.WRAPPED_SOL_MINT,
owner: ownerAddress,
}));
signers.push(wrappedSolAccount);
}
else {
throw new Error('Invalid payer account');
}
}
const placeOrderInstruction = this.makePlaceOrderInstruction(connection, {
owner,
payer,
payer: (_b = wrappedSolAccount === null || wrappedSolAccount === void 0 ? void 0 : wrappedSolAccount.publicKey) !== null && _b !== void 0 ? _b : payer,
side,

@@ -157,2 +183,9 @@ price,

transaction.add(placeOrderInstruction);
if (wrappedSolAccount) {
transaction.add(token_instructions_1.closeAccount({
source: wrappedSolAccount.publicKey,
destination: ownerAddress,
owner: ownerAddress,
}));
}
return { transaction, signers };

@@ -239,7 +272,8 @@ }

}
const transaction = await this.makeSettleFundsTransaction(connection, openOrders, baseWallet, quoteWallet);
return await this._sendTransaction(connection, transaction, [owner]);
const { transaction, signers } = await this.makeSettleFundsTransaction(connection, openOrders, baseWallet, quoteWallet);
signers[0] = owner;
// @ts-ignore
return await this._sendTransaction(connection, transaction, signers);
}
async makeSettleFundsTransaction(connection, openOrders, baseWallet, quoteWallet) {
const tx = new web3_js_1.Transaction();
// @ts-ignore

@@ -250,8 +284,25 @@ const vaultSigner = await web3_js_1.PublicKey.createProgramAddress([

], this._programId);
const settleInstruction = this.makeSettleInstruction(openOrders, baseWallet, quoteWallet, vaultSigner);
tx.add(settleInstruction);
return tx;
}
makeSettleInstruction(openOrders, baseWallet, quoteWallet, vaultSigner) {
return instructions_1.DexInstructions.settleFunds({
const transaction = new web3_js_1.Transaction();
const signers = [openOrders.owner];
let wrappedSolAccount = null;
if ((this.baseMintAddress.equals(token_instructions_1.WRAPPED_SOL_MINT) &&
baseWallet.equals(openOrders.owner)) ||
(this.quoteMintAddress.equals(token_instructions_1.WRAPPED_SOL_MINT) &&
quoteWallet.equals(openOrders.owner))) {
wrappedSolAccount = new web3_js_1.Account();
transaction.add(web3_js_1.SystemProgram.createAccount({
fromPubkey: openOrders.owner,
newAccountPubkey: wrappedSolAccount.publicKey,
lamports: await connection.getMinimumBalanceForRentExemption(165),
space: 165,
programId: token_instructions_1.TOKEN_PROGRAM_ID,
}));
transaction.add(token_instructions_1.initializeAccount({
account: wrappedSolAccount.publicKey,
mint: token_instructions_1.WRAPPED_SOL_MINT,
owner: openOrders.owner,
}));
signers.push(wrappedSolAccount);
}
transaction.add(instructions_1.DexInstructions.settleFunds({
market: this.address,

@@ -262,7 +313,19 @@ openOrders: openOrders.address,

quoteVault: this._decoded.quoteVault,
baseWallet,
quoteWallet,
baseWallet: baseWallet.equals(openOrders.owner) && wrappedSolAccount
? wrappedSolAccount.publicKey
: baseWallet,
quoteWallet: quoteWallet.equals(openOrders.owner) && wrappedSolAccount
? wrappedSolAccount.publicKey
: quoteWallet,
vaultSigner,
programId: this._programId,
});
}));
if (wrappedSolAccount) {
transaction.add(token_instructions_1.closeAccount({
source: wrappedSolAccount.publicKey,
destination: openOrders.owner,
owner: openOrders.owner,
}));
}
return { transaction, signers };
}

@@ -528,2 +591,5 @@ async loadRequestQueue(connection) {

async function getMintDecimals(connection, mint) {
if (mint.equals(token_instructions_1.WRAPPED_SOL_MINT)) {
return 6;
}
const { data } = throwIfNull(await connection.getAccountInfo(mint), 'mint not found');

@@ -530,0 +596,0 @@ const { decimals } = MINT_LAYOUT.decode(data);

@@ -30,2 +30,7 @@ export function initializeMint({ mint, decimals, mintAuthority, freezeAuthority, }: {

}): TransactionInstruction;
export function closeAccount({ source, destination, owner }: {
source: any;
destination: any;
owner: any;
}): TransactionInstruction;
export const TOKEN_PROGRAM_ID: PublicKey;

@@ -32,0 +37,0 @@ export const WRAPPED_SOL_MINT: PublicKey;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.mintTo = exports.approve = exports.transfer = exports.initializeAccount = exports.initializeMint = exports.WRAPPED_SOL_MINT = exports.TOKEN_PROGRAM_ID = void 0;
exports.closeAccount = exports.mintTo = exports.approve = exports.transfer = exports.initializeAccount = exports.initializeMint = exports.WRAPPED_SOL_MINT = exports.TOKEN_PROGRAM_ID = void 0;
const BufferLayout = __importStar(require("buffer-layout"));

@@ -28,3 +28,3 @@ const web3_js_1 = require("@solana/web3.js");

exports.TOKEN_PROGRAM_ID = new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
exports.WRAPPED_SOL_MINT = new web3_js_1.PublicKey('So11111111111111111111111111111111111111111');
exports.WRAPPED_SOL_MINT = new web3_js_1.PublicKey('So11111111111111111111111111111111111111112');
const LAYOUT = BufferLayout.union(BufferLayout.u8('instruction'));

@@ -41,2 +41,3 @@ LAYOUT.addVariant(0, BufferLayout.struct([

LAYOUT.addVariant(8, BufferLayout.struct([BufferLayout.nu64('amount')]), 'burn');
LAYOUT.addVariant(9, BufferLayout.struct([]), 'closeAccount');
const instructionMaxSpan = Math.max(...Object.values(LAYOUT.registry).map((r) => r.span));

@@ -128,2 +129,17 @@ function encodeTokenInstructionData(instruction) {

exports.mintTo = mintTo;
function closeAccount({ source, destination, owner }) {
const keys = [
{ pubkey: source, isSigner: false, isWritable: true },
{ pubkey: destination, isSigner: false, isWritable: true },
{ pubkey: owner, isSigner: true, isWritable: false },
];
return new web3_js_1.TransactionInstruction({
keys,
data: encodeTokenInstructionData({
closeAccount: {},
}),
programId: exports.TOKEN_PROGRAM_ID,
});
}
exports.closeAccount = closeAccount;
//# sourceMappingURL=token-instructions.js.map
{
"name": "@project-serum/serum",
"version": "0.9.5",
"version": "0.10.0",
"description": "Library for interacting with the serum dex",

@@ -5,0 +5,0 @@ "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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc