@kamino-finance/klend-sdk 2.10.6
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/README.md +85 -0
- package/dist/classes/action.d.ts +154 -0
- package/dist/classes/action.js +1505 -0
- package/dist/classes/action.js.map +1 -0
- package/dist/classes/curve.d.ts +15 -0
- package/dist/classes/curve.js +32 -0
- package/dist/classes/curve.js.map +1 -0
- package/dist/classes/fraction.d.ts +23 -0
- package/dist/classes/fraction.js +60 -0
- package/dist/classes/fraction.js.map +1 -0
- package/dist/classes/index.d.ts +8 -0
- package/dist/classes/index.js +25 -0
- package/dist/classes/index.js.map +1 -0
- package/dist/classes/jupiterPerps.d.ts +2 -0
- package/dist/classes/jupiterPerps.js +25 -0
- package/dist/classes/jupiterPerps.js.map +1 -0
- package/dist/classes/market.d.ts +140 -0
- package/dist/classes/market.js +901 -0
- package/dist/classes/market.js.map +1 -0
- package/dist/classes/obligation.d.ts +170 -0
- package/dist/classes/obligation.js +610 -0
- package/dist/classes/obligation.js.map +1 -0
- package/dist/classes/reserve.d.ts +161 -0
- package/dist/classes/reserve.js +474 -0
- package/dist/classes/reserve.js.map +1 -0
- package/dist/classes/shared.d.ts +41 -0
- package/dist/classes/shared.js +10 -0
- package/dist/classes/shared.js.map +1 -0
- package/dist/classes/utils.d.ts +40 -0
- package/dist/classes/utils.js +129 -0
- package/dist/classes/utils.js.map +1 -0
- package/dist/idl.json +4102 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +153 -0
- package/dist/idl_codegen/accounts/LendingMarket.js +204 -0
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts +139 -0
- package/dist/idl_codegen/accounts/Obligation.js +193 -0
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerState.d.ts +22 -0
- package/dist/idl_codegen/accounts/ReferrerState.js +101 -0
- package/dist/idl_codegen/accounts/ReferrerState.js.map +1 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.d.ts +51 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.js +126 -0
- package/dist/idl_codegen/accounts/ReferrerTokenState.js.map +1 -0
- package/dist/idl_codegen/accounts/Reserve.d.ts +72 -0
- package/dist/idl_codegen/accounts/Reserve.js +156 -0
- package/dist/idl_codegen/accounts/Reserve.js.map +1 -0
- package/dist/idl_codegen/accounts/ShortUrl.d.ts +22 -0
- package/dist/idl_codegen/accounts/ShortUrl.js +101 -0
- package/dist/idl_codegen/accounts/ShortUrl.js.map +1 -0
- package/dist/idl_codegen/accounts/UserMetadata.d.ts +48 -0
- package/dist/idl_codegen/accounts/UserMetadata.js +126 -0
- package/dist/idl_codegen/accounts/UserMetadata.js.map +1 -0
- package/dist/idl_codegen/accounts/UserState.d.ts +143 -0
- package/dist/idl_codegen/accounts/UserState.js +180 -0
- package/dist/idl_codegen/accounts/UserState.js.map +1 -0
- package/dist/idl_codegen/accounts/index.d.ts +16 -0
- package/dist/idl_codegen/accounts/index.js +20 -0
- package/dist/idl_codegen/accounts/index.js.map +1 -0
- package/dist/idl_codegen/errors/anchor.d.ts +434 -0
- package/dist/idl_codegen/errors/anchor.js +713 -0
- package/dist/idl_codegen/errors/anchor.js.map +1 -0
- package/dist/idl_codegen/errors/custom.d.ts +730 -0
- package/dist/idl_codegen/errors/custom.js +1194 -0
- package/dist/idl_codegen/errors/custom.js.map +1 -0
- package/dist/idl_codegen/errors/index.d.ts +5 -0
- package/dist/idl_codegen/errors/index.js +71 -0
- package/dist/idl_codegen/errors/index.js.map +1 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.d.ts +20 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +75 -0
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.d.ts +9 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js +20 -0
- package/dist/idl_codegen/instructions/deleteReferrerStateAndShortUrl.js.map +1 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.d.ts +17 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.js +64 -0
- package/dist/idl_codegen/instructions/depositObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.d.ts +19 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +74 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.d.ts +21 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +80 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.d.ts +20 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js +75 -0
- package/dist/idl_codegen/instructions/flashBorrowReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.d.ts +21 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js +75 -0
- package/dist/idl_codegen/instructions/flashRepayReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +18 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.js +62 -0
- package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -0
- package/dist/idl_codegen/instructions/index.d.ts +66 -0
- package/dist/idl_codegen/instructions/index.js +70 -0
- package/dist/idl_codegen/instructions/index.js.map +1 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.d.ts +19 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +63 -0
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/initLendingMarket.d.ts +13 -0
- package/dist/idl_codegen/instructions/initLendingMarket.js +55 -0
- package/dist/idl_codegen/instructions/initLendingMarket.js.map +1 -0
- package/dist/idl_codegen/instructions/initObligation.d.ts +19 -0
- package/dist/idl_codegen/instructions/initObligation.js +55 -0
- package/dist/idl_codegen/instructions/initObligation.js.map +1 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.d.ts +20 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +60 -0
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.d.ts +14 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js +54 -0
- package/dist/idl_codegen/instructions/initReferrerStateAndShortUrl.js.map +1 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +14 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.js +50 -0
- package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts +16 -0
- package/dist/idl_codegen/instructions/initReserve.js +47 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/initUserMetadata.d.ts +14 -0
- package/dist/idl_codegen/instructions/initUserMetadata.js +54 -0
- package/dist/idl_codegen/instructions/initUserMetadata.js.map +1 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.d.ts +27 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +102 -0
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/redeemFees.d.ts +10 -0
- package/dist/idl_codegen/instructions/redeemFees.js +33 -0
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.d.ts +19 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +78 -0
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligation.d.ts +6 -0
- package/dist/idl_codegen/instructions/refreshObligation.js +17 -0
- package/dist/idl_codegen/instructions/refreshObligation.js.map +1 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.d.ts +19 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +63 -0
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/refreshReserve.d.ts +10 -0
- package/dist/idl_codegen/instructions/refreshReserve.js +29 -0
- package/dist/idl_codegen/instructions/refreshReserve.js.map +1 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.d.ts +17 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +60 -0
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.d.ts +11 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.js +47 -0
- package/dist/idl_codegen/instructions/requestElevationGroup.js.map +1 -0
- package/dist/idl_codegen/instructions/socializeLoss.d.ts +14 -0
- package/dist/idl_codegen/instructions/socializeLoss.js +53 -0
- package/dist/idl_codegen/instructions/socializeLoss.js.map +1 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.d.ts +13 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.js +51 -0
- package/dist/idl_codegen/instructions/updateEntireReserveConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.d.ts +12 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.js +50 -0
- package/dist/idl_codegen/instructions/updateLendingMarket.js.map +1 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.d.ts +6 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.js +21 -0
- package/dist/idl_codegen/instructions/updateLendingMarketOwner.js.map +1 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +13 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.js +51 -0
- package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.d.ts +13 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.js +51 -0
- package/dist/idl_codegen/instructions/updateSingleReserveConfig.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.d.ts +18 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js +69 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.d.ts +21 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +84 -0
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +16 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +59 -0
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.d.ts +12 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +35 -0
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -0
- package/dist/idl_codegen/programId.d.ts +4 -0
- package/dist/idl_codegen/programId.js +13 -0
- package/dist/idl_codegen/programId.js.map +1 -0
- package/dist/idl_codegen/types/AssetTier.d.ts +44 -0
- package/dist/idl_codegen/types/AssetTier.js +128 -0
- package/dist/idl_codegen/types/AssetTier.js.map +1 -0
- package/dist/idl_codegen/types/BigFractionBytes.d.ts +27 -0
- package/dist/idl_codegen/types/BigFractionBytes.js +73 -0
- package/dist/idl_codegen/types/BigFractionBytes.js.map +1 -0
- package/dist/idl_codegen/types/BorrowRateCurve.d.ts +27 -0
- package/dist/idl_codegen/types/BorrowRateCurve.js +62 -0
- package/dist/idl_codegen/types/BorrowRateCurve.js.map +1 -0
- package/dist/idl_codegen/types/CurvePoint.d.ts +26 -0
- package/dist/idl_codegen/types/CurvePoint.js +66 -0
- package/dist/idl_codegen/types/CurvePoint.js.map +1 -0
- package/dist/idl_codegen/types/ElevationGroup.d.ts +52 -0
- package/dist/idl_codegen/types/ElevationGroup.js +103 -0
- package/dist/idl_codegen/types/ElevationGroup.js.map +1 -0
- package/dist/idl_codegen/types/FeeCalculation.d.ts +31 -0
- package/dist/idl_codegen/types/FeeCalculation.js +102 -0
- package/dist/idl_codegen/types/FeeCalculation.js.map +1 -0
- package/dist/idl_codegen/types/InitObligationArgs.d.ts +26 -0
- package/dist/idl_codegen/types/InitObligationArgs.js +66 -0
- package/dist/idl_codegen/types/InitObligationArgs.js.map +1 -0
- package/dist/idl_codegen/types/LastUpdate.d.ts +47 -0
- package/dist/idl_codegen/types/LastUpdate.js +86 -0
- package/dist/idl_codegen/types/LastUpdate.js.map +1 -0
- package/dist/idl_codegen/types/ObligationCollateral.d.ts +48 -0
- package/dist/idl_codegen/types/ObligationCollateral.js +87 -0
- package/dist/idl_codegen/types/ObligationCollateral.js.map +1 -0
- package/dist/idl_codegen/types/ObligationLiquidity.d.ts +75 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js +107 -0
- package/dist/idl_codegen/types/ObligationLiquidity.js.map +1 -0
- package/dist/idl_codegen/types/PriceHeuristic.d.ts +41 -0
- package/dist/idl_codegen/types/PriceHeuristic.js +75 -0
- package/dist/idl_codegen/types/PriceHeuristic.js.map +1 -0
- package/dist/idl_codegen/types/PythConfiguration.d.ts +25 -0
- package/dist/idl_codegen/types/PythConfiguration.js +62 -0
- package/dist/idl_codegen/types/PythConfiguration.js.map +1 -0
- package/dist/idl_codegen/types/ReserveCollateral.d.ts +53 -0
- package/dist/idl_codegen/types/ReserveCollateral.js +93 -0
- package/dist/idl_codegen/types/ReserveCollateral.js.map +1 -0
- package/dist/idl_codegen/types/ReserveConfig.d.ts +304 -0
- package/dist/idl_codegen/types/ReserveConfig.js +209 -0
- package/dist/idl_codegen/types/ReserveConfig.js.map +1 -0
- package/dist/idl_codegen/types/ReserveFarmKind.d.ts +31 -0
- package/dist/idl_codegen/types/ReserveFarmKind.js +102 -0
- package/dist/idl_codegen/types/ReserveFarmKind.js.map +1 -0
- package/dist/idl_codegen/types/ReserveFees.d.ts +78 -0
- package/dist/idl_codegen/types/ReserveFees.js +86 -0
- package/dist/idl_codegen/types/ReserveFees.js.map +1 -0
- package/dist/idl_codegen/types/ReserveLiquidity.d.ts +173 -0
- package/dist/idl_codegen/types/ReserveLiquidity.js +166 -0
- package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen/types/ReserveStatus.d.ts +44 -0
- package/dist/idl_codegen/types/ReserveStatus.js +128 -0
- package/dist/idl_codegen/types/ReserveStatus.js.map +1 -0
- package/dist/idl_codegen/types/ScopeConfiguration.d.ts +41 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js +76 -0
- package/dist/idl_codegen/types/ScopeConfiguration.js.map +1 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.d.ts +30 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js +67 -0
- package/dist/idl_codegen/types/SwitchboardConfiguration.js.map +1 -0
- package/dist/idl_codegen/types/TokenInfo.d.ts +109 -0
- package/dist/idl_codegen/types/TokenInfo.js +116 -0
- package/dist/idl_codegen/types/TokenInfo.js.map +1 -0
- package/dist/idl_codegen/types/UpdateConfigMode.d.ts +538 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js +1116 -0
- package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +155 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +273 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js.map +1 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +200 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +440 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -0
- package/dist/idl_codegen/types/WithdrawalCaps.d.ts +38 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js +86 -0
- package/dist/idl_codegen/types/WithdrawalCaps.js.map +1 -0
- package/dist/idl_codegen/types/index.d.ts +65 -0
- package/dist/idl_codegen/types/index.js +77 -0
- package/dist/idl_codegen/types/index.js.map +1 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +53 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.js +140 -0
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -0
- package/dist/idl_codegen/zero_padding/index.d.ts +1 -0
- package/dist/idl_codegen/zero_padding/index.js +6 -0
- package/dist/idl_codegen/zero_padding/index.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.d.ts +48 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js +144 -0
- package/dist/idl_codegen_jupiter_perps/accounts/Pool.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.d.ts +2 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.js +6 -0
- package/dist/idl_codegen_jupiter_perps/accounts/index.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/programId.d.ts +3 -0
- package/dist/idl_codegen_jupiter_perps/programId.js +9 -0
- package/dist/idl_codegen_jupiter_perps/programId.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.d.ts +62 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js +115 -0
- package/dist/idl_codegen_jupiter_perps/types/Fees.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.d.ts +32 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js +75 -0
- package/dist/idl_codegen_jupiter_perps/types/Limit.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.d.ts +32 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js +75 -0
- package/dist/idl_codegen_jupiter_perps/types/PoolApr.js.map +1 -0
- package/dist/idl_codegen_jupiter_perps/types/index.d.ts +6 -0
- package/dist/idl_codegen_jupiter_perps/types/index.js +10 -0
- package/dist/idl_codegen_jupiter_perps/types/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/lending_operations/index.d.ts +2 -0
- package/dist/lending_operations/index.js +19 -0
- package/dist/lending_operations/index.js.map +1 -0
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +5 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js +26 -0
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -0
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +47 -0
- package/dist/lending_operations/repay_with_collateral_operations.js +163 -0
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -0
- package/dist/leverage/calcs.d.ts +132 -0
- package/dist/leverage/calcs.js +291 -0
- package/dist/leverage/calcs.js.map +1 -0
- package/dist/leverage/index.d.ts +4 -0
- package/dist/leverage/index.js +21 -0
- package/dist/leverage/index.js.map +1 -0
- package/dist/leverage/instructions.d.ts +43 -0
- package/dist/leverage/instructions.js +103 -0
- package/dist/leverage/instructions.js.map +1 -0
- package/dist/leverage/operations.d.ts +231 -0
- package/dist/leverage/operations.js +1058 -0
- package/dist/leverage/operations.js.map +1 -0
- package/dist/leverage/utils.d.ts +22 -0
- package/dist/leverage/utils.js +144 -0
- package/dist/leverage/utils.js.map +1 -0
- package/dist/lib.d.ts +9 -0
- package/dist/lib.js +26 -0
- package/dist/lib.js.map +1 -0
- package/dist/referrals/index.d.ts +2 -0
- package/dist/referrals/index.js +19 -0
- package/dist/referrals/index.js.map +1 -0
- package/dist/referrals/instructions.d.ts +16 -0
- package/dist/referrals/instructions.js +76 -0
- package/dist/referrals/instructions.js.map +1 -0
- package/dist/referrals/operations.d.ts +97 -0
- package/dist/referrals/operations.js +258 -0
- package/dist/referrals/operations.js.map +1 -0
- package/dist/utils/ObligationType.d.ts +49 -0
- package/dist/utils/ObligationType.js +129 -0
- package/dist/utils/ObligationType.js.map +1 -0
- package/dist/utils/api.d.ts +6 -0
- package/dist/utils/api.js +61 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/ata.d.ts +25 -0
- package/dist/utils/ata.js +155 -0
- package/dist/utils/ata.js.map +1 -0
- package/dist/utils/constants.d.ts +48 -0
- package/dist/utils/constants.js +75 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/idl.d.ts +2 -0
- package/dist/utils/idl.js +9 -0
- package/dist/utils/idl.js.map +1 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/instruction.d.ts +22 -0
- package/dist/utils/instruction.js +202 -0
- package/dist/utils/instruction.js.map +1 -0
- package/dist/utils/kamino.d.ts +3 -0
- package/dist/utils/kamino.js +45 -0
- package/dist/utils/kamino.js.map +1 -0
- package/dist/utils/layout.d.ts +13 -0
- package/dist/utils/layout.js +123 -0
- package/dist/utils/layout.js.map +1 -0
- package/dist/utils/lookupTable.d.ts +5 -0
- package/dist/utils/lookupTable.js +57 -0
- package/dist/utils/lookupTable.js.map +1 -0
- package/dist/utils/oracle.d.ts +51 -0
- package/dist/utils/oracle.js +295 -0
- package/dist/utils/oracle.js.map +1 -0
- package/dist/utils/pubkey.d.ts +74 -0
- package/dist/utils/pubkey.js +229 -0
- package/dist/utils/pubkey.js.map +1 -0
- package/dist/utils/seeds.d.ts +122 -0
- package/dist/utils/seeds.js +153 -0
- package/dist/utils/seeds.js.map +1 -0
- package/dist/utils/slots.d.ts +18 -0
- package/dist/utils/slots.js +32 -0
- package/dist/utils/slots.js.map +1 -0
- package/dist/utils/syncNative.d.ts +10 -0
- package/dist/utils/syncNative.js +46 -0
- package/dist/utils/syncNative.js.map +1 -0
- package/dist/utils/userMetadata.d.ts +15 -0
- package/dist/utils/userMetadata.js +259 -0
- package/dist/utils/userMetadata.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.notEmpty = exports.getComputeBudgetAndPriorityFeeIxns = exports.getLookupTableAccounts = exports.getLookupTableAccount = exports.buildVersionedTransaction = exports.simulateTransactionV0 = exports.sendTransactionV0 = exports.buildComputeBudgetIx = exports.simulateTxn = exports.sendAndConfirmVersionedTransaction = exports.buildAndSendTxnWithLogs = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const errors_1 = require("../idl_codegen/errors");
|
|
15
|
+
const utils_1 = require("../classes/utils");
|
|
16
|
+
function buildAndSendTxnWithLogs(c, tx, owner, signers, withLogsIfSuccess = false, withDescription = '') {
|
|
17
|
+
var _a;
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
tx.sign([owner, ...signers]);
|
|
20
|
+
try {
|
|
21
|
+
const sig = yield sendAndConfirmVersionedTransaction(c, tx, 'confirmed', {
|
|
22
|
+
preflightCommitment: 'processed',
|
|
23
|
+
});
|
|
24
|
+
console.log('Transaction Hash:', withDescription, sig);
|
|
25
|
+
if (withLogsIfSuccess) {
|
|
26
|
+
yield (0, utils_1.sleep)(5000);
|
|
27
|
+
const res = yield c.getTransaction(sig, {
|
|
28
|
+
commitment: 'confirmed',
|
|
29
|
+
maxSupportedTransactionVersion: 6,
|
|
30
|
+
});
|
|
31
|
+
console.log('Transaction Logs:\n', (_a = res === null || res === void 0 ? void 0 : res.meta) === null || _a === void 0 ? void 0 : _a.logMessages);
|
|
32
|
+
}
|
|
33
|
+
return sig;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.log(e);
|
|
37
|
+
process.stdout.write(e.logs.toString());
|
|
38
|
+
yield (0, utils_1.sleep)(5000);
|
|
39
|
+
const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];
|
|
40
|
+
const res = yield c.getTransaction(sig, {
|
|
41
|
+
commitment: 'confirmed',
|
|
42
|
+
maxSupportedTransactionVersion: 6,
|
|
43
|
+
});
|
|
44
|
+
console.log('Txn', res.meta.logMessages);
|
|
45
|
+
return sig;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.buildAndSendTxnWithLogs = buildAndSendTxnWithLogs;
|
|
50
|
+
function sendAndConfirmVersionedTransaction(c, tx, commitment = 'confirmed', sendTransactionOptions = { preflightCommitment: 'processed' }) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const defaultOptions = { skipPreflight: true };
|
|
54
|
+
const txId = yield c.sendTransaction(tx, Object.assign(Object.assign({}, defaultOptions), sendTransactionOptions));
|
|
55
|
+
console.log('Sending versioned txn', txId.toString());
|
|
56
|
+
const latestBlockHash = yield c.getLatestBlockhash('finalized');
|
|
57
|
+
const t = yield c.confirmTransaction({
|
|
58
|
+
blockhash: latestBlockHash.blockhash,
|
|
59
|
+
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
|
|
60
|
+
signature: txId,
|
|
61
|
+
}, commitment);
|
|
62
|
+
if (t.value && t.value.err) {
|
|
63
|
+
const txDetails = yield c.getTransaction(txId, {
|
|
64
|
+
maxSupportedTransactionVersion: 0,
|
|
65
|
+
commitment: 'confirmed',
|
|
66
|
+
});
|
|
67
|
+
if (txDetails) {
|
|
68
|
+
throw { err: (_a = txDetails.meta) === null || _a === void 0 ? void 0 : _a.err, logs: ((_b = txDetails.meta) === null || _b === void 0 ? void 0 : _b.logMessages) || [] };
|
|
69
|
+
}
|
|
70
|
+
throw t.value.err;
|
|
71
|
+
}
|
|
72
|
+
return txId;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.sendAndConfirmVersionedTransaction = sendAndConfirmVersionedTransaction;
|
|
76
|
+
function simulateTxn(c, tx, owner, signers) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const { blockhash } = yield c.getLatestBlockhash();
|
|
79
|
+
tx.recentBlockhash = blockhash;
|
|
80
|
+
tx.feePayer = owner.publicKey;
|
|
81
|
+
try {
|
|
82
|
+
const simulation = yield c.simulateTransaction(tx, [owner, ...signers]);
|
|
83
|
+
console.log('Transaction Hash:', simulation);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
console.log(e);
|
|
87
|
+
process.stdout.write(e.logs.toString());
|
|
88
|
+
yield (0, utils_1.sleep)(5000);
|
|
89
|
+
const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];
|
|
90
|
+
const res = yield c.getTransaction(sig, {
|
|
91
|
+
commitment: 'confirmed',
|
|
92
|
+
});
|
|
93
|
+
console.log('Txn', res.meta.logMessages);
|
|
94
|
+
return sig;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.simulateTxn = simulateTxn;
|
|
99
|
+
function buildComputeBudgetIx(units) {
|
|
100
|
+
return web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units });
|
|
101
|
+
}
|
|
102
|
+
exports.buildComputeBudgetIx = buildComputeBudgetIx;
|
|
103
|
+
/**
|
|
104
|
+
* Send a transaction with optional address lookup tables
|
|
105
|
+
* Translates anchor errors into anchor error types
|
|
106
|
+
* @param connection
|
|
107
|
+
* @param payer
|
|
108
|
+
* @param instructions
|
|
109
|
+
* @param lookupTables
|
|
110
|
+
*/
|
|
111
|
+
function sendTransactionV0(connection, payer, instructions, lookupTables = undefined, options) {
|
|
112
|
+
var _a;
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const recentBlockhash = (yield connection.getLatestBlockhash()).blockhash;
|
|
115
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
116
|
+
payerKey: payer.publicKey,
|
|
117
|
+
recentBlockhash,
|
|
118
|
+
instructions,
|
|
119
|
+
}).compileToV0Message(lookupTables);
|
|
120
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
121
|
+
tx.sign([payer]);
|
|
122
|
+
try {
|
|
123
|
+
return yield connection.sendTransaction(tx, options);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
throw (_a = (0, errors_1.fromTxError)(err)) !== null && _a !== void 0 ? _a : err;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
exports.sendTransactionV0 = sendTransactionV0;
|
|
131
|
+
function simulateTransactionV0(connection, payer, instructions, lookupTables = undefined) {
|
|
132
|
+
var _a;
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const recentBlockhash = (yield connection.getLatestBlockhash()).blockhash;
|
|
135
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
136
|
+
payerKey: payer.publicKey,
|
|
137
|
+
recentBlockhash,
|
|
138
|
+
instructions,
|
|
139
|
+
}).compileToV0Message(lookupTables);
|
|
140
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
141
|
+
tx.sign([payer]);
|
|
142
|
+
try {
|
|
143
|
+
return yield connection.simulateTransaction(tx);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
throw (_a = (0, errors_1.fromTxError)(err)) !== null && _a !== void 0 ? _a : err;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
exports.simulateTransactionV0 = simulateTransactionV0;
|
|
151
|
+
const buildVersionedTransaction = (connection, payer, instructions, lookupTables = []) => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
+
const blockhash = yield connection.getLatestBlockhash('confirmed').then((res) => res.blockhash);
|
|
153
|
+
const lookupTablesAccounts = yield Promise.all(lookupTables.map((address) => {
|
|
154
|
+
return (0, exports.getLookupTableAccount)(connection, address);
|
|
155
|
+
}));
|
|
156
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
157
|
+
payerKey: payer,
|
|
158
|
+
recentBlockhash: blockhash,
|
|
159
|
+
instructions,
|
|
160
|
+
}).compileToV0Message(lookupTablesAccounts.filter(notEmpty));
|
|
161
|
+
return new web3_js_1.VersionedTransaction(messageV0);
|
|
162
|
+
});
|
|
163
|
+
exports.buildVersionedTransaction = buildVersionedTransaction;
|
|
164
|
+
const getLookupTableAccount = (connection, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
return connection.getAddressLookupTable(address).then((res) => res.value);
|
|
166
|
+
});
|
|
167
|
+
exports.getLookupTableAccount = getLookupTableAccount;
|
|
168
|
+
const getLookupTableAccounts = (connection, addresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
const lookupTableAccounts = [];
|
|
170
|
+
for (const address of addresses) {
|
|
171
|
+
const lookupTableAccount = yield connection.getAddressLookupTable(address).then((res) => res.value);
|
|
172
|
+
if (!lookupTableAccount) {
|
|
173
|
+
console.error('lookup table is not found');
|
|
174
|
+
throw new Error('lookup table is not found');
|
|
175
|
+
}
|
|
176
|
+
lookupTableAccounts.push(lookupTableAccount);
|
|
177
|
+
}
|
|
178
|
+
return lookupTableAccounts;
|
|
179
|
+
});
|
|
180
|
+
exports.getLookupTableAccounts = getLookupTableAccounts;
|
|
181
|
+
const getComputeBudgetAndPriorityFeeIxns = (units, priorityFeeLamports) => {
|
|
182
|
+
const ixns = [];
|
|
183
|
+
ixns.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units }));
|
|
184
|
+
if (priorityFeeLamports && priorityFeeLamports.gt(0)) {
|
|
185
|
+
const unitPrice = priorityFeeLamports.mul(Math.pow(10, 6)).div(units);
|
|
186
|
+
ixns.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: BigInt(unitPrice.floor().toString()) }));
|
|
187
|
+
}
|
|
188
|
+
return ixns;
|
|
189
|
+
};
|
|
190
|
+
exports.getComputeBudgetAndPriorityFeeIxns = getComputeBudgetAndPriorityFeeIxns;
|
|
191
|
+
// filters null values from array and make typescript happy
|
|
192
|
+
function notEmpty(value) {
|
|
193
|
+
if (value === null || value === undefined) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
//
|
|
197
|
+
// eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars
|
|
198
|
+
const testDummy = value;
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
exports.notEmpty = notEmpty;
|
|
202
|
+
//# sourceMappingURL=instruction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/utils/instruction.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6CAgByB;AACzB,kDAAoD;AACpD,4CAAyC;AAEzC,SAAsB,uBAAuB,CAC3C,CAAa,EACb,EAAwB,EACxB,KAAc,EACd,OAAiB,EACjB,oBAA6B,KAAK,EAClC,kBAA0B,EAAE;;;QAE5B,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;QAE7B,IAAI;YACF,MAAM,GAAG,GAAW,MAAM,kCAAkC,CAAC,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE;gBAC/E,mBAAmB,EAAE,WAAW;aACjC,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,eAAe,EAAE,GAAG,CAAC,CAAC;YACvD,IAAI,iBAAiB,EAAE;gBACrB,MAAM,IAAA,aAAK,EAAC,IAAI,C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kC,GAAG,CAChD,KAAa,EACb,mBAA6B,EACH,EAAE;IAC5B,MAAM,IAAI,GAA6B,EAAE,CAAC;IAC1C,IAAI,CAAC,IAAI,CAAC,8BAAoB,CAAC,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAE/D,IAAI,mBAAmB,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QACpD,MAAM,SAAS,GAAG,mBAAmB,CAAC,GAAG,CAAC,SAAA,EAAE,EAAI,CAAC,CAAA,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,CAAC,8BAAoB,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;KAC9G;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAbW,QAAA,kCAAkC,sCAa7C;AAEF,2DAA2D;AAC3D,SAAgB,QAAQ,CAAS,KAAgC;IAC/D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;QACzC,OAAO,KAAK,CAAC;KACd;IACD,EAAE;IACF,4EAA4E;IAC5E,MAAM,SAAS,GAAW,KAAK,CAAC;IAChC,OAAO,IAAI,CAAC;AACd,CAAC;AARD,4BAQC","sourcesContent":["import Decimal from 'decimal.js';\n\nimport {\n AddressLookupTableAccount,\n Commitment,\n ComputeBudgetProgram,\n Connection,\n Keypair,\n PublicKey,\n SendOptions,\n Signer,\n Transaction,\n TransactionInstruction,\n TransactionMessage,\n TransactionResponse,\n TransactionSignature,\n VersionedTransaction,\n VersionedTransactionResponse,\n} from '@solana/web3.js';\nimport { fromTxError } from '../idl_codegen/errors';\nimport { sleep } from '../classes/utils';\n\nexport async function buildAndSendTxnWithLogs(\n c: Connection,\n tx: VersionedTransaction,\n owner: Keypair,\n signers: Signer[],\n withLogsIfSuccess: boolean = false,\n withDescription: string = ''\n): Promise<TransactionSignature> {\n tx.sign([owner, ...signers]);\n\n try {\n const sig: string = await sendAndConfirmVersionedTransaction(c, tx, 'confirmed', {\n preflightCommitment: 'processed',\n });\n console.log('Transaction Hash:', withDescription, sig);\n if (withLogsIfSuccess) {\n await sleep(5000);\n const res = await c.getTransaction(sig, {\n commitment: 'confirmed',\n maxSupportedTransactionVersion: 6,\n });\n console.log('Transaction Logs:\\n', res?.meta?.logMessages);\n }\n return sig;\n } catch (e: any) {\n console.log(e);\n process.stdout.write(e.logs.toString());\n await sleep(5000);\n const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];\n const res: VersionedTransactionResponse | null = await c.getTransaction(sig, {\n commitment: 'confirmed',\n maxSupportedTransactionVersion: 6,\n });\n console.log('Txn', res!.meta!.logMessages);\n return sig;\n }\n}\n\nexport async function sendAndConfirmVersionedTransaction(\n c: Connection,\n tx: VersionedTransaction,\n commitment: Commitment = 'confirmed',\n sendTransactionOptions: SendOptions = { preflightCommitment: 'processed' }\n) {\n const defaultOptions: SendOptions = { skipPreflight: true };\n const txId = await c.sendTransaction(tx, { ...defaultOptions, ...sendTransactionOptions });\n console.log('Sending versioned txn', txId.toString());\n\n const latestBlockHash = await c.getLatestBlockhash('finalized');\n const t = await c.confirmTransaction(\n {\n blockhash: latestBlockHash.blockhash,\n lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,\n signature: txId,\n },\n commitment\n );\n if (t.value && t.value.err) {\n const txDetails = await c.getTransaction(txId, {\n maxSupportedTransactionVersion: 0,\n commitment: 'confirmed',\n });\n if (txDetails) {\n throw { err: txDetails.meta?.err, logs: txDetails.meta?.logMessages || [] };\n }\n throw t.value.err;\n }\n return txId;\n}\n\nexport async function simulateTxn(c: Connection, tx: Transaction, owner: Keypair, signers: Signer[]) {\n const { blockhash } = await c.getLatestBlockhash();\n tx.recentBlockhash = blockhash;\n tx.feePayer = owner.publicKey;\n\n try {\n const simulation = await c.simulateTransaction(tx, [owner, ...signers]);\n console.log('Transaction Hash:', simulation);\n } catch (e: any) {\n console.log(e);\n process.stdout.write(e.logs.toString());\n await sleep(5000);\n const sig = e.toString().split(' failed ')[0].split('Transaction ')[1];\n const res: TransactionResponse | null = await c.getTransaction(sig, {\n commitment: 'confirmed',\n });\n console.log('Txn', res!.meta!.logMessages);\n return sig;\n }\n}\n\nexport function buildComputeBudgetIx(units: number): TransactionInstruction {\n return ComputeBudgetProgram.setComputeUnitLimit({ units });\n}\n\n/**\n * Send a transaction with optional address lookup tables\n * Translates anchor errors into anchor error types\n * @param connection\n * @param payer\n * @param instructions\n * @param lookupTables\n */\nexport async function sendTransactionV0(\n connection: Connection,\n payer: Keypair,\n instructions: TransactionInstruction[],\n lookupTables: AddressLookupTableAccount[] | undefined = undefined,\n options?: SendOptions\n): Promise<string> {\n const recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n\n const messageV0 = new TransactionMessage({\n payerKey: payer.publicKey,\n recentBlockhash,\n instructions,\n }).compileToV0Message(lookupTables);\n\n const tx = new VersionedTransaction(messageV0);\n tx.sign([payer]);\n try {\n return await connection.sendTransaction(tx, options);\n } catch (err) {\n throw fromTxError(err) ?? err;\n }\n}\n\nexport async function simulateTransactionV0(\n connection: Connection,\n payer: Keypair,\n instructions: TransactionInstruction[],\n lookupTables: AddressLookupTableAccount[] | undefined = undefined\n) {\n const recentBlockhash = (await connection.getLatestBlockhash()).blockhash;\n\n const messageV0 = new TransactionMessage({\n payerKey: payer.publicKey,\n recentBlockhash,\n instructions,\n }).compileToV0Message(lookupTables);\n\n const tx = new VersionedTransaction(messageV0);\n tx.sign([payer]);\n try {\n return await connection.simulateTransaction(tx);\n } catch (err) {\n throw fromTxError(err) ?? err;\n }\n}\n\nexport const buildVersionedTransaction = async (\n connection: Connection,\n payer: PublicKey,\n instructions: TransactionInstruction[],\n lookupTables: PublicKey[] = []\n): Promise<VersionedTransaction> => {\n const blockhash = await connection.getLatestBlockhash('confirmed').then((res) => res.blockhash);\n\n const lookupTablesAccounts = await Promise.all(\n lookupTables.map((address) => {\n return getLookupTableAccount(connection, address);\n })\n );\n\n const messageV0 = new TransactionMessage({\n payerKey: payer,\n recentBlockhash: blockhash,\n instructions,\n }).compileToV0Message(lookupTablesAccounts.filter(notEmpty));\n\n return new VersionedTransaction(messageV0);\n};\n\nexport const getLookupTableAccount = async (connection: Connection, address: PublicKey) => {\n return connection.getAddressLookupTable(address).then((res) => res.value);\n};\n\nexport const getLookupTableAccounts = async (connection: Connection, addresses: PublicKey[]) => {\n const lookupTableAccounts: AddressLookupTableAccount[] = [];\n for (const address of addresses) {\n const lookupTableAccount = await connection.getAddressLookupTable(address).then((res) => res.value);\n\n if (!lookupTableAccount) {\n console.error('lookup table is not found');\n throw new Error('lookup table is not found');\n }\n\n lookupTableAccounts.push(lookupTableAccount);\n }\n return lookupTableAccounts;\n};\n\nexport const getComputeBudgetAndPriorityFeeIxns = (\n units: number,\n priorityFeeLamports?: Decimal\n): TransactionInstruction[] => {\n const ixns: TransactionInstruction[] = [];\n ixns.push(ComputeBudgetProgram.setComputeUnitLimit({ units }));\n\n if (priorityFeeLamports && priorityFeeLamports.gt(0)) {\n const unitPrice = priorityFeeLamports.mul(10 ** 6).div(units);\n ixns.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: BigInt(unitPrice.floor().toString()) }));\n }\n\n return ixns;\n};\n\n// filters null values from array and make typescript happy\nexport function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {\n if (value === null || value === undefined) {\n return false;\n }\n //\n // eslint-disable-next-line no-unused-vars,@typescript-eslint/no-unused-vars\n const testDummy: TValue = value;\n return true;\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isKtoken = void 0;
|
|
13
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
14
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
+
function isKtoken(mintKey, kamino) {
|
|
16
|
+
var _a;
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const [expectedMintAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('authority'), mintKey.toBuffer()], kamino.getProgramID());
|
|
19
|
+
const mintInfo = deserializeMint((_a = (yield kamino.getConnection().getAccountInfo(mintKey))) === null || _a === void 0 ? void 0 : _a.data);
|
|
20
|
+
return mintInfo.mintAuthority !== null && mintInfo.mintAuthority.equals(expectedMintAuthority);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.isKtoken = isKtoken;
|
|
24
|
+
function deserializeMint(data) {
|
|
25
|
+
if (data.length !== spl_token_1.MintLayout.span) {
|
|
26
|
+
throw new Error('Not a valid Mint');
|
|
27
|
+
}
|
|
28
|
+
const mintInfo = spl_token_1.MintLayout.decode(data);
|
|
29
|
+
if (mintInfo.mintAuthorityOption === 0) {
|
|
30
|
+
mintInfo.mintAuthority = null;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
mintInfo.mintAuthority = new web3_js_1.PublicKey(mintInfo.mintAuthority);
|
|
34
|
+
}
|
|
35
|
+
mintInfo.supply = spl_token_1.u64.fromBuffer(mintInfo.supply);
|
|
36
|
+
mintInfo.isInitialized = mintInfo.isInitialized !== 0;
|
|
37
|
+
if (mintInfo.freezeAuthorityOption === 0) {
|
|
38
|
+
mintInfo.freezeAuthority = null;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
mintInfo.freezeAuthority = new web3_js_1.PublicKey(mintInfo.freezeAuthority);
|
|
42
|
+
}
|
|
43
|
+
return mintInfo;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=kamino.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kamino.js","sourceRoot":"","sources":["../../src/utils/kamino.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iDAA8D;AAC9D,6CAA4C;AAE5C,SAAsB,QAAQ,CAAC,OAAkB,EAAE,MAAc;;;QAC/D,MAAM,CAAC,qBAAqB,CAAC,GAAG,mBAAS,CAAC,sBAAsB,CAC9D,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAC9C,MAAM,CAAC,YAAY,EAAE,CACtB,CAAC;QACF,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAA,CAAC,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,0CAAE,IAAK,CAAC,CAAC;QAChG,OAAO,QAAQ,CAAC,aAAa,KAAK,IAAI,IAAI,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;;CAChG;AAPD,4BAOC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,IAAI,IAAI,CAAC,MAAM,KAAK,sBAAU,CAAC,IAAI,EAAE;QACnC,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;KACrC;IAED,MAAM,QAAQ,GAAG,sBAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEzC,IAAI,QAAQ,CAAC,mBAAmB,KAAK,CAAC,EAAE;QACtC,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC;KAC/B;SAAM;QACL,QAAQ,CAAC,aAAa,GAAG,IAAI,mBAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;KAChE;IAED,QAAQ,CAAC,MAAM,GAAG,eAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClD,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,KAAK,CAAC,CAAC;IAEtD,IAAI,QAAQ,CAAC,qBAAqB,KAAK,CAAC,EAAE;QACxC,QAAQ,CAAC,eAAe,GAAG,IAAI,CAAC;KACjC;SAAM;QACL,QAAQ,CAAC,eAAe,GAAG,IAAI,mBAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;KACpE;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { Kamino } from '@hubbleprotocol/kamino-sdk';\nimport { MintInfo, MintLayout, u64 } from '@solana/spl-token';\nimport { PublicKey } from '@solana/web3.js';\n\nexport async function isKtoken(mintKey: PublicKey, kamino: Kamino): Promise<boolean> {\n const [expectedMintAuthority] = PublicKey.findProgramAddressSync(\n [Buffer.from('authority'), mintKey.toBuffer()],\n kamino.getProgramID()\n );\n const mintInfo = deserializeMint((await kamino.getConnection().getAccountInfo(mintKey))?.data!);\n return mintInfo.mintAuthority !== null && mintInfo.mintAuthority.equals(expectedMintAuthority);\n}\n\nfunction deserializeMint(data: Buffer): MintInfo {\n if (data.length !== MintLayout.span) {\n throw new Error('Not a valid Mint');\n }\n\n const mintInfo = MintLayout.decode(data);\n\n if (mintInfo.mintAuthorityOption === 0) {\n mintInfo.mintAuthority = null;\n } else {\n mintInfo.mintAuthority = new PublicKey(mintInfo.mintAuthority);\n }\n\n mintInfo.supply = u64.fromBuffer(mintInfo.supply);\n mintInfo.isInitialized = mintInfo.isInitialized !== 0;\n\n if (mintInfo.freezeAuthorityOption === 0) {\n mintInfo.freezeAuthority = null;\n } else {\n mintInfo.freezeAuthority = new PublicKey(mintInfo.freezeAuthority);\n }\n\n return mintInfo;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout for a public key
|
|
3
|
+
*/
|
|
4
|
+
export declare const publicKey: (property?: string) => unknown;
|
|
5
|
+
/**
|
|
6
|
+
* Layout for a 64bit unsigned value
|
|
7
|
+
*/
|
|
8
|
+
export declare const uint64: (property?: string) => unknown;
|
|
9
|
+
export declare const uint128: (property?: string) => unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Layout for a Rust String type
|
|
12
|
+
*/
|
|
13
|
+
export declare const rustString: (property?: string) => unknown;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.rustString = exports.uint128 = exports.uint64 = exports.publicKey = void 0;
|
|
30
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
31
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
32
|
+
const BufferLayout = __importStar(require("buffer-layout"));
|
|
33
|
+
/**
|
|
34
|
+
* Layout for a public key
|
|
35
|
+
*/
|
|
36
|
+
const publicKey = (property = 'publicKey') => {
|
|
37
|
+
const publicKeyLayout = BufferLayout.blob(32, property);
|
|
38
|
+
const _decode = publicKeyLayout.decode.bind(publicKeyLayout);
|
|
39
|
+
const _encode = publicKeyLayout.encode.bind(publicKeyLayout);
|
|
40
|
+
publicKeyLayout.decode = (buffer, offset) => {
|
|
41
|
+
const data = _decode(buffer, offset);
|
|
42
|
+
return new web3_js_1.PublicKey(data);
|
|
43
|
+
};
|
|
44
|
+
publicKeyLayout.encode = (key, buffer, offset) => _encode(key.toBuffer(), buffer, offset);
|
|
45
|
+
return publicKeyLayout;
|
|
46
|
+
};
|
|
47
|
+
exports.publicKey = publicKey;
|
|
48
|
+
/**
|
|
49
|
+
* Layout for a 64bit unsigned value
|
|
50
|
+
*/
|
|
51
|
+
const uint64 = (property = 'uint64') => {
|
|
52
|
+
const layout = BufferLayout.blob(8, property);
|
|
53
|
+
const _decode = layout.decode.bind(layout);
|
|
54
|
+
const _encode = layout.encode.bind(layout);
|
|
55
|
+
layout.decode = (buffer, offset) => {
|
|
56
|
+
const data = _decode(buffer, offset);
|
|
57
|
+
return new bn_js_1.default([...data]
|
|
58
|
+
.reverse()
|
|
59
|
+
.map((i) => `00${i.toString(16)}`.slice(-2))
|
|
60
|
+
.join(''), 16);
|
|
61
|
+
};
|
|
62
|
+
layout.encode = (num, buffer, offset) => {
|
|
63
|
+
const a = num.toArray().reverse();
|
|
64
|
+
let b = Buffer.from(a);
|
|
65
|
+
if (b.length !== 8) {
|
|
66
|
+
const zeroPad = Buffer.alloc(8);
|
|
67
|
+
b.copy(zeroPad);
|
|
68
|
+
b = zeroPad;
|
|
69
|
+
}
|
|
70
|
+
return _encode(b, buffer, offset);
|
|
71
|
+
};
|
|
72
|
+
return layout;
|
|
73
|
+
};
|
|
74
|
+
exports.uint64 = uint64;
|
|
75
|
+
const uint128 = (property = 'uint128') => {
|
|
76
|
+
const layout = BufferLayout.blob(16, property);
|
|
77
|
+
const _decode = layout.decode.bind(layout);
|
|
78
|
+
const _encode = layout.encode.bind(layout);
|
|
79
|
+
layout.decode = (buffer, offset) => {
|
|
80
|
+
const data = _decode(buffer, offset);
|
|
81
|
+
return new bn_js_1.default([...data]
|
|
82
|
+
.reverse()
|
|
83
|
+
.map((i) => `00${i.toString(16)}`.slice(-2))
|
|
84
|
+
.join(''), 16);
|
|
85
|
+
};
|
|
86
|
+
layout.encode = (num, buffer, offset) => {
|
|
87
|
+
const a = num.toArray().reverse();
|
|
88
|
+
let b = Buffer.from(a);
|
|
89
|
+
if (b.length !== 16) {
|
|
90
|
+
const zeroPad = Buffer.alloc(16);
|
|
91
|
+
b.copy(zeroPad);
|
|
92
|
+
b = zeroPad;
|
|
93
|
+
}
|
|
94
|
+
return _encode(b, buffer, offset);
|
|
95
|
+
};
|
|
96
|
+
return layout;
|
|
97
|
+
};
|
|
98
|
+
exports.uint128 = uint128;
|
|
99
|
+
/**
|
|
100
|
+
* Layout for a Rust String type
|
|
101
|
+
*/
|
|
102
|
+
const rustString = (property = 'string') => {
|
|
103
|
+
const rsl = BufferLayout.struct([
|
|
104
|
+
BufferLayout.u32('length'),
|
|
105
|
+
BufferLayout.u32('lengthPadding'),
|
|
106
|
+
BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), 'chars'),
|
|
107
|
+
], property);
|
|
108
|
+
const _decode = rsl.decode.bind(rsl);
|
|
109
|
+
const _encode = rsl.encode.bind(rsl);
|
|
110
|
+
rsl.decode = (buffer, offset) => {
|
|
111
|
+
const data = _decode(buffer, offset);
|
|
112
|
+
return data.chars.toString('utf8');
|
|
113
|
+
};
|
|
114
|
+
rsl.encode = (str, buffer, offset) => {
|
|
115
|
+
const data = {
|
|
116
|
+
chars: Buffer.from(str, 'utf8'),
|
|
117
|
+
};
|
|
118
|
+
return _encode(data, buffer, offset);
|
|
119
|
+
};
|
|
120
|
+
return rsl;
|
|
121
|
+
};
|
|
122
|
+
exports.rustString = rustString;
|
|
123
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/utils/layout.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4C;AAC5C,kDAAuB;AACvB,4DAA8C;AAE9C;;GAEG;AACI,MAAM,SAAS,GAAG,CAAC,QAAQ,GAAG,WAAW,EAAW,EAAE;IAC3D,MAAM,eAAe,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAExD,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAE7D,eAAe,CAAC,MAAM,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,EAAE;QAC1D,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrC,OAAO,IAAI,mBAAS,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,eAAe,CAAC,MAAM,GAAG,CAAC,GAAc,EAAE,MAAc,EAAE,MAAc,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAErH,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAdW,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N from 'bn.js';\nimport * as BufferLayout from 'buffer-layout';\n\n/**\n * Layout for a public key\n */\nexport const publicKey = (property = 'publicKey'): unknown => {\n const publicKeyLayout = BufferLayout.blob(32, property);\n\n const _decode = publicKeyLayout.decode.bind(publicKeyLayout);\n const _encode = publicKeyLayout.encode.bind(publicKeyLayout);\n\n publicKeyLayout.decode = (buffer: Buffer, offset: number) => {\n const data = _decode(buffer, offset);\n return new PublicKey(data);\n };\n\n publicKeyLayout.encode = (key: PublicKey, buffer: Buffer, offset: number) => _encode(key.toBuffer(), buffer, offset);\n\n return publicKeyLayout;\n};\n\n/**\n * Layout for a 64bit unsigned value\n */\nexport const uint64 = (property = 'uint64'): unknown => {\n const layout = BufferLayout.blob(8, property);\n\n const _decode = layout.decode.bind(layout);\n const _encode = layout.encode.bind(layout);\n\n layout.decode = (buffer: Buffer, offset: number) => {\n const data = _decode(buffer, offset);\n return new BN(\n [...data]\n .reverse()\n .map((i) => `00${i.toString(16)}`.slice(-2))\n .join(''),\n 16\n );\n };\n\n layout.encode = (num: BN, buffer: Buffer, offset: number) => {\n const a = num.toArray().reverse();\n let b = Buffer.from(a);\n if (b.length !== 8) {\n const zeroPad = Buffer.alloc(8);\n b.copy(zeroPad);\n b = zeroPad;\n }\n return _encode(b, buffer, offset);\n };\n\n return layout;\n};\n\nexport const uint128 = (property = 'uint128'): unknown => {\n const layout = BufferLayout.blob(16, property);\n\n const _decode = layout.decode.bind(layout);\n const _encode = layout.encode.bind(layout);\n\n layout.decode = (buffer: Buffer, offset: number) => {\n const data = _decode(buffer, offset);\n return new BN(\n [...data]\n .reverse()\n .map((i) => `00${i.toString(16)}`.slice(-2))\n .join(''),\n 16\n );\n };\n\n layout.encode = (num: BN, buffer: Buffer, offset: number) => {\n const a = num.toArray().reverse();\n let b = Buffer.from(a);\n if (b.length !== 16) {\n const zeroPad = Buffer.alloc(16);\n b.copy(zeroPad);\n b = zeroPad;\n }\n\n return _encode(b, buffer, offset);\n };\n\n return layout;\n};\n\n/**\n * Layout for a Rust String type\n */\nexport const rustString = (property = 'string'): unknown => {\n const rsl = BufferLayout.struct(\n [\n BufferLayout.u32('length'),\n BufferLayout.u32('lengthPadding'),\n BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), 'chars'),\n ],\n property\n );\n const _decode = rsl.decode.bind(rsl);\n const _encode = rsl.encode.bind(rsl);\n\n rsl.decode = (buffer: Buffer, offset: number) => {\n const data = _decode(buffer, offset);\n return data.chars.toString('utf8');\n };\n\n rsl.encode = (str: string, buffer: Buffer, offset: number) => {\n const data = {\n chars: Buffer.from(str, 'utf8'),\n };\n return _encode(data, buffer, offset);\n };\n\n return rsl;\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
export declare function printAddressLookupTable(connection: Connection, lookupTablePk: PublicKey): Promise<void>;
|
|
3
|
+
export declare function createLookupTableIx(connection: Connection, wallet: PublicKey): Promise<[TransactionInstruction, PublicKey]>;
|
|
4
|
+
export declare function extendLookupTableChunkIx(wallet: PublicKey, lookupTablePk: PublicKey, keys: PublicKey[], payer?: PublicKey): TransactionInstruction;
|
|
5
|
+
export declare const extendLookupTableIxs: (wallet: PublicKey, table: PublicKey, keys: PublicKey[], payer?: PublicKey) => TransactionInstruction[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.extendLookupTableIxs = exports.extendLookupTableChunkIx = exports.createLookupTableIx = exports.printAddressLookupTable = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
function printAddressLookupTable(connection, lookupTablePk) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const lookupTableAccount = (yield connection.getAddressLookupTable(lookupTablePk)).value;
|
|
17
|
+
if (!lookupTableAccount) {
|
|
18
|
+
console.error('Lookup table is not found');
|
|
19
|
+
}
|
|
20
|
+
console.log(`Lookup table account, ${lookupTablePk.toString()}`);
|
|
21
|
+
lookupTableAccount === null || lookupTableAccount === void 0 ? void 0 : lookupTableAccount.state.addresses.forEach((address, index) => {
|
|
22
|
+
console.log(`Address: ${address.toString()} at index ${index}`);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.printAddressLookupTable = printAddressLookupTable;
|
|
27
|
+
function createLookupTableIx(connection, wallet) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const [createLookupTableIxs, lookupTableAddress] = web3_js_1.AddressLookupTableProgram.createLookupTable({
|
|
30
|
+
authority: wallet,
|
|
31
|
+
payer: wallet,
|
|
32
|
+
recentSlot: yield connection.getSlot('confirmed'),
|
|
33
|
+
});
|
|
34
|
+
return [createLookupTableIxs, lookupTableAddress];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.createLookupTableIx = createLookupTableIx;
|
|
38
|
+
function extendLookupTableChunkIx(wallet, lookupTablePk, keys, payer = web3_js_1.PublicKey.default) {
|
|
39
|
+
return web3_js_1.AddressLookupTableProgram.extendLookupTable({
|
|
40
|
+
authority: wallet,
|
|
41
|
+
payer: payer.equals(web3_js_1.PublicKey.default) ? wallet : payer,
|
|
42
|
+
lookupTable: lookupTablePk,
|
|
43
|
+
addresses: keys,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.extendLookupTableChunkIx = extendLookupTableChunkIx;
|
|
47
|
+
const extendLookupTableIxs = (wallet, table, keys, payer = web3_js_1.PublicKey.default) => {
|
|
48
|
+
const chunkSize = 25;
|
|
49
|
+
const extendLookupIxs = [];
|
|
50
|
+
for (let i = 0; i < keys.length; i += chunkSize) {
|
|
51
|
+
const chunk = keys.slice(i, i + chunkSize);
|
|
52
|
+
extendLookupIxs.push(extendLookupTableChunkIx(wallet, table, chunk, payer));
|
|
53
|
+
}
|
|
54
|
+
return extendLookupIxs;
|
|
55
|
+
};
|
|
56
|
+
exports.extendLookupTableIxs = extendLookupTableIxs;
|
|
57
|
+
//# sourceMappingURL=lookupTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookupTable.js","sourceRoot":"","sources":["../../src/utils/lookupTable.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA2G;AAE3G,SAAsB,uBAAuB,CAAC,UAAsB,EAAE,aAAwB;;QAC5F,MAAM,kBAAkB,GAAG,CAAC,MAAM,UAAU,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;QACzF,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC5C;QACD,OAAO,CAAC,GAAG,CAAC,yBAAyB,aAAa,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACjE,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAkB,EAAE,KAAa,EAAE,EAAE;YAChF,OAAO,CAAC,GAAG,CAAC,YAAY,OAAO,CAAC,QAAQ,EAAE,aAAa,KAAK,EAAE,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AATD,0DASC;AA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AAC;AAdW,QAAA,oBAAoB,wBAc/B","sourcesContent":["import { AddressLookupTableProgram, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';\n\nexport async function printAddressLookupTable(connection: Connection, lookupTablePk: PublicKey) {\n const lookupTableAccount = (await connection.getAddressLookupTable(lookupTablePk)).value;\n if (!lookupTableAccount) {\n console.error('Lookup table is not found');\n }\n console.log(`Lookup table account, ${lookupTablePk.toString()}`);\n lookupTableAccount?.state.addresses.forEach((address: PublicKey, index: number) => {\n console.log(`Address: ${address.toString()} at index ${index}`);\n });\n}\n\nexport async function createLookupTableIx(\n connection: Connection,\n wallet: PublicKey\n): Promise<[TransactionInstruction, PublicKey]> {\n const [createLookupTableIxs, lookupTableAddress] = AddressLookupTableProgram.createLookupTable({\n authority: wallet,\n payer: wallet,\n recentSlot: await connection.getSlot('confirmed'),\n });\n\n return [createLookupTableIxs, lookupTableAddress];\n}\n\nexport function extendLookupTableChunkIx(\n wallet: PublicKey,\n lookupTablePk: PublicKey,\n keys: PublicKey[],\n payer: PublicKey = PublicKey.default\n): TransactionInstruction {\n return AddressLookupTableProgram.extendLookupTable({\n authority: wallet,\n payer: payer.equals(PublicKey.default) ? wallet : payer,\n lookupTable: lookupTablePk,\n addresses: keys,\n });\n}\n\nexport const extendLookupTableIxs = (\n wallet: PublicKey,\n table: PublicKey,\n keys: PublicKey[],\n payer: PublicKey = PublicKey.default\n): TransactionInstruction[] => {\n const chunkSize = 25;\n const extendLookupIxs: TransactionInstruction[] = [];\n for (let i = 0; i < keys.length; i += chunkSize) {\n const chunk = keys.slice(i, i + chunkSize);\n extendLookupIxs.push(extendLookupTableChunkIx(wallet, table, chunk, payer));\n }\n\n return extendLookupIxs;\n};\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AccountInfo, Connection, PublicKey } from '@solana/web3.js';
|
|
3
|
+
import Decimal from 'decimal.js';
|
|
4
|
+
import { OraclePrices } from '@hubbleprotocol/scope-sdk';
|
|
5
|
+
import { PubkeyHashMap } from './pubkey';
|
|
6
|
+
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
|
7
|
+
import { Reserve } from '../lib';
|
|
8
|
+
export declare const MAX_CONFIDENCE_PERCENTAGE: Decimal;
|
|
9
|
+
export declare const CONFIDENCE_FACTOR: Decimal;
|
|
10
|
+
export type TokenOracleData = {
|
|
11
|
+
mintAddress: PublicKey;
|
|
12
|
+
decimals: Decimal;
|
|
13
|
+
price: Decimal;
|
|
14
|
+
timestamp: bigint;
|
|
15
|
+
valid: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type CandidatePrice = {
|
|
18
|
+
price: Decimal;
|
|
19
|
+
timestamp: bigint;
|
|
20
|
+
valid: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare function getTokenOracleData(connection: Connection, reserves: Reserve[]): Promise<Array<[Reserve, TokenOracleData | undefined]>>;
|
|
23
|
+
export type AllOracleAccounts = PubkeyHashMap<PublicKey, AccountInfo<Buffer>>;
|
|
24
|
+
export declare function getAllOracleAccounts(connection: Connection, reserves: Reserve[]): Promise<AllOracleAccounts>;
|
|
25
|
+
export type PythPrices = {
|
|
26
|
+
spot?: CandidatePrice;
|
|
27
|
+
twap?: CandidatePrice;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Get pyth price from cache or fetch if not available
|
|
31
|
+
* @param oracle oracle address
|
|
32
|
+
* @param cache pyth cache
|
|
33
|
+
* @param oracleAccounts all oracle accounts
|
|
34
|
+
*/
|
|
35
|
+
export declare function cacheOrGetPythPrices(oracle: PublicKey, cache: Map<PublicKey, PythPrices>, oracleAccounts: AllOracleAccounts): PythPrices | null;
|
|
36
|
+
/**
|
|
37
|
+
* Get switchboard price from cache or fetch if not available
|
|
38
|
+
* @param oracle oracle address
|
|
39
|
+
* @param switchboardCache cache for oracle prices
|
|
40
|
+
* @param oracleAccounts all oracle accounts
|
|
41
|
+
* @param switchboardV2 loaded switchboard program
|
|
42
|
+
*/
|
|
43
|
+
export declare function cacheOrGetSwitchboardPrice(oracle: PublicKey, switchboardCache: Map<PublicKey, CandidatePrice>, oracleAccounts: AllOracleAccounts, switchboardV2: SwitchboardProgram): CandidatePrice | null;
|
|
44
|
+
/**
|
|
45
|
+
* Get scope price from cache or fetch if not available
|
|
46
|
+
* @param oracle oracle address
|
|
47
|
+
* @param scopeCache cache for oracle prices
|
|
48
|
+
* @param allOracleAccounts all oracle accounts
|
|
49
|
+
* @param chain scope chain
|
|
50
|
+
*/
|
|
51
|
+
export declare function cacheOrGetScopePrice(oracle: PublicKey, scopeCache: Map<PublicKey, OraclePrices>, allOracleAccounts: AllOracleAccounts, chain: number[]): CandidatePrice | null;
|