@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
|
@@ -13,16 +13,7 @@ export type UseSwapsApiIntentPacketParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to long-poll the relayer until the fill packet lands on the destination chain via the
|
|
18
|
-
* swaps API — `sodax.api.swaps.getSolvedIntentPacket`. The request is held open server-side until
|
|
19
|
-
* the packet arrives (or `body.timeout` ms elapses), so no client-side `refetchInterval` is set.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const { data: packet } = useSwapsApiIntentPacket({
|
|
23
|
-
* params: { body: { chainId: '146', fillTxHash: '0x123...' } },
|
|
24
|
-
* });
|
|
25
|
-
*/
|
|
16
|
+
/** Long-polls server-side until the packet lands (or `body.timeout` ms), so no `refetchInterval` is set. */
|
|
26
17
|
export const useSwapsApiIntentPacket = ({
|
|
27
18
|
params,
|
|
28
19
|
queryOptions,
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiPartnerFeeParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to compute the partner fee for a given input amount via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getPartnerFee`. Returns `{ fee }` (decimal string).
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useSwapsApiPartnerFee({ params: { amount: '1000000' } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiPartnerFee = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -14,26 +14,7 @@ export type UseSwapsApiQuoteParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook to get a solver quote for a cross-chain swap via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.getQuote`. Pass `query.includeTxData = true` to also build an unsigned
|
|
20
|
-
* create-intent transaction (`txData`); `srcAddress`/`dstAddress` are then required in the body.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { data: quote } = useSwapsApiQuote({
|
|
24
|
-
* params: {
|
|
25
|
-
* body: {
|
|
26
|
-
* tokenSrc: '0x...', tokenSrcChainKey: '0xa4b1.arbitrum',
|
|
27
|
-
* tokenDst: '0x...', tokenDstChainKey: 'sonic',
|
|
28
|
-
* amount: '1000000', quoteType: 'exact_input',
|
|
29
|
-
* partnerFee: { address: '0xSonicFeeReceiver', percentage: 10 },
|
|
30
|
-
* },
|
|
31
|
-
* // Optional per-request override of the configured backend API key (`x-api-key`);
|
|
32
|
-
* // usually set once instead via new Sodax({ apiKey }).
|
|
33
|
-
* apiConfig: { apiKey: 'partner-api-key' },
|
|
34
|
-
* },
|
|
35
|
-
* });
|
|
36
|
-
*/
|
|
17
|
+
/** `query.includeTxData` also builds the unsigned create-intent tx; `srcAddress`/`dstAddress` are then required. */
|
|
37
18
|
export const useSwapsApiQuote = ({
|
|
38
19
|
params,
|
|
39
20
|
queryOptions,
|
|
@@ -44,10 +25,7 @@ export const useSwapsApiQuote = ({
|
|
|
44
25
|
const apiConfig = params?.apiConfig;
|
|
45
26
|
|
|
46
27
|
return useQuery({
|
|
47
|
-
//
|
|
48
|
-
// SwapExtrasV2 fields — is a cache dimension; a partnerFee change alters the quote and must
|
|
49
|
-
// miss the cache. QuoteRequestV2 is bigint-free (compile-time guaranteed), so React Query's
|
|
50
|
-
// default key hashing handles the object directly.
|
|
28
|
+
// Key on the whole (bigint-free) body so every input, e.g. partnerFee, is a cache dimension.
|
|
51
29
|
queryKey: ['swapsApi', 'quote', body, query?.includeTxData ?? false],
|
|
52
30
|
queryFn: async (): Promise<QuoteResponseV2 | undefined> => {
|
|
53
31
|
if (!body) return undefined;
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiSolverFeeParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to compute the protocol (solver) fee for a given input amount via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getSolverFee`. Returns `{ fee }` (decimal string).
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data } = useSwapsApiSolverFee({ params: { amount: '1000000' } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiSolverFee = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
|
@@ -14,17 +14,7 @@ export type UseSwapsApiStatusParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook for polling the solver intent status by hub-chain intent tx hash via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.getStatus`. Returns `{ status, fillTxHash? }` (`fillTxHash` set when `status === 3`).
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* const { data } = useSwapsApiStatus({ params: { intentTxHash: '0x123...' } });
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* - Default refetch interval is 1 second; stops once `status` is `3` (SOLVED) or `4` (FAILED), or
|
|
26
|
-
* once the backend rejects the API key (401/403 is terminal — a retry cannot fix it).
|
|
27
|
-
*/
|
|
17
|
+
/** Polls every 1s until SOLVED (3), FAILED (4) or an API-key rejection (401/403). */
|
|
28
18
|
export const useSwapsApiStatus = ({
|
|
29
19
|
params,
|
|
30
20
|
queryOptions,
|
|
@@ -4,26 +4,12 @@ import { unwrapResult } from '../shared/unwrapResult.js';
|
|
|
4
4
|
import type { MutationHookParams } from '../shared/types.js';
|
|
5
5
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Mutation variables for {@link useSwapsApiSubmitIntent}. The per-request `apiConfig` override
|
|
9
|
-
* belongs here rather than at the hook level.
|
|
10
|
-
*/
|
|
11
7
|
export type UseSwapsApiSubmitIntentVars = {
|
|
12
8
|
body: SubmitIntentRequestV2;
|
|
13
9
|
apiConfig?: RequestOverrideConfig;
|
|
14
10
|
};
|
|
15
11
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to submit the broadcast intent tx to the relay via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.submitIntent`. Returns `{ result }` (opaque relay response).
|
|
19
|
-
*
|
|
20
|
-
* No auto-retry (`retry: false`): submitting is non-idempotent — a retry after a lost response
|
|
21
|
-
* could double-submit to the relay. Override via `mutationOptions.retry` if your relay dedupes.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const { mutateAsync: submitIntent } = useSwapsApiSubmitIntent();
|
|
25
|
-
* const { result } = await submitIntent({ body: { chainId: '146', txHash: '0x123...' } });
|
|
26
|
-
*/
|
|
12
|
+
/** No auto-retry: submit is non-idempotent, so a retry after a lost response could double-submit. */
|
|
27
13
|
export const useSwapsApiSubmitIntent = ({
|
|
28
14
|
mutationOptions,
|
|
29
15
|
}: MutationHookParams<SubmitIntentResponseV2, UseSwapsApiSubmitIntentVars> = {}): SafeUseMutationResult<
|
|
@@ -5,32 +5,11 @@ 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 useSwapsApiSubmitTx}. The per-request `apiConfig` override
|
|
10
|
-
* (e.g. base URL) belongs here rather than at the hook level — different submissions in the same
|
|
11
|
-
* component can target different endpoints without re-rendering.
|
|
12
|
-
*/
|
|
13
8
|
export type UseSwapsApiSubmitTxVars = {
|
|
14
9
|
request: SubmitTxRequestV2;
|
|
15
10
|
apiConfig?: RequestOverrideConfig;
|
|
16
11
|
};
|
|
17
12
|
|
|
18
|
-
/**
|
|
19
|
-
* React hook for submitting a swap transaction to be processed (relay, post execution to the
|
|
20
|
-
* solver, etc.) via the swaps API — `sodax.api.swaps.submitTx`.
|
|
21
|
-
*
|
|
22
|
-
* Pure mutation: pass `{ request, apiConfig? }` to `mutate({...})`. Retries up to 3 times at the hook
|
|
23
|
-
* level, except on a terminal API-key rejection (401/403) — see `retryUnlessAuthFailure`. Consumers
|
|
24
|
-
* can override via `mutationOptions.retry`.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* const { mutateAsync: submitSwapTx, isPending, error } = useSwapsApiSubmitTx();
|
|
28
|
-
*
|
|
29
|
-
* const result = await submitSwapTx({
|
|
30
|
-
* request: { txHash: '0x123...', srcChainKey: 'sonic', walletAddress: '0xabc...', intent: { ... }, relayData: '0x...' },
|
|
31
|
-
* apiConfig: { baseURL: 'https://...' },
|
|
32
|
-
* });
|
|
33
|
-
*/
|
|
34
13
|
export const useSwapsApiSubmitTx = ({
|
|
35
14
|
mutationOptions,
|
|
36
15
|
}: MutationHookParams<SubmitTxResponseV2, UseSwapsApiSubmitTxVars> = {}): SafeUseMutationResult<
|
|
@@ -14,21 +14,7 @@ export type UseSwapsApiSubmitTxStatusParams = ReadHookParams<
|
|
|
14
14
|
}
|
|
15
15
|
>;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* React hook for polling the processing status of a submitted swap transaction via the swaps API —
|
|
19
|
-
* `sodax.api.swaps.getSubmitTxStatus`. Both `txHash` and `srcChainKey` are required for the query
|
|
20
|
-
* to run (the swaps API status query requires the source chain key).
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const { data: status } = useSwapsApiSubmitTxStatus({
|
|
24
|
-
* params: { txHash: '0x123...', srcChainKey: 'sonic' },
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
* - Default refetch interval is 1 second; stops on 'solved' or 'failed' status, when the
|
|
29
|
-
* backend marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal, or
|
|
30
|
-
* once the backend rejects the API key (401/403 is terminal — a retry cannot fix it).
|
|
31
|
-
*/
|
|
17
|
+
/** Polls every 1s until solved/failed, `abandonedAt` is set, or an API-key rejection (401/403). */
|
|
32
18
|
export const useSwapsApiSubmitTxStatus = ({
|
|
33
19
|
params,
|
|
34
20
|
queryOptions,
|
|
@@ -41,8 +27,6 @@ export const useSwapsApiSubmitTxStatus = ({
|
|
|
41
27
|
return useQuery({
|
|
42
28
|
queryKey: ['swapsApi', 'submitTx', 'status', txHash, srcChainKey],
|
|
43
29
|
queryFn: async (): Promise<SubmitTxStatusResponseV2 | undefined> => {
|
|
44
|
-
// `srcChainKey` is required by the swaps API status query. The `enabled` gate below
|
|
45
|
-
// ensures both are present; this guard also narrows the types for the call.
|
|
46
30
|
if (!txHash || !srcChainKey) return undefined;
|
|
47
31
|
return unwrapResult(await sodax.api.swaps.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
48
32
|
},
|
|
@@ -52,8 +36,7 @@ export const useSwapsApiSubmitTxStatus = ({
|
|
|
52
36
|
// `retry` bounds attempts within a tick, not the interval itself — so stop it here too.
|
|
53
37
|
if (isAuthFailure(query.state.error)) return false;
|
|
54
38
|
const data = query.state.data?.data;
|
|
55
|
-
// `abandonedAt` is terminal even
|
|
56
|
-
// SDK's pollBackendSubmitTx and the bridge-api status hook.
|
|
39
|
+
// `abandonedAt` is terminal even while `status` is not, as in the SDK's pollBackendSubmitTx.
|
|
57
40
|
if (data?.status === 'solved' || data?.status === 'failed' || data?.abandonedAt) return false;
|
|
58
41
|
return 1000;
|
|
59
42
|
},
|
|
@@ -12,13 +12,6 @@ export type UseSwapsApiTokensParams = ReadHookParams<
|
|
|
12
12
|
}
|
|
13
13
|
>;
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* React hook to fetch all supported swap tokens grouped by SpokeChainKey via the swaps API —
|
|
17
|
-
* `sodax.api.swaps.getTokens`.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* const { data: tokensByChain } = useSwapsApiTokens();
|
|
21
|
-
*/
|
|
22
15
|
export const useSwapsApiTokens = ({
|
|
23
16
|
params,
|
|
24
17
|
queryOptions,
|
|
@@ -13,13 +13,6 @@ export type UseSwapsApiTokensByChainParams = ReadHookParams<
|
|
|
13
13
|
}
|
|
14
14
|
>;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* React hook to fetch supported swap tokens for a single SpokeChainKey via the swaps API —
|
|
18
|
-
* `sodax.api.swaps.getTokensByChain`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const { data: tokens } = useSwapsApiTokensByChain({ params: { chainKey: '0xa4b1.arbitrum' } });
|
|
22
|
-
*/
|
|
23
16
|
export const useSwapsApiTokensByChain = ({
|
|
24
17
|
params,
|
|
25
18
|
queryOptions,
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* provider must reach the backend as `x-api-key` on requests made through the provided instance.
|
|
4
|
-
*
|
|
5
|
-
* Covers the one key-supply surface the hook manifests' hand-built `Sodax` does not: the provider's
|
|
6
|
-
* own `new Sodax(config)`. No renderer — `useMemo` is patched to evaluate its factory so the
|
|
7
|
-
* component can be called as a plain function and the provided `sodax` read off the element's
|
|
8
|
-
* context value.
|
|
9
|
-
*/
|
|
1
|
+
// `config.apiKey` given to the provider must reach the backend as `x-api-key`.
|
|
2
|
+
// `useMemo` is patched to run its factory so the component can be called without a renderer.
|
|
10
3
|
|
|
11
4
|
import type { Sodax } from '@sodax/sdk';
|
|
12
5
|
import type { ReactElement } from 'react';
|
|
@@ -4,18 +4,7 @@ import { SodaxContext } from '@/contexts/index.js';
|
|
|
4
4
|
|
|
5
5
|
interface SodaxProviderProps {
|
|
6
6
|
children: ReactNode;
|
|
7
|
-
/**
|
|
8
|
-
* Sodax SDK config. Tracked by **reference** - a new identity re-instantiates the
|
|
9
|
-
* SDK. Hoist to a module constant or wrap in `useMemo`; include any value the SDK
|
|
10
|
-
* should react to (e.g. solver env) in the deps. Inline `{...}` re-creates the SDK
|
|
11
|
-
* every parent render and resets every `useSodaxContext` consumer.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* const config = useMemo(() => ({ solver: solverMap[env] }), [env]);
|
|
16
|
-
* <SodaxProvider config={config}>...</SodaxProvider>
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
7
|
+
/** Tracked by reference: a new identity re-creates the SDK and resets consumers, so memoize it. */
|
|
19
8
|
config?: SodaxOptions;
|
|
20
9
|
}
|
|
21
10
|
|
|
@@ -1,36 +1,11 @@
|
|
|
1
|
-
// packages/dapp-kit/src/providers/createSodaxQueryClient.ts
|
|
2
1
|
import { MutationCache, QueryClient, type QueryClientConfig } from '@tanstack/react-query';
|
|
3
2
|
|
|
4
3
|
export type CreateSodaxQueryClientOptions = {
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* This is **global observability** — it runs alongside any per-hook `onError` handler the
|
|
10
|
-
* consumer set, NOT instead of them. In particular, it fires:
|
|
11
|
-
* - whether or not `mutateAsync` was awaited inside `try/catch`
|
|
12
|
-
* - whether or not `mutateAsyncSafe` was used (the wrapper packs into `Result<T>` AFTER React
|
|
13
|
-
* Query has already entered the error state and dispatched its callbacks)
|
|
14
|
-
* - whether or not the consumer's `mutationOptions.onError` already toasted/logged
|
|
15
|
-
*
|
|
16
|
-
* It is NOT a "did this rejection escape to the global handler?" detector — accurate
|
|
17
|
-
* unhandled-rejection detection lives at `window.onunhandledrejection`, not here.
|
|
18
|
-
*
|
|
19
|
-
* To silence the default for a specific mutation that the consumer is handling locally, set
|
|
20
|
-
* `meta: { silent: true }`:
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* useSwap({ mutationOptions: { meta: { silent: true }, onError: (e) => toast(e.message) } });
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* To disable the default globally (e.g. wire your own error boundary), pass a no-op:
|
|
27
|
-
*
|
|
28
|
-
* ```ts
|
|
29
|
-
* createSodaxQueryClient({ onMutationError: () => {} });
|
|
30
|
-
* ```
|
|
5
|
+
* Fires on every mutation failure, alongside per-hook `onError`, unless the mutation sets `meta: { silent: true }`.
|
|
6
|
+
* Defaults to `console.error`.
|
|
31
7
|
*/
|
|
32
8
|
onMutationError?: (error: unknown) => void;
|
|
33
|
-
/** Pass-through for any other QueryClient config (default queries options, etc.) */
|
|
34
9
|
config?: QueryClientConfig;
|
|
35
10
|
};
|
|
36
11
|
|
|
@@ -38,39 +13,12 @@ const defaultOnMutationError = (error: unknown): void => {
|
|
|
38
13
|
console.error('[sodax] Mutation error:', error);
|
|
39
14
|
};
|
|
40
15
|
|
|
41
|
-
/**
|
|
42
|
-
* Creates a `QueryClient` pre-wired with a mutation-error observability hook that gives dapp-kit
|
|
43
|
-
* consumers a single seam for every mutation failure across the app — wire to Sentry/Datadog/console
|
|
44
|
-
* as you like. Optional opt-in: consumers who construct their own `QueryClient` are unaffected.
|
|
45
|
-
*
|
|
46
|
-
* **Composition with a custom `MutationCache`.** If you pass `config.mutationCache`, we keep your
|
|
47
|
-
* cache instance (preserving its own `onError` / `onSuccess` / etc.) and *additionally* subscribe
|
|
48
|
-
* to its event stream to dispatch `onMutationError`. Both your handler and the dapp-kit handler
|
|
49
|
-
* fire — neither replaces the other. If you don't pass one, we install our own.
|
|
50
|
-
*
|
|
51
|
-
* @example default — logs to console
|
|
52
|
-
* const queryClient = createSodaxQueryClient();
|
|
53
|
-
*
|
|
54
|
-
* @example custom — Sentry
|
|
55
|
-
* const queryClient = createSodaxQueryClient({
|
|
56
|
-
* onMutationError: (e) => Sentry.captureException(e),
|
|
57
|
-
* });
|
|
58
|
-
*
|
|
59
|
-
* @example silent — disable the default
|
|
60
|
-
* const queryClient = createSodaxQueryClient({ onMutationError: () => {} });
|
|
61
|
-
*
|
|
62
|
-
* @example bring-your-own MutationCache
|
|
63
|
-
* const myCache = new MutationCache({ onError: myOwnErrorHandler });
|
|
64
|
-
* const queryClient = createSodaxQueryClient({ config: { mutationCache: myCache } });
|
|
65
|
-
* // myOwnErrorHandler still runs; onMutationError ALSO runs (unless meta.silent).
|
|
66
|
-
*/
|
|
16
|
+
/** A custom `config.mutationCache` is kept and subscribed to, so its own handlers still fire too. */
|
|
67
17
|
export function createSodaxQueryClient({
|
|
68
18
|
onMutationError = defaultOnMutationError,
|
|
69
19
|
config,
|
|
70
20
|
}: CreateSodaxQueryClientOptions = {}): QueryClient {
|
|
71
21
|
if (config?.mutationCache) {
|
|
72
|
-
// Compose: keep the consumer's cache, attach our observability as an extra subscriber.
|
|
73
|
-
// The consumer's own `MutationCache.onError` (if any) still fires — subscribe is additive.
|
|
74
22
|
config.mutationCache.subscribe(event => {
|
|
75
23
|
if (event.type === 'updated' && event.action.type === 'error' && event.mutation.options.meta?.silent !== true) {
|
|
76
24
|
onMutationError(event.action.error);
|
|
@@ -79,7 +27,7 @@ export function createSodaxQueryClient({
|
|
|
79
27
|
return new QueryClient(config);
|
|
80
28
|
}
|
|
81
29
|
|
|
82
|
-
// No consumer cache: install our own
|
|
30
|
+
// No consumer cache: install our own `onError` (cheaper than a subscribe loop).
|
|
83
31
|
return new QueryClient({
|
|
84
32
|
...config,
|
|
85
33
|
mutationCache: new MutationCache({
|
|
@@ -57,21 +57,12 @@ type ChainSender = {
|
|
|
57
57
|
/** Reads better than the id inside an error sentence. */
|
|
58
58
|
const stepLabel = (step: ApprovalStepId): string => (step === 'allowance-reset' ? 'allowance reset' : 'approve');
|
|
59
59
|
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* passes viem's `'reverted'` through unchanged, so both spellings reach here. A receipt without a
|
|
63
|
-
* status is pre-Byzantium and inconclusive — not a revert.
|
|
64
|
-
*/
|
|
60
|
+
/** Matches both the JSON-RPC hex flag and viem's `'reverted'`, which `EvmWalletProvider` passes through unchanged.
|
|
61
|
+
* A missing status is pre-Byzantium and inconclusive, not a revert. */
|
|
65
62
|
const isRevertedEvmReceiptStatus = (status: string | undefined): boolean => status === 'reverted' || status === '0x0';
|
|
66
63
|
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* spokes, and Stellar. Every other chain reports its allowance as always sufficient, so approval
|
|
70
|
-
* never runs for it.
|
|
71
|
-
*
|
|
72
|
-
* Resolved once, before anything is sent: an unsupported chain or a Stellar wallet that cannot sign
|
|
73
|
-
* then fails without first asking the user for a signature that could never be broadcast.
|
|
74
|
-
*/
|
|
64
|
+
/** Resolved before anything is sent, so an unsupported chain or a Stellar wallet that cannot sign fails
|
|
65
|
+
* without prompting for a signature that could never be broadcast. */
|
|
75
66
|
function resolveChainSender(
|
|
76
67
|
srcChainKey: SpokeChainKey,
|
|
77
68
|
walletProvider: GetWalletProviderType<SpokeChainKey>,
|
|
@@ -79,9 +70,7 @@ function resolveChainSender(
|
|
|
79
70
|
): ChainSender {
|
|
80
71
|
const fail = (message: string): Error => new Error(`[${hookName}] ${message}`);
|
|
81
72
|
|
|
82
|
-
//
|
|
83
|
-
// SpokeService's approve-params guards resolve to, so a chain added there isn't silently
|
|
84
|
-
// missed here too.
|
|
73
|
+
// Same SDK partition SpokeService's approve guards use, so a newly added chain isn't missed here.
|
|
85
74
|
if (!isApprovalSupportedChainKeyType(srcChainKey)) {
|
|
86
75
|
throw fail(
|
|
87
76
|
`${srcChainKey} cannot be approved — SODAX approve routes support the hub (Sonic), EVM spokes, and Stellar.`,
|
|
@@ -92,8 +81,7 @@ function resolveChainSender(
|
|
|
92
81
|
const evm = walletProvider as IEvmWalletProvider;
|
|
93
82
|
|
|
94
83
|
return {
|
|
95
|
-
// Chain-bind the send: the wallet broadcasts on ITS active chain, so refuse when
|
|
96
|
-
// from the srcChainKey the user asked for. (Verifying the tx CONTENT is a separate concern.)
|
|
84
|
+
// Chain-bind the send: the wallet broadcasts on ITS active chain, so refuse when it differs from srcChainKey.
|
|
97
85
|
send: raw => evm.sendTransaction(raw as EvmRawTransaction, { expectedChainId: getEvmViemChain(srcChainKey).id }),
|
|
98
86
|
confirm: async (hash, step) => {
|
|
99
87
|
const receipt = await evm.waitForTransactionReceipt(hash as Hex);
|
|
@@ -124,25 +112,14 @@ function resolveChainSender(
|
|
|
124
112
|
};
|
|
125
113
|
}
|
|
126
114
|
|
|
127
|
-
// Unreachable:
|
|
128
|
-
// or Stellar, and the two branches above cover all three — kept only to satisfy TypeScript's
|
|
129
|
-
// return-path check (the guard is a plain boolean, so it doesn't narrow srcChainKey's type here).
|
|
115
|
+
// Unreachable: the boolean guard above doesn't narrow srcChainKey, so TypeScript needs this return path.
|
|
130
116
|
throw fail(
|
|
131
117
|
`${srcChainKey} cannot be approved — SODAX approve routes support the hub (Sonic), EVM spokes, and Stellar.`,
|
|
132
118
|
);
|
|
133
119
|
}
|
|
134
120
|
|
|
135
|
-
/**
|
|
136
|
-
*
|
|
137
|
-
* approve, which is not a valid state transition until the allowance has been zeroed on-chain.
|
|
138
|
-
*
|
|
139
|
-
* Not a pure helper like its neighbours here — it signs and sends through the caller's wallet
|
|
140
|
-
* provider — but it is framework-free, and shared by the swaps and bridge approve-and-broadcast
|
|
141
|
-
* hooks so the ordering is not re-derived per feature. `hookName` prefixes the errors.
|
|
142
|
-
*
|
|
143
|
-
* `onProgress` reports which transaction the user is being prompted for — `isPending` alone cannot
|
|
144
|
-
* say whether a popup is the reset or the approve.
|
|
145
|
-
*/
|
|
121
|
+
/** Broadcasts `resetTx` and waits for it to be mined before the approve, which is invalid until the allowance is zeroed.
|
|
122
|
+
* `hookName` prefixes errors; `onProgress` says which tx the wallet is prompting for. */
|
|
146
123
|
export async function runApprovalPlan({
|
|
147
124
|
plan,
|
|
148
125
|
srcChainKey,
|
package/src/utils/dex-utils.ts
CHANGED
|
@@ -14,22 +14,13 @@ import {
|
|
|
14
14
|
import type { SpokeChainKey } from '@sodax/sdk';
|
|
15
15
|
import { parseUnits } from 'viem';
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Subset of {@link CreateAssetDepositParams} produced by {@link createDepositParamsProps}.
|
|
19
|
-
* Callers add `srcChainKey` + `srcAddress` at the mutation call site.
|
|
20
|
-
*/
|
|
17
|
+
/** Callers add `srcChainKey` + `srcAddress` at the mutation call site. */
|
|
21
18
|
export type DepositParamsCore = Omit<CreateAssetDepositParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'>;
|
|
22
19
|
|
|
23
|
-
/**
|
|
24
|
-
* Subset of {@link CreateAssetWithdrawParams} produced by {@link createWithdrawParamsProps}.
|
|
25
|
-
* Callers add `srcChainKey` + `srcAddress` at the mutation call site.
|
|
26
|
-
*/
|
|
20
|
+
/** Callers add `srcChainKey` + `srcAddress` at the mutation call site. */
|
|
27
21
|
export type WithdrawParamsCore = Omit<CreateAssetWithdrawParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'>;
|
|
28
22
|
|
|
29
|
-
/**
|
|
30
|
-
* Subset of {@link ClDecreaseLiquidityParams} produced by {@link createDecreaseLiquidityParamsProps}.
|
|
31
|
-
* Callers add `srcChainKey` + `srcAddress` at the mutation call site.
|
|
32
|
-
*/
|
|
23
|
+
/** Callers add `srcChainKey` + `srcAddress` at the mutation call site. */
|
|
33
24
|
export type DecreaseLiquidityParamsCore = Omit<ClDecreaseLiquidityParams<SpokeChainKey>, 'srcChainKey' | 'srcAddress'>;
|
|
34
25
|
|
|
35
26
|
export function createDecreaseLiquidityParamsProps({
|
|
@@ -50,13 +41,11 @@ export function createDecreaseLiquidityParamsProps({
|
|
|
50
41
|
throw new Error('Slippage must be between 0 and 100');
|
|
51
42
|
}
|
|
52
43
|
|
|
53
|
-
// Calculate liquidity to remove based on percentage
|
|
54
44
|
const liquidityToRemove =
|
|
55
45
|
percentageNum === 100
|
|
56
46
|
? positionInfo.liquidity
|
|
57
47
|
: (positionInfo.liquidity * BigInt(Math.floor(percentageNum * 100))) / 10000n;
|
|
58
48
|
|
|
59
|
-
// Calculate expected token amounts from this liquidity
|
|
60
49
|
const expectedAmount0 =
|
|
61
50
|
percentageNum === 100
|
|
62
51
|
? positionInfo.amount0
|
|
@@ -66,7 +55,6 @@ export function createDecreaseLiquidityParamsProps({
|
|
|
66
55
|
? positionInfo.amount1
|
|
67
56
|
: (positionInfo.amount1 * BigInt(Math.floor(percentageNum * 100))) / 10000n;
|
|
68
57
|
|
|
69
|
-
// Apply slippage to minimum amounts
|
|
70
58
|
const slippageMultiplier = BigInt(Math.floor((100 - slippage) * 100));
|
|
71
59
|
const amount0Min = (expectedAmount0 * slippageMultiplier) / 10000n;
|
|
72
60
|
const amount1Min = (expectedAmount1 * slippageMultiplier) / 10000n;
|
|
@@ -97,7 +85,7 @@ export function createDepositParamsProps({
|
|
|
97
85
|
|
|
98
86
|
return {
|
|
99
87
|
asset: originalAsset.address,
|
|
100
|
-
//
|
|
88
|
+
// Deposit token (original asset) decimals, not the pool token's.
|
|
101
89
|
amount: parseUnits(String(amount), originalAsset.decimals),
|
|
102
90
|
poolToken: token.address,
|
|
103
91
|
};
|
|
@@ -135,7 +123,6 @@ export function createSupplyLiquidityParamsProps({
|
|
|
135
123
|
const amount0BigInt = parseUnits(liquidityToken0Amount, poolData.token0.decimals);
|
|
136
124
|
const amount1BigInt = parseUnits(liquidityToken1Amount, poolData.token1.decimals);
|
|
137
125
|
|
|
138
|
-
// Convert prices to ticks
|
|
139
126
|
const token0 = poolData.token0;
|
|
140
127
|
const token1 = poolData.token1;
|
|
141
128
|
const tickSpacing = poolData.tickSpacing;
|
|
@@ -143,7 +130,6 @@ export function createSupplyLiquidityParamsProps({
|
|
|
143
130
|
const tickLower = ClService.priceToTick(minPriceNum, token0, token1, tickSpacing);
|
|
144
131
|
const tickUpper = ClService.priceToTick(maxPriceNum, token0, token1, tickSpacing);
|
|
145
132
|
|
|
146
|
-
// Calculate liquidity from full amounts (the desired deposit)
|
|
147
133
|
const liquidity = ClService.calculateLiquidityFromAmounts(
|
|
148
134
|
amount0BigInt,
|
|
149
135
|
amount1BigInt,
|
|
@@ -152,8 +138,7 @@ export function createSupplyLiquidityParamsProps({
|
|
|
152
138
|
BigInt(poolData.currentTick),
|
|
153
139
|
);
|
|
154
140
|
|
|
155
|
-
//
|
|
156
|
-
// If price moves unfavorably, the contract may need slightly more tokens than expected.
|
|
141
|
+
// Max amounts are the slippage-padded ceiling the contract may pull if price moves unfavorably.
|
|
157
142
|
const { amount0Max, amount1Max } = ClService.calculateMaxAmountsForSlippage(
|
|
158
143
|
liquidity,
|
|
159
144
|
tickLower,
|
package/src/utils/index.ts
CHANGED
|
@@ -10,23 +10,12 @@ export interface NearStorageGateState {
|
|
|
10
10
|
isNear: boolean;
|
|
11
11
|
/** Show the "register storage" action: the check resolved and the recipient is not registered. */
|
|
12
12
|
needsRegistration: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Keep the downstream action (swap/bridge/borrow/withdraw) disabled: the NEAR gate is unresolved
|
|
15
|
-
* (still checking) or unmet (needs registration).
|
|
16
|
-
*/
|
|
13
|
+
/** True while the check is unresolved or registration is needed. */
|
|
17
14
|
blocksAction: boolean;
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* on NEAR — NEAR's analogue of the Stellar trustline gate. Unwrapped (no hook): pass the destination
|
|
23
|
-
* `chainKey` and the `useNearStorageCheck` result; the util owns the `=== NEAR` test and reads
|
|
24
|
-
* `isLoading` (NOT `isPending`, which stays `true` for a disabled query and would block forever).
|
|
25
|
-
*
|
|
26
|
-
* `blocksAction` deliberately also covers the in-flight check window so the action can't be
|
|
27
|
-
* triggered before registration status is known; `needsRegistration` only flips once the check has
|
|
28
|
-
* resolved (so the "register" button isn't shown speculatively while still checking).
|
|
29
|
-
*/
|
|
17
|
+
/** NEAR analogue of the Stellar trustline gate. Reads `isLoading`, not `isPending` (stays true for a disabled query);
|
|
18
|
+
* `blocksAction` also covers the in-flight check, while `needsRegistration` waits for it to resolve. */
|
|
30
19
|
export function resolveNearStorageGate(
|
|
31
20
|
chainKey: SpokeChainKey | undefined,
|
|
32
21
|
check: NearStorageCheckResult,
|
package/src/utils/stellarGate.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
import { ChainKeys, type SpokeChainKey, type StellarAccountStatus } from '@sodax/sdk';
|
|
2
2
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* The subset of a query result the gate reads. A full `UseQueryResult<T>` satisfies it.
|
|
6
|
-
*
|
|
7
|
-
* `isLoading` is intentional: `isPending` remains true for disabled queries.
|
|
8
|
-
* Errors remain distinct from unmet prerequisites.
|
|
9
|
-
*/
|
|
4
|
+
/** Reads `isLoading` because `isPending` stays true for disabled queries; errors stay distinct from unmet prerequisites. */
|
|
10
5
|
export type StellarCheckResult<T> = Pick<UseQueryResult<T>, 'isLoading' | 'isError' | 'data'>;
|
|
11
6
|
|
|
12
7
|
export interface StellarGateState {
|
|
13
8
|
isStellar: boolean;
|
|
14
9
|
needsActivation: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* The account needs a trustline but lacks spendable XLM. Never set for
|
|
17
|
-
* native XLM or an existing trustline.
|
|
18
|
-
*/
|
|
10
|
+
/** Never set for native XLM or an existing trustline. */
|
|
19
11
|
needsFunding: boolean;
|
|
20
12
|
needsTrustline: boolean;
|
|
21
13
|
/** A query failed; disabled or unresolved queries do not set this. */
|
|
@@ -45,12 +37,7 @@ const NOT_STELLAR: StellarGateState = {
|
|
|
45
37
|
blocksAction: false,
|
|
46
38
|
};
|
|
47
39
|
|
|
48
|
-
/**
|
|
49
|
-
* Resolve activation, trustline, and funding prerequisites in order.
|
|
50
|
-
*
|
|
51
|
-
* Check the trustline before affordability because an existing trustline needs
|
|
52
|
-
* no additional XLM. Unknown states fail closed.
|
|
53
|
-
*/
|
|
40
|
+
/** Checks the trustline before affordability because an existing trustline needs no extra XLM. Unknown states fail closed. */
|
|
54
41
|
export function resolveStellarGate(chainKey: SpokeChainKey | undefined, inputs: StellarGateInputs): StellarGateState {
|
|
55
42
|
const { statusCheck, trustlineCheck, isNativeToken } = inputs;
|
|
56
43
|
|