@sodax/dapp-kit 2.4.0-rc.1 → 2.4.0-rc.3
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/README.md +11 -3
- package/dist/index.d.ts +395 -2413
- package/dist/index.mjs +206 -31
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +4 -29
- package/src/hooks/_mutationContract.test.ts +2 -8
- package/src/hooks/backend/index.ts +0 -13
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +0 -6
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +0 -10
- package/src/hooks/backend/useBackendIntentByHash.ts +0 -6
- package/src/hooks/backend/useBackendIntentByTxHash.ts +1 -10
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +0 -6
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +0 -8
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +0 -6
- package/src/hooks/backend/useBackendOracleCandles.ts +1 -9
- package/src/hooks/backend/useBackendOracleMarkets.ts +1 -7
- package/src/hooks/backend/useBackendOrderbook.ts +0 -6
- package/src/hooks/backend/useBackendUserIntents.ts +0 -8
- package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +1 -3
- package/src/hooks/bitcoin/resolveBtcReadAddress.ts +2 -12
- package/src/hooks/bitcoin/useBitcoinBalance.ts +1 -7
- package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +2 -4
- package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +2 -13
- package/src/hooks/bitcoin/useFundTradingWallet.ts +0 -6
- package/src/hooks/bitcoin/useRadfiAuth.ts +1 -6
- package/src/hooks/bitcoin/useRadfiSession.ts +0 -1
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +0 -6
- package/src/hooks/bitcoin/useRenewUtxos.ts +0 -5
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -4
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.test.ts +1 -7
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.ts +7 -21
- package/src/hooks/bridge/useBridge.test.ts +1 -11
- package/src/hooks/bridge/useBridge.ts +2 -12
- package/src/hooks/bridge/useBridgeAllowance.ts +1 -2
- package/src/hooks/bridge/useBridgeApprovalStrategy.ts +2 -6
- package/src/hooks/bridge/useBridgeApprove.ts +2 -14
- package/src/hooks/bridge/useBridgeDetailedStatus.test.ts +2 -11
- package/src/hooks/bridge/useBridgeDetailedStatus.ts +3 -23
- package/src/hooks/bridge/useBridgeWithApproval.ts +2 -11
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.test.ts +2 -7
- package/src/hooks/bridgeApi/getBridgeSubmitTxStatusRefetchInterval.ts +2 -13
- package/src/hooks/bridgeApi/index.ts +11 -14
- package/src/hooks/bridgeApi/useBridgeApiAllowance.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiApprove.ts +2 -17
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.test.ts +2 -13
- package/src/hooks/bridgeApi/useBridgeApiApproveAndBroadcast.ts +3 -20
- package/src/hooks/bridgeApi/useBridgeApiBridgeableAmount.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts +1 -14
- package/src/hooks/bridgeApi/useBridgeApiFee.ts +2 -11
- package/src/hooks/bridgeApi/useBridgeApiIsBridgeable.ts +1 -12
- package/src/hooks/bridgeApi/useBridgeApiSubmitTx.ts +2 -23
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.test.ts +1 -9
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.ts +1 -19
- package/src/hooks/bridgeApi/useBridgeApiTokens.ts +0 -8
- package/src/hooks/bridgeApi/useBridgeApiTokensByChain.ts +0 -7
- package/src/hooks/dex/useClaimRewards.ts +1 -12
- package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +1 -5
- package/src/hooks/dex/useCreateDepositParams.ts +1 -5
- package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +1 -10
- package/src/hooks/dex/useCreateWithdrawParams.ts +1 -5
- package/src/hooks/dex/useDecreaseLiquidity.ts +2 -15
- package/src/hooks/dex/useDexAllowance.ts +1 -5
- package/src/hooks/dex/useDexApprove.ts +1 -12
- package/src/hooks/dex/useDexDeposit.ts +1 -23
- package/src/hooks/dex/useDexWithdraw.ts +1 -13
- package/src/hooks/dex/useLiquidityAmounts.ts +1 -4
- package/src/hooks/dex/usePoolBalances.ts +0 -4
- package/src/hooks/dex/usePoolData.ts +1 -4
- package/src/hooks/dex/usePools.ts +1 -4
- package/src/hooks/dex/usePositionInfo.ts +1 -4
- package/src/hooks/dex/useSupplyLiquidity.ts +3 -20
- package/src/hooks/leverageYield/useApproveLeveragePositionFunding.ts +2 -8
- package/src/hooks/leverageYield/useLeveragePositionAccount.ts +2 -13
- package/src/hooks/leverageYield/useLeveragePositionCollateral.ts +2 -14
- package/src/hooks/leverageYield/useLeveragePositionFundingAllowance.ts +2 -9
- package/src/hooks/leverageYield/useLeveragePositionInfo.ts +1 -13
- package/src/hooks/leverageYield/useLeveragePositionPayoutAddress.ts +3 -15
- package/src/hooks/leverageYield/useLeveragePositionPending.ts +2 -16
- package/src/hooks/leverageYield/useLeveragePositions.ts +1 -15
- package/src/hooks/leverageYield/useLeveragePositionsForUser.ts +1 -15
- package/src/hooks/leverageYield/useLeverageYieldApprovalStrategy.ts +1 -6
- package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +1 -17
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.test.ts +3 -14
- package/src/hooks/leverageYield/useLeverageYieldDetailedStatus.ts +2 -19
- package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldPosition.ts +1 -13
- package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +1 -12
- package/src/hooks/leverageYield/useLeverageYieldQuote.test.ts +3 -13
- package/src/hooks/leverageYield/useLeverageYieldQuote.ts +5 -54
- package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +2 -29
- package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +1 -9
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -25
- package/src/hooks/leverageYield/useLeverageYieldVaultSwapWithApproval.ts +1 -11
- package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +1 -17
- package/src/hooks/leverageYield/useOpenLeveragePosition.ts +5 -18
- package/src/hooks/leverageYield/useRunLeveragePositionOperation.ts +4 -20
- package/src/hooks/leverageYield/useSubmitLeveragePositionIntent.ts +3 -15
- package/src/hooks/leverageYieldApi/index.ts +0 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +3 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +4 -14
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +4 -26
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +1 -15
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +1 -6
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +1 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +2 -12
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +2 -8
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +2 -17
- package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +1 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +0 -7
- package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +1 -15
- package/src/hooks/migrate/useMigrateBaln.ts +1 -8
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +1 -12
- package/src/hooks/migrate/useMigratebnUSD.ts +1 -12
- package/src/hooks/migrate/useMigrationAllowance.ts +3 -19
- package/src/hooks/migrate/useMigrationApprove.ts +2 -20
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +0 -7
- package/src/hooks/mm/useAToken.ts +1 -6
- package/src/hooks/mm/useATokensBalances.ts +0 -5
- package/src/hooks/mm/useBorrow.ts +1 -13
- package/src/hooks/mm/useEModes.ts +2 -13
- package/src/hooks/mm/useMMAllowance.test.ts +55 -0
- package/src/hooks/mm/useMMAllowance.ts +6 -16
- package/src/hooks/mm/useMMApprove.ts +1 -14
- package/src/hooks/mm/useRepay.ts +1 -12
- package/src/hooks/mm/useReservesData.ts +0 -4
- package/src/hooks/mm/useReservesHumanized.ts +0 -4
- package/src/hooks/mm/useReservesList.ts +0 -4
- package/src/hooks/mm/useReservesUsdFormat.ts +0 -4
- package/src/hooks/mm/useSupply.ts +1 -24
- package/src/hooks/mm/useUserFormattedSummary.ts +0 -7
- package/src/hooks/mm/useUserReservesData.ts +0 -4
- package/src/hooks/mm/useWithdraw.ts +1 -13
- package/src/hooks/partner/useApproveToken.ts +1 -7
- package/src/hooks/partner/useFeeClaimSwap.ts +1 -7
- package/src/hooks/partner/useFeeClaimWithdraw.ts +3 -20
- package/src/hooks/partner/useFetchAssetsBalances.ts +0 -4
- package/src/hooks/partner/useGetAutoSwapPreferences.ts +0 -4
- package/src/hooks/partner/useGetIntentDetails.ts +1 -8
- package/src/hooks/partner/useGetUserIntent.ts +1 -8
- package/src/hooks/partner/useIsTokenApproved.ts +0 -4
- package/src/hooks/partner/usePartnerCancelIntent.ts +2 -9
- package/src/hooks/partner/useSetSwapPreference.ts +1 -14
- package/src/hooks/recovery/useHubAssetBalances.ts +1 -6
- package/src/hooks/recovery/useWithdrawHubAsset.ts +1 -13
- package/src/hooks/shared/index.ts +4 -0
- package/src/hooks/shared/invalidateBalances.ts +2 -10
- package/src/hooks/shared/isUserRejectedError.test.ts +0 -3
- package/src/hooks/shared/isUserRejectedError.ts +2 -23
- package/src/hooks/shared/notFoundStreak.ts +5 -22
- package/src/hooks/shared/retryUnlessAuthFailure.test.ts +1 -2
- package/src/hooks/shared/retryUnlessAuthFailure.ts +1 -12
- package/src/hooks/shared/solverStatusPolicy.test.ts +0 -5
- package/src/hooks/shared/solverStatusPolicy.ts +8 -58
- package/src/hooks/shared/types.ts +4 -55
- package/src/hooks/shared/unwrapResult.ts +1 -8
- package/src/hooks/shared/useBalances.ts +6 -39
- package/src/hooks/shared/useEstablishTrustline.test.ts +1 -5
- package/src/hooks/shared/useEstablishTrustline.ts +3 -13
- package/src/hooks/shared/useEstablishXrpTrustline.test.ts +112 -0
- package/src/hooks/shared/useEstablishXrpTrustline.ts +63 -0
- package/src/hooks/shared/useEstimateGas.ts +0 -1
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +1 -18
- package/src/hooks/shared/useNearStorageCheck.ts +2 -9
- package/src/hooks/shared/useNearStorageGate.ts +5 -15
- package/src/hooks/shared/useRegisterNearStorage.ts +2 -10
- package/src/hooks/shared/useRequestTrustline.test.ts +1 -7
- package/src/hooks/shared/useRequestTrustline.ts +4 -14
- package/src/hooks/shared/useSafeMutation.test.ts +0 -3
- package/src/hooks/shared/useSafeMutation.ts +2 -26
- package/src/hooks/shared/useSodaxContext.ts +0 -6
- package/src/hooks/shared/useStellarGate.test.ts +2 -9
- package/src/hooks/shared/useStellarGate.ts +3 -9
- package/src/hooks/shared/useStellarTrustlineCheck.test.ts +0 -2
- package/src/hooks/shared/useStellarTrustlineCheck.ts +1 -4
- package/src/hooks/shared/useXBalances.ts +2 -20
- package/src/hooks/shared/useXrpDestinationCheck.ts +71 -0
- package/src/hooks/shared/useXrpGate.test.ts +116 -0
- package/src/hooks/shared/useXrpGate.ts +80 -0
- package/src/hooks/shared/useXrpTrustlineReserveCheck.ts +45 -0
- package/src/hooks/shared/waitForApiAllowance.test.ts +0 -1
- package/src/hooks/shared/waitForApiAllowance.ts +2 -6
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +1 -2
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +1 -5
- package/src/hooks/sponsoring/useActivateStellarAccount.wire.test.ts +2 -13
- package/src/hooks/sponsoring/useSponsorConfig.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountActive.ts +0 -1
- package/src/hooks/sponsoring/useStellarAccountStatus.ts +1 -4
- package/src/hooks/staking/index.ts +0 -1
- package/src/hooks/staking/useCancelUnstake.ts +1 -7
- package/src/hooks/staking/useClaim.ts +1 -7
- package/src/hooks/staking/useConvertedAssets.ts +1 -4
- package/src/hooks/staking/useInstantUnstake.ts +1 -7
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useInstantUnstakeApprove.ts +1 -11
- package/src/hooks/staking/useInstantUnstakeRatio.ts +1 -4
- package/src/hooks/staking/useStake.ts +1 -12
- package/src/hooks/staking/useStakeAllowance.ts +1 -5
- package/src/hooks/staking/useStakeApprove.ts +1 -11
- package/src/hooks/staking/useStakeRatio.ts +1 -4
- package/src/hooks/staking/useStakingConfig.ts +1 -4
- package/src/hooks/staking/useStakingInfo.ts +1 -5
- package/src/hooks/staking/useUnstake.ts +2 -9
- package/src/hooks/staking/useUnstakeAllowance.ts +1 -5
- package/src/hooks/staking/useUnstakeApprove.ts +1 -10
- package/src/hooks/staking/useUnstakingInfo.ts +1 -4
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +1 -4
- package/src/hooks/swap/useCancelLimitOrder.ts +1 -7
- package/src/hooks/swap/useCancelSwap.ts +1 -7
- package/src/hooks/swap/useCreateLimitOrder.ts +2 -12
- package/src/hooks/swap/useDetailedStatus.test.ts +6 -18
- package/src/hooks/swap/useDetailedStatus.ts +2 -19
- package/src/hooks/swap/useQuote.test.ts +2 -8
- package/src/hooks/swap/useQuote.ts +5 -32
- package/src/hooks/swap/useStatus.ts +2 -10
- package/src/hooks/swap/useSwap.test.ts +1 -11
- package/src/hooks/swap/useSwap.ts +2 -12
- package/src/hooks/swap/useSwapAllowance.ts +1 -2
- package/src/hooks/swap/useSwapApprovalStrategy.ts +2 -7
- package/src/hooks/swap/useSwapApprove.ts +2 -14
- package/src/hooks/swap/useSwapLifecycle.test.ts +47 -2
- package/src/hooks/swap/useSwapLifecycle.ts +36 -30
- package/src/hooks/swap/useSwapWithApproval.ts +2 -11
- package/src/hooks/swapsApi/index.ts +2 -14
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +1 -5
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +1 -14
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -20
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.ts +3 -24
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.test.ts +2 -8
- package/src/hooks/swapsApi/useSwapsApiBroadcastWithApproval.ts +6 -41
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +0 -13
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +1 -13
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +0 -8
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +1 -7
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +1 -8
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +1 -10
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +2 -24
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +1 -11
- package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +1 -15
- package/src/hooks/swapsApi/useSwapsApiSubmitTx.ts +0 -21
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +2 -19
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +0 -7
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +0 -7
- package/src/index.ts +1 -1
- package/src/providers/SodaxProvider.test.ts +2 -9
- package/src/providers/SodaxProvider.tsx +1 -12
- package/src/providers/createSodaxQueryClient.ts +4 -56
- package/src/utils/approvalPlan.ts +9 -32
- package/src/utils/dex-utils.ts +5 -20
- package/src/utils/index.ts +1 -0
- package/src/utils/nearStorageGate.ts +3 -14
- package/src/utils/stellarGate.ts +3 -16
- package/src/utils/swapLifecycle.test.ts +35 -0
- package/src/utils/swapLifecycle.ts +21 -28
- package/src/utils/xrpGate.test.ts +112 -0
- package/src/utils/xrpGate.ts +69 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ChainKeys, type Sodax, type SpokeChainKey, type XrpDestinationReadiness } from '@sodax/sdk';
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { ReadHookParams } from './types.js';
|
|
4
|
+
import { useSodaxContext } from './useSodaxContext.js';
|
|
5
|
+
|
|
6
|
+
export type UseXrpDestinationCheckParams = ReadHookParams<
|
|
7
|
+
XrpDestinationReadiness,
|
|
8
|
+
{
|
|
9
|
+
chainId: SpokeChainKey | undefined;
|
|
10
|
+
token: string | undefined;
|
|
11
|
+
address: string | undefined;
|
|
12
|
+
/** The least that arrives, in the token's decimals. */
|
|
13
|
+
amount: bigint | undefined;
|
|
14
|
+
/** The most that can arrive, which the trustline needs room for. Defaults to `amount`. */
|
|
15
|
+
maxAmount?: bigint;
|
|
16
|
+
}
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
type XrpDestinationReader = { spoke: { xrp: Pick<Sodax['spoke']['xrp'], 'checkDestination'> } };
|
|
20
|
+
|
|
21
|
+
export function getXrpDestinationCheckQueryOptions({
|
|
22
|
+
sodax,
|
|
23
|
+
chainId,
|
|
24
|
+
token,
|
|
25
|
+
address,
|
|
26
|
+
amount,
|
|
27
|
+
maxAmount,
|
|
28
|
+
}: {
|
|
29
|
+
sodax: XrpDestinationReader;
|
|
30
|
+
chainId: SpokeChainKey | undefined;
|
|
31
|
+
token: string | undefined;
|
|
32
|
+
address: string | undefined;
|
|
33
|
+
amount: bigint | undefined;
|
|
34
|
+
maxAmount?: bigint;
|
|
35
|
+
}) {
|
|
36
|
+
return {
|
|
37
|
+
queryKey: [
|
|
38
|
+
'shared',
|
|
39
|
+
'xrpDestinationCheck',
|
|
40
|
+
chainId,
|
|
41
|
+
token,
|
|
42
|
+
address,
|
|
43
|
+
amount?.toString(),
|
|
44
|
+
maxAmount?.toString(),
|
|
45
|
+
] as const,
|
|
46
|
+
queryFn: async (): Promise<XrpDestinationReadiness> => {
|
|
47
|
+
if (!address || !token || amount === undefined) throw new Error('address, token and amount are required');
|
|
48
|
+
return sodax.spoke.xrp.checkDestination({ address, token, amount, maxAmount });
|
|
49
|
+
},
|
|
50
|
+
enabled: chainId === ChainKeys.XRP_MAINNET && !!address && !!token && amount !== undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Whether an XRPL account can receive `amount` of `token` (up to `maxAmount`), and if not, why. */
|
|
55
|
+
export function useXrpDestinationCheck({
|
|
56
|
+
params,
|
|
57
|
+
queryOptions,
|
|
58
|
+
}: UseXrpDestinationCheckParams = {}): UseQueryResult<XrpDestinationReadiness, Error> {
|
|
59
|
+
const { sodax } = useSodaxContext();
|
|
60
|
+
return useQuery<XrpDestinationReadiness, Error>({
|
|
61
|
+
...getXrpDestinationCheckQueryOptions({
|
|
62
|
+
sodax,
|
|
63
|
+
chainId: params?.chainId,
|
|
64
|
+
token: params?.token,
|
|
65
|
+
address: params?.address,
|
|
66
|
+
amount: params?.amount,
|
|
67
|
+
maxAmount: params?.maxAmount,
|
|
68
|
+
}),
|
|
69
|
+
...queryOptions,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ChainKeys } from '@sodax/sdk';
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
const destinationCheck = vi.fn();
|
|
5
|
+
const reserveCheck = vi.fn();
|
|
6
|
+
const establish = vi.fn();
|
|
7
|
+
const requiresTrustline = vi.fn(() => true);
|
|
8
|
+
|
|
9
|
+
// Stubbing the child hooks keeps this a DOM-free assertion on the params the gate builds.
|
|
10
|
+
vi.mock('./useXrpDestinationCheck.js', () => ({
|
|
11
|
+
useXrpDestinationCheck: (args: unknown) => destinationCheck(args),
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('./useXrpTrustlineReserveCheck.js', () => ({
|
|
14
|
+
useXrpTrustlineReserveCheck: (args: unknown) => reserveCheck(args),
|
|
15
|
+
}));
|
|
16
|
+
vi.mock('./useEstablishXrpTrustline.js', () => ({
|
|
17
|
+
useEstablishXrpTrustline: () => ({ mutateAsyncSafe: establish, isPending: false }),
|
|
18
|
+
}));
|
|
19
|
+
vi.mock('./useSodaxContext.js', () => ({
|
|
20
|
+
useSodaxContext: () => ({ sodax: { spoke: { xrp: { requiresTrustline } } } }),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const { useXrpGate } = await import('./useXrpGate.js');
|
|
24
|
+
|
|
25
|
+
const TOKEN = 'rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De';
|
|
26
|
+
const ADDRESS = 'rJB8dmrf4JxkLKHPUfdxyPwpXMyxjkQsyG';
|
|
27
|
+
const XRP_WALLET = { chainType: 'XRP' };
|
|
28
|
+
|
|
29
|
+
const idle = { isLoading: false, isError: false, data: undefined, error: null, refetch: vi.fn() };
|
|
30
|
+
|
|
31
|
+
const run = (readiness: unknown, overrides: Record<string, unknown> = {}) => {
|
|
32
|
+
destinationCheck.mockReturnValue({ ...idle, data: readiness });
|
|
33
|
+
reserveCheck.mockReturnValue({ ...idle, data: true });
|
|
34
|
+
const gate = useXrpGate({
|
|
35
|
+
dstChainKey: ChainKeys.XRP_MAINNET,
|
|
36
|
+
token: TOKEN,
|
|
37
|
+
address: ADDRESS,
|
|
38
|
+
amount: 1_000_000n,
|
|
39
|
+
maxAmount: 2_000_000n,
|
|
40
|
+
walletProvider: XRP_WALLET,
|
|
41
|
+
...overrides,
|
|
42
|
+
} as never);
|
|
43
|
+
return {
|
|
44
|
+
gate,
|
|
45
|
+
destinationParams: destinationCheck.mock.calls[0]?.[0]?.params,
|
|
46
|
+
reserveParams: reserveCheck.mock.calls[0]?.[0]?.params,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
destinationCheck.mockReset();
|
|
52
|
+
reserveCheck.mockReset();
|
|
53
|
+
establish.mockReset();
|
|
54
|
+
requiresTrustline.mockReset().mockReturnValue(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('useXrpGate', () => {
|
|
58
|
+
it('checks the destination with the amount and the most that can arrive', () => {
|
|
59
|
+
const { destinationParams } = run({ ready: true });
|
|
60
|
+
|
|
61
|
+
expect(destinationParams).toEqual({
|
|
62
|
+
chainId: ChainKeys.XRP_MAINNET,
|
|
63
|
+
token: TOKEN,
|
|
64
|
+
address: ADDRESS,
|
|
65
|
+
amount: 1_000_000n,
|
|
66
|
+
maxAmount: 2_000_000n,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('reads nothing for native XRP or another chain', () => {
|
|
71
|
+
requiresTrustline.mockReturnValue(false);
|
|
72
|
+
expect(run(undefined).destinationParams?.chainId).toBeUndefined();
|
|
73
|
+
|
|
74
|
+
requiresTrustline.mockReturnValue(true);
|
|
75
|
+
destinationCheck.mockReset();
|
|
76
|
+
expect(run(undefined, { dstChainKey: ChainKeys.STELLAR_MAINNET }).destinationParams?.chainId).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('reads the reserve only once the trustline is known to need setting', () => {
|
|
80
|
+
expect(run({ ready: true }).reserveParams).toEqual({ token: undefined, address: undefined });
|
|
81
|
+
|
|
82
|
+
reserveCheck.mockReset();
|
|
83
|
+
destinationCheck.mockReset();
|
|
84
|
+
expect(run({ ready: false, reason: 'issuer_frozen' }).reserveParams).toEqual({
|
|
85
|
+
token: undefined,
|
|
86
|
+
address: undefined,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
reserveCheck.mockReset();
|
|
90
|
+
destinationCheck.mockReset();
|
|
91
|
+
const { gate, reserveParams } = run({ ready: false, reason: 'no_trustline' });
|
|
92
|
+
expect(reserveParams).toEqual({ token: TOKEN, address: ADDRESS });
|
|
93
|
+
expect(gate.needsTrustline).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('requests the trustline with the XRPL destination wallet only', async () => {
|
|
97
|
+
establish.mockResolvedValue({ ok: true, value: 'hash' });
|
|
98
|
+
const { gate } = run({ ready: false, reason: 'trustline_limit' });
|
|
99
|
+
|
|
100
|
+
await expect(gate.requestTrustline()).resolves.toEqual({ ok: true, value: 'hash' });
|
|
101
|
+
expect(establish).toHaveBeenCalledWith({ token: TOKEN, address: ADDRESS, walletProvider: XRP_WALLET });
|
|
102
|
+
|
|
103
|
+
establish.mockReset();
|
|
104
|
+
const { gate: evmWallet } = run({ ready: false, reason: 'no_trustline' }, { walletProvider: { chainType: 'EVM' } });
|
|
105
|
+
await expect(evmWallet.requestTrustline()).resolves.toBeUndefined();
|
|
106
|
+
expect(establish).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('surfaces a refusal no trustline fixes as blockedReason', () => {
|
|
110
|
+
const { gate } = run({ ready: false, reason: 'trustline_unauthorized' });
|
|
111
|
+
|
|
112
|
+
expect(gate.blockedReason).toBe('trustline_unauthorized');
|
|
113
|
+
expect(gate.needsTrustline).toBe(false);
|
|
114
|
+
expect(gate.blocksAction).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ChainKeys, type GetWalletProviderType, type Result, type SpokeChainKey } from '@sodax/sdk';
|
|
2
|
+
import { resolveXrpGate, type XrpGateState } from '../../utils/xrpGate.js';
|
|
3
|
+
import { useEstablishXrpTrustline } from './useEstablishXrpTrustline.js';
|
|
4
|
+
import { useSodaxContext } from './useSodaxContext.js';
|
|
5
|
+
import { useXrpDestinationCheck } from './useXrpDestinationCheck.js';
|
|
6
|
+
import { useXrpTrustlineReserveCheck } from './useXrpTrustlineReserveCheck.js';
|
|
7
|
+
|
|
8
|
+
export interface UseXrpGateParams {
|
|
9
|
+
dstChainKey: SpokeChainKey | undefined;
|
|
10
|
+
token: string | undefined;
|
|
11
|
+
address: string | undefined;
|
|
12
|
+
/** The least that arrives, in the token's decimals. */
|
|
13
|
+
amount: bigint | undefined;
|
|
14
|
+
/** The most that can arrive, which the trustline needs room for. Defaults to `amount`. */
|
|
15
|
+
maxAmount?: bigint;
|
|
16
|
+
/** Must control `address`: `requestTrustline` refuses, before signing, a wallet connected to another account. */
|
|
17
|
+
walletProvider: GetWalletProviderType<SpokeChainKey> | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface XrpGate extends XrpGateState {
|
|
21
|
+
isChecking: boolean;
|
|
22
|
+
/** Surface when `checkFailed` is true. */
|
|
23
|
+
error: Error | undefined;
|
|
24
|
+
retry: () => void;
|
|
25
|
+
isRequestingTrustline: boolean;
|
|
26
|
+
/** Returns `undefined` when required inputs are missing. */
|
|
27
|
+
requestTrustline: () => Promise<Result<string> | undefined>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gates XRPL delivery on a trustline with room for the payout and enough XRP to set one. Refusals a
|
|
32
|
+
* trustline cannot fix surface as `blockedReason`.
|
|
33
|
+
*/
|
|
34
|
+
export function useXrpGate({
|
|
35
|
+
dstChainKey,
|
|
36
|
+
token,
|
|
37
|
+
address,
|
|
38
|
+
amount,
|
|
39
|
+
maxAmount,
|
|
40
|
+
walletProvider,
|
|
41
|
+
}: UseXrpGateParams): XrpGate {
|
|
42
|
+
const { sodax } = useSodaxContext();
|
|
43
|
+
const isXrpDestination = dstChainKey === ChainKeys.XRP_MAINNET;
|
|
44
|
+
const requiresTrustline = isXrpDestination && !!token && sodax.spoke.xrp.requiresTrustline(token);
|
|
45
|
+
const xrpWalletProvider = walletProvider?.chainType === 'XRP' ? walletProvider : undefined;
|
|
46
|
+
|
|
47
|
+
const readinessCheck = useXrpDestinationCheck({
|
|
48
|
+
params: { chainId: requiresTrustline ? dstChainKey : undefined, token, address, amount, maxAmount },
|
|
49
|
+
});
|
|
50
|
+
const trustlineReason =
|
|
51
|
+
readinessCheck.data?.ready === false &&
|
|
52
|
+
(readinessCheck.data.reason === 'no_trustline' || readinessCheck.data.reason === 'trustline_limit');
|
|
53
|
+
// Read the reserve only once the trustline is known to need setting.
|
|
54
|
+
const reserveCheck = useXrpTrustlineReserveCheck({
|
|
55
|
+
params: { token: trustlineReason ? token : undefined, address: trustlineReason ? address : undefined },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const state = resolveXrpGate(dstChainKey, { readinessCheck, reserveCheck, requiresTrustline });
|
|
59
|
+
|
|
60
|
+
const { mutateAsyncSafe: establishTrustline, isPending: isRequestingTrustline } = useEstablishXrpTrustline();
|
|
61
|
+
|
|
62
|
+
const requestTrustline = async (): Promise<Result<string> | undefined> => {
|
|
63
|
+
if (!xrpWalletProvider || !token || !address) return undefined;
|
|
64
|
+
return establishTrustline({ token, address, walletProvider: xrpWalletProvider });
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const retry = (): void => {
|
|
68
|
+
void readinessCheck.refetch();
|
|
69
|
+
if (trustlineReason) void reserveCheck.refetch();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
isChecking: readinessCheck.isLoading || reserveCheck.isLoading,
|
|
75
|
+
error: readinessCheck.error ?? reserveCheck.error ?? undefined,
|
|
76
|
+
retry,
|
|
77
|
+
isRequestingTrustline,
|
|
78
|
+
requestTrustline,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Sodax } from '@sodax/sdk';
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { ReadHookParams } from './types.js';
|
|
4
|
+
import { useSodaxContext } from './useSodaxContext.js';
|
|
5
|
+
|
|
6
|
+
export type UseXrpTrustlineReserveCheckParams = ReadHookParams<
|
|
7
|
+
boolean,
|
|
8
|
+
{
|
|
9
|
+
token: string | undefined;
|
|
10
|
+
address: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
type XrpReserveReader = { spoke: { xrp: Pick<Sodax['spoke']['xrp'], 'canAffordTrustline'> } };
|
|
15
|
+
|
|
16
|
+
export function getXrpTrustlineReserveCheckQueryOptions({
|
|
17
|
+
sodax,
|
|
18
|
+
token,
|
|
19
|
+
address,
|
|
20
|
+
}: {
|
|
21
|
+
sodax: XrpReserveReader;
|
|
22
|
+
token: string | undefined;
|
|
23
|
+
address: string | undefined;
|
|
24
|
+
}) {
|
|
25
|
+
return {
|
|
26
|
+
queryKey: ['shared', 'xrpTrustlineReserveCheck', token, address] as const,
|
|
27
|
+
queryFn: async (): Promise<boolean> => {
|
|
28
|
+
if (!address || !token) throw new Error('address and token are required');
|
|
29
|
+
return sodax.spoke.xrp.canAffordTrustline({ address, token });
|
|
30
|
+
},
|
|
31
|
+
enabled: !!address && !!token,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether an XRPL account holds the spendable XRP to set the trustline for an issued `token`. */
|
|
36
|
+
export function useXrpTrustlineReserveCheck({
|
|
37
|
+
params,
|
|
38
|
+
queryOptions,
|
|
39
|
+
}: UseXrpTrustlineReserveCheckParams = {}): UseQueryResult<boolean, Error> {
|
|
40
|
+
const { sodax } = useSodaxContext();
|
|
41
|
+
return useQuery<boolean, Error>({
|
|
42
|
+
...getXrpTrustlineReserveCheckQueryOptions({ sodax, token: params?.token, address: params?.address }),
|
|
43
|
+
...queryOptions,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -4,7 +4,6 @@ import { waitForApiAllowance } from './waitForApiAllowance.js';
|
|
|
4
4
|
|
|
5
5
|
const valid = (value: boolean) => ({ ok: true as const, value: { valid: value } });
|
|
6
6
|
|
|
7
|
-
/** A backend failure as the API services surface it: `EXTERNAL_API_ERROR` with the status on context. */
|
|
8
7
|
const apiError = (status: number): SodaxError =>
|
|
9
8
|
new SodaxError('EXTERNAL_API_ERROR', `responded with ${status}`, {
|
|
10
9
|
feature: 'backend',
|
|
@@ -19,12 +19,8 @@ async function settleWithin<T>(promise: Promise<T>, ms: number): Promise<T | und
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* stale `valid: false` leaves Approve enabled after a successful approval. A failed check is retried like a
|
|
25
|
-
* stale one, except an auth failure, which no retry fixes. Each check gets `apiConfig` with its request timeout
|
|
26
|
-
* capped to the time left and is abandoned when that runs out, so a hanging API cannot stretch the wait. Never
|
|
27
|
-
* throws: the approval has already landed, and the caller's allowance refetch shows whatever the API reports last.
|
|
22
|
+
* Polls until the API reports `valid` (its RPC can trail the confirming node); stops on auth failure or
|
|
23
|
+
* when the budget runs out. Never throws, since the approval has already landed.
|
|
28
24
|
*/
|
|
29
25
|
export async function waitForApiAllowance(
|
|
30
26
|
check: (config: RequestOverrideConfig) => Promise<Result<{ valid: boolean }>>,
|
|
@@ -64,8 +64,7 @@ describe('useActivateStellarAccount — cache invalidation', () => {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it('invalidates Stellar balances through the shared invalidateBalances helper', () => {
|
|
67
|
-
// Routed through invalidateBalances (
|
|
68
|
-
// hand-rolled invalidateQueries call, so it is not one of the literal matches above.
|
|
67
|
+
// Routed through invalidateBalances (both balance hooks), so it is not a literal match above.
|
|
69
68
|
expect(SRC).toMatch(/invalidateBalances\(queryClient,\s*ChainKeys\.STELLAR_MAINNET\)/);
|
|
70
69
|
});
|
|
71
70
|
|
|
@@ -6,13 +6,9 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
7
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
8
|
|
|
9
|
-
/** Keep mutation variables aligned with the SDK operation. */
|
|
10
9
|
export type UseActivateStellarAccountVars = ActivateStellarAccountParams;
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* Activate a Stellar account through the sponsoring service. Both `submitted`
|
|
14
|
-
* and `alreadyActive` are successful outcomes.
|
|
15
|
-
*/
|
|
11
|
+
/** Both `submitted` and `alreadyActive` are successful outcomes. */
|
|
16
12
|
export function useActivateStellarAccount({
|
|
17
13
|
mutationOptions,
|
|
18
14
|
}: MutationHookParams<ActivateStellarAccountResult, UseActivateStellarAccountVars> = {}): SafeUseMutationResult<
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* mutation vars must reach the sponsoring `/accounts` POST as `x-api-key`, beating the
|
|
4
|
-
* instance-level key.
|
|
5
|
-
*
|
|
6
|
-
* Follows the package convention of testing hooks without a renderer (captured `mutationFn`),
|
|
7
|
-
* driving a real keyed `Sodax` end to end the way packages/sdk/src/sponsoring/SponsoringService.test.ts
|
|
8
|
-
* does: Horizon is stubbed on the instance, the wallet signs with a real throwaway keypair, and the
|
|
9
|
-
* config GET + account POST run call-through to a stubbed global fetch.
|
|
10
|
-
*
|
|
11
|
-
* `@stellar/stellar-sdk` is not a dapp-kit dependency, so it is loaded through `@sodax/sdk`'s own
|
|
12
|
-
* module graph — the same copy the SDK builds and verifies the transaction with.
|
|
13
|
-
*/
|
|
1
|
+
// `requestConfig.apiKey` in the mutation vars must reach the `/accounts` POST as `x-api-key`, beating the instance key.
|
|
2
|
+
// `@stellar/stellar-sdk` is not a dapp-kit dependency, so it is loaded through `@sodax/sdk`'s module graph.
|
|
14
3
|
|
|
15
4
|
import { createRequire } from 'node:module';
|
|
16
5
|
import { Sodax } from '@sodax/sdk';
|
|
@@ -19,7 +19,6 @@ export function getSponsorConfigQueryOptions({ sodax }: { sodax: SponsorConfigRe
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** Read the sponsoring service's published transaction parameters. */
|
|
23
22
|
export function useSponsorConfig({
|
|
24
23
|
queryOptions,
|
|
25
24
|
}: UseSponsorConfigParams = {}): UseQueryResult<StellarSponsorConfig, Error> {
|
|
@@ -41,10 +41,7 @@ export function getStellarAccountStatusQueryOptions({
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* Read account existence and trustline affordability in one Horizon request.
|
|
46
|
-
* Prefer {@link useStellarGate} for destination gating.
|
|
47
|
-
*/
|
|
44
|
+
/** One Horizon request; prefer {@link useStellarGate} for destination gating. */
|
|
48
45
|
export function useStellarAccountStatus({
|
|
49
46
|
params,
|
|
50
47
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useCancelUnstake.ts
|
|
2
1
|
import type { CancelUnstakeAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,12 +7,7 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
8
7
|
|
|
9
8
|
export type UseCancelUnstakeVars<K extends SpokeChainKey = SpokeChainKey> = Omit<CancelUnstakeAction<K, false>, 'raw'>;
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* React hook for cancelling a pending unstake request.
|
|
13
|
-
*
|
|
14
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
15
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
16
|
-
*/
|
|
10
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
17
11
|
export function useCancelUnstake<K extends SpokeChainKey = SpokeChainKey>({
|
|
18
12
|
mutationOptions,
|
|
19
13
|
}: MutationHookParams<TxHashPair, UseCancelUnstakeVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useClaim.ts
|
|
2
1
|
import type { ClaimAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -9,12 +8,7 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
9
8
|
|
|
10
9
|
export type UseClaimVars<K extends SpokeChainKey = SpokeChainKey> = Omit<ClaimAction<K, false>, 'raw'>;
|
|
11
10
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook for claiming an unstaked SODA request that has reached the end of its waiting period.
|
|
14
|
-
*
|
|
15
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
16
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
17
|
-
*/
|
|
11
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
18
12
|
export function useClaim<K extends SpokeChainKey = SpokeChainKey>({
|
|
19
13
|
mutationOptions,
|
|
20
14
|
}: MutationHookParams<TxHashPair, UseClaimVars<K>> = {}): SafeUseMutationResult<TxHashPair, Error, UseClaimVars<K>> {
|
|
@@ -9,10 +9,7 @@ export type UseConvertedAssetsParams = ReadHookParams<
|
|
|
9
9
|
}
|
|
10
10
|
>;
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook to convert an xSODA share amount to its underlying SODA value via the vault's
|
|
14
|
-
* exchange rate. Hub-only read. Throws on `!ok`.
|
|
15
|
-
*/
|
|
12
|
+
/** Converts xSODA shares to SODA at the vault rate. Throws on `!ok`. */
|
|
16
13
|
export function useConvertedAssets({
|
|
17
14
|
params,
|
|
18
15
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useInstantUnstake.ts
|
|
2
1
|
import type { InstantUnstakeAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -12,12 +11,7 @@ export type UseInstantUnstakeVars<K extends SpokeChainKey = SpokeChainKey> = Omi
|
|
|
12
11
|
'raw'
|
|
13
12
|
>;
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
* React hook for instant-unstaking SODA (bypassing the waiting period at a slippage cost).
|
|
17
|
-
*
|
|
18
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
19
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
20
|
-
*/
|
|
14
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
21
15
|
export function useInstantUnstake<K extends SpokeChainKey = SpokeChainKey>({
|
|
22
16
|
mutationOptions,
|
|
23
17
|
}: MutationHookParams<TxHashPair, UseInstantUnstakeVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -11,11 +11,7 @@ export type UseInstantUnstakeAllowanceParams<K extends SpokeChainKey = SpokeChai
|
|
|
11
11
|
}
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* React hook to check whether the user has approved sufficient xSODA spending for the
|
|
16
|
-
* instant-unstake action. Read-only — calls `staking.isAllowanceValid` with `raw: true` so no
|
|
17
|
-
* `walletProvider` is required.
|
|
18
|
-
*/
|
|
14
|
+
/** Read-only (`raw: true`), so no `walletProvider` is needed. */
|
|
19
15
|
export function useInstantUnstakeAllowance<K extends SpokeChainKey = SpokeChainKey>({
|
|
20
16
|
params,
|
|
21
17
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useInstantUnstakeApprove.ts
|
|
2
1
|
import type { GetWalletProviderType, InstantUnstakeParams, SpokeChainKey, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,21 +5,12 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useInstantUnstakeApprove}. The `action` literal is injected by
|
|
11
|
-
* the hook.
|
|
12
|
-
*/
|
|
13
8
|
export type UseInstantUnstakeApproveVars<K extends SpokeChainKey = SpokeChainKey> = {
|
|
14
9
|
params: Omit<InstantUnstakeParams<K>, 'action'>;
|
|
15
10
|
walletProvider: GetWalletProviderType<K>;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for approving xSODA spending on the instant-unstake action.
|
|
20
|
-
*
|
|
21
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
22
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success.
|
|
23
|
-
*/
|
|
13
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped tx return value. */
|
|
24
14
|
export function useInstantUnstakeApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
25
15
|
mutationOptions,
|
|
26
16
|
}: MutationHookParams<TxReturnType<K, false>, UseInstantUnstakeApproveVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -9,10 +9,7 @@ export type UseInstantUnstakeRatioParams = ReadHookParams<
|
|
|
9
9
|
}
|
|
10
10
|
>;
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook to estimate the SODA amount received from instant-unstaking a given xSODA amount
|
|
14
|
-
* (after slippage). Hub-only read. Throws on `!ok`.
|
|
15
|
-
*/
|
|
12
|
+
/** SODA received for instant-unstaking the xSODA amount, after slippage. Throws on `!ok`. */
|
|
16
13
|
export function useInstantUnstakeRatio({
|
|
17
14
|
params,
|
|
18
15
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useStake.ts
|
|
2
1
|
import type { SpokeChainKey, StakeAction, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -7,19 +6,9 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
7
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
7
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* Mutation variables for {@link useStake}. Generic over `K extends SpokeChainKey` (defaults to
|
|
12
|
-
* the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
13
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
14
|
-
*/
|
|
15
9
|
export type UseStakeVars<K extends SpokeChainKey = SpokeChainKey> = Omit<StakeAction<K, false>, 'raw'>;
|
|
16
10
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook for staking SODA tokens.
|
|
19
|
-
*
|
|
20
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
21
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
22
|
-
*/
|
|
11
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
23
12
|
export function useStake<K extends SpokeChainKey = SpokeChainKey>({
|
|
24
13
|
mutationOptions,
|
|
25
14
|
}: MutationHookParams<TxHashPair, UseStakeVars<K>> = {}): SafeUseMutationResult<TxHashPair, Error, UseStakeVars<K>> {
|
|
@@ -11,11 +11,7 @@ export type UseStakeAllowanceParams<K extends SpokeChainKey = SpokeChainKey> = R
|
|
|
11
11
|
}
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* React hook to check whether the user has approved sufficient SODA spending for the stake
|
|
16
|
-
* action. Read-only — calls `staking.isAllowanceValid` with `raw: true` so no `walletProvider`
|
|
17
|
-
* is required.
|
|
18
|
-
*/
|
|
14
|
+
/** Read-only (`raw: true`), so no `walletProvider` is needed. */
|
|
19
15
|
export function useStakeAllowance<K extends SpokeChainKey = SpokeChainKey>({
|
|
20
16
|
params,
|
|
21
17
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/staking/useStakeApprove.ts
|
|
2
1
|
import type { GetWalletProviderType, SpokeChainKey, StakeParams, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,21 +5,12 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
6
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
7
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useStakeApprove}. The `action` literal is injected by the hook —
|
|
11
|
-
* callers pass the stake-specific fields only.
|
|
12
|
-
*/
|
|
13
8
|
export type UseStakeApproveVars<K extends SpokeChainKey = SpokeChainKey> = {
|
|
14
9
|
params: Omit<StakeParams<K>, 'action'>;
|
|
15
10
|
walletProvider: GetWalletProviderType<K>;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for approving SODA spending on the stake action.
|
|
20
|
-
*
|
|
21
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
22
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success.
|
|
23
|
-
*/
|
|
13
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped tx return value. */
|
|
24
14
|
export function useStakeApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
25
15
|
mutationOptions,
|
|
26
16
|
}: MutationHookParams<TxReturnType<K, false>, UseStakeApproveVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -9,10 +9,7 @@ export type UseStakeRatioParams = ReadHookParams<
|
|
|
9
9
|
}
|
|
10
10
|
>;
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* React hook to estimate the SODA → xSODA stake ratio for a given amount. Hub-only read. Throws
|
|
14
|
-
* on `!ok`.
|
|
15
|
-
*/
|
|
12
|
+
/** Throws on `!ok`. */
|
|
16
13
|
export function useStakeRatio({
|
|
17
14
|
params,
|
|
18
15
|
queryOptions,
|
|
@@ -5,10 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseStakingConfigParams = ReadHookParams<StakingConfig>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* React hook to fetch the global staking config (unstaking period, min unstaking period, max
|
|
10
|
-
* penalty). Hub-only read; no chain context required. Throws on `!ok`.
|
|
11
|
-
*/
|
|
8
|
+
/** Throws on `!ok`. */
|
|
12
9
|
export function useStakingConfig({ queryOptions }: UseStakingConfigParams = {}): UseQueryResult<StakingConfig, Error> {
|
|
13
10
|
const { sodax } = useSodaxContext();
|
|
14
11
|
|