UNPKG

@kamino-finance/klend-sdk

Version:

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

110 lines 5.25 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getRepayFlashLoanInstruction = exports.getBorrowFlashLoanInstruction = exports.getFlashLoanInstructions = void 0; const web3_js_1 = require("@solana/web3.js"); const anchor = __importStar(require("@coral-xyz/anchor")); const lib_1 = require("../lib"); const getFlashLoanInstructions = (args) => { const flashBorrowIx = (0, exports.getBorrowFlashLoanInstruction)({ walletPublicKey: args.walletPublicKey, lendingMarketAuthority: args.lendingMarketAuthority, lendingMarketAddress: args.lendingMarketAddress, reserve: args.reserve, amountLamports: args.amountLamports, destinationAta: args.destinationAta, referrerAccount: args.referrerAccount, referrerTokenState: args.referrerTokenState, programId: args.programId, }); const flashRepayIx = (0, exports.getRepayFlashLoanInstruction)({ borrowIxIndex: args.borrowIxIndex, walletPublicKey: args.walletPublicKey, lendingMarketAuthority: args.lendingMarketAuthority, lendingMarketAddress: args.lendingMarketAddress, reserve: args.reserve, amountLamports: args.amountLamports, userSourceLiquidity: args.destinationAta, referrerAccount: args.referrerAccount, referrerTokenState: args.referrerTokenState, programId: args.programId, }); return { flashBorrowIx, flashRepayIx }; }; exports.getFlashLoanInstructions = getFlashLoanInstructions; const getBorrowFlashLoanInstruction = ({ walletPublicKey, lendingMarketAuthority, lendingMarketAddress, reserve, amountLamports, destinationAta, referrerAccount, referrerTokenState, programId, }) => { const args = { liquidityAmount: new anchor.BN(amountLamports.floor().toString()), }; const accounts = { userTransferAuthority: walletPublicKey, lendingMarketAuthority: lendingMarketAuthority, lendingMarket: lendingMarketAddress, reserve: reserve.address, reserveLiquidityMint: reserve.getLiquidityMint(), reserveSourceLiquidity: reserve.state.liquidity.supplyVault, userDestinationLiquidity: destinationAta, referrerAccount: referrerAccount, referrerTokenState: referrerTokenState, reserveLiquidityFeeReceiver: reserve.state.liquidity.feeVault, sysvarInfo: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, tokenProgram: reserve.getLiquidityTokenProgram(), }; return (0, lib_1.flashBorrowReserveLiquidity)(args, accounts, programId); }; exports.getBorrowFlashLoanInstruction = getBorrowFlashLoanInstruction; const getRepayFlashLoanInstruction = ({ borrowIxIndex, walletPublicKey, lendingMarketAuthority, lendingMarketAddress, reserve, amountLamports, userSourceLiquidity, referrerAccount, referrerTokenState, programId, }) => { const args = { borrowInstructionIndex: borrowIxIndex, liquidityAmount: new anchor.BN(amountLamports.floor().toString()), }; const accounts = { userTransferAuthority: walletPublicKey, lendingMarketAuthority: lendingMarketAuthority, lendingMarket: lendingMarketAddress, reserve: reserve.address, reserveLiquidityMint: reserve.getLiquidityMint(), reserveDestinationLiquidity: reserve.state.liquidity.supplyVault, userSourceLiquidity: userSourceLiquidity, referrerAccount: referrerAccount, referrerTokenState: referrerTokenState, reserveLiquidityFeeReceiver: reserve.state.liquidity.feeVault, sysvarInfo: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, tokenProgram: reserve.getLiquidityTokenProgram(), }; return (0, lib_1.flashRepayReserveLiquidity)(args, accounts, programId); }; exports.getRepayFlashLoanInstruction = getRepayFlashLoanInstruction; //# sourceMappingURL=instructions.js.map