diff --git a/package.json b/package.json index 0b35877..b90c80e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "@mango/client", + "name": "@blockworks-foundation/mango-client", "version": "0.1.0", - "description": "Library for interacting with Mango Margin solana smart contracts.", - "repository": "blockworks-foundation/mango", + "description": "Library for interacting with Mango Markets' solana smart contracts.", + "repository": "blockworks-foundation/mango-client-ts", "author": { "name": "Blockworks Foundation", "email": "hello@blockworks.foundation", @@ -13,7 +13,7 @@ "types": "lib/index.d.ts", "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "scripts": { "build": "tsc", @@ -52,7 +52,8 @@ ], "prettier": { "singleQuote": true, - "trailingComma": "all" + "trailingComma": "all", + "printWidth": 120 }, "dependencies": { "@project-serum/serum": "^0.13.20", diff --git a/src/instruction.ts b/src/instruction.ts index f4fb0a1..ea11e39 100644 --- a/src/instruction.ts +++ b/src/instruction.ts @@ -1,3 +1,4 @@ +import BN from 'bn.js'; import { PublicKey, SYSVAR_CLOCK_PUBKEY, TransactionInstruction } from '@solana/web3.js'; import { Order } from '@project-serum/serum/lib/market'; import { encodeMangoInstruction } from './layout'; @@ -49,12 +50,12 @@ export function makeCancelOrderInstruction( openOrdersPk: PublicKey, signerKey: PublicKey, eventQueuePk: PublicKey, - order: Order + order: Order, ): TransactionInstruction { const keys = [ - { isSigner: false, isWritable: true, pubkey: mangoGroupPk}, - { isSigner: true, isWritable: false, pubkey: ownerPk }, - { isSigner: false, isWritable: true, pubkey: marginAccountPk }, + { isSigner: false, isWritable: true, pubkey: mangoGroupPk }, + { isSigner: true, isWritable: false, pubkey: ownerPk }, + { isSigner: false, isWritable: true, pubkey: marginAccountPk }, { isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY }, { isSigner: false, isWritable: false, pubkey: dexProgramId }, { isSigner: false, isWritable: true, pubkey: spotMarketPk }, @@ -63,18 +64,17 @@ export function makeCancelOrderInstruction( { isSigner: false, isWritable: true, pubkey: openOrdersPk }, { isSigner: false, isWritable: false, pubkey: signerKey }, { isSigner: false, isWritable: true, pubkey: eventQueuePk }, - ] + ]; const data = encodeMangoInstruction({ CancelOrder: { side: order.side, orderId: order.orderId, - } - }) - return new TransactionInstruction( { keys, data, programId }) + }, + }); + return new TransactionInstruction({ keys, data, programId }); } - export function makeSettleFundsInstruction( programId: PublicKey, mangoGroupPk: PublicKey, @@ -91,9 +91,9 @@ export function makeSettleFundsInstruction( dexSignerKey: PublicKey, ): TransactionInstruction { const keys = [ - { isSigner: false, isWritable: true, pubkey: mangoGroupPk}, - { isSigner: true, isWritable: false, pubkey: ownerPk }, - { isSigner: false, isWritable: true, pubkey: marginAccountPk }, + { isSigner: false, isWritable: true, pubkey: mangoGroupPk }, + { isSigner: true, isWritable: false, pubkey: ownerPk }, + { isSigner: false, isWritable: true, pubkey: marginAccountPk }, { isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY }, { isSigner: false, isWritable: false, pubkey: dexProgramId }, { isSigner: false, isWritable: true, pubkey: spotMarketPk }, @@ -105,8 +105,28 @@ export function makeSettleFundsInstruction( { isSigner: false, isWritable: true, pubkey: mangoQuoteVaultPk }, { isSigner: false, isWritable: false, pubkey: dexSignerKey }, { isSigner: false, isWritable: false, pubkey: TOKEN_PROGRAM_ID }, - ] - const data = encodeMangoInstruction( {SettleFunds: {}} ) + ]; + const data = encodeMangoInstruction({ SettleFunds: {} }); - return new TransactionInstruction( { keys, data, programId }) -} \ No newline at end of file + return new TransactionInstruction({ keys, data, programId }); +} + +export function makeSettleBorrowInstruction( + programId: PublicKey, + mangoGroupPk: PublicKey, + marginAccountPk: PublicKey, + walletPk: PublicKey, + tokenIndex: number, + quantity: number, +): TransactionInstruction { + const keys = [ + { isSigner: false, isWritable: true, pubkey: mangoGroupPk }, + { isSigner: false, isWritable: true, pubkey: marginAccountPk }, + { isSigner: true, isWritable: false, pubkey: walletPk }, + { isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY }, + ]; + const data = encodeMangoInstruction({ + SettleBorrow: { tokenIndex: new BN(tokenIndex), quantity }, + }); + return new TransactionInstruction({ keys, data, programId }); +}