@kamino-finance/klend-sdk 3.2.26 → 4.0.1
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.d.ts.map +1 -0
- package/dist/classes/action.js +1132 -1188
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/curve.d.ts +1 -0
- package/dist/classes/curve.d.ts.map +1 -0
- package/dist/classes/curve.js +1 -1
- package/dist/classes/curve.js.map +1 -1
- package/dist/classes/fraction.d.ts +1 -0
- package/dist/classes/fraction.d.ts.map +1 -0
- package/dist/classes/fraction.js +7 -6
- package/dist/classes/fraction.js.map +1 -1
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.d.ts.map +1 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/jupiterPerps.d.ts +1 -0
- package/dist/classes/jupiterPerps.d.ts.map +1 -0
- package/dist/classes/jupiterPerps.js +7 -18
- package/dist/classes/jupiterPerps.js.map +1 -1
- package/dist/classes/manager.d.ts +1 -0
- package/dist/classes/manager.d.ts.map +1 -0
- package/dist/classes/manager.js +132 -159
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +2 -1
- package/dist/classes/market.d.ts.map +1 -0
- package/dist/classes/market.js +622 -716
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -0
- package/dist/classes/obligation.d.ts.map +1 -0
- package/dist/classes/obligation.js +60 -62
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -0
- package/dist/classes/reserve.d.ts.map +1 -0
- package/dist/classes/reserve.js +121 -130
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +2 -1
- package/dist/classes/shared.d.ts.map +1 -0
- package/dist/classes/shared.js.map +1 -1
- package/dist/classes/utils.d.ts +1 -0
- package/dist/classes/utils.d.ts.map +1 -0
- package/dist/classes/utils.js +3 -3
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +1 -0
- package/dist/classes/vault.d.ts.map +1 -0
- package/dist/classes/vault.js +334 -354
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts +1 -0
- package/dist/client_kamino_manager.d.ts.map +1 -0
- package/dist/client_kamino_manager.js +323 -326
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +1 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/LendingMarket.js +89 -55
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +1 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/Obligation.js +87 -56
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/accounts/ReferrerState.d.ts +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.js +22 -33
- package/dist/idl_codegen/accounts/ReferrerState.js.map +1 -1
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.js +35 -37
- package/dist/idl_codegen/accounts/ReferrerTokenState.js.map +1 -1
- package/dist/idl_codegen/accounts/Reserve.d.ts +1 -0
- package/dist/idl_codegen/accounts/Reserve.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/Reserve.js +60 -49
- package/dist/idl_codegen/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen/accounts/ShortUrl.d.ts +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.js +22 -33
- package/dist/idl_codegen/accounts/ShortUrl.js.map +1 -1
- package/dist/idl_codegen/accounts/UserMetadata.d.ts +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.js +34 -37
- package/dist/idl_codegen/accounts/UserMetadata.js.map +1 -1
- package/dist/idl_codegen/accounts/UserState.d.ts +1 -0
- package/dist/idl_codegen/accounts/UserState.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/UserState.js +77 -48
- package/dist/idl_codegen/accounts/UserState.js.map +1 -1
- package/dist/idl_codegen/accounts/index.d.ts +1 -0
- package/dist/idl_codegen/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen/accounts/index.js.map +1 -1
- package/dist/idl_codegen/errors/anchor.d.ts +1 -0
- package/dist/idl_codegen/errors/anchor.d.ts.map +1 -0
- package/dist/idl_codegen/errors/anchor.js +270 -216
- package/dist/idl_codegen/errors/anchor.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +1 -0
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -0
- package/dist/idl_codegen/errors/custom.js +560 -448
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/errors/index.d.ts +1 -0
- package/dist/idl_codegen/errors/index.d.ts.map +1 -0
- package/dist/idl_codegen/errors/index.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js.map +1 -1
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +1 -0
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligation.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligation.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initObligation.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js.map +1 -1
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.d.ts +1 -0
- package/dist/idl_codegen/instructions/redeemFees.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligation.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshReservesBatch.d.ts +1 -0
- package/dist/idl_codegen/instructions/refreshReservesBatch.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/refreshReservesBatch.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.js.map +1 -1
- package/dist/idl_codegen/instructions/socializeLoss.d.ts +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.js.map +1 -1
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.js.map +1 -1
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.js.map +1 -1
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/programId.d.ts +1 -0
- package/dist/idl_codegen/programId.d.ts.map +1 -0
- package/dist/idl_codegen/programId.js.map +1 -1
- package/dist/idl_codegen/types/AssetTier.d.ts +1 -0
- package/dist/idl_codegen/types/AssetTier.d.ts.map +1 -0
- package/dist/idl_codegen/types/AssetTier.js +12 -18
- package/dist/idl_codegen/types/AssetTier.js.map +1 -1
- package/dist/idl_codegen/types/BigFractionBytes.d.ts +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.d.ts.map +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.js +2 -0
- package/dist/idl_codegen/types/BigFractionBytes.js.map +1 -1
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts.map +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.js +2 -1
- package/dist/idl_codegen/types/BorrowRateCurve.js.map +1 -1
- package/dist/idl_codegen/types/CurvePoint.d.ts +1 -0
- package/dist/idl_codegen/types/CurvePoint.d.ts.map +1 -0
- package/dist/idl_codegen/types/CurvePoint.js +2 -0
- package/dist/idl_codegen/types/CurvePoint.js.map +1 -1
- package/dist/idl_codegen/types/ElevationGroup.d.ts +1 -0
- package/dist/idl_codegen/types/ElevationGroup.d.ts.map +1 -0
- package/dist/idl_codegen/types/ElevationGroup.js +10 -0
- package/dist/idl_codegen/types/ElevationGroup.js.map +1 -1
- package/dist/idl_codegen/types/FeeCalculation.d.ts +1 -0
- package/dist/idl_codegen/types/FeeCalculation.d.ts.map +1 -0
- package/dist/idl_codegen/types/FeeCalculation.js +8 -12
- package/dist/idl_codegen/types/FeeCalculation.js.map +1 -1
- package/dist/idl_codegen/types/InitObligationArgs.d.ts +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.d.ts.map +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.js +2 -0
- package/dist/idl_codegen/types/InitObligationArgs.js.map +1 -1
- package/dist/idl_codegen/types/LastUpdate.d.ts +1 -0
- package/dist/idl_codegen/types/LastUpdate.d.ts.map +1 -0
- package/dist/idl_codegen/types/LastUpdate.js +7 -0
- package/dist/idl_codegen/types/LastUpdate.js.map +1 -1
- package/dist/idl_codegen/types/ObligationCollateral.d.ts +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.js +14 -0
- package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js +17 -1
- package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/PriceHeuristic.d.ts +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.d.ts.map +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.js +6 -0
- package/dist/idl_codegen/types/PriceHeuristic.js.map +1 -1
- package/dist/idl_codegen/types/PythConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/PythConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/PythConfiguration.js +2 -0
- package/dist/idl_codegen/types/PythConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/ReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.js +8 -0
- package/dist/idl_codegen/types/ReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/types/ReserveConfig.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveConfig.js +78 -5
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.js +8 -12
- package/dist/idl_codegen/types/ReserveFarmKind.js.map +1 -1
- package/dist/idl_codegen/types/ReserveFees.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveFees.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveFees.js +16 -0
- package/dist/idl_codegen/types/ReserveFees.js.map +1 -1
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.js +43 -1
- package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/types/ReserveStatus.d.ts +1 -0
- package/dist/idl_codegen/types/ReserveStatus.d.ts.map +1 -0
- package/dist/idl_codegen/types/ReserveStatus.js +12 -18
- package/dist/idl_codegen/types/ReserveStatus.js.map +1 -1
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js +6 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js +3 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js.map +1 -1
- package/dist/idl_codegen/types/TokenInfo.d.ts +1 -0
- package/dist/idl_codegen/types/TokenInfo.d.ts.map +1 -0
- package/dist/idl_codegen/types/TokenInfo.js +27 -4
- package/dist/idl_codegen/types/TokenInfo.js.map +1 -1
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js +188 -282
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +41 -33
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +72 -108
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts.map +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js +4 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +1 -0
- package/dist/idl_codegen/types/index.d.ts.map +1 -0
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.js +83 -54
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/idl_codegen/zero_padding/index.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/index.d.ts.map +1 -0
- package/dist/idl_codegen/zero_padding/index.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js +39 -42
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/programId.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js +9 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js +3 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js +3 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js.map +1 -1
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js +58 -47
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +51 -47
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.js +270 -216
- package/dist/idl_codegen_kamino_vault/errors/anchor.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.js +120 -96
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/programId.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/programId.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/programId.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js +2 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js +7 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js +6 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js +2 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js +8 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js +77 -5
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js +16 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js +41 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js +6 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js +3 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js +27 -4
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js +8 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +4 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lending_operations/index.d.ts +1 -0
- package/dist/lending_operations/index.d.ts.map +1 -0
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.js +15 -24
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -0
- package/dist/leverage/calcs.d.ts.map +1 -0
- package/dist/leverage/calcs.js +119 -132
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/index.d.ts +1 -0
- package/dist/leverage/index.d.ts.map +1 -0
- package/dist/leverage/index.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -0
- package/dist/leverage/instructions.d.ts.map +1 -0
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +1 -0
- package/dist/leverage/operations.d.ts.map +1 -0
- package/dist/leverage/operations.js +75 -84
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/utils.d.ts +1 -0
- package/dist/leverage/utils.d.ts.map +1 -0
- package/dist/leverage/utils.js +73 -88
- package/dist/leverage/utils.js.map +1 -1
- package/dist/lib.d.ts +1 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js.map +1 -1
- package/dist/referrals/index.d.ts +1 -0
- package/dist/referrals/index.d.ts.map +1 -0
- package/dist/referrals/index.js.map +1 -1
- package/dist/referrals/instructions.d.ts +1 -0
- package/dist/referrals/instructions.d.ts.map +1 -0
- package/dist/referrals/instructions.js +8 -17
- package/dist/referrals/instructions.js.map +1 -1
- package/dist/referrals/operations.d.ts +2 -1
- package/dist/referrals/operations.d.ts.map +1 -0
- package/dist/referrals/operations.js +119 -143
- package/dist/referrals/operations.js.map +1 -1
- package/dist/utils/ObligationType.d.ts +1 -0
- package/dist/utils/ObligationType.d.ts.map +1 -0
- package/dist/utils/ObligationType.js +16 -7
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/api.d.ts +1 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +10 -21
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -0
- package/dist/utils/ata.d.ts.map +1 -0
- package/dist/utils/ata.js +25 -38
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/idl.d.ts +1 -0
- package/dist/utils/idl.d.ts.map +1 -0
- package/dist/utils/idl.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.d.ts.map +1 -0
- package/dist/utils/instruction.js +116 -143
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/kamino.d.ts +1 -0
- package/dist/utils/kamino.d.ts.map +1 -0
- package/dist/utils/kamino.js +4 -15
- package/dist/utils/kamino.js.map +1 -1
- package/dist/utils/layout.d.ts +1 -0
- package/dist/utils/layout.d.ts.map +1 -0
- package/dist/utils/layout.js.map +1 -1
- package/dist/utils/lookupTable.d.ts +1 -0
- package/dist/utils/lookupTable.d.ts.map +1 -0
- package/dist/utils/lookupTable.js +14 -27
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -0
- package/dist/utils/managerTypes.js +32 -3
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +2 -1
- package/dist/utils/oracle.d.ts.map +1 -0
- package/dist/utils/oracle.js +71 -85
- package/dist/utils/oracle.js.map +1 -1
- package/dist/utils/pubkey.d.ts +1 -0
- package/dist/utils/pubkey.d.ts.map +1 -0
- package/dist/utils/pubkey.js +7 -9
- package/dist/utils/pubkey.js.map +1 -1
- package/dist/utils/rpc.d.ts +1 -0
- package/dist/utils/rpc.d.ts.map +1 -0
- package/dist/utils/rpc.js +48 -70
- package/dist/utils/rpc.js.map +1 -1
- package/dist/utils/seeds.d.ts +1 -0
- package/dist/utils/seeds.d.ts.map +1 -0
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/sendTransactionsUtils.d.ts +1 -0
- package/dist/utils/sendTransactionsUtils.d.ts.map +1 -0
- package/dist/utils/sendTransactionsUtils.js +82 -82
- package/dist/utils/sendTransactionsUtils.js.map +1 -1
- package/dist/utils/slots.d.ts +1 -0
- package/dist/utils/slots.d.ts.map +1 -0
- package/dist/utils/slots.js.map +1 -1
- package/dist/utils/syncNative.d.ts +1 -0
- package/dist/utils/syncNative.d.ts.map +1 -0
- package/dist/utils/syncNative.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +1 -0
- package/dist/utils/userMetadata.d.ts.map +1 -0
- package/dist/utils/userMetadata.js +41 -53
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +14 -8
- package/src/classes/action.ts +2884 -0
- package/src/classes/curve.ts +29 -0
- package/src/classes/fraction.ts +65 -0
- package/src/classes/index.ts +10 -0
- package/src/classes/jupiterPerps.ts +14 -0
- package/src/classes/manager.ts +746 -0
- package/src/classes/market.ts +1459 -0
- package/src/classes/obligation.ts +1315 -0
- package/src/classes/reserve.ts +1980 -0
- package/src/classes/shared.ts +57 -0
- package/src/classes/utils.ts +192 -0
- package/src/classes/vault.ts +808 -0
- package/src/client.ts +446 -0
- package/src/client_kamino_manager.ts +791 -0
- package/src/global.d.ts +1 -0
- package/src/idl_codegen/accounts/LendingMarket.ts +364 -0
- package/src/idl_codegen/accounts/Obligation.ts +349 -0
- package/src/idl_codegen/accounts/ReferrerState.ts +97 -0
- package/src/idl_codegen/accounts/ReferrerTokenState.ts +145 -0
- package/src/idl_codegen/accounts/Reserve.ts +248 -0
- package/src/idl_codegen/accounts/ShortUrl.ts +97 -0
- package/src/idl_codegen/accounts/UserMetadata.ts +142 -0
- package/src/idl_codegen/accounts/UserState.ts +301 -0
- package/src/idl_codegen/accounts/index.ts +19 -0
- package/src/idl_codegen/errors/anchor.ts +773 -0
- package/src/idl_codegen/errors/custom.ts +1633 -0
- package/src/idl_codegen/errors/index.ts +62 -0
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +82 -0
- package/src/idl_codegen/instructions/deleteReferrerStateAndShortUrl.ts +30 -0
- package/src/idl_codegen/instructions/depositObligationCollateral.ts +62 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +90 -0
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +98 -0
- package/src/idl_codegen/instructions/flashBorrowReserveLiquidity.ts +82 -0
- package/src/idl_codegen/instructions/flashRepayReserveLiquidity.ts +83 -0
- package/src/idl_codegen/instructions/idlMissingTypes.ts +62 -0
- package/src/idl_codegen/instructions/index.ts +138 -0
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +62 -0
- package/src/idl_codegen/instructions/initLendingMarket.ts +50 -0
- package/src/idl_codegen/instructions/initObligation.ts +52 -0
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +60 -0
- package/src/idl_codegen/instructions/initReferrerStateAndShortUrl.ts +50 -0
- package/src/idl_codegen/instructions/initReferrerTokenState.ts +46 -0
- package/src/idl_codegen/instructions/initReserve.ts +74 -0
- package/src/idl_codegen/instructions/initUserMetadata.ts +50 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +139 -0
- package/src/idl_codegen/instructions/redeemFees.ts +50 -0
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +94 -0
- package/src/idl_codegen/instructions/refreshObligation.ts +24 -0
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +62 -0
- package/src/idl_codegen/instructions/refreshReserve.ts +40 -0
- package/src/idl_codegen/instructions/refreshReservesBatch.ts +29 -0
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +64 -0
- package/src/idl_codegen/instructions/requestElevationGroup.ts +40 -0
- package/src/idl_codegen/instructions/socializeLoss.ts +48 -0
- package/src/idl_codegen/instructions/updateEntireReserveConfig.ts +45 -0
- package/src/idl_codegen/instructions/updateLendingMarket.ts +43 -0
- package/src/idl_codegen/instructions/updateLendingMarketOwner.ts +28 -0
- package/src/idl_codegen/instructions/updateReserveConfig.ts +52 -0
- package/src/idl_codegen/instructions/updateSingleReserveConfig.ts +48 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateral.ts +68 -0
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +102 -0
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +62 -0
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +54 -0
- package/src/idl_codegen/programId.ts +13 -0
- package/src/idl_codegen/types/AssetTier.ts +118 -0
- package/src/idl_codegen/types/BigFractionBytes.ts +67 -0
- package/src/idl_codegen/types/BorrowRateCurve.ts +60 -0
- package/src/idl_codegen/types/CurvePoint.ts +64 -0
- package/src/idl_codegen/types/ElevationGroup.ts +133 -0
- package/src/idl_codegen/types/FeeCalculation.ts +90 -0
- package/src/idl_codegen/types/InitObligationArgs.ts +61 -0
- package/src/idl_codegen/types/LastUpdate.ts +95 -0
- package/src/idl_codegen/types/ObligationCollateral.ts +128 -0
- package/src/idl_codegen/types/ObligationLiquidity.ts +159 -0
- package/src/idl_codegen/types/PriceHeuristic.ts +81 -0
- package/src/idl_codegen/types/PythConfiguration.ts +56 -0
- package/src/idl_codegen/types/ReserveCollateral.ts +104 -0
- package/src/idl_codegen/types/ReserveConfig.ts +467 -0
- package/src/idl_codegen/types/ReserveFarmKind.ts +90 -0
- package/src/idl_codegen/types/ReserveFees.ts +122 -0
- package/src/idl_codegen/types/ReserveLiquidity.ts +286 -0
- package/src/idl_codegen/types/ReserveStatus.ts +120 -0
- package/src/idl_codegen/types/ScopeConfiguration.ts +85 -0
- package/src/idl_codegen/types/SwitchboardConfiguration.ts +67 -0
- package/src/idl_codegen/types/TokenInfo.ts +190 -0
- package/src/idl_codegen/types/UpdateConfigMode.ts +1440 -0
- package/src/idl_codegen/types/UpdateLendingMarketConfigValue.ts +376 -0
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +570 -0
- package/src/idl_codegen/types/WithdrawalCaps.ts +86 -0
- package/src/idl_codegen/types/index.ts +276 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +186 -0
- package/src/idl_codegen/zero_padding/index.ts +1 -0
- package/src/idl_codegen_jupiter_perps/accounts/Pool.ts +155 -0
- package/src/idl_codegen_jupiter_perps/accounts/index.ts +2 -0
- package/src/idl_codegen_jupiter_perps/programId.ts +7 -0
- package/src/idl_codegen_jupiter_perps/types/Fees.ts +130 -0
- package/src/idl_codegen_jupiter_perps/types/Limit.ts +72 -0
- package/src/idl_codegen_jupiter_perps/types/PoolApr.ts +69 -0
- package/src/idl_codegen_jupiter_perps/types/index.ts +6 -0
- package/src/idl_codegen_kamino_vault/accounts/Reserve.ts +221 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +214 -0
- package/src/idl_codegen_kamino_vault/accounts/index.ts +4 -0
- package/src/idl_codegen_kamino_vault/errors/anchor.ts +764 -0
- package/src/idl_codegen_kamino_vault/errors/custom.ts +344 -0
- package/src/idl_codegen_kamino_vault/errors/index.ts +49 -0
- package/src/idl_codegen_kamino_vault/instructions/deposit.ts +54 -0
- package/src/idl_codegen_kamino_vault/instructions/index.ts +10 -0
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +35 -0
- package/src/idl_codegen_kamino_vault/instructions/invest.ts +60 -0
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +58 -0
- package/src/idl_codegen_kamino_vault/instructions/withdraw.ts +81 -0
- package/src/idl_codegen_kamino_vault/programId.ts +7 -0
- package/src/idl_codegen_kamino_vault/types/BigFractionBytes.ts +61 -0
- package/src/idl_codegen_kamino_vault/types/BorrowRateCurve.ts +55 -0
- package/src/idl_codegen_kamino_vault/types/CurvePoint.ts +61 -0
- package/src/idl_codegen_kamino_vault/types/LastUpdate.ts +90 -0
- package/src/idl_codegen_kamino_vault/types/PriceHeuristic.ts +78 -0
- package/src/idl_codegen_kamino_vault/types/PythConfiguration.ts +56 -0
- package/src/idl_codegen_kamino_vault/types/ReserveCollateral.ts +104 -0
- package/src/idl_codegen_kamino_vault/types/ReserveConfig.ts +426 -0
- package/src/idl_codegen_kamino_vault/types/ReserveFees.ts +118 -0
- package/src/idl_codegen_kamino_vault/types/ReserveLiquidity.ts +268 -0
- package/src/idl_codegen_kamino_vault/types/ScopeConfiguration.ts +85 -0
- package/src/idl_codegen_kamino_vault/types/SwitchboardConfiguration.ts +64 -0
- package/src/idl_codegen_kamino_vault/types/TokenInfo.ts +172 -0
- package/src/idl_codegen_kamino_vault/types/VaultAllocation.ts +115 -0
- package/src/idl_codegen_kamino_vault/types/WithdrawalCaps.ts +86 -0
- package/src/idl_codegen_kamino_vault/types/index.ts +30 -0
- package/src/index.ts +1 -0
- package/src/lending_operations/index.ts +2 -0
- package/src/lending_operations/repay_with_collateral_calcs.ts +71 -0
- package/src/lending_operations/repay_with_collateral_operations.ts +318 -0
- package/src/leverage/calcs.ts +465 -0
- package/src/leverage/index.ts +4 -0
- package/src/leverage/instructions.ts +144 -0
- package/src/leverage/operations.ts +1814 -0
- package/src/leverage/utils.ts +273 -0
- package/src/lib.ts +9 -0
- package/src/referrals/index.ts +2 -0
- package/src/referrals/instructions.ts +114 -0
- package/src/referrals/operations.ts +325 -0
- package/src/utils/ObligationType.ts +171 -0
- package/src/utils/api.ts +59 -0
- package/src/utils/ata.ts +195 -0
- package/src/utils/constants.ts +81 -0
- package/src/utils/idl.ts +4 -0
- package/src/utils/index.ts +16 -0
- package/src/utils/instruction.ts +258 -0
- package/src/utils/kamino.ts +12 -0
- package/src/utils/layout.ts +118 -0
- package/src/utils/lookupTable.ts +55 -0
- package/src/utils/managerTypes.ts +456 -0
- package/src/utils/oracle.ts +337 -0
- package/src/utils/pubkey.ts +261 -0
- package/src/utils/rpc.ts +108 -0
- package/src/utils/seeds.ts +183 -0
- package/src/utils/sendTransactionsUtils.ts +207 -0
- package/src/utils/slots.ts +28 -0
- package/src/utils/syncNative.ts +22 -0
- package/src/utils/userMetadata.ts +401 -0
|
@@ -0,0 +1,1980 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import {
|
|
3
|
+
AccountInfo,
|
|
4
|
+
Connection,
|
|
5
|
+
PublicKey,
|
|
6
|
+
SystemProgram,
|
|
7
|
+
SYSVAR_RENT_PUBKEY,
|
|
8
|
+
TransactionInstruction,
|
|
9
|
+
} from '@solana/web3.js';
|
|
10
|
+
import Decimal from 'decimal.js';
|
|
11
|
+
import {
|
|
12
|
+
INITIAL_COLLATERAL_RATE,
|
|
13
|
+
lendingMarketAuthPda,
|
|
14
|
+
MarketWithAddress,
|
|
15
|
+
ONE_HUNDRED_PCT_IN_BPS,
|
|
16
|
+
reservePdas,
|
|
17
|
+
SLOTS_PER_DAY,
|
|
18
|
+
SLOTS_PER_SECOND,
|
|
19
|
+
SLOTS_PER_YEAR,
|
|
20
|
+
TokenOracleData,
|
|
21
|
+
U64_MAX,
|
|
22
|
+
} from '../utils';
|
|
23
|
+
import { ReserveDataType, ReserveFarmInfo, ReserveRewardYield, ReserveStatus } from './shared';
|
|
24
|
+
import { Reserve, ReserveFields } from '../idl_codegen/accounts';
|
|
25
|
+
import { BorrowRateCurve, CurvePointFields, ReserveConfig, UpdateConfigMode } from '../idl_codegen/types';
|
|
26
|
+
import { calculateAPYFromAPR, getBorrowRate, lamportsToNumberDecimal, parseTokenSymbol, positiveOrZero } from './utils';
|
|
27
|
+
import { Fraction } from './fraction';
|
|
28
|
+
import BN from 'bn.js';
|
|
29
|
+
import { ActionType } from './action';
|
|
30
|
+
import { BorrowCapsAndCounters, ElevationGroupDescription, KaminoMarket } from './market';
|
|
31
|
+
import {
|
|
32
|
+
initReserve,
|
|
33
|
+
InitReserveAccounts,
|
|
34
|
+
updateReserveConfig,
|
|
35
|
+
UpdateReserveConfigAccounts,
|
|
36
|
+
UpdateReserveConfigArgs,
|
|
37
|
+
} from '../lib';
|
|
38
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
39
|
+
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
40
|
+
import { UpdateBorrowRateCurve } from '../idl_codegen/types/UpdateConfigMode';
|
|
41
|
+
import { aprToApy, KaminoPrices } from '@kamino-finance/kliquidity-sdk';
|
|
42
|
+
import { FarmState, RewardInfo } from '@kamino-finance/farms-sdk';
|
|
43
|
+
|
|
44
|
+
export const DEFAULT_RECENT_SLOT_DURATION_MS = 450;
|
|
45
|
+
|
|
46
|
+
export class KaminoReserve {
|
|
47
|
+
state: Reserve;
|
|
48
|
+
address: PublicKey;
|
|
49
|
+
symbol: string;
|
|
50
|
+
|
|
51
|
+
tokenOraclePrice: TokenOracleData;
|
|
52
|
+
stats: ReserveDataType;
|
|
53
|
+
private farmData: ReserveFarmInfo = { fetched: false, farmStates: [] };
|
|
54
|
+
|
|
55
|
+
private buffer: AccountInfo<Buffer> | null;
|
|
56
|
+
private connection: Connection;
|
|
57
|
+
private readonly recentSlotDurationMs: number;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
state: Reserve,
|
|
61
|
+
address: PublicKey,
|
|
62
|
+
tokenOraclePrice: TokenOracleData,
|
|
63
|
+
connection: Connection,
|
|
64
|
+
recentSlotDurationMs: number
|
|
65
|
+
) {
|
|
66
|
+
this.state = state;
|
|
67
|
+
this.address = address;
|
|
68
|
+
this.buffer = null;
|
|
69
|
+
this.tokenOraclePrice = tokenOraclePrice;
|
|
70
|
+
this.stats = {} as ReserveDataType;
|
|
71
|
+
this.connection = connection;
|
|
72
|
+
this.symbol = parseTokenSymbol(state.config.tokenInfo.name);
|
|
73
|
+
this.recentSlotDurationMs = recentSlotDurationMs;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static initialize(
|
|
77
|
+
accountData: AccountInfo<Buffer>,
|
|
78
|
+
address: PublicKey,
|
|
79
|
+
state: Reserve,
|
|
80
|
+
tokenOraclePrice: TokenOracleData,
|
|
81
|
+
connection: Connection,
|
|
82
|
+
recentSlotDurationMs: number
|
|
83
|
+
) {
|
|
84
|
+
const reserve = new KaminoReserve(state, address, tokenOraclePrice, connection, recentSlotDurationMs);
|
|
85
|
+
reserve.setBuffer(accountData);
|
|
86
|
+
reserve.stats = reserve.formatReserveData(state);
|
|
87
|
+
return reserve;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// GETTERS
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @returns the parsed token symbol of the reserve
|
|
94
|
+
*/
|
|
95
|
+
getTokenSymbol(): string {
|
|
96
|
+
return parseTokenSymbol(this.state.config.tokenInfo.name);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @returns the total borrowed amount of the reserve in lamports
|
|
101
|
+
*/
|
|
102
|
+
getBorrowedAmount(): Decimal {
|
|
103
|
+
return new Fraction(this.state.liquidity.borrowedAmountSf).toDecimal();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @returns the available liquidity amount of the reserve in lamports
|
|
108
|
+
*/
|
|
109
|
+
getLiquidityAvailableAmount(): Decimal {
|
|
110
|
+
return new Decimal(this.state.liquidity.availableAmount.toString());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @returns the last cached price stored in the reserve in USD
|
|
116
|
+
*/
|
|
117
|
+
getReserveMarketPrice(): Decimal {
|
|
118
|
+
return new Fraction(this.state.liquidity.marketPriceSf).toDecimal();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @returns the current market price of the reserve in USD
|
|
123
|
+
*/
|
|
124
|
+
getOracleMarketPrice(): Decimal {
|
|
125
|
+
return this.tokenOraclePrice.price;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @returns the total accumulated protocol fees of the reserve
|
|
130
|
+
*/
|
|
131
|
+
getAccumulatedProtocolFees(): Decimal {
|
|
132
|
+
return new Fraction(this.state.liquidity.accumulatedProtocolFeesSf).toDecimal();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @returns the total accumulated referrer fees of the reserve
|
|
137
|
+
*/
|
|
138
|
+
getAccumulatedReferrerFees(): Decimal {
|
|
139
|
+
return new Fraction(this.state.liquidity.accumulatedReferrerFeesSf).toDecimal();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @returns the total pending referrer fees of the reserve
|
|
144
|
+
*/
|
|
145
|
+
getPendingReferrerFees(): Decimal {
|
|
146
|
+
return new Fraction(this.state.liquidity.pendingReferrerFeesSf).toDecimal();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
*
|
|
151
|
+
* @returns the flash loan fee percentage of the reserve
|
|
152
|
+
*/
|
|
153
|
+
getFlashLoanFee = (): Decimal => {
|
|
154
|
+
if (this.state.config.fees.flashLoanFeeSf.toString() === U64_MAX) {
|
|
155
|
+
return new Decimal('0');
|
|
156
|
+
}
|
|
157
|
+
return new Fraction(this.state.config.fees.flashLoanFeeSf).toDecimal();
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* @returns the origination fee percentage of the reserve
|
|
163
|
+
*/
|
|
164
|
+
getBorrowFee = (): Decimal => {
|
|
165
|
+
return new Fraction(this.state.config.fees.borrowFeeSf).toDecimal();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @returns the fixed interest rate allocated to the host
|
|
171
|
+
*/
|
|
172
|
+
getFixedHostInterestRate = (): Decimal => {
|
|
173
|
+
return new Decimal(this.state.config.hostFixedInterestRateBps).div(10_000);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Use getEstimatedTotalSupply() for the most accurate value
|
|
178
|
+
* @returns the stale total liquidity supply of the reserve from the last refresh
|
|
179
|
+
*/
|
|
180
|
+
getTotalSupply(): Decimal {
|
|
181
|
+
return this.getLiquidityAvailableAmount()
|
|
182
|
+
.add(this.getBorrowedAmount())
|
|
183
|
+
.sub(this.getAccumulatedProtocolFees())
|
|
184
|
+
.sub(this.getAccumulatedReferrerFees())
|
|
185
|
+
.sub(this.getPendingReferrerFees());
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Calculates the total liquidity supply of the reserve
|
|
190
|
+
*/
|
|
191
|
+
getEstimatedTotalSupply(slot: number, referralFeeBps: number): Decimal {
|
|
192
|
+
const { totalSupply } = this.getEstimatedDebtAndSupply(slot, referralFeeBps);
|
|
193
|
+
return totalSupply;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Use getEstimatedCumulativeBorrowRate() for the most accurate value
|
|
198
|
+
* @returns the stale cumulative borrow rate of the reserve from the last refresh
|
|
199
|
+
*/
|
|
200
|
+
getCumulativeBorrowRate(): Decimal {
|
|
201
|
+
const cumulativeBorrowRateBsf = this.state.liquidity.cumulativeBorrowRateBsf.value;
|
|
202
|
+
const accSf = cumulativeBorrowRateBsf.reduce((prev, curr, i) => prev.add(curr.shln(i * 64)), new BN(0));
|
|
203
|
+
return new Fraction(accSf).toDecimal();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @Returns estimated cumulative borrow rate of the reserve
|
|
208
|
+
*/
|
|
209
|
+
getEstimatedCumulativeBorrowRate(currentSlot: number, referralFeeBps: number): Decimal {
|
|
210
|
+
const currentBorrowRate = new Decimal(this.calculateBorrowAPR(currentSlot, referralFeeBps));
|
|
211
|
+
const slotsElapsed = Math.max(currentSlot - this.state.lastUpdate.slot.toNumber(), 0);
|
|
212
|
+
|
|
213
|
+
const compoundInterest = this.approximateCompoundedInterest(currentBorrowRate, slotsElapsed);
|
|
214
|
+
|
|
215
|
+
const previousCumulativeBorrowRate = this.getCumulativeBorrowRate();
|
|
216
|
+
|
|
217
|
+
return previousCumulativeBorrowRate.mul(compoundInterest);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Use getEstimatedCollateralExchangeRate() for the most accurate value
|
|
222
|
+
* @returns the stale exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18
|
|
223
|
+
*/
|
|
224
|
+
getCollateralExchangeRate(): Decimal {
|
|
225
|
+
const totalSupply = this.getTotalSupply();
|
|
226
|
+
const mintTotalSupply = this.state.collateral.mintTotalSupply;
|
|
227
|
+
if (mintTotalSupply.isZero() || totalSupply.isZero()) {
|
|
228
|
+
return INITIAL_COLLATERAL_RATE;
|
|
229
|
+
} else {
|
|
230
|
+
return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
*
|
|
236
|
+
* @returns the estimated exchange rate between the collateral tokens and the liquidity - this is a decimal number scaled by 1e18
|
|
237
|
+
*/
|
|
238
|
+
getEstimatedCollateralExchangeRate(slot: number, referralFeeBps: number): Decimal {
|
|
239
|
+
const totalSupply = this.getEstimatedTotalSupply(slot, referralFeeBps);
|
|
240
|
+
const mintTotalSupply = this.state.collateral.mintTotalSupply;
|
|
241
|
+
if (mintTotalSupply.isZero() || totalSupply.isZero()) {
|
|
242
|
+
return INITIAL_COLLATERAL_RATE;
|
|
243
|
+
} else {
|
|
244
|
+
return new Decimal(mintTotalSupply.toString()).dividedBy(totalSupply.toString());
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
*
|
|
250
|
+
* @returns the total USD value of the existing collateral in the reserve
|
|
251
|
+
*/
|
|
252
|
+
getDepositTvl = (): Decimal => {
|
|
253
|
+
return new Decimal(this.getTotalSupply().toString()).mul(this.getOracleMarketPrice()).div(this.getMintFactor());
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
*
|
|
258
|
+
* Get the total USD value of the borrowed assets from the reserve
|
|
259
|
+
*/
|
|
260
|
+
getBorrowTvl = (): Decimal => {
|
|
261
|
+
return this.getBorrowedAmount().mul(this.getOracleMarketPrice()).div(this.getMintFactor());
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @returns 10^mint_decimals
|
|
266
|
+
*/
|
|
267
|
+
getMintFactor(): Decimal {
|
|
268
|
+
return new Decimal(10).pow(this.state.liquidity.mintDecimals.toNumber());
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @Returns true if the total liquidity supply of the reserve is greater than the deposit limit
|
|
273
|
+
*/
|
|
274
|
+
depositLimitCrossed(): boolean {
|
|
275
|
+
return this.getTotalSupply().gt(new Decimal(this.state.config.depositLimit.toString()));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @Returns true if the total borrowed amount of the reserve is greater than the borrow limit
|
|
280
|
+
*/
|
|
281
|
+
borrowLimitCrossed(): boolean {
|
|
282
|
+
return this.getBorrowedAmount().gt(new Decimal(this.state.config.borrowLimit.toString()));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
*
|
|
287
|
+
* @returns the max capacity of the daily deposit withdrawal cap
|
|
288
|
+
*/
|
|
289
|
+
getDepositWithdrawalCapCapacity(): Decimal {
|
|
290
|
+
return new Decimal(this.state.config.depositWithdrawalCap.configCapacity.toString());
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
*
|
|
295
|
+
* @returns the current capacity of the daily deposit withdrawal cap
|
|
296
|
+
*/
|
|
297
|
+
getDepositWithdrawalCapCurrent(slot: number): Decimal {
|
|
298
|
+
const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);
|
|
299
|
+
if (slotsElapsed > SLOTS_PER_DAY) {
|
|
300
|
+
return new Decimal(0);
|
|
301
|
+
} else {
|
|
302
|
+
return new Decimal(this.state.config.depositWithdrawalCap.currentTotal.toString());
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
*
|
|
308
|
+
* @returns the max capacity of the daily debt withdrawal cap
|
|
309
|
+
*/
|
|
310
|
+
getDebtWithdrawalCapCapacity(): Decimal {
|
|
311
|
+
return new Decimal(this.state.config.debtWithdrawalCap.configCapacity.toString());
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
*
|
|
316
|
+
* @returns the borrow limit of the reserve outside the elevation group
|
|
317
|
+
*/
|
|
318
|
+
getBorrowLimitOutsideElevationGroup(): Decimal {
|
|
319
|
+
return new Decimal(this.state.config.borrowLimitOutsideElevationGroup.toString());
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
*
|
|
324
|
+
* @returns the borrowed amount of the reserve outside the elevation group
|
|
325
|
+
*/
|
|
326
|
+
getBorrowedAmountOutsideElevationGroup(): Decimal {
|
|
327
|
+
return new Decimal(this.state.borrowedAmountOutsideElevationGroup.toString());
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
*
|
|
332
|
+
* @returns the borrow limit against the collateral reserve in the elevation group
|
|
333
|
+
*/
|
|
334
|
+
getBorrowLimitAgainstCollateralInElevationGroup(elevationGroupIndex: number): Decimal {
|
|
335
|
+
return new Decimal(
|
|
336
|
+
this.state.config.borrowLimitAgainstThisCollateralInElevationGroup[elevationGroupIndex].toString()
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
*
|
|
342
|
+
* @returns the borrowed amount against the collateral reserve in the elevation group
|
|
343
|
+
*/
|
|
344
|
+
getBorrowedAmountAgainstCollateralInElevationGroup(elevationGroupIndex: number): Decimal {
|
|
345
|
+
return new Decimal(this.state.borrowedAmountsAgainstThisReserveInElevationGroups[elevationGroupIndex].toString());
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
*
|
|
350
|
+
* @returns the current capacity of the daily debt withdrawal cap
|
|
351
|
+
*/
|
|
352
|
+
getDebtWithdrawalCapCurrent(slot: number): Decimal {
|
|
353
|
+
const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);
|
|
354
|
+
if (slotsElapsed > SLOTS_PER_DAY) {
|
|
355
|
+
return new Decimal(0);
|
|
356
|
+
} else {
|
|
357
|
+
return new Decimal(this.state.config.debtWithdrawalCap.currentTotal.toString());
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
getBorrowFactor(): Decimal {
|
|
362
|
+
return new Decimal(this.state.config.borrowFactorPct.toString()).div(100);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
calculateSupplyAPR(slot: number, referralFeeBps: number) {
|
|
366
|
+
const currentUtilization = this.calculateUtilizationRatio();
|
|
367
|
+
|
|
368
|
+
const borrowRate = this.calculateEstimatedBorrowRate(slot, referralFeeBps);
|
|
369
|
+
const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;
|
|
370
|
+
return currentUtilization * borrowRate * protocolTakeRatePct;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
getEstimatedDebtAndSupply(slot: number, referralFeeBps: number): { totalBorrow: Decimal; totalSupply: Decimal } {
|
|
374
|
+
const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);
|
|
375
|
+
let totalBorrow: Decimal;
|
|
376
|
+
let totalSupply: Decimal;
|
|
377
|
+
if (slotsElapsed === 0) {
|
|
378
|
+
totalBorrow = this.getBorrowedAmount();
|
|
379
|
+
totalSupply = this.getTotalSupply();
|
|
380
|
+
} else {
|
|
381
|
+
const { newDebt, newAccProtocolFees, pendingReferralFees } = this.compoundInterest(slotsElapsed, referralFeeBps);
|
|
382
|
+
const newTotalSupply = this.getLiquidityAvailableAmount()
|
|
383
|
+
.add(newDebt)
|
|
384
|
+
.sub(newAccProtocolFees)
|
|
385
|
+
.sub(this.getAccumulatedReferrerFees())
|
|
386
|
+
.sub(pendingReferralFees);
|
|
387
|
+
totalBorrow = newDebt;
|
|
388
|
+
totalSupply = newTotalSupply;
|
|
389
|
+
}
|
|
390
|
+
return { totalBorrow, totalSupply };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
getEstimatedAccumulatedProtocolFees(
|
|
394
|
+
slot: number,
|
|
395
|
+
referralFeeBps: number
|
|
396
|
+
): { accumulatedProtocolFees: Decimal; compoundedVariableProtocolFee: Decimal; compoundedFixedHostFee: Decimal } {
|
|
397
|
+
const slotsElapsed = Math.max(slot - this.state.lastUpdate.slot.toNumber(), 0);
|
|
398
|
+
let accumulatedProtocolFees: Decimal;
|
|
399
|
+
let compoundedVariableProtocolFee: Decimal;
|
|
400
|
+
let compoundedFixedHostFee: Decimal;
|
|
401
|
+
if (slotsElapsed === 0) {
|
|
402
|
+
accumulatedProtocolFees = this.getAccumulatedProtocolFees();
|
|
403
|
+
compoundedVariableProtocolFee = new Decimal(0);
|
|
404
|
+
compoundedFixedHostFee = new Decimal(0);
|
|
405
|
+
} else {
|
|
406
|
+
const { newAccProtocolFees, variableProtocolFee, fixedHostFee } = this.compoundInterest(
|
|
407
|
+
slotsElapsed,
|
|
408
|
+
referralFeeBps
|
|
409
|
+
);
|
|
410
|
+
accumulatedProtocolFees = newAccProtocolFees;
|
|
411
|
+
compoundedVariableProtocolFee = variableProtocolFee;
|
|
412
|
+
compoundedFixedHostFee = fixedHostFee;
|
|
413
|
+
}
|
|
414
|
+
return { accumulatedProtocolFees, compoundedVariableProtocolFee, compoundedFixedHostFee };
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
calculateUtilizationRatio() {
|
|
418
|
+
const totalBorrows = this.getBorrowedAmount();
|
|
419
|
+
const totalSupply = this.getTotalSupply();
|
|
420
|
+
if (totalSupply.eq(0)) {
|
|
421
|
+
return 0;
|
|
422
|
+
}
|
|
423
|
+
return totalBorrows.dividedBy(totalSupply).toNumber();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
getEstimatedUtilizationRatio(slot: number, referralFeeBps: number) {
|
|
427
|
+
const { totalBorrow: estimatedTotalBorrowed, totalSupply: estimatedTotalSupply } = this.getEstimatedDebtAndSupply(
|
|
428
|
+
slot,
|
|
429
|
+
referralFeeBps
|
|
430
|
+
);
|
|
431
|
+
if (estimatedTotalSupply.eq(0)) {
|
|
432
|
+
return 0;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return estimatedTotalBorrowed.dividedBy(estimatedTotalSupply).toNumber();
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
calcSimulatedUtilizationRatio(
|
|
439
|
+
amount: Decimal,
|
|
440
|
+
action: ActionType,
|
|
441
|
+
slot: number,
|
|
442
|
+
referralFeeBps: number,
|
|
443
|
+
outflowAmount?: Decimal
|
|
444
|
+
): number {
|
|
445
|
+
const { totalBorrow: previousTotalBorrowed, totalSupply: previousTotalSupply } = this.getEstimatedDebtAndSupply(
|
|
446
|
+
slot,
|
|
447
|
+
referralFeeBps
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
switch (action) {
|
|
451
|
+
case 'deposit': {
|
|
452
|
+
const newTotalSupply = previousTotalSupply.add(amount);
|
|
453
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
454
|
+
}
|
|
455
|
+
case 'withdraw': {
|
|
456
|
+
const newTotalSupply = previousTotalSupply.sub(amount);
|
|
457
|
+
if (newTotalSupply.eq(0)) {
|
|
458
|
+
return 0;
|
|
459
|
+
} else {
|
|
460
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
case 'borrow': {
|
|
464
|
+
const newTotalBorrowed = previousTotalBorrowed.add(amount);
|
|
465
|
+
return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();
|
|
466
|
+
}
|
|
467
|
+
case 'repay': {
|
|
468
|
+
const newTotalBorrowed = previousTotalBorrowed.sub(amount);
|
|
469
|
+
return newTotalBorrowed.dividedBy(previousTotalSupply).toNumber();
|
|
470
|
+
}
|
|
471
|
+
case 'depositAndBorrow': {
|
|
472
|
+
const newTotalSupply = previousTotalSupply.add(amount);
|
|
473
|
+
const newTotalBorrowed = previousTotalBorrowed.add(outflowAmount!);
|
|
474
|
+
return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
475
|
+
}
|
|
476
|
+
case 'repayAndWithdraw': {
|
|
477
|
+
const newTotalBorrowed = previousTotalBorrowed.sub(amount);
|
|
478
|
+
const newTotalSupply = previousTotalSupply.sub(outflowAmount!);
|
|
479
|
+
if (newTotalSupply.eq(0)) {
|
|
480
|
+
return 0;
|
|
481
|
+
}
|
|
482
|
+
return newTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
483
|
+
}
|
|
484
|
+
case 'mint': {
|
|
485
|
+
const newTotalSupply = previousTotalSupply.add(amount);
|
|
486
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
487
|
+
}
|
|
488
|
+
case 'redeem': {
|
|
489
|
+
const newTotalSupply = previousTotalSupply.sub(amount);
|
|
490
|
+
return previousTotalBorrowed.dividedBy(newTotalSupply).toNumber();
|
|
491
|
+
}
|
|
492
|
+
default:
|
|
493
|
+
throw Error(`Invalid action type ${action} for simulatedUtilizationRatio`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
getMaxBorrowAmountWithCollReserve(market: KaminoMarket, collReserve: KaminoReserve, slot: number): Decimal {
|
|
498
|
+
const groupsColl = collReserve.state.config.elevationGroups;
|
|
499
|
+
const groupsDebt = this.state.config.elevationGroups;
|
|
500
|
+
const groups = market.state.elevationGroups;
|
|
501
|
+
const commonElevationGroups = [...groupsColl].filter(
|
|
502
|
+
(item) => groupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(this.address)
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
let eModeGroup = 0;
|
|
506
|
+
|
|
507
|
+
if (commonElevationGroups.length !== 0) {
|
|
508
|
+
const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
|
|
509
|
+
const prevGroup = groups.find((group) => group.id === prev);
|
|
510
|
+
const currGroup = groups.find((group) => group.id === curr);
|
|
511
|
+
return prevGroup!.ltvPct > currGroup!.ltvPct ? prev : curr;
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve)!.id;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const elevationGroupActivated = this.state.config.elevationGroups.includes(eModeGroup) && eModeGroup !== 0;
|
|
518
|
+
|
|
519
|
+
const reserveAvailableAmount = this.getLiquidityAvailableAmount();
|
|
520
|
+
const reserveBorrowCapRemained = this.stats.reserveBorrowLimit.sub(this.getBorrowedAmount());
|
|
521
|
+
|
|
522
|
+
let maxBorrowAmount = Decimal.min(reserveAvailableAmount, reserveBorrowCapRemained);
|
|
523
|
+
|
|
524
|
+
const debtWithdrawalCap = this.getDebtWithdrawalCapCapacity().sub(this.getDebtWithdrawalCapCurrent(slot));
|
|
525
|
+
maxBorrowAmount = this.getDebtWithdrawalCapCapacity().gt(0)
|
|
526
|
+
? Decimal.min(maxBorrowAmount, debtWithdrawalCap)
|
|
527
|
+
: maxBorrowAmount;
|
|
528
|
+
|
|
529
|
+
let originationFeeRate = this.getBorrowFee();
|
|
530
|
+
|
|
531
|
+
// Inclusive fee rate
|
|
532
|
+
originationFeeRate = originationFeeRate.div(originationFeeRate.add(new Decimal(1)));
|
|
533
|
+
const borrowFee = maxBorrowAmount.mul(originationFeeRate);
|
|
534
|
+
|
|
535
|
+
maxBorrowAmount = maxBorrowAmount.sub(borrowFee);
|
|
536
|
+
|
|
537
|
+
const utilizationRatioLimit = this.state.config.utilizationLimitBlockBorrowingAbove / 100;
|
|
538
|
+
const currentUtilizationRatio = this.calculateUtilizationRatio();
|
|
539
|
+
|
|
540
|
+
if (utilizationRatioLimit > 0 && currentUtilizationRatio > utilizationRatioLimit) {
|
|
541
|
+
return new Decimal(0);
|
|
542
|
+
} else if (utilizationRatioLimit > 0 && currentUtilizationRatio < utilizationRatioLimit) {
|
|
543
|
+
const maxBorrowBasedOnUtilization = new Decimal(utilizationRatioLimit - currentUtilizationRatio).mul(
|
|
544
|
+
this.getTotalSupply()
|
|
545
|
+
);
|
|
546
|
+
maxBorrowAmount = Decimal.min(maxBorrowAmount, maxBorrowBasedOnUtilization);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
let borrowLimitDependentOnElevationGroup = new Decimal(U64_MAX);
|
|
550
|
+
|
|
551
|
+
if (!elevationGroupActivated) {
|
|
552
|
+
borrowLimitDependentOnElevationGroup = this.getBorrowLimitOutsideElevationGroup().sub(
|
|
553
|
+
this.getBorrowedAmountOutsideElevationGroup()
|
|
554
|
+
);
|
|
555
|
+
} else {
|
|
556
|
+
let maxDebtTakenAgainstCollaterals = new Decimal(U64_MAX);
|
|
557
|
+
const maxDebtAllowedAgainstCollateral = collReserve
|
|
558
|
+
.getBorrowLimitAgainstCollateralInElevationGroup(eModeGroup - 1)
|
|
559
|
+
.sub(collReserve.getBorrowedAmountAgainstCollateralInElevationGroup(eModeGroup - 1));
|
|
560
|
+
|
|
561
|
+
maxDebtTakenAgainstCollaterals = Decimal.max(
|
|
562
|
+
new Decimal(0),
|
|
563
|
+
Decimal.min(maxDebtAllowedAgainstCollateral, maxDebtTakenAgainstCollaterals)
|
|
564
|
+
);
|
|
565
|
+
borrowLimitDependentOnElevationGroup = maxDebtTakenAgainstCollaterals;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
maxBorrowAmount = Decimal.min(maxBorrowAmount, borrowLimitDependentOnElevationGroup);
|
|
569
|
+
|
|
570
|
+
return Decimal.max(new Decimal(0), maxBorrowAmount);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
calcSimulatedBorrowAPR(
|
|
574
|
+
amount: Decimal,
|
|
575
|
+
action: ActionType,
|
|
576
|
+
slot: number,
|
|
577
|
+
referralFeeBps: number,
|
|
578
|
+
outflowAmount?: Decimal
|
|
579
|
+
) {
|
|
580
|
+
const slotAdjustmentFactor = this.slotAdjustmentFactor();
|
|
581
|
+
const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);
|
|
582
|
+
const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);
|
|
583
|
+
return getBorrowRate(newUtilization, curve) * slotAdjustmentFactor + this.getFixedHostInterestRate().toNumber();
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
calcSimulatedSupplyAPR(
|
|
587
|
+
amount: Decimal,
|
|
588
|
+
action: ActionType,
|
|
589
|
+
slot: number,
|
|
590
|
+
referralFeeBps: number,
|
|
591
|
+
outflowAmount?: Decimal
|
|
592
|
+
) {
|
|
593
|
+
const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);
|
|
594
|
+
const simulatedBorrowAPR = this.calcSimulatedBorrowAPR(amount, action, slot, referralFeeBps, outflowAmount);
|
|
595
|
+
const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;
|
|
596
|
+
|
|
597
|
+
return newUtilization * simulatedBorrowAPR * protocolTakeRatePct;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
slotAdjustmentFactor(): number {
|
|
601
|
+
return 1000 / SLOTS_PER_SECOND / this.recentSlotDurationMs;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
calculateBorrowRate() {
|
|
605
|
+
const slotAdjustmentFactor = this.slotAdjustmentFactor();
|
|
606
|
+
const currentUtilization = this.calculateUtilizationRatio();
|
|
607
|
+
const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);
|
|
608
|
+
|
|
609
|
+
return getBorrowRate(currentUtilization, curve) * slotAdjustmentFactor;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
calculateEstimatedBorrowRate(slot: number, referralFeeBps: number) {
|
|
613
|
+
const slotAdjustmentFactor = this.slotAdjustmentFactor();
|
|
614
|
+
const estimatedCurrentUtilization = this.getEstimatedUtilizationRatio(slot, referralFeeBps);
|
|
615
|
+
const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);
|
|
616
|
+
return getBorrowRate(estimatedCurrentUtilization, curve) * slotAdjustmentFactor;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
calculateBorrowAPR(slot: number, referralFeeBps: number) {
|
|
620
|
+
const borrowRate = this.calculateEstimatedBorrowRate(slot, referralFeeBps);
|
|
621
|
+
return borrowRate + this.getFixedHostInterestRate().toNumber();
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* @returns the mint of the reserve liquidity token
|
|
626
|
+
*/
|
|
627
|
+
getLiquidityMint(): PublicKey {
|
|
628
|
+
return this.state.liquidity.mintPubkey;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* @returns the token program of the reserve liquidity mint
|
|
633
|
+
*/
|
|
634
|
+
getLiquidityTokenProgram(): PublicKey {
|
|
635
|
+
return this.state.liquidity.tokenProgram;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* @returns the mint of the reserve collateral token , i.e. the cToken minted for depositing the liquidity token
|
|
640
|
+
*/
|
|
641
|
+
getCTokenMint(): PublicKey {
|
|
642
|
+
return this.state.collateral.mintPubkey;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
setBuffer(buffer: AccountInfo<Buffer> | null) {
|
|
646
|
+
this.buffer = buffer;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
async load(tokenOraclePrice: TokenOracleData) {
|
|
650
|
+
if (!this.buffer) {
|
|
651
|
+
this.setBuffer(await this.connection.getAccountInfo(this.address, 'processed'));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if (!this.buffer) {
|
|
655
|
+
throw Error(`Error requesting account info for ${this.symbol}`);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const parsedData = await Reserve.fetch(this.connection, this.address);
|
|
659
|
+
if (!parsedData) {
|
|
660
|
+
throw Error(`Unable to parse data of reserve ${this.symbol}`);
|
|
661
|
+
}
|
|
662
|
+
this.state = parsedData;
|
|
663
|
+
this.tokenOraclePrice = tokenOraclePrice;
|
|
664
|
+
this.stats = this.formatReserveData(parsedData);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
totalSupplyAPY(currentSlot: number) {
|
|
668
|
+
const { stats } = this;
|
|
669
|
+
if (!stats) {
|
|
670
|
+
throw Error('KaminoMarket must call loadRewards.');
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return calculateAPYFromAPR(this.calculateSupplyAPR(currentSlot, 0));
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
totalBorrowAPY(currentSlot: number) {
|
|
677
|
+
const { stats } = this;
|
|
678
|
+
if (!stats) {
|
|
679
|
+
throw Error('KaminoMarket must call loadRewards.');
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
return calculateAPYFromAPR(this.calculateBorrowAPR(currentSlot, 0));
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
async loadFarmStates() {
|
|
686
|
+
if (!this.farmData.fetched) {
|
|
687
|
+
const farmStates: FarmState[] = [];
|
|
688
|
+
if (!this.state.farmDebt.equals(PublicKey.default)) {
|
|
689
|
+
const farmState = await FarmState.fetch(this.connection, this.state.farmDebt);
|
|
690
|
+
if (farmState !== null) {
|
|
691
|
+
farmStates.push(farmState);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (!this.state.farmCollateral.equals(PublicKey.default)) {
|
|
695
|
+
const farmState = await FarmState.fetch(this.connection, this.state.farmCollateral);
|
|
696
|
+
if (farmState !== null) {
|
|
697
|
+
farmStates.push(farmState);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
this.farmData.farmStates = farmStates;
|
|
701
|
+
this.farmData.fetched = true;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
async getRewardYields(prices: KaminoPrices): Promise<ReserveRewardYield[]> {
|
|
706
|
+
const { stats } = this;
|
|
707
|
+
if (!stats) {
|
|
708
|
+
throw Error('KaminoMarket must call loadReserves.');
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const isDebtReward = this.state.farmDebt.equals(this.address);
|
|
712
|
+
await this.loadFarmStates();
|
|
713
|
+
const yields: ReserveRewardYield[] = [];
|
|
714
|
+
for (const farmState of this.farmData.farmStates) {
|
|
715
|
+
for (const rewardInfo of farmState.rewardInfos.filter(
|
|
716
|
+
(x) => !x.token.mint.equals(PublicKey.default) && !x.rewardsAvailable.isZero()
|
|
717
|
+
)) {
|
|
718
|
+
const { apy, apr } = this.calculateRewardYield(prices, rewardInfo, isDebtReward);
|
|
719
|
+
if (apy.isZero() && apr.isZero()) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
yields.push({ apy, apr, rewardInfo });
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
return yields;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
private calculateRewardYield(prices: KaminoPrices, rewardInfo: RewardInfo, isDebtReward: boolean) {
|
|
729
|
+
const mintAddress = this.getLiquidityMint();
|
|
730
|
+
const rewardPerTimeUnitSecond = this.getRewardPerTimeUnitSecond(rewardInfo);
|
|
731
|
+
const reserveToken = prices.spot[mintAddress.toString()];
|
|
732
|
+
const rewardToken = prices.spot[rewardInfo.token.mint.toString()];
|
|
733
|
+
|
|
734
|
+
if (rewardPerTimeUnitSecond.isZero() || reserveToken === undefined || rewardToken === undefined) {
|
|
735
|
+
return { apy: new Decimal(0), apr: new Decimal(0) };
|
|
736
|
+
}
|
|
737
|
+
const { decimals } = this.stats;
|
|
738
|
+
const totalBorrows = this.getBorrowedAmount();
|
|
739
|
+
const totalSupply = this.getTotalSupply();
|
|
740
|
+
|
|
741
|
+
const totalAmount = isDebtReward
|
|
742
|
+
? lamportsToNumberDecimal(totalBorrows, decimals)
|
|
743
|
+
: lamportsToNumberDecimal(totalSupply, decimals);
|
|
744
|
+
const totalValue = totalAmount.mul(reserveToken.price);
|
|
745
|
+
const rewardsInYear = rewardPerTimeUnitSecond.mul(60 * 60 * 24 * 365);
|
|
746
|
+
const rewardsInYearValue = rewardsInYear.mul(rewardToken.price);
|
|
747
|
+
const apr = rewardsInYearValue.div(totalValue);
|
|
748
|
+
return { apy: aprToApy(apr, 365), apr };
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
private getRewardPerTimeUnitSecond(reward: RewardInfo) {
|
|
752
|
+
const now = new Decimal(new Date().getTime()).div(1000);
|
|
753
|
+
let rewardPerTimeUnitSecond = new Decimal(0);
|
|
754
|
+
for (let i = 0; i < reward.rewardScheduleCurve.points.length - 1; i++) {
|
|
755
|
+
const { tsStart: tsStartThisPoint, rewardPerTimeUnit } = reward.rewardScheduleCurve.points[i];
|
|
756
|
+
const { tsStart: tsStartNextPoint } = reward.rewardScheduleCurve.points[i + 1];
|
|
757
|
+
|
|
758
|
+
const thisPeriodStart = new Decimal(tsStartThisPoint.toString());
|
|
759
|
+
const thisPeriodEnd = new Decimal(tsStartNextPoint.toString());
|
|
760
|
+
const rps = new Decimal(rewardPerTimeUnit.toString());
|
|
761
|
+
if (thisPeriodStart <= now && thisPeriodEnd >= now) {
|
|
762
|
+
rewardPerTimeUnitSecond = rps;
|
|
763
|
+
break;
|
|
764
|
+
} else if (thisPeriodStart > now && thisPeriodEnd > now) {
|
|
765
|
+
rewardPerTimeUnitSecond = rps;
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const rewardTokenDecimals = reward.token.decimals.toNumber();
|
|
771
|
+
const rewardAmountPerUnitDecimals = new Decimal(10).pow(reward.rewardsPerSecondDecimals.toString());
|
|
772
|
+
const rewardAmountPerUnitLamports = new Decimal(10).pow(rewardTokenDecimals.toString());
|
|
773
|
+
|
|
774
|
+
const rpsAdjusted = new Decimal(rewardPerTimeUnitSecond.toString())
|
|
775
|
+
.div(rewardAmountPerUnitDecimals)
|
|
776
|
+
.div(rewardAmountPerUnitLamports);
|
|
777
|
+
|
|
778
|
+
return rewardPerTimeUnitSecond ? rpsAdjusted : new Decimal(0);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
private formatReserveData(parsedData: ReserveFields): ReserveDataType {
|
|
782
|
+
const mintTotalSupply = new Decimal(parsedData.collateral.mintTotalSupply.toString()).div(this.getMintFactor());
|
|
783
|
+
let reserveStatus = ReserveStatus.Active;
|
|
784
|
+
switch (parsedData.config.status) {
|
|
785
|
+
case 0:
|
|
786
|
+
reserveStatus = ReserveStatus.Active;
|
|
787
|
+
break;
|
|
788
|
+
case 1:
|
|
789
|
+
reserveStatus = ReserveStatus.Obsolete;
|
|
790
|
+
break;
|
|
791
|
+
case 2:
|
|
792
|
+
reserveStatus = ReserveStatus.Hidden;
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
return {
|
|
796
|
+
// Reserve config
|
|
797
|
+
|
|
798
|
+
status: reserveStatus,
|
|
799
|
+
mintAddress: parsedData.liquidity.mintPubkey,
|
|
800
|
+
borrowCurve: truncateBorrowCurve(parsedData.config.borrowRateCurve.points),
|
|
801
|
+
loanToValue: parsedData.config.loanToValuePct / 100,
|
|
802
|
+
maxLiquidationBonus: parsedData.config.maxLiquidationBonusBps / 10000,
|
|
803
|
+
minLiquidationBonus: parsedData.config.minLiquidationBonusBps / 10000,
|
|
804
|
+
liquidationThreshold: parsedData.config.liquidationThresholdPct / 100,
|
|
805
|
+
protocolTakeRate: parsedData.config.protocolTakeRatePct / 100,
|
|
806
|
+
reserveDepositLimit: new Decimal(parsedData.config.depositLimit.toString()),
|
|
807
|
+
reserveBorrowLimit: new Decimal(parsedData.config.borrowLimit.toString()),
|
|
808
|
+
|
|
809
|
+
// Reserve info
|
|
810
|
+
symbol: parseTokenSymbol(parsedData.config.tokenInfo.name),
|
|
811
|
+
decimals: this.state.liquidity.mintDecimals.toNumber(),
|
|
812
|
+
accumulatedProtocolFees: this.getAccumulatedProtocolFees().div(this.getMintFactor()),
|
|
813
|
+
mintTotalSupply,
|
|
814
|
+
depositLimitCrossedSlot: parsedData.liquidity.depositLimitCrossedSlot.toNumber(),
|
|
815
|
+
borrowLimitCrossedSlot: parsedData.liquidity.borrowLimitCrossedSlot.toNumber(),
|
|
816
|
+
borrowFactor: parsedData.config.borrowFactorPct.toNumber(),
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Compound current borrow rate over elapsed slots
|
|
822
|
+
*
|
|
823
|
+
* This also calculates protocol fees, which are taken for all obligations that have borrowed from current reserve.
|
|
824
|
+
*
|
|
825
|
+
* This also calculates referral fees, which are taken into pendingReferralFees.
|
|
826
|
+
*
|
|
827
|
+
* https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L517
|
|
828
|
+
*
|
|
829
|
+
* @param slotsElapsed
|
|
830
|
+
* @param referralFeeBps
|
|
831
|
+
*/
|
|
832
|
+
private compoundInterest(
|
|
833
|
+
slotsElapsed: number,
|
|
834
|
+
referralFeeBps: number
|
|
835
|
+
): {
|
|
836
|
+
newDebt: Decimal;
|
|
837
|
+
netNewDebt: Decimal;
|
|
838
|
+
variableProtocolFee: Decimal;
|
|
839
|
+
fixedHostFee: Decimal;
|
|
840
|
+
absoluteReferralFee: Decimal;
|
|
841
|
+
maxReferralFees: Decimal;
|
|
842
|
+
newAccProtocolFees: Decimal;
|
|
843
|
+
pendingReferralFees: Decimal;
|
|
844
|
+
} {
|
|
845
|
+
const currentBorrowRate = this.calculateBorrowRate();
|
|
846
|
+
const protocolTakeRate = new Decimal(this.state.config.protocolTakeRatePct).div(100);
|
|
847
|
+
const referralRate = new Decimal(referralFeeBps).div(10_000);
|
|
848
|
+
const fixedHostInterestRate = this.getFixedHostInterestRate();
|
|
849
|
+
|
|
850
|
+
const compoundedInterestRate = this.approximateCompoundedInterest(
|
|
851
|
+
new Decimal(currentBorrowRate).plus(fixedHostInterestRate),
|
|
852
|
+
slotsElapsed
|
|
853
|
+
);
|
|
854
|
+
const compoundedFixedRate = this.approximateCompoundedInterest(fixedHostInterestRate, slotsElapsed);
|
|
855
|
+
|
|
856
|
+
const previousDebt = this.getBorrowedAmount();
|
|
857
|
+
const newDebt = previousDebt.mul(compoundedInterestRate);
|
|
858
|
+
const fixedHostFee = previousDebt.mul(compoundedFixedRate).sub(previousDebt);
|
|
859
|
+
|
|
860
|
+
const netNewDebt = newDebt.sub(previousDebt).sub(fixedHostFee);
|
|
861
|
+
|
|
862
|
+
const variableProtocolFee = netNewDebt.mul(protocolTakeRate);
|
|
863
|
+
const absoluteReferralFee = protocolTakeRate.mul(referralRate);
|
|
864
|
+
const maxReferralFees = netNewDebt.mul(absoluteReferralFee);
|
|
865
|
+
|
|
866
|
+
const newAccProtocolFees = variableProtocolFee
|
|
867
|
+
.add(fixedHostFee)
|
|
868
|
+
.sub(maxReferralFees)
|
|
869
|
+
.add(this.getAccumulatedProtocolFees());
|
|
870
|
+
|
|
871
|
+
const pendingReferralFees = this.getPendingReferrerFees().add(maxReferralFees);
|
|
872
|
+
|
|
873
|
+
return {
|
|
874
|
+
newDebt,
|
|
875
|
+
netNewDebt,
|
|
876
|
+
variableProtocolFee,
|
|
877
|
+
fixedHostFee,
|
|
878
|
+
absoluteReferralFee,
|
|
879
|
+
maxReferralFees,
|
|
880
|
+
newAccProtocolFees,
|
|
881
|
+
pendingReferralFees,
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Approximation to match the smart contract calculation
|
|
887
|
+
* https://github.com/Kamino-Finance/klend/blob/release/1.3.0/programs/klend/src/state/reserve.rs#L1026
|
|
888
|
+
* @param rate
|
|
889
|
+
* @param elapsedSlots
|
|
890
|
+
* @private
|
|
891
|
+
*/
|
|
892
|
+
private approximateCompoundedInterest(rate: Decimal, elapsedSlots: number): Decimal {
|
|
893
|
+
const base = rate.div(SLOTS_PER_YEAR);
|
|
894
|
+
switch (elapsedSlots) {
|
|
895
|
+
case 0:
|
|
896
|
+
return new Decimal(1);
|
|
897
|
+
case 1:
|
|
898
|
+
return base.add(1);
|
|
899
|
+
case 2:
|
|
900
|
+
return base.add(1).mul(base.add(1));
|
|
901
|
+
case 3:
|
|
902
|
+
return base.add(1).mul(base.add(1)).mul(base.add(1));
|
|
903
|
+
case 4:
|
|
904
|
+
// eslint-disable-next-line no-case-declarations
|
|
905
|
+
const pow2 = base.add(1).mul(base.add(1));
|
|
906
|
+
return pow2.mul(pow2);
|
|
907
|
+
}
|
|
908
|
+
const exp = elapsedSlots;
|
|
909
|
+
const expMinus1 = exp - 1;
|
|
910
|
+
const expMinus2 = exp - 2;
|
|
911
|
+
|
|
912
|
+
const basePow2 = base.mul(base);
|
|
913
|
+
const basePow3 = basePow2.mul(base);
|
|
914
|
+
|
|
915
|
+
const firstTerm = base.mul(exp);
|
|
916
|
+
const secondTerm = basePow2.mul(exp).mul(expMinus1).div(2);
|
|
917
|
+
const thirdTerm = basePow3.mul(exp).mul(expMinus1).mul(expMinus2).div(6);
|
|
918
|
+
|
|
919
|
+
return new Decimal(1).add(firstTerm).add(secondTerm).add(thirdTerm);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
getBorrowCapForReserve(market: KaminoMarket): BorrowCapsAndCounters {
|
|
923
|
+
// Utilization cap
|
|
924
|
+
const utilizationCap = this.state.config.utilizationLimitBlockBorrowingAbove;
|
|
925
|
+
const utilizationCurrentValue = this.calculateUtilizationRatio();
|
|
926
|
+
|
|
927
|
+
// Daily borrow cap
|
|
928
|
+
const withdrawalCap = this.state.config.debtWithdrawalCap;
|
|
929
|
+
|
|
930
|
+
// Debt against collaterals in elevation groups
|
|
931
|
+
const debtAgainstCollateralReserveCaps: {
|
|
932
|
+
collateralReserve: PublicKey;
|
|
933
|
+
elevationGroup: number;
|
|
934
|
+
maxDebt: Decimal;
|
|
935
|
+
currentValue: Decimal;
|
|
936
|
+
}[] = market
|
|
937
|
+
.getMarketElevationGroupDescriptions()
|
|
938
|
+
.filter((x) => x.debtReserve === this.address.toString())
|
|
939
|
+
.map((elevationGroupDescription: ElevationGroupDescription) =>
|
|
940
|
+
elevationGroupDescription.collateralReserves.map((collateralReserveAddress) => {
|
|
941
|
+
const collRes = market.reserves.get(new PublicKey(collateralReserveAddress))!;
|
|
942
|
+
|
|
943
|
+
const debtLimitAgainstThisCollInGroup =
|
|
944
|
+
collRes.state.config.borrowLimitAgainstThisCollateralInElevationGroup[
|
|
945
|
+
elevationGroupDescription.elevationGroup - 1
|
|
946
|
+
].toString();
|
|
947
|
+
|
|
948
|
+
const debtCounterAgainstThisCollInGroup =
|
|
949
|
+
collRes.state.borrowedAmountsAgainstThisReserveInElevationGroups[
|
|
950
|
+
elevationGroupDescription.elevationGroup - 1
|
|
951
|
+
].toString();
|
|
952
|
+
|
|
953
|
+
return {
|
|
954
|
+
collateralReserve: collRes.address,
|
|
955
|
+
elevationGroup: elevationGroupDescription.elevationGroup,
|
|
956
|
+
maxDebt: new Decimal(debtLimitAgainstThisCollInGroup),
|
|
957
|
+
currentValue: new Decimal(debtCounterAgainstThisCollInGroup),
|
|
958
|
+
};
|
|
959
|
+
})
|
|
960
|
+
)
|
|
961
|
+
.flat();
|
|
962
|
+
|
|
963
|
+
const caps: BorrowCapsAndCounters = {
|
|
964
|
+
// Utilization cap
|
|
965
|
+
utilizationCap: new Decimal(utilizationCap > 0 ? utilizationCap / 100 : 1),
|
|
966
|
+
utilizationCurrentValue: new Decimal(utilizationCurrentValue),
|
|
967
|
+
|
|
968
|
+
// Daily borrow cap
|
|
969
|
+
netWithdrawalCap: new Decimal(withdrawalCap.configCapacity.toString()),
|
|
970
|
+
netWithdrawalCurrentValue: new Decimal(withdrawalCap.currentTotal.toString()),
|
|
971
|
+
netWithdrawalLastUpdateTs: new Decimal(withdrawalCap.lastIntervalStartTimestamp.toString()),
|
|
972
|
+
netWithdrawalIntervalDurationSeconds: new Decimal(withdrawalCap.configIntervalLengthSeconds.toString()),
|
|
973
|
+
|
|
974
|
+
// Global cap
|
|
975
|
+
globalDebtCap: new Decimal(this.state.config.borrowLimit.toString()),
|
|
976
|
+
globalTotalBorrowed: this.getBorrowedAmount(),
|
|
977
|
+
|
|
978
|
+
// Debt outside emode cap
|
|
979
|
+
debtOutsideEmodeCap: new Decimal(this.state.config.borrowLimitOutsideElevationGroup.toString()),
|
|
980
|
+
borrowedOutsideEmode: this.getBorrowedAmountOutsideElevationGroup(),
|
|
981
|
+
|
|
982
|
+
debtAgainstCollateralReserveCaps: debtAgainstCollateralReserveCaps,
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
return caps;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/* This takes into account all the caps */
|
|
989
|
+
getLiquidityAvailableForDebtReserveGivenCaps(market: KaminoMarket, elevationGroups: number[]): Decimal[] {
|
|
990
|
+
const caps = this.getBorrowCapForReserve(market);
|
|
991
|
+
|
|
992
|
+
const liquidityAvailable = this.getLiquidityAvailableAmount();
|
|
993
|
+
|
|
994
|
+
// Cap this to utilization cap first
|
|
995
|
+
const utilizationRatioLimit = caps.utilizationCap;
|
|
996
|
+
const currentUtilizationRatio = this.calculateUtilizationRatio();
|
|
997
|
+
|
|
998
|
+
const liquidityGivenUtilizationCap = this.getTotalSupply().mul(
|
|
999
|
+
utilizationRatioLimit.minus(currentUtilizationRatio)
|
|
1000
|
+
);
|
|
1001
|
+
|
|
1002
|
+
const remainingDailyCap = caps.netWithdrawalIntervalDurationSeconds.eq(new Decimal(0))
|
|
1003
|
+
? new Decimal(U64_MAX)
|
|
1004
|
+
: caps.netWithdrawalCap.minus(caps.netWithdrawalCurrentValue);
|
|
1005
|
+
|
|
1006
|
+
const remainingGlobalCap = caps.globalDebtCap.minus(caps.globalTotalBorrowed);
|
|
1007
|
+
const remainingOutsideEmodeCap = caps.debtOutsideEmodeCap.minus(caps.borrowedOutsideEmode);
|
|
1008
|
+
|
|
1009
|
+
const available = elevationGroups.map((elevationGroup) => {
|
|
1010
|
+
if (elevationGroup === 0) {
|
|
1011
|
+
const availableInCrossMode = Decimal.min(
|
|
1012
|
+
positiveOrZero(liquidityAvailable),
|
|
1013
|
+
positiveOrZero(remainingOutsideEmodeCap),
|
|
1014
|
+
positiveOrZero(remainingDailyCap),
|
|
1015
|
+
positiveOrZero(remainingGlobalCap),
|
|
1016
|
+
positiveOrZero(liquidityGivenUtilizationCap)
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
return availableInCrossMode;
|
|
1020
|
+
} else {
|
|
1021
|
+
const remainingInsideEmodeCaps = Decimal.min(
|
|
1022
|
+
...caps.debtAgainstCollateralReserveCaps
|
|
1023
|
+
.filter((x) => x.elevationGroup === elevationGroup)
|
|
1024
|
+
.map((x) => x.maxDebt.minus(x.currentValue))
|
|
1025
|
+
);
|
|
1026
|
+
return Decimal.min(
|
|
1027
|
+
positiveOrZero(liquidityAvailable),
|
|
1028
|
+
positiveOrZero(remainingInsideEmodeCaps),
|
|
1029
|
+
positiveOrZero(remainingDailyCap),
|
|
1030
|
+
positiveOrZero(remainingGlobalCap),
|
|
1031
|
+
positiveOrZero(liquidityGivenUtilizationCap)
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
return available;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
const truncateBorrowCurve = (points: CurvePointFields[]): [number, number][] => {
|
|
1041
|
+
const curve: [number, number][] = [];
|
|
1042
|
+
for (const { utilizationRateBps, borrowRateBps } of points) {
|
|
1043
|
+
curve.push([utilizationRateBps / ONE_HUNDRED_PCT_IN_BPS, borrowRateBps / ONE_HUNDRED_PCT_IN_BPS]);
|
|
1044
|
+
|
|
1045
|
+
if (utilizationRateBps === ONE_HUNDRED_PCT_IN_BPS) {
|
|
1046
|
+
break;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return curve;
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
export async function createReserveIxs(
|
|
1053
|
+
connection: Connection,
|
|
1054
|
+
owner: PublicKey,
|
|
1055
|
+
lendingMarket: PublicKey,
|
|
1056
|
+
liquidityMint: PublicKey,
|
|
1057
|
+
reserveAddress: PublicKey,
|
|
1058
|
+
programId: PublicKey
|
|
1059
|
+
): Promise<TransactionInstruction[]> {
|
|
1060
|
+
const size = Reserve.layout.span + 8;
|
|
1061
|
+
|
|
1062
|
+
const createReserveIx = SystemProgram.createAccount({
|
|
1063
|
+
fromPubkey: owner,
|
|
1064
|
+
newAccountPubkey: reserveAddress,
|
|
1065
|
+
lamports: await connection.getMinimumBalanceForRentExemption(size),
|
|
1066
|
+
space: size,
|
|
1067
|
+
programId: programId,
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
const { liquiditySupplyVault, collateralMint, collateralSupplyVault, feeVault } = reservePdas(
|
|
1071
|
+
programId,
|
|
1072
|
+
lendingMarket,
|
|
1073
|
+
liquidityMint
|
|
1074
|
+
);
|
|
1075
|
+
const [lendingMarketAuthority, _] = lendingMarketAuthPda(lendingMarket, programId);
|
|
1076
|
+
|
|
1077
|
+
const accounts: InitReserveAccounts = {
|
|
1078
|
+
lendingMarketOwner: owner,
|
|
1079
|
+
lendingMarket: lendingMarket,
|
|
1080
|
+
lendingMarketAuthority: lendingMarketAuthority,
|
|
1081
|
+
reserve: reserveAddress,
|
|
1082
|
+
reserveLiquidityMint: liquidityMint,
|
|
1083
|
+
reserveLiquiditySupply: liquiditySupplyVault,
|
|
1084
|
+
feeReceiver: feeVault,
|
|
1085
|
+
reserveCollateralMint: collateralMint,
|
|
1086
|
+
reserveCollateralSupply: collateralSupplyVault,
|
|
1087
|
+
liquidityTokenProgram: TOKEN_PROGRAM_ID,
|
|
1088
|
+
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1089
|
+
systemProgram: SystemProgram.programId,
|
|
1090
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
const initReserveIx = initReserve(accounts, programId);
|
|
1094
|
+
|
|
1095
|
+
return [createReserveIx, initReserveIx];
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
export function updateReserveConfigIx(
|
|
1099
|
+
marketWithAddress: MarketWithAddress,
|
|
1100
|
+
reserveAddress: PublicKey,
|
|
1101
|
+
modeDiscriminator: number,
|
|
1102
|
+
value: Uint8Array,
|
|
1103
|
+
programId: PublicKey
|
|
1104
|
+
): TransactionInstruction {
|
|
1105
|
+
value;
|
|
1106
|
+
const args: UpdateReserveConfigArgs = {
|
|
1107
|
+
mode: new anchor.BN(modeDiscriminator),
|
|
1108
|
+
value: value,
|
|
1109
|
+
skipValidation: false,
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
const accounts: UpdateReserveConfigAccounts = {
|
|
1113
|
+
lendingMarketOwner: marketWithAddress.state.lendingMarketOwner,
|
|
1114
|
+
lendingMarket: marketWithAddress.address,
|
|
1115
|
+
reserve: reserveAddress,
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
const ix = updateReserveConfig(args, accounts, programId);
|
|
1119
|
+
|
|
1120
|
+
return ix;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
export function updateEntireReserveConfigIx(
|
|
1124
|
+
marketWithAddress: MarketWithAddress,
|
|
1125
|
+
reserveAddress: PublicKey,
|
|
1126
|
+
reserveConfig: ReserveConfig,
|
|
1127
|
+
programId: PublicKey
|
|
1128
|
+
): TransactionInstruction {
|
|
1129
|
+
const layout = ReserveConfig.layout();
|
|
1130
|
+
const data = Buffer.alloc(1000);
|
|
1131
|
+
const len = layout.encode(reserveConfig.toEncodable(), data);
|
|
1132
|
+
const value = Uint8Array.from([...data.subarray(0, len)]);
|
|
1133
|
+
|
|
1134
|
+
const args: UpdateReserveConfigArgs = {
|
|
1135
|
+
mode: new anchor.BN(25),
|
|
1136
|
+
value: value,
|
|
1137
|
+
skipValidation: true,
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
const accounts: UpdateReserveConfigAccounts = {
|
|
1141
|
+
lendingMarketOwner: marketWithAddress.state.lendingMarketOwner,
|
|
1142
|
+
lendingMarket: marketWithAddress.address,
|
|
1143
|
+
reserve: reserveAddress,
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
const ix = updateReserveConfig(args, accounts, programId);
|
|
1147
|
+
|
|
1148
|
+
return ix;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
export function parseForChangesReserveConfigAndGetIxs(
|
|
1152
|
+
marketWithAddress: MarketWithAddress,
|
|
1153
|
+
reserve: Reserve | undefined,
|
|
1154
|
+
reserveAddress: PublicKey,
|
|
1155
|
+
reserveConfig: ReserveConfig,
|
|
1156
|
+
programId: PublicKey
|
|
1157
|
+
) {
|
|
1158
|
+
const updateReserveIxnsArgs: { mode: number; value: Uint8Array }[] = [];
|
|
1159
|
+
for (const key in reserveConfig.toEncodable()) {
|
|
1160
|
+
if (key === 'borrowRateCurve') {
|
|
1161
|
+
if (reserve === undefined) {
|
|
1162
|
+
updateReserveIxnsArgs.push({
|
|
1163
|
+
mode: UpdateBorrowRateCurve.discriminator,
|
|
1164
|
+
value: updateReserveConfigEncodedValue(UpdateBorrowRateCurve.discriminator, reserveConfig.borrowRateCurve),
|
|
1165
|
+
});
|
|
1166
|
+
} else {
|
|
1167
|
+
for (let i = 0; i < reserveConfig.borrowRateCurve.points.length; i++) {
|
|
1168
|
+
if (
|
|
1169
|
+
reserve.config.borrowRateCurve.points[i].utilizationRateBps !==
|
|
1170
|
+
reserveConfig.borrowRateCurve.points[i].utilizationRateBps ||
|
|
1171
|
+
reserve.config.borrowRateCurve.points[i].borrowRateBps !==
|
|
1172
|
+
reserveConfig.borrowRateCurve.points[i].borrowRateBps
|
|
1173
|
+
) {
|
|
1174
|
+
updateReserveIxnsArgs.push({
|
|
1175
|
+
mode: UpdateBorrowRateCurve.discriminator,
|
|
1176
|
+
value: updateReserveConfigEncodedValue(
|
|
1177
|
+
UpdateBorrowRateCurve.discriminator,
|
|
1178
|
+
reserveConfig.borrowRateCurve
|
|
1179
|
+
),
|
|
1180
|
+
});
|
|
1181
|
+
break;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
} else if (key === 'fees') {
|
|
1186
|
+
if (reserve === undefined) {
|
|
1187
|
+
updateReserveIxnsArgs.push({
|
|
1188
|
+
mode: UpdateConfigMode.UpdateFeesBorrowFee.discriminator,
|
|
1189
|
+
value: updateReserveConfigEncodedValue(
|
|
1190
|
+
UpdateConfigMode.UpdateFeesBorrowFee.discriminator,
|
|
1191
|
+
reserveConfig.fees.borrowFeeSf.toNumber()
|
|
1192
|
+
),
|
|
1193
|
+
});
|
|
1194
|
+
updateReserveIxnsArgs.push({
|
|
1195
|
+
mode: UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator,
|
|
1196
|
+
value: updateReserveConfigEncodedValue(
|
|
1197
|
+
UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator,
|
|
1198
|
+
reserveConfig.fees.flashLoanFeeSf.toNumber()
|
|
1199
|
+
),
|
|
1200
|
+
});
|
|
1201
|
+
} else if (!reserve.config.fees.borrowFeeSf.eq(reserveConfig.fees.borrowFeeSf)) {
|
|
1202
|
+
updateReserveIxnsArgs.push({
|
|
1203
|
+
mode: UpdateConfigMode.UpdateFeesBorrowFee.discriminator,
|
|
1204
|
+
value: updateReserveConfigEncodedValue(
|
|
1205
|
+
UpdateConfigMode.UpdateFeesBorrowFee.discriminator,
|
|
1206
|
+
reserveConfig.fees.borrowFeeSf.toNumber()
|
|
1207
|
+
),
|
|
1208
|
+
});
|
|
1209
|
+
} else if (!reserve.config.fees.flashLoanFeeSf.eq(reserveConfig.fees.flashLoanFeeSf)) {
|
|
1210
|
+
updateReserveIxnsArgs.push({
|
|
1211
|
+
mode: UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator,
|
|
1212
|
+
value: updateReserveConfigEncodedValue(
|
|
1213
|
+
UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator,
|
|
1214
|
+
reserveConfig.fees.flashLoanFeeSf.toNumber()
|
|
1215
|
+
),
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
} else if (key === 'depositLimit') {
|
|
1219
|
+
if (reserve === undefined) {
|
|
1220
|
+
updateReserveIxnsArgs.push({
|
|
1221
|
+
mode: UpdateConfigMode.UpdateDepositLimit.discriminator,
|
|
1222
|
+
value: updateReserveConfigEncodedValue(
|
|
1223
|
+
UpdateConfigMode.UpdateDepositLimit.discriminator,
|
|
1224
|
+
reserveConfig.depositLimit.toNumber()
|
|
1225
|
+
),
|
|
1226
|
+
});
|
|
1227
|
+
} else if (!reserve.config.depositLimit.eq(reserveConfig.depositLimit)) {
|
|
1228
|
+
updateReserveIxnsArgs.push({
|
|
1229
|
+
mode: UpdateConfigMode.UpdateDepositLimit.discriminator,
|
|
1230
|
+
value: updateReserveConfigEncodedValue(
|
|
1231
|
+
UpdateConfigMode.UpdateDepositLimit.discriminator,
|
|
1232
|
+
reserveConfig.depositLimit.toNumber()
|
|
1233
|
+
),
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
} else if (key === 'borrowLimit') {
|
|
1237
|
+
if (reserve === undefined) {
|
|
1238
|
+
updateReserveIxnsArgs.push({
|
|
1239
|
+
mode: UpdateConfigMode.UpdateBorrowLimit.discriminator,
|
|
1240
|
+
value: updateReserveConfigEncodedValue(
|
|
1241
|
+
UpdateConfigMode.UpdateBorrowLimit.discriminator,
|
|
1242
|
+
reserveConfig.borrowLimit.toNumber()
|
|
1243
|
+
),
|
|
1244
|
+
});
|
|
1245
|
+
} else if (!reserve.config.borrowLimit.eq(reserveConfig.borrowLimit)) {
|
|
1246
|
+
updateReserveIxnsArgs.push({
|
|
1247
|
+
mode: UpdateConfigMode.UpdateBorrowLimit.discriminator,
|
|
1248
|
+
value: updateReserveConfigEncodedValue(
|
|
1249
|
+
UpdateConfigMode.UpdateBorrowLimit.discriminator,
|
|
1250
|
+
reserveConfig.borrowLimit.toNumber()
|
|
1251
|
+
),
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
} else if (key === 'maxLiquidationBonusBps') {
|
|
1255
|
+
if (reserve === undefined) {
|
|
1256
|
+
updateReserveIxnsArgs.push({
|
|
1257
|
+
mode: UpdateConfigMode.UpdateMaxLiquidationBonusBps.discriminator,
|
|
1258
|
+
value: updateReserveConfigEncodedValue(
|
|
1259
|
+
UpdateConfigMode.UpdateMaxLiquidationBonusBps.discriminator,
|
|
1260
|
+
reserveConfig.maxLiquidationBonusBps
|
|
1261
|
+
),
|
|
1262
|
+
});
|
|
1263
|
+
} else if (reserve.config.maxLiquidationBonusBps !== reserveConfig.maxLiquidationBonusBps) {
|
|
1264
|
+
updateReserveIxnsArgs.push({
|
|
1265
|
+
mode: UpdateConfigMode.UpdateMaxLiquidationBonusBps.discriminator,
|
|
1266
|
+
value: updateReserveConfigEncodedValue(
|
|
1267
|
+
UpdateConfigMode.UpdateMaxLiquidationBonusBps.discriminator,
|
|
1268
|
+
reserveConfig.maxLiquidationBonusBps
|
|
1269
|
+
),
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
} else if (key === 'minLiquidationBonusBps') {
|
|
1273
|
+
if (reserve === undefined) {
|
|
1274
|
+
updateReserveIxnsArgs.push({
|
|
1275
|
+
mode: UpdateConfigMode.UpdateMinLiquidationBonusBps.discriminator,
|
|
1276
|
+
value: updateReserveConfigEncodedValue(
|
|
1277
|
+
UpdateConfigMode.UpdateMinLiquidationBonusBps.discriminator,
|
|
1278
|
+
reserveConfig.minLiquidationBonusBps
|
|
1279
|
+
),
|
|
1280
|
+
});
|
|
1281
|
+
} else if (reserve.config.minLiquidationBonusBps !== reserveConfig.minLiquidationBonusBps) {
|
|
1282
|
+
updateReserveIxnsArgs.push({
|
|
1283
|
+
mode: UpdateConfigMode.UpdateMinLiquidationBonusBps.discriminator,
|
|
1284
|
+
value: updateReserveConfigEncodedValue(
|
|
1285
|
+
UpdateConfigMode.UpdateMinLiquidationBonusBps.discriminator,
|
|
1286
|
+
reserveConfig.minLiquidationBonusBps
|
|
1287
|
+
),
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
} else if (key === 'badDebtLiquidationBonusBps') {
|
|
1291
|
+
if (reserve === undefined) {
|
|
1292
|
+
updateReserveIxnsArgs.push({
|
|
1293
|
+
mode: UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.discriminator,
|
|
1294
|
+
value: updateReserveConfigEncodedValue(
|
|
1295
|
+
UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.discriminator,
|
|
1296
|
+
reserveConfig.badDebtLiquidationBonusBps
|
|
1297
|
+
),
|
|
1298
|
+
});
|
|
1299
|
+
} else if (reserve.config.badDebtLiquidationBonusBps !== reserveConfig.badDebtLiquidationBonusBps) {
|
|
1300
|
+
updateReserveIxnsArgs.push({
|
|
1301
|
+
mode: UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.discriminator,
|
|
1302
|
+
value: updateReserveConfigEncodedValue(
|
|
1303
|
+
UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.discriminator,
|
|
1304
|
+
reserveConfig.badDebtLiquidationBonusBps
|
|
1305
|
+
),
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
} else if (key === 'liquidationThresholdPct') {
|
|
1309
|
+
if (reserve === undefined) {
|
|
1310
|
+
updateReserveIxnsArgs.push({
|
|
1311
|
+
mode: UpdateConfigMode.UpdateLiquidationThresholdPct.discriminator,
|
|
1312
|
+
value: updateReserveConfigEncodedValue(
|
|
1313
|
+
UpdateConfigMode.UpdateLiquidationThresholdPct.discriminator,
|
|
1314
|
+
reserveConfig.liquidationThresholdPct
|
|
1315
|
+
),
|
|
1316
|
+
});
|
|
1317
|
+
} else if (reserve.config.liquidationThresholdPct !== reserveConfig.liquidationThresholdPct) {
|
|
1318
|
+
updateReserveIxnsArgs.push({
|
|
1319
|
+
mode: UpdateConfigMode.UpdateLiquidationThresholdPct.discriminator,
|
|
1320
|
+
value: updateReserveConfigEncodedValue(
|
|
1321
|
+
UpdateConfigMode.UpdateLiquidationThresholdPct.discriminator,
|
|
1322
|
+
reserveConfig.liquidationThresholdPct
|
|
1323
|
+
),
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
} else if (key === 'protocolTakeRatePct') {
|
|
1327
|
+
if (reserve === undefined) {
|
|
1328
|
+
updateReserveIxnsArgs.push({
|
|
1329
|
+
mode: UpdateConfigMode.UpdateProtocolTakeRate.discriminator,
|
|
1330
|
+
value: updateReserveConfigEncodedValue(
|
|
1331
|
+
UpdateConfigMode.UpdateProtocolTakeRate.discriminator,
|
|
1332
|
+
reserveConfig.protocolTakeRatePct
|
|
1333
|
+
),
|
|
1334
|
+
});
|
|
1335
|
+
} else if (reserve.config.protocolTakeRatePct !== reserveConfig.protocolTakeRatePct) {
|
|
1336
|
+
updateReserveIxnsArgs.push({
|
|
1337
|
+
mode: UpdateConfigMode.UpdateProtocolTakeRate.discriminator,
|
|
1338
|
+
value: updateReserveConfigEncodedValue(
|
|
1339
|
+
UpdateConfigMode.UpdateProtocolTakeRate.discriminator,
|
|
1340
|
+
reserveConfig.protocolTakeRatePct
|
|
1341
|
+
),
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
} else if (key === 'status') {
|
|
1345
|
+
if (reserve === undefined) {
|
|
1346
|
+
updateReserveIxnsArgs.push({
|
|
1347
|
+
mode: UpdateConfigMode.UpdateReserveStatus.discriminator,
|
|
1348
|
+
value: updateReserveConfigEncodedValue(
|
|
1349
|
+
UpdateConfigMode.UpdateReserveStatus.discriminator,
|
|
1350
|
+
reserveConfig.status
|
|
1351
|
+
),
|
|
1352
|
+
});
|
|
1353
|
+
} else if (reserve.config.status !== reserveConfig.status) {
|
|
1354
|
+
updateReserveIxnsArgs.push({
|
|
1355
|
+
mode: UpdateConfigMode.UpdateReserveStatus.discriminator,
|
|
1356
|
+
value: updateReserveConfigEncodedValue(
|
|
1357
|
+
UpdateConfigMode.UpdateReserveStatus.discriminator,
|
|
1358
|
+
reserveConfig.status
|
|
1359
|
+
),
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
} else if (key === 'disableUsageAsCollOutsideEmode') {
|
|
1363
|
+
if (reserve === undefined) {
|
|
1364
|
+
updateReserveIxnsArgs.push({
|
|
1365
|
+
mode: UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator,
|
|
1366
|
+
value: updateReserveConfigEncodedValue(
|
|
1367
|
+
UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator,
|
|
1368
|
+
reserveConfig.disableUsageAsCollOutsideEmode
|
|
1369
|
+
),
|
|
1370
|
+
});
|
|
1371
|
+
} else if (reserve.config.disableUsageAsCollOutsideEmode !== reserveConfig.disableUsageAsCollOutsideEmode) {
|
|
1372
|
+
updateReserveIxnsArgs.push({
|
|
1373
|
+
mode: UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator,
|
|
1374
|
+
value: updateReserveConfigEncodedValue(
|
|
1375
|
+
UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator,
|
|
1376
|
+
reserveConfig.disableUsageAsCollOutsideEmode
|
|
1377
|
+
),
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
} else if (key === 'utilizationLimitBlockBorrowingAbove') {
|
|
1381
|
+
if (reserve === undefined) {
|
|
1382
|
+
updateReserveIxnsArgs.push({
|
|
1383
|
+
mode: UpdateConfigMode.UpdateBlockBorrowingAboveUtilization.discriminator,
|
|
1384
|
+
value: updateReserveConfigEncodedValue(
|
|
1385
|
+
UpdateConfigMode.UpdateBlockBorrowingAboveUtilization.discriminator,
|
|
1386
|
+
reserveConfig.utilizationLimitBlockBorrowingAbove
|
|
1387
|
+
),
|
|
1388
|
+
});
|
|
1389
|
+
} else if (
|
|
1390
|
+
reserve.config.utilizationLimitBlockBorrowingAbove !== reserveConfig.utilizationLimitBlockBorrowingAbove
|
|
1391
|
+
) {
|
|
1392
|
+
updateReserveIxnsArgs.push({
|
|
1393
|
+
mode: UpdateConfigMode.UpdateBlockBorrowingAboveUtilization.discriminator,
|
|
1394
|
+
value: updateReserveConfigEncodedValue(
|
|
1395
|
+
UpdateConfigMode.UpdateBlockBorrowingAboveUtilization.discriminator,
|
|
1396
|
+
reserveConfig.utilizationLimitBlockBorrowingAbove
|
|
1397
|
+
),
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
} else if (key === 'deleveragingThresholdSlotsPerBps') {
|
|
1401
|
+
if (reserve === undefined) {
|
|
1402
|
+
updateReserveIxnsArgs.push({
|
|
1403
|
+
mode: UpdateConfigMode.DeleveragingThresholdSlotsPerBps.discriminator,
|
|
1404
|
+
value: updateReserveConfigEncodedValue(
|
|
1405
|
+
UpdateConfigMode.DeleveragingThresholdSlotsPerBps.discriminator,
|
|
1406
|
+
reserveConfig.deleveragingThresholdSlotsPerBps.toNumber()
|
|
1407
|
+
),
|
|
1408
|
+
});
|
|
1409
|
+
} else if (!reserve.config.deleveragingThresholdSlotsPerBps.eq(reserveConfig.deleveragingThresholdSlotsPerBps)) {
|
|
1410
|
+
updateReserveIxnsArgs.push({
|
|
1411
|
+
mode: UpdateConfigMode.DeleveragingThresholdSlotsPerBps.discriminator,
|
|
1412
|
+
value: updateReserveConfigEncodedValue(
|
|
1413
|
+
UpdateConfigMode.DeleveragingThresholdSlotsPerBps.discriminator,
|
|
1414
|
+
reserveConfig.deleveragingThresholdSlotsPerBps.toNumber()
|
|
1415
|
+
),
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
} else if (key === 'depositWithdrawalCap') {
|
|
1419
|
+
if (reserve === undefined) {
|
|
1420
|
+
updateReserveIxnsArgs.push({
|
|
1421
|
+
mode: UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator,
|
|
1422
|
+
value: updateReserveConfigEncodedValue(UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator, [
|
|
1423
|
+
reserveConfig.depositWithdrawalCap.configCapacity.toNumber(),
|
|
1424
|
+
reserveConfig.depositWithdrawalCap.configIntervalLengthSeconds.toNumber(),
|
|
1425
|
+
]),
|
|
1426
|
+
});
|
|
1427
|
+
updateReserveIxnsArgs.push({
|
|
1428
|
+
mode: UpdateConfigMode.UpdateDepositWithdrawalCapCurrentTotal.discriminator,
|
|
1429
|
+
value: updateReserveConfigEncodedValue(
|
|
1430
|
+
UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator,
|
|
1431
|
+
reserveConfig.depositWithdrawalCap.currentTotal.toNumber()
|
|
1432
|
+
),
|
|
1433
|
+
});
|
|
1434
|
+
} else if (
|
|
1435
|
+
!reserve.config.depositWithdrawalCap.configCapacity.eq(reserveConfig.depositWithdrawalCap.configCapacity) ||
|
|
1436
|
+
!reserve.config.depositWithdrawalCap.configIntervalLengthSeconds.eq(
|
|
1437
|
+
reserveConfig.depositWithdrawalCap.configIntervalLengthSeconds
|
|
1438
|
+
)
|
|
1439
|
+
) {
|
|
1440
|
+
updateReserveIxnsArgs.push({
|
|
1441
|
+
mode: UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator,
|
|
1442
|
+
value: updateReserveConfigEncodedValue(UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator, [
|
|
1443
|
+
reserveConfig.depositWithdrawalCap.configCapacity.toNumber(),
|
|
1444
|
+
reserveConfig.depositWithdrawalCap.configIntervalLengthSeconds.toNumber(),
|
|
1445
|
+
]),
|
|
1446
|
+
});
|
|
1447
|
+
} else if (
|
|
1448
|
+
!reserve.config.depositWithdrawalCap.currentTotal.eq(reserveConfig.depositWithdrawalCap.currentTotal)
|
|
1449
|
+
) {
|
|
1450
|
+
updateReserveIxnsArgs.push({
|
|
1451
|
+
mode: UpdateConfigMode.UpdateDepositWithdrawalCapCurrentTotal.discriminator,
|
|
1452
|
+
value: updateReserveConfigEncodedValue(
|
|
1453
|
+
UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator,
|
|
1454
|
+
reserveConfig.depositWithdrawalCap.currentTotal.toNumber()
|
|
1455
|
+
),
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
} else if (key === 'debtWithdrawalCap') {
|
|
1459
|
+
if (reserve === undefined) {
|
|
1460
|
+
updateReserveIxnsArgs.push({
|
|
1461
|
+
mode: UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator,
|
|
1462
|
+
value: updateReserveConfigEncodedValue(UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator, [
|
|
1463
|
+
reserveConfig.debtWithdrawalCap.configCapacity.toNumber(),
|
|
1464
|
+
reserveConfig.debtWithdrawalCap.configIntervalLengthSeconds.toNumber(),
|
|
1465
|
+
]),
|
|
1466
|
+
});
|
|
1467
|
+
updateReserveIxnsArgs.push({
|
|
1468
|
+
mode: UpdateConfigMode.UpdateDebtWithdrawalCapCurrentTotal.discriminator,
|
|
1469
|
+
value: updateReserveConfigEncodedValue(
|
|
1470
|
+
UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator,
|
|
1471
|
+
reserveConfig.debtWithdrawalCap.currentTotal.toNumber()
|
|
1472
|
+
),
|
|
1473
|
+
});
|
|
1474
|
+
} else if (
|
|
1475
|
+
!reserve.config.debtWithdrawalCap.configCapacity.eq(reserveConfig.debtWithdrawalCap.configCapacity) ||
|
|
1476
|
+
!reserve.config.debtWithdrawalCap.configIntervalLengthSeconds.eq(
|
|
1477
|
+
reserveConfig.debtWithdrawalCap.configIntervalLengthSeconds
|
|
1478
|
+
)
|
|
1479
|
+
) {
|
|
1480
|
+
updateReserveIxnsArgs.push({
|
|
1481
|
+
mode: UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator,
|
|
1482
|
+
value: updateReserveConfigEncodedValue(UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator, [
|
|
1483
|
+
reserveConfig.debtWithdrawalCap.configCapacity.toNumber(),
|
|
1484
|
+
reserveConfig.debtWithdrawalCap.configIntervalLengthSeconds.toNumber(),
|
|
1485
|
+
]),
|
|
1486
|
+
});
|
|
1487
|
+
} else if (!reserve.config.debtWithdrawalCap.currentTotal.eq(reserveConfig.debtWithdrawalCap.currentTotal)) {
|
|
1488
|
+
updateReserveIxnsArgs.push({
|
|
1489
|
+
mode: UpdateConfigMode.UpdateDebtWithdrawalCapCurrentTotal.discriminator,
|
|
1490
|
+
value: updateReserveConfigEncodedValue(
|
|
1491
|
+
UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator,
|
|
1492
|
+
reserveConfig.debtWithdrawalCap.currentTotal.toNumber()
|
|
1493
|
+
),
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
} else if (key === 'elevationGroups') {
|
|
1497
|
+
if (reserve === undefined) {
|
|
1498
|
+
updateReserveIxnsArgs.push({
|
|
1499
|
+
mode: UpdateConfigMode.UpdateElevationGroup.discriminator,
|
|
1500
|
+
value: updateReserveConfigEncodedValue(
|
|
1501
|
+
UpdateConfigMode.UpdateElevationGroup.discriminator,
|
|
1502
|
+
reserveConfig.elevationGroups
|
|
1503
|
+
),
|
|
1504
|
+
});
|
|
1505
|
+
} else {
|
|
1506
|
+
for (let i = 0; i < reserveConfig.elevationGroups.length; i++) {
|
|
1507
|
+
if (reserve.config.elevationGroups[i] !== reserveConfig.elevationGroups[i]) {
|
|
1508
|
+
updateReserveIxnsArgs.push({
|
|
1509
|
+
mode: UpdateConfigMode.UpdateElevationGroup.discriminator,
|
|
1510
|
+
value: updateReserveConfigEncodedValue(
|
|
1511
|
+
UpdateConfigMode.UpdateElevationGroup.discriminator,
|
|
1512
|
+
reserveConfig.elevationGroups
|
|
1513
|
+
),
|
|
1514
|
+
});
|
|
1515
|
+
break;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
} else if (key === 'borrowFactorPct') {
|
|
1520
|
+
if (reserve === undefined) {
|
|
1521
|
+
updateReserveIxnsArgs.push({
|
|
1522
|
+
mode: UpdateConfigMode.UpdateBorrowFactor.discriminator,
|
|
1523
|
+
value: updateReserveConfigEncodedValue(
|
|
1524
|
+
UpdateConfigMode.UpdateBorrowFactor.discriminator,
|
|
1525
|
+
reserveConfig.borrowFactorPct.toNumber()
|
|
1526
|
+
),
|
|
1527
|
+
});
|
|
1528
|
+
} else if (!reserve.config.borrowFactorPct.eq(reserveConfig.borrowFactorPct)) {
|
|
1529
|
+
updateReserveIxnsArgs.push({
|
|
1530
|
+
mode: UpdateConfigMode.UpdateBorrowFactor.discriminator,
|
|
1531
|
+
value: updateReserveConfigEncodedValue(
|
|
1532
|
+
UpdateConfigMode.UpdateBorrowFactor.discriminator,
|
|
1533
|
+
reserveConfig.borrowFactorPct.toNumber()
|
|
1534
|
+
),
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
} else if (key === 'loanToValuePct') {
|
|
1538
|
+
if (reserve === undefined) {
|
|
1539
|
+
updateReserveIxnsArgs.push({
|
|
1540
|
+
mode: UpdateConfigMode.UpdateLoanToValuePct.discriminator,
|
|
1541
|
+
value: updateReserveConfigEncodedValue(
|
|
1542
|
+
UpdateConfigMode.UpdateLoanToValuePct.discriminator,
|
|
1543
|
+
reserveConfig.loanToValuePct
|
|
1544
|
+
),
|
|
1545
|
+
});
|
|
1546
|
+
} else if (reserve.config.loanToValuePct !== reserveConfig.loanToValuePct) {
|
|
1547
|
+
updateReserveIxnsArgs.push({
|
|
1548
|
+
mode: UpdateConfigMode.UpdateLoanToValuePct.discriminator,
|
|
1549
|
+
value: updateReserveConfigEncodedValue(
|
|
1550
|
+
UpdateConfigMode.UpdateLoanToValuePct.discriminator,
|
|
1551
|
+
reserveConfig.loanToValuePct
|
|
1552
|
+
),
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
} else if (key === 'protocolLiquidationFeePct') {
|
|
1556
|
+
if (reserve === undefined) {
|
|
1557
|
+
updateReserveIxnsArgs.push({
|
|
1558
|
+
mode: UpdateConfigMode.UpdateProtocolLiquidationFee.discriminator,
|
|
1559
|
+
value: updateReserveConfigEncodedValue(
|
|
1560
|
+
UpdateConfigMode.UpdateProtocolLiquidationFee.discriminator,
|
|
1561
|
+
reserveConfig.protocolLiquidationFeePct
|
|
1562
|
+
),
|
|
1563
|
+
});
|
|
1564
|
+
} else if (reserve.config.protocolLiquidationFeePct !== reserveConfig.protocolLiquidationFeePct) {
|
|
1565
|
+
updateReserveIxnsArgs.push({
|
|
1566
|
+
mode: UpdateConfigMode.UpdateProtocolLiquidationFee.discriminator,
|
|
1567
|
+
value: updateReserveConfigEncodedValue(
|
|
1568
|
+
UpdateConfigMode.UpdateProtocolLiquidationFee.discriminator,
|
|
1569
|
+
reserveConfig.protocolLiquidationFeePct
|
|
1570
|
+
),
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
} else if (key === 'deleveragingMarginCallPeriodSecs') {
|
|
1574
|
+
if (reserve === undefined) {
|
|
1575
|
+
updateReserveIxnsArgs.push({
|
|
1576
|
+
mode: UpdateConfigMode.DeleveragingMarginCallPeriod.discriminator,
|
|
1577
|
+
value: updateReserveConfigEncodedValue(
|
|
1578
|
+
UpdateConfigMode.DeleveragingMarginCallPeriod.discriminator,
|
|
1579
|
+
reserveConfig.deleveragingMarginCallPeriodSecs.toNumber()
|
|
1580
|
+
),
|
|
1581
|
+
});
|
|
1582
|
+
} else if (!reserve.config.deleveragingMarginCallPeriodSecs.eq(reserveConfig.deleveragingMarginCallPeriodSecs)) {
|
|
1583
|
+
updateReserveIxnsArgs.push({
|
|
1584
|
+
mode: UpdateConfigMode.DeleveragingMarginCallPeriod.discriminator,
|
|
1585
|
+
value: updateReserveConfigEncodedValue(
|
|
1586
|
+
UpdateConfigMode.DeleveragingMarginCallPeriod.discriminator,
|
|
1587
|
+
reserveConfig.deleveragingMarginCallPeriodSecs.toNumber()
|
|
1588
|
+
),
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
} else if (key === 'assetTier') {
|
|
1592
|
+
if (reserve === undefined) {
|
|
1593
|
+
updateReserveIxnsArgs.push({
|
|
1594
|
+
mode: UpdateConfigMode.UpdateAssetTier.discriminator,
|
|
1595
|
+
value: updateReserveConfigEncodedValue(
|
|
1596
|
+
UpdateConfigMode.UpdateAssetTier.discriminator,
|
|
1597
|
+
reserveConfig.assetTier
|
|
1598
|
+
),
|
|
1599
|
+
});
|
|
1600
|
+
} else if (reserve.config.assetTier !== reserveConfig.assetTier) {
|
|
1601
|
+
updateReserveIxnsArgs.push({
|
|
1602
|
+
mode: UpdateConfigMode.UpdateAssetTier.discriminator,
|
|
1603
|
+
value: updateReserveConfigEncodedValue(
|
|
1604
|
+
UpdateConfigMode.UpdateAssetTier.discriminator,
|
|
1605
|
+
reserveConfig.assetTier
|
|
1606
|
+
),
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
} else if (key === 'tokenInfo') {
|
|
1610
|
+
const tokenInfo = reserveConfig.tokenInfo;
|
|
1611
|
+
if (reserve === undefined) {
|
|
1612
|
+
updateReserveIxnsArgs.push({
|
|
1613
|
+
mode: UpdateConfigMode.UpdateTokenInfoName.discriminator,
|
|
1614
|
+
value: updateReserveConfigEncodedValue(UpdateConfigMode.UpdateTokenInfoName.discriminator, tokenInfo.name),
|
|
1615
|
+
});
|
|
1616
|
+
updateReserveIxnsArgs.push({
|
|
1617
|
+
mode: UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator,
|
|
1618
|
+
value: updateReserveConfigEncodedValue(
|
|
1619
|
+
UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator,
|
|
1620
|
+
tokenInfo.heuristic.lower.toNumber()
|
|
1621
|
+
),
|
|
1622
|
+
});
|
|
1623
|
+
updateReserveIxnsArgs.push({
|
|
1624
|
+
mode: UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator,
|
|
1625
|
+
value: updateReserveConfigEncodedValue(
|
|
1626
|
+
UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator,
|
|
1627
|
+
tokenInfo.heuristic.upper.toNumber()
|
|
1628
|
+
),
|
|
1629
|
+
});
|
|
1630
|
+
updateReserveIxnsArgs.push({
|
|
1631
|
+
mode: UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator,
|
|
1632
|
+
value: updateReserveConfigEncodedValue(
|
|
1633
|
+
UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator,
|
|
1634
|
+
tokenInfo.heuristic.exp.toNumber()
|
|
1635
|
+
),
|
|
1636
|
+
});
|
|
1637
|
+
updateReserveIxnsArgs.push({
|
|
1638
|
+
mode: UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator,
|
|
1639
|
+
value: updateReserveConfigEncodedValue(
|
|
1640
|
+
UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator,
|
|
1641
|
+
tokenInfo.maxTwapDivergenceBps.toNumber()
|
|
1642
|
+
),
|
|
1643
|
+
});
|
|
1644
|
+
updateReserveIxnsArgs.push({
|
|
1645
|
+
mode: UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator,
|
|
1646
|
+
value: updateReserveConfigEncodedValue(
|
|
1647
|
+
UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator,
|
|
1648
|
+
tokenInfo.maxAgePriceSeconds.toNumber()
|
|
1649
|
+
),
|
|
1650
|
+
});
|
|
1651
|
+
updateReserveIxnsArgs.push({
|
|
1652
|
+
mode: UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator,
|
|
1653
|
+
value: updateReserveConfigEncodedValue(
|
|
1654
|
+
UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator,
|
|
1655
|
+
tokenInfo.maxAgeTwapSeconds.toNumber()
|
|
1656
|
+
),
|
|
1657
|
+
});
|
|
1658
|
+
updateReserveIxnsArgs.push({
|
|
1659
|
+
mode: UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1660
|
+
value: updateReserveConfigEncodedValue(
|
|
1661
|
+
UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1662
|
+
tokenInfo.scopeConfiguration.priceChain
|
|
1663
|
+
),
|
|
1664
|
+
});
|
|
1665
|
+
updateReserveIxnsArgs.push({
|
|
1666
|
+
mode: UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1667
|
+
value: updateReserveConfigEncodedValue(
|
|
1668
|
+
UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1669
|
+
tokenInfo.scopeConfiguration.twapChain
|
|
1670
|
+
),
|
|
1671
|
+
});
|
|
1672
|
+
updateReserveIxnsArgs.push({
|
|
1673
|
+
mode: UpdateConfigMode.UpdateSwitchboardFeed.discriminator,
|
|
1674
|
+
value: updateReserveConfigEncodedValue(
|
|
1675
|
+
UpdateConfigMode.UpdateSwitchboardFeed.discriminator,
|
|
1676
|
+
tokenInfo.switchboardConfiguration.priceAggregator
|
|
1677
|
+
),
|
|
1678
|
+
});
|
|
1679
|
+
updateReserveIxnsArgs.push({
|
|
1680
|
+
mode: UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator,
|
|
1681
|
+
value: updateReserveConfigEncodedValue(
|
|
1682
|
+
UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator,
|
|
1683
|
+
tokenInfo.switchboardConfiguration.twapAggregator
|
|
1684
|
+
),
|
|
1685
|
+
});
|
|
1686
|
+
updateReserveIxnsArgs.push({
|
|
1687
|
+
mode: UpdateConfigMode.UpdatePythPrice.discriminator,
|
|
1688
|
+
value: updateReserveConfigEncodedValue(
|
|
1689
|
+
UpdateConfigMode.UpdatePythPrice.discriminator,
|
|
1690
|
+
tokenInfo.pythConfiguration.price
|
|
1691
|
+
),
|
|
1692
|
+
});
|
|
1693
|
+
updateReserveIxnsArgs.push({
|
|
1694
|
+
mode: UpdateConfigMode.UpdateBlockPriceUsage.discriminator,
|
|
1695
|
+
value: updateReserveConfigEncodedValue(
|
|
1696
|
+
UpdateConfigMode.UpdateBlockPriceUsage.discriminator,
|
|
1697
|
+
tokenInfo.blockPriceUsage
|
|
1698
|
+
),
|
|
1699
|
+
});
|
|
1700
|
+
} else {
|
|
1701
|
+
for (let i = 0; i < tokenInfo.name.length; i++) {
|
|
1702
|
+
if (reserve.config.tokenInfo.name[i] !== tokenInfo.name[i]) {
|
|
1703
|
+
updateReserveIxnsArgs.push({
|
|
1704
|
+
mode: UpdateConfigMode.UpdateTokenInfoName.discriminator,
|
|
1705
|
+
value: updateReserveConfigEncodedValue(
|
|
1706
|
+
UpdateConfigMode.UpdateTokenInfoName.discriminator,
|
|
1707
|
+
tokenInfo.name
|
|
1708
|
+
),
|
|
1709
|
+
});
|
|
1710
|
+
break;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
if (!reserve.config.tokenInfo.heuristic.lower.eq(tokenInfo.heuristic.lower)) {
|
|
1714
|
+
updateReserveIxnsArgs.push({
|
|
1715
|
+
mode: UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator,
|
|
1716
|
+
value: updateReserveConfigEncodedValue(
|
|
1717
|
+
UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator,
|
|
1718
|
+
tokenInfo.heuristic.lower.toNumber()
|
|
1719
|
+
),
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
if (!reserve.config.tokenInfo.heuristic.upper.eq(tokenInfo.heuristic.upper)) {
|
|
1723
|
+
updateReserveIxnsArgs.push({
|
|
1724
|
+
mode: UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator,
|
|
1725
|
+
value: updateReserveConfigEncodedValue(
|
|
1726
|
+
UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator,
|
|
1727
|
+
tokenInfo.heuristic.upper.toNumber()
|
|
1728
|
+
),
|
|
1729
|
+
});
|
|
1730
|
+
}
|
|
1731
|
+
if (!reserve.config.tokenInfo.heuristic.exp.eq(tokenInfo.heuristic.exp)) {
|
|
1732
|
+
updateReserveIxnsArgs.push({
|
|
1733
|
+
mode: UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator,
|
|
1734
|
+
value: updateReserveConfigEncodedValue(
|
|
1735
|
+
UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator,
|
|
1736
|
+
tokenInfo.heuristic.exp.toNumber()
|
|
1737
|
+
),
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
if (!reserve.config.tokenInfo.maxTwapDivergenceBps.eq(tokenInfo.maxTwapDivergenceBps)) {
|
|
1741
|
+
updateReserveIxnsArgs.push({
|
|
1742
|
+
mode: UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator,
|
|
1743
|
+
value: updateReserveConfigEncodedValue(
|
|
1744
|
+
UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator,
|
|
1745
|
+
tokenInfo.maxTwapDivergenceBps.toNumber()
|
|
1746
|
+
),
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
if (!reserve.config.tokenInfo.maxAgePriceSeconds.eq(tokenInfo.maxAgePriceSeconds)) {
|
|
1750
|
+
updateReserveIxnsArgs.push({
|
|
1751
|
+
mode: UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator,
|
|
1752
|
+
value: updateReserveConfigEncodedValue(
|
|
1753
|
+
UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator,
|
|
1754
|
+
tokenInfo.maxAgePriceSeconds.toNumber()
|
|
1755
|
+
),
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
if (!reserve.config.tokenInfo.maxAgeTwapSeconds.eq(tokenInfo.maxAgeTwapSeconds)) {
|
|
1759
|
+
updateReserveIxnsArgs.push({
|
|
1760
|
+
mode: UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator,
|
|
1761
|
+
value: updateReserveConfigEncodedValue(
|
|
1762
|
+
UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator,
|
|
1763
|
+
tokenInfo.maxAgeTwapSeconds.toNumber()
|
|
1764
|
+
),
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
for (let i = 0; i < tokenInfo.scopeConfiguration.priceChain.length; i++) {
|
|
1768
|
+
if (
|
|
1769
|
+
reserve.config.tokenInfo.scopeConfiguration.priceChain[i] !== tokenInfo.scopeConfiguration.priceChain[i]
|
|
1770
|
+
) {
|
|
1771
|
+
updateReserveIxnsArgs.push({
|
|
1772
|
+
mode: UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1773
|
+
value: updateReserveConfigEncodedValue(
|
|
1774
|
+
UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1775
|
+
tokenInfo.scopeConfiguration.priceChain
|
|
1776
|
+
),
|
|
1777
|
+
});
|
|
1778
|
+
break;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
for (let i = 0; i < tokenInfo.scopeConfiguration.twapChain.length; i++) {
|
|
1782
|
+
if (reserve.config.tokenInfo.scopeConfiguration.twapChain[i] !== tokenInfo.scopeConfiguration.twapChain[i]) {
|
|
1783
|
+
updateReserveIxnsArgs.push({
|
|
1784
|
+
mode: UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1785
|
+
value: updateReserveConfigEncodedValue(
|
|
1786
|
+
UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1787
|
+
tokenInfo.scopeConfiguration.twapChain
|
|
1788
|
+
),
|
|
1789
|
+
});
|
|
1790
|
+
break;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (
|
|
1794
|
+
!reserve.config.tokenInfo.switchboardConfiguration.priceAggregator.equals(
|
|
1795
|
+
tokenInfo.switchboardConfiguration.priceAggregator
|
|
1796
|
+
)
|
|
1797
|
+
) {
|
|
1798
|
+
updateReserveIxnsArgs.push({
|
|
1799
|
+
mode: UpdateConfigMode.UpdateSwitchboardFeed.discriminator,
|
|
1800
|
+
value: updateReserveConfigEncodedValue(
|
|
1801
|
+
UpdateConfigMode.UpdateSwitchboardFeed.discriminator,
|
|
1802
|
+
tokenInfo.switchboardConfiguration.priceAggregator
|
|
1803
|
+
),
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
if (
|
|
1807
|
+
!reserve.config.tokenInfo.switchboardConfiguration.twapAggregator.equals(
|
|
1808
|
+
tokenInfo.switchboardConfiguration.twapAggregator
|
|
1809
|
+
)
|
|
1810
|
+
) {
|
|
1811
|
+
updateReserveIxnsArgs.push({
|
|
1812
|
+
mode: UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator,
|
|
1813
|
+
value: updateReserveConfigEncodedValue(
|
|
1814
|
+
UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator,
|
|
1815
|
+
tokenInfo.switchboardConfiguration.twapAggregator
|
|
1816
|
+
),
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
if (!reserve.config.tokenInfo.pythConfiguration.price.equals(tokenInfo.pythConfiguration.price)) {
|
|
1820
|
+
updateReserveIxnsArgs.push({
|
|
1821
|
+
mode: UpdateConfigMode.UpdatePythPrice.discriminator,
|
|
1822
|
+
value: updateReserveConfigEncodedValue(
|
|
1823
|
+
UpdateConfigMode.UpdatePythPrice.discriminator,
|
|
1824
|
+
tokenInfo.pythConfiguration.price
|
|
1825
|
+
),
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
if (reserve.config.tokenInfo.blockPriceUsage !== tokenInfo.blockPriceUsage) {
|
|
1829
|
+
updateReserveIxnsArgs.push({
|
|
1830
|
+
mode: UpdateConfigMode.UpdateBlockPriceUsage.discriminator,
|
|
1831
|
+
value: updateReserveConfigEncodedValue(
|
|
1832
|
+
UpdateConfigMode.UpdateBlockPriceUsage.discriminator,
|
|
1833
|
+
tokenInfo.blockPriceUsage
|
|
1834
|
+
),
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
if (!reserve.config.tokenInfo.scopeConfiguration.priceFeed.equals(tokenInfo.scopeConfiguration.priceFeed)) {
|
|
1838
|
+
updateReserveIxnsArgs.push({
|
|
1839
|
+
mode: UpdateConfigMode.UpdateScopePriceFeed.discriminator,
|
|
1840
|
+
value: updateReserveConfigEncodedValue(
|
|
1841
|
+
UpdateConfigMode.UpdateScopePriceFeed.discriminator,
|
|
1842
|
+
tokenInfo.scopeConfiguration.priceFeed
|
|
1843
|
+
),
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
} // for loop
|
|
1849
|
+
|
|
1850
|
+
const ixns: TransactionInstruction[] = [];
|
|
1851
|
+
|
|
1852
|
+
updateReserveIxnsArgs.forEach((updateReserveConfigArgs) => {
|
|
1853
|
+
ixns.push(
|
|
1854
|
+
updateReserveConfigIx(
|
|
1855
|
+
marketWithAddress,
|
|
1856
|
+
reserveAddress,
|
|
1857
|
+
updateReserveConfigArgs.mode + 1,
|
|
1858
|
+
updateReserveConfigArgs.value,
|
|
1859
|
+
programId
|
|
1860
|
+
)
|
|
1861
|
+
);
|
|
1862
|
+
});
|
|
1863
|
+
|
|
1864
|
+
return ixns;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
export function updateReserveConfigEncodedValue(
|
|
1868
|
+
discriminator: number,
|
|
1869
|
+
value: number | number[] | BorrowRateCurve | PublicKey
|
|
1870
|
+
): Uint8Array {
|
|
1871
|
+
let buffer: Buffer;
|
|
1872
|
+
let valueArray: number[] = [];
|
|
1873
|
+
|
|
1874
|
+
switch (discriminator) {
|
|
1875
|
+
case UpdateConfigMode.UpdateLoanToValuePct.discriminator:
|
|
1876
|
+
case UpdateConfigMode.UpdateLiquidationThresholdPct.discriminator:
|
|
1877
|
+
case UpdateConfigMode.UpdateProtocolLiquidationFee.discriminator:
|
|
1878
|
+
case UpdateConfigMode.UpdateProtocolTakeRate.discriminator:
|
|
1879
|
+
case UpdateConfigMode.UpdateAssetTier.discriminator:
|
|
1880
|
+
case UpdateConfigMode.UpdateReserveStatus.discriminator:
|
|
1881
|
+
case UpdateConfigMode.UpdateDisableUsageAsCollateralOutsideEmode.discriminator:
|
|
1882
|
+
case UpdateConfigMode.UpdateBlockBorrowingAboveUtilization.discriminator:
|
|
1883
|
+
case UpdateConfigMode.UpdateBlockPriceUsage.discriminator:
|
|
1884
|
+
buffer = Buffer.alloc(1);
|
|
1885
|
+
buffer.writeUIntLE(value as number, 0, 1);
|
|
1886
|
+
break;
|
|
1887
|
+
case UpdateConfigMode.UpdateMaxLiquidationBonusBps.discriminator:
|
|
1888
|
+
case UpdateConfigMode.UpdateBadDebtLiquidationBonusBps.discriminator:
|
|
1889
|
+
case UpdateConfigMode.UpdateMinLiquidationBonusBps.discriminator:
|
|
1890
|
+
buffer = Buffer.alloc(2);
|
|
1891
|
+
buffer.writeUInt16LE(value as number, 0);
|
|
1892
|
+
break;
|
|
1893
|
+
case UpdateConfigMode.UpdateFeesBorrowFee.discriminator:
|
|
1894
|
+
case UpdateConfigMode.UpdateFeesFlashLoanFee.discriminator:
|
|
1895
|
+
case UpdateConfigMode.UpdateDepositLimit.discriminator:
|
|
1896
|
+
case UpdateConfigMode.UpdateBorrowLimit.discriminator:
|
|
1897
|
+
case UpdateConfigMode.UpdateTokenInfoLowerHeuristic.discriminator:
|
|
1898
|
+
case UpdateConfigMode.UpdateTokenInfoUpperHeuristic.discriminator:
|
|
1899
|
+
case UpdateConfigMode.UpdateTokenInfoExpHeuristic.discriminator:
|
|
1900
|
+
case UpdateConfigMode.UpdateTokenInfoTwapDivergence.discriminator:
|
|
1901
|
+
case UpdateConfigMode.UpdateTokenInfoPriceMaxAge.discriminator:
|
|
1902
|
+
case UpdateConfigMode.UpdateTokenInfoTwapMaxAge.discriminator:
|
|
1903
|
+
case UpdateConfigMode.UpdateDebtWithdrawalCapCurrentTotal.discriminator:
|
|
1904
|
+
case UpdateConfigMode.UpdateDepositWithdrawalCapCurrentTotal.discriminator:
|
|
1905
|
+
case UpdateConfigMode.DeleveragingMarginCallPeriod.discriminator:
|
|
1906
|
+
case UpdateConfigMode.UpdateBorrowFactor.discriminator:
|
|
1907
|
+
case UpdateConfigMode.DeleveragingThresholdSlotsPerBps.discriminator:
|
|
1908
|
+
case UpdateConfigMode.UpdateBorrowLimitOutsideElevationGroup.discriminator:
|
|
1909
|
+
value = value as number;
|
|
1910
|
+
buffer = Buffer.alloc(8);
|
|
1911
|
+
buffer.writeBigUint64LE(BigInt(value), 0);
|
|
1912
|
+
break;
|
|
1913
|
+
case UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator:
|
|
1914
|
+
case UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator:
|
|
1915
|
+
valueArray = value as number[];
|
|
1916
|
+
buffer = Buffer.alloc(8);
|
|
1917
|
+
for (let i = 0; i < valueArray.length; i++) {
|
|
1918
|
+
buffer.writeUInt16LE(valueArray[i], 2 * i);
|
|
1919
|
+
}
|
|
1920
|
+
break;
|
|
1921
|
+
case UpdateConfigMode.UpdateTokenInfoName.discriminator:
|
|
1922
|
+
valueArray = value as number[];
|
|
1923
|
+
buffer = Buffer.alloc(32);
|
|
1924
|
+
for (let i = 0; i < valueArray.length; i++) {
|
|
1925
|
+
buffer.writeUIntLE(valueArray[i], i, 1);
|
|
1926
|
+
}
|
|
1927
|
+
break;
|
|
1928
|
+
case UpdateConfigMode.UpdateScopePriceFeed.discriminator:
|
|
1929
|
+
case UpdateConfigMode.UpdatePythPrice.discriminator:
|
|
1930
|
+
case UpdateConfigMode.UpdateSwitchboardFeed.discriminator:
|
|
1931
|
+
case UpdateConfigMode.UpdateSwitchboardTwapFeed.discriminator:
|
|
1932
|
+
case UpdateConfigMode.UpdateFarmCollateral.discriminator:
|
|
1933
|
+
case UpdateConfigMode.UpdateFarmDebt.discriminator:
|
|
1934
|
+
buffer = (value as PublicKey).toBuffer();
|
|
1935
|
+
break;
|
|
1936
|
+
case UpdateConfigMode.UpdateBorrowRateCurve.discriminator:
|
|
1937
|
+
buffer = serializeBorrowRateCurve(value as BorrowRateCurve);
|
|
1938
|
+
break;
|
|
1939
|
+
case UpdateConfigMode.UpdateDebtWithdrawalCap.discriminator:
|
|
1940
|
+
case UpdateConfigMode.UpdateDepositWithdrawalCap.discriminator:
|
|
1941
|
+
valueArray = value as number[];
|
|
1942
|
+
buffer = Buffer.alloc(16);
|
|
1943
|
+
buffer.writeBigUint64LE(BigInt(valueArray[0]), 0);
|
|
1944
|
+
buffer.writeBigUInt64LE(BigInt(valueArray[1]), 8);
|
|
1945
|
+
break;
|
|
1946
|
+
case UpdateConfigMode.UpdateElevationGroup.discriminator:
|
|
1947
|
+
valueArray = value as number[];
|
|
1948
|
+
buffer = Buffer.alloc(20);
|
|
1949
|
+
for (let i = 0; i < valueArray.length; i++) {
|
|
1950
|
+
buffer.writeUIntLE(valueArray[i], i, 1);
|
|
1951
|
+
}
|
|
1952
|
+
break;
|
|
1953
|
+
case UpdateConfigMode.UpdateBorrowLimitsInElevationGroupAgainstThisReserve.discriminator:
|
|
1954
|
+
valueArray = value as number[];
|
|
1955
|
+
buffer = Buffer.alloc(32 * 8);
|
|
1956
|
+
for (let i = 0; i < valueArray.length; i++) {
|
|
1957
|
+
buffer.writeBigUint64LE(BigInt(valueArray[i]), i * 8);
|
|
1958
|
+
}
|
|
1959
|
+
break;
|
|
1960
|
+
default:
|
|
1961
|
+
buffer = Buffer.alloc(0);
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
return Uint8Array.from([...buffer]);
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
export function serializeBorrowRateCurve(curve: BorrowRateCurve): Buffer {
|
|
1968
|
+
const buffer = Buffer.alloc(4 + 8 * curve.points.length);
|
|
1969
|
+
buffer.writeUInt32LE(curve.points.length, 0);
|
|
1970
|
+
for (let i = 0; i < curve.points.length; i++) {
|
|
1971
|
+
buffer.writeUInt32LE(curve.points[i].utilizationRateBps, 4 + 8 * i);
|
|
1972
|
+
buffer.writeUInt32LE(curve.points[i].borrowRateBps, 8 + 8 * i);
|
|
1973
|
+
}
|
|
1974
|
+
return buffer;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
export type ReserveWithAddress = {
|
|
1978
|
+
address: PublicKey;
|
|
1979
|
+
state: Reserve;
|
|
1980
|
+
};
|