feat: liquidate instruction

This commit is contained in:
bartosz-lipinski 2020-11-21 21:10:08 -06:00
parent 3086ee66f4
commit e2f8cafade
1 changed files with 27 additions and 11 deletions

View File

@ -22,12 +22,17 @@ import * as Layout from "./../../utils/layout";
/// 12 `[]` Token program id /// 12 `[]` Token program id
export const liquidateInstruction = ( export const liquidateInstruction = (
liquidityAmount: number | BN, liquidityAmount: number | BN,
from: PublicKey, // Collateral input SPL Token account. $authority can transfer $liquidity_amount from: PublicKey, // Liquidity input SPL Token account. $authority can transfer $liquidity_amount
to: PublicKey, // Liquidity output SPL Token account, to: PublicKey, // Collateral output SPL Token account,
reserveAccount: PublicKey, repayReserveAccount: PublicKey,
collateralMint: PublicKey, repayReserveLiquiditySupply: PublicKey,
reserveSupply: PublicKey, withdrawReserve: PublicKey,
authority: PublicKey withdrawReserveCollateralSupply: PublicKey,
obligation: PublicKey,
authority: PublicKey,
dexMarket: PublicKey,
dexOrderBookSide: PublicKey,
memory: PublicKey,
): TransactionInstruction => { ): TransactionInstruction => {
const dataLayout = BufferLayout.struct([ const dataLayout = BufferLayout.struct([
BufferLayout.u8("instruction"), BufferLayout.u8("instruction"),
@ -37,7 +42,7 @@ export const liquidateInstruction = (
const data = Buffer.alloc(dataLayout.span); const data = Buffer.alloc(dataLayout.span);
dataLayout.encode( dataLayout.encode(
{ {
instruction: LendingInstruction.RepayOblogationLiquidity, instruction: LendingInstruction.LiquidateObligation,
collateralAmount: new BN(liquidityAmount), collateralAmount: new BN(liquidityAmount),
}, },
data data
@ -46,11 +51,22 @@ export const liquidateInstruction = (
const keys = [ const keys = [
{ pubkey: from, isSigner: false, isWritable: true }, { pubkey: from, isSigner: false, isWritable: true },
{ pubkey: to, isSigner: false, isWritable: true }, { pubkey: to, isSigner: false, isWritable: true },
{ pubkey: reserveAccount, isSigner: false, isWritable: true },
{ pubkey: collateralMint, isSigner: false, isWritable: true }, { pubkey: repayReserveAccount, isSigner: false, isWritable: true },
{ pubkey: reserveSupply, isSigner: false, isWritable: true }, { pubkey: repayReserveLiquiditySupply, isSigner: false, isWritable: true },
{ pubkey: withdrawReserve, isSigner: false, isWritable: true },
{ pubkey: withdrawReserveCollateralSupply, isSigner: false, isWritable: true },
{ pubkey: obligation, isSigner: false, isWritable: true },
{ pubkey: authority, isSigner: false, isWritable: false }, { pubkey: authority, isSigner: false, isWritable: false },
{ pubkey: dexMarket, isSigner: false, isWritable: false },
{ pubkey: dexOrderBookSide, isSigner: false, isWritable: false },
{ pubkey: memory, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, { pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
]; ];