@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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/migrate/useMigrationApprove.ts
|
|
2
1
|
import type {
|
|
3
2
|
IcxRevertMigrationAction,
|
|
4
3
|
MigrationAction,
|
|
@@ -12,27 +11,12 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
12
11
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
13
12
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
* Mutation variables for {@link useMigrationApprove}. The SDK's `approve` accepts a union of
|
|
17
|
-
* action wrappers (Icx-revert OR bnUSD bidirectional) plus a separate `'migrate' | 'revert'`
|
|
18
|
-
* discriminator. Both ride along in `TVars` here so the hook stays a pure pass-through.
|
|
19
|
-
*/
|
|
20
14
|
export type UseMigrationApproveVars<K extends SpokeChainKey = SpokeChainKey> = (
|
|
21
15
|
| Omit<IcxRevertMigrationAction<false>, 'raw'>
|
|
22
16
|
| Omit<UnifiedBnUSDMigrateAction<K, false>, 'raw'>
|
|
23
17
|
) & { action: MigrationAction };
|
|
24
18
|
|
|
25
|
-
/**
|
|
26
|
-
* React hook for approving token spending on a migration intent. Required before:
|
|
27
|
-
* - SODA → ICX revert (consumes SODA on Sonic via the user's hub router)
|
|
28
|
-
* - bnUSD migrations on EVM/Stellar source chains (consumes the source bnUSD via asset manager)
|
|
29
|
-
*
|
|
30
|
-
* NOT required for ICX → SODA forward migrations or BALN migrations (both originate on Icon
|
|
31
|
-
* which doesn't use ERC-20 allowances).
|
|
32
|
-
*
|
|
33
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
34
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success.
|
|
35
|
-
*/
|
|
19
|
+
/** Required for SODA → ICX revert and EVM/Stellar bnUSD migrations; not for ICX → SODA or BALN (Icon). */
|
|
36
20
|
export function useMigrationApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
37
21
|
mutationOptions,
|
|
38
22
|
}: MutationHookParams<TxReturnType<K, false>, UseMigrationApproveVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -54,9 +38,7 @@ export function useMigrationApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
54
38
|
),
|
|
55
39
|
),
|
|
56
40
|
onSuccess: async (data, vars, ctx) => {
|
|
57
|
-
// Broad
|
|
58
|
-
// (action, params) tuple the consumer was reading, so refetch all and let the active
|
|
59
|
-
// queries reconcile.
|
|
41
|
+
// Broad: the mutation can't know which (action, params) allowance the consumer reads.
|
|
60
42
|
queryClient.invalidateQueries({ queryKey: ['migrate', 'allowance'] });
|
|
61
43
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
62
44
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/migrate/useRevertMigrateSodaToIcx.ts
|
|
2
1
|
import type { IcxRevertMigrationAction, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { ChainKeys } from '@sodax/sdk';
|
|
4
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
@@ -10,12 +9,6 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
10
9
|
|
|
11
10
|
export type UseRevertMigrateSodaToIcxVars = Omit<IcxRevertMigrationAction<false>, 'raw'>;
|
|
12
11
|
|
|
13
|
-
/**
|
|
14
|
-
* React hook for reverting SODA → ICX (the inverse of {@link useMigrateIcxToSoda}).
|
|
15
|
-
*
|
|
16
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
17
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
18
|
-
*/
|
|
19
12
|
export function useRevertMigrateSodaToIcx({
|
|
20
13
|
mutationOptions,
|
|
21
14
|
}: MutationHookParams<TxHashPair, UseRevertMigrateSodaToIcxVars> = {}): SafeUseMutationResult<
|
|
@@ -14,12 +14,7 @@ export type UseATokenParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to fetch ERC-20 metadata for a given aToken address on the hub chain.
|
|
19
|
-
* Returns `Erc20Token` (`name`, `symbol`, `decimals`, `address`) augmented with the hub
|
|
20
|
-
* `chainKey`. Note: the returned shape is a subset of `XToken` — `hubAsset` and `vault` fields
|
|
21
|
-
* must be resolved separately if needed.
|
|
22
|
-
*/
|
|
17
|
+
/** Returns ERC-20 metadata plus hub `chainKey` only; `hubAsset` and `vault` are not resolved. */
|
|
23
18
|
export function useAToken({ params, queryOptions }: UseATokenParams = {}): UseQueryResult<ATokenData, Error> {
|
|
24
19
|
const { sodax } = useSodaxContext();
|
|
25
20
|
const aToken = params?.aToken;
|
|
@@ -14,11 +14,6 @@ export type UseATokensBalancesParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to fetch aToken balances for a list of addresses in a single multicall.
|
|
19
|
-
* Derives the user's hub wallet via `EvmHubProvider.getUserHubWalletAddress` from the
|
|
20
|
-
* spoke `chainKey` + spoke wallet `userAddress`.
|
|
21
|
-
*/
|
|
22
17
|
export function useATokensBalances({
|
|
23
18
|
params,
|
|
24
19
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/mm/useBorrow.ts
|
|
2
1
|
import type { MoneyMarketBorrowActionParams, SpokeChainKey, OutboundSettlement } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,23 +7,12 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
|
|
|
8
7
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
9
8
|
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* Mutation variables for {@link useBorrow}. Generic over `K extends SpokeChainKey` (defaults to
|
|
13
|
-
* the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
14
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
15
|
-
*/
|
|
16
10
|
export type UseBorrowVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
17
11
|
MoneyMarketBorrowActionParams<K, false>,
|
|
18
12
|
'raw'
|
|
19
13
|
>;
|
|
20
14
|
|
|
21
|
-
/**
|
|
22
|
-
* React hook for borrowing tokens from the Sodax money market protocol.
|
|
23
|
-
*
|
|
24
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
25
|
-
* `onError`, `retry`). Returns the unwrapped {@link OutboundSettlement} on success: a tx pair, or
|
|
26
|
-
* from Tron the relay's `trackingId` beside the destination tx.
|
|
27
|
-
*/
|
|
15
|
+
/** Throws on SDK failure; resolves to an {@link OutboundSettlement} (tx pair, or Tron relay `trackingId` + dst tx). */
|
|
28
16
|
export function useBorrow<K extends SpokeChainKey = SpokeChainKey>({
|
|
29
17
|
mutationOptions,
|
|
30
18
|
}: MutationHookParams<OutboundSettlement<K>, UseBorrowVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -6,19 +6,8 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
6
6
|
export type UseEModesParams = ReadHookParams<EmodeDataHumanized[]>;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* A category's LTV replaces the reserve's own when a user opts into it, so anything projecting
|
|
13
|
-
* borrowing power for an eMode position must read it from here rather than from the reserve.
|
|
14
|
-
* Categories only change by governance, so this is not polled.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const { data: categories } = useEModes();
|
|
19
|
-
* const cat = categories?.find(c => Number(c.id) === selected);
|
|
20
|
-
* const ltv = Number(cat?.eMode.ltv ?? 0) / 10_000;
|
|
21
|
-
* ```
|
|
9
|
+
* A category's LTV replaces the reserve's own when a user opts in, so eMode borrow-power projections
|
|
10
|
+
* must read it from here. Categories change only by governance, so this is not polled.
|
|
22
11
|
*/
|
|
23
12
|
export function useEModes({ queryOptions }: UseEModesParams = {}): UseQueryResult<EmodeDataHumanized[], Error> {
|
|
24
13
|
const { sodax } = useSodaxContext();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { MoneyMarketParams, SpokeChainKey } from '@sodax/sdk';
|
|
3
|
+
import type { QueryObserverOptions } from '@tanstack/react-query';
|
|
4
|
+
|
|
5
|
+
// No renderer, per the package convention: capture the options bag and drive a real observer with it.
|
|
6
|
+
let captured: QueryObserverOptions<boolean, Error> | undefined;
|
|
7
|
+
|
|
8
|
+
const isAllowanceValid = vi.fn();
|
|
9
|
+
vi.mock('../shared/useSodaxContext.js', () => ({
|
|
10
|
+
useSodaxContext: () => ({ sodax: { moneyMarket: { isAllowanceValid } } }),
|
|
11
|
+
}));
|
|
12
|
+
vi.mock('@tanstack/react-query', async importOriginal => ({
|
|
13
|
+
...(await importOriginal<typeof import('@tanstack/react-query')>()),
|
|
14
|
+
useQuery: (options: QueryObserverOptions<boolean, Error>) => {
|
|
15
|
+
captured = options;
|
|
16
|
+
return {};
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const { QueryClient, QueryObserver } = await import('@tanstack/react-query');
|
|
21
|
+
const { useMMAllowance } = await import('./useMMAllowance.js');
|
|
22
|
+
|
|
23
|
+
type Action = 'supply' | 'borrow' | 'withdraw' | 'repay';
|
|
24
|
+
|
|
25
|
+
const observe = (action: Action) => {
|
|
26
|
+
const fields = { srcChainKey: '0xa4b1.arbitrum', token: '0xtoken', action };
|
|
27
|
+
// The hook only reads these fields; a full MoneyMarketParams needs real chain/wallet config.
|
|
28
|
+
const payload = fields as unknown as MoneyMarketParams<SpokeChainKey>;
|
|
29
|
+
useMMAllowance({ params: { payload } });
|
|
30
|
+
if (!captured) throw new Error('useQuery was not called');
|
|
31
|
+
const client = new QueryClient();
|
|
32
|
+
return { client, result: new QueryObserver(client, captured).getCurrentResult() };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
captured = undefined;
|
|
37
|
+
isAllowanceValid.mockReset();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('useMMAllowance', () => {
|
|
41
|
+
it.each<Action>(['borrow', 'withdraw'])('reports %s as approved without querying the SDK', action => {
|
|
42
|
+
const { client, result } = observe(action);
|
|
43
|
+
expect(result.data).toBe(true);
|
|
44
|
+
expect(result.isLoading).toBe(false);
|
|
45
|
+
expect(isAllowanceValid).not.toHaveBeenCalled();
|
|
46
|
+
client.clear();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it.each<Action>(['supply', 'repay'])('leaves %s pending until the SDK answers', action => {
|
|
50
|
+
const { client, result } = observe(action);
|
|
51
|
+
expect(result.data).toBeUndefined();
|
|
52
|
+
expect(captured?.enabled).toBe(true);
|
|
53
|
+
client.clear();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -12,19 +12,8 @@ export type UseMMAllowanceParams<K extends SpokeChainKey> = ReadHookParams<
|
|
|
12
12
|
>;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* Skips the on-chain check entirely for `borrow` and `withdraw` actions — those don't require
|
|
18
|
-
* approval, and the SDK already short-circuits to `true` for them. The early `enabled: false`
|
|
19
|
-
* here additionally avoids a render flash with `isLoading: true`.
|
|
20
|
-
*
|
|
21
|
-
* The query key matches the invalidation keys emitted by `useMMApprove` and the four mutation
|
|
22
|
-
* hooks: `['mm', 'allowance', srcChainKey, token, action]`.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* const { data: hasAllowance } = useMMAllowance({ params: { payload: supplyParams } });
|
|
27
|
-
* ```
|
|
15
|
+
* `borrow`/`withdraw` need no approval: the query stays disabled and `data` is seeded with `true`. Query key must
|
|
16
|
+
* match the `['mm', 'allowance', srcChainKey, token, action]` invalidations from `useMMApprove` and mutations.
|
|
28
17
|
*/
|
|
29
18
|
export function useMMAllowance<K extends SpokeChainKey>({
|
|
30
19
|
params,
|
|
@@ -32,6 +21,7 @@ export function useMMAllowance<K extends SpokeChainKey>({
|
|
|
32
21
|
}: UseMMAllowanceParams<K> = {}): UseQueryResult<boolean, Error> {
|
|
33
22
|
const { sodax } = useSodaxContext();
|
|
34
23
|
const payload = params?.payload;
|
|
24
|
+
const needsApproval = payload?.action !== 'borrow' && payload?.action !== 'withdraw';
|
|
35
25
|
|
|
36
26
|
return useQuery<boolean, Error>({
|
|
37
27
|
queryKey: ['mm', 'allowance', payload?.srcChainKey, payload?.token, payload?.action],
|
|
@@ -40,8 +30,7 @@ export function useMMAllowance<K extends SpokeChainKey>({
|
|
|
40
30
|
throw new Error('Params are required');
|
|
41
31
|
}
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
if (payload.action === 'borrow' || payload.action === 'withdraw') {
|
|
33
|
+
if (!needsApproval) {
|
|
45
34
|
return true;
|
|
46
35
|
}
|
|
47
36
|
|
|
@@ -49,7 +38,8 @@ export function useMMAllowance<K extends SpokeChainKey>({
|
|
|
49
38
|
if (!result.ok) throw result.error;
|
|
50
39
|
return result.value;
|
|
51
40
|
},
|
|
52
|
-
|
|
41
|
+
initialData: () => (payload && !needsApproval ? true : undefined),
|
|
42
|
+
enabled: !!payload && needsApproval,
|
|
53
43
|
refetchInterval: 5000,
|
|
54
44
|
gcTime: 0,
|
|
55
45
|
...queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/mm/useMMApprove.ts
|
|
2
1
|
import type { MoneyMarketApproveActionParams, SpokeChainKey, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,24 +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 useMMApprove}. Generic over `K extends SpokeChainKey` (defaults
|
|
11
|
-
* to the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
12
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
13
|
-
*/
|
|
14
8
|
export type UseMMApproveVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
15
9
|
MoneyMarketApproveActionParams<K, false>,
|
|
16
10
|
'raw'
|
|
17
11
|
>;
|
|
18
12
|
|
|
19
|
-
/**
|
|
20
|
-
* React hook for approving ERC-20 token spending (or trustline establishment) for a Sodax money
|
|
21
|
-
* market action.
|
|
22
|
-
*
|
|
23
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
24
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success. Invalidates the matching
|
|
25
|
-
* `['mm', 'allowance', srcChainKey, token, action]` query on confirmed success.
|
|
26
|
-
*/
|
|
13
|
+
/** Throws on SDK failure; invalidates the matching `['mm', 'allowance', ...]` query on success. */
|
|
27
14
|
export function useMMApprove<K extends SpokeChainKey = SpokeChainKey>({
|
|
28
15
|
mutationOptions,
|
|
29
16
|
}: MutationHookParams<TxReturnType<K, false>, UseMMApproveVars<K>> = {}): SafeUseMutationResult<
|
package/src/hooks/mm/useRepay.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/mm/useRepay.ts
|
|
2
1
|
import type { MoneyMarketRepayActionParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,19 +7,9 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
|
|
|
8
7
|
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
9
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* Mutation variables for {@link useRepay}. Generic over `K extends SpokeChainKey` (defaults to
|
|
13
|
-
* the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
14
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
15
|
-
*/
|
|
16
10
|
export type UseRepayVars<K extends SpokeChainKey = SpokeChainKey> = Omit<MoneyMarketRepayActionParams<K, false>, 'raw'>;
|
|
17
11
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for repaying a borrow in the Sodax money market protocol.
|
|
20
|
-
*
|
|
21
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
22
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
23
|
-
*/
|
|
12
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
24
13
|
export function useRepay<K extends SpokeChainKey = SpokeChainKey>({
|
|
25
14
|
mutationOptions,
|
|
26
15
|
}: MutationHookParams<TxHashPair, UseRepayVars<K>> = {}): SafeUseMutationResult<TxHashPair, Error, UseRepayVars<K>> {
|
|
@@ -5,10 +5,6 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseReservesDataParams = ReadHookParams<readonly [readonly AggregatedReserveData[], BaseCurrencyInfo]>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* React hook for fetching the latest aggregated reserves data and base-currency info from the
|
|
10
|
-
* Sodax money market.
|
|
11
|
-
*/
|
|
12
8
|
export function useReservesData({
|
|
13
9
|
queryOptions,
|
|
14
10
|
}: UseReservesDataParams = {}): UseQueryResult<readonly [readonly AggregatedReserveData[], BaseCurrencyInfo], Error> {
|
|
@@ -5,10 +5,6 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseReservesHumanizedParams = ReadHookParams<ReservesDataHumanized>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* React hook for fetching the human-readable (decimal-normalized, string-formatted) reserves
|
|
10
|
-
* snapshot from the Sodax money market.
|
|
11
|
-
*/
|
|
12
8
|
export function useReservesHumanized({
|
|
13
9
|
queryOptions,
|
|
14
10
|
}: UseReservesHumanizedParams = {}): UseQueryResult<ReservesDataHumanized, Error> {
|
|
@@ -5,10 +5,6 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseReservesListParams = ReadHookParams<readonly Address[]>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* React hook for fetching the list of reserve asset addresses currently registered in the
|
|
10
|
-
* Sodax money market.
|
|
11
|
-
*/
|
|
12
8
|
export function useReservesList({
|
|
13
9
|
queryOptions,
|
|
14
10
|
}: UseReservesListParams = {}): UseQueryResult<readonly Address[], Error> {
|
|
@@ -7,10 +7,6 @@ export type ReserveUsdFormat = ReserveDataHumanized & FormatReserveUSDResponse;
|
|
|
7
7
|
|
|
8
8
|
export type UseReservesUsdFormatParams = ReadHookParams<ReserveUsdFormat[]>;
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* React hook returning reserves with USD-formatted values for the Sodax money market.
|
|
12
|
-
* Chains `getReservesHumanized` → `buildReserveDataWithPrice` → `formatReservesUSD`.
|
|
13
|
-
*/
|
|
14
10
|
export function useReservesUsdFormat({
|
|
15
11
|
queryOptions,
|
|
16
12
|
}: UseReservesUsdFormatParams = {}): UseQueryResult<ReserveUsdFormat[], Error> {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/mm/useSupply.ts
|
|
2
1
|
import type { MoneyMarketSupplyActionParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,34 +7,12 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
|
|
|
8
7
|
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
9
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* Mutation variables for {@link useSupply}. Generic over `K extends SpokeChainKey` (defaults to
|
|
13
|
-
* the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
14
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
15
|
-
*/
|
|
16
10
|
export type UseSupplyVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
17
11
|
MoneyMarketSupplyActionParams<K, false>,
|
|
18
12
|
'raw'
|
|
19
13
|
>;
|
|
20
14
|
|
|
21
|
-
/**
|
|
22
|
-
* React hook for supplying tokens to the Sodax money market protocol.
|
|
23
|
-
*
|
|
24
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
25
|
-
* `onError`, `retry`). Returns the unwrapped `TxHashPair` on success.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```tsx
|
|
29
|
-
* const walletProvider = useWalletProvider({ xChainId: chainKey });
|
|
30
|
-
* const { mutateAsync: supply, isError, error } = useSupply();
|
|
31
|
-
* if (!walletProvider) return;
|
|
32
|
-
* try {
|
|
33
|
-
* const { spokeTxHash, hubTxHash } = await supply({ params: supplyParams, walletProvider });
|
|
34
|
-
* } catch (e) {
|
|
35
|
-
* // surfaced via mutation.error / onError
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
15
|
+
/** Throws on SDK failure (React Query error state); resolves to the unwrapped `TxHashPair`. */
|
|
39
16
|
export function useSupply<K extends SpokeChainKey = SpokeChainKey>({
|
|
40
17
|
mutationOptions,
|
|
41
18
|
}: MutationHookParams<TxHashPair, UseSupplyVars<K>> = {}): SafeUseMutationResult<TxHashPair, Error, UseSupplyVars<K>> {
|
|
@@ -13,13 +13,6 @@ export type UseUserFormattedSummaryParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook returning the user's formatted money market portfolio summary (collateral, borrows,
|
|
18
|
-
* health factor, available borrow power, etc.) for the given spoke chain.
|
|
19
|
-
*
|
|
20
|
-
* Internally chains `getReservesHumanized` → `formatReservesUSD` → `getUserReservesHumanized`
|
|
21
|
-
* → `formatUserSummary`.
|
|
22
|
-
*/
|
|
23
16
|
export function useUserFormattedSummary({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -13,10 +13,6 @@ export type UseUserReservesDataParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook for fetching the raw user reserves data (positions on the hub) for a given spoke
|
|
18
|
-
* chain and user address.
|
|
19
|
-
*/
|
|
20
16
|
export function useUserReservesData({
|
|
21
17
|
params,
|
|
22
18
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/mm/useWithdraw.ts
|
|
2
1
|
import type { MoneyMarketWithdrawActionParams, SpokeChainKey, OutboundSettlement } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,23 +7,12 @@ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMu
|
|
|
8
7
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
9
8
|
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* Mutation variables for {@link useWithdraw}. Generic over `K extends SpokeChainKey` (defaults to
|
|
13
|
-
* the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
14
|
-
* `walletProvider` and `params.srcChainKey` types.
|
|
15
|
-
*/
|
|
16
10
|
export type UseWithdrawVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
17
11
|
MoneyMarketWithdrawActionParams<K, false>,
|
|
18
12
|
'raw'
|
|
19
13
|
>;
|
|
20
14
|
|
|
21
|
-
/**
|
|
22
|
-
* React hook for withdrawing supplied tokens from the Sodax money market protocol.
|
|
23
|
-
*
|
|
24
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
25
|
-
* `onError`, `retry`). Returns the unwrapped {@link OutboundSettlement} on success: a tx pair, or
|
|
26
|
-
* from Tron the relay's `trackingId` beside the destination tx.
|
|
27
|
-
*/
|
|
15
|
+
/** Throws on SDK failure; resolves to an {@link OutboundSettlement} (tx pair, or Tron relay `trackingId` + dst tx). */
|
|
28
16
|
export function useWithdraw<K extends SpokeChainKey = SpokeChainKey>({
|
|
29
17
|
mutationOptions,
|
|
30
18
|
}: MutationHookParams<OutboundSettlement<K>, UseWithdrawVars<K>> = {}): SafeUseMutationResult<
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/partner/useApproveToken.ts
|
|
2
1
|
import type { FeeTokenApproveAction, HubChainKey, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -10,12 +9,7 @@ export type UseApproveTokenVars = Omit<FeeTokenApproveAction<HubChainKey, false>
|
|
|
10
9
|
|
|
11
10
|
type ApproveTokenData = TxReturnType<HubChainKey, false>;
|
|
12
11
|
|
|
13
|
-
/**
|
|
14
|
-
* React hook to approve a token to the protocol-intents contract on Sonic with max allowance.
|
|
15
|
-
*
|
|
16
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
17
|
-
* `onError`, `retry`). Returns the unwrapped tx return value on success.
|
|
18
|
-
*/
|
|
12
|
+
/** Approves max allowance to the protocol-intents contract on Sonic. */
|
|
19
13
|
export function useApproveToken({
|
|
20
14
|
mutationOptions,
|
|
21
15
|
}: MutationHookParams<ApproveTokenData, UseApproveTokenVars> = {}): SafeUseMutationResult<
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/partner/useFeeClaimSwap.ts
|
|
2
1
|
import type { HubChainKey, IntentAutoSwapResult, PartnerFeeClaimSwapAction } 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 UseFeeClaimSwapVars = Omit<PartnerFeeClaimSwapAction<HubChainKey, false>, 'raw'>;
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* React hook to create a partner-fee auto-swap intent and wait for the solver execution.
|
|
13
|
-
*
|
|
14
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
15
|
-
* `onError`, `retry`). Returns the unwrapped `IntentAutoSwapResult` on success.
|
|
16
|
-
*/
|
|
10
|
+
/** Creates a partner-fee auto-swap intent and waits for solver execution. */
|
|
17
11
|
export function useFeeClaimSwap({
|
|
18
12
|
mutationOptions,
|
|
19
13
|
}: MutationHookParams<IntentAutoSwapResult, UseFeeClaimSwapVars> = {}): SafeUseMutationResult<
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/partner/useFeeClaimWithdraw.ts
|
|
2
1
|
import {
|
|
3
2
|
ChainKeys,
|
|
4
3
|
type Address,
|
|
@@ -15,13 +14,7 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
15
14
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
16
15
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
17
16
|
|
|
18
|
-
/**
|
|
19
|
-
* Mutation variables for {@link useFeeClaimWithdraw}. Maps a partner fee balance to a
|
|
20
|
-
* Sonic-sourced bridge: `feeToken` is the wrapped hub-asset address on Sonic
|
|
21
|
-
* (`PartnerFeeClaimAssetBalance.address`); `dstToken` is the original token address on
|
|
22
|
-
* `dstChainKey` (`PartnerFeeClaimAssetBalance.originalAddress`, or `feeToken` for same-chain
|
|
23
|
-
* delivery to a Sonic address).
|
|
24
|
-
*/
|
|
17
|
+
/** `feeToken` is the hub asset `address` on Sonic; `dstToken` is its `originalAddress` (or `feeToken` for Sonic). */
|
|
25
18
|
export type UseFeeClaimWithdrawVars = {
|
|
26
19
|
params: {
|
|
27
20
|
srcAddress: string;
|
|
@@ -35,18 +28,8 @@ export type UseFeeClaimWithdrawVars = {
|
|
|
35
28
|
};
|
|
36
29
|
|
|
37
30
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* For fees the partner wants to keep as-is (the desired output equals the fee token, e.g. BTC→BTC),
|
|
41
|
-
* an auto-swap is impossible — the solver rejects a same-token swap. This bridges the wrapped fee
|
|
42
|
-
* token from Sonic to its native chain (or transfers it on Sonic when `dstChainKey` is Sonic),
|
|
43
|
-
* bypassing the solver entirely.
|
|
44
|
-
*
|
|
45
|
-
* Bridging from Sonic pulls the token via the partner's hub-wallet router, which requires a prior
|
|
46
|
-
* allowance to that spender — a different approval than the ProtocolIntents one used by the swap
|
|
47
|
-
* claim. Use `useBridgeAllowance` / `useBridgeApprove` (with the same mapped bridge params) first.
|
|
48
|
-
*
|
|
49
|
-
* Throws on SDK failure so React Query's native error model engages. Returns the `TxHashPair`.
|
|
31
|
+
* Bridges a fee token out without a swap (the solver rejects same-token swaps). Needs a prior hub-wallet
|
|
32
|
+
* router allowance via `useBridgeAllowance` / `useBridgeApprove`, not the ProtocolIntents approval.
|
|
50
33
|
*/
|
|
51
34
|
export function useFeeClaimWithdraw({
|
|
52
35
|
mutationOptions,
|
|
@@ -10,10 +10,6 @@ export type UseFetchAssetsBalancesParams = ReadHookParams<
|
|
|
10
10
|
}
|
|
11
11
|
>;
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* React hook to fetch hub-asset balances on Sonic for a given EVM address. Disabled when
|
|
15
|
-
* `queryAddress` is missing. Throws on `!ok`.
|
|
16
|
-
*/
|
|
17
13
|
export function useFetchAssetsBalances({
|
|
18
14
|
params,
|
|
19
15
|
queryOptions,
|
|
@@ -10,10 +10,6 @@ export type UseGetAutoSwapPreferencesParams = ReadHookParams<
|
|
|
10
10
|
}
|
|
11
11
|
>;
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* React hook to fetch the auto-swap preferences (output token, destination chain, destination
|
|
15
|
-
* address) for a given EVM address. Disabled when `queryAddress` is missing. Throws on `!ok`.
|
|
16
|
-
*/
|
|
17
13
|
export function useGetAutoSwapPreferences({
|
|
18
14
|
params,
|
|
19
15
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/partner/useGetIntentDetails.ts
|
|
2
1
|
import type { Hex, Intent } from '@sodax/sdk';
|
|
3
2
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -8,13 +7,7 @@ const ZERO_HASH = '0x00000000000000000000000000000000000000000000000000000000000
|
|
|
8
7
|
|
|
9
8
|
export type UseGetIntentDetailsParams = ReadHookParams<Intent, { intentHash: Hex | undefined }>;
|
|
10
9
|
|
|
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
|
-
*/
|
|
10
|
+
/** Disabled for a missing or zero hash; pair with {@link useGetUserIntent} to inspect a stuck intent. */
|
|
18
11
|
export function useGetIntentDetails({
|
|
19
12
|
params,
|
|
20
13
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/partner/useGetUserIntent.ts
|
|
2
1
|
import type { GetUserIntentParams, Hex } from '@sodax/sdk';
|
|
3
2
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -6,13 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
6
5
|
|
|
7
6
|
export type UseGetUserIntentParams = ReadHookParams<Hex, Partial<GetUserIntentParams>>;
|
|
8
7
|
|
|
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
|
-
*/
|
|
8
|
+
/** A non-zero hash is an open auto-swap intent, recoverable via {@link usePartnerCancelIntent}. */
|
|
16
9
|
export function useGetUserIntent({ params, queryOptions }: UseGetUserIntentParams = {}): UseQueryResult<Hex, Error> {
|
|
17
10
|
const { sodax } = useSodaxContext();
|
|
18
11
|
const user = params?.user;
|
|
@@ -10,10 +10,6 @@ export type UseIsTokenApprovedParams = ReadHookParams<
|
|
|
10
10
|
}
|
|
11
11
|
>;
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* React hook to check whether a token is approved to the protocol-intents contract on Sonic for
|
|
15
|
-
* a given owner. Read-only; throws on `!ok`.
|
|
16
|
-
*/
|
|
17
13
|
export function useIsTokenApproved({
|
|
18
14
|
params,
|
|
19
15
|
queryOptions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/dapp-kit/src/hooks/partner/usePartnerCancelIntent.ts
|
|
2
1
|
import type { HubChainKey, PartnerFeeClaimCancelAction, TxReturnType } from '@sodax/sdk';
|
|
3
2
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
@@ -9,14 +8,8 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
9
8
|
export type UsePartnerCancelIntentVars = Omit<PartnerFeeClaimCancelAction<HubChainKey, false>, 'raw'>;
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
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.
|
|
11
|
+
* The only authorized cancel for partner auto-swap intents (ProtocolIntents is the creator, so the generic
|
|
12
|
+
* swap cancel reverts); refunds the locked input to the partner.
|
|
20
13
|
*/
|
|
21
14
|
export function usePartnerCancelIntent({
|
|
22
15
|
mutationOptions,
|