Merge branch 'main' into borrow_limits

# Conflicts:
#	src/client.ts
#	src/index.ts
#	src/layout.ts
This commit is contained in:
dd 2021-02-22 21:48:05 -05:00
commit 8404d8d4fa
2 changed files with 42 additions and 21 deletions

View File

@ -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",

View File

@ -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 })
}
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 });
}