UNPKG

@mercurial-finance/frakt-sdk

Version:

Frakt SDK for interacting with frakt.xyz protocols

1 lines 243 kB
{"version":3,"sources":["../src/common/constants.ts","../src/common/index.ts","../src/common/classes/nodewallet.ts","../src/loans/index.ts","../src/loans/functions/private/approveLoanByAdmin.ts","../src/loans/helpers.ts","../src/loans/constants.ts","../src/loans/functions/private/closeLoanByAdmin.ts","../src/loans/functions/private/initializeCollectionInfo.ts","../src/loans/functions/private/initializePriceBasedLiquidityPool.ts","../src/loans/functions/private/initializeTimeBasedLiquidityPool.ts","../src/loans/functions/private/liquidateLoanByAdmin.ts","../src/loans/functions/private/revealLotTicketByAdmin.ts","../src/loans/functions/private/rejectLoanByAdmin.ts","../src/loans/functions/private/updateCollectionInfo.ts","../src/loans/functions/private/updatePriceBasedLiquidityPool.ts","../src/loans/functions/private/updateTimeBasedLiquidityPool.ts","../src/loans/functions/private/liquidateLoanToRaffles.ts","../src/loans/functions/private/stopLiquidationRaffles.ts","../src/loans/functions/private/unstakeGemFarmByAdmin.ts","../src/loans/functions/private/putLoanToLiquidationRaffles.ts","../src/loans/functions/public/depositLiquidity.ts","../src/loans/functions/public/getAllProgramAccounts.ts","../src/loans/functions/public/harvestLiquidity.ts","../src/loans/functions/public/paybackLoan.ts","../src/loans/functions/public/paybackLoanIx.ts","../src/loans/functions/public/proposeLoan.ts","../src/loans/functions/public/unstakeLiquidity.ts","../src/loans/functions/public/redeemWinningLotTicket.ts","../src/loans/functions/public/getLotTicket.ts","../src/loans/functions/public/initializeNftAttemptsByStaking.ts","../src/loans/functions/public/getLotTicketByStaking.ts","../src/loans/functions/public/paybackLoanWithGrace.ts","../src/loans/functions/public/paybackLoanWithGraceIx.ts","../src/loans/functions/public/stakeGemFarm.ts","../src/loans/functions/public/unstakeGemFarm.ts","../src/loans/functions/public/unstakeGemFarmIx.ts","../src/loans/functions/public/claimGemFarm.ts","../src/loans/functions/public/claimGemFarmIx.ts","../src/loans/functions/public/calculateRewardDegod.ts","../src/loans/functions/public/getAllFarmAccounts.ts","../src/loans/idl/idl-gem-farm.ts","../src/loans/functions/public/getFarmAccount.ts","../src/index.ts"],"sourcesContent":["import { TokenInfo } from './types';\n\nexport const SOL_TOKEN: TokenInfo = {\n chainId: 101,\n address: 'So11111111111111111111111111111111111111112',\n name: 'SOL',\n decimals: 9,\n symbol: 'SOL',\n logoURI:\n 'https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png',\n extensions: {\n coingeckoId: 'solana',\n },\n};\n","import { web3, utils } from '@project-serum/anchor';\n\nimport { NodeWallet } from './classes/nodewallet';\nimport { BulkNft, BulkNftRaw } from './types';\n\n//when we only want to view vaults, no need to connect a real wallet.\nexport const createFakeWallet = () => {\n const leakedKp = web3.Keypair.fromSecretKey(\n Uint8Array.from([\n 208, 175, 150, 242, 88, 34, 108, 88, 177, 16, 168, 75, 115, 181, 199, 242, 120, 4, 78, 75, 19, 227, 13, 215, 184,\n 108, 226, 53, 111, 149, 179, 84, 137, 121, 79, 1, 160, 223, 124, 241, 202, 203, 220, 237, 50, 242, 57, 158, 226,\n 207, 203, 188, 43, 28, 70, 110, 214, 234, 251, 15, 249, 157, 62, 80,\n ]),\n );\n return new NodeWallet(leakedKp);\n};\n\nexport const findAssociatedTokenAddress = async (\n walletAddress: web3.PublicKey,\n tokenMintAddress: web3.PublicKey,\n): Promise<web3.PublicKey> =>\n (\n await web3.PublicKey.findProgramAddress(\n [walletAddress.toBuffer(), utils.token.TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],\n utils.token.ASSOCIATED_PROGRAM_ID,\n )\n )[0];\n\nexport const getTokenBalance = async (pubkey: web3.PublicKey, connection: web3.Connection) => {\n const balance = await connection.getTokenAccountBalance(pubkey);\n\n return parseInt(balance.value.amount);\n};\n\nexport const createAssociatedTokenAccountInstruction = (\n associatedTokenAddress: web3.PublicKey,\n payer: web3.PublicKey,\n walletAddress: web3.PublicKey,\n splTokenMintAddress: web3.PublicKey,\n): web3.TransactionInstruction[] => {\n const keys = [\n {\n pubkey: payer,\n isSigner: true,\n isWritable: true,\n },\n {\n pubkey: associatedTokenAddress,\n isSigner: false,\n isWritable: true,\n },\n {\n pubkey: walletAddress,\n isSigner: false,\n isWritable: false,\n },\n {\n pubkey: splTokenMintAddress,\n isSigner: false,\n isWritable: false,\n },\n {\n pubkey: web3.SystemProgram.programId,\n isSigner: false,\n isWritable: false,\n },\n {\n pubkey: utils.token.TOKEN_PROGRAM_ID,\n isSigner: false,\n isWritable: false,\n },\n {\n pubkey: web3.SYSVAR_RENT_PUBKEY,\n isSigner: false,\n isWritable: false,\n },\n ];\n\n return [\n new web3.TransactionInstruction({\n keys,\n programId: utils.token.ASSOCIATED_PROGRAM_ID,\n data: Buffer.from([]),\n }),\n ];\n};\n\nexport const getSuggestedLoans = (items: BulkNftRaw[], minValue: number) => {\n let sum = 0;\n let i = 0;\n const best: BulkNft[] = [];\n const cheapest: BulkNft[] = [];\n const safest: BulkNft[] = [];\n\n const sortedElementsByValue = items.sort((a, b) => {\n if (a.maxLoanValue !== b.maxLoanValue) {\n return a.maxLoanValue - b.maxLoanValue;\n }\n\n return a.interest - b.interest;\n });\n const sortedElementsByInterest = items.sort((a, b) => {\n if (a.interest !== b.interest) {\n return a.interest - b.interest;\n } else if (a.maxLoanValue !== b.maxLoanValue) {\n return a.maxLoanValue - b.maxLoanValue;\n }\n\n return a.amountOfDays - b.amountOfDays;\n });\n const priceBased = sortedElementsByInterest.filter((element) => element.maxLoanValue !== element.minLoanValue);\n const timeBased = sortedElementsByInterest.filter((element) => element.maxLoanValue === element.minLoanValue);\n\n const concated = priceBased.concat(timeBased);\n\n while (sum < minValue && i < sortedElementsByValue.length) {\n best.push({\n nftMint: sortedElementsByValue[i].nftMint,\n loanValue: sortedElementsByValue[i].maxLoanValue,\n interest: sortedElementsByValue[i].interest,\n amountOfDays: sortedElementsByValue[i].amountOfDays\n });\n sum += sortedElementsByValue[i].maxLoanValue;\n i += 1;\n }\n\n if (sum < minValue) {\n return {\n best: best,\n safest: best,\n cheapest: best,\n };\n }\n\n sum = 0;\n i = 0;\n\n while (sum < minValue && i < concated.length) {\n cheapest.push({\n nftMint: concated[i].nftMint,\n loanValue: concated[i].maxLoanValue,\n interest: concated[i].interest,\n amountOfDays: concated[i].amountOfDays\n });\n sum += concated[i].maxLoanValue;\n i += 1;\n }\n\n sum = 0;\n i = 0;\n\n while (sum < minValue && i < concated.length) {\n safest.push({\n nftMint: concated[i].nftMint,\n loanValue: concated[i].minLoanValue,\n interest: concated[i].interest,\n amountOfDays: concated[i].amountOfDays\n });\n sum += concated[i].minLoanValue;\n i += 1;\n }\n\n i = 0;\n\n while (sum < minValue) {\n sum += (concated[i].maxLoanValue - safest[i].loanValue);\n safest[i].loanValue = concated[i].maxLoanValue;\n i += 1;\n }\n\n return {\n best,\n safest,\n cheapest,\n }\n};\n","import { web3 } from'@project-serum/anchor';\n\nexport interface Wallet {\n publicKey: web3.PublicKey;\n signTransaction(tx: web3.Transaction): Promise<web3.Transaction>;\n signAllTransactions(txs: web3.Transaction[]): Promise<web3.Transaction[]>;\n}\n\nexport class NodeWallet implements Wallet {\n constructor(readonly payer: web3.Keypair) {}\n\n async signTransaction(tx: web3.Transaction): Promise<web3.Transaction> {\n tx.partialSign(this.payer);\n return tx;\n }\n\n async signAllTransactions(txs: web3.Transaction[]): Promise<web3.Transaction[]> {\n return txs.map((tx) => {\n tx.partialSign(this.payer);\n return tx;\n });\n }\n\n get publicKey(): web3.PublicKey {\n return this.payer.publicKey;\n }\n}\n","export * from './functions/private/approveLoanByAdmin';\nexport * from './functions/private/closeLoanByAdmin';\nexport * from './functions/private/initializeCollectionInfo';\nexport * from './functions/private/initializePriceBasedLiquidityPool';\nexport * from './functions/private/initializeTimeBasedLiquidityPool';\nexport * from './functions/private/liquidateLoanByAdmin';\nexport * from './functions/private/revealLotTicketByAdmin';\nexport * from './functions/private/rejectLoanByAdmin';\nexport * from './functions/private/updateCollectionInfo';\nexport * from './functions/private/updatePriceBasedLiquidityPool';\nexport * from './functions/private/updateTimeBasedLiquidityPool';\nexport * from './functions/private/liquidateLoanToRaffles';\nexport * from './functions/private/stopLiquidationRaffles';\nexport * from './functions/private/unstakeGemFarmByAdmin';\nexport * from './functions/private/putLoanToLiquidationRaffles';\n\nexport * from './functions/public/depositLiquidity';\nexport * from './functions/public/getAllProgramAccounts';\nexport * from './functions/public/harvestLiquidity';\nexport * from './functions/public/paybackLoan';\nexport * from './functions/public/paybackLoanIx';\nexport * from './functions/public/proposeLoan';\nexport * from './functions/public/unstakeLiquidity';\nexport * from './functions/public/redeemWinningLotTicket';\nexport * from './functions/public/getLotTicket';\nexport * from './functions/public/initializeNftAttemptsByStaking';\nexport * from './functions/public/getLotTicketByStaking';\nexport * from './functions/public/paybackLoanWithGrace';\nexport * from './functions/public/paybackLoanWithGraceIx';\nexport * from './functions/public/stakeGemFarm';\nexport * from './functions/public/unstakeGemFarm';\nexport * from './functions/public/unstakeGemFarmIx';\nexport * from './functions/public/claimGemFarm';\nexport * from './functions/public/claimGemFarmIx';\nexport * from './functions/public/calculateRewardDegod';\nexport * from './functions/public/getAllFarmAccounts';\nexport * from './functions/public/getFarmAccount';\n\nexport * from './helpers';\n","import { web3, BN } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype ApproveLoanByAdmin = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n loan: web3.PublicKey;\n liquidityPool: web3.PublicKey;\n collectionInfo: web3.PublicKey;\n nftPrice: number | BN;\n discount: number | BN;\n user: web3.PublicKey;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const approveLoanByAdmin: ApproveLoanByAdmin = async ({\n programId,\n connection,\n admin,\n loan,\n liquidityPool,\n collectionInfo,\n nftPrice,\n discount,\n user,\n sendTxn,\n}) => {\n const encoder = new TextEncoder();\n const program = returnAnchorProgram(programId, connection);\n\n const [liqOwner] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), liquidityPool.toBuffer()],\n programId,\n );\n\n const instruction = program.instruction.approveLoanByAdmin(new BN(nftPrice), new BN(discount), {\n accounts: {\n loan: loan,\n user,\n liquidityPool,\n liqOwner,\n collectionInfo,\n admin,\n systemProgram: web3.SystemProgram.programId,\n },\n });\n\n const transaction = new web3.Transaction().add(instruction);\n\n await sendTxn(transaction);\n};\n","import { Program, AnchorProvider, web3, BN, utils } from '@project-serum/anchor';\n\nimport idl from './idl/nft_lending_v2.json';\nimport {\n CollectionInfoView,\n DepositView,\n LoanView,\n TimeBasedLiquidityPoolView,\n PriceBasedLiquidityPoolView,\n LotTicketView,\n FarmerView,\n LendingStakeView,\n GemFarmRewardView,\n FixedRateView,\n PromisedSchedule,\n} from './types';\nimport { createFakeWallet } from '../common';\nimport { EDITION_PREFIX, METADATA_PREFIX, METADATA_PROGRAM_PUBKEY } from './constants';\n\ntype ReturnAnchorProgram = (programId: web3.PublicKey, connection: web3.Connection) => Program;\nexport const returnAnchorProgram: ReturnAnchorProgram = (programId, connection) =>\n new Program(\n idl as any,\n programId,\n new AnchorProvider(connection, createFakeWallet(), AnchorProvider.defaultOptions()),\n );\n\ntype DecodedCollectionInfo = (decodedCollection: any, address: web3.PublicKey) => CollectionInfoView;\nexport const decodedCollectionInfo: DecodedCollectionInfo = (decodedCollection, address) => ({\n collectionInfoPubkey: address.toBase58(),\n creator: decodedCollection.creator.toBase58(),\n liquidityPool: decodedCollection.liquidityPool.toBase58(),\n pricingLookupAddress: decodedCollection.pricingLookupAddress.toBase58(),\n royaltyAddress: decodedCollection.royaltyAddress.toBase58(),\n royaltyFeeTime: decodedCollection.royaltyFeeTime.toNumber(),\n royaltyFeePrice: decodedCollection.royaltyFeePrice.toNumber(),\n loanToValue: decodedCollection.loanToValue.toNumber(),\n collaterizationRate: decodedCollection.collaterizationRate.toNumber(),\n availableLoanTypes: Object.keys(decodedCollection.availableLoanTypes)[0],\n expirationTime: decodedCollection.expirationTime.toNumber(),\n});\n\ntype DecodedLendingStake = (decodedLendingStake: any, address: web3.PublicKey) => LendingStakeView;\nexport const decodedLendingStake: DecodedLendingStake = (decodedStake, address) => ({\n lendingStakePubkey: address.toBase58(),\n stakeType: Object.keys(decodedStake.stakeType)[0],\n loan: decodedStake.loan.toBase58(),\n stakeContract: decodedStake.stakeContract.toBase58(),\n stakeConstractOptional: decodedStake.stakeConstractOptional?.toBase58(),\n stakeState: Object.keys(decodedStake.stakeState)[0],\n identity: decodedStake.identity.toBase58(),\n dataA: decodedStake.dataA.toBase58(),\n dataB: decodedStake.dataB.toBase58(),\n dataC: decodedStake.dataC.toBase58(),\n dataD: decodedStake.dataD.toBase58(),\n totalHarvested: decodedStake.totalHarvested.toNumber(),\n totalHarvestedOptional: decodedStake.totalHarvestedOptional.toNumber(),\n lastTime: decodedStake.lastTime.toNumber()\n});\n\ntype DecodedFarmer = (decodedFarmer: any, address: web3.PublicKey) => FarmerView;\nexport const decodedFarmer: DecodedFarmer = (decodedFarmer, address) => ({\n farmerPubkey: address.toBase58(),\n farm: decodedFarmer.farm.toBase58(),\n identity: decodedFarmer.identity.toBase58(),\n vault: decodedFarmer.vault.toBase58(),\n state: Object.keys(decodedFarmer.state)[0],\n gemsStaked: decodedFarmer.gemsStaked.toNumber(),\n minStakingEndsTs: decodedFarmer.minStakingEndsTs.toNumber(),\n cooldownEndsTs: decodedFarmer.cooldownEndsTs.toNumber(),\n rewardA: decodedReward(decodedFarmer.rewardA),\n rewardB: decodedReward(decodedFarmer.rewardB),\n});\n\ntype DecodedGemFarmReward = (decodedFarmer: any) => GemFarmRewardView;\nconst decodedReward: DecodedGemFarmReward = (decodedReward) => ({\n paidOutReward: decodedReward.paidOutReward.toNumber(),\n accruedReward: decodedReward.accruedReward.toNumber(),\n variableRate: decodedReward.lastRecordedAccruedRewardPerRarityPoint?.n?.toNumber(),\n fixedRate: decodedFixedRate(decodedReward.fixedRate)\n});\n\ntype DecodedFixedRate = (decodedFixedRate: any) => FixedRateView;\nconst decodedFixedRate: DecodedFixedRate = (decodedFixedRate) => ({\n beginScheduleTs: decodedFixedRate.beginScheduleTs.toNumber(),\n beginStakingTs: decodedFixedRate.beginStakingTs.toNumber(),\n lastUpdatedTs: decodedFixedRate.lastUpdatedTs.toNumber(),\n promisedDuration: decodedFixedRate.promisedDuration.toNumber(),\n promisedSchedule: decodedPromisedSchedule(decodedFixedRate.promisedSchedule)\n})\n\ntype DecodedPromisedSchedule = (decodedPromisedSchedule: any) => PromisedSchedule;\nconst decodedPromisedSchedule: DecodedPromisedSchedule = (decodedSchedule) => ({\n baseRate: decodedSchedule.baseRate?.toNumber(),\n tier1: decodedSchedule.tier1?.toNumber(),\n tier2: decodedSchedule.tier2?.toNumber(),\n tier3: decodedSchedule.tier3?.toNumber(),\n denominator: decodedSchedule.denominator?.toNumber()\n})\n\ntype DecodedTimeBasedLiquidityPool = (decodedLiquidityPool: any, address: web3.PublicKey) => TimeBasedLiquidityPoolView;\nexport const decodedTimeBasedLiquidityPool: DecodedTimeBasedLiquidityPool = (decodedLiquidityPool, address) => ({\n liquidityPoolPubkey: address.toBase58(),\n id: decodedLiquidityPool.id.toNumber(),\n rewardInterestRateTime: decodedLiquidityPool.rewardInterestRateTime.toNumber(),\n feeInterestRateTime: decodedLiquidityPool.feeInterestRateTime.toNumber(),\n rewardInterestRatePrice: decodedLiquidityPool.rewardInterestRatePrice.toNumber(),\n feeInterestRatePrice: decodedLiquidityPool.feeInterestRatePrice.toNumber(),\n liquidityAmount: decodedLiquidityPool.liquidityAmount.toNumber(),\n liqOwner: decodedLiquidityPool.liqOwner.toBase58(),\n amountOfStaked: decodedLiquidityPool.amountOfStaked.toNumber(),\n userRewardsAmount: decodedLiquidityPool.userRewardsAmount.toNumber(),\n apr: decodedLiquidityPool.apr.toNumber(),\n cumulative: decodedLiquidityPool.cumulative.toNumber(),\n lastTime: decodedLiquidityPool.lastTime.toNumber(),\n oldCumulative: decodedLiquidityPool.oldCumulative.toNumber(),\n period: decodedLiquidityPool.period.toNumber(),\n});\n\ntype DecodedPriceBasedLiquidityPool = (\n decodedLiquidityPool: any,\n address: web3.PublicKey,\n) => PriceBasedLiquidityPoolView;\nexport const decodedPriceBasedLiquidityPool: DecodedPriceBasedLiquidityPool = (decodedLiquidityPool, address) => ({\n liquidityPoolPubkey: address.toBase58(),\n id: decodedLiquidityPool.id.toNumber(),\n baseBorrowRate: decodedLiquidityPool.baseBorrowRate,\n variableSlope1: decodedLiquidityPool.variableSlope1,\n variableSlope2: decodedLiquidityPool.variableSlope2,\n utilizationRateOptimal: decodedLiquidityPool.utilizationRateOptimal,\n reserveFactor: decodedLiquidityPool.reserveFactor,\n reserveAmount: decodedLiquidityPool.reserveAmount.toString(),\n liquidityAmount: decodedLiquidityPool.liquidityAmount.toNumber(),\n liqOwner: decodedLiquidityPool.liqOwner.toBase58(),\n amountOfStaked: decodedLiquidityPool.amountOfStaked.toNumber(),\n depositApr: decodedLiquidityPool.depositApr.toNumber(),\n depositCumulative: decodedLiquidityPool.depositCumulative.toNumber(),\n borrowApr: decodedLiquidityPool.borrowApr.toNumber(),\n borrowCumulative: decodedLiquidityPool.borrowCumulative.toNumber(),\n lastTime: decodedLiquidityPool.lastTime.toNumber(),\n depositCommission: decodedLiquidityPool.depositCommission,\n borrowCommission: decodedLiquidityPool.borrowCommission,\n});\n\ntype decodedDeposit = (decodedDeposit: any, address: web3.PublicKey) => DepositView;\nexport const decodedDeposit: decodedDeposit = (decodedDeposit, address) => ({\n depositPubkey: address.toBase58(),\n liquidityPool: decodedDeposit.liquidityPool.toBase58(),\n user: decodedDeposit.user.toBase58(),\n amount: decodedDeposit.amount.toNumber(),\n stakedAt: decodedDeposit.stakedAt.toNumber(),\n stakedAtCumulative: decodedDeposit.stakedAtCumulative.toNumber(),\n});\n\ntype DecodedLoan = (decodedLoan: any, address: web3.PublicKey) => LoanView;\nexport const decodedLoan: DecodedLoan = (decodedLoan, address) => ({\n loanPubkey: address.toBase58(),\n user: decodedLoan.user.toBase58(),\n nftMint: decodedLoan.nftMint.toBase58(),\n nftUserTokenAccount: decodedLoan.nftUserTokenAccount.toBase58(),\n liquidityPool: decodedLoan.liquidityPool.toBase58(),\n collectionInfo: decodedLoan.collectionInfo.toBase58(),\n startedAt: decodedLoan.startedAt.toNumber(),\n expiredAt: new BN(decodedLoan.expiredAt || 0).toNumber(),\n finishedAt: decodedLoan.finishedAt.toNumber(),\n originalPrice: decodedLoan.originalPrice.toNumber(),\n amountToGet: decodedLoan.amountToGet.toNumber(),\n rewardAmount: decodedLoan.rewardAmount.toNumber(),\n feeAmount: decodedLoan.feeAmount.toNumber(),\n royaltyAmount: decodedLoan.royaltyAmount.toNumber(),\n borrowedAtCumulative: new BN(decodedLoan.rewardInterestRate || 0).toNumber(),\n alreadyPaidBack: new BN(decodedLoan.feeInterestRate || 0).toNumber(),\n loanStatus: Object.keys(decodedLoan.loanStatus)[0],\n loanType: Object.keys(decodedLoan.loanType)[0],\n});\n\ntype DecodeLoan = (buffer: Buffer, connection: web3.Connection, programId: web3.PublicKey) => any;\nexport const decodeLoan: DecodeLoan = (buffer, connection, programId) => {\n const program = returnAnchorProgram(programId, connection);\n return program.coder.accounts.decode('Loan', buffer);\n};\n\ntype DecodeLotTicket = (\n buffer: Buffer,\n lotTicketPubkey: web3.PublicKey,\n connection: web3.Connection,\n programId: web3.PublicKey,\n) => LotTicketView;\nexport const decodeLotTicket: DecodeLotTicket = (buffer, lotTicketPubkey, connection, programId) => {\n const program = returnAnchorProgram(programId, connection);\n const rawAccount = program.coder.accounts.decode('LotTicket', buffer);\n return anchorRawBNsAndPubkeysToNumsAndStrings({ account: rawAccount, publicKey: lotTicketPubkey });\n};\n\ntype GetMetaplexEditionPda = (mintPubkey: web3.PublicKey) => web3.PublicKey;\nexport const getMetaplexEditionPda: GetMetaplexEditionPda = (mintPubkey) => {\n const editionPda = utils.publicKey.findProgramAddressSync(\n [\n Buffer.from(METADATA_PREFIX),\n METADATA_PROGRAM_PUBKEY.toBuffer(),\n new web3.PublicKey(mintPubkey).toBuffer(),\n Buffer.from(EDITION_PREFIX),\n ],\n METADATA_PROGRAM_PUBKEY,\n );\n return editionPda[0];\n};\n\nexport const anchorRawBNsAndPubkeysToNumsAndStrings = (rawAccount: any) => {\n const copyRawAccount = { ...rawAccount };\n for (let key in copyRawAccount.account) {\n if (copyRawAccount.account[key] === null) continue;\n if (copyRawAccount.account[key].toNumber) {\n copyRawAccount.account[key] = copyRawAccount.account[key].toNumber();\n }\n\n if (copyRawAccount.account[key].toBase58) {\n copyRawAccount.account[key] = copyRawAccount.account[key].toBase58();\n }\n if (typeof copyRawAccount.account[key] === 'object') {\n copyRawAccount.account[key] = Object.keys(copyRawAccount.account[key])[0];\n }\n }\n return { ...copyRawAccount.account, publicKey: copyRawAccount.publicKey.toBase58() };\n};\n\nconst knapsackAlgorithm = (\n items: { v: number; w: number; loanValue: number; nftMint: string; interest: number }[],\n capacity: number,\n): { maxValue: number; subset: { v: number; w: number; loanValue: number; nftMint: string; interest: number }[] } => {\n const getLast = (memo) => {\n let lastRow = memo[memo.length - 1];\n return lastRow[lastRow.length - 1];\n };\n const getSolution = (row, cap, memo) => {\n const NO_SOLUTION = { maxValue: 0, subset: [] };\n // the column number starts from zero.\n let col = cap - 1;\n let lastItem = items[row];\n // The remaining capacity for the sub-problem to solve.\n let remaining = cap - lastItem.w;\n\n // Refer to the last solution for this capacity,\n // which is in the cell of the previous row with the same column\n let lastSolution = row > 0 ? memo[row - 1][col] || NO_SOLUTION : NO_SOLUTION;\n // Refer to the last solution for the remaining capacity,\n // which is in the cell of the previous row with the corresponding column\n let lastSubSolution = row > 0 ? memo[row - 1][remaining - 1] || NO_SOLUTION : NO_SOLUTION;\n\n // If any one of the items weights greater than the 'cap', return the last solution\n if (remaining < 0) {\n return lastSolution;\n }\n\n // Compare the current best solution for the sub-problem with a specific capacity\n // to a new solution trial with the lastItem(new item) added\n let lastValue = lastSolution.maxValue;\n let lastSubValue = lastSubSolution.maxValue;\n\n let newValue = lastSubValue + lastItem.v;\n if (newValue >= lastValue) {\n // copy the subset of the last sub-problem solution\n let _lastSubSet = lastSubSolution.subset.slice();\n _lastSubSet.push(lastItem);\n return { maxValue: newValue, subset: _lastSubSet };\n } else {\n return lastSolution;\n }\n };\n // This implementation uses dynamic programming.\n // Variable 'memo' is a grid(2-dimentional array) to store optimal solution for sub-problems,\n // which will be later used as the code execution goes on.\n // This is called memoization in programming.\n // The cell will store best solution objects for different capacities and selectable items.\n let memo: any[] = [];\n\n // Filling the sub-problem solutions grid.\n for (let i = 0; i < items.length; i++) {\n // Variable 'cap' is the capacity for sub-problems. In this example, 'cap' ranges from 1 to 6.\n let row: any[] = [];\n for (let cap = 1; cap <= capacity; cap++) {\n row.push(getSolution(i, cap, memo));\n }\n memo.push(row);\n }\n\n // The right-bottom-corner cell of the grid contains the final solution for the whole problem.\n return getLast(memo);\n};\n\n/*\n Returns most optimal loans by lowest interest using Knapsack Algorithm.\n*/\nexport const getMostOptimalLoansClosestToNeededSolInBulk = ({\n neededSol,\n possibleLoans,\n}: {\n possibleLoans: { nftMint: string; loanValue: number; interest: number }[];\n neededSol: number;\n}) => {\n const divider = 1e7;\n\n const preparedItems = possibleLoans.map((loan) => ({\n ...loan,\n v: Math.ceil((loan.loanValue - loan.interest) / divider),\n w: Math.ceil(loan.loanValue / divider),\n }));\n\n const preparedNeededSol = Math.ceil(neededSol / divider);\n const { maxValue, subset } = knapsackAlgorithm(preparedItems, preparedNeededSol);\n\n const result = subset.map((item) => ({ nftMint: item.nftMint, loanValue: item.loanValue, interest: item.interest }));\n return result;\n};\n\nexport function objectBNsAndPubkeysToNums(obj: any) {\n const copyobj = { ...obj };\n\n for (const key in copyobj.account) {\n if (copyobj.account[key] === null) continue;\n\n if (copyobj.account[key].toNumber) {\n copyobj.account[key] = copyobj.account[key].toNumber();\n }\n\n if (copyobj.account[key].toBase58) {\n copyobj.account[key] = copyobj.account[key].toBase58();\n }\n\n if (typeof copyobj.account[key] === 'object') {\n copyobj.account[key] = Object.keys(copyobj.account[key])[0];\n }\n }\n\n return { ...copyobj.account, publicKey: copyobj.publicKey.toBase58() };\n}\n","import { web3 } from '@project-serum/anchor';\n\nexport const METADATA_PROGRAM_PUBKEY = new web3.PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');\n\nexport const METADATA_PREFIX = 'metadata';\n\nexport const EDITION_PREFIX = 'edition';\n","import { web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype CloseLoanByAdmin = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n loan: web3.PublicKey;\n admin: web3.PublicKey;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const closeLoanByAdmin: CloseLoanByAdmin = async ({ programId, connection, loan, admin, sendTxn }) => {\n const encoder = new TextEncoder();\n const program = returnAnchorProgram(programId, connection);\n\n const [communityPoolsAuthority, bumpPoolsAuth] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), programId.toBuffer()],\n programId,\n );\n\n const instruction = await program.methods\n .closeLoan(bumpPoolsAuth)\n .accounts({\n loan: loan,\n admin: admin,\n communityPoolsAuthority,\n })\n .instruction();\n\n const transaction = new web3.Transaction().add(instruction);\n\n await sendTxn(transaction);\n};\n","import { BN, web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype InitializeCollectionInfo = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n liquidityPool: web3.PublicKey;\n admin: web3.PublicKey;\n creatorAddress: web3.PublicKey;\n pricingLookupAddress: web3.PublicKey;\n loanToValue: number | BN;\n collaterizationRate: number | BN;\n royaltyAddress: web3.PublicKey;\n royaltyFeeTime: number | BN;\n royaltyFeePrice: number | BN;\n expirationTime: number | BN;\n isPriceBased: boolean;\n sendTxn: (transaction: web3.Transaction, signers: web3.Keypair[]) => Promise<void>;\n}) => Promise<web3.PublicKey>;\n\nexport const initializeCollectionInfo: InitializeCollectionInfo = async ({\n programId,\n connection,\n liquidityPool,\n admin,\n creatorAddress,\n pricingLookupAddress,\n loanToValue,\n collaterizationRate,\n royaltyAddress,\n royaltyFeeTime,\n royaltyFeePrice,\n expirationTime,\n isPriceBased,\n sendTxn,\n}) => {\n const program = returnAnchorProgram(programId, connection);\n const collectionInfo = web3.Keypair.generate();\n\n const instruction = program.instruction.initializeCollectionInfo(\n {\n loanToValue: new BN(loanToValue),\n collaterizationRate: new BN(collaterizationRate),\n royaltyFeeTime: new BN(royaltyFeeTime),\n royaltyFeePrice: new BN(royaltyFeePrice),\n expirationTime: new BN(expirationTime),\n isPriceBased,\n },\n {\n accounts: {\n liquidityPool: liquidityPool,\n collectionInfo: collectionInfo.publicKey,\n admin: admin,\n creatorAddress: creatorAddress,\n royaltyAddress,\n pricingLookupAddress: pricingLookupAddress,\n rent: web3.SYSVAR_RENT_PUBKEY,\n systemProgram: web3.SystemProgram.programId,\n },\n },\n );\n\n const transaction = new web3.Transaction().add(instruction);\n\n await sendTxn(transaction, [collectionInfo]);\n\n return collectionInfo.publicKey;\n};\n","import { web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype InitializePriceBasedLiquidityPool = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n baseBorrowRate: number;\n variableSlope1: number;\n variableSlope2: number;\n utilizationRateOptimal: number;\n reserveFactor: number;\n depositCommission: number;\n borrowCommission: number;\n id: number;\n sendTxn: (transaction: web3.Transaction, signers: web3.Keypair[]) => Promise<void>;\n}) => Promise<web3.PublicKey>;\n\nexport const initializePriceBasedLiquidityPool: InitializePriceBasedLiquidityPool = async ({\n programId,\n connection,\n admin,\n baseBorrowRate,\n variableSlope1,\n variableSlope2,\n utilizationRateOptimal,\n reserveFactor,\n depositCommission,\n borrowCommission,\n id,\n sendTxn,\n}) => {\n const program = returnAnchorProgram(programId, connection);\n const encoder = new TextEncoder();\n\n const liquidityPool = web3.Keypair.generate();\n const [liqOwner, liqOwnerBump] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), liquidityPool.publicKey.toBuffer()],\n program.programId,\n );\n const ix = program.instruction.initializePriceBasedLiquidityPool(\n liqOwnerBump,\n {\n id: id,\n baseBorrowRate: baseBorrowRate,\n variableSlope1: variableSlope1,\n variableSlope2: variableSlope2,\n utilizationRateOptimal: utilizationRateOptimal,\n reserveFactor: reserveFactor,\n depositCommission,\n borrowCommission,\n },\n {\n accounts: {\n liquidityPool: liquidityPool.publicKey,\n liqOwner,\n admin: admin,\n rent: web3.SYSVAR_RENT_PUBKEY,\n systemProgram: web3.SystemProgram.programId,\n },\n },\n );\n\n const transaction = new web3.Transaction().add(ix);\n\n await sendTxn(transaction, [liquidityPool]);\n return liquidityPool.publicKey;\n};\n","import { BN, web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype InitializeTimeBasedLiquidityPool = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n rewardInterestRateTime: number | BN;\n feeInterestRateTime: number | BN;\n rewardInterestRatePrice: number | BN;\n feeInterestRatePrice: number | BN;\n id: number | BN;\n period: number | BN;\n sendTxn: (transaction: web3.Transaction, signers: web3.Keypair[]) => Promise<void>;\n}) => Promise<web3.PublicKey>;\n\nexport const initializeTimeBasedLiquidityPool: InitializeTimeBasedLiquidityPool = async ({\n programId,\n connection,\n admin,\n rewardInterestRateTime,\n feeInterestRateTime,\n rewardInterestRatePrice,\n feeInterestRatePrice,\n id,\n period,\n sendTxn,\n}) => {\n const encoder = new TextEncoder();\n const program = returnAnchorProgram(programId, connection);\n const liquidityPool = web3.Keypair.generate();\n\n const [liqOwner, liqOwnerBump] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), liquidityPool.publicKey.toBuffer()],\n program.programId,\n );\n\n const instruction = program.instruction.initializeTimeBasedLiquidityPool(\n liqOwnerBump,\n {\n rewardInterestRateTime: new BN(rewardInterestRateTime),\n rewardInterestRatePrice: new BN(rewardInterestRatePrice),\n feeInterestRateTime: new BN(feeInterestRateTime),\n feeInterestRatePrice: new BN(feeInterestRatePrice),\n id: new BN(id),\n period: new BN(period),\n },\n {\n accounts: {\n liquidityPool: liquidityPool.publicKey,\n liqOwner,\n admin: admin,\n rent: web3.SYSVAR_RENT_PUBKEY,\n systemProgram: web3.SystemProgram.programId,\n },\n },\n );\n\n const transaction = new web3.Transaction().add(instruction);\n\n await sendTxn(transaction, [liquidityPool]);\n\n return liquidityPool.publicKey;\n};\n","import { web3, utils } from '@project-serum/anchor';\n\nimport { getMetaplexEditionPda, returnAnchorProgram } from '../../helpers';\nimport { findAssociatedTokenAddress } from '../../../common';\nimport { METADATA_PROGRAM_PUBKEY } from '../../constants';\n\ntype LiquidateLoanByAdmin = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n liquidator: web3.PublicKey;\n user: web3.PublicKey;\n loan: web3.PublicKey;\n nftMint: web3.PublicKey;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const liquidateLoanByAdmin: LiquidateLoanByAdmin = async ({\n programId,\n connection,\n liquidator,\n user,\n loan,\n nftMint,\n sendTxn,\n}) => {\n const encoder = new TextEncoder();\n const program = returnAnchorProgram(programId, connection);\n const nftUserTokenAccount = await findAssociatedTokenAddress(user, nftMint);\n const nftLiquidatorTokenAccount = await findAssociatedTokenAddress(liquidator, nftMint);\n const editionId = getMetaplexEditionPda(nftMint);\n\n const [communityPoolsAuthority, bumpPoolsAuth] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), programId.toBuffer()],\n program.programId,\n );\n\n const instruction = program.instruction.liquidateLoanByAdmin(bumpPoolsAuth, {\n accounts: {\n loan: loan,\n liquidator: liquidator,\n nftMint: nftMint,\n nftLiquidatorTokenAccount: nftLiquidatorTokenAccount,\n user: user,\n nftUserTokenAccount: nftUserTokenAccount,\n communityPoolsAuthority,\n rent: web3.SYSVAR_RENT_PUBKEY,\n systemProgram: web3.SystemProgram.programId,\n tokenProgram: utils.token.TOKEN_PROGRAM_ID,\n associatedTokenProgram: utils.token.ASSOCIATED_PROGRAM_ID,\n metadataProgram: METADATA_PROGRAM_PUBKEY,\n editionInfo: editionId,\n },\n });\n\n const transaction = new web3.Transaction().add(instruction);\n await sendTxn(transaction);\n};\n","import { web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype RevealLotTicketByAdmin = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n lotTicket: web3.PublicKey;\n isWinning: boolean;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const revealLotTicketByAdmin: RevealLotTicketByAdmin = async ({\n programId,\n connection,\n admin,\n lotTicket,\n isWinning,\n sendTxn,\n}) => {\n const program = returnAnchorProgram(programId, connection);\n\n const ix = program.instruction.revealLotTicketByAdmin(isWinning, {\n accounts: {\n admin,\n lotTicket,\n },\n });\n const transaction = new web3.Transaction().add(ix);\n\n await sendTxn(transaction);\n};\n","import { web3, utils } from '@project-serum/anchor';\n\nimport { METADATA_PROGRAM_PUBKEY } from '../../constants';\nimport { getMetaplexEditionPda, returnAnchorProgram } from '../../helpers';\n\ntype RejectLoanByAdmin = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n loan: web3.PublicKey;\n nftUserTokenAccount: web3.PublicKey;\n admin: web3.PublicKey;\n user: web3.PublicKey;\n nftMint: web3.PublicKey;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const rejectLoanByAdmin: RejectLoanByAdmin = async ({\n programId,\n connection,\n loan,\n nftUserTokenAccount,\n admin,\n user,\n nftMint,\n sendTxn,\n}) => {\n const encoder = new TextEncoder();\n const program = returnAnchorProgram(programId, connection);\n const editionId = getMetaplexEditionPda(nftMint);\n\n const [communityPoolsAuthority, bumpPoolsAuth] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), programId.toBuffer()],\n programId,\n );\n\n const instruction = program.instruction.rejectLoanByAdmin(bumpPoolsAuth, {\n accounts: {\n loan: loan,\n admin: admin,\n nftMint: nftMint,\n nftUserTokenAccount: nftUserTokenAccount,\n user: user,\n communityPoolsAuthority,\n tokenProgram: utils.token.TOKEN_PROGRAM_ID,\n systemProgram: web3.SystemProgram.programId,\n metadataProgram: METADATA_PROGRAM_PUBKEY,\n editionInfo: editionId,\n },\n });\n\n const transaction = new web3.Transaction().add(instruction);\n\n await sendTxn(transaction);\n};\n","import { BN, web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype UpdateCollectionInfo = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n liquidityPool: web3.PublicKey;\n admin: web3.PublicKey;\n creatorAddress: web3.PublicKey;\n collectionInfo: web3.PublicKey;\n pricingLookupAddress: web3.PublicKey;\n loanToValue: number | BN;\n collaterizationRate: number | BN;\n royaltyAddress: web3.PublicKey;\n royaltyFeeTime: number | BN;\n royaltyFeePrice: number | BN;\n expirationTime: number | BN;\n isPriceBased: boolean;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const updateCollectionInfo: UpdateCollectionInfo = async ({\n programId,\n connection,\n liquidityPool,\n admin,\n creatorAddress,\n collectionInfo,\n pricingLookupAddress,\n loanToValue,\n collaterizationRate,\n royaltyAddress,\n royaltyFeeTime,\n royaltyFeePrice,\n expirationTime,\n isPriceBased,\n sendTxn,\n}) => {\n const program = returnAnchorProgram(programId, connection);\n\n const instruction = program.instruction.updateCollectionInfo(\n {\n loanToValue: new BN(loanToValue),\n collaterizationRate: new BN(collaterizationRate),\n royaltyFeeTime: new BN(royaltyFeeTime),\n royaltyFeePrice: new BN(royaltyFeePrice),\n expirationTime: new BN(expirationTime),\n isPriceBased,\n },\n {\n accounts: {\n liquidityPool: liquidityPool,\n collectionInfo: collectionInfo,\n admin: admin,\n creatorAddress: creatorAddress,\n royaltyAddress,\n pricingLookupAddress: pricingLookupAddress,\n },\n },\n );\n\n const transaction = new web3.Transaction().add(instruction);\n\n await sendTxn(transaction);\n};\n","import { web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype UpdatePriceBasedLiquidityPool = (params: {\n programId: web3.PublicKey;\n liquidityPool: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n baseBorrowRate: number;\n variableSlope1: number;\n variableSlope2: number;\n utilizationRateOptimal: number;\n reserveFactor: number;\n depositCommission: number;\n borrowCommission: number;\n id: number;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const updatePriceBasedLiquidityPool: UpdatePriceBasedLiquidityPool = async ({\n programId,\n liquidityPool,\n connection,\n admin,\n baseBorrowRate,\n variableSlope1,\n variableSlope2,\n utilizationRateOptimal,\n reserveFactor,\n depositCommission,\n borrowCommission,\n id,\n sendTxn,\n}) => {\n const program = returnAnchorProgram(programId, connection);\n\n const ix = program.instruction.updatePriceBasedLiquidityPool(\n {\n id,\n baseBorrowRate,\n variableSlope1,\n variableSlope2,\n utilizationRateOptimal,\n reserveFactor,\n depositCommission,\n borrowCommission,\n },\n {\n accounts: {\n liquidityPool: liquidityPool,\n admin: admin,\n rent: web3.SYSVAR_RENT_PUBKEY,\n systemProgram: web3.SystemProgram.programId,\n },\n },\n );\n\n const transaction = new web3.Transaction().add(ix);\n\n await sendTxn(transaction);\n // return liquidityPool;\n};\n","import { BN, web3 } from '@project-serum/anchor';\n\nimport { returnAnchorProgram } from '../../helpers';\n\ntype UpdateTimeBasedLiquidityPool = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n liquidityPool: web3.PublicKey;\n rewardInterestRateTime: number | BN;\n feeInterestRateTime: number | BN;\n rewardInterestRatePrice: number | BN;\n feeInterestRatePrice: number | BN;\n id: number | BN;\n period: number | BN;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const updateTimeBasedLiquidityPool: UpdateTimeBasedLiquidityPool = async ({\n programId,\n connection,\n admin,\n liquidityPool,\n rewardInterestRateTime,\n feeInterestRateTime,\n rewardInterestRatePrice,\n feeInterestRatePrice,\n id,\n period,\n sendTxn,\n}) => {\n const program = returnAnchorProgram(programId, connection);\n\n const instruction = program.instruction.updateLiquidityPool(\n {\n rewardInterestRateTime: new BN(rewardInterestRateTime),\n rewardInterestRatePrice: new BN(rewardInterestRatePrice),\n feeInterestRateTime: new BN(feeInterestRateTime),\n feeInterestRatePrice: new BN(feeInterestRatePrice),\n id: new BN(id),\n period: new BN(period),\n },\n {\n accounts: {\n liquidityPool: liquidityPool,\n admin: admin,\n rent: web3.SYSVAR_RENT_PUBKEY,\n systemProgram: web3.SystemProgram.programId,\n },\n },\n );\n\n const transaction = new web3.Transaction().add(instruction);\n\n await sendTxn(transaction);\n};\n","import { web3, utils, BN } from '@project-serum/anchor';\n\nimport { getMetaplexEditionPda, returnAnchorProgram } from '../../helpers';\nimport { findAssociatedTokenAddress } from '../../../common';\nimport { METADATA_PROGRAM_PUBKEY } from '../../constants';\n\ntype LiquidateLoanToRaffles = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n user: web3.PublicKey;\n liquidator: web3.PublicKey;\n\n gracePeriod: number;\n loan: web3.PublicKey;\n nftMint: web3.PublicKey;\n sendTxn: (transaction: web3.Transaction, signers: web3.Keypair[]) => Promise<void>;\n}) => Promise<web3.PublicKey>;\n\nexport const liquidateLoanToRaffles: LiquidateLoanToRaffles = async ({\n programId,\n connection,\n user,\n liquidator,\n gracePeriod,\n loan,\n nftMint,\n sendTxn,\n}) => {\n const encoder = new TextEncoder();\n const program = returnAnchorProgram(programId, connection);\n\n const [communityPoolsAuthority, bumpPoolsAuth] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), programId.toBuffer()],\n program.programId,\n );\n\n const nftUserTokenAccount = await findAssociatedTokenAddress(user, nftMint);\n const vaultNftTokenAccount = await findAssociatedTokenAddress(communityPoolsAuthority, nftMint);\n const editionId = getMetaplexEditionPda(nftMint);\n const liquidationLot = web3.Keypair.generate();\n\n const ix = program.instruction.liquidateNftToRaffles(bumpPoolsAuth, new BN(gracePeriod), {\n accounts: {\n loan,\n liquidationLot: liquidationLot.publicKey,\n user,\n liquidator: liquidator,\n nftMint,\n vaultNftTokenAccount,\n nftUserTokenAccount,\n communityPoolsAuthority,\n systemProgram: web3.SystemProgram.programId,\n tokenProgram: utils.token.TOKEN_PROGRAM_ID,\n associatedTokenProgram: utils.token.ASSOCIATED_PROGRAM_ID,\n metadataProgram: METADATA_PROGRAM_PUBKEY,\n editionInfo: editionId,\n rent: web3.SYSVAR_RENT_PUBKEY,\n },\n });\n const transaction = new web3.Transaction().add(ix);\n\n await sendTxn(transaction, [liquidationLot]);\n return liquidationLot.publicKey;\n};\n","import { web3, utils } from '@project-serum/anchor';\nimport { findAssociatedTokenAddress } from '../../../common';\nimport { returnAnchorProgram } from '../../helpers';\n\ntype RevealLotTicketByAdmin = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n nftMint: web3.PublicKey;\n liquidationLot: web3.PublicKey;\n loan: web3.PublicKey;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const stopLiquidationRaffles: RevealLotTicketByAdmin = async ({\n programId,\n connection,\n admin,\n nftMint,\n liquidationLot,\n loan,\n sendTxn,\n}) => {\n const encoder = new TextEncoder();\n\n const program = returnAnchorProgram(programId, connection);\n const nftAdminTokenAccount = await findAssociatedTokenAddress(admin, nftMint);\n\n const [communityPoolsAuthority, bumpPoolsAuth] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), programId.toBuffer()],\n program.programId,\n );\n const vaultNftTokenAccount = await findAssociatedTokenAddress(communityPoolsAuthority, nftMint);\n\n const ix = program.instruction.stopLiquidationRafflesByAdmin(bumpPoolsAuth, {\n accounts: {\n admin,\n nftMint,\n communityPoolsAuthority,\n liquidationLot,\n loan,\n vaultNftTokenAccount,\n nftAdminTokenAccount,\n tokenProgram: utils.token.TOKEN_PROGRAM_ID,\n associatedTokenProgram: utils.token.ASSOCIATED_PROGRAM_ID,\n systemProgram: web3.SystemProgram.programId,\n rent: web3.SYSVAR_RENT_PUBKEY,\n },\n });\n const transaction = new web3.Transaction().add(ix);\n\n await sendTxn(transaction);\n};\n","import { web3, utils } from '@project-serum/anchor';\nimport { METADATA_PROGRAM_PUBKEY } from '../../constants';\n\nimport { returnAnchorProgram, getMetaplexEditionPda } from '../../helpers';\nimport { findAssociatedTokenAddress } from '../../../common';\n\ntype UnstakeGemFarmByAdmin = (params: {\n programId: web3.PublicKey;\n connection: web3.Connection;\n admin: web3.PublicKey;\n gemFarm: web3.PublicKey;\n gemBank: web3.PublicKey;\n farm: web3.PublicKey;\n bank: web3.PublicKey;\n feeAcc: web3.PublicKey;\n nftMint: web3.PublicKey;\n loan: web3.PublicKey;\n isDegod: boolean;\n sendTxn: (transaction: web3.Transaction) => Promise<void>;\n}) => Promise<void>;\n\nexport const unstakeGemFarmByAdmin: UnstakeGemFarmByAdmin = async ({\n programId,\n connection,\n admin,\n gemFarm,\n gemBank,\n farm,\n bank,\n feeAcc,\n nftMint,\n loan, \n isDegod,\n sendTxn,\n}) => {\n const encoder = new TextEncoder();\n const program = returnAnchorProgram(programId, connection);\n const [communityPoolsAuthority, bumpPoolsAuth] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('nftlendingv2'), programId.toBuffer()],\n program.programId,\n );\n const [identity, bumpAuth] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('degod_stake'), nftMint.toBuffer(), loan.toBuffer()],\n programId,\n );\n const editionId = getMetaplexEditionPda(nftMint);\n\n const [farmer, bumpFarmer] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('farmer'), farm.toBuffer(), identity.toBuffer()],\n gemFarm,\n );\n const [lendingStake] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('stake_acc'), loan.toBuffer()],\n programId,\n );\n const [vault, _bumpVault] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('vault'), bank.toBuffer(), identity.toBuffer()],\n gemBank,\n );\n\n const [bankAuthority, bumpAuthVaultAuthority] = await web3.PublicKey.findProgramAddress(\n [vault.toBuffer()],\n gemBank,\n );\n\n const [gemBox, bumpGemBox] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('gem_box'), vault.toBuffer(), nftMint.toBuffer()],\n gemBank,\n );\n\n const [gemDepositReceipt, bumpGdr] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('gem_deposit_receipt'), vault.toBuffer(), nftMint.toBuffer()],\n gemBank,\n );\n\n const [gemRarity, bumpRarity] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('gem_rarity'), bank.toBuffer(), nftMint.toBuffer()],\n gemBank,\n );\n\n const [farmTreasury, bumpTreasury] = await web3.PublicKey.findProgramAddress(\n [encoder.encode('treasury'), farm.toBuffer()],\n gemFarm,\n );\n\n const [farmAuthority, bumpAuthAuthority] = await web3.PublicKey.findProgramAddress(\n [f