@kestrelfi/lyc-sdk 1.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/.env.example +11 -0
- package/README.md +207 -0
- package/dist/sdks/long-yield-carry/scripts/asyncBurn.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/asyncBurn.js +117 -0
- package/dist/sdks/long-yield-carry/scripts/burnToken.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/burnToken.js +98 -0
- package/dist/sdks/long-yield-carry/scripts/claimIncentives.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/claimIncentives.js +108 -0
- package/dist/sdks/long-yield-carry/scripts/closeCpiPlans.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/closeCpiPlans.js +93 -0
- package/dist/sdks/long-yield-carry/scripts/collectInterest.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/collectInterest.js +164 -0
- package/dist/sdks/long-yield-carry/scripts/collectProtocolFees.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/collectProtocolFees.js +120 -0
- package/dist/sdks/long-yield-carry/scripts/computeOptimalAllocations.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/computeOptimalAllocations.js +84 -0
- package/dist/sdks/long-yield-carry/scripts/createToken.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/createToken.js +76 -0
- package/dist/sdks/long-yield-carry/scripts/createTokenLendingPosition.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/createTokenLendingPosition.js +157 -0
- package/dist/sdks/long-yield-carry/scripts/createYieldingBank.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/createYieldingBank.js +69 -0
- package/dist/sdks/long-yield-carry/scripts/decreaseCarryPositions.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/decreaseCarryPositions.js +247 -0
- package/dist/sdks/long-yield-carry/scripts/depositUnlentCollateral.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/depositUnlentCollateral.js +90 -0
- package/dist/sdks/long-yield-carry/scripts/emergency/deleverageAll.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/emergency/deleverageAll.js +202 -0
- package/dist/sdks/long-yield-carry/scripts/emergency/triggerCircuitBreaker.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/emergency/triggerCircuitBreaker.js +68 -0
- package/dist/sdks/long-yield-carry/scripts/env.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/env.js +8 -0
- package/dist/sdks/long-yield-carry/scripts/findTxs.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/findTxs.js +143 -0
- package/dist/sdks/long-yield-carry/scripts/increaseCarryPositions.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/increaseCarryPositions.js +112 -0
- package/dist/sdks/long-yield-carry/scripts/inspect/format.d.ts +13 -0
- package/dist/sdks/long-yield-carry/scripts/inspect/format.js +363 -0
- package/dist/sdks/long-yield-carry/scripts/inspect.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/inspect.js +108 -0
- package/dist/sdks/long-yield-carry/scripts/localUtils.d.ts +53 -0
- package/dist/sdks/long-yield-carry/scripts/localUtils.js +191 -0
- package/dist/sdks/long-yield-carry/scripts/mintToken.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/mintToken.js +103 -0
- package/dist/sdks/long-yield-carry/scripts/processAsyncBurns.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/processAsyncBurns.js +76 -0
- package/dist/sdks/long-yield-carry/scripts/rebalanceToken.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/rebalanceToken.js +210 -0
- package/dist/sdks/long-yield-carry/scripts/rebalanceYieldingBank.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/rebalanceYieldingBank.js +149 -0
- package/dist/sdks/long-yield-carry/scripts/recollateralizeLoss.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/recollateralizeLoss.js +64 -0
- package/dist/sdks/long-yield-carry/scripts/refresh.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/refresh.js +101 -0
- package/dist/sdks/long-yield-carry/scripts/updateFees.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/updateFees.js +369 -0
- package/dist/sdks/long-yield-carry/scripts/updateGeneralLut.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/updateGeneralLut.js +27 -0
- package/dist/sdks/long-yield-carry/scripts/updateLendingPositionConfig.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/updateLendingPositionConfig.js +127 -0
- package/dist/sdks/long-yield-carry/scripts/updateTokenLuts.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/updateTokenLuts.js +27 -0
- package/dist/sdks/long-yield-carry/scripts/updateTokenMetadata.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/updateTokenMetadata.js +194 -0
- package/dist/sdks/long-yield-carry/scripts/updateYieldingBankConfig.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/updateYieldingBankConfig.js +84 -0
- package/dist/sdks/long-yield-carry/scripts/withdrawUnlentCollateral.d.ts +1 -0
- package/dist/sdks/long-yield-carry/scripts/withdrawUnlentCollateral.js +140 -0
- package/dist/sdks/long-yield-carry/src/client/account.d.ts +152 -0
- package/dist/sdks/long-yield-carry/src/client/account.js +349 -0
- package/dist/sdks/long-yield-carry/src/client/builders/args.d.ts +299 -0
- package/dist/sdks/long-yield-carry/src/client/builders/args.js +2 -0
- package/dist/sdks/long-yield-carry/src/client/builders/asyncBurnBuilder.d.ts +20 -0
- package/dist/sdks/long-yield-carry/src/client/builders/asyncBurnBuilder.js +212 -0
- package/dist/sdks/long-yield-carry/src/client/builders/base.d.ts +77 -0
- package/dist/sdks/long-yield-carry/src/client/builders/base.js +191 -0
- package/dist/sdks/long-yield-carry/src/client/builders/burnTokenBuilder.d.ts +18 -0
- package/dist/sdks/long-yield-carry/src/client/builders/burnTokenBuilder.js +165 -0
- package/dist/sdks/long-yield-carry/src/client/builders/claimIncentivesBuilder.d.ts +9 -0
- package/dist/sdks/long-yield-carry/src/client/builders/claimIncentivesBuilder.js +135 -0
- package/dist/sdks/long-yield-carry/src/client/builders/collectFeesBuilder.d.ts +14 -0
- package/dist/sdks/long-yield-carry/src/client/builders/collectFeesBuilder.js +50 -0
- package/dist/sdks/long-yield-carry/src/client/builders/collectInterestBuilder.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/client/builders/collectInterestBuilder.js +86 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createCpiPlanBuilder.d.ts +6 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createCpiPlanBuilder.js +22 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createTokenBuilder.d.ts +7 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createTokenBuilder.js +64 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createTokenLendingPositionBuilder.d.ts +10 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createTokenLendingPositionBuilder.js +138 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createYieldingBankAllocationBuilder.d.ts +7 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createYieldingBankAllocationBuilder.js +29 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createYieldingBankBuilder.d.ts +7 -0
- package/dist/sdks/long-yield-carry/src/client/builders/createYieldingBankBuilder.js +39 -0
- package/dist/sdks/long-yield-carry/src/client/builders/decreaseCarryPositionBuilder.d.ts +30 -0
- package/dist/sdks/long-yield-carry/src/client/builders/decreaseCarryPositionBuilder.js +99 -0
- package/dist/sdks/long-yield-carry/src/client/builders/depositUnlentCollateralBuilder.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/client/builders/depositUnlentCollateralBuilder.js +64 -0
- package/dist/sdks/long-yield-carry/src/client/builders/increaseCarryPositionBuilder.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/client/builders/increaseCarryPositionBuilder.js +73 -0
- package/dist/sdks/long-yield-carry/src/client/builders/index.d.ts +28 -0
- package/dist/sdks/long-yield-carry/src/client/builders/index.js +62 -0
- package/dist/sdks/long-yield-carry/src/client/builders/mintTokenBuilder.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/client/builders/mintTokenBuilder.js +95 -0
- package/dist/sdks/long-yield-carry/src/client/builders/rebalanceTokenBuilder.d.ts +11 -0
- package/dist/sdks/long-yield-carry/src/client/builders/rebalanceTokenBuilder.js +255 -0
- package/dist/sdks/long-yield-carry/src/client/builders/rebalanceYieldingBankBuilder.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/client/builders/rebalanceYieldingBankBuilder.js +75 -0
- package/dist/sdks/long-yield-carry/src/client/builders/recollateralizeLossBuilder.d.ts +12 -0
- package/dist/sdks/long-yield-carry/src/client/builders/recollateralizeLossBuilder.js +220 -0
- package/dist/sdks/long-yield-carry/src/client/builders/refreshTokenStateBuilder.d.ts +9 -0
- package/dist/sdks/long-yield-carry/src/client/builders/refreshTokenStateBuilder.js +112 -0
- package/dist/sdks/long-yield-carry/src/client/builders/refreshTokensBuilder.d.ts +9 -0
- package/dist/sdks/long-yield-carry/src/client/builders/refreshTokensBuilder.js +59 -0
- package/dist/sdks/long-yield-carry/src/client/builders/refreshYieldingBankBuilder.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/client/builders/refreshYieldingBankBuilder.js +29 -0
- package/dist/sdks/long-yield-carry/src/client/builders/resetTokenBurnRateLimitBuilder.d.ts +7 -0
- package/dist/sdks/long-yield-carry/src/client/builders/resetTokenBurnRateLimitBuilder.js +19 -0
- package/dist/sdks/long-yield-carry/src/client/builders/setTokenCircuitBreakerBuilder.d.ts +11 -0
- package/dist/sdks/long-yield-carry/src/client/builders/setTokenCircuitBreakerBuilder.js +31 -0
- package/dist/sdks/long-yield-carry/src/client/builders/setYieldingBankCircuitBreakerBuilder.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/client/builders/setYieldingBankCircuitBreakerBuilder.js +28 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateLendingPositionConfigBuilder.d.ts +10 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateLendingPositionConfigBuilder.js +30 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateTokenConfigurationBuilder.d.ts +11 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateTokenConfigurationBuilder.js +47 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateTokenMetadataBuilder.d.ts +7 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateTokenMetadataBuilder.js +24 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateYieldingBankConfigBuilder.d.ts +10 -0
- package/dist/sdks/long-yield-carry/src/client/builders/updateYieldingBankConfigBuilder.js +31 -0
- package/dist/sdks/long-yield-carry/src/client/builders/utils.d.ts +4 -0
- package/dist/sdks/long-yield-carry/src/client/builders/utils.js +20 -0
- package/dist/sdks/long-yield-carry/src/client/client.d.ts +115 -0
- package/dist/sdks/long-yield-carry/src/client/client.js +166 -0
- package/dist/sdks/long-yield-carry/src/client/externalLiquidityResolver.d.ts +13 -0
- package/dist/sdks/long-yield-carry/src/client/externalLiquidityResolver.js +34 -0
- package/dist/sdks/long-yield-carry/src/client/index.d.ts +10 -0
- package/dist/sdks/long-yield-carry/src/client/index.js +33 -0
- package/dist/sdks/long-yield-carry/src/client/lendingPlatformClients.d.ts +19 -0
- package/dist/sdks/long-yield-carry/src/client/lendingPlatformClients.js +33 -0
- package/dist/sdks/long-yield-carry/src/client/pda.d.ts +33 -0
- package/dist/sdks/long-yield-carry/src/client/pda.js +79 -0
- package/dist/sdks/long-yield-carry/src/client/plans/collectInterest.d.ts +24 -0
- package/dist/sdks/long-yield-carry/src/client/plans/collectInterest.js +150 -0
- package/dist/sdks/long-yield-carry/src/client/plans/decreaseCarryPosition.d.ts +12 -0
- package/dist/sdks/long-yield-carry/src/client/plans/decreaseCarryPosition.js +140 -0
- package/dist/sdks/long-yield-carry/src/client/routes/collectInterest.d.ts +13 -0
- package/dist/sdks/long-yield-carry/src/client/routes/collectInterest.js +39 -0
- package/dist/sdks/long-yield-carry/src/client/transaction.d.ts +41 -0
- package/dist/sdks/long-yield-carry/src/client/transaction.js +55 -0
- package/dist/sdks/long-yield-carry/src/client/types/builders.d.ts +18 -0
- package/dist/sdks/long-yield-carry/src/client/types/builders.js +2 -0
- package/dist/sdks/long-yield-carry/src/client/types/enums.d.ts +22 -0
- package/dist/sdks/long-yield-carry/src/client/types/enums.js +48 -0
- package/dist/sdks/long-yield-carry/src/client/types/general.d.ts +98 -0
- package/dist/sdks/long-yield-carry/src/client/types/general.js +2 -0
- package/dist/sdks/long-yield-carry/src/client/types/index.d.ts +6 -0
- package/dist/sdks/long-yield-carry/src/client/types/index.js +22 -0
- package/dist/sdks/long-yield-carry/src/client/types/ix.d.ts +352 -0
- package/dist/sdks/long-yield-carry/src/client/types/ix.js +2 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/collectInterest.d.ts +91 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/collectInterest.js +2 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/common.d.ts +28 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/common.js +2 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/decreaseCarryPosition.d.ts +128 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/decreaseCarryPosition.js +2 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/index.d.ts +3 -0
- package/dist/sdks/long-yield-carry/src/client/types/planTypes/index.js +19 -0
- package/dist/sdks/long-yield-carry/src/client/types/tx.d.ts +339 -0
- package/dist/sdks/long-yield-carry/src/client/types/tx.js +2 -0
- package/dist/sdks/long-yield-carry/src/constants/configs/allocations.d.ts +3 -0
- package/dist/sdks/long-yield-carry/src/constants/configs/allocations.js +23 -0
- package/dist/sdks/long-yield-carry/src/constants/configs/carryTradePresets.d.ts +58 -0
- package/dist/sdks/long-yield-carry/src/constants/configs/carryTradePresets.js +116 -0
- package/dist/sdks/long-yield-carry/src/constants/configs/index.d.ts +2 -0
- package/dist/sdks/long-yield-carry/src/constants/configs/index.js +18 -0
- package/dist/sdks/long-yield-carry/src/constants/general.d.ts +70 -0
- package/dist/sdks/long-yield-carry/src/constants/general.js +107 -0
- package/dist/sdks/long-yield-carry/src/constants/index.d.ts +3 -0
- package/dist/sdks/long-yield-carry/src/constants/index.js +19 -0
- package/dist/sdks/long-yield-carry/src/constants/lycTokenMetadata.d.ts +36 -0
- package/dist/sdks/long-yield-carry/src/constants/lycTokenMetadata.js +41 -0
- package/dist/sdks/long-yield-carry/src/decoders/decodeTransaction.d.ts +86 -0
- package/dist/sdks/long-yield-carry/src/decoders/decodeTransaction.js +230 -0
- package/dist/sdks/long-yield-carry/src/decoders/discriminators.d.ts +8 -0
- package/dist/sdks/long-yield-carry/src/decoders/discriminators.js +11 -0
- package/dist/sdks/long-yield-carry/src/decoders/idlAccounts.d.ts +29 -0
- package/dist/sdks/long-yield-carry/src/decoders/idlAccounts.js +57 -0
- package/dist/sdks/long-yield-carry/src/decoders/index.d.ts +6 -0
- package/dist/sdks/long-yield-carry/src/decoders/index.js +14 -0
- package/dist/sdks/long-yield-carry/src/decoders/innerCpis.d.ts +68 -0
- package/dist/sdks/long-yield-carry/src/decoders/innerCpis.js +225 -0
- package/dist/sdks/long-yield-carry/src/decoders/lycInstructionNames.d.ts +6 -0
- package/dist/sdks/long-yield-carry/src/decoders/lycInstructionNames.js +73 -0
- package/dist/sdks/long-yield-carry/src/decoders/programIds.d.ts +4 -0
- package/dist/sdks/long-yield-carry/src/decoders/programIds.js +11 -0
- package/dist/sdks/long-yield-carry/src/decoders/solana.d.ts +7 -0
- package/dist/sdks/long-yield-carry/src/decoders/solana.js +30 -0
- package/dist/sdks/long-yield-carry/src/decoders/transactionPayload.d.ts +41 -0
- package/dist/sdks/long-yield-carry/src/decoders/transactionPayload.js +6 -0
- package/dist/sdks/long-yield-carry/src/decoders/types.d.ts +58 -0
- package/dist/sdks/long-yield-carry/src/decoders/types.js +2 -0
- package/dist/sdks/long-yield-carry/src/errors.d.ts +69 -0
- package/dist/sdks/long-yield-carry/src/errors.js +183 -0
- package/dist/sdks/long-yield-carry/src/idl/long_yield_carry.d.ts +7327 -0
- package/dist/sdks/long-yield-carry/src/idl/long_yield_carry.js +7323 -0
- package/dist/sdks/long-yield-carry/src/index.d.ts +10 -0
- package/dist/sdks/long-yield-carry/src/index.js +25 -0
- package/dist/sdks/long-yield-carry/src/metrics/index.d.ts +1 -0
- package/dist/sdks/long-yield-carry/src/metrics/index.js +17 -0
- package/dist/sdks/long-yield-carry/src/metrics/protocolMetrics.d.ts +276 -0
- package/dist/sdks/long-yield-carry/src/metrics/protocolMetrics.js +547 -0
- package/dist/sdks/long-yield-carry/src/models/index.d.ts +3 -0
- package/dist/sdks/long-yield-carry/src/models/index.js +7 -0
- package/dist/sdks/long-yield-carry/src/models/lycToken.d.ts +156 -0
- package/dist/sdks/long-yield-carry/src/models/lycToken.js +288 -0
- package/dist/sdks/long-yield-carry/src/models/yieldingBank.d.ts +52 -0
- package/dist/sdks/long-yield-carry/src/models/yieldingBank.js +109 -0
- package/dist/sdks/long-yield-carry/src/services/allocation/allocationService.d.ts +106 -0
- package/dist/sdks/long-yield-carry/src/services/allocation/allocationService.js +589 -0
- package/dist/sdks/long-yield-carry/src/services/allocation/index.d.ts +2 -0
- package/dist/sdks/long-yield-carry/src/services/allocation/index.js +18 -0
- package/dist/sdks/long-yield-carry/src/services/allocation/types.d.ts +25 -0
- package/dist/sdks/long-yield-carry/src/services/allocation/types.js +2 -0
- package/dist/sdks/long-yield-carry/src/services/carry/carryAllocationConfig.d.ts +103 -0
- package/dist/sdks/long-yield-carry/src/services/carry/carryAllocationConfig.js +146 -0
- package/dist/sdks/long-yield-carry/src/services/carry/index.d.ts +2 -0
- package/dist/sdks/long-yield-carry/src/services/carry/index.js +18 -0
- package/dist/sdks/long-yield-carry/src/services/carry/lycLendingPositionManager.d.ts +39 -0
- package/dist/sdks/long-yield-carry/src/services/carry/lycLendingPositionManager.js +100 -0
- package/dist/sdks/long-yield-carry/src/services/index.d.ts +5 -0
- package/dist/sdks/long-yield-carry/src/services/index.js +21 -0
- package/dist/sdks/long-yield-carry/src/services/lendingPosition/index.d.ts +2 -0
- package/dist/sdks/long-yield-carry/src/services/lendingPosition/index.js +5 -0
- package/dist/sdks/long-yield-carry/src/services/lendingPosition/lendingPositionService.d.ts +88 -0
- package/dist/sdks/long-yield-carry/src/services/lendingPosition/lendingPositionService.js +229 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/index.d.ts +2 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/index.js +18 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/token/index.d.ts +1 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/token/index.js +17 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/token/tokenRebalanceService.d.ts +51 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/token/tokenRebalanceService.js +99 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/index.d.ts +3 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/index.js +21 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/planner.d.ts +68 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/planner.js +181 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/strategy.d.ts +26 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/strategy.js +26 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/types.d.ts +40 -0
- package/dist/sdks/long-yield-carry/src/services/rebalance/yieldingBank/types.js +2 -0
- package/dist/sdks/long-yield-carry/src/services/redemption/index.d.ts +2 -0
- package/dist/sdks/long-yield-carry/src/services/redemption/index.js +5 -0
- package/dist/sdks/long-yield-carry/src/services/redemption/redemptionService.d.ts +139 -0
- package/dist/sdks/long-yield-carry/src/services/redemption/redemptionService.js +532 -0
- package/dist/sdks/long-yield-carry/src/types/enriched.d.ts +168 -0
- package/dist/sdks/long-yield-carry/src/types/enriched.js +2 -0
- package/dist/sdks/long-yield-carry/src/types/index.d.ts +1 -0
- package/dist/sdks/long-yield-carry/src/types/index.js +17 -0
- package/dist/sdks/long-yield-carry/src/utils/cache.d.ts +4 -0
- package/dist/sdks/long-yield-carry/src/utils/cache.js +10 -0
- package/dist/sdks/long-yield-carry/src/utils/data.d.ts +12 -0
- package/dist/sdks/long-yield-carry/src/utils/data.js +59 -0
- package/dist/sdks/long-yield-carry/src/utils/enrichment.d.ts +5 -0
- package/dist/sdks/long-yield-carry/src/utils/enrichment.js +244 -0
- package/dist/sdks/long-yield-carry/src/utils/feeDripMetrics.d.ts +36 -0
- package/dist/sdks/long-yield-carry/src/utils/feeDripMetrics.js +93 -0
- package/dist/sdks/long-yield-carry/src/utils/general.d.ts +28 -0
- package/dist/sdks/long-yield-carry/src/utils/general.js +47 -0
- package/dist/sdks/long-yield-carry/src/utils/index.d.ts +13 -0
- package/dist/sdks/long-yield-carry/src/utils/index.js +29 -0
- package/dist/sdks/long-yield-carry/src/utils/ix.d.ts +83 -0
- package/dist/sdks/long-yield-carry/src/utils/ix.js +165 -0
- package/dist/sdks/long-yield-carry/src/utils/lendingPosition.d.ts +68 -0
- package/dist/sdks/long-yield-carry/src/utils/lendingPosition.js +105 -0
- package/dist/sdks/long-yield-carry/src/utils/lookupTables.d.ts +55 -0
- package/dist/sdks/long-yield-carry/src/utils/lookupTables.js +216 -0
- package/dist/sdks/long-yield-carry/src/utils/lycData.d.ts +66 -0
- package/dist/sdks/long-yield-carry/src/utils/lycData.js +211 -0
- package/dist/sdks/long-yield-carry/src/utils/timelock.d.ts +19 -0
- package/dist/sdks/long-yield-carry/src/utils/timelock.js +37 -0
- package/dist/sdks/long-yield-carry/src/utils/tokenFeeMath.d.ts +11 -0
- package/dist/sdks/long-yield-carry/src/utils/tokenFeeMath.js +24 -0
- package/dist/sdks/long-yield-carry/src/utils/transactions.d.ts +20 -0
- package/dist/sdks/long-yield-carry/src/utils/transactions.js +72 -0
- package/dist/sdks/long-yield-carry/src/utils/yieldingBank.d.ts +24 -0
- package/dist/sdks/long-yield-carry/src/utils/yieldingBank.js +36 -0
- package/dist/shared/common/src/constants/accountMetas.d.ts +3 -0
- package/dist/shared/common/src/constants/accountMetas.js +9 -0
- package/dist/shared/common/src/constants/general.d.ts +21 -0
- package/dist/shared/common/src/constants/general.js +30 -0
- package/dist/shared/common/src/constants/generated/cpi.d.ts +23 -0
- package/dist/shared/common/src/constants/generated/cpi.js +28 -0
- package/dist/shared/common/src/constants/generated/index.d.ts +1 -0
- package/dist/shared/common/src/constants/generated/index.js +17 -0
- package/dist/shared/common/src/constants/index.d.ts +3 -0
- package/dist/shared/common/src/constants/index.js +19 -0
- package/dist/shared/common/src/index.d.ts +4 -0
- package/dist/shared/common/src/index.js +20 -0
- package/dist/shared/common/src/services/baseAccountClient.d.ts +22 -0
- package/dist/shared/common/src/services/baseAccountClient.js +38 -0
- package/dist/shared/common/src/services/baseIxBuilderService.d.ts +27 -0
- package/dist/shared/common/src/services/baseIxBuilderService.js +48 -0
- package/dist/shared/common/src/services/dataCache.d.ts +41 -0
- package/dist/shared/common/src/services/dataCache.js +130 -0
- package/dist/shared/common/src/services/index.d.ts +8 -0
- package/dist/shared/common/src/services/index.js +24 -0
- package/dist/shared/common/src/services/lutManager.d.ts +31 -0
- package/dist/shared/common/src/services/lutManager.js +133 -0
- package/dist/shared/common/src/services/mints/defaults.d.ts +2 -0
- package/dist/shared/common/src/services/mints/defaults.js +152 -0
- package/dist/shared/common/src/services/mints/index.d.ts +4 -0
- package/dist/shared/common/src/services/mints/index.js +20 -0
- package/dist/shared/common/src/services/mints/registry.d.ts +70 -0
- package/dist/shared/common/src/services/mints/registry.js +117 -0
- package/dist/shared/common/src/services/mints/symbols.d.ts +6 -0
- package/dist/shared/common/src/services/mints/symbols.js +13 -0
- package/dist/shared/common/src/services/mints/types.d.ts +30 -0
- package/dist/shared/common/src/services/mints/types.js +2 -0
- package/dist/shared/common/src/services/swap/index.d.ts +4 -0
- package/dist/shared/common/src/services/swap/index.js +20 -0
- package/dist/shared/common/src/services/swap/routableSwapClient.d.ts +36 -0
- package/dist/shared/common/src/services/swap/routableSwapClient.js +2 -0
- package/dist/shared/common/src/services/swap/swapClientBase.d.ts +45 -0
- package/dist/shared/common/src/services/swap/swapClientBase.js +2 -0
- package/dist/shared/common/src/services/swap/swapRouting.d.ts +13 -0
- package/dist/shared/common/src/services/swap/swapRouting.js +28 -0
- package/dist/shared/common/src/services/swap/types.d.ts +77 -0
- package/dist/shared/common/src/services/swap/types.js +2 -0
- package/dist/shared/common/src/services/token/index.d.ts +2 -0
- package/dist/shared/common/src/services/token/index.js +18 -0
- package/dist/shared/common/src/services/token/tokenProtocolClientBase.d.ts +51 -0
- package/dist/shared/common/src/services/token/tokenProtocolClientBase.js +2 -0
- package/dist/shared/common/src/services/token/types.d.ts +19 -0
- package/dist/shared/common/src/services/token/types.js +2 -0
- package/dist/shared/common/src/services/transactionSender.d.ts +24 -0
- package/dist/shared/common/src/services/transactionSender.js +30 -0
- package/dist/shared/common/src/types/cpi.d.ts +34 -0
- package/dist/shared/common/src/types/cpi.js +8 -0
- package/dist/shared/common/src/types/enums.d.ts +59 -0
- package/dist/shared/common/src/types/enums.js +122 -0
- package/dist/shared/common/src/types/general.d.ts +38 -0
- package/dist/shared/common/src/types/general.js +2 -0
- package/dist/shared/common/src/types/index.d.ts +4 -0
- package/dist/shared/common/src/types/index.js +20 -0
- package/dist/shared/common/src/types/solana.d.ts +24 -0
- package/dist/shared/common/src/types/solana.js +2 -0
- package/dist/shared/common/src/utils/accounts/index.d.ts +5 -0
- package/dist/shared/common/src/utils/accounts/index.js +21 -0
- package/dist/shared/common/src/utils/accounts/meta.d.ts +21 -0
- package/dist/shared/common/src/utils/accounts/meta.js +27 -0
- package/dist/shared/common/src/utils/accounts/pda.d.ts +2 -0
- package/dist/shared/common/src/utils/accounts/pda.js +17 -0
- package/dist/shared/common/src/utils/accounts/roles.d.ts +26 -0
- package/dist/shared/common/src/utils/accounts/roles.js +54 -0
- package/dist/shared/common/src/utils/accounts/rpc.d.ts +8 -0
- package/dist/shared/common/src/utils/accounts/rpc.js +30 -0
- package/dist/shared/common/src/utils/accounts/splBalances.d.ts +15 -0
- package/dist/shared/common/src/utils/accounts/splBalances.js +52 -0
- package/dist/shared/common/src/utils/anchor.d.ts +17 -0
- package/dist/shared/common/src/utils/anchor.js +29 -0
- package/dist/shared/common/src/utils/asyncConcurrency.d.ts +5 -0
- package/dist/shared/common/src/utils/asyncConcurrency.js +28 -0
- package/dist/shared/common/src/utils/compat.d.ts +46 -0
- package/dist/shared/common/src/utils/compat.js +72 -0
- package/dist/shared/common/src/utils/cpi/args.d.ts +69 -0
- package/dist/shared/common/src/utils/cpi/args.js +100 -0
- package/dist/shared/common/src/utils/cpi/index.d.ts +2 -0
- package/dist/shared/common/src/utils/cpi/index.js +18 -0
- package/dist/shared/common/src/utils/cpi/refs.d.ts +122 -0
- package/dist/shared/common/src/utils/cpi/refs.js +234 -0
- package/dist/shared/common/src/utils/data.d.ts +20 -0
- package/dist/shared/common/src/utils/data.js +27 -0
- package/dist/shared/common/src/utils/general.d.ts +24 -0
- package/dist/shared/common/src/utils/general.js +95 -0
- package/dist/shared/common/src/utils/index.d.ts +22 -0
- package/dist/shared/common/src/utils/index.js +38 -0
- package/dist/shared/common/src/utils/instruction.d.ts +74 -0
- package/dist/shared/common/src/utils/instruction.js +147 -0
- package/dist/shared/common/src/utils/jito.d.ts +113 -0
- package/dist/shared/common/src/utils/jito.js +178 -0
- package/dist/shared/common/src/utils/json.d.ts +5 -0
- package/dist/shared/common/src/utils/json.js +25 -0
- package/dist/shared/common/src/utils/jsonRpcFetch.d.ts +21 -0
- package/dist/shared/common/src/utils/jsonRpcFetch.js +134 -0
- package/dist/shared/common/src/utils/metadata.d.ts +107 -0
- package/dist/shared/common/src/utils/metadata.js +194 -0
- package/dist/shared/common/src/utils/numbers.d.ts +72 -0
- package/dist/shared/common/src/utils/numbers.js +193 -0
- package/dist/shared/common/src/utils/priorityFee.d.ts +18 -0
- package/dist/shared/common/src/utils/priorityFee.js +63 -0
- package/dist/shared/common/src/utils/retry.d.ts +20 -0
- package/dist/shared/common/src/utils/retry.js +69 -0
- package/dist/shared/common/src/utils/rpc.d.ts +40 -0
- package/dist/shared/common/src/utils/rpc.js +130 -0
- package/dist/shared/common/src/utils/solana.d.ts +23 -0
- package/dist/shared/common/src/utils/solana.js +61 -0
- package/dist/shared/common/src/utils/timeSeries.d.ts +18 -0
- package/dist/shared/common/src/utils/timeSeries.js +40 -0
- package/dist/shared/common/src/utils/token.d.ts +33 -0
- package/dist/shared/common/src/utils/token.js +82 -0
- package/dist/shared/common/src/utils/transaction.d.ts +154 -0
- package/dist/shared/common/src/utils/transaction.js +585 -0
- package/dist/shared/common/src/utils/transactionSplitter.d.ts +85 -0
- package/dist/shared/common/src/utils/transactionSplitter.js +127 -0
- package/dist/shared/common/src/utils/txAccountCoverage.d.ts +49 -0
- package/dist/shared/common/src/utils/txAccountCoverage.js +122 -0
- package/dist/shared/jupiter-helpers/src/api.d.ts +59 -0
- package/dist/shared/jupiter-helpers/src/api.js +130 -0
- package/dist/shared/jupiter-helpers/src/client.d.ts +79 -0
- package/dist/shared/jupiter-helpers/src/client.js +173 -0
- package/dist/shared/jupiter-helpers/src/constants.d.ts +35 -0
- package/dist/shared/jupiter-helpers/src/constants.js +38 -0
- package/dist/shared/jupiter-helpers/src/extract.d.ts +30 -0
- package/dist/shared/jupiter-helpers/src/extract.js +57 -0
- package/dist/shared/jupiter-helpers/src/index.d.ts +5 -0
- package/dist/shared/jupiter-helpers/src/index.js +21 -0
- package/dist/shared/jupiter-helpers/src/routePreInstructions.d.ts +19 -0
- package/dist/shared/jupiter-helpers/src/routePreInstructions.js +61 -0
- package/dist/shared/jupiter-helpers/src/sizeExactInForMinOutput.d.ts +70 -0
- package/dist/shared/jupiter-helpers/src/sizeExactInForMinOutput.js +95 -0
- package/dist/shared/jupiter-helpers/src/types.d.ts +66 -0
- package/dist/shared/jupiter-helpers/src/types.js +2 -0
- package/dist/shared/lending-platforms/src/constants/cache.d.ts +8 -0
- package/dist/shared/lending-platforms/src/constants/cache.js +11 -0
- package/dist/shared/lending-platforms/src/constants/index.d.ts +3 -0
- package/dist/shared/lending-platforms/src/constants/index.js +19 -0
- package/dist/shared/lending-platforms/src/constants/kamino.d.ts +7 -0
- package/dist/shared/lending-platforms/src/constants/kamino.js +83 -0
- package/dist/shared/lending-platforms/src/constants/lendingPosition.d.ts +7 -0
- package/dist/shared/lending-platforms/src/constants/lendingPosition.js +10 -0
- package/dist/shared/lending-platforms/src/data/accounts/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/data/accounts/index.js +18 -0
- package/dist/shared/lending-platforms/src/data/accounts/kamino.d.ts +42 -0
- package/dist/shared/lending-platforms/src/data/accounts/kamino.js +104 -0
- package/dist/shared/lending-platforms/src/data/accounts/lpAccountsBase.d.ts +7 -0
- package/dist/shared/lending-platforms/src/data/accounts/lpAccountsBase.js +9 -0
- package/dist/shared/lending-platforms/src/data/incentive/incentiveBase.d.ts +35 -0
- package/dist/shared/lending-platforms/src/data/incentive/incentiveBase.js +26 -0
- package/dist/shared/lending-platforms/src/data/incentive/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/data/incentive/index.js +18 -0
- package/dist/shared/lending-platforms/src/data/incentive/kamino.d.ts +55 -0
- package/dist/shared/lending-platforms/src/data/incentive/kamino.js +101 -0
- package/dist/shared/lending-platforms/src/data/index.d.ts +6 -0
- package/dist/shared/lending-platforms/src/data/index.js +22 -0
- package/dist/shared/lending-platforms/src/data/instructions/index.d.ts +3 -0
- package/dist/shared/lending-platforms/src/data/instructions/index.js +19 -0
- package/dist/shared/lending-platforms/src/data/instructions/kamino.d.ts +55 -0
- package/dist/shared/lending-platforms/src/data/instructions/kamino.js +630 -0
- package/dist/shared/lending-platforms/src/data/instructions/lpInstructionsBase.d.ts +175 -0
- package/dist/shared/lending-platforms/src/data/instructions/lpInstructionsBase.js +192 -0
- package/dist/shared/lending-platforms/src/data/instructions/types.d.ts +7 -0
- package/dist/shared/lending-platforms/src/data/instructions/types.js +2 -0
- package/dist/shared/lending-platforms/src/data/platform/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/data/platform/index.js +18 -0
- package/dist/shared/lending-platforms/src/data/platform/kamino.d.ts +59 -0
- package/dist/shared/lending-platforms/src/data/platform/kamino.js +206 -0
- package/dist/shared/lending-platforms/src/data/platform/lpDataBase.d.ts +35 -0
- package/dist/shared/lending-platforms/src/data/platform/lpDataBase.js +31 -0
- package/dist/shared/lending-platforms/src/data/reserve/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/data/reserve/index.js +18 -0
- package/dist/shared/lending-platforms/src/data/reserve/kamino.d.ts +45 -0
- package/dist/shared/lending-platforms/src/data/reserve/kamino.js +141 -0
- package/dist/shared/lending-platforms/src/data/reserve/reserveBase.d.ts +114 -0
- package/dist/shared/lending-platforms/src/data/reserve/reserveBase.js +125 -0
- package/dist/shared/lending-platforms/src/data/userPosition/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/data/userPosition/index.js +18 -0
- package/dist/shared/lending-platforms/src/data/userPosition/kamino.d.ts +15 -0
- package/dist/shared/lending-platforms/src/data/userPosition/kamino.js +45 -0
- package/dist/shared/lending-platforms/src/data/userPosition/userPositionBase.d.ts +50 -0
- package/dist/shared/lending-platforms/src/data/userPosition/userPositionBase.js +63 -0
- package/dist/shared/lending-platforms/src/index.d.ts +5 -0
- package/dist/shared/lending-platforms/src/index.js +21 -0
- package/dist/shared/lending-platforms/src/services/client/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/services/client/index.js +18 -0
- package/dist/shared/lending-platforms/src/services/client/kamino.d.ts +53 -0
- package/dist/shared/lending-platforms/src/services/client/kamino.js +142 -0
- package/dist/shared/lending-platforms/src/services/client/lpClientBase.d.ts +66 -0
- package/dist/shared/lending-platforms/src/services/client/lpClientBase.js +19 -0
- package/dist/shared/lending-platforms/src/services/flashLoan/flashLoanBase.d.ts +49 -0
- package/dist/shared/lending-platforms/src/services/flashLoan/flashLoanBase.js +16 -0
- package/dist/shared/lending-platforms/src/services/flashLoan/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/services/flashLoan/index.js +18 -0
- package/dist/shared/lending-platforms/src/services/flashLoan/kamino.d.ts +11 -0
- package/dist/shared/lending-platforms/src/services/flashLoan/kamino.js +85 -0
- package/dist/shared/lending-platforms/src/services/index.d.ts +5 -0
- package/dist/shared/lending-platforms/src/services/index.js +21 -0
- package/dist/shared/lending-platforms/src/services/lendingPosition/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/services/lendingPosition/index.js +18 -0
- package/dist/shared/lending-platforms/src/services/lendingPosition/lendingPositionManager.d.ts +117 -0
- package/dist/shared/lending-platforms/src/services/lendingPosition/lendingPositionManager.js +342 -0
- package/dist/shared/lending-platforms/src/services/lendingPosition/types.d.ts +40 -0
- package/dist/shared/lending-platforms/src/services/lendingPosition/types.js +2 -0
- package/dist/shared/lending-platforms/src/services/leverage/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/services/leverage/index.js +18 -0
- package/dist/shared/lending-platforms/src/services/leverage/leverageService.d.ts +104 -0
- package/dist/shared/lending-platforms/src/services/leverage/leverageService.js +437 -0
- package/dist/shared/lending-platforms/src/services/leverage/types.d.ts +261 -0
- package/dist/shared/lending-platforms/src/services/leverage/types.js +2 -0
- package/dist/shared/lending-platforms/src/services/reservesManager.d.ts +53 -0
- package/dist/shared/lending-platforms/src/services/reservesManager.js +112 -0
- package/dist/shared/lending-platforms/src/types/general.d.ts +37 -0
- package/dist/shared/lending-platforms/src/types/general.js +8 -0
- package/dist/shared/lending-platforms/src/types/index.d.ts +2 -0
- package/dist/shared/lending-platforms/src/types/index.js +18 -0
- package/dist/shared/lending-platforms/src/types/kamino.d.ts +10 -0
- package/dist/shared/lending-platforms/src/types/kamino.js +2 -0
- package/dist/shared/lending-platforms/src/utils/accounts.d.ts +16 -0
- package/dist/shared/lending-platforms/src/utils/accounts.js +36 -0
- package/dist/shared/lending-platforms/src/utils/cache.d.ts +3 -0
- package/dist/shared/lending-platforms/src/utils/cache.js +11 -0
- package/dist/shared/lending-platforms/src/utils/index.d.ts +6 -0
- package/dist/shared/lending-platforms/src/utils/index.js +22 -0
- package/dist/shared/lending-platforms/src/utils/kamino.d.ts +87 -0
- package/dist/shared/lending-platforms/src/utils/kamino.js +190 -0
- package/dist/shared/lending-platforms/src/utils/lendingPlatform.d.ts +6 -0
- package/dist/shared/lending-platforms/src/utils/lendingPlatform.js +16 -0
- package/dist/shared/lending-platforms/src/utils/math.d.ts +47 -0
- package/dist/shared/lending-platforms/src/utils/math.js +123 -0
- package/dist/shared/lending-platforms/src/utils/scope.d.ts +38 -0
- package/dist/shared/lending-platforms/src/utils/scope.js +144 -0
- package/dist/shared/oracle-service/src/constants/index.d.ts +3 -0
- package/dist/shared/oracle-service/src/constants/index.js +19 -0
- package/dist/shared/oracle-service/src/constants/pyth.d.ts +7 -0
- package/dist/shared/oracle-service/src/constants/pyth.js +71 -0
- package/dist/shared/oracle-service/src/constants/splStake.d.ts +2 -0
- package/dist/shared/oracle-service/src/constants/splStake.js +6 -0
- package/dist/shared/oracle-service/src/constants/switchboard.d.ts +7 -0
- package/dist/shared/oracle-service/src/constants/switchboard.js +10 -0
- package/dist/shared/oracle-service/src/feeds/custom.d.ts +30 -0
- package/dist/shared/oracle-service/src/feeds/custom.js +56 -0
- package/dist/shared/oracle-service/src/feeds/jupiter.d.ts +7 -0
- package/dist/shared/oracle-service/src/feeds/jupiter.js +43 -0
- package/dist/shared/oracle-service/src/feeds/priceBase.d.ts +13 -0
- package/dist/shared/oracle-service/src/feeds/priceBase.js +25 -0
- package/dist/shared/oracle-service/src/feeds/pyth.d.ts +8 -0
- package/dist/shared/oracle-service/src/feeds/pyth.js +59 -0
- package/dist/shared/oracle-service/src/feeds/splStake.d.ts +26 -0
- package/dist/shared/oracle-service/src/feeds/splStake.js +99 -0
- package/dist/shared/oracle-service/src/feeds/switchboard.d.ts +6 -0
- package/dist/shared/oracle-service/src/feeds/switchboard.js +11 -0
- package/dist/shared/oracle-service/src/index.d.ts +5 -0
- package/dist/shared/oracle-service/src/index.js +26 -0
- package/dist/shared/oracle-service/src/oracle.d.ts +22 -0
- package/dist/shared/oracle-service/src/oracle.js +104 -0
- package/dist/shared/oracle-service/src/types.d.ts +4 -0
- package/dist/shared/oracle-service/src/types.js +2 -0
- package/dist/shared/oracle-service/src/utils/general.d.ts +20 -0
- package/dist/shared/oracle-service/src/utils/general.js +65 -0
- package/dist/shared/oracle-service/src/utils/index.d.ts +1 -0
- package/dist/shared/oracle-service/src/utils/index.js +17 -0
- package/dist/shared/perena-helpers/src/accounts.d.ts +7 -0
- package/dist/shared/perena-helpers/src/accounts.js +12 -0
- package/dist/shared/perena-helpers/src/client.d.ts +299 -0
- package/dist/shared/perena-helpers/src/client.js +680 -0
- package/dist/shared/perena-helpers/src/constants.d.ts +5 -0
- package/dist/shared/perena-helpers/src/constants.js +8 -0
- package/dist/shared/perena-helpers/src/cpi/burn.d.ts +27 -0
- package/dist/shared/perena-helpers/src/cpi/burn.js +22 -0
- package/dist/shared/perena-helpers/src/cpi/index.d.ts +3 -0
- package/dist/shared/perena-helpers/src/cpi/index.js +19 -0
- package/dist/shared/perena-helpers/src/cpi/mint.d.ts +27 -0
- package/dist/shared/perena-helpers/src/cpi/mint.js +22 -0
- package/dist/shared/perena-helpers/src/cpi/requestUnstake.d.ts +19 -0
- package/dist/shared/perena-helpers/src/cpi/requestUnstake.js +16 -0
- package/dist/shared/perena-helpers/src/index.d.ts +5 -0
- package/dist/shared/perena-helpers/src/index.js +21 -0
- package/dist/shared/perena-helpers/src/utils.d.ts +9 -0
- package/dist/shared/perena-helpers/src/utils.js +54 -0
- package/dist/shared/swap-aggregator/src/aggSwapClient.d.ts +71 -0
- package/dist/shared/swap-aggregator/src/aggSwapClient.js +103 -0
- package/dist/shared/swap-aggregator/src/index.d.ts +1 -0
- package/dist/shared/swap-aggregator/src/index.js +17 -0
- package/docs/launchingToken.md +57 -0
- package/package.json +75 -0
- package/scripts/asyncBurn.ts +155 -0
- package/scripts/burnToken.ts +120 -0
- package/scripts/claimIncentives.ts +125 -0
- package/scripts/closeCpiPlans.ts +113 -0
- package/scripts/collectInterest.ts +194 -0
- package/scripts/collectProtocolFees.ts +144 -0
- package/scripts/computeOptimalAllocations.ts +117 -0
- package/scripts/createToken.ts +100 -0
- package/scripts/createTokenLendingPosition.ts +204 -0
- package/scripts/createYieldingBank.ts +91 -0
- package/scripts/decreaseCarryPositions.ts +359 -0
- package/scripts/depositUnlentCollateral.ts +106 -0
- package/scripts/emergency/deleverageAll.ts +287 -0
- package/scripts/emergency/triggerCircuitBreaker.ts +87 -0
- package/scripts/env.ts +4 -0
- package/scripts/findTxs.ts +169 -0
- package/scripts/increaseCarryPositions.ts +134 -0
- package/scripts/inspect/format.ts +576 -0
- package/scripts/inspect.ts +147 -0
- package/scripts/localUtils.ts +249 -0
- package/scripts/mintToken.ts +126 -0
- package/scripts/processAsyncBurns.ts +89 -0
- package/scripts/rebalanceToken.ts +269 -0
- package/scripts/rebalanceYieldingBank.ts +183 -0
- package/scripts/recollateralizeLoss.ts +79 -0
- package/scripts/refresh.ts +156 -0
- package/scripts/updateFees.ts +486 -0
- package/scripts/updateGeneralLut.ts +36 -0
- package/scripts/updateLendingPositionConfig.ts +172 -0
- package/scripts/updateTokenLuts.ts +36 -0
- package/scripts/updateTokenMetadata.ts +199 -0
- package/scripts/updateYieldingBankConfig.ts +100 -0
- package/scripts/withdrawUnlentCollateral.ts +178 -0
- package/src/client/account.ts +503 -0
- package/src/client/builders/args.ts +381 -0
- package/src/client/builders/asyncBurnBuilder.ts +305 -0
- package/src/client/builders/base.ts +303 -0
- package/src/client/builders/burnTokenBuilder.ts +258 -0
- package/src/client/builders/claimIncentivesBuilder.ts +211 -0
- package/src/client/builders/collectFeesBuilder.ts +52 -0
- package/src/client/builders/collectInterestBuilder.ts +165 -0
- package/src/client/builders/createCpiPlanBuilder.ts +21 -0
- package/src/client/builders/createTokenBuilder.ts +73 -0
- package/src/client/builders/createTokenLendingPositionBuilder.ts +219 -0
- package/src/client/builders/createYieldingBankAllocationBuilder.ts +32 -0
- package/src/client/builders/createYieldingBankBuilder.ts +39 -0
- package/src/client/builders/decreaseCarryPositionBuilder.ts +162 -0
- package/src/client/builders/depositUnlentCollateralBuilder.ts +95 -0
- package/src/client/builders/increaseCarryPositionBuilder.ts +105 -0
- package/src/client/builders/index.ts +37 -0
- package/src/client/builders/mintTokenBuilder.ts +137 -0
- package/src/client/builders/rebalanceTokenBuilder.ts +356 -0
- package/src/client/builders/rebalanceYieldingBankBuilder.ts +109 -0
- package/src/client/builders/recollateralizeLossBuilder.ts +367 -0
- package/src/client/builders/refreshTokenStateBuilder.ts +153 -0
- package/src/client/builders/refreshTokensBuilder.ts +82 -0
- package/src/client/builders/refreshYieldingBankBuilder.ts +42 -0
- package/src/client/builders/resetTokenBurnRateLimitBuilder.ts +21 -0
- package/src/client/builders/setTokenCircuitBreakerBuilder.ts +40 -0
- package/src/client/builders/setYieldingBankCircuitBreakerBuilder.ts +37 -0
- package/src/client/builders/updateLendingPositionConfigBuilder.ts +33 -0
- package/src/client/builders/updateTokenConfigurationBuilder.ts +50 -0
- package/src/client/builders/updateTokenMetadataBuilder.ts +24 -0
- package/src/client/builders/updateYieldingBankConfigBuilder.ts +32 -0
- package/src/client/builders/utils.ts +26 -0
- package/src/client/client.ts +264 -0
- package/src/client/externalLiquidityResolver.ts +54 -0
- package/src/client/index.ts +20 -0
- package/src/client/lendingPlatformClients.ts +50 -0
- package/src/client/pda.ts +102 -0
- package/src/client/plans/collectInterest.ts +207 -0
- package/src/client/plans/decreaseCarryPosition.ts +226 -0
- package/src/client/routes/collectInterest.ts +56 -0
- package/src/client/transaction.ts +106 -0
- package/src/client/types/builders.ts +19 -0
- package/src/client/types/enums.ts +47 -0
- package/src/client/types/general.ts +117 -0
- package/src/client/types/index.ts +6 -0
- package/src/client/types/ix.ts +452 -0
- package/src/client/types/planTypes/collectInterest.ts +97 -0
- package/src/client/types/planTypes/common.ts +31 -0
- package/src/client/types/planTypes/decreaseCarryPosition.ts +134 -0
- package/src/client/types/planTypes/index.ts +3 -0
- package/src/client/types/tx.ts +409 -0
- package/src/constants/configs/allocations.ts +30 -0
- package/src/constants/configs/carryTradePresets.ts +164 -0
- package/src/constants/configs/index.ts +2 -0
- package/src/constants/general.ts +141 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/lycTokenMetadata.ts +52 -0
- package/src/decoders/decodeTransaction.ts +319 -0
- package/src/decoders/discriminators.ts +10 -0
- package/src/decoders/idlAccounts.ts +75 -0
- package/src/decoders/index.ts +15 -0
- package/src/decoders/innerCpis.ts +262 -0
- package/src/decoders/lycInstructionNames.ts +73 -0
- package/src/decoders/programIds.ts +12 -0
- package/src/decoders/solana.ts +25 -0
- package/src/decoders/transactionPayload.ts +41 -0
- package/src/decoders/types.ts +60 -0
- package/src/errors.ts +195 -0
- package/src/idl/long_yield_carry.ts +14648 -0
- package/src/index.ts +10 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/protocolMetrics.ts +976 -0
- package/src/models/index.ts +9 -0
- package/src/models/lycToken.ts +380 -0
- package/src/models/yieldingBank.ts +127 -0
- package/src/services/allocation/allocationService.ts +823 -0
- package/src/services/allocation/index.ts +2 -0
- package/src/services/allocation/types.ts +27 -0
- package/src/services/carry/carryAllocationConfig.ts +266 -0
- package/src/services/carry/index.ts +2 -0
- package/src/services/carry/lycLendingPositionManager.ts +167 -0
- package/src/services/index.ts +5 -0
- package/src/services/lendingPosition/index.ts +5 -0
- package/src/services/lendingPosition/lendingPositionService.ts +328 -0
- package/src/services/rebalance/index.ts +2 -0
- package/src/services/rebalance/token/index.ts +1 -0
- package/src/services/rebalance/token/tokenRebalanceService.ts +142 -0
- package/src/services/rebalance/yieldingBank/index.ts +3 -0
- package/src/services/rebalance/yieldingBank/planner.ts +215 -0
- package/src/services/rebalance/yieldingBank/strategy.ts +41 -0
- package/src/services/rebalance/yieldingBank/types.ts +41 -0
- package/src/services/redemption/index.ts +9 -0
- package/src/services/redemption/redemptionService.ts +758 -0
- package/src/types/enriched.ts +187 -0
- package/src/types/index.ts +1 -0
- package/src/utils/cache.ts +12 -0
- package/src/utils/data.ts +65 -0
- package/src/utils/enrichment.ts +330 -0
- package/src/utils/feeDripMetrics.ts +146 -0
- package/src/utils/general.ts +54 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/ix.ts +227 -0
- package/src/utils/lendingPosition.ts +221 -0
- package/src/utils/lookupTables.ts +309 -0
- package/src/utils/lycData.ts +321 -0
- package/src/utils/timelock.ts +63 -0
- package/src/utils/tokenFeeMath.ts +25 -0
- package/src/utils/transactions.ts +109 -0
- package/src/utils/yieldingBank.ts +38 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { type Address, type TransactionSigner } from "@solana/kit";
|
|
2
|
+
import { fromWeb3Pk, LendingPlatform, mints, toBigInt } from "common";
|
|
3
|
+
import type { LongYieldCarryClient } from "../../client/client";
|
|
4
|
+
import type { LongYieldCarryTransactionPlan } from "../../client/types";
|
|
5
|
+
import { LendingPositionBootstrapError } from "../../errors";
|
|
6
|
+
import type { IndexedLendingPosition, LYCToken } from "../../models/lycToken";
|
|
7
|
+
import {
|
|
8
|
+
getAvailableTokenLendingUserAccountId,
|
|
9
|
+
resolveDefaultPool,
|
|
10
|
+
updateTokenLutIfNeeded,
|
|
11
|
+
} from "../../utils";
|
|
12
|
+
import { AllocationService } from "../allocation";
|
|
13
|
+
import { computeConfigForCollateral } from "../carry/carryAllocationConfig";
|
|
14
|
+
|
|
15
|
+
export interface OptimalLendingPosition {
|
|
16
|
+
/** The lending position selected. */
|
|
17
|
+
lp: IndexedLendingPosition;
|
|
18
|
+
/** Debt mint of the selected position. */
|
|
19
|
+
debtMint: Address;
|
|
20
|
+
/** Human-readable symbol of the debt mint. */
|
|
21
|
+
debtSymbol: string;
|
|
22
|
+
/** Whether this position uses the optimal debt mint (true) or is the best available fallback. */
|
|
23
|
+
isOptimal: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type LogFn = (msg: string) => void;
|
|
27
|
+
|
|
28
|
+
export interface EnsureInitialKaminoLendingPositionOptions {
|
|
29
|
+
manager: TransactionSigner;
|
|
30
|
+
/** When set, refreshes the per-token LUT after the new LP is created. */
|
|
31
|
+
lutManager?: TransactionSigner;
|
|
32
|
+
token: LYCToken;
|
|
33
|
+
sendPlan: (plan: LongYieldCarryTransactionPlan, label: string) => Promise<void>;
|
|
34
|
+
log?: LogFn;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Shared logic for choosing and interacting with a token's lending positions
|
|
39
|
+
* based on allocation optimality. Used by {@link RedemptionService} (to
|
|
40
|
+
* prioritize which positions to unwind) and by deposit scripts / backend
|
|
41
|
+
* services (to deposit into the best position).
|
|
42
|
+
*/
|
|
43
|
+
export class LendingPositionService {
|
|
44
|
+
constructor(private readonly client: LongYieldCarryClient) {}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns the lending position whose debt mint matches the current optimal
|
|
48
|
+
* allocation. If no position matches the optimal mint, returns the position
|
|
49
|
+
* with the most collateral as a fallback.
|
|
50
|
+
*
|
|
51
|
+
* Returns `null` only when the token has no active lending positions.
|
|
52
|
+
*/
|
|
53
|
+
async findOptimalLendingPosition(
|
|
54
|
+
token: LYCToken,
|
|
55
|
+
log?: LogFn
|
|
56
|
+
): Promise<OptimalLendingPosition | null> {
|
|
57
|
+
const usedLps = token.usedLendingPositions;
|
|
58
|
+
if (usedLps.length === 0) {
|
|
59
|
+
const activeLps = token.activeLendingPositions;
|
|
60
|
+
if (activeLps.length === 0) return null;
|
|
61
|
+
// Freshly created slots have zero collateral until the first deposit.
|
|
62
|
+
log?.("No collateral on any LP yet — using first active slot");
|
|
63
|
+
return this.toLpResult(activeLps[0], true);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (usedLps.length === 1) {
|
|
67
|
+
return this.toLpResult(usedLps[0], true);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const optimalMint = await this.findOptimalDebtMint(token, log);
|
|
71
|
+
if (optimalMint) {
|
|
72
|
+
const match = usedLps.find(
|
|
73
|
+
(lp) => fromWeb3Pk(lp.data.accounting.debt.mint) === optimalMint.mint
|
|
74
|
+
);
|
|
75
|
+
if (match) {
|
|
76
|
+
log?.(`Using optimal LP[${match.index}] (debt: ${optimalMint.symbol})`);
|
|
77
|
+
return this.toLpResult(match, true);
|
|
78
|
+
}
|
|
79
|
+
log?.(`No LP matches optimal debt mint ${optimalMint.symbol} — using largest LP`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const largest = this.largestLp(usedLps);
|
|
83
|
+
return this.toLpResult(largest, false);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sorts lending positions so non-optimal debt mints come first. Useful for
|
|
88
|
+
* choosing which positions to unwind during redemptions — non-optimal
|
|
89
|
+
* positions are unwound first to preserve the best-yielding ones.
|
|
90
|
+
*
|
|
91
|
+
* Returns the original order if there's only one LP or the optimal mint
|
|
92
|
+
* lookup fails.
|
|
93
|
+
*/
|
|
94
|
+
async sortByOptimality(
|
|
95
|
+
token: LYCToken,
|
|
96
|
+
lps: IndexedLendingPosition[],
|
|
97
|
+
log?: LogFn
|
|
98
|
+
): Promise<IndexedLendingPosition[]> {
|
|
99
|
+
if (lps.length <= 1) return lps;
|
|
100
|
+
|
|
101
|
+
const optimalMint = await this.findOptimalDebtMint(token, log);
|
|
102
|
+
if (!optimalMint) return lps;
|
|
103
|
+
|
|
104
|
+
log?.(`Optimal debt mint: ${optimalMint.symbol} — prioritizing non-optimal LPs for unwind`);
|
|
105
|
+
|
|
106
|
+
const nonOptimal = lps.filter(
|
|
107
|
+
(lp) => fromWeb3Pk(lp.data.accounting.debt.mint) !== optimalMint.mint
|
|
108
|
+
);
|
|
109
|
+
const optimal = lps.filter(
|
|
110
|
+
(lp) => fromWeb3Pk(lp.data.accounting.debt.mint) === optimalMint.mint
|
|
111
|
+
);
|
|
112
|
+
return [...nonOptimal, ...optimal];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Opens the first Kamino lending position on a token that has none yet.
|
|
117
|
+
*
|
|
118
|
+
* Mirrors `scripts/createTokenLendingPosition.ts` and the create-LP branch in
|
|
119
|
+
* `TokenRebalanceWorker`: resolve pool + optimal debt mint, compute carry
|
|
120
|
+
* allocation config, send `createTokenLendingPosition`, then refetch the token.
|
|
121
|
+
*
|
|
122
|
+
* Kamino-specific: the flow resolves the default Kamino pool, fetches Kamino
|
|
123
|
+
* reserves, and uses {@link AllocationService} over Kamino reserve data. It is
|
|
124
|
+
* named accordingly until a second lending platform actually needs bootstrap
|
|
125
|
+
* support (avoid speculative platform abstraction with a single implementation).
|
|
126
|
+
*
|
|
127
|
+
* No-op when the token already has at least one active lending position slot.
|
|
128
|
+
*
|
|
129
|
+
* @throws {LendingPositionBootstrapError} when the token cannot be bootstrapped
|
|
130
|
+
* because of a permanent configuration gap (collateral mint not in any pool,
|
|
131
|
+
* no preset, no viable debt mint / reserve). Callers should treat this as a
|
|
132
|
+
* skip rather than a retryable failure.
|
|
133
|
+
*/
|
|
134
|
+
async ensureInitialKaminoLendingPosition(
|
|
135
|
+
options: EnsureInitialKaminoLendingPositionOptions
|
|
136
|
+
): Promise<LYCToken> {
|
|
137
|
+
const { manager, lutManager, token, sendPlan, log } = options;
|
|
138
|
+
|
|
139
|
+
if (token.activeLendingPositions.length > 0) {
|
|
140
|
+
return token;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
log?.("No lending positions — creating initial LP");
|
|
144
|
+
|
|
145
|
+
let pool: Address;
|
|
146
|
+
try {
|
|
147
|
+
pool = resolveDefaultPool(token.collateralMint);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
throw new LendingPositionBootstrapError(
|
|
150
|
+
`Cannot resolve a default pool for ${token.label} (${token.collateralMint}): ${
|
|
151
|
+
err instanceof Error ? err.message : String(err)
|
|
152
|
+
}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const kamino = this.client.getLendingPlatformClientByPlatform(LendingPlatform.Kamino);
|
|
157
|
+
const collateralReserve = await kamino.data.fetchReserveByMint(pool, token.collateralMint);
|
|
158
|
+
if (!collateralReserve) {
|
|
159
|
+
throw new LendingPositionBootstrapError(
|
|
160
|
+
`No Kamino reserve found for collateral ${token.label} (${token.collateralMint}) in pool ${pool}`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const yieldingBanks = await this.client.account.fetchAllYieldingBanks();
|
|
165
|
+
const allocationService = new AllocationService(kamino.data, { logger: log, yieldingBanks });
|
|
166
|
+
const optimalDebt = await allocationService.findOptimalDebtMint(pool, collateralReserve, token);
|
|
167
|
+
if (!optimalDebt) {
|
|
168
|
+
throw new LendingPositionBootstrapError(
|
|
169
|
+
`No viable debt mint found for ${token.label} on pool ${pool}`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
log?.(
|
|
174
|
+
`Selected debt mint ${optimalDebt.symbol} (borrow APY ${(optimalDebt.borrowApy * 100).toFixed(3)}%)`
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const debtReserve = await kamino.data.fetchReserveByMint(pool, optimalDebt.mint);
|
|
178
|
+
if (!debtReserve) {
|
|
179
|
+
throw new LendingPositionBootstrapError(
|
|
180
|
+
`No Kamino reserve found for debt mint ${optimalDebt.symbol} (${optimalDebt.mint})`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let config: ReturnType<typeof computeConfigForCollateral>;
|
|
185
|
+
try {
|
|
186
|
+
config = computeConfigForCollateral({
|
|
187
|
+
collateralMint: token.collateralMint,
|
|
188
|
+
collateralReserve,
|
|
189
|
+
debtReserve,
|
|
190
|
+
});
|
|
191
|
+
} catch (err) {
|
|
192
|
+
throw new LendingPositionBootstrapError(
|
|
193
|
+
`No carry allocation config for ${token.label} (${token.collateralMint}): ${
|
|
194
|
+
err instanceof Error ? err.message : String(err)
|
|
195
|
+
}`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const userAccountId = await getAvailableTokenLendingUserAccountId({
|
|
200
|
+
lendingClient: kamino,
|
|
201
|
+
token,
|
|
202
|
+
pool,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const label = `create-initial-lp-${token.label}-${optimalDebt.symbol}`;
|
|
206
|
+
const plan = await this.client.tx.createTokenLendingPosition.getTx({
|
|
207
|
+
token: token.address,
|
|
208
|
+
debtMint: optimalDebt.mint,
|
|
209
|
+
userAccountId,
|
|
210
|
+
pool,
|
|
211
|
+
...config,
|
|
212
|
+
});
|
|
213
|
+
await sendPlan(plan, label);
|
|
214
|
+
log?.(`Sent createTokenLendingPosition (${plan.instructions.length} ix)`);
|
|
215
|
+
|
|
216
|
+
this.client.clearAllCache();
|
|
217
|
+
const freshToken = await this.client.account.fetchToken(token.address, { fresh: true });
|
|
218
|
+
|
|
219
|
+
if (lutManager) {
|
|
220
|
+
try {
|
|
221
|
+
await updateTokenLutIfNeeded(lutManager, this.client.rpc, this.client, freshToken);
|
|
222
|
+
log?.("Updated per-token LUT after initial lending position");
|
|
223
|
+
} catch (err) {
|
|
224
|
+
log?.(`updateTokenLutIfNeeded failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (freshToken.activeLendingPositions.length === 0) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`Initial lending position creation completed but ${token.label} still has no active LPs`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return freshToken;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Deposits unlent collateral into the optimal lending position. Refreshes
|
|
239
|
+
* the token state first, then deposits all unlent collateral into the
|
|
240
|
+
* position returned by {@link findOptimalLendingPosition}.
|
|
241
|
+
*/
|
|
242
|
+
async depositToOptimalPosition(
|
|
243
|
+
signer: TransactionSigner,
|
|
244
|
+
token: LYCToken,
|
|
245
|
+
log?: LogFn
|
|
246
|
+
): Promise<{ signature: string; lendingPositionIndex: number; debtSymbol: string }> {
|
|
247
|
+
const optimal = await this.findOptimalLendingPosition(token, log);
|
|
248
|
+
if (!optimal) {
|
|
249
|
+
throw new Error(`Token ${token.address} has no used lending positions to deposit into`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
log?.(
|
|
253
|
+
`Depositing unlent collateral into LP[${optimal.lp.index}] (debt: ${optimal.debtSymbol})...`
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const refreshPlan = await this.client.tx.refreshTokens.getTx({
|
|
257
|
+
signer: signer.address,
|
|
258
|
+
params: { tokens: [token.address] },
|
|
259
|
+
});
|
|
260
|
+
await this.client.sendTransaction(signer, refreshPlan);
|
|
261
|
+
this.client.clearAllCache();
|
|
262
|
+
|
|
263
|
+
const depositPlan = await this.client.tx.depositUnlentCollateral.getTx({
|
|
264
|
+
manager: signer.address,
|
|
265
|
+
token: token.address,
|
|
266
|
+
params: {
|
|
267
|
+
lendingPositionIndex: optimal.lp.index,
|
|
268
|
+
depositAll: true,
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
const sig = await this.client.sendTransaction(signer, depositPlan);
|
|
272
|
+
this.client.clearAllCache();
|
|
273
|
+
log?.(`Deposit done: ${sig}`);
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
signature: sig,
|
|
277
|
+
lendingPositionIndex: optimal.lp.index,
|
|
278
|
+
debtSymbol: optimal.debtSymbol,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ── Private ─────────────────────────────────────────────────────────────
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Queries `AllocationService.findOptimalDebtMint` for the token's
|
|
286
|
+
* pool + collateral pair. Returns null on any failure (missing reserve, etc.).
|
|
287
|
+
*/
|
|
288
|
+
private async findOptimalDebtMint(
|
|
289
|
+
token: LYCToken,
|
|
290
|
+
log?: LogFn
|
|
291
|
+
): Promise<{ mint: Address; symbol: string } | null> {
|
|
292
|
+
try {
|
|
293
|
+
const firstLp = token.usedLendingPositions[0]?.data;
|
|
294
|
+
if (!firstLp) return null;
|
|
295
|
+
|
|
296
|
+
const pool = fromWeb3Pk(firstLp.pool);
|
|
297
|
+
const kaminoData = this.client.getLendingPlatformClientByPlatform(
|
|
298
|
+
LendingPlatform.Kamino
|
|
299
|
+
).data;
|
|
300
|
+
const collateralReserve = await kaminoData.fetchReserve(
|
|
301
|
+
pool,
|
|
302
|
+
fromWeb3Pk(firstLp.collateralReserve)
|
|
303
|
+
);
|
|
304
|
+
if (!collateralReserve) return null;
|
|
305
|
+
|
|
306
|
+
const yieldingBanks = await this.client.account.fetchAllYieldingBanks();
|
|
307
|
+
const allocationService = new AllocationService(kaminoData, { yieldingBanks });
|
|
308
|
+
return await allocationService.findOptimalDebtMint(pool, collateralReserve, token);
|
|
309
|
+
} catch (err) {
|
|
310
|
+
log?.(`Optimal debt mint lookup failed: ${err instanceof Error ? err.message : err}`);
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private largestLp(lps: IndexedLendingPosition[]): IndexedLendingPosition {
|
|
316
|
+
return lps.reduce((best, lp) =>
|
|
317
|
+
toBigInt(lp.data.accounting.collateral) > toBigInt(best.data.accounting.collateral)
|
|
318
|
+
? lp
|
|
319
|
+
: best
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private toLpResult(lp: IndexedLendingPosition, isOptimal: boolean): OptimalLendingPosition {
|
|
324
|
+
const debtMint = fromWeb3Pk(lp.data.accounting.debt.mint);
|
|
325
|
+
const debtSymbol = mints.get(debtMint)?.symbol ?? debtMint.slice(0, 6);
|
|
326
|
+
return { lp, debtMint, debtSymbol, isOptimal };
|
|
327
|
+
}
|
|
328
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tokenRebalanceService";
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
import { ExactInQuoteExceedsMaxInputError } from "jupiter-helpers";
|
|
3
|
+
import { FlashRebalanceSwapCostExceededError } from "lending-platforms";
|
|
4
|
+
import { NoOpTransactionError } from "../../../errors";
|
|
5
|
+
import type { LYCToken } from "../../../models/lycToken";
|
|
6
|
+
import type { LongYieldCarryTransactionPlan } from "../../../client/types";
|
|
7
|
+
import type { DebtAllocationTarget, DebtReallocation } from "../../allocation/types";
|
|
8
|
+
import type { LongYieldCarryClient } from "../../../client/client";
|
|
9
|
+
import { REBALANCE_TOKEN_RATE_LIMIT_SECS } from "../../../constants/general";
|
|
10
|
+
import { mints } from "common";
|
|
11
|
+
|
|
12
|
+
export type RebalancePlanResult =
|
|
13
|
+
| { outcome: "skipped"; reason: string }
|
|
14
|
+
| { outcome: "plan"; plan: LongYieldCarryTransactionPlan; label: string };
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Shared logic for building a token rebalance plan from a {@link DebtReallocation}.
|
|
18
|
+
* Callers are responsible for sending the returned plan (and any post-send steps such as
|
|
19
|
+
* excess-rent reclaim).
|
|
20
|
+
*/
|
|
21
|
+
export interface TokenRebalanceServiceOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Maximum acceptable execution cost (route fees + price impact) of the
|
|
24
|
+
* rebalance swap quote vs the oracle-fair cross rate, in bps. Candidates
|
|
25
|
+
* quoting worse are skipped — that cost is permanently lost value.
|
|
26
|
+
* Unset = no limit.
|
|
27
|
+
*/
|
|
28
|
+
maxSwapCostBps?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum acceptable market basis between the two debt stables, in bps
|
|
31
|
+
* either direction. Bounds how much mark-to-market difference the $1-pinned
|
|
32
|
+
* books absorb per conversion, and blocks rebalancing through a depegging
|
|
33
|
+
* stable. Unset = no limit.
|
|
34
|
+
*/
|
|
35
|
+
maxMarketBasisBps?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class TokenRebalanceService {
|
|
39
|
+
constructor(
|
|
40
|
+
private readonly client: LongYieldCarryClient,
|
|
41
|
+
private readonly options: TokenRebalanceServiceOptions = {}
|
|
42
|
+
) {}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Validates a reallocation and builds the rebalance transaction plan.
|
|
46
|
+
* If the primary targets fail due to insufficient borrow/swap capacity
|
|
47
|
+
* ({@link ExactInQuoteExceedsMaxInputError}), retries with each fallback
|
|
48
|
+
* option in order before giving up.
|
|
49
|
+
*
|
|
50
|
+
* Returns `{ outcome: "skipped" }` for benign no-ops (inactive token, no active LP for the
|
|
51
|
+
* reallocation index, no targets). Throws on unexpected errors from the builder.
|
|
52
|
+
*/
|
|
53
|
+
async buildPlan(token: LYCToken, realloc: DebtReallocation): Promise<RebalancePlanResult> {
|
|
54
|
+
if (!token.isActive) {
|
|
55
|
+
return { outcome: "skipped", reason: "token inactive (circuit breaker)" };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const lpIndex = realloc.lendingPositionIndex;
|
|
59
|
+
const lp = token.activeLendingPositions.find((p) => p.index === lpIndex);
|
|
60
|
+
if (!lp) {
|
|
61
|
+
return { outcome: "skipped", reason: `no active lending position at index ${lpIndex}` };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Rate limit: the program rejects a rebalance on a position touched within
|
|
65
|
+
// REBALANCE_TOKEN_RATE_LIMIT_SECS (RebalanceRateLimited). Skip client-side
|
|
66
|
+
// so we don't build a transaction that would revert on-chain.
|
|
67
|
+
const lastUpdatedTs = Number(lp.data.lastUpdatedTs.toString());
|
|
68
|
+
const nowSecs = Math.floor(Date.now() / 1000);
|
|
69
|
+
const elapsed = nowSecs - lastUpdatedTs;
|
|
70
|
+
if (lastUpdatedTs > 0 && elapsed < REBALANCE_TOKEN_RATE_LIMIT_SECS) {
|
|
71
|
+
const hoursLeft = ((REBALANCE_TOKEN_RATE_LIMIT_SECS - elapsed) / 3600).toFixed(1);
|
|
72
|
+
const reason =
|
|
73
|
+
`lp${lpIndex} rebalanced ${(elapsed / 3600).toFixed(1)}h ago; ` +
|
|
74
|
+
`rate limit is ${REBALANCE_TOKEN_RATE_LIMIT_SECS / 3600}h (${hoursLeft}h remaining)`;
|
|
75
|
+
console.log(`Skip token ${token.address.slice(0, 8)}…: ${reason}`);
|
|
76
|
+
return { outcome: "skipped", reason };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const label = `rebalance-token-${token.address.slice(0, 8)}-lp${lpIndex}`;
|
|
80
|
+
const allOptions = [realloc.targets, ...(realloc.fallbackTargets ?? [])];
|
|
81
|
+
|
|
82
|
+
for (const targets of allOptions) {
|
|
83
|
+
const targetMint = targets[0]?.mint;
|
|
84
|
+
if (!targetMint) continue;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const plan = await this.client.tx.rebalanceToken.getTx({
|
|
88
|
+
token: token.address,
|
|
89
|
+
params: {
|
|
90
|
+
lpIndex,
|
|
91
|
+
destinationDebtMint: targetMint,
|
|
92
|
+
uiAmount: "all",
|
|
93
|
+
maxSwapCostBps: this.options.maxSwapCostBps,
|
|
94
|
+
maxMarketBasisBps: this.options.maxMarketBasisBps,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
return { outcome: "plan", plan, label };
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (err instanceof NoOpTransactionError) {
|
|
100
|
+
return { outcome: "skipped", reason: err.message };
|
|
101
|
+
}
|
|
102
|
+
if (err instanceof FlashRebalanceSwapCostExceededError) {
|
|
103
|
+
const symbol = mints.get(targetMint)?.symbol ?? targetMint.slice(0, 6);
|
|
104
|
+
console.log(
|
|
105
|
+
`Skip ${symbol}: swap ${err.reason} over ${err.limitBps} bps limit ` +
|
|
106
|
+
`(execution cost ${err.executionCostBps.toFixed(2)} bps, ` +
|
|
107
|
+
`market basis ${err.marketBasisBps.toFixed(2)} bps); trying next candidate`
|
|
108
|
+
);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (err instanceof ExactInQuoteExceedsMaxInputError) {
|
|
112
|
+
const symbol = mints.get(targetMint)?.symbol ?? targetMint.slice(0, 6);
|
|
113
|
+
console.log(
|
|
114
|
+
`Skip ${symbol}: borrow capacity (${err.maxInputAmount}) < swap input (${err.inputAmount}); trying next candidate`
|
|
115
|
+
);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (err instanceof Error && err.message.includes("no available borrow capacity")) {
|
|
119
|
+
const symbol = mints.get(targetMint)?.symbol ?? targetMint.slice(0, 6);
|
|
120
|
+
console.log(`Skip ${symbol}: no available borrow capacity; trying next candidate`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
outcome: "skipped",
|
|
129
|
+
reason:
|
|
130
|
+
"all candidates exhausted — insufficient borrow/swap capacity or swap cost above limit for each",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Convenience: fetch a fresh token then call {@link buildPlan}. */
|
|
135
|
+
async fetchAndBuildPlan(
|
|
136
|
+
tokenAddress: Address,
|
|
137
|
+
realloc: DebtReallocation
|
|
138
|
+
): Promise<RebalancePlanResult> {
|
|
139
|
+
const token = await this.client.account.fetchToken(tokenAddress, { fresh: true });
|
|
140
|
+
return this.buildPlan(token, realloc);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { Address } from "@solana/kit";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { applyBps, fromWeb3Pk, toBigInt } from "common";
|
|
4
|
+
import type { RebalanceSwapSpec, YieldingBankAllocationConfig } from "../../../client/types";
|
|
5
|
+
import type { LYCYieldingBank } from "../../../models";
|
|
6
|
+
import type { AllocationStrategy } from "./strategy";
|
|
7
|
+
import type { AllocationTarget, YieldingBankRebalancePlan } from "./types";
|
|
8
|
+
|
|
9
|
+
/** Minimum 6-decimal stablecoin amount worth swapping: 0.01 token (~$0.01). */
|
|
10
|
+
const MIN_STABLE_SWAP_AMOUNT = 10_000;
|
|
11
|
+
|
|
12
|
+
interface HoldingSnapshot {
|
|
13
|
+
mint: Address;
|
|
14
|
+
amount: bigint;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Computes the swaps needed to move a yielding bank from its current
|
|
19
|
+
* asset distribution to a target allocation.
|
|
20
|
+
*
|
|
21
|
+
* The planner is stateless and performs no RPC — it operates entirely on
|
|
22
|
+
* the in-memory bank model and the strategy's target. This makes it
|
|
23
|
+
* straightforward to unit-test.
|
|
24
|
+
*
|
|
25
|
+
* ## How it works
|
|
26
|
+
*
|
|
27
|
+
* 1. The {@link AllocationStrategy} produces a {@link TargetAllocation}
|
|
28
|
+
* (e.g. 25% USD*, 75% USD*-J).
|
|
29
|
+
* 2. The planner classifies every bank holding as either a **target**
|
|
30
|
+
* (a mint the strategy manages) or an **idle source** (everything
|
|
31
|
+
* else — the base asset, plus any non-target stablecoins that
|
|
32
|
+
* arrived from borrows in other denominations).
|
|
33
|
+
* 3. Each idle source with a non-trivial balance gets its own
|
|
34
|
+
* {@link YieldingBankRebalancePlan} that deploys its capital
|
|
35
|
+
* proportionally across the targets according to their weights.
|
|
36
|
+
* 4. If existing target holdings are imbalanced relative to their
|
|
37
|
+
* weights (overweight / underweight), a separate rebalance plan
|
|
38
|
+
* routes through the base mint. The resulting swaps are sorted
|
|
39
|
+
* sells-first so freed base-mint liquidity is available for
|
|
40
|
+
* subsequent buy swaps.
|
|
41
|
+
*
|
|
42
|
+
* All swaps route through the bank's base mint as the common
|
|
43
|
+
* intermediate, matching how the on-chain `rebalance_yielding_bank`
|
|
44
|
+
* instruction processes CPI swaps.
|
|
45
|
+
*/
|
|
46
|
+
export class RebalancePlanner {
|
|
47
|
+
constructor(private readonly strategy: AllocationStrategy) {}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Plan the rebalance for a single yielding bank.
|
|
51
|
+
* Returns an empty array if no action is needed.
|
|
52
|
+
*
|
|
53
|
+
* Each element is an independent plan that can be sent as its own
|
|
54
|
+
* transaction. Separate plans are produced for:
|
|
55
|
+
* - Each idle source (base asset, or non-target stablecoins)
|
|
56
|
+
* - Target-to-target rebalancing (selling overweight, buying underweight)
|
|
57
|
+
*/
|
|
58
|
+
plan(bank: LYCYieldingBank): YieldingBankRebalancePlan[] {
|
|
59
|
+
const targets = this.strategy.computeTarget(bank);
|
|
60
|
+
const targetMints = new Set(targets.map((t) => t.mint));
|
|
61
|
+
|
|
62
|
+
const idleSources = this.discoverIdleSources(bank, targetMints);
|
|
63
|
+
const targetHoldings = this.snapshotTargetHoldings(bank, targetMints);
|
|
64
|
+
|
|
65
|
+
const plans: YieldingBankRebalancePlan[] = [];
|
|
66
|
+
|
|
67
|
+
for (const source of idleSources) {
|
|
68
|
+
const plan = this.buildDeploymentPlan(bank, targets, source);
|
|
69
|
+
if (plan) plans.push(plan);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const rebalancePlan = this.buildTargetRebalancePlan(bank, targets, targetHoldings);
|
|
73
|
+
if (rebalancePlan) plans.push(rebalancePlan);
|
|
74
|
+
|
|
75
|
+
return plans;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// Idle source discovery
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns every holding on the bank that is NOT a strategy target.
|
|
84
|
+
* This includes the base asset and any non-target asset slots with
|
|
85
|
+
* a positive balance (e.g. a stablecoin that arrived from a
|
|
86
|
+
* non-base-mint borrow).
|
|
87
|
+
*/
|
|
88
|
+
private discoverIdleSources(bank: LYCYieldingBank, targetMints: Set<string>): HoldingSnapshot[] {
|
|
89
|
+
const sources: HoldingSnapshot[] = [];
|
|
90
|
+
|
|
91
|
+
const baseAmount = toBigInt(bank.data.baseAsset.amount);
|
|
92
|
+
if (baseAmount > 0n) {
|
|
93
|
+
sources.push({ mint: bank.baseMint, amount: baseAmount });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (const asset of bank.data.assets) {
|
|
97
|
+
if (asset.mint.equals(PublicKey.default)) continue;
|
|
98
|
+
const mint = fromWeb3Pk(asset.mint);
|
|
99
|
+
if (targetMints.has(mint)) continue;
|
|
100
|
+
const amount = toBigInt(asset.amount);
|
|
101
|
+
if (amount > 0n) {
|
|
102
|
+
sources.push({ mint, amount });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return sources;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Snapshot only the holdings that ARE strategy targets. */
|
|
110
|
+
private snapshotTargetHoldings(
|
|
111
|
+
bank: LYCYieldingBank,
|
|
112
|
+
targetMints: Set<string>
|
|
113
|
+
): HoldingSnapshot[] {
|
|
114
|
+
const result: HoldingSnapshot[] = [];
|
|
115
|
+
|
|
116
|
+
for (const asset of bank.data.assets) {
|
|
117
|
+
if (asset.mint.equals(PublicKey.default)) continue;
|
|
118
|
+
const mint = fromWeb3Pk(asset.mint);
|
|
119
|
+
if (!targetMints.has(mint)) continue;
|
|
120
|
+
result.push({ mint, amount: toBigInt(asset.amount) });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// Plan builders
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Build a plan that deploys a single idle source proportionally
|
|
132
|
+
* across the strategy's targets according to their weights.
|
|
133
|
+
*/
|
|
134
|
+
private buildDeploymentPlan(
|
|
135
|
+
bank: LYCYieldingBank,
|
|
136
|
+
targets: AllocationTarget[],
|
|
137
|
+
source: HoldingSnapshot
|
|
138
|
+
): YieldingBankRebalancePlan | null {
|
|
139
|
+
if (source.amount < BigInt(MIN_STABLE_SWAP_AMOUNT)) return null;
|
|
140
|
+
|
|
141
|
+
const swaps: RebalanceSwapSpec[] = [];
|
|
142
|
+
let newAllocation: { config: YieldingBankAllocationConfig } | undefined;
|
|
143
|
+
|
|
144
|
+
for (const alloc of targets) {
|
|
145
|
+
const share = applyBps(source.amount, alloc.weightBps);
|
|
146
|
+
if (Number(share) < MIN_STABLE_SWAP_AMOUNT) continue;
|
|
147
|
+
|
|
148
|
+
swaps.push({
|
|
149
|
+
inputMint: source.mint,
|
|
150
|
+
outputMint: alloc.mint,
|
|
151
|
+
amount: Number(share),
|
|
152
|
+
slippageBps: alloc.slippageBps,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (!newAllocation && bank.findAssetHolding(alloc.mint) === null) {
|
|
156
|
+
newAllocation = { config: alloc.allocationConfig };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (swaps.length === 0 && !newAllocation) return null;
|
|
161
|
+
return { swaps, newAllocation };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Build a plan that rebalances between existing target holdings when
|
|
166
|
+
* they've drifted from the strategy's desired weights. Overweight
|
|
167
|
+
* targets are sold back to the base mint; underweight targets are
|
|
168
|
+
* bought with the freed base.
|
|
169
|
+
*/
|
|
170
|
+
private buildTargetRebalancePlan(
|
|
171
|
+
bank: LYCYieldingBank,
|
|
172
|
+
targets: AllocationTarget[],
|
|
173
|
+
targetHoldings: HoldingSnapshot[]
|
|
174
|
+
): YieldingBankRebalancePlan | null {
|
|
175
|
+
const totalTargetValue = targetHoldings.reduce((sum, h) => sum + h.amount, 0n);
|
|
176
|
+
if (totalTargetValue <= 0n) return null;
|
|
177
|
+
|
|
178
|
+
const swaps: RebalanceSwapSpec[] = [];
|
|
179
|
+
|
|
180
|
+
for (const alloc of targets) {
|
|
181
|
+
const desired = applyBps(totalTargetValue, alloc.weightBps);
|
|
182
|
+
const current = this.findCurrentAmount(targetHoldings, alloc.mint);
|
|
183
|
+
const delta = desired - current;
|
|
184
|
+
const absDelta = delta < 0n ? -delta : delta;
|
|
185
|
+
|
|
186
|
+
if (Number(absDelta) < MIN_STABLE_SWAP_AMOUNT) continue;
|
|
187
|
+
|
|
188
|
+
if (delta < 0n) {
|
|
189
|
+
swaps.push({
|
|
190
|
+
inputMint: alloc.mint,
|
|
191
|
+
outputMint: bank.baseMint,
|
|
192
|
+
amount: Number(absDelta),
|
|
193
|
+
slippageBps: alloc.slippageBps,
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
swaps.push({
|
|
197
|
+
inputMint: bank.baseMint,
|
|
198
|
+
outputMint: alloc.mint,
|
|
199
|
+
amount: Number(delta),
|
|
200
|
+
slippageBps: alloc.slippageBps,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (swaps.length === 0) return null;
|
|
206
|
+
swaps.sort(
|
|
207
|
+
(a, b) => (a.inputMint === bank.baseMint ? 1 : 0) - (b.inputMint === bank.baseMint ? 1 : 0)
|
|
208
|
+
);
|
|
209
|
+
return { swaps };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private findCurrentAmount(holdings: HoldingSnapshot[], mint: string): bigint {
|
|
213
|
+
return holdings.find((h) => h.mint === mint)?.amount ?? 0n;
|
|
214
|
+
}
|
|
215
|
+
}
|