@kamino-finance/klend-sdk 3.2.20 → 3.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,6 @@ export declare function sendTransactionV0(connection: Connection, payer: Keypair
17
17
  export declare function simulateTransactionV0(connection: Connection, payer: Keypair, instructions: TransactionInstruction[], lookupTables?: AddressLookupTableAccount[] | undefined): Promise<import("@solana/web3.js").RpcResponseAndContext<import("@solana/web3.js").SimulatedTransactionResponse>>;
18
18
  export declare const buildVersionedTransaction: (connection: Connection, payer: PublicKey, instructions: TransactionInstruction[], lookupTables?: PublicKey[]) => Promise<VersionedTransaction>;
19
19
  export declare const getLookupTableAccount: (connection: Connection, address: PublicKey) => Promise<AddressLookupTableAccount | null>;
20
- export declare const getLookupTableAccounts: (connection: Connection, addresses: PublicKey[]) => Promise<AddressLookupTableAccount[]>;
20
+ export declare function getLookupTableAccounts(connection: Connection, addresses: PublicKey[]): Promise<AddressLookupTableAccount[]>;
21
21
  export declare const getComputeBudgetAndPriorityFeeIxns: (units: number, priorityFeeLamports?: Decimal) => TransactionInstruction[];
22
22
  export declare function notEmpty<TValue>(value: TValue | null | undefined): value is TValue;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getComputeBudgetAndPriorityFeeIxns = exports.getLookupTableAccounts = exports.getLookupTableAccount = exports.buildVersionedTransaction = void 0;
12
+ exports.getComputeBudgetAndPriorityFeeIxns = exports.getLookupTableAccount = exports.buildVersionedTransaction = void 0;
13
13
  exports.buildAndSendTxnWithLogs = buildAndSendTxnWithLogs;
14
14
  exports.buildAndSendTxn = buildAndSendTxn;
15
15
  exports.sendAndConfirmVersionedTransaction = sendAndConfirmVersionedTransaction;
@@ -17,10 +17,12 @@ exports.simulateTxn = simulateTxn;
17
17
  exports.buildComputeBudgetIx = buildComputeBudgetIx;
18
18
  exports.sendTransactionV0 = sendTransactionV0;
19
19
  exports.simulateTransactionV0 = simulateTransactionV0;
20
+ exports.getLookupTableAccounts = getLookupTableAccounts;
20
21
  exports.notEmpty = notEmpty;
21
22
  const web3_js_1 = require("@solana/web3.js");
22
23
  const errors_1 = require("../idl_codegen/errors");
23
24
  const utils_1 = require("../classes/utils");
25
+ const kliquidity_sdk_1 = require("@kamino-finance/kliquidity-sdk");
24
26
  function buildAndSendTxnWithLogs(c_1, tx_1, owner_1, signers_1) {
25
27
  return __awaiter(this, arguments, void 0, function* (c, tx, owner, signers, withLogsIfSuccess = false, withDescription = '') {
26
28
  var _a;
@@ -172,19 +174,23 @@ const getLookupTableAccount = (connection, address) => __awaiter(void 0, void 0,
172
174
  return connection.getAddressLookupTable(address).then((res) => res.value);
173
175
  });
174
176
  exports.getLookupTableAccount = getLookupTableAccount;
175
- const getLookupTableAccounts = (connection, addresses) => __awaiter(void 0, void 0, void 0, function* () {
176
- const lookupTableAccounts = [];
177
- for (const address of addresses) {
178
- const lookupTableAccount = yield connection.getAddressLookupTable(address).then((res) => res.value);
179
- if (!lookupTableAccount) {
180
- console.error('lookup table is not found');
181
- throw new Error('lookup table is not found');
177
+ function getLookupTableAccounts(connection, addresses) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ const lookupTableAccounts = [];
180
+ const accountInfos = yield (0, kliquidity_sdk_1.batchFetch)(addresses, (batch) => connection.getMultipleAccountsInfo(batch));
181
+ for (let i = 0; i < addresses.length; i++) {
182
+ const info = accountInfos[i];
183
+ if (!info) {
184
+ throw new Error(`Lookup table ${addresses[i]} is not found`);
185
+ }
186
+ lookupTableAccounts.push(new web3_js_1.AddressLookupTableAccount({
187
+ key: addresses[i],
188
+ state: web3_js_1.AddressLookupTableAccount.deserialize(info.data),
189
+ }));
182
190
  }
183
- lookupTableAccounts.push(lookupTableAccount);
184
- }
185
- return lookupTableAccounts;
186
- });
187
- exports.getLookupTableAccounts = getLookupTableAccounts;
191
+ return lookupTableAccounts;
192
+ });
193
+ }
188
194
  const getComputeBudgetAndPriorityFeeIxns = (units, priorityFeeLamports) => {
189
195
  const ixns = [];
190
196
  ixns.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units }));
