UNPKG

@kamino-finance/klend-sdk

Version:

Typescript SDK for interacting with the Kamino Lending (klend) protocol

55 lines (49 loc) 1.67 kB
/* eslint-disable @typescript-eslint/no-unused-vars */ import { Address, isSome, AccountMeta, AccountSignerMeta, Instruction, Option, TransactionSigner, } from "@solana/kit" /* eslint-enable @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 { borshAddress } from "../utils" // 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 const DISCRIMINATOR = Buffer.from([18, 154, 24, 18, 237, 214, 19, 80]) export interface SetFeeArgs { singleUpdateFeeInLamports: BN } export interface SetFeeAccounts { payer: TransactionSigner config: Address } export const layout = borsh.struct<SetFeeArgs>([ borsh.u64("singleUpdateFeeInLamports"), ]) export function setFee( args: SetFeeArgs, accounts: SetFeeAccounts, remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [], programAddress: Address = PROGRAM_ID ) { const keys: Array<AccountMeta | AccountSignerMeta> = [ { address: accounts.payer.address, role: 2, signer: accounts.payer }, { address: accounts.config, role: 1 }, ...remainingAccounts, ] const buffer = Buffer.alloc(1000) const len = layout.encode( { singleUpdateFeeInLamports: args.singleUpdateFeeInLamports, }, buffer ) const data = Buffer.concat([DISCRIMINATOR, buffer]).slice(0, 8 + len) const ix: Instruction = { accounts: keys, programAddress, data } return ix }