added makeSettleFundsInstruction as another example
This commit is contained in:
parent
ab1053e596
commit
c128a9a676
|
@ -31,7 +31,7 @@ import { Market, OpenOrders, Orderbook } from '@project-serum/serum';
|
||||||
import { SRM_DECIMALS, TOKEN_PROGRAM_ID } from '@project-serum/serum/lib/token-instructions';
|
import { SRM_DECIMALS, TOKEN_PROGRAM_ID } from '@project-serum/serum/lib/token-instructions';
|
||||||
import { Order } from '@project-serum/serum/lib/market';
|
import { Order } from '@project-serum/serum/lib/market';
|
||||||
import Wallet from '@project-serum/sol-wallet-adapter';
|
import Wallet from '@project-serum/sol-wallet-adapter';
|
||||||
import { makeCancelOrderInstruction } from './instruction';
|
import { makeCancelOrderInstruction, makeSettleFundsInstruction } from './instruction';
|
||||||
|
|
||||||
|
|
||||||
export class MangoGroup {
|
export class MangoGroup {
|
||||||
|
@ -778,27 +778,22 @@ export class MangoClient {
|
||||||
spotMarket.programId
|
spotMarket.programId
|
||||||
)
|
)
|
||||||
|
|
||||||
const keys = [
|
const instruction = makeSettleFundsInstruction(
|
||||||
{ isSigner: false, isWritable: true, pubkey: mangoGroup.publicKey},
|
programId,
|
||||||
{ isSigner: true, isWritable: false, pubkey: owner.publicKey },
|
mangoGroup.publicKey,
|
||||||
{ isSigner: false, isWritable: true, pubkey: marginAccount.publicKey },
|
owner.publicKey,
|
||||||
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
|
marginAccount.publicKey,
|
||||||
{ isSigner: false, isWritable: false, pubkey: spotMarket.programId },
|
spotMarket.programId,
|
||||||
{ isSigner: false, isWritable: true, pubkey: spotMarket.publicKey },
|
spotMarket.publicKey,
|
||||||
{ isSigner: false, isWritable: true, pubkey: marginAccount.openOrders[marketIndex] },
|
marginAccount.openOrders[marketIndex],
|
||||||
{ isSigner: false, isWritable: false, pubkey: mangoGroup.signerKey },
|
mangoGroup.signerKey,
|
||||||
{ isSigner: false, isWritable: true, pubkey: spotMarket['_decoded'].baseVault },
|
spotMarket['_decoded'].baseVault,
|
||||||
{ isSigner: false, isWritable: true, pubkey: spotMarket['_decoded'].quoteVault },
|
spotMarket['_decoded'].quoteVault,
|
||||||
{ isSigner: false, isWritable: true, pubkey: mangoGroup.vaults[marketIndex] },
|
mangoGroup.vaults[marketIndex],
|
||||||
{ isSigner: false, isWritable: true, pubkey: mangoGroup.vaults[mangoGroup.vaults.length - 1] },
|
mangoGroup.vaults[mangoGroup.vaults.length - 1],
|
||||||
{ isSigner: false, isWritable: false, pubkey: dexSigner },
|
dexSigner
|
||||||
{ isSigner: false, isWritable: false, pubkey: TOKEN_PROGRAM_ID },
|
)
|
||||||
]
|
|
||||||
const data = encodeMangoInstruction( {SettleFunds: {}} )
|
|
||||||
|
|
||||||
const instruction = new TransactionInstruction( { keys, data, programId })
|
|
||||||
|
|
||||||
// Add all instructions to one atomic transaction
|
|
||||||
const transaction = new Transaction()
|
const transaction = new Transaction()
|
||||||
transaction.add(instruction)
|
transaction.add(instruction)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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';
|
||||||
|
import { TOKEN_PROGRAM_ID } from '@project-serum/serum/lib/token-instructions';
|
||||||
|
|
||||||
export function makeCancelOrderInstruction(
|
export function makeCancelOrderInstruction(
|
||||||
programId: PublicKey,
|
programId: PublicKey,
|
||||||
|
@ -38,3 +39,40 @@ export function makeCancelOrderInstruction(
|
||||||
})
|
})
|
||||||
return new TransactionInstruction( { keys, data, programId })
|
return new TransactionInstruction( { keys, data, programId })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function makeSettleFundsInstruction(
|
||||||
|
programId: PublicKey,
|
||||||
|
mangoGroupPk: PublicKey,
|
||||||
|
ownerPk: PublicKey,
|
||||||
|
marginAccountPk: PublicKey,
|
||||||
|
dexProgramId: PublicKey,
|
||||||
|
spotMarketPk: PublicKey,
|
||||||
|
openOrdersPk: PublicKey,
|
||||||
|
signerKey: PublicKey,
|
||||||
|
spotMarketBaseVaultPk: PublicKey,
|
||||||
|
spotMarketQuoteVaultPk: PublicKey,
|
||||||
|
mangoBaseVaultPk: PublicKey,
|
||||||
|
mangoQuoteVaultPk: PublicKey,
|
||||||
|
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: false, pubkey: SYSVAR_CLOCK_PUBKEY },
|
||||||
|
{ isSigner: false, isWritable: false, pubkey: dexProgramId },
|
||||||
|
{ isSigner: false, isWritable: true, pubkey: spotMarketPk },
|
||||||
|
{ isSigner: false, isWritable: true, pubkey: openOrdersPk },
|
||||||
|
{ isSigner: false, isWritable: false, pubkey: signerKey },
|
||||||
|
{ isSigner: false, isWritable: true, pubkey: spotMarketBaseVaultPk },
|
||||||
|
{ isSigner: false, isWritable: true, pubkey: spotMarketQuoteVaultPk },
|
||||||
|
{ isSigner: false, isWritable: true, pubkey: mangoBaseVaultPk },
|
||||||
|
{ isSigner: false, isWritable: true, pubkey: mangoQuoteVaultPk },
|
||||||
|
{ isSigner: false, isWritable: false, pubkey: dexSignerKey },
|
||||||
|
{ isSigner: false, isWritable: false, pubkey: TOKEN_PROGRAM_ID },
|
||||||
|
]
|
||||||
|
const data = encodeMangoInstruction( {SettleFunds: {}} )
|
||||||
|
|
||||||
|
return new TransactionInstruction( { keys, data, programId })
|
||||||
|
}
|
Loading…
Reference in New Issue