add fn to create settle borrow instructions
This commit is contained in:
parent
460eae5858
commit
7f254fe289
|
@ -1,3 +1,4 @@
|
||||||
|
import * as BN from 'bn.js';
|
||||||
import { PublicKey, SYSVAR_CLOCK_PUBKEY, TransactionInstruction } from '@solana/web3.js';
|
import { PublicKey, SYSVAR_CLOCK_PUBKEY, TransactionInstruction } from '@solana/web3.js';
|
||||||
import { Order } from '@project-serum/serum/lib/market';
|
import { Order } from '@project-serum/serum/lib/market';
|
||||||
import { encodeMangoInstruction } from './layout';
|
import { encodeMangoInstruction } from './layout';
|
||||||
|
@ -15,12 +16,12 @@ export function makeCancelOrderInstruction(
|
||||||
openOrdersPk: PublicKey,
|
openOrdersPk: PublicKey,
|
||||||
signerKey: PublicKey,
|
signerKey: PublicKey,
|
||||||
eventQueuePk: PublicKey,
|
eventQueuePk: PublicKey,
|
||||||
order: Order
|
order: Order,
|
||||||
): TransactionInstruction {
|
): TransactionInstruction {
|
||||||
const keys = [
|
const keys = [
|
||||||
{ isSigner: false, isWritable: true, pubkey: mangoGroupPk},
|
{ isSigner: false, isWritable: true, pubkey: mangoGroupPk },
|
||||||
{ isSigner: true, isWritable: false, pubkey: ownerPk },
|
{ isSigner: true, isWritable: false, pubkey: ownerPk },
|
||||||
{ isSigner: false, isWritable: true, pubkey: marginAccountPk },
|
{ isSigner: false, isWritable: true, pubkey: marginAccountPk },
|
||||||
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
|
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
|
||||||
{ isSigner: false, isWritable: false, pubkey: dexProgramId },
|
{ isSigner: false, isWritable: false, pubkey: dexProgramId },
|
||||||
{ isSigner: false, isWritable: true, pubkey: spotMarketPk },
|
{ isSigner: false, isWritable: true, pubkey: spotMarketPk },
|
||||||
|
@ -29,18 +30,17 @@ export function makeCancelOrderInstruction(
|
||||||
{ isSigner: false, isWritable: true, pubkey: openOrdersPk },
|
{ isSigner: false, isWritable: true, pubkey: openOrdersPk },
|
||||||
{ isSigner: false, isWritable: false, pubkey: signerKey },
|
{ isSigner: false, isWritable: false, pubkey: signerKey },
|
||||||
{ isSigner: false, isWritable: true, pubkey: eventQueuePk },
|
{ isSigner: false, isWritable: true, pubkey: eventQueuePk },
|
||||||
]
|
];
|
||||||
|
|
||||||
const data = encodeMangoInstruction({
|
const data = encodeMangoInstruction({
|
||||||
CancelOrder: {
|
CancelOrder: {
|
||||||
side: order.side,
|
side: order.side,
|
||||||
orderId: order.orderId,
|
orderId: order.orderId,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
return new TransactionInstruction( { keys, data, programId })
|
return new TransactionInstruction({ keys, data, programId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function makeSettleFundsInstruction(
|
export function makeSettleFundsInstruction(
|
||||||
programId: PublicKey,
|
programId: PublicKey,
|
||||||
mangoGroupPk: PublicKey,
|
mangoGroupPk: PublicKey,
|
||||||
|
@ -57,9 +57,9 @@ export function makeSettleFundsInstruction(
|
||||||
dexSignerKey: PublicKey,
|
dexSignerKey: PublicKey,
|
||||||
): TransactionInstruction {
|
): TransactionInstruction {
|
||||||
const keys = [
|
const keys = [
|
||||||
{ isSigner: false, isWritable: true, pubkey: mangoGroupPk},
|
{ isSigner: false, isWritable: true, pubkey: mangoGroupPk },
|
||||||
{ isSigner: true, isWritable: false, pubkey: ownerPk },
|
{ isSigner: true, isWritable: false, pubkey: ownerPk },
|
||||||
{ isSigner: false, isWritable: true, pubkey: marginAccountPk },
|
{ isSigner: false, isWritable: true, pubkey: marginAccountPk },
|
||||||
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
|
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
|
||||||
{ isSigner: false, isWritable: false, pubkey: dexProgramId },
|
{ isSigner: false, isWritable: false, pubkey: dexProgramId },
|
||||||
{ isSigner: false, isWritable: true, pubkey: spotMarketPk },
|
{ isSigner: false, isWritable: true, pubkey: spotMarketPk },
|
||||||
|
@ -71,8 +71,28 @@ export function makeSettleFundsInstruction(
|
||||||
{ isSigner: false, isWritable: true, pubkey: mangoQuoteVaultPk },
|
{ isSigner: false, isWritable: true, pubkey: mangoQuoteVaultPk },
|
||||||
{ isSigner: false, isWritable: false, pubkey: dexSignerKey },
|
{ isSigner: false, isWritable: false, pubkey: dexSignerKey },
|
||||||
{ isSigner: false, isWritable: false, pubkey: TOKEN_PROGRAM_ID },
|
{ 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 });
|
||||||
}
|
}
|
Loading…
Reference in New Issue