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