@sodax/dapp-kit 2.4.0-rc.2 → 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 +1 -1
- package/dist/index.d.ts +279 -2428
- package/dist/index.mjs +15 -24
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +4 -29
- package/src/hooks/_mutationContract.test.ts +1 -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/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 +1 -2
- package/src/hooks/shared/useEstablishXrpTrustline.ts +3 -5
- 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 +1 -5
- package/src/hooks/shared/useXrpGate.test.ts +1 -3
- package/src/hooks/shared/useXrpGate.ts +2 -3
- 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 +1 -2
- package/src/hooks/swap/useSwapLifecycle.ts +9 -27
- 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/nearStorageGate.ts +3 -14
- package/src/utils/stellarGate.ts +3 -16
- package/src/utils/swapLifecycle.ts +7 -26
- package/src/utils/xrpGate.ts +1 -4
|
@@ -9,22 +9,8 @@ export type UseLeveragePositionPendingParams = ReadHookParams<
|
|
|
9
9
|
>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* A position's operation slot
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* Gate leverage controls on `isLive` — a position permits one intent at a time, so offering a button
|
|
16
|
-
* that can only revert is worse than disabling it. Offer a settle on `needsSettle`: that is the state
|
|
17
|
-
* where the intent is gone but the position still holds the grant and any contribution, and it is
|
|
18
|
-
* invisible from `isLive` alone.
|
|
19
|
-
*
|
|
20
|
-
* Polled, because both change without the user acting: a solver fills, or the intent expires. The
|
|
21
|
-
* interval sits well inside the 5-minute intent deadline so a resolution shows up while it matters.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const { data: slot } = useLeveragePositionPending({ params: { position } });
|
|
26
|
-
* if (slot?.needsSettle) offerSettle();
|
|
27
|
-
* ```
|
|
12
|
+
* A position's operation slot. Gate controls on `isLive` (one intent at a time); offer settle on `needsSettle`.
|
|
13
|
+
* Polled well inside the 5-minute intent deadline since fills/expiry happen without user action.
|
|
28
14
|
*/
|
|
29
15
|
export function useLeveragePositionPending({
|
|
30
16
|
params,
|
|
@@ -5,21 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseLeveragePositionsParams = ReadHookParams<readonly Address[], { owner: Address | undefined }>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Lists the leverage-position clones owned by `owner`, in creation order.
|
|
10
|
-
*
|
|
11
|
-
* Positions are the unpooled counterpart to leverage-yield vaults: each is its own AAVE
|
|
12
|
-
* account, so one owner can hold several at different eMode categories and leverage tiers.
|
|
13
|
-
* There is no static registry — discovery goes through the factory.
|
|
14
|
-
*
|
|
15
|
-
* Requires `leverageYield.positionFactory` in the `Sodax` config; without it the underlying
|
|
16
|
-
* SDK call fails with a lookup error rather than guessing an address.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const { data: positions } = useLeveragePositions({ params: { owner } });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
8
|
+
/** Position clones owned by a hub `owner`, in creation order. Requires `leverageYield.positionFactory` in the Sodax config. */
|
|
23
9
|
export function useLeveragePositions({
|
|
24
10
|
params,
|
|
25
11
|
queryOptions,
|
|
@@ -8,21 +8,7 @@ export type UseLeveragePositionsForUserParams = ReadHookParams<
|
|
|
8
8
|
{ spokeChainKey: SpokeChainKey | undefined; spokeAddress: string | undefined }
|
|
9
9
|
>;
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Lists a user's leverage positions from their spoke-side address and chain.
|
|
13
|
-
*
|
|
14
|
-
* Positions are owned by the user's hub wallet, not their EOA, so discovery resolves that address
|
|
15
|
-
* first — the wallet router for a Sonic user, the cross-chain wallet for a spoke user, via one
|
|
16
|
-
* call. Use this in user-facing code; {@link useLeveragePositions} takes a hub address directly
|
|
17
|
-
* and will find nothing if handed an EOA.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const { data: positions } = useLeveragePositionsForUser({
|
|
22
|
-
* params: { spokeChainKey: chain, spokeAddress: account.address },
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
11
|
+
/** Resolves the user's hub wallet first, since positions are owned by it; {@link useLeveragePositions} finds nothing for an EOA. */
|
|
26
12
|
export function useLeveragePositionsForUser({
|
|
27
13
|
params,
|
|
28
14
|
queryOptions,
|
|
@@ -7,7 +7,6 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
7
7
|
export type UseLeverageYieldApprovalStrategyParams<K extends SpokeChainKey = SpokeChainKey> = ReadHookParams<
|
|
8
8
|
ApprovalStrategy,
|
|
9
9
|
{
|
|
10
|
-
/** The payload `useLeverageYieldDeposit` / `useLeverageYieldWithdraw` built. */
|
|
11
10
|
payload: LeverageYieldSwapPayload | undefined;
|
|
12
11
|
walletProvider: GetWalletProviderType<K> | undefined;
|
|
13
12
|
/** `false` keeps a wallet that would first ask to upgrade the account (EIP-5792 `'ready'`) off the batch path. Defaults to `true`. */
|
|
@@ -16,11 +15,7 @@ export type UseLeverageYieldApprovalStrategyParams<K extends SpokeChainKey = Spo
|
|
|
16
15
|
>;
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
* Which approval path {@link useLeverageYieldVaultSwapWithApproval} would take
|
|
20
|
-
* (always for a withdraw), `'atomic-batch'` (approve + deposit in one EIP-5792 signature) or
|
|
21
|
-
* `'sequential'` (approve, then deposit). Use it to label the deposit button. Pass the same
|
|
22
|
-
* `allowAccountUpgrade` you give the vault swap.
|
|
23
|
-
*
|
|
18
|
+
* Which approval path {@link useLeverageYieldVaultSwapWithApproval} would take; pass it the same `allowAccountUpgrade`.
|
|
24
19
|
* Not polled: the vault swap invalidates it on success and re-reads the strategy at execution.
|
|
25
20
|
*/
|
|
26
21
|
export function useLeverageYieldApprovalStrategy<K extends SpokeChainKey = SpokeChainKey>({
|
|
@@ -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 useLeverageYieldDeposit} — the swap-style deposit inputs. */
|
|
8
7
|
export type UseLeverageYieldDepositVars = LeverageYieldSwapDepositParams;
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* Builds the `LeverageYieldSwapPayload` for a leverage-yield deposit (any token → `lsoda*` shares,
|
|
12
|
-
* delivered to the user's hub wallet). Spread the returned payload into
|
|
13
|
-
* {@link useLeverageYieldVaultSwap}.
|
|
14
|
-
*
|
|
15
|
-
* This is a builder, not an executor — it derives the hub wallet and assembles the intent; the
|
|
16
|
-
* actual swap is relayed by `useLeverageYieldVaultSwap`. Throws on SDK failure so React Query's
|
|
17
|
-
* error model engages; returns the unwrapped `LeverageYieldSwapPayload` on success.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* const { mutateAsyncSafe: buildDeposit } = useLeverageYieldDeposit();
|
|
22
|
-
* const built = await buildDeposit({ vault, srcChainKey, srcAddress, inputToken, inputAmount, minOutputAmount });
|
|
23
|
-
* if (built.ok) vaultSwap({ ...built.value, walletProvider });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
9
|
+
/** Builds (does not execute) a deposit payload; spread it into {@link useLeverageYieldVaultSwap}. */
|
|
26
10
|
export function useLeverageYieldDeposit({
|
|
27
11
|
mutationOptions,
|
|
28
12
|
}: MutationHookParams<LeverageYieldSwapPayload, UseLeverageYieldDepositVars> = {}): SafeUseMutationResult<
|
|
@@ -2,14 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
import { SodaxError, SolverIntentStatusCode } from '@sodax/sdk';
|
|
3
3
|
import { MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from '../shared/notFoundStreak.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Pins the WIRING the pure-policy test cannot see: the hook must pass the read into the policy and
|
|
7
|
-
* advance the budget once per query update. Feeding the policy the wrong argument reproduces a poll
|
|
8
|
-
* that never stops, with the policy's own tests still green.
|
|
9
|
-
*
|
|
10
|
-
* No renderer, per the package convention (see `_apiKeyWire.test.ts`): the React Query wrapper is
|
|
11
|
-
* mocked so the captured options bag can be driven directly.
|
|
12
|
-
*/
|
|
5
|
+
// Pins hook-to-policy wiring the pure-policy test cannot see; React Query is mocked to drive the options bag directly.
|
|
13
6
|
|
|
14
7
|
// The captured options bag is opaque, like the real wrapper's.
|
|
15
8
|
let captured: any;
|
|
@@ -17,8 +10,7 @@ let captured: any;
|
|
|
17
10
|
const refSlots: Array<{ current: unknown }> = [];
|
|
18
11
|
let refCursor = 0;
|
|
19
12
|
|
|
20
|
-
//
|
|
21
|
-
// enough to observe the budget across refetchInterval calls.
|
|
13
|
+
// Replays React's useRef slot semantics (stable call order) to observe the budget across calls.
|
|
22
14
|
vi.mock('react', () => ({
|
|
23
15
|
useRef: (initial: unknown) => {
|
|
24
16
|
const slot = refSlots[refCursor] ?? { current: initial };
|
|
@@ -93,9 +85,7 @@ describe('useLeverageYieldDetailedStatus wiring', () => {
|
|
|
93
85
|
it('stops outright on a rejected API key, without spending the budget', () => {
|
|
94
86
|
refSlots.length = 0;
|
|
95
87
|
render();
|
|
96
|
-
//
|
|
97
|
-
// checks the instance. The SDK returns 401/403 as a Result, so React Query never sees an error
|
|
98
|
-
// to withhold a retry from — the policy is the only thing that can stop this poll.
|
|
88
|
+
// Must be a real SodaxError: `isAuthFailure` checks the instance via `isSodaxError`.
|
|
99
89
|
const rejected = {
|
|
100
90
|
ok: false,
|
|
101
91
|
error: new SodaxError('LOOKUP_FAILED', 'rejected', { feature: 'leverageYield', context: { status: 401 } }),
|
|
@@ -122,7 +112,6 @@ describe('useLeverageYieldDetailedStatus wiring', () => {
|
|
|
122
112
|
for (let update = 1; update <= MAX_NOT_FOUND_POLLS - 1; update++) {
|
|
123
113
|
captured.refetchInterval({ state: { data: notFound, dataUpdateCount: update } });
|
|
124
114
|
}
|
|
125
|
-
// One real answer in between clears the streak, so the next miss starts from zero.
|
|
126
115
|
captured.refetchInterval({
|
|
127
116
|
state: { data: solverRead(SolverIntentStatusCode.NOT_STARTED_YET), dataUpdateCount: 40 },
|
|
128
117
|
});
|
|
@@ -30,25 +30,8 @@ export type UseLeverageYieldDetailedStatusParams = ReadHookParams<
|
|
|
30
30
|
>;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* `useLeverageYieldApiSubmitTxStatus` needs the backend to still hold a usable record; this takes
|
|
36
|
-
* `(srcChainKey, srcTxHash)` — the pair you hold after `vaultSwap()` — and routes to whichever
|
|
37
|
-
* source can answer, so it also covers a vault swap the client-side fallback completed. `data.value`
|
|
38
|
-
* is discriminated on `source`, and each variant carries that source's payload unmodified.
|
|
39
|
-
*
|
|
40
|
-
* Polls every 3s. Stops once the answering source is terminal, once the backend rejects the API
|
|
41
|
-
* key, and — like `useDetailedStatus` — after 40 consecutive *ambiguous* reads: a solver
|
|
42
|
-
* `NOT_FOUND`, or a `LOOKUP_FAILED` whose relay has no packet for the tx. Neither can distinguish "still in flight" from "never will be", so the
|
|
43
|
-
* budget is what stops a vault swap nothing can resolve. A dependency outage — relay unreachable,
|
|
44
|
-
* solver down — keeps polling instead, so the read recovers by itself; any real status resets the
|
|
45
|
-
* budget. Override with `queryOptions.refetchInterval`.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const { data } = useLeverageYieldDetailedStatus({ params: { srcChainKey, srcTxHash } });
|
|
50
|
-
* if (data?.ok && data.value.source === 'backend') console.log(data.value.data.status);
|
|
51
|
-
* ```
|
|
33
|
+
* Vault-swap status from `(srcChainKey, srcTxHash)`, routed to whichever source can answer. Polls until terminal,
|
|
34
|
+
* auth rejection, or 40 consecutive ambiguous reads (solver NOT_FOUND / relay not delivered); outages keep polling.
|
|
52
35
|
*/
|
|
53
36
|
export const useLeverageYieldDetailedStatus = ({
|
|
54
37
|
params,
|
|
@@ -8,18 +8,7 @@ export type UseLeverageYieldEffectiveAprParams = ReadHookParams<
|
|
|
8
8
|
{ vault: Address | undefined }
|
|
9
9
|
>;
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Reads a leverage-yield vault's effective APR — AAVE supply/borrow rates plus the LSD
|
|
13
|
-
* staking yield, with the vault's leverage formula re-applied on the boosted supply side.
|
|
14
|
-
*
|
|
15
|
-
* The underlying SDK call does the on-chain reads (AAVE rates + `targetLTV`) and the
|
|
16
|
-
* off-chain LSD fetch in parallel. Rates drift slowly, so the default refresh is 60s.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const { data: apr } = useLeverageYieldEffectiveApr({ params: { vault: vault.vault } });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
11
|
+
/** Vault APR: AAVE supply/borrow rates plus LSD staking yield, with the vault's leverage applied. */
|
|
23
12
|
export function useLeverageYieldEffectiveApr({
|
|
24
13
|
params,
|
|
25
14
|
queryOptions,
|
|
@@ -4,19 +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 useLeverageYieldNotifySolver} — the hub-side intent tx hash. */
|
|
8
7
|
export type UseLeverageYieldNotifySolverVars = SolverExecutionRequest;
|
|
9
8
|
|
|
10
|
-
/**
|
|
11
|
-
* Notifies the solver that a leverage-yield vault intent landed on the hub, triggering the fill.
|
|
12
|
-
* The standalone notify step for the manual create → relay → notify flow: build the intent with
|
|
13
|
-
* `sodax.leverageYield.createVaultIntent`, relay it yourself, then call this with the hub-side
|
|
14
|
-
* intent tx hash. The end-to-end {@link useLeverageYieldVaultSwap} already calls notifySolver
|
|
15
|
-
* internally — only reach for this hook when driving the relay manually.
|
|
16
|
-
*
|
|
17
|
-
* Throws on SDK failure so React Query's error model engages; returns the unwrapped
|
|
18
|
-
* `SolverExecutionResponse` (`{ answer: 'OK', intent_hash }`) on success.
|
|
19
|
-
*/
|
|
9
|
+
/** Manual-relay notify step with the hub-side intent tx hash; {@link useLeverageYieldVaultSwap} already does this. */
|
|
20
10
|
export function useLeverageYieldNotifySolver({
|
|
21
11
|
mutationOptions,
|
|
22
12
|
}: MutationHookParams<SolverExecutionResponse, UseLeverageYieldNotifySolverVars> = {}): SafeUseMutationResult<
|
|
@@ -5,19 +5,7 @@ import type { ReadHookParams } from '../shared/types.js';
|
|
|
5
5
|
|
|
6
6
|
export type UseLeverageYieldPositionParams = ReadHookParams<LeverageYieldPosition, { vault: Address | undefined }>;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Reads a leverage-yield vault's live position snapshot via the vault's `getPositionDetails`:
|
|
10
|
-
* collateral, debt, current LTV (drift vs `targetLTV`), health factor (∞ when no debt), and
|
|
11
|
-
* idle (not-yet-deployed) asset.
|
|
12
|
-
*
|
|
13
|
-
* LTV shifts with each rebalance/rate tick, so the default refresh (30s) is faster than the
|
|
14
|
-
* APR/stats reads.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const { data: position } = useLeverageYieldPosition({ params: { vault: vault.vault } });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
8
|
+
/** Vault position snapshot (`getPositionDetails`); health factor is ∞ when there is no debt. */
|
|
21
9
|
export function useLeverageYieldPosition({
|
|
22
10
|
params,
|
|
23
11
|
queryOptions,
|
|
@@ -8,18 +8,7 @@ export type UseLeverageYieldPreviewRedeemParams = ReadHookParams<
|
|
|
8
8
|
{ vault: Address | undefined; shares: bigint | undefined }
|
|
9
9
|
>;
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Reads the assets received for redeeming `shares` of a leverage-yield vault (ERC-4626
|
|
13
|
-
* `previewRedeem`). Passing `10n ** 18n` (one share) yields the per-share price that creeps
|
|
14
|
-
* up as the vault accrues interest. Moves slowly, so the default refresh is 60s.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const { data: sharePrice } = useLeverageYieldPreviewRedeem({
|
|
19
|
-
* params: { vault: vault.vault, shares: 10n ** 18n },
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
11
|
+
/** ERC-4626 `previewRedeem`; pass `10n ** 18n` (one share) for the per-share price. */
|
|
23
12
|
export function useLeverageYieldPreviewRedeem({
|
|
24
13
|
params,
|
|
25
14
|
queryOptions,
|
|
@@ -22,7 +22,6 @@ const PAYLOAD: LeverageYieldQuoteParams = {
|
|
|
22
22
|
quote_type: 'exact_input',
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
/** The SDK's own quote Result, derived so the doubles stay honest without an unsafe cast. */
|
|
26
25
|
type QuoteResult = Awaited<ReturnType<Sodax['leverageYield']['getQuote']>>;
|
|
27
26
|
|
|
28
27
|
const QUOTE: QuoteResult = { ok: true, value: { quoted_amount: 990_000n } };
|
|
@@ -63,8 +62,7 @@ describe('getLeverageYieldQuoteQueryOptions', () => {
|
|
|
63
62
|
expect(getQuote).not.toHaveBeenCalled();
|
|
64
63
|
});
|
|
65
64
|
|
|
66
|
-
// React Query hashes keys with JSON.stringify, which throws on bigint.
|
|
67
|
-
// (`amount` and a fixed-amount `partnerFee`) must be stringified or every render crashes.
|
|
65
|
+
// React Query hashes keys with JSON.stringify, which throws on bigint.
|
|
68
66
|
it('produces a hashable key for a percentage partner fee', () => {
|
|
69
67
|
const partnerFee = { address: FEE_RECIPIENT, percentage: 100 } satisfies PartnerFee;
|
|
70
68
|
const { sodax } = makeSodax();
|
|
@@ -87,7 +85,6 @@ describe('getLeverageYieldQuoteQueryOptions', () => {
|
|
|
87
85
|
sodax,
|
|
88
86
|
payload: { ...PAYLOAD, partnerFee: { address: FEE_RECIPIENT, percentage: 100 } },
|
|
89
87
|
}).queryKey;
|
|
90
|
-
// Sharing a cache entry would serve a quote priced on a different net input.
|
|
91
88
|
expect(hashKey(base)).not.toBe(hashKey(withFee));
|
|
92
89
|
});
|
|
93
90
|
|
|
@@ -97,9 +94,6 @@ describe('getLeverageYieldQuoteQueryOptions', () => {
|
|
|
97
94
|
expect(hashKey(queryKey)).toContain('"amount":"1000000"');
|
|
98
95
|
});
|
|
99
96
|
|
|
100
|
-
// The configured fee is a real input to the quote whenever payload.partnerFee is omitted, so it
|
|
101
|
-
// has to participate in the key — otherwise differently-configured providers share a cache entry
|
|
102
|
-
// and a reconfigured provider serves the previous fee's quote.
|
|
103
97
|
it('keys the configured leverageYield fee when the payload omits partnerFee', () => {
|
|
104
98
|
const noFee = getLeverageYieldQuoteQueryOptions({ sodax: makeSodax().sodax, payload: PAYLOAD }).queryKey;
|
|
105
99
|
const withConfigFee = getLeverageYieldQuoteQueryOptions({
|
|
@@ -130,9 +124,7 @@ describe('getLeverageYieldQuoteQueryOptions', () => {
|
|
|
130
124
|
expect(hashKey(queryKey)).toContain('7000');
|
|
131
125
|
});
|
|
132
126
|
|
|
133
|
-
//
|
|
134
|
-
// decision about whether it belongs in the key — rather than a spread silently carrying a new
|
|
135
|
-
// bigint in and crashing `hashKey` at render time.
|
|
127
|
+
// Fails when `LeverageYieldQuoteParams` gains a field, forcing a decision on whether it belongs in the key.
|
|
136
128
|
it('keys exactly the known request fields', () => {
|
|
137
129
|
const { sodax } = makeSodax();
|
|
138
130
|
const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD });
|
|
@@ -150,10 +142,9 @@ describe('getLeverageYieldQuoteQueryOptions', () => {
|
|
|
150
142
|
);
|
|
151
143
|
});
|
|
152
144
|
|
|
153
|
-
// Key derivation runs during render, so it must not throw on a payload assembled from
|
|
154
|
-
// partially-validated form state — the SDK's own validation reports that as a Result.
|
|
155
145
|
it('derives a hashable key even when amount is missing', () => {
|
|
156
146
|
const { sodax } = makeSodax();
|
|
147
|
+
// Simulates half-filled form state that the type forbids; key derivation must not throw during render.
|
|
157
148
|
const malformed = { ...PAYLOAD, amount: undefined } as unknown as LeverageYieldQuoteParams;
|
|
158
149
|
|
|
159
150
|
const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: malformed });
|
|
@@ -169,7 +160,6 @@ describe('getLeverageYieldQuoteQueryOptions', () => {
|
|
|
169
160
|
sodax,
|
|
170
161
|
payload: { ...PAYLOAD, partnerFee: explicitFee },
|
|
171
162
|
});
|
|
172
|
-
// Mirrors getQuote's own precedence: per-call override beats the configured fee.
|
|
173
163
|
expect(hashKey(queryKey)).toContain('"percentage":10');
|
|
174
164
|
});
|
|
175
165
|
});
|
|
@@ -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
|
},
|