@exponent-labs/exponent-sdk 0.1.8 → 0.9.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/build/CodamaEventDecoder.d.ts +49 -0
- package/build/CodamaEventDecoder.js +113 -0
- package/build/CodamaEventDecoder.js.map +1 -0
- package/build/addressLookupTableUtil.d.ts +23 -18
- package/build/addressLookupTableUtil.js +31 -5
- package/build/addressLookupTableUtil.js.map +1 -1
- package/build/client/clmm/accounts/lpPosition.d.ts +29 -0
- package/build/client/clmm/accounts/lpPosition.js +82 -0
- package/build/client/clmm/accounts/lpPosition.js.map +1 -0
- package/build/client/clmm/accounts/marketThree.d.ts +47 -0
- package/build/client/clmm/accounts/marketThree.js +139 -0
- package/build/client/clmm/accounts/marketThree.js.map +1 -0
- package/build/client/clmm/accounts/vault.d.ts +48 -0
- package/build/client/clmm/accounts/vault.js +128 -0
- package/build/client/clmm/accounts/vault.js.map +1 -0
- package/build/client/clmm/eventRegistry.d.ts +59 -0
- package/build/client/clmm/eventRegistry.js +58 -0
- package/build/client/clmm/eventRegistry.js.map +1 -0
- package/build/client/clmm/index.d.ts +78 -0
- package/build/client/clmm/index.js +96 -0
- package/build/client/clmm/index.js.map +1 -0
- package/build/client/clmm/instructions/addFarm.d.ts +19 -0
- package/build/client/clmm/instructions/addFarm.js +31 -0
- package/build/client/clmm/instructions/addFarm.js.map +1 -0
- package/build/client/clmm/instructions/addLiquidity.d.ts +26 -0
- package/build/client/clmm/instructions/addLiquidity.js +38 -0
- package/build/client/clmm/instructions/addLiquidity.js.map +1 -0
- package/build/client/clmm/instructions/addMarketEmission.d.ts +15 -0
- package/build/client/clmm/instructions/addMarketEmission.js +27 -0
- package/build/client/clmm/instructions/addMarketEmission.js.map +1 -0
- package/build/client/clmm/instructions/buyPt.d.ts +24 -0
- package/build/client/clmm/instructions/buyPt.js +36 -0
- package/build/client/clmm/instructions/buyPt.js.map +1 -0
- package/build/client/clmm/instructions/buyYt.d.ts +26 -0
- package/build/client/clmm/instructions/buyYt.js +42 -0
- package/build/client/clmm/instructions/buyYt.js.map +1 -0
- package/build/client/clmm/instructions/claimFarmEmission.d.ts +18 -0
- package/build/client/clmm/instructions/claimFarmEmission.js +30 -0
- package/build/client/clmm/instructions/claimFarmEmission.js.map +1 -0
- package/build/client/clmm/instructions/closeMarket.d.ts +17 -0
- package/build/client/clmm/instructions/closeMarket.js +26 -0
- package/build/client/clmm/instructions/closeMarket.js.map +1 -0
- package/build/client/clmm/instructions/depositLiquidity.d.ts +25 -0
- package/build/client/clmm/instructions/depositLiquidity.js +37 -0
- package/build/client/clmm/instructions/depositLiquidity.js.map +1 -0
- package/build/client/clmm/instructions/initializeMarket.d.ts +47 -0
- package/build/client/clmm/instructions/initializeMarket.js +63 -0
- package/build/client/clmm/instructions/initializeMarket.js.map +1 -0
- package/build/client/clmm/instructions/marketAccrueEmission.d.ts +13 -0
- package/build/client/clmm/instructions/marketAccrueEmission.js +22 -0
- package/build/client/clmm/instructions/marketAccrueEmission.js.map +1 -0
- package/build/client/clmm/instructions/marketCollectEmission.d.ts +18 -0
- package/build/client/clmm/instructions/marketCollectEmission.js +30 -0
- package/build/client/clmm/instructions/marketCollectEmission.js.map +1 -0
- package/build/client/clmm/instructions/modifyFarm.d.ts +17 -0
- package/build/client/clmm/instructions/modifyFarm.js +29 -0
- package/build/client/clmm/instructions/modifyFarm.js.map +1 -0
- package/build/client/clmm/instructions/modifyMarketSetting.d.ts +11 -0
- package/build/client/clmm/instructions/modifyMarketSetting.js +23 -0
- package/build/client/clmm/instructions/modifyMarketSetting.js.map +1 -0
- package/build/client/clmm/instructions/sellPt.d.ts +24 -0
- package/build/client/clmm/instructions/sellPt.js +36 -0
- package/build/client/clmm/instructions/sellPt.js.map +1 -0
- package/build/client/clmm/instructions/sellYt.d.ts +26 -0
- package/build/client/clmm/instructions/sellYt.js +42 -0
- package/build/client/clmm/instructions/sellYt.js.map +1 -0
- package/build/client/clmm/instructions/tradePt.d.ts +25 -0
- package/build/client/clmm/instructions/tradePt.js +37 -0
- package/build/client/clmm/instructions/tradePt.js.map +1 -0
- package/build/client/clmm/instructions/tradePtExactOut.d.ts +25 -0
- package/build/client/clmm/instructions/tradePtExactOut.js +37 -0
- package/build/client/clmm/instructions/tradePtExactOut.js.map +1 -0
- package/build/client/clmm/instructions/withdrawLiquidity.d.ts +23 -0
- package/build/client/clmm/instructions/withdrawLiquidity.js +35 -0
- package/build/client/clmm/instructions/withdrawLiquidity.js.map +1 -0
- package/build/client/clmm/instructions/wrapperBuyYt.d.ts +28 -0
- package/build/client/clmm/instructions/wrapperBuyYt.js +48 -0
- package/build/client/clmm/instructions/wrapperBuyYt.js.map +1 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidity.d.ts +33 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidity.js +53 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidity.js.map +1 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidityBase.d.ts +32 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidityBase.js +52 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidityBase.js.map +1 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidityClassic.d.ts +28 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidityClassic.js +44 -0
- package/build/client/clmm/instructions/wrapperProvideLiquidityClassic.js.map +1 -0
- package/build/client/clmm/instructions/wrapperSellYt.d.ts +27 -0
- package/build/client/clmm/instructions/wrapperSellYt.js +47 -0
- package/build/client/clmm/instructions/wrapperSellYt.js.map +1 -0
- package/build/client/clmm/instructions/wrapperWithdrawLiquidity.d.ts +25 -0
- package/build/client/clmm/instructions/wrapperWithdrawLiquidity.js +41 -0
- package/build/client/clmm/instructions/wrapperWithdrawLiquidity.js.map +1 -0
- package/build/client/clmm/instructions/wrapperWithdrawLiquidityClassic.d.ts +22 -0
- package/build/client/clmm/instructions/wrapperWithdrawLiquidityClassic.js +38 -0
- package/build/client/clmm/instructions/wrapperWithdrawLiquidityClassic.js.map +1 -0
- package/build/client/clmm/types/addFarmEvent.d.ts +35 -0
- package/build/client/clmm/types/addFarmEvent.js +24 -0
- package/build/client/clmm/types/addFarmEvent.js.map +1 -0
- package/build/client/clmm/types/amount.d.ts +33 -0
- package/build/client/clmm/types/amount.js +20 -0
- package/build/client/clmm/types/amount.js.map +1 -0
- package/build/client/clmm/types/buyPtEvent.d.ts +23 -0
- package/build/client/clmm/types/buyPtEvent.js +18 -0
- package/build/client/clmm/types/buyPtEvent.js.map +1 -0
- package/build/client/clmm/types/buyYtEvent.d.ts +56 -0
- package/build/client/clmm/types/buyYtEvent.js +36 -0
- package/build/client/clmm/types/buyYtEvent.js.map +1 -0
- package/build/client/clmm/types/claimFarmEmissionsEvent.d.ts +171 -0
- package/build/client/clmm/types/claimFarmEmissionsEvent.js +42 -0
- package/build/client/clmm/types/claimFarmEmissionsEvent.js.map +1 -0
- package/build/client/clmm/types/claimLimits.d.ts +22 -0
- package/build/client/clmm/types/claimLimits.js +11 -0
- package/build/client/clmm/types/claimLimits.js.map +1 -0
- package/build/client/clmm/types/closeMarketEvent.d.ts +23 -0
- package/build/client/clmm/types/closeMarketEvent.js +18 -0
- package/build/client/clmm/types/closeMarketEvent.js.map +1 -0
- package/build/client/clmm/types/configurationOptions.d.ts +34 -0
- package/build/client/clmm/types/configurationOptions.js +14 -0
- package/build/client/clmm/types/configurationOptions.js.map +1 -0
- package/build/client/clmm/types/cpiAccounts.d.ts +107 -0
- package/build/client/clmm/types/cpiAccounts.js +13 -0
- package/build/client/clmm/types/cpiAccounts.js.map +1 -0
- package/build/client/clmm/types/cpiCoreAccounts.d.ts +47 -0
- package/build/client/clmm/types/cpiCoreAccounts.js +10 -0
- package/build/client/clmm/types/cpiCoreAccounts.js.map +1 -0
- package/build/client/clmm/types/cpiInterfaceContext.d.ts +18 -0
- package/build/client/clmm/types/cpiInterfaceContext.js +10 -0
- package/build/client/clmm/types/cpiInterfaceContext.js.map +1 -0
- package/build/client/clmm/types/crossingSplit.d.ts +124 -0
- package/build/client/clmm/types/crossingSplit.js +20 -0
- package/build/client/clmm/types/crossingSplit.js.map +1 -0
- package/build/client/clmm/types/depositLiquidityEvent.d.ts +171 -0
- package/build/client/clmm/types/depositLiquidityEvent.js +42 -0
- package/build/client/clmm/types/depositLiquidityEvent.js.map +1 -0
- package/build/client/clmm/types/depositLiquidityReturnData.d.ts +67 -0
- package/build/client/clmm/types/depositLiquidityReturnData.js +38 -0
- package/build/client/clmm/types/depositLiquidityReturnData.js.map +1 -0
- package/build/client/clmm/types/emissionInfo.d.ts +36 -0
- package/build/client/clmm/types/emissionInfo.js +22 -0
- package/build/client/clmm/types/emissionInfo.js.map +1 -0
- package/build/client/clmm/types/farmEmission.d.ts +24 -0
- package/build/client/clmm/types/farmEmission.js +16 -0
- package/build/client/clmm/types/farmEmission.js.map +1 -0
- package/build/client/clmm/types/index.d.ts +48 -0
- package/build/client/clmm/types/index.js +65 -0
- package/build/client/clmm/types/index.js.map +1 -0
- package/build/client/clmm/types/liquidityNetBalanceLimits.d.ts +26 -0
- package/build/client/clmm/types/liquidityNetBalanceLimits.js +12 -0
- package/build/client/clmm/types/liquidityNetBalanceLimits.js.map +1 -0
- package/build/client/clmm/types/lpFarm.d.ts +35 -0
- package/build/client/clmm/types/lpFarm.js +10 -0
- package/build/client/clmm/types/lpFarm.js.map +1 -0
- package/build/client/clmm/types/marketAccrueEmissionEvent.d.ts +151 -0
- package/build/client/clmm/types/marketAccrueEmissionEvent.js +31 -0
- package/build/client/clmm/types/marketAccrueEmissionEvent.js.map +1 -0
- package/build/client/clmm/types/marketAdminAction.d.ts +359 -0
- package/build/client/clmm/types/marketAdminAction.js +72 -0
- package/build/client/clmm/types/marketAdminAction.js.map +1 -0
- package/build/client/clmm/types/marketCollectEmissionEvent.d.ts +163 -0
- package/build/client/clmm/types/marketCollectEmissionEvent.js +37 -0
- package/build/client/clmm/types/marketCollectEmissionEvent.js.map +1 -0
- package/build/client/clmm/types/marketEmission.d.ts +20 -0
- package/build/client/clmm/types/marketEmission.js +15 -0
- package/build/client/clmm/types/marketEmission.js.map +1 -0
- package/build/client/clmm/types/marketEmissions.d.ts +27 -0
- package/build/client/clmm/types/marketEmissions.js +9 -0
- package/build/client/clmm/types/marketEmissions.js.map +1 -0
- package/build/client/clmm/types/marketFinancials.d.ts +26 -0
- package/build/client/clmm/types/marketFinancials.js +12 -0
- package/build/client/clmm/types/marketFinancials.js.map +1 -0
- package/build/client/clmm/types/marketThreeInitEvent.d.ts +71 -0
- package/build/client/clmm/types/marketThreeInitEvent.js +42 -0
- package/build/client/clmm/types/marketThreeInitEvent.js.map +1 -0
- package/build/client/clmm/types/mergeEvent.d.ts +84 -0
- package/build/client/clmm/types/mergeEvent.js +55 -0
- package/build/client/clmm/types/mergeEvent.js.map +1 -0
- package/build/client/clmm/types/modifiedTick.d.ts +18 -0
- package/build/client/clmm/types/modifiedTick.js +10 -0
- package/build/client/clmm/types/modifiedTick.js.map +1 -0
- package/build/client/clmm/types/modifiedTicks.d.ts +43 -0
- package/build/client/clmm/types/modifiedTicks.js +13 -0
- package/build/client/clmm/types/modifiedTicks.js.map +1 -0
- package/build/client/clmm/types/modifyFarmEvent.d.ts +43 -0
- package/build/client/clmm/types/modifyFarmEvent.js +26 -0
- package/build/client/clmm/types/modifyFarmEvent.js.map +1 -0
- package/build/client/clmm/types/number.d.ts +2 -0
- package/build/client/clmm/types/number.js +8 -0
- package/build/client/clmm/types/number.js.map +1 -0
- package/build/client/clmm/types/personalYieldTracker.d.ts +15 -0
- package/build/client/clmm/types/personalYieldTracker.js +10 -0
- package/build/client/clmm/types/personalYieldTracker.js.map +1 -0
- package/build/client/clmm/types/personalYieldTrackers.d.ts +23 -0
- package/build/client/clmm/types/personalYieldTrackers.js +9 -0
- package/build/client/clmm/types/personalYieldTrackers.js.map +1 -0
- package/build/client/clmm/types/principalShare.d.ts +51 -0
- package/build/client/clmm/types/principalShare.js +14 -0
- package/build/client/clmm/types/principalShare.js.map +1 -0
- package/build/client/clmm/types/principalShareTrackers.d.ts +63 -0
- package/build/client/clmm/types/principalShareTrackers.js +9 -0
- package/build/client/clmm/types/principalShareTrackers.js.map +1 -0
- package/build/client/clmm/types/sellPtEvent.d.ts +23 -0
- package/build/client/clmm/types/sellPtEvent.js +18 -0
- package/build/client/clmm/types/sellPtEvent.js.map +1 -0
- package/build/client/clmm/types/sellYtEvent.d.ts +47 -0
- package/build/client/clmm/types/sellYtEvent.js +33 -0
- package/build/client/clmm/types/sellYtEvent.js.map +1 -0
- package/build/client/clmm/types/stripEvent.d.ts +84 -0
- package/build/client/clmm/types/stripEvent.js +58 -0
- package/build/client/clmm/types/stripEvent.js.map +1 -0
- package/build/client/clmm/types/swapDirection.d.ts +5 -0
- package/build/client/clmm/types/swapDirection.js +11 -0
- package/build/client/clmm/types/swapDirection.js.map +1 -0
- package/build/client/clmm/types/tradePtEvent.d.ts +110 -0
- package/build/client/clmm/types/tradePtEvent.js +37 -0
- package/build/client/clmm/types/tradePtEvent.js.map +1 -0
- package/build/client/clmm/types/withdrawLiquidityEvent.d.ts +183 -0
- package/build/client/clmm/types/withdrawLiquidityEvent.js +45 -0
- package/build/client/clmm/types/withdrawLiquidityEvent.js.map +1 -0
- package/build/client/clmm/types/withdrawLiquidityReturnData.d.ts +46 -0
- package/build/client/clmm/types/withdrawLiquidityReturnData.js +17 -0
- package/build/client/clmm/types/withdrawLiquidityReturnData.js.map +1 -0
- package/build/client/clmm/types/wrapperBuyYtEvent.d.ts +23 -0
- package/build/client/clmm/types/wrapperBuyYtEvent.js +18 -0
- package/build/client/clmm/types/wrapperBuyYtEvent.js.map +1 -0
- package/build/client/clmm/types/wrapperProvideLiquidityBaseEvent.d.ts +56 -0
- package/build/client/clmm/types/wrapperProvideLiquidityBaseEvent.js +30 -0
- package/build/client/clmm/types/wrapperProvideLiquidityBaseEvent.js.map +1 -0
- package/build/client/clmm/types/wrapperProvideLiquidityClassicEvent.d.ts +52 -0
- package/build/client/clmm/types/wrapperProvideLiquidityClassicEvent.js +29 -0
- package/build/client/clmm/types/wrapperProvideLiquidityClassicEvent.js.map +1 -0
- package/build/client/clmm/types/wrapperProvideLiquidityEvent.d.ts +56 -0
- package/build/client/clmm/types/wrapperProvideLiquidityEvent.js +30 -0
- package/build/client/clmm/types/wrapperProvideLiquidityEvent.js.map +1 -0
- package/build/client/clmm/types/wrapperSellYtEvent.d.ts +23 -0
- package/build/client/clmm/types/wrapperSellYtEvent.js +18 -0
- package/build/client/clmm/types/wrapperSellYtEvent.js.map +1 -0
- package/build/client/clmm/types/wrapperWithdrawLiquidityClassicEvent.d.ts +60 -0
- package/build/client/clmm/types/wrapperWithdrawLiquidityClassicEvent.js +31 -0
- package/build/client/clmm/types/wrapperWithdrawLiquidityClassicEvent.js.map +1 -0
- package/build/client/clmm/types/wrapperWithdrawLiquidityEvent.d.ts +60 -0
- package/build/client/clmm/types/wrapperWithdrawLiquidityEvent.js +31 -0
- package/build/client/clmm/types/wrapperWithdrawLiquidityEvent.js.map +1 -0
- package/build/client/core/accounts/admin.d.ts +18 -0
- package/build/client/core/accounts/admin.js +71 -0
- package/build/client/core/accounts/admin.js.map +1 -0
- package/build/client/core/accounts/lpPosition.d.ts +20 -0
- package/build/client/core/accounts/lpPosition.js +73 -0
- package/build/client/core/accounts/lpPosition.js.map +1 -0
- package/build/client/core/accounts/marketTwo.d.ts +42 -0
- package/build/client/core/accounts/marketTwo.js +122 -0
- package/build/client/core/accounts/marketTwo.js.map +1 -0
- package/build/client/core/accounts/vault.d.ts +48 -0
- package/build/client/core/accounts/vault.js +128 -0
- package/build/client/core/accounts/vault.js.map +1 -0
- package/build/client/core/accounts/yieldTokenPosition.d.ts +20 -0
- package/build/client/core/accounts/yieldTokenPosition.js +74 -0
- package/build/client/core/accounts/yieldTokenPosition.js.map +1 -0
- package/build/client/core/eventRegistry.d.ts +87 -0
- package/build/client/core/eventRegistry.js +86 -0
- package/build/client/core/eventRegistry.js.map +1 -0
- package/build/client/core/index.d.ts +109 -0
- package/build/client/core/index.js +127 -0
- package/build/client/core/index.js.map +1 -0
- package/build/client/core/instructions/addEmission.d.ts +19 -0
- package/build/client/core/instructions/addEmission.js +35 -0
- package/build/client/core/instructions/addEmission.js.map +1 -0
- package/build/client/core/instructions/addFarm.d.ts +17 -0
- package/build/client/core/instructions/addFarm.js +29 -0
- package/build/client/core/instructions/addFarm.js.map +1 -0
- package/build/client/core/instructions/addLpTokensMetadata.d.ts +16 -0
- package/build/client/core/instructions/addLpTokensMetadata.js +32 -0
- package/build/client/core/instructions/addLpTokensMetadata.js.map +1 -0
- package/build/client/core/instructions/addMarketEmission.d.ts +16 -0
- package/build/client/core/instructions/addMarketEmission.js +28 -0
- package/build/client/core/instructions/addMarketEmission.js.map +1 -0
- package/build/client/core/instructions/buyYt.d.ts +28 -0
- package/build/client/core/instructions/buyYt.js +44 -0
- package/build/client/core/instructions/buyYt.js.map +1 -0
- package/build/client/core/instructions/claimFarmEmissions.d.ts +17 -0
- package/build/client/core/instructions/claimFarmEmissions.js +29 -0
- package/build/client/core/instructions/claimFarmEmissions.js.map +1 -0
- package/build/client/core/instructions/collectEmission.d.ts +21 -0
- package/build/client/core/instructions/collectEmission.js +37 -0
- package/build/client/core/instructions/collectEmission.js.map +1 -0
- package/build/client/core/instructions/collectInterest.d.ts +20 -0
- package/build/client/core/instructions/collectInterest.js +36 -0
- package/build/client/core/instructions/collectInterest.js.map +1 -0
- package/build/client/core/instructions/collectTreasuryEmission.d.ts +21 -0
- package/build/client/core/instructions/collectTreasuryEmission.js +33 -0
- package/build/client/core/instructions/collectTreasuryEmission.js.map +1 -0
- package/build/client/core/instructions/collectTreasuryInterest.d.ts +20 -0
- package/build/client/core/instructions/collectTreasuryInterest.js +32 -0
- package/build/client/core/instructions/collectTreasuryInterest.js.map +1 -0
- package/build/client/core/instructions/depositYt.d.ts +19 -0
- package/build/client/core/instructions/depositYt.js +31 -0
- package/build/client/core/instructions/depositYt.js.map +1 -0
- package/build/client/core/instructions/initLpPosition.d.ts +11 -0
- package/build/client/core/instructions/initLpPosition.js +20 -0
- package/build/client/core/instructions/initLpPosition.js.map +1 -0
- package/build/client/core/instructions/initMarketTwo.d.ts +37 -0
- package/build/client/core/instructions/initMarketTwo.js +53 -0
- package/build/client/core/instructions/initMarketTwo.js.map +1 -0
- package/build/client/core/instructions/initializeVault.d.ts +34 -0
- package/build/client/core/instructions/initializeVault.js +58 -0
- package/build/client/core/instructions/initializeVault.js.map +1 -0
- package/build/client/core/instructions/initializeYieldPosition.d.ts +10 -0
- package/build/client/core/instructions/initializeYieldPosition.js +19 -0
- package/build/client/core/instructions/initializeYieldPosition.js.map +1 -0
- package/build/client/core/instructions/marketCollectEmission.d.ts +17 -0
- package/build/client/core/instructions/marketCollectEmission.js +29 -0
- package/build/client/core/instructions/marketCollectEmission.js.map +1 -0
- package/build/client/core/instructions/marketDepositLp.d.ts +19 -0
- package/build/client/core/instructions/marketDepositLp.js +31 -0
- package/build/client/core/instructions/marketDepositLp.js.map +1 -0
- package/build/client/core/instructions/marketTwoDepositLiquidity.d.ts +22 -0
- package/build/client/core/instructions/marketTwoDepositLiquidity.js +34 -0
- package/build/client/core/instructions/marketTwoDepositLiquidity.js.map +1 -0
- package/build/client/core/instructions/marketTwoWithdrawLiquidity.d.ts +22 -0
- package/build/client/core/instructions/marketTwoWithdrawLiquidity.js +34 -0
- package/build/client/core/instructions/marketTwoWithdrawLiquidity.js.map +1 -0
- package/build/client/core/instructions/marketWithdrawLp.d.ts +19 -0
- package/build/client/core/instructions/marketWithdrawLp.js +31 -0
- package/build/client/core/instructions/marketWithdrawLp.js.map +1 -0
- package/build/client/core/instructions/merge.d.ts +22 -0
- package/build/client/core/instructions/merge.js +32 -0
- package/build/client/core/instructions/merge.js.map +1 -0
- package/build/client/core/instructions/modifyFarm.d.ts +15 -0
- package/build/client/core/instructions/modifyFarm.js +27 -0
- package/build/client/core/instructions/modifyFarm.js.map +1 -0
- package/build/client/core/instructions/modifyMarketSetting.d.ts +12 -0
- package/build/client/core/instructions/modifyMarketSetting.js +24 -0
- package/build/client/core/instructions/modifyMarketSetting.js.map +1 -0
- package/build/client/core/instructions/modifyVaultSetting.d.ts +12 -0
- package/build/client/core/instructions/modifyVaultSetting.js +24 -0
- package/build/client/core/instructions/modifyVaultSetting.js.map +1 -0
- package/build/client/core/instructions/reallocMarket.d.ts +12 -0
- package/build/client/core/instructions/reallocMarket.js +24 -0
- package/build/client/core/instructions/reallocMarket.js.map +1 -0
- package/build/client/core/instructions/sellYt.d.ts +28 -0
- package/build/client/core/instructions/sellYt.js +44 -0
- package/build/client/core/instructions/sellYt.js.map +1 -0
- package/build/client/core/instructions/stageYtYield.d.ts +13 -0
- package/build/client/core/instructions/stageYtYield.js +22 -0
- package/build/client/core/instructions/stageYtYield.js.map +1 -0
- package/build/client/core/instructions/strip.d.ts +22 -0
- package/build/client/core/instructions/strip.js +32 -0
- package/build/client/core/instructions/strip.js.map +1 -0
- package/build/client/core/instructions/tradePt.d.ts +20 -0
- package/build/client/core/instructions/tradePt.js +32 -0
- package/build/client/core/instructions/tradePt.js.map +1 -0
- package/build/client/core/instructions/withdrawYt.d.ts +20 -0
- package/build/client/core/instructions/withdrawYt.js +32 -0
- package/build/client/core/instructions/withdrawYt.js.map +1 -0
- package/build/client/core/instructions/wrapperBuyPt.d.ts +21 -0
- package/build/client/core/instructions/wrapperBuyPt.js +33 -0
- package/build/client/core/instructions/wrapperBuyPt.js.map +1 -0
- package/build/client/core/instructions/wrapperBuyYt.d.ts +32 -0
- package/build/client/core/instructions/wrapperBuyYt.js +52 -0
- package/build/client/core/instructions/wrapperBuyYt.js.map +1 -0
- package/build/client/core/instructions/wrapperCollectInterest.d.ts +19 -0
- package/build/client/core/instructions/wrapperCollectInterest.js +35 -0
- package/build/client/core/instructions/wrapperCollectInterest.js.map +1 -0
- package/build/client/core/instructions/wrapperMerge.d.ts +24 -0
- package/build/client/core/instructions/wrapperMerge.js +44 -0
- package/build/client/core/instructions/wrapperMerge.js.map +1 -0
- package/build/client/core/instructions/wrapperProvideLiquidity.d.ts +35 -0
- package/build/client/core/instructions/wrapperProvideLiquidity.js +59 -0
- package/build/client/core/instructions/wrapperProvideLiquidity.js.map +1 -0
- package/build/client/core/instructions/wrapperProvideLiquidityBase.d.ts +28 -0
- package/build/client/core/instructions/wrapperProvideLiquidityBase.js +44 -0
- package/build/client/core/instructions/wrapperProvideLiquidityBase.js.map +1 -0
- package/build/client/core/instructions/wrapperProvideLiquidityClassic.d.ts +26 -0
- package/build/client/core/instructions/wrapperProvideLiquidityClassic.js +42 -0
- package/build/client/core/instructions/wrapperProvideLiquidityClassic.js.map +1 -0
- package/build/client/core/instructions/wrapperSellPt.d.ts +21 -0
- package/build/client/core/instructions/wrapperSellPt.js +33 -0
- package/build/client/core/instructions/wrapperSellPt.js.map +1 -0
- package/build/client/core/instructions/wrapperSellYt.d.ts +29 -0
- package/build/client/core/instructions/wrapperSellYt.js +49 -0
- package/build/client/core/instructions/wrapperSellYt.js.map +1 -0
- package/build/client/core/instructions/wrapperStrip.d.ts +26 -0
- package/build/client/core/instructions/wrapperStrip.js +46 -0
- package/build/client/core/instructions/wrapperStrip.js.map +1 -0
- package/build/client/core/instructions/wrapperWithdrawLiquidity.d.ts +26 -0
- package/build/client/core/instructions/wrapperWithdrawLiquidity.js +42 -0
- package/build/client/core/instructions/wrapperWithdrawLiquidity.js.map +1 -0
- package/build/client/core/instructions/wrapperWithdrawLiquidityClassic.d.ts +24 -0
- package/build/client/core/instructions/wrapperWithdrawLiquidityClassic.js +40 -0
- package/build/client/core/instructions/wrapperWithdrawLiquidityClassic.js.map +1 -0
- package/build/client/core/types/adminAction.d.ts +326 -0
- package/build/client/core/types/adminAction.js +87 -0
- package/build/client/core/types/adminAction.js.map +1 -0
- package/build/client/core/types/amount.d.ts +33 -0
- package/build/client/core/types/amount.js +20 -0
- package/build/client/core/types/amount.js.map +1 -0
- package/build/client/core/types/buyPtEvent.d.ts +27 -0
- package/build/client/core/types/buyPtEvent.js +19 -0
- package/build/client/core/types/buyPtEvent.js.map +1 -0
- package/build/client/core/types/buyYtEvent.d.ts +68 -0
- package/build/client/core/types/buyYtEvent.js +45 -0
- package/build/client/core/types/buyYtEvent.js.map +1 -0
- package/build/client/core/types/claimFarmEmissionsEvent.d.ts +43 -0
- package/build/client/core/types/claimFarmEmissionsEvent.js +35 -0
- package/build/client/core/types/claimFarmEmissionsEvent.js.map +1 -0
- package/build/client/core/types/claimFarmEmissionsEventV2.d.ts +98 -0
- package/build/client/core/types/claimFarmEmissionsEventV2.js +38 -0
- package/build/client/core/types/claimFarmEmissionsEventV2.js.map +1 -0
- package/build/client/core/types/claimLimits.d.ts +22 -0
- package/build/client/core/types/claimLimits.js +11 -0
- package/build/client/core/types/claimLimits.js.map +1 -0
- package/build/client/core/types/collectEmissionEvent.d.ts +35 -0
- package/build/client/core/types/collectEmissionEvent.js +24 -0
- package/build/client/core/types/collectEmissionEvent.js.map +1 -0
- package/build/client/core/types/collectEmissionEventV2.d.ts +68 -0
- package/build/client/core/types/collectEmissionEventV2.js +27 -0
- package/build/client/core/types/collectEmissionEventV2.js.map +1 -0
- package/build/client/core/types/collectInterestEvent.d.ts +31 -0
- package/build/client/core/types/collectInterestEvent.js +23 -0
- package/build/client/core/types/collectInterestEvent.js.map +1 -0
- package/build/client/core/types/collectInterestEventV2.d.ts +64 -0
- package/build/client/core/types/collectInterestEventV2.js +26 -0
- package/build/client/core/types/collectInterestEventV2.js.map +1 -0
- package/build/client/core/types/collectTreasuryEmissionKind.d.ts +5 -0
- package/build/client/core/types/collectTreasuryEmissionKind.js +11 -0
- package/build/client/core/types/collectTreasuryEmissionKind.js.map +1 -0
- package/build/client/core/types/collectTreasuryInterestKind.d.ts +5 -0
- package/build/client/core/types/collectTreasuryInterestKind.js +11 -0
- package/build/client/core/types/collectTreasuryInterestKind.js.map +1 -0
- package/build/client/core/types/cpiAccounts.d.ts +107 -0
- package/build/client/core/types/cpiAccounts.js +13 -0
- package/build/client/core/types/cpiAccounts.js.map +1 -0
- package/build/client/core/types/cpiInterfaceContext.d.ts +18 -0
- package/build/client/core/types/cpiInterfaceContext.js +10 -0
- package/build/client/core/types/cpiInterfaceContext.js.map +1 -0
- package/build/client/core/types/depositLiquidityEvent.d.ts +67 -0
- package/build/client/core/types/depositLiquidityEvent.js +47 -0
- package/build/client/core/types/depositLiquidityEvent.js.map +1 -0
- package/build/client/core/types/depositLpEvent.d.ts +43 -0
- package/build/client/core/types/depositLpEvent.js +35 -0
- package/build/client/core/types/depositLpEvent.js.map +1 -0
- package/build/client/core/types/depositLpEventV2.d.ts +98 -0
- package/build/client/core/types/depositLpEventV2.js +38 -0
- package/build/client/core/types/depositLpEventV2.js.map +1 -0
- package/build/client/core/types/depositYtEvent.d.ts +56 -0
- package/build/client/core/types/depositYtEvent.js +39 -0
- package/build/client/core/types/depositYtEvent.js.map +1 -0
- package/build/client/core/types/depositYtEventV2.d.ts +89 -0
- package/build/client/core/types/depositYtEventV2.js +42 -0
- package/build/client/core/types/depositYtEventV2.js.map +1 -0
- package/build/client/core/types/emissionInfo.d.ts +36 -0
- package/build/client/core/types/emissionInfo.js +22 -0
- package/build/client/core/types/emissionInfo.js.map +1 -0
- package/build/client/core/types/farmEmission.d.ts +24 -0
- package/build/client/core/types/farmEmission.js +16 -0
- package/build/client/core/types/farmEmission.js.map +1 -0
- package/build/client/core/types/index.d.ts +60 -0
- package/build/client/core/types/index.js +77 -0
- package/build/client/core/types/index.js.map +1 -0
- package/build/client/core/types/initLpPositionEvent.d.ts +35 -0
- package/build/client/core/types/initLpPositionEvent.js +27 -0
- package/build/client/core/types/initLpPositionEvent.js.map +1 -0
- package/build/client/core/types/initializeYieldPositionEvent.d.ts +23 -0
- package/build/client/core/types/initializeYieldPositionEvent.js +21 -0
- package/build/client/core/types/initializeYieldPositionEvent.js.map +1 -0
- package/build/client/core/types/liquidityNetBalanceLimits.d.ts +26 -0
- package/build/client/core/types/liquidityNetBalanceLimits.js +12 -0
- package/build/client/core/types/liquidityNetBalanceLimits.js.map +1 -0
- package/build/client/core/types/lpFarm.d.ts +35 -0
- package/build/client/core/types/lpFarm.js +10 -0
- package/build/client/core/types/lpFarm.js.map +1 -0
- package/build/client/core/types/marketAdminAction.d.ts +286 -0
- package/build/client/core/types/marketAdminAction.js +61 -0
- package/build/client/core/types/marketAdminAction.js.map +1 -0
- package/build/client/core/types/marketCollectEmissionEvent.d.ts +39 -0
- package/build/client/core/types/marketCollectEmissionEvent.js +31 -0
- package/build/client/core/types/marketCollectEmissionEvent.js.map +1 -0
- package/build/client/core/types/marketCollectEmissionEventV2.d.ts +94 -0
- package/build/client/core/types/marketCollectEmissionEventV2.js +34 -0
- package/build/client/core/types/marketCollectEmissionEventV2.js.map +1 -0
- package/build/client/core/types/marketEmission.d.ts +20 -0
- package/build/client/core/types/marketEmission.js +15 -0
- package/build/client/core/types/marketEmission.js.map +1 -0
- package/build/client/core/types/marketEmissions.d.ts +27 -0
- package/build/client/core/types/marketEmissions.js +9 -0
- package/build/client/core/types/marketEmissions.js.map +1 -0
- package/build/client/core/types/marketFinancials.d.ts +30 -0
- package/build/client/core/types/marketFinancials.js +13 -0
- package/build/client/core/types/marketFinancials.js.map +1 -0
- package/build/client/core/types/mergeEvent.d.ts +84 -0
- package/build/client/core/types/mergeEvent.js +55 -0
- package/build/client/core/types/mergeEvent.js.map +1 -0
- package/build/client/core/types/number.d.ts +2 -0
- package/build/client/core/types/number.js +8 -0
- package/build/client/core/types/number.js.map +1 -0
- package/build/client/core/types/personalYieldTracker.d.ts +15 -0
- package/build/client/core/types/personalYieldTracker.js +10 -0
- package/build/client/core/types/personalYieldTracker.js.map +1 -0
- package/build/client/core/types/personalYieldTrackers.d.ts +23 -0
- package/build/client/core/types/personalYieldTrackers.js +9 -0
- package/build/client/core/types/personalYieldTrackers.js.map +1 -0
- package/build/client/core/types/principleDetails.d.ts +11 -0
- package/build/client/core/types/principleDetails.js +12 -0
- package/build/client/core/types/principleDetails.js.map +1 -0
- package/build/client/core/types/principles.d.ts +79 -0
- package/build/client/core/types/principles.js +14 -0
- package/build/client/core/types/principles.js.map +1 -0
- package/build/client/core/types/sellPtEvent.d.ts +27 -0
- package/build/client/core/types/sellPtEvent.js +19 -0
- package/build/client/core/types/sellPtEvent.js.map +1 -0
- package/build/client/core/types/sellYtEvent.d.ts +59 -0
- package/build/client/core/types/sellYtEvent.js +42 -0
- package/build/client/core/types/sellYtEvent.js.map +1 -0
- package/build/client/core/types/stageYieldEvent.d.ts +44 -0
- package/build/client/core/types/stageYieldEvent.js +30 -0
- package/build/client/core/types/stageYieldEvent.js.map +1 -0
- package/build/client/core/types/stageYieldEventV2.d.ts +73 -0
- package/build/client/core/types/stageYieldEventV2.js +32 -0
- package/build/client/core/types/stageYieldEventV2.js.map +1 -0
- package/build/client/core/types/stripEvent.d.ts +84 -0
- package/build/client/core/types/stripEvent.js +58 -0
- package/build/client/core/types/stripEvent.js.map +1 -0
- package/build/client/core/types/tradePtEvent.d.ts +52 -0
- package/build/client/core/types/tradePtEvent.js +38 -0
- package/build/client/core/types/tradePtEvent.js.map +1 -0
- package/build/client/core/types/withdrawLiquidityEvent.d.ts +59 -0
- package/build/client/core/types/withdrawLiquidityEvent.js +45 -0
- package/build/client/core/types/withdrawLiquidityEvent.js.map +1 -0
- package/build/client/core/types/withdrawLpEvent.d.ts +43 -0
- package/build/client/core/types/withdrawLpEvent.js +35 -0
- package/build/client/core/types/withdrawLpEvent.js.map +1 -0
- package/build/client/core/types/withdrawLpEventV2.d.ts +98 -0
- package/build/client/core/types/withdrawLpEventV2.js +38 -0
- package/build/client/core/types/withdrawLpEventV2.js.map +1 -0
- package/build/client/core/types/withdrawYtEvent.d.ts +56 -0
- package/build/client/core/types/withdrawYtEvent.js +39 -0
- package/build/client/core/types/withdrawYtEvent.js.map +1 -0
- package/build/client/core/types/withdrawYtEventV2.d.ts +89 -0
- package/build/client/core/types/withdrawYtEventV2.js +42 -0
- package/build/client/core/types/withdrawYtEventV2.js.map +1 -0
- package/build/client/core/types/wrapperBuyYtEvent.d.ts +27 -0
- package/build/client/core/types/wrapperBuyYtEvent.js +19 -0
- package/build/client/core/types/wrapperBuyYtEvent.js.map +1 -0
- package/build/client/core/types/wrapperCollectInterestEvent.d.ts +23 -0
- package/build/client/core/types/wrapperCollectInterestEvent.js +18 -0
- package/build/client/core/types/wrapperCollectInterestEvent.js.map +1 -0
- package/build/client/core/types/wrapperMergeEvent.d.ts +27 -0
- package/build/client/core/types/wrapperMergeEvent.js +19 -0
- package/build/client/core/types/wrapperMergeEvent.js.map +1 -0
- package/build/client/core/types/wrapperProvideLiquidityBaseEvent.d.ts +35 -0
- package/build/client/core/types/wrapperProvideLiquidityBaseEvent.js +21 -0
- package/build/client/core/types/wrapperProvideLiquidityBaseEvent.js.map +1 -0
- package/build/client/core/types/wrapperProvideLiquidityClassicEvent.d.ts +31 -0
- package/build/client/core/types/wrapperProvideLiquidityClassicEvent.js +20 -0
- package/build/client/core/types/wrapperProvideLiquidityClassicEvent.js.map +1 -0
- package/build/client/core/types/wrapperProvideLiquidityEvent.d.ts +31 -0
- package/build/client/core/types/wrapperProvideLiquidityEvent.js +20 -0
- package/build/client/core/types/wrapperProvideLiquidityEvent.js.map +1 -0
- package/build/client/core/types/wrapperSellYtEvent.d.ts +27 -0
- package/build/client/core/types/wrapperSellYtEvent.js +19 -0
- package/build/client/core/types/wrapperSellYtEvent.js.map +1 -0
- package/build/client/core/types/wrapperStripEvent.d.ts +27 -0
- package/build/client/core/types/wrapperStripEvent.js +19 -0
- package/build/client/core/types/wrapperStripEvent.js.map +1 -0
- package/build/client/core/types/wrapperWithdrawLiquidityClassicEvent.d.ts +31 -0
- package/build/client/core/types/wrapperWithdrawLiquidityClassicEvent.js +20 -0
- package/build/client/core/types/wrapperWithdrawLiquidityClassicEvent.js.map +1 -0
- package/build/client/core/types/wrapperWithdrawLiquidityEvent.d.ts +27 -0
- package/build/client/core/types/wrapperWithdrawLiquidityEvent.js +19 -0
- package/build/client/core/types/wrapperWithdrawLiquidityEvent.js.map +1 -0
- package/build/client/core/types/yieldTokenTracker.d.ts +15 -0
- package/build/client/core/types/yieldTokenTracker.js +10 -0
- package/build/client/core/types/yieldTokenTracker.js.map +1 -0
- package/build/client/orderbook/accounts/cpiAccountsOrderbook.d.ts +18 -0
- package/build/client/orderbook/accounts/cpiAccountsOrderbook.js +66 -0
- package/build/client/orderbook/accounts/cpiAccountsOrderbook.js.map +1 -0
- package/build/client/orderbook/accounts/vault.d.ts +48 -0
- package/build/client/orderbook/accounts/vault.js +128 -0
- package/build/client/orderbook/accounts/vault.js.map +1 -0
- package/build/client/orderbook/eventRegistry.d.ts +45 -0
- package/build/client/orderbook/eventRegistry.js +44 -0
- package/build/client/orderbook/eventRegistry.js.map +1 -0
- package/build/client/orderbook/index.d.ts +51 -0
- package/build/client/orderbook/index.js +69 -0
- package/build/client/orderbook/index.js.map +1 -0
- package/build/client/orderbook/instructions/collectAdminEmission.d.ts +14 -0
- package/build/client/orderbook/instructions/collectAdminEmission.js +26 -0
- package/build/client/orderbook/instructions/collectAdminEmission.js.map +1 -0
- package/build/client/orderbook/instructions/collectAdminFee.d.ts +21 -0
- package/build/client/orderbook/instructions/collectAdminFee.js +34 -0
- package/build/client/orderbook/instructions/collectAdminFee.js.map +1 -0
- package/build/client/orderbook/instructions/collectInterest.d.ts +21 -0
- package/build/client/orderbook/instructions/collectInterest.js +37 -0
- package/build/client/orderbook/instructions/collectInterest.js.map +1 -0
- package/build/client/orderbook/instructions/initializeOrderbook.d.ts +36 -0
- package/build/client/orderbook/instructions/initializeOrderbook.js +52 -0
- package/build/client/orderbook/instructions/initializeOrderbook.js.map +1 -0
- package/build/client/orderbook/instructions/marketOffer.d.ts +30 -0
- package/build/client/orderbook/instructions/marketOffer.js +46 -0
- package/build/client/orderbook/instructions/marketOffer.js.map +1 -0
- package/build/client/orderbook/instructions/postOffer.d.ts +33 -0
- package/build/client/orderbook/instructions/postOffer.js +49 -0
- package/build/client/orderbook/instructions/postOffer.js.map +1 -0
- package/build/client/orderbook/instructions/reallocOrderbookAccount.d.ts +12 -0
- package/build/client/orderbook/instructions/reallocOrderbookAccount.js +24 -0
- package/build/client/orderbook/instructions/reallocOrderbookAccount.js.map +1 -0
- package/build/client/orderbook/instructions/removeExpiredOffers.d.ts +12 -0
- package/build/client/orderbook/instructions/removeExpiredOffers.js +21 -0
- package/build/client/orderbook/instructions/removeExpiredOffers.js.map +1 -0
- package/build/client/orderbook/instructions/removeOffer.d.ts +24 -0
- package/build/client/orderbook/instructions/removeOffer.js +40 -0
- package/build/client/orderbook/instructions/removeOffer.js.map +1 -0
- package/build/client/orderbook/instructions/setConfigurationOptions.d.ts +10 -0
- package/build/client/orderbook/instructions/setConfigurationOptions.js +22 -0
- package/build/client/orderbook/instructions/setConfigurationOptions.js.map +1 -0
- package/build/client/orderbook/instructions/withdrawFunds.d.ts +27 -0
- package/build/client/orderbook/instructions/withdrawFunds.js +43 -0
- package/build/client/orderbook/instructions/withdrawFunds.js.map +1 -0
- package/build/client/orderbook/instructions/wrapperCollectAdminFee.d.ts +24 -0
- package/build/client/orderbook/instructions/wrapperCollectAdminFee.js +40 -0
- package/build/client/orderbook/instructions/wrapperCollectAdminFee.js.map +1 -0
- package/build/client/orderbook/instructions/wrapperCollectInterest.d.ts +20 -0
- package/build/client/orderbook/instructions/wrapperCollectInterest.js +36 -0
- package/build/client/orderbook/instructions/wrapperCollectInterest.js.map +1 -0
- package/build/client/orderbook/instructions/wrapperMarketOffer.d.ts +32 -0
- package/build/client/orderbook/instructions/wrapperMarketOffer.js +48 -0
- package/build/client/orderbook/instructions/wrapperMarketOffer.js.map +1 -0
- package/build/client/orderbook/instructions/wrapperPostOffer.d.ts +34 -0
- package/build/client/orderbook/instructions/wrapperPostOffer.js +50 -0
- package/build/client/orderbook/instructions/wrapperPostOffer.js.map +1 -0
- package/build/client/orderbook/instructions/wrapperRemoveOffer.d.ts +25 -0
- package/build/client/orderbook/instructions/wrapperRemoveOffer.js +41 -0
- package/build/client/orderbook/instructions/wrapperRemoveOffer.js.map +1 -0
- package/build/client/orderbook/instructions/wrapperWithdrawFunds.d.ts +28 -0
- package/build/client/orderbook/instructions/wrapperWithdrawFunds.js +44 -0
- package/build/client/orderbook/instructions/wrapperWithdrawFunds.js.map +1 -0
- package/build/client/orderbook/types/amount.d.ts +33 -0
- package/build/client/orderbook/types/amount.js +20 -0
- package/build/client/orderbook/types/amount.js.map +1 -0
- package/build/client/orderbook/types/claimLimits.d.ts +22 -0
- package/build/client/orderbook/types/claimLimits.js +11 -0
- package/build/client/orderbook/types/claimLimits.js.map +1 -0
- package/build/client/orderbook/types/collectAdminEmissionEvent.d.ts +27 -0
- package/build/client/orderbook/types/collectAdminEmissionEvent.js +19 -0
- package/build/client/orderbook/types/collectAdminEmissionEvent.js.map +1 -0
- package/build/client/orderbook/types/collectAdminFeeEvent.d.ts +26 -0
- package/build/client/orderbook/types/collectAdminFeeEvent.js +12 -0
- package/build/client/orderbook/types/collectAdminFeeEvent.js.map +1 -0
- package/build/client/orderbook/types/collectEmissionEventV2.d.ts +68 -0
- package/build/client/orderbook/types/collectEmissionEventV2.js +27 -0
- package/build/client/orderbook/types/collectEmissionEventV2.js.map +1 -0
- package/build/client/orderbook/types/collectInterestEventV2.d.ts +64 -0
- package/build/client/orderbook/types/collectInterestEventV2.js +26 -0
- package/build/client/orderbook/types/collectInterestEventV2.js.map +1 -0
- package/build/client/orderbook/types/collectUserInterestEvent.d.ts +23 -0
- package/build/client/orderbook/types/collectUserInterestEvent.js +18 -0
- package/build/client/orderbook/types/collectUserInterestEvent.js.map +1 -0
- package/build/client/orderbook/types/cpiAccounts.d.ts +107 -0
- package/build/client/orderbook/types/cpiAccounts.js +13 -0
- package/build/client/orderbook/types/cpiAccounts.js.map +1 -0
- package/build/client/orderbook/types/cpiInterfaceContext.d.ts +18 -0
- package/build/client/orderbook/types/cpiInterfaceContext.js +10 -0
- package/build/client/orderbook/types/cpiInterfaceContext.js.map +1 -0
- package/build/client/orderbook/types/emissionInfo.d.ts +36 -0
- package/build/client/orderbook/types/emissionInfo.js +22 -0
- package/build/client/orderbook/types/emissionInfo.js.map +1 -0
- package/build/client/orderbook/types/exponentCoreCpiAccounts.d.ts +107 -0
- package/build/client/orderbook/types/exponentCoreCpiAccounts.js +13 -0
- package/build/client/orderbook/types/exponentCoreCpiAccounts.js.map +1 -0
- package/build/client/orderbook/types/filledOffersEvent.d.ts +30 -0
- package/build/client/orderbook/types/filledOffersEvent.js +13 -0
- package/build/client/orderbook/types/filledOffersEvent.js.map +1 -0
- package/build/client/orderbook/types/index.d.ts +30 -0
- package/build/client/orderbook/types/index.js +47 -0
- package/build/client/orderbook/types/index.js.map +1 -0
- package/build/client/orderbook/types/marketOfferEvent.d.ts +93 -0
- package/build/client/orderbook/types/marketOfferEvent.js +33 -0
- package/build/client/orderbook/types/marketOfferEvent.js.map +1 -0
- package/build/client/orderbook/types/mergeEvent.d.ts +84 -0
- package/build/client/orderbook/types/mergeEvent.js +55 -0
- package/build/client/orderbook/types/mergeEvent.js.map +1 -0
- package/build/client/orderbook/types/number.d.ts +2 -0
- package/build/client/orderbook/types/number.js +8 -0
- package/build/client/orderbook/types/number.js.map +1 -0
- package/build/client/orderbook/types/offerOptions.d.ts +24 -0
- package/build/client/orderbook/types/offerOptions.js +22 -0
- package/build/client/orderbook/types/offerOptions.js.map +1 -0
- package/build/client/orderbook/types/offerType.d.ts +5 -0
- package/build/client/orderbook/types/offerType.js +11 -0
- package/build/client/orderbook/types/offerType.js.map +1 -0
- package/build/client/orderbook/types/orderbookInitEvent.d.ts +39 -0
- package/build/client/orderbook/types/orderbookInitEvent.js +25 -0
- package/build/client/orderbook/types/orderbookInitEvent.js.map +1 -0
- package/build/client/orderbook/types/postOfferEvent.d.ts +118 -0
- package/build/client/orderbook/types/postOfferEvent.js +36 -0
- package/build/client/orderbook/types/postOfferEvent.js.map +1 -0
- package/build/client/orderbook/types/removeOfferEvent.d.ts +39 -0
- package/build/client/orderbook/types/removeOfferEvent.js +31 -0
- package/build/client/orderbook/types/removeOfferEvent.js.map +1 -0
- package/build/client/orderbook/types/setConfigurationOptionsEnum.d.ts +72 -0
- package/build/client/orderbook/types/setConfigurationOptionsEnum.js +34 -0
- package/build/client/orderbook/types/setConfigurationOptionsEnum.js.map +1 -0
- package/build/client/orderbook/types/stripEvent.d.ts +84 -0
- package/build/client/orderbook/types/stripEvent.js +58 -0
- package/build/client/orderbook/types/stripEvent.js.map +1 -0
- package/build/client/orderbook/types/withdrawFundsEvent.d.ts +39 -0
- package/build/client/orderbook/types/withdrawFundsEvent.js +31 -0
- package/build/client/orderbook/types/withdrawFundsEvent.js.map +1 -0
- package/build/client/orderbook/types/wrapperCollectAdminFeeEvent.d.ts +18 -0
- package/build/client/orderbook/types/wrapperCollectAdminFeeEvent.js +10 -0
- package/build/client/orderbook/types/wrapperCollectAdminFeeEvent.js.map +1 -0
- package/build/client/orderbook/types/wrapperCollectInterestEvent.d.ts +15 -0
- package/build/client/orderbook/types/wrapperCollectInterestEvent.js +13 -0
- package/build/client/orderbook/types/wrapperCollectInterestEvent.js.map +1 -0
- package/build/client/orderbook/types/wrapperMarketOfferEvent.d.ts +19 -0
- package/build/client/orderbook/types/wrapperMarketOfferEvent.js +14 -0
- package/build/client/orderbook/types/wrapperMarketOfferEvent.js.map +1 -0
- package/build/client/orderbook/types/wrapperPostOfferEvent.d.ts +39 -0
- package/build/client/orderbook/types/wrapperPostOfferEvent.js +34 -0
- package/build/client/orderbook/types/wrapperPostOfferEvent.js.map +1 -0
- package/build/client/orderbook/types/wrapperRemoveOfferEvent.d.ts +15 -0
- package/build/client/orderbook/types/wrapperRemoveOfferEvent.js +13 -0
- package/build/client/orderbook/types/wrapperRemoveOfferEvent.js.map +1 -0
- package/build/client/orderbook/types/wrapperWithdrawFundsEvent.d.ts +27 -0
- package/build/client/orderbook/types/wrapperWithdrawFundsEvent.js +19 -0
- package/build/client/orderbook/types/wrapperWithdrawFundsEvent.js.map +1 -0
- package/build/client/orderbook/types/yieldTokenTracker.d.ts +15 -0
- package/build/client/orderbook/types/yieldTokenTracker.js +10 -0
- package/build/client/orderbook/types/yieldTokenTracker.js.map +1 -0
- package/build/client/vaults/accounts/actionProposal.d.ts +30 -0
- package/build/client/vaults/accounts/actionProposal.js +84 -0
- package/build/client/vaults/accounts/actionProposal.js.map +1 -0
- package/build/client/vaults/accounts/exponentStrategyVault.d.ts +39 -0
- package/build/client/vaults/accounts/exponentStrategyVault.js +113 -0
- package/build/client/vaults/accounts/exponentStrategyVault.js.map +1 -0
- package/build/client/vaults/accounts/programConfig.d.ts +19 -0
- package/build/client/vaults/accounts/programConfig.js +76 -0
- package/build/client/vaults/accounts/programConfig.js.map +1 -0
- package/build/client/vaults/accounts/voteAccount.d.ts +23 -0
- package/build/client/vaults/accounts/voteAccount.js +80 -0
- package/build/client/vaults/accounts/voteAccount.js.map +1 -0
- package/build/client/vaults/accounts/withdrawalAccount.d.ts +23 -0
- package/build/client/vaults/accounts/withdrawalAccount.js +78 -0
- package/build/client/vaults/accounts/withdrawalAccount.js.map +1 -0
- package/build/client/vaults/eventRegistry.d.ts +27 -0
- package/build/client/vaults/eventRegistry.js +27 -0
- package/build/client/vaults/eventRegistry.js.map +1 -0
- package/build/client/vaults/index.d.ts +108 -0
- package/build/client/vaults/index.js +127 -0
- package/build/client/vaults/index.js.map +1 -0
- package/build/client/vaults/instructions/activateProposal.d.ts +12 -0
- package/build/client/vaults/instructions/activateProposal.js +25 -0
- package/build/client/vaults/instructions/activateProposal.js.map +1 -0
- package/build/client/vaults/instructions/addPolicy.d.ts +16 -0
- package/build/client/vaults/instructions/addPolicy.js +33 -0
- package/build/client/vaults/instructions/addPolicy.js.map +1 -0
- package/build/client/vaults/instructions/appendProposalActions.d.ts +13 -0
- package/build/client/vaults/instructions/appendProposalActions.js +26 -0
- package/build/client/vaults/instructions/appendProposalActions.js.map +1 -0
- package/build/client/vaults/instructions/cancelProposal.d.ts +7 -0
- package/build/client/vaults/instructions/cancelProposal.js +17 -0
- package/build/client/vaults/instructions/cancelProposal.js.map +1 -0
- package/build/client/vaults/instructions/cancelWithdrawal.d.ts +10 -0
- package/build/client/vaults/instructions/cancelWithdrawal.js +20 -0
- package/build/client/vaults/instructions/cancelWithdrawal.js.map +1 -0
- package/build/client/vaults/instructions/collectManagementFee.d.ts +9 -0
- package/build/client/vaults/instructions/collectManagementFee.js +19 -0
- package/build/client/vaults/instructions/collectManagementFee.js.map +1 -0
- package/build/client/vaults/instructions/depositLiquidity.d.ts +20 -0
- package/build/client/vaults/instructions/depositLiquidity.js +33 -0
- package/build/client/vaults/instructions/depositLiquidity.js.map +1 -0
- package/build/client/vaults/instructions/executeProposal.d.ts +11 -0
- package/build/client/vaults/instructions/executeProposal.js +21 -0
- package/build/client/vaults/instructions/executeProposal.js.map +1 -0
- package/build/client/vaults/instructions/executeWithdrawal.d.ts +18 -0
- package/build/client/vaults/instructions/executeWithdrawal.js +31 -0
- package/build/client/vaults/instructions/executeWithdrawal.js.map +1 -0
- package/build/client/vaults/instructions/executeWithdrawalFromReserves.d.ts +22 -0
- package/build/client/vaults/instructions/executeWithdrawalFromReserves.js +35 -0
- package/build/client/vaults/instructions/executeWithdrawalFromReserves.js.map +1 -0
- package/build/client/vaults/instructions/fillWithdrawal.d.ts +17 -0
- package/build/client/vaults/instructions/fillWithdrawal.js +34 -0
- package/build/client/vaults/instructions/fillWithdrawal.js.map +1 -0
- package/build/client/vaults/instructions/finalizeProposal.d.ts +7 -0
- package/build/client/vaults/instructions/finalizeProposal.js +17 -0
- package/build/client/vaults/instructions/finalizeProposal.js.map +1 -0
- package/build/client/vaults/instructions/initProposal.d.ts +12 -0
- package/build/client/vaults/instructions/initProposal.js +25 -0
- package/build/client/vaults/instructions/initProposal.js.map +1 -0
- package/build/client/vaults/instructions/initializePrices.d.ts +7 -0
- package/build/client/vaults/instructions/initializePrices.js +17 -0
- package/build/client/vaults/instructions/initializePrices.js.map +1 -0
- package/build/client/vaults/instructions/initializeVault.d.ts +44 -0
- package/build/client/vaults/instructions/initializeVault.js +80 -0
- package/build/client/vaults/instructions/initializeVault.js.map +1 -0
- package/build/client/vaults/instructions/makeSentienelManager.d.ts +7 -0
- package/build/client/vaults/instructions/makeSentienelManager.js +17 -0
- package/build/client/vaults/instructions/makeSentienelManager.js.map +1 -0
- package/build/client/vaults/instructions/managePrices.d.ts +11 -0
- package/build/client/vaults/instructions/managePrices.js +24 -0
- package/build/client/vaults/instructions/managePrices.js.map +1 -0
- package/build/client/vaults/instructions/manageVaultSettings.d.ts +12 -0
- package/build/client/vaults/instructions/manageVaultSettings.js +25 -0
- package/build/client/vaults/instructions/manageVaultSettings.js.map +1 -0
- package/build/client/vaults/instructions/managerUpdatePosition.d.ts +12 -0
- package/build/client/vaults/instructions/managerUpdatePosition.js +25 -0
- package/build/client/vaults/instructions/managerUpdatePosition.js.map +1 -0
- package/build/client/vaults/instructions/proposeAction.d.ts +16 -0
- package/build/client/vaults/instructions/proposeAction.js +29 -0
- package/build/client/vaults/instructions/proposeAction.js.map +1 -0
- package/build/client/vaults/instructions/queueWithdrawal.d.ts +14 -0
- package/build/client/vaults/instructions/queueWithdrawal.js +27 -0
- package/build/client/vaults/instructions/queueWithdrawal.js.map +1 -0
- package/build/client/vaults/instructions/removePolicy.d.ts +13 -0
- package/build/client/vaults/instructions/removePolicy.js +27 -0
- package/build/client/vaults/instructions/removePolicy.js.map +1 -0
- package/build/client/vaults/instructions/sentinelSetVaultFlags.d.ts +10 -0
- package/build/client/vaults/instructions/sentinelSetVaultFlags.js +23 -0
- package/build/client/vaults/instructions/sentinelSetVaultFlags.js.map +1 -0
- package/build/client/vaults/instructions/stakeVote.d.ts +18 -0
- package/build/client/vaults/instructions/stakeVote.js +31 -0
- package/build/client/vaults/instructions/stakeVote.js.map +1 -0
- package/build/client/vaults/instructions/unstakeVote.d.ts +14 -0
- package/build/client/vaults/instructions/unstakeVote.js +24 -0
- package/build/client/vaults/instructions/unstakeVote.js.map +1 -0
- package/build/client/vaults/instructions/updatePolicy.d.ts +17 -0
- package/build/client/vaults/instructions/updatePolicy.js +34 -0
- package/build/client/vaults/instructions/updatePolicy.js.map +1 -0
- package/build/client/vaults/instructions/updatePolicyManager.d.ts +13 -0
- package/build/client/vaults/instructions/updatePolicyManager.js +27 -0
- package/build/client/vaults/instructions/updatePolicyManager.js.map +1 -0
- package/build/client/vaults/instructions/updatePrice.d.ts +9 -0
- package/build/client/vaults/instructions/updatePrice.js +22 -0
- package/build/client/vaults/instructions/updatePrice.js.map +1 -0
- package/build/client/vaults/instructions/validateInteractionHook.d.ts +16 -0
- package/build/client/vaults/instructions/validateInteractionHook.js +33 -0
- package/build/client/vaults/instructions/validateInteractionHook.js.map +1 -0
- package/build/client/vaults/instructions/wrapperAddPolicy.d.ts +16 -0
- package/build/client/vaults/instructions/wrapperAddPolicy.js +33 -0
- package/build/client/vaults/instructions/wrapperAddPolicy.js.map +1 -0
- package/build/client/vaults/instructions/wrapperExecuteWithdrawal.d.ts +27 -0
- package/build/client/vaults/instructions/wrapperExecuteWithdrawal.js +40 -0
- package/build/client/vaults/instructions/wrapperExecuteWithdrawal.js.map +1 -0
- package/build/client/vaults/instructions/wrapperManageVaultSettings.d.ts +12 -0
- package/build/client/vaults/instructions/wrapperManageVaultSettings.js +25 -0
- package/build/client/vaults/instructions/wrapperManageVaultSettings.js.map +1 -0
- package/build/client/vaults/instructions/wrapperManagerUpdatePosition.d.ts +12 -0
- package/build/client/vaults/instructions/wrapperManagerUpdatePosition.js +25 -0
- package/build/client/vaults/instructions/wrapperManagerUpdatePosition.js.map +1 -0
- package/build/client/vaults/instructions/wrapperRemovePolicy.d.ts +13 -0
- package/build/client/vaults/instructions/wrapperRemovePolicy.js +27 -0
- package/build/client/vaults/instructions/wrapperRemovePolicy.js.map +1 -0
- package/build/client/vaults/instructions/wrapperUpdatePolicy.d.ts +17 -0
- package/build/client/vaults/instructions/wrapperUpdatePolicy.js +34 -0
- package/build/client/vaults/instructions/wrapperUpdatePolicy.js.map +1 -0
- package/build/client/vaults/types/accountConstraint.d.ts +20 -0
- package/build/client/vaults/types/accountConstraint.js +16 -0
- package/build/client/vaults/types/accountConstraint.js.map +1 -0
- package/build/client/vaults/types/accountConstraintType.d.ts +18 -0
- package/build/client/vaults/types/accountConstraintType.js +38 -0
- package/build/client/vaults/types/accountConstraintType.js.map +1 -0
- package/build/client/vaults/types/allowedSettingsChange.d.ts +79 -0
- package/build/client/vaults/types/allowedSettingsChange.js +45 -0
- package/build/client/vaults/types/allowedSettingsChange.js.map +1 -0
- package/build/client/vaults/types/cancelProposalEvent.d.ts +27 -0
- package/build/client/vaults/types/cancelProposalEvent.js +23 -0
- package/build/client/vaults/types/cancelProposalEvent.js.map +1 -0
- package/build/client/vaults/types/clmmPositionEntry.d.ts +88 -0
- package/build/client/vaults/types/clmmPositionEntry.js +20 -0
- package/build/client/vaults/types/clmmPositionEntry.js.map +1 -0
- package/build/client/vaults/types/dataConstraint.d.ts +116 -0
- package/build/client/vaults/types/dataConstraint.js +13 -0
- package/build/client/vaults/types/dataConstraint.js.map +1 -0
- package/build/client/vaults/types/dataOperator.d.ts +9 -0
- package/build/client/vaults/types/dataOperator.js +16 -0
- package/build/client/vaults/types/dataOperator.js.map +1 -0
- package/build/client/vaults/types/dataValue.d.ts +104 -0
- package/build/client/vaults/types/dataValue.js +33 -0
- package/build/client/vaults/types/dataValue.js.map +1 -0
- package/build/client/vaults/types/depositLiquidityEvent.d.ts +55 -0
- package/build/client/vaults/types/depositLiquidityEvent.js +42 -0
- package/build/client/vaults/types/depositLiquidityEvent.js.map +1 -0
- package/build/client/vaults/types/executeProposalEvent.d.ts +27 -0
- package/build/client/vaults/types/executeProposalEvent.js +23 -0
- package/build/client/vaults/types/executeProposalEvent.js.map +1 -0
- package/build/client/vaults/types/executeWithdrawalEvent.d.ts +14 -0
- package/build/client/vaults/types/executeWithdrawalEvent.js +10 -0
- package/build/client/vaults/types/executeWithdrawalEvent.js.map +1 -0
- package/build/client/vaults/types/fillParam.d.ts +14 -0
- package/build/client/vaults/types/fillParam.js +10 -0
- package/build/client/vaults/types/fillParam.js.map +1 -0
- package/build/client/vaults/types/finalizeProposalEvent.d.ts +48 -0
- package/build/client/vaults/types/finalizeProposalEvent.js +26 -0
- package/build/client/vaults/types/finalizeProposalEvent.js.map +1 -0
- package/build/client/vaults/types/hook.d.ts +44 -0
- package/build/client/vaults/types/hook.js +18 -0
- package/build/client/vaults/types/hook.js.map +1 -0
- package/build/client/vaults/types/hookCompiledInstruction.d.ts +18 -0
- package/build/client/vaults/types/hookCompiledInstruction.js +11 -0
- package/build/client/vaults/types/hookCompiledInstruction.js.map +1 -0
- package/build/client/vaults/types/index.d.ts +67 -0
- package/build/client/vaults/types/index.js +85 -0
- package/build/client/vaults/types/index.js.map +1 -0
- package/build/client/vaults/types/instructionConstraint.d.ts +173 -0
- package/build/client/vaults/types/instructionConstraint.js +17 -0
- package/build/client/vaults/types/instructionConstraint.js.map +1 -0
- package/build/client/vaults/types/internalFundTransferPolicyCreationPayload.d.ts +19 -0
- package/build/client/vaults/types/internalFundTransferPolicyCreationPayload.js +18 -0
- package/build/client/vaults/types/internalFundTransferPolicyCreationPayload.js.map +1 -0
- package/build/client/vaults/types/kaminoFarmEntry.d.ts +15 -0
- package/build/client/vaults/types/kaminoFarmEntry.js +17 -0
- package/build/client/vaults/types/kaminoFarmEntry.js.map +1 -0
- package/build/client/vaults/types/kaminoObligationEntry.d.ts +134 -0
- package/build/client/vaults/types/kaminoObligationEntry.js +24 -0
- package/build/client/vaults/types/kaminoObligationEntry.js.map +1 -0
- package/build/client/vaults/types/limitedQuantityConstraints.d.ts +10 -0
- package/build/client/vaults/types/limitedQuantityConstraints.js +9 -0
- package/build/client/vaults/types/limitedQuantityConstraints.js.map +1 -0
- package/build/client/vaults/types/limitedSpendingLimit.d.ts +105 -0
- package/build/client/vaults/types/limitedSpendingLimit.js +17 -0
- package/build/client/vaults/types/limitedSpendingLimit.js.map +1 -0
- package/build/client/vaults/types/limitedTimeConstraints.d.ts +67 -0
- package/build/client/vaults/types/limitedTimeConstraints.js +12 -0
- package/build/client/vaults/types/limitedTimeConstraints.js.map +1 -0
- package/build/client/vaults/types/loopscaleLoanEntry.d.ts +11 -0
- package/build/client/vaults/types/loopscaleLoanEntry.js +13 -0
- package/build/client/vaults/types/loopscaleLoanEntry.js.map +1 -0
- package/build/client/vaults/types/loopscaleStrategyEntry.d.ts +11 -0
- package/build/client/vaults/types/loopscaleStrategyEntry.js +13 -0
- package/build/client/vaults/types/loopscaleStrategyEntry.js.map +1 -0
- package/build/client/vaults/types/number.d.ts +2 -0
- package/build/client/vaults/types/number.js +9 -0
- package/build/client/vaults/types/number.js.map +1 -0
- package/build/client/vaults/types/obligationType.d.ts +13 -0
- package/build/client/vaults/types/obligationType.js +24 -0
- package/build/client/vaults/types/obligationType.js.map +1 -0
- package/build/client/vaults/types/orderbookEntry.d.ts +64 -0
- package/build/client/vaults/types/orderbookEntry.js +25 -0
- package/build/client/vaults/types/orderbookEntry.js.map +1 -0
- package/build/client/vaults/types/periodV2.d.ts +60 -0
- package/build/client/vaults/types/periodV2.js +24 -0
- package/build/client/vaults/types/periodV2.js.map +1 -0
- package/build/client/vaults/types/permissions.d.ts +10 -0
- package/build/client/vaults/types/permissions.js +7 -0
- package/build/client/vaults/types/permissions.js.map +1 -0
- package/build/client/vaults/types/policyAction.d.ts +61 -0
- package/build/client/vaults/types/policyAction.js +29 -0
- package/build/client/vaults/types/policyAction.js.map +1 -0
- package/build/client/vaults/types/policyConfig.d.ts +10 -0
- package/build/client/vaults/types/policyConfig.js +15 -0
- package/build/client/vaults/types/policyConfig.js.map +1 -0
- package/build/client/vaults/types/policyCreationPayload.d.ts +287 -0
- package/build/client/vaults/types/policyCreationPayload.js +50 -0
- package/build/client/vaults/types/policyCreationPayload.js.map +1 -0
- package/build/client/vaults/types/policyExpirationArgs.d.ts +33 -0
- package/build/client/vaults/types/policyExpirationArgs.js +21 -0
- package/build/client/vaults/types/policyExpirationArgs.js.map +1 -0
- package/build/client/vaults/types/positionUpdate.d.ts +54 -0
- package/build/client/vaults/types/positionUpdate.js +112 -0
- package/build/client/vaults/types/positionUpdate.js.map +1 -0
- package/build/client/vaults/types/priceId.d.ts +40 -0
- package/build/client/vaults/types/priceId.js +21 -0
- package/build/client/vaults/types/priceId.js.map +1 -0
- package/build/client/vaults/types/priceType.d.ts +19 -0
- package/build/client/vaults/types/priceType.js +26 -0
- package/build/client/vaults/types/priceType.js.map +1 -0
- package/build/client/vaults/types/programInteractionPolicyCreationPayload.d.ts +11 -0
- package/build/client/vaults/types/programInteractionPolicyCreationPayload.js +16 -0
- package/build/client/vaults/types/programInteractionPolicyCreationPayload.js.map +1 -0
- package/build/client/vaults/types/proposalAction.d.ts +226 -0
- package/build/client/vaults/types/proposalAction.js +37 -0
- package/build/client/vaults/types/proposalAction.js.map +1 -0
- package/build/client/vaults/types/proposalActionKind.d.ts +7 -0
- package/build/client/vaults/types/proposalActionKind.js +14 -0
- package/build/client/vaults/types/proposalActionKind.js.map +1 -0
- package/build/client/vaults/types/proposalStatus.d.ts +9 -0
- package/build/client/vaults/types/proposalStatus.js +16 -0
- package/build/client/vaults/types/proposalStatus.js.map +1 -0
- package/build/client/vaults/types/proposalVoteConfig.d.ts +46 -0
- package/build/client/vaults/types/proposalVoteConfig.js +18 -0
- package/build/client/vaults/types/proposalVoteConfig.js.map +1 -0
- package/build/client/vaults/types/proposeActionEvent.d.ts +48 -0
- package/build/client/vaults/types/proposeActionEvent.js +29 -0
- package/build/client/vaults/types/proposeActionEvent.js.map +1 -0
- package/build/client/vaults/types/quantityConstraints.d.ts +18 -0
- package/build/client/vaults/types/quantityConstraints.js +11 -0
- package/build/client/vaults/types/quantityConstraints.js.map +1 -0
- package/build/client/vaults/types/reserveFarmMapping.d.ts +19 -0
- package/build/client/vaults/types/reserveFarmMapping.js +18 -0
- package/build/client/vaults/types/reserveFarmMapping.js.map +1 -0
- package/build/client/vaults/types/reservePriceMapping.d.ts +48 -0
- package/build/client/vaults/types/reservePriceMapping.js +15 -0
- package/build/client/vaults/types/reservePriceMapping.js.map +1 -0
- package/build/client/vaults/types/settingsChangePolicyCreationPayload.d.ts +81 -0
- package/build/client/vaults/types/settingsChangePolicyCreationPayload.js +10 -0
- package/build/client/vaults/types/settingsChangePolicyCreationPayload.js.map +1 -0
- package/build/client/vaults/types/spendingLimitPolicyCreationPayload.d.ts +142 -0
- package/build/client/vaults/types/spendingLimitPolicyCreationPayload.js +24 -0
- package/build/client/vaults/types/spendingLimitPolicyCreationPayload.js.map +1 -0
- package/build/client/vaults/types/stakeVoteEvent.d.ts +40 -0
- package/build/client/vaults/types/stakeVoteEvent.js +27 -0
- package/build/client/vaults/types/stakeVoteEvent.js.map +1 -0
- package/build/client/vaults/types/strategyPosition.d.ts +48 -0
- package/build/client/vaults/types/strategyPosition.js +59 -0
- package/build/client/vaults/types/strategyPosition.js.map +1 -0
- package/build/client/vaults/types/timeConstraints.d.ts +71 -0
- package/build/client/vaults/types/timeConstraints.js +13 -0
- package/build/client/vaults/types/timeConstraints.js.map +1 -0
- package/build/client/vaults/types/tokenAccountBalance.d.ts +52 -0
- package/build/client/vaults/types/tokenAccountBalance.js +19 -0
- package/build/client/vaults/types/tokenAccountBalance.js.map +1 -0
- package/build/client/vaults/types/tokenAccountEntry.d.ts +72 -0
- package/build/client/vaults/types/tokenAccountEntry.js +15 -0
- package/build/client/vaults/types/tokenAccountEntry.js.map +1 -0
- package/build/client/vaults/types/tokenEntry.d.ts +60 -0
- package/build/client/vaults/types/tokenEntry.js +24 -0
- package/build/client/vaults/types/tokenEntry.js.map +1 -0
- package/build/client/vaults/types/unstakeVoteEvent.d.ts +36 -0
- package/build/client/vaults/types/unstakeVoteEvent.js +26 -0
- package/build/client/vaults/types/unstakeVoteEvent.js.map +1 -0
- package/build/client/vaults/types/updatePriceAction.d.ts +174 -0
- package/build/client/vaults/types/updatePriceAction.js +104 -0
- package/build/client/vaults/types/updatePriceAction.js.map +1 -0
- package/build/client/vaults/types/updatePriceInput.d.ts +14 -0
- package/build/client/vaults/types/updatePriceInput.js +10 -0
- package/build/client/vaults/types/updatePriceInput.js.map +1 -0
- package/build/client/vaults/types/usageState.d.ts +14 -0
- package/build/client/vaults/types/usageState.js +10 -0
- package/build/client/vaults/types/usageState.js.map +1 -0
- package/build/client/vaults/types/vaultConfig.d.ts +87 -0
- package/build/client/vaults/types/vaultConfig.js +19 -0
- package/build/client/vaults/types/vaultConfig.js.map +1 -0
- package/build/client/vaults/types/vaultFinancials.d.ts +58 -0
- package/build/client/vaults/types/vaultFinancials.js +21 -0
- package/build/client/vaults/types/vaultFinancials.js.map +1 -0
- package/build/client/vaults/types/vaultFlagAction.d.ts +56 -0
- package/build/client/vaults/types/vaultFlagAction.js +22 -0
- package/build/client/vaults/types/vaultFlagAction.js.map +1 -0
- package/build/client/vaults/types/vaultFlagsUpdatedEvent.d.ts +23 -0
- package/build/client/vaults/types/vaultFlagsUpdatedEvent.js +19 -0
- package/build/client/vaults/types/vaultFlagsUpdatedEvent.js.map +1 -0
- package/build/client/vaults/types/vaultRoleKind.d.ts +7 -0
- package/build/client/vaults/types/vaultRoleKind.js +14 -0
- package/build/client/vaults/types/vaultRoleKind.js.map +1 -0
- package/build/client/vaults/types/vaultRoles.d.ts +23 -0
- package/build/client/vaults/types/vaultRoles.js +25 -0
- package/build/client/vaults/types/vaultRoles.js.map +1 -0
- package/build/client/vaults/types/vaultSettingsAction.d.ts +109 -0
- package/build/client/vaults/types/vaultSettingsAction.js +161 -0
- package/build/client/vaults/types/vaultSettingsAction.js.map +1 -0
- package/build/client/vaults/types/voteChoice.d.ts +5 -0
- package/build/client/vaults/types/voteChoice.js +12 -0
- package/build/client/vaults/types/voteChoice.js.map +1 -0
- package/build/client/vaults/types/withdrawalPeriodSettings.d.ts +48 -0
- package/build/client/vaults/types/withdrawalPeriodSettings.js +28 -0
- package/build/client/vaults/types/withdrawalPeriodSettings.js.map +1 -0
- package/build/client/vaults/types/withdrawalTokenFill.d.ts +19 -0
- package/build/client/vaults/types/withdrawalTokenFill.js +18 -0
- package/build/client/vaults/types/withdrawalTokenFill.js.map +1 -0
- package/build/client/vaults/types/yieldPositionEntry.d.ts +52 -0
- package/build/client/vaults/types/yieldPositionEntry.js +19 -0
- package/build/client/vaults/types/yieldPositionEntry.js.map +1 -0
- package/build/clmm/codamaEvents.d.ts +23 -0
- package/build/clmm/codamaEvents.js +24 -0
- package/build/clmm/codamaEvents.js.map +1 -0
- package/build/clmm/index.d.ts +1 -1
- package/build/clmm/index.js +1 -1
- package/build/clmm/index.js.map +1 -1
- package/build/codamaEvents.d.ts +18 -0
- package/build/codamaEvents.js +21 -0
- package/build/codamaEvents.js.map +1 -0
- package/build/environment.d.ts +8 -7
- package/build/environment.js +8 -7
- package/build/environment.js.map +1 -1
- package/build/exponentVaults/aumCalculator.d.ts +203 -0
- package/build/exponentVaults/aumCalculator.js +999 -0
- package/build/exponentVaults/aumCalculator.js.map +1 -0
- package/build/exponentVaults/events.d.ts +8 -0
- package/build/exponentVaults/events.js +12 -0
- package/build/exponentVaults/events.js.map +1 -0
- package/build/exponentVaults/fetcher.d.ts +52 -0
- package/build/exponentVaults/fetcher.js +199 -0
- package/build/exponentVaults/fetcher.js.map +1 -0
- package/build/exponentVaults/index.d.ts +31 -0
- package/build/exponentVaults/index.js +193 -0
- package/build/exponentVaults/index.js.map +1 -0
- package/build/exponentVaults/kamino-farms.d.ts +144 -0
- package/build/exponentVaults/kamino-farms.js +396 -0
- package/build/exponentVaults/kamino-farms.js.map +1 -0
- package/build/exponentVaults/kamino-markets.d.ts +887 -0
- package/build/exponentVaults/kamino-markets.js +345 -0
- package/build/exponentVaults/kamino-markets.js.map +1 -0
- package/build/exponentVaults/loopscale/client.d.ts +240 -0
- package/build/exponentVaults/loopscale/client.js +590 -0
- package/build/exponentVaults/loopscale/client.js.map +1 -0
- package/build/exponentVaults/loopscale/client.test.d.ts +1 -0
- package/build/exponentVaults/loopscale/client.test.js +183 -0
- package/build/exponentVaults/loopscale/client.test.js.map +1 -0
- package/build/exponentVaults/loopscale/helpers.d.ts +29 -0
- package/build/exponentVaults/loopscale/helpers.js +119 -0
- package/build/exponentVaults/loopscale/helpers.js.map +1 -0
- package/build/exponentVaults/loopscale/index.d.ts +3 -0
- package/build/exponentVaults/loopscale/index.js +12 -0
- package/build/exponentVaults/loopscale/index.js.map +1 -0
- package/build/exponentVaults/loopscale/prepared-transactions.d.ts +13 -0
- package/build/exponentVaults/loopscale/prepared-transactions.js +271 -0
- package/build/exponentVaults/loopscale/prepared-transactions.js.map +1 -0
- package/build/exponentVaults/loopscale/prepared-transactions.test.d.ts +1 -0
- package/build/exponentVaults/loopscale/prepared-transactions.test.js +400 -0
- package/build/exponentVaults/loopscale/prepared-transactions.test.js.map +1 -0
- package/build/exponentVaults/loopscale/prepared-types.d.ts +62 -0
- package/build/exponentVaults/loopscale/prepared-types.js +3 -0
- package/build/exponentVaults/loopscale/prepared-types.js.map +1 -0
- package/build/exponentVaults/loopscale/response-plan.d.ts +69 -0
- package/build/exponentVaults/loopscale/response-plan.js +141 -0
- package/build/exponentVaults/loopscale/response-plan.js.map +1 -0
- package/build/exponentVaults/loopscale/response-plan.test.d.ts +1 -0
- package/build/exponentVaults/loopscale/response-plan.test.js +139 -0
- package/build/exponentVaults/loopscale/response-plan.test.js.map +1 -0
- package/build/exponentVaults/loopscale/send-plan.d.ts +75 -0
- package/build/exponentVaults/loopscale/send-plan.js +235 -0
- package/build/exponentVaults/loopscale/send-plan.js.map +1 -0
- package/build/exponentVaults/loopscale/types.d.ts +443 -0
- package/build/exponentVaults/loopscale/types.js +3 -0
- package/build/exponentVaults/loopscale/types.js.map +1 -0
- package/build/exponentVaults/loopscale-client.d.ts +130 -0
- package/build/exponentVaults/loopscale-client.js +489 -0
- package/build/exponentVaults/loopscale-client.js.map +1 -0
- package/build/exponentVaults/loopscale-client.test.d.ts +1 -0
- package/build/exponentVaults/loopscale-client.test.js +162 -0
- package/build/exponentVaults/loopscale-client.test.js.map +1 -0
- package/build/exponentVaults/loopscale-client.types.d.ts +425 -0
- package/build/exponentVaults/loopscale-client.types.js +3 -0
- package/build/exponentVaults/loopscale-client.types.js.map +1 -0
- package/build/exponentVaults/loopscale-execution.d.ts +125 -0
- package/build/exponentVaults/loopscale-execution.js +341 -0
- package/build/exponentVaults/loopscale-execution.js.map +1 -0
- package/build/exponentVaults/loopscale-execution.test.d.ts +1 -0
- package/build/exponentVaults/loopscale-execution.test.js +139 -0
- package/build/exponentVaults/loopscale-execution.test.js.map +1 -0
- package/build/exponentVaults/loopscale-vault.d.ts +115 -0
- package/build/exponentVaults/loopscale-vault.js +275 -0
- package/build/exponentVaults/loopscale-vault.js.map +1 -0
- package/build/exponentVaults/loopscale-vault.test.d.ts +1 -0
- package/build/exponentVaults/loopscale-vault.test.js +102 -0
- package/build/exponentVaults/loopscale-vault.test.js.map +1 -0
- package/build/exponentVaults/policyBuilders.d.ts +756 -0
- package/build/exponentVaults/policyBuilders.js +1248 -0
- package/build/exponentVaults/policyBuilders.js.map +1 -0
- package/build/exponentVaults/policyMatcher.d.ts +82 -0
- package/build/exponentVaults/policyMatcher.js +730 -0
- package/build/exponentVaults/policyMatcher.js.map +1 -0
- package/build/exponentVaults/pricePathResolver.d.ts +45 -0
- package/build/exponentVaults/pricePathResolver.js +198 -0
- package/build/exponentVaults/pricePathResolver.js.map +1 -0
- package/build/exponentVaults/pricePathResolver.test.d.ts +1 -0
- package/build/exponentVaults/pricePathResolver.test.js +369 -0
- package/build/exponentVaults/pricePathResolver.test.js.map +1 -0
- package/build/exponentVaults/scope-refresh.d.ts +10 -0
- package/build/exponentVaults/scope-refresh.js +140 -0
- package/build/exponentVaults/scope-refresh.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/constants.d.ts +2 -0
- package/build/exponentVaults/squadsVaultTxnResolver/constants.js +61 -0
- package/build/exponentVaults/squadsVaultTxnResolver/constants.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/helpers.d.ts +26 -0
- package/build/exponentVaults/squadsVaultTxnResolver/helpers.js +268 -0
- package/build/exponentVaults/squadsVaultTxnResolver/helpers.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/index.d.ts +5 -0
- package/build/exponentVaults/squadsVaultTxnResolver/index.js +15 -0
- package/build/exponentVaults/squadsVaultTxnResolver/index.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/exponent.d.ts +6 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/exponent.js +361 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/exponent.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/helpers.d.ts +2 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/helpers.js +28 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/helpers.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/index.d.ts +2 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/index.js +25 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/index.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/kamino.d.ts +2 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/kamino.js +67 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/kamino.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/loopscale.d.ts +2 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/loopscale.js +73 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/loopscale.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/titan.d.ts +2 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/titan.js +35 -0
- package/build/exponentVaults/squadsVaultTxnResolver/resolvers/titan.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/squadsVaultTxnResolver.d.ts +21 -0
- package/build/exponentVaults/squadsVaultTxnResolver/squadsVaultTxnResolver.js +64 -0
- package/build/exponentVaults/squadsVaultTxnResolver/squadsVaultTxnResolver.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/types.d.ts +111 -0
- package/build/exponentVaults/squadsVaultTxnResolver/types.js +92 -0
- package/build/exponentVaults/squadsVaultTxnResolver/types.js.map +1 -0
- package/build/exponentVaults/squadsVaultTxnResolver/utils.d.ts +3 -0
- package/build/exponentVaults/squadsVaultTxnResolver/utils.js +8 -0
- package/build/exponentVaults/squadsVaultTxnResolver/utils.js.map +1 -0
- package/build/exponentVaults/syncTransaction.d.ts +84 -0
- package/build/exponentVaults/syncTransaction.js +344 -0
- package/build/exponentVaults/syncTransaction.js.map +1 -0
- package/build/exponentVaults/titan-quote.d.ts +22 -0
- package/build/exponentVaults/titan-quote.js +301 -0
- package/build/exponentVaults/titan-quote.js.map +1 -0
- package/build/exponentVaults/vault-instruction-types.d.ts +363 -0
- package/build/exponentVaults/vault-instruction-types.js +128 -0
- package/build/exponentVaults/vault-instruction-types.js.map +1 -0
- package/build/exponentVaults/vault-interaction.d.ts +3318 -0
- package/build/exponentVaults/vault-interaction.js +3479 -0
- package/build/exponentVaults/vault-interaction.js.map +1 -0
- package/build/exponentVaults/vault.d.ts +662 -0
- package/build/exponentVaults/vault.js +1713 -0
- package/build/exponentVaults/vault.js.map +1 -0
- package/build/exponentVaults/vaultTransactionBuilder.d.ts +285 -0
- package/build/exponentVaults/vaultTransactionBuilder.js +563 -0
- package/build/exponentVaults/vaultTransactionBuilder.js.map +1 -0
- package/build/exponentVaults/vaultTransactionBuilder.test.d.ts +1 -0
- package/build/exponentVaults/vaultTransactionBuilder.test.js +214 -0
- package/build/exponentVaults/vaultTransactionBuilder.test.js.map +1 -0
- package/build/flavors.d.ts +3 -3
- package/build/flavors.js +115 -111
- package/build/flavors.js.map +1 -1
- package/build/index.d.ts +15 -8
- package/build/index.js +23 -7
- package/build/index.js.map +1 -1
- package/build/lpPosition.d.ts +13 -15
- package/build/lpPosition.js +2 -6
- package/build/lpPosition.js.map +1 -1
- package/build/market.d.ts +203 -230
- package/build/market.js +277 -371
- package/build/market.js.map +1 -1
- package/build/marketThree.d.ts +407 -269
- package/build/marketThree.js +621 -285
- package/build/marketThree.js.map +1 -1
- package/build/marketThree.test.js +12 -12
- package/build/marketThree.test.js.map +1 -1
- package/build/orderbook/codamaEvents.d.ts +19 -0
- package/build/orderbook/codamaEvents.js +22 -0
- package/build/orderbook/codamaEvents.js.map +1 -0
- package/build/orderbook/index.d.ts +6 -3
- package/build/orderbook/index.js +8 -4
- package/build/orderbook/index.js.map +1 -1
- package/build/orderbook/math.d.ts +4 -2
- package/build/orderbook/math.js +23 -11
- package/build/orderbook/math.js.map +1 -1
- package/build/orderbook/orderbook.d.ts +182 -104
- package/build/orderbook/orderbook.js +375 -208
- package/build/orderbook/orderbook.js.map +1 -1
- package/build/orderbook/types.d.ts +6 -20
- package/build/orderbook/types.js +25 -5
- package/build/orderbook/types.js.map +1 -1
- package/build/orderbook/utils.d.ts +1 -3
- package/build/orderbook/utils.js +4 -12
- package/build/orderbook/utils.js.map +1 -1
- package/build/router.d.ts +72 -12
- package/build/router.js +333 -3
- package/build/router.js.map +1 -1
- package/build/syPosition.d.ts +2 -2
- package/build/syPosition.js +7 -7
- package/build/syPosition.js.map +1 -1
- package/build/tokenUtil.d.ts +3 -3
- package/build/tokenUtil.js.map +1 -1
- package/build/utils/index.d.ts +4 -5
- package/build/utils/index.js +3 -24
- package/build/utils/index.js.map +1 -1
- package/build/utils/ix.d.ts +2 -2
- package/build/vault.d.ts +108 -221
- package/build/vault.js +141 -98
- package/build/vault.js.map +1 -1
- package/build/ytPosition.d.ts +28 -36
- package/build/ytPosition.js +71 -62
- package/build/ytPosition.js.map +1 -1
- package/package.json +58 -28
- package/src/CodamaEventDecoder.ts +151 -0
- package/src/addressLookupTableUtil.ts +48 -14
- package/src/client/clmm/accounts/lpPosition.ts +143 -0
- package/src/client/clmm/accounts/marketThree.ts +274 -0
- package/src/client/clmm/accounts/vault.ts +234 -0
- package/src/client/clmm/eventRegistry.ts +92 -0
- package/src/client/clmm/index.ts +82 -0
- package/src/client/clmm/instructions/addFarm.ts +57 -0
- package/src/client/clmm/instructions/addLiquidity.ts +78 -0
- package/src/client/clmm/instructions/addMarketEmission.ts +50 -0
- package/src/client/clmm/instructions/buyPt.ts +73 -0
- package/src/client/clmm/instructions/buyYt.ts +80 -0
- package/src/client/clmm/instructions/claimFarmEmission.ts +56 -0
- package/src/client/clmm/instructions/closeMarket.ts +47 -0
- package/src/client/clmm/instructions/depositLiquidity.ts +71 -0
- package/src/client/clmm/instructions/initializeMarket.ts +127 -0
- package/src/client/clmm/instructions/marketAccrueEmission.ts +39 -0
- package/src/client/clmm/instructions/marketCollectEmission.ts +57 -0
- package/src/client/clmm/instructions/modifyFarm.ts +55 -0
- package/src/client/clmm/instructions/modifyMarketSetting.ts +45 -0
- package/src/client/clmm/instructions/sellPt.ts +73 -0
- package/src/client/clmm/instructions/sellYt.ts +80 -0
- package/src/client/clmm/instructions/tradePt.ts +73 -0
- package/src/client/clmm/instructions/tradePtExactOut.ts +75 -0
- package/src/client/clmm/instructions/withdrawLiquidity.ts +67 -0
- package/src/client/clmm/instructions/wrapperBuyYt.ts +85 -0
- package/src/client/clmm/instructions/wrapperProvideLiquidity.ts +100 -0
- package/src/client/clmm/instructions/wrapperProvideLiquidityBase.ts +98 -0
- package/src/client/clmm/instructions/wrapperProvideLiquidityClassic.ts +86 -0
- package/src/client/clmm/instructions/wrapperSellYt.ts +83 -0
- package/src/client/clmm/instructions/wrapperWithdrawLiquidity.ts +75 -0
- package/src/client/clmm/instructions/wrapperWithdrawLiquidityClassic.ts +69 -0
- package/src/client/clmm/types/addFarmEvent.ts +51 -0
- package/src/client/clmm/types/amount.ts +51 -0
- package/src/client/clmm/types/buyPtEvent.ts +36 -0
- package/src/client/clmm/types/buyYtEvent.ts +74 -0
- package/src/client/clmm/types/claimFarmEmissionsEvent.ts +94 -0
- package/src/client/clmm/types/claimLimits.ts +15 -0
- package/src/client/clmm/types/closeMarketEvent.ts +36 -0
- package/src/client/clmm/types/configurationOptions.ts +29 -0
- package/src/client/clmm/types/cpiAccounts.ts +21 -0
- package/src/client/clmm/types/cpiCoreAccounts.ts +15 -0
- package/src/client/clmm/types/cpiInterfaceContext.ts +13 -0
- package/src/client/clmm/types/crossingSplit.ts +40 -0
- package/src/client/clmm/types/depositLiquidityEvent.ts +93 -0
- package/src/client/clmm/types/depositLiquidityReturnData.ts +81 -0
- package/src/client/clmm/types/emissionInfo.ts +44 -0
- package/src/client/clmm/types/farmEmission.ts +31 -0
- package/src/client/clmm/types/index.ts +48 -0
- package/src/client/clmm/types/liquidityNetBalanceLimits.ts +22 -0
- package/src/client/clmm/types/lpFarm.ts +12 -0
- package/src/client/clmm/types/marketAccrueEmissionEvent.ts +69 -0
- package/src/client/clmm/types/marketAdminAction.ts +239 -0
- package/src/client/clmm/types/marketCollectEmissionEvent.ts +83 -0
- package/src/client/clmm/types/marketEmission.ts +28 -0
- package/src/client/clmm/types/marketEmissions.ts +10 -0
- package/src/client/clmm/types/marketFinancials.ts +17 -0
- package/src/client/clmm/types/marketThreeInitEvent.ts +92 -0
- package/src/client/clmm/types/mergeEvent.ts +118 -0
- package/src/client/clmm/types/modifiedTick.ts +13 -0
- package/src/client/clmm/types/modifiedTicks.ts +18 -0
- package/src/client/clmm/types/modifyFarmEvent.ts +56 -0
- package/src/client/clmm/types/number.ts +7 -0
- package/src/client/clmm/types/personalYieldTracker.ts +12 -0
- package/src/client/clmm/types/personalYieldTrackers.ts +13 -0
- package/src/client/clmm/types/principalShare.ts +22 -0
- package/src/client/clmm/types/principalShareTrackers.ts +10 -0
- package/src/client/clmm/types/sellPtEvent.ts +36 -0
- package/src/client/clmm/types/sellYtEvent.ts +69 -0
- package/src/client/clmm/types/stripEvent.ts +124 -0
- package/src/client/clmm/types/swapDirection.ts +8 -0
- package/src/client/clmm/types/tradePtEvent.ts +76 -0
- package/src/client/clmm/types/withdrawLiquidityEvent.ts +99 -0
- package/src/client/clmm/types/withdrawLiquidityReturnData.ts +27 -0
- package/src/client/clmm/types/wrapperBuyYtEvent.ts +36 -0
- package/src/client/clmm/types/wrapperProvideLiquidityBaseEvent.ts +60 -0
- package/src/client/clmm/types/wrapperProvideLiquidityClassicEvent.ts +58 -0
- package/src/client/clmm/types/wrapperProvideLiquidityEvent.ts +60 -0
- package/src/client/clmm/types/wrapperSellYtEvent.ts +36 -0
- package/src/client/clmm/types/wrapperWithdrawLiquidityClassicEvent.ts +62 -0
- package/src/client/clmm/types/wrapperWithdrawLiquidityEvent.ts +62 -0
- package/src/client/core/accounts/admin.ts +112 -0
- package/src/client/core/accounts/lpPosition.ts +122 -0
- package/src/client/core/accounts/marketTwo.ts +234 -0
- package/src/client/core/accounts/vault.ts +234 -0
- package/src/client/core/accounts/yieldTokenPosition.ts +126 -0
- package/src/client/core/eventRegistry.ts +134 -0
- package/src/client/core/index.ts +113 -0
- package/src/client/core/instructions/addEmission.ts +62 -0
- package/src/client/core/instructions/addFarm.ts +53 -0
- package/src/client/core/instructions/addLpTokensMetadata.ts +62 -0
- package/src/client/core/instructions/addMarketEmission.ts +52 -0
- package/src/client/core/instructions/buyYt.ts +79 -0
- package/src/client/core/instructions/claimFarmEmissions.ts +54 -0
- package/src/client/core/instructions/collectEmission.ts +66 -0
- package/src/client/core/instructions/collectInterest.ts +64 -0
- package/src/client/core/instructions/collectTreasuryEmission.ts +64 -0
- package/src/client/core/instructions/collectTreasuryInterest.ts +62 -0
- package/src/client/core/instructions/depositYt.ts +59 -0
- package/src/client/core/instructions/initLpPosition.ts +35 -0
- package/src/client/core/instructions/initMarketTwo.ts +103 -0
- package/src/client/core/instructions/initializeVault.ts +107 -0
- package/src/client/core/instructions/initializeYieldPosition.ts +33 -0
- package/src/client/core/instructions/marketCollectEmission.ts +55 -0
- package/src/client/core/instructions/marketDepositLp.ts +59 -0
- package/src/client/core/instructions/marketTwoDepositLiquidity.ts +65 -0
- package/src/client/core/instructions/marketTwoWithdrawLiquidity.ts +65 -0
- package/src/client/core/instructions/marketWithdrawLp.ts +59 -0
- package/src/client/core/instructions/merge.ts +61 -0
- package/src/client/core/instructions/modifyFarm.ts +51 -0
- package/src/client/core/instructions/modifyMarketSetting.ts +47 -0
- package/src/client/core/instructions/modifyVaultSetting.ts +44 -0
- package/src/client/core/instructions/reallocMarket.ts +45 -0
- package/src/client/core/instructions/sellYt.ts +79 -0
- package/src/client/core/instructions/stageYtYield.ts +39 -0
- package/src/client/core/instructions/strip.ts +61 -0
- package/src/client/core/instructions/tradePt.ts +59 -0
- package/src/client/core/instructions/withdrawYt.ts +61 -0
- package/src/client/core/instructions/wrapperBuyPt.ts +63 -0
- package/src/client/core/instructions/wrapperBuyYt.ts +93 -0
- package/src/client/core/instructions/wrapperCollectInterest.ts +63 -0
- package/src/client/core/instructions/wrapperMerge.ts +77 -0
- package/src/client/core/instructions/wrapperProvideLiquidity.ts +103 -0
- package/src/client/core/instructions/wrapperProvideLiquidityBase.ts +81 -0
- package/src/client/core/instructions/wrapperProvideLiquidityClassic.ts +77 -0
- package/src/client/core/instructions/wrapperSellPt.ts +63 -0
- package/src/client/core/instructions/wrapperSellYt.ts +87 -0
- package/src/client/core/instructions/wrapperStrip.ts +81 -0
- package/src/client/core/instructions/wrapperWithdrawLiquidity.ts +77 -0
- package/src/client/core/instructions/wrapperWithdrawLiquidityClassic.ts +73 -0
- package/src/client/core/types/adminAction.ts +255 -0
- package/src/client/core/types/amount.ts +51 -0
- package/src/client/core/types/buyPtEvent.ts +39 -0
- package/src/client/core/types/buyYtEvent.ts +95 -0
- package/src/client/core/types/claimFarmEmissionsEvent.ts +75 -0
- package/src/client/core/types/claimFarmEmissionsEventV2.ts +83 -0
- package/src/client/core/types/claimLimits.ts +15 -0
- package/src/client/core/types/collectEmissionEvent.ts +51 -0
- package/src/client/core/types/collectEmissionEventV2.ts +60 -0
- package/src/client/core/types/collectInterestEvent.ts +48 -0
- package/src/client/core/types/collectInterestEventV2.ts +57 -0
- package/src/client/core/types/collectTreasuryEmissionKind.ts +8 -0
- package/src/client/core/types/collectTreasuryInterestKind.ts +8 -0
- package/src/client/core/types/cpiAccounts.ts +21 -0
- package/src/client/core/types/cpiInterfaceContext.ts +13 -0
- package/src/client/core/types/depositLiquidityEvent.ts +101 -0
- package/src/client/core/types/depositLpEvent.ts +75 -0
- package/src/client/core/types/depositLpEventV2.ts +83 -0
- package/src/client/core/types/depositYtEvent.ts +82 -0
- package/src/client/core/types/depositYtEventV2.ts +91 -0
- package/src/client/core/types/emissionInfo.ts +44 -0
- package/src/client/core/types/farmEmission.ts +31 -0
- package/src/client/core/types/index.ts +60 -0
- package/src/client/core/types/initLpPositionEvent.ts +57 -0
- package/src/client/core/types/initializeYieldPositionEvent.ts +43 -0
- package/src/client/core/types/liquidityNetBalanceLimits.ts +22 -0
- package/src/client/core/types/lpFarm.ts +12 -0
- package/src/client/core/types/marketAdminAction.ts +212 -0
- package/src/client/core/types/marketCollectEmissionEvent.ts +67 -0
- package/src/client/core/types/marketCollectEmissionEventV2.ts +75 -0
- package/src/client/core/types/marketEmission.ts +28 -0
- package/src/client/core/types/marketEmissions.ts +10 -0
- package/src/client/core/types/marketFinancials.ts +19 -0
- package/src/client/core/types/mergeEvent.ts +118 -0
- package/src/client/core/types/number.ts +7 -0
- package/src/client/core/types/personalYieldTracker.ts +12 -0
- package/src/client/core/types/personalYieldTrackers.ts +13 -0
- package/src/client/core/types/principleDetails.ts +25 -0
- package/src/client/core/types/principles.ts +23 -0
- package/src/client/core/types/sellPtEvent.ts +39 -0
- package/src/client/core/types/sellYtEvent.ts +90 -0
- package/src/client/core/types/stageYieldEvent.ts +63 -0
- package/src/client/core/types/stageYieldEventV2.ts +69 -0
- package/src/client/core/types/stripEvent.ts +124 -0
- package/src/client/core/types/tradePtEvent.ts +80 -0
- package/src/client/core/types/withdrawLiquidityEvent.ts +97 -0
- package/src/client/core/types/withdrawLpEvent.ts +75 -0
- package/src/client/core/types/withdrawLpEventV2.ts +83 -0
- package/src/client/core/types/withdrawYtEvent.ts +82 -0
- package/src/client/core/types/withdrawYtEventV2.ts +91 -0
- package/src/client/core/types/wrapperBuyYtEvent.ts +39 -0
- package/src/client/core/types/wrapperCollectInterestEvent.ts +37 -0
- package/src/client/core/types/wrapperMergeEvent.ts +38 -0
- package/src/client/core/types/wrapperProvideLiquidityBaseEvent.ts +43 -0
- package/src/client/core/types/wrapperProvideLiquidityClassicEvent.ts +41 -0
- package/src/client/core/types/wrapperProvideLiquidityEvent.ts +41 -0
- package/src/client/core/types/wrapperSellYtEvent.ts +39 -0
- package/src/client/core/types/wrapperStripEvent.ts +38 -0
- package/src/client/core/types/wrapperWithdrawLiquidityClassicEvent.ts +41 -0
- package/src/client/core/types/wrapperWithdrawLiquidityEvent.ts +39 -0
- package/src/client/core/types/yieldTokenTracker.ts +12 -0
- package/src/client/orderbook/accounts/cpiAccountsOrderbook.ts +101 -0
- package/src/client/orderbook/accounts/vault.ts +234 -0
- package/src/client/orderbook/eventRegistry.ts +71 -0
- package/src/client/orderbook/index.ts +55 -0
- package/src/client/orderbook/instructions/collectAdminEmission.ts +48 -0
- package/src/client/orderbook/instructions/collectAdminFee.ts +59 -0
- package/src/client/orderbook/instructions/collectInterest.ts +66 -0
- package/src/client/orderbook/instructions/initializeOrderbook.ts +104 -0
- package/src/client/orderbook/instructions/marketOffer.ts +89 -0
- package/src/client/orderbook/instructions/postOffer.ts +96 -0
- package/src/client/orderbook/instructions/reallocOrderbookAccount.ts +45 -0
- package/src/client/orderbook/instructions/removeExpiredOffers.ts +37 -0
- package/src/client/orderbook/instructions/removeOffer.ts +73 -0
- package/src/client/orderbook/instructions/setConfigurationOptions.ts +43 -0
- package/src/client/orderbook/instructions/withdrawFunds.ts +78 -0
- package/src/client/orderbook/instructions/wrapperCollectAdminFee.ts +73 -0
- package/src/client/orderbook/instructions/wrapperCollectInterest.ts +65 -0
- package/src/client/orderbook/instructions/wrapperMarketOffer.ts +94 -0
- package/src/client/orderbook/instructions/wrapperPostOffer.ts +99 -0
- package/src/client/orderbook/instructions/wrapperRemoveOffer.ts +75 -0
- package/src/client/orderbook/instructions/wrapperWithdrawFunds.ts +80 -0
- package/src/client/orderbook/types/amount.ts +51 -0
- package/src/client/orderbook/types/claimLimits.ts +15 -0
- package/src/client/orderbook/types/collectAdminEmissionEvent.ts +39 -0
- package/src/client/orderbook/types/collectAdminFeeEvent.ts +17 -0
- package/src/client/orderbook/types/collectEmissionEventV2.ts +60 -0
- package/src/client/orderbook/types/collectInterestEventV2.ts +57 -0
- package/src/client/orderbook/types/collectUserInterestEvent.ts +36 -0
- package/src/client/orderbook/types/cpiAccounts.ts +21 -0
- package/src/client/orderbook/types/cpiInterfaceContext.ts +13 -0
- package/src/client/orderbook/types/emissionInfo.ts +44 -0
- package/src/client/orderbook/types/exponentCoreCpiAccounts.ts +21 -0
- package/src/client/orderbook/types/filledOffersEvent.ts +19 -0
- package/src/client/orderbook/types/index.ts +30 -0
- package/src/client/orderbook/types/marketOfferEvent.ts +72 -0
- package/src/client/orderbook/types/mergeEvent.ts +118 -0
- package/src/client/orderbook/types/number.ts +7 -0
- package/src/client/orderbook/types/offerOptions.ts +56 -0
- package/src/client/orderbook/types/offerType.ts +8 -0
- package/src/client/orderbook/types/orderbookInitEvent.ts +54 -0
- package/src/client/orderbook/types/postOfferEvent.ts +78 -0
- package/src/client/orderbook/types/removeOfferEvent.ts +67 -0
- package/src/client/orderbook/types/setConfigurationOptionsEnum.ts +116 -0
- package/src/client/orderbook/types/stripEvent.ts +124 -0
- package/src/client/orderbook/types/withdrawFundsEvent.ts +65 -0
- package/src/client/orderbook/types/wrapperCollectAdminFeeEvent.ts +13 -0
- package/src/client/orderbook/types/wrapperCollectInterestEvent.ts +25 -0
- package/src/client/orderbook/types/wrapperMarketOfferEvent.ts +27 -0
- package/src/client/orderbook/types/wrapperPostOfferEvent.ts +72 -0
- package/src/client/orderbook/types/wrapperRemoveOfferEvent.ts +25 -0
- package/src/client/orderbook/types/wrapperWithdrawFundsEvent.ts +38 -0
- package/src/client/orderbook/types/yieldTokenTracker.ts +12 -0
- package/src/client/vaults/accounts/actionProposal.ts +144 -0
- package/src/client/vaults/accounts/exponentStrategyVault.ts +211 -0
- package/src/client/vaults/accounts/programConfig.ts +123 -0
- package/src/client/vaults/accounts/voteAccount.ts +132 -0
- package/src/client/vaults/accounts/withdrawalAccount.ts +132 -0
- package/src/client/vaults/eventRegistry.ts +45 -0
- package/src/client/vaults/index.ts +113 -0
- package/src/client/vaults/instructions/activateProposal.ts +46 -0
- package/src/client/vaults/instructions/addPolicy.ts +57 -0
- package/src/client/vaults/instructions/appendProposalActions.ts +47 -0
- package/src/client/vaults/instructions/cancelProposal.ts +28 -0
- package/src/client/vaults/instructions/cancelWithdrawal.ts +34 -0
- package/src/client/vaults/instructions/collectManagementFee.ts +32 -0
- package/src/client/vaults/instructions/depositLiquidity.ts +62 -0
- package/src/client/vaults/instructions/executeProposal.ts +36 -0
- package/src/client/vaults/instructions/executeWithdrawal.ts +58 -0
- package/src/client/vaults/instructions/executeWithdrawalFromReserves.ts +66 -0
- package/src/client/vaults/instructions/fillWithdrawal.ts +59 -0
- package/src/client/vaults/instructions/finalizeProposal.ts +28 -0
- package/src/client/vaults/instructions/initProposal.ts +46 -0
- package/src/client/vaults/instructions/initializePrices.ts +28 -0
- package/src/client/vaults/instructions/initializeVault.ts +148 -0
- package/src/client/vaults/instructions/makeSentienelManager.ts +28 -0
- package/src/client/vaults/instructions/managePrices.ts +46 -0
- package/src/client/vaults/instructions/manageVaultSettings.ts +48 -0
- package/src/client/vaults/instructions/managerUpdatePosition.ts +45 -0
- package/src/client/vaults/instructions/queueWithdrawal.ts +50 -0
- package/src/client/vaults/instructions/removePolicy.ts +44 -0
- package/src/client/vaults/instructions/sentinelSetVaultFlags.ts +44 -0
- package/src/client/vaults/instructions/stakeVote.ts +57 -0
- package/src/client/vaults/instructions/unstakeVote.ts +42 -0
- package/src/client/vaults/instructions/updatePolicy.ts +59 -0
- package/src/client/vaults/instructions/updatePolicyManager.ts +44 -0
- package/src/client/vaults/instructions/updatePrice.ts +42 -0
- package/src/client/vaults/instructions/validateInteractionHook.ts +60 -0
- package/src/client/vaults/instructions/wrapperAddPolicy.ts +57 -0
- package/src/client/vaults/instructions/wrapperExecuteWithdrawal.ts +76 -0
- package/src/client/vaults/instructions/wrapperManageVaultSettings.ts +48 -0
- package/src/client/vaults/instructions/wrapperManagerUpdatePosition.ts +45 -0
- package/src/client/vaults/instructions/wrapperRemovePolicy.ts +44 -0
- package/src/client/vaults/instructions/wrapperUpdatePolicy.ts +59 -0
- package/src/client/vaults/types/accountConstraint.ts +35 -0
- package/src/client/vaults/types/accountConstraintType.ts +93 -0
- package/src/client/vaults/types/allowedSettingsChange.ts +136 -0
- package/src/client/vaults/types/cancelProposalEvent.ts +47 -0
- package/src/client/vaults/types/clmmPositionEntry.ts +37 -0
- package/src/client/vaults/types/dataConstraint.ts +16 -0
- package/src/client/vaults/types/dataOperator.ts +13 -0
- package/src/client/vaults/types/dataValue.ts +119 -0
- package/src/client/vaults/types/depositLiquidityEvent.ts +89 -0
- package/src/client/vaults/types/executeProposalEvent.ts +47 -0
- package/src/client/vaults/types/executeWithdrawalEvent.ts +12 -0
- package/src/client/vaults/types/fillParam.ts +12 -0
- package/src/client/vaults/types/finalizeProposalEvent.ts +51 -0
- package/src/client/vaults/types/hook.ts +40 -0
- package/src/client/vaults/types/hookCompiledInstruction.ts +20 -0
- package/src/client/vaults/types/index.ts +68 -0
- package/src/client/vaults/types/instructionConstraint.ts +33 -0
- package/src/client/vaults/types/internalFundTransferPolicyCreationPayload.ts +35 -0
- package/src/client/vaults/types/kaminoFarmEntry.ts +32 -0
- package/src/client/vaults/types/kaminoObligationEntry.ts +51 -0
- package/src/client/vaults/types/limitedQuantityConstraints.ts +10 -0
- package/src/client/vaults/types/limitedSpendingLimit.ts +35 -0
- package/src/client/vaults/types/limitedTimeConstraints.ts +15 -0
- package/src/client/vaults/types/loopscaleLoanEntry.ts +23 -0
- package/src/client/vaults/types/loopscaleStrategyEntry.ts +23 -0
- package/src/client/vaults/types/number.ts +8 -0
- package/src/client/vaults/types/obligationType.ts +63 -0
- package/src/client/vaults/types/orderbookEntry.ts +50 -0
- package/src/client/vaults/types/periodV2.ts +76 -0
- package/src/client/vaults/types/permissions.ts +8 -0
- package/src/client/vaults/types/policyAction.ts +74 -0
- package/src/client/vaults/types/policyConfig.ts +32 -0
- package/src/client/vaults/types/policyCreationPayload.ts +147 -0
- package/src/client/vaults/types/policyExpirationArgs.ts +67 -0
- package/src/client/vaults/types/positionUpdate.ts +313 -0
- package/src/client/vaults/types/priceId.ts +57 -0
- package/src/client/vaults/types/priceType.ts +23 -0
- package/src/client/vaults/types/programInteractionPolicyCreationPayload.ts +32 -0
- package/src/client/vaults/types/proposalAction.ts +97 -0
- package/src/client/vaults/types/proposalActionKind.ts +11 -0
- package/src/client/vaults/types/proposalStatus.ts +13 -0
- package/src/client/vaults/types/proposalVoteConfig.ts +36 -0
- package/src/client/vaults/types/proposeActionEvent.ts +62 -0
- package/src/client/vaults/types/quantityConstraints.ts +14 -0
- package/src/client/vaults/types/reserveFarmMapping.ts +35 -0
- package/src/client/vaults/types/reservePriceMapping.ts +26 -0
- package/src/client/vaults/types/settingsChangePolicyCreationPayload.ts +14 -0
- package/src/client/vaults/types/spendingLimitPolicyCreationPayload.ts +54 -0
- package/src/client/vaults/types/stakeVoteEvent.ts +54 -0
- package/src/client/vaults/types/strategyPosition.ts +178 -0
- package/src/client/vaults/types/timeConstraints.ts +22 -0
- package/src/client/vaults/types/tokenAccountBalance.ts +35 -0
- package/src/client/vaults/types/tokenAccountEntry.ts +30 -0
- package/src/client/vaults/types/tokenEntry.ts +48 -0
- package/src/client/vaults/types/unstakeVoteEvent.ts +53 -0
- package/src/client/vaults/types/updatePriceAction.ts +268 -0
- package/src/client/vaults/types/updatePriceInput.ts +12 -0
- package/src/client/vaults/types/usageState.ts +12 -0
- package/src/client/vaults/types/vaultConfig.ts +38 -0
- package/src/client/vaults/types/vaultFinancials.ts +40 -0
- package/src/client/vaults/types/vaultFlagAction.ts +75 -0
- package/src/client/vaults/types/vaultFlagsUpdatedEvent.ts +37 -0
- package/src/client/vaults/types/vaultRoleKind.ts +11 -0
- package/src/client/vaults/types/vaultRoles.ts +59 -0
- package/src/client/vaults/types/vaultSettingsAction.ts +533 -0
- package/src/client/vaults/types/voteChoice.ts +9 -0
- package/src/client/vaults/types/withdrawalPeriodSettings.ts +83 -0
- package/src/client/vaults/types/withdrawalTokenFill.ts +35 -0
- package/src/client/vaults/types/yieldPositionEntry.ts +35 -0
- package/src/clmm/codamaEvents.ts +34 -0
- package/src/clmm/index.ts +1 -1
- package/src/codamaEvents.ts +27 -0
- package/src/environment.ts +15 -13
- package/src/exponentVaults/aumCalculator.ts +1350 -0
- package/src/exponentVaults/events.ts +15 -0
- package/src/exponentVaults/fetcher.ts +257 -0
- package/src/exponentVaults/index.ts +322 -0
- package/src/exponentVaults/kamino-farms.ts +538 -0
- package/src/exponentVaults/kamino-markets.ts +363 -0
- package/src/exponentVaults/loopscale/client.ts +808 -0
- package/src/exponentVaults/loopscale/helpers.ts +172 -0
- package/src/exponentVaults/loopscale/index.ts +57 -0
- package/src/exponentVaults/loopscale/prepared-transactions.ts +435 -0
- package/src/exponentVaults/loopscale/prepared-types.ts +73 -0
- package/src/exponentVaults/loopscale/types.ts +466 -0
- package/src/exponentVaults/policyBuilders.ts +1729 -0
- package/src/exponentVaults/policyMatcher.ts +895 -0
- package/src/exponentVaults/pricePathResolver.test.ts +466 -0
- package/src/exponentVaults/pricePathResolver.ts +273 -0
- package/src/exponentVaults/scope-refresh.ts +169 -0
- package/src/exponentVaults/squadsVaultTxnResolver/constants.ts +59 -0
- package/src/exponentVaults/squadsVaultTxnResolver/helpers.ts +355 -0
- package/src/exponentVaults/squadsVaultTxnResolver/index.ts +16 -0
- package/src/exponentVaults/squadsVaultTxnResolver/resolvers/exponent.ts +472 -0
- package/src/exponentVaults/squadsVaultTxnResolver/resolvers/helpers.ts +33 -0
- package/src/exponentVaults/squadsVaultTxnResolver/resolvers/index.ts +38 -0
- package/src/exponentVaults/squadsVaultTxnResolver/resolvers/kamino.ts +83 -0
- package/src/exponentVaults/squadsVaultTxnResolver/resolvers/loopscale.ts +94 -0
- package/src/exponentVaults/squadsVaultTxnResolver/resolvers/titan.ts +41 -0
- package/src/exponentVaults/squadsVaultTxnResolver/squadsVaultTxnResolver.ts +91 -0
- package/src/exponentVaults/squadsVaultTxnResolver/types.ts +171 -0
- package/src/exponentVaults/squadsVaultTxnResolver/utils.ts +3 -0
- package/src/exponentVaults/syncTransaction.ts +500 -0
- package/src/exponentVaults/titan-quote.ts +446 -0
- package/src/exponentVaults/vault-instruction-types.ts +493 -0
- package/src/exponentVaults/vault-interaction.ts +5070 -0
- package/src/exponentVaults/vault.ts +2667 -0
- package/src/exponentVaults/vaultTransactionBuilder.test.ts +256 -0
- package/src/exponentVaults/vaultTransactionBuilder.ts +927 -0
- package/src/flavors.ts +100 -99
- package/src/index.ts +17 -8
- package/src/lpPosition.ts +13 -18
- package/src/market.ts +461 -544
- package/src/marketThree.test.ts +16 -14
- package/src/marketThree.ts +920 -489
- package/src/orderbook/codamaEvents.ts +28 -0
- package/src/orderbook/index.ts +5 -4
- package/src/orderbook/math.ts +25 -9
- package/src/orderbook/orderbook.ts +531 -330
- package/src/orderbook/types.ts +6 -11
- package/src/orderbook/utils.ts +4 -12
- package/src/router.ts +469 -19
- package/src/syPosition.ts +15 -16
- package/src/tokenUtil.ts +4 -4
- package/src/utils/index.ts +5 -31
- package/src/utils/ix.ts +2 -2
- package/src/vault.ts +282 -327
- package/src/ytPosition.ts +75 -118
- package/tsconfig.json +6 -1
- package/build/EventDecoderV2.d.ts +0 -31
- package/build/EventDecoderV2.js +0 -76
- package/build/EventDecoderV2.js.map +0 -1
- package/build/clmm/events.d.ts +0 -10
- package/build/clmm/events.js +0 -10
- package/build/clmm/events.js.map +0 -1
- package/build/events.d.ts +0 -563
- package/build/events.js +0 -301
- package/build/events.js.map +0 -1
- package/build/eventsV2.d.ts +0 -7
- package/build/eventsV2.js +0 -10
- package/build/eventsV2.js.map +0 -1
- package/build/orderbook/events.d.ts +0 -7
- package/build/orderbook/events.js +0 -10
- package/build/orderbook/events.js.map +0 -1
- package/src/EventDecoderV2.ts +0 -96
- package/src/clmm/events.ts +0 -17
- package/src/events.ts +0 -921
- package/src/eventsV2.ts +0 -13
- package/src/orderbook/events.ts +0 -13
|
@@ -0,0 +1,3479 @@
|
|
|
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.SwapDirection = exports.clmmAction = exports.loopscaleAction = exports.titanAction = exports.createOrderbookSyncTransaction = exports.coreAction = exports.syAction = exports.orderbookAction = exports.buildSetupStatePriceRefreshInstructions = exports.createStrategySetupContext = exports.createVaultSyncTransaction = exports.kaminoFarmAction = exports.kaminoVaultAction = exports.kaminoAction = exports.ClmmAction = exports.LoopscaleAction = exports.TitanAction = exports.SyAction = exports.CoreAction = exports.OrderbookAction = exports.OrderbookTradeDirection = exports.KaminoFarmAction = exports.KaminoVaultAction = exports.VaultAction = void 0;
|
|
30
|
+
const kamino_reserve_deserializer_1 = require("@exponent-labs/kamino-reserve-deserializer");
|
|
31
|
+
const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
|
|
32
|
+
const kamino_markets_1 = require("./kamino-markets");
|
|
33
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
34
|
+
const constants_1 = require("./../../../kamino-lend-standard/src/constants");
|
|
35
|
+
const policyBuilders_1 = require("./policyBuilders");
|
|
36
|
+
const accounts_1 = require("@exponent-labs/klend-idl/accounts");
|
|
37
|
+
const orderbook_1 = require("../orderbook/orderbook");
|
|
38
|
+
const marketThree_1 = require("../marketThree");
|
|
39
|
+
const utils_1 = require("../utils");
|
|
40
|
+
const clmm_1 = require("../client/clmm");
|
|
41
|
+
Object.defineProperty(exports, "SwapDirection", { enumerable: true, get: function () { return clmm_1.SwapDirection; } });
|
|
42
|
+
const exponentClmm = __importStar(require("../client/clmm"));
|
|
43
|
+
const exponentVaults = __importStar(require("../client/vaults"));
|
|
44
|
+
const orderbook_2 = require("../client/orderbook");
|
|
45
|
+
const environment_1 = require("../environment");
|
|
46
|
+
const vault_1 = require("../vault");
|
|
47
|
+
const vault_2 = require("./vault");
|
|
48
|
+
const ytPosition_1 = require("../ytPosition");
|
|
49
|
+
const vault_3 = require("./vault");
|
|
50
|
+
const kamino_farms_1 = require("./kamino-farms");
|
|
51
|
+
const pricePathResolver_1 = require("./pricePathResolver");
|
|
52
|
+
const instructions_1 = require("@exponent-labs/klend-idl/instructions");
|
|
53
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
54
|
+
const syncTransaction_1 = require("./syncTransaction");
|
|
55
|
+
const policyMatcher_1 = require("./policyMatcher");
|
|
56
|
+
const scope_refresh_1 = require("./scope-refresh");
|
|
57
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
58
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
59
|
+
const KAMINO_FARMS_PROGRAM_ID = new web3_js_1.PublicKey("FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr");
|
|
60
|
+
const KAMINO_VAULT_PRICE_TYPE_WIRE = 14;
|
|
61
|
+
const KAMINO_VAULT_ACCOUNT_DISCRIMINATOR_LEN = 8;
|
|
62
|
+
const KAMINO_VAULT_ALLOCATION_STRATEGY_OFFSET = 304;
|
|
63
|
+
const KAMINO_VAULT_ALLOCATION_SIZE = 2160;
|
|
64
|
+
const KAMINO_VAULT_ALLOCATION_CTOKEN_VAULT_OFFSET = 32;
|
|
65
|
+
const KAMINO_VAULT_GLOBAL_CONFIG_SEED = Buffer.from("global_config");
|
|
66
|
+
// ============================================================================
|
|
67
|
+
// Vault Instruction Types (re-exported from vault-instruction-types.ts)
|
|
68
|
+
// ============================================================================
|
|
69
|
+
var vault_instruction_types_1 = require("./vault-instruction-types");
|
|
70
|
+
Object.defineProperty(exports, "VaultAction", { enumerable: true, get: function () { return vault_instruction_types_1.VaultAction; } });
|
|
71
|
+
Object.defineProperty(exports, "KaminoVaultAction", { enumerable: true, get: function () { return vault_instruction_types_1.KaminoVaultAction; } });
|
|
72
|
+
Object.defineProperty(exports, "KaminoFarmAction", { enumerable: true, get: function () { return vault_instruction_types_1.KaminoFarmAction; } });
|
|
73
|
+
Object.defineProperty(exports, "OrderbookTradeDirection", { enumerable: true, get: function () { return vault_instruction_types_1.OrderbookTradeDirection; } });
|
|
74
|
+
Object.defineProperty(exports, "OrderbookAction", { enumerable: true, get: function () { return vault_instruction_types_1.OrderbookAction; } });
|
|
75
|
+
Object.defineProperty(exports, "CoreAction", { enumerable: true, get: function () { return vault_instruction_types_1.CoreAction; } });
|
|
76
|
+
Object.defineProperty(exports, "SyAction", { enumerable: true, get: function () { return vault_instruction_types_1.SyAction; } });
|
|
77
|
+
Object.defineProperty(exports, "TitanAction", { enumerable: true, get: function () { return vault_instruction_types_1.TitanAction; } });
|
|
78
|
+
Object.defineProperty(exports, "LoopscaleAction", { enumerable: true, get: function () { return vault_instruction_types_1.LoopscaleAction; } });
|
|
79
|
+
Object.defineProperty(exports, "ClmmAction", { enumerable: true, get: function () { return vault_instruction_types_1.ClmmAction; } });
|
|
80
|
+
const vault_instruction_types_2 = require("./vault-instruction-types");
|
|
81
|
+
// ============================================================================
|
|
82
|
+
// Kamino Action Builders
|
|
83
|
+
// ============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Builder for Kamino Lending (KLend) vault action descriptors.
|
|
86
|
+
*
|
|
87
|
+
* Each method returns a `VaultInstruction` that describes what to do.
|
|
88
|
+
* Pass these to `createVaultSyncTransaction` which resolves them into
|
|
89
|
+
* raw Solana instructions, handles refresh ordering, and wraps them
|
|
90
|
+
* in a Squads sync transaction.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { kaminoAction, KaminoMarket, createVaultSyncTransaction } from "@exponent-labs/exponent-sdk"
|
|
95
|
+
*
|
|
96
|
+
* const syncTx = await createVaultSyncTransaction({
|
|
97
|
+
* instructions: [
|
|
98
|
+
* kaminoAction.initUserMetadata(KaminoMarket.MAIN),
|
|
99
|
+
* kaminoAction.initObligation(KaminoMarket.MAIN),
|
|
100
|
+
* kaminoAction.deposit(KaminoMarket.MAIN, "USDC", new BN(1_000_000)),
|
|
101
|
+
* ],
|
|
102
|
+
* owner: vaultPda,
|
|
103
|
+
* connection,
|
|
104
|
+
* policyPda,
|
|
105
|
+
* vaultPda,
|
|
106
|
+
* signer: walletPublicKey,
|
|
107
|
+
* })
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
exports.kaminoAction = {
|
|
111
|
+
/**
|
|
112
|
+
* Initialize Kamino user metadata for a market.
|
|
113
|
+
* No-ops if the account already exists on-chain.
|
|
114
|
+
* @param market - The Kamino lending market
|
|
115
|
+
*/
|
|
116
|
+
initUserMetadata(market) {
|
|
117
|
+
return { action: vault_instruction_types_2.VaultAction.INIT_USER_METADATA, market };
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Initialize a Kamino obligation for a market.
|
|
121
|
+
* When `autoManagePositions` is enabled, the SDK also registers the new
|
|
122
|
+
* obligation as a tracked strategy position after the init succeeds.
|
|
123
|
+
* @param market - The Kamino lending market
|
|
124
|
+
*/
|
|
125
|
+
initObligation(market) {
|
|
126
|
+
return { action: vault_instruction_types_2.VaultAction.INIT_OBLIGATION, market };
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Deposit collateral into a Kamino reserve.
|
|
130
|
+
* Automatically prepends refreshReserve + refreshObligation instructions.
|
|
131
|
+
* @param market - The Kamino lending market
|
|
132
|
+
* @param asset - The reserve asset (e.g. "USDC", "SOL")
|
|
133
|
+
* @param amount - Amount in the asset's native units
|
|
134
|
+
*/
|
|
135
|
+
deposit(market, asset, amount) {
|
|
136
|
+
return { action: vault_instruction_types_2.VaultAction.DEPOSIT, market, asset: asset, amount };
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Withdraw collateral from a Kamino reserve.
|
|
140
|
+
* @param market - The Kamino lending market
|
|
141
|
+
* @param asset - The reserve asset (e.g. "USDC", "SOL")
|
|
142
|
+
* @param amount - Amount in the asset's native units
|
|
143
|
+
*/
|
|
144
|
+
withdraw(market, asset, amount) {
|
|
145
|
+
return { action: vault_instruction_types_2.VaultAction.WITHDRAW, market, asset: asset, amount };
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* Borrow from a Kamino reserve.
|
|
149
|
+
* @param market - The Kamino lending market
|
|
150
|
+
* @param asset - The reserve asset (e.g. "USDC", "SOL")
|
|
151
|
+
* @param amount - Amount in the asset's native units
|
|
152
|
+
*/
|
|
153
|
+
borrow(market, asset, amount) {
|
|
154
|
+
return { action: vault_instruction_types_2.VaultAction.BORROW, market, asset: asset, amount };
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* Repay a borrow on a Kamino reserve.
|
|
158
|
+
* @param market - The Kamino lending market
|
|
159
|
+
* @param asset - The reserve asset (e.g. "USDC", "SOL")
|
|
160
|
+
* @param amount - Amount in the asset's native units
|
|
161
|
+
*/
|
|
162
|
+
repay(market, asset, amount) {
|
|
163
|
+
return { action: vault_instruction_types_2.VaultAction.REPAY, market, asset: asset, amount };
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Builder for direct Kamino Vault action descriptors.
|
|
168
|
+
*
|
|
169
|
+
* These actions move vault-owned tokens into a Kamino Vault and, when
|
|
170
|
+
* `autoManagePositions` is enabled, automatically track the resulting share
|
|
171
|
+
* token account as a managed strategy position.
|
|
172
|
+
*/
|
|
173
|
+
exports.kaminoVaultAction = {
|
|
174
|
+
/**
|
|
175
|
+
* Deposit the vault-owned token account into a Kamino Vault.
|
|
176
|
+
* @param params.vault - Kamino Vault address
|
|
177
|
+
* @param params.amount - Amount of deposit tokens to move into the vault
|
|
178
|
+
*/
|
|
179
|
+
deposit(params) {
|
|
180
|
+
return { action: vault_instruction_types_2.KaminoVaultAction.DEPOSIT, ...params };
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* Withdraw Kamino Vault shares back into the vault-owned token account.
|
|
184
|
+
* When the Kamino Vault currently allocates across multiple reserves,
|
|
185
|
+
* specify the reserve to disinvest from.
|
|
186
|
+
*/
|
|
187
|
+
withdraw(params) {
|
|
188
|
+
return { action: vault_instruction_types_2.KaminoVaultAction.WITHDRAW, ...params };
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Builder for direct Kamino Farm action descriptors.
|
|
193
|
+
*
|
|
194
|
+
* These actions operate on a farm `user_state` derived from the managed vault
|
|
195
|
+
* owner by default. Pass `delegatee` when targeting a delegated farm user
|
|
196
|
+
* state, such as a Kamino obligation-owned farm entry.
|
|
197
|
+
*/
|
|
198
|
+
exports.kaminoFarmAction = {
|
|
199
|
+
/** Initialize the farm `user_state` PDA. */
|
|
200
|
+
initializeUser(params) {
|
|
201
|
+
return { action: vault_instruction_types_2.KaminoFarmAction.INITIALIZE_USER, ...params };
|
|
202
|
+
},
|
|
203
|
+
/** Stake the managed vault's token ATA into the farm. */
|
|
204
|
+
stake(params) {
|
|
205
|
+
return { action: vault_instruction_types_2.KaminoFarmAction.STAKE, ...params };
|
|
206
|
+
},
|
|
207
|
+
/** Unstake a scaled share amount from the farm. */
|
|
208
|
+
unstake(params) {
|
|
209
|
+
return { action: vault_instruction_types_2.KaminoFarmAction.UNSTAKE, ...params };
|
|
210
|
+
},
|
|
211
|
+
/** Withdraw matured unstaked deposits back into the managed vault ATA. */
|
|
212
|
+
withdrawUnstakedDeposits(params) {
|
|
213
|
+
return { action: vault_instruction_types_2.KaminoFarmAction.WITHDRAW_UNSTAKED_DEPOSITS, ...params };
|
|
214
|
+
},
|
|
215
|
+
/** Harvest a specific reward index into a managed vault reward ATA. */
|
|
216
|
+
harvestReward(params) {
|
|
217
|
+
return { action: vault_instruction_types_2.KaminoFarmAction.HARVEST_REWARD, ...params };
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Build vault instructions and wrap them in a Squads sync transaction.
|
|
222
|
+
*
|
|
223
|
+
* Takes high-level `VaultInstruction` descriptors (built with `kamino.*`),
|
|
224
|
+
* resolves them to raw Solana instructions, then separates them:
|
|
225
|
+
* - Permissionless refresh instructions → `preInstructions` (top-level)
|
|
226
|
+
* - Vault-signed instructions → `instruction` (Squads sync transaction)
|
|
227
|
+
*
|
|
228
|
+
* KLend's `check_refresh` requires refreshReserve to be a top-level instruction
|
|
229
|
+
* so it can be found via the instruction sysvar.
|
|
230
|
+
*
|
|
231
|
+
* @returns `{ setupInstructions, preInstructions, instruction, postInstructions, signers, addressLookupTableAddresses }`
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const { setupInstructions, preInstructions, instruction, postInstructions, signers, addressLookupTableAddresses } = await createVaultSyncTransaction({
|
|
236
|
+
* instructions: [
|
|
237
|
+
* kamino.initUserMetadata(KaminoMarket.MAIN),
|
|
238
|
+
* kamino.initObligation(KaminoMarket.MAIN),
|
|
239
|
+
* kamino.deposit(KaminoMarket.MAIN, "USDC", new BN(1_000_000)),
|
|
240
|
+
* ],
|
|
241
|
+
* owner: vaultPda,
|
|
242
|
+
* connection,
|
|
243
|
+
* policyPda,
|
|
244
|
+
* vaultPda,
|
|
245
|
+
* signer: wallet.publicKey,
|
|
246
|
+
* vaultAddress: VAULT_ADDRESS,
|
|
247
|
+
* })
|
|
248
|
+
* // Send: [...setupInstructions, ...preInstructions, instruction, ...postInstructions]
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
async function createVaultSyncTransaction({ instructions, owner, connection, policyPda, vaultPda, signer, accountIndex = 0, constraintIndices, vaultAddress, leadingAccounts, preHookAccounts, postHookAccounts, squadsProgram = syncTransaction_1.SQUADS_PROGRAM_ID, autoManagePositions = false, setupContext, }) {
|
|
252
|
+
vaultPda ??= owner;
|
|
253
|
+
const resolvedSetupContext = setupContext ?? createStrategySetupContext({
|
|
254
|
+
connection,
|
|
255
|
+
env: environment_1.LOCAL_ENV,
|
|
256
|
+
owner,
|
|
257
|
+
signer,
|
|
258
|
+
vaultAddress,
|
|
259
|
+
policyPda,
|
|
260
|
+
vaultPda,
|
|
261
|
+
accountIndex,
|
|
262
|
+
squadsProgram,
|
|
263
|
+
leadingAccounts,
|
|
264
|
+
preHookAccounts,
|
|
265
|
+
postHookAccounts,
|
|
266
|
+
autoManagePositions,
|
|
267
|
+
});
|
|
268
|
+
const { setupInstructions, syncInstructions, preInstructions, postInstructions, signers, addressLookupTableAddresses } = await buildVaultInstructions(instructions, owner, connection, signer, policyPda, vaultPda, accountIndex, vaultAddress, leadingAccounts, preHookAccounts, postHookAccounts, squadsProgram, autoManagePositions, resolvedSetupContext);
|
|
269
|
+
const setupStatePriceRefreshInstructions = setupContext
|
|
270
|
+
? []
|
|
271
|
+
: await buildSetupStatePriceRefreshInstructions(resolvedSetupContext);
|
|
272
|
+
let resolvedPolicyPda = policyPda;
|
|
273
|
+
let resolvedConstraintIndices = constraintIndices;
|
|
274
|
+
if (!resolvedPolicyPda) {
|
|
275
|
+
if (!vaultAddress) {
|
|
276
|
+
throw new Error("vaultAddress is required when policyPda is not provided");
|
|
277
|
+
}
|
|
278
|
+
const match = await (0, policyMatcher_1.resolvePolicyMatchForVault)(connection, vaultAddress, signer, syncInstructions);
|
|
279
|
+
resolvedPolicyPda = match.policyPda;
|
|
280
|
+
resolvedConstraintIndices ??= match.constraintIndices;
|
|
281
|
+
}
|
|
282
|
+
// Auto-resolve constraint indices when not explicitly provided
|
|
283
|
+
resolvedConstraintIndices ??= await (0, policyMatcher_1.resolveConstraintIndices)(connection, resolvedPolicyPda, syncInstructions);
|
|
284
|
+
// Auto-resolve policy prefix and hook accounts when not explicitly provided
|
|
285
|
+
let resolvedLeadingAccounts = leadingAccounts;
|
|
286
|
+
let resolvedPreHookAccounts = preHookAccounts;
|
|
287
|
+
let resolvedPostHookAccounts = postHookAccounts;
|
|
288
|
+
if (vaultAddress && (!leadingAccounts || !preHookAccounts || !postHookAccounts)) {
|
|
289
|
+
const hooks = await (0, policyMatcher_1.resolveHookAccounts)(connection, resolvedPolicyPda, vaultAddress, signer);
|
|
290
|
+
resolvedLeadingAccounts ??= hooks.leadingAccounts;
|
|
291
|
+
resolvedPreHookAccounts ??= hooks.preHookAccounts;
|
|
292
|
+
resolvedPostHookAccounts ??= hooks.postHookAccounts;
|
|
293
|
+
}
|
|
294
|
+
const instruction = (0, syncTransaction_1.wrapInstructionsInSyncTransaction)({
|
|
295
|
+
policyPda: resolvedPolicyPda,
|
|
296
|
+
vaultPda,
|
|
297
|
+
signer,
|
|
298
|
+
instructions: syncInstructions,
|
|
299
|
+
squadsProgram,
|
|
300
|
+
accountIndex,
|
|
301
|
+
constraintIndices: resolvedConstraintIndices,
|
|
302
|
+
leadingAccounts: resolvedLeadingAccounts,
|
|
303
|
+
preHookAccounts: resolvedPreHookAccounts,
|
|
304
|
+
postHookAccounts: resolvedPostHookAccounts,
|
|
305
|
+
});
|
|
306
|
+
return {
|
|
307
|
+
setupInstructions,
|
|
308
|
+
preInstructions: [...setupStatePriceRefreshInstructions, ...preInstructions],
|
|
309
|
+
instruction,
|
|
310
|
+
postInstructions,
|
|
311
|
+
signers,
|
|
312
|
+
addressLookupTableAddresses,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
exports.createVaultSyncTransaction = createVaultSyncTransaction;
|
|
316
|
+
// ============================================================================
|
|
317
|
+
// Internal: Instruction Assembly
|
|
318
|
+
// ============================================================================
|
|
319
|
+
/** KLend farm modes — collateral for deposit/withdraw, debt for borrow/repay. */
|
|
320
|
+
const FARM_COLLATERAL = 0;
|
|
321
|
+
const FARM_DEBT = 1;
|
|
322
|
+
function isKaminoVaultInstruction(ix) {
|
|
323
|
+
return Object.values(vault_instruction_types_2.KaminoVaultAction).includes(ix.action);
|
|
324
|
+
}
|
|
325
|
+
function isKaminoFarmInstruction(ix) {
|
|
326
|
+
return Object.values(vault_instruction_types_2.KaminoFarmAction).includes(ix.action);
|
|
327
|
+
}
|
|
328
|
+
function isOrderbookInstruction(ix) {
|
|
329
|
+
return Object.values(vault_instruction_types_2.OrderbookAction).includes(ix.action);
|
|
330
|
+
}
|
|
331
|
+
function isCoreInstruction(ix) {
|
|
332
|
+
return Object.values(vault_instruction_types_2.CoreAction).includes(ix.action);
|
|
333
|
+
}
|
|
334
|
+
function isSyInstruction(ix) {
|
|
335
|
+
return Object.values(vault_instruction_types_2.SyAction).includes(ix.action);
|
|
336
|
+
}
|
|
337
|
+
function isTitanInstruction(ix) {
|
|
338
|
+
return Object.values(vault_instruction_types_2.TitanAction).includes(ix.action);
|
|
339
|
+
}
|
|
340
|
+
function isClmmInstruction(ix) {
|
|
341
|
+
return Object.values(vault_instruction_types_2.ClmmAction).includes(ix.action);
|
|
342
|
+
}
|
|
343
|
+
function isLoopscaleInstruction(ix) {
|
|
344
|
+
return Object.values(vault_instruction_types_2.LoopscaleAction).includes(ix.action);
|
|
345
|
+
}
|
|
346
|
+
/** Cache for loaded vaults to avoid redundant fetches */
|
|
347
|
+
const vaultCache = new Map();
|
|
348
|
+
const TITAN_INPUT_MINT_ACCOUNT_INDEX = 2;
|
|
349
|
+
const TITAN_INPUT_TOKEN_ACCOUNT_INDEX = 3;
|
|
350
|
+
const TITAN_OUTPUT_MINT_ACCOUNT_INDEX = 4;
|
|
351
|
+
const TITAN_OUTPUT_TOKEN_ACCOUNT_INDEX = 5;
|
|
352
|
+
const TITAN_INPUT_TOKEN_PROGRAM_ACCOUNT_INDEX = 6;
|
|
353
|
+
const TITAN_OUTPUT_TOKEN_PROGRAM_ACCOUNT_INDEX = 7;
|
|
354
|
+
const YIELD_POSITION_BASE_SIZE = 124;
|
|
355
|
+
const YIELD_POSITION_TRACKER_SIZE = 40;
|
|
356
|
+
function createStrategySetupContext({ connection, env, owner, signer, vaultAddress, policyPda, vaultPda, accountIndex = 0, squadsProgram = syncTransaction_1.SQUADS_PROGRAM_ID, leadingAccounts, preHookAccounts, postHookAccounts, autoManagePositions = true, pricesAccount, }) {
|
|
357
|
+
return {
|
|
358
|
+
connection,
|
|
359
|
+
env,
|
|
360
|
+
owner,
|
|
361
|
+
signer,
|
|
362
|
+
vaultAddress,
|
|
363
|
+
policyPda,
|
|
364
|
+
vaultPda,
|
|
365
|
+
accountIndex,
|
|
366
|
+
squadsProgram,
|
|
367
|
+
leadingAccounts,
|
|
368
|
+
preHookAccounts,
|
|
369
|
+
postHookAccounts,
|
|
370
|
+
autoManagePositions,
|
|
371
|
+
pricesAccount,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
exports.createStrategySetupContext = createStrategySetupContext;
|
|
375
|
+
function trackRequiredPriceIds(requiredPriceIds, priceIdValue) {
|
|
376
|
+
for (const id of (0, pricePathResolver_1.extractPriceIds)(priceIdValue)) {
|
|
377
|
+
const numericId = Number(id);
|
|
378
|
+
if (numericId !== 0) {
|
|
379
|
+
requiredPriceIds.add(numericId);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async function loadStrategySetupState(context) {
|
|
384
|
+
if (!context.vaultAddress) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
if (!context.statePromise) {
|
|
388
|
+
context.statePromise = (async () => {
|
|
389
|
+
const strategyVault = await vault_3.ExponentVault.load({
|
|
390
|
+
env: context.env,
|
|
391
|
+
connection: context.connection,
|
|
392
|
+
address: context.vaultAddress,
|
|
393
|
+
});
|
|
394
|
+
const prices = context.pricesAccount ?? await strategyVault.fetcher.fetchExponentPrices();
|
|
395
|
+
const trackedOrderbooks = new Set();
|
|
396
|
+
const trackedYieldVaults = new Set();
|
|
397
|
+
const trackedKaminoObligations = new Map();
|
|
398
|
+
const trackedKaminoFarms = new Set();
|
|
399
|
+
const trackedClmmPositions = new Set();
|
|
400
|
+
const tokenEntryAccountByMint = new Map();
|
|
401
|
+
const tokenPositionIndexByMint = new Map();
|
|
402
|
+
const trackedTokenAccounts = new Set();
|
|
403
|
+
for (const entry of strategyVault.state.tokenEntries) {
|
|
404
|
+
tokenEntryAccountByMint.set(entry.mint.toBase58(), entry.tokenSquadsAccount.toBase58());
|
|
405
|
+
trackedTokenAccounts.add(entry.tokenSquadsAccount.toBase58());
|
|
406
|
+
}
|
|
407
|
+
for (const [index, position] of strategyVault.state.strategyPositions.entries()) {
|
|
408
|
+
if ("orderbook" in position && position.orderbook?.[0]) {
|
|
409
|
+
trackedOrderbooks.add(position.orderbook[0].orderbook.toBase58());
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if ("yieldPosition" in position && position.yieldPosition?.[0]) {
|
|
413
|
+
trackedYieldVaults.add(position.yieldPosition[0].vault.toBase58());
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const kaminoEntry = getTrackedKaminoObligationFromPosition(position);
|
|
417
|
+
if (kaminoEntry) {
|
|
418
|
+
trackedKaminoObligations.set(kaminoEntry.obligation.toBase58(), {
|
|
419
|
+
quotePriceId: kaminoEntry.quotePriceId,
|
|
420
|
+
quoteInputMint: (0, pricePathResolver_1.getPriceInputMintFromPriceId)(prices, kaminoEntry.quotePriceId),
|
|
421
|
+
mappedReserves: new Set((kaminoEntry.reservePriceMappings ?? []).map((mapping) => mapping.reserve.toBase58())),
|
|
422
|
+
});
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
const kaminoFarmEntry = getTrackedKaminoFarmFromPosition(position);
|
|
426
|
+
if (kaminoFarmEntry) {
|
|
427
|
+
trackedKaminoFarms.add(kaminoFarmKey(kaminoFarmEntry.farmState, kaminoFarmEntry.userState));
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const clmmEntry = getTrackedClmmPositionFromPosition(position);
|
|
431
|
+
if (clmmEntry) {
|
|
432
|
+
trackedClmmPositions.add(clmmEntry.lpPosition.toBase58());
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if ("tokenAccount" in position && position.tokenAccount?.[0]) {
|
|
436
|
+
const entry = position.tokenAccount[0];
|
|
437
|
+
tokenPositionIndexByMint.set(entry.tokenMint.toBase58(), index);
|
|
438
|
+
for (const balance of entry.balances) {
|
|
439
|
+
trackedTokenAccounts.add(balance.tokenAccount.toBase58());
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
strategyVault,
|
|
445
|
+
prices,
|
|
446
|
+
requiredPriceIds: (0, vault_2.collectTrackedStrategyVaultPriceIds)({
|
|
447
|
+
tokenEntries: strategyVault.state.tokenEntries,
|
|
448
|
+
strategyPositions: strategyVault.state.strategyPositions,
|
|
449
|
+
}),
|
|
450
|
+
nextStrategyPositionIndex: strategyVault.state.strategyPositions.length,
|
|
451
|
+
trackedOrderbooks,
|
|
452
|
+
trackedYieldVaults,
|
|
453
|
+
trackedKaminoObligations,
|
|
454
|
+
trackedKaminoFarms,
|
|
455
|
+
trackedClmmPositions,
|
|
456
|
+
tokenEntryAccountByMint,
|
|
457
|
+
tokenPositionIndexByMint,
|
|
458
|
+
trackedTokenAccounts,
|
|
459
|
+
baseAumAccounts: mutableStrategyVault(strategyVault).aumRemainingAccounts(),
|
|
460
|
+
plannedAumAccounts: [],
|
|
461
|
+
existingAccounts: new Map(),
|
|
462
|
+
};
|
|
463
|
+
})();
|
|
464
|
+
}
|
|
465
|
+
return context.statePromise;
|
|
466
|
+
}
|
|
467
|
+
async function buildSetupStatePriceRefreshInstructions(setupContext) {
|
|
468
|
+
const state = await loadStrategySetupState(setupContext);
|
|
469
|
+
if (!state) {
|
|
470
|
+
return [];
|
|
471
|
+
}
|
|
472
|
+
const refreshInstructions = [];
|
|
473
|
+
const reserveAccounts = new Map();
|
|
474
|
+
for (const priceId of state.requiredPriceIds) {
|
|
475
|
+
const priceEntry = state.prices.prices[priceId];
|
|
476
|
+
if (!priceEntry || !isKaminoVaultPriceType(priceEntry.priceType)) {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
for (const reserveAddress of priceEntry.interfaceAccounts.slice(1)) {
|
|
480
|
+
const reserveKey = reserveAddress.toBase58();
|
|
481
|
+
if (reserveAccounts.has(reserveKey)) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
const reserveAccount = await kamino_reserve_deserializer_1.Reserve.fetch(setupContext.connection, reserveAddress);
|
|
485
|
+
if (!reserveAccount) {
|
|
486
|
+
throw new Error(`Missing Kamino reserve account ${reserveKey} required to refresh Kamino vault prices`);
|
|
487
|
+
}
|
|
488
|
+
reserveAccounts.set(reserveKey, { account: reserveAccount });
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (reserveAccounts.size > 0) {
|
|
492
|
+
const reserves = [...reserveAccounts.values()];
|
|
493
|
+
const defaultKey = web3_js_1.PublicKey.default;
|
|
494
|
+
const oracleOrSentinel = (key) => key.equals(defaultKey) ? policyBuilders_1.KAMINO_LENDING_PROGRAM_ID : key;
|
|
495
|
+
refreshInstructions.push(...await (0, scope_refresh_1.buildScopeRefreshInstructions)(setupContext.connection, reserves));
|
|
496
|
+
for (const [reserveKey, { account }] of reserveAccounts.entries()) {
|
|
497
|
+
const tokenInfo = account.config.tokenInfo;
|
|
498
|
+
refreshInstructions.push((0, instructions_1.refreshReserve)({
|
|
499
|
+
reserve: new web3_js_1.PublicKey(reserveKey),
|
|
500
|
+
lendingMarket: account.lendingMarket,
|
|
501
|
+
pythOracle: oracleOrSentinel(tokenInfo.pythConfiguration.price),
|
|
502
|
+
switchboardPriceOracle: oracleOrSentinel(tokenInfo.switchboardConfiguration.priceAggregator),
|
|
503
|
+
switchboardTwapOracle: oracleOrSentinel(tokenInfo.switchboardConfiguration.twapAggregator),
|
|
504
|
+
scopePrices: oracleOrSentinel(tokenInfo.scopeConfiguration.priceFeed),
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
const updatePriceInstructions = await state.strategyVault.ixsUpdateStrategyVaultPrices(state.prices, {
|
|
509
|
+
manager: setupContext.signer,
|
|
510
|
+
priceIds: [...state.requiredPriceIds].sort((a, b) => a - b),
|
|
511
|
+
});
|
|
512
|
+
return [...refreshInstructions, ...updatePriceInstructions];
|
|
513
|
+
}
|
|
514
|
+
exports.buildSetupStatePriceRefreshInstructions = buildSetupStatePriceRefreshInstructions;
|
|
515
|
+
function isAutoManagePositionsEnabled(setupContext) {
|
|
516
|
+
return setupContext?.autoManagePositions ?? true;
|
|
517
|
+
}
|
|
518
|
+
function unwrapTupleLikeValue(value) {
|
|
519
|
+
if (Array.isArray(value)) {
|
|
520
|
+
return value[0];
|
|
521
|
+
}
|
|
522
|
+
if (value && typeof value === "object" && "0" in value) {
|
|
523
|
+
return value[0];
|
|
524
|
+
}
|
|
525
|
+
return value ?? undefined;
|
|
526
|
+
}
|
|
527
|
+
function getTrackedKaminoObligationFromPosition(position) {
|
|
528
|
+
if (!position || typeof position !== "object" || !("obligation" in position)) {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
const obligationContainer = position.obligation;
|
|
532
|
+
const obligationValue = unwrapTupleLikeValue(obligationContainer);
|
|
533
|
+
const kaminoContainer = (obligationValue
|
|
534
|
+
&& typeof obligationValue === "object"
|
|
535
|
+
&& "kaminoObligation" in obligationValue)
|
|
536
|
+
? obligationValue.kaminoObligation
|
|
537
|
+
: obligationValue;
|
|
538
|
+
const kaminoEntry = unwrapTupleLikeValue(kaminoContainer);
|
|
539
|
+
if (!kaminoEntry
|
|
540
|
+
|| typeof kaminoEntry !== "object"
|
|
541
|
+
|| !("obligation" in kaminoEntry)
|
|
542
|
+
|| !(kaminoEntry.obligation instanceof web3_js_1.PublicKey)) {
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
const typedKaminoEntry = kaminoEntry;
|
|
546
|
+
return {
|
|
547
|
+
obligation: typedKaminoEntry.obligation,
|
|
548
|
+
quotePriceId: typedKaminoEntry.quotePriceId,
|
|
549
|
+
reservePriceMappings: typedKaminoEntry.reservePriceMappings ?? [],
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function getTrackedKaminoFarmFromPosition(position) {
|
|
553
|
+
if (!position || typeof position !== "object" || !("kaminoFarm" in position)) {
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
const kaminoFarmContainer = position.kaminoFarm;
|
|
557
|
+
const kaminoFarmEntry = unwrapTupleLikeValue(kaminoFarmContainer);
|
|
558
|
+
if (!kaminoFarmEntry
|
|
559
|
+
|| typeof kaminoFarmEntry !== "object"
|
|
560
|
+
|| !(kaminoFarmEntry.farmState instanceof web3_js_1.PublicKey)
|
|
561
|
+
|| !(kaminoFarmEntry.userState instanceof web3_js_1.PublicKey)) {
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
farmState: kaminoFarmEntry.farmState,
|
|
566
|
+
userState: kaminoFarmEntry.userState,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
function kaminoFarmKey(farmState, userState) {
|
|
570
|
+
return `${farmState.toBase58()}:${userState.toBase58()}`;
|
|
571
|
+
}
|
|
572
|
+
function getTrackedClmmPositionFromPosition(position) {
|
|
573
|
+
if (!position || typeof position !== "object" || !("clmmPosition" in position)) {
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const clmmContainer = position.clmmPosition;
|
|
577
|
+
const clmmEntry = unwrapTupleLikeValue(clmmContainer);
|
|
578
|
+
if (!clmmEntry
|
|
579
|
+
|| typeof clmmEntry !== "object"
|
|
580
|
+
|| !(clmmEntry.lpPosition instanceof web3_js_1.PublicKey)
|
|
581
|
+
|| !(clmmEntry.market instanceof web3_js_1.PublicKey)) {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
return {
|
|
585
|
+
lpPosition: clmmEntry.lpPosition,
|
|
586
|
+
market: clmmEntry.market,
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
async function accountExists(state, connection, address) {
|
|
590
|
+
const cacheKey = address.toBase58();
|
|
591
|
+
const cached = state.existingAccounts.get(cacheKey);
|
|
592
|
+
if (cached !== undefined) {
|
|
593
|
+
return cached;
|
|
594
|
+
}
|
|
595
|
+
const exists = (await connection.getAccountInfo(address)) !== null;
|
|
596
|
+
state.existingAccounts.set(cacheKey, exists);
|
|
597
|
+
return exists;
|
|
598
|
+
}
|
|
599
|
+
function mutableStrategyVault(value) {
|
|
600
|
+
return ("strategyVault" in value ? value.strategyVault : value);
|
|
601
|
+
}
|
|
602
|
+
function buildTrackedAumRemainingAccounts(state, extraAccounts = []) {
|
|
603
|
+
return (0, utils_1.uniqueRemainingAccounts)([
|
|
604
|
+
...state.baseAumAccounts,
|
|
605
|
+
...state.plannedAumAccounts,
|
|
606
|
+
...extraAccounts,
|
|
607
|
+
]);
|
|
608
|
+
}
|
|
609
|
+
function recordPlannedOrderbookEntry(state, params) {
|
|
610
|
+
state.trackedOrderbooks.add(params.orderbook.toBase58());
|
|
611
|
+
state.plannedAumAccounts.push({ pubkey: params.orderbook, isSigner: false, isWritable: false });
|
|
612
|
+
state.strategyVault.state.strategyPositions.push({
|
|
613
|
+
orderbook: [{
|
|
614
|
+
orderbook: params.orderbook,
|
|
615
|
+
mint: params.mint,
|
|
616
|
+
offerIdxVec: [],
|
|
617
|
+
priceIdPt: params.priceIdPt,
|
|
618
|
+
baseMint: params.baseMint,
|
|
619
|
+
}],
|
|
620
|
+
});
|
|
621
|
+
state.nextStrategyPositionIndex += 1;
|
|
622
|
+
}
|
|
623
|
+
function recordPlannedYieldPosition(state, params) {
|
|
624
|
+
state.trackedYieldVaults.add(params.vault.toBase58());
|
|
625
|
+
state.existingAccounts.set(params.yieldPosition.toBase58(), true);
|
|
626
|
+
state.strategyVault.state.strategyPositions.push({
|
|
627
|
+
yieldPosition: [{
|
|
628
|
+
yieldPosition: params.yieldPosition,
|
|
629
|
+
vault: params.vault,
|
|
630
|
+
priceIdPt: params.priceIdPt,
|
|
631
|
+
}],
|
|
632
|
+
});
|
|
633
|
+
state.nextStrategyPositionIndex += 1;
|
|
634
|
+
}
|
|
635
|
+
function recordPlannedTokenAccountEntry(state, params) {
|
|
636
|
+
const tokenMintKey = params.tokenMint.toBase58();
|
|
637
|
+
const tokenAccountKey = params.tokenAccount.toBase58();
|
|
638
|
+
state.tokenPositionIndexByMint.set(tokenMintKey, state.nextStrategyPositionIndex);
|
|
639
|
+
state.trackedTokenAccounts.add(tokenAccountKey);
|
|
640
|
+
state.plannedAumAccounts.push({ pubkey: params.tokenAccount, isSigner: false, isWritable: false });
|
|
641
|
+
state.strategyVault.state.strategyPositions.push({
|
|
642
|
+
tokenAccount: [{
|
|
643
|
+
tokenMint: params.tokenMint,
|
|
644
|
+
balances: [{
|
|
645
|
+
tokenAccount: params.tokenAccount,
|
|
646
|
+
mint: params.tokenMint,
|
|
647
|
+
priceId: params.priceId,
|
|
648
|
+
}],
|
|
649
|
+
}],
|
|
650
|
+
});
|
|
651
|
+
state.nextStrategyPositionIndex += 1;
|
|
652
|
+
}
|
|
653
|
+
function recordPlannedTokenAccountBalance(state, params) {
|
|
654
|
+
const tokenMintKey = params.tokenMint.toBase58();
|
|
655
|
+
const tokenAccountKey = params.tokenAccount.toBase58();
|
|
656
|
+
state.trackedTokenAccounts.add(tokenAccountKey);
|
|
657
|
+
state.plannedAumAccounts.push({ pubkey: params.tokenAccount, isSigner: false, isWritable: false });
|
|
658
|
+
const positions = state.strategyVault.state.strategyPositions;
|
|
659
|
+
const target = positions.find((position) => {
|
|
660
|
+
const tokenAccountEntry = Array.isArray(position.tokenAccount) ? position.tokenAccount[0] : undefined;
|
|
661
|
+
return tokenAccountEntry && tokenAccountEntry.tokenMint instanceof web3_js_1.PublicKey && tokenAccountEntry.tokenMint.equals(params.tokenMint);
|
|
662
|
+
});
|
|
663
|
+
const tokenAccountEntry = target?.tokenAccount?.[0];
|
|
664
|
+
tokenAccountEntry?.balances?.push({
|
|
665
|
+
tokenAccount: params.tokenAccount,
|
|
666
|
+
mint: params.tokenMint,
|
|
667
|
+
priceId: params.priceId,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
function recordPlannedKaminoObligation(state, entry) {
|
|
671
|
+
state.existingAccounts.set(entry.obligation.toBase58(), true);
|
|
672
|
+
state.trackedKaminoObligations.set(entry.obligation.toBase58(), {
|
|
673
|
+
quotePriceId: entry.quotePriceId,
|
|
674
|
+
quoteInputMint: entry.quoteInputMint,
|
|
675
|
+
mappedReserves: new Set(entry.reservePriceMappings.map((mapping) => mapping.reserve.toBase58())),
|
|
676
|
+
});
|
|
677
|
+
state.plannedAumAccounts.push({ pubkey: entry.obligation, isSigner: false, isWritable: false });
|
|
678
|
+
for (const mapping of entry.reservePriceMappings) {
|
|
679
|
+
state.plannedAumAccounts.push({ pubkey: mapping.reserve, isSigner: false, isWritable: false });
|
|
680
|
+
}
|
|
681
|
+
;
|
|
682
|
+
state.strategyVault.state.strategyPositions.push({
|
|
683
|
+
obligation: [{
|
|
684
|
+
kaminoObligation: [{
|
|
685
|
+
obligation: entry.obligation,
|
|
686
|
+
lendingProgramId: policyBuilders_1.KAMINO_LENDING_PROGRAM_ID,
|
|
687
|
+
quotePriceId: entry.quotePriceId,
|
|
688
|
+
reservePriceMappings: entry.reservePriceMappings,
|
|
689
|
+
remainingAccountsAmount: entry.remainingAccountsAmount,
|
|
690
|
+
minPriceStatusFlags: entry.minPriceStatusFlags,
|
|
691
|
+
}],
|
|
692
|
+
}],
|
|
693
|
+
});
|
|
694
|
+
state.nextStrategyPositionIndex += 1;
|
|
695
|
+
}
|
|
696
|
+
function recordPlannedKaminoReserveMappings(state, params) {
|
|
697
|
+
const tracked = state.trackedKaminoObligations.get(params.obligation.toBase58());
|
|
698
|
+
if (!tracked) {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
tracked.quoteInputMint = params.quoteInputMint;
|
|
702
|
+
for (const mapping of params.reservePriceMappings) {
|
|
703
|
+
tracked.mappedReserves.add(mapping.reserve.toBase58());
|
|
704
|
+
}
|
|
705
|
+
const positions = state.strategyVault.state.strategyPositions;
|
|
706
|
+
const target = positions.find((position) => {
|
|
707
|
+
const entry = getTrackedKaminoObligationFromPosition(position);
|
|
708
|
+
return entry?.obligation.equals(params.obligation);
|
|
709
|
+
});
|
|
710
|
+
const kaminoEntry = (Array.isArray(target?.obligation)
|
|
711
|
+
? target?.obligation?.[0]?.kaminoObligation?.[0]
|
|
712
|
+
: undefined);
|
|
713
|
+
if (!kaminoEntry) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
for (const mapping of params.reservePriceMappings) {
|
|
717
|
+
const existing = kaminoEntry.reservePriceMappings?.find((item) => item.reserve.equals(mapping.reserve));
|
|
718
|
+
if (existing) {
|
|
719
|
+
existing.reservePriceId = mapping.reservePriceId;
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
kaminoEntry.reservePriceMappings ??= [];
|
|
723
|
+
kaminoEntry.reservePriceMappings.push(mapping);
|
|
724
|
+
}
|
|
725
|
+
state.plannedAumAccounts.push({ pubkey: mapping.reserve, isSigner: false, isWritable: false });
|
|
726
|
+
}
|
|
727
|
+
kaminoEntry.remainingAccountsAmount = BigInt(1 + (kaminoEntry.reservePriceMappings?.length ?? 0));
|
|
728
|
+
}
|
|
729
|
+
function recordPlannedKaminoFarmPosition(state, params) {
|
|
730
|
+
const trackingKey = kaminoFarmKey(params.farmState, params.userState);
|
|
731
|
+
if (state.trackedKaminoFarms.has(trackingKey)) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
state.trackedKaminoFarms.add(trackingKey);
|
|
735
|
+
state.existingAccounts.set(params.userState.toBase58(), true);
|
|
736
|
+
state.plannedAumAccounts.push({ pubkey: params.farmState, isSigner: false, isWritable: false });
|
|
737
|
+
state.plannedAumAccounts.push({ pubkey: params.userState, isSigner: false, isWritable: false });
|
|
738
|
+
state.plannedAumAccounts.push({ pubkey: params.globalConfig, isSigner: false, isWritable: false });
|
|
739
|
+
if (params.scopePrices) {
|
|
740
|
+
state.plannedAumAccounts.push({ pubkey: params.scopePrices, isSigner: false, isWritable: false });
|
|
741
|
+
}
|
|
742
|
+
;
|
|
743
|
+
state.strategyVault.state.strategyPositions.push({
|
|
744
|
+
kaminoFarm: [{
|
|
745
|
+
farmState: params.farmState,
|
|
746
|
+
userState: params.userState,
|
|
747
|
+
}],
|
|
748
|
+
});
|
|
749
|
+
state.nextStrategyPositionIndex += 1;
|
|
750
|
+
}
|
|
751
|
+
function recordPlannedClmmPosition(state, params) {
|
|
752
|
+
state.existingAccounts.set(params.lpPosition.toBase58(), true);
|
|
753
|
+
state.trackedClmmPositions.add(params.lpPosition.toBase58());
|
|
754
|
+
state.plannedAumAccounts.push({ pubkey: params.lpPosition, isSigner: false, isWritable: false });
|
|
755
|
+
mutableStrategyVault(state).clmmTicksMap.set(params.market.toBase58(), params.ticksKey);
|
|
756
|
+
state.strategyVault.state.strategyPositions.push({
|
|
757
|
+
clmmPosition: [{
|
|
758
|
+
lpPosition: params.lpPosition,
|
|
759
|
+
market: params.market,
|
|
760
|
+
priceIdPt: params.priceIdPt,
|
|
761
|
+
priceIdSy: params.priceIdSy,
|
|
762
|
+
}],
|
|
763
|
+
});
|
|
764
|
+
state.nextStrategyPositionIndex += 1;
|
|
765
|
+
}
|
|
766
|
+
async function maybeCreateOwnedAtaSetupInstruction({ state, connection, payer, owner, mint, tokenProgram, tokenAccount, }) {
|
|
767
|
+
if (await accountExists(state, connection, tokenAccount)) {
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
const expectedAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, owner, true, tokenProgram);
|
|
771
|
+
if (!expectedAta.equals(tokenAccount)) {
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
state.existingAccounts.set(tokenAccount.toBase58(), true);
|
|
775
|
+
return (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payer, tokenAccount, owner, mint, tokenProgram);
|
|
776
|
+
}
|
|
777
|
+
async function ensureOrderbookPositionSetup(orderbook, buckets, setupContext) {
|
|
778
|
+
const state = await loadStrategySetupState(setupContext);
|
|
779
|
+
if (!state) {
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
const orderbookKey = orderbook.selfAddress.toBase58();
|
|
783
|
+
if (state.trackedOrderbooks.has(orderbookKey)) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
const priceIdPt = (0, pricePathResolver_1.resolvePriceIdFromMintToUnderlyingOrThrow)({
|
|
787
|
+
prices: state.prices,
|
|
788
|
+
sourceMint: orderbook.mintPt,
|
|
789
|
+
targetMint: state.strategyVault.state.underlyingMint,
|
|
790
|
+
label: `orderbook setup (${orderbook.selfAddress.toBase58()})`,
|
|
791
|
+
});
|
|
792
|
+
trackRequiredPriceIds(state.requiredPriceIds, priceIdPt);
|
|
793
|
+
buckets.setupInstructions.push(state.strategyVault.ixWrapperManageVaultSettings({
|
|
794
|
+
manager: setupContext.signer,
|
|
795
|
+
actions: [
|
|
796
|
+
exponentVaults.vaultSettingsAction("AddOrderbookEntry", [{
|
|
797
|
+
orderbook: orderbook.selfAddress,
|
|
798
|
+
// Legacy field retained for layout compatibility. Order ownership is
|
|
799
|
+
// derived from live orderbook state during AUM calculation.
|
|
800
|
+
userEscrowIdx: 0,
|
|
801
|
+
mint: orderbook.vault.mintSy,
|
|
802
|
+
offerIdxVec: [],
|
|
803
|
+
priceIdPt,
|
|
804
|
+
baseMint: state.strategyVault.state.underlyingMint,
|
|
805
|
+
}]),
|
|
806
|
+
],
|
|
807
|
+
remainingAccounts: [
|
|
808
|
+
{ pubkey: orderbook.selfAddress, isSigner: false, isWritable: false },
|
|
809
|
+
{ pubkey: orderbook.state.vault, isSigner: false, isWritable: false },
|
|
810
|
+
],
|
|
811
|
+
}));
|
|
812
|
+
recordPlannedOrderbookEntry(state, {
|
|
813
|
+
orderbook: orderbook.selfAddress,
|
|
814
|
+
mint: orderbook.vault.mintSy,
|
|
815
|
+
priceIdPt,
|
|
816
|
+
baseMint: state.strategyVault.state.underlyingMint,
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
async function ensureYieldPositionSetup(coreVault, buckets, setupContext) {
|
|
820
|
+
const state = await loadStrategySetupState(setupContext);
|
|
821
|
+
if (!state) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
const coreVaultKey = coreVault.selfAddress.toBase58();
|
|
825
|
+
if (state.trackedYieldVaults.has(coreVaultKey)) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const priceIdPt = (0, pricePathResolver_1.resolvePriceIdFromMintToUnderlyingOrThrow)({
|
|
829
|
+
prices: state.prices,
|
|
830
|
+
sourceMint: coreVault.mintPt,
|
|
831
|
+
targetMint: state.strategyVault.state.underlyingMint,
|
|
832
|
+
label: `core vault setup (${coreVault.selfAddress.toBase58()})`,
|
|
833
|
+
});
|
|
834
|
+
trackRequiredPriceIds(state.requiredPriceIds, priceIdPt);
|
|
835
|
+
const yieldPosition = coreVault.pda.yieldPosition({ owner: setupContext.owner, vault: coreVault.selfAddress });
|
|
836
|
+
if (!(await accountExists(state, setupContext.connection, yieldPosition))) {
|
|
837
|
+
const requiredLamports = await setupContext.connection.getMinimumBalanceForRentExemption(YIELD_POSITION_BASE_SIZE + (coreVault.state.emissions.length * YIELD_POSITION_TRACKER_SIZE));
|
|
838
|
+
const ownerLamports = await setupContext.connection.getBalance(setupContext.owner);
|
|
839
|
+
if (ownerLamports < requiredLamports) {
|
|
840
|
+
buckets.setupInstructions.push(web3_js_1.SystemProgram.transfer({
|
|
841
|
+
fromPubkey: setupContext.signer,
|
|
842
|
+
toPubkey: setupContext.owner,
|
|
843
|
+
lamports: requiredLamports - ownerLamports,
|
|
844
|
+
}));
|
|
845
|
+
}
|
|
846
|
+
const initializeYieldPositionIx = coreVault.ixInitializeYieldPosition({ owner: setupContext.owner });
|
|
847
|
+
try {
|
|
848
|
+
buckets.setupInstructions.push(await wrapVaultSignedSetupInstruction({
|
|
849
|
+
instruction: initializeYieldPositionIx,
|
|
850
|
+
setupContext,
|
|
851
|
+
}));
|
|
852
|
+
}
|
|
853
|
+
catch (error) {
|
|
854
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
855
|
+
throw new Error(`Failed to auto-initialize yield position ${yieldPosition.toBase58()} for ${coreVault.selfAddress.toBase58()}: ${reason}`);
|
|
856
|
+
}
|
|
857
|
+
state.existingAccounts.set(yieldPosition.toBase58(), true);
|
|
858
|
+
}
|
|
859
|
+
buckets.setupInstructions.push(state.strategyVault.ixWrapperManageVaultSettings({
|
|
860
|
+
manager: setupContext.signer,
|
|
861
|
+
actions: [
|
|
862
|
+
exponentVaults.vaultSettingsAction("AddYieldPositionEntry", {
|
|
863
|
+
yieldPosition,
|
|
864
|
+
vault: coreVault.selfAddress,
|
|
865
|
+
priceIdPt,
|
|
866
|
+
}),
|
|
867
|
+
],
|
|
868
|
+
remainingAccounts: [
|
|
869
|
+
{ pubkey: coreVault.selfAddress, isSigner: false, isWritable: false },
|
|
870
|
+
{ pubkey: yieldPosition, isSigner: false, isWritable: false },
|
|
871
|
+
],
|
|
872
|
+
}));
|
|
873
|
+
recordPlannedYieldPosition(state, {
|
|
874
|
+
yieldPosition,
|
|
875
|
+
vault: coreVault.selfAddress,
|
|
876
|
+
priceIdPt,
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
async function wrapVaultSignedSetupInstruction({ instruction, setupContext, }) {
|
|
880
|
+
if (!setupContext.vaultPda) {
|
|
881
|
+
throw new Error("vaultPda is required to auto-wrap setup instructions");
|
|
882
|
+
}
|
|
883
|
+
let resolvedPolicyPda = setupContext.policyPda;
|
|
884
|
+
let constraintIndices;
|
|
885
|
+
if (!resolvedPolicyPda) {
|
|
886
|
+
if (!setupContext.vaultAddress) {
|
|
887
|
+
throw new Error("vaultAddress is required when policyPda is not provided");
|
|
888
|
+
}
|
|
889
|
+
const match = await (0, policyMatcher_1.resolvePolicyMatchForVault)(setupContext.connection, setupContext.vaultAddress, setupContext.signer, [instruction]);
|
|
890
|
+
resolvedPolicyPda = match.policyPda;
|
|
891
|
+
constraintIndices = match.constraintIndices;
|
|
892
|
+
}
|
|
893
|
+
else {
|
|
894
|
+
constraintIndices = await (0, policyMatcher_1.resolveConstraintIndices)(setupContext.connection, resolvedPolicyPda, [instruction]);
|
|
895
|
+
}
|
|
896
|
+
let resolvedLeadingAccounts = setupContext.leadingAccounts;
|
|
897
|
+
let resolvedPreHookAccounts = setupContext.preHookAccounts;
|
|
898
|
+
let resolvedPostHookAccounts = setupContext.postHookAccounts;
|
|
899
|
+
if (setupContext.vaultAddress
|
|
900
|
+
&& (!resolvedLeadingAccounts || !resolvedPreHookAccounts || !resolvedPostHookAccounts)) {
|
|
901
|
+
// Cache hook resolution on the context to avoid redundant RPC calls
|
|
902
|
+
// when wrapping multiple setup instructions in the same build.
|
|
903
|
+
if (!setupContext.resolvedHooksPromise) {
|
|
904
|
+
setupContext.resolvedHooksPromise = (0, policyMatcher_1.resolveHookAccounts)(setupContext.connection, resolvedPolicyPda, setupContext.vaultAddress, setupContext.signer);
|
|
905
|
+
}
|
|
906
|
+
const hooks = await setupContext.resolvedHooksPromise;
|
|
907
|
+
resolvedLeadingAccounts ??= hooks.leadingAccounts;
|
|
908
|
+
resolvedPreHookAccounts ??= hooks.preHookAccounts;
|
|
909
|
+
resolvedPostHookAccounts ??= hooks.postHookAccounts;
|
|
910
|
+
}
|
|
911
|
+
return (0, syncTransaction_1.wrapInstructionsInSyncTransaction)({
|
|
912
|
+
policyPda: resolvedPolicyPda,
|
|
913
|
+
vaultPda: setupContext.vaultPda,
|
|
914
|
+
signer: setupContext.signer,
|
|
915
|
+
instructions: [instruction],
|
|
916
|
+
squadsProgram: setupContext.squadsProgram,
|
|
917
|
+
accountIndex: setupContext.accountIndex,
|
|
918
|
+
constraintIndices,
|
|
919
|
+
leadingAccounts: resolvedLeadingAccounts,
|
|
920
|
+
preHookAccounts: resolvedPreHookAccounts,
|
|
921
|
+
postHookAccounts: resolvedPostHookAccounts,
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
async function ensureTrackedTokenAccountSetup({ tokenMint, tokenAccount, tokenProgram, buckets, setupContext, }) {
|
|
925
|
+
const state = await loadStrategySetupState(setupContext);
|
|
926
|
+
if (!state) {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
const tokenMintKey = tokenMint.toBase58();
|
|
930
|
+
const tokenAccountKey = tokenAccount.toBase58();
|
|
931
|
+
const tokenEntryAccount = state.tokenEntryAccountByMint.get(tokenMintKey);
|
|
932
|
+
if (tokenEntryAccount) {
|
|
933
|
+
if (tokenEntryAccount !== tokenAccountKey) {
|
|
934
|
+
throw new Error(`Mint ${tokenMintKey} is tracked as a token entry on ${tokenEntryAccount}; use that account instead of ${tokenAccountKey}`);
|
|
935
|
+
}
|
|
936
|
+
state.trackedTokenAccounts.add(tokenAccountKey);
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
if (state.trackedTokenAccounts.has(tokenAccountKey)) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
const priceId = (0, pricePathResolver_1.resolvePriceIdFromMintToUnderlyingOrThrow)({
|
|
943
|
+
prices: state.prices,
|
|
944
|
+
sourceMint: tokenMint,
|
|
945
|
+
targetMint: state.strategyVault.state.underlyingMint,
|
|
946
|
+
label: `token position setup (${tokenMint.toBase58()})`,
|
|
947
|
+
});
|
|
948
|
+
trackRequiredPriceIds(state.requiredPriceIds, priceId);
|
|
949
|
+
const maybeAtaIx = await maybeCreateOwnedAtaSetupInstruction({
|
|
950
|
+
state,
|
|
951
|
+
connection: setupContext.connection,
|
|
952
|
+
payer: setupContext.signer,
|
|
953
|
+
owner: setupContext.owner,
|
|
954
|
+
mint: tokenMint,
|
|
955
|
+
tokenProgram,
|
|
956
|
+
tokenAccount,
|
|
957
|
+
});
|
|
958
|
+
if (maybeAtaIx) {
|
|
959
|
+
buckets.setupInstructions.push(maybeAtaIx);
|
|
960
|
+
}
|
|
961
|
+
const positionIndex = state.tokenPositionIndexByMint.get(tokenMintKey);
|
|
962
|
+
if (positionIndex === undefined) {
|
|
963
|
+
buckets.setupInstructions.push(state.strategyVault.ixWrapperManageVaultSettings({
|
|
964
|
+
manager: setupContext.signer,
|
|
965
|
+
actions: [
|
|
966
|
+
exponentVaults.vaultSettingsAction("AddTokenAccountEntry", [{
|
|
967
|
+
tokenMint,
|
|
968
|
+
balances: [{
|
|
969
|
+
tokenAccount,
|
|
970
|
+
mint: tokenMint,
|
|
971
|
+
priceId,
|
|
972
|
+
}],
|
|
973
|
+
}]),
|
|
974
|
+
],
|
|
975
|
+
remainingAccounts: [
|
|
976
|
+
{ pubkey: tokenAccount, isSigner: false, isWritable: false },
|
|
977
|
+
],
|
|
978
|
+
}));
|
|
979
|
+
recordPlannedTokenAccountEntry(state, {
|
|
980
|
+
tokenMint,
|
|
981
|
+
tokenAccount,
|
|
982
|
+
priceId,
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
buckets.setupInstructions.push(state.strategyVault.ixWrapperManagerUpdatePosition({
|
|
987
|
+
manager: setupContext.signer,
|
|
988
|
+
update: {
|
|
989
|
+
__kind: "AddTokenAccountBalance",
|
|
990
|
+
tokenMint,
|
|
991
|
+
balance: {
|
|
992
|
+
tokenAccount,
|
|
993
|
+
mint: tokenMint,
|
|
994
|
+
priceId,
|
|
995
|
+
},
|
|
996
|
+
},
|
|
997
|
+
remainingAccounts: [
|
|
998
|
+
{ pubkey: tokenAccount, isSigner: false, isWritable: false },
|
|
999
|
+
],
|
|
1000
|
+
}));
|
|
1001
|
+
recordPlannedTokenAccountBalance(state, {
|
|
1002
|
+
tokenMint,
|
|
1003
|
+
tokenAccount,
|
|
1004
|
+
priceId,
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
state.trackedTokenAccounts.add(tokenAccountKey);
|
|
1008
|
+
}
|
|
1009
|
+
async function buildVaultInstructions(instructions, owner, connection, signer, policyPda, vaultPda, accountIndex, vaultAddress, leadingAccounts, preHookAccounts, postHookAccounts, squadsProgram = syncTransaction_1.SQUADS_PROGRAM_ID, autoManagePositions = true, sharedSetupContext) {
|
|
1010
|
+
const buckets = {
|
|
1011
|
+
setupInstructions: [],
|
|
1012
|
+
syncInstructions: [],
|
|
1013
|
+
preInstructions: [],
|
|
1014
|
+
postInstructions: [],
|
|
1015
|
+
signers: [],
|
|
1016
|
+
addressLookupTableAddresses: [],
|
|
1017
|
+
};
|
|
1018
|
+
const setupContext = sharedSetupContext ?? createStrategySetupContext({
|
|
1019
|
+
connection,
|
|
1020
|
+
env: environment_1.LOCAL_ENV,
|
|
1021
|
+
owner,
|
|
1022
|
+
signer,
|
|
1023
|
+
vaultAddress,
|
|
1024
|
+
policyPda,
|
|
1025
|
+
vaultPda,
|
|
1026
|
+
accountIndex,
|
|
1027
|
+
squadsProgram,
|
|
1028
|
+
leadingAccounts,
|
|
1029
|
+
preHookAccounts,
|
|
1030
|
+
postHookAccounts,
|
|
1031
|
+
autoManagePositions,
|
|
1032
|
+
});
|
|
1033
|
+
for (const ix of instructions) {
|
|
1034
|
+
if (isKaminoVaultInstruction(ix)) {
|
|
1035
|
+
await buildKaminoVaultInstruction(ix, buckets, setupContext);
|
|
1036
|
+
continue;
|
|
1037
|
+
}
|
|
1038
|
+
if (isKaminoFarmInstruction(ix)) {
|
|
1039
|
+
await buildKaminoFarmInstruction(ix, buckets, setupContext);
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
if (isOrderbookInstruction(ix)) {
|
|
1043
|
+
await buildOrderbookInstruction(ix, owner, connection, buckets, setupContext);
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
if (isCoreInstruction(ix)) {
|
|
1047
|
+
await buildCoreInstruction(ix, owner, connection, buckets, setupContext);
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
if (isSyInstruction(ix)) {
|
|
1051
|
+
await buildSyInstruction(ix, owner, connection, buckets, setupContext);
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (isTitanInstruction(ix)) {
|
|
1055
|
+
await buildTitanInstruction(ix, buckets, setupContext);
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
if (isLoopscaleInstruction(ix)) {
|
|
1059
|
+
await buildLoopscaleInstruction(ix, buckets, setupContext);
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (isClmmInstruction(ix)) {
|
|
1063
|
+
await buildClmmInstruction(ix, owner, connection, buckets, setupContext);
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
switch (ix.action) {
|
|
1067
|
+
case vault_instruction_types_2.VaultAction.INIT_USER_METADATA:
|
|
1068
|
+
await buildInitUserMetadata(owner, connection, buckets);
|
|
1069
|
+
break;
|
|
1070
|
+
case vault_instruction_types_2.VaultAction.INIT_OBLIGATION:
|
|
1071
|
+
await buildInitObligation(ix, owner, connection, buckets, setupContext);
|
|
1072
|
+
break;
|
|
1073
|
+
case vault_instruction_types_2.VaultAction.DEPOSIT:
|
|
1074
|
+
await buildDeposit(ix, owner, connection, signer, buckets, setupContext);
|
|
1075
|
+
break;
|
|
1076
|
+
case vault_instruction_types_2.VaultAction.WITHDRAW:
|
|
1077
|
+
await buildWithdraw(ix, owner, connection, signer, buckets, setupContext);
|
|
1078
|
+
break;
|
|
1079
|
+
case vault_instruction_types_2.VaultAction.BORROW:
|
|
1080
|
+
await buildBorrow(ix, owner, connection, signer, buckets, setupContext);
|
|
1081
|
+
break;
|
|
1082
|
+
case vault_instruction_types_2.VaultAction.REPAY:
|
|
1083
|
+
await buildRepay(ix, owner, connection, signer, buckets, setupContext);
|
|
1084
|
+
break;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
return buckets;
|
|
1088
|
+
}
|
|
1089
|
+
const KAMINO_VAULT_EVENT_AUTHORITY = (0, utils_1.emitEventAuthority)(policyBuilders_1.KAMINO_VAULT_PROGRAM_ID);
|
|
1090
|
+
const KAMINO_FARM_USER_STATE_SIZE = 920;
|
|
1091
|
+
const KAMINO_STAKE_ALL_AMOUNT = new bn_js_1.default("18446744073709551615");
|
|
1092
|
+
function toBn(value) {
|
|
1093
|
+
if (bn_js_1.default.isBN(value)) {
|
|
1094
|
+
return value;
|
|
1095
|
+
}
|
|
1096
|
+
return new bn_js_1.default(value.toString());
|
|
1097
|
+
}
|
|
1098
|
+
function encodeU64InstructionData(discriminator, value) {
|
|
1099
|
+
return Buffer.concat([discriminator, toBn(value).toArrayLike(Buffer, "le", 8)]);
|
|
1100
|
+
}
|
|
1101
|
+
function encodeU128InstructionData(discriminator, value) {
|
|
1102
|
+
return Buffer.concat([discriminator, toBn(value).toArrayLike(Buffer, "le", 16)]);
|
|
1103
|
+
}
|
|
1104
|
+
function getKaminoFarmUserStateAddress(delegatee, farmState) {
|
|
1105
|
+
return (0, constants_1.getKaminoFarmsObligationFarm)(delegatee, farmState, KAMINO_FARMS_PROGRAM_ID);
|
|
1106
|
+
}
|
|
1107
|
+
async function accountExistsMaybeTracked(setupContext, address) {
|
|
1108
|
+
if (!setupContext) {
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1111
|
+
const state = await loadStrategySetupState(setupContext);
|
|
1112
|
+
if (state) {
|
|
1113
|
+
return accountExists(state, setupContext.connection, address);
|
|
1114
|
+
}
|
|
1115
|
+
return (await setupContext.connection.getAccountInfo(address)) !== null;
|
|
1116
|
+
}
|
|
1117
|
+
function matchesKaminoVaultInterfaceAccounts(entry, interfaceAccounts) {
|
|
1118
|
+
return (entry.interfaceAccounts.length === interfaceAccounts.length
|
|
1119
|
+
&& entry.interfaceAccounts.every((account, index) => account.equals(interfaceAccounts[index])));
|
|
1120
|
+
}
|
|
1121
|
+
// ExponentPrices stores explicit wire discriminators, which can drift from the
|
|
1122
|
+
// generated TypeScript enum ordinals. Accept both so Kamino vault share
|
|
1123
|
+
// tracking works across current program/IDL combinations.
|
|
1124
|
+
function isKaminoVaultPriceType(priceType) {
|
|
1125
|
+
return priceType === KAMINO_VAULT_PRICE_TYPE_WIRE || priceType === exponentVaults.PriceType.KaminoVault;
|
|
1126
|
+
}
|
|
1127
|
+
function resolveKaminoVaultPriceEntry(params) {
|
|
1128
|
+
const candidates = params.prices.prices.filter((entry) => entry !== null).filter((entry) => isKaminoVaultPriceType(entry.priceType)
|
|
1129
|
+
&& entry.priceMint.equals(params.sharesMint)
|
|
1130
|
+
&& entry.underlyingMint.equals(params.depositTokenMint)
|
|
1131
|
+
&& matchesKaminoVaultInterfaceAccounts(entry, params.interfaceAccounts));
|
|
1132
|
+
if (candidates.length === 0) {
|
|
1133
|
+
const interfaceAccountsLabel = params.interfaceAccounts.map((account) => account.toBase58()).join(", ");
|
|
1134
|
+
throw new Error(`Missing Exponent KaminoVault price for shares mint ${params.sharesMint.toBase58()} and deposit mint ${params.depositTokenMint.toBase58()} (interface accounts: ${interfaceAccountsLabel}). Register a PriceType.KaminoVault price for this vault before using auto-managed Kamino vault share tracking.`);
|
|
1135
|
+
}
|
|
1136
|
+
if (candidates.length > 1) {
|
|
1137
|
+
throw new Error(`Multiple Exponent KaminoVault prices matched shares mint ${params.sharesMint.toBase58()} and deposit mint ${params.depositTokenMint.toBase58()}`);
|
|
1138
|
+
}
|
|
1139
|
+
return candidates[0];
|
|
1140
|
+
}
|
|
1141
|
+
function resolveKaminoVaultTrackedPriceId(params) {
|
|
1142
|
+
if (params.depositTokenMint.equals(params.state.strategyVault.state.underlyingMint)) {
|
|
1143
|
+
return { __kind: "Simple", priceId: params.sharePriceId };
|
|
1144
|
+
}
|
|
1145
|
+
const reservePriceId = (0, pricePathResolver_1.resolvePriceIdFromMintToUnderlyingOrThrow)({
|
|
1146
|
+
prices: params.state.prices,
|
|
1147
|
+
sourceMint: params.depositTokenMint,
|
|
1148
|
+
targetMint: params.state.strategyVault.state.underlyingMint,
|
|
1149
|
+
label: params.label,
|
|
1150
|
+
});
|
|
1151
|
+
const reservePriceIds = (0, pricePathResolver_1.extractPriceIds)(reservePriceId).map((id) => BigInt(id));
|
|
1152
|
+
return { __kind: "Multiply", priceIds: [...reservePriceIds, params.sharePriceId] };
|
|
1153
|
+
}
|
|
1154
|
+
async function resolveKaminoVaultContext(vaultAddress, setupContext) {
|
|
1155
|
+
const rawIndex = await (0, exponent_fetcher_1.fetchKaminoVaultIndex)({
|
|
1156
|
+
connection: setupContext.connection,
|
|
1157
|
+
kaminoVaultAccount: vaultAddress,
|
|
1158
|
+
});
|
|
1159
|
+
const reserveAddresses = rawIndex.reserves.map((reserve) => reserve.reserveAddress);
|
|
1160
|
+
const [vaultInfo, tokenMintInfo, sharesMintInfo, reserveInfos] = await Promise.all([
|
|
1161
|
+
setupContext.connection.getAccountInfo(vaultAddress),
|
|
1162
|
+
setupContext.connection.getAccountInfo(rawIndex.tokenMint),
|
|
1163
|
+
setupContext.connection.getAccountInfo(rawIndex.sharesMint),
|
|
1164
|
+
setupContext.connection.getMultipleAccountsInfo(reserveAddresses),
|
|
1165
|
+
]);
|
|
1166
|
+
if (!vaultInfo?.data) {
|
|
1167
|
+
throw new Error(`Kamino vault account not found: ${vaultAddress.toBase58()}`);
|
|
1168
|
+
}
|
|
1169
|
+
const decodedReserves = reserveInfos.map((reserveInfo, index) => {
|
|
1170
|
+
if (!reserveInfo?.data) {
|
|
1171
|
+
throw new Error(`Missing Kamino reserve account ${reserveAddresses[index].toBase58()}`);
|
|
1172
|
+
}
|
|
1173
|
+
return kamino_reserve_deserializer_1.Reserve.decode(reserveInfo.data);
|
|
1174
|
+
});
|
|
1175
|
+
const collateralMintInfos = await setupContext.connection.getMultipleAccountsInfo(decodedReserves.map((reserve) => reserve.collateral.mintPubkey));
|
|
1176
|
+
const normalizedReserves = reserveAddresses.map((reserveAddress, index) => {
|
|
1177
|
+
const reserveAccount = decodedReserves[index];
|
|
1178
|
+
const rawReserve = rawIndex.reserves[index];
|
|
1179
|
+
const allocationOffset = KAMINO_VAULT_ACCOUNT_DISCRIMINATOR_LEN
|
|
1180
|
+
+ KAMINO_VAULT_ALLOCATION_STRATEGY_OFFSET
|
|
1181
|
+
+ (index * KAMINO_VAULT_ALLOCATION_SIZE);
|
|
1182
|
+
const ctokenVaultOffset = allocationOffset + KAMINO_VAULT_ALLOCATION_CTOKEN_VAULT_OFFSET;
|
|
1183
|
+
const [lendingMarketAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("lma"), reserveAccount.lendingMarket.toBuffer()], policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
1184
|
+
return {
|
|
1185
|
+
reserveAddress,
|
|
1186
|
+
marketAddress: rawReserve.marketAddress ?? rawReserve.reserve ?? reserveAccount.lendingMarket,
|
|
1187
|
+
ctokenVault: rawReserve.ctokenVault
|
|
1188
|
+
?? new web3_js_1.PublicKey(vaultInfo.data.subarray(ctokenVaultOffset, ctokenVaultOffset + 32)),
|
|
1189
|
+
lendingMarketAuthority: rawReserve.lendingMarketAuthority ?? lendingMarketAuthority,
|
|
1190
|
+
pythOracle: rawReserve.pythOracle ?? reserveAccount.config.tokenInfo.pythConfiguration.price,
|
|
1191
|
+
switchboardPriceOracle: rawReserve.switchboardPriceOracle
|
|
1192
|
+
?? reserveAccount.config.tokenInfo.switchboardConfiguration.priceAggregator,
|
|
1193
|
+
switchboardTwapOracle: rawReserve.switchboardTwapOracle
|
|
1194
|
+
?? reserveAccount.config.tokenInfo.switchboardConfiguration.twapAggregator,
|
|
1195
|
+
scopePrices: rawReserve.scopePrices ?? reserveAccount.config.tokenInfo.scopeConfiguration.priceFeed,
|
|
1196
|
+
reserveLiquiditySupply: rawReserve.reserveLiquiditySupply ?? reserveAccount.liquidity.supplyVault,
|
|
1197
|
+
reserveCollateralMint: rawReserve.reserveCollateralMint ?? reserveAccount.collateral.mintPubkey,
|
|
1198
|
+
reserveCollateralTokenProgram: rawReserve.reserveCollateralTokenProgram ?? collateralMintInfos[index]?.owner ?? web3_js_1.PublicKey.default,
|
|
1199
|
+
};
|
|
1200
|
+
});
|
|
1201
|
+
const index = {
|
|
1202
|
+
...rawIndex,
|
|
1203
|
+
reserves: normalizedReserves,
|
|
1204
|
+
tokenProgram: rawIndex.tokenProgram ?? tokenMintInfo?.owner ?? spl_token_1.TOKEN_PROGRAM_ID,
|
|
1205
|
+
sharesTokenProgram: rawIndex.sharesTokenProgram
|
|
1206
|
+
?? sharesMintInfo?.owner
|
|
1207
|
+
?? spl_token_1.TOKEN_PROGRAM_ID,
|
|
1208
|
+
vaultLookupTable: rawIndex.vaultLookupTable ?? web3_js_1.PublicKey.default,
|
|
1209
|
+
};
|
|
1210
|
+
const tokenAta = (0, spl_token_1.getAssociatedTokenAddressSync)(index.tokenMint, setupContext.owner, true, index.tokenProgram);
|
|
1211
|
+
const sharesAta = (0, spl_token_1.getAssociatedTokenAddressSync)(index.sharesMint, setupContext.owner, true, index.sharesTokenProgram);
|
|
1212
|
+
return { index, tokenAta, sharesAta };
|
|
1213
|
+
}
|
|
1214
|
+
async function queueKaminoVaultSharesTracking(params) {
|
|
1215
|
+
const state = await loadStrategySetupState(params.setupContext);
|
|
1216
|
+
if (!state) {
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
const sharesMintKey = params.vaultContext.index.sharesMint.toBase58();
|
|
1220
|
+
const sharesAtaKey = params.vaultContext.sharesAta.toBase58();
|
|
1221
|
+
if (state.trackedTokenAccounts.has(sharesAtaKey)) {
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
const tokenEntryAccount = state.tokenEntryAccountByMint.get(sharesMintKey);
|
|
1225
|
+
if (tokenEntryAccount) {
|
|
1226
|
+
throw new Error(`Kamino Vault shares mint ${sharesMintKey} is already configured as a token entry on ${tokenEntryAccount}`);
|
|
1227
|
+
}
|
|
1228
|
+
const interfaceAccounts = [
|
|
1229
|
+
params.kaminoVaultAddress,
|
|
1230
|
+
...params.vaultContext.index.reserves.map((reserve) => reserve.reserveAddress),
|
|
1231
|
+
];
|
|
1232
|
+
const priceEntry = resolveKaminoVaultPriceEntry({
|
|
1233
|
+
prices: state.prices,
|
|
1234
|
+
sharesMint: params.vaultContext.index.sharesMint,
|
|
1235
|
+
depositTokenMint: params.vaultContext.index.tokenMint,
|
|
1236
|
+
interfaceAccounts,
|
|
1237
|
+
});
|
|
1238
|
+
const resolvedPriceId = resolveKaminoVaultTrackedPriceId({
|
|
1239
|
+
state,
|
|
1240
|
+
depositTokenMint: params.vaultContext.index.tokenMint,
|
|
1241
|
+
sharePriceId: priceEntry.priceId,
|
|
1242
|
+
label: `Kamino Vault shares tracking (${params.kaminoVaultAddress.toBase58()})`,
|
|
1243
|
+
});
|
|
1244
|
+
const remainingAccounts = (0, utils_1.uniqueRemainingAccounts)([
|
|
1245
|
+
{ pubkey: params.vaultContext.sharesAta, isSigner: false, isWritable: false },
|
|
1246
|
+
{ pubkey: priceEntry.priceInterfaceAccounts, isSigner: false, isWritable: false },
|
|
1247
|
+
...priceEntry.interfaceAccounts.map((account) => ({
|
|
1248
|
+
pubkey: account,
|
|
1249
|
+
isSigner: false,
|
|
1250
|
+
isWritable: false,
|
|
1251
|
+
})),
|
|
1252
|
+
...buildTrackedAumRemainingAccounts(state),
|
|
1253
|
+
]);
|
|
1254
|
+
// The hook validates Kamino vault deposits against the currently tracked
|
|
1255
|
+
// shares ATA, so this registration must happen before the Squads sync step.
|
|
1256
|
+
params.buckets.preInstructions.push(state.strategyVault.ixWrapperManagerUpdatePosition({
|
|
1257
|
+
manager: params.setupContext.signer,
|
|
1258
|
+
update: exponentVaults.positionUpdate("TrackKaminoVaultShares", {
|
|
1259
|
+
sharesMint: params.vaultContext.index.sharesMint,
|
|
1260
|
+
depositTokenMint: params.vaultContext.index.tokenMint,
|
|
1261
|
+
sharesTokenAccount: params.vaultContext.sharesAta,
|
|
1262
|
+
priceInterfaceAccounts: priceEntry.priceInterfaceAccounts,
|
|
1263
|
+
}),
|
|
1264
|
+
remainingAccounts,
|
|
1265
|
+
}));
|
|
1266
|
+
trackRequiredPriceIds(state.requiredPriceIds, resolvedPriceId);
|
|
1267
|
+
if (state.tokenPositionIndexByMint.get(sharesMintKey) === undefined) {
|
|
1268
|
+
recordPlannedTokenAccountEntry(state, {
|
|
1269
|
+
tokenMint: params.vaultContext.index.sharesMint,
|
|
1270
|
+
tokenAccount: params.vaultContext.sharesAta,
|
|
1271
|
+
priceId: resolvedPriceId,
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
recordPlannedTokenAccountBalance(state, {
|
|
1276
|
+
tokenMint: params.vaultContext.index.sharesMint,
|
|
1277
|
+
tokenAccount: params.vaultContext.sharesAta,
|
|
1278
|
+
priceId: resolvedPriceId,
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
async function resolveKaminoVaultValidationAccounts(params) {
|
|
1283
|
+
const state = await loadStrategySetupState(params.setupContext);
|
|
1284
|
+
if (!state) {
|
|
1285
|
+
return [];
|
|
1286
|
+
}
|
|
1287
|
+
const priceEntry = resolveKaminoVaultPriceEntry({
|
|
1288
|
+
prices: state.prices,
|
|
1289
|
+
sharesMint: params.vaultContext.index.sharesMint,
|
|
1290
|
+
depositTokenMint: params.vaultContext.index.tokenMint,
|
|
1291
|
+
interfaceAccounts: [
|
|
1292
|
+
params.kaminoVaultAddress,
|
|
1293
|
+
...params.vaultContext.index.reserves.map((reserve) => reserve.reserveAddress),
|
|
1294
|
+
],
|
|
1295
|
+
});
|
|
1296
|
+
return [
|
|
1297
|
+
{ pubkey: priceEntry.priceInterfaceAccounts, isSigner: false, isWritable: false },
|
|
1298
|
+
];
|
|
1299
|
+
}
|
|
1300
|
+
function buildKaminoVaultDepositInstruction(params) {
|
|
1301
|
+
const reserveAccounts = params.vaultContext.index.reserves.flatMap((reserve) => [
|
|
1302
|
+
{ pubkey: reserve.reserveAddress, isSigner: false, isWritable: true },
|
|
1303
|
+
{ pubkey: reserve.ctokenVault, isSigner: false, isWritable: true },
|
|
1304
|
+
{ pubkey: reserve.marketAddress, isSigner: false, isWritable: false },
|
|
1305
|
+
{ pubkey: reserve.lendingMarketAuthority, isSigner: false, isWritable: false },
|
|
1306
|
+
{ pubkey: reserve.reserveLiquiditySupply, isSigner: false, isWritable: true },
|
|
1307
|
+
{ pubkey: reserve.reserveCollateralMint, isSigner: false, isWritable: true },
|
|
1308
|
+
{ pubkey: reserve.reserveCollateralTokenProgram, isSigner: false, isWritable: false },
|
|
1309
|
+
{ pubkey: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
|
|
1310
|
+
{ pubkey: KAMINO_VAULT_EVENT_AUTHORITY, isSigner: false, isWritable: false },
|
|
1311
|
+
{ pubkey: policyBuilders_1.KAMINO_VAULT_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
1312
|
+
]);
|
|
1313
|
+
return new web3_js_1.TransactionInstruction({
|
|
1314
|
+
programId: policyBuilders_1.KAMINO_VAULT_PROGRAM_ID,
|
|
1315
|
+
keys: [
|
|
1316
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1317
|
+
{ pubkey: params.kaminoVaultAddress, isSigner: false, isWritable: true },
|
|
1318
|
+
{ pubkey: params.vaultContext.index.tokenVault, isSigner: false, isWritable: true },
|
|
1319
|
+
{ pubkey: params.vaultContext.index.tokenMint, isSigner: false, isWritable: false },
|
|
1320
|
+
{ pubkey: params.vaultContext.index.baseVaultAuthority, isSigner: false, isWritable: false },
|
|
1321
|
+
{ pubkey: params.vaultContext.index.sharesMint, isSigner: false, isWritable: true },
|
|
1322
|
+
{ pubkey: params.vaultContext.tokenAta, isSigner: false, isWritable: true },
|
|
1323
|
+
{ pubkey: params.vaultContext.sharesAta, isSigner: false, isWritable: true },
|
|
1324
|
+
{ pubkey: policyBuilders_1.KAMINO_LENDING_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
1325
|
+
{ pubkey: params.vaultContext.index.tokenProgram, isSigner: false, isWritable: false },
|
|
1326
|
+
{ pubkey: params.vaultContext.index.sharesTokenProgram, isSigner: false, isWritable: false },
|
|
1327
|
+
{ pubkey: KAMINO_VAULT_EVENT_AUTHORITY, isSigner: false, isWritable: false },
|
|
1328
|
+
{ pubkey: policyBuilders_1.KAMINO_VAULT_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
1329
|
+
...reserveAccounts,
|
|
1330
|
+
...params.vaultContext.index.reserves.map((reserve) => ({
|
|
1331
|
+
pubkey: reserve.reserveAddress,
|
|
1332
|
+
isSigner: false,
|
|
1333
|
+
isWritable: true,
|
|
1334
|
+
})),
|
|
1335
|
+
...(params.validationAccounts ?? []),
|
|
1336
|
+
],
|
|
1337
|
+
data: encodeU64InstructionData(policyBuilders_1.KAMINO_VAULT_DISCRIMINATORS.deposit, params.amount),
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
function resolveKaminoVaultWithdrawReserve(ix, vaultContext) {
|
|
1341
|
+
if (ix.reserve) {
|
|
1342
|
+
const reserve = vaultContext.index.reserves.find((entry) => entry.reserveAddress.equals(ix.reserve));
|
|
1343
|
+
if (!reserve) {
|
|
1344
|
+
throw new Error(`Kamino Vault ${ix.vault.toBase58()} does not use reserve ${ix.reserve.toBase58()}`);
|
|
1345
|
+
}
|
|
1346
|
+
return reserve;
|
|
1347
|
+
}
|
|
1348
|
+
if (vaultContext.index.reserves.length !== 1) {
|
|
1349
|
+
throw new Error(`Kamino Vault ${ix.vault.toBase58()} uses ${vaultContext.index.reserves.length} reserves; specify withdraw.reserve`);
|
|
1350
|
+
}
|
|
1351
|
+
return vaultContext.index.reserves[0];
|
|
1352
|
+
}
|
|
1353
|
+
function buildKaminoVaultWithdrawInstruction(params) {
|
|
1354
|
+
const reserve = resolveKaminoVaultWithdrawReserve(params.ix, params.vaultContext);
|
|
1355
|
+
const [globalConfig] = web3_js_1.PublicKey.findProgramAddressSync([KAMINO_VAULT_GLOBAL_CONFIG_SEED], policyBuilders_1.KAMINO_VAULT_PROGRAM_ID);
|
|
1356
|
+
return new web3_js_1.TransactionInstruction({
|
|
1357
|
+
programId: policyBuilders_1.KAMINO_VAULT_PROGRAM_ID,
|
|
1358
|
+
keys: [
|
|
1359
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1360
|
+
{ pubkey: params.ix.vault, isSigner: false, isWritable: true },
|
|
1361
|
+
{ pubkey: globalConfig, isSigner: false, isWritable: false },
|
|
1362
|
+
{ pubkey: params.vaultContext.index.tokenVault, isSigner: false, isWritable: true },
|
|
1363
|
+
{ pubkey: params.vaultContext.index.baseVaultAuthority, isSigner: false, isWritable: false },
|
|
1364
|
+
{ pubkey: params.vaultContext.tokenAta, isSigner: false, isWritable: true },
|
|
1365
|
+
{ pubkey: params.vaultContext.index.tokenMint, isSigner: false, isWritable: true },
|
|
1366
|
+
{ pubkey: params.vaultContext.sharesAta, isSigner: false, isWritable: true },
|
|
1367
|
+
{ pubkey: params.vaultContext.index.sharesMint, isSigner: false, isWritable: true },
|
|
1368
|
+
{ pubkey: params.vaultContext.index.tokenProgram, isSigner: false, isWritable: false },
|
|
1369
|
+
{ pubkey: params.vaultContext.index.sharesTokenProgram, isSigner: false, isWritable: false },
|
|
1370
|
+
{ pubkey: policyBuilders_1.KAMINO_LENDING_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
1371
|
+
{ pubkey: KAMINO_VAULT_EVENT_AUTHORITY, isSigner: false, isWritable: false },
|
|
1372
|
+
{ pubkey: policyBuilders_1.KAMINO_VAULT_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
1373
|
+
{ pubkey: params.ix.vault, isSigner: false, isWritable: true },
|
|
1374
|
+
{ pubkey: reserve.reserveAddress, isSigner: false, isWritable: true },
|
|
1375
|
+
{ pubkey: reserve.ctokenVault, isSigner: false, isWritable: true },
|
|
1376
|
+
{ pubkey: reserve.marketAddress, isSigner: false, isWritable: false },
|
|
1377
|
+
{ pubkey: reserve.lendingMarketAuthority, isSigner: false, isWritable: false },
|
|
1378
|
+
{ pubkey: reserve.reserveLiquiditySupply, isSigner: false, isWritable: true },
|
|
1379
|
+
{ pubkey: reserve.reserveCollateralMint, isSigner: false, isWritable: true },
|
|
1380
|
+
{ pubkey: reserve.reserveCollateralTokenProgram, isSigner: false, isWritable: false },
|
|
1381
|
+
{ pubkey: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
|
|
1382
|
+
{ pubkey: KAMINO_VAULT_EVENT_AUTHORITY, isSigner: false, isWritable: false },
|
|
1383
|
+
{ pubkey: policyBuilders_1.KAMINO_VAULT_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
1384
|
+
...params.vaultContext.index.reserves.map((entry) => ({
|
|
1385
|
+
pubkey: entry.reserveAddress,
|
|
1386
|
+
isSigner: false,
|
|
1387
|
+
isWritable: true,
|
|
1388
|
+
})),
|
|
1389
|
+
...(params.validationAccounts ?? []),
|
|
1390
|
+
],
|
|
1391
|
+
data: encodeU64InstructionData(policyBuilders_1.KAMINO_VAULT_DISCRIMINATORS.withdraw, params.ix.sharesAmount),
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
async function buildKaminoVaultInstruction(ix, buckets, setupContext) {
|
|
1395
|
+
const vaultContext = await resolveKaminoVaultContext(ix.vault, setupContext);
|
|
1396
|
+
const validationAccounts = await resolveKaminoVaultValidationAccounts({
|
|
1397
|
+
setupContext,
|
|
1398
|
+
kaminoVaultAddress: ix.vault,
|
|
1399
|
+
vaultContext,
|
|
1400
|
+
});
|
|
1401
|
+
buckets.setupInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(setupContext.signer, vaultContext.sharesAta, setupContext.owner, vaultContext.index.sharesMint, vaultContext.index.sharesTokenProgram));
|
|
1402
|
+
if (setupContext.autoManagePositions) {
|
|
1403
|
+
await ensureTrackedTokenAccountSetup({
|
|
1404
|
+
tokenMint: vaultContext.index.tokenMint,
|
|
1405
|
+
tokenAccount: vaultContext.tokenAta,
|
|
1406
|
+
tokenProgram: vaultContext.index.tokenProgram,
|
|
1407
|
+
buckets,
|
|
1408
|
+
setupContext,
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
const vaultLookupTable = vaultContext.index.vaultLookupTable ?? web3_js_1.PublicKey.default;
|
|
1412
|
+
if (!vaultLookupTable.equals(web3_js_1.PublicKey.default)) {
|
|
1413
|
+
buckets.addressLookupTableAddresses.push(vaultLookupTable);
|
|
1414
|
+
}
|
|
1415
|
+
if (ix.action === vault_instruction_types_2.KaminoVaultAction.DEPOSIT) {
|
|
1416
|
+
buckets.syncInstructions.push(buildKaminoVaultDepositInstruction({
|
|
1417
|
+
owner: setupContext.owner,
|
|
1418
|
+
kaminoVaultAddress: ix.vault,
|
|
1419
|
+
vaultContext,
|
|
1420
|
+
amount: ix.amount,
|
|
1421
|
+
validationAccounts,
|
|
1422
|
+
}));
|
|
1423
|
+
if (isAutoManagePositionsEnabled(setupContext)) {
|
|
1424
|
+
await queueKaminoVaultSharesTracking({
|
|
1425
|
+
setupContext,
|
|
1426
|
+
buckets,
|
|
1427
|
+
kaminoVaultAddress: ix.vault,
|
|
1428
|
+
vaultContext,
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
buckets.syncInstructions.push(buildKaminoVaultWithdrawInstruction({
|
|
1434
|
+
owner: setupContext.owner,
|
|
1435
|
+
ix,
|
|
1436
|
+
vaultContext,
|
|
1437
|
+
validationAccounts,
|
|
1438
|
+
}));
|
|
1439
|
+
}
|
|
1440
|
+
function getOptionalReadonlyAccountMeta(account, placeholderProgram) {
|
|
1441
|
+
return {
|
|
1442
|
+
pubkey: account ?? placeholderProgram,
|
|
1443
|
+
isSigner: false,
|
|
1444
|
+
isWritable: false,
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
async function resolveKaminoFarmContext(ix, setupContext) {
|
|
1448
|
+
const farmInfo = await setupContext.connection.getAccountInfo(ix.farmState);
|
|
1449
|
+
if (!farmInfo?.data) {
|
|
1450
|
+
throw new Error(`Kamino farm not found: ${ix.farmState.toBase58()}`);
|
|
1451
|
+
}
|
|
1452
|
+
const farm = (0, kamino_farms_1.decodeKaminoFarmState)(Buffer.from(farmInfo.data));
|
|
1453
|
+
const delegatee = ix.delegatee ?? setupContext.owner;
|
|
1454
|
+
const userState = getKaminoFarmUserStateAddress(delegatee, ix.farmState);
|
|
1455
|
+
const sourceAta = (0, spl_token_1.getAssociatedTokenAddressSync)(farm.underlyingMint, setupContext.owner, true, farm.tokenProgram);
|
|
1456
|
+
return {
|
|
1457
|
+
farm,
|
|
1458
|
+
farmState: ix.farmState,
|
|
1459
|
+
userState,
|
|
1460
|
+
delegatee,
|
|
1461
|
+
sourceAta,
|
|
1462
|
+
scopePrices: (0, kamino_farms_1.getKaminoFarmScopePricesAddress)(farm),
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
function buildKaminoFarmInitializeUserRawInstruction(params) {
|
|
1466
|
+
return new web3_js_1.TransactionInstruction({
|
|
1467
|
+
programId: KAMINO_FARMS_PROGRAM_ID,
|
|
1468
|
+
keys: [
|
|
1469
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1470
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1471
|
+
{ pubkey: params.owner, isSigner: false, isWritable: false },
|
|
1472
|
+
{ pubkey: params.delegatee, isSigner: false, isWritable: false },
|
|
1473
|
+
{ pubkey: params.userState, isSigner: false, isWritable: true },
|
|
1474
|
+
{ pubkey: params.farmState, isSigner: false, isWritable: true },
|
|
1475
|
+
{ pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1476
|
+
{ pubkey: web3_js_1.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
|
|
1477
|
+
],
|
|
1478
|
+
data: Buffer.from(policyBuilders_1.KAMINO_FARM_DISCRIMINATORS.initializeUser),
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
async function ensureKaminoFarmUserSetup(params) {
|
|
1482
|
+
if (await accountExistsMaybeTracked(params.setupContext, params.farmContext.userState)) {
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
const requiredLamports = await params.setupContext.connection.getMinimumBalanceForRentExemption(KAMINO_FARM_USER_STATE_SIZE);
|
|
1486
|
+
const ownerLamports = await params.setupContext.connection.getBalance(params.setupContext.owner);
|
|
1487
|
+
if (ownerLamports < requiredLamports) {
|
|
1488
|
+
params.buckets.setupInstructions.push(web3_js_1.SystemProgram.transfer({
|
|
1489
|
+
fromPubkey: params.setupContext.signer,
|
|
1490
|
+
toPubkey: params.setupContext.owner,
|
|
1491
|
+
lamports: requiredLamports - ownerLamports,
|
|
1492
|
+
}));
|
|
1493
|
+
}
|
|
1494
|
+
params.buckets.syncInstructions.push(buildKaminoFarmInitializeUserRawInstruction({
|
|
1495
|
+
owner: params.setupContext.owner,
|
|
1496
|
+
delegatee: params.farmContext.delegatee,
|
|
1497
|
+
userState: params.farmContext.userState,
|
|
1498
|
+
farmState: params.farmContext.farmState,
|
|
1499
|
+
}));
|
|
1500
|
+
const state = await loadStrategySetupState(params.setupContext);
|
|
1501
|
+
state?.existingAccounts.set(params.farmContext.userState.toBase58(), true);
|
|
1502
|
+
}
|
|
1503
|
+
function buildKaminoFarmStakeInstructionRaw(params) {
|
|
1504
|
+
const amount = params.amount === "ALL" ? KAMINO_STAKE_ALL_AMOUNT : params.amount;
|
|
1505
|
+
return new web3_js_1.TransactionInstruction({
|
|
1506
|
+
programId: KAMINO_FARMS_PROGRAM_ID,
|
|
1507
|
+
keys: [
|
|
1508
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1509
|
+
{ pubkey: params.farmContext.userState, isSigner: false, isWritable: true },
|
|
1510
|
+
{ pubkey: params.farmContext.farmState, isSigner: false, isWritable: true },
|
|
1511
|
+
{ pubkey: params.farmContext.farm.farmVault, isSigner: false, isWritable: true },
|
|
1512
|
+
{ pubkey: params.farmContext.sourceAta, isSigner: false, isWritable: true },
|
|
1513
|
+
{ pubkey: params.farmContext.farm.underlyingMint, isSigner: false, isWritable: false },
|
|
1514
|
+
getOptionalReadonlyAccountMeta(params.farmContext.scopePrices, KAMINO_FARMS_PROGRAM_ID),
|
|
1515
|
+
{ pubkey: params.farmContext.farm.tokenProgram, isSigner: false, isWritable: false },
|
|
1516
|
+
],
|
|
1517
|
+
data: encodeU64InstructionData(policyBuilders_1.KAMINO_FARM_DISCRIMINATORS.stake, amount),
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
function buildKaminoFarmUnstakeInstructionRaw(params) {
|
|
1521
|
+
return new web3_js_1.TransactionInstruction({
|
|
1522
|
+
programId: KAMINO_FARMS_PROGRAM_ID,
|
|
1523
|
+
keys: [
|
|
1524
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1525
|
+
{ pubkey: params.farmContext.userState, isSigner: false, isWritable: true },
|
|
1526
|
+
{ pubkey: params.farmContext.farmState, isSigner: false, isWritable: true },
|
|
1527
|
+
getOptionalReadonlyAccountMeta(params.farmContext.scopePrices, KAMINO_FARMS_PROGRAM_ID),
|
|
1528
|
+
],
|
|
1529
|
+
data: encodeU128InstructionData(policyBuilders_1.KAMINO_FARM_DISCRIMINATORS.unstake, params.stakeSharesScaled),
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
function buildKaminoFarmWithdrawUnstakedDepositsRawInstruction(params) {
|
|
1533
|
+
return new web3_js_1.TransactionInstruction({
|
|
1534
|
+
programId: KAMINO_FARMS_PROGRAM_ID,
|
|
1535
|
+
keys: [
|
|
1536
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1537
|
+
{ pubkey: params.farmContext.userState, isSigner: false, isWritable: true },
|
|
1538
|
+
{ pubkey: params.farmContext.farmState, isSigner: false, isWritable: true },
|
|
1539
|
+
{ pubkey: params.farmContext.sourceAta, isSigner: false, isWritable: true },
|
|
1540
|
+
{ pubkey: params.farmContext.farm.farmVault, isSigner: false, isWritable: true },
|
|
1541
|
+
{ pubkey: params.farmContext.farm.farmVaultsAuthority, isSigner: false, isWritable: false },
|
|
1542
|
+
{ pubkey: params.farmContext.farm.tokenProgram, isSigner: false, isWritable: false },
|
|
1543
|
+
],
|
|
1544
|
+
data: Buffer.from(policyBuilders_1.KAMINO_FARM_DISCRIMINATORS.withdrawUnstakedDeposits),
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
function buildKaminoFarmHarvestRewardRawInstruction(params) {
|
|
1548
|
+
const rewardInfo = params.farmContext.farm.rewardInfos[params.rewardIndex];
|
|
1549
|
+
if (!rewardInfo) {
|
|
1550
|
+
throw new Error(`Reward index ${params.rewardIndex} is out of range for Kamino farm ${params.farmContext.farmState.toBase58()}`);
|
|
1551
|
+
}
|
|
1552
|
+
return new web3_js_1.TransactionInstruction({
|
|
1553
|
+
programId: KAMINO_FARMS_PROGRAM_ID,
|
|
1554
|
+
keys: [
|
|
1555
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
1556
|
+
{ pubkey: params.farmContext.userState, isSigner: false, isWritable: true },
|
|
1557
|
+
{ pubkey: params.farmContext.farmState, isSigner: false, isWritable: true },
|
|
1558
|
+
{ pubkey: params.farmContext.farm.globalConfig, isSigner: false, isWritable: false },
|
|
1559
|
+
{ pubkey: rewardInfo.rewardMint, isSigner: false, isWritable: false },
|
|
1560
|
+
{ pubkey: params.rewardAta, isSigner: false, isWritable: true },
|
|
1561
|
+
{ pubkey: rewardInfo.rewardsVault, isSigner: false, isWritable: true },
|
|
1562
|
+
{
|
|
1563
|
+
pubkey: (0, constants_1.getKaminoFarmsRewardsTreasuryVault)(rewardInfo.rewardMint, params.farmContext.farm.globalConfig, KAMINO_FARMS_PROGRAM_ID),
|
|
1564
|
+
isSigner: false,
|
|
1565
|
+
isWritable: true,
|
|
1566
|
+
},
|
|
1567
|
+
{ pubkey: params.farmContext.farm.farmVaultsAuthority, isSigner: false, isWritable: false },
|
|
1568
|
+
getOptionalReadonlyAccountMeta(params.farmContext.scopePrices, KAMINO_FARMS_PROGRAM_ID),
|
|
1569
|
+
{ pubkey: rewardInfo.tokenProgram, isSigner: false, isWritable: false },
|
|
1570
|
+
],
|
|
1571
|
+
data: encodeU64InstructionData(policyBuilders_1.KAMINO_FARM_DISCRIMINATORS.harvestReward, params.rewardIndex),
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
async function buildKaminoFarmInstruction(ix, buckets, setupContext) {
|
|
1575
|
+
const farmContext = await resolveKaminoFarmContext(ix, setupContext);
|
|
1576
|
+
switch (ix.action) {
|
|
1577
|
+
case vault_instruction_types_2.KaminoFarmAction.INITIALIZE_USER: {
|
|
1578
|
+
if (farmContext.farm.isDelegated && !farmContext.delegatee.equals(setupContext.owner)) {
|
|
1579
|
+
throw new Error(`Delegated Kamino farm initialization is not supported for ${ix.farmState.toBase58()}`);
|
|
1580
|
+
}
|
|
1581
|
+
await ensureKaminoFarmUserSetup({ farmContext, buckets, setupContext });
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
case vault_instruction_types_2.KaminoFarmAction.STAKE: {
|
|
1585
|
+
if (farmContext.farm.isDelegated) {
|
|
1586
|
+
throw new Error(`Kamino farm ${ix.farmState.toBase58()} is delegated and cannot be staked directly`);
|
|
1587
|
+
}
|
|
1588
|
+
if (isAutoManagePositionsEnabled(setupContext)) {
|
|
1589
|
+
await ensureKaminoFarmUserSetup({ farmContext, buckets, setupContext });
|
|
1590
|
+
await ensureTrackedTokenAccountSetup({
|
|
1591
|
+
tokenMint: farmContext.farm.underlyingMint,
|
|
1592
|
+
tokenAccount: farmContext.sourceAta,
|
|
1593
|
+
tokenProgram: farmContext.farm.tokenProgram,
|
|
1594
|
+
buckets,
|
|
1595
|
+
setupContext,
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
buckets.syncInstructions.push(buildKaminoFarmStakeInstructionRaw({
|
|
1599
|
+
owner: setupContext.owner,
|
|
1600
|
+
farmContext,
|
|
1601
|
+
amount: ix.amount,
|
|
1602
|
+
}));
|
|
1603
|
+
if (isAutoManagePositionsEnabled(setupContext)) {
|
|
1604
|
+
const state = await loadStrategySetupState(setupContext);
|
|
1605
|
+
if (state) {
|
|
1606
|
+
recordPlannedKaminoFarmPosition(state, {
|
|
1607
|
+
farmState: ix.farmState,
|
|
1608
|
+
userState: farmContext.userState,
|
|
1609
|
+
globalConfig: farmContext.farm.globalConfig,
|
|
1610
|
+
scopePrices: farmContext.scopePrices,
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
case vault_instruction_types_2.KaminoFarmAction.UNSTAKE: {
|
|
1617
|
+
if (farmContext.farm.isDelegated) {
|
|
1618
|
+
throw new Error(`Kamino farm ${ix.farmState.toBase58()} is delegated and cannot be unstaked directly`);
|
|
1619
|
+
}
|
|
1620
|
+
buckets.syncInstructions.push(buildKaminoFarmUnstakeInstructionRaw({
|
|
1621
|
+
owner: setupContext.owner,
|
|
1622
|
+
farmContext,
|
|
1623
|
+
stakeSharesScaled: ix.stakeSharesScaled,
|
|
1624
|
+
}));
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
case vault_instruction_types_2.KaminoFarmAction.WITHDRAW_UNSTAKED_DEPOSITS: {
|
|
1628
|
+
if (farmContext.farm.isDelegated) {
|
|
1629
|
+
throw new Error(`Kamino farm ${ix.farmState.toBase58()} is delegated and cannot withdraw unstaked deposits directly`);
|
|
1630
|
+
}
|
|
1631
|
+
buckets.syncInstructions.push(buildKaminoFarmWithdrawUnstakedDepositsRawInstruction({
|
|
1632
|
+
owner: setupContext.owner,
|
|
1633
|
+
farmContext,
|
|
1634
|
+
}));
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
case vault_instruction_types_2.KaminoFarmAction.HARVEST_REWARD: {
|
|
1638
|
+
const rewardInfo = farmContext.farm.rewardInfos[ix.rewardIndex];
|
|
1639
|
+
if (!rewardInfo) {
|
|
1640
|
+
throw new Error(`Reward index ${ix.rewardIndex} is out of range for Kamino farm ${ix.farmState.toBase58()}`);
|
|
1641
|
+
}
|
|
1642
|
+
const rewardAta = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardInfo.rewardMint, setupContext.owner, true, rewardInfo.tokenProgram);
|
|
1643
|
+
if (isAutoManagePositionsEnabled(setupContext)) {
|
|
1644
|
+
await ensureTrackedTokenAccountSetup({
|
|
1645
|
+
tokenMint: rewardInfo.rewardMint,
|
|
1646
|
+
tokenAccount: rewardAta,
|
|
1647
|
+
tokenProgram: rewardInfo.tokenProgram,
|
|
1648
|
+
buckets,
|
|
1649
|
+
setupContext,
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
buckets.setupInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(setupContext.signer, rewardAta, setupContext.owner, rewardInfo.rewardMint, rewardInfo.tokenProgram));
|
|
1653
|
+
buckets.syncInstructions.push(buildKaminoFarmHarvestRewardRawInstruction({
|
|
1654
|
+
owner: setupContext.owner,
|
|
1655
|
+
farmContext,
|
|
1656
|
+
rewardIndex: ix.rewardIndex,
|
|
1657
|
+
rewardAta,
|
|
1658
|
+
}));
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
async function buildTitanInstruction(ix, buckets, setupContext) {
|
|
1664
|
+
const inputMint = ix.instruction.keys[TITAN_INPUT_MINT_ACCOUNT_INDEX]?.pubkey;
|
|
1665
|
+
const inputTokenAccount = ix.instruction.keys[TITAN_INPUT_TOKEN_ACCOUNT_INDEX]?.pubkey;
|
|
1666
|
+
const outputMint = ix.instruction.keys[TITAN_OUTPUT_MINT_ACCOUNT_INDEX]?.pubkey;
|
|
1667
|
+
const outputTokenAccount = ix.instruction.keys[TITAN_OUTPUT_TOKEN_ACCOUNT_INDEX]?.pubkey;
|
|
1668
|
+
const inputTokenProgram = ix.instruction.keys[TITAN_INPUT_TOKEN_PROGRAM_ACCOUNT_INDEX]?.pubkey;
|
|
1669
|
+
const outputTokenProgram = ix.instruction.keys[TITAN_OUTPUT_TOKEN_PROGRAM_ACCOUNT_INDEX]?.pubkey;
|
|
1670
|
+
if (!inputMint
|
|
1671
|
+
|| !inputTokenAccount
|
|
1672
|
+
|| !outputMint
|
|
1673
|
+
|| !outputTokenAccount
|
|
1674
|
+
|| !inputTokenProgram
|
|
1675
|
+
|| !outputTokenProgram) {
|
|
1676
|
+
throw new Error("Titan SwapRouteV2 instruction is missing expected token accounts");
|
|
1677
|
+
}
|
|
1678
|
+
await ensureTrackedTokenAccountSetup({
|
|
1679
|
+
tokenMint: inputMint,
|
|
1680
|
+
tokenAccount: inputTokenAccount,
|
|
1681
|
+
tokenProgram: inputTokenProgram,
|
|
1682
|
+
buckets,
|
|
1683
|
+
setupContext,
|
|
1684
|
+
});
|
|
1685
|
+
await ensureTrackedTokenAccountSetup({
|
|
1686
|
+
tokenMint: outputMint,
|
|
1687
|
+
tokenAccount: outputTokenAccount,
|
|
1688
|
+
tokenProgram: outputTokenProgram,
|
|
1689
|
+
buckets,
|
|
1690
|
+
setupContext,
|
|
1691
|
+
});
|
|
1692
|
+
if (ix.addressLookupTableAddresses?.length) {
|
|
1693
|
+
buckets.addressLookupTableAddresses.push(...ix.addressLookupTableAddresses);
|
|
1694
|
+
}
|
|
1695
|
+
buckets.syncInstructions.push(ix.instruction);
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Loopscale account index mapping per instruction (from the Loopscale IDL).
|
|
1699
|
+
* Actions not listed here (create_loan, close_loan, update_weight_matrix,
|
|
1700
|
+
* create_strategy, close_strategy, lock_loan, unlock_loan, refinance_ledger,
|
|
1701
|
+
* update_strategy) have no token accounts to track — the on-chain hook handles
|
|
1702
|
+
* TrackLoopscaleLoan/UntrackLoopscaleLoan mutations.
|
|
1703
|
+
*/
|
|
1704
|
+
const LOOPSCALE_TOKEN_INDICES = {
|
|
1705
|
+
[vault_instruction_types_2.LoopscaleAction.DEPOSIT_COLLATERAL]: { mint: 6, account: 4, program: 9 },
|
|
1706
|
+
[vault_instruction_types_2.LoopscaleAction.BORROW_PRINCIPAL]: { mint: 6, account: 7, program: 10 },
|
|
1707
|
+
[vault_instruction_types_2.LoopscaleAction.REPAY_PRINCIPAL]: { mint: 6, account: 7, program: 10 },
|
|
1708
|
+
[vault_instruction_types_2.LoopscaleAction.WITHDRAW_COLLATERAL]: { mint: 7, account: 4, program: 8 },
|
|
1709
|
+
[vault_instruction_types_2.LoopscaleAction.DEPOSIT_STRATEGY]: { mint: 4, account: 6, program: 8 },
|
|
1710
|
+
[vault_instruction_types_2.LoopscaleAction.WITHDRAW_STRATEGY]: { mint: 4, account: 6, program: 9 },
|
|
1711
|
+
};
|
|
1712
|
+
/** Build a single Loopscale instruction (loan or strategy). Extracts token accounts for tracking. */
|
|
1713
|
+
async function buildLoopscaleInstruction(ix, buckets, setupContext) {
|
|
1714
|
+
const indices = LOOPSCALE_TOKEN_INDICES[ix.action];
|
|
1715
|
+
if (indices) {
|
|
1716
|
+
const tokenMint = ix.instruction.keys[indices.mint]?.pubkey;
|
|
1717
|
+
const tokenAccount = ix.instruction.keys[indices.account]?.pubkey;
|
|
1718
|
+
const tokenProgram = ix.instruction.keys[indices.program]?.pubkey;
|
|
1719
|
+
if (!tokenMint || !tokenAccount || !tokenProgram) {
|
|
1720
|
+
throw new Error(`Loopscale ${ix.action} instruction is missing expected token accounts`);
|
|
1721
|
+
}
|
|
1722
|
+
await ensureTrackedTokenAccountSetup({ tokenMint, tokenAccount, tokenProgram, buckets, setupContext });
|
|
1723
|
+
}
|
|
1724
|
+
buckets.syncInstructions.push(ix.instruction);
|
|
1725
|
+
}
|
|
1726
|
+
/** Build a single orderbook instruction (uses LOCAL_ENV for Orderbook.load) */
|
|
1727
|
+
async function buildOrderbookInstruction(ix, owner, connection, buckets, setupContext, env = environment_1.LOCAL_ENV) {
|
|
1728
|
+
const cacheKey = ix.orderbook.toBase58();
|
|
1729
|
+
let orderbook = orderbookCache.get(cacheKey);
|
|
1730
|
+
if (!orderbook) {
|
|
1731
|
+
orderbook = await orderbook_1.Orderbook.load(env, connection, ix.orderbook);
|
|
1732
|
+
orderbookCache.set(cacheKey, orderbook);
|
|
1733
|
+
}
|
|
1734
|
+
switch (ix.action) {
|
|
1735
|
+
case vault_instruction_types_2.OrderbookAction.POST_OFFER:
|
|
1736
|
+
await buildPostOffer(ix, orderbook, owner, setupContext?.signer ?? owner, buckets, setupContext);
|
|
1737
|
+
break;
|
|
1738
|
+
case vault_instruction_types_2.OrderbookAction.MARKET_OFFER:
|
|
1739
|
+
await buildMarketOffer(ix, orderbook, owner, setupContext?.signer ?? owner, buckets, setupContext);
|
|
1740
|
+
break;
|
|
1741
|
+
case vault_instruction_types_2.OrderbookAction.REMOVE_OFFER:
|
|
1742
|
+
await buildRemoveOffer(ix, orderbook, owner, buckets);
|
|
1743
|
+
break;
|
|
1744
|
+
case vault_instruction_types_2.OrderbookAction.WITHDRAW_FUNDS:
|
|
1745
|
+
await buildWithdrawFunds(ix, orderbook, owner, buckets);
|
|
1746
|
+
break;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
// ============================================================================
|
|
1750
|
+
// Action Builders (one per VaultAction)
|
|
1751
|
+
// ============================================================================
|
|
1752
|
+
function createKaminoInitUserMetadataInstruction(owner) {
|
|
1753
|
+
const userMetadata = (0, constants_1.getKaminoUserMetadata)(owner, policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
1754
|
+
return (0, instructions_1.initUserMetadata)({ userLookupTable: web3_js_1.PublicKey.default }, {
|
|
1755
|
+
owner,
|
|
1756
|
+
feePayer: owner,
|
|
1757
|
+
userMetadata,
|
|
1758
|
+
referrerUserMetadata: policyBuilders_1.KAMINO_LENDING_PROGRAM_ID,
|
|
1759
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1760
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
function createKaminoInitObligationInstruction(params) {
|
|
1764
|
+
const lendingMarket = kamino_markets_1.KAMINO_MARKETS[params.market];
|
|
1765
|
+
const obligation = (0, constants_1.getKaminoLendObligation)(params.owner, lendingMarket, policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
1766
|
+
const userMetadata = (0, constants_1.getKaminoUserMetadata)(params.owner, policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
1767
|
+
return (0, instructions_1.initObligation)({ args: { tag: 0, id: 0 } }, {
|
|
1768
|
+
obligationOwner: params.owner,
|
|
1769
|
+
feePayer: params.owner,
|
|
1770
|
+
obligation,
|
|
1771
|
+
lendingMarket,
|
|
1772
|
+
seed1Account: web3_js_1.SystemProgram.programId,
|
|
1773
|
+
seed2Account: web3_js_1.SystemProgram.programId,
|
|
1774
|
+
ownerUserMetadata: userMetadata,
|
|
1775
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1776
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
async function buildInitUserMetadata(owner, connection, { syncInstructions }) {
|
|
1780
|
+
const userMetadata = (0, constants_1.getKaminoUserMetadata)(owner, policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
1781
|
+
const userMetadataAccount = await connection.getAccountInfo(userMetadata);
|
|
1782
|
+
if (userMetadataAccount)
|
|
1783
|
+
return;
|
|
1784
|
+
syncInstructions.push(createKaminoInitUserMetadataInstruction(owner));
|
|
1785
|
+
}
|
|
1786
|
+
async function buildInitObligation(ix, owner, connection, { syncInstructions, postInstructions }, setupContext) {
|
|
1787
|
+
const lendingMarket = kamino_markets_1.KAMINO_MARKETS[ix.market];
|
|
1788
|
+
const obligation = (0, constants_1.getKaminoLendObligation)(owner, lendingMarket, policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
1789
|
+
const obligationAccount = await connection.getAccountInfo(obligation);
|
|
1790
|
+
if (obligationAccount)
|
|
1791
|
+
return;
|
|
1792
|
+
syncInstructions.push(createKaminoInitObligationInstruction({ market: ix.market, owner }));
|
|
1793
|
+
if (setupContext && isAutoManagePositionsEnabled(setupContext)) {
|
|
1794
|
+
await queueKaminoObligationTrackingAfterInit({
|
|
1795
|
+
market: ix.market,
|
|
1796
|
+
obligation,
|
|
1797
|
+
postInstructions,
|
|
1798
|
+
setupContext,
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
async function queueKaminoObligationTrackingAfterInit(params) {
|
|
1803
|
+
const state = await loadStrategySetupState(params.setupContext);
|
|
1804
|
+
if (!state || state.trackedKaminoObligations.has(params.obligation.toBase58())) {
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
const quotePath = (0, pricePathResolver_1.resolveBestKaminoQuotePath)({
|
|
1808
|
+
prices: state.prices,
|
|
1809
|
+
vaultUnderlyingMint: state.strategyVault.state.underlyingMint,
|
|
1810
|
+
});
|
|
1811
|
+
trackRequiredPriceIds(state.requiredPriceIds, quotePath.quotePriceId);
|
|
1812
|
+
const remainingAccountsAmount = 1n;
|
|
1813
|
+
const obligationEntry = {
|
|
1814
|
+
obligation: params.obligation,
|
|
1815
|
+
lendingProgramId: policyBuilders_1.KAMINO_LENDING_PROGRAM_ID,
|
|
1816
|
+
quotePriceId: quotePath.quotePriceId,
|
|
1817
|
+
reservePriceMappings: [],
|
|
1818
|
+
reserveFarmMappings: [],
|
|
1819
|
+
minPriceStatusFlags: 0,
|
|
1820
|
+
};
|
|
1821
|
+
params.postInstructions.push(state.strategyVault.ixWrapperManagerUpdatePosition({
|
|
1822
|
+
manager: params.setupContext.signer,
|
|
1823
|
+
update: exponentVaults.positionUpdate("AddKaminoObligationEntry", [obligationEntry]),
|
|
1824
|
+
remainingAccounts: buildTrackedAumRemainingAccounts(state, [
|
|
1825
|
+
{ pubkey: params.obligation, isSigner: false, isWritable: false },
|
|
1826
|
+
]),
|
|
1827
|
+
}));
|
|
1828
|
+
recordPlannedKaminoObligation(state, {
|
|
1829
|
+
obligation: params.obligation,
|
|
1830
|
+
quotePriceId: quotePath.quotePriceId,
|
|
1831
|
+
quoteInputMint: quotePath.quoteInputMint,
|
|
1832
|
+
reservePriceMappings: [],
|
|
1833
|
+
remainingAccountsAmount,
|
|
1834
|
+
minPriceStatusFlags: 0,
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
async function ensureKaminoObligationSetup(params) {
|
|
1838
|
+
const { ix, reserveContext, buckets, setupContext } = params;
|
|
1839
|
+
if (!setupContext || !isAutoManagePositionsEnabled(setupContext)) {
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
const state = await loadStrategySetupState(setupContext);
|
|
1843
|
+
if (!state) {
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
// Ensure user metadata exists
|
|
1847
|
+
const userMetadata = (0, constants_1.getKaminoUserMetadata)(setupContext.owner, policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
1848
|
+
if (!(await accountExists(state, setupContext.connection, userMetadata))) {
|
|
1849
|
+
buckets.setupInstructions.push(await wrapVaultSignedSetupInstruction({
|
|
1850
|
+
instruction: createKaminoInitUserMetadataInstruction(setupContext.owner),
|
|
1851
|
+
setupContext,
|
|
1852
|
+
}));
|
|
1853
|
+
state.existingAccounts.set(userMetadata.toBase58(), true);
|
|
1854
|
+
}
|
|
1855
|
+
// Ensure obligation exists and is tracked
|
|
1856
|
+
const obligationKey = reserveContext.obligation.toBase58();
|
|
1857
|
+
const obligationExistsOnChain = await accountExists(state, setupContext.connection, reserveContext.obligation);
|
|
1858
|
+
const trackedObligation = state.trackedKaminoObligations.get(obligationKey);
|
|
1859
|
+
if (!trackedObligation) {
|
|
1860
|
+
if (obligationExistsOnChain) {
|
|
1861
|
+
throw new Error(`Kamino obligation ${obligationKey} already exists on-chain but is not tracked on vault ${state.strategyVault.selfAddress.toBase58()}. Automatic repair is disabled; manually add the Kamino obligation entry.`);
|
|
1862
|
+
}
|
|
1863
|
+
buckets.setupInstructions.push(await wrapVaultSignedSetupInstruction({
|
|
1864
|
+
instruction: createKaminoInitObligationInstruction({ market: ix.market, owner: setupContext.owner }),
|
|
1865
|
+
setupContext,
|
|
1866
|
+
}));
|
|
1867
|
+
state.existingAccounts.set(obligationKey, true);
|
|
1868
|
+
const quotePath = (0, pricePathResolver_1.resolveBestKaminoQuotePath)({
|
|
1869
|
+
prices: state.prices,
|
|
1870
|
+
vaultUnderlyingMint: state.strategyVault.state.underlyingMint,
|
|
1871
|
+
});
|
|
1872
|
+
const reservePriceMapping = {
|
|
1873
|
+
reserve: reserveContext.reservePubkey,
|
|
1874
|
+
reservePriceId: (0, pricePathResolver_1.resolveKaminoReservePriceIdOrThrow)({
|
|
1875
|
+
prices: state.prices,
|
|
1876
|
+
reserveMint: reserveContext.reserveAccount.liquidity.mintPubkey,
|
|
1877
|
+
quoteInputMint: quotePath.quoteInputMint,
|
|
1878
|
+
}),
|
|
1879
|
+
};
|
|
1880
|
+
trackRequiredPriceIds(state.requiredPriceIds, quotePath.quotePriceId);
|
|
1881
|
+
trackRequiredPriceIds(state.requiredPriceIds, reservePriceMapping.reservePriceId);
|
|
1882
|
+
const remainingAccountsAmount = BigInt(1 + 1);
|
|
1883
|
+
const obligationEntry = {
|
|
1884
|
+
obligation: reserveContext.obligation,
|
|
1885
|
+
lendingProgramId: policyBuilders_1.KAMINO_LENDING_PROGRAM_ID,
|
|
1886
|
+
quotePriceId: quotePath.quotePriceId,
|
|
1887
|
+
reservePriceMappings: [reservePriceMapping],
|
|
1888
|
+
reserveFarmMappings: [],
|
|
1889
|
+
minPriceStatusFlags: 0,
|
|
1890
|
+
};
|
|
1891
|
+
buckets.setupInstructions.push(state.strategyVault.ixWrapperManagerUpdatePosition({
|
|
1892
|
+
manager: setupContext.signer,
|
|
1893
|
+
update: exponentVaults.positionUpdate("AddKaminoObligationEntry", [obligationEntry]),
|
|
1894
|
+
remainingAccounts: buildTrackedAumRemainingAccounts(state, [
|
|
1895
|
+
{ pubkey: reserveContext.obligation, isSigner: false, isWritable: false },
|
|
1896
|
+
{ pubkey: reserveContext.reservePubkey, isSigner: false, isWritable: false },
|
|
1897
|
+
]),
|
|
1898
|
+
}));
|
|
1899
|
+
recordPlannedKaminoObligation(state, {
|
|
1900
|
+
obligation: reserveContext.obligation,
|
|
1901
|
+
quotePriceId: quotePath.quotePriceId,
|
|
1902
|
+
quoteInputMint: quotePath.quoteInputMint,
|
|
1903
|
+
reservePriceMappings: [reservePriceMapping],
|
|
1904
|
+
remainingAccountsAmount,
|
|
1905
|
+
minPriceStatusFlags: 0,
|
|
1906
|
+
});
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
// Obligation exists and is tracked — ensure the reserve is mapped
|
|
1910
|
+
await ensureKaminoReserveMapped({
|
|
1911
|
+
state,
|
|
1912
|
+
reserveContext,
|
|
1913
|
+
setupContext,
|
|
1914
|
+
buckets,
|
|
1915
|
+
trackedObligation,
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
/** Ensure a Kamino reserve is mapped on an already-tracked obligation. */
|
|
1919
|
+
async function ensureKaminoReserveMapped(params) {
|
|
1920
|
+
const { state, reserveContext, setupContext, buckets, trackedObligation } = params;
|
|
1921
|
+
if (trackedObligation.mappedReserves.has(reserveContext.reservePubkey.toBase58())) {
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
const reservePriceMapping = {
|
|
1925
|
+
reserve: reserveContext.reservePubkey,
|
|
1926
|
+
reservePriceId: (0, pricePathResolver_1.resolveKaminoReservePriceIdOrThrow)({
|
|
1927
|
+
prices: state.prices,
|
|
1928
|
+
reserveMint: reserveContext.reserveAccount.liquidity.mintPubkey,
|
|
1929
|
+
quoteInputMint: trackedObligation.quoteInputMint,
|
|
1930
|
+
}),
|
|
1931
|
+
};
|
|
1932
|
+
trackRequiredPriceIds(state.requiredPriceIds, reservePriceMapping.reservePriceId);
|
|
1933
|
+
buckets.setupInstructions.push(...await buildKaminoPositionFreshnessInstructions({
|
|
1934
|
+
reservePubkey: reserveContext.reservePubkey,
|
|
1935
|
+
reserveAccount: reserveContext.reserveAccount,
|
|
1936
|
+
lendingMarket: reserveContext.lendingMarket,
|
|
1937
|
+
obligation: reserveContext.obligation,
|
|
1938
|
+
connection: setupContext.connection,
|
|
1939
|
+
}));
|
|
1940
|
+
buckets.setupInstructions.push(state.strategyVault.ixWrapperManagerUpdatePosition({
|
|
1941
|
+
manager: setupContext.signer,
|
|
1942
|
+
update: exponentVaults.positionUpdate("UpsertKaminoObligationReservePriceMappings", {
|
|
1943
|
+
obligation: reserveContext.obligation,
|
|
1944
|
+
reservePriceMappings: [reservePriceMapping],
|
|
1945
|
+
reserveFarmMappings: [],
|
|
1946
|
+
}),
|
|
1947
|
+
remainingAccounts: buildTrackedAumRemainingAccounts(state, [
|
|
1948
|
+
{ pubkey: reserveContext.reservePubkey, isSigner: false, isWritable: false },
|
|
1949
|
+
]),
|
|
1950
|
+
}));
|
|
1951
|
+
recordPlannedKaminoReserveMappings(state, {
|
|
1952
|
+
obligation: reserveContext.obligation,
|
|
1953
|
+
quoteInputMint: trackedObligation.quoteInputMint,
|
|
1954
|
+
reservePriceMappings: [reservePriceMapping],
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
async function buildKaminoPositionFreshnessInstructions({ reservePubkey, reserveAccount, lendingMarket, obligation, connection, }) {
|
|
1958
|
+
const instructions = [];
|
|
1959
|
+
const defaultKey = web3_js_1.PublicKey.default;
|
|
1960
|
+
const oracleOrSentinel = (key) => key.equals(defaultKey) ? policyBuilders_1.KAMINO_LENDING_PROGRAM_ID : key;
|
|
1961
|
+
const obligationState = await accounts_1.Obligation.fetch(connection, obligation);
|
|
1962
|
+
const otherReservePubkeys = [];
|
|
1963
|
+
if (obligationState) {
|
|
1964
|
+
for (const deposit of obligationState.deposits) {
|
|
1965
|
+
if (!deposit.depositReserve.equals(defaultKey) && !deposit.depositReserve.equals(reservePubkey)) {
|
|
1966
|
+
otherReservePubkeys.push(deposit.depositReserve);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
for (const borrow of obligationState.borrows) {
|
|
1970
|
+
if (!borrow.borrowReserve.equals(defaultKey) && !borrow.borrowReserve.equals(reservePubkey)) {
|
|
1971
|
+
otherReservePubkeys.push(borrow.borrowReserve);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
const otherReserves = [];
|
|
1976
|
+
for (const otherReservePubkey of otherReservePubkeys) {
|
|
1977
|
+
const otherReserveAccount = await kamino_reserve_deserializer_1.Reserve.fetch(connection, otherReservePubkey);
|
|
1978
|
+
if (!otherReserveAccount) {
|
|
1979
|
+
continue;
|
|
1980
|
+
}
|
|
1981
|
+
otherReserves.push({ pubkey: otherReservePubkey, account: otherReserveAccount });
|
|
1982
|
+
}
|
|
1983
|
+
for (const { pubkey, account } of otherReserves) {
|
|
1984
|
+
const tokenInfo = account.config.tokenInfo;
|
|
1985
|
+
instructions.push((0, instructions_1.refreshReserve)({
|
|
1986
|
+
reserve: pubkey,
|
|
1987
|
+
lendingMarket,
|
|
1988
|
+
pythOracle: oracleOrSentinel(tokenInfo.pythConfiguration.price),
|
|
1989
|
+
switchboardPriceOracle: oracleOrSentinel(tokenInfo.switchboardConfiguration.priceAggregator),
|
|
1990
|
+
switchboardTwapOracle: oracleOrSentinel(tokenInfo.switchboardConfiguration.twapAggregator),
|
|
1991
|
+
scopePrices: oracleOrSentinel(tokenInfo.scopeConfiguration.priceFeed),
|
|
1992
|
+
}));
|
|
1993
|
+
}
|
|
1994
|
+
const tokenInfo = reserveAccount.config.tokenInfo;
|
|
1995
|
+
instructions.push((0, instructions_1.refreshReserve)({
|
|
1996
|
+
reserve: reservePubkey,
|
|
1997
|
+
lendingMarket,
|
|
1998
|
+
pythOracle: oracleOrSentinel(tokenInfo.pythConfiguration.price),
|
|
1999
|
+
switchboardPriceOracle: oracleOrSentinel(tokenInfo.switchboardConfiguration.priceAggregator),
|
|
2000
|
+
switchboardTwapOracle: oracleOrSentinel(tokenInfo.switchboardConfiguration.twapAggregator),
|
|
2001
|
+
scopePrices: oracleOrSentinel(tokenInfo.scopeConfiguration.priceFeed),
|
|
2002
|
+
}));
|
|
2003
|
+
const refreshObligationIx = (0, instructions_1.refreshObligation)({ lendingMarket, obligation });
|
|
2004
|
+
if (obligationState) {
|
|
2005
|
+
const depositReserves = obligationState.deposits
|
|
2006
|
+
.map((deposit) => deposit.depositReserve)
|
|
2007
|
+
.filter((reserve) => !reserve.equals(defaultKey));
|
|
2008
|
+
const borrowReserves = obligationState.borrows
|
|
2009
|
+
.map((borrow) => borrow.borrowReserve)
|
|
2010
|
+
.filter((reserve) => !reserve.equals(defaultKey));
|
|
2011
|
+
for (const reserve of [...depositReserves, ...borrowReserves]) {
|
|
2012
|
+
refreshObligationIx.keys.push({ pubkey: reserve, isSigner: false, isWritable: false });
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
instructions.push(refreshObligationIx);
|
|
2016
|
+
return instructions;
|
|
2017
|
+
}
|
|
2018
|
+
async function buildDeposit(ix, owner, connection, signer, { setupInstructions, syncInstructions, preInstructions, postInstructions }, setupContext) {
|
|
2019
|
+
const ctx = await resolveReserveContext(ix, owner, connection);
|
|
2020
|
+
await ensureKaminoObligationSetup({ ix, reserveContext: ctx, buckets: { setupInstructions, syncInstructions, preInstructions, postInstructions, signers: [], addressLookupTableAddresses: [] }, setupContext });
|
|
2021
|
+
const refreshes = await buildRefreshInstructions({
|
|
2022
|
+
...ctx, owner, farmMode: FARM_COLLATERAL, signer, connection, needsScopeRefresh: false,
|
|
2023
|
+
});
|
|
2024
|
+
const isSOL = ctx.reserveAccount.liquidity.mintPubkey.equals(spl_token_1.NATIVE_MINT);
|
|
2025
|
+
const userSourceLiquidity = (0, spl_token_1.getAssociatedTokenAddressSync)(ctx.reserveAccount.liquidity.mintPubkey, owner, true, ctx.reserveAccount.liquidity.tokenProgram);
|
|
2026
|
+
if (isSOL) {
|
|
2027
|
+
setupInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(signer, userSourceLiquidity, owner, spl_token_1.NATIVE_MINT, spl_token_1.TOKEN_PROGRAM_ID));
|
|
2028
|
+
}
|
|
2029
|
+
preInstructions.push(...refreshes.preInstructions);
|
|
2030
|
+
postInstructions.push(...refreshes.postInstructions);
|
|
2031
|
+
syncInstructions.push((0, instructions_1.depositReserveLiquidityAndObligationCollateralV2)({ liquidityAmount: ix.amount }, {
|
|
2032
|
+
depositAccounts: {
|
|
2033
|
+
owner,
|
|
2034
|
+
obligation: ctx.obligation,
|
|
2035
|
+
lendingMarket: ctx.lendingMarket,
|
|
2036
|
+
lendingMarketAuthority: ctx.lendingMarketAuthority,
|
|
2037
|
+
reserve: ctx.reservePubkey,
|
|
2038
|
+
reserveLiquidityMint: ctx.reserveAccount.liquidity.mintPubkey,
|
|
2039
|
+
reserveLiquiditySupply: ctx.reserveAccount.liquidity.supplyVault,
|
|
2040
|
+
reserveCollateralMint: ctx.reserveAccount.collateral.mintPubkey,
|
|
2041
|
+
reserveDestinationDepositCollateral: ctx.reserveAccount.collateral.supplyVault,
|
|
2042
|
+
userSourceLiquidity,
|
|
2043
|
+
placeholderUserDestinationCollateral: owner,
|
|
2044
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2045
|
+
liquidityTokenProgram: ctx.reserveAccount.liquidity.tokenProgram,
|
|
2046
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2047
|
+
},
|
|
2048
|
+
farmsAccounts: refreshes.farmsAccounts,
|
|
2049
|
+
farmsProgram: KAMINO_FARMS_PROGRAM_ID,
|
|
2050
|
+
}));
|
|
2051
|
+
}
|
|
2052
|
+
async function buildWithdraw(ix, owner, connection, signer, { setupInstructions, syncInstructions, preInstructions, postInstructions }, setupContext) {
|
|
2053
|
+
const ctx = await resolveReserveContext(ix, owner, connection);
|
|
2054
|
+
await ensureKaminoObligationSetup({ ix, reserveContext: ctx, buckets: { setupInstructions, syncInstructions, preInstructions, postInstructions, signers: [], addressLookupTableAddresses: [] }, setupContext });
|
|
2055
|
+
const refreshes = await buildRefreshInstructions({
|
|
2056
|
+
...ctx, owner, farmMode: FARM_COLLATERAL, signer, connection, needsScopeRefresh: true,
|
|
2057
|
+
});
|
|
2058
|
+
const isSOL = ctx.reserveAccount.liquidity.mintPubkey.equals(spl_token_1.NATIVE_MINT);
|
|
2059
|
+
const userDestinationLiquidity = (0, spl_token_1.getAssociatedTokenAddressSync)(ctx.reserveAccount.liquidity.mintPubkey, owner, true, ctx.reserveAccount.liquidity.tokenProgram);
|
|
2060
|
+
preInstructions.push(...refreshes.scopeRefreshInstructions);
|
|
2061
|
+
if (isSOL) {
|
|
2062
|
+
setupInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(signer, userDestinationLiquidity, owner, spl_token_1.NATIVE_MINT, spl_token_1.TOKEN_PROGRAM_ID));
|
|
2063
|
+
}
|
|
2064
|
+
preInstructions.push(...refreshes.preInstructions);
|
|
2065
|
+
postInstructions.push(...refreshes.postInstructions);
|
|
2066
|
+
// Convert liquidity amount → collateral amount using the reserve's exchange rate
|
|
2067
|
+
const exchangeRate = ctx.reserveAccount.getCollateralExchangeRate();
|
|
2068
|
+
if (exchangeRate.isZero())
|
|
2069
|
+
throw new Error(`Reserve ${ctx.reservePubkey.toBase58()} has zero exchange rate`);
|
|
2070
|
+
const collateralAmount = new bn_js_1.default(new decimal_js_1.default(ix.amount.toString()).div(exchangeRate).floor().toString());
|
|
2071
|
+
syncInstructions.push((0, instructions_1.withdrawObligationCollateralAndRedeemReserveCollateralV2)({ collateralAmount }, {
|
|
2072
|
+
withdrawAccounts: {
|
|
2073
|
+
owner,
|
|
2074
|
+
obligation: ctx.obligation,
|
|
2075
|
+
lendingMarket: ctx.lendingMarket,
|
|
2076
|
+
lendingMarketAuthority: ctx.lendingMarketAuthority,
|
|
2077
|
+
withdrawReserve: ctx.reservePubkey,
|
|
2078
|
+
reserveLiquidityMint: ctx.reserveAccount.liquidity.mintPubkey,
|
|
2079
|
+
reserveSourceCollateral: ctx.reserveAccount.collateral.supplyVault,
|
|
2080
|
+
reserveCollateralMint: ctx.reserveAccount.collateral.mintPubkey,
|
|
2081
|
+
reserveLiquiditySupply: ctx.reserveAccount.liquidity.supplyVault,
|
|
2082
|
+
userDestinationLiquidity,
|
|
2083
|
+
placeholderUserDestinationCollateral: owner,
|
|
2084
|
+
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2085
|
+
liquidityTokenProgram: ctx.reserveAccount.liquidity.tokenProgram,
|
|
2086
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2087
|
+
},
|
|
2088
|
+
farmsAccounts: refreshes.farmsAccounts,
|
|
2089
|
+
farmsProgram: KAMINO_FARMS_PROGRAM_ID,
|
|
2090
|
+
}));
|
|
2091
|
+
}
|
|
2092
|
+
async function buildBorrow(ix, owner, connection, signer, { setupInstructions, syncInstructions, preInstructions, postInstructions }, setupContext) {
|
|
2093
|
+
const ctx = await resolveReserveContext(ix, owner, connection);
|
|
2094
|
+
await ensureKaminoObligationSetup({ ix, reserveContext: ctx, buckets: { setupInstructions, syncInstructions, preInstructions, postInstructions, signers: [], addressLookupTableAddresses: [] }, setupContext });
|
|
2095
|
+
const refreshes = await buildRefreshInstructions({
|
|
2096
|
+
...ctx, owner, farmMode: FARM_DEBT, signer, connection, needsScopeRefresh: true,
|
|
2097
|
+
});
|
|
2098
|
+
const isSOL = ctx.reserveAccount.liquidity.mintPubkey.equals(spl_token_1.NATIVE_MINT);
|
|
2099
|
+
const userDestinationLiquidity = (0, spl_token_1.getAssociatedTokenAddressSync)(ctx.reserveAccount.liquidity.mintPubkey, owner, true, ctx.reserveAccount.liquidity.tokenProgram);
|
|
2100
|
+
preInstructions.push(...refreshes.scopeRefreshInstructions);
|
|
2101
|
+
setupInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(signer, userDestinationLiquidity, owner, ctx.reserveAccount.liquidity.mintPubkey, ctx.reserveAccount.liquidity.tokenProgram));
|
|
2102
|
+
preInstructions.push(...refreshes.preInstructions);
|
|
2103
|
+
postInstructions.push(...refreshes.postInstructions);
|
|
2104
|
+
syncInstructions.push((0, instructions_1.borrowObligationLiquidityV2)({ liquidityAmount: ix.amount }, {
|
|
2105
|
+
borrowAccounts: {
|
|
2106
|
+
owner,
|
|
2107
|
+
obligation: ctx.obligation,
|
|
2108
|
+
lendingMarket: ctx.lendingMarket,
|
|
2109
|
+
lendingMarketAuthority: ctx.lendingMarketAuthority,
|
|
2110
|
+
borrowReserve: ctx.reservePubkey,
|
|
2111
|
+
borrowReserveLiquidityMint: ctx.reserveAccount.liquidity.mintPubkey,
|
|
2112
|
+
reserveSourceLiquidity: ctx.reserveAccount.liquidity.supplyVault,
|
|
2113
|
+
borrowReserveLiquidityFeeReceiver: ctx.reserveAccount.liquidity.feeVault,
|
|
2114
|
+
userDestinationLiquidity,
|
|
2115
|
+
referrerTokenState: null,
|
|
2116
|
+
tokenProgram: ctx.reserveAccount.liquidity.tokenProgram,
|
|
2117
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2118
|
+
},
|
|
2119
|
+
farmsAccounts: refreshes.farmsAccounts,
|
|
2120
|
+
farmsProgram: KAMINO_FARMS_PROGRAM_ID,
|
|
2121
|
+
}));
|
|
2122
|
+
}
|
|
2123
|
+
async function buildRepay(ix, owner, connection, signer, { setupInstructions, syncInstructions, preInstructions, postInstructions }, setupContext) {
|
|
2124
|
+
const ctx = await resolveReserveContext(ix, owner, connection);
|
|
2125
|
+
await ensureKaminoObligationSetup({ ix, reserveContext: ctx, buckets: { setupInstructions, syncInstructions, preInstructions, postInstructions, signers: [], addressLookupTableAddresses: [] }, setupContext });
|
|
2126
|
+
const refreshes = await buildRefreshInstructions({
|
|
2127
|
+
...ctx, owner, farmMode: FARM_DEBT, signer, connection, needsScopeRefresh: false,
|
|
2128
|
+
});
|
|
2129
|
+
const isSOL = ctx.reserveAccount.liquidity.mintPubkey.equals(spl_token_1.NATIVE_MINT);
|
|
2130
|
+
const userSourceLiquidity = (0, spl_token_1.getAssociatedTokenAddressSync)(ctx.reserveAccount.liquidity.mintPubkey, owner, true, ctx.reserveAccount.liquidity.tokenProgram);
|
|
2131
|
+
if (isSOL) {
|
|
2132
|
+
setupInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(signer, userSourceLiquidity, owner, spl_token_1.NATIVE_MINT, spl_token_1.TOKEN_PROGRAM_ID));
|
|
2133
|
+
}
|
|
2134
|
+
preInstructions.push(...refreshes.preInstructions);
|
|
2135
|
+
postInstructions.push(...refreshes.postInstructions);
|
|
2136
|
+
syncInstructions.push((0, instructions_1.repayObligationLiquidityV2)({ liquidityAmount: ix.amount }, {
|
|
2137
|
+
repayAccounts: {
|
|
2138
|
+
owner,
|
|
2139
|
+
obligation: ctx.obligation,
|
|
2140
|
+
lendingMarket: ctx.lendingMarket,
|
|
2141
|
+
repayReserve: ctx.reservePubkey,
|
|
2142
|
+
reserveLiquidityMint: ctx.reserveAccount.liquidity.mintPubkey,
|
|
2143
|
+
reserveDestinationLiquidity: ctx.reserveAccount.liquidity.supplyVault,
|
|
2144
|
+
userSourceLiquidity,
|
|
2145
|
+
tokenProgram: ctx.reserveAccount.liquidity.tokenProgram,
|
|
2146
|
+
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2147
|
+
},
|
|
2148
|
+
farmsAccounts: refreshes.farmsAccounts,
|
|
2149
|
+
lendingMarketAuthority: ctx.lendingMarketAuthority,
|
|
2150
|
+
farmsProgram: KAMINO_FARMS_PROGRAM_ID,
|
|
2151
|
+
}));
|
|
2152
|
+
}
|
|
2153
|
+
async function resolveReserveContext(ix, owner, connection) {
|
|
2154
|
+
const lendingMarket = kamino_markets_1.KAMINO_MARKETS[ix.market];
|
|
2155
|
+
const reserveEntry = kamino_markets_1.KAMINO_RESERVES[ix.market][ix.asset];
|
|
2156
|
+
const reservePubkey = reserveEntry?.pubkey;
|
|
2157
|
+
if (!reservePubkey)
|
|
2158
|
+
throw new Error(`Unknown reserve: ${ix.market}/${ix.asset}`);
|
|
2159
|
+
const reserveAccount = await kamino_reserve_deserializer_1.Reserve.fetch(connection, reservePubkey);
|
|
2160
|
+
if (!reserveAccount)
|
|
2161
|
+
throw new Error(`Reserve not found: ${reservePubkey.toBase58()}`);
|
|
2162
|
+
const obligation = (0, constants_1.getKaminoLendObligation)(owner, lendingMarket, policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
2163
|
+
const [lendingMarketAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("lma"), lendingMarket.toBuffer()], policyBuilders_1.KAMINO_LENDING_PROGRAM_ID);
|
|
2164
|
+
return { reservePubkey, reserveAccount, obligation, lendingMarket, lendingMarketAuthority };
|
|
2165
|
+
}
|
|
2166
|
+
/**
|
|
2167
|
+
* Build the freshness and farm-setup instructions required before direct KLend operations.
|
|
2168
|
+
*
|
|
2169
|
+
* @param farmMode - FARM_COLLATERAL (deposit/withdraw) or FARM_DEBT (borrow/repay)
|
|
2170
|
+
* @param needsScopeRefresh - true for borrow/withdraw (ALL_CHECKS), false for deposit/repay (NONE)
|
|
2171
|
+
*/
|
|
2172
|
+
async function buildRefreshInstructions({ reservePubkey, reserveAccount, lendingMarket, lendingMarketAuthority, obligation, owner, farmMode, signer, connection, needsScopeRefresh, }) {
|
|
2173
|
+
const pre = [];
|
|
2174
|
+
const post = [];
|
|
2175
|
+
const defaultKey = web3_js_1.PublicKey.default;
|
|
2176
|
+
const oracleOrSentinel = (key) => key.equals(defaultKey) ? policyBuilders_1.KAMINO_LENDING_PROGRAM_ID : key;
|
|
2177
|
+
// Determine farm state based on mode (collateral vs debt)
|
|
2178
|
+
const farmState = farmMode === FARM_COLLATERAL ? reserveAccount.farmCollateral : reserveAccount.farmDebt;
|
|
2179
|
+
const hasFarm = !farmState.equals(defaultKey);
|
|
2180
|
+
let obligationFarmUserState;
|
|
2181
|
+
if (hasFarm) {
|
|
2182
|
+
obligationFarmUserState = (0, constants_1.getKaminoFarmsObligationFarm)(obligation, farmState, KAMINO_FARMS_PROGRAM_ID);
|
|
2183
|
+
}
|
|
2184
|
+
const farmsAccounts = hasFarm
|
|
2185
|
+
? {
|
|
2186
|
+
obligationFarmUserState,
|
|
2187
|
+
reserveFarmState: farmState,
|
|
2188
|
+
}
|
|
2189
|
+
: {};
|
|
2190
|
+
// 1. Init obligation farms (if needed, before all refreshes)
|
|
2191
|
+
if (hasFarm) {
|
|
2192
|
+
const farmUserStateAccount = await connection.getAccountInfo(obligationFarmUserState);
|
|
2193
|
+
if (!farmUserStateAccount) {
|
|
2194
|
+
pre.push((0, instructions_1.initObligationFarmsForReserve)({ mode: farmMode }, {
|
|
2195
|
+
payer: signer,
|
|
2196
|
+
owner,
|
|
2197
|
+
obligation,
|
|
2198
|
+
lendingMarketAuthority,
|
|
2199
|
+
reserve: reservePubkey,
|
|
2200
|
+
reserveFarmState: farmState,
|
|
2201
|
+
obligationFarm: obligationFarmUserState,
|
|
2202
|
+
lendingMarket,
|
|
2203
|
+
farmsProgram: KAMINO_FARMS_PROGRAM_ID,
|
|
2204
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
2205
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
2206
|
+
}));
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
// 2. Refresh ALL active reserves in the obligation + the operation reserve.
|
|
2210
|
+
// KLend's refreshObligation requires every reserve passed as a remaining
|
|
2211
|
+
// account to have been refreshed in the same transaction.
|
|
2212
|
+
// IMPORTANT: The operation reserve's refreshReserve MUST be the last one
|
|
2213
|
+
// pushed (position -3 from the sync tx) because check_refresh looks for it there.
|
|
2214
|
+
const obligationState = await accounts_1.Obligation.fetch(connection, obligation);
|
|
2215
|
+
const otherReservePubkeys = [];
|
|
2216
|
+
if (obligationState) {
|
|
2217
|
+
for (const d of obligationState.deposits) {
|
|
2218
|
+
if (!d.depositReserve.equals(defaultKey) && !d.depositReserve.equals(reservePubkey)) {
|
|
2219
|
+
otherReservePubkeys.push(d.depositReserve);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
for (const b of obligationState.borrows) {
|
|
2223
|
+
if (!b.borrowReserve.equals(defaultKey) && !b.borrowReserve.equals(reservePubkey)) {
|
|
2224
|
+
otherReservePubkeys.push(b.borrowReserve);
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
// Fetch all other reserve accounts (needed for refreshReserve and optionally Scope refresh)
|
|
2229
|
+
const otherReserves = [];
|
|
2230
|
+
for (const rPubkey of otherReservePubkeys) {
|
|
2231
|
+
const rAccount = await kamino_reserve_deserializer_1.Reserve.fetch(connection, rPubkey);
|
|
2232
|
+
if (!rAccount)
|
|
2233
|
+
continue;
|
|
2234
|
+
otherReserves.push({ pubkey: rPubkey, account: rAccount });
|
|
2235
|
+
}
|
|
2236
|
+
// Scope refreshPriceList — only needed for operations that check ALL_CHECKS
|
|
2237
|
+
// (borrow/withdraw). Must be the FIRST instructions in the transaction
|
|
2238
|
+
// (after ComputeBudget) because the Scope program validates ordering.
|
|
2239
|
+
const allReserves = [...otherReserves, { pubkey: reservePubkey, account: reserveAccount }];
|
|
2240
|
+
const scopeRefreshIxs = needsScopeRefresh
|
|
2241
|
+
? await (0, scope_refresh_1.buildScopeRefreshInstructions)(connection, allReserves)
|
|
2242
|
+
: [];
|
|
2243
|
+
// Refresh other reserves first (order doesn't matter for these)
|
|
2244
|
+
for (const { pubkey: rPubkey, account: rAccount } of otherReserves) {
|
|
2245
|
+
const ti = rAccount.config.tokenInfo;
|
|
2246
|
+
pre.push((0, instructions_1.refreshReserve)({
|
|
2247
|
+
reserve: rPubkey,
|
|
2248
|
+
lendingMarket,
|
|
2249
|
+
pythOracle: oracleOrSentinel(ti.pythConfiguration.price),
|
|
2250
|
+
switchboardPriceOracle: oracleOrSentinel(ti.switchboardConfiguration.priceAggregator),
|
|
2251
|
+
switchboardTwapOracle: oracleOrSentinel(ti.switchboardConfiguration.twapAggregator),
|
|
2252
|
+
scopePrices: oracleOrSentinel(ti.scopeConfiguration.priceFeed),
|
|
2253
|
+
}));
|
|
2254
|
+
}
|
|
2255
|
+
// Refresh the operation reserve LAST — must be at position -3 from the sync tx
|
|
2256
|
+
const ti = reserveAccount.config.tokenInfo;
|
|
2257
|
+
pre.push((0, instructions_1.refreshReserve)({
|
|
2258
|
+
reserve: reservePubkey,
|
|
2259
|
+
lendingMarket,
|
|
2260
|
+
pythOracle: oracleOrSentinel(ti.pythConfiguration.price),
|
|
2261
|
+
switchboardPriceOracle: oracleOrSentinel(ti.switchboardConfiguration.priceAggregator),
|
|
2262
|
+
switchboardTwapOracle: oracleOrSentinel(ti.switchboardConfiguration.twapAggregator),
|
|
2263
|
+
scopePrices: oracleOrSentinel(ti.scopeConfiguration.priceFeed),
|
|
2264
|
+
}));
|
|
2265
|
+
// 3. RefreshObligation — pass all active reserves as remaining accounts.
|
|
2266
|
+
const refreshObligationIx = (0, instructions_1.refreshObligation)({ lendingMarket, obligation });
|
|
2267
|
+
if (obligationState) {
|
|
2268
|
+
const depositReserves = obligationState.deposits
|
|
2269
|
+
.map(d => d.depositReserve)
|
|
2270
|
+
.filter(r => !r.equals(defaultKey));
|
|
2271
|
+
const borrowReserves = obligationState.borrows
|
|
2272
|
+
.map(b => b.borrowReserve)
|
|
2273
|
+
.filter(r => !r.equals(defaultKey));
|
|
2274
|
+
for (const reserve of [...depositReserves, ...borrowReserves]) {
|
|
2275
|
+
refreshObligationIx.keys.push({ pubkey: reserve, isSigner: false, isWritable: false });
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
pre.push(refreshObligationIx);
|
|
2279
|
+
return {
|
|
2280
|
+
scopeRefreshInstructions: scopeRefreshIxs,
|
|
2281
|
+
preInstructions: pre,
|
|
2282
|
+
postInstructions: post,
|
|
2283
|
+
farmsAccounts,
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
// ============================================================================
|
|
2287
|
+
// Orderbook Action Builders
|
|
2288
|
+
// ============================================================================
|
|
2289
|
+
/**
|
|
2290
|
+
* Builder for Exponent Orderbook vault action descriptors.
|
|
2291
|
+
*
|
|
2292
|
+
* Each method returns an `OrderbookInstruction` that describes what to do.
|
|
2293
|
+
* Pass these to `createVaultSyncTransaction` which resolves them into
|
|
2294
|
+
* raw Solana instructions and wraps them in a Squads sync transaction.
|
|
2295
|
+
*
|
|
2296
|
+
* @example
|
|
2297
|
+
* ```ts
|
|
2298
|
+
* import { orderbookAction, createVaultSyncTransaction, OrderbookTradeDirection } from "@exponent-labs/exponent-sdk"
|
|
2299
|
+
*
|
|
2300
|
+
* const { instruction, preInstructions } = await createVaultSyncTransaction({
|
|
2301
|
+
* instructions: [
|
|
2302
|
+
* orderbookAction.postOffer({
|
|
2303
|
+
* orderbook: ORDERBOOK_ADDRESS,
|
|
2304
|
+
* direction: OrderbookTradeDirection.BUY_PT,
|
|
2305
|
+
* priceApy: 0.10,
|
|
2306
|
+
* amount: 1_000_000n,
|
|
2307
|
+
* }),
|
|
2308
|
+
* ],
|
|
2309
|
+
* owner: squadsVault,
|
|
2310
|
+
* connection,
|
|
2311
|
+
* policyPda,
|
|
2312
|
+
* vaultPda: squadsVault,
|
|
2313
|
+
* signer: walletPublicKey,
|
|
2314
|
+
* })
|
|
2315
|
+
* ```
|
|
2316
|
+
*/
|
|
2317
|
+
exports.orderbookAction = {
|
|
2318
|
+
/**
|
|
2319
|
+
* Post a limit order on the orderbook.
|
|
2320
|
+
* @param params - Order parameters
|
|
2321
|
+
*/
|
|
2322
|
+
postOffer(params) {
|
|
2323
|
+
return {
|
|
2324
|
+
action: vault_instruction_types_2.OrderbookAction.POST_OFFER,
|
|
2325
|
+
orderbook: params.orderbook,
|
|
2326
|
+
mode: params.mode,
|
|
2327
|
+
direction: params.direction,
|
|
2328
|
+
priceApy: params.priceApy,
|
|
2329
|
+
amount: params.amount,
|
|
2330
|
+
offerOption: params.offerOption,
|
|
2331
|
+
expirySeconds: params.expirySeconds,
|
|
2332
|
+
};
|
|
2333
|
+
},
|
|
2334
|
+
/**
|
|
2335
|
+
* Execute a market order on the orderbook.
|
|
2336
|
+
* @param params - Order parameters
|
|
2337
|
+
*/
|
|
2338
|
+
marketOffer(params) {
|
|
2339
|
+
return {
|
|
2340
|
+
action: vault_instruction_types_2.OrderbookAction.MARKET_OFFER,
|
|
2341
|
+
orderbook: params.orderbook,
|
|
2342
|
+
mode: params.mode,
|
|
2343
|
+
direction: params.direction,
|
|
2344
|
+
maxPriceApy: params.maxPriceApy,
|
|
2345
|
+
amount: params.amount,
|
|
2346
|
+
minAmountOut: params.minAmountOut,
|
|
2347
|
+
virtualOffer: params.virtualOffer,
|
|
2348
|
+
};
|
|
2349
|
+
},
|
|
2350
|
+
/**
|
|
2351
|
+
* Cancel an existing limit order.
|
|
2352
|
+
* @param params - Cancel parameters
|
|
2353
|
+
*/
|
|
2354
|
+
removeOffer(params) {
|
|
2355
|
+
return {
|
|
2356
|
+
action: vault_instruction_types_2.OrderbookAction.REMOVE_OFFER,
|
|
2357
|
+
orderbook: params.orderbook,
|
|
2358
|
+
offerIdx: params.offerIdx,
|
|
2359
|
+
};
|
|
2360
|
+
},
|
|
2361
|
+
/**
|
|
2362
|
+
* Withdraw funds from user escrow to token accounts.
|
|
2363
|
+
* @param params - Withdraw parameters (null amounts = withdraw max)
|
|
2364
|
+
*/
|
|
2365
|
+
withdrawFunds(params) {
|
|
2366
|
+
return {
|
|
2367
|
+
action: vault_instruction_types_2.OrderbookAction.WITHDRAW_FUNDS,
|
|
2368
|
+
orderbook: params.orderbook,
|
|
2369
|
+
ptAmount: params.ptAmount,
|
|
2370
|
+
ytAmount: params.ytAmount,
|
|
2371
|
+
syAmount: params.syAmount,
|
|
2372
|
+
};
|
|
2373
|
+
},
|
|
2374
|
+
};
|
|
2375
|
+
exports.syAction = {
|
|
2376
|
+
mint(params) {
|
|
2377
|
+
return {
|
|
2378
|
+
action: vault_instruction_types_2.SyAction.MINT,
|
|
2379
|
+
vault: params.vault,
|
|
2380
|
+
amountBase: params.amountBase,
|
|
2381
|
+
};
|
|
2382
|
+
},
|
|
2383
|
+
redeem(params) {
|
|
2384
|
+
return {
|
|
2385
|
+
action: vault_instruction_types_2.SyAction.REDEEM,
|
|
2386
|
+
vault: params.vault,
|
|
2387
|
+
amountSy: params.amountSy,
|
|
2388
|
+
};
|
|
2389
|
+
},
|
|
2390
|
+
};
|
|
2391
|
+
// ============================================================================
|
|
2392
|
+
// Core Action Builders (Strip/Merge)
|
|
2393
|
+
// ============================================================================
|
|
2394
|
+
/**
|
|
2395
|
+
* Builder for Exponent Core strip/merge action descriptors.
|
|
2396
|
+
*
|
|
2397
|
+
* Each method returns a `CoreInstruction` that describes what to do.
|
|
2398
|
+
* Pass these to `createVaultSyncTransaction` which resolves them into
|
|
2399
|
+
* raw Solana instructions and wraps them in a Squads sync transaction.
|
|
2400
|
+
*
|
|
2401
|
+
* @example
|
|
2402
|
+
* ```ts
|
|
2403
|
+
* import { coreAction, createVaultSyncTransaction } from "@exponent-labs/exponent-sdk"
|
|
2404
|
+
*
|
|
2405
|
+
* const { instruction, preInstructions } = await createVaultSyncTransaction({
|
|
2406
|
+
* instructions: [
|
|
2407
|
+
* coreAction.strip({
|
|
2408
|
+
* vault: VAULT_ADDRESS,
|
|
2409
|
+
* amountBase: 1_000_000_000n, // 1 SOL worth
|
|
2410
|
+
* }),
|
|
2411
|
+
* ],
|
|
2412
|
+
* owner: squadsVault,
|
|
2413
|
+
* connection,
|
|
2414
|
+
* policyPda,
|
|
2415
|
+
* vaultPda: squadsVault,
|
|
2416
|
+
* signer: walletPublicKey,
|
|
2417
|
+
* })
|
|
2418
|
+
* ```
|
|
2419
|
+
*/
|
|
2420
|
+
exports.coreAction = {
|
|
2421
|
+
/**
|
|
2422
|
+
* Strip LST (base token) into PT + YT.
|
|
2423
|
+
* @param params - Strip parameters
|
|
2424
|
+
*/
|
|
2425
|
+
strip(params) {
|
|
2426
|
+
return {
|
|
2427
|
+
action: vault_instruction_types_2.CoreAction.STRIP,
|
|
2428
|
+
vault: params.vault,
|
|
2429
|
+
amountBase: params.amountBase,
|
|
2430
|
+
};
|
|
2431
|
+
},
|
|
2432
|
+
/**
|
|
2433
|
+
* Merge PT + YT into LST (base token).
|
|
2434
|
+
* Requires equal amounts of PT and YT.
|
|
2435
|
+
* @param params - Merge parameters
|
|
2436
|
+
*/
|
|
2437
|
+
merge(params) {
|
|
2438
|
+
return {
|
|
2439
|
+
action: vault_instruction_types_2.CoreAction.MERGE,
|
|
2440
|
+
vault: params.vault,
|
|
2441
|
+
amountPy: params.amountPy,
|
|
2442
|
+
};
|
|
2443
|
+
},
|
|
2444
|
+
/**
|
|
2445
|
+
* Withdraw YT from the tracked yield position into the owner's YT token account.
|
|
2446
|
+
* Useful before wrapper_merge, which consumes YT from the token account.
|
|
2447
|
+
*/
|
|
2448
|
+
withdrawYt(params) {
|
|
2449
|
+
return {
|
|
2450
|
+
action: vault_instruction_types_2.CoreAction.WITHDRAW_YT,
|
|
2451
|
+
vault: params.vault,
|
|
2452
|
+
amountYt: params.amountYt,
|
|
2453
|
+
};
|
|
2454
|
+
},
|
|
2455
|
+
/**
|
|
2456
|
+
* Deposit YT from the owner's YT token account back into the tracked yield position.
|
|
2457
|
+
* Use this to ensure idle YT continues earning yield.
|
|
2458
|
+
*/
|
|
2459
|
+
depositYt(params) {
|
|
2460
|
+
return {
|
|
2461
|
+
action: vault_instruction_types_2.CoreAction.DEPOSIT_YT,
|
|
2462
|
+
vault: params.vault,
|
|
2463
|
+
amountYt: params.amountYt,
|
|
2464
|
+
};
|
|
2465
|
+
},
|
|
2466
|
+
/**
|
|
2467
|
+
* Initialize yield position for the Squads vault (owner).
|
|
2468
|
+
* Required before buying YT or depositing YT. When `autoManagePositions`
|
|
2469
|
+
* is enabled, the SDK also tracks the new yield position automatically.
|
|
2470
|
+
*/
|
|
2471
|
+
initializeYieldPosition(params) {
|
|
2472
|
+
return {
|
|
2473
|
+
action: vault_instruction_types_2.CoreAction.INITIALIZE_YIELD_POSITION,
|
|
2474
|
+
vault: params.vault,
|
|
2475
|
+
};
|
|
2476
|
+
},
|
|
2477
|
+
};
|
|
2478
|
+
/**
|
|
2479
|
+
* Convert trade direction to OfferType used by the orderbook program.
|
|
2480
|
+
*/
|
|
2481
|
+
function directionToOfferType(direction) {
|
|
2482
|
+
switch (direction) {
|
|
2483
|
+
case vault_instruction_types_2.OrderbookTradeDirection.BUY_PT:
|
|
2484
|
+
case vault_instruction_types_2.OrderbookTradeDirection.SELL_YT:
|
|
2485
|
+
return orderbook_2.OfferType.SellYt;
|
|
2486
|
+
case vault_instruction_types_2.OrderbookTradeDirection.SELL_PT:
|
|
2487
|
+
case vault_instruction_types_2.OrderbookTradeDirection.BUY_YT:
|
|
2488
|
+
return orderbook_2.OfferType.BuyYt;
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Build orderbook instructions and wrap them in a Squads sync transaction.
|
|
2493
|
+
*
|
|
2494
|
+
* Takes high-level `OrderbookInstruction` descriptors (built with `orderbookAction.*`),
|
|
2495
|
+
* loads the orderbook SDK, resolves them to raw Solana instructions, and wraps them
|
|
2496
|
+
* in a Squads sync transaction.
|
|
2497
|
+
*
|
|
2498
|
+
* @returns `{ setupInstructions, preInstructions, instruction, postInstructions }` — include all in your transaction
|
|
2499
|
+
*
|
|
2500
|
+
* @example
|
|
2501
|
+
* ```ts
|
|
2502
|
+
* const { setupInstructions, preInstructions, instruction, postInstructions } = await createOrderbookSyncTransaction({
|
|
2503
|
+
* instructions: [
|
|
2504
|
+
* orderbookAction.postOffer({
|
|
2505
|
+
* orderbook: ORDERBOOK_ADDRESS,
|
|
2506
|
+
* direction: OrderbookTradeDirection.BUY_PT,
|
|
2507
|
+
* priceApy: 0.10,
|
|
2508
|
+
* amount: 1_000_000n,
|
|
2509
|
+
* }),
|
|
2510
|
+
* ],
|
|
2511
|
+
* owner: squadsVault,
|
|
2512
|
+
* connection,
|
|
2513
|
+
* policyPda,
|
|
2514
|
+
* vaultPda: squadsVault,
|
|
2515
|
+
* signer: wallet.publicKey,
|
|
2516
|
+
* vaultAddress: VAULT_ADDRESS,
|
|
2517
|
+
* })
|
|
2518
|
+
* // Send: [...setupInstructions, ...preInstructions, instruction, ...postInstructions]
|
|
2519
|
+
* ```
|
|
2520
|
+
*/
|
|
2521
|
+
async function createOrderbookSyncTransaction({ instructions, owner, connection, policyPda, vaultPda, signer, accountIndex = 0, constraintIndices, vaultAddress, leadingAccounts, preHookAccounts, postHookAccounts, squadsProgram = syncTransaction_1.SQUADS_PROGRAM_ID, env = environment_1.LOCAL_ENV, }) {
|
|
2522
|
+
vaultPda ??= owner;
|
|
2523
|
+
const { setupInstructions, syncInstructions, preInstructions, postInstructions, signers, addressLookupTableAddresses } = await buildOrderbookInstructions(instructions, owner, connection, signer, policyPda, vaultPda, accountIndex, vaultAddress, leadingAccounts, preHookAccounts, postHookAccounts, squadsProgram, env);
|
|
2524
|
+
let resolvedPolicyPda = policyPda;
|
|
2525
|
+
let resolvedConstraintIndices = constraintIndices;
|
|
2526
|
+
if (!resolvedPolicyPda) {
|
|
2527
|
+
if (!vaultAddress) {
|
|
2528
|
+
throw new Error("vaultAddress is required when policyPda is not provided");
|
|
2529
|
+
}
|
|
2530
|
+
const match = await (0, policyMatcher_1.resolvePolicyMatchForVault)(connection, vaultAddress, signer, syncInstructions);
|
|
2531
|
+
resolvedPolicyPda = match.policyPda;
|
|
2532
|
+
resolvedConstraintIndices ??= match.constraintIndices;
|
|
2533
|
+
}
|
|
2534
|
+
// Auto-resolve constraint indices when not explicitly provided
|
|
2535
|
+
resolvedConstraintIndices ??= await (0, policyMatcher_1.resolveConstraintIndices)(connection, resolvedPolicyPda, syncInstructions);
|
|
2536
|
+
// Auto-resolve policy prefix and hook accounts when not explicitly provided
|
|
2537
|
+
let resolvedLeadingAccounts = leadingAccounts;
|
|
2538
|
+
let resolvedPreHookAccounts = preHookAccounts;
|
|
2539
|
+
let resolvedPostHookAccounts = postHookAccounts;
|
|
2540
|
+
if (vaultAddress && (!leadingAccounts || !preHookAccounts || !postHookAccounts)) {
|
|
2541
|
+
const hooks = await (0, policyMatcher_1.resolveHookAccounts)(connection, resolvedPolicyPda, vaultAddress, signer);
|
|
2542
|
+
resolvedLeadingAccounts ??= hooks.leadingAccounts;
|
|
2543
|
+
resolvedPreHookAccounts ??= hooks.preHookAccounts;
|
|
2544
|
+
resolvedPostHookAccounts ??= hooks.postHookAccounts;
|
|
2545
|
+
}
|
|
2546
|
+
const instruction = (0, syncTransaction_1.wrapInstructionsInSyncTransaction)({
|
|
2547
|
+
policyPda: resolvedPolicyPda,
|
|
2548
|
+
vaultPda,
|
|
2549
|
+
signer,
|
|
2550
|
+
instructions: syncInstructions,
|
|
2551
|
+
squadsProgram,
|
|
2552
|
+
accountIndex,
|
|
2553
|
+
constraintIndices: resolvedConstraintIndices,
|
|
2554
|
+
leadingAccounts: resolvedLeadingAccounts,
|
|
2555
|
+
preHookAccounts: resolvedPreHookAccounts,
|
|
2556
|
+
postHookAccounts: resolvedPostHookAccounts,
|
|
2557
|
+
});
|
|
2558
|
+
return { setupInstructions, preInstructions, instruction, postInstructions, signers, addressLookupTableAddresses };
|
|
2559
|
+
}
|
|
2560
|
+
exports.createOrderbookSyncTransaction = createOrderbookSyncTransaction;
|
|
2561
|
+
/** Cache for loaded orderbooks to avoid redundant fetches */
|
|
2562
|
+
const orderbookCache = new Map();
|
|
2563
|
+
/**
|
|
2564
|
+
* Build raw Solana instructions from orderbook action descriptors.
|
|
2565
|
+
*/
|
|
2566
|
+
async function buildOrderbookInstructions(instructions, owner, connection, signer, policyPda, vaultPda, accountIndex, vaultAddress, leadingAccounts, preHookAccounts, postHookAccounts, squadsProgram, env) {
|
|
2567
|
+
const buckets = {
|
|
2568
|
+
setupInstructions: [],
|
|
2569
|
+
syncInstructions: [],
|
|
2570
|
+
preInstructions: [],
|
|
2571
|
+
postInstructions: [],
|
|
2572
|
+
signers: [],
|
|
2573
|
+
addressLookupTableAddresses: [],
|
|
2574
|
+
};
|
|
2575
|
+
const setupContext = createStrategySetupContext({
|
|
2576
|
+
connection,
|
|
2577
|
+
env,
|
|
2578
|
+
owner,
|
|
2579
|
+
signer,
|
|
2580
|
+
vaultAddress,
|
|
2581
|
+
policyPda,
|
|
2582
|
+
vaultPda,
|
|
2583
|
+
accountIndex,
|
|
2584
|
+
squadsProgram,
|
|
2585
|
+
leadingAccounts,
|
|
2586
|
+
preHookAccounts,
|
|
2587
|
+
postHookAccounts,
|
|
2588
|
+
});
|
|
2589
|
+
for (const ix of instructions) {
|
|
2590
|
+
await buildOrderbookInstruction(ix, owner, connection, buckets, setupContext, env);
|
|
2591
|
+
}
|
|
2592
|
+
return buckets;
|
|
2593
|
+
}
|
|
2594
|
+
async function buildPostOffer(ix, orderbook, owner, setupPayer, buckets, setupContext) {
|
|
2595
|
+
const offerType = directionToOfferType(ix.direction);
|
|
2596
|
+
const option = ix.offerOption ?? "FillOrKill";
|
|
2597
|
+
const offerIdx = orderbook.getNextOfferIndex();
|
|
2598
|
+
if (setupContext) {
|
|
2599
|
+
await ensureOrderbookPositionSetup(orderbook, buckets, setupContext);
|
|
2600
|
+
await ensureTrackedTokenAccountSetup({
|
|
2601
|
+
tokenMint: orderbook.vault.mintSy,
|
|
2602
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(orderbook.vault.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2603
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2604
|
+
buckets,
|
|
2605
|
+
setupContext,
|
|
2606
|
+
});
|
|
2607
|
+
await ensureTrackedTokenAccountSetup({
|
|
2608
|
+
tokenMint: orderbook.mintPt,
|
|
2609
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(orderbook.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2610
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2611
|
+
buckets,
|
|
2612
|
+
setupContext,
|
|
2613
|
+
});
|
|
2614
|
+
await ensureTrackedTokenAccountSetup({
|
|
2615
|
+
tokenMint: orderbook.mintYt,
|
|
2616
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(orderbook.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2617
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2618
|
+
buckets,
|
|
2619
|
+
setupContext,
|
|
2620
|
+
});
|
|
2621
|
+
await ensureYieldPositionSetup(orderbook.vault, buckets, setupContext);
|
|
2622
|
+
}
|
|
2623
|
+
if (ix.mode === "raw") {
|
|
2624
|
+
buckets.syncInstructions.push(orderbook.ixPostOffer({
|
|
2625
|
+
trader: owner,
|
|
2626
|
+
price: ix.priceApy,
|
|
2627
|
+
amount: ix.amount,
|
|
2628
|
+
offerType,
|
|
2629
|
+
offerOption: (0, orderbook_2.offerOptions)(option, [false]),
|
|
2630
|
+
virtualOffer: true,
|
|
2631
|
+
expirySeconds: ix.expirySeconds ?? 3600,
|
|
2632
|
+
mintSy: orderbook.vault.mintSy,
|
|
2633
|
+
offerIdx,
|
|
2634
|
+
}));
|
|
2635
|
+
return;
|
|
2636
|
+
}
|
|
2637
|
+
const { ix: postOfferIx, setupIxs } = await orderbook.ixWrapperPostOffer({
|
|
2638
|
+
trader: owner,
|
|
2639
|
+
setupPayer,
|
|
2640
|
+
price: ix.priceApy,
|
|
2641
|
+
amount: ix.amount,
|
|
2642
|
+
offerType,
|
|
2643
|
+
offerOption: (0, orderbook_2.offerOptions)(option, [false]),
|
|
2644
|
+
virtualOffer: true,
|
|
2645
|
+
expirySeconds: ix.expirySeconds ?? 3600,
|
|
2646
|
+
mintSy: orderbook.vault.mintSy,
|
|
2647
|
+
offerIdx,
|
|
2648
|
+
});
|
|
2649
|
+
buckets.preInstructions.push(...setupIxs);
|
|
2650
|
+
buckets.syncInstructions.push(postOfferIx);
|
|
2651
|
+
}
|
|
2652
|
+
async function buildMarketOffer(ix, orderbook, owner, setupPayer, buckets, setupContext) {
|
|
2653
|
+
const offerType = directionToOfferType(ix.direction);
|
|
2654
|
+
if (setupContext) {
|
|
2655
|
+
await ensureOrderbookPositionSetup(orderbook, buckets, setupContext);
|
|
2656
|
+
await ensureTrackedTokenAccountSetup({
|
|
2657
|
+
tokenMint: orderbook.vault.mintSy,
|
|
2658
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(orderbook.vault.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2659
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2660
|
+
buckets,
|
|
2661
|
+
setupContext,
|
|
2662
|
+
});
|
|
2663
|
+
await ensureTrackedTokenAccountSetup({
|
|
2664
|
+
tokenMint: orderbook.mintPt,
|
|
2665
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(orderbook.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2666
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2667
|
+
buckets,
|
|
2668
|
+
setupContext,
|
|
2669
|
+
});
|
|
2670
|
+
await ensureTrackedTokenAccountSetup({
|
|
2671
|
+
tokenMint: orderbook.mintYt,
|
|
2672
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(orderbook.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2673
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2674
|
+
buckets,
|
|
2675
|
+
setupContext,
|
|
2676
|
+
});
|
|
2677
|
+
await ensureYieldPositionSetup(orderbook.vault, buckets, setupContext);
|
|
2678
|
+
}
|
|
2679
|
+
if (ix.mode === "raw") {
|
|
2680
|
+
buckets.syncInstructions.push(orderbook.ixMarketOffer({
|
|
2681
|
+
trader: owner,
|
|
2682
|
+
maxPriceApy: ix.maxPriceApy,
|
|
2683
|
+
amount: ix.amount,
|
|
2684
|
+
minAmountOut: ix.minAmountOut,
|
|
2685
|
+
offerType,
|
|
2686
|
+
virtualOffer: ix.virtualOffer ?? false,
|
|
2687
|
+
mintSy: orderbook.vault.mintSy,
|
|
2688
|
+
}));
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2691
|
+
const { ix: marketOfferIx, setupIxs } = await orderbook.ixWrapperMarketOffer({
|
|
2692
|
+
trader: owner,
|
|
2693
|
+
setupPayer,
|
|
2694
|
+
maxPriceApy: ix.maxPriceApy,
|
|
2695
|
+
amount: ix.amount,
|
|
2696
|
+
offerType,
|
|
2697
|
+
minAmountOut: ix.minAmountOut,
|
|
2698
|
+
virtualOffer: ix.virtualOffer ?? false,
|
|
2699
|
+
mintSy: orderbook.vault.mintSy,
|
|
2700
|
+
});
|
|
2701
|
+
buckets.preInstructions.push(...setupIxs);
|
|
2702
|
+
buckets.syncInstructions.push(marketOfferIx);
|
|
2703
|
+
}
|
|
2704
|
+
async function buildRemoveOffer(ix, orderbook, owner, { syncInstructions }) {
|
|
2705
|
+
const removeOfferIx = await orderbook.ixWrapperRemoveOffer({
|
|
2706
|
+
trader: owner,
|
|
2707
|
+
offerIdx: ix.offerIdx,
|
|
2708
|
+
mintSy: orderbook.vault.mintSy,
|
|
2709
|
+
});
|
|
2710
|
+
syncInstructions.push(removeOfferIx);
|
|
2711
|
+
}
|
|
2712
|
+
async function buildWithdrawFunds(ix, orderbook, owner, { syncInstructions }) {
|
|
2713
|
+
// Convert bigint | null | undefined to Amount type
|
|
2714
|
+
const toAmount = (value) => {
|
|
2715
|
+
if (value === null || value === undefined) {
|
|
2716
|
+
return (0, orderbook_2.amount)("All");
|
|
2717
|
+
}
|
|
2718
|
+
return (0, orderbook_2.amount)("Some", [value]);
|
|
2719
|
+
};
|
|
2720
|
+
const withdrawFundsIx = await orderbook.ixWrapperWithdrawFunds({
|
|
2721
|
+
trader: owner,
|
|
2722
|
+
mintSy: orderbook.vault.mintSy,
|
|
2723
|
+
ptAmount: toAmount(ix.ptAmount),
|
|
2724
|
+
ytAmount: toAmount(ix.ytAmount),
|
|
2725
|
+
syAmount: toAmount(ix.syAmount),
|
|
2726
|
+
});
|
|
2727
|
+
syncInstructions.push(withdrawFundsIx);
|
|
2728
|
+
}
|
|
2729
|
+
// ============================================================================
|
|
2730
|
+
// Core Instruction Builders (Strip/Merge)
|
|
2731
|
+
// ============================================================================
|
|
2732
|
+
async function queueYieldPositionTrackingAfterInit(params) {
|
|
2733
|
+
const state = await loadStrategySetupState(params.setupContext);
|
|
2734
|
+
if (!state || state.trackedYieldVaults.has(params.vault.selfAddress.toBase58())) {
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
const yieldPosition = params.vault.pda.yieldPosition({
|
|
2738
|
+
owner: params.setupContext.owner,
|
|
2739
|
+
vault: params.vault.selfAddress,
|
|
2740
|
+
});
|
|
2741
|
+
const priceIdPt = (0, pricePathResolver_1.resolvePriceIdFromMintToUnderlyingOrThrow)({
|
|
2742
|
+
prices: state.prices,
|
|
2743
|
+
sourceMint: params.vault.mintPt,
|
|
2744
|
+
targetMint: state.strategyVault.state.underlyingMint,
|
|
2745
|
+
label: `yield position setup (${params.vault.selfAddress.toBase58()})`,
|
|
2746
|
+
});
|
|
2747
|
+
trackRequiredPriceIds(state.requiredPriceIds, priceIdPt);
|
|
2748
|
+
params.postInstructions.push(state.strategyVault.ixWrapperManageVaultSettings({
|
|
2749
|
+
manager: params.setupContext.signer,
|
|
2750
|
+
actions: [
|
|
2751
|
+
exponentVaults.vaultSettingsAction("AddYieldPositionEntry", {
|
|
2752
|
+
yieldPosition,
|
|
2753
|
+
vault: params.vault.selfAddress,
|
|
2754
|
+
priceIdPt,
|
|
2755
|
+
}),
|
|
2756
|
+
],
|
|
2757
|
+
remainingAccounts: [
|
|
2758
|
+
{ pubkey: params.vault.selfAddress, isSigner: false, isWritable: false },
|
|
2759
|
+
{ pubkey: yieldPosition, isSigner: false, isWritable: false },
|
|
2760
|
+
],
|
|
2761
|
+
}));
|
|
2762
|
+
recordPlannedYieldPosition(state, {
|
|
2763
|
+
yieldPosition,
|
|
2764
|
+
vault: params.vault.selfAddress,
|
|
2765
|
+
priceIdPt,
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
/** Build a single core instruction (strip/merge) */
|
|
2769
|
+
async function buildCoreInstruction(ix, owner, connection, buckets, setupContext) {
|
|
2770
|
+
const cacheKey = ix.vault.toBase58();
|
|
2771
|
+
let vault = vaultCache.get(cacheKey);
|
|
2772
|
+
if (!vault) {
|
|
2773
|
+
vault = await vault_1.Vault.load(environment_1.LOCAL_ENV, connection, ix.vault);
|
|
2774
|
+
vaultCache.set(cacheKey, vault);
|
|
2775
|
+
}
|
|
2776
|
+
const isInitializeYieldPosition = ix.action === vault_instruction_types_2.CoreAction.INITIALIZE_YIELD_POSITION;
|
|
2777
|
+
if (setupContext && !isInitializeYieldPosition) {
|
|
2778
|
+
await ensureTrackedTokenAccountSetup({
|
|
2779
|
+
tokenMint: vault.mintPt,
|
|
2780
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintPt, setupContext.owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2781
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2782
|
+
buckets,
|
|
2783
|
+
setupContext,
|
|
2784
|
+
});
|
|
2785
|
+
await ensureYieldPositionSetup(vault, buckets, setupContext);
|
|
2786
|
+
if (ix.action === vault_instruction_types_2.CoreAction.WITHDRAW_YT) {
|
|
2787
|
+
await ensureTrackedTokenAccountSetup({
|
|
2788
|
+
tokenMint: vault.mintYt,
|
|
2789
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintYt, setupContext.owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
2790
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2791
|
+
buckets,
|
|
2792
|
+
setupContext,
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
switch (ix.action) {
|
|
2797
|
+
case vault_instruction_types_2.CoreAction.STRIP:
|
|
2798
|
+
await buildStrip(ix, vault, owner, setupContext?.signer ?? owner, buckets);
|
|
2799
|
+
break;
|
|
2800
|
+
case vault_instruction_types_2.CoreAction.MERGE:
|
|
2801
|
+
await buildMerge(ix, vault, owner, setupContext?.signer ?? owner, buckets);
|
|
2802
|
+
break;
|
|
2803
|
+
case vault_instruction_types_2.CoreAction.WITHDRAW_YT:
|
|
2804
|
+
await buildWithdrawYt(ix, vault, owner, setupContext?.signer ?? owner, buckets);
|
|
2805
|
+
break;
|
|
2806
|
+
case vault_instruction_types_2.CoreAction.DEPOSIT_YT:
|
|
2807
|
+
await buildDepositYt(ix, vault, owner, buckets);
|
|
2808
|
+
break;
|
|
2809
|
+
case vault_instruction_types_2.CoreAction.INITIALIZE_YIELD_POSITION:
|
|
2810
|
+
await buildInitializeYieldPosition(ix, vault, owner, buckets, setupContext);
|
|
2811
|
+
break;
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
async function buildInitializeYieldPosition(ix, vault, owner, { syncInstructions, postInstructions }, setupContext) {
|
|
2815
|
+
const initIx = vault.ixInitializeYieldPosition({ owner });
|
|
2816
|
+
syncInstructions.push(initIx);
|
|
2817
|
+
if (setupContext && isAutoManagePositionsEnabled(setupContext)) {
|
|
2818
|
+
await queueYieldPositionTrackingAfterInit({
|
|
2819
|
+
vault,
|
|
2820
|
+
setupContext,
|
|
2821
|
+
postInstructions,
|
|
2822
|
+
});
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
async function buildStrip(ix, vault, owner, payer, { syncInstructions, preInstructions }) {
|
|
2826
|
+
const sySrc = (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
2827
|
+
const ptDst = (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
2828
|
+
const ytDst = (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
2829
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payer, sySrc, owner, vault.mintSy), (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payer, ptDst, owner, vault.mintPt), (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payer, ytDst, owner, vault.mintYt));
|
|
2830
|
+
const stripIx = await vault.ixStripFromBase({
|
|
2831
|
+
owner,
|
|
2832
|
+
amountBase: ix.amountBase,
|
|
2833
|
+
sySrc,
|
|
2834
|
+
ptDst,
|
|
2835
|
+
ytDst,
|
|
2836
|
+
});
|
|
2837
|
+
// Strip instruction needs vault signature
|
|
2838
|
+
syncInstructions.push(stripIx);
|
|
2839
|
+
}
|
|
2840
|
+
async function buildMerge(ix, vault, owner, payer, { syncInstructions, preInstructions }) {
|
|
2841
|
+
const { ixs, setupIxs } = await vault.ixMergeToBase({
|
|
2842
|
+
owner,
|
|
2843
|
+
payer,
|
|
2844
|
+
amountPy: ix.amountPy,
|
|
2845
|
+
});
|
|
2846
|
+
// Setup instructions (ATA creation) go in preInstructions
|
|
2847
|
+
preInstructions.push(...setupIxs);
|
|
2848
|
+
// Merge instructions need vault signature
|
|
2849
|
+
syncInstructions.push(...ixs);
|
|
2850
|
+
}
|
|
2851
|
+
async function buildWithdrawYt(ix, vault, owner, payer, { syncInstructions, preInstructions }) {
|
|
2852
|
+
const ytDst = (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
2853
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payer, ytDst, owner, vault.mintYt));
|
|
2854
|
+
const ytPosition = await ytPosition_1.YtPosition.loadByOwner(environment_1.LOCAL_ENV, vault.connection, owner, vault);
|
|
2855
|
+
syncInstructions.push(ytPosition.ixWithdrawYt({
|
|
2856
|
+
amount: ix.amountYt,
|
|
2857
|
+
ytDst,
|
|
2858
|
+
}));
|
|
2859
|
+
}
|
|
2860
|
+
async function buildDepositYt(ix, vault, owner, { syncInstructions }) {
|
|
2861
|
+
const ytSrc = (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
2862
|
+
const ytPosition = await ytPosition_1.YtPosition.loadByOwner(environment_1.LOCAL_ENV, vault.connection, owner, vault);
|
|
2863
|
+
syncInstructions.push(ytPosition.ixDepositYt({
|
|
2864
|
+
amount: ix.amountYt,
|
|
2865
|
+
ytSrc,
|
|
2866
|
+
}));
|
|
2867
|
+
}
|
|
2868
|
+
async function buildSyInstruction(ix, owner, connection, buckets, setupContext) {
|
|
2869
|
+
const cacheKey = ix.vault.toBase58();
|
|
2870
|
+
let vault = vaultCache.get(cacheKey);
|
|
2871
|
+
if (!vault) {
|
|
2872
|
+
vault = await vault_1.Vault.load(environment_1.LOCAL_ENV, connection, ix.vault);
|
|
2873
|
+
vaultCache.set(cacheKey, vault);
|
|
2874
|
+
}
|
|
2875
|
+
if (!setupContext) {
|
|
2876
|
+
throw new Error("SY actions require a strategy setup context");
|
|
2877
|
+
}
|
|
2878
|
+
const setupState = await loadStrategySetupState(setupContext);
|
|
2879
|
+
if (!setupState) {
|
|
2880
|
+
throw new Error("SY actions require a strategy vault context");
|
|
2881
|
+
}
|
|
2882
|
+
const trackedBaseTokenAccount = setupState.tokenEntryAccountByMint.get(vault.flavor.mintBase.toBase58());
|
|
2883
|
+
const baseTokenAccount = trackedBaseTokenAccount
|
|
2884
|
+
? new web3_js_1.PublicKey(trackedBaseTokenAccount)
|
|
2885
|
+
: (0, spl_token_1.getAssociatedTokenAddressSync)(vault.flavor.mintBase, owner, true, vault.flavor.baseTokenProgram);
|
|
2886
|
+
const syTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(vault.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
2887
|
+
await ensureTrackedTokenAccountSetup({
|
|
2888
|
+
tokenMint: vault.mintSy,
|
|
2889
|
+
tokenAccount: syTokenAccount,
|
|
2890
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2891
|
+
buckets,
|
|
2892
|
+
setupContext,
|
|
2893
|
+
});
|
|
2894
|
+
if (!setupState.trackedTokenAccounts.has(baseTokenAccount.toBase58())) {
|
|
2895
|
+
throw new Error(`Base mint ${vault.flavor.mintBase.toBase58()} must be tracked on the strategy vault before using mint_sy/redeem_sy`);
|
|
2896
|
+
}
|
|
2897
|
+
switch (ix.action) {
|
|
2898
|
+
case vault_instruction_types_2.SyAction.MINT:
|
|
2899
|
+
buckets.syncInstructions.push(await vault.flavor.ixMintSy({
|
|
2900
|
+
amountBase: ix.amountBase.toString(),
|
|
2901
|
+
depositor: owner,
|
|
2902
|
+
depositorBaseTokenAccount: baseTokenAccount,
|
|
2903
|
+
depositorSyTokenAccount: syTokenAccount,
|
|
2904
|
+
}));
|
|
2905
|
+
break;
|
|
2906
|
+
case vault_instruction_types_2.SyAction.REDEEM:
|
|
2907
|
+
buckets.syncInstructions.push(await vault.flavor.ixRedeemSy({
|
|
2908
|
+
amountSy: ix.amountSy.toString(),
|
|
2909
|
+
redeemer: owner,
|
|
2910
|
+
redeemerBaseTokenAccount: baseTokenAccount,
|
|
2911
|
+
redeemerSyTokenAccount: syTokenAccount,
|
|
2912
|
+
}));
|
|
2913
|
+
break;
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
/**
|
|
2917
|
+
* Builder for Titan swap vault action descriptors.
|
|
2918
|
+
*
|
|
2919
|
+
* Since Titan swap instructions contain complex routing data from Titan's API,
|
|
2920
|
+
* you pass a pre-built `TransactionInstruction` and we wrap it in a sync transaction.
|
|
2921
|
+
*
|
|
2922
|
+
* @example
|
|
2923
|
+
* ```ts
|
|
2924
|
+
* import { titanAction, createVaultSyncTransaction } from "@exponent-labs/exponent-sdk"
|
|
2925
|
+
*
|
|
2926
|
+
* const { setupInstructions, instruction } = await createVaultSyncTransaction({
|
|
2927
|
+
* instructions: [titanAction.swap({ instruction: titanSwapIx })],
|
|
2928
|
+
* owner: squadsVault,
|
|
2929
|
+
* connection,
|
|
2930
|
+
* policyPda,
|
|
2931
|
+
* vaultPda: squadsVault,
|
|
2932
|
+
* signer: wallet.publicKey,
|
|
2933
|
+
* vaultAddress: VAULT_ADDRESS,
|
|
2934
|
+
* })
|
|
2935
|
+
* ```
|
|
2936
|
+
*/
|
|
2937
|
+
exports.titanAction = {
|
|
2938
|
+
/**
|
|
2939
|
+
* Wrap a Titan SwapRouteV2 instruction for vault execution.
|
|
2940
|
+
* @param params.instruction - Pre-built TransactionInstruction from Titan's router API
|
|
2941
|
+
* @param params.addressLookupTableAddresses - Optional ALT addresses returned by Titan for this route
|
|
2942
|
+
*/
|
|
2943
|
+
swap(params) {
|
|
2944
|
+
return {
|
|
2945
|
+
action: vault_instruction_types_2.TitanAction.SWAP,
|
|
2946
|
+
instruction: params.instruction,
|
|
2947
|
+
addressLookupTableAddresses: params.addressLookupTableAddresses,
|
|
2948
|
+
};
|
|
2949
|
+
},
|
|
2950
|
+
};
|
|
2951
|
+
// ============================================================================
|
|
2952
|
+
// Loopscale Action Builder
|
|
2953
|
+
// ============================================================================
|
|
2954
|
+
/**
|
|
2955
|
+
* Builder for Loopscale action descriptors used in Exponent sync transactions.
|
|
2956
|
+
*
|
|
2957
|
+
* Loans (BORROWER side): create/close loan, deposit/withdraw collateral, borrow/repay principal.
|
|
2958
|
+
* Strategies (LENDER side): create/close strategy, deposit/withdraw into strategy.
|
|
2959
|
+
*
|
|
2960
|
+
* Since Loopscale instructions come from the Loopscale API (which also
|
|
2961
|
+
* handles `bs_auth` co-signing), you pass pre-built `TransactionInstruction`s
|
|
2962
|
+
* and we wrap them in a sync transaction.
|
|
2963
|
+
*
|
|
2964
|
+
* @example
|
|
2965
|
+
* ```ts
|
|
2966
|
+
* import { loopscaleAction, createVaultSyncTransaction } from "@exponent-labs/exponent-sdk"
|
|
2967
|
+
*
|
|
2968
|
+
* const { instruction } = await createVaultSyncTransaction({
|
|
2969
|
+
* instructions: [
|
|
2970
|
+
* loopscaleAction.createLoan({ instruction: createLoanIx }),
|
|
2971
|
+
* loopscaleAction.depositCollateral({ instruction: depositIx }),
|
|
2972
|
+
* loopscaleAction.borrowPrincipal({ instruction: borrowIx }),
|
|
2973
|
+
* ],
|
|
2974
|
+
* owner: squadsSettings,
|
|
2975
|
+
* connection,
|
|
2976
|
+
* policyPda,
|
|
2977
|
+
* vaultPda: squadsVault,
|
|
2978
|
+
* signer: wallet.publicKey,
|
|
2979
|
+
* vaultAddress,
|
|
2980
|
+
* })
|
|
2981
|
+
* ```
|
|
2982
|
+
*/
|
|
2983
|
+
exports.loopscaleAction = {
|
|
2984
|
+
createLoan(params) {
|
|
2985
|
+
return { action: vault_instruction_types_2.LoopscaleAction.CREATE_LOAN, instruction: params.instruction };
|
|
2986
|
+
},
|
|
2987
|
+
depositCollateral(params) {
|
|
2988
|
+
return { action: vault_instruction_types_2.LoopscaleAction.DEPOSIT_COLLATERAL, instruction: params.instruction };
|
|
2989
|
+
},
|
|
2990
|
+
borrowPrincipal(params) {
|
|
2991
|
+
return { action: vault_instruction_types_2.LoopscaleAction.BORROW_PRINCIPAL, instruction: params.instruction };
|
|
2992
|
+
},
|
|
2993
|
+
repayPrincipal(params) {
|
|
2994
|
+
return { action: vault_instruction_types_2.LoopscaleAction.REPAY_PRINCIPAL, instruction: params.instruction };
|
|
2995
|
+
},
|
|
2996
|
+
withdrawCollateral(params) {
|
|
2997
|
+
return { action: vault_instruction_types_2.LoopscaleAction.WITHDRAW_COLLATERAL, instruction: params.instruction };
|
|
2998
|
+
},
|
|
2999
|
+
closeLoan(params) {
|
|
3000
|
+
return { action: vault_instruction_types_2.LoopscaleAction.CLOSE_LOAN, instruction: params.instruction };
|
|
3001
|
+
},
|
|
3002
|
+
/** Assign collateral fractions to ledgers (BORROWER side). Must call before borrow_principal. */
|
|
3003
|
+
updateWeightMatrix(params) {
|
|
3004
|
+
return { action: vault_instruction_types_2.LoopscaleAction.UPDATE_WEIGHT_MATRIX, instruction: params.instruction };
|
|
3005
|
+
},
|
|
3006
|
+
createStrategy(params) {
|
|
3007
|
+
return { action: vault_instruction_types_2.LoopscaleAction.CREATE_STRATEGY, instruction: params.instruction };
|
|
3008
|
+
},
|
|
3009
|
+
depositStrategy(params) {
|
|
3010
|
+
return { action: vault_instruction_types_2.LoopscaleAction.DEPOSIT_STRATEGY, instruction: params.instruction };
|
|
3011
|
+
},
|
|
3012
|
+
withdrawStrategy(params) {
|
|
3013
|
+
return { action: vault_instruction_types_2.LoopscaleAction.WITHDRAW_STRATEGY, instruction: params.instruction };
|
|
3014
|
+
},
|
|
3015
|
+
closeStrategy(params) {
|
|
3016
|
+
return { action: vault_instruction_types_2.LoopscaleAction.CLOSE_STRATEGY, instruction: params.instruction };
|
|
3017
|
+
},
|
|
3018
|
+
/** Configure collateral terms on a strategy (LENDER side). */
|
|
3019
|
+
updateStrategy(params) {
|
|
3020
|
+
return { action: vault_instruction_types_2.LoopscaleAction.UPDATE_STRATEGY, instruction: params.instruction };
|
|
3021
|
+
},
|
|
3022
|
+
/** Lock loan before borrow_principal (BORROWER side). Must be in same tx as unlock. */
|
|
3023
|
+
lockLoan(params) {
|
|
3024
|
+
return { action: vault_instruction_types_2.LoopscaleAction.LOCK_LOAN, instruction: params.instruction };
|
|
3025
|
+
},
|
|
3026
|
+
/** Unlock loan after borrow_principal (BORROWER side). Runs health check. */
|
|
3027
|
+
unlockLoan(params) {
|
|
3028
|
+
return { action: vault_instruction_types_2.LoopscaleAction.UNLOCK_LOAN, instruction: params.instruction };
|
|
3029
|
+
},
|
|
3030
|
+
/** Refinance a loan ledger from one strategy to another (BORROWER side). */
|
|
3031
|
+
refinanceLedger(params) {
|
|
3032
|
+
return { action: vault_instruction_types_2.LoopscaleAction.REFINANCE_LEDGER, instruction: params.instruction };
|
|
3033
|
+
},
|
|
3034
|
+
};
|
|
3035
|
+
// ============================================================================
|
|
3036
|
+
// CLMM Action Builder
|
|
3037
|
+
// ============================================================================
|
|
3038
|
+
/**
|
|
3039
|
+
* Builder for Exponent CLMM vault action descriptors.
|
|
3040
|
+
*
|
|
3041
|
+
* Each method returns a `VaultInstruction` descriptor. Pass these to
|
|
3042
|
+
* `createVaultSyncTransaction` which resolves them into raw Solana
|
|
3043
|
+
* instructions, wraps them in a Squads sync transaction, and returns
|
|
3044
|
+
* any extra signers (e.g., the new LP position keypair from deposit).
|
|
3045
|
+
*
|
|
3046
|
+
* @example
|
|
3047
|
+
* ```ts
|
|
3048
|
+
* import { clmmAction, createVaultSyncTransaction } from "@exponent-labs/exponent-sdk"
|
|
3049
|
+
*
|
|
3050
|
+
* const result = await createVaultSyncTransaction({
|
|
3051
|
+
* instructions: [
|
|
3052
|
+
* clmmAction.depositLiquidity({
|
|
3053
|
+
* market: CLMM_MARKET,
|
|
3054
|
+
* ptInIntent: 1_000_000n,
|
|
3055
|
+
* syInIntent: 1_000_000n,
|
|
3056
|
+
* lowerTickKey: 500,
|
|
3057
|
+
* upperTickKey: 1500,
|
|
3058
|
+
* }),
|
|
3059
|
+
* ],
|
|
3060
|
+
* owner: squadsVault,
|
|
3061
|
+
* connection,
|
|
3062
|
+
* vaultPda: squadsVault,
|
|
3063
|
+
* signer: wallet.publicKey,
|
|
3064
|
+
* vaultAddress: VAULT_ADDRESS,
|
|
3065
|
+
* })
|
|
3066
|
+
* // result.signers contains the generated LP position keypair
|
|
3067
|
+
* ```
|
|
3068
|
+
*/
|
|
3069
|
+
exports.clmmAction = {
|
|
3070
|
+
/**
|
|
3071
|
+
* Create a new LP position on the CLMM with a specified tick range.
|
|
3072
|
+
* The LP position keypair is generated internally — retrieve it from
|
|
3073
|
+
* `result.signers[0]` after calling `createVaultSyncTransaction`. When
|
|
3074
|
+
* `autoManagePositions` is enabled, the SDK also tracks the new LP
|
|
3075
|
+
* position automatically after the deposit sync instruction succeeds.
|
|
3076
|
+
*
|
|
3077
|
+
* @param params.market - CLMM MarketThree account address
|
|
3078
|
+
* @param params.ptInIntent - Maximum PT to deposit
|
|
3079
|
+
* @param params.syInIntent - Maximum SY to deposit
|
|
3080
|
+
* @param params.lowerTickKey - Lower tick boundary (APY value)
|
|
3081
|
+
* @param params.upperTickKey - Upper tick boundary (APY value)
|
|
3082
|
+
*/
|
|
3083
|
+
depositLiquidity(params) {
|
|
3084
|
+
return { action: vault_instruction_types_2.ClmmAction.DEPOSIT_LIQUIDITY, ...params };
|
|
3085
|
+
},
|
|
3086
|
+
/**
|
|
3087
|
+
* Add liquidity to an existing LP position.
|
|
3088
|
+
*
|
|
3089
|
+
* @param params.market - CLMM MarketThree account address
|
|
3090
|
+
* @param params.lpPosition - Existing LpPosition account public key
|
|
3091
|
+
* @param params.ptInIntent - Maximum PT to add
|
|
3092
|
+
* @param params.syInIntent - Maximum SY to add
|
|
3093
|
+
*/
|
|
3094
|
+
addLiquidity(params) {
|
|
3095
|
+
return { action: vault_instruction_types_2.ClmmAction.ADD_LIQUIDITY, ...params };
|
|
3096
|
+
},
|
|
3097
|
+
/**
|
|
3098
|
+
* Withdraw liquidity from an LP position, receiving PT + SY.
|
|
3099
|
+
*
|
|
3100
|
+
* @param params.market - CLMM MarketThree account address
|
|
3101
|
+
* @param params.lpPosition - LpPosition account to withdraw from
|
|
3102
|
+
* @param params.lpIn - Amount of liquidity (LP units) to remove
|
|
3103
|
+
* @param params.minPtOut - Minimum PT to receive (slippage protection)
|
|
3104
|
+
* @param params.minSyOut - Minimum SY to receive (slippage protection)
|
|
3105
|
+
*/
|
|
3106
|
+
withdrawLiquidity(params) {
|
|
3107
|
+
return { action: vault_instruction_types_2.ClmmAction.WITHDRAW_LIQUIDITY, ...params };
|
|
3108
|
+
},
|
|
3109
|
+
/**
|
|
3110
|
+
* Low-level PT/SY swap on the CLMM. Prefer {@link buyPt} / {@link sellPt}
|
|
3111
|
+
* for directional trades.
|
|
3112
|
+
*
|
|
3113
|
+
* @param params.market - CLMM MarketThree account address
|
|
3114
|
+
* @param params.traderAmount - Amount of the input token
|
|
3115
|
+
* @param params.outConstraint - Minimum output amount (slippage protection)
|
|
3116
|
+
* @param params.swapDirection - `SwapDirection.SyToPt` or `SwapDirection.PtToSy`
|
|
3117
|
+
* @param params.lnImpliedApyLimit - Optional price limit (ln implied APY)
|
|
3118
|
+
*/
|
|
3119
|
+
tradePt(params) {
|
|
3120
|
+
return { action: vault_instruction_types_2.ClmmAction.TRADE_PT, ...params };
|
|
3121
|
+
},
|
|
3122
|
+
/**
|
|
3123
|
+
* Buy PT with SY on the CLMM.
|
|
3124
|
+
*
|
|
3125
|
+
* @param params.market - CLMM MarketThree account address
|
|
3126
|
+
* @param params.amountSy - Amount of SY to spend
|
|
3127
|
+
* @param params.outConstraint - Minimum PT to receive (slippage protection)
|
|
3128
|
+
* @param params.lnImpliedApyLimit - Optional price limit (ln implied APY)
|
|
3129
|
+
*/
|
|
3130
|
+
buyPt(params) {
|
|
3131
|
+
return { action: vault_instruction_types_2.ClmmAction.BUY_PT, ...params };
|
|
3132
|
+
},
|
|
3133
|
+
/**
|
|
3134
|
+
* Sell PT for SY on the CLMM.
|
|
3135
|
+
*
|
|
3136
|
+
* @param params.market - CLMM MarketThree account address
|
|
3137
|
+
* @param params.amountPt - Amount of PT to sell
|
|
3138
|
+
* @param params.outConstraint - Minimum SY to receive (slippage protection)
|
|
3139
|
+
* @param params.lnImpliedApyLimit - Optional price limit (ln implied APY)
|
|
3140
|
+
*/
|
|
3141
|
+
sellPt(params) {
|
|
3142
|
+
return { action: vault_instruction_types_2.ClmmAction.SELL_PT, ...params };
|
|
3143
|
+
},
|
|
3144
|
+
/**
|
|
3145
|
+
* Buy YT with SY on the CLMM.
|
|
3146
|
+
*
|
|
3147
|
+
* @param params.market - CLMM MarketThree account address
|
|
3148
|
+
* @param params.ytOut - Minimum YT to receive
|
|
3149
|
+
* @param params.maxSyIn - Maximum SY to spend
|
|
3150
|
+
* @param params.lnImpliedApyLimit - Optional price limit (ln implied APY)
|
|
3151
|
+
*/
|
|
3152
|
+
buyYt(params) {
|
|
3153
|
+
return { action: vault_instruction_types_2.ClmmAction.BUY_YT, ...params };
|
|
3154
|
+
},
|
|
3155
|
+
/**
|
|
3156
|
+
* Sell YT for SY on the CLMM.
|
|
3157
|
+
*
|
|
3158
|
+
* @param params.market - CLMM MarketThree account address
|
|
3159
|
+
* @param params.ytIn - Amount of YT to sell
|
|
3160
|
+
* @param params.minSyOut - Minimum SY to receive (slippage protection)
|
|
3161
|
+
* @param params.lnImpliedApyLimit - Optional price limit (ln implied APY)
|
|
3162
|
+
*/
|
|
3163
|
+
sellYt(params) {
|
|
3164
|
+
return { action: vault_instruction_types_2.ClmmAction.SELL_YT, ...params };
|
|
3165
|
+
},
|
|
3166
|
+
/**
|
|
3167
|
+
* Claim farm emissions from an LP position.
|
|
3168
|
+
*
|
|
3169
|
+
* @param params.market - CLMM MarketThree account address
|
|
3170
|
+
* @param params.lpPosition - LpPosition account to claim from
|
|
3171
|
+
* @param params.farmIndex - Index of the farm emission to claim
|
|
3172
|
+
*/
|
|
3173
|
+
claimFarmEmission(params) {
|
|
3174
|
+
return { action: vault_instruction_types_2.ClmmAction.CLAIM_FARM_EMISSION, ...params };
|
|
3175
|
+
},
|
|
3176
|
+
};
|
|
3177
|
+
// ============================================================================
|
|
3178
|
+
// Internal: CLMM Instruction Resolution
|
|
3179
|
+
// ============================================================================
|
|
3180
|
+
/** Cache for loaded MarketThree instances to avoid redundant fetches. */
|
|
3181
|
+
const marketThreeCache = new Map();
|
|
3182
|
+
async function ensureTrackedClmmPosition(params) {
|
|
3183
|
+
if (!params.setupContext || !isAutoManagePositionsEnabled(params.setupContext)) {
|
|
3184
|
+
return;
|
|
3185
|
+
}
|
|
3186
|
+
const state = await loadStrategySetupState(params.setupContext);
|
|
3187
|
+
if (!state || state.trackedClmmPositions.has(params.lpPosition.toBase58())) {
|
|
3188
|
+
return;
|
|
3189
|
+
}
|
|
3190
|
+
const existsOnChain = await accountExists(state, params.setupContext.connection, params.lpPosition);
|
|
3191
|
+
if (existsOnChain) {
|
|
3192
|
+
throw new Error(`CLMM lp position ${params.lpPosition.toBase58()} already exists on-chain but is not tracked on vault ${state.strategyVault.selfAddress.toBase58()}. Automatic repair is disabled; manually add the CLMM position entry.`);
|
|
3193
|
+
}
|
|
3194
|
+
throw new Error(`CLMM lp position ${params.lpPosition.toBase58()} is not tracked on vault ${state.strategyVault.selfAddress.toBase58()}. Create it with clmmAction.depositLiquidity() through this SDK flow or manually add the position entry.`);
|
|
3195
|
+
}
|
|
3196
|
+
async function queueClmmPositionTrackingAfterDeposit(params) {
|
|
3197
|
+
if (!params.setupContext || !isAutoManagePositionsEnabled(params.setupContext)) {
|
|
3198
|
+
return;
|
|
3199
|
+
}
|
|
3200
|
+
const state = await loadStrategySetupState(params.setupContext);
|
|
3201
|
+
if (!state || state.trackedClmmPositions.has(params.lpPosition.toBase58())) {
|
|
3202
|
+
return;
|
|
3203
|
+
}
|
|
3204
|
+
const priceIdPt = (0, pricePathResolver_1.resolvePriceIdFromMintToUnderlyingOrThrow)({
|
|
3205
|
+
prices: state.prices,
|
|
3206
|
+
sourceMint: params.market.mintPt,
|
|
3207
|
+
targetMint: state.strategyVault.state.underlyingMint,
|
|
3208
|
+
label: `CLMM PT position setup (${params.market.selfAddress.toBase58()})`,
|
|
3209
|
+
});
|
|
3210
|
+
trackRequiredPriceIds(state.requiredPriceIds, priceIdPt);
|
|
3211
|
+
const priceIdSy = (0, pricePathResolver_1.resolvePriceIdFromMintToUnderlyingOrThrow)({
|
|
3212
|
+
prices: state.prices,
|
|
3213
|
+
sourceMint: params.market.mintSy,
|
|
3214
|
+
targetMint: state.strategyVault.state.underlyingMint,
|
|
3215
|
+
label: `CLMM SY position setup (${params.market.selfAddress.toBase58()})`,
|
|
3216
|
+
});
|
|
3217
|
+
trackRequiredPriceIds(state.requiredPriceIds, priceIdSy);
|
|
3218
|
+
params.postInstructions.push(state.strategyVault.ixWrapperManageVaultSettings({
|
|
3219
|
+
manager: params.setupContext.signer,
|
|
3220
|
+
actions: [exponentVaults.vaultSettingsAction("AddClmmPositionEntry", [{
|
|
3221
|
+
lpPosition: params.lpPosition,
|
|
3222
|
+
market: params.market.selfAddress,
|
|
3223
|
+
priceIdPt,
|
|
3224
|
+
priceIdSy,
|
|
3225
|
+
}])],
|
|
3226
|
+
remainingAccounts: [
|
|
3227
|
+
{ pubkey: params.lpPosition, isSigner: false, isWritable: false },
|
|
3228
|
+
{ pubkey: params.market.selfAddress, isSigner: false, isWritable: false },
|
|
3229
|
+
],
|
|
3230
|
+
}));
|
|
3231
|
+
recordPlannedClmmPosition(state, {
|
|
3232
|
+
lpPosition: params.lpPosition,
|
|
3233
|
+
market: params.market.selfAddress,
|
|
3234
|
+
priceIdPt,
|
|
3235
|
+
priceIdSy,
|
|
3236
|
+
ticksKey: params.market.ticksKey,
|
|
3237
|
+
});
|
|
3238
|
+
}
|
|
3239
|
+
/**
|
|
3240
|
+
* Resolve a high-level CLMM action descriptor into raw Solana instructions.
|
|
3241
|
+
* Loads the MarketThree from cache, derives token accounts from the vault
|
|
3242
|
+
* owner, and delegates to the appropriate sub-builder.
|
|
3243
|
+
*/
|
|
3244
|
+
async function buildClmmInstruction(ix, owner, connection, buckets, setupContext, env = environment_1.LOCAL_ENV) {
|
|
3245
|
+
const cacheKey = ix.market.toBase58();
|
|
3246
|
+
let market = marketThreeCache.get(cacheKey);
|
|
3247
|
+
if (!market) {
|
|
3248
|
+
market = await marketThree_1.MarketThree.load(env, connection, ix.market);
|
|
3249
|
+
marketThreeCache.set(cacheKey, market);
|
|
3250
|
+
}
|
|
3251
|
+
// Ensure PT and SY token accounts are tracked (needed by all CLMM actions)
|
|
3252
|
+
if (setupContext) {
|
|
3253
|
+
await ensureTrackedTokenAccountSetup({
|
|
3254
|
+
tokenMint: market.mintPt,
|
|
3255
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
3256
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3257
|
+
buckets,
|
|
3258
|
+
setupContext,
|
|
3259
|
+
});
|
|
3260
|
+
await ensureTrackedTokenAccountSetup({
|
|
3261
|
+
tokenMint: market.mintSy,
|
|
3262
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
3263
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3264
|
+
buckets,
|
|
3265
|
+
setupContext,
|
|
3266
|
+
});
|
|
3267
|
+
}
|
|
3268
|
+
// Include the CLMM market's ALT so callers can compress remaining accounts
|
|
3269
|
+
buckets.addressLookupTableAddresses.push(market.addressLookupTable);
|
|
3270
|
+
switch (ix.action) {
|
|
3271
|
+
case vault_instruction_types_2.ClmmAction.DEPOSIT_LIQUIDITY:
|
|
3272
|
+
await buildClmmDepositLiquidity(ix, market, owner, buckets, setupContext);
|
|
3273
|
+
break;
|
|
3274
|
+
case vault_instruction_types_2.ClmmAction.ADD_LIQUIDITY:
|
|
3275
|
+
await ensureTrackedClmmPosition({ lpPosition: ix.lpPosition, setupContext });
|
|
3276
|
+
buildClmmAddLiquidity(ix, market, owner, buckets);
|
|
3277
|
+
break;
|
|
3278
|
+
case vault_instruction_types_2.ClmmAction.WITHDRAW_LIQUIDITY:
|
|
3279
|
+
await ensureTrackedClmmPosition({ lpPosition: ix.lpPosition, setupContext });
|
|
3280
|
+
buildClmmWithdrawLiquidity(ix, market, owner, buckets);
|
|
3281
|
+
break;
|
|
3282
|
+
case vault_instruction_types_2.ClmmAction.TRADE_PT:
|
|
3283
|
+
buildClmmTradePt(ix, market, owner, buckets);
|
|
3284
|
+
break;
|
|
3285
|
+
case vault_instruction_types_2.ClmmAction.BUY_PT:
|
|
3286
|
+
buildClmmBuyPt(ix, market, owner, buckets);
|
|
3287
|
+
break;
|
|
3288
|
+
case vault_instruction_types_2.ClmmAction.SELL_PT:
|
|
3289
|
+
buildClmmSellPt(ix, market, owner, buckets);
|
|
3290
|
+
break;
|
|
3291
|
+
case vault_instruction_types_2.ClmmAction.BUY_YT:
|
|
3292
|
+
await buildClmmBuyYt(ix, market, owner, buckets, setupContext);
|
|
3293
|
+
break;
|
|
3294
|
+
case vault_instruction_types_2.ClmmAction.SELL_YT:
|
|
3295
|
+
await buildClmmSellYt(ix, market, owner, buckets, setupContext);
|
|
3296
|
+
break;
|
|
3297
|
+
case vault_instruction_types_2.ClmmAction.CLAIM_FARM_EMISSION:
|
|
3298
|
+
await ensureTrackedClmmPosition({ lpPosition: ix.lpPosition, setupContext });
|
|
3299
|
+
buildClmmClaimFarmEmission(ix, market, owner, buckets);
|
|
3300
|
+
break;
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
/**
|
|
3304
|
+
* Create a new LP position. Generates the keypair internally and adds it
|
|
3305
|
+
* to `buckets.signers` so consumers can include it in the transaction.
|
|
3306
|
+
*/
|
|
3307
|
+
async function buildClmmDepositLiquidity(ix, market, owner, buckets, setupContext) {
|
|
3308
|
+
const ptSrc = (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
3309
|
+
const sySrc = (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
3310
|
+
const { ix: depositIx, signers: lpPositionKeypair } = market.ixDepositLiquidity({
|
|
3311
|
+
depositor: owner,
|
|
3312
|
+
ptInIntent: ix.ptInIntent,
|
|
3313
|
+
syInIntent: ix.syInIntent,
|
|
3314
|
+
lowerTickKey: ix.lowerTickKey,
|
|
3315
|
+
upperTickKey: ix.upperTickKey,
|
|
3316
|
+
ptSrc,
|
|
3317
|
+
sySrc,
|
|
3318
|
+
});
|
|
3319
|
+
buckets.syncInstructions.push(depositIx);
|
|
3320
|
+
buckets.signers.push(lpPositionKeypair);
|
|
3321
|
+
await queueClmmPositionTrackingAfterDeposit({
|
|
3322
|
+
market,
|
|
3323
|
+
lpPosition: lpPositionKeypair.publicKey,
|
|
3324
|
+
postInstructions: buckets.postInstructions,
|
|
3325
|
+
setupContext,
|
|
3326
|
+
});
|
|
3327
|
+
}
|
|
3328
|
+
/** Add liquidity to an existing LP position. */
|
|
3329
|
+
function buildClmmAddLiquidity(ix, market, owner, buckets) {
|
|
3330
|
+
const ptSrc = (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
3331
|
+
const sySrc = (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
3332
|
+
const remainingAccounts = (0, utils_1.uniqueRemainingAccounts)([
|
|
3333
|
+
...market.cpiSyAccounts.depositSy,
|
|
3334
|
+
...market.cpiSyAccounts.withdrawSy,
|
|
3335
|
+
...market.cpiCoreAccounts.stripSy,
|
|
3336
|
+
...market.cpiSyAccounts.getPositionState,
|
|
3337
|
+
]);
|
|
3338
|
+
const addLiqIx = exponentClmm.createAddLiquidityInstruction({
|
|
3339
|
+
owner,
|
|
3340
|
+
market: market.selfAddress,
|
|
3341
|
+
ticks: market.ticksKey,
|
|
3342
|
+
lpPosition: ix.lpPosition,
|
|
3343
|
+
tokenPtSrc: ptSrc,
|
|
3344
|
+
tokenSySrc: sySrc,
|
|
3345
|
+
tokenPtEscrow: market.tokenPtEscrow,
|
|
3346
|
+
tokenSyEscrow: market.tokenSyEscrow,
|
|
3347
|
+
addressLookupTable: market.addressLookupTable,
|
|
3348
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3349
|
+
syProgram: market.syProgram,
|
|
3350
|
+
instructionsSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
3351
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
3352
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
3353
|
+
eventAuthority: market.eventAuthority,
|
|
3354
|
+
program: exponentClmm.EXPONENTCLMM_PROGRAM_ID,
|
|
3355
|
+
}, {
|
|
3356
|
+
maxSyInToAdd: ix.syInIntent,
|
|
3357
|
+
maxPtInToAdd: ix.ptInIntent,
|
|
3358
|
+
lowerTickKeyOptional: null,
|
|
3359
|
+
upperTickKeyOptional: null,
|
|
3360
|
+
});
|
|
3361
|
+
addLiqIx.keys.push(...remainingAccounts);
|
|
3362
|
+
buckets.syncInstructions.push(addLiqIx);
|
|
3363
|
+
}
|
|
3364
|
+
/** Remove liquidity from an LP position. */
|
|
3365
|
+
function buildClmmWithdrawLiquidity(ix, market, owner, buckets) {
|
|
3366
|
+
const { ixs } = market.ixWithdrawLiquidity({
|
|
3367
|
+
withdrawer: owner,
|
|
3368
|
+
lpPosition: ix.lpPosition,
|
|
3369
|
+
lpIn: ix.lpIn,
|
|
3370
|
+
minPtOut: ix.minPtOut,
|
|
3371
|
+
minSyOut: ix.minSyOut,
|
|
3372
|
+
});
|
|
3373
|
+
buckets.syncInstructions.push(...ixs);
|
|
3374
|
+
}
|
|
3375
|
+
/** Low-level PT/SY swap. */
|
|
3376
|
+
function buildClmmTradePt(ix, market, owner, buckets) {
|
|
3377
|
+
const { ixs } = market.ixTradePt({
|
|
3378
|
+
trader: owner,
|
|
3379
|
+
traderAmount: ix.traderAmount,
|
|
3380
|
+
outConstraint: ix.outConstraint,
|
|
3381
|
+
swapDirection: ix.swapDirection,
|
|
3382
|
+
lnImpliedApyLimit: ix.lnImpliedApyLimit,
|
|
3383
|
+
});
|
|
3384
|
+
buckets.syncInstructions.push(...ixs);
|
|
3385
|
+
}
|
|
3386
|
+
/** Buy PT with SY. */
|
|
3387
|
+
function buildClmmBuyPt(ix, market, owner, buckets) {
|
|
3388
|
+
const { ixs } = market.ixBuyPt({
|
|
3389
|
+
trader: owner,
|
|
3390
|
+
amountSy: ix.amountSy,
|
|
3391
|
+
outConstraint: ix.outConstraint,
|
|
3392
|
+
lnImpliedApyLimit: ix.lnImpliedApyLimit,
|
|
3393
|
+
});
|
|
3394
|
+
buckets.syncInstructions.push(...ixs);
|
|
3395
|
+
}
|
|
3396
|
+
/** Sell PT for SY. */
|
|
3397
|
+
function buildClmmSellPt(ix, market, owner, buckets) {
|
|
3398
|
+
const { ixs } = market.ixSellPt({
|
|
3399
|
+
trader: owner,
|
|
3400
|
+
amountPt: ix.amountPt,
|
|
3401
|
+
outConstraint: ix.outConstraint,
|
|
3402
|
+
lnImpliedApyLimit: ix.lnImpliedApyLimit,
|
|
3403
|
+
});
|
|
3404
|
+
buckets.syncInstructions.push(...ixs);
|
|
3405
|
+
}
|
|
3406
|
+
/** Buy YT with SY. Also ensures YT token account is tracked. */
|
|
3407
|
+
async function buildClmmBuyYt(ix, market, owner, buckets, setupContext) {
|
|
3408
|
+
// YT operations need the YT token account tracked
|
|
3409
|
+
if (setupContext) {
|
|
3410
|
+
await ensureTrackedTokenAccountSetup({
|
|
3411
|
+
tokenMint: market.mintYt,
|
|
3412
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
3413
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3414
|
+
buckets,
|
|
3415
|
+
setupContext,
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3418
|
+
const { ixs, setupIxs } = market.ixBuyYt({
|
|
3419
|
+
trader: owner,
|
|
3420
|
+
payer: setupContext?.signer,
|
|
3421
|
+
ytOut: ix.ytOut,
|
|
3422
|
+
maxSyIn: ix.maxSyIn,
|
|
3423
|
+
lnImpliedApyLimit: ix.lnImpliedApyLimit,
|
|
3424
|
+
});
|
|
3425
|
+
buckets.setupInstructions.push(...setupIxs);
|
|
3426
|
+
buckets.syncInstructions.push(...ixs);
|
|
3427
|
+
}
|
|
3428
|
+
/** Sell YT for SY. Also ensures YT token account is tracked. */
|
|
3429
|
+
async function buildClmmSellYt(ix, market, owner, buckets, setupContext) {
|
|
3430
|
+
// YT operations need the YT token account tracked
|
|
3431
|
+
if (setupContext) {
|
|
3432
|
+
await ensureTrackedTokenAccountSetup({
|
|
3433
|
+
tokenMint: market.mintYt,
|
|
3434
|
+
tokenAccount: (0, spl_token_1.getAssociatedTokenAddressSync)(market.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID),
|
|
3435
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3436
|
+
buckets,
|
|
3437
|
+
setupContext,
|
|
3438
|
+
});
|
|
3439
|
+
}
|
|
3440
|
+
const { ixs, setupIxs } = market.ixSellYt({
|
|
3441
|
+
trader: owner,
|
|
3442
|
+
payer: setupContext?.signer,
|
|
3443
|
+
ytIn: ix.ytIn,
|
|
3444
|
+
minSyOut: ix.minSyOut,
|
|
3445
|
+
lnImpliedApyLimit: ix.lnImpliedApyLimit,
|
|
3446
|
+
});
|
|
3447
|
+
buckets.setupInstructions.push(...setupIxs);
|
|
3448
|
+
buckets.syncInstructions.push(...ixs);
|
|
3449
|
+
}
|
|
3450
|
+
/**
|
|
3451
|
+
* Claim farm emissions from an LP position. Reads the farm info from the
|
|
3452
|
+
* loaded market state and builds the instruction directly.
|
|
3453
|
+
*/
|
|
3454
|
+
function buildClmmClaimFarmEmission(ix, market, owner, buckets) {
|
|
3455
|
+
const farm = market.state.lpFarm.farmEmissions[ix.farmIndex];
|
|
3456
|
+
if (!farm) {
|
|
3457
|
+
throw new Error(`Farm at index ${ix.farmIndex} not found on CLMM market ${ix.market.toBase58()}`);
|
|
3458
|
+
}
|
|
3459
|
+
const tokenDst = (0, spl_token_1.getAssociatedTokenAddressSync)(farm.mint, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
3460
|
+
const tokenFarm = (0, spl_token_1.getAssociatedTokenAddressSync)(farm.mint, ix.market, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
3461
|
+
const claimIx = exponentClmm.createClaimFarmEmissionInstruction({
|
|
3462
|
+
owner,
|
|
3463
|
+
market: ix.market,
|
|
3464
|
+
ticks: market.ticksKey,
|
|
3465
|
+
lpPosition: ix.lpPosition,
|
|
3466
|
+
tokenDst,
|
|
3467
|
+
mint: farm.mint,
|
|
3468
|
+
tokenFarm,
|
|
3469
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3470
|
+
eventAuthority: market.eventAuthority,
|
|
3471
|
+
program: exponentClmm.EXPONENTCLMM_PROGRAM_ID,
|
|
3472
|
+
}, {
|
|
3473
|
+
amount: exponentClmm.amount("All"),
|
|
3474
|
+
});
|
|
3475
|
+
// Setup: ensure destination ATA exists
|
|
3476
|
+
buckets.setupInstructions.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenDst, owner, farm.mint));
|
|
3477
|
+
buckets.syncInstructions.push(claimIx);
|
|
3478
|
+
}
|
|
3479
|
+
//# sourceMappingURL=vault-interaction.js.map
|