import { TOKEN_PROGRAM_ID } from '@solana/spl-token' ; import { PublicKey , SYSVAR_CLOCK_PUBKEY , TransactionInstruction , } from '@solana/web3.js' ; import { nu64 , struct , u8 } from 'buffer-layout' ; export function addLiquidityInstructionV4 ( programId , ammId , ammAuthority , ammOpenOrders , ammTargetOrders , lpMintAddress , poolCoinTokenAccount , poolPcTokenAccount , serumMarket , userCoinTokenAccount , userPcTokenAccount , userLpTokenAccount , userOwner , maxCoinAmount , maxPcAmount , fixedFromCoin ) { const dataLayout = struct ( [ u8 ( 'instruction' ) , nu64 ( 'maxCoinAmount' ) , nu64 ( 'maxPcAmount' ) , nu64 ( 'fixedFromCoin' ) , ] ) ; const keys = [ { pubkey : TOKEN_PROGRAM_ID , isSigner : false , isWritable : false } , { pubkey : ammId , isSigner : false , isWritable : true } , { pubkey : ammAuthority , isSigner : false , isWritable : false } , { pubkey : ammOpenOrders , isSigner : false , isWritable : false } , { pubkey : ammTargetOrders , isSigner : false , isWritable : true } , { pubkey : lpMintAddress , isSigner : false , isWritable : true } , { pubkey : poolCoinTokenAccount , isSigner : false , isWritable : true } , { pubkey : poolPcTokenAccount , isSigner : false , isWritable : true } , { pubkey : serumMarket , isSigner : false , isWritable : false } , { pubkey : userCoinTokenAccount , isSigner : false , isWritable : true } , { pubkey : userPcTokenAccount , isSigner : false , isWritable : true } , { pubkey : userLpTokenAccount , isSigner : false , isWritable : true } , { pubkey : userOwner , isSigner : true , isWritable : false } , ] ; const data = Buffer . alloc ( dataLayout . span ) ; dataLayout . encode ( { instruction : 3 , maxCoinAmount , maxPcAmount , fixedFromCoin , } , data ) ; return new TransactionInstruction ( { keys , programId , data , } ) ; } export function depositInstructionV4 ( programId , poolId , poolAuthority , userInfoAccount , userOwner , userLpTokenAccount , poolLpTokenAccount , userRewardTokenAccount , poolRewardTokenAccount , userRewardTokenAccountB , poolRewardTokenAccountB , amount ) { const dataLayout = struct ( [ u8 ( 'instruction' ) , nu64 ( 'amount' ) ] ) ; const keys = [ { pubkey : poolId , isSigner : false , isWritable : true } , { pubkey : poolAuthority , isSigner : false , isWritable : true } , { pubkey : userInfoAccount , isSigner : false , isWritable : true } , { pubkey : userOwner , isSigner : true , isWritable : true } , { pubkey : userLpTokenAccount , isSigner : false , isWritable : true } , { pubkey : poolLpTokenAccount , isSigner : false , isWritable : true } , { pubkey : userRewardTokenAccount , isSigner : false , isWritable : true } , { pubkey : poolRewardTokenAccount , isSigner : false , isWritable : true } , { pubkey : SYSVAR_CLOCK_PUBKEY , isSigner : false , isWritable : true } , { pubkey : TOKEN_PROGRAM_ID , isSigner : false , isWritable : true } , { pubkey : userRewardTokenAccountB , isSigner : false , isWritable : true } , { pubkey : poolRewardTokenAccountB , isSigner : false , isWritable : true } , ] ; const data = Buffer . alloc ( dataLayout . span ) ; dataLayout . encode ( { instruction : 1 , amount , } , data ) ; return new TransactionInstruction ( { keys , programId , data , } ) ; } export function depositInstruction ( programId , poolId , poolAuthority , userInfoAccount , userOwner , userLpTokenAccount , poolLpTokenAccount , userRewardTokenAccount , poolRewardTokenAccount , amount ) { const dataLayout = struct ( [ u8 ( 'instruction' ) , nu64 ( 'amount' ) ] ) ; const keys = [ { pubkey : poolId , isSigner : false , isWritable : true } , { pubkey : poolAuthority , isSigner : false , isWritable : false } , { pubkey : userInfoAccount , isSigner : false , isWritable : true } , { pubkey : userOwner , isSigner : true , isWritable : false } , { pubkey : userLpTokenAccount , isSigner : false , isWritable : true } , { pubkey : poolLpTokenAccount , isSigner : false , isWritable : true } , { pubkey : userRewardTokenAccount , isSigner : false , isWritable : true } , { pubkey : poolRewardTokenAccount , isSigner : false , isWritable : true } , { pubkey : SYSVAR_CLOCK_PUBKEY , isSigner : false , isWritable : false } , { pubkey : TOKEN_PROGRAM_ID , isSigner : false , isWritable : false } , ] ; const data = Buffer . alloc ( dataLayout . span ) ; dataLayout . encode ( { instruction : 1 , amount , } , data ) ; return new TransactionInstruction ( { keys , programId , data , } ) ; }