@kamino-finance/klend-sdk 2.10.21 → 2.11.0
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.
- package/dist/classes/action.d.ts +1 -0
- package/dist/classes/action.js +55 -38
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/obligation.js +21 -0
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +30 -0
- package/dist/classes/reserve.js +66 -6
- package/dist/classes/reserve.js.map +1 -1
- package/dist/idl.json +156 -72
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +3 -3
- package/dist/idl_codegen/accounts/LendingMarket.js +7 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +6 -3
- package/dist/idl_codegen/accounts/Obligation.js +12 -6
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/accounts/Reserve.d.ts +18 -0
- package/dist/idl_codegen/accounts/Reserve.js +14 -2
- package/dist/idl_codegen/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +76 -4
- package/dist/idl_codegen/errors/custom.js +126 -8
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +2 -4
- package/dist/idl_codegen/instructions/index.js +3 -5
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +2 -1
- package/dist/idl_codegen/instructions/updateReserveConfig.js +4 -2
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ElevationGroup.d.ts +24 -10
- package/dist/idl_codegen/types/ElevationGroup.js +25 -12
- package/dist/idl_codegen/types/ElevationGroup.js.map +1 -1
- package/dist/idl_codegen/types/ObligationCollateral.d.ts +23 -0
- package/dist/idl_codegen/types/ObligationCollateral.js +8 -1
- package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts +8 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js +8 -1
- package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/ReserveConfig.d.ts +55 -9
- package/dist/idl_codegen/types/ReserveConfig.js +20 -6
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +39 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js +79 -1
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +4 -2
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +27 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +4 -4
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +3 -2
- package/dist/idl_codegen/zero_padding/ObligationZP.js +8 -3
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reserve.js","sourceRoot":"","sources":["../../src/classes/reserve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,4DAAiC;AACjC,oCAQkB;AAClB,qCAA0D;AAC1D,sDAAiE;AAEjE,mCAA+E;AAC/E,yCAAsC;AACtC,kDAAuB;AAGV,QAAA,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,IAAI,CAAC,CAAC,kBAAkB,GAAG,8BAAsB,EAAE,aAAa,GAAG,8BAAsB,CAAC,CAAC,CAAC;QAElG,IAAI,kBAAkB,KAAK,8BAAsB,EAAE;YACjD,MAAM;SACP;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport { AccountInfo, Connection, PublicKey } from '@solana/web3.js';\nimport Decimal from 'decimal.js';\nimport {\n INITIAL_COLLATERAL_RATE,\n ONE_HUNDRED_PCT_IN_BPS,\n SLOTS_PER_DAY,\n SLOTS_PER_SECOND,\n SLOTS_PER_YEAR,\n TokenOracleData,\n U64_MAX,\n} from '../utils';\nimport { ReserveDataType, ReserveStatus } from './shared';\nimport { Reserve, ReserveFields } from '../idl_codegen/accounts';\nimport { CurvePointFields } from '../idl_codegen/types';\nimport { calculateAPYFromAPR, getBorrowRate, parseTokenSymbol } from './utils';\nimport { Fraction } from './fraction';\nimport BN from 'bn.js';\nimport { ActionType } from './action';\n\nexport const DEFAULT_RECENT_SLOT_DURATION_MS = 450;\n\nexport class KaminoReserve {\n state: Reserve;\n address: PublicKey;\n symbol: string;\n\n tokenOraclePrice: TokenOracleData;\n stats: ReserveDataType;\n\n private buffer: AccountInfo<Buffer> | null;\n private connection: Connection;\n private readonly recentSlotDurationMs: number;\n\n constructor(\n state: Reserve,\n address: PublicKey,\n tokenOraclePrice: TokenOracleData,\n connection: Connection,\n recentSlotDurationMs: number\n ) {\n this.state = state;\n this.address = address;\n this.buffer = null;\n this.tokenOraclePrice = tokenOraclePrice;\n this.stats = {} as ReserveDataType;\n this.connection = connection;\n this.symbol = parseTokenSymbol(state.config.tokenInfo.name);\n this.recentSlotDurationMs = recentSlotDurationMs;\n }\n\n static initialize(\n accountData: AccountInfo<Buffer>,\n address: PublicKey,\n state: Reserve,\n tokenOraclePrice: TokenOracleData,\n connection: Connection,\n recentSlotDurationMs: number\n ) {\n const reserve = new KaminoReserve(state, address, tokenOraclePrice, connection, recentSlotDurationMs);\n reserve.setBuffer(accountData);\n reserve.stats = reserve.formatReserveData(state);\n return reserve;\n }\n\n /// GETTERS\n\n /**\n * @returns the parsed token symbol of the reserve\n */\n getTokenSymbol(): string {\n return parseTokenSymbol(this.state.config.tokenInfo.name);\n }\n\n /**\n * @returns the total borrowed amount of the reserve\n */\n getBorrowedAmount(): Decimal {\n return new Fraction(this.state.liquidity.borrowedAmountSf).toDecimal();\n }\n\n /**\n * @returns the available liquidity amount of the reserve\n */\n getLiquidityAvailableAmount(): Decimal {\n return new Decimal(this.state.liquidity.availableAmount.toString());\n }\n\n /**\n *\n * @returns the last cached price stored in the reserve in USD\n */\n getReserveMarketPrice(): Decimal {\n return new Fraction(this.state.liquidity.marketPriceSf).toDecimal();\n }\n\n /**\n * @returns the current market price of the reserve in USD\n */\n getOracleMarketPrice(): Decimal {\n return this.tokenOraclePrice.price;\n }\n\n /**\n * @returns the total accumulated protocol fees of the reserve\n */\n getAccumulatedProtocolFees(): Decimal {\n return new Fraction(this.state.liquidity.accumulatedProtocolFeesSf).toDecimal();\n }\n\n /**\n * @returns the total accumulated referrer fees of the reserve\n */\n getAccumulatedReferrerFees(): Decimal {\n return new Fraction(this.state.liquidity.accumulatedReferrerFeesSf).toDecimal();\n }\n\n /**\n * @returns the total pending referrer fees of the reserve\n */\n getPendingReferrerFees(): Decimal {\n return new Fraction(this.state.liquidity.pendingReferrerFeesSf).toDecimal();\n }\n\n /**\n *\n * @returns the flash loan fee percentage of the reserve\n */\n getFlashLoanFee = (): Decimal => {\n if (this.state.config.fees.flashLoanFeeSf.toString() === U64_MAX) {\n return new Decimal('0');\n }\n return new Fraction(this.state.config.fees.flashLoanFeeSf).toDecimal();\n };\n\n /**\n *\n * @returns the origination fee percentage of the reserve\n */\n getBorrowFee = (): Decimal => {\n return new Fraction(this.state.config.fees.borrowFeeSf).toDecimal();\n };\n\n /**\n * Use getEstimatedTotalSupply() for the most accurate value\n * @returns the stale total liquidity supply of the reserve from the last refresh\n */\n getTotalSupply(): Decimal {\n return this.getLiquidityAvailableAmount()\n .add(this.getBorrowedAmount())\n .sub(this.getAccumulatedProtocolFees())\n .sub(this.getAccumulatedReferrerFees())\n .sub(this.getPendingReferrerFees());\n }\n\n /**\n * Calculates the total liquidity supply of the reserve\n */\n getEstimatedTotalSupply(slot: number, referralFeeBps: number): Decimal {\n const { totalSupply } = this.getEstimatedDebtAndSupply(slot, referralFeeBps);\n return totalSupply;\n }\n\n /**\n * Use getEstimatedCumulativeBorrowRate() for the most accurate value\n * @returns the stale cumulative borrow rate of the reserve from the last refresh\n */\n getCumulativeBorrowRate(): Decimal {\n let accSf = new BN(0);\n for (const value of this.state.liquidity.cumulativeBorrowRateBsf.value.reverse()) {\n accSf = accSf.add(value);\n accSf.shrn(64);\n }\n return new Fraction(accSf).toDecimal();\n }\n\n /**\n * @Returns estimated cumulative borrow rate of the reserve\n */\n getEstimatedCumulativeBorrowRate(currentSlot: number): Decimal {\n const currentBorrowRate = new Decimal(this.calculateBorrowAPR());\n const slotsElapsed = Math.max(currentSlot - this.state.lastUpdate.slot.toNumber(), 0);\n\n const compoundInterest = this.approximateCompoundedInterest(currentBorrowRate, slotsElapsed);\n\n const previousCumulativeBorrowRate = this.getCumulativeBorrowRate();\n\n return previousCumulativeBorrowRate.mul(compoundInterest);\n }\n\n /**\n * Use getEstimatedCollateralExchangeRate() for the most accurate value\n * @returns the stale exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18\n */\n getCollateralExchangeRate(): Decimal {\n const totalSupply = this.getTotalSupply();\n const mintTotalSupply = this.state.collateral.mintTotalSupply;\n if (mintTotalSupply.isZero() || totalSupply.isZero()) {\n return INITIAL_COLLATERAL_RATE;\n } else {\n return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());\n }\n }\n\n /**\n *\n * @returns the estimated exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18\n */\n getEstimatedCollateralExchangeRate(slot: number, referralFeeBps: number): Decimal {\n const totalSupply = this.getEstimatedTotalSupply(slot, referralFeeBps);\n const mintTotalSupply = this.state.collateral.mintTotalSupply;\n if (mintTotalSupply.isZero() || totalSupply.isZero()) {\n return INITIAL_COLLATERAL_RATE;\n } else {\n return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());\n }\n }\n\n /**\n *\n * @returns the total USD value of the existing collateral in the reserve\n */\n getDepositTvl = (): Decimal => {\n return new Decimal(this.getTotalSupply().toString()).mul(this.getOracleMarketPrice()).div(this.getMintFactor());\n };\n\n /**\n *\n * Get the total USD value of the borrowed assets from the reserve\n */\n getBorrowTvl = (): Decimal => {\n return this.getBorrowedAmount().mul(this.getOracleMarketPrice()).div(this.getMintFactor());\n };\n\n /**\n * @returns 10^mint_decimals\n */\n getMintFactor(): Decimal {\n return new Decimal(10).pow(this.state.liquidity.mintDecimals.toNumber());\n }\n\n /**\n * @Returns true if the total liquidity supply of the reserve is greater than the deposit limit\n */\n depositLimitCrossed(): boolean {\n return this.getTotalSupply().gt(new Decimal(this.state.config.depositLimit.toString()));\n }\n\n /**\n * @Returns true if the total borrowed amount of the reserve is greater than the borrow limit\n */\n borrowLimitCrossed(): boolean {\n return this.getBorrowedAmount().gt(new Decimal(this.state.config.borrowLimit.toString()));\n }\n\n /**\n *\n * @returns the max capacity of the daily deposit withdrawal cap\n */\n getDepositWithdrawalCapCapacity(): Decimal {\n return new Decimal(this.state.config.depositWithdrawalCap.configCapacity.toString());\n }\n\n /**\n *\n * @returns the current capacity of the daily deposit withdrawal cap\n */\n getDepositWithdrawalCapCurrent(slot: number): Decimal {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n if (slotsElapsed > SLOTS_PER_DAY) {\n return new Decimal(0);\n } else {\n return new Decimal(this.state.config.depositWithdrawalCap.currentTotal.toString());\n }\n }\n\n /**\n *\n * @returns the max capacity of the daily debt withdrawal cap\n */\n getDebtWithdrawalCapCapacity(): Decimal {\n return new Decimal(this.state.config.debtWithdrawalCap.configCapacity.toString());\n }\n\n /**\n *\n * @returns the current capacity of the daily debt withdrawal cap\n */\n getDebtWithdrawalCapCurrent(slot: number): Decimal {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n if (slotsElapsed > SLOTS_PER_DAY) {\n return new Decimal(0);\n } else {\n return new Decimal(this.state.config.debtWithdrawalCap.currentTotal.toString());\n }\n }\n\n getBorrowFactor(): Decimal {\n return new Decimal(this.state.config.borrowFactorPct.toString()).div(100);\n }\n\n calculateSupplyAPR() {\n const currentUtilization = this.calculateUtilizationRatio();\n\n const borrowAPR = this.calculateBorrowAPR();\n const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;\n return currentUtilization * borrowAPR * protocolTakeRatePct;\n }\n\n getEstimatedDebtAndSupply(slot: number, referralFeeBps: number): { totalBorrow: Decimal; totalSupply: Decimal } {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n let totalBorrow: Decimal;\n let totalSupply: Decimal;\n if (slotsElapsed === 0) {\n totalBorrow = this.getBorrowedAmount();\n totalSupply = this.getTotalSupply();\n } else {\n const { newDebt, newAccProtocolFees, pendingReferralFees } = this.compoundInterest(slotsElapsed, referralFeeBps);\n const newTotalSupply = this.getLiquidityAvailableAmount()\n .add(newDebt)\n .sub(newAccProtocolFees)\n .sub(this.getAccumulatedReferrerFees())\n .sub(pendingReferralFees);\n totalBorrow = newDebt;\n totalSupply = newTotalSupply;\n }\n return { totalBorrow, totalSupply };\n }\n\n calculateUtilizationRatio() {\n const totalBorrows = this.getBorrowedAmount();\n const totalSupply = this.getTotalSupply();\n if (totalSupply.eq(0)) {\n return 0;\n }\n return totalBorrows.dividedBy(totalSupply).toNumber();\n }\n\n calcSimulatedUtilizationRatio(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ): number {\n const { totalBorrow: previousTotalBorrowed, totalSupply: previousTotalSupply } = this.getEstimatedDebtAndSupply(\n slot,\n referralFeeBps\n );\n\n switch (action) {\n case 'deposit': {\n const newTotalSupply = previousTotalSupply.add(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'withdraw': {\n const newTotalSupply = previousTotalSupply.sub(amount);\n if (newTotalSupply.eq(0)) {\n return 0;\n } else {\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n }\n case 'borrow': {\n const newTotalBorrowed = previousTotalBorrowed.add(amount);\n return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();\n }\n case 'repay': {\n const newTotalBorrowed = previousTotalBorrowed.sub(amount);\n return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();\n }\n case 'depositAndBorrow': {\n const newTotalSupply = previousTotalSupply.add(amount);\n const newTotalBorrowed = previousTotalBorrowed.add(outflowAmount!);\n return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'repayAndWithdraw': {\n const newTotalBorrowed = previousTotalBorrowed.sub(amount);\n const newTotalSupply = previousTotalSupply.sub(outflowAmount!);\n if (newTotalSupply.eq(0)) {\n return 0;\n }\n return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'mint': {\n const newTotalSupply = previousTotalSupply.add(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'redeem': {\n const newTotalSupply = previousTotalSupply.sub(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n default:\n throw Error(`Invalid action type ${action} for simulatedUtilizationRatio`);\n }\n }\n\n calcSimulatedBorrowAPR(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ) {\n const slotAdjustmentFactor = this.slotAdjustmentFactor();\n const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);\n const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);\n return getBorrowRate(newUtilization, curve) * slotAdjustmentFactor;\n }\n\n calcSimulatedSupplyAPR(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ) {\n const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);\n const simulatedBorrowAPR = this.calcSimulatedBorrowAPR(amount, action, slot, referralFeeBps, outflowAmount);\n const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;\n\n return newUtilization * simulatedBorrowAPR * protocolTakeRatePct;\n }\n\n slotAdjustmentFactor(): number {\n return 1000 / SLOTS_PER_SECOND / this.recentSlotDurationMs;\n }\n\n calculateBorrowAPR() {\n const slotAdjustmentFactor = this.slotAdjustmentFactor();\n const currentUtilization = this.calculateUtilizationRatio();\n const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);\n return getBorrowRate(currentUtilization, curve) * slotAdjustmentFactor;\n }\n\n /**\n * @returns the mint of the reserve liquidity token\n */\n getLiquidityMint(): PublicKey {\n return this.state.liquidity.mintPubkey;\n }\n\n /**\n * @returns the mint of the reserve collateral token , i.e. the cToken minted for depositing the liquidity token\n */\n getCTokenMint(): PublicKey {\n return this.state.collateral.mintPubkey;\n }\n\n setBuffer(buffer: AccountInfo<Buffer> | null) {\n this.buffer = buffer;\n }\n\n async load(tokenOraclePrice: TokenOracleData) {\n if (!this.buffer) {\n this.setBuffer(await this.connection.getAccountInfo(this.address, 'processed'));\n }\n\n if (!this.buffer) {\n throw Error(`Error requesting account info for ${this.symbol}`);\n }\n\n const parsedData = await Reserve.fetch(this.connection, this.address);\n if (!parsedData) {\n throw Error(`Unable to parse data of reserve ${this.symbol}`);\n }\n this.state = parsedData;\n this.tokenOraclePrice = tokenOraclePrice;\n this.stats = this.formatReserveData(parsedData);\n }\n\n totalSupplyAPY() {\n const { stats } = this;\n if (!stats) {\n throw Error('KaminoMarket must call loadRewards.');\n }\n\n const totalAPY = new Decimal(stats.supplyInterestAPY).toNumber();\n\n return {\n interestAPY: stats.supplyInterestAPY,\n totalAPY,\n };\n }\n\n totalBorrowAPY() {\n const { stats } = this;\n if (!stats) {\n throw Error('KaminoMarket must call loadRewards.');\n }\n\n const totalAPY = new Decimal(stats.borrowInterestAPY).toNumber();\n\n return {\n interestAPY: stats.borrowInterestAPY,\n totalAPY,\n };\n }\n\n private formatReserveData(parsedData: ReserveFields): ReserveDataType {\n const mintTotalSupply = new Decimal(parsedData.collateral.mintTotalSupply.toString()).div(this.getMintFactor());\n let reserveStatus = ReserveStatus.Active;\n switch (parsedData.config.status) {\n case 0:\n reserveStatus = ReserveStatus.Active;\n break;\n case 1:\n reserveStatus = ReserveStatus.Obsolete;\n break;\n case 2:\n reserveStatus = ReserveStatus.Hidden;\n break;\n }\n return {\n // Reserve config\n\n status: reserveStatus,\n mintAddress: parsedData.liquidity.mintPubkey,\n borrowCurve: truncateBorrowCurve(parsedData.config.borrowRateCurve.points),\n loanToValuePct: parsedData.config.loanToValuePct / 100,\n maxLiquidationBonus: parsedData.config.maxLiquidationBonusBps / 10000,\n minLiquidationBonus: parsedData.config.minLiquidationBonusBps / 10000,\n liquidationThreshold: parsedData.config.liquidationThresholdPct / 100,\n protocolTakeRate: parsedData.config.protocolTakeRatePct / 100,\n reserveDepositLimit: new Decimal(parsedData.config.depositLimit.toString()),\n reserveBorrowLimit: new Decimal(parsedData.config.borrowLimit.toString()),\n\n // Reserve info\n symbol: parseTokenSymbol(parsedData.config.tokenInfo.name),\n decimals: this.state.liquidity.mintDecimals.toNumber(),\n supplyInterestAPY: calculateAPYFromAPR(this.calculateSupplyAPR()),\n borrowInterestAPY: calculateAPYFromAPR(this.calculateBorrowAPR()),\n accumulatedProtocolFees: this.getAccumulatedProtocolFees().div(this.getMintFactor()),\n mintTotalSupply,\n depositLimitCrossedSlot: parsedData.liquidity.depositLimitCrossedSlot.toNumber(),\n borrowLimitCrossedSlot: parsedData.liquidity.borrowLimitCrossedSlot.toNumber(),\n borrowFactor: parsedData.config.borrowFactorPct.toNumber(),\n };\n }\n\n /**\n * Compound current borrow rate over elapsed slots\n *\n * This also calculates protocol fees, which are taken for all obligations that have borrowed from current reserve.\n *\n * This also calculates referral fees, which are taken into pendingReferralFees.\n *\n * https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L517\n *\n * @param slotsElapsed\n * @param referralFeeBps\n */\n private compoundInterest(\n slotsElapsed: number,\n referralFeeBps: number\n ): {\n newDebt: Decimal;\n netNewDebt: Decimal;\n totalProtocolFee: Decimal;\n absoluteReferralFee: Decimal;\n maxReferralFees: Decimal;\n newAccProtocolFees: Decimal;\n pendingReferralFees: Decimal;\n } {\n const currentBorrowRate = this.calculateBorrowAPR();\n const protocolTakeRate = new Decimal(this.state.config.protocolTakeRatePct).div(100);\n const referralRate = new Decimal(referralFeeBps).div(10_000);\n\n const compoundInterestRate = this.approximateCompoundedInterest(new Decimal(currentBorrowRate), slotsElapsed);\n\n const previousDebt = this.getBorrowedAmount();\n const newDebt = previousDebt.mul(compoundInterestRate);\n const netNewDebt = newDebt.sub(previousDebt);\n\n const totalProtocolFee = netNewDebt.mul(protocolTakeRate);\n const absoluteReferralFee = protocolTakeRate.mul(referralRate);\n const maxReferralFees = netNewDebt.mul(absoluteReferralFee);\n\n const newAccProtocolFees = totalProtocolFee.sub(maxReferralFees).add(this.getAccumulatedProtocolFees());\n\n const pendingReferralFees = this.getPendingReferrerFees().add(maxReferralFees);\n\n return {\n newDebt,\n netNewDebt,\n totalProtocolFee,\n absoluteReferralFee,\n maxReferralFees,\n newAccProtocolFees,\n pendingReferralFees,\n };\n }\n\n /**\n * Approximation to match the smart contract calculation\n * https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L1026\n * @param rate\n * @param elapsedSlots\n * @private\n */\n private approximateCompoundedInterest(rate: Decimal, elapsedSlots: number): Decimal {\n const base = rate.div(SLOTS_PER_YEAR);\n switch (elapsedSlots) {\n case 0:\n return new Decimal(1);\n case 1:\n return base.add(1);\n case 2:\n return base.add(1).mul(base.add(1));\n case 3:\n return base.add(1).mul(base.add(1)).mul(base.add(1));\n case 4:\n // eslint-disable-next-line no-case-declarations\n const pow2 = base.add(1).mul(base.add(1));\n return pow2.mul(pow2);\n }\n const exp = elapsedSlots;\n const expMinus1 = exp - 1;\n const expMinus2 = exp - 2;\n\n const basePow2 = base.mul(base);\n const basePow3 = basePow2.mul(base);\n\n const firstTerm = base.mul(exp);\n const secondTerm = basePow2.mul(exp).mul(expMinus1).div(2);\n const thirdTerm = basePow3.mul(exp).mul(expMinus1).mul(expMinus2).div(6);\n\n return new Decimal(1).add(firstTerm).add(secondTerm).add(thirdTerm);\n }\n}\n\nconst truncateBorrowCurve = (points: CurvePointFields[]): [number, number][] => {\n const curve: [number, number][] = [];\n for (const { utilizationRateBps, borrowRateBps } of points) {\n curve.push([utilizationRateBps / ONE_HUNDRED_PCT_IN_BPS, borrowRateBps / ONE_HUNDRED_PCT_IN_BPS]);\n\n if (utilizationRateBps === ONE_HUNDRED_PCT_IN_BPS) {\n break;\n }\n }\n return curve;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"reserve.js","sourceRoot":"","sources":["../../src/classes/reserve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,4DAAiC;AACjC,oCAQkB;AAClB,qCAA0D;AAC1D,sDAAiE;AAEjE,mCAA+E;AAC/E,yCAAsC;AACtC,kDAAuB;AAGV,QAAA,+BAA+B,GAAG,GAAG,CAAC;AAEnD,MAAa,aAAa;IAYxB,YACE,KAAc,EACd,OAAkB,EAClB,gBAAiC,EACjC,UAAsB,EACtB,oBAA4B;QAqF9B;;;WAGG;QACH,oBAAe,GAAG,GAAY,EAAE;YAC9B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,eAAO,EAAE;gBAChE,OAAO,IAAI,oBAAO,CAAC,GAAG,CAAC,CAAC;aACzB;YACD,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,KA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,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;CACF;AA1qBD,sCA0qBC;AAED,MAAM,mBAAmB,GAAG,CAAC,MAA0B,EAAsB,EAAE;IAC7E,MAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,KAAK,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,IAAI,MAAM,EAAE;QAC1D,KAAK,CAAC,IAAI,CAAC,CAAC,kBAAkB,GAAG,8BAAsB,EAAE,aAAa,GAAG,8BAAsB,CAAC,CAAC,CAAC;QAElG,IAAI,kBAAkB,KAAK,8BAAsB,EAAE;YACjD,MAAM;SACP;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["/* eslint-disable max-classes-per-file */\nimport { AccountInfo, Connection, PublicKey } from '@solana/web3.js';\nimport Decimal from 'decimal.js';\nimport {\n INITIAL_COLLATERAL_RATE,\n ONE_HUNDRED_PCT_IN_BPS,\n SLOTS_PER_DAY,\n SLOTS_PER_SECOND,\n SLOTS_PER_YEAR,\n TokenOracleData,\n U64_MAX,\n} from '../utils';\nimport { ReserveDataType, ReserveStatus } from './shared';\nimport { Reserve, ReserveFields } from '../idl_codegen/accounts';\nimport { CurvePointFields } from '../idl_codegen/types';\nimport { calculateAPYFromAPR, getBorrowRate, parseTokenSymbol } from './utils';\nimport { Fraction } from './fraction';\nimport BN from 'bn.js';\nimport { ActionType } from './action';\n\nexport const DEFAULT_RECENT_SLOT_DURATION_MS = 450;\n\nexport class KaminoReserve {\n state: Reserve;\n address: PublicKey;\n symbol: string;\n\n tokenOraclePrice: TokenOracleData;\n stats: ReserveDataType;\n\n private buffer: AccountInfo<Buffer> | null;\n private connection: Connection;\n private readonly recentSlotDurationMs: number;\n\n constructor(\n state: Reserve,\n address: PublicKey,\n tokenOraclePrice: TokenOracleData,\n connection: Connection,\n recentSlotDurationMs: number\n ) {\n this.state = state;\n this.address = address;\n this.buffer = null;\n this.tokenOraclePrice = tokenOraclePrice;\n this.stats = {} as ReserveDataType;\n this.connection = connection;\n this.symbol = parseTokenSymbol(state.config.tokenInfo.name);\n this.recentSlotDurationMs = recentSlotDurationMs;\n }\n\n static initialize(\n accountData: AccountInfo<Buffer>,\n address: PublicKey,\n state: Reserve,\n tokenOraclePrice: TokenOracleData,\n connection: Connection,\n recentSlotDurationMs: number\n ) {\n const reserve = new KaminoReserve(state, address, tokenOraclePrice, connection, recentSlotDurationMs);\n reserve.setBuffer(accountData);\n reserve.stats = reserve.formatReserveData(state);\n return reserve;\n }\n\n /// GETTERS\n\n /**\n * @returns the parsed token symbol of the reserve\n */\n getTokenSymbol(): string {\n return parseTokenSymbol(this.state.config.tokenInfo.name);\n }\n\n /**\n * @returns the total borrowed amount of the reserve\n */\n getBorrowedAmount(): Decimal {\n return new Fraction(this.state.liquidity.borrowedAmountSf).toDecimal();\n }\n\n /**\n * @returns the available liquidity amount of the reserve\n */\n getLiquidityAvailableAmount(): Decimal {\n return new Decimal(this.state.liquidity.availableAmount.toString());\n }\n\n /**\n *\n * @returns the last cached price stored in the reserve in USD\n */\n getReserveMarketPrice(): Decimal {\n return new Fraction(this.state.liquidity.marketPriceSf).toDecimal();\n }\n\n /**\n * @returns the current market price of the reserve in USD\n */\n getOracleMarketPrice(): Decimal {\n return this.tokenOraclePrice.price;\n }\n\n /**\n * @returns the total accumulated protocol fees of the reserve\n */\n getAccumulatedProtocolFees(): Decimal {\n return new Fraction(this.state.liquidity.accumulatedProtocolFeesSf).toDecimal();\n }\n\n /**\n * @returns the total accumulated referrer fees of the reserve\n */\n getAccumulatedReferrerFees(): Decimal {\n return new Fraction(this.state.liquidity.accumulatedReferrerFeesSf).toDecimal();\n }\n\n /**\n * @returns the total pending referrer fees of the reserve\n */\n getPendingReferrerFees(): Decimal {\n return new Fraction(this.state.liquidity.pendingReferrerFeesSf).toDecimal();\n }\n\n /**\n *\n * @returns the flash loan fee percentage of the reserve\n */\n getFlashLoanFee = (): Decimal => {\n if (this.state.config.fees.flashLoanFeeSf.toString() === U64_MAX) {\n return new Decimal('0');\n }\n return new Fraction(this.state.config.fees.flashLoanFeeSf).toDecimal();\n };\n\n /**\n *\n * @returns the origination fee percentage of the reserve\n */\n getBorrowFee = (): Decimal => {\n return new Fraction(this.state.config.fees.borrowFeeSf).toDecimal();\n };\n\n /**\n *\n * @returns the fixed interest rate allocated to the host\n */\n getFixedHostInterestRate = (): Decimal => {\n return new Decimal(this.state.config.hostFixedInterestRateBps).div(10_000);\n };\n\n /**\n * Use getEstimatedTotalSupply() for the most accurate value\n * @returns the stale total liquidity supply of the reserve from the last refresh\n */\n getTotalSupply(): Decimal {\n return this.getLiquidityAvailableAmount()\n .add(this.getBorrowedAmount())\n .sub(this.getAccumulatedProtocolFees())\n .sub(this.getAccumulatedReferrerFees())\n .sub(this.getPendingReferrerFees());\n }\n\n /**\n * Calculates the total liquidity supply of the reserve\n */\n getEstimatedTotalSupply(slot: number, referralFeeBps: number): Decimal {\n const { totalSupply } = this.getEstimatedDebtAndSupply(slot, referralFeeBps);\n return totalSupply;\n }\n\n /**\n * Use getEstimatedCumulativeBorrowRate() for the most accurate value\n * @returns the stale cumulative borrow rate of the reserve from the last refresh\n */\n getCumulativeBorrowRate(): Decimal {\n let accSf = new BN(0);\n for (const value of this.state.liquidity.cumulativeBorrowRateBsf.value.reverse()) {\n accSf = accSf.add(value);\n accSf.shrn(64);\n }\n return new Fraction(accSf).toDecimal();\n }\n\n /**\n * @Returns estimated cumulative borrow rate of the reserve\n */\n getEstimatedCumulativeBorrowRate(currentSlot: number): Decimal {\n const currentBorrowRate = new Decimal(this.calculateBorrowAPR());\n const slotsElapsed = Math.max(currentSlot - this.state.lastUpdate.slot.toNumber(), 0);\n\n const compoundInterest = this.approximateCompoundedInterest(currentBorrowRate, slotsElapsed);\n\n const previousCumulativeBorrowRate = this.getCumulativeBorrowRate();\n\n return previousCumulativeBorrowRate.mul(compoundInterest);\n }\n\n /**\n * Use getEstimatedCollateralExchangeRate() for the most accurate value\n * @returns the stale exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18\n */\n getCollateralExchangeRate(): Decimal {\n const totalSupply = this.getTotalSupply();\n const mintTotalSupply = this.state.collateral.mintTotalSupply;\n if (mintTotalSupply.isZero() || totalSupply.isZero()) {\n return INITIAL_COLLATERAL_RATE;\n } else {\n return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());\n }\n }\n\n /**\n *\n * @returns the estimated exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18\n */\n getEstimatedCollateralExchangeRate(slot: number, referralFeeBps: number): Decimal {\n const totalSupply = this.getEstimatedTotalSupply(slot, referralFeeBps);\n const mintTotalSupply = this.state.collateral.mintTotalSupply;\n if (mintTotalSupply.isZero() || totalSupply.isZero()) {\n return INITIAL_COLLATERAL_RATE;\n } else {\n return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());\n }\n }\n\n /**\n *\n * @returns the total USD value of the existing collateral in the reserve\n */\n getDepositTvl = (): Decimal => {\n return new Decimal(this.getTotalSupply().toString()).mul(this.getOracleMarketPrice()).div(this.getMintFactor());\n };\n\n /**\n *\n * Get the total USD value of the borrowed assets from the reserve\n */\n getBorrowTvl = (): Decimal => {\n return this.getBorrowedAmount().mul(this.getOracleMarketPrice()).div(this.getMintFactor());\n };\n\n /**\n * @returns 10^mint_decimals\n */\n getMintFactor(): Decimal {\n return new Decimal(10).pow(this.state.liquidity.mintDecimals.toNumber());\n }\n\n /**\n * @Returns true if the total liquidity supply of the reserve is greater than the deposit limit\n */\n depositLimitCrossed(): boolean {\n return this.getTotalSupply().gt(new Decimal(this.state.config.depositLimit.toString()));\n }\n\n /**\n * @Returns true if the total borrowed amount of the reserve is greater than the borrow limit\n */\n borrowLimitCrossed(): boolean {\n return this.getBorrowedAmount().gt(new Decimal(this.state.config.borrowLimit.toString()));\n }\n\n /**\n *\n * @returns the max capacity of the daily deposit withdrawal cap\n */\n getDepositWithdrawalCapCapacity(): Decimal {\n return new Decimal(this.state.config.depositWithdrawalCap.configCapacity.toString());\n }\n\n /**\n *\n * @returns the current capacity of the daily deposit withdrawal cap\n */\n getDepositWithdrawalCapCurrent(slot: number): Decimal {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n if (slotsElapsed > SLOTS_PER_DAY) {\n return new Decimal(0);\n } else {\n return new Decimal(this.state.config.depositWithdrawalCap.currentTotal.toString());\n }\n }\n\n /**\n *\n * @returns the max capacity of the daily debt withdrawal cap\n */\n getDebtWithdrawalCapCapacity(): Decimal {\n return new Decimal(this.state.config.debtWithdrawalCap.configCapacity.toString());\n }\n\n /**\n *\n * @returns the borrow limit of the reserve outside the elevation group\n */\n getBorrowLimitOutsideElevationGroup(): Decimal {\n return new Decimal(this.state.config.borrowLimitOutsideElevationGroup.toString());\n }\n\n /**\n *\n * @returns the borrowed amount of the reserve outside the elevation group\n */\n getBorrowedAmountOutsideElevationGroup(): Decimal {\n return new Decimal(this.state.borrowedAmountOutsideElevationGroup.toString());\n }\n\n /**\n *\n * @returns the borrow limit against the collateral reserve in the elevation group\n */\n getBorrowLimitAgainstCollateralInElevationGroup(elevationGroupIndex: number): Decimal {\n return new Decimal(\n this.state.config.borrowLimitAgainstThisCollateralInElevationGroup[elevationGroupIndex].toString()\n );\n }\n\n /**\n *\n * @returns the borrowed amount against the collateral reserve in the elevation group\n */\n getBorrowedAmountAgainstCollateralInElevationGroup(elevationGroupIndex: number): Decimal {\n return new Decimal(this.state.borrowedAmountsAgainstThisReserveInElevationGroups[elevationGroupIndex].toString());\n }\n\n /**\n *\n * @returns the current capacity of the daily debt withdrawal cap\n */\n getDebtWithdrawalCapCurrent(slot: number): Decimal {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n if (slotsElapsed > SLOTS_PER_DAY) {\n return new Decimal(0);\n } else {\n return new Decimal(this.state.config.debtWithdrawalCap.currentTotal.toString());\n }\n }\n\n getBorrowFactor(): Decimal {\n return new Decimal(this.state.config.borrowFactorPct.toString()).div(100);\n }\n\n calculateSupplyAPR() {\n const currentUtilization = this.calculateUtilizationRatio();\n\n const borrowAPR = this.calculateBorrowAPR();\n const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;\n return currentUtilization * borrowAPR * protocolTakeRatePct;\n }\n\n getEstimatedDebtAndSupply(slot: number, referralFeeBps: number): { totalBorrow: Decimal; totalSupply: Decimal } {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n let totalBorrow: Decimal;\n let totalSupply: Decimal;\n if (slotsElapsed === 0) {\n totalBorrow = this.getBorrowedAmount();\n totalSupply = this.getTotalSupply();\n } else {\n const { newDebt, newAccProtocolFees, pendingReferralFees } = this.compoundInterest(slotsElapsed, referralFeeBps);\n const newTotalSupply = this.getLiquidityAvailableAmount()\n .add(newDebt)\n .sub(newAccProtocolFees)\n .sub(this.getAccumulatedReferrerFees())\n .sub(pendingReferralFees);\n totalBorrow = newDebt;\n totalSupply = newTotalSupply;\n }\n return { totalBorrow, totalSupply };\n }\n\n getEstimatedAccumulatedProtocolFees(\n slot: number,\n referralFeeBps: number\n ): { accumulatedProtocolFees: Decimal; compoundedVariableProtocolFee: Decimal; compoundedFixedHostFee: Decimal } {\n const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);\n let accumulatedProtocolFees: Decimal;\n let compoundedVariableProtocolFee: Decimal;\n let compoundedFixedHostFee: Decimal;\n if (slotsElapsed === 0) {\n accumulatedProtocolFees = this.getAccumulatedProtocolFees();\n compoundedVariableProtocolFee = new Decimal(0);\n compoundedFixedHostFee = new Decimal(0);\n } else {\n const { newAccProtocolFees, variableProtocolFee, fixedHostFee } = this.compoundInterest(\n slotsElapsed,\n referralFeeBps\n );\n accumulatedProtocolFees = newAccProtocolFees;\n compoundedVariableProtocolFee = variableProtocolFee;\n compoundedFixedHostFee = fixedHostFee;\n }\n return { accumulatedProtocolFees, compoundedVariableProtocolFee, compoundedFixedHostFee };\n }\n\n calculateUtilizationRatio() {\n const totalBorrows = this.getBorrowedAmount();\n const totalSupply = this.getTotalSupply();\n if (totalSupply.eq(0)) {\n return 0;\n }\n return totalBorrows.dividedBy(totalSupply).toNumber();\n }\n\n calcSimulatedUtilizationRatio(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ): number {\n const { totalBorrow: previousTotalBorrowed, totalSupply: previousTotalSupply } = this.getEstimatedDebtAndSupply(\n slot,\n referralFeeBps\n );\n\n switch (action) {\n case 'deposit': {\n const newTotalSupply = previousTotalSupply.add(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'withdraw': {\n const newTotalSupply = previousTotalSupply.sub(amount);\n if (newTotalSupply.eq(0)) {\n return 0;\n } else {\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n }\n case 'borrow': {\n const newTotalBorrowed = previousTotalBorrowed.add(amount);\n return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();\n }\n case 'repay': {\n const newTotalBorrowed = previousTotalBorrowed.sub(amount);\n return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();\n }\n case 'depositAndBorrow': {\n const newTotalSupply = previousTotalSupply.add(amount);\n const newTotalBorrowed = previousTotalBorrowed.add(outflowAmount!);\n return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'repayAndWithdraw': {\n const newTotalBorrowed = previousTotalBorrowed.sub(amount);\n const newTotalSupply = previousTotalSupply.sub(outflowAmount!);\n if (newTotalSupply.eq(0)) {\n return 0;\n }\n return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'mint': {\n const newTotalSupply = previousTotalSupply.add(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n case 'redeem': {\n const newTotalSupply = previousTotalSupply.sub(amount);\n return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();\n }\n default:\n throw Error(`Invalid action type ${action} for simulatedUtilizationRatio`);\n }\n }\n\n calcSimulatedBorrowAPR(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ) {\n const slotAdjustmentFactor = this.slotAdjustmentFactor();\n const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);\n const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);\n return getBorrowRate(newUtilization, curve) * slotAdjustmentFactor;\n }\n\n calcSimulatedSupplyAPR(\n amount: Decimal,\n action: ActionType,\n slot: number,\n referralFeeBps: number,\n outflowAmount?: Decimal\n ) {\n const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);\n const simulatedBorrowAPR = this.calcSimulatedBorrowAPR(amount, action, slot, referralFeeBps, outflowAmount);\n const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;\n\n return newUtilization * simulatedBorrowAPR * protocolTakeRatePct;\n }\n\n slotAdjustmentFactor(): number {\n return 1000 / SLOTS_PER_SECOND / this.recentSlotDurationMs;\n }\n\n calculateBorrowAPR() {\n const slotAdjustmentFactor = this.slotAdjustmentFactor();\n const currentUtilization = this.calculateUtilizationRatio();\n const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);\n return getBorrowRate(currentUtilization, curve) * slotAdjustmentFactor;\n }\n\n /**\n * @returns the mint of the reserve liquidity token\n */\n getLiquidityMint(): PublicKey {\n return this.state.liquidity.mintPubkey;\n }\n\n /**\n * @returns the mint of the reserve collateral token , i.e. the cToken minted for depositing the liquidity token\n */\n getCTokenMint(): PublicKey {\n return this.state.collateral.mintPubkey;\n }\n\n setBuffer(buffer: AccountInfo<Buffer> | null) {\n this.buffer = buffer;\n }\n\n async load(tokenOraclePrice: TokenOracleData) {\n if (!this.buffer) {\n this.setBuffer(await this.connection.getAccountInfo(this.address, 'processed'));\n }\n\n if (!this.buffer) {\n throw Error(`Error requesting account info for ${this.symbol}`);\n }\n\n const parsedData = await Reserve.fetch(this.connection, this.address);\n if (!parsedData) {\n throw Error(`Unable to parse data of reserve ${this.symbol}`);\n }\n this.state = parsedData;\n this.tokenOraclePrice = tokenOraclePrice;\n this.stats = this.formatReserveData(parsedData);\n }\n\n totalSupplyAPY() {\n const { stats } = this;\n if (!stats) {\n throw Error('KaminoMarket must call loadRewards.');\n }\n\n const totalAPY = new Decimal(stats.supplyInterestAPY).toNumber();\n\n return {\n interestAPY: stats.supplyInterestAPY,\n totalAPY,\n };\n }\n\n totalBorrowAPY() {\n const { stats } = this;\n if (!stats) {\n throw Error('KaminoMarket must call loadRewards.');\n }\n\n const totalAPY = new Decimal(stats.borrowInterestAPY).toNumber();\n\n return {\n interestAPY: stats.borrowInterestAPY,\n totalAPY,\n };\n }\n\n private formatReserveData(parsedData: ReserveFields): ReserveDataType {\n const mintTotalSupply = new Decimal(parsedData.collateral.mintTotalSupply.toString()).div(this.getMintFactor());\n let reserveStatus = ReserveStatus.Active;\n switch (parsedData.config.status) {\n case 0:\n reserveStatus = ReserveStatus.Active;\n break;\n case 1:\n reserveStatus = ReserveStatus.Obsolete;\n break;\n case 2:\n reserveStatus = ReserveStatus.Hidden;\n break;\n }\n return {\n // Reserve config\n\n status: reserveStatus,\n mintAddress: parsedData.liquidity.mintPubkey,\n borrowCurve: truncateBorrowCurve(parsedData.config.borrowRateCurve.points),\n loanToValuePct: parsedData.config.loanToValuePct / 100,\n maxLiquidationBonus: parsedData.config.maxLiquidationBonusBps / 10000,\n minLiquidationBonus: parsedData.config.minLiquidationBonusBps / 10000,\n liquidationThreshold: parsedData.config.liquidationThresholdPct / 100,\n protocolTakeRate: parsedData.config.protocolTakeRatePct / 100,\n reserveDepositLimit: new Decimal(parsedData.config.depositLimit.toString()),\n reserveBorrowLimit: new Decimal(parsedData.config.borrowLimit.toString()),\n\n // Reserve info\n symbol: parseTokenSymbol(parsedData.config.tokenInfo.name),\n decimals: this.state.liquidity.mintDecimals.toNumber(),\n supplyInterestAPY: calculateAPYFromAPR(this.calculateSupplyAPR()),\n borrowInterestAPY: calculateAPYFromAPR(this.calculateBorrowAPR()),\n accumulatedProtocolFees: this.getAccumulatedProtocolFees().div(this.getMintFactor()),\n mintTotalSupply,\n depositLimitCrossedSlot: parsedData.liquidity.depositLimitCrossedSlot.toNumber(),\n borrowLimitCrossedSlot: parsedData.liquidity.borrowLimitCrossedSlot.toNumber(),\n borrowFactor: parsedData.config.borrowFactorPct.toNumber(),\n };\n }\n\n /**\n * Compound current borrow rate over elapsed slots\n *\n * This also calculates protocol fees, which are taken for all obligations that have borrowed from current reserve.\n *\n * This also calculates referral fees, which are taken into pendingReferralFees.\n *\n * https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L517\n *\n * @param slotsElapsed\n * @param referralFeeBps\n */\n private compoundInterest(\n slotsElapsed: number,\n referralFeeBps: number\n ): {\n newDebt: Decimal;\n netNewDebt: Decimal;\n variableProtocolFee: Decimal;\n fixedHostFee: Decimal;\n absoluteReferralFee: Decimal;\n maxReferralFees: Decimal;\n newAccProtocolFees: Decimal;\n pendingReferralFees: Decimal;\n } {\n const currentBorrowRate = this.calculateBorrowAPR();\n const protocolTakeRate = new Decimal(this.state.config.protocolTakeRatePct).div(100);\n const referralRate = new Decimal(referralFeeBps).div(10_000);\n const fixedHostInterestRate = this.getFixedHostInterestRate();\n\n const compoundedInterestRate = this.approximateCompoundedInterest(new Decimal(currentBorrowRate), slotsElapsed);\n const compoundedFixedRate = this.approximateCompoundedInterest(fixedHostInterestRate, slotsElapsed);\n\n const previousDebt = this.getBorrowedAmount();\n const newDebt = previousDebt.mul(compoundedInterestRate);\n const fixedHostFee = previousDebt.mul(compoundedFixedRate).sub(previousDebt);\n\n const netNewDebt = newDebt.sub(previousDebt).sub(fixedHostFee);\n\n const variableProtocolFee = netNewDebt.mul(protocolTakeRate);\n const absoluteReferralFee = protocolTakeRate.mul(referralRate);\n const maxReferralFees = netNewDebt.mul(absoluteReferralFee);\n\n const newAccProtocolFees = variableProtocolFee\n .add(fixedHostFee)\n .sub(maxReferralFees)\n .add(this.getAccumulatedProtocolFees());\n\n const pendingReferralFees = this.getPendingReferrerFees().add(maxReferralFees);\n\n return {\n newDebt,\n netNewDebt,\n variableProtocolFee,\n fixedHostFee,\n absoluteReferralFee,\n maxReferralFees,\n newAccProtocolFees,\n pendingReferralFees,\n };\n }\n\n /**\n * Approximation to match the smart contract calculation\n * https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L1026\n * @param rate\n * @param elapsedSlots\n * @private\n */\n private approximateCompoundedInterest(rate: Decimal, elapsedSlots: number): Decimal {\n const base = rate.div(SLOTS_PER_YEAR);\n switch (elapsedSlots) {\n case 0:\n return new Decimal(1);\n case 1:\n return base.add(1);\n case 2:\n return base.add(1).mul(base.add(1));\n case 3:\n return base.add(1).mul(base.add(1)).mul(base.add(1));\n case 4:\n // eslint-disable-next-line no-case-declarations\n const pow2 = base.add(1).mul(base.add(1));\n return pow2.mul(pow2);\n }\n const exp = elapsedSlots;\n const expMinus1 = exp - 1;\n const expMinus2 = exp - 2;\n\n const basePow2 = base.mul(base);\n const basePow3 = basePow2.mul(base);\n\n const firstTerm = base.mul(exp);\n const secondTerm = basePow2.mul(exp).mul(expMinus1).div(2);\n const thirdTerm = basePow3.mul(exp).mul(expMinus1).mul(expMinus2).div(6);\n\n return new Decimal(1).add(firstTerm).add(secondTerm).add(thirdTerm);\n }\n}\n\nconst truncateBorrowCurve = (points: CurvePointFields[]): [number, number][] => {\n const curve: [number, number][] = [];\n for (const { utilizationRateBps, borrowRateBps } of points) {\n curve.push([utilizationRateBps / ONE_HUNDRED_PCT_IN_BPS, borrowRateBps / ONE_HUNDRED_PCT_IN_BPS]);\n\n if (utilizationRateBps === ONE_HUNDRED_PCT_IN_BPS) {\n break;\n }\n }\n return curve;\n};\n"]}
|
package/dist/idl.json
CHANGED
|
@@ -222,7 +222,7 @@
|
|
|
222
222
|
]
|
|
223
223
|
},
|
|
224
224
|
{
|
|
225
|
-
"name": "
|
|
225
|
+
"name": "updateReserveConfig",
|
|
226
226
|
"accounts": [
|
|
227
227
|
{
|
|
228
228
|
"name": "lendingMarketOwner",
|
|
@@ -247,12 +247,7 @@
|
|
|
247
247
|
},
|
|
248
248
|
{
|
|
249
249
|
"name": "value",
|
|
250
|
-
"type":
|
|
251
|
-
"array": [
|
|
252
|
-
"u8",
|
|
253
|
-
32
|
|
254
|
-
]
|
|
255
|
-
}
|
|
250
|
+
"type": "bytes"
|
|
256
251
|
},
|
|
257
252
|
{
|
|
258
253
|
"name": "skipValidation",
|
|
@@ -260,41 +255,6 @@
|
|
|
260
255
|
}
|
|
261
256
|
]
|
|
262
257
|
},
|
|
263
|
-
{
|
|
264
|
-
"name": "updateEntireReserveConfig",
|
|
265
|
-
"accounts": [
|
|
266
|
-
{
|
|
267
|
-
"name": "lendingMarketOwner",
|
|
268
|
-
"isMut": false,
|
|
269
|
-
"isSigner": true
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
"name": "lendingMarket",
|
|
273
|
-
"isMut": false,
|
|
274
|
-
"isSigner": false
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
"name": "reserve",
|
|
278
|
-
"isMut": true,
|
|
279
|
-
"isSigner": false
|
|
280
|
-
}
|
|
281
|
-
],
|
|
282
|
-
"args": [
|
|
283
|
-
{
|
|
284
|
-
"name": "mode",
|
|
285
|
-
"type": "u64"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
"name": "value",
|
|
289
|
-
"type": {
|
|
290
|
-
"array": [
|
|
291
|
-
"u8",
|
|
292
|
-
648
|
|
293
|
-
]
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
]
|
|
297
|
-
},
|
|
298
258
|
{
|
|
299
259
|
"name": "redeemFees",
|
|
300
260
|
"accounts": [
|
|
@@ -867,7 +827,7 @@
|
|
|
867
827
|
},
|
|
868
828
|
{
|
|
869
829
|
"name": "withdrawReserve",
|
|
870
|
-
"isMut":
|
|
830
|
+
"isMut": true,
|
|
871
831
|
"isSigner": false
|
|
872
832
|
},
|
|
873
833
|
{
|
|
@@ -1250,7 +1210,7 @@
|
|
|
1250
1210
|
"type": "u64"
|
|
1251
1211
|
},
|
|
1252
1212
|
{
|
|
1253
|
-
"name": "
|
|
1213
|
+
"name": "minAcceptableReceivedLiquidityAmount",
|
|
1254
1214
|
"type": "u64"
|
|
1255
1215
|
},
|
|
1256
1216
|
{
|
|
@@ -1891,9 +1851,6 @@
|
|
|
1891
1851
|
},
|
|
1892
1852
|
{
|
|
1893
1853
|
"name": "borrowDisabled",
|
|
1894
|
-
"docs": [
|
|
1895
|
-
"Padding used for alignment"
|
|
1896
|
-
],
|
|
1897
1854
|
"type": "u8"
|
|
1898
1855
|
},
|
|
1899
1856
|
{
|
|
@@ -1996,12 +1953,16 @@
|
|
|
1996
1953
|
],
|
|
1997
1954
|
"type": "u128"
|
|
1998
1955
|
},
|
|
1956
|
+
{
|
|
1957
|
+
"name": "minValueSkipLiquidationLtvBfChecks",
|
|
1958
|
+
"type": "u64"
|
|
1959
|
+
},
|
|
1999
1960
|
{
|
|
2000
1961
|
"name": "padding1",
|
|
2001
1962
|
"type": {
|
|
2002
1963
|
"array": [
|
|
2003
1964
|
"u64",
|
|
2004
|
-
|
|
1965
|
+
177
|
|
2005
1966
|
]
|
|
2006
1967
|
}
|
|
2007
1968
|
}
|
|
@@ -2062,7 +2023,7 @@
|
|
|
2062
2023
|
}
|
|
2063
2024
|
},
|
|
2064
2025
|
{
|
|
2065
|
-
"name": "
|
|
2026
|
+
"name": "lowestReserveDepositLiquidationLtv",
|
|
2066
2027
|
"docs": [
|
|
2067
2028
|
"Worst LTV for the collaterals backing the loan, represented as a percentage"
|
|
2068
2029
|
],
|
|
@@ -2185,12 +2146,16 @@
|
|
|
2185
2146
|
]
|
|
2186
2147
|
}
|
|
2187
2148
|
},
|
|
2149
|
+
{
|
|
2150
|
+
"name": "highestBorrowFactorPct",
|
|
2151
|
+
"type": "u64"
|
|
2152
|
+
},
|
|
2188
2153
|
{
|
|
2189
2154
|
"name": "padding3",
|
|
2190
2155
|
"type": {
|
|
2191
2156
|
"array": [
|
|
2192
2157
|
"u64",
|
|
2193
|
-
|
|
2158
|
+
126
|
|
2194
2159
|
]
|
|
2195
2160
|
}
|
|
2196
2161
|
}
|
|
@@ -2427,7 +2392,24 @@
|
|
|
2427
2392
|
"type": {
|
|
2428
2393
|
"array": [
|
|
2429
2394
|
"u64",
|
|
2430
|
-
|
|
2395
|
+
117
|
|
2396
|
+
]
|
|
2397
|
+
}
|
|
2398
|
+
},
|
|
2399
|
+
{
|
|
2400
|
+
"name": "borrowedAmountOutsideElevationGroup",
|
|
2401
|
+
"type": "u64"
|
|
2402
|
+
},
|
|
2403
|
+
{
|
|
2404
|
+
"name": "borrowedAmountsAgainstThisReserveInElevationGroups",
|
|
2405
|
+
"docs": [
|
|
2406
|
+
"Amount of token borrowed in lamport of debt asset in the given",
|
|
2407
|
+
"elevation group when this reserve is part of the collaterals."
|
|
2408
|
+
],
|
|
2409
|
+
"type": {
|
|
2410
|
+
"array": [
|
|
2411
|
+
"u64",
|
|
2412
|
+
32
|
|
2431
2413
|
]
|
|
2432
2414
|
}
|
|
2433
2415
|
},
|
|
@@ -2436,7 +2418,7 @@
|
|
|
2436
2418
|
"type": {
|
|
2437
2419
|
"array": [
|
|
2438
2420
|
"u64",
|
|
2439
|
-
|
|
2421
|
+
207
|
|
2440
2422
|
]
|
|
2441
2423
|
}
|
|
2442
2424
|
}
|
|
@@ -2581,6 +2563,15 @@
|
|
|
2581
2563
|
},
|
|
2582
2564
|
{
|
|
2583
2565
|
"name": "UpdateBlockPriceUsage"
|
|
2566
|
+
},
|
|
2567
|
+
{
|
|
2568
|
+
"name": "UpdateBorrowLimitOutsideElevationGroup"
|
|
2569
|
+
},
|
|
2570
|
+
{
|
|
2571
|
+
"name": "UpdateBorrowLimitsInElevationGroupAgainstThisReserve"
|
|
2572
|
+
},
|
|
2573
|
+
{
|
|
2574
|
+
"name": "UpdateHostFixedInterestRateBps"
|
|
2584
2575
|
}
|
|
2585
2576
|
]
|
|
2586
2577
|
}
|
|
@@ -2700,6 +2691,9 @@
|
|
|
2700
2691
|
},
|
|
2701
2692
|
{
|
|
2702
2693
|
"name": "UpdateMinNetValueObligationPostAction"
|
|
2694
|
+
},
|
|
2695
|
+
{
|
|
2696
|
+
"name": "UpdateMinValueSkipPriorityLiqCheck"
|
|
2703
2697
|
}
|
|
2704
2698
|
]
|
|
2705
2699
|
}
|
|
@@ -2771,20 +2765,26 @@
|
|
|
2771
2765
|
"type": "u8"
|
|
2772
2766
|
},
|
|
2773
2767
|
{
|
|
2774
|
-
"name": "
|
|
2775
|
-
"type":
|
|
2776
|
-
"array": [
|
|
2777
|
-
"u8",
|
|
2778
|
-
2
|
|
2779
|
-
]
|
|
2780
|
-
}
|
|
2768
|
+
"name": "maxReservesAsCollateral",
|
|
2769
|
+
"type": "u8"
|
|
2781
2770
|
},
|
|
2782
2771
|
{
|
|
2783
|
-
"name": "
|
|
2772
|
+
"name": "padding0",
|
|
2773
|
+
"type": "u8"
|
|
2774
|
+
},
|
|
2775
|
+
{
|
|
2776
|
+
"name": "debtReserve",
|
|
2777
|
+
"docs": [
|
|
2778
|
+
"Mandatory debt reserve for this elevation group"
|
|
2779
|
+
],
|
|
2780
|
+
"type": "publicKey"
|
|
2781
|
+
},
|
|
2782
|
+
{
|
|
2783
|
+
"name": "padding1",
|
|
2784
2784
|
"type": {
|
|
2785
2785
|
"array": [
|
|
2786
2786
|
"u64",
|
|
2787
|
-
|
|
2787
|
+
4
|
|
2788
2788
|
]
|
|
2789
2789
|
}
|
|
2790
2790
|
}
|
|
@@ -2836,12 +2836,22 @@
|
|
|
2836
2836
|
],
|
|
2837
2837
|
"type": "u128"
|
|
2838
2838
|
},
|
|
2839
|
+
{
|
|
2840
|
+
"name": "borrowedAmountAgainstThisCollateralInElevationGroup",
|
|
2841
|
+
"docs": [
|
|
2842
|
+
"Debt amount (lamport) taken against this collateral.",
|
|
2843
|
+
"(only meaningful if this obligation is part of an elevation group, otherwise 0)",
|
|
2844
|
+
"This is only indicative of the debt computed on the last refresh obligation.",
|
|
2845
|
+
"If the obligation have multiple collateral this value is the same for all of them."
|
|
2846
|
+
],
|
|
2847
|
+
"type": "u64"
|
|
2848
|
+
},
|
|
2839
2849
|
{
|
|
2840
2850
|
"name": "padding",
|
|
2841
2851
|
"type": {
|
|
2842
2852
|
"array": [
|
|
2843
2853
|
"u64",
|
|
2844
|
-
|
|
2854
|
+
9
|
|
2845
2855
|
]
|
|
2846
2856
|
}
|
|
2847
2857
|
}
|
|
@@ -2897,12 +2907,19 @@
|
|
|
2897
2907
|
],
|
|
2898
2908
|
"type": "u128"
|
|
2899
2909
|
},
|
|
2910
|
+
{
|
|
2911
|
+
"name": "borrowedAmountOutsideElevationGroups",
|
|
2912
|
+
"docs": [
|
|
2913
|
+
"Amount of liquidity borrowed outside of an elevation group"
|
|
2914
|
+
],
|
|
2915
|
+
"type": "u64"
|
|
2916
|
+
},
|
|
2900
2917
|
{
|
|
2901
2918
|
"name": "padding2",
|
|
2902
2919
|
"type": {
|
|
2903
2920
|
"array": [
|
|
2904
2921
|
"u64",
|
|
2905
|
-
|
|
2922
|
+
7
|
|
2906
2923
|
]
|
|
2907
2924
|
}
|
|
2908
2925
|
}
|
|
@@ -3042,13 +3059,11 @@
|
|
|
3042
3059
|
"type": "u8"
|
|
3043
3060
|
},
|
|
3044
3061
|
{
|
|
3045
|
-
"name": "
|
|
3046
|
-
"
|
|
3047
|
-
"
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
]
|
|
3051
|
-
}
|
|
3062
|
+
"name": "hostFixedInterestRateBps",
|
|
3063
|
+
"docs": [
|
|
3064
|
+
"Flat rate that goes to the host"
|
|
3065
|
+
],
|
|
3066
|
+
"type": "u16"
|
|
3052
3067
|
},
|
|
3053
3068
|
{
|
|
3054
3069
|
"name": "multiplierSideBoost",
|
|
@@ -3230,6 +3245,30 @@
|
|
|
3230
3245
|
2
|
|
3231
3246
|
]
|
|
3232
3247
|
}
|
|
3248
|
+
},
|
|
3249
|
+
{
|
|
3250
|
+
"name": "borrowLimitOutsideElevationGroup",
|
|
3251
|
+
"docs": [
|
|
3252
|
+
"Maximum amount liquidity of this reserve borrowed outside all elevation groups",
|
|
3253
|
+
"- u64::MAX for inf",
|
|
3254
|
+
"- 0 to disable borrows outside elevation groups"
|
|
3255
|
+
],
|
|
3256
|
+
"type": "u64"
|
|
3257
|
+
},
|
|
3258
|
+
{
|
|
3259
|
+
"name": "borrowLimitAgainstThisCollateralInElevationGroup",
|
|
3260
|
+
"docs": [
|
|
3261
|
+
"Defines the maximum amount (in lamports of elevation group debt asset)",
|
|
3262
|
+
"that can be borrowed when this reserve is used as collateral.",
|
|
3263
|
+
"- u64::MAX for inf",
|
|
3264
|
+
"- 0 to disable borrows in this elevation group (expected value for the debt asset)"
|
|
3265
|
+
],
|
|
3266
|
+
"type": {
|
|
3267
|
+
"array": [
|
|
3268
|
+
"u64",
|
|
3269
|
+
32
|
|
3270
|
+
]
|
|
3271
|
+
}
|
|
3233
3272
|
}
|
|
3234
3273
|
]
|
|
3235
3274
|
}
|
|
@@ -4041,8 +4080,8 @@
|
|
|
4041
4080
|
},
|
|
4042
4081
|
{
|
|
4043
4082
|
"code": 6066,
|
|
4044
|
-
"name": "
|
|
4045
|
-
"msg": "The reward amount is less than the minimum acceptable received
|
|
4083
|
+
"name": "LiquidationRewardTooSmall",
|
|
4084
|
+
"msg": "The reward amount is less than the minimum acceptable received liquidity"
|
|
4046
4085
|
},
|
|
4047
4086
|
{
|
|
4048
4087
|
"code": 6067,
|
|
@@ -4203,6 +4242,51 @@
|
|
|
4203
4242
|
"code": 6098,
|
|
4204
4243
|
"name": "BorrowingAboveUtilizationRateDisabled",
|
|
4205
4244
|
"msg": "Borrowing above set utilization rate is disabled"
|
|
4245
|
+
},
|
|
4246
|
+
{
|
|
4247
|
+
"code": 6099,
|
|
4248
|
+
"name": "LiquidationBorrowFactorPriority",
|
|
4249
|
+
"msg": "Liquidation must prioritize the debt with the highest borrow factor"
|
|
4250
|
+
},
|
|
4251
|
+
{
|
|
4252
|
+
"code": 6100,
|
|
4253
|
+
"name": "LiquidationLowestLTVPriority",
|
|
4254
|
+
"msg": "Liquidation must prioritize the collateral with the lowest LTV"
|
|
4255
|
+
},
|
|
4256
|
+
{
|
|
4257
|
+
"code": 6101,
|
|
4258
|
+
"name": "ElevationGroupBorrowLimitExceeded",
|
|
4259
|
+
"msg": "Elevation group borrow limit exceeded"
|
|
4260
|
+
},
|
|
4261
|
+
{
|
|
4262
|
+
"code": 6102,
|
|
4263
|
+
"name": "ElevationGroupWithoutDebtReserve",
|
|
4264
|
+
"msg": "The elevation group does not have a debt reserve defined"
|
|
4265
|
+
},
|
|
4266
|
+
{
|
|
4267
|
+
"code": 6103,
|
|
4268
|
+
"name": "ElevationGroupMaxCollateralReserveZero",
|
|
4269
|
+
"msg": "The elevation group does not allow any collateral reserves"
|
|
4270
|
+
},
|
|
4271
|
+
{
|
|
4272
|
+
"code": 6104,
|
|
4273
|
+
"name": "ElevationGroupHasAnotherDebtReserve",
|
|
4274
|
+
"msg": "In elevation group attempt to borrow from a reserve that is not the debt reserve"
|
|
4275
|
+
},
|
|
4276
|
+
{
|
|
4277
|
+
"code": 6105,
|
|
4278
|
+
"name": "ElevationGroupDebtReserveAsCollateral",
|
|
4279
|
+
"msg": "The elevation group's debt reserve cannot be used as a collateral reserve"
|
|
4280
|
+
},
|
|
4281
|
+
{
|
|
4282
|
+
"code": 6106,
|
|
4283
|
+
"name": "ObligationCollateralExceedsElevationGroupLimit",
|
|
4284
|
+
"msg": "Obligation have more collateral than the maximum allowed by the elevation group"
|
|
4285
|
+
},
|
|
4286
|
+
{
|
|
4287
|
+
"code": 6107,
|
|
4288
|
+
"name": "ObligationElevationGroupMultipleDebtReserve",
|
|
4289
|
+
"msg": "Obligation is an elevation group but have more than one debt reserve"
|
|
4206
4290
|
}
|
|
4207
4291
|
]
|
|
4208
4292
|
}
|
|
@@ -20,7 +20,6 @@ export interface LendingMarketFields {
|
|
|
20
20
|
referralFeeBps: number;
|
|
21
21
|
emergencyMode: number;
|
|
22
22
|
autodeleverageEnabled: number;
|
|
23
|
-
/** Padding used for alignment */
|
|
24
23
|
borrowDisabled: number;
|
|
25
24
|
/**
|
|
26
25
|
* Refresh price from oracle only if it's older than this percentage of the price max age.
|
|
@@ -49,6 +48,7 @@ export interface LendingMarketFields {
|
|
|
49
48
|
elevationGroupPadding: Array<BN>;
|
|
50
49
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
51
50
|
minNetValueInObligationSf: BN;
|
|
51
|
+
minValueSkipLiquidationLtvBfChecks: BN;
|
|
52
52
|
padding1: Array<BN>;
|
|
53
53
|
}
|
|
54
54
|
export interface LendingMarketJSON {
|
|
@@ -69,7 +69,6 @@ export interface LendingMarketJSON {
|
|
|
69
69
|
referralFeeBps: number;
|
|
70
70
|
emergencyMode: number;
|
|
71
71
|
autodeleverageEnabled: number;
|
|
72
|
-
/** Padding used for alignment */
|
|
73
72
|
borrowDisabled: number;
|
|
74
73
|
/**
|
|
75
74
|
* Refresh price from oracle only if it's older than this percentage of the price max age.
|
|
@@ -98,6 +97,7 @@ export interface LendingMarketJSON {
|
|
|
98
97
|
elevationGroupPadding: Array<string>;
|
|
99
98
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
100
99
|
minNetValueInObligationSf: string;
|
|
100
|
+
minValueSkipLiquidationLtvBfChecks: string;
|
|
101
101
|
padding1: Array<string>;
|
|
102
102
|
}
|
|
103
103
|
export declare class LendingMarket {
|
|
@@ -118,7 +118,6 @@ export declare class LendingMarket {
|
|
|
118
118
|
readonly referralFeeBps: number;
|
|
119
119
|
readonly emergencyMode: number;
|
|
120
120
|
readonly autodeleverageEnabled: number;
|
|
121
|
-
/** Padding used for alignment */
|
|
122
121
|
readonly borrowDisabled: number;
|
|
123
122
|
/**
|
|
124
123
|
* Refresh price from oracle only if it's older than this percentage of the price max age.
|
|
@@ -147,6 +146,7 @@ export declare class LendingMarket {
|
|
|
147
146
|
readonly elevationGroupPadding: Array<BN>;
|
|
148
147
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
149
148
|
readonly minNetValueInObligationSf: BN;
|
|
149
|
+
readonly minValueSkipLiquidationLtvBfChecks: BN;
|
|
150
150
|
readonly padding1: Array<BN>;
|
|
151
151
|
static readonly discriminator: Buffer;
|
|
152
152
|
static readonly layout: any;
|