UNPKG

@kamino-finance/kliquidity-sdk

Version:

Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol

119 lines (114 loc) 4.84 kB
import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars import { PROGRAM_ID } from "../programId" export interface SingleTokenDepositAndInvestWithMinArgs { tokenAMinPostDepositBalance: BN tokenBMinPostDepositBalance: BN } export interface SingleTokenDepositAndInvestWithMinAccounts { user: PublicKey strategy: PublicKey globalConfig: PublicKey /** check that the pool is owned either by orca or by raydium */ pool: PublicKey position: PublicKey raydiumProtocolPositionOrBaseVaultAuthority: PublicKey positionTokenAccount: PublicKey tokenAVault: PublicKey tokenBVault: PublicKey poolTokenVaultA: PublicKey poolTokenVaultB: PublicKey tickArrayLower: PublicKey tickArrayUpper: PublicKey baseVaultAuthority: PublicKey tokenAAta: PublicKey tokenBAta: PublicKey tokenAMint: PublicKey tokenBMint: PublicKey userSharesAta: PublicKey sharesMint: PublicKey sharesMintAuthority: PublicKey scopePrices: PublicKey tokenInfos: PublicKey tokenProgram: PublicKey tokenProgram2022: PublicKey tokenATokenProgram: PublicKey tokenBTokenProgram: PublicKey memoProgram: PublicKey poolProgram: PublicKey instructionSysvarAccount: PublicKey eventAuthority: PublicKey } export const layout = borsh.struct([ borsh.u64("tokenAMinPostDepositBalance"), borsh.u64("tokenBMinPostDepositBalance"), ]) export function singleTokenDepositAndInvestWithMin( args: SingleTokenDepositAndInvestWithMinArgs, accounts: SingleTokenDepositAndInvestWithMinAccounts, programId: PublicKey = PROGRAM_ID ) { const keys: Array<AccountMeta> = [ { pubkey: accounts.user, isSigner: true, isWritable: true }, { pubkey: accounts.strategy, isSigner: false, isWritable: true }, { pubkey: accounts.globalConfig, isSigner: false, isWritable: false }, { pubkey: accounts.pool, isSigner: false, isWritable: true }, { pubkey: accounts.position, isSigner: false, isWritable: true }, { pubkey: accounts.raydiumProtocolPositionOrBaseVaultAuthority, isSigner: false, isWritable: true, }, { pubkey: accounts.positionTokenAccount, isSigner: false, isWritable: true, }, { pubkey: accounts.tokenAVault, isSigner: false, isWritable: true }, { pubkey: accounts.tokenBVault, isSigner: false, isWritable: true }, { pubkey: accounts.poolTokenVaultA, isSigner: false, isWritable: true }, { pubkey: accounts.poolTokenVaultB, isSigner: false, isWritable: true }, { pubkey: accounts.tickArrayLower, isSigner: false, isWritable: true }, { pubkey: accounts.tickArrayUpper, isSigner: false, isWritable: true }, { pubkey: accounts.baseVaultAuthority, isSigner: false, isWritable: true }, { pubkey: accounts.tokenAAta, isSigner: false, isWritable: true }, { pubkey: accounts.tokenBAta, isSigner: false, isWritable: true }, { pubkey: accounts.tokenAMint, isSigner: false, isWritable: false }, { pubkey: accounts.tokenBMint, isSigner: false, isWritable: false }, { pubkey: accounts.userSharesAta, isSigner: false, isWritable: true }, { pubkey: accounts.sharesMint, isSigner: false, isWritable: true }, { pubkey: accounts.sharesMintAuthority, isSigner: false, isWritable: false, }, { pubkey: accounts.scopePrices, isSigner: false, isWritable: false }, { pubkey: accounts.tokenInfos, isSigner: false, isWritable: false }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, { pubkey: accounts.tokenProgram2022, isSigner: false, isWritable: false }, { pubkey: accounts.tokenATokenProgram, isSigner: false, isWritable: false }, { pubkey: accounts.tokenBTokenProgram, isSigner: false, isWritable: false }, { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, { pubkey: accounts.poolProgram, isSigner: false, isWritable: false }, { pubkey: accounts.instructionSysvarAccount, isSigner: false, isWritable: false, }, { pubkey: accounts.eventAuthority, isSigner: false, isWritable: false }, ] const identifier = Buffer.from([118, 134, 143, 192, 188, 21, 131, 17]) const buffer = Buffer.alloc(1000) const len = layout.encode( { tokenAMinPostDepositBalance: args.tokenAMinPostDepositBalance, tokenBMinPostDepositBalance: args.tokenBMinPostDepositBalance, }, buffer ) const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) const ix = new TransactionInstruction({ keys, programId, data }) return ix }