@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
|
@@ -3,11 +3,7 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
|
3
3
|
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
4
|
import type { ReadHookParams } from '../shared/types.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
* Derived from the SDK method rather than restated, so the public error union
|
|
8
|
-
* (`SolverErrorResponse | LeverageYieldLookupError`) stays exact and cannot drift.
|
|
9
|
-
* `undefined` is the disabled state, before a `payload` exists.
|
|
10
|
-
*/
|
|
6
|
+
// Derived from the SDK method so the error union cannot drift; `undefined` is the disabled state.
|
|
11
7
|
type LeverageYieldQuote = Awaited<ReturnType<Sodax['leverageYield']['getQuote']>> | undefined;
|
|
12
8
|
|
|
13
9
|
export type UseLeverageYieldQuoteParams = ReadHookParams<
|
|
@@ -27,20 +23,8 @@ function feeKeyPart(fee: PartnerFee | undefined) {
|
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
|
-
* Keys on the
|
|
31
|
-
*
|
|
32
|
-
* result. Leaving it out lets two providers configured with different fees share one cache entry,
|
|
33
|
-
* and lets a reconfigured provider serve the previous fee's quote until the next poll — either way
|
|
34
|
-
* a `minOutputAmount` derived from that quote can be unfillable.
|
|
35
|
-
*
|
|
36
|
-
* Fields are named explicitly rather than spread. A spread would carry any future bigint field on
|
|
37
|
-
* `SolverIntentQuoteRequest` straight into the key, and React Query hashes keys with
|
|
38
|
-
* `JSON.stringify`, which throws on bigint — so a spread fails *open* into a render crash, while an
|
|
39
|
-
* allow-list fails *closed* into a missing key segment. Add new fields here deliberately.
|
|
40
|
-
*
|
|
41
|
-
* `String(...)` rather than `.toString()`: a payload assembled from partially-validated form state
|
|
42
|
-
* may not have an `amount` yet, and key derivation runs during render. Staying total lets the SDK's
|
|
43
|
-
* own validation surface it as a `VALIDATION_FAILED` result instead of throwing past React Query.
|
|
26
|
+
* Keys on the effective fee (configured fallback included) and an explicit field allow-list, since a spread could carry
|
|
27
|
+
* a bigint into the key; `String(amount)` keeps render-time key derivation total for half-filled form state.
|
|
44
28
|
*/
|
|
45
29
|
function quoteKeyPart(payload: LeverageYieldQuoteParams | undefined, effectiveFee: PartnerFee | undefined) {
|
|
46
30
|
if (!payload) return undefined;
|
|
@@ -75,41 +59,8 @@ export function getLeverageYieldQuoteQueryOptions({
|
|
|
75
59
|
}
|
|
76
60
|
|
|
77
61
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* `quoted_amount` to size `minOutputAmount`.
|
|
81
|
-
*
|
|
82
|
-
* Use this rather than {@link useQuote}: the swap quote deducts the effective *swap* fee, while a
|
|
83
|
-
* vault intent charges the effective *leverage-yield* fee, so the two disagree whenever the feature
|
|
84
|
-
* fees differ. When overriding the fee per intent, pass the same `partnerFee` here and to whichever
|
|
85
|
-
* builder you use — `useLeverageYieldDeposit`, `useLeverageYieldWithdraw`, or
|
|
86
|
-
* `useLeverageYieldVaultSwap` — or omit it on all of them, which resolves the same configured fee on
|
|
87
|
-
* each side. Both directions are charged, so this applies to withdrawals as much as deposits.
|
|
88
|
-
*
|
|
89
|
-
* Returns the SDK `Result` as query data rather than unwrapping it, matching {@link useQuote}: a
|
|
90
|
-
* quote failure ("no path", thin liquidity) is an expected UI branch, and keeping the `Result`
|
|
91
|
-
* preserves the solver's `detail.code` instead of flattening it to an error message.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* const { data: quote } = useLeverageYieldQuote({
|
|
96
|
-
* params: {
|
|
97
|
-
* payload: {
|
|
98
|
-
* token_src: inputToken,
|
|
99
|
-
* token_src_blockchain_id: ChainKeys.ARBITRUM_MAINNET,
|
|
100
|
-
* token_dst: vault.vault,
|
|
101
|
-
* token_dst_blockchain_id: ChainKeys.SONIC_MAINNET,
|
|
102
|
-
* amount: parseUnits('1', 18),
|
|
103
|
-
* quote_type: 'exact_input',
|
|
104
|
-
* },
|
|
105
|
-
* },
|
|
106
|
-
* });
|
|
107
|
-
* if (quote?.ok) setMinOutput((quote.value.quoted_amount * 9_950n) / 10_000n);
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* @remarks
|
|
111
|
-
* - Refreshes every 3 seconds, like `useQuote` — solver prices go stale.
|
|
112
|
-
* - Disabled while `payload` is undefined.
|
|
62
|
+
* Vault deposit (vault as `token_dst`) or withdraw (as `token_src`) quote, priced on the leverage-yield fee, unlike {@link useQuote}.
|
|
63
|
+
* Pass the same `partnerFee` here as to the builder (or omit on both). Returns the SDK `Result` as data.
|
|
113
64
|
*/
|
|
114
65
|
export function useLeverageYieldQuote({
|
|
115
66
|
params,
|
|
@@ -3,14 +3,12 @@ import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
|
3
3
|
import type { Address, SpokeChainKey } from '@sodax/sdk';
|
|
4
4
|
import type { ReadHookParams } from '../shared/types.js';
|
|
5
5
|
|
|
6
|
-
/** A single `(chain, hub-wallet holder, share balance)` row produced by {@link useLeverageYieldShareBalances}. */
|
|
7
6
|
export type LeverageYieldShareHolding = {
|
|
8
7
|
chainKey: SpokeChainKey;
|
|
9
8
|
holder: Address;
|
|
10
9
|
shares: bigint;
|
|
11
10
|
};
|
|
12
11
|
|
|
13
|
-
/** A `(chainKey, EOA address)` pair the user controls — one per spoke chain they may hold shares under. */
|
|
14
12
|
export type LeverageYieldShareHolder = {
|
|
15
13
|
chainKey: SpokeChainKey;
|
|
16
14
|
address: string;
|
|
@@ -21,30 +19,7 @@ export type UseLeverageYieldShareBalancesParams = ReadHookParams<
|
|
|
21
19
|
{ vault: Address | undefined; holders: readonly LeverageYieldShareHolder[] | undefined }
|
|
22
20
|
>;
|
|
23
21
|
|
|
24
|
-
/**
|
|
25
|
-
* Reads a user's leverage-vault share (`lsoda*`) balances across every chain they may hold a
|
|
26
|
-
* position under — one query per holder, fanned out via `useQueries`.
|
|
27
|
-
*
|
|
28
|
-
* For each `(chainKey, address)` the holder is resolved to the address that actually owns the
|
|
29
|
-
* shares: the user's **derived hub wallet** on every chain, including the hub itself. Leverage
|
|
30
|
-
* deposits always deliver `lsoda*` to `getUserHubWalletAddress(srcAddress, srcChainKey)` (the
|
|
31
|
-
* CREATE3 user-router on Sonic for a hub-sourced deposit, the per-spoke hub wallet otherwise) —
|
|
32
|
-
* never the bare EOA — so a hub-chain deposit's shares live in the router, not the signing EOA.
|
|
33
|
-
* Resolving the holder the same way the deposit does is what makes a Sonic-sourced position show
|
|
34
|
-
* up here instead of reading a stale zero off the EOA.
|
|
35
|
-
*
|
|
36
|
-
* Returns the raw `useQueries` result array (15s refresh per query); callers aggregate as needed
|
|
37
|
-
* (e.g. sum `shares` for a headline total, or pick the row for the active chain).
|
|
38
|
-
*
|
|
39
|
-
* `useQueries` has no top-level options slot, so `queryOptions` is spread into every individual
|
|
40
|
-
* query config (and applies uniformly to each holder's query).
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const balances = useLeverageYieldShareBalances({ params: { vault: vault.vault, holders } });
|
|
45
|
-
* const total = balances.reduce((acc, q) => acc + (q.data?.shares ?? 0n), 0n);
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
22
|
+
/** One `lsoda*` share-balance query per `(chainKey, EOA)` holder; `queryOptions` applies to each query. */
|
|
48
23
|
export function useLeverageYieldShareBalances({
|
|
49
24
|
params,
|
|
50
25
|
queryOptions,
|
|
@@ -61,9 +36,7 @@ export function useLeverageYieldShareBalances({
|
|
|
61
36
|
enabled: !!vault,
|
|
62
37
|
queryFn: async (): Promise<LeverageYieldShareHolding> => {
|
|
63
38
|
if (!vault) throw new Error('vault is required');
|
|
64
|
-
//
|
|
65
|
-
// shares to getUserHubWalletAddress(...), the CREATE3 router on Sonic, never the EOA,
|
|
66
|
-
// so reading balanceOf(EOA) for the hub chain would always come back zero.
|
|
39
|
+
// Hub wallet even on the hub chain: deposits deliver shares there, never to the EOA.
|
|
67
40
|
const holder = await sodax.hubProvider.getUserHubWalletAddress(address, chainKey);
|
|
68
41
|
const result = await sodax.leverageYield.getShareBalance(vault, holder);
|
|
69
42
|
if (!result.ok) throw result.error;
|
|
@@ -5,15 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseLeverageYieldTotalAssetsParams = ReadHookParams<bigint, { vault: Address | undefined }>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Reads a leverage-yield vault's total underlying assets (vault-asset units, 18 decimals) —
|
|
10
|
-
* i.e. its TVL. Moves slowly, so the default refresh is 60s.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const { data: tvl } = useLeverageYieldTotalAssets({ params: { vault: vault.vault } });
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
8
|
+
/** Vault TVL in vault-asset units (18 decimals). */
|
|
17
9
|
export function useLeverageYieldTotalAssets({
|
|
18
10
|
params,
|
|
19
11
|
queryOptions,
|
|
@@ -6,37 +6,14 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
7
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useLeverageYieldVaultSwap}. Generic over `K extends SpokeChainKey`
|
|
11
|
-
* (defaults to the full union). Sophisticated callers can lock K at the hook call site to narrow
|
|
12
|
-
* the `walletProvider` and `params.srcChainKey` types.
|
|
13
|
-
*/
|
|
14
9
|
export type UseLeverageYieldVaultSwapVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
15
10
|
VaultSwapActionParams<K, false>,
|
|
16
11
|
'raw'
|
|
17
12
|
>;
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* Spread a `LeverageYieldSwapPayload` built by {@link useLeverageYieldDeposit} /
|
|
23
|
-
* {@link useLeverageYieldWithdraw} into `mutate` alongside the wallet provider:
|
|
24
|
-
* `vaultSwap({ ...payload, walletProvider })`. Runs `sodax.leverageYield.vaultSwap`, so vault flows
|
|
25
|
-
* never touch the generic swap surface.
|
|
26
|
-
*
|
|
27
|
-
* Which transport it takes is config, not an argument. With `leverageYield.useBackendSubmitTx` on,
|
|
28
|
-
* it creates the intent and hands the broadcast tx to the leverage-yield API, which relays and
|
|
29
|
-
* post-executes server-side, falling back to the client-side path (verify → relay → notify solver)
|
|
30
|
-
* on any non-success. With it off, that client-side path runs outright. Read the effective value on
|
|
31
|
-
* `sodax.config.leverageYieldUseBackendSubmitTx` rather than assuming which way it points.
|
|
32
|
-
* Either way the resolved value is the same `VaultSwapResponse`.
|
|
33
|
-
*
|
|
34
|
-
* Pass `extras.apiKey` to key the backend leg per action, overriding the instance key. Poll the
|
|
35
|
-
* result with {@link useLeverageYieldDetailedStatus}, which reads a vault swap's status from the
|
|
36
|
-
* source-chain tx hash whichever transport completed it.
|
|
37
|
-
*
|
|
38
|
-
* Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
|
|
39
|
-
* `onError`, `retry`). Returns the unwrapped `VaultSwapResponse` on success.
|
|
15
|
+
* Executes a vault swap from a {@link useLeverageYieldDeposit} / {@link useLeverageYieldWithdraw} payload; transport
|
|
16
|
+
* (backend submit with client fallback, or client-only) follows `sodax.config.leverageYieldUseBackendSubmitTx`.
|
|
40
17
|
*/
|
|
41
18
|
export function useLeverageYieldVaultSwap<K extends SpokeChainKey = SpokeChainKey>({
|
|
42
19
|
mutationOptions,
|
|
@@ -6,24 +6,14 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
6
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
7
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Mutation variables for {@link useLeverageYieldVaultSwapWithApproval}: `useLeverageYieldVaultSwap`'s, plus
|
|
11
|
-
* `allowAccountUpgrade`, `resumeBatchId` and `resumeBatchCallCount`.
|
|
12
|
-
*/
|
|
13
9
|
export type UseLeverageYieldVaultSwapWithApprovalVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
14
10
|
VaultSwapWithApprovalParams<K>,
|
|
15
11
|
'raw'
|
|
16
12
|
>;
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
|
-
* `useLeverageYieldVaultSwap` with the deposit
|
|
20
|
-
* (`sodax.leverageYield.vaultSwapWithApproval`): approve + deposit as one EIP-5792 batch (one
|
|
21
|
-
* signature) on a batch-capable EVM wallet, otherwise approve, wait for it, then deposit. A withdraw
|
|
22
|
-
* (`hubWalletSwap`) needs no approval and runs as `useLeverageYieldVaultSwap` does.
|
|
15
|
+
* `useLeverageYieldVaultSwap` with the deposit approval folded in (EIP-5792 batch when supported, else sequential).
|
|
23
16
|
* `data.approvalStrategy` says which path ran; {@link useLeverageYieldApprovalStrategy} predicts it.
|
|
24
|
-
*
|
|
25
|
-
* Throws on SDK failure so React Query's error model engages. On success invalidates balances, the
|
|
26
|
-
* deposit allowance (read through `useSwapAllowance`) and the approval-strategy query.
|
|
27
17
|
*/
|
|
28
18
|
export function useLeverageYieldVaultSwapWithApproval<K extends SpokeChainKey = SpokeChainKey>({
|
|
29
19
|
mutationOptions,
|
|
@@ -4,25 +4,9 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
4
4
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
5
5
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
6
|
|
|
7
|
-
/** Mutation variables for {@link useLeverageYieldWithdraw} — the swap-style withdraw inputs. */
|
|
8
7
|
export type UseLeverageYieldWithdrawVars = LeverageYieldSwapWithdrawParams;
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* Builds the `LeverageYieldSwapPayload` for a leverage-yield withdraw (`lsoda*` shares → any token).
|
|
12
|
-
* The returned payload carries `hubWalletSwap: true`; spread it into
|
|
13
|
-
* {@link useLeverageYieldVaultSwap}, which authorises the hub wallet to spend the shares via a
|
|
14
|
-
* `Connection.sendMessage`.
|
|
15
|
-
*
|
|
16
|
-
* This is a builder, not an executor. Throws on SDK failure so React Query's error model engages;
|
|
17
|
-
* returns the unwrapped `LeverageYieldSwapPayload` on success.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const { mutateAsyncSafe: buildWithdraw } = useLeverageYieldWithdraw();
|
|
22
|
-
* const built = await buildWithdraw({ vault, srcChainKey, srcAddress, dstChainKey, outputToken, inputAmount, minOutputAmount });
|
|
23
|
-
* if (built.ok) vaultSwap({ ...built.value, walletProvider });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
9
|
+
/** Builds (does not execute) a withdraw payload with `hubWalletSwap: true`; spread it into {@link useLeverageYieldVaultSwap}. */
|
|
26
10
|
export function useLeverageYieldWithdraw({
|
|
27
11
|
mutationOptions,
|
|
28
12
|
}: MutationHookParams<LeverageYieldSwapPayload, UseLeverageYieldWithdrawVars> = {}): SafeUseMutationResult<
|
|
@@ -12,27 +12,15 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
12
12
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
13
13
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Mutation variables for {@link useOpenLeveragePosition}.
|
|
17
|
-
*
|
|
18
|
-
* `side` picks which asset funds the open, and the two take different params — so the union is
|
|
19
|
-
* discriminated rather than merged, and the wrong field set is a type error instead of a revert.
|
|
20
|
-
*/
|
|
15
|
+
/** Discriminated on `side` so a wrong field set is a type error rather than a revert. */
|
|
21
16
|
export type UseOpenLeveragePositionVars<K extends SpokeChainKey = SpokeChainKey> =
|
|
22
17
|
| ({ side?: 'collateral' } & Omit<SpokeExecActionParams<K, false, OpenPositionParams<K>>, 'raw'>)
|
|
23
18
|
| ({ side: 'debt' } & Omit<SpokeExecActionParams<K, false, OpenPositionFromDebtTokenParams<K>>, 'raw'>);
|
|
24
19
|
|
|
25
20
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* gets the same guarantee. Resolving means the intent is LIVE, not that the position is open: read
|
|
30
|
-
* `notified` before telling the owner to wait, since a failed notification still resolves.
|
|
31
|
-
*
|
|
32
|
-
* Positions are owned by the hub wallet, never the signing address — pass the signer as
|
|
33
|
-
* `params.srcAddress` and the SDK resolves the owner.
|
|
34
|
-
*
|
|
35
|
-
* @experimental Off-hub (spoke) origins are unverified on-chain; see the SDK method.
|
|
21
|
+
* Resolving means the intent is live, not that the position is open; check `notified`, since a failed notification still resolves.
|
|
22
|
+
* Pass the signer as `params.srcAddress`; the SDK resolves the owning hub wallet.
|
|
23
|
+
* @experimental Off-hub (spoke) origins are unverified on-chain.
|
|
36
24
|
*/
|
|
37
25
|
export function useOpenLeveragePosition<K extends SpokeChainKey = SpokeChainKey>({
|
|
38
26
|
mutationOptions,
|
|
@@ -50,8 +38,7 @@ export function useOpenLeveragePosition<K extends SpokeChainKey = SpokeChainKey>
|
|
|
50
38
|
mutationFn: async vars => unwrapResult(await sodax.leverageYield.openLeveragePosition({ ...vars, raw: false })),
|
|
51
39
|
onSuccess: async (data, vars, ctx) => {
|
|
52
40
|
invalidateBalances(queryClient, vars.params.srcChainKey);
|
|
53
|
-
// A position write
|
|
54
|
-
// partner that has to remember this leaves the UI stale after the one action it just took.
|
|
41
|
+
// A position write affects every position read (account, pending slot, list).
|
|
55
42
|
queryClient.invalidateQueries({ queryKey: ['leverageYield'] });
|
|
56
43
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
57
44
|
},
|
|
@@ -12,30 +12,15 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
12
12
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
13
13
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
14
14
|
|
|
15
|
-
/** Mutation variables for {@link useRunLeveragePositionOperation} — the calls to run as the owner. */
|
|
16
15
|
export type UseRunLeveragePositionOperationVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
17
16
|
SpokeExecActionParams<K, false, PositionOperationParams<K, PositionDirectCall>>,
|
|
18
17
|
'raw'
|
|
19
18
|
>;
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Still routed, never sent directly: the position's `onlyOwner` is the hub wallet, so a call sent
|
|
26
|
-
* from the signer reverts `NotOwner`. Locally through the wallet router on the hub, relayed from
|
|
27
|
-
* anywhere else.
|
|
28
|
-
*
|
|
29
|
-
* USE {@link useSubmitLeveragePositionIntent} FOR `increaseLeverage` AND `decreaseLeverage`. Those
|
|
30
|
-
* only post a request a solver fills later, and this hook does not notify the solver, so sending one
|
|
31
|
-
* through here creates an intent nothing will fill. It expires silently and the operation is lost.
|
|
32
|
-
* The other direction is harmless by comparison: notifying about a withdraw is noise, not damage.
|
|
33
|
-
*
|
|
34
|
-
* Balances are invalidated for `srcChainKey` because a withdraw pays out.
|
|
35
|
-
*
|
|
36
|
-
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN, and this is the hook that carries the
|
|
37
|
-
* worst of it: an exit or cancellation delivering the underlying back to the spoke it
|
|
38
|
-
* came from has never run on mainnet. Bitcoin is refused outright.
|
|
21
|
+
* Synchronous position calls (`withdraw`, `settle`, `cancel`) as the hub wallet; does not notify the solver, so
|
|
22
|
+
* use {@link useSubmitLeveragePositionIntent} for leverage changes or the intent expires unfilled.
|
|
23
|
+
* @experimental Off-hub (spoke) origins are unverified on-chain; Bitcoin is refused.
|
|
39
24
|
*/
|
|
40
25
|
export function useRunLeveragePositionOperation<K extends SpokeChainKey = SpokeChainKey>({
|
|
41
26
|
mutationOptions,
|
|
@@ -54,8 +39,7 @@ export function useRunLeveragePositionOperation<K extends SpokeChainKey = SpokeC
|
|
|
54
39
|
unwrapResult(await sodax.leverageYield.runLeveragePositionOperation({ ...vars, raw: false })),
|
|
55
40
|
onSuccess: async (data, vars, ctx) => {
|
|
56
41
|
invalidateBalances(queryClient, vars.params.srcChainKey);
|
|
57
|
-
// A position write
|
|
58
|
-
// partner that has to remember this leaves the UI stale after the one action it just took.
|
|
42
|
+
// A position write affects every position read (account, pending slot, list).
|
|
59
43
|
queryClient.invalidateQueries({ queryKey: ['leverageYield'] });
|
|
60
44
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
61
45
|
},
|
|
@@ -11,25 +11,14 @@ import type { MutationHookParams } from '../shared/types.js';
|
|
|
11
11
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
12
12
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
13
13
|
|
|
14
|
-
/** Mutation variables for {@link useSubmitLeveragePositionIntent} — the calls to run as the owner. */
|
|
15
14
|
export type UseSubmitLeveragePositionIntentVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
|
|
16
15
|
SpokeExecActionParams<K, false, PositionOperationParams<K, PositionBatchCall>>,
|
|
17
16
|
'raw'
|
|
18
17
|
>;
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* USE {@link useRunLeveragePositionOperation} for `withdraw`, `settle` and `cancel`. The split is the
|
|
25
|
-
* SDK's: those three are synchronous on the hub and need no notification, while these two only post
|
|
26
|
-
* a request a solver fills later. Sending a leverage change through the other hook leaves an intent
|
|
27
|
-
* nothing will fill, and it expires without a word.
|
|
28
|
-
*
|
|
29
|
-
* A position permits one intent at a time, so poll `useLeveragePositionPending` rather than assuming
|
|
30
|
-
* the next call may go out.
|
|
31
|
-
*
|
|
32
|
-
* @experimental Off-hub (spoke) origins are unverified on-chain; see the SDK method.
|
|
20
|
+
* Intent-posting position calls (`increaseLeverage`, `decreaseLeverage`); one intent at a time, so gate on `useLeveragePositionPending`.
|
|
21
|
+
* @experimental Off-hub (spoke) origins are unverified on-chain.
|
|
33
22
|
*/
|
|
34
23
|
export function useSubmitLeveragePositionIntent<K extends SpokeChainKey = SpokeChainKey>({
|
|
35
24
|
mutationOptions,
|
|
@@ -46,8 +35,7 @@ export function useSubmitLeveragePositionIntent<K extends SpokeChainKey = SpokeC
|
|
|
46
35
|
mutationFn: async vars =>
|
|
47
36
|
unwrapResult(await sodax.leverageYield.submitLeveragePositionIntent({ ...vars, raw: false })),
|
|
48
37
|
onSuccess: async (data, vars, ctx) => {
|
|
49
|
-
// The slot is occupied
|
|
50
|
-
// pending read has to be refetched even though nothing has filled yet.
|
|
38
|
+
// The pending slot is occupied as soon as this resolves, before any fill.
|
|
51
39
|
queryClient.invalidateQueries({ queryKey: ['leverageYield'] });
|
|
52
40
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
53
41
|
},
|
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Leverage Yield API hooks — typed React Query wrappers over `sodax.api.leverageYield.*` (the
|
|
3
|
-
* LeverageYieldApiService HTTP client). One hook per endpoint of the backend Leverage Yield API.
|
|
4
|
-
*
|
|
5
|
-
* Distinct from the on-chain `leverageYield/` hooks (`useLeverageYieldDeposit`/…), which drive the
|
|
6
|
-
* `LeverageYieldService` path (wallet → hub chain). These hooks call the backend HTTP API instead.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Vault registry
|
|
10
1
|
export * from './useLeverageYieldApiVaults.js';
|
|
11
2
|
export * from './useLeverageYieldApiVault.js';
|
|
12
3
|
|
|
13
|
-
// Vault reads
|
|
14
4
|
export * from './useLeverageYieldApiAsset.js';
|
|
15
5
|
export * from './useLeverageYieldApiPosition.js';
|
|
16
6
|
export * from './useLeverageYieldApiApr.js';
|
|
@@ -23,19 +13,16 @@ export * from './useLeverageYieldApiPreviewRedeem.js';
|
|
|
23
13
|
export * from './useLeverageYieldApiShareBalance.js';
|
|
24
14
|
export * from './useLeverageYieldApiMaxWithdraw.js';
|
|
25
15
|
|
|
26
|
-
// Quote · deadline · allowance
|
|
27
16
|
export * from './useLeverageYieldApiDepositQuote.js';
|
|
28
17
|
export * from './useLeverageYieldApiWithdrawQuote.js';
|
|
29
18
|
export * from './useLeverageYieldApiDeadline.js';
|
|
30
19
|
export * from './useLeverageYieldApiAllowance.js';
|
|
31
20
|
|
|
32
|
-
// Approve · create intent (deposit / withdraw)
|
|
33
21
|
export * from './useLeverageYieldApiApprove.js';
|
|
34
22
|
export * from './useLeverageYieldApiApproveAndBroadcast.js';
|
|
35
23
|
export * from './useLeverageYieldApiCreateDepositIntent.js';
|
|
36
24
|
export * from './useLeverageYieldApiCreateWithdrawIntent.js';
|
|
37
25
|
|
|
38
|
-
// Intent lifecycle: submit · status · cancel · hash · packet · extra-data · lookup
|
|
39
26
|
export * from './useLeverageYieldApiSubmitIntent.js';
|
|
40
27
|
export * from './useLeverageYieldApiStatus.js';
|
|
41
28
|
export * from './useLeverageYieldApiCancelIntent.js';
|
|
@@ -45,11 +32,9 @@ export * from './useLeverageYieldApiIntentExtraData.js';
|
|
|
45
32
|
export * from './useLeverageYieldApiFilledIntent.js';
|
|
46
33
|
export * from './useLeverageYieldApiIntent.js';
|
|
47
34
|
|
|
48
|
-
// Gas · fees
|
|
49
35
|
export * from './useLeverageYieldApiEstimateGas.js';
|
|
50
36
|
export * from './useLeverageYieldApiPartnerFee.js';
|
|
51
37
|
export * from './useLeverageYieldApiSolverFee.js';
|
|
52
38
|
|
|
53
|
-
// Submit-tx state machine
|
|
54
39
|
export * from './useLeverageYieldApiSubmitTx.js';
|
|
55
40
|
export * from './useLeverageYieldApiSubmitTxStatus.js';
|
|
@@ -13,14 +13,7 @@ export type UseLeverageYieldApiAllowanceParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to check whether the deposit input-token allowance is already sufficient for an intent
|
|
18
|
-
* via the leverage-yield API — `sodax.api.leverageYield.checkAllowance`. Returns `{ valid }`.
|
|
19
|
-
* (Withdraw needs no spoke allowance — it spends lsoda* from the hub wallet.)
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const { data: allowance } = useLeverageYieldApiAllowance({ params: { body: depositIntentParams } });
|
|
23
|
-
*/
|
|
16
|
+
/** Deposit-only: a withdraw needs no spoke allowance (it spends lsoda* from the hub wallet). */
|
|
24
17
|
export const useLeverageYieldApiAllowance = ({
|
|
25
18
|
params,
|
|
26
19
|
queryOptions,
|
|
@@ -5,18 +5,15 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
5
5
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Mutation variables for {@link useLeverageYieldApiApprove}. The per-request `apiConfig` override belongs here
|
|
10
|
-
* rather than at the hook level — different calls in the same component can target different
|
|
11
|
-
* endpoints without re-rendering.
|
|
12
|
-
*/
|
|
8
|
+
/** Per-call `apiConfig` so calls in one component can target different endpoints. */
|
|
13
9
|
export type UseLeverageYieldApiApproveVars = {
|
|
14
10
|
body: CreateDepositIntentParamsV2;
|
|
15
11
|
apiConfig?: RequestOverrideConfig;
|
|
16
12
|
};
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
|
-
*
|
|
15
|
+
* Returns the unsigned `{ tx, resetTx? }`; the reset must be mined before the approve.
|
|
16
|
+
* Prefer {@link useLeverageYieldApiApproveAndBroadcast}, which owns that ordering.
|
|
20
17
|
*/
|
|
21
18
|
export const useLeverageYieldApiApprove = ({
|
|
22
19
|
mutationOptions,
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* `runApprovalPlan` itself — every chain family, every progress phase — is covered by the swaps and
|
|
6
|
-
* bridge suites; this one pins what is leverage-yield-specific: the client method it asks for the
|
|
7
|
-
* plan, that the ordering survives, that errors name THIS hook, and its own invalidation key.
|
|
8
|
-
*
|
|
9
|
-
* Follows the package convention of testing hooks without a renderer: the React Query wrapper is
|
|
10
|
-
* mocked so `mutationFn` can be captured and driven directly.
|
|
2
|
+
* Pins leverage-yield specifics: client method, reset-before-approve ordering, error hook name, invalidation key.
|
|
3
|
+
* `runApprovalPlan` itself is covered by the swaps/bridge suites; React Query is mocked to capture `mutationFn`.
|
|
11
4
|
*/
|
|
12
5
|
|
|
13
6
|
import { ChainKeys } from '@sodax/sdk';
|
|
@@ -65,7 +58,6 @@ function evmProvider(calls: string[], onWait?: (hash: string) => string | void)
|
|
|
65
58
|
};
|
|
66
59
|
}
|
|
67
60
|
|
|
68
|
-
/** One render, then the captured `mutationFn` invoked with `vars`. */
|
|
69
61
|
// biome-ignore lint/suspicious/noExplicitAny: vars mirror the hook's generic mutation variables.
|
|
70
62
|
const run = (vars: any) => {
|
|
71
63
|
useLeverageYieldApiApproveAndBroadcast();
|
|
@@ -112,8 +104,7 @@ describe('useLeverageYieldApiApproveAndBroadcast', () => {
|
|
|
112
104
|
const result = await run({ body: body(ChainKeys.ARBITRUM_MAINNET), walletProvider: evmProvider(calls) });
|
|
113
105
|
|
|
114
106
|
expect(result).toEqual({ resetTxHash: RESET_HASH, approveTxHash: APPROVE_HASH });
|
|
115
|
-
// The wait
|
|
116
|
-
// the transaction `useLeverageYieldApiApprove` callers were dropping.
|
|
107
|
+
// The wait must sit between the two sends; approving over an unconfirmed reset reverts.
|
|
117
108
|
expect(calls).toEqual(['send:0xreset', `wait:${RESET_HASH}`, 'send:0xapprove', `wait:${APPROVE_HASH}`]);
|
|
118
109
|
});
|
|
119
110
|
|
|
@@ -136,8 +127,7 @@ describe('useLeverageYieldApiApproveAndBroadcast', () => {
|
|
|
136
127
|
});
|
|
137
128
|
|
|
138
129
|
it('names this hook, not a sibling, in an error from the shared plan runner', async () => {
|
|
139
|
-
// The runner is shared with
|
|
140
|
-
// leverage-yield integrator at the wrong hook.
|
|
130
|
+
// The runner is shared with swaps and bridge; a hard-coded hook name there would misdirect integrators.
|
|
141
131
|
approve.mockResolvedValue({ ok: true, value: { tx: APPROVE_TX } });
|
|
142
132
|
|
|
143
133
|
await expect(run({ body: body(ChainKeys.SOLANA_MAINNET), walletProvider: {} })).rejects.toThrow(
|
|
@@ -24,30 +24,9 @@ export type UseLeverageYieldApiApproveAndBroadcastVars<K extends SpokeChainKey =
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* Prefer this over {@link useLeverageYieldApiApprove}, which hands back the unsigned
|
|
32
|
-
* `{ tx, resetTx? }` and leaves the ordering — reset mined first, then approve — to the caller. A
|
|
33
|
-
* deposit token of the 2017 TetherToken lineage rejects an allowance change from one non-zero value
|
|
34
|
-
* to another, so broadcasting the approve without the reset spends the user's gas on a transaction
|
|
35
|
-
* that is certain to revert. Confirmation happens inside the hook, so it invalidates
|
|
36
|
-
* `['leverageYieldApi','allowance']` itself — after waiting up to about 15 seconds for the API to report
|
|
37
|
-
* the allowance as valid, since its RPC can trail the node that confirmed the approve. It resolves after
|
|
38
|
-
* that wait either way, so read the allowance rather than treating success as `valid`.
|
|
39
|
-
*
|
|
40
|
-
* Supports the chains the leverage-yield API can approve on — the hub (Sonic), EVM spokes, and
|
|
41
|
-
* Stellar. Every other chain reports its allowance as always sufficient, so approval never runs.
|
|
42
|
-
*
|
|
43
|
-
* `onProgress` reports each transaction as `{ step, phase, index, total }`, so the UI can name the
|
|
44
|
-
* wallet prompt the user is looking at instead of one flat "Approving…" across two signatures.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* const { mutateAsyncSafe: approve } = useLeverageYieldApiApproveAndBroadcast();
|
|
48
|
-
* const result = await approve({ body: depositIntentParams, walletProvider, onProgress: setStep });
|
|
49
|
-
* if (!result.ok) return;
|
|
50
|
-
* const { resetTxHash, approveTxHash } = result.value; // resetTxHash only on a guarded token
|
|
27
|
+
* Signs and confirms the deposit approval plan, mining the reset before the approve (USDT-lineage tokens revert).
|
|
28
|
+
* Resolves after waiting up to ~15s for the API allowance to turn valid, valid or not: read the allowance.
|
|
29
|
+
* Approval runs only on the hub, EVM spokes and Stellar; other chains report the allowance as always sufficient.
|
|
51
30
|
*/
|
|
52
31
|
export const useLeverageYieldApiApproveAndBroadcast = <K extends SpokeChainKey = SpokeChainKey>({
|
|
53
32
|
mutationOptions,
|
|
@@ -79,8 +58,7 @@ export const useLeverageYieldApiApproveAndBroadcast = <K extends SpokeChainKey =
|
|
|
79
58
|
return hashes;
|
|
80
59
|
},
|
|
81
60
|
onSuccess: async (data, vars, ctx) => {
|
|
82
|
-
// Awaited
|
|
83
|
-
// has actually refetched, or a stale cached `valid: false` re-enables a duplicate approval.
|
|
61
|
+
// Awaited so a stale cached `valid: false` cannot re-enable Approve before the refetch lands.
|
|
84
62
|
await queryClient.invalidateQueries({ queryKey: ['leverageYieldApi', 'allowance'] });
|
|
85
63
|
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
86
64
|
},
|
|
@@ -13,13 +13,7 @@ export type UseLeverageYieldApiAprParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to fetch the AAVE-only steady-state APR for a leverage-yield vault via the leverage-yield API —
|
|
18
|
-
* `sodax.api.leverageYield.getApr`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useLeverageYieldApiApr({ params: { vault: '0x...' } });
|
|
22
|
-
*/
|
|
16
|
+
/** AAVE-only steady-state APR; {@link useLeverageYieldApiEffectiveApr} includes LSD yield. */
|
|
23
17
|
export const useLeverageYieldApiApr = ({
|
|
24
18
|
params,
|
|
25
19
|
queryOptions,
|
|
@@ -13,13 +13,6 @@ export type UseLeverageYieldApiAssetParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to fetch the underlying hub asset for a leverage-yield vault via the leverage-yield API —
|
|
18
|
-
* `sodax.api.leverageYield.getAsset`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useLeverageYieldApiAsset({ params: { vault: '0x...' } });
|
|
22
|
-
*/
|
|
23
16
|
export const useLeverageYieldApiAsset = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -5,19 +5,13 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
5
5
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Mutation variables for {@link useLeverageYieldApiCancelIntent}. The per-request `apiConfig` override belongs here
|
|
10
|
-
* rather than at the hook level — different calls in the same component can target different
|
|
11
|
-
* endpoints without re-rendering.
|
|
12
|
-
*/
|
|
8
|
+
/** Per-call `apiConfig` so calls in one component can target different endpoints. */
|
|
13
9
|
export type UseLeverageYieldApiCancelIntentVars = {
|
|
14
10
|
body: CancelIntentRequestV2;
|
|
15
11
|
apiConfig?: RequestOverrideConfig;
|
|
16
12
|
};
|
|
17
13
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook to build an unsigned cancel-intent transaction via the leverage-yield API — `sodax.api.leverageYield.cancelIntent`.
|
|
20
|
-
*/
|
|
14
|
+
/** Builds an unsigned cancel-intent tx for the caller to sign and broadcast. */
|
|
21
15
|
export const useLeverageYieldApiCancelIntent = ({
|
|
22
16
|
mutationOptions,
|
|
23
17
|
}: MutationHookParams<CancelIntentResponseV2, UseLeverageYieldApiCancelIntentVars> = {}): SafeUseMutationResult<
|
|
@@ -5,19 +5,13 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
5
5
|
import type { MutationHookParams } from '../shared/types.js';
|
|
6
6
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Mutation variables for {@link useLeverageYieldApiCreateDepositIntent}. The per-request `apiConfig` override belongs here
|
|
10
|
-
* rather than at the hook level — different calls in the same component can target different
|
|
11
|
-
* endpoints without re-rendering.
|
|
12
|
-
*/
|
|
8
|
+
/** Per-call `apiConfig` so calls in one component can target different endpoints. */
|
|
13
9
|
export type UseLeverageYieldApiCreateDepositIntentVars = {
|
|
14
10
|
body: CreateDepositIntentParamsV2;
|
|
15
11
|
apiConfig?: RequestOverrideConfig;
|
|
16
12
|
};
|
|
17
13
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook to build an unsigned deposit create-intent transaction (any token → lsoda* shares) via the leverage-yield API — `sodax.api.leverageYield.createDepositIntent`.
|
|
20
|
-
*/
|
|
14
|
+
/** Builds an unsigned deposit create-intent tx (any token → lsoda* shares). */
|
|
21
15
|
export const useLeverageYieldApiCreateDepositIntent = ({
|
|
22
16
|
mutationOptions,
|
|
23
17
|
}: MutationHookParams<CreateIntentResponseV2, UseLeverageYieldApiCreateDepositIntentVars> = {}): SafeUseMutationResult<
|