@@ -1 +1 @@
1
- {"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/utils/instruction.ts"],"names":[],"mappings":";;;;;;;;;;;;AAsBA,0DAoCC;AAED,0CAWC;AAED,gFA6BC;AAED,kCAmBC;AAED,oDAEC;AAUD,8CAsBC;AAED,sDAqBC;AA4DD,4BAQC;AAxPD,6CAgByB;AACzB,kDAAoD;AACpD,4CAAyC;AAEzC,SAAsB,uBAAuB;yDAC3C,CAAa,EACb,EAAwB,EACxB,KAAc,EACd,OAAiB,EACjB,oBAA6B,KAAK,EAClC,kBAA0B,EAAE;;QAE5B,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;QAE7B,IAAI,CAAC;YACH,MAAM,GAAG,GAAW,MAAM,kCAAkC,CAAC,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE;gBAC/E,mBAAmB,EAAE,WAAW;aACjC,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC;YACvD,IAAI,iBAAiB,EAAE,CAAC;gBACtB,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;gBAClB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE;oBACtC,UAAU,EAAE,WAAW;oBACvB,8BAA8B,EAAE,CAAC;iBAClC,CAAC,CAAC;gBACH,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,WAAW,CAAC,CAAC;YAC7D,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,CAAM,EAAE,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AsB,0BAajC;AAEK,MAAM,kCAAkC,GAAG,CAChD,KAAa,EACb,mBAA6B,EACH,EAAE;IAC5B,MAAM,IAAI,GAA6B,EAAE,CAAC;IAC1C,IAAI,CAAC,IAAI,CAAC,8BAAoB,CAAC,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAE/D,IAAI,mBAAmB,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,MAAM,SAAS,GAAG,mBAAmB,CAAC,GAAG,CAAC,SAAA,EAAE,EAAI,CAAC,CAAA,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,CAAC,8BAAoB,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/G,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAbW,QAAA,kCAAkC,sCAa7C;AAEF,2DAA2D;AAC3D,SAAgB,QAAQ,CAAS,KAAgC;IAC/D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,EAAE;IACF,4EAA4E;IAC5E,MAAM,SAAS,GAAW,KAAK,CAAC;IAChC,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import Decimal from 'decimal.js';\n\nimport {\n AddressLookupTableAccount,\n Commitment,\n ComputeBudgetProgram,\n Connection,\n Keypair,\n PublicKey,\n SendOptions,\n Signer,\n Transaction,\n TransactionInstruction,\n TransactionMessage,\n TransactionResponse,\n TransactionSignature,\n VersionedTransaction,\n VersionedTransactionResponse,\n} from '@solana/web3.js';\nimport { fromTxError } from '../idl_codegen/errors';\nimport { sleep } from '../classes/utils';\n\nexport async function buildAndSendTxnWithLogs(\n c: Connection,\n tx: VersionedTransaction,\n owner: Keypair,\n signers: Signer[],\n withLogsIfSuccess: boolean = false,\n withDescription: string = ''\n): Promise<TransactionSignature> {\n tx.sign([owner, ...signers]);\n\n try {\n const sig: string = await sendAndConfirmVersionedTransaction(c, tx, 'confirmed', {\n preflightCommitment: 'processed',\n });\n console.log('Transaction Hash:', withDescription, sig);\n if (withLogsIfSuccess) {\n await sleep(5000);\n const res = await c.getTransaction(sig, {\n commitment: 'confirmed',\n maxSupportedTransactionVersion: 6,\n });\n console.log('Transaction Logs:\\n', res?.meta?.logMessages);\n }\n return sig;\n } catch (e: any) {\n console.log(e);\n process.stdout.write(e.logs.toString());\n await sleep(5000);\n const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];\n const res: VersionedTransactionResponse | null = await c.getTransaction(sig, {\n commitment: 'confirmed',\n maxSupportedTransactionVersion: 6,\n });\n console.log('Txn', res!.meta!.logMessages);\n return sig;\n }\n}\n\nexport async function buildAndSendTxn(\n c: Connection,\n owner: Keypair,\n ixns: TransactionInstruction[],\n signers: Signer[],\n lutAddresses: PublicKey[] = [],\n description: string = ''\n): Promise<TransactionSignature> {\n const tx = await buildVersionedTransaction(c, owner.publicKey, ixns, lutAddresses);\n\n return await buildAndSendTxnWithLogs(c, tx, owner, signers, true, description);\n}\n\nexport async function sendAndConfirmVersionedTransaction(\n c: Connection,\n tx: VersionedTransaction,\n commitment: Commitment = 'confirmed',\n sendTransactionOptions: SendOptions = { preflightCommitment: 'processed' }\n) {\n const defaultOptions: SendOptions = { skipPreflight: true };\n const txId = await c.sendTransaction(tx, { ...defaultOptions, ...sendTransactionOptions });\n\n const latestBlockHash = await c.getLatestBlockhash('finalized');\n const t = await c.confirmTransaction(\n {\n blockhash: latestBlockHash.blockhash,\n lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,\n signature: txId,\n },\n commitment\n );\n if (t.value && t.value.err) {\n const txDetails = await c.getTransaction(txId, {\n maxSupportedTransactionVersion: 0,\n commitment: 'confirmed',\n });\n if (txDetails) {\n throw { err: txDetails.meta?.err, logs: txDetails.meta?.logMessages || [] };\n }\n throw t.value.err;\n }\n return txId;\n}\n\nexport async function simulateTxn(c: Connection, tx: Transaction, owner: Keypair, signers: Signer[]) {\n const { blockhash } = await c.getLatestBlockhash();\n tx.recentBlockhash = blockhash;\n tx.feePayer = owner.publicKey;\n\n try {\n const simulation = await c.simulateTransaction(tx, [owner, ...signers]);\n console.log('Transaction Hash:', simulation);\n } catch (e: any) {\n console.log(e);\n process.stdout.write(e.logs.toString());\n await sleep(5000);\n const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];\n const res: TransactionResponse | null = await c.getTransaction(sig, {\n commitment: 'confirmed',\n });\n console.log('Txn', res!.meta!.logMessages);\n return sig;\n }\n}\n\nexport function buildComputeBudgetIx(units: number): TransactionInstruction {\n return ComputeBudgetProgram.setComputeUnitLimit({ units });\n}\n\n/**\n * Send a transaction with optional address lookup tables\n * Translates anchor errors into anchor error types\n * @param connection\n * @param payer\n * @param instructions\n * @param lookupTables\n */\nexport async function sendTransactionV0(\n connection: Connection,\n payer: Keypair,\n instructions: TransactionInstruction[],\n lookupTables: AddressLookupTableAccount[] | undefined = undefined,\n options?: SendOptions\n): Promise<string> {\n const recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n\n const messageV0 = new TransactionMessage({\n payerKey: payer.publicKey,\n recentBlockhash,\n instructions,\n }).compileToV0Message(lookupTables);\n\n const tx = new VersionedTransaction(messageV0);\n tx.sign([payer]);\n try {\n return await connection.sendTransaction(tx, options);\n } catch (err) {\n throw fromTxError(err) ?? err;\n }\n}\n\nexport async function simulateTransactionV0(\n connection: Connection,\n payer: Keypair,\n instructions: TransactionInstruction[],\n lookupTables: AddressLookupTableAccount[] | undefined = undefined\n) {\n const recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n\n const messageV0 = new TransactionMessage({\n payerKey: payer.publicKey,\n recentBlockhash,\n instructions,\n }).compileToV0Message(lookupTables);\n\n const tx = new VersionedTransaction(messageV0);\n tx.sign([payer]);\n try {\n return await connection.simulateTransaction(tx);\n } catch (err) {\n throw fromTxError(err) ?? err;\n }\n}\n\nexport const buildVersionedTransaction = async (\n connection: Connection,\n payer: PublicKey,\n instructions: TransactionInstruction[],\n lookupTables: PublicKey[] = []\n): Promise<VersionedTransaction> => {\n const blockhash = await connection.getLatestBlockhash('confirmed').then((res) => res.blockhash);\n\n const lookupTablesAccounts = await Promise.all(\n lookupTables.map((address) => {\n return getLookupTableAccount(connection, address);\n })\n );\n\n const messageV0 = new TransactionMessage({\n payerKey: payer,\n recentBlockhash: blockhash,\n instructions,\n }).compileToV0Message(lookupTablesAccounts.filter(notEmpty));\n\n return new VersionedTransaction(messageV0);\n};\n\nexport const getLookupTableAccount = async (connection: Connection, address: PublicKey) => {\n return connection.getAddressLookupTable(address).then((res) => res.value);\n};\n\nexport const getLookupTableAccounts = async (connection: Connection, addresses: PublicKey[]) => {\n const lookupTableAccounts: AddressLookupTableAccount[] = [];\n for (const address of addresses) {\n const lookupTableAccount = await connection.getAddressLookupTable(address).then((res) => res.value);\n\n if (!lookupTableAccount) {\n console.error('lookup table is not found');\n throw new Error('lookup table is not found');\n }\n\n lookupTableAccounts.push(lookupTableAccount);\n }\n return lookupTableAccounts;\n};\n\nexport const getComputeBudgetAndPriorityFeeIxns = (\n units: number,\n priorityFeeLamports?: Decimal\n): TransactionInstruction[] => {\n const ixns: TransactionInstruction[] = [];\n ixns.push(ComputeBudgetProgram.setComputeUnitLimit({ units }));\n\n if (priorityFeeLamports && priorityFeeLamports.gt(0)) {\n const unitPrice = priorityFeeLamports.mul(10 ** 6).div(units);\n ixns.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: BigInt(unitPrice.floor().toString()) }));\n }\n\n return ixns;\n};\n\n// filters null values from array and make typescript happy\nexport function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {\n if (value === null || value === undefined) {\n return false;\n }\n //\n // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars\n const testDummy: TValue = value;\n return true;\n}\n"]}
1
+ {"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/utils/instruction.ts"],"names":[],"mappings":";;;;;;;;;;;;AAuBA,0DAoCC;AAED,0CAWC;AAED,gFA6BC;AAED,kCAmBC;AAED,oDAEC;AAUD,8CAsBC;AAED,sDAqBC;AA6BD,wDAmBC;AAkBD,4BAQC;AA/PD,6CAgByB;AACzB,kDAAoD;AACpD,4CAAyC;AACzC,mEAA4D;AAE5D,SAAsB,uBAAuB;yDAC3C,CAAa,EACb,EAAwB,EACxB,KAAc,EACd,OAAiB,EACjB,oBAA6B,KAAK,EAClC,kBAA0B,EAAE;;QAE5B,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;QAE7B,IAAI,CAAC;YACH,MAAM,GAAG,GAAW,MAAM,kCAAkC,CAAC,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE;gBAC/E,mBAAmB,EAAE,WAAW;aACjC,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC;YACvD,IAAI,iBAAiB,EAAE,CAAC;gBACtB,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;gBAClB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE;oBACtC,UAAU,EAAE,WAAW;oBACvB,8BAA8B,EAAE,CAAC;iBAClC,CAAC,CAAC;gBACH,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,WAAW,CAAC,CAAC;YAC7D,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,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C;QACJ,CAAC;QACD,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CAAA;AAEM,MAAM,kCAAkC,GAAG,CAChD,KAAa,EACb,mBAA6B,EACH,EAAE;IAC5B,MAAM,IAAI,GAA6B,EAAE,CAAC;IAC1C,IAAI,CAAC,IAAI,CAAC,8BAAoB,CAAC,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAE/D,IAAI,mBAAmB,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,MAAM,SAAS,GAAG,mBAAmB,CAAC,GAAG,CAAC,SAAA,EAAE,EAAI,CAAC,CAAA,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,CAAC,8BAAoB,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/G,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAbW,QAAA,kCAAkC,sCAa7C;AAEF,2DAA2D;AAC3D,SAAgB,QAAQ,CAAS,KAAgC;IAC/D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,EAAE;IACF,4EAA4E;IAC5E,MAAM,SAAS,GAAW,KAAK,CAAC;IAChC,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import Decimal from 'decimal.js';\n\nimport {\n AddressLookupTableAccount,\n Commitment,\n ComputeBudgetProgram,\n Connection,\n Keypair,\n PublicKey,\n SendOptions,\n Signer,\n Transaction,\n TransactionInstruction,\n TransactionMessage,\n TransactionResponse,\n TransactionSignature,\n VersionedTransaction,\n VersionedTransactionResponse,\n} from '@solana/web3.js';\nimport { fromTxError } from '../idl_codegen/errors';\nimport { sleep } from '../classes/utils';\nimport { batchFetch } from '@kamino-finance/kliquidity-sdk';\n\nexport async function buildAndSendTxnWithLogs(\n c: Connection,\n tx: VersionedTransaction,\n owner: Keypair,\n signers: Signer[],\n withLogsIfSuccess: boolean = false,\n withDescription: string = ''\n): Promise<TransactionSignature> {\n tx.sign([owner, ...signers]);\n\n try {\n const sig: string = await sendAndConfirmVersionedTransaction(c, tx, 'confirmed', {\n preflightCommitment: 'processed',\n });\n console.log('Transaction Hash:', withDescription, sig);\n if (withLogsIfSuccess) {\n await sleep(5000);\n const res = await c.getTransaction(sig, {\n commitment: 'confirmed',\n maxSupportedTransactionVersion: 6,\n });\n console.log('Transaction Logs:\\n', res?.meta?.logMessages);\n }\n return sig;\n } catch (e: any) {\n console.log(e);\n process.stdout.write(e.logs.toString());\n await sleep(5000);\n const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];\n const res: VersionedTransactionResponse | null = await c.getTransaction(sig, {\n commitment: 'confirmed',\n maxSupportedTransactionVersion: 6,\n });\n console.log('Txn', res!.meta!.logMessages);\n return sig;\n }\n}\n\nexport async function buildAndSendTxn(\n c: Connection,\n owner: Keypair,\n ixns: TransactionInstruction[],\n signers: Signer[],\n lutAddresses: PublicKey[] = [],\n description: string = ''\n): Promise<TransactionSignature> {\n const tx = await buildVersionedTransaction(c, owner.publicKey, ixns, lutAddresses);\n\n return await buildAndSendTxnWithLogs(c, tx, owner, signers, true, description);\n}\n\nexport async function sendAndConfirmVersionedTransaction(\n c: Connection,\n tx: VersionedTransaction,\n commitment: Commitment = 'confirmed',\n sendTransactionOptions: SendOptions = { preflightCommitment: 'processed' }\n) {\n const defaultOptions: SendOptions = { skipPreflight: true };\n const txId = await c.sendTransaction(tx, { ...defaultOptions, ...sendTransactionOptions });\n\n const latestBlockHash = await c.getLatestBlockhash('finalized');\n const t = await c.confirmTransaction(\n {\n blockhash: latestBlockHash.blockhash,\n lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,\n signature: txId,\n },\n commitment\n );\n if (t.value && t.value.err) {\n const txDetails = await c.getTransaction(txId, {\n maxSupportedTransactionVersion: 0,\n commitment: 'confirmed',\n });\n if (txDetails) {\n throw { err: txDetails.meta?.err, logs: txDetails.meta?.logMessages || [] };\n }\n throw t.value.err;\n }\n return txId;\n}\n\nexport async function simulateTxn(c: Connection, tx: Transaction, owner: Keypair, signers: Signer[]) {\n const { blockhash } = await c.getLatestBlockhash();\n tx.recentBlockhash = blockhash;\n tx.feePayer = owner.publicKey;\n\n try {\n const simulation = await c.simulateTransaction(tx, [owner, ...signers]);\n console.log('Transaction Hash:', simulation);\n } catch (e: any) {\n console.log(e);\n process.stdout.write(e.logs.toString());\n await sleep(5000);\n const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];\n const res: TransactionResponse | null = await c.getTransaction(sig, {\n commitment: 'confirmed',\n });\n console.log('Txn', res!.meta!.logMessages);\n return sig;\n }\n}\n\nexport function buildComputeBudgetIx(units: number): TransactionInstruction {\n return ComputeBudgetProgram.setComputeUnitLimit({ units });\n}\n\n/**\n * Send a transaction with optional address lookup tables\n * Translates anchor errors into anchor error types\n * @param connection\n * @param payer\n * @param instructions\n * @param lookupTables\n */\nexport async function sendTransactionV0(\n connection: Connection,\n payer: Keypair,\n instructions: TransactionInstruction[],\n lookupTables: AddressLookupTableAccount[] | undefined = undefined,\n options?: SendOptions\n): Promise<string> {\n const recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n\n const messageV0 = new TransactionMessage({\n payerKey: payer.publicKey,\n recentBlockhash,\n instructions,\n }).compileToV0Message(lookupTables);\n\n const tx = new VersionedTransaction(messageV0);\n tx.sign([payer]);\n try {\n return await connection.sendTransaction(tx, options);\n } catch (err) {\n throw fromTxError(err) ?? err;\n }\n}\n\nexport async function simulateTransactionV0(\n connection: Connection,\n payer: Keypair,\n instructions: TransactionInstruction[],\n lookupTables: AddressLookupTableAccount[] | undefined = undefined\n) {\n const recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n\n const messageV0 = new TransactionMessage({\n payerKey: payer.publicKey,\n recentBlockhash,\n instructions,\n }).compileToV0Message(lookupTables);\n\n const tx = new VersionedTransaction(messageV0);\n tx.sign([payer]);\n try {\n return await connection.simulateTransaction(tx);\n } catch (err) {\n throw fromTxError(err) ?? err;\n }\n}\n\nexport const buildVersionedTransaction = async (\n connection: Connection,\n payer: PublicKey,\n instructions: TransactionInstruction[],\n lookupTables: PublicKey[] = []\n): Promise<VersionedTransaction> => {\n const blockhash = await connection.getLatestBlockhash('confirmed').then((res) => res.blockhash);\n\n const lookupTablesAccounts = await Promise.all(\n lookupTables.map((address) => {\n return getLookupTableAccount(connection, address);\n })\n );\n\n const messageV0 = new TransactionMessage({\n payerKey: payer,\n recentBlockhash: blockhash,\n instructions,\n }).compileToV0Message(lookupTablesAccounts.filter(notEmpty));\n\n return new VersionedTransaction(messageV0);\n};\n\nexport const getLookupTableAccount = async (connection: Connection, address: PublicKey) => {\n return connection.getAddressLookupTable(address).then((res) => res.value);\n};\n\nexport async function getLookupTableAccounts(\n connection: Connection,\n addresses: PublicKey[]\n): Promise<AddressLookupTableAccount[]> {\n const lookupTableAccounts: AddressLookupTableAccount[] = [];\n const accountInfos = await batchFetch(addresses, (batch) => connection.getMultipleAccountsInfo(batch));\n for (let i = 0; i < addresses.length; i++) {\n const info = accountInfos[i];\n if (!info) {\n throw new Error(`Lookup table ${addresses[i]} is not found`);\n }\n lookupTableAccounts.push(\n new AddressLookupTableAccount({\n key: addresses[i],\n state: AddressLookupTableAccount.deserialize(info.data),\n })\n );\n }\n return lookupTableAccounts;\n}\n\nexport const getComputeBudgetAndPriorityFeeIxns = (\n units: number,\n priorityFeeLamports?: Decimal\n): TransactionInstruction[] => {\n const ixns: TransactionInstruction[] = [];\n ixns.push(ComputeBudgetProgram.setComputeUnitLimit({ units }));\n\n if (priorityFeeLamports && priorityFeeLamports.gt(0)) {\n const unitPrice = priorityFeeLamports.mul(10 ** 6).div(units);\n ixns.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: BigInt(unitPrice.floor().toString()) }));\n }\n\n return ixns;\n};\n\n// filters null values from array and make typescript happy\nexport function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {\n if (value === null || value === undefined) {\n return false;\n }\n //\n // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars\n const testDummy: TValue = value;\n return true;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamino-finance/klend-sdk",
3
- "version": "3.2.20",
3
+ "version": "3.2.22",
4
4
  "description": "Typescript SDK for interacting with the Kamino Lending (klend) protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,7 +45,7 @@
45
45
  "@bokuweb/zstd-wasm": "^0.0.20",
46
46
  "@coral-xyz/anchor": "^0.28.0",
47
47
  "@coral-xyz/borsh": "^0.28.0",
48
- "@hubbleprotocol/farms-sdk": "^0.11.0",
48
+ "@hubbleprotocol/farms-sdk": "^1.0.3",
49
49
  "@hubbleprotocol/scope-sdk": "^5.0.20",
50
50
  "@kamino-finance/kliquidity-sdk": "^6.1.0",
51
51
  "@pythnetwork/client": "^2.5.1",
@@ -96,7 +96,7 @@
96
96
  },
97
97
  "resolutions": {
98
98
  "@kamino-finance/kliquidity-sdk": "^6.1.0",
99
- "@hubbleprotocol/farms-sdk": "^0.11.0"
99
+ "@hubbleprotocol/farms-sdk": "^1.0.3"
100
100
  },
101
101
  "packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
102
102
  }