@sodax/dapp-kit 2.2.0-rc.5 → 2.2.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1087,6 +1087,14 @@ function useUserFormattedSummary({
1087
1087
  ...queryOptions
1088
1088
  });
1089
1089
  }
1090
+ function useEModes({ queryOptions } = {}) {
1091
+ const { sodax } = useSodaxContext();
1092
+ return useQuery({
1093
+ queryKey: ["moneyMarket", "eModes"],
1094
+ queryFn: () => sodax.moneyMarket.data.getEModesHumanized(),
1095
+ ...queryOptions
1096
+ });
1097
+ }
1090
1098
  function feeKeyPart(fee) {
1091
1099
  if (!fee) return void 0;
1092
1100
  return "amount" in fee ? { ...fee, amount: fee.amount.toString() } : fee;
@@ -3848,6 +3856,216 @@ function useLeverageYieldWithdraw({
3848
3856
  mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.withdraw(vars))
3849
3857
  });
3850
3858
  }
3859
+ function useLeveragePositions({
3860
+ params,
3861
+ queryOptions
3862
+ } = {}) {
3863
+ const { sodax } = useSodaxContext();
3864
+ const owner = params?.owner;
3865
+ return useQuery({
3866
+ queryKey: ["leverageYield", "positions", owner],
3867
+ queryFn: async () => {
3868
+ if (!owner) throw new Error("owner is required");
3869
+ const result = await sodax.leverageYield.listPositions(owner);
3870
+ if (!result.ok) throw result.error;
3871
+ return result.value;
3872
+ },
3873
+ enabled: !!owner,
3874
+ ...queryOptions
3875
+ });
3876
+ }
3877
+ function useLeveragePositionAccount({
3878
+ params,
3879
+ queryOptions
3880
+ } = {}) {
3881
+ const { sodax } = useSodaxContext();
3882
+ const position = params?.position;
3883
+ return useQuery({
3884
+ queryKey: ["leverageYield", "positionAccount", position],
3885
+ queryFn: async () => {
3886
+ if (!position) throw new Error("position is required");
3887
+ const result = await sodax.leverageYield.getPositionAccount(position);
3888
+ if (!result.ok) throw result.error;
3889
+ return result.value;
3890
+ },
3891
+ enabled: !!position,
3892
+ refetchInterval: 3e4,
3893
+ ...queryOptions
3894
+ });
3895
+ }
3896
+ function useLeveragePositionCollateral({
3897
+ params,
3898
+ queryOptions
3899
+ } = {}) {
3900
+ const { sodax } = useSodaxContext();
3901
+ const position = params?.position;
3902
+ const collateral = params?.collateral;
3903
+ return useQuery({
3904
+ queryKey: ["leverageYield", "positionCollateral", position, collateral],
3905
+ queryFn: async () => {
3906
+ if (!position) throw new Error("position is required");
3907
+ const result = await sodax.leverageYield.getPositionCollateralBalance(position, collateral);
3908
+ if (!result.ok) throw result.error;
3909
+ return result.value;
3910
+ },
3911
+ enabled: !!position,
3912
+ // Interest accrues into the balance continuously, so match the account snapshot's cadence.
3913
+ refetchInterval: 3e4,
3914
+ ...queryOptions
3915
+ });
3916
+ }
3917
+ function useLeveragePositionInfo({
3918
+ params,
3919
+ queryOptions
3920
+ } = {}) {
3921
+ const { sodax } = useSodaxContext();
3922
+ const position = params?.position;
3923
+ return useQuery({
3924
+ queryKey: ["leverageYield", "positionInfo", position],
3925
+ queryFn: async () => {
3926
+ if (!position) throw new Error("position is required");
3927
+ const result = await sodax.leverageYield.getPositionInfo(position);
3928
+ if (!result.ok) throw result.error;
3929
+ return result.value;
3930
+ },
3931
+ enabled: !!position,
3932
+ ...queryOptions
3933
+ });
3934
+ }
3935
+ function useLeveragePositionPending({
3936
+ params,
3937
+ queryOptions
3938
+ } = {}) {
3939
+ const { sodax } = useSodaxContext();
3940
+ const position = params?.position;
3941
+ return useQuery({
3942
+ queryKey: ["leverageYield", "positionPending", position],
3943
+ queryFn: async () => {
3944
+ if (!position) throw new Error("position is required");
3945
+ const result = await sodax.leverageYield.getPositionPendingState(position);
3946
+ if (!result.ok) throw result.error;
3947
+ return result.value;
3948
+ },
3949
+ enabled: !!position,
3950
+ refetchInterval: 15e3,
3951
+ ...queryOptions
3952
+ });
3953
+ }
3954
+ function useLeveragePositionsForUser({
3955
+ params,
3956
+ queryOptions
3957
+ } = {}) {
3958
+ const { sodax } = useSodaxContext();
3959
+ const spokeChainKey = params?.spokeChainKey;
3960
+ const spokeAddress = params?.spokeAddress;
3961
+ return useQuery({
3962
+ queryKey: ["leverageYield", "positionsForUser", spokeChainKey, spokeAddress],
3963
+ queryFn: async () => {
3964
+ if (!spokeChainKey || !spokeAddress) throw new Error("spokeChainKey and spokeAddress are required");
3965
+ const result = await sodax.leverageYield.listPositionsForUser(spokeChainKey, spokeAddress);
3966
+ if (!result.ok) throw result.error;
3967
+ return result.value;
3968
+ },
3969
+ enabled: !!spokeChainKey && !!spokeAddress,
3970
+ ...queryOptions
3971
+ });
3972
+ }
3973
+ function useOpenLeveragePosition({
3974
+ mutationOptions
3975
+ } = {}) {
3976
+ const { sodax } = useSodaxContext();
3977
+ const queryClient = useQueryClient();
3978
+ return useSafeMutation({
3979
+ mutationKey: ["leverageYield", "openPosition"],
3980
+ ...mutationOptions,
3981
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.openLeveragePosition({ ...vars, raw: false })),
3982
+ onSuccess: async (data, vars, ctx) => {
3983
+ invalidateBalances(queryClient, vars.params.srcChainKey);
3984
+ queryClient.invalidateQueries({ queryKey: ["leverageYield"] });
3985
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
3986
+ }
3987
+ });
3988
+ }
3989
+ function useSubmitLeveragePositionIntent({
3990
+ mutationOptions
3991
+ } = {}) {
3992
+ const { sodax } = useSodaxContext();
3993
+ const queryClient = useQueryClient();
3994
+ return useSafeMutation({
3995
+ mutationKey: ["leverageYield", "submitPositionIntent"],
3996
+ ...mutationOptions,
3997
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.submitLeveragePositionIntent({ ...vars, raw: false })),
3998
+ onSuccess: async (data, vars, ctx) => {
3999
+ queryClient.invalidateQueries({ queryKey: ["leverageYield"] });
4000
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
4001
+ }
4002
+ });
4003
+ }
4004
+ function useRunLeveragePositionOperation({
4005
+ mutationOptions
4006
+ } = {}) {
4007
+ const { sodax } = useSodaxContext();
4008
+ const queryClient = useQueryClient();
4009
+ return useSafeMutation({
4010
+ mutationKey: ["leverageYield", "runPositionOperation"],
4011
+ ...mutationOptions,
4012
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.runLeveragePositionOperation({ ...vars, raw: false })),
4013
+ onSuccess: async (data, vars, ctx) => {
4014
+ invalidateBalances(queryClient, vars.params.srcChainKey);
4015
+ queryClient.invalidateQueries({ queryKey: ["leverageYield"] });
4016
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
4017
+ }
4018
+ });
4019
+ }
4020
+
4021
+ // src/hooks/leverageYield/useLeveragePositionPayoutAddress.ts
4022
+ function useLeveragePositionPayoutAddress({
4023
+ params
4024
+ } = {}) {
4025
+ const { sodax } = useSodaxContext();
4026
+ if (!params) return void 0;
4027
+ return params.chainKey === sodax.hubProvider.chainConfig.chain.key ? params.signerAddress : params.owner;
4028
+ }
4029
+ function useLeveragePositionFundingAllowance({
4030
+ params,
4031
+ queryOptions
4032
+ } = {}) {
4033
+ const { sodax } = useSodaxContext();
4034
+ const { srcChainKey, srcAddress, token, amount } = params ?? {};
4035
+ return useQuery({
4036
+ queryKey: ["leverageYield", "positionFundingAllowance", srcChainKey, srcAddress, token, amount?.toString()],
4037
+ queryFn: async () => {
4038
+ if (!srcChainKey || !srcAddress || !token || !amount) throw new Error("allowance params are incomplete");
4039
+ const result = await sodax.leverageYield.isPositionFundingAllowanceValid({
4040
+ srcChainKey,
4041
+ srcAddress,
4042
+ token,
4043
+ amount
4044
+ });
4045
+ if (!result.ok) throw result.error;
4046
+ return result.value;
4047
+ },
4048
+ enabled: !!srcChainKey && !!srcAddress && !!token && !!amount && amount > 0n,
4049
+ ...queryOptions
4050
+ });
4051
+ }
4052
+ function useApproveLeveragePositionFunding({
4053
+ mutationOptions
4054
+ } = {}) {
4055
+ const { sodax } = useSodaxContext();
4056
+ const queryClient = useQueryClient();
4057
+ return useSafeMutation({
4058
+ mutationKey: ["leverageYield", "approvePositionFunding"],
4059
+ ...mutationOptions,
4060
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.approvePositionFunding(vars)),
4061
+ onSuccess: async (data, vars, ctx) => {
4062
+ queryClient.invalidateQueries({
4063
+ queryKey: ["leverageYield", "positionFundingAllowance", vars.srcChainKey, vars.srcAddress, vars.token]
4064
+ });
4065
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
4066
+ }
4067
+ });
4068
+ }
3851
4069
  var useLeverageYieldApiVaults = ({
3852
4070
  params,
3853
4071
  queryOptions
@@ -4527,4 +4745,4 @@ function createSodaxQueryClient({
4527
4745
  });
4528
4746
  }
4529
4747
 
4530
- export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getBalancesQueryOptions, getLeverageYieldQuoteQueryOptions, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getSwapQuoteQueryOptions, getXBalancesQueryOptions, invalidateBalances, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, retryUnlessAuthFailure, runApprovalPlan, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOracleCandles, useBackendOracleMarkets, useBackendOrderbook, useBackendUserIntents, useBalances, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiApproveAndBroadcast, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDetailedStatus, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldApiAllowance, useLeverageYieldApiApprove, useLeverageYieldApiApproveAndBroadcast, useLeverageYieldApiApr, useLeverageYieldApiAsset, useLeverageYieldApiCancelIntent, useLeverageYieldApiCreateDepositIntent, useLeverageYieldApiCreateWithdrawIntent, useLeverageYieldApiDeadline, useLeverageYieldApiDepositQuote, useLeverageYieldApiEffectiveApr, useLeverageYieldApiEstimateGas, useLeverageYieldApiFilledIntent, useLeverageYieldApiIntent, useLeverageYieldApiIntentExtraData, useLeverageYieldApiIntentHash, useLeverageYieldApiIntentPacket, useLeverageYieldApiLsdApr, useLeverageYieldApiMaxWithdraw, useLeverageYieldApiPartnerFee, useLeverageYieldApiPosition, useLeverageYieldApiPreviewDeposit, useLeverageYieldApiPreviewRedeem, useLeverageYieldApiPreviewWithdraw, useLeverageYieldApiShareBalance, useLeverageYieldApiSolverFee, useLeverageYieldApiStatus, useLeverageYieldApiSubmitIntent, useLeverageYieldApiSubmitTx, useLeverageYieldApiSubmitTxStatus, useLeverageYieldApiTotalAssets, useLeverageYieldApiVault, useLeverageYieldApiVaults, useLeverageYieldApiWithdrawQuote, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldQuote, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
4748
+ export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getBalancesQueryOptions, getLeverageYieldQuoteQueryOptions, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getSwapQuoteQueryOptions, getXBalancesQueryOptions, invalidateBalances, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, retryUnlessAuthFailure, runApprovalPlan, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveLeveragePositionFunding, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOracleCandles, useBackendOracleMarkets, useBackendOrderbook, useBackendUserIntents, useBalances, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiApproveAndBroadcast, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDetailedStatus, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEModes, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeveragePositionAccount, useLeveragePositionCollateral, useLeveragePositionFundingAllowance, useLeveragePositionInfo, useLeveragePositionPayoutAddress, useLeveragePositionPending, useLeveragePositions, useLeveragePositionsForUser, useLeverageYieldApiAllowance, useLeverageYieldApiApprove, useLeverageYieldApiApproveAndBroadcast, useLeverageYieldApiApr, useLeverageYieldApiAsset, useLeverageYieldApiCancelIntent, useLeverageYieldApiCreateDepositIntent, useLeverageYieldApiCreateWithdrawIntent, useLeverageYieldApiDeadline, useLeverageYieldApiDepositQuote, useLeverageYieldApiEffectiveApr, useLeverageYieldApiEstimateGas, useLeverageYieldApiFilledIntent, useLeverageYieldApiIntent, useLeverageYieldApiIntentExtraData, useLeverageYieldApiIntentHash, useLeverageYieldApiIntentPacket, useLeverageYieldApiLsdApr, useLeverageYieldApiMaxWithdraw, useLeverageYieldApiPartnerFee, useLeverageYieldApiPosition, useLeverageYieldApiPreviewDeposit, useLeverageYieldApiPreviewRedeem, useLeverageYieldApiPreviewWithdraw, useLeverageYieldApiShareBalance, useLeverageYieldApiSolverFee, useLeverageYieldApiStatus, useLeverageYieldApiSubmitIntent, useLeverageYieldApiSubmitTx, useLeverageYieldApiSubmitTxStatus, useLeverageYieldApiTotalAssets, useLeverageYieldApiVault, useLeverageYieldApiVaults, useLeverageYieldApiWithdrawQuote, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldQuote, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, useOpenLeveragePosition, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useRunLeveragePositionOperation, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSubmitLeveragePositionIntent, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "access": "public"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "2.2.0-rc.5",
8
+ "version": "2.2.0-rc.6",
9
9
  "description": "React hooks for building dApps on the SODAX cross-chain DeFi platform",
10
10
  "keywords": [
11
11
  "sodax",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "viem": "2.29.2",
37
- "@sodax/sdk": "2.2.0-rc.5"
37
+ "@sodax/sdk": "2.2.0-rc.6"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@arethetypeswrong/cli": "0.17.4",
@@ -26,10 +26,14 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
26
26
  { path: 'dex/useDexDeposit.ts' },
27
27
  { path: 'dex/useDexWithdraw.ts' },
28
28
  { path: 'dex/useSupplyLiquidity.ts' },
29
+ { path: 'leverageYield/useRunLeveragePositionOperation.ts' },
29
30
  { path: 'leverageYield/useLeverageYieldDeposit.ts' },
30
31
  { path: 'leverageYield/useLeverageYieldNotifySolver.ts' },
31
32
  { path: 'leverageYield/useLeverageYieldVaultSwap.ts' },
32
33
  { path: 'leverageYield/useLeverageYieldWithdraw.ts' },
34
+ { path: 'leverageYield/useApproveLeveragePositionFunding.ts' },
35
+ { path: 'leverageYield/useOpenLeveragePosition.ts' },
36
+ { path: 'leverageYield/useSubmitLeveragePositionIntent.ts' },
33
37
  { path: 'leverageYieldApi/useLeverageYieldApiApprove.ts' },
34
38
  { path: 'leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts' },
35
39
  { path: 'leverageYieldApi/useLeverageYieldApiCancelIntent.ts' },
@@ -8,3 +8,15 @@ export * from './useLeverageYieldDeposit.js';
8
8
  export * from './useLeverageYieldNotifySolver.js';
9
9
  export * from './useLeverageYieldVaultSwap.js';
10
10
  export * from './useLeverageYieldWithdraw.js';
11
+ export * from './useLeveragePositions.js';
12
+ export * from './useLeveragePositionAccount.js';
13
+ export * from './useLeveragePositionCollateral.js';
14
+ export * from './useLeveragePositionInfo.js';
15
+ export * from './useLeveragePositionPending.js';
16
+ export * from './useLeveragePositionsForUser.js';
17
+ export * from './useOpenLeveragePosition.js';
18
+ export * from './useSubmitLeveragePositionIntent.js';
19
+ export * from './useRunLeveragePositionOperation.js';
20
+ export * from './useLeveragePositionPayoutAddress.js';
21
+ export * from './useLeveragePositionFundingAllowance.js';
22
+ export * from './useApproveLeveragePositionFunding.js';
@@ -0,0 +1,48 @@
1
+ import { useQueryClient } from '@tanstack/react-query';
2
+ import type { GetWalletProviderType, SpokeChainKey, TxReturnType } from '@sodax/sdk';
3
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
4
+ import type { MutationHookParams } from '../shared/types.js';
5
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
6
+ import { unwrapResult } from '../shared/unwrapResult.js';
7
+
8
+ /** Mutation variables for {@link useApproveLeveragePositionFunding}. */
9
+ export type UseApproveLeveragePositionFundingVars<K extends SpokeChainKey = SpokeChainKey> = {
10
+ srcChainKey: K;
11
+ srcAddress: string;
12
+ /** Funding token, from `resolvePositionFunding` — not the reserve and not the vault. */
13
+ token: string;
14
+ amount: bigint;
15
+ walletProvider?: GetWalletProviderType<K>;
16
+ };
17
+
18
+ /**
19
+ * Approves the funding token for an open, against the spender the SDK resolves.
20
+ *
21
+ * THE SPENDER IS CHAIN-DEPENDENT — the hub wallet on the hub, the spoke asset manager elsewhere.
22
+ * Nothing is ever approved to the position factory: it pulls from nobody.
23
+ *
24
+ * Wait for this before opening, and gate it on {@link useLeveragePositionFundingAllowance}, whose
25
+ * query is invalidated here on success.
26
+ */
27
+ export function useApproveLeveragePositionFunding<K extends SpokeChainKey = SpokeChainKey>({
28
+ mutationOptions,
29
+ }: MutationHookParams<TxReturnType<K, false>, UseApproveLeveragePositionFundingVars<K>> = {}): SafeUseMutationResult<
30
+ TxReturnType<K, false>,
31
+ Error,
32
+ UseApproveLeveragePositionFundingVars<K>
33
+ > {
34
+ const { sodax } = useSodaxContext();
35
+ const queryClient = useQueryClient();
36
+
37
+ return useSafeMutation<TxReturnType<K, false>, Error, UseApproveLeveragePositionFundingVars<K>>({
38
+ mutationKey: ['leverageYield', 'approvePositionFunding'],
39
+ ...mutationOptions,
40
+ mutationFn: async vars => unwrapResult(await sodax.leverageYield.approvePositionFunding(vars)),
41
+ onSuccess: async (data, vars, ctx) => {
42
+ queryClient.invalidateQueries({
43
+ queryKey: ['leverageYield', 'positionFundingAllowance', vars.srcChainKey, vars.srcAddress, vars.token],
44
+ });
45
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
46
+ },
47
+ });
48
+ }
@@ -0,0 +1,45 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address, LeveragePositionAccount } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeveragePositionAccountParams = ReadHookParams<
7
+ LeveragePositionAccount,
8
+ { position: Address | undefined }
9
+ >;
10
+
11
+ /**
12
+ * Reads the live AAVE account snapshot for a leverage position — collateral, debt, LTV and
13
+ * health factor.
14
+ *
15
+ * The figures come from the pool's `getUserAccountData`, not from the position contract,
16
+ * which keeps no accounting of its own. Health factor is WAD (1e18); below 1e18 the position
17
+ * is liquidatable, and there is no keeper deleveraging on the owner's behalf, so this is the
18
+ * number a UI should surface most prominently. Debt accrues continuously, hence the 30s
19
+ * default refresh.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const { data: account } = useLeveragePositionAccount({ params: { position } });
24
+ * ```
25
+ */
26
+ export function useLeveragePositionAccount({
27
+ params,
28
+ queryOptions,
29
+ }: UseLeveragePositionAccountParams = {}): UseQueryResult<LeveragePositionAccount, Error> {
30
+ const { sodax } = useSodaxContext();
31
+ const position = params?.position;
32
+
33
+ return useQuery<LeveragePositionAccount, Error>({
34
+ queryKey: ['leverageYield', 'positionAccount', position],
35
+ queryFn: async () => {
36
+ if (!position) throw new Error('position is required');
37
+ const result = await sodax.leverageYield.getPositionAccount(position);
38
+ if (!result.ok) throw result.error;
39
+ return result.value;
40
+ },
41
+ enabled: !!position,
42
+ refetchInterval: 30_000,
43
+ ...queryOptions,
44
+ });
45
+ }
@@ -0,0 +1,47 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address, LeveragePositionCollateral } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeveragePositionCollateralParams = ReadHookParams<
7
+ LeveragePositionCollateral,
8
+ { position: Address | undefined; collateral?: Address }
9
+ >;
10
+
11
+ /**
12
+ * Reads a leverage position's collateral as an exact aToken balance.
13
+ *
14
+ * Use this, not `useLeveragePositionAccount().totalCollateralBase`, whenever an amount is going into
15
+ * a transaction. The account snapshot is denominated in the oracle's base currency at 8 decimals, so
16
+ * dividing it back out by a price gives an amount near the balance rather than the balance — and a
17
+ * decrease-leverage call for more collateral than the position holds expires as an unfillable intent
18
+ * instead of failing up front.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const { data: collateral } = useLeveragePositionCollateral({ params: { position } });
23
+ * // collateral.balance is what a full exit sells
24
+ * ```
25
+ */
26
+ export function useLeveragePositionCollateral({
27
+ params,
28
+ queryOptions,
29
+ }: UseLeveragePositionCollateralParams = {}): UseQueryResult<LeveragePositionCollateral, Error> {
30
+ const { sodax } = useSodaxContext();
31
+ const position = params?.position;
32
+ const collateral = params?.collateral;
33
+
34
+ return useQuery<LeveragePositionCollateral, Error>({
35
+ queryKey: ['leverageYield', 'positionCollateral', position, collateral],
36
+ queryFn: async () => {
37
+ if (!position) throw new Error('position is required');
38
+ const result = await sodax.leverageYield.getPositionCollateralBalance(position, collateral);
39
+ if (!result.ok) throw result.error;
40
+ return result.value;
41
+ },
42
+ enabled: !!position,
43
+ // Interest accrues into the balance continuously, so match the account snapshot's cadence.
44
+ refetchInterval: 30_000,
45
+ ...queryOptions,
46
+ });
47
+ }
@@ -0,0 +1,51 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import type { SpokeChainKey } from '@sodax/sdk';
3
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ /** Params for {@link useLeveragePositionFundingAllowance}. */
7
+ export type UseLeveragePositionFundingAllowanceParams = ReadHookParams<
8
+ boolean,
9
+ {
10
+ srcChainKey: SpokeChainKey;
11
+ /** The user's address on `srcChainKey`. */
12
+ srcAddress: string | undefined;
13
+ /** Funding token, from `resolvePositionFunding` — not the reserve and not the vault. */
14
+ token: string | undefined;
15
+ amount: bigint | undefined;
16
+ }
17
+ >;
18
+
19
+ /**
20
+ * Whether the funding token is already approved for an open from `srcChainKey`.
21
+ *
22
+ * THE SPENDER IS CHAIN-DEPENDENT — the hub wallet on the hub, the spoke asset manager elsewhere —
23
+ * so a hand-rolled `allowance` call against a guessed spender is right half the time. The SDK
24
+ * resolves it; this only supplies React Query.
25
+ *
26
+ * Returns the SDK's answer as data. A chain with no allowance concept answers `true` without a call.
27
+ */
28
+ export function useLeveragePositionFundingAllowance({
29
+ params,
30
+ queryOptions,
31
+ }: UseLeveragePositionFundingAllowanceParams = {}): UseQueryResult<boolean, Error> {
32
+ const { sodax } = useSodaxContext();
33
+ const { srcChainKey, srcAddress, token, amount } = params ?? {};
34
+
35
+ return useQuery<boolean, Error>({
36
+ queryKey: ['leverageYield', 'positionFundingAllowance', srcChainKey, srcAddress, token, amount?.toString()],
37
+ queryFn: async () => {
38
+ if (!srcChainKey || !srcAddress || !token || !amount) throw new Error('allowance params are incomplete');
39
+ const result = await sodax.leverageYield.isPositionFundingAllowanceValid({
40
+ srcChainKey,
41
+ srcAddress,
42
+ token,
43
+ amount,
44
+ });
45
+ if (!result.ok) throw result.error;
46
+ return result.value;
47
+ },
48
+ enabled: !!srcChainKey && !!srcAddress && !!token && !!amount && amount > 0n,
49
+ ...queryOptions,
50
+ });
51
+ }
@@ -0,0 +1,39 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address, LeveragePosition } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeveragePositionInfoParams = ReadHookParams<LeveragePosition, { position: Address | undefined }>;
7
+
8
+ /**
9
+ * Reads a leverage position's static descriptor — owner, collateral, borrow token, and the
10
+ * eMode category it was created with.
11
+ *
12
+ * All four are fixed at creation, so this never goes stale for a given position and is left
13
+ * on the default cache behaviour rather than polled. Pair it with
14
+ * `useLeveragePositionAccount` for the values that do move.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const { data: info } = useLeveragePositionInfo({ params: { position } });
19
+ * ```
20
+ */
21
+ export function useLeveragePositionInfo({
22
+ params,
23
+ queryOptions,
24
+ }: UseLeveragePositionInfoParams = {}): UseQueryResult<LeveragePosition, Error> {
25
+ const { sodax } = useSodaxContext();
26
+ const position = params?.position;
27
+
28
+ return useQuery<LeveragePosition, Error>({
29
+ queryKey: ['leverageYield', 'positionInfo', position],
30
+ queryFn: async () => {
31
+ if (!position) throw new Error('position is required');
32
+ const result = await sodax.leverageYield.getPositionInfo(position);
33
+ if (!result.ok) throw result.error;
34
+ return result.value;
35
+ },
36
+ enabled: !!position,
37
+ ...queryOptions,
38
+ });
39
+ }
@@ -0,0 +1,36 @@
1
+ import type { Address, SpokeChainKey } from '@sodax/sdk';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+
4
+ /** Params for {@link useLeveragePositionPayoutAddress}. */
5
+ export type UseLeveragePositionPayoutAddressParams = {
6
+ /** The chain the user signs on. */
7
+ chainKey: SpokeChainKey;
8
+ /**
9
+ * Their address on that chain. Supplied by the caller — this package does not depend on a wallet
10
+ * layer, so it cannot read the connected account itself.
11
+ */
12
+ signerAddress: Address | undefined;
13
+ /** The position's owner, from `useGetUserHubWalletAddress`. */
14
+ owner: Address | undefined;
15
+ };
16
+
17
+ /**
18
+ * Where funds leaving a position can actually be paid.
19
+ *
20
+ * `withdraw` is a plain pool withdrawal, so it pays out to an address ON THE HUB. For a hub-chain
21
+ * user that can be their own address; for anyone else it cannot — their signing address belongs to
22
+ * another chain, and for a non-EVM chain it is not an address the hub could pay at all. The hub
23
+ * wallet is the one destination that is always theirs, and bridging onward is a separate operation.
24
+ *
25
+ * Returns `undefined` while either address is still resolving, which is the disabled state for a
26
+ * withdraw button rather than a reason to fall back to the signer.
27
+ */
28
+ export function useLeveragePositionPayoutAddress({
29
+ params,
30
+ }: {
31
+ params?: UseLeveragePositionPayoutAddressParams;
32
+ } = {}): Address | undefined {
33
+ const { sodax } = useSodaxContext();
34
+ if (!params) return undefined;
35
+ return params.chainKey === sodax.hubProvider.chainConfig.chain.key ? params.signerAddress : params.owner;
36
+ }
@@ -0,0 +1,48 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address, LeveragePositionPendingState } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeveragePositionPendingParams = ReadHookParams<
7
+ LeveragePositionPendingState,
8
+ { position: Address | undefined }
9
+ >;
10
+
11
+ /**
12
+ * A position's operation slot: what it recorded, whether that intent is still live, and whether it
13
+ * is stuck resolved-but-unswept.
14
+ *
15
+ * Gate leverage controls on `isLive` — a position permits one intent at a time, so offering a button
16
+ * that can only revert is worse than disabling it. Offer a settle on `needsSettle`: that is the state
17
+ * where the intent is gone but the position still holds the grant and any contribution, and it is
18
+ * invisible from `isLive` alone.
19
+ *
20
+ * Polled, because both change without the user acting: a solver fills, or the intent expires. The
21
+ * interval sits well inside the 5-minute intent deadline so a resolution shows up while it matters.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const { data: slot } = useLeveragePositionPending({ params: { position } });
26
+ * if (slot?.needsSettle) offerSettle();
27
+ * ```
28
+ */
29
+ export function useLeveragePositionPending({
30
+ params,
31
+ queryOptions,
32
+ }: UseLeveragePositionPendingParams = {}): UseQueryResult<LeveragePositionPendingState, Error> {
33
+ const { sodax } = useSodaxContext();
34
+ const position = params?.position;
35
+
36
+ return useQuery<LeveragePositionPendingState, Error>({
37
+ queryKey: ['leverageYield', 'positionPending', position],
38
+ queryFn: async () => {
39
+ if (!position) throw new Error('position is required');
40
+ const result = await sodax.leverageYield.getPositionPendingState(position);
41
+ if (!result.ok) throw result.error;
42
+ return result.value;
43
+ },
44
+ enabled: !!position,
45
+ refetchInterval: 15_000,
46
+ ...queryOptions,
47
+ });
48
+ }
@@ -0,0 +1,41 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeveragePositionsParams = ReadHookParams<readonly Address[], { owner: Address | undefined }>;
7
+
8
+ /**
9
+ * Lists the leverage-position clones owned by `owner`, in creation order.
10
+ *
11
+ * Positions are the unpooled counterpart to leverage-yield vaults: each is its own AAVE
12
+ * account, so one owner can hold several at different eMode categories and leverage tiers.
13
+ * There is no static registry — discovery goes through the factory.
14
+ *
15
+ * Requires `leverageYield.positionFactory` in the `Sodax` config; without it the underlying
16
+ * SDK call fails with a lookup error rather than guessing an address.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const { data: positions } = useLeveragePositions({ params: { owner } });
21
+ * ```
22
+ */
23
+ export function useLeveragePositions({
24
+ params,
25
+ queryOptions,
26
+ }: UseLeveragePositionsParams = {}): UseQueryResult<readonly Address[], Error> {
27
+ const { sodax } = useSodaxContext();
28
+ const owner = params?.owner;
29
+
30
+ return useQuery<readonly Address[], Error>({
31
+ queryKey: ['leverageYield', 'positions', owner],
32
+ queryFn: async () => {
33
+ if (!owner) throw new Error('owner is required');
34
+ const result = await sodax.leverageYield.listPositions(owner);
35
+ if (!result.ok) throw result.error;
36
+ return result.value;
37
+ },
38
+ enabled: !!owner,
39
+ ...queryOptions,
40
+ });
41
+ }