@kamino-finance/klend-sdk
Version:
Typescript SDK for interacting with the Kamino Lending (klend) protocol
104 lines • 5.12 kB
JavaScript
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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRepayFlashLoanInstruction = exports.getBorrowFlashLoanInstruction = exports.getFlashLoanInstructions = exports.SOL_MINTS = void 0;
const web3_js_1 = require("@solana/web3.js");
const lib_1 = require("../lib");
const anchor = __importStar(require("@coral-xyz/anchor"));
exports.SOL_MINTS = [
new web3_js_1.PublicKey('So11111111111111111111111111111111111111111'),
new web3_js_1.PublicKey('So11111111111111111111111111111111111111112'),
];
const getFlashLoanInstructions = (args) => {
const flashBorrowIxn = (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 flashRepayIxn = (0, exports.getRepayFlashLoanInstruction)({
borrowIxnIndex: args.borrowIxnIndex,
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 { flashBorrowIxn, flashRepayIxn };
};
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 = ({ borrowIxnIndex, walletPublicKey, lendingMarketAuthority, lendingMarketAddress, reserve, amountLamports, userSourceLiquidity, referrerAccount, referrerTokenState, programId, }) => {
const args = {
borrowInstructionIndex: borrowIxnIndex,
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
;