@sodax/dapp-kit 2.0.0-rc.16 → 2.0.0-rc.18
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.d.ts +71 -2
- package/dist/index.mjs +102 -1
- package/package.json +2 -2
- package/src/hooks/_mutationContract.test.ts +2 -0
- package/src/hooks/partner/index.ts +4 -0
- package/src/hooks/partner/useFeeClaimWithdraw.ts +88 -0
- package/src/hooks/partner/useGetIntentDetails.ts +39 -0
- package/src/hooks/partner/useGetUserIntent.ts +35 -0
- package/src/hooks/partner/usePartnerCancelIntent.ts +52 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseMutationOptions, UseQueryOptions, UseMutationResult, MutateOptions, UseQueryResult, QueryClientConfig, QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, IStellarWalletProvider, StellarChainKey, INearWalletProvider, GetWalletProviderType, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, RadfiUtxo, MoneyMarketBorrowActionParams, TxHashPair, MoneyMarketRepayActionParams, MoneyMarketSupplyActionParams, MoneyMarketWithdrawActionParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, ReservesDataHumanized, Address as Address$1, MoneyMarketParams, MoneyMarketApproveActionParams, TxReturnType, Erc20Token, ChainKey, ReserveDataHumanized, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteResponse, SolverErrorResponse, SolverIntentQuoteRequest, SwapActionParams, SwapResponse, SolverIntentStatusResponse, Hex, CreateIntentParams, CreateLimitOrderParams, Intent, LimitOrderActionParams, IntentResponse, UserIntentsResponse, SubmitSwapTxResponse, SubmitSwapTxRequest, RequestOverrideConfig, SubmitSwapTxStatusResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, BridgeParams, CreateBridgeIntentParams, BridgeLimit, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, HubAssetBalance, WithdrawHubAssetAction, IcxMigrateAction, IcxRevertMigrationAction, UnifiedBnUSDMigrateAction, BalnMigrateAction, MigrationAction, IcxMigrateParams, IcxCreateRevertMigrationParams, UnifiedBnUSDMigrateParams, BalnMigrateParams, PoolKey, PoolData, ClPositionInfo, AssetDepositAction, AssetWithdrawAction, CreateAssetDepositParams, ClSupplyParams, ClIncreaseLiquidityParams, ClLiquidityDecreaseLiquidityAction, ClDecreaseLiquidityParams, CreateAssetWithdrawParams, PoolSpokeAssets, DestinationParamsType, ClLiquidityClaimRewardsAction, LeverageYieldEffectiveApr, LeverageYieldPosition, LeverageYieldSwapDepositParams, LeverageYieldSwapPayload, SolverExecutionRequest, SolverExecutionResponse, VaultSwapActionParams, VaultSwapResponse, LeverageYieldSwapWithdrawParams, SodaxOptions } from '@sodax/sdk';
|
|
2
|
+
import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, IStellarWalletProvider, StellarChainKey, INearWalletProvider, GetWalletProviderType, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, RadfiUtxo, MoneyMarketBorrowActionParams, TxHashPair, MoneyMarketRepayActionParams, MoneyMarketSupplyActionParams, MoneyMarketWithdrawActionParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, ReservesDataHumanized, Address as Address$1, MoneyMarketParams, MoneyMarketApproveActionParams, TxReturnType, Erc20Token, ChainKey, ReserveDataHumanized, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteResponse, SolverErrorResponse, SolverIntentQuoteRequest, SwapActionParams, SwapResponse, SolverIntentStatusResponse, Hex, CreateIntentParams, CreateLimitOrderParams, Intent, LimitOrderActionParams, IntentResponse, UserIntentsResponse, SubmitSwapTxResponse, SubmitSwapTxRequest, RequestOverrideConfig, SubmitSwapTxStatusResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, BridgeParams, CreateBridgeIntentParams, BridgeLimit, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, PartnerFeeClaimCancelAction, GetUserIntentParams, HubAssetBalance, WithdrawHubAssetAction, IcxMigrateAction, IcxRevertMigrationAction, UnifiedBnUSDMigrateAction, BalnMigrateAction, MigrationAction, IcxMigrateParams, IcxCreateRevertMigrationParams, UnifiedBnUSDMigrateParams, BalnMigrateParams, PoolKey, PoolData, ClPositionInfo, AssetDepositAction, AssetWithdrawAction, CreateAssetDepositParams, ClSupplyParams, ClIncreaseLiquidityParams, ClLiquidityDecreaseLiquidityAction, ClDecreaseLiquidityParams, CreateAssetWithdrawParams, PoolSpokeAssets, DestinationParamsType, ClLiquidityClaimRewardsAction, LeverageYieldEffectiveApr, LeverageYieldPosition, LeverageYieldSwapDepositParams, LeverageYieldSwapPayload, SolverExecutionRequest, SolverExecutionResponse, VaultSwapActionParams, VaultSwapResponse, LeverageYieldSwapWithdrawParams, SodaxOptions } from '@sodax/sdk';
|
|
3
3
|
export * from '@sodax/sdk';
|
|
4
4
|
import { Address } from 'viem';
|
|
5
5
|
import { ReactNode, ReactElement } from 'react';
|
|
@@ -1178,6 +1178,75 @@ type UseFeeClaimSwapVars = Omit<PartnerFeeClaimSwapAction<HubChainKey, false>, '
|
|
|
1178
1178
|
*/
|
|
1179
1179
|
declare function useFeeClaimSwap({ mutationOptions, }?: MutationHookParams<IntentAutoSwapResult, UseFeeClaimSwapVars>): SafeUseMutationResult<IntentAutoSwapResult, Error, UseFeeClaimSwapVars>;
|
|
1180
1180
|
|
|
1181
|
+
type UsePartnerCancelIntentVars = Omit<PartnerFeeClaimCancelAction<HubChainKey, false>, 'raw'>;
|
|
1182
|
+
/**
|
|
1183
|
+
* React hook to cancel a stuck partner fee-claim auto-swap intent and recover the locked tokens.
|
|
1184
|
+
*
|
|
1185
|
+
* Calls `ProtocolIntents.cancelIntent(fromToken, toToken)` — the only authorized cancel path for
|
|
1186
|
+
* partner auto-swap intents (the generic swap-cancel reverts because ProtocolIntents, not the
|
|
1187
|
+
* partner, is the intent creator). The contract cancels the intent and refunds the input amount to
|
|
1188
|
+
* the partner. Use this to recover funds from an unfillable same-token claim.
|
|
1189
|
+
*
|
|
1190
|
+
* Throws on SDK failure so React Query's native error model engages. Returns the transaction hash.
|
|
1191
|
+
*/
|
|
1192
|
+
declare function usePartnerCancelIntent({ mutationOptions, }?: MutationHookParams<TxReturnType<HubChainKey, false>, UsePartnerCancelIntentVars>): SafeUseMutationResult<TxReturnType<HubChainKey, false>, Error, UsePartnerCancelIntentVars>;
|
|
1193
|
+
|
|
1194
|
+
type UseGetUserIntentParams = ReadHookParams<Hex, Partial<GetUserIntentParams>>;
|
|
1195
|
+
/**
|
|
1196
|
+
* React hook to look up the stored intent hash for a partner's `(user, fromToken, toToken)` pair.
|
|
1197
|
+
*
|
|
1198
|
+
* A non-zero hash means an open auto-swap intent exists for that token pair (e.g. an unfilled
|
|
1199
|
+
* same-token claim) and can be recovered via {@link usePartnerCancelIntent}. Disabled until all
|
|
1200
|
+
* three inputs are present. Throws on `!ok`.
|
|
1201
|
+
*/
|
|
1202
|
+
declare function useGetUserIntent({ params, queryOptions }?: UseGetUserIntentParams): UseQueryResult<Hex, Error>;
|
|
1203
|
+
|
|
1204
|
+
type UseGetIntentDetailsParams = ReadHookParams<Intent, {
|
|
1205
|
+
intentHash: Hex | undefined;
|
|
1206
|
+
}>;
|
|
1207
|
+
/**
|
|
1208
|
+
* React hook to fetch the full {@link Intent} details for a ProtocolIntents intent hash.
|
|
1209
|
+
*
|
|
1210
|
+
* Pair with {@link useGetUserIntent} to display a stuck intent (e.g. its locked `inputAmount`)
|
|
1211
|
+
* before recovering it. Disabled when the hash is missing or the zero hash (no intent). Throws
|
|
1212
|
+
* on `!ok`.
|
|
1213
|
+
*/
|
|
1214
|
+
declare function useGetIntentDetails({ params, queryOptions, }?: UseGetIntentDetailsParams): UseQueryResult<Intent, Error>;
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* Mutation variables for {@link useFeeClaimWithdraw}. Maps a partner fee balance to a
|
|
1218
|
+
* Sonic-sourced bridge: `feeToken` is the wrapped hub-asset address on Sonic
|
|
1219
|
+
* (`PartnerFeeClaimAssetBalance.address`); `dstToken` is the original token address on
|
|
1220
|
+
* `dstChainKey` (`PartnerFeeClaimAssetBalance.originalAddress`, or `feeToken` for same-chain
|
|
1221
|
+
* delivery to a Sonic address).
|
|
1222
|
+
*/
|
|
1223
|
+
type UseFeeClaimWithdrawVars = {
|
|
1224
|
+
params: {
|
|
1225
|
+
srcAddress: string;
|
|
1226
|
+
feeToken: Address$1;
|
|
1227
|
+
amount: bigint;
|
|
1228
|
+
dstChainKey: SpokeChainKey;
|
|
1229
|
+
dstToken: string;
|
|
1230
|
+
recipient: string;
|
|
1231
|
+
};
|
|
1232
|
+
walletProvider: GetWalletProviderType<HubChainKey>;
|
|
1233
|
+
};
|
|
1234
|
+
/**
|
|
1235
|
+
* React hook to withdraw a partner fee token directly to the partner's wallet **without a swap**.
|
|
1236
|
+
*
|
|
1237
|
+
* For fees the partner wants to keep as-is (the desired output equals the fee token, e.g. BTC→BTC),
|
|
1238
|
+
* an auto-swap is impossible — the solver rejects a same-token swap. This bridges the wrapped fee
|
|
1239
|
+
* token from Sonic to its native chain (or transfers it on Sonic when `dstChainKey` is Sonic),
|
|
1240
|
+
* bypassing the solver entirely.
|
|
1241
|
+
*
|
|
1242
|
+
* Bridging from Sonic pulls the token via the partner's hub-wallet router, which requires a prior
|
|
1243
|
+
* allowance to that spender — a different approval than the ProtocolIntents one used by the swap
|
|
1244
|
+
* claim. Use `useBridgeAllowance` / `useBridgeApprove` (with the same mapped bridge params) first.
|
|
1245
|
+
*
|
|
1246
|
+
* Throws on SDK failure so React Query's native error model engages. Returns the `TxHashPair`.
|
|
1247
|
+
*/
|
|
1248
|
+
declare function useFeeClaimWithdraw({ mutationOptions, }?: MutationHookParams<TxHashPair, UseFeeClaimWithdrawVars>): SafeUseMutationResult<TxHashPair, Error, UseFeeClaimWithdrawVars>;
|
|
1249
|
+
|
|
1181
1250
|
type UseHubAssetBalancesParams = ReadHookParams<HubAssetBalance[], {
|
|
1182
1251
|
chainKey: SpokeChainKey | undefined;
|
|
1183
1252
|
/** The user's address on the spoke chain. The SDK derives the hub wallet abstraction internally. */
|
|
@@ -1848,4 +1917,4 @@ interface NearStorageGateState {
|
|
|
1848
1917
|
*/
|
|
1849
1918
|
declare function resolveNearStorageGate(chainKey: SpokeChainKey, check: NearStorageCheckResult): NearStorageGateState;
|
|
1850
1919
|
|
|
1851
|
-
export { type ATokenData, type BackendPaginationParams, type CreateSodaxQueryClientOptions, type DecreaseLiquidityParamsCore, type DepositParamsCore, type LeverageYieldShareHolder, type LeverageYieldShareHolding, type MutationHookOptions, type MutationHookParams, type NearStorageCheckResult, type NearStorageGateState, type RadfiSession, type ReadHookParams, type ReadQueryOptions, type ReserveUsdFormat, type SafeUseMutationResult, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApproveVars, type UseBridgeVars, type UseClaimRewardsVars, type UseCreateDecreaseLiquidityParamsProps, type UseCreateDepositParamsProps, type UseCreateLimitOrderVars, type UseCreateSupplyLiquidityParamsProps, type UseCreateSupplyLiquidityParamsResult, type UseCreateWithdrawParamsProps, type UseDecreaseLiquidityVars, type UseDeriveUserWalletAddressParams, type UseDexAllowanceParams, type UseDexApproveVars, type UseDexDepositVars, type UseDexWithdrawVars, type UseEnsureRadfiAccessTokenVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetUserHubWalletAddressParams, type UseHubAssetBalancesParams, type UseIsTokenApprovedParams, type UseLeverageYieldDepositVars, type UseLeverageYieldEffectiveAprParams, type UseLeverageYieldNotifySolverVars, type UseLeverageYieldPositionParams, type UseLeverageYieldPreviewRedeemParams, type UseLeverageYieldShareBalancesParams, type UseLeverageYieldTotalAssetsParams, type UseLeverageYieldVaultSwapVars, type UseLeverageYieldWithdrawVars, type UseLiquidityAmountsResult, type UseMMAllowanceParams, type UseMMApproveVars, type UseMigrateBalnVars, type UseMigrateIcxToSodaVars, type UseMigratebnUSDVars, type UseMigrationAllowanceInputs, type UseMigrationAllowanceParams, type UseMigrationApproveVars, type UseNearStorageCheckParams, type UsePoolBalancesParams, type UsePoolBalancesResponse, type UsePoolDataParams, type UsePoolsParams, type UsePositionInfoParams, type UsePositionInfoResponse, type UseQuoteParams, type UseRadfiAuthVars, type UseRadfiSessionReturn, type UseRadfiWithdrawVars, type UseRegisterNearStorageVars, type UseRenewUtxosVars, type UseRepayVars, type UseReservesDataParams, type UseReservesHumanizedParams, type UseReservesListParams, type UseReservesUsdFormatParams, type UseRevertMigrateSodaToIcxVars, type UseSetSwapPreferenceVars, type UseSetSwapPreferenceVarsHub, type UseStatusParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
|
1920
|
+
export { type ATokenData, type BackendPaginationParams, type CreateSodaxQueryClientOptions, type DecreaseLiquidityParamsCore, type DepositParamsCore, type LeverageYieldShareHolder, type LeverageYieldShareHolding, type MutationHookOptions, type MutationHookParams, type NearStorageCheckResult, type NearStorageGateState, type RadfiSession, type ReadHookParams, type ReadQueryOptions, type ReserveUsdFormat, type SafeUseMutationResult, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApproveVars, type UseBridgeVars, type UseClaimRewardsVars, type UseCreateDecreaseLiquidityParamsProps, type UseCreateDepositParamsProps, type UseCreateLimitOrderVars, type UseCreateSupplyLiquidityParamsProps, type UseCreateSupplyLiquidityParamsResult, type UseCreateWithdrawParamsProps, type UseDecreaseLiquidityVars, type UseDeriveUserWalletAddressParams, type UseDexAllowanceParams, type UseDexApproveVars, type UseDexDepositVars, type UseDexWithdrawVars, type UseEnsureRadfiAccessTokenVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFeeClaimWithdrawVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetIntentDetailsParams, type UseGetUserHubWalletAddressParams, type UseGetUserIntentParams, type UseHubAssetBalancesParams, type UseIsTokenApprovedParams, type UseLeverageYieldDepositVars, type UseLeverageYieldEffectiveAprParams, type UseLeverageYieldNotifySolverVars, type UseLeverageYieldPositionParams, type UseLeverageYieldPreviewRedeemParams, type UseLeverageYieldShareBalancesParams, type UseLeverageYieldTotalAssetsParams, type UseLeverageYieldVaultSwapVars, type UseLeverageYieldWithdrawVars, type UseLiquidityAmountsResult, type UseMMAllowanceParams, type UseMMApproveVars, type UseMigrateBalnVars, type UseMigrateIcxToSodaVars, type UseMigratebnUSDVars, type UseMigrationAllowanceInputs, type UseMigrationAllowanceParams, type UseMigrationApproveVars, type UseNearStorageCheckParams, type UsePartnerCancelIntentVars, type UsePoolBalancesParams, type UsePoolBalancesResponse, type UsePoolDataParams, type UsePoolsParams, type UsePositionInfoParams, type UsePositionInfoResponse, type UseQuoteParams, type UseRadfiAuthVars, type UseRadfiSessionReturn, type UseRadfiWithdrawVars, type UseRegisterNearStorageVars, type UseRenewUtxosVars, type UseRepayVars, type UseReservesDataParams, type UseReservesHumanizedParams, type UseReservesListParams, type UseReservesUsdFormatParams, type UseRevertMigrateSodaToIcxVars, type UseSetSwapPreferenceVars, type UseSetSwapPreferenceVarsHub, type UseStatusParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, 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, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
package/dist/index.mjs
CHANGED
|
@@ -1883,6 +1883,107 @@ function useFeeClaimSwap({
|
|
|
1883
1883
|
}
|
|
1884
1884
|
});
|
|
1885
1885
|
}
|
|
1886
|
+
function usePartnerCancelIntent({
|
|
1887
|
+
mutationOptions
|
|
1888
|
+
} = {}) {
|
|
1889
|
+
const { sodax } = useSodaxContext();
|
|
1890
|
+
const queryClient = useQueryClient();
|
|
1891
|
+
return useSafeMutation({
|
|
1892
|
+
mutationKey: ["partner", "cancelIntent"],
|
|
1893
|
+
...mutationOptions,
|
|
1894
|
+
mutationFn: async (vars) => unwrapResult(await sodax.partners.feeClaim.cancelIntent({ ...vars, raw: false })),
|
|
1895
|
+
onSuccess: async (data, vars, ctx) => {
|
|
1896
|
+
queryClient.invalidateQueries({
|
|
1897
|
+
queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
|
|
1898
|
+
});
|
|
1899
|
+
queryClient.invalidateQueries({
|
|
1900
|
+
queryKey: [
|
|
1901
|
+
"partner",
|
|
1902
|
+
"feeClaim",
|
|
1903
|
+
"userIntent",
|
|
1904
|
+
vars.params.srcAddress,
|
|
1905
|
+
vars.params.fromToken,
|
|
1906
|
+
vars.params.toToken
|
|
1907
|
+
]
|
|
1908
|
+
});
|
|
1909
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
function useGetUserIntent({ params, queryOptions } = {}) {
|
|
1914
|
+
const { sodax } = useSodaxContext();
|
|
1915
|
+
const user = params?.user;
|
|
1916
|
+
const fromToken = params?.fromToken;
|
|
1917
|
+
const toToken = params?.toToken;
|
|
1918
|
+
return useQuery({
|
|
1919
|
+
queryKey: ["partner", "feeClaim", "userIntent", user, fromToken, toToken],
|
|
1920
|
+
queryFn: async () => {
|
|
1921
|
+
if (!user || !fromToken || !toToken) {
|
|
1922
|
+
throw new Error("user, fromToken and toToken are required");
|
|
1923
|
+
}
|
|
1924
|
+
const result = await sodax.partners.feeClaim.getUserIntent({ user, fromToken, toToken });
|
|
1925
|
+
if (!result.ok) throw result.error;
|
|
1926
|
+
return result.value;
|
|
1927
|
+
},
|
|
1928
|
+
enabled: !!user && !!fromToken && !!toToken,
|
|
1929
|
+
...queryOptions
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
var ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
1933
|
+
function useGetIntentDetails({
|
|
1934
|
+
params,
|
|
1935
|
+
queryOptions
|
|
1936
|
+
} = {}) {
|
|
1937
|
+
const { sodax } = useSodaxContext();
|
|
1938
|
+
const intentHash = params?.intentHash;
|
|
1939
|
+
const hasIntent = !!intentHash && intentHash !== ZERO_HASH;
|
|
1940
|
+
return useQuery({
|
|
1941
|
+
queryKey: ["partner", "feeClaim", "intentDetails", intentHash],
|
|
1942
|
+
queryFn: async () => {
|
|
1943
|
+
if (!intentHash) {
|
|
1944
|
+
throw new Error("intentHash is required");
|
|
1945
|
+
}
|
|
1946
|
+
const result = await sodax.partners.feeClaim.getIntentDetails(intentHash);
|
|
1947
|
+
if (!result.ok) throw result.error;
|
|
1948
|
+
return result.value;
|
|
1949
|
+
},
|
|
1950
|
+
enabled: hasIntent,
|
|
1951
|
+
...queryOptions
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
function useFeeClaimWithdraw({
|
|
1955
|
+
mutationOptions
|
|
1956
|
+
} = {}) {
|
|
1957
|
+
const { sodax } = useSodaxContext();
|
|
1958
|
+
const queryClient = useQueryClient();
|
|
1959
|
+
return useSafeMutation({
|
|
1960
|
+
mutationKey: ["partner", "feeClaimWithdraw"],
|
|
1961
|
+
...mutationOptions,
|
|
1962
|
+
mutationFn: async ({ params, walletProvider }) => {
|
|
1963
|
+
const bridgeParams = {
|
|
1964
|
+
params: {
|
|
1965
|
+
srcChainKey: ChainKeys.SONIC_MAINNET,
|
|
1966
|
+
srcAddress: params.srcAddress,
|
|
1967
|
+
srcToken: params.feeToken,
|
|
1968
|
+
amount: params.amount,
|
|
1969
|
+
dstChainKey: params.dstChainKey,
|
|
1970
|
+
dstToken: params.dstToken,
|
|
1971
|
+
recipient: params.recipient
|
|
1972
|
+
},
|
|
1973
|
+
raw: false,
|
|
1974
|
+
walletProvider
|
|
1975
|
+
};
|
|
1976
|
+
return unwrapResult(await sodax.bridge.bridge(bridgeParams));
|
|
1977
|
+
},
|
|
1978
|
+
onSuccess: async (data, vars, ctx) => {
|
|
1979
|
+
queryClient.invalidateQueries({
|
|
1980
|
+
queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
|
|
1981
|
+
});
|
|
1982
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
|
|
1983
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1984
|
+
}
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1886
1987
|
function useHubAssetBalances({
|
|
1887
1988
|
params,
|
|
1888
1989
|
queryOptions
|
|
@@ -2784,4 +2885,4 @@ function createSodaxQueryClient({
|
|
|
2784
2885
|
});
|
|
2785
2886
|
}
|
|
2786
2887
|
|
|
2787
|
-
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
|
2888
|
+
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, 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, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, 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.0.0-rc.
|
|
8
|
+
"version": "2.0.0-rc.18",
|
|
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.0.0-rc.
|
|
37
|
+
"@sodax/sdk": "2.0.0-rc.18"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@arethetypeswrong/cli": "0.17.4",
|
|
@@ -43,6 +43,8 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
|
|
|
43
43
|
{ path: 'mm/useWithdraw.ts' },
|
|
44
44
|
{ path: 'partner/useApproveToken.ts' },
|
|
45
45
|
{ path: 'partner/useFeeClaimSwap.ts' },
|
|
46
|
+
{ path: 'partner/useFeeClaimWithdraw.ts' },
|
|
47
|
+
{ path: 'partner/usePartnerCancelIntent.ts' },
|
|
46
48
|
{ path: 'partner/useSetSwapPreference.ts' },
|
|
47
49
|
{ path: 'recovery/useWithdrawHubAsset.ts' },
|
|
48
50
|
{ path: 'shared/useEstimateGas.ts' },
|
|
@@ -4,3 +4,7 @@ export * from './useIsTokenApproved.js';
|
|
|
4
4
|
export * from './useApproveToken.js';
|
|
5
5
|
export * from './useSetSwapPreference.js';
|
|
6
6
|
export * from './useFeeClaimSwap.js';
|
|
7
|
+
export * from './usePartnerCancelIntent.js';
|
|
8
|
+
export * from './useGetUserIntent.js';
|
|
9
|
+
export * from './useGetIntentDetails.js';
|
|
10
|
+
export * from './useFeeClaimWithdraw.js';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/partner/useFeeClaimWithdraw.ts
|
|
2
|
+
import {
|
|
3
|
+
ChainKeys,
|
|
4
|
+
type Address,
|
|
5
|
+
type BridgeParams,
|
|
6
|
+
type GetWalletProviderType,
|
|
7
|
+
type HubChainKey,
|
|
8
|
+
type SpokeChainKey,
|
|
9
|
+
type TxHashPair,
|
|
10
|
+
} from '@sodax/sdk';
|
|
11
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
12
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
13
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
14
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
15
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Mutation variables for {@link useFeeClaimWithdraw}. Maps a partner fee balance to a
|
|
19
|
+
* Sonic-sourced bridge: `feeToken` is the wrapped hub-asset address on Sonic
|
|
20
|
+
* (`PartnerFeeClaimAssetBalance.address`); `dstToken` is the original token address on
|
|
21
|
+
* `dstChainKey` (`PartnerFeeClaimAssetBalance.originalAddress`, or `feeToken` for same-chain
|
|
22
|
+
* delivery to a Sonic address).
|
|
23
|
+
*/
|
|
24
|
+
export type UseFeeClaimWithdrawVars = {
|
|
25
|
+
params: {
|
|
26
|
+
srcAddress: string;
|
|
27
|
+
feeToken: Address;
|
|
28
|
+
amount: bigint;
|
|
29
|
+
dstChainKey: SpokeChainKey;
|
|
30
|
+
dstToken: string;
|
|
31
|
+
recipient: string;
|
|
32
|
+
};
|
|
33
|
+
walletProvider: GetWalletProviderType<HubChainKey>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* React hook to withdraw a partner fee token directly to the partner's wallet **without a swap**.
|
|
38
|
+
*
|
|
39
|
+
* For fees the partner wants to keep as-is (the desired output equals the fee token, e.g. BTC→BTC),
|
|
40
|
+
* an auto-swap is impossible — the solver rejects a same-token swap. This bridges the wrapped fee
|
|
41
|
+
* token from Sonic to its native chain (or transfers it on Sonic when `dstChainKey` is Sonic),
|
|
42
|
+
* bypassing the solver entirely.
|
|
43
|
+
*
|
|
44
|
+
* Bridging from Sonic pulls the token via the partner's hub-wallet router, which requires a prior
|
|
45
|
+
* allowance to that spender — a different approval than the ProtocolIntents one used by the swap
|
|
46
|
+
* claim. Use `useBridgeAllowance` / `useBridgeApprove` (with the same mapped bridge params) first.
|
|
47
|
+
*
|
|
48
|
+
* Throws on SDK failure so React Query's native error model engages. Returns the `TxHashPair`.
|
|
49
|
+
*/
|
|
50
|
+
export function useFeeClaimWithdraw({
|
|
51
|
+
mutationOptions,
|
|
52
|
+
}: MutationHookParams<TxHashPair, UseFeeClaimWithdrawVars> = {}): SafeUseMutationResult<
|
|
53
|
+
TxHashPair,
|
|
54
|
+
Error,
|
|
55
|
+
UseFeeClaimWithdrawVars
|
|
56
|
+
> {
|
|
57
|
+
const { sodax } = useSodaxContext();
|
|
58
|
+
const queryClient = useQueryClient();
|
|
59
|
+
|
|
60
|
+
return useSafeMutation<TxHashPair, Error, UseFeeClaimWithdrawVars>({
|
|
61
|
+
mutationKey: ['partner', 'feeClaimWithdraw'],
|
|
62
|
+
...mutationOptions,
|
|
63
|
+
mutationFn: async ({ params, walletProvider }) => {
|
|
64
|
+
const bridgeParams = {
|
|
65
|
+
params: {
|
|
66
|
+
srcChainKey: ChainKeys.SONIC_MAINNET,
|
|
67
|
+
srcAddress: params.srcAddress,
|
|
68
|
+
srcToken: params.feeToken,
|
|
69
|
+
amount: params.amount,
|
|
70
|
+
dstChainKey: params.dstChainKey,
|
|
71
|
+
dstToken: params.dstToken,
|
|
72
|
+
recipient: params.recipient,
|
|
73
|
+
},
|
|
74
|
+
raw: false,
|
|
75
|
+
walletProvider,
|
|
76
|
+
} satisfies BridgeParams<HubChainKey, false>;
|
|
77
|
+
|
|
78
|
+
return unwrapResult(await sodax.bridge.bridge(bridgeParams));
|
|
79
|
+
},
|
|
80
|
+
onSuccess: async (data, vars, ctx) => {
|
|
81
|
+
queryClient.invalidateQueries({
|
|
82
|
+
queryKey: ['partner', 'feeClaim', 'assetsBalances', vars.params.srcAddress],
|
|
83
|
+
});
|
|
84
|
+
queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', vars.params.dstChainKey] });
|
|
85
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/partner/useGetIntentDetails.ts
|
|
2
|
+
import type { Hex, Intent } from '@sodax/sdk';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
const ZERO_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
8
|
+
|
|
9
|
+
export type UseGetIntentDetailsParams = ReadHookParams<Intent, { intentHash: Hex | undefined }>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React hook to fetch the full {@link Intent} details for a ProtocolIntents intent hash.
|
|
13
|
+
*
|
|
14
|
+
* Pair with {@link useGetUserIntent} to display a stuck intent (e.g. its locked `inputAmount`)
|
|
15
|
+
* before recovering it. Disabled when the hash is missing or the zero hash (no intent). Throws
|
|
16
|
+
* on `!ok`.
|
|
17
|
+
*/
|
|
18
|
+
export function useGetIntentDetails({
|
|
19
|
+
params,
|
|
20
|
+
queryOptions,
|
|
21
|
+
}: UseGetIntentDetailsParams = {}): UseQueryResult<Intent, Error> {
|
|
22
|
+
const { sodax } = useSodaxContext();
|
|
23
|
+
const intentHash = params?.intentHash;
|
|
24
|
+
const hasIntent = !!intentHash && intentHash !== ZERO_HASH;
|
|
25
|
+
|
|
26
|
+
return useQuery<Intent, Error>({
|
|
27
|
+
queryKey: ['partner', 'feeClaim', 'intentDetails', intentHash],
|
|
28
|
+
queryFn: async () => {
|
|
29
|
+
if (!intentHash) {
|
|
30
|
+
throw new Error('intentHash is required');
|
|
31
|
+
}
|
|
32
|
+
const result = await sodax.partners.feeClaim.getIntentDetails(intentHash);
|
|
33
|
+
if (!result.ok) throw result.error;
|
|
34
|
+
return result.value;
|
|
35
|
+
},
|
|
36
|
+
enabled: hasIntent,
|
|
37
|
+
...queryOptions,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/partner/useGetUserIntent.ts
|
|
2
|
+
import type { GetUserIntentParams, Hex } from '@sodax/sdk';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseGetUserIntentParams = ReadHookParams<Hex, Partial<GetUserIntentParams>>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* React hook to look up the stored intent hash for a partner's `(user, fromToken, toToken)` pair.
|
|
11
|
+
*
|
|
12
|
+
* A non-zero hash means an open auto-swap intent exists for that token pair (e.g. an unfilled
|
|
13
|
+
* same-token claim) and can be recovered via {@link usePartnerCancelIntent}. Disabled until all
|
|
14
|
+
* three inputs are present. Throws on `!ok`.
|
|
15
|
+
*/
|
|
16
|
+
export function useGetUserIntent({ params, queryOptions }: UseGetUserIntentParams = {}): UseQueryResult<Hex, Error> {
|
|
17
|
+
const { sodax } = useSodaxContext();
|
|
18
|
+
const user = params?.user;
|
|
19
|
+
const fromToken = params?.fromToken;
|
|
20
|
+
const toToken = params?.toToken;
|
|
21
|
+
|
|
22
|
+
return useQuery<Hex, Error>({
|
|
23
|
+
queryKey: ['partner', 'feeClaim', 'userIntent', user, fromToken, toToken],
|
|
24
|
+
queryFn: async () => {
|
|
25
|
+
if (!user || !fromToken || !toToken) {
|
|
26
|
+
throw new Error('user, fromToken and toToken are required');
|
|
27
|
+
}
|
|
28
|
+
const result = await sodax.partners.feeClaim.getUserIntent({ user, fromToken, toToken });
|
|
29
|
+
if (!result.ok) throw result.error;
|
|
30
|
+
return result.value;
|
|
31
|
+
},
|
|
32
|
+
enabled: !!user && !!fromToken && !!toToken,
|
|
33
|
+
...queryOptions,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// packages/dapp-kit/src/hooks/partner/usePartnerCancelIntent.ts
|
|
2
|
+
import type { HubChainKey, PartnerFeeClaimCancelAction, TxReturnType } from '@sodax/sdk';
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
5
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
6
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
|
+
|
|
9
|
+
export type UsePartnerCancelIntentVars = Omit<PartnerFeeClaimCancelAction<HubChainKey, false>, 'raw'>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* React hook to cancel a stuck partner fee-claim auto-swap intent and recover the locked tokens.
|
|
13
|
+
*
|
|
14
|
+
* Calls `ProtocolIntents.cancelIntent(fromToken, toToken)` — the only authorized cancel path for
|
|
15
|
+
* partner auto-swap intents (the generic swap-cancel reverts because ProtocolIntents, not the
|
|
16
|
+
* partner, is the intent creator). The contract cancels the intent and refunds the input amount to
|
|
17
|
+
* the partner. Use this to recover funds from an unfillable same-token claim.
|
|
18
|
+
*
|
|
19
|
+
* Throws on SDK failure so React Query's native error model engages. Returns the transaction hash.
|
|
20
|
+
*/
|
|
21
|
+
export function usePartnerCancelIntent({
|
|
22
|
+
mutationOptions,
|
|
23
|
+
}: MutationHookParams<TxReturnType<HubChainKey, false>, UsePartnerCancelIntentVars> = {}): SafeUseMutationResult<
|
|
24
|
+
TxReturnType<HubChainKey, false>,
|
|
25
|
+
Error,
|
|
26
|
+
UsePartnerCancelIntentVars
|
|
27
|
+
> {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const queryClient = useQueryClient();
|
|
30
|
+
|
|
31
|
+
return useSafeMutation<TxReturnType<HubChainKey, false>, Error, UsePartnerCancelIntentVars>({
|
|
32
|
+
mutationKey: ['partner', 'cancelIntent'],
|
|
33
|
+
...mutationOptions,
|
|
34
|
+
mutationFn: async vars => unwrapResult(await sodax.partners.feeClaim.cancelIntent<false>({ ...vars, raw: false })),
|
|
35
|
+
onSuccess: async (data, vars, ctx) => {
|
|
36
|
+
queryClient.invalidateQueries({
|
|
37
|
+
queryKey: ['partner', 'feeClaim', 'assetsBalances', vars.params.srcAddress],
|
|
38
|
+
});
|
|
39
|
+
queryClient.invalidateQueries({
|
|
40
|
+
queryKey: [
|
|
41
|
+
'partner',
|
|
42
|
+
'feeClaim',
|
|
43
|
+
'userIntent',
|
|
44
|
+
vars.params.srcAddress,
|
|
45
|
+
vars.params.fromToken,
|
|
46
|
+
vars.params.toToken,
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|